Skip to content

Commit

Permalink
user pool share added
Browse files Browse the repository at this point in the history
  • Loading branch information
SdCrypt0 committed May 6, 2024
1 parent 3aa0dcf commit 5bacf12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
1 change: 0 additions & 1 deletion adapters/metavault/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export const getUserTVLByBlock = async ({ blockNumber, blockTimestamp }: BlockDa
getV3UserPositionsAtBlock(blockNumber),
getTradeLiquidityForAddressByPoolAtBlock(blockNumber)
])
console.log(tradeLiquidities);

// combine v2 & v3
const combinedPositions = [...v2Positions, ...v3Positions]
Expand Down
26 changes: 12 additions & 14 deletions adapters/metavault/src/sdk/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,18 @@ export const getTradeLiquidityForAddressByPoolAtBlock = async (blockNumber: numb
let skip = 0;
let fetchNext = true;
let result: any[] = [];
let _stores: any[] = [];
while (fetchNext) {
let query = `{
liquidities(where: {period: "user" amount_gt: 1} ${blockQuery} orderBy: createTimestamp, first:1000,skip:${skip}) {
liquidities(where: {period: "user" lpBalance_gt: 1 } ${blockQuery} orderBy: createTimestamp, first:1000,skip:${skip}) {
user
asset
amountUsd
amount
lpBalance
},
_meta{
block{
number
}
stores(${blockQuery}){
asset:id
lpSupply
poolBalance
}
}`;

Expand All @@ -130,8 +130,8 @@ export const getTradeLiquidityForAddressByPoolAtBlock = async (blockNumber: numb
body: JSON.stringify({ query }),
headers: { "Content-Type": "application/json" },
});
const { data: { liquidities } } = await response.json();

const { data: { liquidities, stores } } = await response.json();
_stores = stores
result = result.concat(liquidities)

if (liquidities.length < 1000) {
Expand All @@ -141,14 +141,12 @@ export const getTradeLiquidityForAddressByPoolAtBlock = async (blockNumber: numb
}
}
return result.map(r => {
let decimals = 18
if (r.asset === "0x176211869ca2b568f2a7d4ee941e073a821ee1ff") {
decimals = 6 // usdt
}
let store = _stores.find(s => s.asset === r.asset);
return {
user: r.user,
asset: r.asset,
amount: BigInt(BigNumber(r.amount).times(new BigNumber(10).pow(decimals)).toString()),
// user pool share is equal to user pool balance divided by the total balance.
amount: BigInt(r.lpBalance) * BigInt(store.poolBalance) / BigInt(store.lpSupply),
}
});
}
Expand Down

0 comments on commit 5bacf12

Please sign in to comment.