@indigo-labs/indigo-sdk 0.2.41 → 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 -495
  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/lrp.test.ts DELETED
@@ -1,673 +0,0 @@
1
- import { assert, beforeEach, describe, expect, test } from 'vitest';
2
- import {
3
- addAssets,
4
- Credential,
5
- Emulator,
6
- EmulatorAccount,
7
- fromText,
8
- generateEmulatorAccount,
9
- Lucid,
10
- paymentCredentialOf,
11
- toText,
12
- UTxO,
13
- } from '@lucid-evolution/lucid';
14
- import { parseLrpDatumOrThrow } from '../src/contracts/lrp/types';
15
- import {
16
- adjustLrp,
17
- cancelLrp,
18
- claimLrp,
19
- openLrp,
20
- redeemLrp,
21
- } from '../src/contracts/lrp/transactions';
22
- import { findLrp } from './queries/lrp-queries';
23
- import { addrDetails, getInlineDatumOrThrow } from '../src/utils/lucid-utils';
24
- import { LucidContext, runAndAwaitTx } from './test-helpers';
25
- import { matchSingle } from '../src/utils/utils';
26
- import { AssetClass, openCdp, SystemParams } from '../src';
27
- import {
28
- assetClassValueOf,
29
- lovelacesAmt,
30
- mkLovelacesOf,
31
- } from '../src/utils/value-helpers';
32
- import { strictEqual } from 'assert';
33
- import { init } from '../src/contracts/initialize/transactions';
34
- import { iusdInitialAssetCfg } from './mock/assets-mock';
35
- import { findAllNecessaryOrefs } from './queries/cdp-queries';
36
-
37
- type MyContext = LucidContext<{
38
- admin: EmulatorAccount;
39
- user: EmulatorAccount;
40
- }>;
41
-
42
- async function findSingleLrp(
43
- context: MyContext,
44
- sysParams: SystemParams,
45
- iasset: string,
46
- pkh: Credential,
47
- ): Promise<UTxO> {
48
- return matchSingle(
49
- await findLrp(
50
- context.lucid,
51
- sysParams.validatorHashes.lrpHash,
52
- pkh.hash,
53
- iasset,
54
- ),
55
- (res) => new Error('Expected a single LRP UTXO.: ' + JSON.stringify(res)),
56
- );
57
- }
58
-
59
- describe('LRP', () => {
60
- beforeEach<MyContext>(async (context: MyContext) => {
61
- context.users = {
62
- admin: generateEmulatorAccount({
63
- lovelace: BigInt(100_000_000_000_000),
64
- }),
65
- user: generateEmulatorAccount(addAssets(mkLovelacesOf(150_000_000n))),
66
- };
67
-
68
- context.emulator = new Emulator([context.users.admin, context.users.user]);
69
- context.lucid = await Lucid(context.emulator, 'Custom');
70
- });
71
-
72
- test<MyContext>('adjust positive and negative', async (context: MyContext) => {
73
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
74
-
75
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg]);
76
-
77
- const iasset = fromText(iusdInitialAssetCfg.name);
78
-
79
- const [ownPkh, _] = await addrDetails(context.lucid);
80
-
81
- await runAndAwaitTx(
82
- context.lucid,
83
- openLrp(
84
- iasset,
85
- 20_000_000n,
86
- { getOnChainInt: 1_000_000n },
87
- context.lucid,
88
- sysParams,
89
- ),
90
- );
91
-
92
- await runAndAwaitTx(
93
- context.lucid,
94
- findSingleLrp(context, sysParams, iasset, ownPkh).then((lrp) =>
95
- adjustLrp(context.lucid, lrp, -1_000_000n, undefined, sysParams),
96
- ),
97
- );
98
-
99
- const adjustedUtxo1 = await findSingleLrp(
100
- context,
101
- sysParams,
102
- iasset,
103
- ownPkh,
104
- );
105
-
106
- assert(
107
- parseLrpDatumOrThrow(getInlineDatumOrThrow(adjustedUtxo1))
108
- .lovelacesToSpend ===
109
- 20_000_000n - 1_000_000n,
110
- );
111
-
112
- expect(
113
- lovelacesAmt(adjustedUtxo1.assets) >=
114
- parseLrpDatumOrThrow(getInlineDatumOrThrow(adjustedUtxo1))
115
- .lovelacesToSpend,
116
- 'Lovelaces to spend has to be smaller than actual lovelaces in UTXO',
117
- ).toBeTruthy();
118
-
119
- await runAndAwaitTx(
120
- context.lucid,
121
- adjustLrp(context.lucid, adjustedUtxo1, 5_000_000n, undefined, sysParams),
122
- );
123
-
124
- const adjustedUtxo2 = await findSingleLrp(
125
- context,
126
- sysParams,
127
- iasset,
128
- ownPkh,
129
- );
130
-
131
- const expectedResultAdaAmt = 20_000_000n - 1_000_000n + 5_000_000n;
132
-
133
- strictEqual(
134
- parseLrpDatumOrThrow(getInlineDatumOrThrow(adjustedUtxo2))
135
- .lovelacesToSpend,
136
- expectedResultAdaAmt,
137
- );
138
-
139
- expect(
140
- lovelacesAmt(adjustedUtxo2.assets) >=
141
- parseLrpDatumOrThrow(getInlineDatumOrThrow(adjustedUtxo2))
142
- .lovelacesToSpend,
143
- 'Lovelaces to spend has to be smaller than actual lovelaces in UTXO',
144
- ).toBeTruthy();
145
- });
146
-
147
- test<MyContext>('claim', async (context: MyContext) => {
148
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
149
-
150
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg]);
151
-
152
- const iasset = fromText(iusdInitialAssetCfg.name);
153
-
154
- const [ownPkh, _] = await addrDetails(context.lucid);
155
-
156
- {
157
- const orefs = await findAllNecessaryOrefs(
158
- context.lucid,
159
- sysParams,
160
- toText(iasset),
161
- );
162
-
163
- await runAndAwaitTx(
164
- context.lucid,
165
- openCdp(
166
- 100_000_000n,
167
- 30_000_000n,
168
- sysParams,
169
- orefs.cdpCreatorUtxo,
170
- orefs.iasset.utxo,
171
- orefs.priceOracleUtxo,
172
- orefs.interestOracleUtxo,
173
- orefs.collectorUtxo,
174
- context.lucid,
175
- context.emulator.slot,
176
- ),
177
- );
178
- }
179
-
180
- await runAndAwaitTx(
181
- context.lucid,
182
- openLrp(
183
- iasset,
184
- 20_000_000n,
185
- { getOnChainInt: 1_000_000n },
186
- context.lucid,
187
- sysParams,
188
- ),
189
- );
190
-
191
- const lrpUtxo = await findSingleLrp(context, sysParams, iasset, ownPkh);
192
-
193
- const redemptionAsset: AssetClass = {
194
- currencySymbol: sysParams.lrpParams.iassetPolicyId.unCurrencySymbol,
195
- tokenName: iasset,
196
- };
197
-
198
- expect(
199
- assetClassValueOf(lrpUtxo.assets, redemptionAsset),
200
- 'LRP should have no iassets before redemption',
201
- ).toBe(0n);
202
-
203
- const redemptionIAssetAmt = 11_000_000n;
204
-
205
- {
206
- const orefs = await findAllNecessaryOrefs(
207
- context.lucid,
208
- sysParams,
209
- toText(iasset),
210
- );
211
-
212
- await runAndAwaitTx(
213
- context.lucid,
214
- redeemLrp(
215
- [[lrpUtxo, redemptionIAssetAmt]],
216
- orefs.priceOracleUtxo,
217
- orefs.iasset.utxo,
218
- context.lucid,
219
- sysParams,
220
- ),
221
- );
222
- }
223
-
224
- const redeemedLrp = await findSingleLrp(context, sysParams, iasset, ownPkh);
225
-
226
- expect(
227
- assetClassValueOf(redeemedLrp.assets, redemptionAsset),
228
- 'LRP has wrong number of iassets after redemption',
229
- ).toBe(redemptionIAssetAmt);
230
-
231
- await runAndAwaitTx(
232
- context.lucid,
233
- claimLrp(context.lucid, redeemedLrp, sysParams),
234
- );
235
-
236
- const claimedLrp = await findSingleLrp(context, sysParams, iasset, ownPkh);
237
-
238
- expect(
239
- assetClassValueOf(claimedLrp.assets, redemptionAsset),
240
- 'LRP has to have 0 redemption assets after claim',
241
- ).toBe(0n);
242
- });
243
-
244
- test<MyContext>('claim using adjust', async (context: MyContext) => {
245
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
246
-
247
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg]);
248
-
249
- const iasset = fromText(iusdInitialAssetCfg.name);
250
-
251
- const [ownPkh, _] = await addrDetails(context.lucid);
252
-
253
- {
254
- const orefs = await findAllNecessaryOrefs(
255
- context.lucid,
256
- sysParams,
257
- toText(iasset),
258
- );
259
-
260
- await runAndAwaitTx(
261
- context.lucid,
262
- openCdp(
263
- 100_000_000n,
264
- 30_000_000n,
265
- sysParams,
266
- orefs.cdpCreatorUtxo,
267
- orefs.iasset.utxo,
268
- orefs.priceOracleUtxo,
269
- orefs.interestOracleUtxo,
270
- orefs.collectorUtxo,
271
- context.lucid,
272
- context.emulator.slot,
273
- ),
274
- );
275
- }
276
-
277
- await runAndAwaitTx(
278
- context.lucid,
279
- openLrp(
280
- iasset,
281
- 20_000_000n,
282
- { getOnChainInt: 1_000_000n },
283
- context.lucid,
284
- sysParams,
285
- ),
286
- );
287
-
288
- const lrpUtxo = await findSingleLrp(context, sysParams, iasset, ownPkh);
289
-
290
- const redemptionAsset: AssetClass = {
291
- currencySymbol: sysParams.lrpParams.iassetPolicyId.unCurrencySymbol,
292
- tokenName: iasset,
293
- };
294
-
295
- expect(
296
- assetClassValueOf(lrpUtxo.assets, redemptionAsset),
297
- 'LRP should have no iassets before redemption',
298
- ).toBe(0n);
299
-
300
- const redemptionIAssetAmt = 11_000_000n;
301
-
302
- {
303
- const orefs = await findAllNecessaryOrefs(
304
- context.lucid,
305
- sysParams,
306
- toText(iasset),
307
- );
308
-
309
- await runAndAwaitTx(
310
- context.lucid,
311
- redeemLrp(
312
- [[lrpUtxo, redemptionIAssetAmt]],
313
- orefs.priceOracleUtxo,
314
- orefs.iasset.utxo,
315
- context.lucid,
316
- sysParams,
317
- ),
318
- );
319
- }
320
-
321
- const redeemedLrp = await findSingleLrp(context, sysParams, iasset, ownPkh);
322
-
323
- expect(
324
- assetClassValueOf(redeemedLrp.assets, redemptionAsset),
325
- 'LRP has wrong number of iassets after redemption',
326
- ).toBe(redemptionIAssetAmt);
327
-
328
- await runAndAwaitTx(
329
- context.lucid,
330
- adjustLrp(context.lucid, redeemedLrp, -1_000_000n, undefined, sysParams),
331
- );
332
-
333
- const adjustedLrp = await findSingleLrp(context, sysParams, iasset, ownPkh);
334
-
335
- expect(
336
- assetClassValueOf(adjustedLrp.assets, redemptionAsset),
337
- 'LRP has to have 0 redemption assets after adjust',
338
- ).toBe(0n);
339
-
340
- strictEqual(
341
- parseLrpDatumOrThrow(getInlineDatumOrThrow(adjustedLrp)).lovelacesToSpend,
342
- // 20mil start, 11mil redeemed at price 1:1, -1mil adjusted
343
- 8_000_000n,
344
- );
345
- });
346
-
347
- test<MyContext>('single redemption and cancel', async (context: MyContext) => {
348
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
349
-
350
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg]);
351
-
352
- const iasset = fromText(iusdInitialAssetCfg.name);
353
-
354
- const [ownPkh, _] = await addrDetails(context.lucid);
355
-
356
- {
357
- const orefs = await findAllNecessaryOrefs(
358
- context.lucid,
359
- sysParams,
360
- toText(iasset),
361
- );
362
-
363
- await runAndAwaitTx(
364
- context.lucid,
365
- openCdp(
366
- 100_000_000n,
367
- 30_000_000n,
368
- sysParams,
369
- orefs.cdpCreatorUtxo,
370
- orefs.iasset.utxo,
371
- orefs.priceOracleUtxo,
372
- orefs.interestOracleUtxo,
373
- orefs.collectorUtxo,
374
- context.lucid,
375
- context.emulator.slot,
376
- ),
377
- );
378
- }
379
-
380
- await runAndAwaitTx(
381
- context.lucid,
382
- openLrp(
383
- iasset,
384
- 20_000_000n,
385
- { getOnChainInt: 1_000_000n },
386
- context.lucid,
387
- sysParams,
388
- ),
389
- );
390
-
391
- const lrpUtxo = await findSingleLrp(context, sysParams, iasset, ownPkh);
392
-
393
- const redemptionAsset: AssetClass = {
394
- currencySymbol: sysParams.lrpParams.iassetPolicyId.unCurrencySymbol,
395
- tokenName: iasset,
396
- };
397
-
398
- expect(
399
- assetClassValueOf(lrpUtxo.assets, redemptionAsset),
400
- 'LRP should have no iassets before redemption',
401
- ).toBe(0n);
402
-
403
- const redemptionIAssetAmt = 11_000_000n;
404
-
405
- {
406
- const orefs = await findAllNecessaryOrefs(
407
- context.lucid,
408
- sysParams,
409
- toText(iasset),
410
- );
411
-
412
- await runAndAwaitTx(
413
- context.lucid,
414
- redeemLrp(
415
- [[lrpUtxo, redemptionIAssetAmt]],
416
- orefs.priceOracleUtxo,
417
- orefs.iasset.utxo,
418
- context.lucid,
419
- sysParams,
420
- ),
421
- );
422
- }
423
-
424
- const redeemedLrp = await findSingleLrp(context, sysParams, iasset, ownPkh);
425
-
426
- expect(
427
- assetClassValueOf(redeemedLrp.assets, redemptionAsset),
428
- 'LRP has wrong number of iassets after redemption',
429
- ).toBe(redemptionIAssetAmt);
430
-
431
- await runAndAwaitTx(
432
- context.lucid,
433
- cancelLrp(redeemedLrp, sysParams, context.lucid),
434
- );
435
- });
436
-
437
- test<MyContext>('redeem, redeem again and cancel', async (context: MyContext) => {
438
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
439
-
440
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg]);
441
-
442
- const iasset = fromText(iusdInitialAssetCfg.name);
443
-
444
- const [ownPkh, _] = await addrDetails(context.lucid);
445
-
446
- {
447
- const orefs = await findAllNecessaryOrefs(
448
- context.lucid,
449
- sysParams,
450
- toText(iasset),
451
- );
452
-
453
- await runAndAwaitTx(
454
- context.lucid,
455
- openCdp(
456
- 100_000_000n,
457
- 30_000_000n,
458
- sysParams,
459
- orefs.cdpCreatorUtxo,
460
- orefs.iasset.utxo,
461
- orefs.priceOracleUtxo,
462
- orefs.interestOracleUtxo,
463
- orefs.collectorUtxo,
464
- context.lucid,
465
- context.emulator.slot,
466
- ),
467
- );
468
- }
469
-
470
- await runAndAwaitTx(
471
- context.lucid,
472
- openLrp(
473
- iasset,
474
- 40_000_000n,
475
- { getOnChainInt: 1_000_000n },
476
- context.lucid,
477
- sysParams,
478
- ),
479
- );
480
-
481
- const lrpUtxo = await findSingleLrp(context, sysParams, iasset, ownPkh);
482
-
483
- const redemptionAsset: AssetClass = {
484
- currencySymbol: sysParams.lrpParams.iassetPolicyId.unCurrencySymbol,
485
- tokenName: iasset,
486
- };
487
-
488
- expect(
489
- assetClassValueOf(lrpUtxo.assets, redemptionAsset),
490
- 'LRP should have no iassets before redemption',
491
- ).toBe(0n);
492
-
493
- const redemptionIAssetAmt = 11_000_000n;
494
-
495
- {
496
- const orefs = await findAllNecessaryOrefs(
497
- context.lucid,
498
- sysParams,
499
- toText(iasset),
500
- );
501
-
502
- await runAndAwaitTx(
503
- context.lucid,
504
- redeemLrp(
505
- [[lrpUtxo, redemptionIAssetAmt]],
506
- orefs.priceOracleUtxo,
507
- orefs.iasset.utxo,
508
- context.lucid,
509
- sysParams,
510
- ),
511
- );
512
- }
513
-
514
- const redeemedLrp = await findSingleLrp(context, sysParams, iasset, ownPkh);
515
-
516
- {
517
- const orefs = await findAllNecessaryOrefs(
518
- context.lucid,
519
- sysParams,
520
- toText(iasset),
521
- );
522
-
523
- await runAndAwaitTx(
524
- context.lucid,
525
- redeemLrp(
526
- [[redeemedLrp, redemptionIAssetAmt]],
527
- orefs.priceOracleUtxo,
528
- orefs.iasset.utxo,
529
- context.lucid,
530
- sysParams,
531
- ),
532
- );
533
- }
534
-
535
- const closableLrp = await findSingleLrp(context, sysParams, iasset, ownPkh);
536
-
537
- strictEqual(
538
- assetClassValueOf(closableLrp.assets, redemptionAsset),
539
- redemptionIAssetAmt * 2n,
540
- 'LRP has wrong number of iassets after 2 redemptions',
541
- );
542
-
543
- expect(
544
- assetClassValueOf(redeemedLrp.assets, redemptionAsset),
545
- 'LRP has wrong number of iassets after redemption',
546
- ).toBe(redemptionIAssetAmt);
547
-
548
- await runAndAwaitTx(
549
- context.lucid,
550
- cancelLrp(closableLrp, sysParams, context.lucid),
551
- );
552
- });
553
-
554
- test<MyContext>('multi redemption case', async (context: MyContext) => {
555
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
556
-
557
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg]);
558
-
559
- const iasset = fromText(iusdInitialAssetCfg.name);
560
-
561
- {
562
- const orefs = await findAllNecessaryOrefs(
563
- context.lucid,
564
- sysParams,
565
- toText(iasset),
566
- );
567
-
568
- await runAndAwaitTx(
569
- context.lucid,
570
- openCdp(
571
- 100_000_000n,
572
- 30_000_000n,
573
- sysParams,
574
- orefs.cdpCreatorUtxo,
575
- orefs.iasset.utxo,
576
- orefs.priceOracleUtxo,
577
- orefs.interestOracleUtxo,
578
- orefs.collectorUtxo,
579
- context.lucid,
580
- context.emulator.slot,
581
- ),
582
- );
583
- }
584
-
585
- await runAndAwaitTx(
586
- context.lucid,
587
- openLrp(
588
- iasset,
589
- 20_000_000n,
590
- { getOnChainInt: 1_000_000n },
591
- context.lucid,
592
- sysParams,
593
- ),
594
- );
595
-
596
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
597
-
598
- await runAndAwaitTx(
599
- context.lucid,
600
- openLrp(
601
- iasset,
602
- 20_000_000n,
603
- { getOnChainInt: 1_000_000n },
604
- context.lucid,
605
- sysParams,
606
- ),
607
- );
608
-
609
- const lrpUtxo1 = await findSingleLrp(
610
- context,
611
- sysParams,
612
- iasset,
613
- paymentCredentialOf(context.users.admin.address),
614
- );
615
- const lrpUtxo2 = await findSingleLrp(
616
- context,
617
- sysParams,
618
- iasset,
619
- paymentCredentialOf(context.users.user.address),
620
- );
621
-
622
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
623
-
624
- {
625
- const orefs = await findAllNecessaryOrefs(
626
- context.lucid,
627
- sysParams,
628
- toText(iasset),
629
- );
630
-
631
- await runAndAwaitTx(
632
- context.lucid,
633
- redeemLrp(
634
- [
635
- [lrpUtxo1, 10_000_000n],
636
- [lrpUtxo2, 11_000_000n],
637
- ],
638
- orefs.priceOracleUtxo,
639
- orefs.iasset.utxo,
640
- context.lucid,
641
- sysParams,
642
- ),
643
- );
644
- }
645
-
646
- const resultLrpUtxo1 = await findSingleLrp(
647
- context,
648
- sysParams,
649
- iasset,
650
- paymentCredentialOf(context.users.admin.address),
651
- );
652
- const resultLrpUtxo2 = await findSingleLrp(
653
- context,
654
- sysParams,
655
- iasset,
656
- paymentCredentialOf(context.users.user.address),
657
- );
658
-
659
- const redemptionAsset: AssetClass = {
660
- currencySymbol: sysParams.lrpParams.iassetPolicyId.unCurrencySymbol,
661
- tokenName: iasset,
662
- };
663
-
664
- expect(
665
- assetClassValueOf(resultLrpUtxo1.assets, redemptionAsset),
666
- 'LRP1 has wrong number of iassets after redemption',
667
- ).toBe(10_000_000n);
668
- expect(
669
- assetClassValueOf(resultLrpUtxo2.assets, redemptionAsset),
670
- 'LRP2 has wrong number of iassets after redemption',
671
- ).toBe(11_000_000n);
672
- });
673
- });