evm/pancakeswap/smartchef.go

36 lines
912 B
Go

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))
})
}