From 5e4a2679483581f378374ceb9b51c7224d2beea1 Mon Sep 17 00:00:00 2001 From: Laurent Le Houerou Date: Fri, 12 Nov 2021 15:05:57 +0400 Subject: [PATCH] avalance + beefy vault v6 --- avalanche/client.go | 30 +++++++++++++++ avalanche/tokenmapper.go | 76 +++++++++++++++++++++++++++++++++++++ beefy/contracts/vaultv6.abi | 1 + beefy/vaultv6.go | 31 +++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 avalanche/client.go create mode 100644 avalanche/tokenmapper.go create mode 100644 beefy/contracts/vaultv6.abi create mode 100644 beefy/vaultv6.go diff --git a/avalanche/client.go b/avalanche/client.go new file mode 100644 index 0000000..e45d813 --- /dev/null +++ b/avalanche/client.go @@ -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...) +} diff --git a/avalanche/tokenmapper.go b/avalanche/tokenmapper.go new file mode 100644 index 0000000..44ec3c9 --- /dev/null +++ b/avalanche/tokenmapper.go @@ -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 +} diff --git a/beefy/contracts/vaultv6.abi b/beefy/contracts/vaultv6.abi new file mode 100644 index 0000000..de301cb --- /dev/null +++ b/beefy/contracts/vaultv6.abi @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"contract IStrategy","name":"_strategy","type":"address"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint256","name":"_approvalDelay","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"implementation","type":"address"}],"name":"NewStratCandidate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"implementation","type":"address"}],"name":"UpgradeStrat","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"approvalDelay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"available","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"balance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"earn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getPricePerFullShare","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"inCaseTokensGetStuck","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_implementation","type":"address"}],"name":"proposeStrat","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stratCandidate","outputs":[{"internalType":"address","name":"implementation","type":"address"},{"internalType":"uint256","name":"proposedTime","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"strategy","outputs":[{"internalType":"contract IStrategy","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"upgradeStrat","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"want","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_shares","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawAll","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/beefy/vaultv6.go b/beefy/vaultv6.go new file mode 100644 index 0000000..365f4b9 --- /dev/null +++ b/beefy/vaultv6.go @@ -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 +}