@argonprotocol/mainchain 1.3.3 → 1.3.4
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.d.ts +17 -9
- package/browser/index.js +54 -43
- package/browser/index.js.map +1 -1
- package/lib/{chunk-IQ3TNLS7.cjs → chunk-LB6BAURC.cjs} +52 -52
- package/lib/{chunk-IQ3TNLS7.cjs.map → chunk-LB6BAURC.cjs.map} +1 -1
- package/lib/{chunk-FCT7GMFN.js → chunk-P3OMJABP.js} +60 -49
- package/lib/{chunk-FCT7GMFN.js.map → chunk-P3OMJABP.js.map} +1 -1
- package/lib/{chunk-UZCZ347U.js → chunk-QVXW4O7X.js} +3 -3
- package/lib/chunk-QVXW4O7X.js.map +1 -0
- package/lib/{chunk-OFYVHBKG.cjs → chunk-W5SOPU7I.cjs} +115 -104
- package/lib/chunk-W5SOPU7I.cjs.map +1 -0
- package/lib/cli.cjs +6 -6
- package/lib/cli.js +2 -2
- package/lib/clis/index.cjs +3 -3
- package/lib/clis/index.js +2 -2
- package/lib/index.cjs +4 -2
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +17 -9
- package/lib/index.d.ts +17 -9
- package/lib/index.js +3 -1
- package/package.json +2 -2
- package/lib/chunk-OFYVHBKG.cjs.map +0 -1
- package/lib/chunk-UZCZ347U.js.map +0 -1
|
@@ -123,20 +123,21 @@ var TxSubmitter = class {
|
|
|
123
123
|
const { tip, unavailableBalance } = options;
|
|
124
124
|
const account = await this.client.query.system.account(this.pair.address);
|
|
125
125
|
let availableBalance = account.data.free.toBigInt();
|
|
126
|
+
const userBalance = availableBalance;
|
|
126
127
|
if (unavailableBalance) {
|
|
127
128
|
availableBalance -= unavailableBalance;
|
|
128
129
|
}
|
|
129
130
|
const existentialDeposit = options.includeExistentialDeposit ? this.client.consts.balances.existentialDeposit.toBigInt() : 0n;
|
|
130
131
|
const fees = await this.feeEstimate(tip);
|
|
131
132
|
const totalCharge = fees + (tip ?? 0n);
|
|
132
|
-
const canAfford = availableBalance
|
|
133
|
-
return { canAfford, availableBalance, txFee: fees };
|
|
133
|
+
const canAfford = availableBalance >= totalCharge + existentialDeposit;
|
|
134
|
+
return { canAfford, availableBalance: userBalance, txFee: fees };
|
|
134
135
|
}
|
|
135
136
|
async submit(options = {}) {
|
|
136
137
|
const { logResults, waitForBlock, useLatestNonce, ...apiOptions } = options;
|
|
137
138
|
await waitForLoad();
|
|
138
139
|
const result = new TxResult(this.client, logResults);
|
|
139
|
-
result.
|
|
140
|
+
result.txProgressCallback = options.txProgressCallback;
|
|
140
141
|
let toHuman = this.tx.toHuman().method;
|
|
141
142
|
let txString = [];
|
|
142
143
|
let api = formatCall(toHuman);
|
|
@@ -202,7 +203,7 @@ var TxResult = class {
|
|
|
202
203
|
* The fee tip paid for the transaction.
|
|
203
204
|
*/
|
|
204
205
|
finalFeeTip;
|
|
205
|
-
|
|
206
|
+
txProgressCallback;
|
|
206
207
|
inBlockResolve;
|
|
207
208
|
inBlockReject;
|
|
208
209
|
finalizedResolve;
|
|
@@ -240,7 +241,15 @@ var TxResult = class {
|
|
|
240
241
|
if (isFinalized) {
|
|
241
242
|
this.finalizedResolve(status.asFinalized);
|
|
242
243
|
}
|
|
243
|
-
this.
|
|
244
|
+
if (this.txProgressCallback) {
|
|
245
|
+
let percent = 0;
|
|
246
|
+
if (result.status.isBroadcast) {
|
|
247
|
+
percent = 50;
|
|
248
|
+
} else if (result.status.isInBlock) {
|
|
249
|
+
percent = 100;
|
|
250
|
+
}
|
|
251
|
+
this.txProgressCallback(percent, this);
|
|
252
|
+
}
|
|
244
253
|
}
|
|
245
254
|
reject(error) {
|
|
246
255
|
this.inBlockReject(error);
|
|
@@ -250,7 +259,6 @@ var TxResult = class {
|
|
|
250
259
|
|
|
251
260
|
// src/utils.ts
|
|
252
261
|
import BigNumber, * as BN from "bignumber.js";
|
|
253
|
-
import { hexToU8a } from "@polkadot/util";
|
|
254
262
|
var { ROUND_FLOOR } = BN;
|
|
255
263
|
var MICROGONS_PER_ARGON = 1e6;
|
|
256
264
|
function formatArgons(x) {
|
|
@@ -400,7 +408,7 @@ var JsonExt = class {
|
|
|
400
408
|
return BigInt(v.slice(0, -1));
|
|
401
409
|
}
|
|
402
410
|
if (typeof v === "object" && v !== null && v.type === "Buffer" && Array.isArray(v.data)) {
|
|
403
|
-
return
|
|
411
|
+
return Uint8Array.from(v.data);
|
|
404
412
|
}
|
|
405
413
|
return v;
|
|
406
414
|
});
|
|
@@ -1292,21 +1300,21 @@ var MiningBids = class {
|
|
|
1292
1300
|
// src/Vault.ts
|
|
1293
1301
|
import BigNumber2, * as BN2 from "bignumber.js";
|
|
1294
1302
|
import bs58check from "bs58check";
|
|
1295
|
-
import { hexToU8a
|
|
1303
|
+
import { hexToU8a } from "@polkadot/util";
|
|
1296
1304
|
var { ROUND_FLOOR: ROUND_FLOOR2 } = BN2;
|
|
1297
1305
|
var Vault = class _Vault {
|
|
1298
1306
|
constructor(id, vault, tickDuration) {
|
|
1299
1307
|
this.tickDuration = tickDuration;
|
|
1300
1308
|
this.vaultId = id;
|
|
1301
|
-
this.load(vault);
|
|
1302
1309
|
this.openedTick = vault.openedTick.toNumber();
|
|
1303
1310
|
this.openedDate = new Date(this.openedTick * this.tickDuration);
|
|
1311
|
+
this.argonsScheduledForRelease = /* @__PURE__ */ new Map();
|
|
1312
|
+
this.load(vault);
|
|
1304
1313
|
}
|
|
1305
1314
|
securitization;
|
|
1306
|
-
securitizationRatio;
|
|
1307
1315
|
argonsLocked;
|
|
1308
1316
|
argonsPendingActivation;
|
|
1309
|
-
argonsScheduledForRelease
|
|
1317
|
+
argonsScheduledForRelease;
|
|
1310
1318
|
terms;
|
|
1311
1319
|
operatorAccountId;
|
|
1312
1320
|
isClosed;
|
|
@@ -1315,9 +1323,12 @@ var Vault = class _Vault {
|
|
|
1315
1323
|
pendingTermsChangeTick;
|
|
1316
1324
|
openedDate;
|
|
1317
1325
|
openedTick;
|
|
1326
|
+
securitizationRatio;
|
|
1318
1327
|
load(vault) {
|
|
1319
1328
|
this.securitization = vault.securitization.toBigInt();
|
|
1320
|
-
this.securitizationRatio = convertFixedU128ToBigNumber(
|
|
1329
|
+
this.securitizationRatio = convertFixedU128ToBigNumber(
|
|
1330
|
+
vault.securitizationRatio.toBigInt()
|
|
1331
|
+
).toNumber();
|
|
1321
1332
|
this.argonsLocked = vault.argonsLocked.toBigInt();
|
|
1322
1333
|
this.argonsPendingActivation = vault.argonsPendingActivation.toBigInt();
|
|
1323
1334
|
if (vault.argonsScheduledForRelease.size > 0) {
|
|
@@ -1359,21 +1370,21 @@ var Vault = class _Vault {
|
|
|
1359
1370
|
getRelockCapacity() {
|
|
1360
1371
|
return [...this.argonsScheduledForRelease.values()].reduce((acc, val) => acc + val, 0n);
|
|
1361
1372
|
}
|
|
1373
|
+
securitizationRatioBN() {
|
|
1374
|
+
return new BigNumber2(this.securitizationRatio);
|
|
1375
|
+
}
|
|
1362
1376
|
recoverySecuritization() {
|
|
1363
|
-
const reserved = new BigNumber2(1).div(this.
|
|
1377
|
+
const reserved = new BigNumber2(1).div(this.securitizationRatioBN());
|
|
1364
1378
|
return this.securitization - BigInt(reserved.multipliedBy(this.securitization.toString()).toFixed(0, ROUND_FLOOR2));
|
|
1365
1379
|
}
|
|
1366
1380
|
minimumSecuritization() {
|
|
1367
1381
|
return BigInt(
|
|
1368
|
-
this.
|
|
1382
|
+
this.securitizationRatioBN().multipliedBy(this.argonsLocked.toString()).decimalPlaces(0, BigNumber2.ROUND_CEIL).toString()
|
|
1369
1383
|
);
|
|
1370
1384
|
}
|
|
1371
1385
|
activatedSecuritization() {
|
|
1372
1386
|
const activated = this.argonsLocked - this.argonsPendingActivation;
|
|
1373
|
-
|
|
1374
|
-
if (this.securitizationRatio.toNumber() > 2) {
|
|
1375
|
-
maxRatio = BigNumber2(2);
|
|
1376
|
-
}
|
|
1387
|
+
const maxRatio = BigNumber2(Math.min(this.securitizationRatio, 2));
|
|
1377
1388
|
return BigInt(maxRatio.multipliedBy(activated.toString()).toFixed(0, ROUND_FLOOR2));
|
|
1378
1389
|
}
|
|
1379
1390
|
/**
|
|
@@ -1404,9 +1415,9 @@ var Vault = class _Vault {
|
|
|
1404
1415
|
bitcoinXpub,
|
|
1405
1416
|
tip,
|
|
1406
1417
|
doNotExceedBalance,
|
|
1407
|
-
|
|
1418
|
+
txProgressCallback
|
|
1408
1419
|
} = args;
|
|
1409
|
-
let xpubBytes =
|
|
1420
|
+
let xpubBytes = hexToU8a(bitcoinXpub);
|
|
1410
1421
|
if (xpubBytes.length !== 78) {
|
|
1411
1422
|
if (bitcoinXpub.startsWith("xpub") || bitcoinXpub.startsWith("tpub") || bitcoinXpub.startsWith("zpub")) {
|
|
1412
1423
|
const bytes = bs58check.decode(bitcoinXpub);
|
|
@@ -1447,21 +1458,7 @@ var Vault = class _Vault {
|
|
|
1447
1458
|
tip,
|
|
1448
1459
|
useLatestNonce: true,
|
|
1449
1460
|
waitForBlock: true,
|
|
1450
|
-
|
|
1451
|
-
let percent = 0;
|
|
1452
|
-
if (result2.status.isInvalid || result2.status.isDropped || result2.status.isUsurped || result2.status.isRetracted) {
|
|
1453
|
-
percent = 1;
|
|
1454
|
-
} else if (result2.status.isReady) {
|
|
1455
|
-
percent = 0;
|
|
1456
|
-
} else if (result2.status.isBroadcast) {
|
|
1457
|
-
percent = 0.5;
|
|
1458
|
-
} else if (result2.status.isInBlock) {
|
|
1459
|
-
percent = 1;
|
|
1460
|
-
} else if (result2.status.isFinalized) {
|
|
1461
|
-
percent = 1.1;
|
|
1462
|
-
}
|
|
1463
|
-
progressCallback?.(percent, result2.status);
|
|
1464
|
-
}
|
|
1461
|
+
txProgressCallback
|
|
1465
1462
|
});
|
|
1466
1463
|
await result.inBlockPromise;
|
|
1467
1464
|
let vaultId;
|
|
@@ -1568,7 +1565,7 @@ var VaultMonitor = class {
|
|
|
1568
1565
|
id: vaultId,
|
|
1569
1566
|
btcSpace: `${formatArgons(vault.availableBitcoinSpace())} (${formatArgons(vault.argonsPendingActivation)} pending)`,
|
|
1570
1567
|
btcDeal: `${formatArgons(vault.terms.bitcoinBaseFee)} + ${formatPercent(vault.terms.bitcoinAnnualPercentRate)}`,
|
|
1571
|
-
securitization: `${formatArgons(vault.securitization)} at ${vault.securitizationRatio
|
|
1568
|
+
securitization: `${formatArgons(vault.securitization)} at ${vault.securitizationRatio}x`,
|
|
1572
1569
|
securActivated: `${formatArgons(vault.activatedSecuritizationPerSlot())}/slot`,
|
|
1573
1570
|
liquidPoolDeal: `${formatPercent(vault.terms.liquidityPoolProfitSharing)} sharing`,
|
|
1574
1571
|
operator: `${this.accountset.namedAccounts.has(vault.operatorAccountId) ? ` (${this.accountset.namedAccounts.get(vault.operatorAccountId)})` : vault.operatorAccountId}`,
|
|
@@ -2247,7 +2244,7 @@ Raising Funds (Frame ${this.nextFrameId + 1}):`);
|
|
|
2247
2244
|
};
|
|
2248
2245
|
|
|
2249
2246
|
// src/BitcoinLocks.ts
|
|
2250
|
-
import { hexToU8a as
|
|
2247
|
+
import { hexToU8a as hexToU8a2, u8aToHex as u8aToHex2 } from "@polkadot/util";
|
|
2251
2248
|
var SATS_PER_BTC = 100000000n;
|
|
2252
2249
|
var BitcoinLocks = class _BitcoinLocks {
|
|
2253
2250
|
constructor(client) {
|
|
@@ -2287,6 +2284,7 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2287
2284
|
const bitcoinNetwork = await client.query.bitcoinUtxos.bitcoinNetwork();
|
|
2288
2285
|
return {
|
|
2289
2286
|
releaseExpirationBlocks: client.consts.bitcoinLocks.lockReleaseCosignDeadlineBlocks.toNumber(),
|
|
2287
|
+
pendingConfirmationExpirationBlocks: client.consts.bitcoinUtxos.maxPendingConfirmationBlocks.toNumber(),
|
|
2290
2288
|
tickDurationMillis: await client.query.ticks.genesisTicker().then((x) => x.tickDurationMillis.toNumber()),
|
|
2291
2289
|
bitcoinNetwork
|
|
2292
2290
|
};
|
|
@@ -2341,7 +2339,7 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2341
2339
|
return void 0;
|
|
2342
2340
|
}
|
|
2343
2341
|
async submitVaultSignature(args) {
|
|
2344
|
-
const { utxoId, vaultSignature, argonKeyring } = args;
|
|
2342
|
+
const { utxoId, vaultSignature, argonKeyring, txProgressCallback } = args;
|
|
2345
2343
|
const client = await this.client;
|
|
2346
2344
|
if (!vaultSignature || vaultSignature.byteLength < 70 || vaultSignature.byteLength > 73) {
|
|
2347
2345
|
throw new Error(
|
|
@@ -2351,7 +2349,7 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2351
2349
|
const signature = u8aToHex2(vaultSignature);
|
|
2352
2350
|
const tx = client.tx.bitcoinLocks.cosignRelease(utxoId, signature);
|
|
2353
2351
|
const submitter = new TxSubmitter(client, tx, argonKeyring);
|
|
2354
|
-
return await submitter.submit();
|
|
2352
|
+
return await submitter.submit({ txProgressCallback });
|
|
2355
2353
|
}
|
|
2356
2354
|
async getBitcoinLock(utxoId) {
|
|
2357
2355
|
const client = await this.client;
|
|
@@ -2522,11 +2520,16 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2522
2520
|
return { tx, securityFee, txFee };
|
|
2523
2521
|
}
|
|
2524
2522
|
async initializeLock(args) {
|
|
2525
|
-
const { argonKeyring, tip = 0n } = args;
|
|
2523
|
+
const { argonKeyring, tip = 0n, txProgressCallback } = args;
|
|
2526
2524
|
const client = await this.client;
|
|
2527
2525
|
const { tx, securityFee } = await this.createInitializeLockTx(args);
|
|
2528
2526
|
const submitter = new TxSubmitter(client, tx, argonKeyring);
|
|
2529
|
-
const txResult = await submitter.submit({
|
|
2527
|
+
const txResult = await submitter.submit({
|
|
2528
|
+
waitForBlock: true,
|
|
2529
|
+
logResults: true,
|
|
2530
|
+
tip,
|
|
2531
|
+
txProgressCallback
|
|
2532
|
+
});
|
|
2530
2533
|
const blockHash = await txResult.inBlockPromise;
|
|
2531
2534
|
const blockHeight = await client.at(blockHash).then((x) => x.query.system.number()).then((x) => x.toNumber());
|
|
2532
2535
|
const utxoId = await this.getUtxoIdFromEvents(txResult.events) ?? 0;
|
|
@@ -2549,7 +2552,8 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2549
2552
|
lock,
|
|
2550
2553
|
releaseRequest: { bitcoinNetworkFee, toScriptPubkey },
|
|
2551
2554
|
argonKeyring,
|
|
2552
|
-
tip
|
|
2555
|
+
tip,
|
|
2556
|
+
txProgressCallback
|
|
2553
2557
|
} = args;
|
|
2554
2558
|
if (!toScriptPubkey.startsWith("0x")) {
|
|
2555
2559
|
throw new Error("toScriptPubkey must be a hex string starting with 0x");
|
|
@@ -2572,7 +2576,12 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2572
2576
|
`Insufficient funds to release lock. Available: ${formatArgons(canAfford.availableBalance)}, Required: ${formatArgons(redemptionPrice)}`
|
|
2573
2577
|
);
|
|
2574
2578
|
}
|
|
2575
|
-
const txResult = await submitter.submit({
|
|
2579
|
+
const txResult = await submitter.submit({
|
|
2580
|
+
waitForBlock: true,
|
|
2581
|
+
logResults: true,
|
|
2582
|
+
tip,
|
|
2583
|
+
txProgressCallback
|
|
2584
|
+
});
|
|
2576
2585
|
const blockHash = await txResult.inBlockPromise;
|
|
2577
2586
|
const blockHeight = await client.at(blockHash).then((x) => x.query.system.number()).then((x) => x.toNumber());
|
|
2578
2587
|
return {
|
|
@@ -2611,7 +2620,7 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2611
2620
|
};
|
|
2612
2621
|
}
|
|
2613
2622
|
async ratchet(args) {
|
|
2614
|
-
const { lock, argonKeyring, tip = 0n, vault } = args;
|
|
2623
|
+
const { lock, argonKeyring, tip = 0n, vault, txProgressCallback } = args;
|
|
2615
2624
|
const client = await this.client;
|
|
2616
2625
|
const ratchetPrice = await this.getRatchetPrice(lock, vault);
|
|
2617
2626
|
const txSubmitter = new TxSubmitter(
|
|
@@ -2632,7 +2641,8 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2632
2641
|
}
|
|
2633
2642
|
const submission = await txSubmitter.submit({
|
|
2634
2643
|
waitForBlock: true,
|
|
2635
|
-
tip
|
|
2644
|
+
tip,
|
|
2645
|
+
txProgressCallback
|
|
2636
2646
|
});
|
|
2637
2647
|
const ratchetEvent = submission.events.find(
|
|
2638
2648
|
(x) => client.events.bitcoinLocks.BitcoinLockRatcheted.is(x)
|
|
@@ -2664,7 +2674,7 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2664
2674
|
const vaults = new VaultMonitor(accountset, {
|
|
2665
2675
|
bitcoinSpaceAvailable: argonAmount
|
|
2666
2676
|
});
|
|
2667
|
-
const bitcoinXpubBuffer =
|
|
2677
|
+
const bitcoinXpubBuffer = hexToU8a2(bitcoinXpub);
|
|
2668
2678
|
return new Promise(async (resolve, reject) => {
|
|
2669
2679
|
vaults.events.on("bitcoin-space-above", async (vaultId, amount) => {
|
|
2670
2680
|
const vault = vaults.vaultsById[vaultId];
|
|
@@ -2721,7 +2731,7 @@ function createKeyringPair(opts) {
|
|
|
2721
2731
|
}
|
|
2722
2732
|
|
|
2723
2733
|
// src/index.ts
|
|
2724
|
-
import { u8aToHex as u8aToHex3, hexToU8a as
|
|
2734
|
+
import { u8aToHex as u8aToHex3, hexToU8a as hexToU8a3, u8aEq } from "@polkadot/util";
|
|
2725
2735
|
import { GenericEvent as GenericEvent2, GenericBlock, GenericAddress } from "@polkadot/types/generic";
|
|
2726
2736
|
import {
|
|
2727
2737
|
BTreeMap,
|
|
@@ -2765,6 +2775,7 @@ export {
|
|
|
2765
2775
|
setConfig,
|
|
2766
2776
|
getConfig,
|
|
2767
2777
|
TxSubmitter,
|
|
2778
|
+
TxResult,
|
|
2768
2779
|
MICROGONS_PER_ARGON,
|
|
2769
2780
|
formatArgons,
|
|
2770
2781
|
formatPercent,
|
|
@@ -2806,7 +2817,7 @@ export {
|
|
|
2806
2817
|
waitForLoad,
|
|
2807
2818
|
getClient,
|
|
2808
2819
|
u8aToHex3 as u8aToHex,
|
|
2809
|
-
|
|
2820
|
+
hexToU8a3 as hexToU8a,
|
|
2810
2821
|
u8aEq,
|
|
2811
2822
|
GenericEvent2 as GenericEvent,
|
|
2812
2823
|
GenericBlock,
|
|
@@ -2834,4 +2845,4 @@ export {
|
|
|
2834
2845
|
u64,
|
|
2835
2846
|
u8
|
|
2836
2847
|
};
|
|
2837
|
-
//# sourceMappingURL=chunk-
|
|
2848
|
+
//# sourceMappingURL=chunk-P3OMJABP.js.map
|