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

Commit

Permalink
Properly calculate pricePerShare and remove testing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kafitz committed May 3, 2022
1 parent da81c45 commit e2764f5
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 34 deletions.
32 changes: 19 additions & 13 deletions src/apps/dfx/ethereum/dfx.amm.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Test address: http://localhost:5001/apps/dfx/tokens?groupIds[]=dfx-curve&network=ethereum
//
import { Inject } from '@nestjs/common';
import _ from 'lodash';

Expand Down Expand Up @@ -39,16 +37,23 @@ export class EthereumDfxCurveTokenFetcher implements PositionFetcher<AppTokenPos
curveAddresses.map(async curveAddress => {
// Fetch data from DFX curve contract
const contract = this.dfxContractFactory.dfxCurve({ address: curveAddress, network });
const [name, symbol, decimals, supplyRaw, token0AddressRaw, token1AddressRaw, [totalLiquidityRaw]] =
await Promise.all([
multicall.wrap(contract).name(),
multicall.wrap(contract).symbol(),
multicall.wrap(contract).decimals(),
multicall.wrap(contract).totalSupply(),
multicall.wrap(contract).numeraires(0),
multicall.wrap(contract).numeraires(1),
multicall.wrap(contract).liquidity(),
]);
const [
name,
symbol,
decimals,
supplyRaw,
token0AddressRaw,
token1AddressRaw,
[totalLiquidityRaw, underlyingLiquidityRaw],
] = await Promise.all([
multicall.wrap(contract).name(),
multicall.wrap(contract).symbol(),
multicall.wrap(contract).decimals(),
multicall.wrap(contract).totalSupply(),
multicall.wrap(contract).numeraires(0),
multicall.wrap(contract).numeraires(1),
multicall.wrap(contract).liquidity(),
]);
const underlyingTokenAddresses = [token0AddressRaw.toLowerCase(), token1AddressRaw.toLowerCase()];

// Find underlying tokens from base dependencies
Expand All @@ -63,7 +68,8 @@ export class EthereumDfxCurveTokenFetcher implements PositionFetcher<AppTokenPos
// Denormalize big integer values
const supply = Number(supplyRaw) / 10 ** decimals;
const totalLiquidity = Number(totalLiquidityRaw) / 1e18;
const pricePerShare = 1;
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;

// Prepare display props
Expand Down
2 changes: 0 additions & 2 deletions src/apps/dfx/ethereum/dfx.balance-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Test address: http://localhost:5001/apps/dfx/balances?addresses[]=0x1867608e55a862e96e468b51dc6983bca8688f3d&network=ethereum
//
import { Inject } from '@nestjs/common';

import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Test address: http://localhost:5001/apps/dfx/positions?groupIds[]=staking&network=ethereum
//
import { Inject } from '@nestjs/common';
import _ from 'lodash';

Expand Down
32 changes: 19 additions & 13 deletions src/apps/dfx/polygon/dfx.amm.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Test address: http://localhost:5001/apps/dfx/tokens?groupIds[]=dfx-curve&network=polygon
//
import { Inject } from '@nestjs/common';
import _ from 'lodash';

Expand Down Expand Up @@ -39,16 +37,23 @@ export class PolygonDfxCurveTokenFetcher implements PositionFetcher<AppTokenPosi
curveAddresses.map(async curveAddress => {
// Fetch data from DFX curve contract
const contract = this.dfxContractFactory.dfxCurve({ address: curveAddress, network });
const [name, symbol, decimals, supplyRaw, token0AddressRaw, token1AddressRaw, [totalLiquidityRaw]] =
await Promise.all([
multicall.wrap(contract).name(),
multicall.wrap(contract).symbol(),
multicall.wrap(contract).decimals(),
multicall.wrap(contract).totalSupply(),
multicall.wrap(contract).numeraires(0),
multicall.wrap(contract).numeraires(1),
multicall.wrap(contract).liquidity(),
]);
const [
name,
symbol,
decimals,
supplyRaw,
token0AddressRaw,
token1AddressRaw,
[totalLiquidityRaw, underlyingLiquidityRaw],
] = await Promise.all([
multicall.wrap(contract).name(),
multicall.wrap(contract).symbol(),
multicall.wrap(contract).decimals(),
multicall.wrap(contract).totalSupply(),
multicall.wrap(contract).numeraires(0),
multicall.wrap(contract).numeraires(1),
multicall.wrap(contract).liquidity(),
]);
const underlyingTokenAddresses = [token0AddressRaw.toLowerCase(), token1AddressRaw.toLowerCase()];

// Find underlying tokens from base dependencies
Expand All @@ -63,7 +68,8 @@ export class PolygonDfxCurveTokenFetcher implements PositionFetcher<AppTokenPosi
// Denormalize big integer values
const supply = Number(supplyRaw) / 10 ** decimals;
const totalLiquidity = Number(totalLiquidityRaw) / 1e18;
const pricePerShare = 1;
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;

// Prepare display props
Expand Down
2 changes: 0 additions & 2 deletions src/apps/dfx/polygon/dfx.balance-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Test address: http://localhost:5001/apps/dfx/balances?addresses[]=0x903103Ef92b5C227D6f3E6eab4311b6d7460F134&network=polygon
//
import { Inject } from '@nestjs/common';

import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
Expand Down
2 changes: 0 additions & 2 deletions src/apps/dfx/polygon/dfx.staking.contract-position-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Test address: http://localhost:5001/apps/dfx/positions?groupIds[]=staking&network=polygon
//
import { Inject } from '@nestjs/common';
import _ from 'lodash';

Expand Down

0 comments on commit e2764f5

Please sign in to comment.