@indigo-labs/indigo-sdk 0.2.35 → 0.2.37
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/dist/index.d.mts +633 -43
- package/dist/index.d.ts +633 -43
- package/dist/index.js +1292 -419
- package/dist/index.mjs +1274 -426
- package/package.json +6 -3
- package/src/contracts/cdp/transactions.ts +175 -201
- package/src/contracts/collector/transactions.ts +7 -11
- package/src/contracts/gov/transactions.ts +72 -67
- package/src/contracts/initialize/helpers.ts +45 -0
- package/{tests/endpoints/initialize.ts → src/contracts/initialize/transactions.ts} +240 -264
- package/src/contracts/initialize/types.ts +42 -0
- package/src/contracts/interest-oracle/transactions.ts +6 -6
- package/src/contracts/leverage/transactions.ts +24 -19
- package/src/contracts/lrp/transactions.ts +18 -20
- package/src/contracts/poll/helpers.ts +1 -1
- package/src/contracts/price-oracle/transactions.ts +6 -5
- package/src/contracts/stability-pool/transactions.ts +4 -10
- package/src/contracts/staking/helpers.ts +30 -47
- package/src/contracts/staking/transactions.ts +89 -58
- package/src/contracts/treasury/transactions.ts +10 -6
- package/src/contracts/vesting/helpers.ts +18 -67
- package/src/index.ts +7 -0
- package/src/utils/lucid-utils.ts +42 -0
- package/tests/cdp.test.ts +1 -1
- package/tests/gov.test.ts +99 -17
- package/tests/initialize.test.ts +1 -1
- package/tests/lrp-leverage.test.ts +1 -1
- package/tests/lrp.test.ts +1 -1
- package/tests/mock/assets-mock.ts +2 -29
- package/tests/stability-pool.test.ts +1 -1
- package/tests/staking.test.ts +25 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indigo-labs/indigo-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.37",
|
|
4
4
|
"description": "Indigo SDK for interacting with Indigo endpoints via lucid-evolution",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"@3rd-eye-labs/cardano-offchain-common": "^1.1.8",
|
|
44
44
|
"@evolution-sdk/evolution": "^0.2.5",
|
|
45
45
|
"@harmoniclabs/crypto": "^0.3.0",
|
|
46
|
-
"@lucid-evolution/lucid": "^0.4.29",
|
|
47
46
|
"decimal.js": "^10.6.0",
|
|
48
47
|
"dotenv": "^16.5.0",
|
|
49
48
|
"fp-ts": "^2.16.10",
|
|
@@ -63,6 +62,10 @@
|
|
|
63
62
|
"tsup": "^8.3.6",
|
|
64
63
|
"typescript": "^5.9.2",
|
|
65
64
|
"typescript-eslint": "^8.39.0",
|
|
66
|
-
"vitest": "^4.0.14"
|
|
65
|
+
"vitest": "^4.0.14",
|
|
66
|
+
"@lucid-evolution/lucid": "^0.4.29"
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"@lucid-evolution/lucid": ">=0.4.29"
|
|
67
70
|
}
|
|
68
71
|
}
|
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
addrDetails,
|
|
18
18
|
createScriptAddress,
|
|
19
19
|
getInlineDatumOrThrow,
|
|
20
|
+
resolveUtxo,
|
|
21
|
+
UtxoOrOutRef,
|
|
20
22
|
} from '../../utils/lucid-utils';
|
|
21
23
|
import { matchSingle } from '../../utils/utils';
|
|
22
24
|
import {
|
|
@@ -61,11 +63,11 @@ export async function openCdp(
|
|
|
61
63
|
collateralAmount: bigint,
|
|
62
64
|
mintedAmount: bigint,
|
|
63
65
|
sysParams: SystemParams,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
cdpCreator: UtxoOrOutRef,
|
|
67
|
+
iasset: UtxoOrOutRef,
|
|
68
|
+
priceOracle: UtxoOrOutRef,
|
|
69
|
+
interestOracle: UtxoOrOutRef,
|
|
70
|
+
collector: UtxoOrOutRef,
|
|
69
71
|
lucid: LucidEvolution,
|
|
70
72
|
currentSlot: number,
|
|
71
73
|
): Promise<TxBuilder> {
|
|
@@ -99,33 +101,37 @@ export async function openCdp(
|
|
|
99
101
|
(_) => new Error('Expected a single iasset token policy Ref Script UTXO'),
|
|
100
102
|
);
|
|
101
103
|
|
|
102
|
-
const iassetUtxo =
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
const iassetUtxo = await resolveUtxo(
|
|
105
|
+
iasset,
|
|
106
|
+
lucid,
|
|
107
|
+
'Expected a single iasset UTXO',
|
|
105
108
|
);
|
|
106
109
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
107
110
|
getInlineDatumOrThrow(iassetUtxo),
|
|
108
111
|
);
|
|
109
112
|
|
|
110
|
-
const priceOracleUtxo =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
114
|
+
priceOracle,
|
|
115
|
+
lucid,
|
|
116
|
+
'Expected a single price oracle UTXO',
|
|
113
117
|
);
|
|
114
118
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
115
119
|
getInlineDatumOrThrow(priceOracleUtxo),
|
|
116
120
|
);
|
|
117
121
|
|
|
118
|
-
const interestOracleUtxo =
|
|
119
|
-
|
|
120
|
-
|
|
122
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
123
|
+
interestOracle,
|
|
124
|
+
lucid,
|
|
125
|
+
'Expected a single interest oracle UTXO',
|
|
121
126
|
);
|
|
122
127
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
123
128
|
getInlineDatumOrThrow(interestOracleUtxo),
|
|
124
129
|
);
|
|
125
130
|
|
|
126
|
-
const cdpCreatorUtxo =
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
const cdpCreatorUtxo = await resolveUtxo(
|
|
132
|
+
cdpCreator,
|
|
133
|
+
lucid,
|
|
134
|
+
'Expected a single CDP creator UTXO',
|
|
129
135
|
);
|
|
130
136
|
|
|
131
137
|
match(iassetDatum.price)
|
|
@@ -212,7 +218,7 @@ export async function openCdp(
|
|
|
212
218
|
);
|
|
213
219
|
|
|
214
220
|
if (debtMintingFee > 0) {
|
|
215
|
-
await collectorFeeTx(debtMintingFee, lucid, sysParams, tx,
|
|
221
|
+
await collectorFeeTx(debtMintingFee, lucid, sysParams, tx, collector);
|
|
216
222
|
}
|
|
217
223
|
|
|
218
224
|
return tx;
|
|
@@ -221,13 +227,13 @@ export async function openCdp(
|
|
|
221
227
|
async function adjustCdp(
|
|
222
228
|
collateralAmount: bigint,
|
|
223
229
|
mintAmount: bigint,
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
230
|
+
cdp: UtxoOrOutRef,
|
|
231
|
+
iasset: UtxoOrOutRef,
|
|
232
|
+
priceOracle: UtxoOrOutRef,
|
|
233
|
+
interestOracle: UtxoOrOutRef,
|
|
234
|
+
collector: UtxoOrOutRef,
|
|
235
|
+
gov: UtxoOrOutRef,
|
|
236
|
+
treasury: UtxoOrOutRef,
|
|
231
237
|
sysParams: SystemParams,
|
|
232
238
|
lucid: LucidEvolution,
|
|
233
239
|
currentSlot: number,
|
|
@@ -242,37 +248,34 @@ async function adjustCdp(
|
|
|
242
248
|
(_) => new Error('Expected a single cdp Ref Script UTXO'),
|
|
243
249
|
);
|
|
244
250
|
|
|
245
|
-
const cdpUtxo =
|
|
246
|
-
await lucid.utxosByOutRef([cdpOref]),
|
|
247
|
-
(_) => new Error('Expected a single cdp UTXO'),
|
|
248
|
-
);
|
|
251
|
+
const cdpUtxo = await resolveUtxo(cdp, lucid, 'Expected a single cdp UTXO');
|
|
249
252
|
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(cdpUtxo));
|
|
250
253
|
|
|
251
|
-
const iassetUtxo =
|
|
252
|
-
|
|
253
|
-
|
|
254
|
+
const iassetUtxo = await resolveUtxo(
|
|
255
|
+
iasset,
|
|
256
|
+
lucid,
|
|
257
|
+
'Expected a single iasset UTXO',
|
|
254
258
|
);
|
|
255
259
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
256
260
|
getInlineDatumOrThrow(iassetUtxo),
|
|
257
261
|
);
|
|
258
262
|
|
|
259
|
-
const govUtxo =
|
|
260
|
-
await lucid.utxosByOutRef([govOref]),
|
|
261
|
-
(_) => new Error('Expected a single gov UTXO'),
|
|
262
|
-
);
|
|
263
|
+
const govUtxo = await resolveUtxo(gov, lucid, 'Expected a single gov UTXO');
|
|
263
264
|
const govDatum = parseGovDatumOrThrow(getInlineDatumOrThrow(govUtxo));
|
|
264
265
|
|
|
265
|
-
const priceOracleUtxo =
|
|
266
|
-
|
|
267
|
-
|
|
266
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
267
|
+
priceOracle,
|
|
268
|
+
lucid,
|
|
269
|
+
'Expected a single price oracle UTXO',
|
|
268
270
|
);
|
|
269
271
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
270
272
|
getInlineDatumOrThrow(priceOracleUtxo),
|
|
271
273
|
);
|
|
272
274
|
|
|
273
|
-
const interestOracleUtxo =
|
|
274
|
-
|
|
275
|
-
|
|
275
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
276
|
+
interestOracle,
|
|
277
|
+
lucid,
|
|
278
|
+
'Expected a single interest oracle UTXO',
|
|
276
279
|
);
|
|
277
280
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
278
281
|
getInlineDatumOrThrow(interestOracleUtxo),
|
|
@@ -388,13 +391,7 @@ async function adjustCdp(
|
|
|
388
391
|
const interestTreasuryAdaAmt = interestAdaAmt - interestCollectorAdaAmt;
|
|
389
392
|
|
|
390
393
|
if (interestTreasuryAdaAmt > 0) {
|
|
391
|
-
await treasuryFeeTx(
|
|
392
|
-
interestTreasuryAdaAmt,
|
|
393
|
-
lucid,
|
|
394
|
-
sysParams,
|
|
395
|
-
tx,
|
|
396
|
-
treasuryOref,
|
|
397
|
-
);
|
|
394
|
+
await treasuryFeeTx(interestTreasuryAdaAmt, lucid, sysParams, tx, treasury);
|
|
398
395
|
}
|
|
399
396
|
|
|
400
397
|
let collectorFee = interestCollectorAdaAmt;
|
|
@@ -416,7 +413,7 @@ async function adjustCdp(
|
|
|
416
413
|
}
|
|
417
414
|
|
|
418
415
|
if (collectorFee > 0n) {
|
|
419
|
-
await collectorFeeTx(collectorFee, lucid, sysParams, tx,
|
|
416
|
+
await collectorFeeTx(collectorFee, lucid, sysParams, tx, collector);
|
|
420
417
|
}
|
|
421
418
|
|
|
422
419
|
return tx;
|
|
@@ -424,13 +421,13 @@ async function adjustCdp(
|
|
|
424
421
|
|
|
425
422
|
export async function depositCdp(
|
|
426
423
|
amount: bigint,
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
424
|
+
cdp: UtxoOrOutRef,
|
|
425
|
+
iasset: UtxoOrOutRef,
|
|
426
|
+
priceOracle: UtxoOrOutRef,
|
|
427
|
+
interestOracle: UtxoOrOutRef,
|
|
428
|
+
collector: UtxoOrOutRef,
|
|
429
|
+
gov: UtxoOrOutRef,
|
|
430
|
+
treasury: UtxoOrOutRef,
|
|
434
431
|
params: SystemParams,
|
|
435
432
|
lucid: LucidEvolution,
|
|
436
433
|
currentSlot: number,
|
|
@@ -438,13 +435,13 @@ export async function depositCdp(
|
|
|
438
435
|
return adjustCdp(
|
|
439
436
|
amount,
|
|
440
437
|
0n,
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
438
|
+
cdp,
|
|
439
|
+
iasset,
|
|
440
|
+
priceOracle,
|
|
441
|
+
interestOracle,
|
|
442
|
+
collector,
|
|
443
|
+
gov,
|
|
444
|
+
treasury,
|
|
448
445
|
params,
|
|
449
446
|
lucid,
|
|
450
447
|
currentSlot,
|
|
@@ -453,13 +450,13 @@ export async function depositCdp(
|
|
|
453
450
|
|
|
454
451
|
export async function withdrawCdp(
|
|
455
452
|
amount: bigint,
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
453
|
+
cdp: UtxoOrOutRef,
|
|
454
|
+
iasset: UtxoOrOutRef,
|
|
455
|
+
priceOracle: UtxoOrOutRef,
|
|
456
|
+
interestOracle: UtxoOrOutRef,
|
|
457
|
+
collector: UtxoOrOutRef,
|
|
458
|
+
gov: UtxoOrOutRef,
|
|
459
|
+
treasury: UtxoOrOutRef,
|
|
463
460
|
params: SystemParams,
|
|
464
461
|
lucid: LucidEvolution,
|
|
465
462
|
currentSlot: number,
|
|
@@ -467,13 +464,13 @@ export async function withdrawCdp(
|
|
|
467
464
|
return adjustCdp(
|
|
468
465
|
-amount,
|
|
469
466
|
0n,
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
467
|
+
cdp,
|
|
468
|
+
iasset,
|
|
469
|
+
priceOracle,
|
|
470
|
+
interestOracle,
|
|
471
|
+
collector,
|
|
472
|
+
gov,
|
|
473
|
+
treasury,
|
|
477
474
|
params,
|
|
478
475
|
lucid,
|
|
479
476
|
currentSlot,
|
|
@@ -482,13 +479,13 @@ export async function withdrawCdp(
|
|
|
482
479
|
|
|
483
480
|
export async function mintCdp(
|
|
484
481
|
amount: bigint,
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
482
|
+
cdp: UtxoOrOutRef,
|
|
483
|
+
iasset: UtxoOrOutRef,
|
|
484
|
+
priceOracle: UtxoOrOutRef,
|
|
485
|
+
interestOracle: UtxoOrOutRef,
|
|
486
|
+
collector: UtxoOrOutRef,
|
|
487
|
+
gov: UtxoOrOutRef,
|
|
488
|
+
treasury: UtxoOrOutRef,
|
|
492
489
|
params: SystemParams,
|
|
493
490
|
lucid: LucidEvolution,
|
|
494
491
|
currentSlot: number,
|
|
@@ -496,13 +493,13 @@ export async function mintCdp(
|
|
|
496
493
|
return adjustCdp(
|
|
497
494
|
0n,
|
|
498
495
|
amount,
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
496
|
+
cdp,
|
|
497
|
+
iasset,
|
|
498
|
+
priceOracle,
|
|
499
|
+
interestOracle,
|
|
500
|
+
collector,
|
|
501
|
+
gov,
|
|
502
|
+
treasury,
|
|
506
503
|
params,
|
|
507
504
|
lucid,
|
|
508
505
|
currentSlot,
|
|
@@ -511,13 +508,13 @@ export async function mintCdp(
|
|
|
511
508
|
|
|
512
509
|
export async function burnCdp(
|
|
513
510
|
amount: bigint,
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
511
|
+
cdp: UtxoOrOutRef,
|
|
512
|
+
iasset: UtxoOrOutRef,
|
|
513
|
+
priceOracle: UtxoOrOutRef,
|
|
514
|
+
interestOracle: UtxoOrOutRef,
|
|
515
|
+
collector: UtxoOrOutRef,
|
|
516
|
+
gov: UtxoOrOutRef,
|
|
517
|
+
treasury: UtxoOrOutRef,
|
|
521
518
|
params: SystemParams,
|
|
522
519
|
lucid: LucidEvolution,
|
|
523
520
|
currentSlot: number,
|
|
@@ -525,13 +522,13 @@ export async function burnCdp(
|
|
|
525
522
|
return adjustCdp(
|
|
526
523
|
0n,
|
|
527
524
|
-amount,
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
525
|
+
cdp,
|
|
526
|
+
iasset,
|
|
527
|
+
priceOracle,
|
|
528
|
+
interestOracle,
|
|
529
|
+
collector,
|
|
530
|
+
gov,
|
|
531
|
+
treasury,
|
|
535
532
|
params,
|
|
536
533
|
lucid,
|
|
537
534
|
currentSlot,
|
|
@@ -539,13 +536,13 @@ export async function burnCdp(
|
|
|
539
536
|
}
|
|
540
537
|
|
|
541
538
|
export async function closeCdp(
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
539
|
+
cdp: UtxoOrOutRef,
|
|
540
|
+
iasset: UtxoOrOutRef,
|
|
541
|
+
priceOracle: UtxoOrOutRef,
|
|
542
|
+
interestOracle: UtxoOrOutRef,
|
|
543
|
+
collector: UtxoOrOutRef,
|
|
544
|
+
gov: UtxoOrOutRef,
|
|
545
|
+
treasury: UtxoOrOutRef,
|
|
549
546
|
sysParams: SystemParams,
|
|
550
547
|
lucid: LucidEvolution,
|
|
551
548
|
currentSlot: number,
|
|
@@ -578,37 +575,34 @@ export async function closeCdp(
|
|
|
578
575
|
(_) => new Error('Expected a single iasset token policy Ref Script UTXO'),
|
|
579
576
|
);
|
|
580
577
|
|
|
581
|
-
const cdpUtxo =
|
|
582
|
-
await lucid.utxosByOutRef([cdpOref]),
|
|
583
|
-
(_) => new Error('Expected a single cdp UTXO'),
|
|
584
|
-
);
|
|
578
|
+
const cdpUtxo = await resolveUtxo(cdp, lucid, 'Expected a single cdp UTXO');
|
|
585
579
|
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(cdpUtxo));
|
|
586
580
|
|
|
587
|
-
const iassetUtxo =
|
|
588
|
-
|
|
589
|
-
|
|
581
|
+
const iassetUtxo = await resolveUtxo(
|
|
582
|
+
iasset,
|
|
583
|
+
lucid,
|
|
584
|
+
'Expected a single iasset UTXO',
|
|
590
585
|
);
|
|
591
586
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
592
587
|
getInlineDatumOrThrow(iassetUtxo),
|
|
593
588
|
);
|
|
594
589
|
|
|
595
|
-
const govUtxo =
|
|
596
|
-
await lucid.utxosByOutRef([govOref]),
|
|
597
|
-
(_) => new Error('Expected a single gov UTXO'),
|
|
598
|
-
);
|
|
590
|
+
const govUtxo = await resolveUtxo(gov, lucid, 'Expected a single gov UTXO');
|
|
599
591
|
const govDatum = parseGovDatumOrThrow(getInlineDatumOrThrow(govUtxo));
|
|
600
592
|
|
|
601
|
-
const priceOracleUtxo =
|
|
602
|
-
|
|
603
|
-
|
|
593
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
594
|
+
priceOracle,
|
|
595
|
+
lucid,
|
|
596
|
+
'Expected a single price oracle UTXO',
|
|
604
597
|
);
|
|
605
598
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
606
599
|
getInlineDatumOrThrow(priceOracleUtxo),
|
|
607
600
|
);
|
|
608
601
|
|
|
609
|
-
const interestOracleUtxo =
|
|
610
|
-
|
|
611
|
-
|
|
602
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
603
|
+
interestOracle,
|
|
604
|
+
lucid,
|
|
605
|
+
'Expected a single interest oracle UTXO',
|
|
612
606
|
);
|
|
613
607
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
614
608
|
getInlineDatumOrThrow(interestOracleUtxo),
|
|
@@ -683,13 +677,7 @@ export async function closeCdp(
|
|
|
683
677
|
const interestTreasuryAdaAmt = interestAdaAmt - interestCollectorAdaAmt;
|
|
684
678
|
|
|
685
679
|
if (interestTreasuryAdaAmt > 0) {
|
|
686
|
-
await treasuryFeeTx(
|
|
687
|
-
interestTreasuryAdaAmt,
|
|
688
|
-
lucid,
|
|
689
|
-
sysParams,
|
|
690
|
-
tx,
|
|
691
|
-
treasuryOref,
|
|
692
|
-
);
|
|
680
|
+
await treasuryFeeTx(interestTreasuryAdaAmt, lucid, sysParams, tx, treasury);
|
|
693
681
|
}
|
|
694
682
|
|
|
695
683
|
const collectorFee =
|
|
@@ -700,7 +688,7 @@ export async function closeCdp(
|
|
|
700
688
|
);
|
|
701
689
|
|
|
702
690
|
if (collectorFee > 0n) {
|
|
703
|
-
await collectorFeeTx(collectorFee, lucid, sysParams, tx,
|
|
691
|
+
await collectorFeeTx(collectorFee, lucid, sysParams, tx, collector);
|
|
704
692
|
}
|
|
705
693
|
|
|
706
694
|
return tx;
|
|
@@ -712,12 +700,12 @@ export async function redeemCdp(
|
|
|
712
700
|
* The logic will automatically cap the amount to the max.
|
|
713
701
|
*/
|
|
714
702
|
attemptedRedemptionIAssetAmt: bigint,
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
703
|
+
cdp: UtxoOrOutRef,
|
|
704
|
+
iasset: UtxoOrOutRef,
|
|
705
|
+
priceOracle: UtxoOrOutRef,
|
|
706
|
+
interestOracle: UtxoOrOutRef,
|
|
707
|
+
collector: UtxoOrOutRef,
|
|
708
|
+
treasury: UtxoOrOutRef,
|
|
721
709
|
sysParams: SystemParams,
|
|
722
710
|
lucid: LucidEvolution,
|
|
723
711
|
currentSlot: number,
|
|
@@ -741,31 +729,31 @@ export async function redeemCdp(
|
|
|
741
729
|
(_) => new Error('Expected a single iasset token policy Ref Script UTXO'),
|
|
742
730
|
);
|
|
743
731
|
|
|
744
|
-
const cdpUtxo =
|
|
745
|
-
await lucid.utxosByOutRef([cdpOref]),
|
|
746
|
-
(_) => new Error('Expected a single cdp UTXO'),
|
|
747
|
-
);
|
|
732
|
+
const cdpUtxo = await resolveUtxo(cdp, lucid, 'Expected a single cdp UTXO');
|
|
748
733
|
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(cdpUtxo));
|
|
749
734
|
|
|
750
|
-
const iassetUtxo =
|
|
751
|
-
|
|
752
|
-
|
|
735
|
+
const iassetUtxo = await resolveUtxo(
|
|
736
|
+
iasset,
|
|
737
|
+
lucid,
|
|
738
|
+
'Expected a single iasset UTXO',
|
|
753
739
|
);
|
|
754
740
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
755
741
|
getInlineDatumOrThrow(iassetUtxo),
|
|
756
742
|
);
|
|
757
743
|
|
|
758
|
-
const priceOracleUtxo =
|
|
759
|
-
|
|
760
|
-
|
|
744
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
745
|
+
priceOracle,
|
|
746
|
+
lucid,
|
|
747
|
+
'Expected a single price oracle UTXO',
|
|
761
748
|
);
|
|
762
749
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
763
750
|
getInlineDatumOrThrow(priceOracleUtxo),
|
|
764
751
|
);
|
|
765
752
|
|
|
766
|
-
const interestOracleUtxo =
|
|
767
|
-
|
|
768
|
-
|
|
753
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
754
|
+
interestOracle,
|
|
755
|
+
lucid,
|
|
756
|
+
'Expected a single interest oracle UTXO',
|
|
769
757
|
);
|
|
770
758
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
771
759
|
getInlineDatumOrThrow(interestOracleUtxo),
|
|
@@ -902,25 +890,19 @@ export async function redeemCdp(
|
|
|
902
890
|
lucid,
|
|
903
891
|
sysParams,
|
|
904
892
|
tx,
|
|
905
|
-
|
|
893
|
+
collector,
|
|
906
894
|
);
|
|
907
895
|
|
|
908
|
-
await treasuryFeeTx(
|
|
909
|
-
interestTreasuryAdaAmt,
|
|
910
|
-
lucid,
|
|
911
|
-
sysParams,
|
|
912
|
-
tx,
|
|
913
|
-
treasuryOref,
|
|
914
|
-
);
|
|
896
|
+
await treasuryFeeTx(interestTreasuryAdaAmt, lucid, sysParams, tx, treasury);
|
|
915
897
|
|
|
916
898
|
return tx;
|
|
917
899
|
}
|
|
918
900
|
|
|
919
901
|
export async function freezeCdp(
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
902
|
+
cdp: UtxoOrOutRef,
|
|
903
|
+
iasset: UtxoOrOutRef,
|
|
904
|
+
priceOracle: UtxoOrOutRef,
|
|
905
|
+
interestOracle: UtxoOrOutRef,
|
|
924
906
|
sysParams: SystemParams,
|
|
925
907
|
lucid: LucidEvolution,
|
|
926
908
|
currentSlot: number,
|
|
@@ -934,31 +916,31 @@ export async function freezeCdp(
|
|
|
934
916
|
]),
|
|
935
917
|
(_) => new Error('Expected a single cdp Ref Script UTXO'),
|
|
936
918
|
);
|
|
937
|
-
const cdpUtxo =
|
|
938
|
-
await lucid.utxosByOutRef([cdpOref]),
|
|
939
|
-
(_) => new Error('Expected a single cdp UTXO'),
|
|
940
|
-
);
|
|
919
|
+
const cdpUtxo = await resolveUtxo(cdp, lucid, 'Expected a single cdp UTXO');
|
|
941
920
|
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(cdpUtxo));
|
|
942
921
|
|
|
943
|
-
const iassetUtxo =
|
|
944
|
-
|
|
945
|
-
|
|
922
|
+
const iassetUtxo = await resolveUtxo(
|
|
923
|
+
iasset,
|
|
924
|
+
lucid,
|
|
925
|
+
'Expected a single iasset UTXO',
|
|
946
926
|
);
|
|
947
927
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
948
928
|
getInlineDatumOrThrow(iassetUtxo),
|
|
949
929
|
);
|
|
950
930
|
|
|
951
|
-
const priceOracleUtxo =
|
|
952
|
-
|
|
953
|
-
|
|
931
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
932
|
+
priceOracle,
|
|
933
|
+
lucid,
|
|
934
|
+
'Expected a single price oracle UTXO',
|
|
954
935
|
);
|
|
955
936
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
956
937
|
getInlineDatumOrThrow(priceOracleUtxo),
|
|
957
938
|
);
|
|
958
939
|
|
|
959
|
-
const interestOracleUtxo =
|
|
960
|
-
|
|
961
|
-
|
|
940
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
941
|
+
interestOracle,
|
|
942
|
+
lucid,
|
|
943
|
+
'Expected a single interest oracle UTXO',
|
|
962
944
|
);
|
|
963
945
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
964
946
|
getInlineDatumOrThrow(interestOracleUtxo),
|
|
@@ -1061,10 +1043,10 @@ export async function freezeCdp(
|
|
|
1061
1043
|
}
|
|
1062
1044
|
|
|
1063
1045
|
export async function liquidateCdp(
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1046
|
+
cdp: UtxoOrOutRef,
|
|
1047
|
+
stabilityPool: UtxoOrOutRef,
|
|
1048
|
+
collector: UtxoOrOutRef,
|
|
1049
|
+
treasury: UtxoOrOutRef,
|
|
1068
1050
|
sysParams: SystemParams,
|
|
1069
1051
|
lucid: LucidEvolution,
|
|
1070
1052
|
): Promise<TxBuilder> {
|
|
@@ -1099,15 +1081,13 @@ export async function liquidateCdp(
|
|
|
1099
1081
|
(_) => new Error('Expected a single cdp auth token policy Ref Script UTXO'),
|
|
1100
1082
|
);
|
|
1101
1083
|
|
|
1102
|
-
const cdpUtxo =
|
|
1103
|
-
await lucid.utxosByOutRef([cdpOref]),
|
|
1104
|
-
(_) => new Error('Expected a single cdp UTXO'),
|
|
1105
|
-
);
|
|
1084
|
+
const cdpUtxo = await resolveUtxo(cdp, lucid, 'Expected a single cdp UTXO');
|
|
1106
1085
|
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(cdpUtxo));
|
|
1107
1086
|
|
|
1108
|
-
const spUtxo =
|
|
1109
|
-
|
|
1110
|
-
|
|
1087
|
+
const spUtxo = await resolveUtxo(
|
|
1088
|
+
stabilityPool,
|
|
1089
|
+
lucid,
|
|
1090
|
+
'Expected a single stability pool UTXO',
|
|
1111
1091
|
);
|
|
1112
1092
|
const spDatum = parseStabilityPoolDatum(getInlineDatumOrThrow(spUtxo));
|
|
1113
1093
|
|
|
@@ -1198,15 +1178,9 @@ export async function liquidateCdp(
|
|
|
1198
1178
|
);
|
|
1199
1179
|
}
|
|
1200
1180
|
|
|
1201
|
-
await collectorFeeTx(
|
|
1202
|
-
lovelacesForCollector,
|
|
1203
|
-
lucid,
|
|
1204
|
-
sysParams,
|
|
1205
|
-
tx,
|
|
1206
|
-
collectorOref,
|
|
1207
|
-
);
|
|
1181
|
+
await collectorFeeTx(lovelacesForCollector, lucid, sysParams, tx, collector);
|
|
1208
1182
|
|
|
1209
|
-
await treasuryFeeTx(lovelacesForTreasury, lucid, sysParams, tx,
|
|
1183
|
+
await treasuryFeeTx(lovelacesForTreasury, lucid, sysParams, tx, treasury);
|
|
1210
1184
|
|
|
1211
1185
|
return tx;
|
|
1212
1186
|
}
|