@indigo-labs/indigo-sdk 0.5.4 → 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 (208) hide show
  1. package/dist/index.d.mts +11 -1
  2. package/dist/index.d.ts +11 -1
  3. package/dist/index.js +17 -0
  4. package/dist/index.mjs +15 -0
  5. package/package.json +11 -1
  6. package/.claude/settings.local.json +0 -7
  7. package/.github/workflows/ci.yml +0 -66
  8. package/.husky/pre-commit +0 -1
  9. package/.nvmrc +0 -1
  10. package/.prettierignore +0 -1
  11. package/.prettierrc +0 -6
  12. package/eslint.config.mjs +0 -42
  13. package/scripts/bench.sh +0 -62
  14. package/scripts/run-repeat.sh +0 -22
  15. package/src/contracts/cdp/helpers.ts +0 -173
  16. package/src/contracts/cdp/scripts.ts +0 -70
  17. package/src/contracts/cdp/transactions.ts +0 -1584
  18. package/src/contracts/cdp/types-new.ts +0 -277
  19. package/src/contracts/cdp/types.ts +0 -43
  20. package/src/contracts/cdp-creator/queries.ts +0 -30
  21. package/src/contracts/cdp-creator/scripts.ts +0 -45
  22. package/src/contracts/cdp-creator/types-new.ts +0 -50
  23. package/src/contracts/cdp-creator/types.ts +0 -24
  24. package/src/contracts/collector/scripts.ts +0 -32
  25. package/src/contracts/collector/transactions.ts +0 -50
  26. package/src/contracts/collector/types-new.ts +0 -17
  27. package/src/contracts/execute/scripts.ts +0 -57
  28. package/src/contracts/execute/types-new.ts +0 -44
  29. package/src/contracts/execute/types.ts +0 -24
  30. package/src/contracts/gov/helpers.ts +0 -351
  31. package/src/contracts/gov/scripts.ts +0 -41
  32. package/src/contracts/gov/transactions.ts +0 -1607
  33. package/src/contracts/gov/types-new.ts +0 -268
  34. package/src/contracts/gov/types.ts +0 -22
  35. package/src/contracts/iasset/helpers.ts +0 -170
  36. package/src/contracts/iasset/queries.ts +0 -102
  37. package/src/contracts/iasset/scripts.ts +0 -38
  38. package/src/contracts/iasset/types.ts +0 -154
  39. package/src/contracts/initialize/actions.ts +0 -789
  40. package/src/contracts/initialize/helpers.ts +0 -616
  41. package/src/contracts/initialize/types.ts +0 -116
  42. package/src/contracts/interest-collection/helpers.ts +0 -19
  43. package/src/contracts/interest-collection/queries.ts +0 -66
  44. package/src/contracts/interest-collection/scripts.ts +0 -44
  45. package/src/contracts/interest-collection/transactions.ts +0 -433
  46. package/src/contracts/interest-collection/types-new.ts +0 -50
  47. package/src/contracts/interest-collection/types.ts +0 -26
  48. package/src/contracts/interest-oracle/helpers.ts +0 -61
  49. package/src/contracts/interest-oracle/scripts.ts +0 -18
  50. package/src/contracts/interest-oracle/transactions.ts +0 -151
  51. package/src/contracts/interest-oracle/types-new.ts +0 -32
  52. package/src/contracts/interest-oracle/types.ts +0 -16
  53. package/src/contracts/one-shot/scripts.ts +0 -12
  54. package/src/contracts/one-shot/transactions.ts +0 -66
  55. package/src/contracts/one-shot/types.ts +0 -22
  56. package/src/contracts/poll/helpers.ts +0 -37
  57. package/src/contracts/poll/scripts.ts +0 -71
  58. package/src/contracts/poll/types-poll-manager.ts +0 -20
  59. package/src/contracts/poll/types-poll-new.ts +0 -196
  60. package/src/contracts/poll/types-poll-shard.ts +0 -16
  61. package/src/contracts/price-oracle/helpers.ts +0 -30
  62. package/src/contracts/price-oracle/scripts.ts +0 -18
  63. package/src/contracts/price-oracle/transactions.ts +0 -115
  64. package/src/contracts/price-oracle/types-new.ts +0 -50
  65. package/src/contracts/price-oracle/types.ts +0 -16
  66. package/src/contracts/pyth-feed/helpers.ts +0 -82
  67. package/src/contracts/pyth-feed/scripts.ts +0 -15
  68. package/src/contracts/pyth-feed/types.ts +0 -181
  69. package/src/contracts/rob/helpers.ts +0 -666
  70. package/src/contracts/rob/scripts.ts +0 -35
  71. package/src/contracts/rob/transactions.ts +0 -423
  72. package/src/contracts/rob/types-new.ts +0 -128
  73. package/src/contracts/rob/types.ts +0 -16
  74. package/src/contracts/rob-leverage/helpers.ts +0 -422
  75. package/src/contracts/rob-leverage/transactions.ts +0 -368
  76. package/src/contracts/stability-pool/helpers.ts +0 -798
  77. package/src/contracts/stability-pool/queries.ts +0 -132
  78. package/src/contracts/stability-pool/scripts.ts +0 -51
  79. package/src/contracts/stability-pool/transactions.ts +0 -921
  80. package/src/contracts/stability-pool/types-new.ts +0 -385
  81. package/src/contracts/stability-pool/types.ts +0 -25
  82. package/src/contracts/stableswap/helpers.ts +0 -507
  83. package/src/contracts/stableswap/scripts.ts +0 -37
  84. package/src/contracts/stableswap/transactions.ts +0 -475
  85. package/src/contracts/stableswap/types-new.ts +0 -131
  86. package/src/contracts/stableswap/types.ts +0 -17
  87. package/src/contracts/staking/helpers.ts +0 -136
  88. package/src/contracts/staking/scripts.ts +0 -41
  89. package/src/contracts/staking/transactions.ts +0 -349
  90. package/src/contracts/staking/types-new.ts +0 -137
  91. package/src/contracts/staking/types.ts +0 -17
  92. package/src/contracts/treasury/helpers.ts +0 -21
  93. package/src/contracts/treasury/queries.ts +0 -100
  94. package/src/contracts/treasury/scripts.ts +0 -27
  95. package/src/contracts/treasury/transactions.ts +0 -334
  96. package/src/contracts/treasury/types-new.ts +0 -69
  97. package/src/contracts/treasury/types.ts +0 -14
  98. package/src/contracts/version-registry/scripts.ts +0 -29
  99. package/src/contracts/version-registry/types-new.ts +0 -18
  100. package/src/contracts/version-registry/types.ts +0 -17
  101. package/src/index.ts +0 -93
  102. package/src/scripts/always-fail-validator.ts +0 -7
  103. package/src/scripts/auth-token-policy.ts +0 -24
  104. package/src/scripts/iasset-policy.ts +0 -23
  105. package/src/types/evolution-schema-options.ts +0 -16
  106. package/src/types/generic.ts +0 -52
  107. package/src/types/multisig.ts +0 -48
  108. package/src/types/on-chain-decimal.ts +0 -57
  109. package/src/types/rational.ts +0 -61
  110. package/src/types/system-params.ts +0 -463
  111. package/src/utils/array-utils.ts +0 -108
  112. package/src/utils/bigint-utils.ts +0 -35
  113. package/src/utils/helper-txs.ts +0 -31
  114. package/src/utils/indigo-helpers.ts +0 -17
  115. package/src/utils/lucid-utils.ts +0 -125
  116. package/src/utils/oracle-helpers.ts +0 -62
  117. package/src/utils/pyth/decode.ts +0 -223
  118. package/src/utils/pyth/encode.ts +0 -262
  119. package/src/utils/pyth/index.ts +0 -14
  120. package/src/utils/pyth/types.ts +0 -87
  121. package/src/utils/time-helpers.ts +0 -4
  122. package/src/utils/utils.ts +0 -25
  123. package/src/validators/always-succeed-validator.ts +0 -6
  124. package/src/validators/cdp-creator-validator.ts +0 -7
  125. package/src/validators/cdp-redeem-validator.ts +0 -7
  126. package/src/validators/cdp-validator.ts +0 -7
  127. package/src/validators/collector-validator.ts +0 -7
  128. package/src/validators/execute-validator.ts +0 -7
  129. package/src/validators/governance-validator.ts +0 -7
  130. package/src/validators/iasset-validator.ts +0 -7
  131. package/src/validators/interest-collection-validator.ts +0 -7
  132. package/src/validators/interest-oracle-validator.ts +0 -7
  133. package/src/validators/one-shot-policy.ts +0 -7
  134. package/src/validators/poll-manager-validator.ts +0 -7
  135. package/src/validators/poll-shard-validator.ts +0 -7
  136. package/src/validators/price-oracle-validator.ts +0 -7
  137. package/src/validators/pyth-feed-validator.ts +0 -7
  138. package/src/validators/rob-validator.ts +0 -7
  139. package/src/validators/stability-pool-validator.ts +0 -7
  140. package/src/validators/stableswap-validator.ts +0 -7
  141. package/src/validators/staking-validator.ts +0 -7
  142. package/src/validators/treasury-validator.ts +0 -7
  143. package/src/validators/version-record-policy.ts +0 -7
  144. package/src/validators/version-registry-validator.ts +0 -7
  145. package/tests/always-succeed/script.ts +0 -7
  146. package/tests/array-utils.test.ts +0 -92
  147. package/tests/bigint-utils.test.ts +0 -41
  148. package/tests/cdp/actions.ts +0 -680
  149. package/tests/cdp/cdp-helpers.ts +0 -55
  150. package/tests/cdp/cdp-queries.ts +0 -423
  151. package/tests/cdp/cdp.test.ts +0 -6730
  152. package/tests/cdp/transactions-mutated.ts +0 -1733
  153. package/tests/data/system-params.json +0 -1155
  154. package/tests/datums.test.ts +0 -302
  155. package/tests/endpoints/initialize.ts +0 -78
  156. package/tests/endpoints/interest-collector.ts +0 -37
  157. package/tests/endpoints/treasury.ts +0 -70
  158. package/tests/gov/actions.ts +0 -381
  159. package/tests/gov/gov.test.ts +0 -5147
  160. package/tests/gov/governance-queries.ts +0 -37
  161. package/tests/hash-checks.test.ts +0 -112
  162. package/tests/indigo-test-helpers.ts +0 -99
  163. package/tests/initialize.test.ts +0 -79
  164. package/tests/interest-calculations.test.ts +0 -120
  165. package/tests/interest-collection/interest-collection.test.ts +0 -843
  166. package/tests/interest-collection/transactions-mutated.ts +0 -260
  167. package/tests/interest-oracle.test.ts +0 -93
  168. package/tests/mock/assets-mock.ts +0 -243
  169. package/tests/mock/protocol-params-mock.ts +0 -21
  170. package/tests/price-oracle/actions.ts +0 -161
  171. package/tests/price-oracle/price-oracle-queries.ts +0 -12
  172. package/tests/price-oracle/price-oracle.test.ts +0 -228
  173. package/tests/price-oracle/transactions-mutated.ts +0 -59
  174. package/tests/pyth/endpoints.ts +0 -96
  175. package/tests/pyth/helpers.ts +0 -37
  176. package/tests/pyth/pyth-encoding.test.ts +0 -376
  177. package/tests/pyth/pyth-feeds.test.ts +0 -943
  178. package/tests/pyth/pyth-indigo.test.ts +0 -505
  179. package/tests/pyth/pyth.test.ts +0 -299
  180. package/tests/queries/collector-queries.ts +0 -27
  181. package/tests/queries/execute-queries.ts +0 -47
  182. package/tests/queries/iasset-queries.ts +0 -149
  183. package/tests/queries/interest-oracle-queries.ts +0 -12
  184. package/tests/queries/poll-queries.ts +0 -97
  185. package/tests/queries/staking-queries.ts +0 -54
  186. package/tests/rob/actions.ts +0 -56
  187. package/tests/rob/rob-leverage.test.ts +0 -2555
  188. package/tests/rob/rob-queries.ts +0 -95
  189. package/tests/rob/rob.test.ts +0 -3677
  190. package/tests/rob/transactions-mutated.ts +0 -844
  191. package/tests/script-size.test.ts +0 -240
  192. package/tests/setup.ts +0 -135
  193. package/tests/stability-pool/actions.ts +0 -229
  194. package/tests/stability-pool.test.ts +0 -6491
  195. package/tests/stableswap/stableswap-actions.ts +0 -83
  196. package/tests/stableswap/stableswap-queries.ts +0 -98
  197. package/tests/stableswap/stableswap.test.ts +0 -4471
  198. package/tests/stableswap/transactions-mutated.ts +0 -348
  199. package/tests/staking.test.ts +0 -172
  200. package/tests/test-helpers.ts +0 -94
  201. package/tests/treasury/actions.ts +0 -67
  202. package/tests/treasury/treasury.test.ts +0 -320
  203. package/tests/utils/asserts.ts +0 -87
  204. package/tests/utils/benchmark-utils.ts +0 -130
  205. package/tests/utils/index.ts +0 -168
  206. package/tsconfig.build.json +0 -4
  207. package/tsconfig.json +0 -27
  208. package/vitest.config.ts +0 -11
@@ -1,505 +0,0 @@
1
- import { beforeEach, describe, test, expect } from 'vitest';
2
- import { IndigoTestContext, runAndAwaitTx } from '../test-helpers';
3
- import {
4
- EXAMPLE_TOKEN_1,
5
- EXAMPLE_TOKEN_2,
6
- EXAMPLE_TOKEN_3,
7
- MAINNET_PROTOCOL_PARAMETERS,
8
- } from '../indigo-test-helpers';
9
- import {
10
- addAssets,
11
- Emulator,
12
- fromHex,
13
- fromText,
14
- generateEmulatorAccount,
15
- generateEmulatorAccountFromPrivateKey,
16
- Lucid,
17
- toHex,
18
- } from '@lucid-evolution/lucid';
19
- import {
20
- adaAssetClass,
21
- AssetClass,
22
- mkAssetsOf,
23
- mkLovelacesOf,
24
- } from '@3rd-eye-labs/cardano-offchain-common';
25
- import {
26
- DEFAULT_INTEREST,
27
- DEFAULT_PRICE,
28
- ibtcInitialAssetCfgWithPyth,
29
- iethInitialAssetCfgWithPyth,
30
- iusdInitialAssetCfgWithPyth,
31
- mkBaseCollateralAsset,
32
- } from '../mock/assets-mock';
33
- import { runFreezeCdp, runOpenCdp, runWithdrawCdp } from '../cdp/actions';
34
- import { benchmarkAndAwaitTx } from '../utils/benchmark-utils';
35
- import { addrDetails, MIN_ROB_COLLATERAL_AMT, openRob } from '../../src';
36
- import { ParsedFeedPayload } from '@pythnetwork/pyth-lazer-sdk';
37
- import { createPythMessage } from './helpers';
38
- import { findSingleRob } from '../rob/rob-queries';
39
- import { expectValue } from '../utils/asserts';
40
- import { runRedeemRob } from '../rob/actions';
41
- import { rationalFromInt } from '../../src/types/rational';
42
- import { init } from '../endpoints/initialize';
43
-
44
- const collateralAssetA: AssetClass = {
45
- currencySymbol: fromHex(
46
- // random generated
47
- 'cc072059ae741791b7b9c23d9baea6a0b0d764dec617ce7e027a8dea',
48
- ),
49
- tokenName: fromHex(fromText('A')),
50
- };
51
-
52
- describe('Pyth > Indigo', () => {
53
- beforeEach<IndigoTestContext>(async (context: IndigoTestContext) => {
54
- context.users = {
55
- admin: generateEmulatorAccount(
56
- addAssets(
57
- mkLovelacesOf(100_000_000_000_000n),
58
- mkAssetsOf(EXAMPLE_TOKEN_1, 1_000_000_000_000_000n),
59
- mkAssetsOf(collateralAssetA, 100_000_000n),
60
- ),
61
- ),
62
- user: generateEmulatorAccount(
63
- addAssets(
64
- mkLovelacesOf(100_000_000_000_000n),
65
- mkAssetsOf(EXAMPLE_TOKEN_1, 1_000_000_000_000_000n),
66
- mkAssetsOf(EXAMPLE_TOKEN_2, 1_000_000_000_000_000n),
67
- mkAssetsOf(EXAMPLE_TOKEN_3, 1_000_000_000_000_000n),
68
- ),
69
- ),
70
- user2: generateEmulatorAccount({
71
- lovelace: BigInt(100_000_000_000_000),
72
- }),
73
- withdrawalAccount: generateEmulatorAccountFromPrivateKey({}),
74
- };
75
-
76
- context.emulator = new Emulator(
77
- [
78
- context.users.admin,
79
- context.users.user,
80
- context.users.user2,
81
- context.users.withdrawalAccount,
82
- ],
83
- MAINNET_PROTOCOL_PARAMETERS,
84
- );
85
- context.lucid = await Lucid(context.emulator, 'Custom');
86
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
87
-
88
- const [systemParams, assetConfigs] = await init(
89
- context.lucid,
90
- [],
91
- (pythStateNft: AssetClass) => [
92
- iusdInitialAssetCfgWithPyth(pythStateNft, (pythStatePolicyId) => [
93
- mkBaseCollateralAsset(
94
- adaAssetClass,
95
- DEFAULT_INTEREST,
96
- DEFAULT_PRICE,
97
- 0n,
98
- pythStatePolicyId,
99
- {
100
- tag: 'value',
101
- val: { priceFeedId: 1 },
102
- },
103
- ),
104
- ]),
105
- iethInitialAssetCfgWithPyth(pythStateNft, (pythStatePolicyId) => [
106
- mkBaseCollateralAsset(
107
- collateralAssetA,
108
- DEFAULT_INTEREST,
109
- DEFAULT_PRICE,
110
- 0n,
111
- pythStatePolicyId,
112
- {
113
- tag: 'value',
114
- val: { priceFeedId: 2 },
115
- },
116
- ),
117
- ]),
118
- ibtcInitialAssetCfgWithPyth(pythStateNft, (pythStatePolicyId) => [
119
- mkBaseCollateralAsset(
120
- adaAssetClass,
121
- DEFAULT_INTEREST,
122
- DEFAULT_PRICE,
123
- 0n,
124
- pythStatePolicyId,
125
- {
126
- tag: 'divide',
127
- val: [
128
- { tag: 'value', val: { priceFeedId: 1 } },
129
- { tag: 'value', val: { priceFeedId: 2 } },
130
- ],
131
- },
132
- ),
133
- ]),
134
- ],
135
- );
136
-
137
- context.systemParams = systemParams;
138
- context.assetConfigs = assetConfigs;
139
- });
140
-
141
- test('Open CDP - Direct Price Value (ada collateral)', async (context: IndigoTestContext) => {
142
- const currentTime = BigInt(
143
- context.lucid.slotToUnixTime(context.lucid.currentSlot()),
144
- );
145
-
146
- const iUsdFeed: ParsedFeedPayload = {
147
- priceFeedId: 1,
148
- price: '1000000',
149
- exponent: -6,
150
- };
151
- const message = await createPythMessage([iUsdFeed], currentTime * 1_000n);
152
-
153
- await benchmarkAndAwaitTx(
154
- 'Pyth - CDP - Direct Price Value (ADA collateral)',
155
- await runOpenCdp(
156
- context,
157
- context.systemParams,
158
- 'iUSD',
159
- adaAssetClass,
160
- 10_000_000n,
161
- 500_000n,
162
- toHex(message),
163
- ),
164
- context.lucid,
165
- context.emulator,
166
- );
167
- });
168
-
169
- test('Open CDP - Direct Price Value (non-ADA collateral)', async (context: IndigoTestContext) => {
170
- const currentTime = BigInt(
171
- context.lucid.slotToUnixTime(context.lucid.currentSlot()),
172
- );
173
-
174
- const iEthFeed: ParsedFeedPayload = {
175
- priceFeedId: 2,
176
- price: '1000000',
177
- exponent: -6,
178
- feedUpdateTimestamp: Number(currentTime) * 1000,
179
- };
180
- const message = await createPythMessage([iEthFeed], currentTime * 1_000n);
181
-
182
- await benchmarkAndAwaitTx(
183
- 'Pyth - CDP - Direct Price Value (non-ADA collateral)',
184
- await runOpenCdp(
185
- context,
186
- context.systemParams,
187
- 'iETH',
188
- collateralAssetA,
189
- 10_000_000n,
190
- 500_000n,
191
- toHex(message),
192
- ),
193
- context.lucid,
194
- context.emulator,
195
- );
196
- });
197
-
198
- test('Open CDP - Divide Price Value', async (context: IndigoTestContext) => {
199
- const currentTime = BigInt(
200
- context.lucid.slotToUnixTime(context.lucid.currentSlot()),
201
- );
202
-
203
- const feed1: ParsedFeedPayload = {
204
- priceFeedId: 1,
205
- price: '1000000',
206
- exponent: -6,
207
- };
208
- const feed2: ParsedFeedPayload = {
209
- priceFeedId: 2,
210
- price: '10',
211
- exponent: -1,
212
- };
213
- const message = await createPythMessage(
214
- [feed1, feed2],
215
- currentTime * 1_000n,
216
- );
217
-
218
- await benchmarkAndAwaitTx(
219
- 'Pyth - CDP - Divide Price Value',
220
- await runOpenCdp(
221
- context,
222
- context.systemParams,
223
- 'iBTC',
224
- adaAssetClass,
225
- 10_000_000n,
226
- 500_000n,
227
- toHex(message),
228
- ),
229
- context.lucid,
230
- context.emulator,
231
- );
232
- });
233
-
234
- test('Open CDP - Fails if missing feed price', async (context: IndigoTestContext) => {
235
- const currentTime = BigInt(
236
- context.lucid.slotToUnixTime(context.lucid.currentSlot()),
237
- );
238
-
239
- // This feed doesn't include a price for feedId 2, which is used by the iBTC asset
240
- const feed1: ParsedFeedPayload = {
241
- priceFeedId: 1,
242
- price: '1000000',
243
- exponent: -6,
244
- };
245
- const message = await createPythMessage([feed1], currentTime * 1_000n);
246
-
247
- await expect(
248
- runOpenCdp(
249
- context,
250
- context.systemParams,
251
- 'iBTC',
252
- adaAssetClass,
253
- 10_000_000n,
254
- 500_000n,
255
- toHex(message),
256
- ),
257
- ).rejects.toThrowError('Pyth payload not found for feed ID: 2');
258
- });
259
-
260
- test('Withdraw CDP - Direct Price Value', async (context: IndigoTestContext) => {
261
- const currentTime = BigInt(
262
- context.lucid.slotToUnixTime(context.lucid.currentSlot()),
263
- );
264
-
265
- const iUsdFeed: ParsedFeedPayload = {
266
- priceFeedId: 1,
267
- price: '1000000',
268
- exponent: -6,
269
- feedUpdateTimestamp: Number(currentTime) * 1000,
270
- };
271
- const message = await createPythMessage([iUsdFeed], currentTime * 1_000n);
272
-
273
- await runAndAwaitTx(
274
- context.lucid,
275
- runOpenCdp(
276
- context,
277
- context.systemParams,
278
- 'iUSD',
279
- adaAssetClass,
280
- 11_000_000n,
281
- 500_000n,
282
- toHex(message),
283
- ),
284
- );
285
-
286
- await benchmarkAndAwaitTx(
287
- 'Pyth - CDP - Withdraw CDP - Direct Price Value',
288
- await runWithdrawCdp(
289
- context,
290
- context.systemParams,
291
- 'iUSD',
292
- adaAssetClass,
293
- 1_000_000n,
294
- toHex(message),
295
- ),
296
- context.lucid,
297
- context.emulator,
298
- );
299
- });
300
-
301
- test('Freeze CDP - Direct Price Value', async (context: IndigoTestContext) => {
302
- const currentTime = BigInt(
303
- context.lucid.slotToUnixTime(context.lucid.currentSlot()),
304
- );
305
- {
306
- const iUsdFeed: ParsedFeedPayload = {
307
- priceFeedId: 1,
308
- price: '1000000',
309
- exponent: -6,
310
- };
311
- const message = await createPythMessage([iUsdFeed], currentTime * 1_000n);
312
-
313
- await runAndAwaitTx(
314
- context.lucid,
315
- runOpenCdp(
316
- context,
317
- context.systemParams,
318
- 'iUSD',
319
- adaAssetClass,
320
- 11_000_000n,
321
- 500_000n,
322
- toHex(message),
323
- ),
324
- );
325
- }
326
- {
327
- const iUsdFeed: ParsedFeedPayload = {
328
- priceFeedId: 1,
329
- price: '100000000',
330
- exponent: -6,
331
- };
332
- const message = await createPythMessage([iUsdFeed], currentTime * 1_000n);
333
- const [pkh, skh] = await addrDetails(context.lucid);
334
-
335
- await benchmarkAndAwaitTx(
336
- 'Pyth - CDP - Freeze CDP - Direct Price Value',
337
- await runFreezeCdp(
338
- context,
339
- context.systemParams,
340
- 'iUSD',
341
- adaAssetClass,
342
- pkh.hash,
343
- skh,
344
- toHex(message),
345
- ),
346
- context.lucid,
347
- context.emulator,
348
- );
349
- }
350
- });
351
-
352
- test<IndigoTestContext>('ROB redemption on buy order', async (context: IndigoTestContext) => {
353
- const [ownPkh, _] = await addrDetails(context.lucid);
354
-
355
- const currentTime = BigInt(
356
- context.lucid.slotToUnixTime(context.lucid.currentSlot()),
357
- );
358
- const iUsdFeed: ParsedFeedPayload = {
359
- priceFeedId: 1,
360
- price: '1000000',
361
- exponent: -6,
362
- feedUpdateTimestamp: Number(currentTime) * 1000,
363
- };
364
- const message = await createPythMessage([iUsdFeed], currentTime * 1_000n);
365
-
366
- await runAndAwaitTx(
367
- context.lucid,
368
- runOpenCdp(
369
- context,
370
- context.systemParams,
371
- 'iUSD',
372
- adaAssetClass,
373
- 100_000_000n,
374
- 30_000_000n,
375
- toHex(message),
376
- ),
377
- );
378
-
379
- const initialDeposit = 20_000_000n;
380
-
381
- await runAndAwaitTx(
382
- context.lucid,
383
- openRob(
384
- 'iUSD',
385
- initialDeposit,
386
- {
387
- BuyIAssetOrder: {
388
- collateralAsset: adaAssetClass,
389
- maxPrice: rationalFromInt(1n),
390
- },
391
- },
392
- context.lucid,
393
- context.systemParams,
394
- ),
395
- );
396
-
397
- const robUtxo = await findSingleRob(
398
- context,
399
- context.systemParams,
400
- 'iUSD',
401
- ownPkh,
402
- );
403
-
404
- const redemptionIAssetAmt = 7_500_000n;
405
-
406
- await benchmarkAndAwaitTx(
407
- 'Pyth - ROB - Redemption on buy order',
408
- await runRedeemRob(
409
- context,
410
- context.systemParams,
411
- [[robUtxo, redemptionIAssetAmt]],
412
- 'iUSD',
413
- adaAssetClass,
414
- toHex(message),
415
- ),
416
- context.lucid,
417
- context.emulator,
418
- );
419
- });
420
-
421
- test<IndigoTestContext>('ROB redemption on sell order', async (context: IndigoTestContext) => {
422
- const [ownPkh, _] = await addrDetails(context.lucid);
423
-
424
- const currentTime = BigInt(
425
- context.lucid.slotToUnixTime(context.lucid.currentSlot()),
426
- );
427
- const iUsdFeed: ParsedFeedPayload = {
428
- priceFeedId: 1,
429
- price: '1250000',
430
- exponent: -6,
431
- feedUpdateTimestamp: Number(currentTime) * 1000,
432
- };
433
- const message = await createPythMessage([iUsdFeed], currentTime * 1_000n);
434
-
435
- await runAndAwaitTx(
436
- context.lucid,
437
- runOpenCdp(
438
- context,
439
- context.systemParams,
440
- 'iUSD',
441
- adaAssetClass,
442
- 100_000_000n,
443
- 30_000_000n,
444
- toHex(message),
445
- ),
446
- );
447
-
448
- const initialDeposit = 20_000_000n;
449
-
450
- await runAndAwaitTx(
451
- context.lucid,
452
- openRob(
453
- 'iUSD',
454
- initialDeposit,
455
- {
456
- SellIAssetOrder: {
457
- allowedCollateralAssets: [[adaAssetClass, rationalFromInt(1n)]],
458
- },
459
- },
460
- context.lucid,
461
- context.systemParams,
462
- ),
463
- );
464
-
465
- const robUtxo = await findSingleRob(
466
- context,
467
- context.systemParams,
468
- 'iUSD',
469
- ownPkh,
470
- );
471
-
472
- const iassetAc: AssetClass = {
473
- currencySymbol: fromHex(
474
- context.systemParams.robParams.iassetPolicyId.unCurrencySymbol,
475
- ),
476
- tokenName: fromHex(fromText('iUSD')),
477
- };
478
-
479
- expectValue(
480
- robUtxo.utxo.assets,
481
- 'Wrong ROB value before redemption',
482
- ).toEqual(
483
- addAssets(
484
- mkLovelacesOf(MIN_ROB_COLLATERAL_AMT),
485
- mkAssetsOf(iassetAc, initialDeposit),
486
- ),
487
- );
488
-
489
- const payoutCollateralAmt = 7_500_000n;
490
-
491
- await benchmarkAndAwaitTx(
492
- 'Pyth - ROB - Redemption on sell order',
493
- await runRedeemRob(
494
- context,
495
- context.systemParams,
496
- [[robUtxo, payoutCollateralAmt]],
497
- 'iUSD',
498
- adaAssetClass,
499
- toHex(message),
500
- ),
501
- context.lucid,
502
- context.emulator,
503
- );
504
- });
505
- });