Skip to content

Commit

Permalink
refactor(cardbon-defi) use getAppContractPositions
Browse files Browse the repository at this point in the history
  • Loading branch information
GrandSchtroumpf committed Jan 31, 2024
1 parent e6464c4 commit 13958c7
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ETH_ADDR_ALIAS, ZERO_ADDRESS } from '~app-toolkit/constants/address';
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';
import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper';
import { ContractPositionBalance, RawContractPositionBalance } from '~position/position-balance.interface';
import { MetaType } from '~position/position.interface';
import { ContractPosition, MetaType } from '~position/position.interface';
import {
DefaultContractPositionDefinition,
UnderlyingTokenDefinition,
Expand Down Expand Up @@ -101,7 +101,12 @@ export class EthereumCarbonDefiStrategyContractPositionFetcher extends CustomCon
async getBalances(address: string): Promise<ContractPositionBalance<StrategyProps>[]> {
if (address === ZERO_ADDRESS) return [];

const positions = await this.getPositions();
const positions = await this.appToolkit.getAppContractPositions<StrategyDefinition>({
appId: this.appId,
network: this.network,
groupIds: [this.groupId],
});

const balances: ContractPositionBalance<StrategyProps>[] = [];
for (const position of positions) {
const { owner, orders } = position.dataProps.strategy;
Expand All @@ -122,13 +127,18 @@ export class EthereumCarbonDefiStrategyContractPositionFetcher extends CustomCon
async getRawBalances(address: string): Promise<RawContractPositionBalance[]> {
if (address === ZERO_ADDRESS) return [];

const positions = await this.getPositions();
const positions = await this.appToolkit.getAppContractPositions<StrategyDefinition>({
appId: this.appId,
network: this.network,
groupIds: [this.groupId],
});

const balances: RawContractPositionBalance[] = [];
for (const position of positions) {
const { owner, orders } = position.dataProps.strategy;
if (owner.toLowerCase() !== address.toLowerCase()) continue;
balances.push({
key: this.appToolkit.getPositionKey(position),
key: this.appToolkit.getPositionKey(position as ContractPosition<any>),
tokens: [
{
key: this.appToolkit.getPositionKey(position.tokens[0]),
Expand Down

0 comments on commit 13958c7

Please sign in to comment.