@ezeonlabs/polestar 0.0.0-stage → 0.1.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 +176 -0
- package/README.md +171 -2
- package/dist/calls.d.ts +20 -0
- package/dist/calls.js +44 -0
- package/dist/calls.js.map +1 -0
- package/dist/client.d.ts +148 -0
- package/dist/client.js +249 -0
- package/dist/client.js.map +1 -0
- package/dist/eligibility.d.ts +10 -0
- package/dist/eligibility.js +16 -0
- package/dist/eligibility.js.map +1 -0
- package/dist/errors.d.ts +27 -0
- package/dist/errors.js +103 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +7 -0
- package/dist/events.js +34 -0
- package/dist/events.js.map +1 -0
- package/dist/governance.d.ts +78 -0
- package/dist/governance.js +115 -0
- package/dist/governance.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/near-api-js.d.ts +3 -0
- package/dist/near-api-js.js +12 -0
- package/dist/near-api-js.js.map +1 -0
- package/dist/rpc.d.ts +5 -0
- package/dist/rpc.js +64 -0
- package/dist/rpc.js.map +1 -0
- package/dist/serialization.d.ts +6 -0
- package/dist/serialization.js +33 -0
- package/dist/serialization.js.map +1 -0
- package/dist/types.d.ts +100 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/units.d.ts +8 -0
- package/dist/units.js +32 -0
- package/dist/units.js.map +1 -0
- package/package.json +63 -4
package/dist/client.js
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { DEFAULT_COUNTING_STEPS, polestarCalls } from "./calls.js";
|
|
2
|
+
import { classifySendError, readOutcome } from "./errors.js";
|
|
3
|
+
import { canSubmit, canVote, governanceCalls, proposalBond, } from "./governance.js";
|
|
4
|
+
import { rpcBlock, rpcView } from "./rpc.js";
|
|
5
|
+
import { contractJson, toId, toU128 } from "./serialization.js";
|
|
6
|
+
export const DEFAULT_TESTNET_RPC = "https://test.rpc.fastnear.com";
|
|
7
|
+
export function mapRound(raw) {
|
|
8
|
+
return {
|
|
9
|
+
id: toId(raw.id, "round id"),
|
|
10
|
+
config: {
|
|
11
|
+
budget: toU128(raw.config.budget),
|
|
12
|
+
opensAt: toId(raw.config.opens_at, "opens_at"),
|
|
13
|
+
closesAt: toId(raw.config.closes_at, "closes_at"),
|
|
14
|
+
tMin: toId(raw.config.t_min, "t_min"),
|
|
15
|
+
},
|
|
16
|
+
phase: raw.phase,
|
|
17
|
+
remaining: toU128(raw.remaining),
|
|
18
|
+
remainingReturned: raw.remaining_returned ?? false,
|
|
19
|
+
voterNamespace: raw.voter_namespace ?? null,
|
|
20
|
+
projectCount: toId(raw.project_count, "project_count"),
|
|
21
|
+
ballotCount: toId(raw.ballot_count, "ballot_count"),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function mapProject(raw) {
|
|
25
|
+
return {
|
|
26
|
+
id: toId(raw.id, "project id"),
|
|
27
|
+
proposer: raw.proposer,
|
|
28
|
+
recipient: raw.recipient,
|
|
29
|
+
title: raw.title,
|
|
30
|
+
summary: raw.summary,
|
|
31
|
+
cost: toU128(raw.cost),
|
|
32
|
+
milestones: raw.milestones.map((m) => ({ amount: toU128(m.amount), attested: m.attested })),
|
|
33
|
+
status: raw.status,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function mapAllocationResult(raw) {
|
|
37
|
+
return {
|
|
38
|
+
budget: toU128(raw.budget),
|
|
39
|
+
funded: raw.funded.map((f) => ({ project: toId(f.project, "project id"), stage: f.stage, amount: toU128(f.amount) })),
|
|
40
|
+
unfunded: raw.unfunded.map((id) => toId(id, "project id")),
|
|
41
|
+
remaining: toU128(raw.remaining),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export async function sendTransaction(signer, transaction) {
|
|
45
|
+
let raw;
|
|
46
|
+
try {
|
|
47
|
+
raw = await signer.signAndSendTransaction({
|
|
48
|
+
receiverId: transaction.receiverId,
|
|
49
|
+
actions: [
|
|
50
|
+
{
|
|
51
|
+
type: "FunctionCall",
|
|
52
|
+
params: {
|
|
53
|
+
methodName: transaction.method,
|
|
54
|
+
args: new TextEncoder().encode(contractJson(transaction.args)),
|
|
55
|
+
gas: transaction.gas.toString(),
|
|
56
|
+
deposit: transaction.deposit.toString(),
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw classifySendError(error);
|
|
64
|
+
}
|
|
65
|
+
return readOutcome((raw ?? {}));
|
|
66
|
+
}
|
|
67
|
+
export class PolestarClient {
|
|
68
|
+
contractId;
|
|
69
|
+
daoId;
|
|
70
|
+
calls;
|
|
71
|
+
governance;
|
|
72
|
+
viewFn;
|
|
73
|
+
blockFn;
|
|
74
|
+
constructor(options) {
|
|
75
|
+
const rpcUrl = options.rpcUrl ?? DEFAULT_TESTNET_RPC;
|
|
76
|
+
this.contractId = options.contractId;
|
|
77
|
+
this.daoId = options.daoId;
|
|
78
|
+
this.viewFn = options.view ?? rpcView(rpcUrl, options.fetch);
|
|
79
|
+
this.blockFn = options.block ?? rpcBlock(rpcUrl, options.fetch);
|
|
80
|
+
this.calls = polestarCalls(options.contractId);
|
|
81
|
+
this.governance = new PolestarGovernanceReader(this);
|
|
82
|
+
}
|
|
83
|
+
view(method, args = {}, contractId = this.contractId) {
|
|
84
|
+
return this.viewFn(method, args, contractId);
|
|
85
|
+
}
|
|
86
|
+
async getRoundCount() {
|
|
87
|
+
return toId(await this.view("get_round_count"), "round count");
|
|
88
|
+
}
|
|
89
|
+
async getRound(roundId) {
|
|
90
|
+
const raw = await this.view("get_round", { round_id: toId(roundId, "round id") });
|
|
91
|
+
return raw ? mapRound(raw) : null;
|
|
92
|
+
}
|
|
93
|
+
async getRoundPhase(roundId) {
|
|
94
|
+
return (await this.view("get_round_phase", { round_id: toId(roundId, "round id") })) ?? null;
|
|
95
|
+
}
|
|
96
|
+
async getProjects(roundId) {
|
|
97
|
+
const raw = await this.view("get_projects", { round_id: toId(roundId, "round id") });
|
|
98
|
+
return raw.map(mapProject);
|
|
99
|
+
}
|
|
100
|
+
async getProject(roundId, projectId) {
|
|
101
|
+
const raw = await this.view("get_project", {
|
|
102
|
+
round_id: toId(roundId, "round id"),
|
|
103
|
+
project_id: toId(projectId, "project id"),
|
|
104
|
+
});
|
|
105
|
+
return raw ? mapProject(raw) : null;
|
|
106
|
+
}
|
|
107
|
+
async getProjectSupport(roundId, projectId) {
|
|
108
|
+
const raw = await this.view("get_project_support", {
|
|
109
|
+
round_id: toId(roundId, "round id"),
|
|
110
|
+
project_id: toId(projectId, "project id"),
|
|
111
|
+
});
|
|
112
|
+
return toId(raw, "support count");
|
|
113
|
+
}
|
|
114
|
+
async getBallot(roundId, voter) {
|
|
115
|
+
const raw = await this.view("get_ballot", {
|
|
116
|
+
round_id: toId(roundId, "round id"),
|
|
117
|
+
voter,
|
|
118
|
+
});
|
|
119
|
+
return raw ? { voter: raw.voter, approved: raw.approved.map((id) => toId(id, "project id")) } : null;
|
|
120
|
+
}
|
|
121
|
+
async getFirstSeen(accountId) {
|
|
122
|
+
const raw = await this.view("get_first_seen", { account_id: accountId });
|
|
123
|
+
return raw === null || raw === undefined ? null : toId(raw, "block height");
|
|
124
|
+
}
|
|
125
|
+
async getAllocationResult(roundId) {
|
|
126
|
+
const raw = await this.view("get_allocation_result", { round_id: toId(roundId, "round id") });
|
|
127
|
+
return raw ? mapAllocationResult(raw) : null;
|
|
128
|
+
}
|
|
129
|
+
async getRemaining(roundId) {
|
|
130
|
+
const raw = await this.view("get_remaining", { round_id: toId(roundId, "round id") });
|
|
131
|
+
return raw === null || raw === undefined ? null : toU128(raw);
|
|
132
|
+
}
|
|
133
|
+
getBlock(ref = "final") {
|
|
134
|
+
return this.blockFn(ref);
|
|
135
|
+
}
|
|
136
|
+
async getChainClock(sampleSpan = 1_000) {
|
|
137
|
+
const head = await this.blockFn("final");
|
|
138
|
+
const past = await this.blockFn(head.height - sampleSpan).catch(() => null);
|
|
139
|
+
const msPerBlock = past ? (head.timestampMs - past.timestampMs) / (head.height - past.height) : null;
|
|
140
|
+
return { ...head, msPerBlock: msPerBlock && msPerBlock > 0 ? msPerBlock : null };
|
|
141
|
+
}
|
|
142
|
+
withSigner(signer) {
|
|
143
|
+
return new PolestarWriter(this, signer);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
export class PolestarGovernanceReader {
|
|
147
|
+
calls;
|
|
148
|
+
client;
|
|
149
|
+
constructor(client) {
|
|
150
|
+
this.client = client;
|
|
151
|
+
this.calls = governanceCalls(client.daoId, client.contractId);
|
|
152
|
+
}
|
|
153
|
+
getPolicy() {
|
|
154
|
+
return this.client.view("get_policy", {}, this.client.daoId);
|
|
155
|
+
}
|
|
156
|
+
async getOpenProposals(window = 50) {
|
|
157
|
+
const last = toId(await this.client.view("get_last_proposal_id", {}, this.client.daoId), "proposal id");
|
|
158
|
+
const from = Math.max(0, last - window);
|
|
159
|
+
const proposals = await this.client.view("get_proposals", { from_index: from, limit: window }, this.client.daoId);
|
|
160
|
+
return proposals
|
|
161
|
+
.filter((p) => p.status === "InProgress" && p.kind.FunctionCall?.receiver_id === this.client.contractId)
|
|
162
|
+
.sort((a, b) => b.id - a.id);
|
|
163
|
+
}
|
|
164
|
+
async canSubmit(accountId) {
|
|
165
|
+
return canSubmit(await this.getPolicy(), accountId);
|
|
166
|
+
}
|
|
167
|
+
async canVote(accountId) {
|
|
168
|
+
return canVote(await this.getPolicy(), accountId);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
export class PolestarWriter {
|
|
172
|
+
client;
|
|
173
|
+
signer;
|
|
174
|
+
governance;
|
|
175
|
+
constructor(client, signer) {
|
|
176
|
+
this.client = client;
|
|
177
|
+
this.signer = signer;
|
|
178
|
+
this.governance = new PolestarGovernanceWriter(this);
|
|
179
|
+
}
|
|
180
|
+
send(transaction) {
|
|
181
|
+
return sendTransaction(this.signer, transaction);
|
|
182
|
+
}
|
|
183
|
+
registerVoter() {
|
|
184
|
+
return this.send(this.client.calls.registerVoter());
|
|
185
|
+
}
|
|
186
|
+
async registerProject(input) {
|
|
187
|
+
const outcome = await this.send(this.client.calls.registerProject(input));
|
|
188
|
+
return { projectId: toId(outcome.value, "project id"), outcome };
|
|
189
|
+
}
|
|
190
|
+
submitBallot(roundId, projectIds) {
|
|
191
|
+
return this.send(this.client.calls.submitBallot(roundId, projectIds));
|
|
192
|
+
}
|
|
193
|
+
startVoting(roundId) {
|
|
194
|
+
return this.send(this.client.calls.startVoting(roundId));
|
|
195
|
+
}
|
|
196
|
+
endVoting(roundId) {
|
|
197
|
+
return this.send(this.client.calls.endVoting(roundId));
|
|
198
|
+
}
|
|
199
|
+
async processAllocationStep(roundId) {
|
|
200
|
+
const outcome = await this.send(this.client.calls.processAllocationStep(roundId));
|
|
201
|
+
return { done: outcome.value === true, outcome };
|
|
202
|
+
}
|
|
203
|
+
async processAllocationSteps(roundId, maxSteps = DEFAULT_COUNTING_STEPS) {
|
|
204
|
+
const outcome = await this.send(this.client.calls.processAllocationSteps(roundId, maxSteps));
|
|
205
|
+
return { done: outcome.value === true, outcome };
|
|
206
|
+
}
|
|
207
|
+
async runCounting(roundId, options = {}) {
|
|
208
|
+
const outcomes = [];
|
|
209
|
+
const limit = options.maxTransactions ?? Number.POSITIVE_INFINITY;
|
|
210
|
+
while (outcomes.length < limit) {
|
|
211
|
+
if (options.signal?.aborted)
|
|
212
|
+
return { done: false, transactions: outcomes.length, outcomes };
|
|
213
|
+
const { done, outcome } = await this.processAllocationSteps(roundId, options.maxStepsPerTransaction);
|
|
214
|
+
outcomes.push(outcome);
|
|
215
|
+
options.onProgress?.({ transactions: outcomes.length, outcome, done });
|
|
216
|
+
if (done)
|
|
217
|
+
return { done: true, transactions: outcomes.length, outcomes };
|
|
218
|
+
}
|
|
219
|
+
return { done: false, transactions: outcomes.length, outcomes };
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
export class PolestarGovernanceWriter {
|
|
223
|
+
writer;
|
|
224
|
+
constructor(writer) {
|
|
225
|
+
this.writer = writer;
|
|
226
|
+
}
|
|
227
|
+
async options(description, bond) {
|
|
228
|
+
return { description, bond: bond ?? proposalBond(await this.writer.client.governance.getPolicy()) };
|
|
229
|
+
}
|
|
230
|
+
get calls() {
|
|
231
|
+
return this.writer.client.governance.calls;
|
|
232
|
+
}
|
|
233
|
+
async proposeFundRound(input, options) {
|
|
234
|
+
return this.writer.send(this.calls.proposeFundRound(input, await this.options(options.description, options.bond)));
|
|
235
|
+
}
|
|
236
|
+
async proposeMilestonePayment(input, options) {
|
|
237
|
+
return this.writer.send(this.calls.proposeMilestonePayment(input, await this.options(options.description, options.bond)));
|
|
238
|
+
}
|
|
239
|
+
async proposeReturnRemaining(roundId, options) {
|
|
240
|
+
return this.writer.send(this.calls.proposeReturnRemaining(roundId, await this.options(options.description, options.bond)));
|
|
241
|
+
}
|
|
242
|
+
approve(proposal) {
|
|
243
|
+
return this.writer.send(this.calls.approve(proposal));
|
|
244
|
+
}
|
|
245
|
+
reject(proposal) {
|
|
246
|
+
return this.writer.send(this.calls.reject(proposal));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAA6B,MAAM,YAAY,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EACL,SAAS,EACT,OAAO,EACP,eAAe,EACf,YAAY,GAKb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAA6B,MAAM,UAAU,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM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CAAC,CAAC,CAAC,CAAC;IAC5H,CAAC;IAED,KAAK,CAAC,sBAAsB,CAAC,OAAe,EAAE,OAA+C;QAC3F,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7H,CAAC;IAED,OAAO,CAAC,QAAqB;QAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,CAAC,QAAqB;QAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvD,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type VoterStatus = "eligible" | "too-late" | "not-registered" | "not-member";
|
|
2
|
+
export interface EligibilityRound {
|
|
3
|
+
config: {
|
|
4
|
+
opensAt: number;
|
|
5
|
+
tMin: number;
|
|
6
|
+
};
|
|
7
|
+
voterNamespace: string | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function isDirectSubAccount(account: string, parent: string): boolean;
|
|
10
|
+
export declare function voterStatus(round: EligibilityRound, accountId: string, firstSeen: number | null): VoterStatus;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function isDirectSubAccount(account, parent) {
|
|
2
|
+
const suffix = `.${parent}`;
|
|
3
|
+
if (!account.endsWith(suffix))
|
|
4
|
+
return false;
|
|
5
|
+
const label = account.slice(0, -suffix.length);
|
|
6
|
+
return label.length > 0 && !label.includes(".");
|
|
7
|
+
}
|
|
8
|
+
export function voterStatus(round, accountId, firstSeen) {
|
|
9
|
+
if (round.voterNamespace && !isDirectSubAccount(accountId, round.voterNamespace))
|
|
10
|
+
return "not-member";
|
|
11
|
+
if (firstSeen === null)
|
|
12
|
+
return "not-registered";
|
|
13
|
+
const { opensAt, tMin } = round.config;
|
|
14
|
+
return firstSeen < opensAt && firstSeen + tMin <= opensAt ? "eligible" : "too-late";
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=eligibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eligibility.js","sourceRoot":"","sources":["../src/eligibility.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,kBAAkB,CAAC,OAAe,EAAE,MAAc;IAChE,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;IAC5B,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/C,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAuB,EAAE,SAAiB,EAAE,SAAwB;IAC9F,IAAI,KAAK,CAAC,cAAc,IAAI,CAAC,kBAAkB,CAAC,SAAS,EAAE,KAAK,CAAC,cAAc,CAAC;QAAE,OAAO,YAAY,CAAC;IACtG,IAAI,SAAS,KAAK,IAAI;QAAE,OAAO,gBAAgB,CAAC;IAChD,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC;IACvC,OAAO,SAAS,GAAG,OAAO,IAAI,SAAS,GAAG,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC;AACtF,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RawOutcome, TransactionOutcome } from "./types.js";
|
|
2
|
+
export declare class PolestarError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class ViewError extends PolestarError {
|
|
6
|
+
}
|
|
7
|
+
export declare class ContractPanicError extends ViewError {
|
|
8
|
+
readonly method: string;
|
|
9
|
+
readonly panic: string;
|
|
10
|
+
readonly code: string | null;
|
|
11
|
+
constructor(method: string, panic: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class TransactionCancelledError extends PolestarError {
|
|
14
|
+
}
|
|
15
|
+
export declare class ContractError extends PolestarError {
|
|
16
|
+
readonly code: string;
|
|
17
|
+
readonly raw: string;
|
|
18
|
+
constructor(code: string, raw: string);
|
|
19
|
+
}
|
|
20
|
+
export declare class NetworkError extends PolestarError {
|
|
21
|
+
}
|
|
22
|
+
export declare class TransactionOutcomeUnknownError extends PolestarError {
|
|
23
|
+
}
|
|
24
|
+
export declare const ERROR_CODES: Readonly<Record<string, string>>;
|
|
25
|
+
export declare function errorCode(text: string): string | null;
|
|
26
|
+
export declare function classifySendError(error: unknown): PolestarError;
|
|
27
|
+
export declare function readOutcome(raw: RawOutcome): TransactionOutcome;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { base64ToUtf8, parsePreservingBigNumbers } from "./serialization.js";
|
|
2
|
+
export class PolestarError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = new.target.name;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export class ViewError extends PolestarError {
|
|
9
|
+
}
|
|
10
|
+
export class ContractPanicError extends ViewError {
|
|
11
|
+
method;
|
|
12
|
+
panic;
|
|
13
|
+
code;
|
|
14
|
+
constructor(method, panic) {
|
|
15
|
+
super(`${method}: ${panic}`);
|
|
16
|
+
this.method = method;
|
|
17
|
+
this.panic = panic;
|
|
18
|
+
this.code = errorCode(panic);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class TransactionCancelledError extends PolestarError {
|
|
22
|
+
}
|
|
23
|
+
export class ContractError extends PolestarError {
|
|
24
|
+
code;
|
|
25
|
+
raw;
|
|
26
|
+
constructor(code, raw) {
|
|
27
|
+
super(`${code}: ${raw}`);
|
|
28
|
+
this.code = code;
|
|
29
|
+
this.raw = raw;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class NetworkError extends PolestarError {
|
|
33
|
+
}
|
|
34
|
+
export class TransactionOutcomeUnknownError extends PolestarError {
|
|
35
|
+
}
|
|
36
|
+
export const ERROR_CODES = {
|
|
37
|
+
ERR_NOT_SPUTNIK_DAO: "Only the configured SputnikDAO account can call this; submit it as a DAO proposal.",
|
|
38
|
+
ERR_DEPOSIT_MISMATCH: "fund_round must attach exactly the round's budget.",
|
|
39
|
+
ERR_INVALID_CONFIG: "closes_at must be after opens_at.",
|
|
40
|
+
ERR_ROUND_NOT_FOUND: "No round with this id.",
|
|
41
|
+
ERR_WRONG_PHASE: "The round is not in the stage this call needs.",
|
|
42
|
+
ERR_NO_DEPOSIT: "register_project needs a non-zero deposit.",
|
|
43
|
+
ERR_ZERO_COST: "A project's cost must be greater than zero.",
|
|
44
|
+
ERR_TITLE_TOO_LONG: "Title is longer than 200 bytes.",
|
|
45
|
+
ERR_SUMMARY_TOO_LONG: "Summary is longer than 2000 bytes.",
|
|
46
|
+
ERR_TOO_MANY_PROJECTS: "The round already has the maximum of 50 projects.",
|
|
47
|
+
ERR_MILESTONE_SUM_MISMATCH: "Milestone amounts must add up exactly to the cost.",
|
|
48
|
+
ERR_NO_PROJECTS: "Voting can only start once the round has a project.",
|
|
49
|
+
ERR_DECLARATION_CLOSED: "Voting has closed for this round.",
|
|
50
|
+
ERR_DECLARATION_NOT_YET_CLOSED: "Voting can only be ended after closes_at.",
|
|
51
|
+
ERR_NOT_IN_VOTER_NAMESPACE: "This round only accepts votes from direct sub-accounts of its voter namespace.",
|
|
52
|
+
ERR_ALREADY_VOTED: "This account has already voted in this round.",
|
|
53
|
+
ERR_EMPTY_APPROVAL: "A ballot must approve at least one project.",
|
|
54
|
+
ERR_UNREGISTERED_PROJECT: "A ballot named a project that is not in this round.",
|
|
55
|
+
ERR_NO_PRIOR_INTERACTION: "The account was not registered (register_voter or register_project) before opens_at.",
|
|
56
|
+
ERR_ACCOUNT_TOO_NEW: "The account registered later than opens_at minus t_min.",
|
|
57
|
+
ERR_INVALID_STEP_COUNT: "max_steps must be at least 1.",
|
|
58
|
+
ERR_PROJECT_NOT_FOUND: "No project with this id in the round.",
|
|
59
|
+
ERR_PROJECT_NOT_FUNDED: "Only funded projects have payable milestones.",
|
|
60
|
+
ERR_INVALID_MILESTONE_INDEX: "The project has no milestone at this index.",
|
|
61
|
+
ERR_ALREADY_ATTESTED: "This milestone has already been paid.",
|
|
62
|
+
ERR_ALREADY_RETURNED: "This round's remainder has already been returned.",
|
|
63
|
+
ERR_NOTHING_TO_RETURN: "This round has no unallocated budget.",
|
|
64
|
+
ERR_INSUFFICIENT_BALANCE: "The contract's available balance cannot cover this transfer.",
|
|
65
|
+
ERR_RATIONAL_OVERFLOW: "Allocation arithmetic overflowed; the round cannot be counted by this build.",
|
|
66
|
+
ERR_ALLOCATION_INVARIANT_VIOLATED: "An internal allocation invariant failed; report this.",
|
|
67
|
+
};
|
|
68
|
+
const CANCEL_PATTERN = /reject|cancel|denied|closed|user (?:closed|abort)/i;
|
|
69
|
+
export function errorCode(text) {
|
|
70
|
+
return /\b(ERR_[A-Z_]+)\b/.exec(text)?.[1] ?? null;
|
|
71
|
+
}
|
|
72
|
+
export function classifySendError(error) {
|
|
73
|
+
if (error instanceof PolestarError)
|
|
74
|
+
return error;
|
|
75
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
76
|
+
const code = errorCode(message);
|
|
77
|
+
if (code)
|
|
78
|
+
return new ContractError(code, message);
|
|
79
|
+
if (CANCEL_PATTERN.test(message))
|
|
80
|
+
return new TransactionCancelledError(message);
|
|
81
|
+
return new TransactionOutcomeUnknownError(message);
|
|
82
|
+
}
|
|
83
|
+
export function readOutcome(raw) {
|
|
84
|
+
const hash = raw.transaction?.hash ?? raw.transaction_outcome?.id ?? null;
|
|
85
|
+
const logs = (raw.receipts_outcome ?? []).flatMap((receipt) => receipt.outcome?.logs ?? []);
|
|
86
|
+
const status = raw.status;
|
|
87
|
+
if (status && typeof status === "object" && "Failure" in status && status.Failure !== undefined) {
|
|
88
|
+
const text = JSON.stringify(status.Failure);
|
|
89
|
+
throw new ContractError(errorCode(text) ?? "UNKNOWN", text);
|
|
90
|
+
}
|
|
91
|
+
let value = null;
|
|
92
|
+
const encoded = status && typeof status === "object" ? status.SuccessValue : undefined;
|
|
93
|
+
if (encoded) {
|
|
94
|
+
try {
|
|
95
|
+
value = parsePreservingBigNumbers(base64ToUtf8(encoded));
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
value = null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return { hash, logs, value };
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAG7E,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED,MAAM,OAAO,SAAU,SAAQ,aAAa;CAAG;AAE/C,MAAM,OAAO,kBAAmB,SAAQ,SAAS;IACtC,MAAM,CAAS;IACf,KAAK,CAAS;IACd,IAAI,CAAgB;IAE7B,YAAY,MAAc,EAAE,KAAa;QACvC,KAAK,CAAC,GAAG,MAAM,KAAK,KAAK,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC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AAE,CAAC,CAAC;IAC5F,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC1B,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,SAAS,IAAI,MAAM,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAChG,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC5C,MAAM,IAAI,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,SAAS,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;IACD,IAAI,KAAK,GAAY,IAAI,CAAC;IAC1B,MAAM,OAAO,GAAG,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;IACvF,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,CAAC;YACH,KAAK,GAAG,yBAAyB,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;QAC3D,CAAC;QAAC,MAAM,CAAC;YACP,KAAK,GAAG,IAAI,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC/B,CAAC"}
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type PolestarEventType = "RoundFunded" | "ProjectRegistered" | "DeclarationOpened" | "BallotSubmitted" | "DeclarationClosed" | "ProjectFunded" | "ProjectUnfunded" | "AllocationFinalized" | "MilestoneAttested" | "MilestoneReleaseFailed" | "RemainingReturned" | "RemainingReturnFailed";
|
|
2
|
+
export interface PolestarEvent {
|
|
3
|
+
type: PolestarEventType;
|
|
4
|
+
data: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
export declare function parseEvent(line: string): PolestarEvent | null;
|
|
7
|
+
export declare function parseEvents(logs: string[]): PolestarEvent[];
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const TYPES = new Set([
|
|
2
|
+
"RoundFunded",
|
|
3
|
+
"ProjectRegistered",
|
|
4
|
+
"DeclarationOpened",
|
|
5
|
+
"BallotSubmitted",
|
|
6
|
+
"DeclarationClosed",
|
|
7
|
+
"ProjectFunded",
|
|
8
|
+
"ProjectUnfunded",
|
|
9
|
+
"AllocationFinalized",
|
|
10
|
+
"MilestoneAttested",
|
|
11
|
+
"MilestoneReleaseFailed",
|
|
12
|
+
"RemainingReturned",
|
|
13
|
+
"RemainingReturnFailed",
|
|
14
|
+
]);
|
|
15
|
+
export function parseEvent(line) {
|
|
16
|
+
const [type, ...pairs] = line.trim().split(/\s+/);
|
|
17
|
+
if (!type || !TYPES.has(type))
|
|
18
|
+
return null;
|
|
19
|
+
const data = {};
|
|
20
|
+
for (const pair of pairs) {
|
|
21
|
+
const eq = pair.indexOf("=");
|
|
22
|
+
if (eq <= 0)
|
|
23
|
+
return null;
|
|
24
|
+
data[pair.slice(0, eq)] = pair.slice(eq + 1);
|
|
25
|
+
}
|
|
26
|
+
return { type: type, data };
|
|
27
|
+
}
|
|
28
|
+
export function parseEvents(logs) {
|
|
29
|
+
return logs.flatMap((line) => {
|
|
30
|
+
const event = parseEvent(line);
|
|
31
|
+
return event ? [event] : [];
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAmBA,MAAM,KAAK,GAAG,IAAI,GAAG,CAAS;IAC5B,aAAa;IACb,mBAAmB;IACnB,mBAAmB;IACnB,iBAAiB;IACjB,mBAAmB;IACnB,eAAe;IACf,iBAAiB;IACjB,qBAAqB;IACrB,mBAAmB;IACnB,wBAAwB;IACxB,mBAAmB;IACnB,uBAAuB;CACxB,CAAC,CAAC;AAEH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,MAAM,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClD,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3C,MAAM,IAAI,GAA2B,EAAE,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,EAAE,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,IAAyB,EAAE,IAAI,EAAE,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAc;IACxC,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3B,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QAC/B,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Transaction } from "./types.js";
|
|
2
|
+
export interface PolicyRole {
|
|
3
|
+
name: string;
|
|
4
|
+
kind: "Everyone" | {
|
|
5
|
+
Group: string[];
|
|
6
|
+
} | {
|
|
7
|
+
Member: string;
|
|
8
|
+
};
|
|
9
|
+
permissions: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface DaoPolicy {
|
|
12
|
+
roles: PolicyRole[];
|
|
13
|
+
proposal_bond: string;
|
|
14
|
+
[field: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
export interface ProposalAction {
|
|
17
|
+
method_name: string;
|
|
18
|
+
args: string;
|
|
19
|
+
deposit: string;
|
|
20
|
+
gas: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ProposalKind {
|
|
23
|
+
FunctionCall?: {
|
|
24
|
+
receiver_id: string;
|
|
25
|
+
actions: ProposalAction[];
|
|
26
|
+
};
|
|
27
|
+
[other: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
export type ProposalStatus = "InProgress" | "Approved" | "Rejected" | "Removed" | "Expired" | "Moved" | "Failed";
|
|
30
|
+
export interface DaoProposal {
|
|
31
|
+
id: number;
|
|
32
|
+
proposer: string;
|
|
33
|
+
description: string;
|
|
34
|
+
kind: ProposalKind;
|
|
35
|
+
status: ProposalStatus;
|
|
36
|
+
vote_counts: Record<string, string[]>;
|
|
37
|
+
votes: Record<string, string>;
|
|
38
|
+
[field: string]: unknown;
|
|
39
|
+
}
|
|
40
|
+
export interface DecodedAction {
|
|
41
|
+
receiverId: string;
|
|
42
|
+
method: string;
|
|
43
|
+
args: Record<string, unknown> | null;
|
|
44
|
+
deposit: bigint;
|
|
45
|
+
gas: bigint;
|
|
46
|
+
}
|
|
47
|
+
export interface FundRoundInput {
|
|
48
|
+
budget: bigint;
|
|
49
|
+
opensAt: number;
|
|
50
|
+
closesAt: number;
|
|
51
|
+
tMin?: number;
|
|
52
|
+
voterNamespace?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface MilestonePaymentInput {
|
|
55
|
+
roundId: number;
|
|
56
|
+
projectId: number;
|
|
57
|
+
milestoneIndex: number;
|
|
58
|
+
}
|
|
59
|
+
export interface ProposalOptions {
|
|
60
|
+
description: string;
|
|
61
|
+
bond: bigint;
|
|
62
|
+
}
|
|
63
|
+
export type VoteAction = "VoteApprove" | "VoteReject" | "VoteRemove";
|
|
64
|
+
export declare function canSubmit(policy: DaoPolicy, accountId: string): boolean;
|
|
65
|
+
export declare function canVote(policy: DaoPolicy, accountId: string): boolean;
|
|
66
|
+
export declare function proposalBond(policy: DaoPolicy): bigint;
|
|
67
|
+
export declare function approvalCount(proposal: DaoProposal): number;
|
|
68
|
+
export declare function decodeProposalAction(proposal: DaoProposal): DecodedAction | null;
|
|
69
|
+
export declare function governanceCalls(daoId: string, contractId: string): {
|
|
70
|
+
propose: (action: Transaction, options: ProposalOptions) => Transaction;
|
|
71
|
+
proposeFundRound(input: FundRoundInput, options: ProposalOptions): Transaction;
|
|
72
|
+
proposeMilestonePayment(input: MilestonePaymentInput, options: ProposalOptions): Transaction;
|
|
73
|
+
proposeReturnRemaining(roundId: number, options: ProposalOptions): Transaction;
|
|
74
|
+
vote: (proposal: DaoProposal, action: VoteAction) => Transaction;
|
|
75
|
+
approve: (proposal: DaoProposal) => Transaction;
|
|
76
|
+
reject: (proposal: DaoProposal) => Transaction;
|
|
77
|
+
};
|
|
78
|
+
export type GovernanceCalls = ReturnType<typeof governanceCalls>;
|