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

Commit

Permalink
fix(vendor-finance): fix lender positions after migration (#1752)
Browse files Browse the repository at this point in the history
  • Loading branch information
Clonescody authored Nov 18, 2022
1 parent fd79639 commit ef42f6e
Showing 1 changed file with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { MetaType } from '~position/position.interface';
import { isBorrowed } from '~position/position.utils';
import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher';
import {
GetDataPropsParams,
GetDisplayPropsParams,
GetTokenBalancesParams,
GetTokenDefinitionsParams,
Expand All @@ -34,6 +35,12 @@ export type VendorFinancePoolDefinition = {
lendBalance: string;
totalBorrowed: string;
};

type VendorFinancePoolDataProps = DefaultDataProps & {
deployer: string;
totalDeposited: number;
};

@PositionTemplate()
export class ArbitrumVendorFinancePoolContractPositionFetcher extends ContractPositionTemplatePositionFetcher<VendorFinancePool> {
groupLabel = 'Lending Pools';
Expand Down Expand Up @@ -68,10 +75,13 @@ export class ArbitrumVendorFinancePoolContractPositionFetcher extends ContractPo
}));
}

// returning the lendToken with two different status as it'll either be
// deposited initially (user = lender) or borrowed (user = borrower).
async getTokenDefinitions({ definition }: GetTokenDefinitionsParams<VendorFinancePool, VendorFinancePoolDefinition>) {
return [
{ metaType: MetaType.SUPPLIED, address: definition.colToken, network: this.network },
{ metaType: MetaType.BORROWED, address: definition.lendToken, network: this.network },
{ metaType: MetaType.SUPPLIED, address: definition.lendToken, network: this.network },
];
}

Expand Down Expand Up @@ -123,14 +133,30 @@ export class ArbitrumVendorFinancePoolContractPositionFetcher extends ContractPo
},
];
}
async getDataProps(
_params: GetDataPropsParams<VendorFinancePool, DefaultDataProps, VendorFinancePoolDefinition>,
): Promise<VendorFinancePoolDataProps> {
return {
deployer: _params.definition.deployer,
totalDeposited: parseInt(_params.definition.lendBalance) + parseInt(_params.definition.totalBorrowed),
};
}

async getTokenBalancesPerPosition({
address,
contractPosition,
}: GetTokenBalancesParams<VendorFinancePool, DefaultDataProps>) {
}: GetTokenBalancesParams<VendorFinancePool, VendorFinancePoolDataProps>) {
const collateralToken = contractPosition.tokens[0]!;
const lentToken = contractPosition.tokens[1]!;

// --- Lender logic ----
// No deposit, no borrow, but lending out
if (address === contractPosition.dataProps.deployer.toLowerCase()) {
return ['0', '0', contractPosition.dataProps.totalDeposited.toString()];
}
// --! Lender logic !---

// --- Borrower logic ----
const data = await this.appToolkit.helpers.theGraphHelper.requestGraph<VendorBorrowerGraphResponse>({
endpoint: VENDOR_GRAPH_URL,
query: borrowerInfosQuery(address),
Expand All @@ -144,6 +170,8 @@ export class ArbitrumVendorFinancePoolContractPositionFetcher extends ContractPo
const suppliedBalanceRaw = suppliedBalance * 10 ** collateralToken.decimals;
const borrowedBalance = parseInt(borrowerPosition.totalBorrowed);

return [suppliedBalanceRaw.toString(), borrowedBalance.toString()];
// Deposit, borrow, no lending out (not pool creator)
return [suppliedBalanceRaw.toString(), borrowedBalance.toString(), '0'];
// --! Borrower logic !---
}
}

0 comments on commit ef42f6e

Please sign in to comment.