package polycat import ( "context" "math/big" "git.lehouerou.net/laurent/evm" "git.lehouerou.net/laurent/evm/polycat/contracts" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/pkg/errors" "github.com/shopspring/decimal" ) const ( MasterchefAddress = "0x8CFD1B9B7478E7B0422916B72d1DB6A9D513D734" DepositReferer = "0" ) type MasterchefService struct { client evm.Client contract *contracts.Masterchef } func NewMasterchefService(c evm.Client) (*MasterchefService, error) { contract, err := contracts.NewMasterchef(common.HexToAddress(MasterchefAddress), c) if err != nil { return nil, errors.Wrap(err, "init contract") } return &MasterchefService{ contract: contract, client: c, }, nil } func (s *MasterchefService) Harvest(ctx context.Context, poolid int, opts ...evm.ExecutionOption) (evm.Transaction, error) { return s.client.Execute(ctx, func(ctx context.Context, options *evm.TransactOpts) (*types.Transaction, error) { return s.contract.Deposit(options.TransactOpts, big.NewInt(int64(poolid)), big.NewInt(0), common.HexToAddress(DepositReferer)) }, opts...) } func (s *MasterchefService) Deposit(ctx context.Context, poolid int, amount decimal.Decimal, opts ...evm.ExecutionOption) (evm.Transaction, error) { return s.client.Execute(ctx, func(ctx context.Context, options *evm.TransactOpts) (*types.Transaction, error) { return s.contract.Deposit(options.TransactOpts, big.NewInt(int64(poolid)), amount.Shift(18).BigInt(), common.HexToAddress(DepositReferer)) }, opts...) }