@argonprotocol/mainchain 1.4.3-dev.cd7db477 → 1.4.3-dev.e162cc56

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.
@@ -12891,7 +12891,11 @@ declare class TxResult {
12891
12891
  private parseEvents;
12892
12892
  }
12893
12893
 
12894
- type ISubmittableOptions = Partial<SignerOptions> & {
12894
+ type TxSigningAccount = KeyringPair | {
12895
+ address: string;
12896
+ signer: NonNullable<SignerOptions['signer']>;
12897
+ };
12898
+ type ISubmittableOptions = Partial<Omit<SignerOptions, 'signer'>> & {
12895
12899
  tip?: bigint;
12896
12900
  logResults?: boolean;
12897
12901
  useLatestNonce?: boolean;
@@ -12901,8 +12905,9 @@ type ISubmittableOptions = Partial<SignerOptions> & {
12901
12905
  declare class TxSubmitter {
12902
12906
  readonly client: ArgonClient;
12903
12907
  tx: SubmittableExtrinsic$1;
12904
- pair: KeyringPair;
12905
- constructor(client: ArgonClient, tx: SubmittableExtrinsic$1, pair: KeyringPair);
12908
+ readonly account: TxSigningAccount;
12909
+ readonly address: string;
12910
+ constructor(client: ArgonClient, tx: SubmittableExtrinsic$1, account: TxSigningAccount);
12906
12911
  feeEstimate(tip?: bigint): Promise<bigint>;
12907
12912
  canAfford(options?: {
12908
12913
  tip?: bigint;
@@ -12913,6 +12918,8 @@ declare class TxSubmitter {
12913
12918
  availableBalance: bigint;
12914
12919
  txFee: bigint;
12915
12920
  }>;
12921
+ sign(options?: ISubmittableOptions): Promise<SubmittableExtrinsic$1>;
12922
+ submitSigned(signedTx: SubmittableExtrinsic$1, options?: ISubmittableOptions): Promise<TxResult>;
12916
12923
  submit(options?: ISubmittableOptions): Promise<TxResult>;
12917
12924
  private logRequest;
12918
12925
  }
@@ -12978,7 +12985,7 @@ declare class Vault {
12978
12985
  activatedSecuritizationPerSlot(): bigint;
12979
12986
  calculateBitcoinFee(amount: bigint): bigint;
12980
12987
  static get(client: ArgonClient | ApiDecoration<'promise'>, vaultId: number, tickDurationMillis?: number): Promise<Vault>;
12981
- static create(client: ArgonClient, keypair: KeyringPair, args: {
12988
+ static create(client: ArgonClient, txSigner: TxSigningAccount, args: {
12982
12989
  securitization: bigint | number;
12983
12990
  securitizationRatio: number;
12984
12991
  annualPercentRate: number;
@@ -12993,7 +13000,7 @@ declare class Vault {
12993
13000
  getVault(): Promise<Vault>;
12994
13001
  txResult: TxResult;
12995
13002
  }>;
12996
- static setName(client: ArgonClient, keypair: KeyringPair, args: {
13003
+ static setName(client: ArgonClient, txSigner: TxSigningAccount, args: {
12997
13004
  name?: string | null;
12998
13005
  } & ISubmittableOptions): Promise<TxResult>;
12999
13006
  }
@@ -13075,7 +13082,7 @@ declare class BitcoinLock implements IBitcoinLock {
13075
13082
  ratchet(args: {
13076
13083
  client: ArgonClient;
13077
13084
  priceIndex: PriceIndex;
13078
- argonKeyring: KeyringPair;
13085
+ txSigner: TxSigningAccount;
13079
13086
  vault: Vault;
13080
13087
  microgonsPerBtc?: bigint;
13081
13088
  } & ISubmittableOptions): Promise<{
@@ -13096,7 +13103,7 @@ declare class BitcoinLock implements IBitcoinLock {
13096
13103
  client: ArgonClient;
13097
13104
  priceIndex: PriceIndex;
13098
13105
  releaseRequest: IReleaseRequest;
13099
- argonKeyring: KeyringPair;
13106
+ txSigner: TxSigningAccount;
13100
13107
  } & ISubmittableOptions): Promise<TxResult>;
13101
13108
  getReleaseRequest(client: IQueryableClient): Promise<IReleaseRequestDetails | undefined>;
13102
13109
  /**
@@ -13122,7 +13129,7 @@ declare class BitcoinLock implements IBitcoinLock {
13122
13129
  client: ArgonClient;
13123
13130
  utxoId: number;
13124
13131
  vaultSignature: Uint8Array;
13125
- argonKeyring: KeyringPair;
13132
+ txSigner: TxSigningAccount;
13126
13133
  } & ISubmittableOptions): Promise<TxResult>;
13127
13134
  static createIncreaseSecuritizationTx(args: {
13128
13135
  utxoId: number;
@@ -13153,7 +13160,7 @@ declare class BitcoinLock implements IBitcoinLock {
13153
13160
  priceIndex: PriceIndex;
13154
13161
  ownerBitcoinPubkey: Uint8Array;
13155
13162
  satoshis: bigint;
13156
- argonKeyring: KeyringPair;
13163
+ txSigner: TxSigningAccount;
13157
13164
  reducedBalanceBy?: bigint;
13158
13165
  microgonsPerBtc?: bigint;
13159
13166
  tip?: bigint;
@@ -13171,7 +13178,7 @@ declare class BitcoinLock implements IBitcoinLock {
13171
13178
  vault: Vault;
13172
13179
  priceIndex: PriceIndex;
13173
13180
  ownerBitcoinPubkey: Uint8Array;
13174
- argonKeyring: KeyringPair;
13181
+ txSigner: TxSigningAccount;
13175
13182
  satoshis: bigint;
13176
13183
  } & ISubmittableOptions): Promise<{
13177
13184
  getLock(): Promise<{
@@ -13244,4 +13251,4 @@ declare function waitForLoad(): Promise<void>;
13244
13251
  declare function getClient(host: string, options?: ApiOptions): Promise<ArgonClient>;
13245
13252
  declare function getOfflineRegistry(): TypeRegistry;
13246
13253
 
13247
- export { type ArgonClient, BitcoinLock, ExtrinsicError, FIXED_U128_DECIMALS, type IBitcoinLock, type IBitcoinLockConfig, type IReleaseRequest, type IReleaseRequestDetails, type ISubmittableOptions, type ITerms, type ITxProgressCallback, MICROGONS_PER_ARGON, PERMILL_DECIMALS, PriceIndex, SATS_PER_BTC, TxResult, TxSubmitter, Vault, WageProtector, checkForExtrinsicSuccess, createKeyringPair, dispatchErrorToExtrinsicError, dispatchErrorToString, formatArgons, fromFixedNumber, getAuthorFromHeader, getClient, getFrameInfoFromHeader, getOfflineRegistry, getTickFromHeader, gettersToObject, keyringFromSuri, toFixedNumber, waitForLoad };
13254
+ export { type ArgonClient, BitcoinLock, ExtrinsicError, FIXED_U128_DECIMALS, type IBitcoinLock, type IBitcoinLockConfig, type IReleaseRequest, type IReleaseRequestDetails, type ISubmittableOptions, type ITerms, type ITxProgressCallback, MICROGONS_PER_ARGON, PERMILL_DECIMALS, PriceIndex, SATS_PER_BTC, TxResult, type TxSigningAccount, TxSubmitter, Vault, WageProtector, checkForExtrinsicSuccess, createKeyringPair, dispatchErrorToExtrinsicError, dispatchErrorToString, formatArgons, fromFixedNumber, getAuthorFromHeader, getClient, getFrameInfoFromHeader, getOfflineRegistry, getTickFromHeader, gettersToObject, keyringFromSuri, toFixedNumber, waitForLoad };
package/browser/index.js CHANGED
@@ -344,18 +344,20 @@ _submissionError = new WeakMap();
344
344
 
345
345
  // src/TxSubmitter.ts
346
346
  var TxSubmitter = class {
347
- constructor(client, tx, pair) {
347
+ constructor(client, tx, account) {
348
348
  this.client = client;
349
349
  this.tx = tx;
350
- this.pair = pair;
350
+ this.account = account;
351
+ __publicField(this, "address");
352
+ this.address = account.address;
351
353
  }
352
354
  async feeEstimate(tip) {
353
- const { partialFee } = await this.tx.paymentInfo(this.pair, { tip });
355
+ const { partialFee } = await this.tx.paymentInfo(this.address, { tip });
354
356
  return partialFee.toBigInt();
355
357
  }
356
358
  async canAfford(options = {}) {
357
359
  const { tip, unavailableBalance } = options;
358
- const account = await this.client.query.system.account(this.pair.address);
360
+ const account = await this.client.query.system.account(this.address);
359
361
  let availableBalance = account.data.free.toBigInt();
360
362
  const userBalance = availableBalance;
361
363
  if (unavailableBalance) {
@@ -367,26 +369,32 @@ var TxSubmitter = class {
367
369
  const canAfford = availableBalance >= totalCharge + existentialDeposit;
368
370
  return { canAfford, availableBalance: userBalance, txFee: fees };
369
371
  }
370
- async submit(options = {}) {
372
+ async sign(options = {}) {
371
373
  const { useLatestNonce, ...apiOptions } = options;
372
374
  await waitForLoad();
375
+ if (useLatestNonce && apiOptions.nonce === void 0) {
376
+ apiOptions.nonce = await this.client.rpc.system.accountNextIndex(this.address);
377
+ }
378
+ if ("signer" in this.account) {
379
+ return await this.tx.signAsync(this.address, { ...apiOptions, signer: this.account.signer });
380
+ }
381
+ return await this.tx.signAsync(this.account, apiOptions);
382
+ }
383
+ async submitSigned(signedTx, options = {}) {
373
384
  const blockHeight = await this.client.rpc.chain.getHeader().then((h) => h.number.toNumber());
374
385
  if (options.logResults) {
375
386
  this.logRequest();
376
387
  }
377
- if (useLatestNonce && !apiOptions.nonce) {
378
- apiOptions.nonce = await this.client.rpc.system.accountNextIndex(this.pair.address);
379
- }
380
- const signedTx = await this.tx.signAsync(this.pair, apiOptions);
381
388
  const txHash = signedTx.hash.toHex();
382
389
  const result2 = new TxResult(this.client, {
383
390
  signedHash: txHash,
384
391
  method: signedTx.method.toHuman(),
385
- accountAddress: this.pair.address,
392
+ accountAddress: this.address,
386
393
  submittedTime: /* @__PURE__ */ new Date(),
387
394
  submittedAtBlockNumber: blockHeight,
388
395
  nonce: signedTx.nonce.toNumber()
389
396
  });
397
+ result2.txProgressCallback = options.txProgressCallback;
390
398
  if (options.disableAutomaticTxTracking !== true) {
391
399
  await signedTx.send(result2.onSubscriptionResult.bind(result2));
392
400
  } else {
@@ -399,6 +407,10 @@ var TxSubmitter = class {
399
407
  }
400
408
  return result2;
401
409
  }
410
+ async submit(options = {}) {
411
+ const signedTx = await this.sign(options);
412
+ return await this.submitSigned(signedTx, options);
413
+ }
402
414
  logRequest() {
403
415
  let toHuman = this.tx.toHuman().method;
404
416
  const txString = [];
@@ -417,7 +429,7 @@ var TxSubmitter = class {
417
429
  args.push(toHuman.args);
418
430
  }
419
431
  args.unshift(txString.join("->"));
420
- console.log("Submitting transaction from %s:", this.pair.address, ...args);
432
+ console.log("Submitting transaction from %s:", this.address, ...args);
421
433
  }
422
434
  };
423
435
  function formatCall(call) {
@@ -614,7 +626,7 @@ var Vault = class _Vault {
614
626
  const tickDuration = tickDurationMillis ?? await client.query.ticks.genesisTicker().then((x) => x.tickDurationMillis.toNumber());
615
627
  return new _Vault(vaultId, rawVault.unwrap(), tickDuration);
616
628
  }
617
- static async create(client, keypair, args, config = {}) {
629
+ static async create(client, txSigner, args, config = {}) {
618
630
  const {
619
631
  securitization,
620
632
  securitizationRatio,
@@ -651,7 +663,7 @@ var Vault = class _Vault {
651
663
  bitcoinXpubkey: xpubBytes,
652
664
  name: encodedName
653
665
  };
654
- const tx = new TxSubmitter(client, client.tx.vaults.create(vaultParams), keypair);
666
+ const tx = new TxSubmitter(client, client.tx.vaults.create(vaultParams), txSigner);
655
667
  if (doNotExceedBalance) {
656
668
  const finalTip = tip ?? 0n;
657
669
  let txFee = await tx.feeEstimate(finalTip);
@@ -687,11 +699,11 @@ var Vault = class _Vault {
687
699
  }
688
700
  return { getVault, txResult: result2 };
689
701
  }
690
- static async setName(client, keypair, args) {
702
+ static async setName(client, txSigner, args) {
691
703
  const tx = new TxSubmitter(
692
704
  client,
693
705
  client.tx.vaults.setName(encodeVaultName(args.name)),
694
- keypair
706
+ txSigner
695
707
  );
696
708
  return tx.submit({
697
709
  ...args,
@@ -714,7 +726,7 @@ function encodeVaultName(name) {
714
726
  "Vault name must start with a capital letter and contain at most 18 alphanumeric characters"
715
727
  );
716
728
  }
717
- return new TextEncoder().encode(name);
729
+ return name;
718
730
  }
719
731
  function toFixedNumber(value, decimals) {
720
732
  const factor = new BigNumber3__default(10).pow(decimals);
@@ -840,10 +852,10 @@ var BitcoinLock = class _BitcoinLock {
840
852
  };
841
853
  }
842
854
  async ratchet(args) {
843
- const { priceIndex, argonKeyring, tip = 0n, vault, client, microgonsPerBtc = null } = args;
855
+ const { priceIndex, txSigner, tip = 0n, vault, client, microgonsPerBtc = null } = args;
844
856
  const ratchetPrice = await this.getRatchetPrice(client, priceIndex, vault);
845
857
  const tx = client.tx.bitcoinLocks.ratchet(this.utxoId, { V1: { microgonsPerBtc } });
846
- const txSubmitter = new TxSubmitter(client, tx, argonKeyring);
858
+ const txSubmitter = new TxSubmitter(client, tx, txSigner);
847
859
  const canAfford = await txSubmitter.canAfford({
848
860
  tip,
849
861
  unavailableBalance: BigInt(ratchetPrice.burnAmount + ratchetPrice.ratchetingFee)
@@ -901,7 +913,7 @@ var BitcoinLock = class _BitcoinLock {
901
913
  const {
902
914
  priceIndex,
903
915
  releaseRequest: { bitcoinNetworkFee, toScriptPubkey },
904
- argonKeyring,
916
+ txSigner,
905
917
  tip = 0n,
906
918
  client
907
919
  } = args;
@@ -911,7 +923,7 @@ var BitcoinLock = class _BitcoinLock {
911
923
  const submitter = new TxSubmitter(
912
924
  client,
913
925
  client.tx.bitcoinLocks.requestRelease(this.utxoId, toScriptPubkey, bitcoinNetworkFee),
914
- argonKeyring
926
+ txSigner
915
927
  );
916
928
  const redemptionPrice = await _BitcoinLock.getRedemptionRate(priceIndex, this);
917
929
  const canAfford = await submitter.canAfford({
@@ -1052,7 +1064,7 @@ var BitcoinLock = class _BitcoinLock {
1052
1064
  return await client.query.bitcoinUtxos.confirmedBitcoinBlockTip().then((x) => x.value?.blockHeight.toNumber() ?? 0);
1053
1065
  }
1054
1066
  static async submitVaultSignature(args) {
1055
- const { utxoId, vaultSignature, argonKeyring, client } = args;
1067
+ const { utxoId, vaultSignature, txSigner, client } = args;
1056
1068
  if (!vaultSignature || vaultSignature.byteLength < 70 || vaultSignature.byteLength > 73) {
1057
1069
  throw new Error(
1058
1070
  `Invalid vault signature length: ${vaultSignature.byteLength}. Must be 70-73 bytes.`
@@ -1060,7 +1072,7 @@ var BitcoinLock = class _BitcoinLock {
1060
1072
  }
1061
1073
  const signature = u8aToHex(vaultSignature);
1062
1074
  const tx = client.tx.bitcoinLocks.cosignRelease(utxoId, signature);
1063
- const submitter = new TxSubmitter(client, tx, argonKeyring);
1075
+ const submitter = new TxSubmitter(client, tx, txSigner);
1064
1076
  return await submitter.submit(args);
1065
1077
  }
1066
1078
  static async createIncreaseSecuritizationTx(args) {
@@ -1190,7 +1202,7 @@ var BitcoinLock = class _BitcoinLock {
1190
1202
  const {
1191
1203
  vault,
1192
1204
  priceIndex,
1193
- argonKeyring,
1205
+ txSigner,
1194
1206
  satoshis,
1195
1207
  tip = 0n,
1196
1208
  ownerBitcoinPubkey,
@@ -1223,9 +1235,9 @@ var BitcoinLock = class _BitcoinLock {
1223
1235
  }
1224
1236
  });
1225
1237
  }
1226
- const submitter = new TxSubmitter(client, tx, argonKeyring);
1238
+ const submitter = new TxSubmitter(client, tx, txSigner);
1227
1239
  const marketPrice = await this.getMarketRate(priceIndex, satoshis);
1228
- const isVaultOwner = argonKeyring.address === vault.operatorAccountId;
1240
+ const isVaultOwner = txSigner.address === vault.operatorAccountId;
1229
1241
  const securityFee = isVaultOwner ? 0n : vault.calculateBitcoinFee(marketPrice);
1230
1242
  const { canAfford, availableBalance, txFee } = await submitter.canAfford({
1231
1243
  tip,
@@ -1242,14 +1254,14 @@ var BitcoinLock = class _BitcoinLock {
1242
1254
  };
1243
1255
  }
1244
1256
  static async initialize(args) {
1245
- const { argonKeyring, client } = args;
1257
+ const { txSigner, client } = args;
1246
1258
  const { tx, securityFee, canAfford, txFeePlusTip } = await this.createInitializeTx(args);
1247
1259
  if (!canAfford) {
1248
1260
  throw new Error(
1249
1261
  `Insufficient funds to initialize bitcoin lock. Required security fee: ${formatArgons(securityFee)}, Tx fee plus tip: ${formatArgons(txFeePlusTip)}`
1250
1262
  );
1251
1263
  }
1252
- const submitter = new TxSubmitter(client, tx, argonKeyring);
1264
+ const submitter = new TxSubmitter(client, tx, txSigner);
1253
1265
  const txResult = await submitter.submit({ logResults: true, ...args });
1254
1266
  return {
1255
1267
  getLock: () => this.getBitcoinLockFromTxResult(client, txResult),