package curve import ( "git.lehouerou.net/laurent/evm" "git.lehouerou.net/laurent/evm/curve/contracts" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" "github.com/shopspring/decimal" ) type Pool struct { client evm.Client contract *contracts.Pool lptoken evm.Token tokens []evm.Token } func NewPool(client evm.Client, address common.Address) (*Pool, error) { contract, err := contracts.NewPool(address, client) if err != nil { return nil, errors.Wrap(err, "init contract") } lptokenaddress, err := contract.LpToken(&bind.CallOpts{}) if err != nil { return nil, errors.Wrap(err, "getting lp token address") } lptoken, err := client.TokenService().TokenByAddress(lptokenaddress) if err != nil { return nil, errors.Wrap(err, "getting lp token") } return &Pool{ client: client, contract: contract, lptoken: lptoken, }, nil } func (p *Pool) VirtualPrice() (decimal.Decimal, error) { price, err := p.contract.GetVirtualPrice(&bind.CallOpts{}) if err != nil { return decimal.Zero, errors.Wrap(err, "calling contract") } return decimal.NewFromBigInt(price, -18), nil } //func (p *Pool) CalculateTokenAmount(amounts []decimal.Decimal)