evm/beefy/vaultv6.go

42 lines
1.0 KiB
Go

package beefy
import (
"git.lehouerou.net/laurent/evm"
"git.lehouerou.net/laurent/evm/beefy/contracts"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"github.com/shopspring/decimal"
)
type VaultV6 struct {
evm.Token
client evm.Client
contract *contracts.VaultV6
}
func NewVaultV6(client evm.Client, address common.Address) (*VaultV6, error) {
contract, err := contracts.NewVaultV6(address, client)
if err != nil {
return nil, errors.Wrap(err, "init vault contract")
}
token, err := client.TokenService().TokenByAddress(address)
if err != nil {
return nil, errors.Wrap(err, "init token contract")
}
return &VaultV6{
client: client,
contract: contract,
Token: token,
}, nil
}
func (v *VaultV6) PricePerFullShare() (decimal.Decimal, error) {
ppfs, err := v.contract.GetPricePerFullShare(&bind.CallOpts{})
if err != nil {
return decimal.Zero, errors.Wrap(err, "calling contract")
}
return v.ValueFromBigInt(ppfs), nil
}