@indigo-labs/indigo-sdk 0.1.13 → 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 CHANGED
@@ -1625,6 +1625,15 @@ var StabilityPoolContract = class {
1625
1625
  action: request
1626
1626
  }
1627
1627
  };
1628
+ const value = {
1629
+ lovelace: BigInt(
1630
+ params.stabilityPoolParams.requestCollateralLovelaces + params.stabilityPoolParams.accountAdjustmentFeeLovelaces
1631
+ ),
1632
+ [params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0, import_lucid17.fromText)(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n
1633
+ };
1634
+ if (amount > 0n) {
1635
+ value[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid17.fromText)(asset)] = amount;
1636
+ }
1628
1637
  return lucid.newTx().readFrom([stabilityPoolScriptRef]).collectFrom([accountUtxo], serialiseStabilityPoolRedeemer(redeemer)).pay.ToContract(
1629
1638
  (0, import_lucid17.credentialToAddress)(lucid.config().network, {
1630
1639
  hash: (0, import_lucid17.validatorToScriptHash)(
@@ -1640,13 +1649,7 @@ var StabilityPoolContract = class {
1640
1649
  }
1641
1650
  })
1642
1651
  },
1643
- {
1644
- lovelace: BigInt(
1645
- params.stabilityPoolParams.requestCollateralLovelaces + params.stabilityPoolParams.accountAdjustmentFeeLovelaces
1646
- ),
1647
- [params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0, import_lucid17.fromText)(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n,
1648
- [params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid17.fromText)(asset)]: amount
1649
- }
1652
+ value
1650
1653
  ).addSignerKey(pkh.hash);
1651
1654
  }
1652
1655
  static async closeAccount(accountUtxo, params, lucid) {
@@ -1830,7 +1833,7 @@ var StabilityPoolContract = class {
1830
1833
  );
1831
1834
  const isDepositOrRewardWithdrawal = amount > 0n;
1832
1835
  const bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);
1833
- const balanceChange = isDepositOrRewardWithdrawal ? amount : bigIntMax(amount, fromSPInteger(accountDatum.snapshot.depositVal));
1836
+ const balanceChange = isDepositOrRewardWithdrawal ? amount : bigIntMax(amount, -fromSPInteger(updatedAccountSnapshot.depositVal));
1834
1837
  const newAccountSnapshot = {
1835
1838
  ...updatedAccountSnapshot,
1836
1839
  depositVal: spAdd(
@@ -2814,7 +2817,7 @@ function serialiseLrpDatum(datum) {
2814
2817
  return import_lucid33.Data.to(datum, LRPDatum);
2815
2818
  }
2816
2819
  function serialiseLrpRedeemer(redeemer) {
2817
- return import_lucid33.Data.to(redeemer, LRPRedeemer);
2820
+ return import_lucid33.Data.to(redeemer, LRPRedeemer, { canonical: true });
2818
2821
  }
2819
2822
  function castLrpParams(params) {
2820
2823
  return import_lucid33.Data.castTo(params, LRPParams);
package/dist/index.mjs CHANGED
@@ -1504,6 +1504,15 @@ var StabilityPoolContract = class {
1504
1504
  action: request
1505
1505
  }
1506
1506
  };
1507
+ const value = {
1508
+ lovelace: BigInt(
1509
+ params.stabilityPoolParams.requestCollateralLovelaces + params.stabilityPoolParams.accountAdjustmentFeeLovelaces
1510
+ ),
1511
+ [params.stabilityPoolParams.accountToken[0].unCurrencySymbol + fromText6(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n
1512
+ };
1513
+ if (amount > 0n) {
1514
+ value[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + fromText6(asset)] = amount;
1515
+ }
1507
1516
  return lucid.newTx().readFrom([stabilityPoolScriptRef]).collectFrom([accountUtxo], serialiseStabilityPoolRedeemer(redeemer)).pay.ToContract(
1508
1517
  credentialToAddress4(lucid.config().network, {
1509
1518
  hash: validatorToScriptHash4(
@@ -1519,13 +1528,7 @@ var StabilityPoolContract = class {
1519
1528
  }
1520
1529
  })
1521
1530
  },
1522
- {
1523
- lovelace: BigInt(
1524
- params.stabilityPoolParams.requestCollateralLovelaces + params.stabilityPoolParams.accountAdjustmentFeeLovelaces
1525
- ),
1526
- [params.stabilityPoolParams.accountToken[0].unCurrencySymbol + fromText6(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n,
1527
- [params.stabilityPoolParams.assetSymbol.unCurrencySymbol + fromText6(asset)]: amount
1528
- }
1531
+ value
1529
1532
  ).addSignerKey(pkh.hash);
1530
1533
  }
1531
1534
  static async closeAccount(accountUtxo, params, lucid) {
@@ -1709,7 +1712,7 @@ var StabilityPoolContract = class {
1709
1712
  );
1710
1713
  const isDepositOrRewardWithdrawal = amount > 0n;
1711
1714
  const bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);
1712
- const balanceChange = isDepositOrRewardWithdrawal ? amount : bigIntMax(amount, fromSPInteger(accountDatum.snapshot.depositVal));
1715
+ const balanceChange = isDepositOrRewardWithdrawal ? amount : bigIntMax(amount, -fromSPInteger(updatedAccountSnapshot.depositVal));
1713
1716
  const newAccountSnapshot = {
1714
1717
  ...updatedAccountSnapshot,
1715
1718
  depositVal: spAdd(
@@ -2718,7 +2721,7 @@ function serialiseLrpDatum(datum) {
2718
2721
  return Data20.to(datum, LRPDatum);
2719
2722
  }
2720
2723
  function serialiseLrpRedeemer(redeemer) {
2721
- return Data20.to(redeemer, LRPRedeemer);
2724
+ return Data20.to(redeemer, LRPRedeemer, { canonical: true });
2722
2725
  }
2723
2726
  function castLrpParams(params) {
2724
2727
  return Data20.castTo(params, LRPParams);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigo-labs/indigo-sdk",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
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",
@@ -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,6 +125,22 @@ export class StabilityPoolContract {
124
125
  },
125
126
  };
126
127
 
128
+ const value = {
129
+ lovelace: BigInt(
130
+ params.stabilityPoolParams.requestCollateralLovelaces +
131
+ params.stabilityPoolParams.accountAdjustmentFeeLovelaces,
132
+ ),
133
+ [params.stabilityPoolParams.accountToken[0].unCurrencySymbol +
134
+ fromText(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n,
135
+ };
136
+
137
+ if (amount > 0n) {
138
+ value[
139
+ params.stabilityPoolParams.assetSymbol.unCurrencySymbol +
140
+ fromText(asset)
141
+ ] = amount;
142
+ }
143
+
127
144
  return lucid
128
145
  .newTx()
129
146
  .readFrom([stabilityPoolScriptRef])
@@ -143,16 +160,7 @@ export class StabilityPoolContract {
143
160
  },
144
161
  }),
145
162
  },
146
- {
147
- lovelace: BigInt(
148
- params.stabilityPoolParams.requestCollateralLovelaces +
149
- params.stabilityPoolParams.accountAdjustmentFeeLovelaces,
150
- ),
151
- [params.stabilityPoolParams.accountToken[0].unCurrencySymbol +
152
- fromText(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n,
153
- [params.stabilityPoolParams.assetSymbol.unCurrencySymbol +
154
- fromText(asset)]: amount,
155
- },
163
+ value,
156
164
  )
157
165
  .addSignerKey(pkh.hash);
158
166
  }
@@ -394,9 +402,10 @@ export class StabilityPoolContract {
394
402
  const isDepositOrRewardWithdrawal: boolean = amount > 0n;
395
403
  const bigIntMax = (...args: bigint[]): bigint =>
396
404
  args.reduce((m, e) => (e > m ? e : m));
405
+
397
406
  const balanceChange: bigint = isDepositOrRewardWithdrawal
398
407
  ? amount
399
- : bigIntMax(amount, fromSPInteger(accountDatum.snapshot.depositVal));
408
+ : bigIntMax(amount, -fromSPInteger(updatedAccountSnapshot.depositVal));
400
409
  const newAccountSnapshot: StabilityPoolSnapshot = {
401
410
  ...updatedAccountSnapshot,
402
411
  depositVal: spAdd(
@@ -463,7 +472,6 @@ export class StabilityPoolContract {
463
472
  await CollectorContract.feeTx(rewardLovelacesFee, lucid, params, tx);
464
473
 
465
474
  tx.readFrom([govUtxo, iAssetUtxo, ...refInputs]);
466
-
467
475
  tx.pay.ToContract(
468
476
  stabilityPoolUtxo.address,
469
477
  {
@@ -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 {
@@ -253,6 +253,62 @@ test<LucidContext>('Stability Pool - Adjust Account', async ({
253
253
  lucid,
254
254
  ),
255
255
  );
256
+
257
+ // Withdraw 10n iUSD from the stability pool account.
258
+ lucid.selectWallet.fromSeed(users.user.seedPhrase);
259
+
260
+ stabilityPoolUtxo = await findStabilityPool(
261
+ lucid,
262
+ systemParams.validatorHashes.stabilityPoolHash,
263
+ {
264
+ currencySymbol:
265
+ systemParams.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol,
266
+ tokenName: fromText(
267
+ systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
268
+ ),
269
+ },
270
+ 'iUSD',
271
+ );
272
+
273
+ accountUtxo = await findStabilityPoolAccount(
274
+ lucid,
275
+ systemParams.validatorHashes.stabilityPoolHash,
276
+ pkh.hash,
277
+ 'iUSD',
278
+ );
279
+
280
+ await runAndAwaitTx(
281
+ lucid,
282
+ StabilityPoolContract.adjustAccount(
283
+ 'iUSD',
284
+ -10n,
285
+ accountUtxo,
286
+ systemParams,
287
+ lucid,
288
+ ),
289
+ );
290
+ lucid.selectWallet.fromSeed(users.admin.seedPhrase);
291
+
292
+ accountUtxo = await findStabilityPoolAccount(
293
+ lucid,
294
+ systemParams.validatorHashes.stabilityPoolHash,
295
+ pkh.hash,
296
+ 'iUSD',
297
+ );
298
+
299
+ await runAndAwaitTx(
300
+ lucid,
301
+ StabilityPoolContract.processRequest(
302
+ 'iUSD',
303
+ stabilityPoolUtxo,
304
+ accountUtxo,
305
+ govUtxo,
306
+ assetUtxo,
307
+ undefined,
308
+ systemParams,
309
+ lucid,
310
+ ),
311
+ );
256
312
  });
257
313
 
258
314
  test<LucidContext>('Stability Pool - Close Account', async ({