@atomiqlabs/sdk 8.7.3 → 8.7.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/dist/swapper/SwapperUtils.d.ts +6 -0
- package/dist/swapper/SwapperUtils.js +13 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +4 -1
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +4 -1
- package/package.json +2 -2
- package/src/swapper/SwapperUtils.ts +12 -0
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +9 -2
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +8 -2
|
@@ -138,6 +138,12 @@ export declare class SwapperUtils<T extends MultiChain> {
|
|
|
138
138
|
* Returns the address of the native currency of the smart chain
|
|
139
139
|
*/
|
|
140
140
|
getNativeToken<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier): SCToken<ChainIdentifier>;
|
|
141
|
+
/**
|
|
142
|
+
* Returns whether when swapping to the provided token a gas drop can be requested
|
|
143
|
+
*
|
|
144
|
+
* @param token
|
|
145
|
+
*/
|
|
146
|
+
destinationTokenSupportsGasDrop<ChainIdentifier extends ChainIds<T>>(token: SCToken<ChainIdentifier>): boolean;
|
|
141
147
|
/**
|
|
142
148
|
* Returns a random signer for a given smart chain
|
|
143
149
|
*
|
|
@@ -373,6 +373,19 @@ class SwapperUtils {
|
|
|
373
373
|
throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
|
|
374
374
|
return this.root._tokens[chainIdentifier][this.root._chains[chainIdentifier].chainInterface.getNativeCurrencyAddress()];
|
|
375
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* Returns whether when swapping to the provided token a gas drop can be requested
|
|
378
|
+
*
|
|
379
|
+
* @param token
|
|
380
|
+
*/
|
|
381
|
+
destinationTokenSupportsGasDrop(token) {
|
|
382
|
+
if (this.root._chains[token.chainId] == null)
|
|
383
|
+
throw new Error("Invalid chain identifier! Unknown chain: " + token.chainId);
|
|
384
|
+
const { chainInterface } = this.root._chains[token.chainId];
|
|
385
|
+
if (chainInterface.shouldGetNativeTokenDrop != null)
|
|
386
|
+
return chainInterface.shouldGetNativeTokenDrop(token.address);
|
|
387
|
+
return chainInterface.getNativeCurrencyAddress() === token.address;
|
|
388
|
+
}
|
|
376
389
|
/**
|
|
377
390
|
* Returns a random signer for a given smart chain
|
|
378
391
|
*
|
|
@@ -231,7 +231,10 @@ class FromBTCLNAutoWrapper extends IFromBTCLNWrapper_1.IFromBTCLNWrapper {
|
|
|
231
231
|
description: options?.description,
|
|
232
232
|
descriptionHash: (0, Utils_1.parseHashValueExact32Bytes)(options?.descriptionHash, "description hash")
|
|
233
233
|
};
|
|
234
|
-
if (
|
|
234
|
+
if (_options.gasAmount !== 0n &&
|
|
235
|
+
(this._chain.shouldGetNativeTokenDrop != null
|
|
236
|
+
? !this._chain.shouldGetNativeTokenDrop(amountData.token)
|
|
237
|
+
: amountData.token === this._chain.getNativeCurrencyAddress()))
|
|
235
238
|
throw new UserError_1.UserError("Cannot specify `gasAmount` for swaps to a native token!");
|
|
236
239
|
if (_options.description != null && buffer_1.Buffer.byteLength(_options.description, "utf8") > 500)
|
|
237
240
|
throw new UserError_1.UserError("Invalid description length");
|
|
@@ -466,7 +466,10 @@ class SpvFromBTCWrapper extends ISwapWrapper_1.ISwapWrapper {
|
|
|
466
466
|
feeSafetyFactor: options?.feeSafetyFactor ?? 1.25,
|
|
467
467
|
maxAllowedBitcoinFeeRate: options?.maxAllowedBitcoinFeeRate ?? options?.maxAllowedNetworkFeeRate ?? Infinity
|
|
468
468
|
};
|
|
469
|
-
if (
|
|
469
|
+
if (_options.gasAmount !== 0n &&
|
|
470
|
+
(this._chain.shouldGetNativeTokenDrop != null
|
|
471
|
+
? !this._chain.shouldGetNativeTokenDrop(amountData.token)
|
|
472
|
+
: amountData.token === this._chain.getNativeCurrencyAddress()))
|
|
470
473
|
throw new UserError_1.UserError("Cannot specify `gasAmount` for swaps to a native token!");
|
|
471
474
|
const lpVersions = Intermediary_1.Intermediary.getContractVersionsForLps(this.chainIdentifier, lps);
|
|
472
475
|
const _abortController = (0, Utils_1.extendAbortController)(abortSignal);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomiqlabs/sdk",
|
|
3
|
-
"version": "8.7.
|
|
3
|
+
"version": "8.7.4",
|
|
4
4
|
"description": "atomiq labs SDK for cross-chain swaps between smart chains and bitcoin",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types:": "./dist/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"author": "adambor",
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@atomiqlabs/base": "^13.5.
|
|
26
|
+
"@atomiqlabs/base": "^13.5.2",
|
|
27
27
|
"@atomiqlabs/bolt11": "1.6.1",
|
|
28
28
|
"@atomiqlabs/btc-mempool": "^1.0.4",
|
|
29
29
|
"@atomiqlabs/messenger-nostr": "^2.0.0",
|
|
@@ -454,6 +454,18 @@ export class SwapperUtils<T extends MultiChain> {
|
|
|
454
454
|
return this.root._tokens[chainIdentifier][this.root._chains[chainIdentifier].chainInterface.getNativeCurrencyAddress()] as SCToken<ChainIdentifier>;
|
|
455
455
|
}
|
|
456
456
|
|
|
457
|
+
/**
|
|
458
|
+
* Returns whether when swapping to the provided token a gas drop can be requested
|
|
459
|
+
*
|
|
460
|
+
* @param token
|
|
461
|
+
*/
|
|
462
|
+
destinationTokenSupportsGasDrop<ChainIdentifier extends ChainIds<T>>(token: SCToken<ChainIdentifier>): boolean {
|
|
463
|
+
if(this.root._chains[token.chainId]==null) throw new Error("Invalid chain identifier! Unknown chain: "+token.chainId);
|
|
464
|
+
const {chainInterface} = this.root._chains[token.chainId];
|
|
465
|
+
if(chainInterface.shouldGetNativeTokenDrop!=null) return chainInterface.shouldGetNativeTokenDrop(token.address);
|
|
466
|
+
return chainInterface.getNativeCurrencyAddress() !== token.address;
|
|
467
|
+
}
|
|
468
|
+
|
|
457
469
|
/**
|
|
458
470
|
* Returns a random signer for a given smart chain
|
|
459
471
|
*
|
|
@@ -382,8 +382,15 @@ export class FromBTCLNAutoWrapper<
|
|
|
382
382
|
descriptionHash: parseHashValueExact32Bytes(options?.descriptionHash, "description hash")
|
|
383
383
|
};
|
|
384
384
|
|
|
385
|
-
|
|
386
|
-
|
|
385
|
+
|
|
386
|
+
if(
|
|
387
|
+
_options.gasAmount!==0n &&
|
|
388
|
+
(
|
|
389
|
+
this._chain.shouldGetNativeTokenDrop!=null
|
|
390
|
+
? !this._chain.shouldGetNativeTokenDrop(amountData.token)
|
|
391
|
+
: amountData.token===this._chain.getNativeCurrencyAddress()
|
|
392
|
+
)
|
|
393
|
+
) throw new UserError("Cannot specify `gasAmount` for swaps to a native token!");
|
|
387
394
|
|
|
388
395
|
if(_options.description!=null && Buffer.byteLength(_options.description, "utf8") > 500)
|
|
389
396
|
throw new UserError("Invalid description length");
|
|
@@ -643,8 +643,14 @@ export class SpvFromBTCWrapper<
|
|
|
643
643
|
maxAllowedBitcoinFeeRate: options?.maxAllowedBitcoinFeeRate ?? options?.maxAllowedNetworkFeeRate ?? Infinity
|
|
644
644
|
};
|
|
645
645
|
|
|
646
|
-
if(
|
|
647
|
-
|
|
646
|
+
if(
|
|
647
|
+
_options.gasAmount!==0n &&
|
|
648
|
+
(
|
|
649
|
+
this._chain.shouldGetNativeTokenDrop!=null
|
|
650
|
+
? !this._chain.shouldGetNativeTokenDrop(amountData.token)
|
|
651
|
+
: amountData.token===this._chain.getNativeCurrencyAddress()
|
|
652
|
+
)
|
|
653
|
+
) throw new UserError("Cannot specify `gasAmount` for swaps to a native token!");
|
|
648
654
|
|
|
649
655
|
const lpVersions = Intermediary.getContractVersionsForLps(this.chainIdentifier, lps);
|
|
650
656
|
|