Using Token Adapters
Don't forget to initialize DeFi SDK first! Read more about what TokenAdapters are here.
Get derivative token underlying components
>>> UNISWAP_DAI_POOL = '0x2a1530c4c41db0b0b2bb646cb5eb1a67b7158667'
>>> await defi_sdk.get_token_components('Uniswap V1 pool token', UNISWAP_DAI_POOL)
[
TokenBalance(
metadata=TokenMetadata(
address='0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
name='Ether',
symbol='ETH',
decimals=18
),
balance=Decimal('1.115069671320704604')
),
TokenBalance(
metadata=TokenMetadata(
address='0x6b175474e89094c44da98b954eedeac495271d0f',
name='Dai Stablecoin',
symbol='DAI',
decimals=18
),
balance=Decimal('216.692050327076500045')
)
]
uniswapDaiPool := "0x2a1530c4c41db0b0b2bb646cb5eb1a67b7158667"
sdk.GetTokenComponents("Uniswap V1 pool token", uniswapDaiPool)
// [{
// Metadata:{
// Token:[238 238 238 238 238 238 238 238 238 238 238 238 238 238 238 238 238 238 238 238]
// Name:Ether
// Symbol:ETH
// Decimals:18
// }
// Amount:+1108093230485279057
// }
// {
// Metadata:{
// Token:[107 23 84 116 232 144 148 196 77 169 139 149 78 237 234 196 149 39 29 15]
// Name:Dai Stablecoin
// Symbol:DAI
// Decimals:18
// }
// Amount:+221366932637588225901
// }]
const tokenType = 'Uniswap V2 pool token';
const tokenAddress = '0xa478c2975ab1ea89e8196811f51a7b7ade33eb11';
defiSdk.getTokenComponents(tokenType, tokenAddress).then(components => {
console.log("Base", components.base);
console.log("Underlying", components.underlying);
});
// output:
// Base TokenBalance {
// balance: '1000000000000000000',
// metadata: TokenMetadata {
// address: '0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11',
// decimals: 18,
// name: 'DAI/WETH Pool',
// symbol: 'UNI-V2'
// }
// }
// Underlying [
// TokenBalance {
// balance: '14400197657513580020',
// metadata: TokenMetadata {
// address: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
// decimals: 18,
// name: 'Dai Stablecoin',
// symbol: 'DAI'
// }
// },
// TokenBalance {
// balance: '70472588741190622',
// metadata: TokenMetadata {
// address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
// decimals: 18,
// name: 'Wrapped Ether',
// symbol: 'WETH'
// }
// }
// ]
Last updated