Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[with-balance] Add alias for strategies and change erc20-with-balance to with-balance #114

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"pretest": "npm run build",
"prepublishOnly": "npm run build",
"prepare": "npm run build",
"postbuild": "copyfiles -u 1 src/**/*.md dist/ && copyfiles -u 1 src/**/*.json dist/",
"postbuild": "copyfiles -u 1 \"src/**/*.md\" dist/ && copyfiles -u 1 \"src/**/*.json\" dist/",
"lint": "eslint . --ext .ts,.json --fix"
},
"dependencies": {
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import strategies from './strategies';
import utils from './utils';
import alias from './strategies/alias.json';

export default {
strategies,
utils
utils,
alias
};
3 changes: 3 additions & 0 deletions src/strategies/alias.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"erc20-with-balance": "with-balance"
}
2 changes: 1 addition & 1 deletion src/strategies/holds-tokens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function strategy(
const tokens = options.tokenAddresses || [];

options.strategies = tokens.map((token) => ({
name: 'erc20-with-balance',
name: 'with-balance',
network: token.network,
params: {
address: token.address,
Expand Down
19 changes: 12 additions & 7 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { readFileSync } from 'fs';
import path from 'path';
import alias from './alias.json';

import * as nounsPower from './nouns-rfp-power';
import * as erc20Votes from './erc20-votes';
import * as antiWhale from './anti-whale';
Expand All @@ -19,7 +21,7 @@ import * as erc20BalanceOf from './erc20-balance-of';
import * as erc20BalanceOfCoeff from './erc20-balance-of-coeff';
import * as erc20BalanceOfFixedTotal from './erc20-balance-of-fixed-total';
import * as erc20BalanceOfCv from './erc20-balance-of-cv';
import * as erc20WithBalance from './erc20-with-balance';
import * as withBalance from './with-balance';
import * as erc20BalanceOfDelegation from './erc20-balance-of-delegation';
import * as erc20BalanceOfQuadraticDelegation from './erc20-balance-of-quadratic-delegation';
import * as erc20BalanceOfWeighted from './erc20-balance-of-weighted';
Expand Down Expand Up @@ -222,7 +224,8 @@ const strategies = {
'erc20-balance-of-fixed-total': erc20BalanceOfFixedTotal,
'erc20-balance-of-cv': erc20BalanceOfCv,
'erc20-balance-of-coeff': erc20BalanceOfCoeff,
'erc20-with-balance': erc20WithBalance,
'erc20-with-balance': { ...withBalance },
'with-balance': withBalance,
'erc20-balance-of-delegation': erc20BalanceOfDelegation,
'erc20-balance-of-quadratic-delegation': erc20BalanceOfQuadraticDelegation,
'erc20-balance-of-weighted': erc20BalanceOfWeighted,
Expand Down Expand Up @@ -401,18 +404,20 @@ const strategies = {
Object.keys(strategies).forEach(function (strategyName) {
let examples = null;
let about = '';
let folderName = strategyName;
if (alias[strategyName]) {
folderName = alias[strategyName];
strategies[strategyName].alias = alias[strategyName];
}
try {
examples = JSON.parse(
readFileSync(path.join(__dirname, strategyName, 'examples.json'), 'utf8')
readFileSync(path.join(__dirname, folderName, 'examples.json'), 'utf8')
);
} catch (error) {
examples = null;
}
try {
about = readFileSync(
path.join(__dirname, strategyName, 'README.md'),
'utf8'
);
about = readFileSync(path.join(__dirname, folderName, 'README.md'), 'utf8');
} catch (error) {
about = '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"name": "Example query",
"strategy": {
"name": "erc20-with-balance",
"name": "with-balance",
"params": {
"address": "0x84cA8bc7997272c7CfB4D0Cd3D55cd942B3c9419",
"symbol": "DIA",
Expand All @@ -25,7 +25,7 @@
{
"name": "Example query with minimum balance",
"strategy": {
"name": "erc20-with-balance",
"name": "with-balance",
"params": {
"address": "0x84cA8bc7997272c7CfB4D0Cd3D55cd942B3c9419",
"symbol": "DIA",
Expand Down
2 changes: 1 addition & 1 deletion test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const moreArg =
?.pop();
const strategy = Object.keys(snapshot.strategies).find((s) => strategyArg == s);
if (!strategy) throw 'Strategy not found';
const example = require(`../src/strategies/${strategy}/examples.json`)[0];
const example = snapshot.strategies[strategy].examples[0];

function callGetScores(example) {
return snapshot.utils.getScoresDirect(
Expand Down