@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.
- 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.d.cts
CHANGED
|
@@ -12891,7 +12891,11 @@ declare class TxResult {
|
|
|
12891
12891
|
private parseEvents;
|
|
12892
12892
|
}
|
|
12893
12893
|
|
|
12894
|
-
type
|
|
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
|
-
|
|
12905
|
-
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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/lib/index.d.ts
CHANGED
|
@@ -12891,7 +12891,11 @@ declare class TxResult {
|
|
|
12891
12891
|
private parseEvents;
|
|
12892
12892
|
}
|
|
12893
12893
|
|
|
12894
|
-
type
|
|
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
|
-
|
|
12905
|
-
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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/lib/index.js
CHANGED
|
@@ -346,18 +346,20 @@ var TxResult = 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
|
+
address;
|
|
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 = tickDurationMillis ?? 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 = 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) => x.value?.blockHeight.toNumber() ?? 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 = u8aToHex(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),
|