avalance + beefy vault v6

This commit is contained in:
Laurent Le Houerou 2021-11-12 15:05:57 +04:00
parent 923903d9f5
commit 5e4a267948
4 changed files with 138 additions and 0 deletions

30
avalanche/client.go Normal file
View File

@ -0,0 +1,30 @@
package avalanche
import (
"context"
"git.lehouerou.net/laurent/evm"
"github.com/pkg/errors"
)
const (
RpcUrl = "https://api.avax.network/ext/bc/C/rpc"
)
type Client struct {
evm.Client
}
func NewClientWithUrl(ctx context.Context, rpcurl string, privatekey string, options ...evm.ClientOption) (*Client, error) {
ethclient, err := evm.NewClient(ctx, rpcurl, privatekey, NewTokenMapper(), options...)
if err != nil {
return nil, errors.Wrap(err, "creating ethereum client")
}
return &Client{
ethclient,
}, nil
}
func NewClient(ctx context.Context, privatekey string, options ...evm.ClientOption) (*Client, error) {
return NewClientWithUrl(ctx, RpcUrl, privatekey, options...)
}

76
avalanche/tokenmapper.go Normal file
View File

@ -0,0 +1,76 @@
package avalanche
import (
"git.lehouerou.net/laurent/evm"
"github.com/ethereum/go-ethereum/common"
)
var tokens = map[string]string{
"ANY": "0xb44a9b6905af7c801311e8f4e76932ee959c663c",
"AVE": "0x78ea17559b3d2cf85a7f9c2c704eda119db5e6de",
"AVXT": "0x397bbd6a0e41bdf4c3f971731e180db8ad06ebc1",
"BAG": "0xa1144a6a1304bd9cbb16c800f7a867508726566e",
"BIFI": "0xd6070ae98b8069de6b494332d1a1a81b6179d960",
"BLIZZ": "0xb147656604217a03fe2c73c4838770df8d9d21b8",
"DAI.e": "0xd586e7f844cea2f87f50152665bcbc2c279d8d70",
"DYP": "0x961c8c0b1aad0c0b10a51fef6a867e3091bcef17",
"ELK": "0xe1c110e1b1b4a1ded0caf3e42bfbdbb7b5d7ce1c",
"FRAX": "0xd24c2ad096400b6fbcd2ad8b24e7acbc21a1da64",
"FXS": "0x214db107654ff987ad859f34125307783fc8e387",
"GAJ": "0x595c8481c48894771ce8fade54ac6bf59093f9e8",
"HCT": "0x45c13620b55c35a5f539d26e88247011eb10fdbd",
"HUSKY": "0x65378b697853568da9ff8eab60c13e1ee9f4a654",
"JOE": "0x6e84a6216ea6dacc71ee8e6b0a5b7322eebc0fdd",
"KLO": "0xb27c8941a7df8958a1778c0259f76d1f8b711c35",
"LINK.e": "0x5947bb275c521040051d82396192181b413227a3",
"MFI": "0x9fda7ceec4c18008096c2fe2b85f05dc300f94d0",
"MIM": "0x130966628846bfd36ff31a822705796e8cb8c18d",
"NFTD": "0x8e0fe2947752be0d5acf73aae77362daf79cb379",
"OH": "0x937e077abaea52d3abf879c9b9d3f2ebd15baa21",
"OOE": "0x0ebd9537a25f56713e34c45b38f421a1e7191469",
"PEFI": "0xe896cdeaac9615145c0ca09c8cd5c25bced6384c",
"PENDLE": "0xfb98b335551a418cd0737375a2ea0ded62ea213b",
"PNG": "0x60781c2586d68229fde47564546784ab3faca982",
"QI": "0x8729438eb15e2c8b576fcc6aecda6a148776c0f5",
"RAI": "0x97cd1cfe2ed5712660bb6c14053c0ecb031bff7d",
"SHIBX": "0x440abbf18c54b2782a4917b80a1746d3a2c2cce1",
"SMRT": "0xcc2f1d827b18321254223df4e84de399d9ff116c",
"SMRTr": "0x6d923f688c7ff287dc3a5943caeefc994f97b290",
"SNOB": "0xc38f41a296a4493ff429f1238e030924a1542e50",
"SPORE": "0x6e7f5c0b9f4432716bdd0a77a3601291b9d9e985",
"START": "0xf44fb887334fa17d2c5c0f970b5d320ab53ed557",
"SUSHI": "0x39cf1bd5f15fb22ec3d9ff86b0727afc203427cc",
"SWAP.e": "0xc7b5d72c836e718cda8888eaf03707faef675079",
"TEDDY": "0x094bd7b2d99711a1486fb94d4395801c6d0fddcc",
"TIME": "0xb54f16fb19478766a268f172c9480f8da1a7c9c3",
"TRACTOR": "0x542fa0b261503333b90fe60c78f2beed16b7b7fd",
"TRYB": "0x564a341df6c126f90cf3ecb92120fd7190acb401",
"TSD": "0x4fbf0429599460d327bd5f55625e30e4fc066095",
"TUSD": "0x1c20e891bab6b1727d14da358fae2984ed9b59eb",
"USDT.e": "0xc7198437980c041c805a1edcba50c1ce5db95118",
"USDt": "0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7",
"VEE": "0x3709e8615e02c15b096f8a9b460ccb8ca8194e86",
"VSO": "0x846d50248baf8b7ceaa9d9b53bfd12d7d7fbb25a",
"WALBT": "0x9e037de681cafa6e661e6108ed9c2bd1aa567ecd",
"WAVAX": "0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7",
"WOW": "0xa384bc7cdc0a93e686da9e7b8c0807cd040f4e0b",
"XAVA": "0xd1c3f94de7e5b45fa4edbba472491a9f4b166fc4",
"XCRS": "0x70b4ae8eb7bd572fc0eb244cd8021066b3ce7ee4",
"XMTL": "0x4c1057455747e3ee5871d374fdd77a304ce10989",
"XSLR": "0xe6ee049183b474ecf7704da3f6f555a1dcaf240f",
"YAK": "0x59414b3089ce2af0010e7523dea7e2b35d776ec7",
"xJOE": "0x57319d41f71e81f3c65f2a47ca4e001ebafd4f33",
"WETH.e": "0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab",
"WBTC.e": "0x50b7545627a5162F82A992c33b87aDc75187B218",
}
func NewTokenMapper() evm.TokenMapper {
tm := evm.NewTokenMapper()
for s, s2 := range tokens {
tm.AddToken(s, common.HexToAddress(s2))
}
tm.AddAlias("ETH", "WETH.e")
tm.AddAlias("BTC", "WBTC.e")
return tm
}

File diff suppressed because one or more lines are too long

31
beefy/vaultv6.go Normal file
View File

@ -0,0 +1,31 @@
package beefy
import (
"git.lehouerou.net/laurent/evm"
"git.lehouerou.net/laurent/evm/beefy/contracts"
"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
)
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
}