@argonprotocol/mainchain 1.4.3-dev.5e4d8d6a → 1.4.3-dev.6de0a801

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/browser/index.js CHANGED
@@ -609,6 +609,21 @@ var Vault = class _Vault {
609
609
  availableSecuritization() {
610
610
  return this.securitization - this.securitizationLocked;
611
611
  }
612
+ availableBondSpace(priceIndex, bondLots, bondFullCapacityPerFrame) {
613
+ if (this.securitizedSatoshis <= 0) return 0n;
614
+ const microgonsPerBond = BigInt(MICROGONS_PER_ARGON);
615
+ const totalBondCapacityMicrogons = priceIndex.getSatoshiPriceInTargetMicrogons(
616
+ BigInt(this.securitizedSatoshis)
617
+ );
618
+ const capacityMicrogons = bondFullCapacityPerFrame ? totalBondCapacityMicrogons : totalBondCapacityMicrogons / 10n;
619
+ const bondCapacity = Number(capacityMicrogons / microgonsPerBond);
620
+ const activeBonds = [...bondLots ?? []].reduce(
621
+ (sum, bondLot) => sum + bondLot.activeBonds,
622
+ 0
623
+ );
624
+ const availableBonds = activeBonds < bondCapacity ? bondCapacity - activeBonds : 0;
625
+ return BigInt(availableBonds) * microgonsPerBond;
626
+ }
612
627
  getRelockCapacity() {
613
628
  return [...this.securitizationReleaseSchedule.values()].reduce((acc, val) => acc + val, 0n);
614
629
  }
@@ -1057,20 +1072,22 @@ var BitcoinLock = class _BitcoinLock {
1057
1072
  if (maxMicrogonsAtTarget !== void 0 && maxMicrogonsAtTarget < btcMicrogonsAtTarget) {
1058
1073
  price = maxMicrogonsAtTarget;
1059
1074
  }
1075
+ const multiplierBn = this.redemptionMultiplierBn(priceIndex);
1076
+ return BigInt(
1077
+ new BigNumber4__default(price.toString()).times(multiplierBn).integerValue(BigNumber4__default.ROUND_DOWN).toFixed(0)
1078
+ );
1079
+ }
1080
+ static redemptionMultiplierBn(priceIndex) {
1060
1081
  const r = priceIndex.rValue;
1061
- let multiplier;
1062
1082
  if (r.gte(1)) {
1063
- multiplier = new BigNumber4__default(1);
1083
+ return new BigNumber4__default(1);
1064
1084
  } else if (r.gte(0.9)) {
1065
- multiplier = new BigNumber4__default(20).times(r.pow(2)).minus(new BigNumber4__default(38).times(r)).plus(19);
1085
+ return new BigNumber4__default(20).times(r.pow(2)).minus(new BigNumber4__default(38).times(r)).plus(19);
1066
1086
  } else if (r.gte(0.01)) {
1067
- multiplier = new BigNumber4__default(0.5618).times(r).plus(0.3944).div(r);
1087
+ return new BigNumber4__default(0.5618).times(r).plus(0.3944).div(r);
1068
1088
  } else {
1069
- multiplier = new BigNumber4__default(1).div(r).times(new BigNumber4__default(0.576).times(r).plus(0.4));
1089
+ return new BigNumber4__default(1).div(r).times(new BigNumber4__default(0.576).times(r).plus(0.4));
1070
1090
  }
1071
- return BigInt(
1072
- new BigNumber4__default(price.toString()).times(multiplier).integerValue(BigNumber4__default.ROUND_DOWN).toFixed(0)
1073
- );
1074
1091
  }
1075
1092
  static async getConfig(client) {
1076
1093
  const bitcoinNetwork = await client.query.bitcoinUtxos.bitcoinNetwork();
@@ -1308,9 +1325,26 @@ var BitcoinLock = class _BitcoinLock {
1308
1325
  }
1309
1326
  return { lock, createdAtHeight: blockHeight, txResult };
1310
1327
  }
1311
- static async requiredSatoshisForArgonLiquidity(priceIndex, argonAmount) {
1312
- const marketRatePerBitcoin = priceIndex.getSatoshiPriceInMarketMicrogons(SATS_PER_BTC);
1313
- return argonAmount * SATS_PER_BTC / marketRatePerBitcoin;
1328
+ static satoshisRequiredForRedemptionAmount(priceIndex, redemptionAmount) {
1329
+ if (redemptionAmount <= 0n) return 0n;
1330
+ const multiplierBn = this.redemptionMultiplierBn(priceIndex);
1331
+ const targetMicrogonsPerBtc = priceIndex.getSatoshiPriceInTargetMicrogons(SATS_PER_BTC);
1332
+ let requiredTargetMicrogons = BigInt(
1333
+ new BigNumber4__default(redemptionAmount.toString()).div(multiplierBn).integerValue(BigNumber4__default.ROUND_CEIL).toFixed(0)
1334
+ );
1335
+ while (this.calculateRedemptionAmount(priceIndex, requiredTargetMicrogons) < redemptionAmount) {
1336
+ requiredTargetMicrogons += 1n;
1337
+ }
1338
+ let satoshis = BigInt(
1339
+ new BigNumber4__default(requiredTargetMicrogons.toString()).times(SATS_PER_BTC.toString()).div(targetMicrogonsPerBtc.toString()).integerValue(BigNumber4__default.ROUND_CEIL).toFixed(0)
1340
+ );
1341
+ while (this.calculateRedemptionAmountFromSatoshis(priceIndex, satoshis) < redemptionAmount) {
1342
+ satoshis += 1n;
1343
+ }
1344
+ while (satoshis > 0n && this.calculateRedemptionAmountFromSatoshis(priceIndex, satoshis - 1n) >= redemptionAmount) {
1345
+ satoshis -= 1n;
1346
+ }
1347
+ return satoshis;
1314
1348
  }
1315
1349
  };
1316
1350
  var SATS_PER_BTC2 = 100000000n;