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

Gamma Strategies: address double counting issue #292

Merged
merged 4 commits into from
Aug 20, 2024
Merged
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
15 changes: 11 additions & 4 deletions adapters/gammastrategies/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const getAccountData = async (
limitUpper,
},
shares,
sharesStaked,
}
}
}`;
Expand All @@ -77,16 +78,22 @@ const getAccountData = async (
continue;
}

// Staked lynex positions are already accounted for by lynex adapter, exclude them here
const shares = hypeShare.shares - hypeShare.sharesStaked
if (shares <= 0) {
continue;
}

accountHoldings[account.id] ??= {};

const shareOfPool = hypeShare.shares / hypeShare.hypervisor.totalSupply;
const shareOfPool = shares / hypeShare.hypervisor.totalSupply;
const tvl0Share = Math.round(shareOfPool * hypeShare.hypervisor.tvl0);
const tvl1Share = Math.round(shareOfPool * hypeShare.hypervisor.tvl1);

const token0Address: string = hypeShare.hypervisor.pool.token0.id;
const token1Address: string = hypeShare.hypervisor.pool.token1.id;

if (token0Address in accountHoldings) {
if (token0Address in accountHoldings[account.id]) {
accountHoldings[account.id][token0Address].balance += tvl0Share;
} else {
accountHoldings[account.id][token0Address] = {
Expand All @@ -95,7 +102,7 @@ const getAccountData = async (
};
}

if (token1Address in accountHoldings) {
if (token1Address in accountHoldings[account.id]) {
accountHoldings[account.id][token1Address].balance += tvl1Share;
} else {
accountHoldings[account.id][token1Address] = {
Expand Down Expand Up @@ -159,11 +166,11 @@ export const getUserTVLByBlock = async (blocks: BlockData) => {
const { blockNumber, blockTimestamp } = blocks;
// Retrieve data using block number and timestamp

// Exclude Nile as all positions already reflected in nile adapter
const protocolData: AccountBalances[] = await Promise.all([
getAccountData(PROTOCOLS.UNISWAP),
getAccountData(PROTOCOLS.LYNEX),
getAccountData(PROTOCOLS.LINEHUB),
getAccountData(PROTOCOLS.NILE),
]);

const allProtocolHoldings: AccountBalances = {};
Expand Down
Loading