Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pool prices #77

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.tabSize": 2,
"editor.detectIndentation": false,
"typescript.tsdk": "packages/chain-stats-subql/node_modules/typescript/lib"
}
4 changes: 4 additions & 0 deletions packages/dex-subql/src/types/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ export {RemoveLiquidity} from "./RemoveLiquidity"

export {Swap} from "./Swap"

export {StableAssetSwap} from "./StableAssetSwap"

export {StableAssetPoolHourlyData} from "./StableAssetPoolHourlyData"

20 changes: 10 additions & 10 deletions packages/dex-subql/src/utils/queryPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getOtherPrice = async (api: AnyApi, block: SubstrateBlock, token: string,
const amountB = FN.fromInner(_amountB.toString(), 18);
const StakingPrice = stakingCurrency === 'DOT' ? await getDotMarketPrice(api, block) : await getKsmMarketPrice(api, block);
const StablePrice = stakingCurrency === 'DOT' ? await getAusdMarketPrice(api, block) : await getKusdMarketPrice(api, block);

const partA = rateA.mul(StakingPrice).times(amountA).div(amountA.add(amountB));
const partB = rateB.mul(StablePrice).times(amountB).div(amountA.add(amountB));

Expand All @@ -32,9 +32,9 @@ const getPriceFromDexPool = async (tokenA: string, tokenB: string) => {
rate: FN.ZERO,
amount: BigInt(1)
};
}
}



const amount0 = FN.fromInner(pool.token0Amount.toString() || "0", token0.decimals);
const amount1 = FN.fromInner(pool.token1Amount.toString() || "0", token1.decimals);

Expand All @@ -51,15 +51,15 @@ const getPriceFromDexPool = async (tokenA: string, tokenB: string) => {

const getKusdMarketPrice = async (api: AnyApi, block: SubstrateBlock) => {
const stakingCurrencyMarketPrice = await getKsmMarketPrice(api, block)

const stakingCurrency = api.consts.prices.getStakingCurrencyId;

const stableCurrency = api.consts.prices.getStableCurrencyId;
const stakingCurrencyName = getTokenName(stakingCurrency as any);
const stableCurrencyName = getTokenName(stableCurrency as any);

const pool = await getPool(stableCurrencyName, stakingCurrencyName)

const token0 = await getToken(pool.token0Id);
const token1 = await getToken(pool.token1Id);

Expand All @@ -71,13 +71,13 @@ const getKusdMarketPrice = async (api: AnyApi, block: SubstrateBlock) => {

const getAusdMarketPrice = async (api: AnyApi, block: SubstrateBlock) => {
const acaPrice = await queryPriceFromOracle(api, block, 'ACA')

const pool = await getPool('ACA', 'AUSD')

const token0 = await getToken(pool.token0Id); // ACA
const token1 = await getToken(pool.token1Id); // AUSD


const amount0 = FN.fromInner(pool.token0Amount.toString() || "0", token0.decimals); // ACA
const amount1 = FN.fromInner(pool.token1Amount.toString() || "0", token1.decimals); // AUSD

Expand Down Expand Up @@ -119,7 +119,7 @@ export const circulatePrice = async (api: AnyApi, block: SubstrateBlock, name: M
else if (_name === "AUSD") return getStablePriceBundle(api, block, 'AUSD');

else if (_name === 'KSM') return getKsmMarketPrice(api, block);

else if (_name === 'DOT') return getDotMarketPrice(api, block);

else if (_name === "TAI") return getTaiMarketPrice(api, block);
Expand Down Expand Up @@ -164,5 +164,5 @@ export const getStablePriceBundle = async (api: AnyApi, block: SubstrateBlock, t
await record.save();
}

return FN.fromInner(record.price?.toString() || "0", 12)
return FN.fromInner(record.price?.toString() || "0", 12)
}
Loading