@argonprotocol/mainchain 1.4.3-dev.07e7292e → 1.4.3-dev.1523df53
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 +18 -11
- package/browser/index.js +39 -27
- package/browser/index.js.map +1 -1
- package/lib/index.cjs +39 -27
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +18 -11
- package/lib/index.d.ts +18 -11
- package/lib/index.js +39 -27
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -346,18 +346,20 @@ var TxResult = (_class = class {
|
|
|
346
346
|
|
|
347
347
|
// src/TxSubmitter.ts
|
|
348
348
|
var TxSubmitter = class {
|
|
349
|
-
constructor(client, tx,
|
|
349
|
+
constructor(client, tx, account) {
|
|
350
350
|
this.client = client;
|
|
351
351
|
this.tx = tx;
|
|
352
|
-
this.
|
|
352
|
+
this.account = account;
|
|
353
|
+
this.address = account.address;
|
|
353
354
|
}
|
|
355
|
+
|
|
354
356
|
async feeEstimate(tip) {
|
|
355
|
-
const { partialFee } = await this.tx.paymentInfo(this.
|
|
357
|
+
const { partialFee } = await this.tx.paymentInfo(this.address, { tip });
|
|
356
358
|
return partialFee.toBigInt();
|
|
357
359
|
}
|
|
358
360
|
async canAfford(options = {}) {
|
|
359
361
|
const { tip, unavailableBalance } = options;
|
|
360
|
-
const account = await this.client.query.system.account(this.
|
|
362
|
+
const account = await this.client.query.system.account(this.address);
|
|
361
363
|
let availableBalance = account.data.free.toBigInt();
|
|
362
364
|
const userBalance = availableBalance;
|
|
363
365
|
if (unavailableBalance) {
|
|
@@ -369,26 +371,32 @@ var TxSubmitter = class {
|
|
|
369
371
|
const canAfford = availableBalance >= totalCharge + existentialDeposit;
|
|
370
372
|
return { canAfford, availableBalance: userBalance, txFee: fees };
|
|
371
373
|
}
|
|
372
|
-
async
|
|
374
|
+
async sign(options = {}) {
|
|
373
375
|
const { useLatestNonce, ...apiOptions } = options;
|
|
374
376
|
await waitForLoad();
|
|
377
|
+
if (useLatestNonce && apiOptions.nonce === void 0) {
|
|
378
|
+
apiOptions.nonce = await this.client.rpc.system.accountNextIndex(this.address);
|
|
379
|
+
}
|
|
380
|
+
if ("signer" in this.account) {
|
|
381
|
+
return await this.tx.signAsync(this.address, { ...apiOptions, signer: this.account.signer });
|
|
382
|
+
}
|
|
383
|
+
return await this.tx.signAsync(this.account, apiOptions);
|
|
384
|
+
}
|
|
385
|
+
async submitSigned(signedTx, options = {}) {
|
|
375
386
|
const blockHeight = await this.client.rpc.chain.getHeader().then((h) => h.number.toNumber());
|
|
376
387
|
if (options.logResults) {
|
|
377
388
|
this.logRequest();
|
|
378
389
|
}
|
|
379
|
-
if (useLatestNonce && !apiOptions.nonce) {
|
|
380
|
-
apiOptions.nonce = await this.client.rpc.system.accountNextIndex(this.pair.address);
|
|
381
|
-
}
|
|
382
|
-
const signedTx = await this.tx.signAsync(this.pair, apiOptions);
|
|
383
390
|
const txHash = signedTx.hash.toHex();
|
|
384
391
|
const result2 = new TxResult(this.client, {
|
|
385
392
|
signedHash: txHash,
|
|
386
393
|
method: signedTx.method.toHuman(),
|
|
387
|
-
accountAddress: this.
|
|
394
|
+
accountAddress: this.address,
|
|
388
395
|
submittedTime: /* @__PURE__ */ new Date(),
|
|
389
396
|
submittedAtBlockNumber: blockHeight,
|
|
390
397
|
nonce: signedTx.nonce.toNumber()
|
|
391
398
|
});
|
|
399
|
+
result2.txProgressCallback = options.txProgressCallback;
|
|
392
400
|
if (options.disableAutomaticTxTracking !== true) {
|
|
393
401
|
await signedTx.send(result2.onSubscriptionResult.bind(result2));
|
|
394
402
|
} else {
|
|
@@ -401,6 +409,10 @@ var TxSubmitter = class {
|
|
|
401
409
|
}
|
|
402
410
|
return result2;
|
|
403
411
|
}
|
|
412
|
+
async submit(options = {}) {
|
|
413
|
+
const signedTx = await this.sign(options);
|
|
414
|
+
return await this.submitSigned(signedTx, options);
|
|
415
|
+
}
|
|
404
416
|
logRequest() {
|
|
405
417
|
let toHuman = this.tx.toHuman().method;
|
|
406
418
|
const txString = [];
|
|
@@ -419,7 +431,7 @@ var TxSubmitter = class {
|
|
|
419
431
|
args.push(toHuman.args);
|
|
420
432
|
}
|
|
421
433
|
args.unshift(txString.join("->"));
|
|
422
|
-
console.log("Submitting transaction from %s:", this.
|
|
434
|
+
console.log("Submitting transaction from %s:", this.address, ...args);
|
|
423
435
|
}
|
|
424
436
|
};
|
|
425
437
|
function formatCall(call) {
|
|
@@ -621,7 +633,7 @@ var Vault = class _Vault {
|
|
|
621
633
|
const tickDuration = await _asyncNullishCoalesce(tickDurationMillis, async () => ( await client.query.ticks.genesisTicker().then((x) => x.tickDurationMillis.toNumber())));
|
|
622
634
|
return new _Vault(vaultId, rawVault.unwrap(), tickDuration);
|
|
623
635
|
}
|
|
624
|
-
static async create(client,
|
|
636
|
+
static async create(client, txSigner, args, config = {}) {
|
|
625
637
|
const {
|
|
626
638
|
securitization,
|
|
627
639
|
securitizationRatio,
|
|
@@ -658,7 +670,7 @@ var Vault = class _Vault {
|
|
|
658
670
|
bitcoinXpubkey: xpubBytes,
|
|
659
671
|
name: encodedName
|
|
660
672
|
};
|
|
661
|
-
const tx = new TxSubmitter(client, client.tx.vaults.create(vaultParams),
|
|
673
|
+
const tx = new TxSubmitter(client, client.tx.vaults.create(vaultParams), txSigner);
|
|
662
674
|
if (doNotExceedBalance) {
|
|
663
675
|
const finalTip = _nullishCoalesce(tip, () => ( 0n));
|
|
664
676
|
let txFee = await tx.feeEstimate(finalTip);
|
|
@@ -694,11 +706,11 @@ var Vault = class _Vault {
|
|
|
694
706
|
}
|
|
695
707
|
return { getVault, txResult: result2 };
|
|
696
708
|
}
|
|
697
|
-
static async setName(client,
|
|
709
|
+
static async setName(client, txSigner, args) {
|
|
698
710
|
const tx = new TxSubmitter(
|
|
699
711
|
client,
|
|
700
712
|
client.tx.vaults.setName(encodeVaultName(args.name)),
|
|
701
|
-
|
|
713
|
+
txSigner
|
|
702
714
|
);
|
|
703
715
|
return tx.submit({
|
|
704
716
|
...args,
|
|
@@ -721,7 +733,7 @@ function encodeVaultName(name) {
|
|
|
721
733
|
"Vault name must start with a capital letter and contain at most 18 alphanumeric characters"
|
|
722
734
|
);
|
|
723
735
|
}
|
|
724
|
-
return
|
|
736
|
+
return name;
|
|
725
737
|
}
|
|
726
738
|
|
|
727
739
|
// src/convert.ts
|
|
@@ -853,10 +865,10 @@ var BitcoinLock = class _BitcoinLock {
|
|
|
853
865
|
};
|
|
854
866
|
}
|
|
855
867
|
async ratchet(args) {
|
|
856
|
-
const { priceIndex,
|
|
868
|
+
const { priceIndex, txSigner, tip = 0n, vault, client, microgonsPerBtc = null } = args;
|
|
857
869
|
const ratchetPrice = await this.getRatchetPrice(client, priceIndex, vault);
|
|
858
870
|
const tx = client.tx.bitcoinLocks.ratchet(this.utxoId, { V1: { microgonsPerBtc } });
|
|
859
|
-
const txSubmitter = new TxSubmitter(client, tx,
|
|
871
|
+
const txSubmitter = new TxSubmitter(client, tx, txSigner);
|
|
860
872
|
const canAfford = await txSubmitter.canAfford({
|
|
861
873
|
tip,
|
|
862
874
|
unavailableBalance: BigInt(ratchetPrice.burnAmount + ratchetPrice.ratchetingFee)
|
|
@@ -914,7 +926,7 @@ var BitcoinLock = class _BitcoinLock {
|
|
|
914
926
|
const {
|
|
915
927
|
priceIndex,
|
|
916
928
|
releaseRequest: { bitcoinNetworkFee, toScriptPubkey },
|
|
917
|
-
|
|
929
|
+
txSigner,
|
|
918
930
|
tip = 0n,
|
|
919
931
|
client
|
|
920
932
|
} = args;
|
|
@@ -924,7 +936,7 @@ var BitcoinLock = class _BitcoinLock {
|
|
|
924
936
|
const submitter = new TxSubmitter(
|
|
925
937
|
client,
|
|
926
938
|
client.tx.bitcoinLocks.requestRelease(this.utxoId, toScriptPubkey, bitcoinNetworkFee),
|
|
927
|
-
|
|
939
|
+
txSigner
|
|
928
940
|
);
|
|
929
941
|
const redemptionPrice = await _BitcoinLock.getRedemptionRate(priceIndex, this);
|
|
930
942
|
const canAfford = await submitter.canAfford({
|
|
@@ -1065,7 +1077,7 @@ var BitcoinLock = class _BitcoinLock {
|
|
|
1065
1077
|
return await client.query.bitcoinUtxos.confirmedBitcoinBlockTip().then((x) => _nullishCoalesce(_optionalChain([x, 'access', _10 => _10.value, 'optionalAccess', _11 => _11.blockHeight, 'access', _12 => _12.toNumber, 'call', _13 => _13()]), () => ( 0)));
|
|
1066
1078
|
}
|
|
1067
1079
|
static async submitVaultSignature(args) {
|
|
1068
|
-
const { utxoId, vaultSignature,
|
|
1080
|
+
const { utxoId, vaultSignature, txSigner, client } = args;
|
|
1069
1081
|
if (!vaultSignature || vaultSignature.byteLength < 70 || vaultSignature.byteLength > 73) {
|
|
1070
1082
|
throw new Error(
|
|
1071
1083
|
`Invalid vault signature length: ${vaultSignature.byteLength}. Must be 70-73 bytes.`
|
|
@@ -1073,7 +1085,7 @@ var BitcoinLock = class _BitcoinLock {
|
|
|
1073
1085
|
}
|
|
1074
1086
|
const signature = _util.u8aToHex.call(void 0, vaultSignature);
|
|
1075
1087
|
const tx = client.tx.bitcoinLocks.cosignRelease(utxoId, signature);
|
|
1076
|
-
const submitter = new TxSubmitter(client, tx,
|
|
1088
|
+
const submitter = new TxSubmitter(client, tx, txSigner);
|
|
1077
1089
|
return await submitter.submit(args);
|
|
1078
1090
|
}
|
|
1079
1091
|
static async createIncreaseSecuritizationTx(args) {
|
|
@@ -1203,7 +1215,7 @@ var BitcoinLock = class _BitcoinLock {
|
|
|
1203
1215
|
const {
|
|
1204
1216
|
vault,
|
|
1205
1217
|
priceIndex,
|
|
1206
|
-
|
|
1218
|
+
txSigner,
|
|
1207
1219
|
satoshis,
|
|
1208
1220
|
tip = 0n,
|
|
1209
1221
|
ownerBitcoinPubkey,
|
|
@@ -1236,9 +1248,9 @@ var BitcoinLock = class _BitcoinLock {
|
|
|
1236
1248
|
}
|
|
1237
1249
|
});
|
|
1238
1250
|
}
|
|
1239
|
-
const submitter = new TxSubmitter(client, tx,
|
|
1251
|
+
const submitter = new TxSubmitter(client, tx, txSigner);
|
|
1240
1252
|
const marketPrice = await this.getMarketRate(priceIndex, satoshis);
|
|
1241
|
-
const isVaultOwner =
|
|
1253
|
+
const isVaultOwner = txSigner.address === vault.operatorAccountId;
|
|
1242
1254
|
const securityFee = isVaultOwner ? 0n : vault.calculateBitcoinFee(marketPrice);
|
|
1243
1255
|
const { canAfford, availableBalance, txFee } = await submitter.canAfford({
|
|
1244
1256
|
tip,
|
|
@@ -1255,14 +1267,14 @@ var BitcoinLock = class _BitcoinLock {
|
|
|
1255
1267
|
};
|
|
1256
1268
|
}
|
|
1257
1269
|
static async initialize(args) {
|
|
1258
|
-
const {
|
|
1270
|
+
const { txSigner, client } = args;
|
|
1259
1271
|
const { tx, securityFee, canAfford, txFeePlusTip } = await this.createInitializeTx(args);
|
|
1260
1272
|
if (!canAfford) {
|
|
1261
1273
|
throw new Error(
|
|
1262
1274
|
`Insufficient funds to initialize bitcoin lock. Required security fee: ${formatArgons(securityFee)}, Tx fee plus tip: ${formatArgons(txFeePlusTip)}`
|
|
1263
1275
|
);
|
|
1264
1276
|
}
|
|
1265
|
-
const submitter = new TxSubmitter(client, tx,
|
|
1277
|
+
const submitter = new TxSubmitter(client, tx, txSigner);
|
|
1266
1278
|
const txResult = await submitter.submit({ logResults: true, ...args });
|
|
1267
1279
|
return {
|
|
1268
1280
|
getLock: () => this.getBitcoinLockFromTxResult(client, txResult),
|