Skip to content

Commit

Permalink
Clean offchain delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
bonustrack committed Nov 8, 2022
1 parent 5de602c commit 2637e3c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/strategies/marsecosystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ export async function strategy(
let amount = BigNumber.from(0);
amount = amount.add(result[`${address}-${options.token}`]);
if (options.miningMasters)
for (let miningMaster of options.miningMasters) {
for (const miningMaster of options.miningMasters) {
amount = amount.add(
result[`${address}-${miningMaster.address}-${miningMaster.pid}`][0]
);
}
if (options.upMiningMasters)
for (let upMiningMaster of options.upMiningMasters) {
for (const upMiningMaster of options.upMiningMasters) {
amount = amount.add(
result[`${address}-${upMiningMaster.address}-${upMiningMaster.pid}`]
);
}
for (let lp of options.lps) {
for (const lp of options.lps) {
amount = amount.add(
result[`${address}-${lp.lpToken}`]
.mul(result[`${lp.lpToken}-${options.token}`])
Expand All @@ -118,7 +118,7 @@ export async function strategy(
.div(1000)
);
if (lp.miningMasters)
for (let miningMaster of lp.miningMasters) {
for (const miningMaster of lp.miningMasters) {
amount = amount.add(
result[
`${address}-${lp.lpToken}-${miningMaster.address}-${miningMaster.pid}`
Expand All @@ -130,7 +130,7 @@ export async function strategy(
);
}
if (lp.upMiningMasters)
for (let upMiningMaster of lp.upMiningMasters) {
for (const upMiningMaster of lp.upMiningMasters) {
amount = amount.add(
result[
`${address}-${lp.lpToken}-${upMiningMaster.address}-${upMiningMaster.pid}`
Expand Down
13 changes: 5 additions & 8 deletions src/strategies/offchain-delegation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,23 @@ This strategy is used to handle offchain delegations.
- And use the id after "pub?gid=" as "gid" parameter
- You are ready!


## Parameters
- `sheetId`: The id of the spreadsheet
- `gid`: The id of the sheet
- `strategies`: The strategies to use, to calculate the score of the delegations
- `delegationSpace`: The space to use for the delegations (Optional, default: space of the proposal)

Here is an example of the strategy parameters:

```json
{
"sheetId": "2PACX-1vTAo2yFq6GyBZcB3BOnIw_Rzub7KEEzqhhgFY5CD6eCW-Rfx9d4NaMJP8IP67G9YnV3PNPHKvgJeSNY",
"gid": "1557274211",
"strategies": [
{
"name": "erc20-balance-of",
"params": {
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"decimals": 18
}
"name": "erc20-balance-of",
"params": {
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"decimals": 18
}
}
]
}
Expand Down
3 changes: 1 addition & 2 deletions src/strategies/offchain-delegation/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
"strategy": {
"name": "offchain-delegation",
"params": {
"symbol": "DAI DELEGATEDW",
"symbol": "DAI (delegated)",
"sheetId": "2PACX-1vTAo2yFq6GyBZcB3BOnIw_Rzub7KEEzqhhgFY5CD6eCW-Rfx9d4NaMJP8IP67G9YnV3PNPHKvgJeSNY",
"gid": "1557274211",
"delegationSpace": "test7.shot.eth",
"strategies": [
{
"name": "erc20-balance-of",
Expand Down
8 changes: 1 addition & 7 deletions src/strategies/offchain-delegation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export async function strategy(
const res = await fetch(url);
const text = await res.text();
const csv = csvToJson(text) || [];
const delegationSpace = options.delegationSpace || space;
const delegations = Object.fromEntries(
csv
.map((item) => ({
Expand All @@ -47,12 +46,7 @@ export async function strategy(
delegate: getAddress(item.delegate),
ts: parseInt(item.timestamp || '0')
}))
.filter(
(item) =>
item.ts <= ts &&
item.space === delegationSpace &&
!addresses.includes(item.delegator)
)
.filter((item) => item.ts <= ts && !addresses.includes(item.delegator))
.sort((a, b) => a.ts - b.ts)
.map((item) => [item.delegator, item.delegate])
);
Expand Down

0 comments on commit 2637e3c

Please sign in to comment.