@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 ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/README.md CHANGED
@@ -1,3 +1,172 @@
1
- # Temporary Holding Version
1
+ # @ezeonlabs/polestar
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A TypeScript client for Polestar, participatory budgeting for SputnikDAO treasuries on NEAR. It reads rounds, projects and results without a wallet. It builds and sends every Polestar transaction, with amounts encoded exactly. And it prepares the SputnikDAO proposals a council approves to fund rounds and pay milestones.
4
+
5
+ It has no runtime dependencies, works in browsers and Node.js 20.12+, and doesn't tie you to a wallet.
6
+
7
+ ## What you can build
8
+
9
+ - **Membership issuers.** A round can be limited to direct sub-accounts of a named account, such as `*.guild.near`. An app that creates those accounts for vouched-for members decides who can vote, with no change to Polestar.
10
+ - **Keeper bots.** Anyone can end voting and run the count once voting closes. [`examples/keeper.mjs`](https://github.com/maelstrom0x8/polestar/blob/main/packages/sdk/examples/keeper.mjs) does both.
11
+ - **Council and treasury tools.** Prepare "fund a round", "pay a milestone" and "return unspent budget" proposals from scripts, scheduled jobs or another treasury interface.
12
+ - **Community front-ends and alerts.** Show a community's rounds on its own site, or post "voting is open" and "results are in" from the contract's event logs.
13
+ - **Dashboards.** Turnout, funded and unfunded projects, payment progress per project.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ npm install @ezeonlabs/polestar
19
+ ```
20
+
21
+ To work from a clone of the repository instead:
22
+
23
+ ```bash
24
+ cd packages/sdk
25
+ npm install
26
+ npm run build
27
+ ```
28
+
29
+ ## Read without a wallet
30
+
31
+ ```ts
32
+ import { PolestarClient, formatNearAmount } from "@ezeonlabs/polestar";
33
+
34
+ const polestar = new PolestarClient({
35
+ contractId: "budgeting.polestar-dev.testnet",
36
+ daoId: "dao.polestar-dev.testnet",
37
+ });
38
+
39
+ const round = await polestar.getRound(3);
40
+ const projects = await polestar.getProjects(3);
41
+ const result = await polestar.getAllocationResult(3);
42
+
43
+ console.log(round?.phase, formatNearAmount(round!.config.budget));
44
+ ```
45
+
46
+ | Method | Returns |
47
+ | --- | --- |
48
+ | `getRoundCount()` | Number of rounds ever created; ids run from `0` |
49
+ | `getRound(id)`, `getRoundPhase(id)` | A round, or `null` |
50
+ | `getProjects(roundId)`, `getProject(roundId, projectId)` | Projects with their milestones and status |
51
+ | `getProjectSupport(roundId, projectId)` | How many ballots approved the project |
52
+ | `getBallot(roundId, voter)` | A voter's ballot, or `null` |
53
+ | `getFirstSeen(accountId)` | Block at which the account registered, or `null` |
54
+ | `getAllocationResult(roundId)`, `getRemaining(roundId)` | The count's result and leftover budget |
55
+ | `getBlock()`, `getChainClock()` | Chain head, and the measured time per block for converting block heights to dates |
56
+ | `governance.getPolicy()`, `governance.getOpenProposals()` | The DAO's policy and its open proposals that call Polestar |
57
+
58
+ There is no "list all rounds" call: the contract exposes rounds one at a time. For many rounds, read `getRoundCount()` and fetch the ids you need.
59
+
60
+ Some old rounds can't be decoded by newer contract builds. Reading one throws `ContractPanicError`; skip it.
61
+
62
+ ## Write with a signer
63
+
64
+ `client.withSigner(signer)` returns a writer. A signer is anything with `signAndSendTransaction({ receiverId, actions })`.
65
+
66
+ **Browser wallets** through `@hot-labs/near-connect` already have that shape:
67
+
68
+ ```ts
69
+ const { wallet } = await connector.getConnectedWallet();
70
+ const writer = polestar.withSigner({
71
+ signAndSendTransaction: (tx) => wallet.signAndSendTransaction(tx as never),
72
+ });
73
+ await writer.submitBallot(3, [0, 2]);
74
+ ```
75
+
76
+ **Servers and bots** use a near-api-js account:
77
+
78
+ ```ts
79
+ import { Account, JsonRpcProvider } from "near-api-js";
80
+ import { fromNearApiAccount } from "@ezeonlabs/polestar/near-api-js";
81
+
82
+ const account = new Account("keeper.testnet", new JsonRpcProvider({ url: "https://test.rpc.fastnear.com" }), privateKey);
83
+ const writer = polestar.withSigner(fromNearApiAccount(account));
84
+ ```
85
+
86
+ | Writer method | What it does |
87
+ | --- | --- |
88
+ | `registerVoter()` | One-time registration that makes an account eligible for rounds opening later |
89
+ | `registerProject({ roundId, recipient, title, summary, milestones, deposit })` | Proposes a project; the cost is the sum of `milestones` |
90
+ | `submitBallot(roundId, projectIds)` | Approves any number of projects |
91
+ | `startVoting(roundId)`, `endVoting(roundId)` | Moves a round into and out of voting; anyone can call these |
92
+ | `processAllocationSteps(roundId, maxSteps?)` | Runs as many counting steps as fit in one transaction |
93
+ | `runCounting(roundId, { onProgress, signal })` | Repeats the above until the results are in |
94
+
95
+ Every writer method has a pure builder on `polestar.calls` (for example `polestar.calls.submitBallot(3, [0, 2])`) that returns the exact transaction without sending it. Use it to show people what they are about to sign.
96
+
97
+ ## DAO actions are proposals
98
+
99
+ Three operations can only be carried out by the DAO itself: funding a round, paying a milestone and returning unspent budget. The SDK never offers them as direct calls. It prepares the SputnikDAO proposal, and the DAO's members approve it under their own rules.
100
+
101
+ ```ts
102
+ await writer.governance.proposeFundRound(
103
+ { budget: parseNear("5")!, opensAt, closesAt, voterNamespace: "guild.near" },
104
+ { description: "May round for the guild" },
105
+ );
106
+
107
+ const [proposal] = await polestar.governance.getOpenProposals();
108
+ await writer.governance.approve(proposal);
109
+ ```
110
+
111
+ - The proposal bond is read from the DAO's policy unless you pass `bond`.
112
+ - Leaving out `voterNamespace` creates a round anyone registered can vote in.
113
+ - `approve` and `reject` send the vote the way SputnikDAO requires, echoing the proposal so a vote can't land on a different one.
114
+ - Submitting a proposal does not fund anything. Funding happens when the proposal is approved, and the bond is returned once it's decided.
115
+
116
+ ## Amounts and precision
117
+
118
+ NEAR amounts are integers in yoctoNEAR (10⁻²⁴ NEAR), far beyond what a JavaScript `number` holds exactly. The contract also returns them as plain JSON numbers, so a normal `JSON.parse` silently corrupts them.
119
+
120
+ - Every amount the SDK returns or accepts is a `bigint`. Use `parseNear("1.25")` and `formatNearAmount(yocto)` to convert, with no floating point involved.
121
+ - Reads go through `parsePreservingBigNumbers`, which keeps any 16-digit or longer number as a string before converting it to `bigint`.
122
+ - Writes are encoded per method, the way the contract expects: `fund_round`'s budget as a bare integer, `register_project`'s amounts as decimal strings.
123
+ - Round and project ids are `number`s. The SDK throws if one is ever outside JavaScript's safe integer range.
124
+
125
+ ## Errors, and when not to retry
126
+
127
+ | Error | Meaning | Retry? |
128
+ | --- | --- | --- |
129
+ | `TransactionCancelledError` | The person closed the wallet or declined. Nothing was sent. | Yes, if they want to |
130
+ | `ContractError` | The contract refused. `error.code` is an `ERR_*` code; `ERROR_CODES[code]` explains it. Nothing changed. | Only after fixing the cause |
131
+ | `TransactionOutcomeUnknownError` | The transaction may have been sent, but no result came back. | **No.** Read the chain first: resending `registerProject` can create a duplicate project |
132
+ | `ViewError`, `ContractPanicError` | A read failed, or the contract panicked while reading | Reads are safe to retry |
133
+
134
+ ## Counting
135
+
136
+ When voting closes, anyone can end it and run the count. The count is deterministic: the same ballots always give the same result, however many transactions it takes. A typical round finishes in one `processAllocationSteps` call. `runCounting` keeps going until the contract reports the results are in, and stops early if you abort its `signal`.
137
+
138
+ It is not atomic. Each transaction is final on its own, and progress is saved between them.
139
+
140
+ ## Events
141
+
142
+ The contract logs one line per state change, for example `ProjectFunded round_id=3 project_id=1 stage=Mes amount=300000000000000000000000`. `parseEvents(outcome.logs)` turns them into `{ type, data }` objects.
143
+
144
+ The event types are: `RoundFunded`, `ProjectRegistered`, `DeclarationOpened`, `BallotSubmitted`, `DeclarationClosed`, `ProjectFunded`, `ProjectUnfunded`, `AllocationFinalized`, `MilestoneAttested`, `MilestoneReleaseFailed`, `RemainingReturned`, `RemainingReturnFailed`.
145
+
146
+ ## Eligibility
147
+
148
+ `voterStatus(round, accountId, firstSeen)` predicts whether an account can vote in a round: `"eligible"`, `"not-registered"`, `"too-late"` or `"not-member"`. It is an estimate for showing people where they stand; the contract makes the final decision.
149
+
150
+ Eligibility is a social threshold, not proof of a unique person. A namespace's owner can create as many sub-accounts as they like.
151
+
152
+ ## Examples
153
+
154
+ ```bash
155
+ npm run build
156
+ node examples/read-round.mjs --round 3
157
+ node examples/keeper.mjs
158
+ node examples/keeper.mjs --send --account keeper.testnet --watch 60
159
+ ```
160
+
161
+ The keeper runs dry unless you pass `--send`. It reads the signing key from `~/.near-credentials/testnet/<account>.json`, where the NEAR CLI stores keys.
162
+
163
+ ## Development
164
+
165
+ ```bash
166
+ npm test
167
+ npm run typecheck
168
+ ```
169
+
170
+ ## License
171
+
172
+ [Apache-2.0](LICENSE)
@@ -0,0 +1,20 @@
1
+ import type { Transaction } from "./types.js";
2
+ export declare const DEFAULT_COUNTING_STEPS = 100;
3
+ export interface RegisterProjectInput {
4
+ roundId: number;
5
+ recipient: string;
6
+ title: string;
7
+ summary: string;
8
+ milestones: bigint[];
9
+ deposit: bigint;
10
+ }
11
+ export declare function polestarCalls(contractId: string): {
12
+ registerVoter: () => Transaction;
13
+ registerProject(input: RegisterProjectInput): Transaction;
14
+ submitBallot(roundId: number, projectIds: number[]): Transaction;
15
+ startVoting: (roundId: number) => Transaction;
16
+ endVoting: (roundId: number) => Transaction;
17
+ processAllocationStep: (roundId: number) => Transaction;
18
+ processAllocationSteps(roundId: number, maxSteps?: number): Transaction;
19
+ };
20
+ export type PolestarCalls = ReturnType<typeof polestarCalls>;
package/dist/calls.js ADDED
@@ -0,0 +1,44 @@
1
+ import { toId, toU128 } from "./serialization.js";
2
+ import { TGAS } from "./units.js";
3
+ export const DEFAULT_COUNTING_STEPS = 100;
4
+ export function polestarCalls(contractId) {
5
+ const call = (method, args, gas, deposit = 0n) => ({
6
+ receiverId: contractId,
7
+ method,
8
+ args,
9
+ deposit,
10
+ gas,
11
+ });
12
+ const round = (roundId) => ({ round_id: toId(roundId, "round id") });
13
+ return {
14
+ registerVoter: () => call("register_voter", {}, 30n * TGAS),
15
+ registerProject(input) {
16
+ if (input.milestones.length === 0)
17
+ throw new RangeError("a project needs at least one milestone");
18
+ const amounts = input.milestones.map((m) => toU128(m));
19
+ const cost = toU128(amounts.reduce((sum, m) => sum + m, 0n));
20
+ return call("register_project", {
21
+ ...round(input.roundId),
22
+ recipient: input.recipient,
23
+ title: input.title,
24
+ summary: input.summary,
25
+ cost: cost.toString(),
26
+ milestone_amounts: amounts.map((m) => m.toString()),
27
+ }, 100n * TGAS, toU128(input.deposit));
28
+ },
29
+ submitBallot(roundId, projectIds) {
30
+ const approved = [...new Set(projectIds.map((id) => toId(id, "project id")))].sort((a, b) => a - b);
31
+ return call("submit_ballot", { ...round(roundId), approved }, 50n * TGAS);
32
+ },
33
+ startVoting: (roundId) => call("open_declaration", round(roundId), 300n * TGAS),
34
+ endVoting: (roundId) => call("close_declaration", round(roundId), 300n * TGAS),
35
+ processAllocationStep: (roundId) => call("process_allocation_step", round(roundId), 300n * TGAS),
36
+ processAllocationSteps(roundId, maxSteps = DEFAULT_COUNTING_STEPS) {
37
+ if (!Number.isInteger(maxSteps) || maxSteps < 1 || maxSteps > 0xffff_ffff) {
38
+ throw new RangeError("maxSteps must be an integer between 1 and 2^32 - 1");
39
+ }
40
+ return call("process_allocation_steps", { ...round(roundId), max_steps: maxSteps }, 300n * TGAS);
41
+ },
42
+ };
43
+ }
44
+ //# sourceMappingURL=calls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calls.js","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,148 @@
1
+ import { polestarCalls, type RegisterProjectInput } from "./calls.js";
2
+ import { governanceCalls, type DaoPolicy, type DaoProposal, type FundRoundInput, type MilestonePaymentInput } from "./governance.js";
3
+ import { type BlockFn, type ViewFn } from "./rpc.js";
4
+ import type { AllocationResult, Ballot, Block, ChainClock, FundingStage, Project, ProjectStatus, Round, RoundPhase, Signer, Transaction, TransactionOutcome } from "./types.js";
5
+ export declare const DEFAULT_TESTNET_RPC = "https://test.rpc.fastnear.com";
6
+ export interface PolestarClientOptions {
7
+ contractId: string;
8
+ daoId: string;
9
+ rpcUrl?: string;
10
+ fetch?: typeof fetch;
11
+ view?: ViewFn;
12
+ block?: BlockFn;
13
+ }
14
+ interface RoundRaw {
15
+ id: number | string;
16
+ config: {
17
+ budget: string | number;
18
+ opens_at: number | string;
19
+ closes_at: number | string;
20
+ t_min: number | string;
21
+ };
22
+ phase: RoundPhase;
23
+ remaining: string | number;
24
+ remaining_returned?: boolean;
25
+ voter_namespace?: string | null;
26
+ project_count: number | string;
27
+ ballot_count: number | string;
28
+ }
29
+ interface ProjectRaw {
30
+ id: number | string;
31
+ proposer: string;
32
+ recipient: string;
33
+ title: string;
34
+ summary: string;
35
+ cost: string | number;
36
+ milestones: {
37
+ amount: string | number;
38
+ attested: boolean;
39
+ }[];
40
+ status: ProjectStatus;
41
+ }
42
+ interface AllocationResultRaw {
43
+ budget: string | number;
44
+ funded: {
45
+ project: number | string;
46
+ stage: FundingStage;
47
+ amount: string | number;
48
+ }[];
49
+ unfunded: (number | string)[];
50
+ remaining: string | number;
51
+ }
52
+ export declare function mapRound(raw: RoundRaw): Round;
53
+ export declare function mapProject(raw: ProjectRaw): Project;
54
+ export declare function mapAllocationResult(raw: AllocationResultRaw): AllocationResult;
55
+ export declare function sendTransaction(signer: Signer, transaction: Transaction): Promise<TransactionOutcome>;
56
+ export declare class PolestarClient {
57
+ readonly contractId: string;
58
+ readonly daoId: string;
59
+ readonly calls: ReturnType<typeof polestarCalls>;
60
+ readonly governance: PolestarGovernanceReader;
61
+ private readonly viewFn;
62
+ private readonly blockFn;
63
+ constructor(options: PolestarClientOptions);
64
+ view<T>(method: string, args?: Record<string, unknown>, contractId?: string): Promise<T>;
65
+ getRoundCount(): Promise<number>;
66
+ getRound(roundId: number): Promise<Round | null>;
67
+ getRoundPhase(roundId: number): Promise<RoundPhase | null>;
68
+ getProjects(roundId: number): Promise<Project[]>;
69
+ getProject(roundId: number, projectId: number): Promise<Project | null>;
70
+ getProjectSupport(roundId: number, projectId: number): Promise<number>;
71
+ getBallot(roundId: number, voter: string): Promise<Ballot | null>;
72
+ getFirstSeen(accountId: string): Promise<number | null>;
73
+ getAllocationResult(roundId: number): Promise<AllocationResult | null>;
74
+ getRemaining(roundId: number): Promise<bigint | null>;
75
+ getBlock(ref?: "final" | number): Promise<Block>;
76
+ getChainClock(sampleSpan?: number): Promise<ChainClock>;
77
+ withSigner(signer: Signer): PolestarWriter;
78
+ }
79
+ export declare class PolestarGovernanceReader {
80
+ readonly calls: ReturnType<typeof governanceCalls>;
81
+ private readonly client;
82
+ constructor(client: PolestarClient);
83
+ getPolicy(): Promise<DaoPolicy>;
84
+ getOpenProposals(window?: number): Promise<DaoProposal[]>;
85
+ canSubmit(accountId: string): Promise<boolean>;
86
+ canVote(accountId: string): Promise<boolean>;
87
+ }
88
+ export interface CountingProgress {
89
+ transactions: number;
90
+ outcome: TransactionOutcome;
91
+ done: boolean;
92
+ }
93
+ export interface CountingOptions {
94
+ maxStepsPerTransaction?: number;
95
+ maxTransactions?: number;
96
+ signal?: AbortSignal;
97
+ onProgress?: (progress: CountingProgress) => void;
98
+ }
99
+ export interface CountingResult {
100
+ done: boolean;
101
+ transactions: number;
102
+ outcomes: TransactionOutcome[];
103
+ }
104
+ export declare class PolestarWriter {
105
+ readonly client: PolestarClient;
106
+ readonly signer: Signer;
107
+ readonly governance: PolestarGovernanceWriter;
108
+ constructor(client: PolestarClient, signer: Signer);
109
+ send(transaction: Transaction): Promise<TransactionOutcome>;
110
+ registerVoter(): Promise<TransactionOutcome>;
111
+ registerProject(input: RegisterProjectInput): Promise<{
112
+ projectId: number;
113
+ outcome: TransactionOutcome;
114
+ }>;
115
+ submitBallot(roundId: number, projectIds: number[]): Promise<TransactionOutcome>;
116
+ startVoting(roundId: number): Promise<TransactionOutcome>;
117
+ endVoting(roundId: number): Promise<TransactionOutcome>;
118
+ processAllocationStep(roundId: number): Promise<{
119
+ done: boolean;
120
+ outcome: TransactionOutcome;
121
+ }>;
122
+ processAllocationSteps(roundId: number, maxSteps?: number): Promise<{
123
+ done: boolean;
124
+ outcome: TransactionOutcome;
125
+ }>;
126
+ runCounting(roundId: number, options?: CountingOptions): Promise<CountingResult>;
127
+ }
128
+ export declare class PolestarGovernanceWriter {
129
+ private readonly writer;
130
+ constructor(writer: PolestarWriter);
131
+ private options;
132
+ private get calls();
133
+ proposeFundRound(input: FundRoundInput, options: {
134
+ description: string;
135
+ bond?: bigint;
136
+ }): Promise<TransactionOutcome>;
137
+ proposeMilestonePayment(input: MilestonePaymentInput, options: {
138
+ description: string;
139
+ bond?: bigint;
140
+ }): Promise<TransactionOutcome>;
141
+ proposeReturnRemaining(roundId: number, options: {
142
+ description: string;
143
+ bond?: bigint;
144
+ }): Promise<TransactionOutcome>;
145
+ approve(proposal: DaoProposal): Promise<TransactionOutcome>;
146
+ reject(proposal: DaoProposal): Promise<TransactionOutcome>;
147
+ }
148
+ export {};