yearn / yearn-sdk

🦧 SDK for the yearn.finance platform. WIP
https://npm.im/@yfi/sdk
MIT License
53 stars 56 forks source link

refactor: TokenInterface#balances [WEB-1420] #250

Closed karelianpie closed 2 years ago

karelianpie commented 2 years ago

WEB-1420 (subtask of WEB-1008)

Add a new type for token data source, it will be set to the service where the token data came from.

type TokenDataSource = "vaults" | "ironbank" | "zapper" | "labs";

Add a few props to the Token interface

interface Token extends ERC20 {
  // ...
  dataSource: TokenDataSource; // new
  supported: {
    zapper?: boolean;
    vaults?: boolean; // new
    ironBank?: boolean; // new
    labs?: boolean; // new
  };
  // ...
}
linear[bot] commented 2 years ago
WEB-1009 Supported Zap Tokens

### Elevator Pitch: **SDK should provide information if a token is supported to zap in/out of a contract** ### Customer Value: **Frontends can display just the supported tokens for a given zap** ### Agreed upon Acceptance Criteria (definition of Done): * Token interface should include the property `supported[customZapContractNameAlias]: boolean` if its supported by a zap contract. supported.zapper will not be deprecated, but new properties will be added: ``` export interface Token extends ERC20 { icon?: string; priceUsdc: Usdc; supported: { zapper?: boolean; zapperZapIn?: boolean; zapperZapOut?: boolean; ftmApeZap?: boolean; ...otherCustomZapContracts; }; metadata?: TokenMetadata; } ``` ### ### Design Approach: Hardcode in SDK all available zap contract addresses by alias. Use zappers api to handle zapperZapIn supported tokens for eth mainnet. Add to yearn meta zapperZapOut contract to ETH, DAI, USDC, USDT, WBTC from eth mainnet, Add to yearn meta other custom contracts like ftmApeZap (`0xfCE6CbeF3867102da383465cc237B49fF4B9d48F`) (Seems done here [https://github.com/yearn/yearn-meta/blob/master/data/tokens/250/0x0000000000000000000000000000000000000000.json](https://github.com/yearn/yearn-meta/blob/master/data/tokens/250/0x0000000000000000000000000000000000000000.json)) ### Assumptions: can be cached since we dont expect changes frequently ### Design review: xgambitox

linear[bot] commented 2 years ago
WEB-1420 [sdk] Refactor TokenInterface#balances()

`TokenInterface#balances()` should return balance, balance in usdc and price for the given token addresses if they are supported in current network. **Technical details** Similar to the work done in `tokens.supported()` \- Fails gracefully when there is an error with zapper; \- Merge balances following same precedence (vaults > iron bank > zapper) and remove dupes \- If a token is not supported it throws an error \- If token addresses list is not provided, return balances for all supported tokens (i.e. `Token.supported()`) Add the following properties on Token so that we know which service supports a particular token: ``` interface Token extends ERC20 { // ... dataSource: TokenDataSource; // new supported: { zapper?: boolean; vaults?: boolean; // new ironBank?: boolean; // new labs?: boolean; // new }; // ... } ``` Token data source is where the token data is coming from (i.e. Vaults, Iron Bank, Zapper or Labs) ``` type TokenDataSource = "vaults" | "ironbank" | "zapper" | "labs"; ```

github-actions[bot] commented 2 years ago

size-limit report 📦

Path Size
dist/sdk.cjs.production.min.js 43.29 KB (+0.31% 🔺)
dist/sdk.esm.js 43.51 KB (+0.3% 🔺)