Skip to content

Commit

Permalink
[spooky-lp-sonic] Added spooky-lp-sonic strategy and updated index.ts (
Browse files Browse the repository at this point in the history
…#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
3 people authored Jan 23, 2025
1 parent a83f7d7 commit e4d0c9a
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 474 in src/strategies/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Delete `·`
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':
Expand Down
13 changes: 13 additions & 0 deletions src/strategies/spooky-lp-sonic/README.md
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.
17 changes: 17 additions & 0 deletions src/strategies/spooky-lp-sonic/examples.json
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
}
]
88 changes: 88 additions & 0 deletions src/strategies/spooky-lp-sonic/index.ts
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",

Check failure on line 20 in src/strategies/spooky-lp-sonic/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `"0x686d873a9e0696afaca0bc163dcc95b577d9e3e8"` with `'0x686d873a9e0696afaca0bc163dcc95b577d9e3e8'`
"0xf4dcfaa2711908a8c61d9516d84b24ffdae241db",

Check failure on line 21 in src/strategies/spooky-lp-sonic/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `"0xf4dcfaa2711908a8c61d9516d84b24ffdae241db"` with `'0xf4dcfaa2711908a8c61d9516d84b24ffdae241db'`
"0xb7228a39cdd2c734064fc95c54e75910ff06eed6",

Check failure on line 22 in src/strategies/spooky-lp-sonic/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `"0xb7228a39cdd2c734064fc95c54e75910ff06eed6"` with `'0xb7228a39cdd2c734064fc95c54e75910ff06eed6'`
"0x84d4716c1cf4d7b1b1c247ad69b62fa72ccc46d7",

Check failure on line 23 in src/strategies/spooky-lp-sonic/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `"0x84d4716c1cf4d7b1b1c247ad69b62fa72ccc46d7"` with `'0x84d4716c1cf4d7b1b1c247ad69b62fa72ccc46d7'`
"0xaa4ee51f55f9baa7cf180fbaf2688cc35fdc8012",

Check failure on line 24 in src/strategies/spooky-lp-sonic/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `"0xaa4ee51f55f9baa7cf180fbaf2688cc35fdc8012",` with `'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 || {};
}

0 comments on commit e4d0c9a

Please sign in to comment.