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

Commit

Permalink
fix: fixed euler finance supply APY, fixed uppercase contract address…
Browse files Browse the repository at this point in the history
…es, fixed labels, etc (#647)

* fix: fixed euler finance supply APY, fixed uppercase contract addresses, fixed labels, etc

* fix: fixed supply and borrow APY + enabled TVL
  • Loading branch information
wpoulin authored Jun 15, 2022
1 parent 46ba164 commit 7fc2291
Show file tree
Hide file tree
Showing 31 changed files with 233 additions and 294 deletions.
2 changes: 0 additions & 2 deletions src/apps/coslend/coslend.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { CoslendAppDefinition, COSLEND_DEFINITION } from './coslend.definition';
import { EvmosCoslendBalanceFetcher } from './evmos/coslend.balance-fetcher';
import { EvmosCoslendBorrowContractPositionFetcher } from './evmos/coslend.borrow.contract-position-fetcher';
import { EvmosCoslendSupplyTokenFetcher } from './evmos/coslend.supply.token-fetcher';
import { EvmosCoslendTvlFetcher } from './evmos/coslend.tvl-fetcher';
import { CoslendBorrowBalanceHelper } from './helper/coslend.borrow.balance-helper';
import { CoslendBorrowContractPositionHelper } from './helper/coslend.borrow.contract-position-helper';
import { CoslendLendingMetaHelper } from './helper/coslend.lending.meta-helper';
Expand All @@ -22,7 +21,6 @@ import { CoslendTvlHelper } from './helper/coslend.tvl-helper';
EvmosCoslendBalanceFetcher,
EvmosCoslendBorrowContractPositionFetcher,
EvmosCoslendSupplyTokenFetcher,
EvmosCoslendTvlFetcher,
// Helpers
CoslendLendingMetaHelper,
CoslendSupplyTokenHelper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const appId = COSLEND_DEFINITION.id;
const groupId = COSLEND_DEFINITION.groups.borrow.id;
const network = Network.EVMOS_MAINNET;

@Register.ContractPositionFetcher({ appId, groupId, network })
@Register.ContractPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } })
export class EvmosCoslendBorrowContractPositionFetcher implements PositionFetcher<ContractPosition> {
constructor(
@Inject(CoslendBorrowContractPositionHelper)
Expand Down
4 changes: 2 additions & 2 deletions src/apps/coslend/evmos/coslend.supply.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const appId = COSLEND_DEFINITION.id;
const groupId = COSLEND_DEFINITION.groups.supply.id;
const network = Network.EVMOS_MAINNET;

@Register.TokenPositionFetcher({ appId, groupId, network })
@Register.TokenPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } })
export class EvmosCoslendSupplyTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(CoslendContractFactory) private readonly coslendContractFactory: CoslendContractFactory,
Expand All @@ -25,7 +25,7 @@ export class EvmosCoslendSupplyTokenFetcher implements PositionFetcher<AppTokenP
network,
appId,
groupId,
comptrollerAddress: '0x2C8b48Dc777C26dc857E1040D8ef3Bdd3B1ef499',
comptrollerAddress: '0x2c8b48dc777c26dc857e1040d8ef3bdd3b1ef499',
getComptrollerContract: ({ address, network }) =>
this.coslendContractFactory.coslendComptroller({ address, network }),
getTokenContract: ({ address, network }) => this.coslendContractFactory.coslendCToken({ address, network }),
Expand Down
25 changes: 0 additions & 25 deletions src/apps/coslend/evmos/coslend.tvl-fetcher.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class CoslendBorrowContractPositionHelper {
const borrowApy = appToken.dataProps.borrowApy;

// Display Props
const label = `Borrowed ${getLabelFromToken(appToken.tokens[0])}`;
const label = `${getLabelFromToken(appToken.tokens[0])}`;
const secondaryLabel = buildDollarDisplayItem(underlyingPrice);
const tertiaryLabel = isNumber(borrowApy) ? `${(borrowApy * 100).toFixed(3)}% APR` : '';
const images = appToken.displayProps.images;
Expand Down
10 changes: 5 additions & 5 deletions src/apps/dfx/ethereum/dfx.curve.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const appId = DFX_DEFINITION.id;
const groupId = DFX_DEFINITION.groups.dfxCurve.id;
const network = Network.ETHEREUM_MAINNET;

@Register.TokenPositionFetcher({ appId, groupId, network })
@Register.TokenPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } })
export class EthereumDfxCurveTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
Expand Down Expand Up @@ -67,10 +67,10 @@ export class EthereumDfxCurveTokenFetcher implements PositionFetcher<AppTokenPos

// Denormalize big integer values
const supply = Number(supplyRaw) / 10 ** decimals;
const totalLiquidity = Number(totalLiquidityRaw) / 1e18;
const liquidity = Number(totalLiquidityRaw) / 1e18;
const reserves = underlyingLiquidityRaw.map(reserveRaw => Number(reserveRaw) / 10 ** 18); // DFX report all token liquidity in 10**18
const pricePerShare = reserves.map(r => r / supply);
const price = totalLiquidity / supply;
const price = liquidity / supply;

// Prepare display props
const [, baseToken, quoteToken] = name.split('-');
Expand All @@ -92,7 +92,7 @@ export class EthereumDfxCurveTokenFetcher implements PositionFetcher<AppTokenPos
pricePerShare,
tokens,
dataProps: {
tvl: totalLiquidity,
liquidity,
},
displayProps: {
label,
Expand All @@ -101,7 +101,7 @@ export class EthereumDfxCurveTokenFetcher implements PositionFetcher<AppTokenPos
statsItems: [
{
label: 'Liquidity',
value: buildDollarDisplayItem(totalLiquidity),
value: buildDollarDisplayItem(liquidity),
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import { Addresses } from '../addresses';
import { DfxContractFactory } from '../contracts';
import { DFX_DEFINITION } from '../dfx.definition';

const appId = DFX_DEFINITION.id;
const groupId = DFX_DEFINITION.groups.staking.id;
const network = Network.ETHEREUM_MAINNET;

type DfxCurveContractPositionDataProps = {
liquidity: number;
};

const appId = DFX_DEFINITION.id;
const groupId = DFX_DEFINITION.groups.staking.id;
const network = Network.ETHEREUM_MAINNET;

@Register.ContractPositionFetcher({ appId, groupId, network })
export class EthereumDfxStakingContractPositionFetcher implements PositionFetcher<ContractPosition> {
constructor(
Expand Down
9 changes: 1 addition & 8 deletions src/apps/ease/ease.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@ import { EaseContractFactory } from './contracts';
import { EaseAppDefinition, EASE_DEFINITION } from './ease.definition';
import { EthereumEaseBalanceFetcher } from './ethereum/ease.balance-fetcher';
import { EthereumEaseRcaTokenFetcher } from './ethereum/ease.rca.token-fetcher';
import { EthereumEaseTvlFetcher } from './ethereum/ease.tvl-fetcher';

@Register.AppModule({
appId: EASE_DEFINITION.id,
providers: [
EaseAppDefinition,
EaseContractFactory,
EthereumEaseBalanceFetcher,
EthereumEaseRcaTokenFetcher,
EthereumEaseTvlFetcher,
],
providers: [EaseAppDefinition, EaseContractFactory, EthereumEaseBalanceFetcher, EthereumEaseRcaTokenFetcher],
})
export class EaseAppModule extends AbstractApp() {}
2 changes: 1 addition & 1 deletion src/apps/ease/ethereum/ease.balance-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class EthereumEaseBalanceFetcher implements BalanceFetcher {
address,
appId: EASE_DEFINITION.id,
groupId: EASE_DEFINITION.groups.rca.id,
network: network,
network,
});
}

Expand Down
14 changes: 8 additions & 6 deletions src/apps/ease/ethereum/ease.rca.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import _ from 'lodash';

import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { AAVE_V2_DEFINITION } from '~apps/aave-v2/aave-v2.definition';
import { COMPOUND_DEFINITION } from '~apps/compound/compound.definition';
import { YEARN_DEFINITION } from '~apps/yearn/yearn.definition';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { AppTokenPosition } from '~position/position.interface';
Expand All @@ -24,7 +26,7 @@ export type EaseRcaVaultDetails = {
token: [];
};

@Register.TokenPositionFetcher({ appId, groupId, network })
@Register.TokenPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } })
export class EthereumEaseRcaTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
Expand All @@ -36,16 +38,16 @@ export class EthereumEaseRcaTokenFetcher implements PositionFetcher<AppTokenPosi
const ethData = await Axios.get<EaseRcaVaultDetails[]>(endpoint).then(v => v.data);
const rcaAddressToDetails = _.keyBy(ethData, v => v.address.toLowerCase());
return this.appToolkit.helpers.vaultTokenHelper.getTokens<EaseRcaShield>({
appId: EASE_DEFINITION.id,
groupId: EASE_DEFINITION.groups.rca.id,
network: Network.ETHEREUM_MAINNET,
appId,
groupId,
network,
dependencies: [
{ appId: YEARN_DEFINITION.id, groupIds: [YEARN_DEFINITION.groups.vault.id], network },
{ appId: AAVE_V2_DEFINITION.id, groupIds: [AAVE_V2_DEFINITION.groups.supply.id], network },
{ appId: COMPOUND_DEFINITION.id, groupIds: [COMPOUND_DEFINITION.groups.supply.id], network },
//TODO: migrate
{ appId: 'sushiswap', groupIds: ['pool'], network },
{ appId: 'convex', groupIds: ['deposit'], network },
{ appId: 'aave-v2', groupIds: ['supply'], network },
{ appId: 'compound', groupIds: ['supply'], network },
],
resolveContract: ({ address, network }) => this.easeContractFactory.easeRcaShield({ address, network }),
resolveVaultAddresses: async () => ethData.map(({ address }) => address.toLowerCase()),
Expand Down
26 changes: 0 additions & 26 deletions src/apps/ease/ethereum/ease.tvl-fetcher.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const appId = ENZYME_FINANCE_DEFINITION.id;
const groupId = ENZYME_FINANCE_DEFINITION.groups.vault.id;
const network = Network.ETHEREUM_MAINNET;

@Register.TokenPositionFetcher({ appId, groupId, network })
@Register.TokenPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } })
export class EthereumEnzymeFinanceVaultTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(EnzymeFinanceContractFactory) private readonly enzymeFinanceContractFactory: EnzymeFinanceContractFactory,
Expand Down
6 changes: 3 additions & 3 deletions src/apps/euler/ethereum/euler.balance-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class EthereumEulerBalanceFetcher implements BalanceFetcher {
address,
appId: EULER_DEFINITION.id,
groupId: EULER_DEFINITION.groups.eToken.id,
network: network,
network,
});
}

Expand All @@ -28,7 +28,7 @@ export class EthereumEulerBalanceFetcher implements BalanceFetcher {
address,
appId: EULER_DEFINITION.id,
groupId: EULER_DEFINITION.groups.dToken.id,
network: network,
network,
});
}

Expand All @@ -37,7 +37,7 @@ export class EthereumEulerBalanceFetcher implements BalanceFetcher {
address,
appId: EULER_DEFINITION.id,
groupId: EULER_DEFINITION.groups.pToken.id,
network: network,
network,
});
}

Expand Down
97 changes: 60 additions & 37 deletions src/apps/euler/ethereum/euler.d-token.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ interface EulerMarketsResponse {
};
}

@Register.TokenPositionFetcher({ appId, groupId, network })
type EulerTokenDataProps = {
liquidity: number;
interestRate: number;
borrowAPY: number;
supplyAPY: number;
};

@Register.TokenPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } })
export class EthereumEulerDTokenTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
Expand All @@ -67,6 +74,7 @@ export class EthereumEulerDTokenTokenFetcher implements PositionFetcher<AppToken
async getPositions() {
const endpoint = 'https://api.thegraph.com/subgraphs/name/euler-xyz/euler-mainnet';
const data = await this.appToolkit.helpers.theGraphHelper.request<EulerMarketsResponse>({ endpoint, query });
const multicall = this.appToolkit.getMulticall(network);
const baseTokens = await this.appToolkit.getBaseTokenPrices(network);

const tokens = await Promise.all(
Expand All @@ -78,53 +86,68 @@ export class EthereumEulerDTokenTokenFetcher implements PositionFetcher<AppToken
network,
});

const totalSupply = await dTokenContract.totalSupply();
const [totalSupplyRaw, decimals] = await Promise.all([
multicall.wrap(dTokenContract).totalSupply(),
multicall.wrap(dTokenContract).decimals(),
]);
const underlyingToken = baseTokens.find(token => token?.address === market.id.toLowerCase());
if (totalSupplyRaw.isZero() || !underlyingToken) return null;

if (totalSupply.isZero() || !underlyingToken) return null;
const supply = Number(totalSupplyRaw) / 10 ** decimals;
const symbol = `D${market.symbol}`;
const price = underlyingToken.price;
const pricePerShare = 1;
const liquidity = supply * underlyingToken.price * -1;
const interestRate = Number(market.interestRate) / 10 ** decimals;
const borrowAPY = Number(market.borrowAPY) / 10 ** 25;
const supplyAPY = Number(market.supplyAPY) / 10 ** 25;

const dataProps = {
name: `Euler D token ${market.name}`,
liquidity: Number(totalSupply) * underlyingToken.price,
interestRate: Number(market.interestRate) / 10 ** 18,
borrowAPY: Number(market.borrowAPY) / 10 ** 18,
supplyAPY: Number(market.borrowAPY) / 10 ** 18,
liquidity,
interestRate,
borrowAPY,
supplyAPY,
};

const statsItems = [
{
label: 'Liquidity',
value: buildDollarDisplayItem(liquidity),
},
{
label: 'Borrow APY',
value: buildDollarDisplayItem(borrowAPY),
},
{
label: 'Supply APY',
value: buildDollarDisplayItem(supplyAPY),
},
];

const displayProps = {
label: `Euler D token ${market.name}`,
secondaryLabel: buildDollarDisplayItem(price),
images: getImagesFromToken(underlyingToken),
statsItems,
};

return {
const token: AppTokenPosition<EulerTokenDataProps> = {
type: ContractType.APP_TOKEN,
address: market.dTokenAddress,
symbol: `D${market.symbol}`,
name: `Euler D token ${market.name}`,
type: ContractType.APP_TOKEN as const,
supply: Number(market.totalSupply) / 10 ** Number(market.decimals),
pricePerShare: 1,
price: underlyingToken.price,
appId,
groupId,
network,
decimals: 18,
symbol,
decimals,
supply,
price,
pricePerShare,
tokens: [underlyingToken],
dataProps,
displayProps: {
label: `Euler D token ${market.name}`,
secondaryLabel: buildDollarDisplayItem(underlyingToken.price),
images: getImagesFromToken(underlyingToken),
statsItems: [
{
label: 'Liquidity',
value: buildDollarDisplayItem(dataProps.liquidity),
},
{
label: 'Borrow APY',
value: buildDollarDisplayItem(dataProps.borrowAPY),
},
{
label: 'Supply APY',
value: buildDollarDisplayItem(dataProps.supplyAPY),
},
],
},
appId,
groupId,
displayProps,
};

return token;
}),
);

Expand Down
Loading

0 comments on commit 7fc2291

Please sign in to comment.