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

Commit

Permalink
feat(debt): Add ability to define debt for app token positions (#1515)
Browse files Browse the repository at this point in the history
  • Loading branch information
Émile Filteau-Tessier authored Oct 11, 2022
1 parent f31e798 commit 056ac90
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export abstract class AaveAmmLendingTemplateTokenFetcher extends AppTokenTemplat
super(appToolkit);
}

abstract isDebt: boolean;
abstract providerAddress: string;
abstract getTokenAddress(reserveTokenAddressesData: AaveV2ReserveTokenAddressesData): string;
abstract getApyFromReserveData(reserveApyData: AaveV2ReserveApyData): number;
Expand Down Expand Up @@ -128,23 +127,4 @@ export abstract class AaveAmmLendingTemplateTokenFetcher extends AppTokenTemplat
}: GetDisplayPropsParams<AaveAmmAToken, AaveV2LendingTokenDataProps>): Promise<string> {
return appToken.symbol;
}

async getBalances(address: string): Promise<AppTokenPositionBalance<AaveV2LendingTokenDataProps>[]> {
const multicall = this.appToolkit.getMulticall(this.network);
const appTokens = await this.appToolkit.getAppTokenPositions<AaveV2LendingTokenDataProps>({
appId: this.appId,
network: this.network,
groupIds: [this.groupId],
});

const balances = await Promise.all(
appTokens.map(async appToken => {
const balanceRaw = await this.getBalancePerToken({ multicall, address, appToken });
const tokenBalance = drillBalance(appToken, balanceRaw.toString(), { isDebt: this.isDebt });
return tokenBalance;
}),
);

return balances as AppTokenPositionBalance<AaveV2LendingTokenDataProps>[];
}
}
20 changes: 0 additions & 20 deletions src/apps/aave-v2/helpers/aave-v2.lending.template.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export abstract class AaveV2LendingTemplateTokenFetcher extends AppTokenTemplate
super(appToolkit);
}

abstract isDebt: boolean;
abstract providerAddress: string;
abstract getTokenAddress(reserveTokenAddressesData: AaveV2ReserveTokenAddressesData): string;
abstract getApyFromReserveData(reserveApyData: AaveV2ReserveApyData): number;
Expand Down Expand Up @@ -150,23 +149,4 @@ export abstract class AaveV2LendingTemplateTokenFetcher extends AppTokenTemplate
}: GetDisplayPropsParams<AaveV2AToken, AaveV2LendingTokenDataProps>): Promise<string> {
return appToken.symbol;
}

async getBalances(address: string): Promise<AppTokenPositionBalance<AaveV2LendingTokenDataProps>[]> {
const multicall = this.appToolkit.getMulticall(this.network);
const appTokens = await this.appToolkit.getAppTokenPositions<AaveV2LendingTokenDataProps>({
appId: this.appId,
network: this.network,
groupIds: [this.groupId],
});

const balances = await Promise.all(
appTokens.map(async appToken => {
const balanceRaw = await this.getBalancePerToken({ multicall, address, appToken });
const tokenBalance = drillBalance(appToken, balanceRaw.toString(), { isDebt: this.isDebt });
return tokenBalance;
}),
);

return balances as AppTokenPositionBalance<AaveV2LendingTokenDataProps>[];
}
}
5 changes: 3 additions & 2 deletions src/position/template/app-token.template.position-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export abstract class AppTokenTemplatePositionFetcher<
appId: string;
groupId: string;
network: Network;
isDebt: boolean = false;
abstract groupLabel: string;

isExcludedFromBalances = false;
Expand Down Expand Up @@ -308,7 +309,7 @@ export abstract class AppTokenTemplatePositionFetcher<
const balances = await Promise.all(
appTokens.map(async appToken => {
const balanceRaw = await this.getBalancePerToken({ multicall, address, appToken });
const tokenBalance = drillBalance(appToken, balanceRaw.toString());
const tokenBalance = drillBalance(appToken, balanceRaw.toString(), { isDebt: this.isDebt });
return tokenBalance;
}),
);
Expand Down Expand Up @@ -343,7 +344,7 @@ export abstract class AppTokenTemplatePositionFetcher<
const tokenBalance = balances.find(b => b.key === this.appToolkit.getPositionKey(token));
if (!tokenBalance) return null;

const result = drillBalance<typeof token, V>(token, tokenBalance.balance);
const result = drillBalance<typeof token, V>(token, tokenBalance.balance, { isDebt: this.isDebt });
return result;
});

Expand Down

0 comments on commit 056ac90

Please sign in to comment.