Skip to content

Commit

Permalink
Add permanence dao space, #1057 (#1058)
Browse files Browse the repository at this point in the history
* Add permanence DAO space

* Update icons

* Update winner choice

* Clean up debug code

* Update

* Update whitelist addresses

* Hide proxy and snapshot for permanence

* Add vote function for whitelist one person one vote

* refactor, #1057

* fix: proxy check on proposal creation, #1057

* Show not member hint for whitelist

* fix: create proposal button and vote button
  • Loading branch information
hyifeng authored Oct 22, 2024
1 parent 31c0041 commit 0021fee
Show file tree
Hide file tree
Showing 30 changed files with 1,001 additions and 485 deletions.
1 change: 1 addition & 0 deletions backend/packages/backend/src/consts/space.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Accessibility = {
PUBLIC: "public",
SOCIETY: "society",
WHITELIST: "whitelist",
};

module.exports = {
Expand Down
23 changes: 23 additions & 0 deletions backend/packages/backend/src/features/proposals/createProposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ function checkNetworkConfig(data) {
"decimals",
"networks",
"accessibility",
"whitelist",
]),
strategies: spaceService.weightStrategy,
...pick(spaceService, ["quorum", "version"]),
Expand Down Expand Up @@ -212,6 +213,28 @@ async function createProposal(ctx) {

const spaceConfig = spaceServices[space];

if (spaceConfig.accessibility === Accessibility.WHITELIST) {
ctx.body = await proposalService.createWhitelistProposal({
space,
networksConfig,
title,
content,
contentType,
choiceType,
choices,
startDate,
endDate,
snapshotHeights,
realProposer,
proposerNetwork,
banner,
data,
address,
signature,
});
return;
}

if (spaceConfig.accessibility === Accessibility.SOCIETY) {
ctx.body = await proposalService.createSocietyProposal({
space,
Expand Down
2 changes: 2 additions & 0 deletions backend/packages/backend/src/scripts/init-spaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const { stafiConfig } = require("./spaces/stafi");
const { creditcoinConfig } = require("./spaces/creditcoin");
const { creditcoinEnterpriseConfig } = require("./spaces/creditcoinEnterprise");
const { dotaConfig } = require("./spaces/dota");
const { permanenceConfig } = require("./spaces/permanence");

const spaces = [
polkadotConfig,
Expand Down Expand Up @@ -74,6 +75,7 @@ const spaces = [
creditcoinConfig,
creditcoinEnterpriseConfig,
dotaConfig,
permanenceConfig,
];

if (["1", "true", "TRUE"].includes(process.env.DEVELOPMENT)) {
Expand Down
44 changes: 44 additions & 0 deletions backend/packages/backend/src/scripts/spaces/permanence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { Accessibility } = require("../../consts/space");
const { networks, strategies } = require("./consts");

const config = {
id: "permanence",
name: "Permanence",
symbol: "DOT",
decimals: 10,
accessibility: Accessibility.WHITELIST,
whitelist: [
// list addresses here to give them access to the space
"1ZSPR3zNg5Po3obkhXTPR95DepNBzBZ3CyomHXGHK9Uvx6w", // William
"1xzcLSwo7xBFkJYZiL4EHaqFpuPTkH641E3V43W4cuk1bX6", // PolkaBiz
"12His7t3EJ38tjdBbivUzWQeaNCLKfMqtKp1Ed3xHMyCE9N3", // The Ionian Group
"12s6UMSSfE2bNxtYrJc6eeuZ7UxQnRpUzaAh1gPQrGNFnE8h", // Polkadotters
"13EDmaUe89xXocPppFmuoAZaCsckaJy3deAyVyiykk1zKQbF", // PMEI
"14333MZvbGkcq5CZ8fYHZiFYwHNDaW3uiErDKMb7oqnupWXn", // Transistor
"14gMJV95zwxUsFEZDSC8mtBVifS6SypKJkfBKANkMsLZdeVb", // Yongfeng Li
"14Gn7SEmCgMX7Ukuppnw5TRjA7pao2HFpuJo39frB42tYLEh", // EzioRed
"15fTH34bbKGMUjF1bLmTqxPYgpg481imThwhWcQfCyktyBzL", // Helikon
"167YoKNriVtP4Nxk9F9GRV7HTKu5VnxaRq1pKMANAnmmTY9F", // José Rabasso
],
networks: [
{
network: networks.polkadot,
ss58Format: 0,
assets: [
{
symbol: "DOT",
decimals: 10,
},
],
},
],
weightStrategy: [strategies.onePersonOneVote],
version: "4",
spaceIcon: "permanence.svg",
seoCoverFilename: "permanence_dao.jpg",
admins: [],
};

module.exports = {
permanenceConfig: config,
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ async function getChainHeight(api) {
return { height: 100000 };
}

async function checkDelegation(api, delegatee, delegator, blockHeight) {
console.log("Use mock checkDelegation");
async function checkProxy(api, delegatee, delegator, blockHeight) {
console.log("Use mock checkProxy");
return { isProxy: true };
}

Expand All @@ -32,6 +32,6 @@ module.exports = {
getTotalBalance,
getTokenBalance,
getChainHeight,
checkDelegation,
checkProxy,
getBalanceFromNetwork,
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { NODE_API_ENDPOINT } = require("../../env");
const { isTestAccount } = require("../../utils");
const { fetchApi } = require("../../utils/fech.api");

async function checkDelegation(network, delegatee, delegator, blockHeight) {
async function checkProxy(network, delegatee, delegator, blockHeight) {
if (isTestAccount(delegator)) {
return;
}
Expand All @@ -23,5 +23,5 @@ async function checkDelegation(network, delegatee, delegator, blockHeight) {
}

module.exports = {
checkDelegation,
checkProxy,
};
4 changes: 2 additions & 2 deletions backend/packages/backend/src/services/node.service/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { getTotalBalance } = require("./getTotalBalance");
const { getTokenBalance } = require("./getTokenBalance");
const { checkDelegation } = require("./checkDelegation");
const { checkProxy } = require("./checkProxy");
const { getBalanceFromNetwork } = require("./getBalanceFromNetwork");
const { getChainHeight } = require("./getChainHeight");
const { getEvmAddressBalance } = require("./getEvmAddressBalance");
Expand All @@ -9,7 +9,7 @@ const { getTotalIssuance } = require("./getTotalIssuance");
module.exports = {
getTotalBalance,
getTokenBalance,
checkDelegation,
checkProxy,
getBalanceFromNetwork,
getChainHeight,
getEvmAddressBalance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { HttpError } = require("../../exc");
const { ContentType } = require("../../constants");
const { getLatestHeight } = require("../chain.service");
const { spaces: spaceServices } = require("../../spaces");
const { checkDelegation } = require("../../services/node.service");
const { checkProxy } = require("../../services/node.service");
const { getBalanceFromNetwork } = require("../../services/node.service");
const { pinData, createSpaceNotifications } = require("./common");
const { isAdmin } = require("../../utils/admin");
Expand Down Expand Up @@ -40,7 +40,7 @@ async function createProposal({
const lastHeight = await getLatestHeight(proposerNetwork);

if (realProposer && realProposer !== address) {
await checkDelegation(proposerNetwork, address, realProposer, lastHeight);
await checkProxy(proposerNetwork, address, realProposer, lastHeight);
}

const proposer = realProposer || address;
Expand All @@ -59,6 +59,46 @@ async function createProposal({
}
}

return await saveProposal({
data,
address,
signature,
choices,
space,
networksConfig,
title,
contentType,
content,
choiceType,
startDate,
endDate,
snapshotHeights,
weightStrategy,
proposer,
proposerNetwork,
banner,
});
}

async function saveProposal({
data,
address,
signature,
choices,
space,
networksConfig,
title,
contentType,
content,
choiceType,
startDate,
endDate,
snapshotHeights,
weightStrategy,
proposer,
proposerNetwork,
banner,
}) {
const { cid, pinHash } = await pinData({ data, address, signature });

const postUid = await nextPostUid();
Expand Down Expand Up @@ -114,4 +154,5 @@ async function createProposal({

module.exports = {
createProposal,
saveProposal,
};
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
const { safeHtml } = require("../../utils/post");
const { NotificationType } = require("../../constants");
const { nextPostUid } = require("../status.service");
const { getProposalCollection } = require("../../mongo");
const { HttpError } = require("../../exc");
const { ContentType } = require("../../constants");
const { spaces: spaceServices } = require("../../spaces");
const { pinData, createSpaceNotifications } = require("./common");
const { Accessibility } = require("../../consts/space");
const { getLatestHeight } = require("../chain.service");
const { checkProxy } = require("../node.service");
const { getSocietyMember } = require("../node.service/getSocietyMember");
const { saveProposal } = require("./createProposal");

async function checkSocietyMember({
networksConfig,
proposerNetwork,
proposer,
}) {
if (networksConfig.accessibility !== Accessibility.SOCIETY) {
return;
}
async function checkSocietyMember({ proposerNetwork, proposer }) {
const societyMember = await getSocietyMember(proposerNetwork, proposer);
if (!societyMember.data) {
throw new HttpError(400, "You are not the society member");
Expand Down Expand Up @@ -44,65 +33,37 @@ async function createSocietyProposal({
const spaceService = spaceServices[space];
const weightStrategy = spaceService.weightStrategy;

if (realProposer && realProposer !== address) {
const lastHeight = await getLatestHeight(proposerNetwork);
await checkProxy(proposerNetwork, address, realProposer, lastHeight);
}

const proposer = realProposer || address;

await checkSocietyMember({
networksConfig,
proposerNetwork,
proposer,
});

const { cid, pinHash } = await pinData({ data, address, signature });

const postUid = await nextPostUid();

const uniqueChoices = Array.from(new Set(choices));
const now = new Date();

const proposalCol = await getProposalCollection();
const result = await proposalCol.insertOne({
return await saveProposal({
data,
address,
signature,
choices,
space,
networksConfig,
postUid,
title,
content: contentType === ContentType.Html ? safeHtml(content) : content,
contentType,
content,
choiceType,
choices: uniqueChoices,
startDate,
endDate,
snapshotHeights,
weightStrategy,
proposer,
proposerNetwork,
banner,
data,
address,
signature,
lastActivityAt: new Date(),
createdAt: now,
updatedAt: now,
cid,
pinHash,
// Version 2: support multi-network space
// Version 3: support multi-assets network
version: "3",
});

if (!result.insertedId) {
throw new HttpError(500, "Failed to create post");
}

createSpaceNotifications(space, NotificationType.NewProposal, {
proposalCid: cid,
space,
title,
});

return {
cid,
postUid,
};
}

module.exports = {
Expand Down
Loading

0 comments on commit 0021fee

Please sign in to comment.