@indigo-labs/indigo-sdk 0.4.3 → 0.5.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.
- package/.claude/settings.local.json +7 -0
- package/dist/index.d.mts +992 -905
- package/dist/index.d.ts +992 -905
- package/dist/index.js +2346 -2155
- package/dist/index.mjs +1925 -1750
- package/package.json +13 -21
- package/scripts/bench.sh +0 -0
- package/src/contracts/cdp/helpers.ts +7 -6
- package/src/contracts/cdp/transactions.ts +8 -29
- package/src/contracts/gov/transactions.ts +15 -17
- package/src/contracts/iasset/helpers.ts +2 -7
- package/src/contracts/initialize/actions.ts +0 -2
- package/src/contracts/initialize/helpers.ts +0 -4
- package/src/contracts/interest-collection/transactions.ts +2 -5
- package/src/contracts/interest-oracle/helpers.ts +4 -0
- package/src/contracts/interest-oracle/transactions.ts +1 -4
- package/src/contracts/price-oracle/helpers.ts +5 -11
- package/src/contracts/price-oracle/transactions.ts +2 -7
- package/src/contracts/rob/transactions.ts +0 -2
- package/src/contracts/rob-leverage/transactions.ts +1 -4
- package/{tests/queries/stability-pool-queries.ts → src/contracts/stability-pool/queries.ts} +22 -14
- package/src/contracts/stability-pool/transactions.ts +2 -8
- package/src/contracts/stableswap/helpers.ts +369 -1
- package/src/contracts/stableswap/transactions.ts +43 -191
- package/src/contracts/staking/transactions.ts +2 -7
- package/src/index.ts +4 -3
- package/tests/cdp/actions.ts +0 -11
- package/tests/cdp/cdp-helpers.ts +2 -2
- package/tests/cdp/cdp-queries.ts +8 -5
- package/tests/cdp/cdp.test.ts +409 -620
- package/tests/cdp/transactions-mutated.ts +30 -25
- package/tests/endpoints/initialize.ts +0 -2
- package/tests/gov/actions.ts +7 -32
- package/tests/gov/gov.test.ts +169 -401
- package/tests/indigo-test-helpers.ts +0 -1
- package/tests/initialize.test.ts +15 -20
- package/tests/interest-collection/interest-collection.test.ts +0 -4
- package/tests/interest-oracle.test.ts +1 -8
- package/tests/price-oracle/actions.ts +6 -8
- package/tests/price-oracle/price-oracle.test.ts +1 -13
- package/tests/price-oracle/transactions-mutated.ts +1 -4
- package/tests/pyth/pyth-feeds.test.ts +943 -0
- package/tests/pyth/pyth-indigo.test.ts +8 -12
- package/tests/pyth/pyth.test.ts +1 -2
- package/tests/rob/actions.ts +0 -2
- package/tests/rob/rob-leverage.test.ts +164 -220
- package/tests/rob/rob.test.ts +158 -263
- package/tests/rob/transactions-mutated.ts +7 -18
- package/tests/stability-pool/actions.ts +31 -22
- package/tests/stability-pool.test.ts +226 -319
- package/tests/stableswap/stableswap-actions.ts +0 -1
- package/tests/stableswap/stableswap.test.ts +226 -4
- package/tests/staking.test.ts +2 -13
- package/tests/treasury/treasury.test.ts +6 -30
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
sortUTxOs,
|
|
12
12
|
toHex,
|
|
13
13
|
TxBuilder,
|
|
14
|
-
UTxO,
|
|
15
14
|
} from '@lucid-evolution/lucid';
|
|
16
15
|
import {
|
|
17
16
|
fromSystemParamsScriptRef,
|
|
@@ -42,34 +41,20 @@ import {
|
|
|
42
41
|
serialiseStableswapPoolDatum,
|
|
43
42
|
StableswapPoolContent,
|
|
44
43
|
} from '../cdp/types-new';
|
|
45
|
-
import { calculateFeeFromRatio } from '../../utils/indigo-helpers';
|
|
46
44
|
import { array as A, function as F } from 'fp-ts';
|
|
47
45
|
import { isEmpty } from 'fp-ts/lib/Array';
|
|
48
|
-
import {
|
|
46
|
+
import {
|
|
47
|
+
BASE_MAX_EXECUTION_FEE,
|
|
48
|
+
createDestinationDatum,
|
|
49
|
+
defaultOrderProcessingConfig,
|
|
50
|
+
OrderProcessConfig,
|
|
51
|
+
StableswapInfo,
|
|
52
|
+
StableswapOrderInfo,
|
|
53
|
+
summariseOrder,
|
|
54
|
+
} from './helpers';
|
|
49
55
|
import * as Core from '@evolution-sdk/evolution';
|
|
50
56
|
import { treasuryFeeTx } from '../treasury/transactions';
|
|
51
|
-
import {
|
|
52
|
-
Rational,
|
|
53
|
-
rationalDiv,
|
|
54
|
-
rationalFloor,
|
|
55
|
-
rationalFromInt,
|
|
56
|
-
rationalMul,
|
|
57
|
-
} from '../../types/rational';
|
|
58
|
-
|
|
59
|
-
type StableswapInfo = {
|
|
60
|
-
suppliedCollateralAsset: bigint;
|
|
61
|
-
suppliedIasset: bigint;
|
|
62
|
-
owedCollateralAsset: bigint;
|
|
63
|
-
owedIasset: bigint;
|
|
64
|
-
mintingFee: bigint;
|
|
65
|
-
redemptionFee: bigint;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
type StableswapOrderInfo = {
|
|
69
|
-
utxo: UTxO;
|
|
70
|
-
datum: StableswapOrderDatum;
|
|
71
|
-
swapInfo: StableswapInfo;
|
|
72
|
-
};
|
|
57
|
+
import { Rational } from '../../types/rational';
|
|
73
58
|
|
|
74
59
|
export async function createStableswapOrder(
|
|
75
60
|
iasset: string,
|
|
@@ -188,6 +173,7 @@ export async function batchProcessStableswapOrders(
|
|
|
188
173
|
treasuryOref: OutRef,
|
|
189
174
|
sysParams: SystemParams,
|
|
190
175
|
lucid: LucidEvolution,
|
|
176
|
+
orderProcessingConfig: OrderProcessConfig = defaultOrderProcessingConfig,
|
|
191
177
|
): Promise<TxBuilder> {
|
|
192
178
|
const stableswapScriptRefUtxo = matchSingle(
|
|
193
179
|
await lucid.utxosByOutRef([
|
|
@@ -269,159 +255,18 @@ export async function batchProcessStableswapOrders(
|
|
|
269
255
|
throw new Error('Wrong batch of orders');
|
|
270
256
|
}
|
|
271
257
|
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
258
|
+
const res = summariseOrder(
|
|
259
|
+
{ utxo: orderUtxo, datum: orderDatum },
|
|
260
|
+
{ utxo: stableswapPoolUtxo, datum: stableswapPoolDatum },
|
|
261
|
+
sysParams,
|
|
262
|
+
orderProcessingConfig,
|
|
276
263
|
);
|
|
277
264
|
|
|
278
|
-
if (
|
|
279
|
-
|
|
280
|
-
(suppliedIasset == 0n && suppliedCollateralAsset == 0n)
|
|
281
|
-
) {
|
|
282
|
-
throw new Error(
|
|
283
|
-
'An order must supply either iAsset or collateral asset',
|
|
284
|
-
);
|
|
265
|
+
if (res._tag === 'ERROR') {
|
|
266
|
+
throw new Error(res.reason);
|
|
285
267
|
}
|
|
286
268
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
const isOneToOne =
|
|
290
|
-
stableswapPoolDatum.collateralToIassetRatio.numerator ===
|
|
291
|
-
stableswapPoolDatum.collateralToIassetRatio.denominator;
|
|
292
|
-
|
|
293
|
-
if (isMinting) {
|
|
294
|
-
// Mint order with one to one ratio case.
|
|
295
|
-
if (isOneToOne) {
|
|
296
|
-
const fee = calculateFeeFromRatio(
|
|
297
|
-
stableswapPoolDatum.mintingFeeRatio,
|
|
298
|
-
suppliedCollateralAsset,
|
|
299
|
-
);
|
|
300
|
-
|
|
301
|
-
return {
|
|
302
|
-
utxo: orderUtxo,
|
|
303
|
-
datum: orderDatum,
|
|
304
|
-
swapInfo: {
|
|
305
|
-
suppliedCollateralAsset: suppliedCollateralAsset,
|
|
306
|
-
suppliedIasset: 0n,
|
|
307
|
-
owedCollateralAsset: 0n,
|
|
308
|
-
owedIasset: suppliedCollateralAsset - fee,
|
|
309
|
-
mintingFee: fee,
|
|
310
|
-
redemptionFee: 0n,
|
|
311
|
-
},
|
|
312
|
-
};
|
|
313
|
-
// Mint order with any ratio case.
|
|
314
|
-
} else {
|
|
315
|
-
const iAssetConversion = rationalFloor(
|
|
316
|
-
rationalDiv(
|
|
317
|
-
rationalFromInt(suppliedCollateralAsset),
|
|
318
|
-
stableswapPoolDatum.collateralToIassetRatio,
|
|
319
|
-
),
|
|
320
|
-
);
|
|
321
|
-
|
|
322
|
-
const attemptedNormalizedCollateral = rationalFloor(
|
|
323
|
-
rationalMul(
|
|
324
|
-
rationalFromInt(iAssetConversion),
|
|
325
|
-
stableswapPoolDatum.collateralToIassetRatio,
|
|
326
|
-
),
|
|
327
|
-
);
|
|
328
|
-
|
|
329
|
-
const normalizedCollateralSupplied =
|
|
330
|
-
rationalFloor(
|
|
331
|
-
rationalDiv(
|
|
332
|
-
rationalFromInt(attemptedNormalizedCollateral),
|
|
333
|
-
stableswapPoolDatum.collateralToIassetRatio,
|
|
334
|
-
),
|
|
335
|
-
) != iAssetConversion
|
|
336
|
-
? suppliedCollateralAsset
|
|
337
|
-
: attemptedNormalizedCollateral;
|
|
338
|
-
|
|
339
|
-
const fee = calculateFeeFromRatio(
|
|
340
|
-
stableswapPoolDatum.mintingFeeRatio,
|
|
341
|
-
iAssetConversion,
|
|
342
|
-
);
|
|
343
|
-
|
|
344
|
-
return {
|
|
345
|
-
utxo: orderUtxo,
|
|
346
|
-
datum: orderDatum,
|
|
347
|
-
swapInfo: {
|
|
348
|
-
suppliedCollateralAsset: normalizedCollateralSupplied,
|
|
349
|
-
suppliedIasset: 0n,
|
|
350
|
-
owedCollateralAsset: 0n,
|
|
351
|
-
owedIasset: iAssetConversion - fee,
|
|
352
|
-
mintingFee: fee,
|
|
353
|
-
redemptionFee: 0n,
|
|
354
|
-
},
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
// Redeem order case
|
|
358
|
-
} else {
|
|
359
|
-
const fee = calculateFeeFromRatio(
|
|
360
|
-
stableswapPoolDatum.redemptionFeeRatio,
|
|
361
|
-
suppliedIasset,
|
|
362
|
-
);
|
|
363
|
-
|
|
364
|
-
const effectiveSuppliedIasset = suppliedIasset - fee;
|
|
365
|
-
|
|
366
|
-
// Redeem order with one to one ratio case
|
|
367
|
-
if (isOneToOne) {
|
|
368
|
-
return {
|
|
369
|
-
utxo: orderUtxo,
|
|
370
|
-
datum: orderDatum,
|
|
371
|
-
swapInfo: {
|
|
372
|
-
suppliedCollateralAsset: 0n,
|
|
373
|
-
suppliedIasset: effectiveSuppliedIasset,
|
|
374
|
-
owedCollateralAsset: effectiveSuppliedIasset,
|
|
375
|
-
owedIasset: 0n,
|
|
376
|
-
mintingFee: 0n,
|
|
377
|
-
redemptionFee: fee,
|
|
378
|
-
},
|
|
379
|
-
};
|
|
380
|
-
// Redeem order with any ratio case
|
|
381
|
-
} else {
|
|
382
|
-
const collateralConversion = rationalFloor(
|
|
383
|
-
rationalMul(
|
|
384
|
-
rationalFromInt(effectiveSuppliedIasset),
|
|
385
|
-
stableswapPoolDatum.collateralToIassetRatio,
|
|
386
|
-
),
|
|
387
|
-
);
|
|
388
|
-
|
|
389
|
-
const attemptedNormalizedEffectiveIasset = rationalFloor(
|
|
390
|
-
rationalDiv(
|
|
391
|
-
rationalFromInt(collateralConversion),
|
|
392
|
-
stableswapPoolDatum.collateralToIassetRatio,
|
|
393
|
-
),
|
|
394
|
-
);
|
|
395
|
-
|
|
396
|
-
const normalizedEffectiveIasset =
|
|
397
|
-
rationalFloor(
|
|
398
|
-
rationalMul(
|
|
399
|
-
rationalFromInt(attemptedNormalizedEffectiveIasset),
|
|
400
|
-
stableswapPoolDatum.collateralToIassetRatio,
|
|
401
|
-
),
|
|
402
|
-
) != collateralConversion
|
|
403
|
-
? effectiveSuppliedIasset
|
|
404
|
-
: attemptedNormalizedEffectiveIasset;
|
|
405
|
-
|
|
406
|
-
return {
|
|
407
|
-
utxo: orderUtxo,
|
|
408
|
-
datum: orderDatum,
|
|
409
|
-
swapInfo: {
|
|
410
|
-
suppliedCollateralAsset: 0n,
|
|
411
|
-
suppliedIasset: normalizedEffectiveIasset,
|
|
412
|
-
owedCollateralAsset: rationalFloor(
|
|
413
|
-
rationalMul(
|
|
414
|
-
rationalFromInt(effectiveSuppliedIasset),
|
|
415
|
-
stableswapPoolDatum.collateralToIassetRatio,
|
|
416
|
-
),
|
|
417
|
-
),
|
|
418
|
-
owedIasset: 0n,
|
|
419
|
-
mintingFee: 0n,
|
|
420
|
-
redemptionFee: fee,
|
|
421
|
-
},
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
}
|
|
269
|
+
return res.result;
|
|
425
270
|
},
|
|
426
271
|
);
|
|
427
272
|
|
|
@@ -448,7 +293,7 @@ export async function batchProcessStableswapOrders(
|
|
|
448
293
|
owedIasset: acc.owedIasset + orderInfo.swapInfo.owedIasset,
|
|
449
294
|
mintingFee: acc.mintingFee + orderInfo.swapInfo.mintingFee,
|
|
450
295
|
redemptionFee: acc.redemptionFee + orderInfo.swapInfo.redemptionFee,
|
|
451
|
-
};
|
|
296
|
+
} satisfies StableswapInfo;
|
|
452
297
|
},
|
|
453
298
|
),
|
|
454
299
|
);
|
|
@@ -456,6 +301,15 @@ export async function batchProcessStableswapOrders(
|
|
|
456
301
|
const collateralAmtChangePool =
|
|
457
302
|
totalSwapInfo.suppliedCollateralAsset - totalSwapInfo.owedCollateralAsset;
|
|
458
303
|
|
|
304
|
+
const newPsmPoolValue = addAssets(
|
|
305
|
+
stableswapPoolUtxo.assets,
|
|
306
|
+
mkAssetsOf(collateralAc, collateralAmtChangePool),
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
if (assetClassValueOf(newPsmPoolValue, collateralAc) < 0n) {
|
|
310
|
+
throw new Error('Cannot batch more than liquidity allows');
|
|
311
|
+
}
|
|
312
|
+
|
|
459
313
|
const amountToMint =
|
|
460
314
|
totalSwapInfo.owedIasset -
|
|
461
315
|
totalSwapInfo.suppliedIasset +
|
|
@@ -486,12 +340,7 @@ export async function batchProcessStableswapOrders(
|
|
|
486
340
|
kind: 'inline',
|
|
487
341
|
value: serialiseStableswapPoolDatum(stableswapPoolDatum),
|
|
488
342
|
},
|
|
489
|
-
|
|
490
|
-
? addAssets(
|
|
491
|
-
stableswapPoolUtxo.assets,
|
|
492
|
-
mkAssetsOf(collateralAc, collateralAmtChangePool),
|
|
493
|
-
)
|
|
494
|
-
: stableswapPoolUtxo.assets,
|
|
343
|
+
newPsmPoolValue,
|
|
495
344
|
)
|
|
496
345
|
// This has to be added as otherwise there is the following error:
|
|
497
346
|
// TxBuilderError: { Complete: RedeemerBuilder: Coin selection had to be updated
|
|
@@ -509,8 +358,8 @@ export async function batchProcessStableswapOrders(
|
|
|
509
358
|
A.reduce<StableswapOrderInfo, TxBuilder>(tx, (acc, orderInfo) => {
|
|
510
359
|
return acc
|
|
511
360
|
.collectFrom(
|
|
512
|
-
[orderInfo.utxo],
|
|
513
|
-
isSameOutRef(orderInfo.utxo, mainOrderUtxo)
|
|
361
|
+
[orderInfo.order.utxo],
|
|
362
|
+
isSameOutRef(orderInfo.order.utxo, mainOrderUtxo)
|
|
514
363
|
? serialiseStableswapOrderRedeemer('BatchProcessStableswapOrders')
|
|
515
364
|
: {
|
|
516
365
|
kind: 'selected',
|
|
@@ -522,26 +371,29 @@ export async function batchProcessStableswapOrders(
|
|
|
522
371
|
},
|
|
523
372
|
});
|
|
524
373
|
},
|
|
525
|
-
inputs: [orderInfo.utxo, mainOrderUtxo],
|
|
374
|
+
inputs: [orderInfo.order.utxo, mainOrderUtxo],
|
|
526
375
|
},
|
|
527
376
|
)
|
|
528
377
|
.pay.ToAddressWithData(
|
|
529
|
-
addressToBech32(
|
|
378
|
+
addressToBech32(
|
|
379
|
+
orderInfo.order.datum.destination,
|
|
380
|
+
lucid.config().network!,
|
|
381
|
+
),
|
|
530
382
|
{
|
|
531
383
|
kind: 'inline',
|
|
532
384
|
value: createDestinationDatum(
|
|
533
|
-
orderInfo.datum.destinationInlineDatum ?? null,
|
|
534
|
-
orderInfo.utxo,
|
|
385
|
+
orderInfo.order.datum.destinationInlineDatum ?? null,
|
|
386
|
+
orderInfo.order.utxo,
|
|
535
387
|
),
|
|
536
388
|
},
|
|
537
389
|
addAssets(
|
|
538
|
-
// Currently, we always take the max execution fee from the order utxo.
|
|
390
|
+
// NOTICE: Currently, we always take the max execution fee from the order utxo.
|
|
539
391
|
// This can be improved so that we take the actual execution fee.
|
|
540
392
|
mkLovelacesOf(
|
|
541
|
-
lovelacesAmt(orderInfo.utxo.assets) -
|
|
542
|
-
orderInfo.datum.maxExecutionFee,
|
|
393
|
+
lovelacesAmt(orderInfo.order.utxo.assets) -
|
|
394
|
+
orderInfo.order.datum.maxExecutionFee,
|
|
543
395
|
),
|
|
544
|
-
orderInfo.
|
|
396
|
+
orderInfo.orderType === 'MINTING'
|
|
545
397
|
? mkAssetsOf(iassetAc, orderInfo.swapInfo.owedIasset)
|
|
546
398
|
: mkAssetsOf(
|
|
547
399
|
collateralAc,
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
fromText,
|
|
6
6
|
LucidEvolution,
|
|
7
7
|
OutRef,
|
|
8
|
-
slotToUnixTime,
|
|
9
8
|
toHex,
|
|
10
9
|
TxBuilder,
|
|
11
10
|
} from '@lucid-evolution/lucid';
|
|
@@ -130,11 +129,9 @@ export async function adjustStakingPosition(
|
|
|
130
129
|
amount: bigint,
|
|
131
130
|
params: SystemParams,
|
|
132
131
|
lucid: LucidEvolution,
|
|
133
|
-
currentSlot: number,
|
|
134
132
|
stakingManagerRef?: OutRef,
|
|
135
133
|
): Promise<TxBuilder> {
|
|
136
|
-
const
|
|
137
|
-
const now = BigInt(slotToUnixTime(network, currentSlot));
|
|
134
|
+
const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
138
135
|
|
|
139
136
|
const stakingPositionOut = await findStakingPositionByOutRef(
|
|
140
137
|
stakingPositionRef,
|
|
@@ -210,11 +207,9 @@ export async function closeStakingPosition(
|
|
|
210
207
|
stakingPositionRef: OutRef,
|
|
211
208
|
params: SystemParams,
|
|
212
209
|
lucid: LucidEvolution,
|
|
213
|
-
currentSlot: number,
|
|
214
210
|
stakingManagerRef?: OutRef,
|
|
215
211
|
): Promise<TxBuilder> {
|
|
216
|
-
const
|
|
217
|
-
const now = BigInt(slotToUnixTime(network, currentSlot));
|
|
212
|
+
const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
218
213
|
|
|
219
214
|
const stakingPositionOut = await findStakingPositionByOutRef(
|
|
220
215
|
stakingPositionRef,
|
package/src/index.ts
CHANGED
|
@@ -13,8 +13,6 @@ export * from './contracts/gov/transactions';
|
|
|
13
13
|
export * from './contracts/gov/types';
|
|
14
14
|
export * from './contracts/gov/types-new';
|
|
15
15
|
export * from './contracts/gov/scripts';
|
|
16
|
-
export * from './contracts/stability-pool/transactions';
|
|
17
|
-
export * from './contracts/stability-pool/scripts';
|
|
18
16
|
export * from './contracts/staking/transactions';
|
|
19
17
|
export * from './contracts/staking/helpers';
|
|
20
18
|
export * from './contracts/staking/types-new';
|
|
@@ -37,7 +35,6 @@ export * from './contracts/treasury/transactions';
|
|
|
37
35
|
export * from './contracts/treasury/helpers';
|
|
38
36
|
export * from './contracts/treasury/scripts';
|
|
39
37
|
export * from './contracts/treasury/queries';
|
|
40
|
-
export * from './contracts/stability-pool/helpers';
|
|
41
38
|
export * from './utils/time-helpers';
|
|
42
39
|
export * from './contracts/cdp/scripts';
|
|
43
40
|
export * from './contracts/collector/scripts';
|
|
@@ -45,8 +42,12 @@ export * from './contracts/execute/types';
|
|
|
45
42
|
export * from './contracts/execute/types-new';
|
|
46
43
|
export * from './contracts/execute/scripts';
|
|
47
44
|
export * from './contracts/price-oracle/types';
|
|
45
|
+
export * from './contracts/stability-pool/helpers';
|
|
48
46
|
export * from './contracts/stability-pool/types';
|
|
49
47
|
export * from './contracts/stability-pool/types-new';
|
|
48
|
+
export * from './contracts/stability-pool/queries';
|
|
49
|
+
export * from './contracts/stability-pool/transactions';
|
|
50
|
+
export * from './contracts/stability-pool/scripts';
|
|
50
51
|
export * from './contracts/poll/types-poll-shard';
|
|
51
52
|
export * from './contracts/poll/types-poll-manager';
|
|
52
53
|
export * from './contracts/poll/types-poll-new';
|
package/tests/cdp/actions.ts
CHANGED
|
@@ -103,7 +103,6 @@ export async function runOpenCdp(
|
|
|
103
103
|
orefs.interestOracleUtxo,
|
|
104
104
|
directTreasuryPayment ? undefined : orefs.treasuryUtxo,
|
|
105
105
|
context.lucid,
|
|
106
|
-
context.emulator.slot,
|
|
107
106
|
pythMessage,
|
|
108
107
|
pythStateOref,
|
|
109
108
|
);
|
|
@@ -142,7 +141,6 @@ export async function runDepositCdp(
|
|
|
142
141
|
orefs.interestCollectorUtxo,
|
|
143
142
|
sysParams,
|
|
144
143
|
context.lucid,
|
|
145
|
-
context.emulator.slot,
|
|
146
144
|
);
|
|
147
145
|
}
|
|
148
146
|
|
|
@@ -194,7 +192,6 @@ export async function runWithdrawCdp(
|
|
|
194
192
|
orefs.interestCollectorUtxo,
|
|
195
193
|
sysParams,
|
|
196
194
|
context.lucid,
|
|
197
|
-
context.emulator.slot,
|
|
198
195
|
pythMessage,
|
|
199
196
|
pythStateOref,
|
|
200
197
|
);
|
|
@@ -249,7 +246,6 @@ export async function runMintCdp(
|
|
|
249
246
|
orefs.interestCollectorUtxo,
|
|
250
247
|
sysParams,
|
|
251
248
|
context.lucid,
|
|
252
|
-
context.emulator.slot,
|
|
253
249
|
pythMessage,
|
|
254
250
|
pythStateOref,
|
|
255
251
|
);
|
|
@@ -288,7 +284,6 @@ export async function runBurnCdp(
|
|
|
288
284
|
orefs.interestCollectorUtxo,
|
|
289
285
|
sysParams,
|
|
290
286
|
context.lucid,
|
|
291
|
-
context.emulator.slot,
|
|
292
287
|
);
|
|
293
288
|
}
|
|
294
289
|
|
|
@@ -321,7 +316,6 @@ export async function runCloseCdp(
|
|
|
321
316
|
orefs.interestCollectorUtxo,
|
|
322
317
|
sysParams,
|
|
323
318
|
context.lucid,
|
|
324
|
-
context.emulator.slot,
|
|
325
319
|
);
|
|
326
320
|
}
|
|
327
321
|
|
|
@@ -367,7 +361,6 @@ export async function runRedeemCdp(
|
|
|
367
361
|
orefs.govUtxo,
|
|
368
362
|
sysParams,
|
|
369
363
|
context.lucid,
|
|
370
|
-
context.emulator.slot,
|
|
371
364
|
);
|
|
372
365
|
}
|
|
373
366
|
|
|
@@ -415,7 +408,6 @@ export async function runFreezeCdp(
|
|
|
415
408
|
orefs.interestOracleUtxo,
|
|
416
409
|
sysParams,
|
|
417
410
|
context.lucid,
|
|
418
|
-
context.emulator.slot,
|
|
419
411
|
pythMessage,
|
|
420
412
|
pythStateOref,
|
|
421
413
|
);
|
|
@@ -463,7 +455,6 @@ export async function runCreateAndFreezeCdps(
|
|
|
463
455
|
orefs.interestOracleUtxo,
|
|
464
456
|
orefs.treasuryUtxo,
|
|
465
457
|
context.lucid,
|
|
466
|
-
context.emulator.slot,
|
|
467
458
|
),
|
|
468
459
|
);
|
|
469
460
|
});
|
|
@@ -475,7 +466,6 @@ export async function runCreateAndFreezeCdps(
|
|
|
475
466
|
priceOracleUtxo!,
|
|
476
467
|
{ numerator: 18n, denominator: 10n }, // 1.8
|
|
477
468
|
assetInfo.collateralAssets[0].oracleParams!,
|
|
478
|
-
context.emulator.slot,
|
|
479
469
|
),
|
|
480
470
|
);
|
|
481
471
|
|
|
@@ -515,7 +505,6 @@ export async function runCreateAndFreezeCdps(
|
|
|
515
505
|
orefs.interestOracleUtxo,
|
|
516
506
|
sysParams,
|
|
517
507
|
context.lucid,
|
|
518
|
-
context.emulator.slot,
|
|
519
508
|
),
|
|
520
509
|
);
|
|
521
510
|
}
|
package/tests/cdp/cdp-helpers.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { match, P } from 'ts-pattern';
|
|
|
2
2
|
import { CDPContent } from '../../src/contracts/cdp/types-new';
|
|
3
3
|
import { calculateAccruedInterest } from '../../src/contracts/interest-oracle/helpers';
|
|
4
4
|
import { LucidContext } from '../test-helpers';
|
|
5
|
-
import {
|
|
5
|
+
import { toHex, toText } from '@lucid-evolution/lucid';
|
|
6
6
|
import { findCollateralAsset } from '../queries/iasset-queries';
|
|
7
7
|
import {
|
|
8
8
|
fromSystemParamsAsset,
|
|
@@ -18,7 +18,7 @@ export async function calculateCdpInterest(
|
|
|
18
18
|
sysParams: SystemParams,
|
|
19
19
|
): Promise<bigint> {
|
|
20
20
|
const currentTime = BigInt(
|
|
21
|
-
|
|
21
|
+
context.lucid.slotToUnixTime(context.lucid.currentSlot()),
|
|
22
22
|
);
|
|
23
23
|
|
|
24
24
|
const collateralAsset = await findCollateralAsset(
|
package/tests/cdp/cdp-queries.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Credential,
|
|
3
|
+
fromHex,
|
|
3
4
|
fromText,
|
|
4
5
|
LucidEvolution,
|
|
5
6
|
ScriptHash,
|
|
@@ -12,6 +13,7 @@ import {
|
|
|
12
13
|
adjustPriceToDecimals,
|
|
13
14
|
cdpCollateralRatioPercentage,
|
|
14
15
|
createScriptAddress,
|
|
16
|
+
findStabilityPool,
|
|
15
17
|
fromSystemParamsAsset,
|
|
16
18
|
matchSingle,
|
|
17
19
|
SystemParams,
|
|
@@ -35,7 +37,6 @@ import {
|
|
|
35
37
|
parseInterestOracleDatum,
|
|
36
38
|
} from '../../src/contracts/interest-oracle/types-new';
|
|
37
39
|
import { findCollateralAsset, findIAsset } from '../queries/iasset-queries';
|
|
38
|
-
import { findStabilityPool } from '../queries/stability-pool-queries';
|
|
39
40
|
import { findPriceOracle } from '../price-oracle/price-oracle-queries';
|
|
40
41
|
import { findInterestOracle } from '../queries/interest-oracle-queries';
|
|
41
42
|
import { findRandomCollector } from '../queries/collector-queries';
|
|
@@ -289,7 +290,11 @@ export async function findAllNecessaryOrefs(
|
|
|
289
290
|
collateralAsset,
|
|
290
291
|
);
|
|
291
292
|
|
|
292
|
-
const stabilityPool = await findStabilityPool(
|
|
293
|
+
const stabilityPool = await findStabilityPool(
|
|
294
|
+
lucid,
|
|
295
|
+
sysParams,
|
|
296
|
+
fromHex(fromText(iasset)),
|
|
297
|
+
);
|
|
293
298
|
|
|
294
299
|
return {
|
|
295
300
|
stabilityPoolUtxo: stabilityPool.utxo,
|
|
@@ -380,7 +385,6 @@ export async function findCdpCR(
|
|
|
380
385
|
lucid: LucidEvolution,
|
|
381
386
|
sysParams: SystemParams,
|
|
382
387
|
cdp: { utxo: UTxO; datum: CDPContent },
|
|
383
|
-
slot: number,
|
|
384
388
|
): Promise<number> {
|
|
385
389
|
const iassetAscii = toText(toHex(cdp.datum.iasset));
|
|
386
390
|
|
|
@@ -405,7 +409,7 @@ export async function findCdpCR(
|
|
|
405
409
|
);
|
|
406
410
|
|
|
407
411
|
return cdpCollateralRatioPercentage(
|
|
408
|
-
|
|
412
|
+
BigInt(lucid.slotToUnixTime(lucid.currentSlot())),
|
|
409
413
|
adjustedPrice,
|
|
410
414
|
cdp.utxo.assets,
|
|
411
415
|
cdp.datum,
|
|
@@ -415,6 +419,5 @@ export async function findCdpCR(
|
|
|
415
419
|
iassetAscii,
|
|
416
420
|
cdp.datum.collateralAsset,
|
|
417
421
|
),
|
|
418
|
-
lucid.config().network!,
|
|
419
422
|
);
|
|
420
423
|
}
|