Skip to content

Commit

Permalink
Merge pull request #292 from l0c4t0r/gamma
Browse files Browse the repository at this point in the history
Gamma Strategies: address double counting issue
  • Loading branch information
0xroll authored Aug 20, 2024
2 parents c602991 + df0dd8b commit fdf3911
Showing 1 changed file with 11 additions and 4 deletions.
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

0 comments on commit fdf3911

Please sign in to comment.