Skip to content

Commit

Permalink
[infinityprotocol-liquidity-pools] changes in infinityprotocol-liquid…
Browse files Browse the repository at this point in the history
…ity-pools strategy (snapshot-labs#50)

* changes in infinityprotocol-liquidity-pools strategy

* Update README.md

* Update examples.json

* Update examples.json

Forgot to add a comma after token symbol. Should work now.

Co-authored-by: Vatsal Gupta <[email protected]>
  • Loading branch information
vatsalgupta13 and Vatsal Gupta authored Aug 31, 2021
1 parent 85f27b1 commit 8b7b59a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
26 changes: 26 additions & 0 deletions src/strategies/infinityprotocol-liquidity-pools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Liquidity Providers

This strategy will return the scores of all users who have provided token liquidity on any Uniswap style exchange. Users can change the subGraphURL field to direct their request to a different subgraph.


## Example

The space config will look like this:

```JSON
{
"strategies": [
["infinityprotocol-liquidity-pools", {
// token parameters
"params": {
"address": "0xc168e40227e4ebd8c1cae80f7a55a4f0e6d66c97",
"symbol": "DFYN"
// subgraphURL for the request
"subGraphURL": "https://api.thegraph.com/subgraphs/name/ss-sonic/dfyn-v5",
// scoreMultiplier can be used to increase users' scores by a certain magnitude
"scoreMultiplier": 1,
},
}],
]
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"name": "infinityprotocol-liquidity-pools",
"params": {
"address": "0xd8a1734945b9ba38eb19a291b475e31f49e59877",
"symbol": "SHARD"
"symbol": "SHARD",
"scoreMultiplier": 1
}
},
"network": "56",
Expand Down
11 changes: 6 additions & 5 deletions src/strategies/infinityprotocol-liquidity-pools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ export async function strategy(
}
const tokenAddress = options.address.toLowerCase();
const result = await subgraphRequest(
INFINITYPROTOCOL_SUBGRAPH_URL[network],
params
);
options.subGraphURL ? options.subGraphURL : INFINITYPROTOCOL_SUBGRAPH_URL[network],
params);
const score = {};
if (result && result.users) {
result.users.forEach((u) => {
Expand All @@ -69,11 +68,13 @@ export async function strategy(
.forEach((lp) => {
const token0perShard = lp.pair.reserve0 / lp.pair.totalSupply;
const token1perShard = lp.pair.reserve1 / lp.pair.totalSupply;
const userScore =
let userScore =
lp.pair.token0.id == tokenAddress
? token0perShard * lp.liquidityTokenBalance
: token1perShard * lp.liquidityTokenBalance;

if (options.scoreMultiplier) {
userScore = userScore * options.scoreMultiplier
}
const userAddress = getAddress(u.id);
if (!score[userAddress]) score[userAddress] = 0;
score[userAddress] = score[userAddress] + userScore;
Expand Down

0 comments on commit 8b7b59a

Please sign in to comment.