Skip to content

Commit 0188a18

Browse files
committed
feat: validate space strategies
1 parent 1a0903b commit 0188a18

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/writer/settings.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { addOrUpdateSpace, getSpace } from '../helpers/actions';
55
import log from '../helpers/log';
66
import db from '../helpers/mysql';
77
import { getLimit, getSpaceType } from '../helpers/options';
8-
import { clearStampCache, DEFAULT_NETWORK, jsonParse } from '../helpers/utils';
8+
import { clearStampCache, DEFAULT_NETWORK, fetchWithKeepAlive, jsonParse } from '../helpers/utils';
99

1010
const SNAPSHOT_ENV = process.env.NETWORK || 'testnet';
1111
const broviderUrl = process.env.BROVIDER_URL || 'https://rpc.snapshot.org';
12+
const scoreAPIUrl = process.env.SCORE_API_URL || 'https://score.snapshot.org';
1213

1314
export async function validateSpaceSettings(originalSpace: any) {
1415
const spaceType = originalSpace.turbo ? 'turbo' : 'default';
@@ -80,6 +81,26 @@ export async function verify(body): Promise<any> {
8081
return Promise.reject(`max number of strategies is ${strategiesLimit}`);
8182
}
8283

84+
try {
85+
const strategiesList = await fetchWithKeepAlive(`${scoreAPIUrl}/api/strategies`);
86+
87+
msg.payload.strategies
88+
.map(strategy => strategy.name)
89+
.forEach(strategyName => {
90+
const strategy = strategiesList[strategyName];
91+
92+
if (!strategy) {
93+
return Promise.reject(`strategy "${strategyName}" is not a valid strategy`);
94+
}
95+
96+
if (strategy.disabled) {
97+
return Promise.reject(`strategy "${strategyName}" has been deprecated`);
98+
}
99+
});
100+
} catch (e) {
101+
return Promise.reject('failed to validate strategies');
102+
}
103+
83104
const controller = await snapshot.utils.getSpaceController(msg.space, DEFAULT_NETWORK, {
84105
broviderUrl
85106
});

0 commit comments

Comments
 (0)