From e4d0c9a9d057704dddb2e109540131c22c04e60f Mon Sep 17 00:00:00 2001 From: Aiden <30964272+0xaaiden@users.noreply.github.com> Date: Thu, 23 Jan 2025 10:31:56 -0500 Subject: [PATCH] [spooky-lp-sonic] Added spooky-lp-sonic strategy and updated index.ts (#1677) * Added spooky-lp-sonic strategy and updated index.ts * removed pagination for request limit * Update src/strategies/spooky-lp-sonic/index.ts Co-authored-by: Chaitanya * Refactor error handling in `src/strategies/spooky-lp-sonic/index.ts` * Remove try-catch block around subgraphRequest * Update src/strategies/index.ts --------- Co-authored-by: Bouneb Rayan Co-authored-by: Chaitanya --- src/strategies/index.ts | 2 + src/strategies/spooky-lp-sonic/README.md | 13 +++ src/strategies/spooky-lp-sonic/examples.json | 17 ++++ src/strategies/spooky-lp-sonic/index.ts | 88 ++++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 src/strategies/spooky-lp-sonic/README.md create mode 100644 src/strategies/spooky-lp-sonic/examples.json create mode 100644 src/strategies/spooky-lp-sonic/index.ts diff --git a/src/strategies/index.ts b/src/strategies/index.ts index 09a50e0bb..12ba9d0c1 100644 --- a/src/strategies/index.ts +++ b/src/strategies/index.ts @@ -471,9 +471,11 @@ import * as morphoDelegation from './morpho-delegation'; import * as lizcoinStrategy2024 from './lizcoin-strategy-2024'; import * as realt from './realt'; import * as superfluidVesting from './superfluid-vesting'; +import * as spookyLpSonic from './spooky-lp-sonic'; import * as synapse from './synapse'; const strategies = { + 'spooky-lp-sonic': spookyLpSonic, 'delegatexyz-erc721-balance-of': delegatexyzErc721BalanceOf, 'giveth-balances-supply-weighted': givethBalancesSupplyWeighted, 'giveth-gnosis-balance-supply-weighted-v3': diff --git a/src/strategies/spooky-lp-sonic/README.md b/src/strategies/spooky-lp-sonic/README.md new file mode 100644 index 000000000..4571feba1 --- /dev/null +++ b/src/strategies/spooky-lp-sonic/README.md @@ -0,0 +1,13 @@ +# LP Liquidity Position for $BOO Pools [Sonic] +This strategy calculates the liquidity position of users in pools where $BOO is one of the tokens. It utilizes data from a subgraph to compute the net liquidity by analyzing mint and burn events. + +## Overview +The strategy queries the following pools: + +Pool 1: 0x686d873a9e0696afaca0bc163dcc95b577d9e3e8 wS/BOO +Pool 2: 0xf4dcfaa2711908a8c61d9516d84b24ffdae241db WETH/BOO +Pool 3: 0xb7228a39cdd2c734064fc95c54e75910ff06eed6 USDC.E/BOO +Pool 4: 0x84d4716c1cf4d7b1b1c247ad69b62fa72ccc46d7 wS/BOO +Pool 5: 0xaa4ee51f55f9baa7cf180fbaf2688cc35fdc8012 BOO/TONS + +The strategy uses a subgraph to fetch mint and burn events, calculates the net liquidity position, and assigns scores to the provided addresses based on their activity. \ No newline at end of file diff --git a/src/strategies/spooky-lp-sonic/examples.json b/src/strategies/spooky-lp-sonic/examples.json new file mode 100644 index 000000000..c93e88c72 --- /dev/null +++ b/src/strategies/spooky-lp-sonic/examples.json @@ -0,0 +1,17 @@ +[ + { + "name": "Example query", + "strategy": { + "name": "spooky-lp-sonic" + }, + "network": "1", + "addresses": [ + "0xf83e546bd2959c22f1715ecaffc03d39b8d0fa96", + "0x02fa5640f5D948f14C9195fB2873D832A49f0A5f", + "0xFE2fb8587760c8d5960CB7A5BA2f2299EdF10506", + "0x593B0c00078A741eB440c7B9Dde999bdD40Aa1F9", + "0x159b567635aea41170aafaf1f832185344c56fba" + ], + "snapshot": 11437846 + } +] diff --git a/src/strategies/spooky-lp-sonic/index.ts b/src/strategies/spooky-lp-sonic/index.ts new file mode 100644 index 000000000..ea9477e6f --- /dev/null +++ b/src/strategies/spooky-lp-sonic/index.ts @@ -0,0 +1,88 @@ +import { subgraphRequest } from '../../utils'; +import { getAddress } from '@ethersproject/address'; + +const MY_SUBGRAPH_URL = { + '1': 'https://api.0xgraph.xyz/api/public/28820bd2-ad8b-4d40-a142-ce8d7c786f66/subgraphs/spookyswap/v3/v0.0.1/gn' +}; + +export const author = '0xaaiden'; +export const version = '0.1.0'; + +export async function strategy( + space, + network, + provider, + addresses, + options, + snapshot +) { + const poolIds = [ + "0x686d873a9e0696afaca0bc163dcc95b577d9e3e8", + "0xf4dcfaa2711908a8c61d9516d84b24ffdae241db", + "0xb7228a39cdd2c734064fc95c54e75910ff06eed6", + "0x84d4716c1cf4d7b1b1c247ad69b62fa72ccc46d7", + "0xaa4ee51f55f9baa7cf180fbaf2688cc35fdc8012", + ]; + + const subgraphURL = MY_SUBGRAPH_URL[network]; + const score = {}; + addresses.forEach((address) => { + score[getAddress(address)] = 0; + }); + + for (const poolId of poolIds) { + const params = { + mints: { + __args: { + where: { + pool_: { id: poolId }, + origin_in: addresses.map((address) => address.toLowerCase()) + } + }, + origin: true, + timestamp: true, + amount: true, + pool: { id: true } + }, + burns: { + __args: { + where: { + pool_: { id: poolId }, + origin_in: addresses.map((address) => address.toLowerCase()) + } + }, + origin: true, + timestamp: true, + amount: true, + pool: { id: true } + } + }; + + if (snapshot !== 'latest') { + // @ts-ignore + params.mints.__args.where.transaction_ = { blockNumber_lte: snapshot }; + // @ts-ignore + params.burns.__args.where.transaction_ = { blockNumber_lte: snapshot }; + } + + const result = await subgraphRequest(subgraphURL, params); + if (result && (result.mints || result.burns)) { + const mints = result.mints; + const burns = result.burns; + + mints.forEach((mint) => { + const userAddress = getAddress(mint.origin); + const amount = parseFloat(mint.amount); + score[userAddress] += amount; + }); + + burns.forEach((burn) => { + const userAddress = getAddress(burn.origin); + const amount = parseFloat(burn.amount); + score[userAddress] -= amount; + }); + } + } + + return score || {}; +}