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] #253

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-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% 🔺)
karelianpie commented 2 years ago

Frontend PR https://github.com/yearn/yearn-finance-v3/pull/552