Skip to content

Commit

Permalink
fix: filter out starknet testnet on mainnet (#1071)
Browse files Browse the repository at this point in the history
* fix: filter out starknet testnet on mainnet

* Update package.json

---------

Co-authored-by: Chaitanya <[email protected]>
  • Loading branch information
wa0x6e and ChaituVR authored Oct 10, 2024
1 parent b0eacfa commit 97a229d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snapshot-labs/snapshot.js",
"version": "0.12.23",
"version": "0.12.24",
"repository": "snapshot-labs/snapshot.js",
"license": "MIT",
"main": "dist/snapshot.cjs.js",
Expand Down
21 changes: 19 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ const ENS_ABI = [
'function resolver(bytes32 node) view returns (address)' // ENS registry ABI
];
const EMPTY_ADDRESS = '0x0000000000000000000000000000000000000000';
const STARKNET_NETWORKS = ['0x534e5f4d41494e', '0x534e5f5345504f4c4941'];
const STARKNET_NETWORKS = {
'0x534e5f4d41494e': {
name: 'Starknet',
testnet: false
},
'0x534e5f5345504f4c4941': {
name: 'Starknet Sepolia',
testnet: true
}
};

const scoreApiHeaders = {
Accept: 'application/json',
Expand Down Expand Up @@ -170,7 +179,15 @@ ajv.addKeyword({
ajv.addKeyword({
keyword: 'starknetNetwork',
validate: function (schema, data) {
return STARKNET_NETWORKS.includes(data);
// @ts-ignore
const snapshotEnv = this.snapshotEnv || 'default';
if (snapshotEnv === 'mainnet') {
return Object.keys(STARKNET_NETWORKS)
.filter((id) => !STARKNET_NETWORKS[id].testnet)
.includes(data);
}

return Object.keys(STARKNET_NETWORKS).includes(data);
},
error: {
message: 'network not allowed'
Expand Down
5 changes: 0 additions & 5 deletions test/examples/space.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@
"name": "Mainnet Starknet treasury",
"address": "0x05702362b68a350c1cae8f2a529d74fdbb502369ddcebfadac7e91da37636947",
"network": "0x534e5f4d41494e"
},
{
"name": "Sepolia Starknet treasury",
"address": "0x05702362b68a350c1cae8f2a529d74fdbb502369ddcebfadac7e91da37636947",
"network": "0x534e5f5345504f4c4941"
}
],
"labels": [
Expand Down

0 comments on commit 97a229d

Please sign in to comment.