@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
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { base64ToUtf8, contractJson, parsePreservingBigNumbers, toId, toU128, utf8ToBase64 } from "./serialization.js";
|
|
2
|
+
import { TGAS, isValidAccountId } from "./units.js";
|
|
3
|
+
function allows(role, accountId, action) {
|
|
4
|
+
const member = role.kind === "Everyone" ||
|
|
5
|
+
("Group" in role.kind && role.kind.Group.includes(accountId)) ||
|
|
6
|
+
("Member" in role.kind && role.kind.Member === accountId);
|
|
7
|
+
return member && role.permissions.some((p) => p === `*:${action}` || p === `call:${action}` || p === "*:*");
|
|
8
|
+
}
|
|
9
|
+
export function canSubmit(policy, accountId) {
|
|
10
|
+
return policy.roles.some((role) => allows(role, accountId, "AddProposal"));
|
|
11
|
+
}
|
|
12
|
+
export function canVote(policy, accountId) {
|
|
13
|
+
return policy.roles.some((role) => allows(role, accountId, "VoteApprove"));
|
|
14
|
+
}
|
|
15
|
+
export function proposalBond(policy) {
|
|
16
|
+
return toU128(policy.proposal_bond);
|
|
17
|
+
}
|
|
18
|
+
export function approvalCount(proposal) {
|
|
19
|
+
return Object.values(proposal.votes).filter((vote) => vote === "Approve").length;
|
|
20
|
+
}
|
|
21
|
+
export function decodeProposalAction(proposal) {
|
|
22
|
+
const call = proposal.kind.FunctionCall;
|
|
23
|
+
const action = call?.actions[0];
|
|
24
|
+
if (!call || !action)
|
|
25
|
+
return null;
|
|
26
|
+
let args = null;
|
|
27
|
+
try {
|
|
28
|
+
args = parsePreservingBigNumbers(base64ToUtf8(action.args));
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
args = null;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
receiverId: call.receiver_id,
|
|
35
|
+
method: action.method_name,
|
|
36
|
+
args,
|
|
37
|
+
deposit: toU128(action.deposit),
|
|
38
|
+
gas: BigInt(action.gas),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function governanceCalls(daoId, contractId) {
|
|
42
|
+
const propose = (action, options) => ({
|
|
43
|
+
receiverId: daoId,
|
|
44
|
+
method: "add_proposal",
|
|
45
|
+
args: {
|
|
46
|
+
proposal: {
|
|
47
|
+
description: options.description,
|
|
48
|
+
kind: {
|
|
49
|
+
FunctionCall: {
|
|
50
|
+
receiver_id: action.receiverId,
|
|
51
|
+
actions: [
|
|
52
|
+
{
|
|
53
|
+
method_name: action.method,
|
|
54
|
+
args: utf8ToBase64(contractJson(action.args)),
|
|
55
|
+
deposit: action.deposit.toString(),
|
|
56
|
+
gas: action.gas.toString(),
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
deposit: toU128(options.bond),
|
|
64
|
+
gas: 50n * TGAS,
|
|
65
|
+
});
|
|
66
|
+
const vote = (proposal, action) => ({
|
|
67
|
+
receiverId: daoId,
|
|
68
|
+
method: "act_proposal",
|
|
69
|
+
args: { id: toId(proposal.id, "proposal id"), action, proposal: proposal.kind, memo: null },
|
|
70
|
+
deposit: 0n,
|
|
71
|
+
gas: 300n * TGAS,
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
propose,
|
|
75
|
+
proposeFundRound(input, options) {
|
|
76
|
+
const budget = toU128(input.budget);
|
|
77
|
+
if (budget === 0n)
|
|
78
|
+
throw new RangeError("budget must be greater than zero");
|
|
79
|
+
if (input.voterNamespace !== undefined && !isValidAccountId(input.voterNamespace)) {
|
|
80
|
+
throw new RangeError(`${input.voterNamespace} is not a valid NEAR account id`);
|
|
81
|
+
}
|
|
82
|
+
const args = {
|
|
83
|
+
config: {
|
|
84
|
+
budget,
|
|
85
|
+
opens_at: toId(input.opensAt, "opensAt"),
|
|
86
|
+
closes_at: toId(input.closesAt, "closesAt"),
|
|
87
|
+
t_min: toId(input.tMin ?? 0, "tMin"),
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
if (input.voterNamespace !== undefined)
|
|
91
|
+
args.voter_namespace = input.voterNamespace;
|
|
92
|
+
return propose({ receiverId: contractId, method: "fund_round", args, deposit: budget, gas: 100n * TGAS }, options);
|
|
93
|
+
},
|
|
94
|
+
proposeMilestonePayment(input, options) {
|
|
95
|
+
return propose({
|
|
96
|
+
receiverId: contractId,
|
|
97
|
+
method: "attest_milestone",
|
|
98
|
+
args: {
|
|
99
|
+
round_id: toId(input.roundId, "round id"),
|
|
100
|
+
project_id: toId(input.projectId, "project id"),
|
|
101
|
+
milestone_index: toId(input.milestoneIndex, "milestone index"),
|
|
102
|
+
},
|
|
103
|
+
deposit: 0n,
|
|
104
|
+
gas: 150n * TGAS,
|
|
105
|
+
}, options);
|
|
106
|
+
},
|
|
107
|
+
proposeReturnRemaining(roundId, options) {
|
|
108
|
+
return propose({ receiverId: contractId, method: "return_remaining", args: { round_id: toId(roundId, "round id") }, deposit: 0n, gas: 50n * TGAS }, options);
|
|
109
|
+
},
|
|
110
|
+
vote,
|
|
111
|
+
approve: (proposal) => vote(proposal, "VoteApprove"),
|
|
112
|
+
reject: (proposal) => vote(proposal, "VoteReject"),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=governance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"governance.js","sourceRoot":"","sources":["../src/governance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,yBAAyB,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvH,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAoEpD,SAAS,MAAM,CAAC,IAAgB,EAAE,SAAiB,EAAE,MAAc;IACjE,MAAM,MAAM,GACV,IAAI,CAAC,IAAI,KAAK,UAAU;QACxB,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC7D,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC;IAC5D,OAAO,MAAM,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,MAAM,EAAE,IAAI,CAAC,KAAK,QAAQ,MAAM,EAAE,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC;AAC9G,CAAC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EAAE,YAAY,CAAC;oBAC/C,eAAe,EAAE,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,iBAAiB,CAAC;iBAC/D;gBACD,OAAO,EAAE,EAAE;gBACX,GAAG,EAAE,IAAI,GAAG,IAAI;aACjB,EACD,OAAO,CACR,CAAC;QACJ,CAAC;QAED,sBAAsB,CAAC,OAAe,EAAE,OAAwB;YAC9D,OAAO,OAAO,CACZ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,EAAE,EACnI,OAAO,CACR,CAAC;QACJ,CAAC;QAED,IAAI;QACJ,OAAO,EAAE,CAAC,QAAqB,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC;QACjE,MAAM,EAAE,CAAC,QAAqB,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC;KAChE,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { DEFAULT_COUNTING_STEPS, polestarCalls, type PolestarCalls, type RegisterProjectInput } from "./calls.js";
|
|
2
|
+
export { DEFAULT_TESTNET_RPC, PolestarClient, PolestarGovernanceReader, PolestarGovernanceWriter, PolestarWriter, mapAllocationResult, mapProject, mapRound, sendTransaction, type CountingOptions, type CountingProgress, type CountingResult, type PolestarClientOptions, } from "./client.js";
|
|
3
|
+
export { isDirectSubAccount, voterStatus, type EligibilityRound, type VoterStatus } from "./eligibility.js";
|
|
4
|
+
export { ContractError, ContractPanicError, ERROR_CODES, NetworkError, PolestarError, TransactionCancelledError, TransactionOutcomeUnknownError, ViewError, classifySendError, errorCode, readOutcome, } from "./errors.js";
|
|
5
|
+
export { parseEvent, parseEvents, type PolestarEvent, type PolestarEventType } from "./events.js";
|
|
6
|
+
export { approvalCount, canSubmit, canVote, decodeProposalAction, governanceCalls, proposalBond, type DaoPolicy, type DaoProposal, type DecodedAction, type FundRoundInput, type GovernanceCalls, type MilestonePaymentInput, type PolicyRole, type ProposalAction, type ProposalKind, type ProposalOptions, type ProposalStatus, type VoteAction, } from "./governance.js";
|
|
7
|
+
export { rpcBlock, rpcView, type BlockFn, type ViewFn } from "./rpc.js";
|
|
8
|
+
export { base64ToUtf8, contractJson, parsePreservingBigNumbers, toId, toU128, utf8ToBase64 } from "./serialization.js";
|
|
9
|
+
export type * from "./types.js";
|
|
10
|
+
export { NEAR_DECIMALS, TGAS, YOCTO_PER_NEAR, formatNearAmount, isValidAccountId, parseNear } from "./units.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { DEFAULT_COUNTING_STEPS, polestarCalls } from "./calls.js";
|
|
2
|
+
export { DEFAULT_TESTNET_RPC, PolestarClient, PolestarGovernanceReader, PolestarGovernanceWriter, PolestarWriter, mapAllocationResult, mapProject, mapRound, sendTransaction, } from "./client.js";
|
|
3
|
+
export { isDirectSubAccount, voterStatus } from "./eligibility.js";
|
|
4
|
+
export { ContractError, ContractPanicError, ERROR_CODES, NetworkError, PolestarError, TransactionCancelledError, TransactionOutcomeUnknownError, ViewError, classifySendError, errorCode, readOutcome, } from "./errors.js";
|
|
5
|
+
export { parseEvent, parseEvents } from "./events.js";
|
|
6
|
+
export { approvalCount, canSubmit, canVote, decodeProposalAction, governanceCalls, proposalBond, } from "./governance.js";
|
|
7
|
+
export { rpcBlock, rpcView } from "./rpc.js";
|
|
8
|
+
export { base64ToUtf8, contractJson, parsePreservingBigNumbers, toId, toU128, utf8ToBase64 } from "./serialization.js";
|
|
9
|
+
export { NEAR_DECIMALS, TGAS, YOCTO_PER_NEAR, formatNearAmount, isValidAccountId, parseNear } from "./units.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAiD,MAAM,YAAY,CAAC;AAClH,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,wBAAwB,EACxB,wBAAwB,EACxB,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,QAAQ,EACR,eAAe,GAKhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAA2C,MAAM,kBAAkB,CAAC;AAC5G,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,yBAAyB,EACzB,8BAA8B,EAC9B,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,WAAW,EAA8C,MAAM,aAAa,CAAC;AAClG,OAAO,EACL,aAAa,EACb,SAAS,EACT,OAAO,EACP,oBAAoB,EACpB,eAAe,EACf,YAAY,GAab,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAA6B,MAAM,UAAU,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,yBAAyB,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvH,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { actions } from "near-api-js";
|
|
2
|
+
export function fromNearApiAccount(account) {
|
|
3
|
+
return {
|
|
4
|
+
accountId: account.accountId,
|
|
5
|
+
signAndSendTransaction: ({ receiverId, actions: calls }) => account.signAndSendTransaction({
|
|
6
|
+
receiverId,
|
|
7
|
+
actions: calls.map((call) => actions.functionCall(call.params.methodName, call.params.args, BigInt(call.params.gas), BigInt(call.params.deposit))),
|
|
8
|
+
throwOnFailure: false,
|
|
9
|
+
}),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=near-api-js.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"near-api-js.js","sourceRoot":"","sources":["../src/near-api-js.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAgB,MAAM,aAAa,CAAC;AAGpD,MAAM,UAAU,kBAAkB,CAAC,OAAgB;IACjD,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,sBAAsB,EAAE,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CACzD,OAAO,CAAC,sBAAsB,CAAC;YAC7B,UAAU;YACV,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAC1B,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CACrH;YACD,cAAc,EAAE,KAAK;SACtB,CAAC;KACL,CAAC;AACJ,CAAC"}
|
package/dist/rpc.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Block } from "./types.js";
|
|
2
|
+
export type ViewFn = (method: string, args: Record<string, unknown>, contractId: string) => Promise<unknown>;
|
|
3
|
+
export type BlockFn = (ref: "final" | number) => Promise<Block>;
|
|
4
|
+
export declare function rpcView(rpcUrl: string, fetchImpl?: typeof fetch): ViewFn;
|
|
5
|
+
export declare function rpcBlock(rpcUrl: string, fetchImpl?: typeof fetch): BlockFn;
|
package/dist/rpc.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ContractPanicError, ViewError } from "./errors.js";
|
|
2
|
+
import { parsePreservingBigNumbers, utf8ToBase64 } from "./serialization.js";
|
|
3
|
+
function panicMessage(raw) {
|
|
4
|
+
return /panic_msg: "([^"]*)"/.exec(raw)?.[1] ?? raw;
|
|
5
|
+
}
|
|
6
|
+
async function post(rpcUrl, fetchImpl, label, body) {
|
|
7
|
+
let res;
|
|
8
|
+
try {
|
|
9
|
+
res = await fetchImpl(rpcUrl, {
|
|
10
|
+
method: "POST",
|
|
11
|
+
headers: { "Content-Type": "application/json" },
|
|
12
|
+
body: JSON.stringify(body),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
throw new ViewError(`${label}: ${error instanceof Error ? error.message : String(error)}`);
|
|
17
|
+
}
|
|
18
|
+
if (!res.ok)
|
|
19
|
+
throw new ViewError(`${label}: RPC request failed (${res.status})`);
|
|
20
|
+
return res.json();
|
|
21
|
+
}
|
|
22
|
+
export function rpcView(rpcUrl, fetchImpl = globalThis.fetch) {
|
|
23
|
+
return async (method, args, contractId) => {
|
|
24
|
+
const body = (await post(rpcUrl, fetchImpl, method, {
|
|
25
|
+
jsonrpc: "2.0",
|
|
26
|
+
id: "polestar-sdk",
|
|
27
|
+
method: "query",
|
|
28
|
+
params: {
|
|
29
|
+
request_type: "call_function",
|
|
30
|
+
finality: "optimistic",
|
|
31
|
+
account_id: contractId,
|
|
32
|
+
method_name: method,
|
|
33
|
+
args_base64: utf8ToBase64(JSON.stringify(args)),
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
if (body.error) {
|
|
37
|
+
if (body.error.cause?.name === "CONTRACT_EXECUTION_ERROR") {
|
|
38
|
+
throw new ContractPanicError(method, panicMessage(body.error.cause.info?.error_message ?? ""));
|
|
39
|
+
}
|
|
40
|
+
throw new ViewError(`${method}: ${body.error.cause?.name ?? body.error.message ?? "unknown RPC error"}`);
|
|
41
|
+
}
|
|
42
|
+
if (body.result?.error !== undefined)
|
|
43
|
+
throw new ContractPanicError(method, panicMessage(body.result.error));
|
|
44
|
+
if (!body.result?.result)
|
|
45
|
+
throw new ViewError(`${method}: malformed RPC response`);
|
|
46
|
+
const text = new TextDecoder().decode(Uint8Array.from(body.result.result));
|
|
47
|
+
return text ? parsePreservingBigNumbers(text) : undefined;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function rpcBlock(rpcUrl, fetchImpl = globalThis.fetch) {
|
|
51
|
+
return async (ref) => {
|
|
52
|
+
const body = (await post(rpcUrl, fetchImpl, "block", {
|
|
53
|
+
jsonrpc: "2.0",
|
|
54
|
+
id: "polestar-sdk",
|
|
55
|
+
method: "block",
|
|
56
|
+
params: ref === "final" ? { finality: "final" } : { block_id: ref },
|
|
57
|
+
}));
|
|
58
|
+
if (!body.result)
|
|
59
|
+
throw new ViewError("block: malformed RPC response");
|
|
60
|
+
const { height, timestamp_nanosec } = body.result.header;
|
|
61
|
+
return { height, timestampMs: Number(BigInt(timestamp_nanosec) / 1000000n) };
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=rpc.js.map
|
package/dist/rpc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAW7E,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC;AACtD,CAAC;AAED,KAAK,UAAU,IAAI,CAAC,MAAc,EAAE,SAAuB,EAAE,KAAa,EAAE,IAAa;IACvF,IAAI,GAAa,CAAC;IAClB,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,SAAS,CAAC,MAAM,EAAE;Y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AC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,SAAS,CAAC,+BAA+B,CAAC,CAAC;QACvE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QACzD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,GAAG,QAAU,CAAC,EAAE,CAAC;IACjF,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function contractJson(value: unknown, indent?: number): string;
|
|
2
|
+
export declare function parsePreservingBigNumbers(json: string): unknown;
|
|
3
|
+
export declare function utf8ToBase64(text: string): string;
|
|
4
|
+
export declare function base64ToUtf8(encoded: string): string;
|
|
5
|
+
export declare function toU128(value: bigint | string | number): bigint;
|
|
6
|
+
export declare function toId(value: unknown, what?: string): number;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const MAX_U128 = (1n << 128n) - 1n;
|
|
2
|
+
export function contractJson(value, indent) {
|
|
3
|
+
const json = JSON.stringify(value, (_key, v) => (typeof v === "bigint" ? `__big__${v}` : v), indent);
|
|
4
|
+
return json.replace(/"__big__(-?\d+)"/g, "$1");
|
|
5
|
+
}
|
|
6
|
+
export function parsePreservingBigNumbers(json) {
|
|
7
|
+
const trimmed = json.trim();
|
|
8
|
+
if (/^\d{16,}$/.test(trimmed))
|
|
9
|
+
return trimmed;
|
|
10
|
+
return JSON.parse(json.replace(/(?<=[:,[])(\d{16,})(?=[,}\]])/g, '"$1"'));
|
|
11
|
+
}
|
|
12
|
+
export function utf8ToBase64(text) {
|
|
13
|
+
let binary = "";
|
|
14
|
+
new TextEncoder().encode(text).forEach((byte) => (binary += String.fromCharCode(byte)));
|
|
15
|
+
return btoa(binary);
|
|
16
|
+
}
|
|
17
|
+
export function base64ToUtf8(encoded) {
|
|
18
|
+
const binary = atob(encoded);
|
|
19
|
+
return new TextDecoder().decode(Uint8Array.from(binary, (c) => c.charCodeAt(0)));
|
|
20
|
+
}
|
|
21
|
+
export function toU128(value) {
|
|
22
|
+
const big = typeof value === "bigint" ? value : BigInt(value);
|
|
23
|
+
if (big < 0n || big > MAX_U128)
|
|
24
|
+
throw new RangeError(`${value} is outside the u128 range`);
|
|
25
|
+
return big;
|
|
26
|
+
}
|
|
27
|
+
export function toId(value, what = "id") {
|
|
28
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
29
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
30
|
+
throw new RangeError(`${what} ${String(value)} is not a safe non-negative integer`);
|
|
31
|
+
return n;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=serialization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.js","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAAA,MAAM,QAAQ,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;AAEnC,MAAM,UAAU,YAAY,CAAC,KAAc,EAAE,MAAe;IAC1D,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACrG,OAAO,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,IAAY;IACpD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5B,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IAC9C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,gCAAgC,EAAE,MAAM,CAAC,CAAC,CAAC;AAC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qC,CAAC,CAAC;IAC3H,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export type RoundPhase = "Registration" | "Declaration" | "Allocation" | "Settlement";
|
|
2
|
+
export type ProjectStatus = "Pending" | "Funded" | "Unfunded";
|
|
3
|
+
export type FundingStage = "Mes" | "Completion";
|
|
4
|
+
export interface RoundConfig {
|
|
5
|
+
budget: bigint;
|
|
6
|
+
opensAt: number;
|
|
7
|
+
closesAt: number;
|
|
8
|
+
tMin: number;
|
|
9
|
+
}
|
|
10
|
+
export interface Round {
|
|
11
|
+
id: number;
|
|
12
|
+
config: RoundConfig;
|
|
13
|
+
phase: RoundPhase;
|
|
14
|
+
remaining: bigint;
|
|
15
|
+
remainingReturned: boolean;
|
|
16
|
+
voterNamespace: string | null;
|
|
17
|
+
projectCount: number;
|
|
18
|
+
ballotCount: number;
|
|
19
|
+
}
|
|
20
|
+
export interface Milestone {
|
|
21
|
+
amount: bigint;
|
|
22
|
+
attested: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface Project {
|
|
25
|
+
id: number;
|
|
26
|
+
proposer: string;
|
|
27
|
+
recipient: string;
|
|
28
|
+
title: string;
|
|
29
|
+
summary: string;
|
|
30
|
+
cost: bigint;
|
|
31
|
+
milestones: Milestone[];
|
|
32
|
+
status: ProjectStatus;
|
|
33
|
+
}
|
|
34
|
+
export interface Ballot {
|
|
35
|
+
voter: string;
|
|
36
|
+
approved: number[];
|
|
37
|
+
}
|
|
38
|
+
export interface FundingRecord {
|
|
39
|
+
project: number;
|
|
40
|
+
stage: FundingStage;
|
|
41
|
+
amount: bigint;
|
|
42
|
+
}
|
|
43
|
+
export interface AllocationResult {
|
|
44
|
+
budget: bigint;
|
|
45
|
+
funded: FundingRecord[];
|
|
46
|
+
unfunded: number[];
|
|
47
|
+
remaining: bigint;
|
|
48
|
+
}
|
|
49
|
+
export interface Block {
|
|
50
|
+
height: number;
|
|
51
|
+
timestampMs: number;
|
|
52
|
+
}
|
|
53
|
+
export interface ChainClock extends Block {
|
|
54
|
+
msPerBlock: number | null;
|
|
55
|
+
}
|
|
56
|
+
export interface Transaction {
|
|
57
|
+
receiverId: string;
|
|
58
|
+
method: string;
|
|
59
|
+
args: Record<string, unknown>;
|
|
60
|
+
deposit: bigint;
|
|
61
|
+
gas: bigint;
|
|
62
|
+
}
|
|
63
|
+
export interface TransactionOutcome {
|
|
64
|
+
hash: string | null;
|
|
65
|
+
logs: string[];
|
|
66
|
+
value: unknown;
|
|
67
|
+
}
|
|
68
|
+
export interface FunctionCallAction {
|
|
69
|
+
type: "FunctionCall";
|
|
70
|
+
params: {
|
|
71
|
+
methodName: string;
|
|
72
|
+
args: Uint8Array;
|
|
73
|
+
gas: string;
|
|
74
|
+
deposit: string;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export interface RawOutcome {
|
|
78
|
+
transaction?: {
|
|
79
|
+
hash?: string;
|
|
80
|
+
};
|
|
81
|
+
transaction_outcome?: {
|
|
82
|
+
id?: string;
|
|
83
|
+
};
|
|
84
|
+
receipts_outcome?: {
|
|
85
|
+
outcome?: {
|
|
86
|
+
logs?: string[];
|
|
87
|
+
};
|
|
88
|
+
}[];
|
|
89
|
+
status?: {
|
|
90
|
+
SuccessValue?: string;
|
|
91
|
+
Failure?: unknown;
|
|
92
|
+
} | string;
|
|
93
|
+
}
|
|
94
|
+
export interface Signer {
|
|
95
|
+
accountId?: string;
|
|
96
|
+
signAndSendTransaction(transaction: {
|
|
97
|
+
receiverId: string;
|
|
98
|
+
actions: FunctionCallAction[];
|
|
99
|
+
}): Promise<unknown>;
|
|
100
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/units.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const NEAR_DECIMALS = 24;
|
|
2
|
+
export declare const YOCTO_PER_NEAR: bigint;
|
|
3
|
+
export declare const TGAS: bigint;
|
|
4
|
+
export declare function parseNear(input: string): bigint | null;
|
|
5
|
+
export declare function formatNearAmount(yocto: bigint | string | number, options?: {
|
|
6
|
+
exact?: boolean;
|
|
7
|
+
}): string;
|
|
8
|
+
export declare function isValidAccountId(id: string): boolean;
|
package/dist/units.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const NEAR_DECIMALS = 24;
|
|
2
|
+
export const YOCTO_PER_NEAR = 10n ** BigInt(NEAR_DECIMALS);
|
|
3
|
+
export const TGAS = 10n ** 12n;
|
|
4
|
+
const NAMED_ACCOUNT = /^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/;
|
|
5
|
+
export function parseNear(input) {
|
|
6
|
+
const text = input.trim();
|
|
7
|
+
const match = /^(\d+)(?:\.(\d*))?$/.exec(text) ?? /^()\.(\d+)$/.exec(text);
|
|
8
|
+
if (!match)
|
|
9
|
+
return null;
|
|
10
|
+
const [, whole, frac = ""] = match;
|
|
11
|
+
if (frac.length > NEAR_DECIMALS)
|
|
12
|
+
return null;
|
|
13
|
+
return BigInt(whole || "0") * YOCTO_PER_NEAR + BigInt(frac.padEnd(NEAR_DECIMALS, "0") || "0");
|
|
14
|
+
}
|
|
15
|
+
export function formatNearAmount(yocto, options = {}) {
|
|
16
|
+
const value = typeof yocto === "bigint" ? yocto : BigInt(yocto);
|
|
17
|
+
const negative = value < 0n;
|
|
18
|
+
const abs = negative ? -value : value;
|
|
19
|
+
const whole = abs / YOCTO_PER_NEAR;
|
|
20
|
+
const frac = (abs % YOCTO_PER_NEAR)
|
|
21
|
+
.toString()
|
|
22
|
+
.padStart(NEAR_DECIMALS, "0")
|
|
23
|
+
.slice(0, options.exact ? NEAR_DECIMALS : 5);
|
|
24
|
+
const trimmed = frac.replace(/0+$/, "").padEnd(2, "0");
|
|
25
|
+
return `${negative ? "-" : ""}${whole.toLocaleString("en-US")}.${trimmed}`;
|
|
26
|
+
}
|
|
27
|
+
export function isValidAccountId(id) {
|
|
28
|
+
if (id.length < 2 || id.length > 64)
|
|
29
|
+
return false;
|
|
30
|
+
return NAMED_ACCOUNT.test(id) || /^[0-9a-f]{64}$/.test(id) || /^0x[0-9a-f]{40}$/.test(id);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=units.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"units.js","sourceRoot":"","sources":["../src/units.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAChC,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,CAAC;AAC3D,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,IAAI,GAAG,CAAC;AAE/B,MAAM,aAAa,GAAG,uDAAuD,CAAC;AAE9E,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1B,MAAM,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3E,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC;IACnC,IAAI,IAAI,CAAC,MAAM,GAAG,aAAa;QAAE,OAAO,IAAI,CAAC;IAC7C,OAAO,MAAM,CAAC,KAAK,IAAI,GAAG,CAAC,GAAG,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC;AAChG,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAA+B,EAAE,UAA+B,EAAE;IACjG,MAAM,KAAK,GAAG,OAAO,KA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3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript client for Polestar participatory budgeting on NEAR",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/maelstrom0x8/polestar.git",
|
|
9
|
+
"directory": "packages/sdk"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/maelstrom0x8/polestar/tree/main/packages/sdk#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/maelstrom0x8/polestar/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"near",
|
|
17
|
+
"sputnik-dao",
|
|
18
|
+
"participatory-budgeting",
|
|
19
|
+
"dao",
|
|
20
|
+
"method-of-equal-shares"
|
|
21
|
+
],
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"type": "module",
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=20.12.0"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"default": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./near-api-js": {
|
|
38
|
+
"types": "./dist/near-api-js.d.ts",
|
|
39
|
+
"default": "./dist/near-api-js.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc -p tsconfig.build.json",
|
|
44
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"prepublishOnly": "npm run build && npm test"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"near-api-js": ">=7.4.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"near-api-js": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/node": "^24.13.3",
|
|
58
|
+
"near-api-js": "7.4.0",
|
|
59
|
+
"typescript": "~6.0.2",
|
|
60
|
+
"vitest": "^5.0.0"
|
|
61
|
+
},
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
}
|
|
65
|
+
}
|