Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
feat(app-tokens): Support definitions as underlying tokens (#1935)
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich authored Dec 16, 2022
1 parent 8e7f377 commit ee22c7b
Show file tree
Hide file tree
Showing 137 changed files with 394 additions and 313 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export abstract class AaveAmmLendingTemplateTokenFetcher extends AppTokenTemplat
);
}

async getUnderlyingTokenAddresses({ contract }: GetUnderlyingTokensParams<AaveAmmAToken>) {
return contract.UNDERLYING_ASSET_ADDRESS();
async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<AaveAmmAToken>) {
return [{ address: await contract.UNDERLYING_ASSET_ADDRESS(), network: this.network }];
}

async getReserveConfigDataProps({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ export class EthereumAaveSafetyModuleAbptTokenFetcher extends AppTokenTemplatePo
return ['0x41a08648c3766f9f9d85598ff102a08f4ef84f84'];
}

async getUnderlyingTokenAddresses(_params: GetUnderlyingTokensParams<AaveAbpt>): Promise<string | string[]> {
return [this.aaveAddress, this.wethAddress];
async getUnderlyingTokenDefinitions(_params: GetUnderlyingTokensParams<AaveAbpt>) {
return [
{ address: this.aaveAddress, network: this.network },
{ address: this.wethAddress, network: this.network },
];
}

async getPricePerShare({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export class EthereumAaveSafetyModuleStkAaveTokenFetcher extends AppTokenTemplat
return ['0x4da27a545c0c5b758a6ba100e3a049001de870f5'];
}

async getUnderlyingTokenAddresses(_params: GetUnderlyingTokensParams<AaveStkAave>) {
return ['0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9'];
async getUnderlyingTokenDefinitions(_params: GetUnderlyingTokensParams<AaveStkAave>) {
return [{ address: '0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9', network: this.network }];
}

async getLiquidity({ appToken }: GetDataPropsParams<AaveStkAave>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export class EthereumAaveSafetyModuleStkAbptTokenFetcher extends AppTokenTemplat
return ['0xa1116930326d21fb917d5a27f1e9943a9595fb47'];
}

async getUnderlyingTokenAddresses() {
return ['0x41a08648c3766f9f9d85598ff102a08f4ef84f84'];
async getUnderlyingTokenDefinitions() {
return [{ address: '0x41a08648c3766f9f9d85598ff102a08f4ef84f84', network: this.network }];
}

async getLiquidity({ appToken }: GetDataPropsParams<AaveStkAbpt>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ export abstract class AaveV2LendingTemplateTokenFetcher extends AppTokenTemplate
);
}

async getUnderlyingTokenAddresses({ contract }: GetUnderlyingTokensParams<AaveV2AToken>) {
return contract.UNDERLYING_ASSET_ADDRESS();
async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<AaveV2AToken>) {
return [{ address: await contract.UNDERLYING_ASSET_ADDRESS(), network: this.network }];
}

async getReserveConfigDataProps({
Expand Down
4 changes: 2 additions & 2 deletions src/apps/across/common/across.v1-pool.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export abstract class AcrossV1PoolTokenFetcher extends AppTokenTemplatePositionF
return this.poolAddresses;
}

async getUnderlyingTokenAddresses({ contract }: GetUnderlyingTokensParams<BadgerPool>) {
return contract.l1Token();
async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<BadgerPool>) {
return [{ address: await contract.l1Token(), network: this.network }];
}

async getPricePerShare({ contract, appToken, multicall }: GetPricePerShareParams<BadgerPool>) {
Expand Down
4 changes: 2 additions & 2 deletions src/apps/across/common/across.v2-pool.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export abstract class AcrossV2PoolTokenFetcher extends AppTokenTemplatePositionF
return definitions.map(v => v.address);
}

async getUnderlyingTokenAddresses({
async getUnderlyingTokenDefinitions({
definition,
}: GetUnderlyingTokensParams<AcrossV2PoolToken, AcrossV2PoolTokenDefinition>) {
return [definition.underlyingTokenAddress];
return [{ address: definition.underlyingTokenAddress, network: this.network }];
}

async getPricePerShare({ appToken, multicall }: GetPricePerShareParams<AcrossV2PoolToken>) {
Expand Down
4 changes: 2 additions & 2 deletions src/apps/aelin/common/aelin.pool.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export abstract class AelinPoolTokenFetcher extends AppTokenTemplatePositionFetc
return data.poolCreateds.map(v => v.id);
}

getUnderlyingTokenAddresses({ contract }: GetUnderlyingTokensParams<AelinPool>) {
return contract.purchaseToken();
async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<AelinPool>) {
return [{ address: await contract.purchaseToken(), network: this.network }];
}

async getLiquidity({ appToken }: GetDataPropsParams<AelinPool>) {
Expand Down
4 changes: 2 additions & 2 deletions src/apps/airswap/ethereum/airswap.s-ast-v2.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export class EthereumAirswapSAstV2TokenFetcher extends AppTokenTemplatePositionF
return ['0x579120871266ccd8de6c85ef59e2ff6743e7cd15'];
}

async getUnderlyingTokenAddresses({ contract }: GetUnderlyingTokensParams<StakingV2>) {
return contract.token();
async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<StakingV2>) {
return [{ address: await contract.token(), network: this.network }];
}

async getLabel(): Promise<string> {
Expand Down
4 changes: 2 additions & 2 deletions src/apps/airswap/ethereum/airswap.s-ast-v3.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export class EthereumAirswapSAstV3TokenFetcher extends AppTokenTemplatePositionF
return ['0x6d88b09805b90dad911e5c5a512eedd984d6860b'];
}

async getUnderlyingTokenAddresses({ contract }: GetUnderlyingTokensParams<StakingV2>) {
return contract.token();
async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<StakingV2>) {
return [{ address: await contract.token(), network: this.network }];
}

async getLabel(): Promise<string> {
Expand Down
5 changes: 3 additions & 2 deletions src/apps/alpha-v1/ethereum/alpha-v1.lending.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Inject } from '@nestjs/common';
import BigNumber from 'bignumber.js';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { ZERO_ADDRESS } from '~app-toolkit/constants/address';
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';
import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher';
import {
Expand Down Expand Up @@ -33,8 +34,8 @@ export class EthereumAlphaV1LendingTokenFetcher extends AppTokenTemplatePosition
return ['0x67b66c99d3eb37fa76aa3ed1ff33e8e39f0b9c7a'];
}

async getUnderlyingTokenAddresses() {
return ['0x0000000000000000000000000000000000000000'];
async getUnderlyingTokenDefinitions() {
return [{ address: ZERO_ADDRESS, network: this.network }];
}

async getPrice({
Expand Down
7 changes: 5 additions & 2 deletions src/apps/arrakis/common/arrakis.pool.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ export abstract class ArrakisPoolTokenFetcher extends AppTokenTemplatePositionFe
return definitions.map(v => v.address);
}

async getUnderlyingTokenAddresses({
async getUnderlyingTokenDefinitions({
definition,
}: GetUnderlyingTokensParams<ArrakisGelatoPool, ArrakisPoolDefinition>) {
return [definition.underlyingTokenAddress0, definition.underlyingTokenAddress1];
return [
{ address: definition.underlyingTokenAddress0, network: this.network },
{ address: definition.underlyingTokenAddress1, network: this.network },
];
}

async getPricePerShare({
Expand Down
4 changes: 2 additions & 2 deletions src/apps/aura/ethereum/aura.aura-bal.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export class EthereumAuraAuraBalTokenFetcher extends AppTokenTemplatePositionFet
return [this.AURA_BAL_ADDRESS];
}

async getUnderlyingTokenAddresses() {
return [this.BAL_WETH_ADDRESS];
async getUnderlyingTokenDefinitions() {
return [{ address: this.BAL_WETH_ADDRESS, network: this.network }];
}

async getPrice(): Promise<number> {
Expand Down
4 changes: 2 additions & 2 deletions src/apps/aura/ethereum/aura.deposit.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ export class EthereumAuraDepositTokenFetcher extends AppTokenTemplatePositionFet
return definitions.map(v => v.address);
}

async getUnderlyingTokenAddresses({
async getUnderlyingTokenDefinitions({
definition,
}: GetUnderlyingTokensParams<AuraDepositToken, AuraDepositTokenDefinition>) {
const boosterContract = this.contractFactory.auraBooster({ address: definition.booster, network: this.network });
const poolInfo = await boosterContract.poolInfo(definition.poolIndex);
return poolInfo.lptoken;
return [{ address: poolInfo.lptoken, network: this.network }];
}

async getLiquidity({ appToken }: GetDataPropsParams<AuraDepositToken>) {
Expand Down
6 changes: 4 additions & 2 deletions src/apps/badger/common/badger.vault.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ export abstract class BadgerVaultTokenFetcher extends AppTokenTemplatePositionFe
return definitions.map(v => v.address);
}

async getUnderlyingTokenAddresses({ definition }: GetUnderlyingTokensParams<BadgerSett, BadgerVaultTokenDefinition>) {
return definition.underlyingTokenAddress;
async getUnderlyingTokenDefinitions({
definition,
}: GetUnderlyingTokensParams<BadgerSett, BadgerVaultTokenDefinition>) {
return [{ address: definition.underlyingTokenAddress, network: this.network }];
}

async getPricePerShare({ contract, appToken, multicall }: GetPricePerShareParams<BadgerSett>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ export class EthereumBalancerV1PoolTokenFetcher extends AppTokenTemplatePosition
return poolsFromSubgraph.pools.map(v => v.id);
}

async getUnderlyingTokenAddresses({ contract }: GetUnderlyingTokensParams<BalancerPoolToken>) {
return contract.getCurrentTokens();
async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<BalancerPoolToken>) {
const tokenAddresses = await contract.getCurrentTokens();
return tokenAddresses.map(address => ({ address, network: this.network }));
}

async getPricePerShare({ contract, appToken }: GetPricePerShareParams<BalancerPoolToken>) {
Expand Down
4 changes: 2 additions & 2 deletions src/apps/balancer-v2/common/balancer-v2.pool.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export abstract class BalancerV2PoolTokenFetcher extends AppTokenTemplatePositio
return contract.totalSupply();
}

async getUnderlyingTokenAddresses({ address, contract, multicall }: GetUnderlyingTokensParams<BalancerPool>) {
async getUnderlyingTokenDefinitions({ address, contract, multicall }: GetUnderlyingTokensParams<BalancerPool>) {
const _vault = this.contractFactory.balancerVault({ address: this.vaultAddress, network: this.network });
const vault = multicall.wrap(_vault);

Expand All @@ -121,7 +121,7 @@ export abstract class BalancerV2PoolTokenFetcher extends AppTokenTemplatePositio
const underlyingTokenAddresses = poolTokens.tokens.map(v => v.toLowerCase());
const redundantIndex = underlyingTokenAddresses.findIndex(v => v === address);
const tokenAddresses = underlyingTokenAddresses.filter((_, i) => i !== redundantIndex);
return tokenAddresses;
return tokenAddresses.map(address => ({ address, network: this.network }));
}

async getPricePerShare({ appToken, contract, multicall }: GetPricePerShareParams<BalancerPool>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class EthereumBalancerV2WrappedAaveTokenFetcher extends AppTokenTemplateP
return this.contractFactory.balancerWrappedAaveToken({ address, network: this.network });
}

async getUnderlyingTokenAddresses({ contract }: GetUnderlyingTokensParams<BalancerWrappedAaveToken>) {
return contract.callStatic.ATOKEN();
async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<BalancerWrappedAaveToken>) {
return [{ address: await contract.callStatic.ATOKEN(), network: this.network }];
}

async getPricePerShare() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ export class EthereumBancorV3BntPoolTokenFetcher extends AppTokenTemplatePositio
return [this.bntPoolTokenAddress];
}

async getUnderlyingTokenAddresses({ contract }: GetUnderlyingTokensParams<PoolToken, DefaultAppTokenDefinition>) {
const underlyingTokenAddress = await contract.reserveToken();
return underlyingTokenAddress.toLowerCase().replace(ETH_ADDR_ALIAS, ZERO_ADDRESS);
async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<PoolToken, DefaultAppTokenDefinition>) {
const underlyingTokenAddressRaw = await contract.reserveToken();
const underlyingTokenAddress = underlyingTokenAddressRaw.toLowerCase().replace(ETH_ADDR_ALIAS, ZERO_ADDRESS);
return [{ address: underlyingTokenAddress, network: this.network }];
}

async getPricePerShare({
Expand Down
7 changes: 4 additions & 3 deletions src/apps/bancor-v3/ethereum/bancor-v3.pool.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ export class EthereumBancorV3PoolTokenFetcher extends AppTokenTemplatePositionFe
return addresses;
}

async getUnderlyingTokenAddresses({ contract }: GetUnderlyingTokensParams<PoolToken, DefaultAppTokenDefinition>) {
const underlyingTokenAddress = await contract.reserveToken();
return underlyingTokenAddress.toLowerCase().replace(ETH_ADDR_ALIAS, ZERO_ADDRESS);
async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<PoolToken, DefaultAppTokenDefinition>) {
const underlyingTokenAddressRaw = await contract.reserveToken();
const underlyingTokenAddress = underlyingTokenAddressRaw.toLowerCase().replace(ETH_ADDR_ALIAS, ZERO_ADDRESS);
return [{ address: underlyingTokenAddress, network: this.network }];
}

async getPricePerShare({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ export abstract class BarnbridgeSmartAlphaJuniorPoolTokenFetcher extends AppToke
return definitions.map(x => x.address);
}

async getUnderlyingTokenAddresses({
async getUnderlyingTokenDefinitions({
definition,
}: GetUnderlyingTokensParams<BarnbridgeSmartAlphaToken, BarnbridgeSmartAlphaJuniorPoolTokenDefinition>) {
return [definition.underlyingTokenAddress];
return [{ address: definition.underlyingTokenAddress, network: this.network }];
}

async getPricePerShare({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ export abstract class BarnbridgeSmartAlphaSeniorPoolTokenFetcher extends AppToke
return definitions.map(x => x.address);
}

async getUnderlyingTokenAddresses({
async getUnderlyingTokenDefinitions({
definition,
}: GetUnderlyingTokensParams<BarnbridgeSmartAlphaToken, BarnbridgeSmartAlphaSeniorPoolTokenDefinition>) {
return [definition.underlyingTokenAddress];
return [{ address: definition.underlyingTokenAddress, network: this.network }];
}

async getPricePerShare({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,19 @@ export class AuroraBastionProtocolPoolTokenFetcher extends AppTokenTemplatePosit
return definitions.map(v => v.address);
}

async getUnderlyingTokenAddresses({
async getUnderlyingTokenDefinitions({
definition,
multicall,
}: GetUnderlyingTokensParams<Erc20, BastionProtocolPoolTokenDefinition>): Promise<string | string[]> {
}: GetUnderlyingTokensParams<Erc20, BastionProtocolPoolTokenDefinition>) {
const swapContract = this.contractFactory.bastionProtocolSwap({
address: definition.swapAddress,
network: this.network,
});

return Promise.all([multicall.wrap(swapContract).getToken(0), multicall.wrap(swapContract).getToken(1)]);
return [
{ address: await multicall.wrap(swapContract).getToken(0), network: this.network },
{ address: await multicall.wrap(swapContract).getToken(1), network: this.network },
];
}

async getPricePerShare({
Expand Down
4 changes: 2 additions & 2 deletions src/apps/beefy/common/beefy.vault.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ export abstract class BeefyVaultTokenFetcher extends AppTokenTemplatePositionFet
return definitions.map(v => v.address);
}

async getUnderlyingTokenAddresses({
async getUnderlyingTokenDefinitions({
definition,
}: GetUnderlyingTokensParams<BeefyVaultToken, BeefyVaultTokenDefinition>) {
return definition.underlyingAddress;
return [{ address: definition.underlyingAddress, network: this.network }];
}

async getPricePerShare({
Expand Down
4 changes: 2 additions & 2 deletions src/apps/bend-dao/ethereum/bend-dao.supply.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export class EthereumBendDaoSupplyTokenFetcher extends AppTokenTemplatePositionF
return [this.bTokenAddress];
}

async getUnderlyingTokenAddresses({ contract }: GetUnderlyingTokensParams<BendDaoBToken>) {
return contract.UNDERLYING_ASSET_ADDRESS();
async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<BendDaoBToken>) {
return [{ address: await contract.UNDERLYING_ASSET_ADDRESS(), network: this.network }];
}

async getLiquidity({ appToken }: GetDataPropsParams<BendDaoBToken>): Promise<number> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export class EthereumBendDaoVariableDebtTokenFetcher extends AppTokenTemplatePos
return [this.debtTokenAddress];
}

async getUnderlyingTokenAddresses({ contract }: GetUnderlyingTokensParams<BendDaoDebtToken>) {
return contract.UNDERLYING_ASSET_ADDRESS();
async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<BendDaoDebtToken>) {
return [{ address: await contract.UNDERLYING_ASSET_ADDRESS(), network: this.network }];
}

async getLiquidity({ appToken }: GetDataPropsParams<BendDaoDebtToken>): Promise<number> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export abstract class CaskProtocolWalletTokenFetcher extends AppTokenTemplatePos
return [this.caskVaultContractAddress];
}

async getUnderlyingTokenAddresses({ contract }: GetUnderlyingTokensParams<CaskVaultToken>) {
return contract.getBaseAsset();
async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<CaskVaultToken>) {
return [{ address: await contract.getBaseAsset(), network: this.network }];
}

async getPricePerShare({ appToken, contract }: GetPricePerShareParams<CaskVaultToken>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class EthereumChickenBondBlusdTokenFetcher extends AppTokenTemplatePositi
return ['0xb9d7dddca9a4ac480991865efef82e01273f79c3'];
}

async getUnderlyingTokenAddresses() {
return ['0x5f98805a4e8be255a32880fdec7f6728c6568ba0'];
async getUnderlyingTokenDefinitions() {
return [{ address: '0x5f98805a4e8be255a32880fdec7f6728c6568ba0', network: this.network }];
}

async getPrice({ multicall }: GetPriceParams<ChickenBondBlusd>): Promise<number> {
Expand Down
4 changes: 2 additions & 2 deletions src/apps/clearpool/common/clearpool.pool.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export abstract class ClearpoolPoolTokenFetcher extends AppTokenTemplatePosition
return this.clearpoolContractFactory.clearpoolPool({ address, network: this.network });
}

getUnderlyingTokenAddresses({ contract }: GetUnderlyingTokensParams<ClearpoolPool>) {
return contract.currency();
async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams<ClearpoolPool>) {
return [{ address: await contract.currency(), network: this.network }];
}

getPricePerShare({ contract }: GetPricePerShareParams<ClearpoolPool>): Promise<number | number[]> {
Expand Down
4 changes: 2 additions & 2 deletions src/apps/clever/ethereum/clever.lever.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export class EthereumCleverLeverTokenFetcher extends AppTokenTemplatePositionFet
return [CLEVCVX];
}

async getUnderlyingTokenAddresses() {
return [CVX];
async getUnderlyingTokenDefinitions() {
return [{ address: CVX, network: this.network }];
}

async getPricePerShare() {
Expand Down
Loading

0 comments on commit ee22c7b

Please sign in to comment.