@alephium/powfi-sdk 0.0.1-rc.1

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.
Files changed (146) hide show
  1. package/README.md +4 -0
  2. package/clmm/artifacts/BitmapWord.ral.json +125 -0
  3. package/clmm/artifacts/BitmapWordDeployer.ral.json +31 -0
  4. package/clmm/artifacts/CreateConfig.ral.json +37 -0
  5. package/clmm/artifacts/CreateLiquidPool.ral.json +55 -0
  6. package/clmm/artifacts/DexAccount.ral.json +110 -0
  7. package/clmm/artifacts/LiquidityAmountsTest.ral.json +161 -0
  8. package/clmm/artifacts/LiquidityManagmentTest.ral.json +384 -0
  9. package/clmm/artifacts/Pool.ral.json +1530 -0
  10. package/clmm/artifacts/PoolConfig.ral.json +31 -0
  11. package/clmm/artifacts/PoolFactory.ral.json +300 -0
  12. package/clmm/artifacts/PoolRouterDemo.ral.json +49 -0
  13. package/clmm/artifacts/PoolUser.ral.json +89 -0
  14. package/clmm/artifacts/Position.ral.json +183 -0
  15. package/clmm/artifacts/PositionManager.ral.json +416 -0
  16. package/clmm/artifacts/SwapWithoutAccount.ral.json +46 -0
  17. package/clmm/artifacts/TestToken.ral.json +68 -0
  18. package/clmm/artifacts/Tick.ral.json +161 -0
  19. package/clmm/artifacts/TickBitmapTest.ral.json +220 -0
  20. package/clmm/artifacts/constants.ral.json +81 -0
  21. package/clmm/artifacts/structs.ral.json +335 -0
  22. package/clmm/artifacts/ts/BitmapWord.ts +337 -0
  23. package/clmm/artifacts/ts/BitmapWordDeployer.ts +164 -0
  24. package/clmm/artifacts/ts/DexAccount.ts +330 -0
  25. package/clmm/artifacts/ts/LiquidityAmountsTest.ts +464 -0
  26. package/clmm/artifacts/ts/LiquidityManagmentTest.ts +859 -0
  27. package/clmm/artifacts/ts/Pool.ts +2535 -0
  28. package/clmm/artifacts/ts/PoolConfig.ts +179 -0
  29. package/clmm/artifacts/ts/PoolFactory.ts +640 -0
  30. package/clmm/artifacts/ts/PoolUser.ts +237 -0
  31. package/clmm/artifacts/ts/Position.ts +440 -0
  32. package/clmm/artifacts/ts/PositionManager.ts +929 -0
  33. package/clmm/artifacts/ts/TestToken.ts +277 -0
  34. package/clmm/artifacts/ts/Tick.ts +351 -0
  35. package/clmm/artifacts/ts/TickBitmapTest.ts +512 -0
  36. package/clmm/artifacts/ts/constants.ts +17 -0
  37. package/clmm/artifacts/ts/contracts.ts +26 -0
  38. package/clmm/artifacts/ts/deployments.ts +160 -0
  39. package/clmm/artifacts/ts/index.ts +20 -0
  40. package/clmm/artifacts/ts/scripts.ts +76 -0
  41. package/clmm/artifacts/ts/types.ts +105 -0
  42. package/clmm/deployments/.deployments.devnet.json +350 -0
  43. package/clmm/deployments/.deployments.testnet.json +350 -0
  44. package/cpmm/artifacts/dex/DexAccount.ral.json +110 -0
  45. package/cpmm/artifacts/dex/Router.ral.json +361 -0
  46. package/cpmm/artifacts/dex/TokenPair.ral.json +512 -0
  47. package/cpmm/artifacts/dex/TokenPairFactory.ral.json +297 -0
  48. package/cpmm/artifacts/examples/ExampleOracleSimple.ral.json +192 -0
  49. package/cpmm/artifacts/examples/FeeCollectorFactoryImpl.ral.json +185 -0
  50. package/cpmm/artifacts/examples/FeeCollectorPerTokenPairImpl.ral.json +216 -0
  51. package/cpmm/artifacts/examples/FullMathTest.ral.json +123 -0
  52. package/cpmm/artifacts/scripts/AddLiquidity.ral.json +46 -0
  53. package/cpmm/artifacts/scripts/Burn.ral.json +31 -0
  54. package/cpmm/artifacts/scripts/CollectFee.ral.json +25 -0
  55. package/cpmm/artifacts/scripts/CreatePair.ral.json +37 -0
  56. package/cpmm/artifacts/scripts/CreatePairAndAddLiquidity.ral.json +43 -0
  57. package/cpmm/artifacts/scripts/EnableFeeCollector.ral.json +28 -0
  58. package/cpmm/artifacts/scripts/Mint.ral.json +34 -0
  59. package/cpmm/artifacts/scripts/RemoveLiquidity.ral.json +43 -0
  60. package/cpmm/artifacts/scripts/SetFeeCollectorFactory.ral.json +28 -0
  61. package/cpmm/artifacts/scripts/Swap.ral.json +46 -0
  62. package/cpmm/artifacts/scripts/SwapMaxIn.ral.json +46 -0
  63. package/cpmm/artifacts/scripts/SwapMinOut.ral.json +46 -0
  64. package/cpmm/artifacts/test/GetToken.ral.json +31 -0
  65. package/cpmm/artifacts/test/MathTest.ral.json +49 -0
  66. package/cpmm/artifacts/test/TestToken.ral.json +87 -0
  67. package/cpmm/artifacts/ts/DexAccount.ts +329 -0
  68. package/cpmm/artifacts/ts/ExampleOracleSimple.ts +383 -0
  69. package/cpmm/artifacts/ts/FeeCollectorFactoryImpl.ts +227 -0
  70. package/cpmm/artifacts/ts/FeeCollectorPerTokenPairImpl.ts +327 -0
  71. package/cpmm/artifacts/ts/FullMathTest.ts +251 -0
  72. package/cpmm/artifacts/ts/MathTest.ts +183 -0
  73. package/cpmm/artifacts/ts/Router.ts +554 -0
  74. package/cpmm/artifacts/ts/TestToken.ts +312 -0
  75. package/cpmm/artifacts/ts/TokenPair.ts +947 -0
  76. package/cpmm/artifacts/ts/TokenPairFactory.ts +501 -0
  77. package/cpmm/artifacts/ts/contracts.ts +26 -0
  78. package/cpmm/artifacts/ts/deployments.ts +109 -0
  79. package/cpmm/artifacts/ts/index.ts +16 -0
  80. package/cpmm/artifacts/ts/scripts.ts +142 -0
  81. package/cpmm/deployments/.deployments.devnet.json +77 -0
  82. package/cpmm/deployments/.deployments.testnet.json +79 -0
  83. package/lib/index.d.mts +8800 -0
  84. package/lib/index.d.ts +8800 -0
  85. package/lib/index.js +21769 -0
  86. package/lib/index.js.map +1 -0
  87. package/lib/index.mjs +22118 -0
  88. package/lib/index.mjs.map +1 -0
  89. package/package.json +80 -0
  90. package/src/clmm/clmm.ts +607 -0
  91. package/src/clmm/constants.ts +7 -0
  92. package/src/clmm/index.ts +6 -0
  93. package/src/clmm/liquidity.ts +163 -0
  94. package/src/clmm/pool.ts +154 -0
  95. package/src/clmm/tick.ts +335 -0
  96. package/src/clmm/types.ts +155 -0
  97. package/src/common/constants.ts +1 -0
  98. package/src/common/error.ts +46 -0
  99. package/src/common/index.ts +7 -0
  100. package/src/common/logger.ts +82 -0
  101. package/src/common/math.ts +88 -0
  102. package/src/common/numeric.ts +64 -0
  103. package/src/common/types.ts +49 -0
  104. package/src/common/utils.ts +3 -0
  105. package/src/cpmm/constants.ts +2 -0
  106. package/src/cpmm/cpmm.ts +631 -0
  107. package/src/cpmm/index.ts +3 -0
  108. package/src/cpmm/types.ts +113 -0
  109. package/src/index.ts +25 -0
  110. package/src/moduleBase.ts +64 -0
  111. package/src/staking/index.ts +4 -0
  112. package/src/staking/settings.ts +38 -0
  113. package/src/staking/staking.ts +277 -0
  114. package/src/staking/types.ts +15 -0
  115. package/src/staking/utils.ts +25 -0
  116. package/src/token/index.ts +1 -0
  117. package/src/token/token.ts +163 -0
  118. package/src/zeta.ts +105 -0
  119. package/staking/artifacts/AlphStakeAndLock.ral.json +31 -0
  120. package/staking/artifacts/AlphUnstakeVault.ral.json +151 -0
  121. package/staking/artifacts/XAlphStakeVault.ral.json +559 -0
  122. package/staking/artifacts/XAlphToken.ral.json +404 -0
  123. package/staking/artifacts/XAlphUnlockAndStartUnstake.ral.json +31 -0
  124. package/staking/artifacts/examples/GovernanceDemo.ral.json +282 -0
  125. package/staking/artifacts/examples/RewardSharingVault.ral.json +253 -0
  126. package/staking/artifacts/structs.ral.json +47 -0
  127. package/staking/artifacts/ts/AlphUnstakeVault.ts +354 -0
  128. package/staking/artifacts/ts/FullMathTest.ts +175 -0
  129. package/staking/artifacts/ts/GovernanceDemo.ts +726 -0
  130. package/staking/artifacts/ts/RewardSharingVault.ts +559 -0
  131. package/staking/artifacts/ts/TestDynamicArrayByteVec32.ts +431 -0
  132. package/staking/artifacts/ts/TestDynamicSortedArrayForU256.ts +516 -0
  133. package/staking/artifacts/ts/TestMerkleProof.ts +343 -0
  134. package/staking/artifacts/ts/XAlphStakeVault.ts +1120 -0
  135. package/staking/artifacts/ts/XAlphToken.ts +835 -0
  136. package/staking/artifacts/ts/contracts.ts +26 -0
  137. package/staking/artifacts/ts/deployments.ts +109 -0
  138. package/staking/artifacts/ts/index.ts +15 -0
  139. package/staking/artifacts/ts/scripts.ts +35 -0
  140. package/staking/artifacts/ts/types.ts +19 -0
  141. package/staking/artifacts/utils/FullMathTest.ral.json +57 -0
  142. package/staking/artifacts/utils/TestDynamicArrayByteVec32.ral.json +165 -0
  143. package/staking/artifacts/utils/TestDynamicSortedArrayForU256.ral.json +189 -0
  144. package/staking/artifacts/utils/TestMerkleProof.ral.json +134 -0
  145. package/staking/deployments/.deployments.devnet.json +77 -0
  146. package/staking/deployments/.deployments.testnet.json +78 -0
@@ -0,0 +1,726 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+
5
+ import {
6
+ Address,
7
+ Contract,
8
+ ContractState,
9
+ TestContractResult,
10
+ HexString,
11
+ ContractFactory,
12
+ EventSubscribeOptions,
13
+ EventSubscription,
14
+ CallContractParams,
15
+ CallContractResult,
16
+ TestContractParams,
17
+ ContractEvent,
18
+ subscribeContractEvent,
19
+ subscribeContractEvents,
20
+ testMethod,
21
+ callMethod,
22
+ multicallMethods,
23
+ fetchContractState,
24
+ Asset,
25
+ ContractInstance,
26
+ getContractEventsCurrentCount,
27
+ TestContractParamsWithoutMaps,
28
+ TestContractResultWithoutMaps,
29
+ SignExecuteContractMethodParams,
30
+ SignExecuteScriptTxResult,
31
+ signExecuteMethod,
32
+ addStdIdToFields,
33
+ encodeContractFields,
34
+ Narrow,
35
+ } from "@alephium/web3";
36
+ import { default as GovernanceDemoContractJson } from "../examples/GovernanceDemo.ral.json";
37
+ import { getContractByCodeHash, registerContract } from "./contracts";
38
+ import * as types from "./types";
39
+ import { RalphMap } from "@alephium/web3";
40
+
41
+ // Custom types for the contract
42
+ export namespace GovernanceDemoTypes {
43
+ export type Fields = {
44
+ xalphStakeVault: HexString;
45
+ proposalOptions: [bigint, bigint, bigint, bigint];
46
+ owner: Address;
47
+ totalVotedAmount: bigint;
48
+ votingStartTime: bigint;
49
+ votingEndTime: bigint;
50
+ };
51
+
52
+ export type State = ContractState<Fields>;
53
+
54
+ export type VotingStartedEvent = ContractEvent<{ votingStartTime: bigint }>;
55
+ export type VoteCastEvent = ContractEvent<{
56
+ voter: Address;
57
+ proposalVoted: bigint;
58
+ amount: bigint;
59
+ }>;
60
+ export type VotingEndedEvent = ContractEvent<{ votingEndTime: bigint }>;
61
+
62
+ export interface CallMethodTable {
63
+ onStake: {
64
+ params: CallContractParams<{ user: Address; addedAmount: bigint }>;
65
+ result: CallContractResult<null>;
66
+ };
67
+ onUnstake: {
68
+ params: CallContractParams<{ user: Address; removedAmount: bigint }>;
69
+ result: CallContractResult<null>;
70
+ };
71
+ startVoting: {
72
+ params: Omit<CallContractParams<{}>, "args">;
73
+ result: CallContractResult<null>;
74
+ };
75
+ endVoting: {
76
+ params: Omit<CallContractParams<{}>, "args">;
77
+ result: CallContractResult<null>;
78
+ };
79
+ getProposalOptions: {
80
+ params: Omit<CallContractParams<{}>, "args">;
81
+ result: CallContractResult<[bigint, bigint, bigint, bigint]>;
82
+ };
83
+ getUserVote: {
84
+ params: CallContractParams<{ user: Address }>;
85
+ result: CallContractResult<types.VoteInfo>;
86
+ };
87
+ getProposalVotes: {
88
+ params: CallContractParams<{ proposal: bigint }>;
89
+ result: CallContractResult<bigint>;
90
+ };
91
+ getTotalVotedAmount: {
92
+ params: Omit<CallContractParams<{}>, "args">;
93
+ result: CallContractResult<bigint>;
94
+ };
95
+ vote: {
96
+ params: CallContractParams<{ proposal: bigint }>;
97
+ result: CallContractResult<null>;
98
+ };
99
+ isVotingStarted: {
100
+ params: Omit<CallContractParams<{}>, "args">;
101
+ result: CallContractResult<boolean>;
102
+ };
103
+ isVotingEnded: {
104
+ params: Omit<CallContractParams<{}>, "args">;
105
+ result: CallContractResult<boolean>;
106
+ };
107
+ isVotingActive: {
108
+ params: Omit<CallContractParams<{}>, "args">;
109
+ result: CallContractResult<boolean>;
110
+ };
111
+ }
112
+ export type CallMethodParams<T extends keyof CallMethodTable> =
113
+ CallMethodTable[T]["params"];
114
+ export type CallMethodResult<T extends keyof CallMethodTable> =
115
+ CallMethodTable[T]["result"];
116
+ export type MultiCallParams = Partial<{
117
+ [Name in keyof CallMethodTable]: CallMethodTable[Name]["params"];
118
+ }>;
119
+ export type MultiCallResults<T extends MultiCallParams> = {
120
+ [MaybeName in keyof T]: MaybeName extends keyof CallMethodTable
121
+ ? CallMethodTable[MaybeName]["result"]
122
+ : undefined;
123
+ };
124
+ export type MulticallReturnType<Callss extends MultiCallParams[]> = {
125
+ [index in keyof Callss]: MultiCallResults<Callss[index]>;
126
+ };
127
+
128
+ export interface SignExecuteMethodTable {
129
+ onStake: {
130
+ params: SignExecuteContractMethodParams<{
131
+ user: Address;
132
+ addedAmount: bigint;
133
+ }>;
134
+ result: SignExecuteScriptTxResult;
135
+ };
136
+ onUnstake: {
137
+ params: SignExecuteContractMethodParams<{
138
+ user: Address;
139
+ removedAmount: bigint;
140
+ }>;
141
+ result: SignExecuteScriptTxResult;
142
+ };
143
+ startVoting: {
144
+ params: Omit<SignExecuteContractMethodParams<{}>, "args">;
145
+ result: SignExecuteScriptTxResult;
146
+ };
147
+ endVoting: {
148
+ params: Omit<SignExecuteContractMethodParams<{}>, "args">;
149
+ result: SignExecuteScriptTxResult;
150
+ };
151
+ getProposalOptions: {
152
+ params: Omit<SignExecuteContractMethodParams<{}>, "args">;
153
+ result: SignExecuteScriptTxResult;
154
+ };
155
+ getUserVote: {
156
+ params: SignExecuteContractMethodParams<{ user: Address }>;
157
+ result: SignExecuteScriptTxResult;
158
+ };
159
+ getProposalVotes: {
160
+ params: SignExecuteContractMethodParams<{ proposal: bigint }>;
161
+ result: SignExecuteScriptTxResult;
162
+ };
163
+ getTotalVotedAmount: {
164
+ params: Omit<SignExecuteContractMethodParams<{}>, "args">;
165
+ result: SignExecuteScriptTxResult;
166
+ };
167
+ vote: {
168
+ params: SignExecuteContractMethodParams<{ proposal: bigint }>;
169
+ result: SignExecuteScriptTxResult;
170
+ };
171
+ isVotingStarted: {
172
+ params: Omit<SignExecuteContractMethodParams<{}>, "args">;
173
+ result: SignExecuteScriptTxResult;
174
+ };
175
+ isVotingEnded: {
176
+ params: Omit<SignExecuteContractMethodParams<{}>, "args">;
177
+ result: SignExecuteScriptTxResult;
178
+ };
179
+ isVotingActive: {
180
+ params: Omit<SignExecuteContractMethodParams<{}>, "args">;
181
+ result: SignExecuteScriptTxResult;
182
+ };
183
+ }
184
+ export type SignExecuteMethodParams<T extends keyof SignExecuteMethodTable> =
185
+ SignExecuteMethodTable[T]["params"];
186
+ export type SignExecuteMethodResult<T extends keyof SignExecuteMethodTable> =
187
+ SignExecuteMethodTable[T]["result"];
188
+
189
+ export type Maps = {
190
+ userVotes?: Map<Address, types.VoteInfo>;
191
+ proposalVotes?: Map<bigint, bigint>;
192
+ };
193
+ }
194
+
195
+ class Factory extends ContractFactory<
196
+ GovernanceDemoInstance,
197
+ GovernanceDemoTypes.Fields
198
+ > {
199
+ encodeFields(fields: GovernanceDemoTypes.Fields) {
200
+ return encodeContractFields(
201
+ addStdIdToFields(this.contract, fields),
202
+ this.contract.fieldsSig,
203
+ types.AllStructs
204
+ );
205
+ }
206
+
207
+ eventIndex = { VotingStarted: 0, VoteCast: 1, VotingEnded: 2 };
208
+ consts = {
209
+ ErrorCodes: {
210
+ AssetAddressCallerOnly: BigInt("0"),
211
+ UserNotStaked: BigInt("1"),
212
+ InvalidVoteProposal: BigInt("2"),
213
+ VotingNotStarted: BigInt("3"),
214
+ VotingAlreadyStarted: BigInt("4"),
215
+ VotingAlreadyEnded: BigInt("5"),
216
+ AlreadyVoted: BigInt("6"),
217
+ OwnerOnly: BigInt("7"),
218
+ StakeVaultCallerOnly: BigInt("8"),
219
+ },
220
+ };
221
+
222
+ at(address: string): GovernanceDemoInstance {
223
+ return new GovernanceDemoInstance(address);
224
+ }
225
+
226
+ tests = {
227
+ onStake: async (
228
+ params: TestContractParams<
229
+ GovernanceDemoTypes.Fields,
230
+ { user: Address; addedAmount: bigint },
231
+ GovernanceDemoTypes.Maps
232
+ >
233
+ ): Promise<TestContractResult<null, GovernanceDemoTypes.Maps>> => {
234
+ return testMethod(this, "onStake", params, getContractByCodeHash);
235
+ },
236
+ onUnstake: async (
237
+ params: TestContractParams<
238
+ GovernanceDemoTypes.Fields,
239
+ { user: Address; removedAmount: bigint },
240
+ GovernanceDemoTypes.Maps
241
+ >
242
+ ): Promise<TestContractResult<null, GovernanceDemoTypes.Maps>> => {
243
+ return testMethod(this, "onUnstake", params, getContractByCodeHash);
244
+ },
245
+ startVoting: async (
246
+ params: Omit<
247
+ TestContractParams<
248
+ GovernanceDemoTypes.Fields,
249
+ never,
250
+ GovernanceDemoTypes.Maps
251
+ >,
252
+ "args"
253
+ >
254
+ ): Promise<TestContractResult<null, GovernanceDemoTypes.Maps>> => {
255
+ return testMethod(this, "startVoting", params, getContractByCodeHash);
256
+ },
257
+ endVoting: async (
258
+ params: Omit<
259
+ TestContractParams<
260
+ GovernanceDemoTypes.Fields,
261
+ never,
262
+ GovernanceDemoTypes.Maps
263
+ >,
264
+ "args"
265
+ >
266
+ ): Promise<TestContractResult<null, GovernanceDemoTypes.Maps>> => {
267
+ return testMethod(this, "endVoting", params, getContractByCodeHash);
268
+ },
269
+ getProposalOptions: async (
270
+ params: Omit<
271
+ TestContractParams<
272
+ GovernanceDemoTypes.Fields,
273
+ never,
274
+ GovernanceDemoTypes.Maps
275
+ >,
276
+ "args"
277
+ >
278
+ ): Promise<
279
+ TestContractResult<
280
+ [bigint, bigint, bigint, bigint],
281
+ GovernanceDemoTypes.Maps
282
+ >
283
+ > => {
284
+ return testMethod(
285
+ this,
286
+ "getProposalOptions",
287
+ params,
288
+ getContractByCodeHash
289
+ );
290
+ },
291
+ getUserVote: async (
292
+ params: TestContractParams<
293
+ GovernanceDemoTypes.Fields,
294
+ { user: Address },
295
+ GovernanceDemoTypes.Maps
296
+ >
297
+ ): Promise<
298
+ TestContractResult<types.VoteInfo, GovernanceDemoTypes.Maps>
299
+ > => {
300
+ return testMethod(this, "getUserVote", params, getContractByCodeHash);
301
+ },
302
+ getProposalVotes: async (
303
+ params: TestContractParams<
304
+ GovernanceDemoTypes.Fields,
305
+ { proposal: bigint },
306
+ GovernanceDemoTypes.Maps
307
+ >
308
+ ): Promise<TestContractResult<bigint, GovernanceDemoTypes.Maps>> => {
309
+ return testMethod(
310
+ this,
311
+ "getProposalVotes",
312
+ params,
313
+ getContractByCodeHash
314
+ );
315
+ },
316
+ getTotalVotedAmount: async (
317
+ params: Omit<
318
+ TestContractParams<
319
+ GovernanceDemoTypes.Fields,
320
+ never,
321
+ GovernanceDemoTypes.Maps
322
+ >,
323
+ "args"
324
+ >
325
+ ): Promise<TestContractResult<bigint, GovernanceDemoTypes.Maps>> => {
326
+ return testMethod(
327
+ this,
328
+ "getTotalVotedAmount",
329
+ params,
330
+ getContractByCodeHash
331
+ );
332
+ },
333
+ vote: async (
334
+ params: TestContractParams<
335
+ GovernanceDemoTypes.Fields,
336
+ { proposal: bigint },
337
+ GovernanceDemoTypes.Maps
338
+ >
339
+ ): Promise<TestContractResult<null, GovernanceDemoTypes.Maps>> => {
340
+ return testMethod(this, "vote", params, getContractByCodeHash);
341
+ },
342
+ isVotingStarted: async (
343
+ params: Omit<
344
+ TestContractParams<
345
+ GovernanceDemoTypes.Fields,
346
+ never,
347
+ GovernanceDemoTypes.Maps
348
+ >,
349
+ "args"
350
+ >
351
+ ): Promise<TestContractResult<boolean, GovernanceDemoTypes.Maps>> => {
352
+ return testMethod(this, "isVotingStarted", params, getContractByCodeHash);
353
+ },
354
+ isVotingEnded: async (
355
+ params: Omit<
356
+ TestContractParams<
357
+ GovernanceDemoTypes.Fields,
358
+ never,
359
+ GovernanceDemoTypes.Maps
360
+ >,
361
+ "args"
362
+ >
363
+ ): Promise<TestContractResult<boolean, GovernanceDemoTypes.Maps>> => {
364
+ return testMethod(this, "isVotingEnded", params, getContractByCodeHash);
365
+ },
366
+ isVotingActive: async (
367
+ params: Omit<
368
+ TestContractParams<
369
+ GovernanceDemoTypes.Fields,
370
+ never,
371
+ GovernanceDemoTypes.Maps
372
+ >,
373
+ "args"
374
+ >
375
+ ): Promise<TestContractResult<boolean, GovernanceDemoTypes.Maps>> => {
376
+ return testMethod(this, "isVotingActive", params, getContractByCodeHash);
377
+ },
378
+ };
379
+
380
+ stateForTest(
381
+ initFields: GovernanceDemoTypes.Fields,
382
+ asset?: Asset,
383
+ address?: string,
384
+ maps?: GovernanceDemoTypes.Maps
385
+ ) {
386
+ return this.stateForTest_(initFields, asset, address, maps);
387
+ }
388
+ }
389
+
390
+ // Use this object to test and deploy the contract
391
+ export const GovernanceDemo = new Factory(
392
+ Contract.fromJson(
393
+ GovernanceDemoContractJson,
394
+ "=6-2+e2=2+c=1-5=2-2=1-3+0=3-1+2=2-1+7=4+7=1+2f1=1-2=1+ff=2-1+c=3-1+d=3-2+e343f3=13-1+a=339-1+b=34+7a7e0214696e73657274206174206d617020706174683a2000=26-2+60=353-1+b=38+7a7e021472656d6f7665206174206d617020706174683a2000=19-1+5=91-1+6=48+7a7e0214696e73657274206174206d617020706174683a2000=25-1+6=878",
395
+ "551e89bdda9d4514effbfebcd14d1383bcfb9a8e1c10b78fda75c33aca894624",
396
+ types.AllStructs
397
+ )
398
+ );
399
+ registerContract(GovernanceDemo);
400
+
401
+ // Use this class to interact with the blockchain
402
+ export class GovernanceDemoInstance extends ContractInstance {
403
+ constructor(address: Address) {
404
+ super(address);
405
+ }
406
+
407
+ maps = {
408
+ userVotes: new RalphMap<Address, types.VoteInfo>(
409
+ GovernanceDemo.contract,
410
+ this.contractId,
411
+ "userVotes"
412
+ ),
413
+ proposalVotes: new RalphMap<bigint, bigint>(
414
+ GovernanceDemo.contract,
415
+ this.contractId,
416
+ "proposalVotes"
417
+ ),
418
+ };
419
+
420
+ async fetchState(): Promise<GovernanceDemoTypes.State> {
421
+ return fetchContractState(GovernanceDemo, this);
422
+ }
423
+
424
+ async getContractEventsCurrentCount(): Promise<number> {
425
+ return getContractEventsCurrentCount(this.address);
426
+ }
427
+
428
+ subscribeVotingStartedEvent(
429
+ options: EventSubscribeOptions<GovernanceDemoTypes.VotingStartedEvent>,
430
+ fromCount?: number
431
+ ): EventSubscription {
432
+ return subscribeContractEvent(
433
+ GovernanceDemo.contract,
434
+ this,
435
+ options,
436
+ "VotingStarted",
437
+ fromCount
438
+ );
439
+ }
440
+
441
+ subscribeVoteCastEvent(
442
+ options: EventSubscribeOptions<GovernanceDemoTypes.VoteCastEvent>,
443
+ fromCount?: number
444
+ ): EventSubscription {
445
+ return subscribeContractEvent(
446
+ GovernanceDemo.contract,
447
+ this,
448
+ options,
449
+ "VoteCast",
450
+ fromCount
451
+ );
452
+ }
453
+
454
+ subscribeVotingEndedEvent(
455
+ options: EventSubscribeOptions<GovernanceDemoTypes.VotingEndedEvent>,
456
+ fromCount?: number
457
+ ): EventSubscription {
458
+ return subscribeContractEvent(
459
+ GovernanceDemo.contract,
460
+ this,
461
+ options,
462
+ "VotingEnded",
463
+ fromCount
464
+ );
465
+ }
466
+
467
+ subscribeAllEvents(
468
+ options: EventSubscribeOptions<
469
+ | GovernanceDemoTypes.VotingStartedEvent
470
+ | GovernanceDemoTypes.VoteCastEvent
471
+ | GovernanceDemoTypes.VotingEndedEvent
472
+ >,
473
+ fromCount?: number
474
+ ): EventSubscription {
475
+ return subscribeContractEvents(
476
+ GovernanceDemo.contract,
477
+ this,
478
+ options,
479
+ fromCount
480
+ );
481
+ }
482
+
483
+ view = {
484
+ onStake: async (
485
+ params: GovernanceDemoTypes.CallMethodParams<"onStake">
486
+ ): Promise<GovernanceDemoTypes.CallMethodResult<"onStake">> => {
487
+ return callMethod(
488
+ GovernanceDemo,
489
+ this,
490
+ "onStake",
491
+ params,
492
+ getContractByCodeHash
493
+ );
494
+ },
495
+ onUnstake: async (
496
+ params: GovernanceDemoTypes.CallMethodParams<"onUnstake">
497
+ ): Promise<GovernanceDemoTypes.CallMethodResult<"onUnstake">> => {
498
+ return callMethod(
499
+ GovernanceDemo,
500
+ this,
501
+ "onUnstake",
502
+ params,
503
+ getContractByCodeHash
504
+ );
505
+ },
506
+ startVoting: async (
507
+ params?: GovernanceDemoTypes.CallMethodParams<"startVoting">
508
+ ): Promise<GovernanceDemoTypes.CallMethodResult<"startVoting">> => {
509
+ return callMethod(
510
+ GovernanceDemo,
511
+ this,
512
+ "startVoting",
513
+ params === undefined ? {} : params,
514
+ getContractByCodeHash
515
+ );
516
+ },
517
+ endVoting: async (
518
+ params?: GovernanceDemoTypes.CallMethodParams<"endVoting">
519
+ ): Promise<GovernanceDemoTypes.CallMethodResult<"endVoting">> => {
520
+ return callMethod(
521
+ GovernanceDemo,
522
+ this,
523
+ "endVoting",
524
+ params === undefined ? {} : params,
525
+ getContractByCodeHash
526
+ );
527
+ },
528
+ getProposalOptions: async (
529
+ params?: GovernanceDemoTypes.CallMethodParams<"getProposalOptions">
530
+ ): Promise<GovernanceDemoTypes.CallMethodResult<"getProposalOptions">> => {
531
+ return callMethod(
532
+ GovernanceDemo,
533
+ this,
534
+ "getProposalOptions",
535
+ params === undefined ? {} : params,
536
+ getContractByCodeHash
537
+ );
538
+ },
539
+ getUserVote: async (
540
+ params: GovernanceDemoTypes.CallMethodParams<"getUserVote">
541
+ ): Promise<GovernanceDemoTypes.CallMethodResult<"getUserVote">> => {
542
+ return callMethod(
543
+ GovernanceDemo,
544
+ this,
545
+ "getUserVote",
546
+ params,
547
+ getContractByCodeHash
548
+ );
549
+ },
550
+ getProposalVotes: async (
551
+ params: GovernanceDemoTypes.CallMethodParams<"getProposalVotes">
552
+ ): Promise<GovernanceDemoTypes.CallMethodResult<"getProposalVotes">> => {
553
+ return callMethod(
554
+ GovernanceDemo,
555
+ this,
556
+ "getProposalVotes",
557
+ params,
558
+ getContractByCodeHash
559
+ );
560
+ },
561
+ getTotalVotedAmount: async (
562
+ params?: GovernanceDemoTypes.CallMethodParams<"getTotalVotedAmount">
563
+ ): Promise<GovernanceDemoTypes.CallMethodResult<"getTotalVotedAmount">> => {
564
+ return callMethod(
565
+ GovernanceDemo,
566
+ this,
567
+ "getTotalVotedAmount",
568
+ params === undefined ? {} : params,
569
+ getContractByCodeHash
570
+ );
571
+ },
572
+ vote: async (
573
+ params: GovernanceDemoTypes.CallMethodParams<"vote">
574
+ ): Promise<GovernanceDemoTypes.CallMethodResult<"vote">> => {
575
+ return callMethod(
576
+ GovernanceDemo,
577
+ this,
578
+ "vote",
579
+ params,
580
+ getContractByCodeHash
581
+ );
582
+ },
583
+ isVotingStarted: async (
584
+ params?: GovernanceDemoTypes.CallMethodParams<"isVotingStarted">
585
+ ): Promise<GovernanceDemoTypes.CallMethodResult<"isVotingStarted">> => {
586
+ return callMethod(
587
+ GovernanceDemo,
588
+ this,
589
+ "isVotingStarted",
590
+ params === undefined ? {} : params,
591
+ getContractByCodeHash
592
+ );
593
+ },
594
+ isVotingEnded: async (
595
+ params?: GovernanceDemoTypes.CallMethodParams<"isVotingEnded">
596
+ ): Promise<GovernanceDemoTypes.CallMethodResult<"isVotingEnded">> => {
597
+ return callMethod(
598
+ GovernanceDemo,
599
+ this,
600
+ "isVotingEnded",
601
+ params === undefined ? {} : params,
602
+ getContractByCodeHash
603
+ );
604
+ },
605
+ isVotingActive: async (
606
+ params?: GovernanceDemoTypes.CallMethodParams<"isVotingActive">
607
+ ): Promise<GovernanceDemoTypes.CallMethodResult<"isVotingActive">> => {
608
+ return callMethod(
609
+ GovernanceDemo,
610
+ this,
611
+ "isVotingActive",
612
+ params === undefined ? {} : params,
613
+ getContractByCodeHash
614
+ );
615
+ },
616
+ };
617
+
618
+ transact = {
619
+ onStake: async (
620
+ params: GovernanceDemoTypes.SignExecuteMethodParams<"onStake">
621
+ ): Promise<GovernanceDemoTypes.SignExecuteMethodResult<"onStake">> => {
622
+ return signExecuteMethod(GovernanceDemo, this, "onStake", params);
623
+ },
624
+ onUnstake: async (
625
+ params: GovernanceDemoTypes.SignExecuteMethodParams<"onUnstake">
626
+ ): Promise<GovernanceDemoTypes.SignExecuteMethodResult<"onUnstake">> => {
627
+ return signExecuteMethod(GovernanceDemo, this, "onUnstake", params);
628
+ },
629
+ startVoting: async (
630
+ params: GovernanceDemoTypes.SignExecuteMethodParams<"startVoting">
631
+ ): Promise<GovernanceDemoTypes.SignExecuteMethodResult<"startVoting">> => {
632
+ return signExecuteMethod(GovernanceDemo, this, "startVoting", params);
633
+ },
634
+ endVoting: async (
635
+ params: GovernanceDemoTypes.SignExecuteMethodParams<"endVoting">
636
+ ): Promise<GovernanceDemoTypes.SignExecuteMethodResult<"endVoting">> => {
637
+ return signExecuteMethod(GovernanceDemo, this, "endVoting", params);
638
+ },
639
+ getProposalOptions: async (
640
+ params: GovernanceDemoTypes.SignExecuteMethodParams<"getProposalOptions">
641
+ ): Promise<
642
+ GovernanceDemoTypes.SignExecuteMethodResult<"getProposalOptions">
643
+ > => {
644
+ return signExecuteMethod(
645
+ GovernanceDemo,
646
+ this,
647
+ "getProposalOptions",
648
+ params
649
+ );
650
+ },
651
+ getUserVote: async (
652
+ params: GovernanceDemoTypes.SignExecuteMethodParams<"getUserVote">
653
+ ): Promise<GovernanceDemoTypes.SignExecuteMethodResult<"getUserVote">> => {
654
+ return signExecuteMethod(GovernanceDemo, this, "getUserVote", params);
655
+ },
656
+ getProposalVotes: async (
657
+ params: GovernanceDemoTypes.SignExecuteMethodParams<"getProposalVotes">
658
+ ): Promise<
659
+ GovernanceDemoTypes.SignExecuteMethodResult<"getProposalVotes">
660
+ > => {
661
+ return signExecuteMethod(
662
+ GovernanceDemo,
663
+ this,
664
+ "getProposalVotes",
665
+ params
666
+ );
667
+ },
668
+ getTotalVotedAmount: async (
669
+ params: GovernanceDemoTypes.SignExecuteMethodParams<"getTotalVotedAmount">
670
+ ): Promise<
671
+ GovernanceDemoTypes.SignExecuteMethodResult<"getTotalVotedAmount">
672
+ > => {
673
+ return signExecuteMethod(
674
+ GovernanceDemo,
675
+ this,
676
+ "getTotalVotedAmount",
677
+ params
678
+ );
679
+ },
680
+ vote: async (
681
+ params: GovernanceDemoTypes.SignExecuteMethodParams<"vote">
682
+ ): Promise<GovernanceDemoTypes.SignExecuteMethodResult<"vote">> => {
683
+ return signExecuteMethod(GovernanceDemo, this, "vote", params);
684
+ },
685
+ isVotingStarted: async (
686
+ params: GovernanceDemoTypes.SignExecuteMethodParams<"isVotingStarted">
687
+ ): Promise<
688
+ GovernanceDemoTypes.SignExecuteMethodResult<"isVotingStarted">
689
+ > => {
690
+ return signExecuteMethod(GovernanceDemo, this, "isVotingStarted", params);
691
+ },
692
+ isVotingEnded: async (
693
+ params: GovernanceDemoTypes.SignExecuteMethodParams<"isVotingEnded">
694
+ ): Promise<
695
+ GovernanceDemoTypes.SignExecuteMethodResult<"isVotingEnded">
696
+ > => {
697
+ return signExecuteMethod(GovernanceDemo, this, "isVotingEnded", params);
698
+ },
699
+ isVotingActive: async (
700
+ params: GovernanceDemoTypes.SignExecuteMethodParams<"isVotingActive">
701
+ ): Promise<
702
+ GovernanceDemoTypes.SignExecuteMethodResult<"isVotingActive">
703
+ > => {
704
+ return signExecuteMethod(GovernanceDemo, this, "isVotingActive", params);
705
+ },
706
+ };
707
+
708
+ async multicall<Calls extends GovernanceDemoTypes.MultiCallParams>(
709
+ calls: Calls
710
+ ): Promise<GovernanceDemoTypes.MultiCallResults<Calls>>;
711
+ async multicall<Callss extends GovernanceDemoTypes.MultiCallParams[]>(
712
+ callss: Narrow<Callss>
713
+ ): Promise<GovernanceDemoTypes.MulticallReturnType<Callss>>;
714
+ async multicall<
715
+ Callss extends
716
+ | GovernanceDemoTypes.MultiCallParams
717
+ | GovernanceDemoTypes.MultiCallParams[]
718
+ >(callss: Callss): Promise<unknown> {
719
+ return await multicallMethods(
720
+ GovernanceDemo,
721
+ this,
722
+ callss,
723
+ getContractByCodeHash
724
+ );
725
+ }
726
+ }