@indigo-labs/indigo-sdk 0.1.14 → 0.1.15
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.js +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +1 -1
- package/src/contracts/stability-pool.ts +48 -44
- package/src/types/indigo/lrp.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1625,7 +1625,7 @@ var StabilityPoolContract = class {
|
|
|
1625
1625
|
action: request
|
|
1626
1626
|
}
|
|
1627
1627
|
};
|
|
1628
|
-
|
|
1628
|
+
const value = {
|
|
1629
1629
|
lovelace: BigInt(
|
|
1630
1630
|
params.stabilityPoolParams.requestCollateralLovelaces + params.stabilityPoolParams.accountAdjustmentFeeLovelaces
|
|
1631
1631
|
),
|
|
@@ -1833,7 +1833,7 @@ var StabilityPoolContract = class {
|
|
|
1833
1833
|
);
|
|
1834
1834
|
const isDepositOrRewardWithdrawal = amount > 0n;
|
|
1835
1835
|
const bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);
|
|
1836
|
-
const balanceChange = isDepositOrRewardWithdrawal ? amount : bigIntMax(amount, fromSPInteger(updatedAccountSnapshot.depositVal));
|
|
1836
|
+
const balanceChange = isDepositOrRewardWithdrawal ? amount : bigIntMax(amount, -fromSPInteger(updatedAccountSnapshot.depositVal));
|
|
1837
1837
|
const newAccountSnapshot = {
|
|
1838
1838
|
...updatedAccountSnapshot,
|
|
1839
1839
|
depositVal: spAdd(
|
|
@@ -2817,7 +2817,7 @@ function serialiseLrpDatum(datum) {
|
|
|
2817
2817
|
return import_lucid33.Data.to(datum, LRPDatum);
|
|
2818
2818
|
}
|
|
2819
2819
|
function serialiseLrpRedeemer(redeemer) {
|
|
2820
|
-
return import_lucid33.Data.to(redeemer, LRPRedeemer);
|
|
2820
|
+
return import_lucid33.Data.to(redeemer, LRPRedeemer, { canonical: true });
|
|
2821
2821
|
}
|
|
2822
2822
|
function castLrpParams(params) {
|
|
2823
2823
|
return import_lucid33.Data.castTo(params, LRPParams);
|
package/dist/index.mjs
CHANGED
|
@@ -1504,7 +1504,7 @@ var StabilityPoolContract = class {
|
|
|
1504
1504
|
action: request
|
|
1505
1505
|
}
|
|
1506
1506
|
};
|
|
1507
|
-
|
|
1507
|
+
const value = {
|
|
1508
1508
|
lovelace: BigInt(
|
|
1509
1509
|
params.stabilityPoolParams.requestCollateralLovelaces + params.stabilityPoolParams.accountAdjustmentFeeLovelaces
|
|
1510
1510
|
),
|
|
@@ -1712,7 +1712,7 @@ var StabilityPoolContract = class {
|
|
|
1712
1712
|
);
|
|
1713
1713
|
const isDepositOrRewardWithdrawal = amount > 0n;
|
|
1714
1714
|
const bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);
|
|
1715
|
-
const balanceChange = isDepositOrRewardWithdrawal ? amount : bigIntMax(amount, fromSPInteger(updatedAccountSnapshot.depositVal));
|
|
1715
|
+
const balanceChange = isDepositOrRewardWithdrawal ? amount : bigIntMax(amount, -fromSPInteger(updatedAccountSnapshot.depositVal));
|
|
1716
1716
|
const newAccountSnapshot = {
|
|
1717
1717
|
...updatedAccountSnapshot,
|
|
1718
1718
|
depositVal: spAdd(
|
|
@@ -2721,7 +2721,7 @@ function serialiseLrpDatum(datum) {
|
|
|
2721
2721
|
return Data20.to(datum, LRPDatum);
|
|
2722
2722
|
}
|
|
2723
2723
|
function serialiseLrpRedeemer(redeemer) {
|
|
2724
|
-
return Data20.to(redeemer, LRPRedeemer);
|
|
2724
|
+
return Data20.to(redeemer, LRPRedeemer, { canonical: true });
|
|
2725
2725
|
}
|
|
2726
2726
|
function castLrpParams(params) {
|
|
2727
2727
|
return Data20.castTo(params, LRPParams);
|
package/package.json
CHANGED
|
@@ -51,7 +51,7 @@ export class StabilityPoolContract {
|
|
|
51
51
|
const [pkh, _skh] = await addrDetails(lucid);
|
|
52
52
|
const minLovelaces = BigInt(
|
|
53
53
|
params.stabilityPoolParams.accountCreateFeeLovelaces +
|
|
54
|
-
|
|
54
|
+
params.stabilityPoolParams.requestCollateralLovelaces,
|
|
55
55
|
);
|
|
56
56
|
const datum: StabilityPoolDatum = {
|
|
57
57
|
Account: {
|
|
@@ -83,7 +83,7 @@ export class StabilityPoolContract {
|
|
|
83
83
|
{
|
|
84
84
|
lovelace: minLovelaces,
|
|
85
85
|
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol +
|
|
86
|
-
|
|
86
|
+
fromText(asset)]: amount,
|
|
87
87
|
},
|
|
88
88
|
)
|
|
89
89
|
.addSignerKey(pkh.hash);
|
|
@@ -113,6 +113,7 @@ export class StabilityPoolContract {
|
|
|
113
113
|
const oldAccountDatum: AccountContent = parseAccountDatum(
|
|
114
114
|
accountUtxo.datum,
|
|
115
115
|
);
|
|
116
|
+
|
|
116
117
|
const newAccountDatum: AccountContent = {
|
|
117
118
|
...oldAccountDatum,
|
|
118
119
|
request,
|
|
@@ -124,17 +125,20 @@ export class StabilityPoolContract {
|
|
|
124
125
|
},
|
|
125
126
|
};
|
|
126
127
|
|
|
127
|
-
|
|
128
|
+
const value = {
|
|
128
129
|
lovelace: BigInt(
|
|
129
130
|
params.stabilityPoolParams.requestCollateralLovelaces +
|
|
130
|
-
|
|
131
|
+
params.stabilityPoolParams.accountAdjustmentFeeLovelaces,
|
|
131
132
|
),
|
|
132
133
|
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol +
|
|
133
|
-
|
|
134
|
+
fromText(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n,
|
|
134
135
|
};
|
|
135
136
|
|
|
136
137
|
if (amount > 0n) {
|
|
137
|
-
value[
|
|
138
|
+
value[
|
|
139
|
+
params.stabilityPoolParams.assetSymbol.unCurrencySymbol +
|
|
140
|
+
fromText(asset)
|
|
141
|
+
] = amount;
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
return lucid
|
|
@@ -156,7 +160,7 @@ export class StabilityPoolContract {
|
|
|
156
160
|
},
|
|
157
161
|
}),
|
|
158
162
|
},
|
|
159
|
-
value
|
|
163
|
+
value,
|
|
160
164
|
)
|
|
161
165
|
.addSignerKey(pkh.hash);
|
|
162
166
|
}
|
|
@@ -215,10 +219,10 @@ export class StabilityPoolContract {
|
|
|
215
219
|
{
|
|
216
220
|
lovelace: BigInt(
|
|
217
221
|
params.stabilityPoolParams.requestCollateralLovelaces +
|
|
218
|
-
|
|
222
|
+
params.stabilityPoolParams.accountAdjustmentFeeLovelaces,
|
|
219
223
|
),
|
|
220
224
|
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol +
|
|
221
|
-
|
|
225
|
+
fromText(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n,
|
|
222
226
|
},
|
|
223
227
|
)
|
|
224
228
|
.addSignerKey(pkh.hash);
|
|
@@ -320,16 +324,16 @@ export class StabilityPoolContract {
|
|
|
320
324
|
stabilityPoolUtxo.assets.lovelace +
|
|
321
325
|
BigInt(params.stabilityPoolParams.accountCreateFeeLovelaces),
|
|
322
326
|
[params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol +
|
|
323
|
-
|
|
327
|
+
fromText(params.stabilityPoolParams.stabilityPoolToken[1].unTokenName)]:
|
|
324
328
|
1n,
|
|
325
329
|
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol +
|
|
326
|
-
|
|
330
|
+
fromText(asset)]: stabilityPoolAssetToken + reqAmount,
|
|
327
331
|
};
|
|
328
332
|
|
|
329
333
|
tx.mintAssets(
|
|
330
334
|
{
|
|
331
335
|
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol +
|
|
332
|
-
|
|
336
|
+
fromText(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n,
|
|
333
337
|
},
|
|
334
338
|
Data.to(new Constr(0, [])),
|
|
335
339
|
);
|
|
@@ -370,7 +374,7 @@ export class StabilityPoolContract {
|
|
|
370
374
|
accountUtxo.assets.lovelace -
|
|
371
375
|
BigInt(params.stabilityPoolParams.accountCreateFeeLovelaces),
|
|
372
376
|
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol +
|
|
373
|
-
|
|
377
|
+
fromText(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n,
|
|
374
378
|
},
|
|
375
379
|
);
|
|
376
380
|
} else if ('Adjust' in accountDatum.request) {
|
|
@@ -401,7 +405,7 @@ export class StabilityPoolContract {
|
|
|
401
405
|
|
|
402
406
|
const balanceChange: bigint = isDepositOrRewardWithdrawal
|
|
403
407
|
? amount
|
|
404
|
-
: bigIntMax(amount, fromSPInteger(updatedAccountSnapshot.depositVal));
|
|
408
|
+
: bigIntMax(amount, -fromSPInteger(updatedAccountSnapshot.depositVal));
|
|
405
409
|
const newAccountSnapshot: StabilityPoolSnapshot = {
|
|
406
410
|
...updatedAccountSnapshot,
|
|
407
411
|
depositVal: spAdd(
|
|
@@ -423,9 +427,9 @@ export class StabilityPoolContract {
|
|
|
423
427
|
isDepositOrRewardWithdrawal || newPoolDepositExcludingFee.value === 0n
|
|
424
428
|
? 0n
|
|
425
429
|
: calculateFeeFromPercentage(
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
430
|
+
iassetDatum.stabilityPoolWithdrawalFeePercentage,
|
|
431
|
+
-balanceChange,
|
|
432
|
+
);
|
|
429
433
|
const newPoolDeposit = spAdd(
|
|
430
434
|
newPoolDepositExcludingFee,
|
|
431
435
|
mkSPInteger(withdrawalFee),
|
|
@@ -434,12 +438,12 @@ export class StabilityPoolContract {
|
|
|
434
438
|
withdrawalFee === 0n
|
|
435
439
|
? stabilityPoolDatum.snapshot.productVal
|
|
436
440
|
: spMul(
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
441
|
+
stabilityPoolDatum.snapshot.productVal,
|
|
442
|
+
spAdd(
|
|
443
|
+
mkSPInteger(1n),
|
|
444
|
+
spDiv(mkSPInteger(withdrawalFee), newPoolDepositExcludingFee),
|
|
445
|
+
),
|
|
446
|
+
);
|
|
443
447
|
const newPoolSum = spAdd(
|
|
444
448
|
stabilityPoolDatum.snapshot.sumVal,
|
|
445
449
|
spDiv(
|
|
@@ -488,14 +492,14 @@ export class StabilityPoolContract {
|
|
|
488
492
|
BigInt(params.stabilityPoolParams.accountAdjustmentFeeLovelaces) -
|
|
489
493
|
reward,
|
|
490
494
|
[params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol +
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
495
|
+
fromText(
|
|
496
|
+
params.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
|
|
497
|
+
)]: 1n,
|
|
494
498
|
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol +
|
|
495
|
-
|
|
499
|
+
fromText(asset)]:
|
|
496
500
|
stabilityPoolUtxo.assets[
|
|
497
|
-
|
|
498
|
-
|
|
501
|
+
params.stabilityPoolParams.assetSymbol.unCurrencySymbol +
|
|
502
|
+
fromText(asset)
|
|
499
503
|
] +
|
|
500
504
|
balanceChange +
|
|
501
505
|
withdrawalFee,
|
|
@@ -522,7 +526,7 @@ export class StabilityPoolContract {
|
|
|
522
526
|
BigInt(params.stabilityPoolParams.accountAdjustmentFeeLovelaces) -
|
|
523
527
|
2_000_000n,
|
|
524
528
|
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol +
|
|
525
|
-
|
|
529
|
+
fromText(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n,
|
|
526
530
|
},
|
|
527
531
|
);
|
|
528
532
|
|
|
@@ -547,9 +551,9 @@ export class StabilityPoolContract {
|
|
|
547
551
|
lovelace: reward - rewardLovelacesFee + 2_000_000n,
|
|
548
552
|
...(amount < 0n
|
|
549
553
|
? {
|
|
550
|
-
|
|
554
|
+
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol +
|
|
551
555
|
fromText(asset)]: -(amount - withdrawalFee),
|
|
552
|
-
|
|
556
|
+
}
|
|
553
557
|
: {}),
|
|
554
558
|
},
|
|
555
559
|
);
|
|
@@ -588,9 +592,9 @@ export class StabilityPoolContract {
|
|
|
588
592
|
newPoolDepositExcludingFee.value === 0n
|
|
589
593
|
? 0n
|
|
590
594
|
: calculateFeeFromPercentage(
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
595
|
+
iassetDatum.stabilityPoolWithdrawalFeePercentage,
|
|
596
|
+
withdrawnAmt.value,
|
|
597
|
+
);
|
|
594
598
|
|
|
595
599
|
const [newPoolDeposit, newPoolProduct] = updatePoolSnapshotWithdrawalFee(
|
|
596
600
|
mkSPInteger(withdrawalFeeAmount),
|
|
@@ -615,7 +619,7 @@ export class StabilityPoolContract {
|
|
|
615
619
|
tx.mintAssets(
|
|
616
620
|
{
|
|
617
621
|
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol +
|
|
618
|
-
|
|
622
|
+
fromText(params.stabilityPoolParams.accountToken[1].unTokenName)]:
|
|
619
623
|
-1n,
|
|
620
624
|
},
|
|
621
625
|
Data.to(new Constr(0, [])),
|
|
@@ -623,8 +627,8 @@ export class StabilityPoolContract {
|
|
|
623
627
|
|
|
624
628
|
const assetOutputAmountForSP =
|
|
625
629
|
stabilityPoolUtxo.assets[
|
|
626
|
-
|
|
627
|
-
|
|
630
|
+
params.stabilityPoolParams.assetSymbol.unCurrencySymbol +
|
|
631
|
+
fromText(asset)
|
|
628
632
|
] -
|
|
629
633
|
fromSPInteger(withdrawnAmt) -
|
|
630
634
|
withdrawalFeeAmount;
|
|
@@ -645,14 +649,14 @@ export class StabilityPoolContract {
|
|
|
645
649
|
{
|
|
646
650
|
lovelace: stabilityPoolUtxo.assets.lovelace - reward,
|
|
647
651
|
[params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol +
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
652
|
+
fromText(
|
|
653
|
+
params.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
|
|
654
|
+
)]: 1n,
|
|
651
655
|
...(assetOutputAmountForSP > 0n
|
|
652
656
|
? {
|
|
653
|
-
|
|
657
|
+
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol +
|
|
654
658
|
fromText(asset)]: assetOutputAmountForSP,
|
|
655
|
-
|
|
659
|
+
}
|
|
656
660
|
: {}),
|
|
657
661
|
},
|
|
658
662
|
);
|
|
@@ -677,7 +681,7 @@ export class StabilityPoolContract {
|
|
|
677
681
|
{
|
|
678
682
|
lovelace: accountUtxo.assets.lovelace + reward - rewardLovelacesFee,
|
|
679
683
|
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol +
|
|
680
|
-
|
|
684
|
+
fromText(asset)]: fromSPInteger(withdrawnAmt) - withdrawalFeeAmount,
|
|
681
685
|
},
|
|
682
686
|
);
|
|
683
687
|
}
|
package/src/types/indigo/lrp.ts
CHANGED
|
@@ -51,7 +51,7 @@ export function serialiseLrpDatum(datum: LRPDatum): Datum {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export function serialiseLrpRedeemer(redeemer: LRPRedeemer): Redeemer {
|
|
54
|
-
return Data.to<LRPRedeemer>(redeemer, LRPRedeemer);
|
|
54
|
+
return Data.to<LRPRedeemer>(redeemer, LRPRedeemer, {canonical: true});
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export function castLrpParams(params: LRPParams): Data {
|