Skip to content

Commit 06a1559

Browse files
authored
No proxy in collectives dao (#1265)
* No proxy in collectives Dao space * Remove debug data * feat: allow unused fields in proposal creation config * Simplify
1 parent 45aec30 commit 06a1559

9 files changed

Lines changed: 52 additions & 53 deletions

File tree

backend/packages/backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"lodash.flatten": "^4.4.0",
3131
"lodash.isempty": "^4.4.0",
3232
"lodash.isequal": "^4.5.0",
33+
"lodash.ismatch": "^4.4.0",
3334
"lodash.isnil": "^4.0.0",
3435
"lodash.omit": "^4.5.0",
3536
"lodash.uniq": "^4.5.0",

backend/packages/backend/src/features/proposals/createProposal.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ const proposalService = require("../../services/proposal.service");
33
const { ChoiceType } = require("../../constants");
44
const isEmpty = require("lodash.isempty");
55
const { spaces: spaceServices } = require("../../spaces");
6-
const { Accessibility } = require("../../consts/space");
6+
const { Accessibility, SpaceType } = require("../../consts/space");
77
const { checkProposalContent } = require("./checkProposalContent");
8-
const isEqual = require("lodash.isequal");
8+
const isMatch = require("lodash.ismatch");
99
const pick = require("lodash/pick");
1010
const { getLatestHeight } = require("../../services/chain.service");
1111
const { strategies } = require("../../consts/voting");
@@ -85,9 +85,10 @@ async function checkSnapshotHeights(data) {
8585
const { networksConfig, snapshotHeights } = data;
8686

8787
if (
88-
networksConfig.accessibility === Accessibility.WHITELIST &&
89-
networksConfig.strategies?.length === 1 &&
90-
networksConfig.strategies[0] === strategies.onePersonOneVote
88+
networksConfig.type === SpaceType.CollectivesDao ||
89+
(networksConfig.accessibility === Accessibility.WHITELIST &&
90+
networksConfig.strategies?.length === 1 &&
91+
networksConfig.strategies[0] === strategies.onePersonOneVote)
9192
) {
9293
// We don't need snapshotHeights in this case
9394
return;
@@ -155,7 +156,7 @@ function checkNetworkConfig(data) {
155156
...pick(spaceService, ["quorum", "version"]),
156157
};
157158

158-
if (!isEqual(networksConfig, spaceNetworksConfig)) {
159+
if (!isMatch(networksConfig, spaceNetworksConfig)) {
159160
throw new HttpError(400, {
160161
networksConfig: [
161162
"The proposal networks config is not matching the space config",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require("dotenv").config();
2+
3+
const { daoSpaces } = require("./spaces");
4+
const { getSpaceCollection } = require("../mongo");
5+
6+
async function main() {
7+
const col = await getSpaceCollection();
8+
for (const item of daoSpaces) {
9+
await col.updateOne(
10+
{ id: item.id },
11+
{
12+
$set: item,
13+
$unset: {
14+
whitelist: "",
15+
symbol: "",
16+
decimals: "",
17+
networks: "",
18+
},
19+
},
20+
);
21+
}
22+
}
23+
24+
main()
25+
.catch(console.error)
26+
.finally(() => process.exit());

backend/packages/backend/src/scripts/spaces/jamdao.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
const { Accessibility, SpaceType } = require("../../consts/space");
2-
const { networks, strategies } = require("./consts");
2+
const { strategies } = require("./consts");
33

44
const config = {
55
id: "jamdao",
66
name: "JAM DAO",
7-
symbol: "DOT",
8-
decimals: 10,
97
accessibility: Accessibility.WHITELIST,
108
type: SpaceType.CollectivesDao,
119
members: [
@@ -26,18 +24,6 @@ const config = {
2624
"15R1pWegyu7AfMev8DBMT67qxYoJhA1v7BbA2nn7S2uJ5QDF", // JamBrains
2725
"15fGrDWmFoaApnZXEw1Zg45zuCqpkbMS9YPzczeU9dHseUUu", // Fluffy Labs
2826
],
29-
networks: [
30-
{
31-
network: networks.polkadot,
32-
ss58Format: 0,
33-
assets: [
34-
{
35-
symbol: "DOT",
36-
decimals: 10,
37-
},
38-
],
39-
},
40-
],
4127
weightStrategy: [strategies.onePersonOneVote],
4228
version: "4",
4329
spaceIcon: "jamdao.svg",

backend/packages/backend/src/scripts/spaces/permanence.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
const { Accessibility, SpaceType } = require("../../consts/space");
2-
const { networks, strategies } = require("./consts");
2+
const { strategies } = require("./consts");
33

44
const config = {
55
id: "permanence",
66
name: "Permanence DAO",
7-
symbol: "DOT",
8-
decimals: 10,
97
accessibility: Accessibility.WHITELIST,
108
type: SpaceType.CollectivesDao,
119
members: [
@@ -23,18 +21,6 @@ const config = {
2321
"13znFMMjHyM2UvSewvaKMC2bLUcySRMzcM8BAMTzm1G2P5ju", // PERMANENCE DAO/GOV-PROXY
2422
"12KtA8mtfsK1CyQb4utLiwG3ao22z77w2cM2GqnaL2RiDCoJ", // Flez
2523
],
26-
networks: [
27-
{
28-
network: networks.polkadot,
29-
ss58Format: 0,
30-
assets: [
31-
{
32-
symbol: "DOT",
33-
decimals: 10,
34-
},
35-
],
36-
},
37-
],
3824
weightStrategy: [strategies.onePersonOneVote],
3925
version: "4",
4026
spaceIcon: "permanence.svg",

backend/packages/backend/src/scripts/spaces/truthdao.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
const { Accessibility, SpaceType } = require("../../consts/space");
2-
const { networks, strategies } = require("./consts");
2+
const { strategies } = require("./consts");
33

44
const config = {
55
id: "truthdao",
66
name: "Truth DAO",
7-
symbol: "DOT",
8-
decimals: 10,
97
accessibility: Accessibility.WHITELIST,
108
type: SpaceType.CollectivesDao,
119
members: [
@@ -17,18 +15,6 @@ const config = {
1715
"14pa3BAYZLPvZfRDjWEfZXZWBVU45E67HUQEUxNCrdXGoata", // Tiny/Mimir
1816
"14qwyVVvW4Tuhq4Fvt2AHZqhbCtGfVb8HUY2xM2PKrzKsmZT",
1917
],
20-
networks: [
21-
{
22-
network: networks.polkadot,
23-
ss58Format: 0,
24-
assets: [
25-
{
26-
symbol: "DOT",
27-
decimals: 10,
28-
},
29-
],
30-
},
31-
],
3218
weightStrategy: [strategies.onePersonOneVote],
3319
version: "4",
3420
spaceIcon: "truthdao.svg",

backend/packages/backend/src/services/proposal.service/createWhitelistProposal.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { SpaceType } = require("../../consts/space");
12
const { HttpError } = require("../../exc");
23
const { spaces: spaceServices } = require("../../spaces");
34
const { isSameAddress } = require("../../utils/address");
@@ -34,7 +35,10 @@ async function createWhitelistProposal({
3435
const spaceService = spaceServices[space];
3536
const weightStrategy = spaceService.weightStrategy;
3637

37-
if (realProposer && realProposer !== address) {
38+
if (realProposer && !isSameAddress(realProposer, address)) {
39+
if (networksConfig?.type === SpaceType.CollectivesDao) {
40+
throw new HttpError(400, "Proxy is not allowed in collectives DAO");
41+
}
3842
const lastHeight = await getLatestHeight(proposerNetwork);
3943
await checkProxy(proposerNetwork, address, realProposer, lastHeight);
4044
}

backend/packages/backend/src/services/proposal.service/vote.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const { adaptBalance } = require("../../utils/balance");
1616
const { getDemocracyDelegated } = require("../node.service/getDelegated");
1717
const { findDelegationStrategies } = require("../../utils/delegation");
1818
const { getSocietyMember } = require("../node.service/getSocietyMember");
19-
const { Accessibility } = require("../../consts/space");
19+
const { Accessibility, SpaceType } = require("../../consts/space");
2020
const {
2121
hasBalanceStrategy,
2222
hasSocietyStrategy,
@@ -146,6 +146,10 @@ async function checkProxy({ proposal, voterNetwork, address, realVoter }) {
146146
return;
147147
}
148148

149+
if (proposal.networksConfig?.type === SpaceType.CollectivesDao) {
150+
throw new HttpError(400, "Proxy is not allowed in collectives DAO");
151+
}
152+
149153
const snapshotHeight = proposal.snapshotHeights?.[voterNetwork];
150154
await _checkProxy(voterNetwork, address, realVoter, snapshotHeight);
151155
}

backend/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5380,6 +5380,11 @@ lodash.isequal@^4.5.0:
53805380
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
53815381
integrity sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==
53825382

5383+
lodash.ismatch@^4.4.0:
5384+
version "4.4.0"
5385+
resolved "https://registry.yarnpkg.com/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37"
5386+
integrity sha512-fPMfXjGQEV9Xsq/8MTSgUf255gawYRbjwMyDbcvDhXgV7enSZA0hynz6vMPnpAb5iONEzBHBPsT+0zes5Z301g==
5387+
53835388
lodash.isnil@^4.0.0:
53845389
version "4.0.0"
53855390
resolved "https://registry.npmjs.org/lodash.isnil/-/lodash.isnil-4.0.0.tgz#49e28cd559013458c814c5479d3c663a21bfaa6c"

0 commit comments

Comments
 (0)