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" ) type TankChefService struct { client evm.Client contract *contracts.TankChef } func NewTankChefService(c evm.Client, address string) (*TankChefService, error) { contract, err := contracts.NewTankChef(common.HexToAddress(address), c) if err != nil { return nil, errors.Wrap(err, "init contract") } return &TankChefService{ contract: contract, client: c, }, nil } func (s *TankChefService) Harvest(ctx context.Context, opts ...evm.ExecutionOption) (evm.Transaction, error) { return s.client.Execute(ctx, func(ctx context.Context, options *evm.TransactOpts) (*types.Transaction, error) { return s.contract.Withdraw(options.TransactOpts, big.NewInt(0)) }, opts...) } func (s *TankChefService) Deposit(ctx context.Context, 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, amount.Shift(18).BigInt()) }, opts...) }