add smartchef harvest method

This commit is contained in:
Laurent Le Houerou 2021-11-19 10:44:55 +04:00
parent 005d54e57d
commit ee4bb4c23d
3 changed files with 2207 additions and 0 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

35
pancakeswap/smartchef.go Normal file
View File

@ -0,0 +1,35 @@
package pancakeswap
import (
"context"
"math/big"
"git.lehouerou.net/laurent/evm"
"git.lehouerou.net/laurent/evm/bsc"
"git.lehouerou.net/laurent/evm/pancakeswap/contracts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/pkg/errors"
)
type SmartChef struct {
client *bsc.Client
contract *contracts.SmartChef
}
func NewSmartChef(client *bsc.Client, address common.Address) (*SmartChef, error) {
contract, err := contracts.NewSmartChef(address, client)
if err != nil {
return nil, errors.Wrap(err, "init contract")
}
return &SmartChef{
client: client,
contract: contract,
}, nil
}
func (s *SmartChef) Harvest(ctx context.Context) (evm.Transaction, error) {
return s.client.Execute(ctx, func(ctx context.Context, opts *evm.TransactOpts) (*types.Transaction, error) {
return s.contract.Deposit(opts.TransactOpts, big.NewInt(0))
})
}