@indigo-labs/indigo-sdk 0.2.42 → 0.3.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.
Files changed (201) hide show
  1. package/.github/workflows/ci.yml +4 -2
  2. package/dist/index.d.mts +3008 -2194
  3. package/dist/index.d.ts +3008 -2194
  4. package/dist/index.js +9827 -6194
  5. package/dist/index.mjs +8591 -4809
  6. package/package.json +14 -3
  7. package/src/contracts/cdp/helpers.ts +68 -72
  8. package/src/contracts/cdp/scripts.ts +50 -13
  9. package/src/contracts/cdp/transactions.ts +831 -545
  10. package/src/contracts/cdp/types-new.ts +256 -0
  11. package/src/contracts/cdp/types.ts +26 -144
  12. package/src/contracts/cdp-creator/scripts.ts +15 -9
  13. package/src/contracts/cdp-creator/types-new.ts +50 -0
  14. package/src/contracts/cdp-creator/types.ts +5 -31
  15. package/src/contracts/collector/scripts.ts +1 -1
  16. package/src/contracts/collector/transactions.ts +23 -13
  17. package/src/contracts/collector/types-new.ts +17 -0
  18. package/src/contracts/execute/scripts.ts +19 -10
  19. package/src/contracts/execute/types-new.ts +44 -0
  20. package/src/contracts/execute/types.ts +5 -38
  21. package/src/contracts/gov/helpers.ts +187 -51
  22. package/src/contracts/gov/scripts.ts +17 -10
  23. package/src/contracts/gov/transactions.ts +599 -271
  24. package/src/contracts/gov/types-new.ts +253 -100
  25. package/src/contracts/gov/types.ts +4 -71
  26. package/src/contracts/iasset/helpers.ts +172 -0
  27. package/src/contracts/iasset/scripts.ts +38 -0
  28. package/src/contracts/iasset/types.ts +154 -0
  29. package/src/contracts/initialize/actions.ts +768 -0
  30. package/src/contracts/initialize/helpers.ts +611 -36
  31. package/src/contracts/initialize/types.ts +102 -28
  32. package/src/contracts/interest-collection/helpers.ts +19 -0
  33. package/src/contracts/interest-collection/scripts.ts +44 -0
  34. package/src/contracts/interest-collection/transactions.ts +436 -0
  35. package/src/contracts/interest-collection/types-new.ts +50 -0
  36. package/src/contracts/interest-collection/types.ts +26 -0
  37. package/src/contracts/interest-oracle/helpers.ts +2 -30
  38. package/src/contracts/interest-oracle/scripts.ts +1 -1
  39. package/src/contracts/interest-oracle/transactions.ts +21 -16
  40. package/src/contracts/interest-oracle/types-new.ts +32 -0
  41. package/src/contracts/interest-oracle/types.ts +1 -40
  42. package/src/contracts/one-shot/transactions.ts +1 -2
  43. package/src/contracts/poll/helpers.ts +5 -23
  44. package/src/contracts/poll/scripts.ts +12 -13
  45. package/src/contracts/poll/types-poll-manager.ts +1 -19
  46. package/src/contracts/poll/types-poll-new.ts +170 -0
  47. package/src/contracts/poll/types-poll-shard.ts +2 -24
  48. package/src/contracts/price-oracle/helpers.ts +1 -4
  49. package/src/contracts/price-oracle/scripts.ts +3 -8
  50. package/src/contracts/price-oracle/transactions.ts +32 -25
  51. package/src/contracts/price-oracle/types-new.ts +50 -0
  52. package/src/contracts/price-oracle/types.ts +2 -36
  53. package/src/contracts/pyth-feed/helpers.ts +58 -0
  54. package/src/contracts/pyth-feed/scripts.ts +15 -0
  55. package/src/contracts/pyth-feed/types.ts +181 -0
  56. package/src/contracts/rob/helpers.ts +405 -0
  57. package/src/contracts/rob/scripts.ts +35 -0
  58. package/src/contracts/rob/transactions.ts +410 -0
  59. package/src/contracts/rob/types-new.ts +128 -0
  60. package/src/contracts/rob/types.ts +16 -0
  61. package/src/contracts/rob-leverage/helpers.ts +424 -0
  62. package/src/contracts/{leverage → rob-leverage}/transactions.ts +68 -48
  63. package/src/contracts/stability-pool/helpers.ts +714 -230
  64. package/src/contracts/stability-pool/scripts.ts +20 -15
  65. package/src/contracts/stability-pool/transactions.ts +625 -493
  66. package/src/contracts/stability-pool/types-new.ts +237 -100
  67. package/src/contracts/stability-pool/types.ts +5 -22
  68. package/src/contracts/stableswap/helpers.ts +22 -0
  69. package/src/contracts/stableswap/scripts.ts +37 -0
  70. package/src/contracts/stableswap/transactions.ts +647 -0
  71. package/src/contracts/stableswap/types-new.ts +131 -0
  72. package/src/contracts/stableswap/types.ts +17 -0
  73. package/src/contracts/staking/helpers.ts +49 -34
  74. package/src/contracts/staking/scripts.ts +1 -1
  75. package/src/contracts/staking/transactions.ts +85 -130
  76. package/src/contracts/staking/types-new.ts +60 -28
  77. package/src/contracts/staking/types.ts +1 -28
  78. package/src/contracts/treasury/helpers.ts +21 -0
  79. package/src/contracts/treasury/scripts.ts +16 -26
  80. package/src/contracts/treasury/transactions.ts +256 -27
  81. package/src/contracts/treasury/types-new.ts +69 -0
  82. package/src/contracts/treasury/types.ts +2 -43
  83. package/src/contracts/version-registry/scripts.ts +2 -2
  84. package/src/contracts/version-registry/types-new.ts +6 -7
  85. package/src/index.ts +37 -20
  86. package/src/scripts/auth-token-policy.ts +3 -2
  87. package/src/scripts/iasset-policy.ts +3 -2
  88. package/src/types/evolution-schema-options.ts +3 -3
  89. package/src/types/generic.ts +17 -89
  90. package/src/types/multisig.ts +48 -0
  91. package/src/types/on-chain-decimal.ts +14 -7
  92. package/src/types/rational.ts +61 -0
  93. package/src/types/system-params.ts +237 -41
  94. package/src/utils/array-utils.ts +70 -1
  95. package/src/utils/bigint-utils.ts +12 -0
  96. package/src/utils/indigo-helpers.ts +8 -10
  97. package/src/utils/lucid-utils.ts +47 -40
  98. package/src/utils/oracle-helpers.ts +62 -0
  99. package/src/utils/pyth/decode.ts +223 -0
  100. package/src/utils/pyth/encode.ts +262 -0
  101. package/src/utils/pyth/index.ts +14 -0
  102. package/src/utils/pyth/types.ts +87 -0
  103. package/src/validators/always-succeed-validator.ts +6 -0
  104. package/src/validators/cdp-creator-validator.ts +2 -2
  105. package/src/validators/cdp-redeem-validator.ts +7 -0
  106. package/src/validators/cdp-validator.ts +2 -2
  107. package/src/validators/collector-validator.ts +2 -2
  108. package/src/validators/execute-validator.ts +2 -2
  109. package/src/validators/governance-validator.ts +2 -2
  110. package/src/validators/iasset-validator.ts +7 -0
  111. package/src/validators/interest-collection-validator.ts +7 -0
  112. package/src/validators/interest-oracle-validator.ts +2 -2
  113. package/src/validators/poll-manager-validator.ts +2 -2
  114. package/src/validators/poll-shard-validator.ts +2 -2
  115. package/src/validators/price-oracle-validator.ts +7 -0
  116. package/src/validators/pyth-feed-validator.ts +7 -0
  117. package/src/validators/rob-validator.ts +7 -0
  118. package/src/validators/stability-pool-validator.ts +2 -2
  119. package/src/validators/stableswap-validator.ts +7 -0
  120. package/src/validators/staking-validator.ts +2 -2
  121. package/src/validators/treasury-validator.ts +2 -2
  122. package/src/validators/version-record-policy.ts +2 -2
  123. package/src/validators/version-registry-validator.ts +2 -2
  124. package/tests/always-succeed/script.ts +7 -0
  125. package/tests/bigint-utils.test.ts +41 -0
  126. package/tests/cdp/actions.ts +611 -0
  127. package/tests/cdp/cdp-helpers.ts +55 -0
  128. package/tests/cdp/cdp-queries.ts +440 -0
  129. package/tests/cdp/cdp.test.ts +6087 -0
  130. package/tests/cdp/transactions-mutated.ts +1729 -0
  131. package/tests/data/system-params.json +177 -34
  132. package/tests/datums.test.ts +209 -210
  133. package/tests/endpoints/initialize.ts +68 -0
  134. package/tests/endpoints/interest-collector.ts +37 -0
  135. package/tests/endpoints/treasury.ts +70 -0
  136. package/tests/gov/actions.ts +406 -0
  137. package/tests/gov/gov.test.ts +4450 -0
  138. package/tests/{queries → gov}/governance-queries.ts +6 -3
  139. package/tests/hash-checks.test.ts +38 -11
  140. package/tests/indigo-test-helpers.ts +100 -0
  141. package/tests/initialize.test.ts +61 -9
  142. package/tests/interest-collection/interest-collection.test.ts +892 -0
  143. package/tests/interest-collection/interest-collector-queries.ts +49 -0
  144. package/tests/interest-collection/transactions-mutated.ts +260 -0
  145. package/tests/interest-oracle.test.ts +43 -35
  146. package/tests/mock/assets-mock.ts +234 -23
  147. package/tests/mock/protocol-params-mock.ts +21 -0
  148. package/tests/price-oracle/actions.ts +163 -0
  149. package/tests/price-oracle/price-oracle-queries.ts +12 -0
  150. package/tests/price-oracle/price-oracle.test.ts +240 -0
  151. package/tests/price-oracle/transactions-mutated.ts +62 -0
  152. package/tests/pyth/endpoints.ts +96 -0
  153. package/tests/pyth/helpers.ts +37 -0
  154. package/tests/pyth/pyth-encoding.test.ts +376 -0
  155. package/tests/pyth/pyth-indigo.test.ts +509 -0
  156. package/tests/pyth/pyth.test.ts +300 -0
  157. package/tests/queries/execute-queries.ts +6 -5
  158. package/tests/queries/iasset-queries.ts +175 -5
  159. package/tests/queries/interest-oracle-queries.ts +4 -2
  160. package/tests/queries/poll-queries.ts +8 -9
  161. package/tests/queries/stability-pool-queries.ts +95 -48
  162. package/tests/queries/staking-queries.ts +4 -2
  163. package/tests/queries/treasury-queries.ts +80 -5
  164. package/tests/rob/actions.ts +58 -0
  165. package/tests/{lrp-leverage.test.ts → rob/rob-leverage.test.ts} +393 -296
  166. package/tests/rob/rob-queries.ts +95 -0
  167. package/tests/rob/rob.test.ts +3762 -0
  168. package/tests/rob/transactions-mutated.ts +853 -0
  169. package/tests/script-size.test.ts +240 -0
  170. package/tests/setup.ts +135 -0
  171. package/tests/stability-pool/actions.ts +210 -0
  172. package/tests/stability-pool.test.ts +5469 -666
  173. package/tests/stableswap/stableswap-actions.ts +84 -0
  174. package/tests/stableswap/stableswap-queries.ts +89 -0
  175. package/tests/stableswap/stableswap.test.ts +3891 -0
  176. package/tests/stableswap/transactions-mutated.ts +348 -0
  177. package/tests/staking.test.ts +82 -99
  178. package/tests/test-helpers.ts +58 -11
  179. package/tests/treasury.test.ts +242 -0
  180. package/tests/utils/asserts.ts +74 -0
  181. package/tests/utils/benchmark-utils.ts +81 -0
  182. package/tests/utils/index.ts +122 -4
  183. package/tsconfig.json +9 -1
  184. package/vitest.config.ts +3 -1
  185. package/src/contracts/collector/types.ts +0 -16
  186. package/src/contracts/initialize/transactions.ts +0 -891
  187. package/src/contracts/leverage/helpers.ts +0 -424
  188. package/src/contracts/lrp/helpers.ts +0 -294
  189. package/src/contracts/lrp/scripts.ts +0 -27
  190. package/src/contracts/lrp/transactions.ts +0 -250
  191. package/src/contracts/lrp/types.ts +0 -131
  192. package/src/contracts/poll/types-poll.ts +0 -88
  193. package/src/contracts/vesting/helpers.ts +0 -218
  194. package/src/utils/value-helpers.ts +0 -37
  195. package/src/validators/lrp-validator.ts +0 -7
  196. package/tests/cdp.test.ts +0 -1528
  197. package/tests/gov.test.ts +0 -2011
  198. package/tests/lrp.test.ts +0 -673
  199. package/tests/queries/cdp-queries.ts +0 -220
  200. package/tests/queries/lrp-queries.ts +0 -76
  201. package/tests/queries/price-oracle-queries.ts +0 -10
package/tests/gov.test.ts DELETED
@@ -1,2011 +0,0 @@
1
- import {
2
- addAssets,
3
- Data,
4
- Emulator,
5
- EmulatorAccount,
6
- fromHex,
7
- fromText,
8
- generateEmulatorAccount,
9
- Lucid,
10
- unixTimeToSlot,
11
- UTxO,
12
- } from '@lucid-evolution/lucid';
13
- import { describe, beforeEach, test, expect, assert } from 'vitest';
14
- import {
15
- assetClassValueOf,
16
- mkAssetsOf,
17
- mkLovelacesOf,
18
- } from '../src/utils/value-helpers';
19
- import { init } from '../src/contracts/initialize/transactions';
20
- import { findGov } from './queries/governance-queries';
21
- import {
22
- addrDetails,
23
- addressFromBech32,
24
- adjustStakingPosition,
25
- createProposal,
26
- createScriptAddress,
27
- createShardsChunks,
28
- endProposal,
29
- executeProposal,
30
- findStakingManager,
31
- fromSystemParamsAsset,
32
- matchSingle,
33
- mergeShards,
34
- ONE_DAY,
35
- openStakingPosition,
36
- startInterestOracle,
37
- SystemParams,
38
- vote,
39
- VoteOption,
40
- } from '../src';
41
- import {
42
- LucidContext,
43
- runAndAwaitTx,
44
- runAndAwaitTxBuilder,
45
- } from './test-helpers';
46
- import { startPriceOracleTx } from '../src/contracts/price-oracle/transactions';
47
- import { findAllIAssets, findIAsset } from './queries/iasset-queries';
48
- import {
49
- findAllPollShards,
50
- findPollManager,
51
- findRandomPollShard,
52
- } from './queries/poll-queries';
53
- import { findStakingPosition } from './queries/staking-queries';
54
- import {
55
- readonlyArray as RA,
56
- task as T,
57
- array as A,
58
- function as F,
59
- number as N,
60
- } from 'fp-ts';
61
- import { findExecute } from './queries/execute-queries';
62
- import {
63
- getNewUtxosAtAddressAfterAction,
64
- getValueChangeAtAddressAfterAction,
65
- } from './utils';
66
- import { serialiseUpgradePaths } from '../src/contracts/gov/types-new';
67
- import { iusdInitialAssetCfg } from './mock/assets-mock';
68
-
69
- type MyContext = LucidContext<{
70
- admin: EmulatorAccount;
71
- user: EmulatorAccount;
72
- withdrawalAccount: EmulatorAccount;
73
- }>;
74
-
75
- async function createUtxoAtTreasury(
76
- indyAmt: bigint,
77
- sysParams: SystemParams,
78
- context: MyContext,
79
- ): Promise<UTxO> {
80
- const treasuryAddr = createScriptAddress(
81
- context.lucid.config().network!,
82
- sysParams.validatorHashes.treasuryHash,
83
- );
84
-
85
- const tx = context.lucid
86
- .newTx()
87
- .pay.ToContract(
88
- treasuryAddr,
89
- { kind: 'inline', value: Data.void() },
90
- mkAssetsOf(fromSystemParamsAsset(sysParams.govParams.indyAsset), indyAmt),
91
- );
92
-
93
- const [_, utxos] = await getNewUtxosAtAddressAfterAction(
94
- context.lucid,
95
- treasuryAddr,
96
- () => runAndAwaitTxBuilder(context.lucid, tx),
97
- );
98
-
99
- return matchSingle(utxos, () => new Error('Expected a single treasury UTXO'));
100
- }
101
-
102
- async function runVote(
103
- pollId: bigint,
104
- option: VoteOption,
105
- sysParams: SystemParams,
106
- context: MyContext,
107
- ): Promise<void> {
108
- const [pkh, _] = await addrDetails(context.lucid);
109
-
110
- const stakingPosOref = await findStakingPosition(
111
- context.lucid,
112
- sysParams.validatorHashes.stakingHash,
113
- fromSystemParamsAsset(sysParams.stakingParams.stakingToken),
114
- pkh.hash,
115
- );
116
-
117
- const pollShard = await findRandomPollShard(
118
- context.lucid,
119
- sysParams.validatorHashes.pollShardHash,
120
- fromSystemParamsAsset(sysParams.pollShardParams.pollToken),
121
- pollId,
122
- );
123
-
124
- await runAndAwaitTx(
125
- context.lucid,
126
- vote(
127
- option,
128
- pollShard.utxo,
129
- stakingPosOref.utxo,
130
- sysParams,
131
- context.lucid,
132
- context.emulator.slot,
133
- ),
134
- );
135
- }
136
-
137
- async function runCreateAllShards(
138
- pollId: bigint,
139
- sysParams: SystemParams,
140
- context: MyContext,
141
- ): Promise<void> {
142
- const govUtxo = await findGov(
143
- context.lucid,
144
- sysParams.validatorHashes.govHash,
145
- fromSystemParamsAsset(sysParams.govParams.govNFT),
146
- );
147
-
148
- for (
149
- let i = 0;
150
- i < Math.ceil(Number(govUtxo.datum.protocolParams.totalShards) / 2);
151
- i++
152
- ) {
153
- const pollUtxo = await findPollManager(
154
- context.lucid,
155
- sysParams.validatorHashes.pollManagerHash,
156
- fromSystemParamsAsset(sysParams.pollManagerParams.pollToken),
157
- pollId,
158
- );
159
-
160
- await runAndAwaitTx(
161
- context.lucid,
162
- createShardsChunks(
163
- 2n,
164
- pollUtxo.utxo,
165
- sysParams,
166
- context.emulator.slot,
167
- context.lucid,
168
- ),
169
- );
170
- }
171
- }
172
-
173
- async function runMergeAllShards(
174
- pollId: bigint,
175
- sysParams: SystemParams,
176
- context: MyContext,
177
- ): Promise<void> {
178
- const govUtxo = await findGov(
179
- context.lucid,
180
- sysParams.validatorHashes.govHash,
181
- fromSystemParamsAsset(sysParams.govParams.govNFT),
182
- );
183
-
184
- for (
185
- let i = 0;
186
- i < Math.ceil(Number(govUtxo.datum.protocolParams.totalShards) / 2);
187
- i++
188
- ) {
189
- const pollUtxo = await findPollManager(
190
- context.lucid,
191
- sysParams.validatorHashes.pollManagerHash,
192
- fromSystemParamsAsset(sysParams.pollManagerParams.pollToken),
193
- pollId,
194
- );
195
-
196
- const allPollShards = await findAllPollShards(
197
- context.lucid,
198
- sysParams.validatorHashes.pollShardHash,
199
- fromSystemParamsAsset(sysParams.pollShardParams.pollToken),
200
- pollUtxo.datum.pollId,
201
- );
202
-
203
- await runAndAwaitTx(
204
- context.lucid,
205
- mergeShards(
206
- pollUtxo.utxo,
207
- A.takeLeft(2)(allPollShards).map((u) => u.utxo),
208
- sysParams,
209
- context.lucid,
210
- context.emulator.slot,
211
- ),
212
- );
213
- }
214
- }
215
-
216
- async function runEndProposal(
217
- pollId: bigint,
218
- sysParams: SystemParams,
219
- context: MyContext,
220
- ): Promise<void> {
221
- const pollUtxo = await findPollManager(
222
- context.lucid,
223
- sysParams.validatorHashes.pollManagerHash,
224
- fromSystemParamsAsset(sysParams.pollManagerParams.pollToken),
225
- pollId,
226
- );
227
-
228
- const govUtxo = await findGov(
229
- context.lucid,
230
- sysParams.validatorHashes.govHash,
231
- fromSystemParamsAsset(sysParams.govParams.govNFT),
232
- );
233
-
234
- await runAndAwaitTx(
235
- context.lucid,
236
- endProposal(
237
- pollUtxo.utxo,
238
- govUtxo.utxo,
239
- sysParams,
240
- context.lucid,
241
- context.emulator.slot,
242
- ),
243
- );
244
- }
245
-
246
- async function waitForVotingEnd(
247
- pollId: bigint,
248
- sysParams: SystemParams,
249
- context: MyContext,
250
- ): Promise<void> {
251
- const pollUtxo = await findPollManager(
252
- context.lucid,
253
- sysParams.validatorHashes.pollManagerHash,
254
- fromSystemParamsAsset(sysParams.pollManagerParams.pollToken),
255
- pollId,
256
- );
257
-
258
- const targetSlot = unixTimeToSlot(
259
- context.lucid.config().network!,
260
- Number(pollUtxo.datum.votingEndTime),
261
- );
262
- expect(targetSlot).toBeGreaterThan(context.emulator.slot);
263
-
264
- context.emulator.awaitSlot(targetSlot - context.emulator.slot + 1);
265
- }
266
-
267
- describe('Gov', () => {
268
- beforeEach<MyContext>(async (context: MyContext) => {
269
- context.users = {
270
- admin: generateEmulatorAccount({
271
- lovelace: BigInt(100_000_000_000_000),
272
- }),
273
- user: generateEmulatorAccount(addAssets(mkLovelacesOf(100_000_000n))),
274
- withdrawalAccount: generateEmulatorAccount({}),
275
- };
276
-
277
- context.emulator = new Emulator([context.users.admin, context.users.user]);
278
- context.lucid = await Lucid(context.emulator, 'Custom');
279
- });
280
-
281
- test<MyContext>('Create text proposal', async (context: MyContext) => {
282
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
283
-
284
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg]);
285
-
286
- const govUtxo = await findGov(
287
- context.lucid,
288
- sysParams.validatorHashes.govHash,
289
- fromSystemParamsAsset(sysParams.govParams.govNFT),
290
- );
291
-
292
- const [tx, _] = await createProposal(
293
- { TextProposal: { bytes: fromText('smth') } },
294
- null,
295
- sysParams,
296
- context.lucid,
297
- context.emulator.slot,
298
- govUtxo.utxo,
299
- [],
300
- );
301
-
302
- await runAndAwaitTxBuilder(context.lucid, tx);
303
- });
304
-
305
- test<MyContext>('Create text proposal with shards', async (context: MyContext) => {
306
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
307
-
308
- const [sysParams, _] = await init(context.lucid, [iusdInitialAssetCfg]);
309
-
310
- const govUtxo = await findGov(
311
- context.lucid,
312
- sysParams.validatorHashes.govHash,
313
- fromSystemParamsAsset(sysParams.govParams.govNFT),
314
- );
315
-
316
- const [tx, pollId] = await createProposal(
317
- { TextProposal: { bytes: fromText('smth') } },
318
- null,
319
- sysParams,
320
- context.lucid,
321
- context.emulator.slot,
322
- govUtxo.utxo,
323
- [],
324
- );
325
-
326
- await runAndAwaitTxBuilder(context.lucid, tx);
327
-
328
- await runCreateAllShards(pollId, sysParams, context);
329
-
330
- const pollUtxo = await findPollManager(
331
- context.lucid,
332
- sysParams.validatorHashes.pollManagerHash,
333
- fromSystemParamsAsset(sysParams.pollManagerParams.pollToken),
334
- pollId,
335
- );
336
-
337
- expect(
338
- pollUtxo.datum.createdShardsCount === pollUtxo.datum.totalShardsCount,
339
- 'Expected total shards count being created',
340
- ).toBeTruthy();
341
- });
342
-
343
- test<MyContext>('Merge proposal shards', async (context: MyContext) => {
344
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
345
-
346
- const [sysParams, _] = await init(context.lucid, [iusdInitialAssetCfg]);
347
-
348
- const govUtxo = await findGov(
349
- context.lucid,
350
- sysParams.validatorHashes.govHash,
351
- fromSystemParamsAsset(sysParams.govParams.govNFT),
352
- );
353
-
354
- const [tx, pollId] = await createProposal(
355
- { TextProposal: { bytes: fromText('smth') } },
356
- null,
357
- sysParams,
358
- context.lucid,
359
- context.emulator.slot,
360
- govUtxo.utxo,
361
- [],
362
- );
363
-
364
- await runAndAwaitTxBuilder(context.lucid, tx);
365
-
366
- {
367
- const pollUtxo = await findPollManager(
368
- context.lucid,
369
- sysParams.validatorHashes.pollManagerHash,
370
- fromSystemParamsAsset(sysParams.pollManagerParams.pollToken),
371
- pollId,
372
- );
373
-
374
- await runAndAwaitTx(
375
- context.lucid,
376
- createShardsChunks(
377
- 2n,
378
- pollUtxo.utxo,
379
- sysParams,
380
- context.emulator.slot,
381
- context.lucid,
382
- ),
383
- );
384
-
385
- const targetSlot = unixTimeToSlot(
386
- context.lucid.config().network!,
387
- Number(pollUtxo.datum.votingEndTime),
388
- );
389
- expect(targetSlot).toBeGreaterThan(context.emulator.slot);
390
-
391
- context.emulator.awaitSlot(targetSlot - context.emulator.slot + 1);
392
- }
393
-
394
- {
395
- const pollUtxo = await findPollManager(
396
- context.lucid,
397
- sysParams.validatorHashes.pollManagerHash,
398
- fromSystemParamsAsset(sysParams.pollManagerParams.pollToken),
399
- pollId,
400
- );
401
-
402
- const allPollShards = await findAllPollShards(
403
- context.lucid,
404
- sysParams.validatorHashes.pollShardHash,
405
- fromSystemParamsAsset(sysParams.pollShardParams.pollToken),
406
- pollUtxo.datum.pollId,
407
- );
408
-
409
- assert(allPollShards.length === 2);
410
-
411
- await runAndAwaitTx(
412
- context.lucid,
413
- mergeShards(
414
- pollUtxo.utxo,
415
- allPollShards.map((u) => u.utxo),
416
- sysParams,
417
- context.lucid,
418
- context.emulator.slot,
419
- ),
420
- );
421
- }
422
-
423
- const pollUtxo = await findPollManager(
424
- context.lucid,
425
- sysParams.validatorHashes.pollManagerHash,
426
- fromSystemParamsAsset(sysParams.pollManagerParams.pollToken),
427
- pollId,
428
- );
429
-
430
- assert(pollUtxo.datum.talliedShardsCount === 2n);
431
- });
432
-
433
- test<MyContext>('Create asset proposal', async (context: MyContext) => {
434
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
435
-
436
- const [sysParams, ___] = await init(context.lucid, [iusdInitialAssetCfg]);
437
-
438
- const [pkh, _] = await addrDetails(context.lucid);
439
-
440
- const [startInterestTx, interestOracleNft] = await startInterestOracle(
441
- 0n,
442
- 0n,
443
- 0n,
444
- {
445
- biasTime: 120_000n,
446
- owner: pkh.hash,
447
- },
448
- context.lucid,
449
- );
450
- await runAndAwaitTxBuilder(context.lucid, startInterestTx);
451
-
452
- const [priceOracleTx, priceOranceNft] = await startPriceOracleTx(
453
- context.lucid,
454
- 'IBTC_ORACLE',
455
- { getOnChainInt: 1_000_000n },
456
- { biasTime: 120_000n, expiration: 1_800_000n, owner: pkh.hash },
457
- );
458
- await runAndAwaitTxBuilder(context.lucid, priceOracleTx);
459
-
460
- const govUtxo = await findGov(
461
- context.lucid,
462
- sysParams.validatorHashes.govHash,
463
- fromSystemParamsAsset(sysParams.govParams.govNFT),
464
- );
465
-
466
- const allIassetOrefs = (
467
- await findAllIAssets(
468
- context.lucid,
469
- sysParams.validatorHashes.cdpHash,
470
- fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
471
- )
472
- ).map((iasset) => iasset.utxo);
473
-
474
- const [tx, __] = await createProposal(
475
- {
476
- ProposeAsset: {
477
- asset: fromText('iBTC'),
478
- priceOracleNft: priceOranceNft,
479
- interestOracleNft: interestOracleNft,
480
- redemptionRatioPercentage: { getOnChainInt: 200_000_000n },
481
- maintenanceRatioPercentage: { getOnChainInt: 150_000_000n },
482
- liquidationRatioPercentage: { getOnChainInt: 120_000_000n },
483
- debtMintingFeePercentage: { getOnChainInt: 500_000n },
484
- liquidationProcessingFeePercentage: { getOnChainInt: 2_000_000n },
485
- stabilityPoolWithdrawalFeePercentage: { getOnChainInt: 500_000n },
486
- redemptionReimbursementPercentage: { getOnChainInt: 1_000_000n },
487
- redemptionProcessingFeePercentage: { getOnChainInt: 1_000_000n },
488
- interestCollectorPortionPercentage: { getOnChainInt: 40_000_000n },
489
- },
490
- },
491
- null,
492
- sysParams,
493
- context.lucid,
494
- context.emulator.slot,
495
- govUtxo.utxo,
496
- allIassetOrefs,
497
- );
498
-
499
- await runAndAwaitTxBuilder(context.lucid, tx);
500
- });
501
-
502
- test<MyContext>('Vote on proposal', async (context: MyContext) => {
503
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
504
-
505
- const [sysParams, _] = await init(context.lucid, [iusdInitialAssetCfg]);
506
-
507
- const govUtxo = await findGov(
508
- context.lucid,
509
- sysParams.validatorHashes.govHash,
510
- fromSystemParamsAsset(sysParams.govParams.govNFT),
511
- );
512
-
513
- const [tx, pollId] = await createProposal(
514
- { TextProposal: { bytes: fromText('smth') } },
515
- null,
516
- sysParams,
517
- context.lucid,
518
- context.emulator.slot,
519
- govUtxo.utxo,
520
- [],
521
- );
522
-
523
- await runAndAwaitTxBuilder(context.lucid, tx);
524
-
525
- await runCreateAllShards(pollId, sysParams, context);
526
-
527
- await runAndAwaitTx(
528
- context.lucid,
529
- openStakingPosition(
530
- 1_000_000n,
531
- sysParams,
532
- context.lucid,
533
- (await findStakingManager(sysParams, context.lucid)).utxo,
534
- ),
535
- );
536
-
537
- await runVote(pollId, 'Yes', sysParams, context);
538
- });
539
-
540
- test<MyContext>('Vote on proposal, then deposit more INDY', async (context: MyContext) => {
541
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
542
-
543
- const [sysParams, _] = await init(context.lucid, [iusdInitialAssetCfg]);
544
-
545
- const govUtxo = await findGov(
546
- context.lucid,
547
- sysParams.validatorHashes.govHash,
548
- fromSystemParamsAsset(sysParams.govParams.govNFT),
549
- );
550
-
551
- const [tx, pollId] = await createProposal(
552
- { TextProposal: { bytes: fromText('smth') } },
553
- null,
554
- sysParams,
555
- context.lucid,
556
- context.emulator.slot,
557
- govUtxo.utxo,
558
- [],
559
- );
560
-
561
- await runAndAwaitTxBuilder(context.lucid, tx);
562
-
563
- await runCreateAllShards(pollId, sysParams, context);
564
-
565
- await runAndAwaitTx(
566
- context.lucid,
567
- openStakingPosition(
568
- 1_000_000n,
569
- sysParams,
570
- context.lucid,
571
- (await findStakingManager(sysParams, context.lucid)).utxo,
572
- ),
573
- );
574
-
575
- await runVote(pollId, 'Yes', sysParams, context);
576
-
577
- const [pkh, _skh] = await addrDetails(context.lucid);
578
- const stakingPosUtxo = await findStakingPosition(
579
- context.lucid,
580
- sysParams.validatorHashes.stakingHash,
581
- fromSystemParamsAsset(sysParams.stakingParams.stakingToken),
582
- pkh.hash,
583
- );
584
-
585
- context.emulator.awaitSlot(60);
586
-
587
- await runAndAwaitTx(
588
- context.lucid,
589
- adjustStakingPosition(
590
- stakingPosUtxo.utxo,
591
- 500_000_000n,
592
- sysParams,
593
- context.lucid,
594
- context.emulator.slot,
595
- (await findStakingManager(sysParams, context.lucid)).utxo,
596
- ),
597
- );
598
- });
599
-
600
- test<MyContext>('Vote on 2 proposals sequentially (lower pollID first)', async (context: MyContext) => {
601
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
602
-
603
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg]);
604
-
605
- await runAndAwaitTx(
606
- context.lucid,
607
- openStakingPosition(
608
- 1_000_000n,
609
- sysParams,
610
- context.lucid,
611
- (await findStakingManager(sysParams, context.lucid)).utxo,
612
- ),
613
- );
614
- const [pkh, _] = await addrDetails(context.lucid);
615
-
616
- // Create proposals
617
- const createProposalsTask = F.pipe(
618
- [fromText('proposal 1'), fromText('proposal 2')].map(
619
- (txtContent): T.Task<bigint> => {
620
- return async () => {
621
- const govUtxo = await findGov(
622
- context.lucid,
623
- sysParams.validatorHashes.govHash,
624
- fromSystemParamsAsset(sysParams.govParams.govNFT),
625
- );
626
-
627
- const [tx, pollId] = await createProposal(
628
- { TextProposal: { bytes: txtContent } },
629
- null,
630
- sysParams,
631
- context.lucid,
632
- context.emulator.slot,
633
- govUtxo.utxo,
634
- [],
635
- );
636
-
637
- await runAndAwaitTxBuilder(context.lucid, tx);
638
-
639
- await runCreateAllShards(pollId, sysParams, context);
640
-
641
- return pollId;
642
- };
643
- },
644
- ),
645
- T.sequenceSeqArray,
646
- );
647
-
648
- const pollIds = await createProposalsTask();
649
-
650
- // vote on each proposal
651
- const voteEachProposalTask = F.pipe(
652
- pollIds.map(
653
- (pollId): T.Task<void> =>
654
- async () => {
655
- await runVote(
656
- pollId,
657
- Number(pollId) % 2 == 0 ? 'Yes' : 'No',
658
- sysParams,
659
- context,
660
- );
661
- },
662
- ),
663
- T.sequenceSeqArray,
664
- );
665
-
666
- await voteEachProposalTask();
667
-
668
- const stakingPosUtxo = await findStakingPosition(
669
- context.lucid,
670
- sysParams.validatorHashes.stakingHash,
671
- fromSystemParamsAsset(sysParams.stakingParams.stakingToken),
672
- pkh.hash,
673
- );
674
-
675
- expect([...stakingPosUtxo.datum.lockedAmount.keys()]).toEqual([1n, 2n]);
676
- });
677
-
678
- test<MyContext>('Vote on 2 proposals in reverse (higher pollID first), both yes and no votes', async (context: MyContext) => {
679
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
680
-
681
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg]);
682
-
683
- await runAndAwaitTx(
684
- context.lucid,
685
- openStakingPosition(
686
- 1_000_000n,
687
- sysParams,
688
- context.lucid,
689
- (await findStakingManager(sysParams, context.lucid)).utxo,
690
- ),
691
- );
692
- const [pkh, _] = await addrDetails(context.lucid);
693
-
694
- // Create proposals
695
- const createProposalsTask = F.pipe(
696
- [fromText('proposal 1'), fromText('proposal 2')].map(
697
- (txtContent): T.Task<bigint> => {
698
- return async () => {
699
- const govUtxo = await findGov(
700
- context.lucid,
701
- sysParams.validatorHashes.govHash,
702
- fromSystemParamsAsset(sysParams.govParams.govNFT),
703
- );
704
-
705
- const [tx, pollId] = await createProposal(
706
- { TextProposal: { bytes: txtContent } },
707
- null,
708
- sysParams,
709
- context.lucid,
710
- context.emulator.slot,
711
- govUtxo.utxo,
712
- [],
713
- );
714
-
715
- await runAndAwaitTxBuilder(context.lucid, tx);
716
-
717
- await runCreateAllShards(pollId, sysParams, context);
718
-
719
- return pollId;
720
- };
721
- },
722
- ),
723
- T.sequenceSeqArray,
724
- );
725
-
726
- const pollIdsDescending = F.pipe(
727
- await createProposalsTask(),
728
- RA.toArray, // Sort it from high to low
729
- A.map(Number),
730
- A.sort(N.Ord),
731
- A.map(BigInt),
732
- A.reverse,
733
- );
734
-
735
- // vote on each proposal
736
- const voteEachProposalTask = F.pipe(
737
- pollIdsDescending.map(
738
- (pollId): T.Task<void> =>
739
- async () => {
740
- await runVote(
741
- pollId,
742
- Number(pollId) % 2 == 0 ? 'Yes' : 'No',
743
- sysParams,
744
- context,
745
- );
746
- },
747
- ),
748
- T.sequenceSeqArray,
749
- );
750
-
751
- await voteEachProposalTask();
752
-
753
- const stakingPosUtxo = await findStakingPosition(
754
- context.lucid,
755
- sysParams.validatorHashes.stakingHash,
756
- fromSystemParamsAsset(sysParams.stakingParams.stakingToken),
757
- pkh.hash,
758
- );
759
-
760
- expect([...stakingPosUtxo.datum.lockedAmount.keys()]).toEqual([2n, 1n]);
761
- });
762
-
763
- test<MyContext>('End passed proposal', async (context: MyContext) => {
764
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
765
-
766
- const [sysParams, _] = await init(context.lucid, [iusdInitialAssetCfg]);
767
-
768
- const [tx, pollId] = await createProposal(
769
- { TextProposal: { bytes: fromText('smth') } },
770
- null,
771
- sysParams,
772
- context.lucid,
773
- context.emulator.slot,
774
- (
775
- await findGov(
776
- context.lucid,
777
- sysParams.validatorHashes.govHash,
778
- fromSystemParamsAsset(sysParams.govParams.govNFT),
779
- )
780
- ).utxo,
781
- [],
782
- );
783
-
784
- await runAndAwaitTxBuilder(context.lucid, tx);
785
-
786
- await runCreateAllShards(pollId, sysParams, context);
787
-
788
- await runAndAwaitTx(
789
- context.lucid,
790
- openStakingPosition(
791
- 100_000_000_000n,
792
- sysParams,
793
- context.lucid,
794
- (await findStakingManager(sysParams, context.lucid)).utxo,
795
- ),
796
- );
797
-
798
- await runVote(pollId, 'Yes', sysParams, context);
799
-
800
- await waitForVotingEnd(pollId, sysParams, context);
801
-
802
- await runMergeAllShards(pollId, sysParams, context);
803
-
804
- await runEndProposal(pollId, sysParams, context);
805
-
806
- await expect(
807
- findExecute(
808
- context.lucid,
809
- sysParams.validatorHashes.executeHash,
810
- fromSystemParamsAsset(sysParams.executeParams.upgradeToken),
811
- pollId,
812
- ),
813
- ).resolves.toBeDefined();
814
- });
815
-
816
- test<MyContext>('End failed proposal', async (context: MyContext) => {
817
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
818
-
819
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg]);
820
-
821
- const [tx, pollId] = await createProposal(
822
- { TextProposal: { bytes: fromText('smth') } },
823
- null,
824
- sysParams,
825
- context.lucid,
826
- context.emulator.slot,
827
- (
828
- await findGov(
829
- context.lucid,
830
- sysParams.validatorHashes.govHash,
831
- fromSystemParamsAsset(sysParams.govParams.govNFT),
832
- )
833
- ).utxo,
834
- [],
835
- );
836
-
837
- await runAndAwaitTxBuilder(context.lucid, tx);
838
-
839
- await runCreateAllShards(pollId, sysParams, context);
840
-
841
- await runAndAwaitTx(
842
- context.lucid,
843
- openStakingPosition(
844
- 100_000_000_000n,
845
- sysParams,
846
- context.lucid,
847
- (await findStakingManager(sysParams, context.lucid)).utxo,
848
- ),
849
- );
850
-
851
- await runVote(pollId, 'No', sysParams, context);
852
-
853
- {
854
- const pollUtxo = await findPollManager(
855
- context.lucid,
856
- sysParams.validatorHashes.pollManagerHash,
857
- fromSystemParamsAsset(sysParams.pollManagerParams.pollToken),
858
- pollId,
859
- );
860
-
861
- const targetSlot = unixTimeToSlot(
862
- context.lucid.config().network!,
863
- Number(pollUtxo.datum.votingEndTime),
864
- );
865
- expect(targetSlot).toBeGreaterThan(context.emulator.slot);
866
-
867
- context.emulator.awaitSlot(targetSlot - context.emulator.slot + 1);
868
- }
869
-
870
- await runMergeAllShards(pollId, sysParams, context);
871
-
872
- const pollUtxo = await findPollManager(
873
- context.lucid,
874
- sysParams.validatorHashes.pollManagerHash,
875
- fromSystemParamsAsset(sysParams.pollManagerParams.pollToken),
876
- pollId,
877
- );
878
-
879
- const govUtxo = await findGov(
880
- context.lucid,
881
- sysParams.validatorHashes.govHash,
882
- fromSystemParamsAsset(sysParams.govParams.govNFT),
883
- );
884
-
885
- const [_, newUtxos] = await getNewUtxosAtAddressAfterAction(
886
- context.lucid,
887
- createScriptAddress(
888
- context.lucid.config().network!,
889
- sysParams.validatorHashes.treasuryHash,
890
- ),
891
- () =>
892
- runAndAwaitTx(
893
- context.lucid,
894
- endProposal(
895
- pollUtxo.utxo,
896
- govUtxo.utxo,
897
- sysParams,
898
- context.lucid,
899
- context.emulator.slot,
900
- ),
901
- ),
902
- );
903
-
904
- const treasuryOutput = matchSingle(
905
- newUtxos,
906
- () => new Error('Expected single treasury output'),
907
- );
908
-
909
- assert(
910
- assetClassValueOf(
911
- treasuryOutput.assets,
912
- fromSystemParamsAsset(sysParams.govParams.indyAsset),
913
- ) === govUtxo.datum.protocolParams.proposalDeposit,
914
- 'Treasury should get proposal deposit back on failed proposal end',
915
- );
916
-
917
- await expect(
918
- findExecute(
919
- context.lucid,
920
- sysParams.validatorHashes.executeHash,
921
- fromSystemParamsAsset(sysParams.executeParams.upgradeToken),
922
- pollId,
923
- ),
924
- ).rejects.toThrow();
925
- });
926
-
927
- test<MyContext>('Execute text proposal', async (context: MyContext) => {
928
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
929
-
930
- const [sysParams, _] = await init(context.lucid, [iusdInitialAssetCfg]);
931
-
932
- const [tx, pollId] = await createProposal(
933
- { TextProposal: { bytes: fromText('smth') } },
934
- null,
935
- sysParams,
936
- context.lucid,
937
- context.emulator.slot,
938
- (
939
- await findGov(
940
- context.lucid,
941
- sysParams.validatorHashes.govHash,
942
- fromSystemParamsAsset(sysParams.govParams.govNFT),
943
- )
944
- ).utxo,
945
- [],
946
- );
947
-
948
- await runAndAwaitTxBuilder(context.lucid, tx);
949
-
950
- await runCreateAllShards(pollId, sysParams, context);
951
-
952
- await runAndAwaitTx(
953
- context.lucid,
954
- openStakingPosition(
955
- 100_000_000_000n,
956
- sysParams,
957
- context.lucid,
958
- (await findStakingManager(sysParams, context.lucid)).utxo,
959
- ),
960
- );
961
-
962
- await runVote(pollId, 'Yes', sysParams, context);
963
-
964
- await waitForVotingEnd(pollId, sysParams, context);
965
-
966
- await runMergeAllShards(pollId, sysParams, context);
967
-
968
- await runEndProposal(pollId, sysParams, context);
969
-
970
- const govUtxo = await findGov(
971
- context.lucid,
972
- sysParams.validatorHashes.govHash,
973
- fromSystemParamsAsset(sysParams.govParams.govNFT),
974
- );
975
- const executeUtxo = await findExecute(
976
- context.lucid,
977
- sysParams.validatorHashes.executeHash,
978
- fromSystemParamsAsset(sysParams.executeParams.upgradeToken),
979
- pollId,
980
- );
981
-
982
- await runAndAwaitTx(
983
- context.lucid,
984
- executeProposal(
985
- executeUtxo.utxo,
986
- govUtxo.utxo,
987
- null,
988
- null,
989
- null,
990
- sysParams,
991
- context.lucid,
992
- context.emulator.slot,
993
- ),
994
- );
995
- });
996
-
997
- test<MyContext>('Execute text proposal with treasury withdrawal', async (context: MyContext) => {
998
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
999
-
1000
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg]);
1001
-
1002
- const withdrawalIndyAmt = 1_000n;
1003
- const treasuryWithdrawalUtxo = await createUtxoAtTreasury(
1004
- withdrawalIndyAmt,
1005
- sysParams,
1006
- context,
1007
- );
1008
-
1009
- const [tx, pollId] = await createProposal(
1010
- { TextProposal: { bytes: fromText('smth') } },
1011
- {
1012
- destination: addressFromBech32(context.users.withdrawalAccount.address),
1013
- value: [
1014
- [
1015
- sysParams.govParams.indyAsset[0].unCurrencySymbol,
1016
- fromText(sysParams.govParams.indyAsset[1].unTokenName),
1017
- withdrawalIndyAmt,
1018
- ],
1019
- ],
1020
- },
1021
- sysParams,
1022
- context.lucid,
1023
- context.emulator.slot,
1024
- (
1025
- await findGov(
1026
- context.lucid,
1027
- sysParams.validatorHashes.govHash,
1028
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1029
- )
1030
- ).utxo,
1031
- [],
1032
- );
1033
-
1034
- await runAndAwaitTxBuilder(context.lucid, tx);
1035
-
1036
- await runCreateAllShards(pollId, sysParams, context);
1037
-
1038
- await runAndAwaitTx(
1039
- context.lucid,
1040
- openStakingPosition(
1041
- 100_000_000_000n,
1042
- sysParams,
1043
- context.lucid,
1044
- (await findStakingManager(sysParams, context.lucid)).utxo,
1045
- ),
1046
- );
1047
-
1048
- await runVote(pollId, 'Yes', sysParams, context);
1049
-
1050
- await waitForVotingEnd(pollId, sysParams, context);
1051
-
1052
- await runMergeAllShards(pollId, sysParams, context);
1053
-
1054
- await runEndProposal(pollId, sysParams, context);
1055
-
1056
- const govUtxo = await findGov(
1057
- context.lucid,
1058
- sysParams.validatorHashes.govHash,
1059
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1060
- );
1061
- const executeUtxo = await findExecute(
1062
- context.lucid,
1063
- sysParams.validatorHashes.executeHash,
1064
- fromSystemParamsAsset(sysParams.executeParams.upgradeToken),
1065
- pollId,
1066
- );
1067
-
1068
- const [_, newVal] = await getValueChangeAtAddressAfterAction(
1069
- context.lucid,
1070
- context.users.withdrawalAccount.address,
1071
- async () =>
1072
- await runAndAwaitTx(
1073
- context.lucid,
1074
- executeProposal(
1075
- executeUtxo.utxo,
1076
- govUtxo.utxo,
1077
- treasuryWithdrawalUtxo,
1078
- null,
1079
- null,
1080
- sysParams,
1081
- context.lucid,
1082
- context.emulator.slot,
1083
- ),
1084
- ),
1085
- );
1086
-
1087
- expect(
1088
- assetClassValueOf(
1089
- newVal,
1090
- fromSystemParamsAsset(sysParams.govParams.indyAsset),
1091
- ) === withdrawalIndyAmt,
1092
- 'Unexpected withdrawn indy amt',
1093
- ).toBeTruthy();
1094
- });
1095
-
1096
- test<MyContext>('Execute create asset proposal', async (context: MyContext) => {
1097
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
1098
-
1099
- const [sysParams, _] = await init(context.lucid, [iusdInitialAssetCfg]);
1100
-
1101
- const [pkh, __] = await addrDetails(context.lucid);
1102
-
1103
- const [startInterestTx, interestOracleNft] = await startInterestOracle(
1104
- 0n,
1105
- 0n,
1106
- 0n,
1107
- {
1108
- biasTime: 120_000n,
1109
- owner: pkh.hash,
1110
- },
1111
- context.lucid,
1112
- );
1113
- await runAndAwaitTxBuilder(context.lucid, startInterestTx);
1114
-
1115
- const [priceOracleTx, priceOranceNft] = await startPriceOracleTx(
1116
- context.lucid,
1117
- 'IBTC_ORACLE',
1118
- { getOnChainInt: 1_000_000n },
1119
- { biasTime: 120_000n, expiration: 1_800_000n, owner: pkh.hash },
1120
- );
1121
- await runAndAwaitTxBuilder(context.lucid, priceOracleTx);
1122
-
1123
- const govUtxo = await findGov(
1124
- context.lucid,
1125
- sysParams.validatorHashes.govHash,
1126
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1127
- );
1128
-
1129
- const [tx, pollId] = await createProposal(
1130
- {
1131
- ProposeAsset: {
1132
- asset: fromText('iBTC'),
1133
- priceOracleNft: priceOranceNft,
1134
- interestOracleNft: interestOracleNft,
1135
- redemptionRatioPercentage: { getOnChainInt: 200_000_000n },
1136
- maintenanceRatioPercentage: { getOnChainInt: 150_000_000n },
1137
- liquidationRatioPercentage: { getOnChainInt: 120_000_000n },
1138
- debtMintingFeePercentage: { getOnChainInt: 500_000n },
1139
- liquidationProcessingFeePercentage: { getOnChainInt: 2_000_000n },
1140
- stabilityPoolWithdrawalFeePercentage: { getOnChainInt: 500_000n },
1141
- redemptionReimbursementPercentage: { getOnChainInt: 1_000_000n },
1142
- redemptionProcessingFeePercentage: { getOnChainInt: 1_000_000n },
1143
- interestCollectorPortionPercentage: { getOnChainInt: 40_000_000n },
1144
- },
1145
- },
1146
- null,
1147
- sysParams,
1148
- context.lucid,
1149
- context.emulator.slot,
1150
- govUtxo.utxo,
1151
- (
1152
- await findAllIAssets(
1153
- context.lucid,
1154
- sysParams.validatorHashes.cdpHash,
1155
- fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
1156
- )
1157
- ).map((iasset) => iasset.utxo),
1158
- );
1159
-
1160
- await runAndAwaitTxBuilder(context.lucid, tx);
1161
-
1162
- await runCreateAllShards(pollId, sysParams, context);
1163
-
1164
- await runAndAwaitTx(
1165
- context.lucid,
1166
- openStakingPosition(
1167
- 100_000_000_000n,
1168
- sysParams,
1169
- context.lucid,
1170
- (await findStakingManager(sysParams, context.lucid)).utxo,
1171
- ),
1172
- );
1173
-
1174
- await runVote(pollId, 'Yes', sysParams, context);
1175
-
1176
- await waitForVotingEnd(pollId, sysParams, context);
1177
-
1178
- await runMergeAllShards(pollId, sysParams, context);
1179
-
1180
- await runEndProposal(pollId, sysParams, context);
1181
-
1182
- const executeUtxo = await findExecute(
1183
- context.lucid,
1184
- sysParams.validatorHashes.executeHash,
1185
- fromSystemParamsAsset(sysParams.executeParams.upgradeToken),
1186
- pollId,
1187
- );
1188
-
1189
- await runAndAwaitTx(
1190
- context.lucid,
1191
- executeProposal(
1192
- executeUtxo.utxo,
1193
- (
1194
- await findGov(
1195
- context.lucid,
1196
- sysParams.validatorHashes.govHash,
1197
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1198
- )
1199
- ).utxo,
1200
- null,
1201
- (
1202
- await findAllIAssets(
1203
- context.lucid,
1204
- sysParams.validatorHashes.cdpHash,
1205
- fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
1206
- )
1207
- ).map((iasset) => iasset.utxo),
1208
- null,
1209
- sysParams,
1210
- context.lucid,
1211
- context.emulator.slot,
1212
- ),
1213
- );
1214
- });
1215
-
1216
- test<MyContext>('Execute create asset proposal with treasury withdrawal', async (context: MyContext) => {
1217
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
1218
-
1219
- const [sysParams, _] = await init(context.lucid, [iusdInitialAssetCfg]);
1220
-
1221
- const [pkh, ___] = await addrDetails(context.lucid);
1222
-
1223
- const withdrawalIndyAmt = 1_000n;
1224
- const treasuryWithdrawalUtxo = await createUtxoAtTreasury(
1225
- withdrawalIndyAmt,
1226
- sysParams,
1227
- context,
1228
- );
1229
-
1230
- const [startInterestTx, interestOracleNft] = await startInterestOracle(
1231
- 0n,
1232
- 0n,
1233
- 0n,
1234
- {
1235
- biasTime: 120_000n,
1236
- owner: pkh.hash,
1237
- },
1238
- context.lucid,
1239
- );
1240
- await runAndAwaitTxBuilder(context.lucid, startInterestTx);
1241
-
1242
- const [priceOracleTx, priceOranceNft] = await startPriceOracleTx(
1243
- context.lucid,
1244
- 'IBTC_ORACLE',
1245
- { getOnChainInt: 1_000_000n },
1246
- { biasTime: 120_000n, expiration: 1_800_000n, owner: pkh.hash },
1247
- );
1248
- await runAndAwaitTxBuilder(context.lucid, priceOracleTx);
1249
-
1250
- const govUtxo = await findGov(
1251
- context.lucid,
1252
- sysParams.validatorHashes.govHash,
1253
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1254
- );
1255
-
1256
- const [tx, pollId] = await createProposal(
1257
- {
1258
- ProposeAsset: {
1259
- asset: fromText('iBTC'),
1260
- priceOracleNft: priceOranceNft,
1261
- interestOracleNft: interestOracleNft,
1262
- redemptionRatioPercentage: { getOnChainInt: 200_000_000n },
1263
- maintenanceRatioPercentage: { getOnChainInt: 150_000_000n },
1264
- liquidationRatioPercentage: { getOnChainInt: 120_000_000n },
1265
- debtMintingFeePercentage: { getOnChainInt: 500_000n },
1266
- liquidationProcessingFeePercentage: { getOnChainInt: 2_000_000n },
1267
- stabilityPoolWithdrawalFeePercentage: { getOnChainInt: 500_000n },
1268
- redemptionReimbursementPercentage: { getOnChainInt: 1_000_000n },
1269
- redemptionProcessingFeePercentage: { getOnChainInt: 1_000_000n },
1270
- interestCollectorPortionPercentage: { getOnChainInt: 40_000_000n },
1271
- },
1272
- },
1273
- {
1274
- destination: addressFromBech32(context.users.withdrawalAccount.address),
1275
- value: [
1276
- [
1277
- sysParams.govParams.indyAsset[0].unCurrencySymbol,
1278
- fromText(sysParams.govParams.indyAsset[1].unTokenName),
1279
- withdrawalIndyAmt,
1280
- ],
1281
- ],
1282
- },
1283
- sysParams,
1284
- context.lucid,
1285
- context.emulator.slot,
1286
- govUtxo.utxo,
1287
- (
1288
- await findAllIAssets(
1289
- context.lucid,
1290
- sysParams.validatorHashes.cdpHash,
1291
- fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
1292
- )
1293
- ).map((iasset) => iasset.utxo),
1294
- );
1295
-
1296
- await runAndAwaitTxBuilder(context.lucid, tx);
1297
-
1298
- await runCreateAllShards(pollId, sysParams, context);
1299
-
1300
- await runAndAwaitTx(
1301
- context.lucid,
1302
- openStakingPosition(
1303
- 100_000_000_000n,
1304
- sysParams,
1305
- context.lucid,
1306
- (await findStakingManager(sysParams, context.lucid)).utxo,
1307
- ),
1308
- );
1309
-
1310
- await runVote(pollId, 'Yes', sysParams, context);
1311
-
1312
- await waitForVotingEnd(pollId, sysParams, context);
1313
-
1314
- await runMergeAllShards(pollId, sysParams, context);
1315
-
1316
- await runEndProposal(pollId, sysParams, context);
1317
-
1318
- const executeUtxo = await findExecute(
1319
- context.lucid,
1320
- sysParams.validatorHashes.executeHash,
1321
- fromSystemParamsAsset(sysParams.executeParams.upgradeToken),
1322
- pollId,
1323
- );
1324
-
1325
- const [__, newVal] = await getValueChangeAtAddressAfterAction(
1326
- context.lucid,
1327
- context.users.withdrawalAccount.address,
1328
- async () =>
1329
- runAndAwaitTx(
1330
- context.lucid,
1331
- executeProposal(
1332
- executeUtxo.utxo,
1333
- (
1334
- await findGov(
1335
- context.lucid,
1336
- sysParams.validatorHashes.govHash,
1337
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1338
- )
1339
- ).utxo,
1340
- treasuryWithdrawalUtxo,
1341
- (
1342
- await findAllIAssets(
1343
- context.lucid,
1344
- sysParams.validatorHashes.cdpHash,
1345
- fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
1346
- )
1347
- ).map((iasset) => iasset.utxo),
1348
- null,
1349
- sysParams,
1350
- context.lucid,
1351
- context.emulator.slot,
1352
- ),
1353
- ),
1354
- );
1355
-
1356
- expect(
1357
- assetClassValueOf(
1358
- newVal,
1359
- fromSystemParamsAsset(sysParams.govParams.indyAsset),
1360
- ) === withdrawalIndyAmt,
1361
- 'Unexpected withdrawn indy amt',
1362
- ).toBeTruthy();
1363
- });
1364
-
1365
- test<MyContext>('Execute modify asset proposal', async (context: MyContext) => {
1366
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
1367
-
1368
- const [sysParams, _] = await init(context.lucid, [iusdInitialAssetCfg]);
1369
-
1370
- const govUtxo = await findGov(
1371
- context.lucid,
1372
- sysParams.validatorHashes.govHash,
1373
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1374
- );
1375
-
1376
- const iassetToModify = await findIAsset(
1377
- context.lucid,
1378
- sysParams.validatorHashes.cdpHash,
1379
- fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
1380
- 'iUSD',
1381
- );
1382
-
1383
- const [tx, pollId] = await createProposal(
1384
- {
1385
- ModifyAsset: {
1386
- asset: fromText('iUSD'),
1387
- newAssetPriceInfo: iassetToModify.datum.price,
1388
- newInterestOracleNft: iassetToModify.datum.interestOracleNft,
1389
- newRedemptionRatioPercentage: iassetToModify.datum.redemptionRatio,
1390
- newMaintenanceRatioPercentage: iassetToModify.datum.maintenanceRatio,
1391
- newLiquidationRatioPercentage: iassetToModify.datum.liquidationRatio,
1392
- newDebtMintingFeePercentage:
1393
- iassetToModify.datum.debtMintingFeePercentage,
1394
- newLiquidationProcessingFeePercentage:
1395
- iassetToModify.datum.liquidationProcessingFeePercentage,
1396
- newStabilityPoolWithdrawalFeePercentage:
1397
- iassetToModify.datum.stabilityPoolWithdrawalFeePercentage,
1398
- newRedemptionReimbursementPercentage:
1399
- iassetToModify.datum.redemptionReimbursementPercentage,
1400
- newRedemptionProcessingFeePercentage:
1401
- iassetToModify.datum.redemptionProcessingFeePercentage,
1402
- newInterestCollectorPortionPercentage:
1403
- iassetToModify.datum.interestCollectorPortionPercentage,
1404
- },
1405
- },
1406
- null,
1407
- sysParams,
1408
- context.lucid,
1409
- context.emulator.slot,
1410
- govUtxo.utxo,
1411
- [],
1412
- );
1413
-
1414
- await runAndAwaitTxBuilder(context.lucid, tx);
1415
-
1416
- await runCreateAllShards(pollId, sysParams, context);
1417
-
1418
- await runAndAwaitTx(
1419
- context.lucid,
1420
- openStakingPosition(
1421
- 100_000_000_000n,
1422
- sysParams,
1423
- context.lucid,
1424
- (await findStakingManager(sysParams, context.lucid)).utxo,
1425
- ),
1426
- );
1427
-
1428
- await runVote(pollId, 'Yes', sysParams, context);
1429
-
1430
- await waitForVotingEnd(pollId, sysParams, context);
1431
-
1432
- await runMergeAllShards(pollId, sysParams, context);
1433
-
1434
- await runEndProposal(pollId, sysParams, context);
1435
-
1436
- const executeUtxo = await findExecute(
1437
- context.lucid,
1438
- sysParams.validatorHashes.executeHash,
1439
- fromSystemParamsAsset(sysParams.executeParams.upgradeToken),
1440
- pollId,
1441
- );
1442
-
1443
- await runAndAwaitTx(
1444
- context.lucid,
1445
- executeProposal(
1446
- executeUtxo.utxo,
1447
- (
1448
- await findGov(
1449
- context.lucid,
1450
- sysParams.validatorHashes.govHash,
1451
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1452
- )
1453
- ).utxo,
1454
- null,
1455
- null,
1456
- iassetToModify.utxo,
1457
- sysParams,
1458
- context.lucid,
1459
- context.emulator.slot,
1460
- ),
1461
- );
1462
- });
1463
-
1464
- test<MyContext>('Execute modify asset proposal with treasury withdrawal', async (context: MyContext) => {
1465
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
1466
-
1467
- const [sysParams, _] = await init(context.lucid, [iusdInitialAssetCfg]);
1468
-
1469
- const withdrawalIndyAmt = 1_000n;
1470
- const treasuryWithdrawalUtxo = await createUtxoAtTreasury(
1471
- withdrawalIndyAmt,
1472
- sysParams,
1473
- context,
1474
- );
1475
-
1476
- const govUtxo = await findGov(
1477
- context.lucid,
1478
- sysParams.validatorHashes.govHash,
1479
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1480
- );
1481
-
1482
- const iassetToModify = await findIAsset(
1483
- context.lucid,
1484
- sysParams.validatorHashes.cdpHash,
1485
- fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
1486
- 'iUSD',
1487
- );
1488
-
1489
- const [tx, pollId] = await createProposal(
1490
- {
1491
- ModifyAsset: {
1492
- asset: fromText('iUSD'),
1493
- newAssetPriceInfo: iassetToModify.datum.price,
1494
- newInterestOracleNft: iassetToModify.datum.interestOracleNft,
1495
- newRedemptionRatioPercentage: iassetToModify.datum.redemptionRatio,
1496
- newMaintenanceRatioPercentage: iassetToModify.datum.maintenanceRatio,
1497
- newLiquidationRatioPercentage: iassetToModify.datum.liquidationRatio,
1498
- newDebtMintingFeePercentage:
1499
- iassetToModify.datum.debtMintingFeePercentage,
1500
- newLiquidationProcessingFeePercentage:
1501
- iassetToModify.datum.liquidationProcessingFeePercentage,
1502
- newStabilityPoolWithdrawalFeePercentage:
1503
- iassetToModify.datum.stabilityPoolWithdrawalFeePercentage,
1504
- newRedemptionReimbursementPercentage:
1505
- iassetToModify.datum.redemptionReimbursementPercentage,
1506
- newRedemptionProcessingFeePercentage:
1507
- iassetToModify.datum.redemptionProcessingFeePercentage,
1508
- newInterestCollectorPortionPercentage:
1509
- iassetToModify.datum.interestCollectorPortionPercentage,
1510
- },
1511
- },
1512
- {
1513
- destination: addressFromBech32(context.users.withdrawalAccount.address),
1514
- value: [
1515
- [
1516
- sysParams.govParams.indyAsset[0].unCurrencySymbol,
1517
- fromText(sysParams.govParams.indyAsset[1].unTokenName),
1518
- withdrawalIndyAmt,
1519
- ],
1520
- ],
1521
- },
1522
- sysParams,
1523
- context.lucid,
1524
- context.emulator.slot,
1525
- govUtxo.utxo,
1526
- [],
1527
- );
1528
-
1529
- await runAndAwaitTxBuilder(context.lucid, tx);
1530
-
1531
- await runCreateAllShards(pollId, sysParams, context);
1532
-
1533
- await runAndAwaitTx(
1534
- context.lucid,
1535
- openStakingPosition(
1536
- 100_000_000_000n,
1537
- sysParams,
1538
- context.lucid,
1539
- (await findStakingManager(sysParams, context.lucid)).utxo,
1540
- ),
1541
- );
1542
-
1543
- await runVote(pollId, 'Yes', sysParams, context);
1544
-
1545
- await waitForVotingEnd(pollId, sysParams, context);
1546
-
1547
- await runMergeAllShards(pollId, sysParams, context);
1548
-
1549
- await runEndProposal(pollId, sysParams, context);
1550
-
1551
- const executeUtxo = await findExecute(
1552
- context.lucid,
1553
- sysParams.validatorHashes.executeHash,
1554
- fromSystemParamsAsset(sysParams.executeParams.upgradeToken),
1555
- pollId,
1556
- );
1557
-
1558
- const [__, newVal] = await getValueChangeAtAddressAfterAction(
1559
- context.lucid,
1560
- context.users.withdrawalAccount.address,
1561
- async () =>
1562
- runAndAwaitTx(
1563
- context.lucid,
1564
- executeProposal(
1565
- executeUtxo.utxo,
1566
- (
1567
- await findGov(
1568
- context.lucid,
1569
- sysParams.validatorHashes.govHash,
1570
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1571
- )
1572
- ).utxo,
1573
- treasuryWithdrawalUtxo,
1574
- null,
1575
- iassetToModify.utxo,
1576
- sysParams,
1577
- context.lucid,
1578
- context.emulator.slot,
1579
- ),
1580
- ),
1581
- );
1582
-
1583
- expect(
1584
- assetClassValueOf(
1585
- newVal,
1586
- fromSystemParamsAsset(sysParams.govParams.indyAsset),
1587
- ) === withdrawalIndyAmt,
1588
- 'Unexpected withdrawn indy amt',
1589
- ).toBeTruthy();
1590
- });
1591
-
1592
- test<MyContext>('Execute modify protocol params proposal', async (context: MyContext) => {
1593
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
1594
-
1595
- const [sysParams, _] = await init(context.lucid, [iusdInitialAssetCfg]);
1596
-
1597
- const govUtxo = await findGov(
1598
- context.lucid,
1599
- sysParams.validatorHashes.govHash,
1600
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1601
- );
1602
-
1603
- const [tx, pollId] = await createProposal(
1604
- {
1605
- ModifyProtocolParams: {
1606
- newParams: {
1607
- proposalDeposit: govUtxo.datum.protocolParams.proposalDeposit * 2n,
1608
- votingPeriod: ONE_DAY * 2n,
1609
- effectiveDelay: govUtxo.datum.protocolParams.effectiveDelay,
1610
- expirationPeriod: ONE_DAY * 2n,
1611
- collateralFeePercentage:
1612
- govUtxo.datum.protocolParams.collateralFeePercentage,
1613
- proposingPeriod: ONE_DAY,
1614
- /// Total numer of shards used for voting.
1615
- totalShards: govUtxo.datum.protocolParams.totalShards,
1616
- /// The minimum number of votes (yes + no votes) for a proposal to be possible to pass.
1617
- minimumQuorum: govUtxo.datum.protocolParams.minimumQuorum,
1618
- /// Maximum amount of lovelaces that can be spent at once from the treasury.
1619
- maxTreasuryLovelaceSpend:
1620
- govUtxo.datum.protocolParams.maxTreasuryLovelaceSpend,
1621
- /// Maximum amount of INDY that can be spent at once from the treasury.
1622
- maxTreasuryIndySpend:
1623
- govUtxo.datum.protocolParams.maxTreasuryIndySpend,
1624
- },
1625
- },
1626
- },
1627
- null,
1628
- sysParams,
1629
- context.lucid,
1630
- context.emulator.slot,
1631
- govUtxo.utxo,
1632
- [],
1633
- );
1634
-
1635
- await runAndAwaitTxBuilder(context.lucid, tx);
1636
-
1637
- await runCreateAllShards(pollId, sysParams, context);
1638
-
1639
- await runAndAwaitTx(
1640
- context.lucid,
1641
- openStakingPosition(
1642
- 100_000_000_000n,
1643
- sysParams,
1644
- context.lucid,
1645
- (await findStakingManager(sysParams, context.lucid)).utxo,
1646
- ),
1647
- );
1648
-
1649
- await runVote(pollId, 'Yes', sysParams, context);
1650
-
1651
- await waitForVotingEnd(pollId, sysParams, context);
1652
-
1653
- await runMergeAllShards(pollId, sysParams, context);
1654
-
1655
- await runEndProposal(pollId, sysParams, context);
1656
-
1657
- const executeUtxo = await findExecute(
1658
- context.lucid,
1659
- sysParams.validatorHashes.executeHash,
1660
- fromSystemParamsAsset(sysParams.executeParams.upgradeToken),
1661
- pollId,
1662
- );
1663
-
1664
- await runAndAwaitTx(
1665
- context.lucid,
1666
- executeProposal(
1667
- executeUtxo.utxo,
1668
- (
1669
- await findGov(
1670
- context.lucid,
1671
- sysParams.validatorHashes.govHash,
1672
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1673
- )
1674
- ).utxo,
1675
- null,
1676
- null,
1677
- null,
1678
- sysParams,
1679
- context.lucid,
1680
- context.emulator.slot,
1681
- ),
1682
- );
1683
- });
1684
-
1685
- test<MyContext>('Execute modify protocol params proposal with treasury withdrawal', async (context: MyContext) => {
1686
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
1687
-
1688
- const [sysParams, _] = await init(context.lucid, [iusdInitialAssetCfg]);
1689
-
1690
- const withdrawalIndyAmt = 1_000n;
1691
- const treasuryWithdrawalUtxo = await createUtxoAtTreasury(
1692
- withdrawalIndyAmt,
1693
- sysParams,
1694
- context,
1695
- );
1696
-
1697
- const govUtxo = await findGov(
1698
- context.lucid,
1699
- sysParams.validatorHashes.govHash,
1700
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1701
- );
1702
-
1703
- const [tx, pollId] = await createProposal(
1704
- {
1705
- ModifyProtocolParams: {
1706
- newParams: {
1707
- proposalDeposit: govUtxo.datum.protocolParams.proposalDeposit * 2n,
1708
- votingPeriod: ONE_DAY * 2n,
1709
- effectiveDelay: govUtxo.datum.protocolParams.effectiveDelay,
1710
- expirationPeriod: ONE_DAY * 2n,
1711
- collateralFeePercentage:
1712
- govUtxo.datum.protocolParams.collateralFeePercentage,
1713
- proposingPeriod: ONE_DAY,
1714
- /// Total numer of shards used for voting.
1715
- totalShards: govUtxo.datum.protocolParams.totalShards,
1716
- /// The minimum number of votes (yes + no votes) for a proposal to be possible to pass.
1717
- minimumQuorum: govUtxo.datum.protocolParams.minimumQuorum,
1718
- /// Maximum amount of lovelaces that can be spent at once from the treasury.
1719
- maxTreasuryLovelaceSpend:
1720
- govUtxo.datum.protocolParams.maxTreasuryLovelaceSpend,
1721
- /// Maximum amount of INDY that can be spent at once from the treasury.
1722
- maxTreasuryIndySpend:
1723
- govUtxo.datum.protocolParams.maxTreasuryIndySpend,
1724
- },
1725
- },
1726
- },
1727
- {
1728
- destination: addressFromBech32(context.users.withdrawalAccount.address),
1729
- value: [
1730
- [
1731
- sysParams.govParams.indyAsset[0].unCurrencySymbol,
1732
- fromText(sysParams.govParams.indyAsset[1].unTokenName),
1733
- withdrawalIndyAmt,
1734
- ],
1735
- ],
1736
- },
1737
- sysParams,
1738
- context.lucid,
1739
- context.emulator.slot,
1740
- govUtxo.utxo,
1741
- [],
1742
- );
1743
-
1744
- await runAndAwaitTxBuilder(context.lucid, tx);
1745
-
1746
- await runCreateAllShards(pollId, sysParams, context);
1747
-
1748
- await runAndAwaitTx(
1749
- context.lucid,
1750
- openStakingPosition(
1751
- 100_000_000_000n,
1752
- sysParams,
1753
- context.lucid,
1754
- (await findStakingManager(sysParams, context.lucid)).utxo,
1755
- ),
1756
- );
1757
-
1758
- await runVote(pollId, 'Yes', sysParams, context);
1759
-
1760
- await waitForVotingEnd(pollId, sysParams, context);
1761
-
1762
- await runMergeAllShards(pollId, sysParams, context);
1763
-
1764
- await runEndProposal(pollId, sysParams, context);
1765
-
1766
- const executeUtxo = await findExecute(
1767
- context.lucid,
1768
- sysParams.validatorHashes.executeHash,
1769
- fromSystemParamsAsset(sysParams.executeParams.upgradeToken),
1770
- pollId,
1771
- );
1772
-
1773
- const [__, newVal] = await getValueChangeAtAddressAfterAction(
1774
- context.lucid,
1775
- context.users.withdrawalAccount.address,
1776
- async () =>
1777
- runAndAwaitTx(
1778
- context.lucid,
1779
- executeProposal(
1780
- executeUtxo.utxo,
1781
- (
1782
- await findGov(
1783
- context.lucid,
1784
- sysParams.validatorHashes.govHash,
1785
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1786
- )
1787
- ).utxo,
1788
- treasuryWithdrawalUtxo,
1789
- null,
1790
- null,
1791
- sysParams,
1792
- context.lucid,
1793
- context.emulator.slot,
1794
- ),
1795
- ),
1796
- );
1797
-
1798
- expect(
1799
- assetClassValueOf(
1800
- newVal,
1801
- fromSystemParamsAsset(sysParams.govParams.indyAsset),
1802
- ) === withdrawalIndyAmt,
1803
- 'Unexpected withdrawn indy amt',
1804
- ).toBeTruthy();
1805
- });
1806
-
1807
- test<MyContext>('Execute upgrade protocol proposal', async (context: MyContext) => {
1808
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
1809
-
1810
- const [sysParams, _] = await init(context.lucid, [iusdInitialAssetCfg]);
1811
-
1812
- const govUtxo = await findGov(
1813
- context.lucid,
1814
- sysParams.validatorHashes.govHash,
1815
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1816
- );
1817
-
1818
- const [tx, pollId] = await createProposal(
1819
- {
1820
- UpgradeProtocol: {
1821
- content: serialiseUpgradePaths({
1822
- upgradeId: govUtxo.datum.currentVersion + 1n,
1823
- upgradePaths: new Map([
1824
- [
1825
- fromHex(sysParams.validatorHashes.cdpHash),
1826
- // NOTICE: this is just a placeholder, in real scenario it needs upgrade minting policy hash
1827
- {
1828
- upgradeSymbol: fromHex(
1829
- sysParams.validatorHashes.cdpCreatorHash,
1830
- ),
1831
- },
1832
- ],
1833
- ]),
1834
- }),
1835
- },
1836
- },
1837
- null,
1838
- sysParams,
1839
- context.lucid,
1840
- context.emulator.slot,
1841
- govUtxo.utxo,
1842
- [],
1843
- );
1844
-
1845
- await runAndAwaitTxBuilder(context.lucid, tx);
1846
-
1847
- await runCreateAllShards(pollId, sysParams, context);
1848
-
1849
- await runAndAwaitTx(
1850
- context.lucid,
1851
- openStakingPosition(
1852
- 100_000_000_000n,
1853
- sysParams,
1854
- context.lucid,
1855
- (await findStakingManager(sysParams, context.lucid)).utxo,
1856
- ),
1857
- );
1858
-
1859
- await runVote(pollId, 'Yes', sysParams, context);
1860
-
1861
- await waitForVotingEnd(pollId, sysParams, context);
1862
-
1863
- await runMergeAllShards(pollId, sysParams, context);
1864
-
1865
- await runEndProposal(pollId, sysParams, context);
1866
-
1867
- const executeUtxo = await findExecute(
1868
- context.lucid,
1869
- sysParams.validatorHashes.executeHash,
1870
- fromSystemParamsAsset(sysParams.executeParams.upgradeToken),
1871
- pollId,
1872
- );
1873
-
1874
- await runAndAwaitTx(
1875
- context.lucid,
1876
- executeProposal(
1877
- executeUtxo.utxo,
1878
- (
1879
- await findGov(
1880
- context.lucid,
1881
- sysParams.validatorHashes.govHash,
1882
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1883
- )
1884
- ).utxo,
1885
- null,
1886
- null,
1887
- null,
1888
- sysParams,
1889
- context.lucid,
1890
- context.emulator.slot,
1891
- ),
1892
- );
1893
- });
1894
-
1895
- test<MyContext>('Execute upgrade protocol proposal with withdrawal', async (context: MyContext) => {
1896
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
1897
-
1898
- const [sysParams, _] = await init(context.lucid, [iusdInitialAssetCfg]);
1899
-
1900
- const withdrawalIndyAmt = 1_000n;
1901
- const treasuryWithdrawalUtxo = await createUtxoAtTreasury(
1902
- withdrawalIndyAmt,
1903
- sysParams,
1904
- context,
1905
- );
1906
-
1907
- const govUtxo = await findGov(
1908
- context.lucid,
1909
- sysParams.validatorHashes.govHash,
1910
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1911
- );
1912
-
1913
- const [tx, pollId] = await createProposal(
1914
- {
1915
- UpgradeProtocol: {
1916
- content: serialiseUpgradePaths({
1917
- upgradeId: govUtxo.datum.currentVersion + 1n,
1918
- upgradePaths: new Map([
1919
- [
1920
- fromHex(sysParams.validatorHashes.cdpHash),
1921
- // NOTICE: this is just a placeholder, in real scenario it needs upgrade minting policy hash
1922
- {
1923
- upgradeSymbol: fromHex(
1924
- sysParams.validatorHashes.cdpCreatorHash,
1925
- ),
1926
- },
1927
- ],
1928
- ]),
1929
- }),
1930
- },
1931
- },
1932
- {
1933
- destination: addressFromBech32(context.users.withdrawalAccount.address),
1934
- value: [
1935
- [
1936
- sysParams.govParams.indyAsset[0].unCurrencySymbol,
1937
- fromText(sysParams.govParams.indyAsset[1].unTokenName),
1938
- withdrawalIndyAmt,
1939
- ],
1940
- ],
1941
- },
1942
- sysParams,
1943
- context.lucid,
1944
- context.emulator.slot,
1945
- govUtxo.utxo,
1946
- [],
1947
- );
1948
-
1949
- await runAndAwaitTxBuilder(context.lucid, tx);
1950
-
1951
- await runCreateAllShards(pollId, sysParams, context);
1952
-
1953
- await runAndAwaitTx(
1954
- context.lucid,
1955
- openStakingPosition(
1956
- 100_000_000_000n,
1957
- sysParams,
1958
- context.lucid,
1959
- (await findStakingManager(sysParams, context.lucid)).utxo,
1960
- ),
1961
- );
1962
-
1963
- await runVote(pollId, 'Yes', sysParams, context);
1964
-
1965
- await waitForVotingEnd(pollId, sysParams, context);
1966
-
1967
- await runMergeAllShards(pollId, sysParams, context);
1968
-
1969
- await runEndProposal(pollId, sysParams, context);
1970
-
1971
- const executeUtxo = await findExecute(
1972
- context.lucid,
1973
- sysParams.validatorHashes.executeHash,
1974
- fromSystemParamsAsset(sysParams.executeParams.upgradeToken),
1975
- pollId,
1976
- );
1977
-
1978
- const [__, newVal] = await getValueChangeAtAddressAfterAction(
1979
- context.lucid,
1980
- context.users.withdrawalAccount.address,
1981
- async () =>
1982
- runAndAwaitTx(
1983
- context.lucid,
1984
- executeProposal(
1985
- executeUtxo.utxo,
1986
- (
1987
- await findGov(
1988
- context.lucid,
1989
- sysParams.validatorHashes.govHash,
1990
- fromSystemParamsAsset(sysParams.govParams.govNFT),
1991
- )
1992
- ).utxo,
1993
- treasuryWithdrawalUtxo,
1994
- null,
1995
- null,
1996
- sysParams,
1997
- context.lucid,
1998
- context.emulator.slot,
1999
- ),
2000
- ),
2001
- );
2002
-
2003
- expect(
2004
- assetClassValueOf(
2005
- newVal,
2006
- fromSystemParamsAsset(sysParams.govParams.indyAsset),
2007
- ) === withdrawalIndyAmt,
2008
- 'Unexpected withdrawn indy amt',
2009
- ).toBeTruthy();
2010
- });
2011
- });