@indigo-labs/indigo-sdk 0.5.5 → 0.5.6

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 (204) hide show
  1. package/package.json +11 -1
  2. package/.claude/settings.local.json +0 -7
  3. package/.github/workflows/ci.yml +0 -66
  4. package/.husky/pre-commit +0 -1
  5. package/.nvmrc +0 -1
  6. package/.prettierignore +0 -1
  7. package/.prettierrc +0 -6
  8. package/eslint.config.mjs +0 -42
  9. package/scripts/bench.sh +0 -62
  10. package/scripts/run-repeat.sh +0 -22
  11. package/src/contracts/cdp/helpers.ts +0 -173
  12. package/src/contracts/cdp/scripts.ts +0 -70
  13. package/src/contracts/cdp/transactions.ts +0 -1584
  14. package/src/contracts/cdp/types-new.ts +0 -277
  15. package/src/contracts/cdp/types.ts +0 -43
  16. package/src/contracts/cdp-creator/queries.ts +0 -30
  17. package/src/contracts/cdp-creator/scripts.ts +0 -45
  18. package/src/contracts/cdp-creator/types-new.ts +0 -50
  19. package/src/contracts/cdp-creator/types.ts +0 -24
  20. package/src/contracts/collector/scripts.ts +0 -32
  21. package/src/contracts/collector/transactions.ts +0 -50
  22. package/src/contracts/collector/types-new.ts +0 -17
  23. package/src/contracts/execute/scripts.ts +0 -57
  24. package/src/contracts/execute/types-new.ts +0 -44
  25. package/src/contracts/execute/types.ts +0 -24
  26. package/src/contracts/gov/helpers.ts +0 -351
  27. package/src/contracts/gov/scripts.ts +0 -41
  28. package/src/contracts/gov/transactions.ts +0 -1607
  29. package/src/contracts/gov/types-new.ts +0 -268
  30. package/src/contracts/gov/types.ts +0 -22
  31. package/src/contracts/iasset/helpers.ts +0 -170
  32. package/src/contracts/iasset/queries.ts +0 -102
  33. package/src/contracts/iasset/scripts.ts +0 -38
  34. package/src/contracts/iasset/types.ts +0 -154
  35. package/src/contracts/initialize/actions.ts +0 -789
  36. package/src/contracts/initialize/helpers.ts +0 -616
  37. package/src/contracts/initialize/types.ts +0 -116
  38. package/src/contracts/interest-collection/helpers.ts +0 -19
  39. package/src/contracts/interest-collection/queries.ts +0 -66
  40. package/src/contracts/interest-collection/scripts.ts +0 -44
  41. package/src/contracts/interest-collection/transactions.ts +0 -433
  42. package/src/contracts/interest-collection/types-new.ts +0 -50
  43. package/src/contracts/interest-collection/types.ts +0 -26
  44. package/src/contracts/interest-oracle/helpers.ts +0 -61
  45. package/src/contracts/interest-oracle/scripts.ts +0 -18
  46. package/src/contracts/interest-oracle/transactions.ts +0 -151
  47. package/src/contracts/interest-oracle/types-new.ts +0 -32
  48. package/src/contracts/interest-oracle/types.ts +0 -16
  49. package/src/contracts/one-shot/scripts.ts +0 -12
  50. package/src/contracts/one-shot/transactions.ts +0 -66
  51. package/src/contracts/one-shot/types.ts +0 -22
  52. package/src/contracts/poll/helpers.ts +0 -37
  53. package/src/contracts/poll/scripts.ts +0 -71
  54. package/src/contracts/poll/types-poll-manager.ts +0 -20
  55. package/src/contracts/poll/types-poll-new.ts +0 -196
  56. package/src/contracts/poll/types-poll-shard.ts +0 -16
  57. package/src/contracts/price-oracle/helpers.ts +0 -30
  58. package/src/contracts/price-oracle/scripts.ts +0 -18
  59. package/src/contracts/price-oracle/transactions.ts +0 -115
  60. package/src/contracts/price-oracle/types-new.ts +0 -50
  61. package/src/contracts/price-oracle/types.ts +0 -16
  62. package/src/contracts/pyth-feed/helpers.ts +0 -82
  63. package/src/contracts/pyth-feed/scripts.ts +0 -15
  64. package/src/contracts/pyth-feed/types.ts +0 -181
  65. package/src/contracts/rob/helpers.ts +0 -666
  66. package/src/contracts/rob/scripts.ts +0 -35
  67. package/src/contracts/rob/transactions.ts +0 -423
  68. package/src/contracts/rob/types-new.ts +0 -128
  69. package/src/contracts/rob/types.ts +0 -16
  70. package/src/contracts/rob-leverage/helpers.ts +0 -422
  71. package/src/contracts/rob-leverage/transactions.ts +0 -368
  72. package/src/contracts/stability-pool/helpers.ts +0 -798
  73. package/src/contracts/stability-pool/queries.ts +0 -132
  74. package/src/contracts/stability-pool/scripts.ts +0 -51
  75. package/src/contracts/stability-pool/transactions.ts +0 -921
  76. package/src/contracts/stability-pool/types-new.ts +0 -385
  77. package/src/contracts/stability-pool/types.ts +0 -25
  78. package/src/contracts/stableswap/helpers.ts +0 -507
  79. package/src/contracts/stableswap/scripts.ts +0 -37
  80. package/src/contracts/stableswap/transactions.ts +0 -475
  81. package/src/contracts/stableswap/types-new.ts +0 -131
  82. package/src/contracts/stableswap/types.ts +0 -17
  83. package/src/contracts/staking/helpers.ts +0 -136
  84. package/src/contracts/staking/scripts.ts +0 -41
  85. package/src/contracts/staking/transactions.ts +0 -349
  86. package/src/contracts/staking/types-new.ts +0 -137
  87. package/src/contracts/staking/types.ts +0 -17
  88. package/src/contracts/treasury/helpers.ts +0 -21
  89. package/src/contracts/treasury/queries.ts +0 -100
  90. package/src/contracts/treasury/scripts.ts +0 -27
  91. package/src/contracts/treasury/transactions.ts +0 -334
  92. package/src/contracts/treasury/types-new.ts +0 -69
  93. package/src/contracts/treasury/types.ts +0 -14
  94. package/src/contracts/version-registry/scripts.ts +0 -29
  95. package/src/contracts/version-registry/types-new.ts +0 -18
  96. package/src/contracts/version-registry/types.ts +0 -17
  97. package/src/index.ts +0 -99
  98. package/src/scripts/always-fail-validator.ts +0 -7
  99. package/src/scripts/auth-token-policy.ts +0 -24
  100. package/src/scripts/iasset-policy.ts +0 -23
  101. package/src/types/evolution-schema-options.ts +0 -16
  102. package/src/types/generic.ts +0 -52
  103. package/src/types/multisig.ts +0 -48
  104. package/src/types/on-chain-decimal.ts +0 -57
  105. package/src/types/rational.ts +0 -76
  106. package/src/types/system-params.ts +0 -463
  107. package/src/utils/array-utils.ts +0 -108
  108. package/src/utils/bigint-utils.ts +0 -35
  109. package/src/utils/helper-txs.ts +0 -31
  110. package/src/utils/indigo-helpers.ts +0 -17
  111. package/src/utils/lucid-utils.ts +0 -125
  112. package/src/utils/oracle-helpers.ts +0 -62
  113. package/src/utils/pyth/decode.ts +0 -223
  114. package/src/utils/pyth/encode.ts +0 -262
  115. package/src/utils/pyth/index.ts +0 -14
  116. package/src/utils/pyth/types.ts +0 -87
  117. package/src/utils/time-helpers.ts +0 -4
  118. package/src/utils/utils.ts +0 -25
  119. package/src/validators/always-succeed-validator.ts +0 -6
  120. package/src/validators/cdp-creator-validator.ts +0 -7
  121. package/src/validators/cdp-redeem-validator.ts +0 -7
  122. package/src/validators/cdp-validator.ts +0 -7
  123. package/src/validators/collector-validator.ts +0 -7
  124. package/src/validators/execute-validator.ts +0 -7
  125. package/src/validators/governance-validator.ts +0 -7
  126. package/src/validators/iasset-validator.ts +0 -7
  127. package/src/validators/interest-collection-validator.ts +0 -7
  128. package/src/validators/interest-oracle-validator.ts +0 -7
  129. package/src/validators/one-shot-policy.ts +0 -7
  130. package/src/validators/poll-manager-validator.ts +0 -7
  131. package/src/validators/poll-shard-validator.ts +0 -7
  132. package/src/validators/price-oracle-validator.ts +0 -7
  133. package/src/validators/pyth-feed-validator.ts +0 -7
  134. package/src/validators/rob-validator.ts +0 -7
  135. package/src/validators/stability-pool-validator.ts +0 -7
  136. package/src/validators/stableswap-validator.ts +0 -7
  137. package/src/validators/staking-validator.ts +0 -7
  138. package/src/validators/treasury-validator.ts +0 -7
  139. package/src/validators/version-record-policy.ts +0 -7
  140. package/src/validators/version-registry-validator.ts +0 -7
  141. package/tests/always-succeed/script.ts +0 -7
  142. package/tests/array-utils.test.ts +0 -92
  143. package/tests/bigint-utils.test.ts +0 -41
  144. package/tests/cdp/actions.ts +0 -680
  145. package/tests/cdp/cdp-helpers.ts +0 -55
  146. package/tests/cdp/cdp-queries.ts +0 -423
  147. package/tests/cdp/cdp.test.ts +0 -6730
  148. package/tests/cdp/transactions-mutated.ts +0 -1733
  149. package/tests/data/system-params.json +0 -1155
  150. package/tests/datums.test.ts +0 -302
  151. package/tests/endpoints/initialize.ts +0 -78
  152. package/tests/endpoints/interest-collector.ts +0 -37
  153. package/tests/endpoints/treasury.ts +0 -70
  154. package/tests/gov/actions.ts +0 -381
  155. package/tests/gov/gov.test.ts +0 -5147
  156. package/tests/gov/governance-queries.ts +0 -37
  157. package/tests/hash-checks.test.ts +0 -112
  158. package/tests/indigo-test-helpers.ts +0 -99
  159. package/tests/initialize.test.ts +0 -79
  160. package/tests/interest-calculations.test.ts +0 -120
  161. package/tests/interest-collection/interest-collection.test.ts +0 -843
  162. package/tests/interest-collection/transactions-mutated.ts +0 -260
  163. package/tests/interest-oracle.test.ts +0 -93
  164. package/tests/mock/assets-mock.ts +0 -243
  165. package/tests/mock/protocol-params-mock.ts +0 -21
  166. package/tests/price-oracle/actions.ts +0 -161
  167. package/tests/price-oracle/price-oracle-queries.ts +0 -12
  168. package/tests/price-oracle/price-oracle.test.ts +0 -228
  169. package/tests/price-oracle/transactions-mutated.ts +0 -59
  170. package/tests/pyth/endpoints.ts +0 -96
  171. package/tests/pyth/helpers.ts +0 -37
  172. package/tests/pyth/pyth-encoding.test.ts +0 -376
  173. package/tests/pyth/pyth-feeds.test.ts +0 -943
  174. package/tests/pyth/pyth-indigo.test.ts +0 -505
  175. package/tests/pyth/pyth.test.ts +0 -299
  176. package/tests/queries/collector-queries.ts +0 -27
  177. package/tests/queries/execute-queries.ts +0 -47
  178. package/tests/queries/iasset-queries.ts +0 -149
  179. package/tests/queries/interest-oracle-queries.ts +0 -12
  180. package/tests/queries/poll-queries.ts +0 -97
  181. package/tests/queries/staking-queries.ts +0 -54
  182. package/tests/rob/actions.ts +0 -56
  183. package/tests/rob/rob-leverage.test.ts +0 -2555
  184. package/tests/rob/rob-queries.ts +0 -95
  185. package/tests/rob/rob.test.ts +0 -3677
  186. package/tests/rob/transactions-mutated.ts +0 -844
  187. package/tests/script-size.test.ts +0 -240
  188. package/tests/setup.ts +0 -135
  189. package/tests/stability-pool/actions.ts +0 -229
  190. package/tests/stability-pool.test.ts +0 -6491
  191. package/tests/stableswap/stableswap-actions.ts +0 -83
  192. package/tests/stableswap/stableswap-queries.ts +0 -98
  193. package/tests/stableswap/stableswap.test.ts +0 -4471
  194. package/tests/stableswap/transactions-mutated.ts +0 -348
  195. package/tests/staking.test.ts +0 -172
  196. package/tests/test-helpers.ts +0 -94
  197. package/tests/treasury/actions.ts +0 -67
  198. package/tests/treasury/treasury.test.ts +0 -320
  199. package/tests/utils/asserts.ts +0 -87
  200. package/tests/utils/benchmark-utils.ts +0 -130
  201. package/tests/utils/index.ts +0 -168
  202. package/tsconfig.build.json +0 -4
  203. package/tsconfig.json +0 -27
  204. package/vitest.config.ts +0 -11
@@ -1,843 +0,0 @@
1
- import { beforeEach, describe, expect, test } from 'vitest';
2
- import { IndigoTestContext, repeat, runAndAwaitTx } from '../test-helpers';
3
- import { expectScriptFailure } from '../utils/asserts';
4
- import {
5
- createIndigoTestContext,
6
- EXAMPLE_TOKEN_1,
7
- EXAMPLE_TOKEN_2,
8
- EXAMPLE_TOKEN_3,
9
- } from '../indigo-test-helpers';
10
- import {
11
- findAdminInterestCollectors as findAdminInterestCollector,
12
- findAdminInterestCollectors,
13
- findAllInterestCollectors,
14
- findRandomNonAdminInterestCollector,
15
- } from '../../src/contracts/interest-collection/queries';
16
- import { benchmarkAndAwaitTx } from '../utils/benchmark-utils';
17
- import {
18
- batchCollectInterest,
19
- distributeInterest,
20
- updatePermissions,
21
- } from '../../src/contracts/interest-collection/transactions';
22
- import {
23
- adaAssetClass,
24
- assetClassValueOf,
25
- matchSingle,
26
- mkAssetsOf,
27
- mkLovelacesOf,
28
- } from '@3rd-eye-labs/cardano-offchain-common';
29
- import {
30
- addAssets,
31
- fromHex,
32
- paymentCredentialOf,
33
- stakeCredentialOf,
34
- } from '@lucid-evolution/lucid';
35
- import {
36
- testCollectInterest,
37
- testDistributeInterest,
38
- } from './transactions-mutated';
39
- import { signersAllOf, fromSystemParamsAsset } from '../../src';
40
- import {
41
- findAllActiveCdps,
42
- findAllNecessaryOrefs,
43
- findPriceOracleFromCollateralAsset,
44
- } from '../cdp/cdp-queries';
45
- import { feedPriceOracleTx } from '../../src/contracts/price-oracle/transactions';
46
- import { createUtxosAtInterestCollector } from '../endpoints/interest-collector';
47
- import { runOpenCdp } from '../cdp/actions';
48
- import { runFeedPriceToOracle } from '../price-oracle/actions';
49
- import { runTestDepositCdpWithInterestVar } from '../cdp/transactions-mutated';
50
- import { findGov } from '../gov/governance-queries';
51
- import { toDataMultisig } from '../../src/types/multisig';
52
- import { createMultipleUtxosAtTreasury } from '../endpoints/treasury';
53
- import { rationalFromInt } from '../../src/types/rational';
54
-
55
- describe('Interest Collection', () => {
56
- beforeEach<IndigoTestContext>(async (context: IndigoTestContext) => {
57
- await createIndigoTestContext(context);
58
- });
59
-
60
- test<IndigoTestContext>('Collect Interest - Cannot collect without interacting with a CDP', async (context: IndigoTestContext) => {
61
- const interestCollectionUtxo = await findRandomNonAdminInterestCollector(
62
- context.lucid,
63
- context.systemParams,
64
- );
65
-
66
- await expectScriptFailure(
67
- 'Single CDP input in the transaction.',
68
- testCollectInterest(
69
- mkLovelacesOf(1000000n),
70
- context.lucid,
71
- context.systemParams,
72
- context.lucid.newTx(),
73
- interestCollectionUtxo,
74
- { kind: 'CollectWithoutCDP' },
75
- ),
76
- );
77
- });
78
-
79
- test<IndigoTestContext>('Collect Interest - Cannot collect from interest admin', async (context: IndigoTestContext) => {
80
- const adminInterestCollectorUtxo = await findAdminInterestCollectors(
81
- context.lucid,
82
- context.systemParams,
83
- );
84
-
85
- const [iAssetConfig] = context.assetConfigs;
86
-
87
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
88
-
89
- await runAndAwaitTx(
90
- context.lucid,
91
- runOpenCdp(
92
- context,
93
- context.systemParams,
94
- 'iUSD',
95
- adaAssetClass,
96
- 10_000_000n,
97
- 500_000n,
98
- ),
99
- );
100
-
101
- context.emulator.awaitSlot(6500);
102
-
103
- await runFeedPriceToOracle(
104
- context,
105
- context.systemParams,
106
- iAssetConfig,
107
- adaAssetClass,
108
- rationalFromInt(1n),
109
- );
110
-
111
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
112
-
113
- await expectScriptFailure(
114
- 'Spent UTxO cannot have admin NFT',
115
- runTestDepositCdpWithInterestVar(
116
- context,
117
- context.systemParams,
118
- 'iUSD',
119
- adaAssetClass,
120
- adminInterestCollectorUtxo,
121
- {
122
- kind: 'CollectFromInterestAdmin',
123
- },
124
- ),
125
- );
126
- });
127
-
128
- test<IndigoTestContext>('Collect Interest - Cannot collect from multiple interest collectors', async (context: IndigoTestContext) => {
129
- const [iAssetConfig] = context.assetConfigs;
130
-
131
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
132
-
133
- await runAndAwaitTx(
134
- context.lucid,
135
- runOpenCdp(
136
- context,
137
- context.systemParams,
138
- 'iUSD',
139
- adaAssetClass,
140
- 10_000_000n,
141
- 500_000n,
142
- ),
143
- );
144
-
145
- context.emulator.awaitSlot(6500);
146
-
147
- await runFeedPriceToOracle(
148
- context,
149
- context.systemParams,
150
- iAssetConfig,
151
- adaAssetClass,
152
- rationalFromInt(1n),
153
- );
154
-
155
- const interestCollectors = await findAllInterestCollectors(
156
- context.lucid,
157
- context.systemParams,
158
- );
159
-
160
- const interestCollectorsUtxos = interestCollectors.filter(
161
- (utxo) =>
162
- assetClassValueOf(
163
- utxo.assets,
164
- fromSystemParamsAsset(
165
- context.systemParams.interestCollectionParams.multisigUtxoNft,
166
- ),
167
- ) === 0n,
168
- );
169
- if (interestCollectorsUtxos.length < 2) {
170
- throw new Error('Expected at least 2 interest collectors');
171
- }
172
-
173
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
174
-
175
- // This can fail in the CDP script or the interest collection script as the
176
- // check of single interest collector is redundant.
177
- await expectScriptFailure(
178
- 'crashed',
179
- runTestDepositCdpWithInterestVar(
180
- context,
181
- context.systemParams,
182
- 'iUSD',
183
- adaAssetClass,
184
- interestCollectorsUtxos[0],
185
- {
186
- kind: 'CollectFromMultipleInterestCollectors',
187
- utxo: interestCollectorsUtxos[1],
188
- },
189
- ),
190
- );
191
- });
192
-
193
- test<IndigoTestContext>('Collect Interest - ADA and 3 assets', async (context: IndigoTestContext) => {
194
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
195
-
196
- const [iAssetConfig] = context.assetConfigs;
197
-
198
- await runAndAwaitTx(
199
- context.lucid,
200
- runOpenCdp(
201
- context,
202
- context.systemParams,
203
- 'iUSD',
204
- adaAssetClass,
205
- 10_000_000n,
206
- 500_000n,
207
- ),
208
- );
209
-
210
- context.emulator.awaitSlot(6500);
211
-
212
- await runFeedPriceToOracle(
213
- context,
214
- context.systemParams,
215
- iAssetConfig,
216
- adaAssetClass,
217
- rationalFromInt(1n),
218
- );
219
-
220
- const interestCollectionUtxo = await findRandomNonAdminInterestCollector(
221
- context.lucid,
222
- context.systemParams,
223
- );
224
-
225
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
226
-
227
- await expectScriptFailure(
228
- 'D',
229
- runTestDepositCdpWithInterestVar(
230
- context,
231
- context.systemParams,
232
- 'iUSD',
233
- adaAssetClass,
234
- interestCollectionUtxo,
235
- {
236
- kind: 'CollectCustomValue',
237
- value: addAssets(
238
- mkLovelacesOf(1000000n),
239
- mkAssetsOf(EXAMPLE_TOKEN_1, 1_000n),
240
- mkAssetsOf(EXAMPLE_TOKEN_2, 1_000n),
241
- mkAssetsOf(EXAMPLE_TOKEN_3, 1_000n),
242
- ),
243
- },
244
- ),
245
- );
246
- });
247
-
248
- // This test settles the biggest possible batch of CDPs
249
- test<IndigoTestContext>('Batch collect - 16 CDPs', async (context: IndigoTestContext) => {
250
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
251
-
252
- await createMultipleUtxosAtTreasury(
253
- mkLovelacesOf(2n),
254
- 12n,
255
- context.systemParams,
256
- context,
257
- );
258
-
259
- const [iAssetConfig] = context.assetConfigs;
260
-
261
- const numberOfCdps = 16;
262
-
263
- await repeat(numberOfCdps, async () => {
264
- await runAndAwaitTx(
265
- context.lucid,
266
- runOpenCdp(
267
- context,
268
- context.systemParams,
269
- iAssetConfig.iassetTokenNameAscii,
270
- adaAssetClass,
271
- 12_000_000n,
272
- 6_000_000n,
273
- ),
274
- );
275
- });
276
-
277
- context.emulator.awaitSlot(
278
- Number(
279
- context.systemParams.interestCollectionParams
280
- .interestSettlementCooldown,
281
- ) / 1_000,
282
- );
283
-
284
- const orefs = await findAllNecessaryOrefs(
285
- context.lucid,
286
- context.systemParams,
287
- 'iUSD',
288
- adaAssetClass,
289
- );
290
-
291
- const priceOracleUtxo = await findPriceOracleFromCollateralAsset(
292
- context.lucid,
293
- orefs.collateralAsset,
294
- );
295
-
296
- const cdpsInfo = await findAllActiveCdps(
297
- context.lucid,
298
- context.systemParams,
299
- 'iUSD',
300
- stakeCredentialOf(context.users.user.address),
301
- );
302
-
303
- expect(
304
- cdpsInfo.length === numberOfCdps,
305
- `Expected ${numberOfCdps} cdps`,
306
- ).toBeTruthy();
307
-
308
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
309
-
310
- await runAndAwaitTx(
311
- context.lucid,
312
- feedPriceOracleTx(
313
- context.lucid,
314
- priceOracleUtxo!,
315
- rationalFromInt(1n),
316
- iAssetConfig.collateralAssets[0].oracleParams!,
317
- ),
318
- );
319
-
320
- await benchmarkAndAwaitTx(
321
- 'Interest Collection - Batch Collect 16 CDPs',
322
- await batchCollectInterest(
323
- orefs.collateralAsset.utxo,
324
- orefs.interestCollectorUtxo,
325
- orefs.interestOracleUtxo,
326
- cdpsInfo.map((cdp) => cdp.utxo),
327
- context.systemParams,
328
- context.lucid,
329
- ),
330
- context.lucid,
331
- context.emulator,
332
- );
333
- });
334
-
335
- test<IndigoTestContext>('Batch collect fails when no cooldown elapsed', async (context: IndigoTestContext) => {
336
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
337
-
338
- await createMultipleUtxosAtTreasury(
339
- mkLovelacesOf(2n),
340
- 10n,
341
- context.systemParams,
342
- context,
343
- );
344
-
345
- const [iAssetConfig] = context.assetConfigs;
346
-
347
- const numberOfCdps = 10;
348
-
349
- await repeat(numberOfCdps, async () => {
350
- await runAndAwaitTx(
351
- context.lucid,
352
- runOpenCdp(
353
- context,
354
- context.systemParams,
355
- iAssetConfig.iassetTokenNameAscii,
356
- adaAssetClass,
357
- 12_000_000n,
358
- 6_000_000n,
359
- ),
360
- );
361
- });
362
-
363
- // NOTE: Awaiting the cooldown period minus 39 seconds makes the transaction succeed,
364
- // this is probably due to the awaitTx time.
365
- context.emulator.awaitSlot(
366
- Number(
367
- context.systemParams.interestCollectionParams
368
- .interestSettlementCooldown,
369
- ) /
370
- 1_000 -
371
- 40,
372
- );
373
-
374
- const orefs = await findAllNecessaryOrefs(
375
- context.lucid,
376
- context.systemParams,
377
- 'iUSD',
378
- adaAssetClass,
379
- );
380
-
381
- const priceOracleUtxo = await findPriceOracleFromCollateralAsset(
382
- context.lucid,
383
- orefs.collateralAsset,
384
- );
385
-
386
- const cdpsInfo = await findAllActiveCdps(
387
- context.lucid,
388
- context.systemParams,
389
- 'iUSD',
390
- stakeCredentialOf(context.users.user.address),
391
- );
392
-
393
- expect(
394
- cdpsInfo.length === numberOfCdps,
395
- `Expected ${numberOfCdps} cdps`,
396
- ).toBeTruthy();
397
-
398
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
399
-
400
- await runAndAwaitTx(
401
- context.lucid,
402
- feedPriceOracleTx(
403
- context.lucid,
404
- priceOracleUtxo!,
405
- rationalFromInt(1n),
406
- iAssetConfig.collateralAssets[0].oracleParams!,
407
- ),
408
- );
409
-
410
- await expectScriptFailure(
411
- 'It is too soon to settle interest',
412
- batchCollectInterest(
413
- orefs.collateralAsset.utxo,
414
- orefs.interestCollectorUtxo,
415
- orefs.interestOracleUtxo,
416
- cdpsInfo.map((cdp) => cdp.utxo),
417
- context.systemParams,
418
- context.lucid,
419
- ),
420
- );
421
- });
422
-
423
- test<IndigoTestContext>('Distribute', async (context: IndigoTestContext) => {
424
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
425
-
426
- await createUtxosAtInterestCollector(
427
- 1,
428
- addAssets(mkLovelacesOf(1000000n), mkAssetsOf(EXAMPLE_TOKEN_1, 1_000n)),
429
- context.systemParams,
430
- context,
431
- );
432
-
433
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
434
-
435
- const interestDistributeUtxo = matchSingle(
436
- (
437
- await findAllInterestCollectors(context.lucid, context.systemParams)
438
- ).filter((utxo) => assetClassValueOf(utxo.assets, EXAMPLE_TOKEN_1)),
439
- (_) => new Error('Expected a single interest distribute UTXO'),
440
- );
441
-
442
- const interestAdminUtxo = await findAdminInterestCollector(
443
- context.lucid,
444
- context.systemParams,
445
- );
446
-
447
- await benchmarkAndAwaitTx(
448
- 'Interest Collection - Distribute',
449
- await distributeInterest(
450
- [interestDistributeUtxo],
451
- interestAdminUtxo,
452
- context.systemParams,
453
- context.lucid,
454
- ),
455
- context.lucid,
456
- context.emulator,
457
- );
458
- });
459
-
460
- test<IndigoTestContext>('Distribute from multiple collectors - 58', async (context: IndigoTestContext) => {
461
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
462
-
463
- const numberOfInterestCollectionUtxos = 58;
464
-
465
- await createUtxosAtInterestCollector(
466
- numberOfInterestCollectionUtxos,
467
- addAssets(mkLovelacesOf(1000000n), mkAssetsOf(EXAMPLE_TOKEN_1, 1_000n)),
468
- context.systemParams,
469
- context,
470
- );
471
-
472
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
473
-
474
- const interestDistributeUtxos = (
475
- await findAllInterestCollectors(context.lucid, context.systemParams)
476
- ).filter((utxo) => assetClassValueOf(utxo.assets, EXAMPLE_TOKEN_1));
477
-
478
- const interestAdminUtxo = await findAdminInterestCollector(
479
- context.lucid,
480
- context.systemParams,
481
- );
482
-
483
- await benchmarkAndAwaitTx(
484
- 'Interest collection - Distribute from multiple collectors, 58',
485
- await distributeInterest(
486
- interestDistributeUtxos,
487
- interestAdminUtxo,
488
- context.systemParams,
489
- context.lucid,
490
- ),
491
- context.lucid,
492
- context.emulator,
493
- );
494
- });
495
-
496
- test<IndigoTestContext>('Distribute - No admin signature', async (context: IndigoTestContext) => {
497
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
498
-
499
- await createUtxosAtInterestCollector(
500
- 1,
501
- addAssets(mkLovelacesOf(1000000n), mkAssetsOf(EXAMPLE_TOKEN_1, 1_000n)),
502
- context.systemParams,
503
- context,
504
- );
505
-
506
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
507
-
508
- const interestDistributeUtxo = matchSingle(
509
- (
510
- await findAllInterestCollectors(context.lucid, context.systemParams)
511
- ).filter((utxo) => assetClassValueOf(utxo.assets, EXAMPLE_TOKEN_1)),
512
- (_) => new Error('Expected a single interest distribute UTXO'),
513
- );
514
-
515
- const interestAdminUtxo = await findAdminInterestCollector(
516
- context.lucid,
517
- context.systemParams,
518
- );
519
-
520
- await expectScriptFailure(
521
- 'Admin multisig must be satisfied',
522
- testDistributeInterest(
523
- interestDistributeUtxo,
524
- interestAdminUtxo,
525
- context.users.user.address,
526
- undefined,
527
- context.systemParams,
528
- context.lucid,
529
- { kind: 'DistributeInterestNoAdmin' },
530
- ),
531
- );
532
- });
533
-
534
- test<IndigoTestContext>('Update Permissions', async (context: IndigoTestContext) => {
535
- const interestAdminUtxo = await findAdminInterestCollector(
536
- context.lucid,
537
- context.systemParams,
538
- );
539
-
540
- const govUtxo = await findGov(
541
- context.lucid,
542
- context.systemParams.validatorHashes.govHash,
543
- fromSystemParamsAsset(
544
- context.systemParams.interestCollectionParams.govAuthTk,
545
- ),
546
- );
547
-
548
- const newAdminPermissions = {
549
- Signature: {
550
- keyHash: fromHex(paymentCredentialOf(context.users.user.address).hash),
551
- },
552
- };
553
-
554
- await benchmarkAndAwaitTx(
555
- 'Interest Collection - Update Permissions',
556
- await updatePermissions(
557
- interestAdminUtxo,
558
- govUtxo.utxo,
559
- newAdminPermissions,
560
- [
561
- ...signersAllOf(govUtxo.datum.protocolParams.foundationMultisig),
562
- ...signersAllOf(newAdminPermissions),
563
- ],
564
- context.systemParams,
565
- context.lucid,
566
- ),
567
- context.lucid,
568
- context.emulator,
569
- [context.users.user.seedPhrase],
570
- );
571
- });
572
-
573
- test<IndigoTestContext>('Update Permissions - all of multiple signers', async (context: IndigoTestContext) => {
574
- const interestAdminUtxo = await findAdminInterestCollector(
575
- context.lucid,
576
- context.systemParams,
577
- );
578
-
579
- const govUtxo = await findGov(
580
- context.lucid,
581
- context.systemParams.validatorHashes.govHash,
582
- fromSystemParamsAsset(
583
- context.systemParams.interestCollectionParams.govAuthTk,
584
- ),
585
- );
586
-
587
- const newAdminPermissions = {
588
- AtLeast: {
589
- required: 1n,
590
- authSignatories: [
591
- toDataMultisig({
592
- Signature: {
593
- keyHash: fromHex(
594
- paymentCredentialOf(context.users.user.address).hash,
595
- ),
596
- },
597
- }),
598
- toDataMultisig({
599
- Signature: {
600
- keyHash: fromHex(
601
- paymentCredentialOf(context.users.user2.address).hash,
602
- ),
603
- },
604
- }),
605
- ],
606
- },
607
- };
608
-
609
- await benchmarkAndAwaitTx(
610
- 'Interest Collection - Update Permissions - all of multiple signers',
611
- await updatePermissions(
612
- interestAdminUtxo,
613
- govUtxo.utxo,
614
- newAdminPermissions,
615
- [
616
- ...signersAllOf(govUtxo.datum.protocolParams.foundationMultisig),
617
- ...signersAllOf(newAdminPermissions),
618
- ],
619
- context.systemParams,
620
- context.lucid,
621
- ),
622
- context.lucid,
623
- context.emulator,
624
- [context.users.user.seedPhrase, context.users.user2.seedPhrase],
625
- );
626
- });
627
-
628
- test<IndigoTestContext>('Update Permissions - some of multiple signers', async (context: IndigoTestContext) => {
629
- const interestAdminUtxo = await findAdminInterestCollector(
630
- context.lucid,
631
- context.systemParams,
632
- );
633
-
634
- const govUtxo = await findGov(
635
- context.lucid,
636
- context.systemParams.validatorHashes.govHash,
637
- fromSystemParamsAsset(
638
- context.systemParams.interestCollectionParams.govAuthTk,
639
- ),
640
- );
641
-
642
- const newAdminPermissions = {
643
- AtLeast: {
644
- required: 2n,
645
- authSignatories: [
646
- toDataMultisig({
647
- Signature: {
648
- keyHash: fromHex(
649
- paymentCredentialOf(context.users.admin.address).hash,
650
- ),
651
- },
652
- }),
653
- toDataMultisig({
654
- Signature: {
655
- keyHash: fromHex(
656
- paymentCredentialOf(context.users.user.address).hash,
657
- ),
658
- },
659
- }),
660
- toDataMultisig({
661
- Signature: {
662
- keyHash: fromHex(
663
- paymentCredentialOf(context.users.user2.address).hash,
664
- ),
665
- },
666
- }),
667
- ],
668
- },
669
- };
670
-
671
- await runAndAwaitTx(
672
- context.lucid,
673
- updatePermissions(
674
- interestAdminUtxo,
675
- govUtxo.utxo,
676
- newAdminPermissions,
677
- [
678
- ...signersAllOf(govUtxo.datum.protocolParams.foundationMultisig),
679
- ...[paymentCredentialOf(context.users.user.address).hash],
680
- ],
681
- context.systemParams,
682
- context.lucid,
683
- ),
684
- [context.users.user.seedPhrase],
685
- );
686
- });
687
-
688
- test<IndigoTestContext>('Update Permissions - nested multisig', async (context: IndigoTestContext) => {
689
- const interestAdminUtxo = await findAdminInterestCollector(
690
- context.lucid,
691
- context.systemParams,
692
- );
693
-
694
- const govUtxo = await findGov(
695
- context.lucid,
696
- context.systemParams.validatorHashes.govHash,
697
- fromSystemParamsAsset(
698
- context.systemParams.interestCollectionParams.govAuthTk,
699
- ),
700
- );
701
-
702
- const newAdminPermissions = {
703
- AtLeast: {
704
- required: 2n,
705
- authSignatories: [
706
- toDataMultisig({
707
- Signature: {
708
- keyHash: fromHex(
709
- paymentCredentialOf(context.users.admin.address).hash,
710
- ),
711
- },
712
- }),
713
- toDataMultisig({
714
- AtLeast: {
715
- required: 1n,
716
- authSignatories: [
717
- toDataMultisig({
718
- Signature: {
719
- keyHash: fromHex(
720
- paymentCredentialOf(context.users.user.address).hash,
721
- ),
722
- },
723
- }),
724
- toDataMultisig({
725
- Signature: {
726
- keyHash: fromHex(
727
- paymentCredentialOf(context.users.user2.address).hash,
728
- ),
729
- },
730
- }),
731
- ],
732
- },
733
- }),
734
- ],
735
- },
736
- };
737
-
738
- await runAndAwaitTx(
739
- context.lucid,
740
- updatePermissions(
741
- interestAdminUtxo,
742
- govUtxo.utxo,
743
- newAdminPermissions,
744
- [
745
- ...signersAllOf(govUtxo.datum.protocolParams.foundationMultisig),
746
- ...[paymentCredentialOf(context.users.user.address).hash],
747
- ],
748
- context.systemParams,
749
- context.lucid,
750
- ),
751
- [context.users.user.seedPhrase],
752
- );
753
- });
754
-
755
- test<IndigoTestContext>('Update Permissions - Fail when new admin is not signed', async (context: IndigoTestContext) => {
756
- const interestAdminUtxo = await findAdminInterestCollector(
757
- context.lucid,
758
- context.systemParams,
759
- );
760
-
761
- const govUtxo = await findGov(
762
- context.lucid,
763
- context.systemParams.validatorHashes.govHash,
764
- fromSystemParamsAsset(
765
- context.systemParams.interestCollectionParams.govAuthTk,
766
- ),
767
- );
768
-
769
- const newAdminPermissions = {
770
- Signature: {
771
- keyHash: fromHex(paymentCredentialOf(context.users.user.address).hash),
772
- },
773
- };
774
-
775
- await expectScriptFailure(
776
- 'New admin multisig must be satisfied',
777
- updatePermissions(
778
- interestAdminUtxo,
779
- govUtxo.utxo,
780
- newAdminPermissions,
781
- signersAllOf(govUtxo.datum.protocolParams.foundationMultisig),
782
- context.systemParams,
783
- context.lucid,
784
- ),
785
- );
786
- });
787
-
788
- test<IndigoTestContext>('Update Permissions - Fail when not enough signers of new admin', async (context: IndigoTestContext) => {
789
- const interestAdminUtxo = await findAdminInterestCollector(
790
- context.lucid,
791
- context.systemParams,
792
- );
793
-
794
- const govUtxo = await findGov(
795
- context.lucid,
796
- context.systemParams.validatorHashes.govHash,
797
- fromSystemParamsAsset(
798
- context.systemParams.interestCollectionParams.govAuthTk,
799
- ),
800
- );
801
-
802
- const newAdminPermissions = {
803
- AtLeast: {
804
- required: 2n,
805
- authSignatories: [
806
- toDataMultisig({
807
- Signature: {
808
- keyHash: fromHex(
809
- paymentCredentialOf(context.users.admin.address).hash,
810
- ),
811
- },
812
- }),
813
- toDataMultisig({
814
- Signature: {
815
- keyHash: fromHex(
816
- paymentCredentialOf(context.users.user.address).hash,
817
- ),
818
- },
819
- }),
820
- toDataMultisig({
821
- Signature: {
822
- keyHash: fromHex(
823
- paymentCredentialOf(context.users.user2.address).hash,
824
- ),
825
- },
826
- }),
827
- ],
828
- },
829
- };
830
-
831
- await expectScriptFailure(
832
- 'New admin multisig must be satisfied',
833
- updatePermissions(
834
- interestAdminUtxo,
835
- govUtxo.utxo,
836
- newAdminPermissions,
837
- signersAllOf(govUtxo.datum.protocolParams.foundationMultisig),
838
- context.systemParams,
839
- context.lucid,
840
- ),
841
- );
842
- });
843
- });