@quantabit/dao-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/dist/index.cjs +168 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.esm.js +156 -0
- package/dist/index.esm.js.map +1 -0
- package/package.json +72 -0
- package/types/index.d.ts +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 QuantaBit Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @quantabit/dao-sdk
|
|
2
|
+
|
|
3
|
+
QuantaBit DAO SDK provides interface implementations and utilities for on-chain voting, decentralised governance proposals, quorum validation, and multi-signature execution in the QuantaBit network.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Proposal Creation**: Create and track governance proposals with customized execution payloads.
|
|
8
|
+
- **On-chain Voting**: Vote on active proposals with weighted token mechanisms.
|
|
9
|
+
- **Proposal Execution**: Trigger chain-level state changes for successful proposals meeting quorum thresholds.
|
|
10
|
+
- **DAO Hooks**: React hooks to query, list, and filter historical and current governance proposals.
|
|
11
|
+
- **Multilingual Support**: Fully localized dictionary support for EN, ZH, JA, and KO.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @quantabit/dao-sdk @quantabit/sdk-config
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import { createDaoProposal, castVote, executeDaoProposal } from '@quantabit/dao-sdk';
|
|
23
|
+
|
|
24
|
+
// Create a new proposal
|
|
25
|
+
const proposal = await createDaoProposal(
|
|
26
|
+
"Community Funding Campaign Q3",
|
|
27
|
+
"Allocate QBT resources for developers.",
|
|
28
|
+
["allocate_funds_payload"]
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// Cast vote
|
|
32
|
+
await castVote(proposal.proposalId, true, 125000); // vote FOR with 125k weight
|
|
33
|
+
|
|
34
|
+
// Execute proposal after passing quorum
|
|
35
|
+
await executeDaoProposal(proposal.proposalId);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Brand & Links
|
|
39
|
+
|
|
40
|
+
- **Official Website**: [https://quantabit.io](https://quantabit.io)
|
|
41
|
+
- **Documentation**: [https://docs.quantabit.io](https://docs.quantabit.io)
|
|
42
|
+
- **Explorer**: [https://explorer.mg.qbitchain.io](https://explorer.mg.qbitchain.io)
|
|
43
|
+
- **Source Code**: [https://github.com/quantabit-chain/qbit-sdk](https://github.com/quantabit-chain/qbit-sdk)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var sdkConfig = require('@quantabit/sdk-config');
|
|
5
|
+
|
|
6
|
+
const messages = {
|
|
7
|
+
en: {
|
|
8
|
+
proposal_created: "Governance proposal created successfully",
|
|
9
|
+
vote_cast: "Vote submitted successfully",
|
|
10
|
+
quorum_not_reached: "Quorum not reached for proposal execution",
|
|
11
|
+
proposal_passed: "Proposal passed successfully",
|
|
12
|
+
proposal_defeated: "Proposal was defeated",
|
|
13
|
+
insufficient_voting_power: "Insufficient voting power to perform this action"
|
|
14
|
+
},
|
|
15
|
+
zh: {
|
|
16
|
+
proposal_created: "治理提案已成功创建",
|
|
17
|
+
vote_cast: "投票已成功提交",
|
|
18
|
+
quorum_not_reached: "未达到提案执行所需的法定人数",
|
|
19
|
+
proposal_passed: "提案已成功通过",
|
|
20
|
+
proposal_defeated: "提案已被否决",
|
|
21
|
+
insufficient_voting_power: "投票权不足,无法执行此操作"
|
|
22
|
+
},
|
|
23
|
+
ja: {
|
|
24
|
+
proposal_created: "ガバナンス提案が正常に作成されました",
|
|
25
|
+
vote_cast: "投票が正常に送信されました",
|
|
26
|
+
quorum_not_reached: "提案の実行に必要な定足数に達していません",
|
|
27
|
+
proposal_passed: "提案が正常に可決されました",
|
|
28
|
+
proposal_defeated: "提案は否決されました",
|
|
29
|
+
insufficient_voting_power: "このアクションを実行するための投票権が不足しています"
|
|
30
|
+
},
|
|
31
|
+
ko: {
|
|
32
|
+
proposal_created: "거버넌스 제안이 성공적으로 생성되었습니다",
|
|
33
|
+
vote_cast: "투표가 성공적으로 제출되었습니다",
|
|
34
|
+
quorum_not_reached: "제안 실행을 위한 정족수가 부족합니다",
|
|
35
|
+
proposal_passed: "제안이 성공적으로 통과되었습니다",
|
|
36
|
+
proposal_defeated: "제안이 부결되었습니다",
|
|
37
|
+
insufficient_voting_power: "이 작업을 수행하기에 투표 권한이 부족합니다"
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
let currentLang = null;
|
|
41
|
+
function getLanguage() {
|
|
42
|
+
return currentLang || sdkConfig.getLanguage() || 'en';
|
|
43
|
+
}
|
|
44
|
+
function setLanguage(lang) {
|
|
45
|
+
if (messages[lang]) {
|
|
46
|
+
currentLang = lang;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function t(key) {
|
|
50
|
+
const lang = getLanguage();
|
|
51
|
+
return messages[lang]?.[key] || messages['en']?.[key] || key;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 模拟治理提案数据
|
|
55
|
+
const PROPOSALS = {
|
|
56
|
+
"prop_001": {
|
|
57
|
+
id: "prop_001",
|
|
58
|
+
title: "QBit Chain Mainnet Upgrade v1.2.0",
|
|
59
|
+
description: "Upgrade consensus layer parameters to reduce block confirmation latency.",
|
|
60
|
+
forVotes: 850000,
|
|
61
|
+
againstVotes: 120000,
|
|
62
|
+
quorum: 500000,
|
|
63
|
+
status: "passed",
|
|
64
|
+
actions: ["call_upgrade_contract"]
|
|
65
|
+
},
|
|
66
|
+
"prop_002": {
|
|
67
|
+
id: "prop_002",
|
|
68
|
+
title: "Eco-fund Grants Allocation Q3",
|
|
69
|
+
description: "Distribute 2,000,000 QBT to community builders.",
|
|
70
|
+
forVotes: 320000,
|
|
71
|
+
againstVotes: 50000,
|
|
72
|
+
quorum: 500000,
|
|
73
|
+
status: "active",
|
|
74
|
+
actions: ["transfer_funds"]
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
async function createDaoProposal(title, description, actions = []) {
|
|
78
|
+
if (!title || !description) {
|
|
79
|
+
throw new Error("Title and description are required for governance proposals");
|
|
80
|
+
}
|
|
81
|
+
const proposalId = `prop_${Math.floor(Math.random() * 900) + 100}`;
|
|
82
|
+
return {
|
|
83
|
+
proposalId,
|
|
84
|
+
title,
|
|
85
|
+
description,
|
|
86
|
+
actions,
|
|
87
|
+
status: "active",
|
|
88
|
+
forVotes: 0,
|
|
89
|
+
againstVotes: 0,
|
|
90
|
+
quorum: 500000,
|
|
91
|
+
message: t('proposal_created')
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
async function castVote(proposalId, support, votingPower) {
|
|
95
|
+
const proposal = PROPOSALS[proposalId];
|
|
96
|
+
if (!proposal) {
|
|
97
|
+
throw new Error("Proposal not found");
|
|
98
|
+
}
|
|
99
|
+
if (votingPower <= 0) {
|
|
100
|
+
throw new Error(t('insufficient_voting_power'));
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
txHash: `vote_tx_${Math.random().toString(36).substr(2, 9)}`,
|
|
104
|
+
proposalId,
|
|
105
|
+
support,
|
|
106
|
+
votingPower,
|
|
107
|
+
status: "confirmed",
|
|
108
|
+
message: t('vote_cast')
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
async function executeDaoProposal(proposalId) {
|
|
112
|
+
const proposal = PROPOSALS[proposalId];
|
|
113
|
+
if (!proposal) {
|
|
114
|
+
throw new Error("Proposal not found");
|
|
115
|
+
}
|
|
116
|
+
const totalVotes = proposal.forVotes + proposal.againstVotes;
|
|
117
|
+
if (totalVotes < proposal.quorum) {
|
|
118
|
+
throw new Error(t('quorum_not_reached'));
|
|
119
|
+
}
|
|
120
|
+
if (proposal.forVotes <= proposal.againstVotes) {
|
|
121
|
+
throw new Error(t('proposal_defeated'));
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
txHash: `exec_tx_${Math.random().toString(36).substr(2, 9)}`,
|
|
125
|
+
proposalId,
|
|
126
|
+
status: "executed",
|
|
127
|
+
message: t('proposal_passed')
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
async function getProposalStatus(proposalId) {
|
|
131
|
+
const proposal = PROPOSALS[proposalId];
|
|
132
|
+
if (!proposal) {
|
|
133
|
+
throw new Error("Proposal not found");
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
...proposal
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function useDaoProposals() {
|
|
140
|
+
const [proposals, setProposals] = react.useState([]);
|
|
141
|
+
const [loading, setLoading] = react.useState(true);
|
|
142
|
+
react.useEffect(() => {
|
|
143
|
+
setLoading(true);
|
|
144
|
+
const timer = setTimeout(() => {
|
|
145
|
+
setProposals(Object.values(PROPOSALS));
|
|
146
|
+
setLoading(false);
|
|
147
|
+
}, 300);
|
|
148
|
+
return () => clearTimeout(timer);
|
|
149
|
+
}, []);
|
|
150
|
+
return {
|
|
151
|
+
proposals,
|
|
152
|
+
loading
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const SUPPORTED_LANGUAGES = ['en', 'zh', 'ja', 'ko'];
|
|
156
|
+
|
|
157
|
+
exports.PROPOSALS = PROPOSALS;
|
|
158
|
+
exports.SUPPORTED_LANGUAGES = SUPPORTED_LANGUAGES;
|
|
159
|
+
exports.castVote = castVote;
|
|
160
|
+
exports.createDaoProposal = createDaoProposal;
|
|
161
|
+
exports.executeDaoProposal = executeDaoProposal;
|
|
162
|
+
exports.getLanguage = getLanguage;
|
|
163
|
+
exports.getProposalStatus = getProposalStatus;
|
|
164
|
+
exports.messages = messages;
|
|
165
|
+
exports.setLanguage = setLanguage;
|
|
166
|
+
exports.t = t;
|
|
167
|
+
exports.useDaoProposals = useDaoProposals;
|
|
168
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/i18n/index.js","../src/index.js"],"sourcesContent":["import { getLanguage as getGlobalLang } from '@quantabit/sdk-config';\n\nexport const messages = {\n en: {\n proposal_created: \"Governance proposal created successfully\",\n vote_cast: \"Vote submitted successfully\",\n quorum_not_reached: \"Quorum not reached for proposal execution\",\n proposal_passed: \"Proposal passed successfully\",\n proposal_defeated: \"Proposal was defeated\",\n insufficient_voting_power: \"Insufficient voting power to perform this action\"\n },\n zh: {\n proposal_created: \"治理提案已成功创建\",\n vote_cast: \"投票已成功提交\",\n quorum_not_reached: \"未达到提案执行所需的法定人数\",\n proposal_passed: \"提案已成功通过\",\n proposal_defeated: \"提案已被否决\",\n insufficient_voting_power: \"投票权不足,无法执行此操作\"\n },\n ja: {\n proposal_created: \"ガバナンス提案が正常に作成されました\",\n vote_cast: \"投票が正常に送信されました\",\n quorum_not_reached: \"提案の実行に必要な定足数に達していません\",\n proposal_passed: \"提案が正常に可決されました\",\n proposal_defeated: \"提案は否決されました\",\n insufficient_voting_power: \"このアクションを実行するための投票権が不足しています\"\n },\n ko: {\n proposal_created: \"거버넌스 제안이 성공적으로 생성되었습니다\",\n vote_cast: \"투표가 성공적으로 제출되었습니다\",\n quorum_not_reached: \"제안 실행을 위한 정족수가 부족합니다\",\n proposal_passed: \"제안이 성공적으로 통과되었습니다\",\n proposal_defeated: \"제안이 부결되었습니다\",\n insufficient_voting_power: \"이 작업을 수행하기에 투표 권한이 부족합니다\"\n }\n};\n\nlet currentLang = null;\n\nexport function getLanguage() {\n return currentLang || getGlobalLang() || 'en';\n}\n\nexport function setLanguage(lang) {\n if (messages[lang]) {\n currentLang = lang;\n }\n}\n\nexport function t(key) {\n const lang = getLanguage();\n return messages[lang]?.[key] || messages['en']?.[key] || key;\n}\n","import { useState, useEffect } from 'react';\nimport { getConfig } from '@quantabit/sdk-config';\nimport { t, setLanguage, getLanguage, messages } from './i18n/index.js';\n\n// 模拟治理提案数据\nconst PROPOSALS = {\n \"prop_001\": {\n id: \"prop_001\",\n title: \"QBit Chain Mainnet Upgrade v1.2.0\",\n description: \"Upgrade consensus layer parameters to reduce block confirmation latency.\",\n forVotes: 850000,\n againstVotes: 120000,\n quorum: 500000,\n status: \"passed\",\n actions: [\"call_upgrade_contract\"]\n },\n \"prop_002\": {\n id: \"prop_002\",\n title: \"Eco-fund Grants Allocation Q3\",\n description: \"Distribute 2,000,000 QBT to community builders.\",\n forVotes: 320000,\n againstVotes: 50000,\n quorum: 500000,\n status: \"active\",\n actions: [\"transfer_funds\"]\n }\n};\n\nexport async function createDaoProposal(title, description, actions = []) {\n if (!title || !description) {\n throw new Error(\"Title and description are required for governance proposals\");\n }\n \n const proposalId = `prop_${Math.floor(Math.random() * 900) + 100}`;\n \n return {\n proposalId,\n title,\n description,\n actions,\n status: \"active\",\n forVotes: 0,\n againstVotes: 0,\n quorum: 500000,\n message: t('proposal_created')\n };\n}\n\nexport async function castVote(proposalId, support, votingPower) {\n const proposal = PROPOSALS[proposalId];\n if (!proposal) {\n throw new Error(\"Proposal not found\");\n }\n if (votingPower <= 0) {\n throw new Error(t('insufficient_voting_power'));\n }\n \n return {\n txHash: `vote_tx_${Math.random().toString(36).substr(2, 9)}`,\n proposalId,\n support,\n votingPower,\n status: \"confirmed\",\n message: t('vote_cast')\n };\n}\n\nexport async function executeDaoProposal(proposalId) {\n const proposal = PROPOSALS[proposalId];\n if (!proposal) {\n throw new Error(\"Proposal not found\");\n }\n \n const totalVotes = proposal.forVotes + proposal.againstVotes;\n if (totalVotes < proposal.quorum) {\n throw new Error(t('quorum_not_reached'));\n }\n \n if (proposal.forVotes <= proposal.againstVotes) {\n throw new Error(t('proposal_defeated'));\n }\n \n return {\n txHash: `exec_tx_${Math.random().toString(36).substr(2, 9)}`,\n proposalId,\n status: \"executed\",\n message: t('proposal_passed')\n };\n}\n\nexport async function getProposalStatus(proposalId) {\n const proposal = PROPOSALS[proposalId];\n if (!proposal) {\n throw new Error(\"Proposal not found\");\n }\n return { ...proposal };\n}\n\nexport function useDaoProposals() {\n const [proposals, setProposals] = useState([]);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n setLoading(true);\n const timer = setTimeout(() => {\n setProposals(Object.values(PROPOSALS));\n setLoading(false);\n }, 300);\n\n return () => clearTimeout(timer);\n }, []);\n\n return { proposals, loading };\n}\n\nexport { t, setLanguage, getLanguage, messages };\nexport const SUPPORTED_LANGUAGES = ['en', 'zh', 'ja', 'ko'];\nexport { PROPOSALS };\n"],"names":["messages","en","proposal_created","vote_cast","quorum_not_reached","proposal_passed","proposal_defeated","insufficient_voting_power","zh","ja","ko","currentLang","getLanguage","getGlobalLang","setLanguage","lang","t","key","PROPOSALS","id","title","description","forVotes","againstVotes","quorum","status","actions","createDaoProposal","Error","proposalId","Math","floor","random","message","castVote","support","votingPower","proposal","txHash","toString","substr","executeDaoProposal","totalVotes","getProposalStatus","useDaoProposals","proposals","setProposals","useState","loading","setLoading","useEffect","timer","setTimeout","Object","values","clearTimeout","SUPPORTED_LANGUAGES"],"mappings":";;;;;AAEO,MAAMA,QAAQ,GAAG;AACtBC,EAAAA,EAAE,EAAE;AACFC,IAAAA,gBAAgB,EAAE,0CAA0C;AAC5DC,IAAAA,SAAS,EAAE,6BAA6B;AACxCC,IAAAA,kBAAkB,EAAE,2CAA2C;AAC/DC,IAAAA,eAAe,EAAE,8BAA8B;AAC/CC,IAAAA,iBAAiB,EAAE,uBAAuB;AAC1CC,IAAAA,yBAAyB,EAAE;GAC5B;AACDC,EAAAA,EAAE,EAAE;AACFN,IAAAA,gBAAgB,EAAE,WAAW;AAC7BC,IAAAA,SAAS,EAAE,SAAS;AACpBC,IAAAA,kBAAkB,EAAE,gBAAgB;AACpCC,IAAAA,eAAe,EAAE,SAAS;AAC1BC,IAAAA,iBAAiB,EAAE,QAAQ;AAC3BC,IAAAA,yBAAyB,EAAE;GAC5B;AACDE,EAAAA,EAAE,EAAE;AACFP,IAAAA,gBAAgB,EAAE,oBAAoB;AACtCC,IAAAA,SAAS,EAAE,eAAe;AAC1BC,IAAAA,kBAAkB,EAAE,sBAAsB;AAC1CC,IAAAA,eAAe,EAAE,eAAe;AAChCC,IAAAA,iBAAiB,EAAE,YAAY;AAC/BC,IAAAA,yBAAyB,EAAE;GAC5B;AACDG,EAAAA,EAAE,EAAE;AACFR,IAAAA,gBAAgB,EAAE,wBAAwB;AAC1CC,IAAAA,SAAS,EAAE,mBAAmB;AAC9BC,IAAAA,k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AAI,CAAC;AAE5CG,EAAAA,eAAS,CAAC,MAAM;IACdD,UAAU,CAAC,IAAI,CAAC;AAChB,IAAA,MAAME,KAAK,GAAGC,UAAU,CAAC,MAAM;AAC7BN,MAAAA,YAAY,CAACO,MAAM,CAACC,MAAM,CAACpC,SAAS,CAAC,CAAC;MACtC+B,UAAU,CAAC,KAAK,CAAC;IACnB,CAAC,EAAE,GAAG,CAAC;AAEP,IAAA,OAAO,MAAMM,YAAY,CAACJ,KAAK,CAAC;EAClC,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IAAEN,SAAS;AAAEG,IAAAA;GAAS;AAC/B;AAGO,MAAMQ,mBAAmB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { getLanguage as getLanguage$1 } from '@quantabit/sdk-config';
|
|
3
|
+
|
|
4
|
+
const messages = {
|
|
5
|
+
en: {
|
|
6
|
+
proposal_created: "Governance proposal created successfully",
|
|
7
|
+
vote_cast: "Vote submitted successfully",
|
|
8
|
+
quorum_not_reached: "Quorum not reached for proposal execution",
|
|
9
|
+
proposal_passed: "Proposal passed successfully",
|
|
10
|
+
proposal_defeated: "Proposal was defeated",
|
|
11
|
+
insufficient_voting_power: "Insufficient voting power to perform this action"
|
|
12
|
+
},
|
|
13
|
+
zh: {
|
|
14
|
+
proposal_created: "治理提案已成功创建",
|
|
15
|
+
vote_cast: "投票已成功提交",
|
|
16
|
+
quorum_not_reached: "未达到提案执行所需的法定人数",
|
|
17
|
+
proposal_passed: "提案已成功通过",
|
|
18
|
+
proposal_defeated: "提案已被否决",
|
|
19
|
+
insufficient_voting_power: "投票权不足,无法执行此操作"
|
|
20
|
+
},
|
|
21
|
+
ja: {
|
|
22
|
+
proposal_created: "ガバナンス提案が正常に作成されました",
|
|
23
|
+
vote_cast: "投票が正常に送信されました",
|
|
24
|
+
quorum_not_reached: "提案の実行に必要な定足数に達していません",
|
|
25
|
+
proposal_passed: "提案が正常に可決されました",
|
|
26
|
+
proposal_defeated: "提案は否決されました",
|
|
27
|
+
insufficient_voting_power: "このアクションを実行するための投票権が不足しています"
|
|
28
|
+
},
|
|
29
|
+
ko: {
|
|
30
|
+
proposal_created: "거버넌스 제안이 성공적으로 생성되었습니다",
|
|
31
|
+
vote_cast: "투표가 성공적으로 제출되었습니다",
|
|
32
|
+
quorum_not_reached: "제안 실행을 위한 정족수가 부족합니다",
|
|
33
|
+
proposal_passed: "제안이 성공적으로 통과되었습니다",
|
|
34
|
+
proposal_defeated: "제안이 부결되었습니다",
|
|
35
|
+
insufficient_voting_power: "이 작업을 수행하기에 투표 권한이 부족합니다"
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
let currentLang = null;
|
|
39
|
+
function getLanguage() {
|
|
40
|
+
return currentLang || getLanguage$1() || 'en';
|
|
41
|
+
}
|
|
42
|
+
function setLanguage(lang) {
|
|
43
|
+
if (messages[lang]) {
|
|
44
|
+
currentLang = lang;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function t(key) {
|
|
48
|
+
const lang = getLanguage();
|
|
49
|
+
return messages[lang]?.[key] || messages['en']?.[key] || key;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 模拟治理提案数据
|
|
53
|
+
const PROPOSALS = {
|
|
54
|
+
"prop_001": {
|
|
55
|
+
id: "prop_001",
|
|
56
|
+
title: "QBit Chain Mainnet Upgrade v1.2.0",
|
|
57
|
+
description: "Upgrade consensus layer parameters to reduce block confirmation latency.",
|
|
58
|
+
forVotes: 850000,
|
|
59
|
+
againstVotes: 120000,
|
|
60
|
+
quorum: 500000,
|
|
61
|
+
status: "passed",
|
|
62
|
+
actions: ["call_upgrade_contract"]
|
|
63
|
+
},
|
|
64
|
+
"prop_002": {
|
|
65
|
+
id: "prop_002",
|
|
66
|
+
title: "Eco-fund Grants Allocation Q3",
|
|
67
|
+
description: "Distribute 2,000,000 QBT to community builders.",
|
|
68
|
+
forVotes: 320000,
|
|
69
|
+
againstVotes: 50000,
|
|
70
|
+
quorum: 500000,
|
|
71
|
+
status: "active",
|
|
72
|
+
actions: ["transfer_funds"]
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
async function createDaoProposal(title, description, actions = []) {
|
|
76
|
+
if (!title || !description) {
|
|
77
|
+
throw new Error("Title and description are required for governance proposals");
|
|
78
|
+
}
|
|
79
|
+
const proposalId = `prop_${Math.floor(Math.random() * 900) + 100}`;
|
|
80
|
+
return {
|
|
81
|
+
proposalId,
|
|
82
|
+
title,
|
|
83
|
+
description,
|
|
84
|
+
actions,
|
|
85
|
+
status: "active",
|
|
86
|
+
forVotes: 0,
|
|
87
|
+
againstVotes: 0,
|
|
88
|
+
quorum: 500000,
|
|
89
|
+
message: t('proposal_created')
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async function castVote(proposalId, support, votingPower) {
|
|
93
|
+
const proposal = PROPOSALS[proposalId];
|
|
94
|
+
if (!proposal) {
|
|
95
|
+
throw new Error("Proposal not found");
|
|
96
|
+
}
|
|
97
|
+
if (votingPower <= 0) {
|
|
98
|
+
throw new Error(t('insufficient_voting_power'));
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
txHash: `vote_tx_${Math.random().toString(36).substr(2, 9)}`,
|
|
102
|
+
proposalId,
|
|
103
|
+
support,
|
|
104
|
+
votingPower,
|
|
105
|
+
status: "confirmed",
|
|
106
|
+
message: t('vote_cast')
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async function executeDaoProposal(proposalId) {
|
|
110
|
+
const proposal = PROPOSALS[proposalId];
|
|
111
|
+
if (!proposal) {
|
|
112
|
+
throw new Error("Proposal not found");
|
|
113
|
+
}
|
|
114
|
+
const totalVotes = proposal.forVotes + proposal.againstVotes;
|
|
115
|
+
if (totalVotes < proposal.quorum) {
|
|
116
|
+
throw new Error(t('quorum_not_reached'));
|
|
117
|
+
}
|
|
118
|
+
if (proposal.forVotes <= proposal.againstVotes) {
|
|
119
|
+
throw new Error(t('proposal_defeated'));
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
txHash: `exec_tx_${Math.random().toString(36).substr(2, 9)}`,
|
|
123
|
+
proposalId,
|
|
124
|
+
status: "executed",
|
|
125
|
+
message: t('proposal_passed')
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async function getProposalStatus(proposalId) {
|
|
129
|
+
const proposal = PROPOSALS[proposalId];
|
|
130
|
+
if (!proposal) {
|
|
131
|
+
throw new Error("Proposal not found");
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
...proposal
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function useDaoProposals() {
|
|
138
|
+
const [proposals, setProposals] = useState([]);
|
|
139
|
+
const [loading, setLoading] = useState(true);
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
setLoading(true);
|
|
142
|
+
const timer = setTimeout(() => {
|
|
143
|
+
setProposals(Object.values(PROPOSALS));
|
|
144
|
+
setLoading(false);
|
|
145
|
+
}, 300);
|
|
146
|
+
return () => clearTimeout(timer);
|
|
147
|
+
}, []);
|
|
148
|
+
return {
|
|
149
|
+
proposals,
|
|
150
|
+
loading
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const SUPPORTED_LANGUAGES = ['en', 'zh', 'ja', 'ko'];
|
|
154
|
+
|
|
155
|
+
export { PROPOSALS, SUPPORTED_LANGUAGES, castVote, createDaoProposal, executeDaoProposal, getLanguage, getProposalStatus, messages, setLanguage, t, useDaoProposals };
|
|
156
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/i18n/index.js","../src/index.js"],"sourcesContent":["import { getLanguage as getGlobalLang } from '@quantabit/sdk-config';\n\nexport const messages = {\n en: {\n proposal_created: \"Governance proposal created successfully\",\n vote_cast: \"Vote submitted successfully\",\n quorum_not_reached: \"Quorum not reached for proposal execution\",\n proposal_passed: \"Proposal passed successfully\",\n proposal_defeated: \"Proposal was defeated\",\n insufficient_voting_power: \"Insufficient voting power to perform this action\"\n },\n zh: {\n proposal_created: \"治理提案已成功创建\",\n vote_cast: \"投票已成功提交\",\n quorum_not_reached: \"未达到提案执行所需的法定人数\",\n proposal_passed: \"提案已成功通过\",\n proposal_defeated: \"提案已被否决\",\n insufficient_voting_power: \"投票权不足,无法执行此操作\"\n },\n ja: {\n proposal_created: \"ガバナンス提案が正常に作成されました\",\n vote_cast: \"投票が正常に送信されました\",\n quorum_not_reached: \"提案の実行に必要な定足数に達していません\",\n proposal_passed: \"提案が正常に可決されました\",\n proposal_defeated: \"提案は否決されました\",\n insufficient_voting_power: \"このアクションを実行するための投票権が不足しています\"\n },\n ko: {\n proposal_created: \"거버넌스 제안이 성공적으로 생성되었습니다\",\n vote_cast: \"투표가 성공적으로 제출되었습니다\",\n quorum_not_reached: \"제안 실행을 위한 정족수가 부족합니다\",\n proposal_passed: \"제안이 성공적으로 통과되었습니다\",\n proposal_defeated: \"제안이 부결되었습니다\",\n insufficient_voting_power: \"이 작업을 수행하기에 투표 권한이 부족합니다\"\n }\n};\n\nlet currentLang = null;\n\nexport function getLanguage() {\n return currentLang || getGlobalLang() || 'en';\n}\n\nexport function setLanguage(lang) {\n if (messages[lang]) {\n currentLang = lang;\n }\n}\n\nexport function t(key) {\n const lang = getLanguage();\n return messages[lang]?.[key] || messages['en']?.[key] || key;\n}\n","import { useState, useEffect } from 'react';\nimport { getConfig } from '@quantabit/sdk-config';\nimport { t, setLanguage, getLanguage, messages } from './i18n/index.js';\n\n// 模拟治理提案数据\nconst PROPOSALS = {\n \"prop_001\": {\n id: \"prop_001\",\n title: \"QBit Chain Mainnet Upgrade v1.2.0\",\n description: \"Upgrade consensus layer parameters to reduce block confirmation latency.\",\n forVotes: 850000,\n againstVotes: 120000,\n quorum: 500000,\n status: \"passed\",\n actions: [\"call_upgrade_contract\"]\n },\n \"prop_002\": {\n id: \"prop_002\",\n title: \"Eco-fund Grants Allocation Q3\",\n description: \"Distribute 2,000,000 QBT to community builders.\",\n forVotes: 320000,\n againstVotes: 50000,\n quorum: 500000,\n status: \"active\",\n actions: [\"transfer_funds\"]\n }\n};\n\nexport async function createDaoProposal(title, description, actions = []) {\n if (!title || !description) {\n throw new Error(\"Title and description are required for governance proposals\");\n }\n \n const proposalId = `prop_${Math.floor(Math.random() * 900) + 100}`;\n \n return {\n proposalId,\n title,\n description,\n actions,\n status: \"active\",\n forVotes: 0,\n againstVotes: 0,\n quorum: 500000,\n message: t('proposal_created')\n };\n}\n\nexport async function castVote(proposalId, support, votingPower) {\n const proposal = PROPOSALS[proposalId];\n if (!proposal) {\n throw new Error(\"Proposal not found\");\n }\n if (votingPower <= 0) {\n throw new Error(t('insufficient_voting_power'));\n }\n \n return {\n txHash: `vote_tx_${Math.random().toString(36).substr(2, 9)}`,\n proposalId,\n support,\n votingPower,\n status: \"confirmed\",\n message: t('vote_cast')\n };\n}\n\nexport async function executeDaoProposal(proposalId) {\n const proposal = PROPOSALS[proposalId];\n if (!proposal) {\n throw new Error(\"Proposal not found\");\n }\n \n const totalVotes = proposal.forVotes + proposal.againstVotes;\n if (totalVotes < proposal.quorum) {\n throw new Error(t('quorum_not_reached'));\n }\n \n if (proposal.forVotes <= proposal.againstVotes) {\n throw new Error(t('proposal_defeated'));\n }\n \n return {\n txHash: `exec_tx_${Math.random().toString(36).substr(2, 9)}`,\n proposalId,\n status: \"executed\",\n message: t('proposal_passed')\n };\n}\n\nexport async function getProposalStatus(proposalId) {\n const proposal = PROPOSALS[proposalId];\n if (!proposal) {\n throw new Error(\"Proposal not found\");\n }\n return { ...proposal };\n}\n\nexport function useDaoProposals() {\n const [proposals, setProposals] = useState([]);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n setLoading(true);\n const timer = setTimeout(() => {\n setProposals(Object.values(PROPOSALS));\n setLoading(false);\n }, 300);\n\n return () => clearTimeout(timer);\n }, []);\n\n return { proposals, loading };\n}\n\nexport { t, setLanguage, getLanguage, messages };\nexport const SUPPORTED_LANGUAGES = ['en', 'zh', 'ja', 'ko'];\nexport { PROPOSALS };\n"],"names":["messages","en","proposal_created","vote_cast","quorum_not_reached","proposal_passed","proposal_defeated","insufficient_voting_power","zh","ja","ko","currentLang","getLanguage","getGlobalLang","setLanguage","lang","t","key","PROPOSALS","id","title","description","forVotes","againstVotes","quorum","status","actions","createDaoProposal","Error","proposalId","Math","floor","random","message","castVote","support","votingPower","proposal","txHash","toString","substr","executeDaoProposal","totalVotes","getProposalStatus","useDaoProposals","proposals","setProposals","useState","loading","setLoading","useEffect","timer","setTimeout","Object","values","clearTimeout","SUPPORTED_LANGUAGES"],"mappings":";;;AAEO,MAAMA,QAAQ,GAAG;AACtBC,EAAAA,EAAE,EAAE;AACFC,IAAAA,gBAAgB,EAAE,0CAA0C;AAC5DC,IAAAA,SAAS,EAAE,6BAA6B;AACxCC,IAAAA,kBAAkB,EAAE,2CAA2C;AAC/DC,IAAAA,eAAe,EAAE,8BAA8B;AAC/CC,IAAAA,iBAAiB,EAAE,uBAAuB;AAC1CC,IAAAA,yBAAyB,EAAE;GAC5B;AACDC,EAAAA,EAAE,EAAE;AACFN,IAAAA,gBAAgB,EAAE,WAAW;AAC7BC,IAAAA,SAAS,EAAE,SAAS;AACpBC,IAAAA,kBAAkB,EAAE,gBAAgB;AACpCC,IAAAA,eAAe,EAAE,SAAS;AAC1BC,IAAAA,iBAAiB,EAAE,QAAQ;AAC3BC,IAAAA,yBAAyB,EAAE;GAC5B;AACDE,EAAAA,EAAE,EAAE;AACFP,IAAAA,gBAAgB,EAAE,oBAAoB;AACtCC,IAAAA,SAAS,EAAE,eAAe;AAC1BC,IAAAA,kBAAkB,EAAE,sBAAsB;AAC1CC,IAAAA,eAAe,EAAE,eAAe;AAChCC,IAAAA,iBAAiB,EAAE,YAAY;AAC/BC,IAAAA,yBAAyB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ACC,SAAS,EAAEC,YAAY,CAAC,GAAGC,QAAQ,CAAC,EAAE,CAAC;EAC9C,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGF,QAAQ,CAAC,IAAI,CAAC;AAE5CG,EAAAA,SAAS,CAAC,MAAM;IACdD,UAAU,CAAC,IAAI,CAAC;AAChB,IAAA,MAAME,KAAK,GAAGC,UAAU,CAAC,MAAM;AAC7BN,MAAAA,YAAY,CAACO,MAAM,CAACC,MAAM,CAACpC,SAAS,CAAC,CAAC;MACtC+B,UAAU,CAAC,KAAK,CAAC;IACnB,CAAC,EAAE,GAAG,CAAC;AAEP,IAAA,OAAO,MAAMM,YAAY,CAACJ,KAAK,CAAC;EAClC,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IAAEN,SAAS;AAAEG,IAAAA;GAAS;AAC/B;AAGO,MAAMQ,mBAAmB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quantabit/dao-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "QuantaBit DAO SDK - Decentralized governance, voting mechanisms and proposal execution",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.esm.js",
|
|
8
|
+
"types": "types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./types/index.d.ts",
|
|
12
|
+
"import": "./dist/index.esm.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": [
|
|
17
|
+
"*.css"
|
|
18
|
+
],
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"types",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "rollup -c",
|
|
27
|
+
"dev": "rollup -c -w",
|
|
28
|
+
"test": "jest --passWithNoTests",
|
|
29
|
+
"prepublishOnly": "npm run build"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/quantabit-chain/qbit-sdk.git",
|
|
34
|
+
"directory": "packages/dao-sdk"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"dao",
|
|
38
|
+
"governance",
|
|
39
|
+
"voting",
|
|
40
|
+
"proposal",
|
|
41
|
+
"web3",
|
|
42
|
+
"react",
|
|
43
|
+
"quantabit"
|
|
44
|
+
],
|
|
45
|
+
"author": "QuantaBit Team",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18.0.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"react": ">=17.0.0",
|
|
52
|
+
"react-dom": ">=17.0.0"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@quantabit/sdk-config": "^1.0.10"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
},
|
|
60
|
+
"qbit": {
|
|
61
|
+
"privacy": {
|
|
62
|
+
"level": "functional",
|
|
63
|
+
"dataCollection": "Queries voting power and proposals. No PII collected.",
|
|
64
|
+
"gdprCompliant": true,
|
|
65
|
+
"ccpaCompliant": true
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"homepage": "https://github.com/quantabit-chain/qbit-sdk/tree/main/packages/dao-sdk#readme",
|
|
69
|
+
"bugs": {
|
|
70
|
+
"url": "https://github.com/quantabit-chain/qbit-sdk/issues"
|
|
71
|
+
}
|
|
72
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export interface Proposal {
|
|
2
|
+
id: string;
|
|
3
|
+
title: string;
|
|
4
|
+
description: string;
|
|
5
|
+
forVotes: number;
|
|
6
|
+
againstVotes: number;
|
|
7
|
+
quorum: number;
|
|
8
|
+
status: string;
|
|
9
|
+
actions: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ProposalCreationResult {
|
|
13
|
+
proposalId: string;
|
|
14
|
+
title: string;
|
|
15
|
+
description: string;
|
|
16
|
+
actions: string[];
|
|
17
|
+
status: string;
|
|
18
|
+
forVotes: number;
|
|
19
|
+
againstVotes: number;
|
|
20
|
+
quorum: number;
|
|
21
|
+
message: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface VoteResult {
|
|
25
|
+
txHash: string;
|
|
26
|
+
proposalId: string;
|
|
27
|
+
support: boolean;
|
|
28
|
+
votingPower: number;
|
|
29
|
+
status: string;
|
|
30
|
+
message: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ExecutionResult {
|
|
34
|
+
txHash: string;
|
|
35
|
+
proposalId: string;
|
|
36
|
+
status: string;
|
|
37
|
+
message: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function createDaoProposal(title: string, description: string, actions?: string[]): Promise<ProposalCreationResult>;
|
|
41
|
+
export function castVote(proposalId: string, support: boolean, votingPower: number): Promise<VoteResult>;
|
|
42
|
+
export function executeDaoProposal(proposalId: string): Promise<ExecutionResult>;
|
|
43
|
+
export function getProposalStatus(proposalId: string): Promise<Proposal>;
|
|
44
|
+
|
|
45
|
+
export function useDaoProposals(): {
|
|
46
|
+
proposals: Proposal[];
|
|
47
|
+
loading: boolean;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export function getLanguage(): string;
|
|
51
|
+
export function setLanguage(lang: string): void;
|
|
52
|
+
export function t(key: string): string;
|
|
53
|
+
export const SUPPORTED_LANGUAGES: string[];
|
|
54
|
+
export const messages: Record<string, Record<string, string>>;
|