-
Notifications
You must be signed in to change notification settings - Fork 809
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 <[email protected]> * 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 <[email protected]> Co-authored-by: Chaitanya <[email protected]>
- Loading branch information
1 parent
a83f7d7
commit e4d0c9a
Showing
4 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[ | ||
{ | ||
"name": "Example query", | ||
"strategy": { | ||
"name": "spooky-lp-sonic" | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0xf83e546bd2959c22f1715ecaffc03d39b8d0fa96", | ||
"0x02fa5640f5D948f14C9195fB2873D832A49f0A5f", | ||
"0xFE2fb8587760c8d5960CB7A5BA2f2299EdF10506", | ||
"0x593B0c00078A741eB440c7B9Dde999bdD40Aa1F9", | ||
"0x159b567635aea41170aafaf1f832185344c56fba" | ||
], | ||
"snapshot": 11437846 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 || {}; | ||
} |