@atomiqlabs/sdk 8.4.4 → 8.5.0
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/README.md +8 -8
- package/dist/enums/SwapSide.d.ts +15 -0
- package/dist/enums/SwapSide.js +19 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/intermediaries/apis/IntermediaryAPI.d.ts +2 -2
- package/dist/intermediaries/apis/IntermediaryAPI.js +2 -2
- package/dist/storage/UnifiedSwapStorage.d.ts +2 -0
- package/dist/swapper/Swapper.d.ts +27 -21
- package/dist/swapper/Swapper.js +19 -26
- package/dist/swapper/SwapperWithChain.d.ts +14 -18
- package/dist/swapper/SwapperWithChain.js +2 -2
- package/dist/swapper/SwapperWithSigner.d.ts +9 -13
- package/dist/swaps/IBTCWalletSwap.d.ts +1 -1
- package/dist/swaps/ISwap.js +2 -0
- package/dist/swaps/ISwapWithGasDrop.d.ts +1 -1
- package/dist/swaps/ISwapWrapper.d.ts +12 -12
- package/dist/swaps/ISwapWrapper.js +22 -14
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +3 -3
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +8 -8
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +5 -5
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +23 -2
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +20 -17
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +4 -4
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +44 -3
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +9 -14
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +3 -3
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +20 -2
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +15 -8
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +7 -7
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +1 -1
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +52 -6
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +20 -30
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +1 -1
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +6 -0
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +6 -6
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +32 -1
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +8 -5
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +3 -3
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +4 -4
- package/dist/types/Token.d.ts +65 -25
- package/dist/types/Token.js +28 -13
- package/dist/types/TokenAmount.d.ts +2 -2
- package/dist/types/fees/Fee.d.ts +3 -3
- package/dist/utils/Utils.d.ts +1 -0
- package/dist/utils/Utils.js +17 -1
- package/package.json +1 -1
- package/src/enums/SwapSide.ts +16 -0
- package/src/index.ts +1 -0
- package/src/intermediaries/apis/IntermediaryAPI.ts +4 -4
- package/src/storage/UnifiedSwapStorage.ts +2 -0
- package/src/swapper/Swapper.ts +46 -37
- package/src/swapper/SwapperWithChain.ts +15 -10
- package/src/swapper/SwapperWithSigner.ts +8 -3
- package/src/swaps/IBTCWalletSwap.ts +1 -1
- package/src/swaps/ISwap.ts +2 -0
- package/src/swaps/ISwapWithGasDrop.ts +1 -1
- package/src/swaps/ISwapWrapper.ts +24 -23
- package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +3 -3
- package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +8 -8
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +5 -5
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +48 -22
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +4 -4
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +56 -20
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +3 -3
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +57 -22
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +7 -7
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +1 -1
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +80 -37
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +1 -1
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +12 -3
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +6 -6
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +53 -11
- package/src/swaps/trusted/ln/LnForGasSwap.ts +3 -3
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +4 -4
- package/src/types/Token.ts +98 -32
- package/src/types/TokenAmount.ts +5 -7
- package/src/types/fees/Fee.ts +3 -3
- package/src/utils/Utils.ts +18 -2
package/README.md
CHANGED
|
@@ -51,8 +51,8 @@ Set Solana & Starknet RPC URL to use
|
|
|
51
51
|
|
|
52
52
|
```typescript
|
|
53
53
|
const solanaRpc = "https://api.mainnet-beta.solana.com";
|
|
54
|
-
const starknetRpc = "https://starknet
|
|
55
|
-
const citreaRpc = "https://rpc.
|
|
54
|
+
const starknetRpc = "https://rpc.starknet.lava.build/"; //Alternatively: https://starknet.api.onfinality.io/public or https://api.zan.top/public/starknet-mainnet
|
|
55
|
+
const citreaRpc = "https://rpc.mainnet.citrea.xyz";
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
Create swapper factory, here we can pick and choose which chains we want to have supported in the SDK, ensure the "as const" keyword is used such that the typescript compiler can properly infer the types.
|
|
@@ -87,10 +87,10 @@ const swapper: TypedSwapper<SupportedChains> = Factory.newSwapper({
|
|
|
87
87
|
rpcUrl: starknetRpc //You can also pass Provider object here
|
|
88
88
|
},
|
|
89
89
|
CITREA: {
|
|
90
|
-
rpcUrl: citreaRpc, //You can also pass
|
|
90
|
+
rpcUrl: citreaRpc, //You can also pass JsonRpcApiProvider object here
|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
|
-
bitcoinNetwork: BitcoinNetwork.
|
|
93
|
+
bitcoinNetwork: BitcoinNetwork.MAINNET //or BitcoinNetwork.TESTNET3, BitcoinNetwork.TESTNET4 - this also sets the network to use for Solana (solana devnet for bitcoin testnet) & Starknet (sepolia for bitcoin testnet)
|
|
94
94
|
});
|
|
95
95
|
```
|
|
96
96
|
|
|
@@ -122,7 +122,7 @@ const swapper: TypedSwapper<SupportedChains> = Factory.newSwapper({
|
|
|
122
122
|
rpcUrl: citreaRpc, //You can also pass JsonApiProvider object here
|
|
123
123
|
}
|
|
124
124
|
},
|
|
125
|
-
bitcoinNetwork: BitcoinNetwork.
|
|
125
|
+
bitcoinNetwork: BitcoinNetwork.MAINNET //or BitcoinNetwork.TESTNET3, BitcoinNetwork.TESTNET4 - this also sets the network to use for Solana (solana devnet for bitcoin testnet) & Starknet (sepolia for bitcoin testnet)
|
|
126
126
|
//The following lines are important for running on backend node.js,
|
|
127
127
|
// because the SDK by default uses browser's Indexed DB
|
|
128
128
|
swapStorage: chainId => new SqliteUnifiedStorage("CHAIN_"+chainId+".sqlite3"),
|
|
@@ -143,7 +143,7 @@ const wallet = new SolanaSigner(anchorWallet);
|
|
|
143
143
|
|
|
144
144
|
```typescript
|
|
145
145
|
import {WalletAccount} from "starknet";
|
|
146
|
-
import {
|
|
146
|
+
import {StarknetBrowserSigner} from "@atomiqlabs/chain-starknet";
|
|
147
147
|
//Browser, using get-starknet
|
|
148
148
|
const swo = await connect();
|
|
149
149
|
const wallet = new StarknetBrowserSigner(new WalletAccount(starknetRpc, swo.wallet));
|
|
@@ -1609,13 +1609,13 @@ Returns swaps that are ready to be claimed by the client, this can happen if cli
|
|
|
1609
1609
|
|
|
1610
1610
|
```typescript
|
|
1611
1611
|
//Get the swaps
|
|
1612
|
-
const claimableSolanaSwaps = await
|
|
1612
|
+
const claimableSolanaSwaps = await swapper.getClaimableSwaps("SOLANA", solanaSigner.getAddress());
|
|
1613
1613
|
//Claim all the claimable swaps
|
|
1614
1614
|
for(let swap of claimableSolanaSwaps) {
|
|
1615
1615
|
await swap.claim(solanaSigner);
|
|
1616
1616
|
}
|
|
1617
1617
|
//Get the swaps
|
|
1618
|
-
const claimableStarknetSwaps = await
|
|
1618
|
+
const claimableStarknetSwaps = await swapper.getClaimableSwaps("STARKNET", starknetSigner.getAddress());
|
|
1619
1619
|
//Claim all the claimable swaps
|
|
1620
1620
|
for(let swap of claimableStarknetSwaps) {
|
|
1621
1621
|
await swap.claim(starknetSigner);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum representing the side of the swap for querying available input/output tokens
|
|
3
|
+
*
|
|
4
|
+
* @category Core
|
|
5
|
+
*/
|
|
6
|
+
export declare enum SwapSide {
|
|
7
|
+
/**
|
|
8
|
+
* Represents input / source side of the swap
|
|
9
|
+
*/
|
|
10
|
+
INPUT = 1,
|
|
11
|
+
/**
|
|
12
|
+
* Represents output / destination side of the swap
|
|
13
|
+
*/
|
|
14
|
+
OUTPUT = 0
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwapSide = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing the side of the swap for querying available input/output tokens
|
|
6
|
+
*
|
|
7
|
+
* @category Core
|
|
8
|
+
*/
|
|
9
|
+
var SwapSide;
|
|
10
|
+
(function (SwapSide) {
|
|
11
|
+
/**
|
|
12
|
+
* Represents input / source side of the swap
|
|
13
|
+
*/
|
|
14
|
+
SwapSide[SwapSide["INPUT"] = 1] = "INPUT";
|
|
15
|
+
/**
|
|
16
|
+
* Represents output / destination side of the swap
|
|
17
|
+
*/
|
|
18
|
+
SwapSide[SwapSide["OUTPUT"] = 0] = "OUTPUT";
|
|
19
|
+
})(SwapSide = exports.SwapSide || (exports.SwapSide = {}));
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { CoinselectAddressTypes } from "./bitcoin/coinselect2";
|
|
|
8
8
|
export * from "./enums/FeeType";
|
|
9
9
|
export * from "./enums/SwapAmountType";
|
|
10
10
|
export * from "./enums/SwapDirection";
|
|
11
|
+
export * from "./enums/SwapSide";
|
|
11
12
|
export * from "./enums/SwapType";
|
|
12
13
|
export * from "./errors/IntermediaryError";
|
|
13
14
|
export * from "./errors/RequestError";
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,7 @@ __exportStar(require("./bitcoin/wallet/SingleAddressBitcoinWallet"), exports);
|
|
|
37
37
|
__exportStar(require("./enums/FeeType"), exports);
|
|
38
38
|
__exportStar(require("./enums/SwapAmountType"), exports);
|
|
39
39
|
__exportStar(require("./enums/SwapDirection"), exports);
|
|
40
|
+
__exportStar(require("./enums/SwapSide"), exports);
|
|
40
41
|
__exportStar(require("./enums/SwapType"), exports);
|
|
41
42
|
__exportStar(require("./errors/IntermediaryError"), exports);
|
|
42
43
|
__exportStar(require("./errors/RequestError"), exports);
|
|
@@ -169,9 +169,9 @@ export type FromBTCInit = BaseFromBTCSwapInit & {
|
|
|
169
169
|
sequence: bigint;
|
|
170
170
|
claimerBounty: Promise<{
|
|
171
171
|
feePerBlock: bigint;
|
|
172
|
-
safetyFactor:
|
|
172
|
+
safetyFactor: bigint;
|
|
173
173
|
startTimestamp: bigint;
|
|
174
|
-
addBlock:
|
|
174
|
+
addBlock: bigint;
|
|
175
175
|
addFee: bigint;
|
|
176
176
|
}>;
|
|
177
177
|
};
|
|
@@ -271,9 +271,9 @@ class IntermediaryAPI {
|
|
|
271
271
|
claimerBounty: init.claimerBounty.then(claimerBounty => {
|
|
272
272
|
return {
|
|
273
273
|
feePerBlock: claimerBounty.feePerBlock.toString(10),
|
|
274
|
-
safetyFactor: claimerBounty.safetyFactor,
|
|
274
|
+
safetyFactor: claimerBounty.safetyFactor.toString(10),
|
|
275
275
|
startTimestamp: claimerBounty.startTimestamp.toString(10),
|
|
276
|
-
addBlock: claimerBounty.addBlock,
|
|
276
|
+
addBlock: claimerBounty.addBlock.toString(10),
|
|
277
277
|
addFee: claimerBounty.addFee.toString(10)
|
|
278
278
|
};
|
|
279
279
|
}),
|
|
@@ -36,6 +36,7 @@ declare const indexes: readonly [{
|
|
|
36
36
|
* Simple index types for SDK swap storage
|
|
37
37
|
*
|
|
38
38
|
* @category Storage
|
|
39
|
+
* @useDeclaredType
|
|
39
40
|
*/
|
|
40
41
|
export type UnifiedSwapStorageIndexes = typeof indexes;
|
|
41
42
|
declare const compositeIndexes: readonly [{
|
|
@@ -55,6 +56,7 @@ declare const compositeIndexes: readonly [{
|
|
|
55
56
|
* Composite index types for SDK swap storage
|
|
56
57
|
*
|
|
57
58
|
* @category Storage
|
|
59
|
+
* @useDeclaredType
|
|
58
60
|
*/
|
|
59
61
|
export type UnifiedSwapStorageCompositeIndexes = typeof compositeIndexes;
|
|
60
62
|
/**
|
|
@@ -16,7 +16,6 @@ import { LnForGasWrapper } from "../swaps/trusted/ln/LnForGasWrapper";
|
|
|
16
16
|
import { LnForGasSwap } from "../swaps/trusted/ln/LnForGasSwap";
|
|
17
17
|
import { EventEmitter } from "events";
|
|
18
18
|
import { Intermediary } from "../intermediaries/Intermediary";
|
|
19
|
-
import { WrapperCtorTokens } from "../swaps/ISwapWrapper";
|
|
20
19
|
import { SwapperWithChain } from "./SwapperWithChain";
|
|
21
20
|
import { OnchainForGasSwap } from "../swaps/trusted/onchain/OnchainForGasSwap";
|
|
22
21
|
import { OnchainForGasWrapper } from "../swaps/trusted/onchain/OnchainForGasWrapper";
|
|
@@ -39,6 +38,7 @@ import { LNURLWithdraw } from "../types/lnurl/LNURLWithdraw";
|
|
|
39
38
|
import { LNURLPay } from "../types/lnurl/LNURLPay";
|
|
40
39
|
import { NotNever } from "../utils/TypeUtils";
|
|
41
40
|
import { LightningInvoiceCreateService } from "../types/wallets/LightningInvoiceCreateService";
|
|
41
|
+
import { SwapSide } from "../enums/SwapSide";
|
|
42
42
|
/**
|
|
43
43
|
* Configuration options for the Swapper
|
|
44
44
|
* @category Core
|
|
@@ -168,6 +168,17 @@ type MultiChainData<T extends MultiChain> = {
|
|
|
168
168
|
type CtorMultiChainData<T extends MultiChain> = {
|
|
169
169
|
[chainIdentifier in keyof T]: ChainData<T[chainIdentifier]>;
|
|
170
170
|
};
|
|
171
|
+
type SwapperCtorTokens<T extends MultiChain = MultiChain> = {
|
|
172
|
+
ticker: string;
|
|
173
|
+
name: string;
|
|
174
|
+
chains: {
|
|
175
|
+
[chainId in ChainIds<T>]?: {
|
|
176
|
+
address: string;
|
|
177
|
+
decimals: number;
|
|
178
|
+
displayDecimals?: number;
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
}[];
|
|
171
182
|
/**
|
|
172
183
|
* Type extracting chain identifiers from a MultiChain type
|
|
173
184
|
* @category Core
|
|
@@ -246,7 +257,7 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
246
257
|
/**
|
|
247
258
|
* @internal
|
|
248
259
|
*/
|
|
249
|
-
constructor(bitcoinRpc: BitcoinRpcWithAddressIndex<any>, lightningApi: LightningNetworkApi, bitcoinSynchronizer: (btcRelay: BtcRelay<any, any, any>) => RelaySynchronizer<any, any, any>, chainsData: CtorMultiChainData<T>, pricing: ISwapPrice<T>, tokens:
|
|
260
|
+
constructor(bitcoinRpc: BitcoinRpcWithAddressIndex<any>, lightningApi: LightningNetworkApi, bitcoinSynchronizer: (btcRelay: BtcRelay<any, any, any>) => RelaySynchronizer<any, any, any>, chainsData: CtorMultiChainData<T>, pricing: ISwapPrice<T>, tokens: SwapperCtorTokens<T>, messenger: Messenger, options?: SwapperOptions);
|
|
250
261
|
private _init;
|
|
251
262
|
private initPromise?;
|
|
252
263
|
private initialized;
|
|
@@ -459,25 +470,25 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
459
470
|
/**
|
|
460
471
|
* @internal
|
|
461
472
|
*/
|
|
462
|
-
swap<C extends ChainIds<T>>(srcToken: BtcToken<true
|
|
473
|
+
swap<C extends ChainIds<T>>(srcToken: BtcToken<true> | "BTCLN" | "BTC-LN" | "LIGHTNING-BTC", dstToken: SCToken<C> | string, amount: bigint | string, exactIn: boolean | SwapAmountType, src: undefined | string | LNURLWithdraw, dstSmartchainWallet: string, options?: (SupportsSwapType<T[C], SwapType.FROM_BTCLN_AUTO> extends true ? FromBTCLNAutoOptions : FromBTCLNOptions)): Promise<(SupportsSwapType<T[C], SwapType.FROM_BTCLN_AUTO> extends true ? FromBTCLNAutoSwap<T[C]> : FromBTCLNSwap<T[C]>)>;
|
|
463
474
|
/**
|
|
464
475
|
* @internal
|
|
465
476
|
*/
|
|
466
|
-
swap<C extends ChainIds<T>>(srcToken: BtcToken<false
|
|
477
|
+
swap<C extends ChainIds<T>>(srcToken: BtcToken<false> | "BTC" | "BITCOIN-BTC", dstToken: SCToken<C> | string, amount: bigint | string, exactIn: boolean | SwapAmountType, src: undefined | string, dstSmartchainWallet: string, options?: (SupportsSwapType<T[C], SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCOptions : FromBTCOptions)): Promise<(SupportsSwapType<T[C], SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCSwap<T[C]> : FromBTCSwap<T[C]>)>;
|
|
467
478
|
/**
|
|
468
479
|
* @internal
|
|
469
480
|
*/
|
|
470
|
-
swap<C extends ChainIds<T>>(srcToken: SCToken<C
|
|
481
|
+
swap<C extends ChainIds<T>>(srcToken: SCToken<C> | string, dstToken: BtcToken<false> | "BTC" | "BITCOIN-BTC", amount: bigint | string, exactIn: boolean | SwapAmountType, src: string, dstAddress: string, options?: ToBTCOptions): Promise<ToBTCSwap<T[C]>>;
|
|
471
482
|
/**
|
|
472
483
|
* @internal
|
|
473
484
|
*/
|
|
474
|
-
swap<C extends ChainIds<T>>(srcToken: SCToken<C
|
|
485
|
+
swap<C extends ChainIds<T>>(srcToken: SCToken<C> | string, dstToken: BtcToken<true> | "BTCLN" | "BTC-LN" | "LIGHTNING-BTC", amount: bigint | string, exactIn: boolean | SwapAmountType, src: string, dstLnurlPayOrInvoiceCreateService: string | LNURLPay | LightningInvoiceCreateService, options?: ToBTCLNOptions & {
|
|
475
486
|
comment?: string;
|
|
476
487
|
}): Promise<ToBTCLNSwap<T[C]>>;
|
|
477
488
|
/**
|
|
478
489
|
* @internal
|
|
479
490
|
*/
|
|
480
|
-
swap<C extends ChainIds<T>>(srcToken: SCToken<C
|
|
491
|
+
swap<C extends ChainIds<T>>(srcToken: SCToken<C> | string, dstToken: BtcToken<true> | "BTCLN" | "BTC-LN" | "LIGHTNING-BTC", amount: undefined, exactIn: false | SwapAmountType.EXACT_OUT, src: string, dstLightningInvoice: string, options?: ToBTCLNOptions): Promise<ToBTCLNSwap<T[C]>>;
|
|
481
492
|
/**
|
|
482
493
|
* Creates a swap from srcToken to dstToken, of a specific token amount, either specifying input amount (if `exactIn=true`)
|
|
483
494
|
* or output amount (if `exactIn=false`), NOTE: For regular Smart chain -> BTC-LN (lightning) swaps the passed amount is ignored and
|
|
@@ -576,14 +587,9 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
576
587
|
* initiated after this blockheight
|
|
577
588
|
*/
|
|
578
589
|
recoverSwaps<C extends ChainIds<T>>(chainId: C, signer: string, startBlockheight?: number): Promise<ISwap<T[C]>[]>;
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
* @param tickerOrAddress Token to return the object for, can use multiple formats:
|
|
583
|
-
* - a) token ticker, such as `"BTC"`, `"SOL"`, etc.
|
|
584
|
-
* - b) token ticker prefixed with smart chain identifier, such as `"SOLANA-SOL"`, `"SOLANA-USDC"`, etc.
|
|
585
|
-
* - c) token address
|
|
586
|
-
*/
|
|
590
|
+
getToken(ticker: "BTC" | "BITCOIN-BTC"): BtcToken<false>;
|
|
591
|
+
getToken(ticker: "BTCLN" | "BTC-LN" | "LIGHTNING-BTC"): BtcToken<true>;
|
|
592
|
+
getToken<ChainIdentifier extends ChainIds<T>>(ticker: `${ChainIdentifier}-${string}`): SCToken<ChainIdentifier>;
|
|
587
593
|
getToken(tickerOrAddress: string): Token<ChainIds<T>>;
|
|
588
594
|
/**
|
|
589
595
|
* Creates a child swapper instance with a given smart chain
|
|
@@ -650,12 +656,12 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
650
656
|
*/
|
|
651
657
|
getSwapLimits<C extends ChainIds<T>, A extends Token<C>, B extends Token<C>>(srcToken: A, dstToken: B): {
|
|
652
658
|
input: {
|
|
653
|
-
min: TokenAmount<
|
|
654
|
-
max?: TokenAmount<
|
|
659
|
+
min: TokenAmount<A>;
|
|
660
|
+
max?: TokenAmount<A>;
|
|
655
661
|
};
|
|
656
662
|
output: {
|
|
657
|
-
min: TokenAmount<
|
|
658
|
-
max?: TokenAmount<
|
|
663
|
+
min: TokenAmount<B>;
|
|
664
|
+
max?: TokenAmount<B>;
|
|
659
665
|
};
|
|
660
666
|
};
|
|
661
667
|
/**
|
|
@@ -663,7 +669,7 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
663
669
|
*
|
|
664
670
|
* @param input Whether to return input tokens or output tokens
|
|
665
671
|
*/
|
|
666
|
-
getSupportedTokens(input: boolean): Token[];
|
|
672
|
+
getSupportedTokens(input: SwapSide | boolean): Token[];
|
|
667
673
|
/**
|
|
668
674
|
* Returns a set of supported tokens by all the intermediaries offering a specific swap service
|
|
669
675
|
*
|
|
@@ -681,6 +687,6 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
681
687
|
* Returns tokens that you can swap to (if input=true) from a given token,
|
|
682
688
|
* or tokens that you can swap from (if input=false) to a given token
|
|
683
689
|
*/
|
|
684
|
-
getSwapCounterTokens(token: Token, input: boolean): Token[];
|
|
690
|
+
getSwapCounterTokens(token: Token, input: SwapSide | boolean): Token[];
|
|
685
691
|
}
|
|
686
692
|
export {};
|
package/dist/swapper/Swapper.js
CHANGED
|
@@ -92,7 +92,9 @@ class Swapper extends events_1.EventEmitter {
|
|
|
92
92
|
name: tokenData.name,
|
|
93
93
|
decimals: chainData.decimals,
|
|
94
94
|
displayDecimals: chainData.displayDecimals,
|
|
95
|
-
address: chainData.address
|
|
95
|
+
address: chainData.address,
|
|
96
|
+
equals: (other) => other.chainId === chainId && other.ticker === tokenData.ticker && other.address === chainData.address,
|
|
97
|
+
toString: () => `${chainId}-${tokenData.ticker}`
|
|
96
98
|
};
|
|
97
99
|
}
|
|
98
100
|
}
|
|
@@ -100,49 +102,49 @@ class Swapper extends events_1.EventEmitter {
|
|
|
100
102
|
this.emit("swapState", swap);
|
|
101
103
|
};
|
|
102
104
|
this._chains = (0, Utils_1.objectMap)(chainsData, (chainData, key) => {
|
|
103
|
-
const { swapContract, chainEvents, btcRelay, chainInterface, spvVaultContract, spvVaultWithdrawalDataConstructor } = chainData;
|
|
105
|
+
const { swapContract, chainEvents, btcRelay, chainInterface, spvVaultContract, spvVaultWithdrawalDataConstructor, chainId } = chainData;
|
|
104
106
|
const synchronizer = bitcoinSynchronizer(btcRelay);
|
|
105
|
-
const storageHandler = swapStorage(storagePrefix +
|
|
107
|
+
const storageHandler = swapStorage(storagePrefix + chainId);
|
|
106
108
|
const unifiedSwapStorage = new UnifiedSwapStorage_1.UnifiedSwapStorage(storageHandler, this.options.noSwapCache);
|
|
107
109
|
const unifiedChainEvents = new UnifiedSwapEventListener_1.UnifiedSwapEventListener(unifiedSwapStorage, chainEvents);
|
|
108
110
|
const wrappers = {};
|
|
109
|
-
wrappers[SwapType_1.SwapType.TO_BTCLN] = new ToBTCLNWrapper_1.ToBTCLNWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing,
|
|
111
|
+
wrappers[SwapType_1.SwapType.TO_BTCLN] = new ToBTCLNWrapper_1.ToBTCLNWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing, this._tokens[chainId], chainData.swapDataConstructor, {
|
|
110
112
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
111
113
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
112
114
|
});
|
|
113
|
-
wrappers[SwapType_1.SwapType.TO_BTC] = new ToBTCWrapper_1.ToBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing,
|
|
115
|
+
wrappers[SwapType_1.SwapType.TO_BTC] = new ToBTCWrapper_1.ToBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing, this._tokens[chainId], chainData.swapDataConstructor, this._bitcoinRpc, {
|
|
114
116
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
115
117
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
116
118
|
bitcoinNetwork: this._btcNetwork
|
|
117
119
|
});
|
|
118
|
-
wrappers[SwapType_1.SwapType.FROM_BTCLN] = new FromBTCLNWrapper_1.FromBTCLNWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing,
|
|
120
|
+
wrappers[SwapType_1.SwapType.FROM_BTCLN] = new FromBTCLNWrapper_1.FromBTCLNWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing, this._tokens[chainId], chainData.swapDataConstructor, lightningApi, {
|
|
119
121
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
120
122
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
121
123
|
unsafeSkipLnNodeCheck: this.bitcoinNetwork === base_1.BitcoinNetwork.TESTNET4 || this.bitcoinNetwork === base_1.BitcoinNetwork.REGTEST
|
|
122
124
|
});
|
|
123
|
-
wrappers[SwapType_1.SwapType.FROM_BTC] = new FromBTCWrapper_1.FromBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing,
|
|
125
|
+
wrappers[SwapType_1.SwapType.FROM_BTC] = new FromBTCWrapper_1.FromBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing, this._tokens[chainId], chainData.swapDataConstructor, btcRelay, synchronizer, this._bitcoinRpc, {
|
|
124
126
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
125
127
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
126
128
|
bitcoinNetwork: this._btcNetwork
|
|
127
129
|
});
|
|
128
|
-
wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTCLN] = new LnForGasWrapper_1.LnForGasWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing,
|
|
130
|
+
wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTCLN] = new LnForGasWrapper_1.LnForGasWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], {
|
|
129
131
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
130
132
|
postRequestTimeout: this.options.postRequestTimeout
|
|
131
133
|
});
|
|
132
|
-
wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTC] = new OnchainForGasWrapper_1.OnchainForGasWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing,
|
|
134
|
+
wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTC] = new OnchainForGasWrapper_1.OnchainForGasWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], bitcoinRpc, {
|
|
133
135
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
134
136
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
135
137
|
bitcoinNetwork: this._btcNetwork
|
|
136
138
|
});
|
|
137
139
|
if (spvVaultContract != null) {
|
|
138
|
-
wrappers[SwapType_1.SwapType.SPV_VAULT_FROM_BTC] = new SpvFromBTCWrapper_1.SpvFromBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, spvVaultContract, pricing,
|
|
140
|
+
wrappers[SwapType_1.SwapType.SPV_VAULT_FROM_BTC] = new SpvFromBTCWrapper_1.SpvFromBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, spvVaultContract, pricing, this._tokens[chainId], spvVaultWithdrawalDataConstructor, btcRelay, synchronizer, bitcoinRpc, {
|
|
139
141
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
140
142
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
141
143
|
bitcoinNetwork: this._btcNetwork
|
|
142
144
|
});
|
|
143
145
|
}
|
|
144
146
|
if (swapContract.supportsInitWithoutClaimer) {
|
|
145
|
-
wrappers[SwapType_1.SwapType.FROM_BTCLN_AUTO] = new FromBTCLNAutoWrapper_1.FromBTCLNAutoWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing,
|
|
147
|
+
wrappers[SwapType_1.SwapType.FROM_BTCLN_AUTO] = new FromBTCLNAutoWrapper_1.FromBTCLNAutoWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing, this._tokens[chainId], chainData.swapDataConstructor, lightningApi, this.messenger, {
|
|
146
148
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
147
149
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
148
150
|
unsafeSkipLnNodeCheck: this.bitcoinNetwork === base_1.BitcoinNetwork.TESTNET4 || this.bitcoinNetwork === base_1.BitcoinNetwork.REGTEST
|
|
@@ -478,9 +480,6 @@ class Swapper extends events_1.EventEmitter {
|
|
|
478
480
|
if (!this._chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
|
|
479
481
|
throw new Error("Invalid " + chainIdentifier + " address");
|
|
480
482
|
signer = this._chains[chainIdentifier].chainInterface.normalizeAddress(signer);
|
|
481
|
-
options ??= {};
|
|
482
|
-
options.confirmationTarget ??= 3;
|
|
483
|
-
options.confirmations ??= 2;
|
|
484
483
|
const amountData = {
|
|
485
484
|
amount,
|
|
486
485
|
token: tokenAddress,
|
|
@@ -502,7 +501,6 @@ class Swapper extends events_1.EventEmitter {
|
|
|
502
501
|
async createToBTCLNSwap(chainIdentifier, signer, tokenAddress, paymentRequest, additionalParams = this.options.defaultAdditionalParameters, options) {
|
|
503
502
|
if (this._chains[chainIdentifier] == null)
|
|
504
503
|
throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
|
|
505
|
-
options ??= {};
|
|
506
504
|
if (paymentRequest.startsWith("lightning:"))
|
|
507
505
|
paymentRequest = paymentRequest.substring(10);
|
|
508
506
|
if (!this.Utils.isValidLightningInvoice(paymentRequest))
|
|
@@ -518,7 +516,6 @@ class Swapper extends events_1.EventEmitter {
|
|
|
518
516
|
token: tokenAddress,
|
|
519
517
|
exactIn: false
|
|
520
518
|
};
|
|
521
|
-
options.expirySeconds ??= 5 * 24 * 3600;
|
|
522
519
|
return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => chain.wrappers[SwapType_1.SwapType.TO_BTCLN].create(signer, paymentRequest, amountData, candidates, options, additionalParams, abortSignal), amountData, SwapType_1.SwapType.TO_BTCLN);
|
|
523
520
|
}
|
|
524
521
|
/**
|
|
@@ -546,8 +543,6 @@ class Swapper extends events_1.EventEmitter {
|
|
|
546
543
|
token: tokenAddress,
|
|
547
544
|
exactIn
|
|
548
545
|
};
|
|
549
|
-
options ??= {};
|
|
550
|
-
options.expirySeconds ??= 5 * 24 * 3600;
|
|
551
546
|
return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => chain.wrappers[SwapType_1.SwapType.TO_BTCLN].createViaLNURL(signer, typeof (lnurlPay) === "string" ? (lnurlPay.startsWith("lightning:") ? lnurlPay.substring(10) : lnurlPay) : lnurlPay.params, amountData, candidates, options, additionalParams, abortSignal), amountData, SwapType_1.SwapType.TO_BTCLN);
|
|
552
547
|
}
|
|
553
548
|
/**
|
|
@@ -568,13 +563,11 @@ class Swapper extends events_1.EventEmitter {
|
|
|
568
563
|
if (!this._chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
|
|
569
564
|
throw new Error("Invalid " + chainIdentifier + " address");
|
|
570
565
|
signer = this._chains[chainIdentifier].chainInterface.normalizeAddress(signer);
|
|
571
|
-
options ??= {};
|
|
572
566
|
const amountData = {
|
|
573
567
|
amount,
|
|
574
568
|
token: tokenAddress,
|
|
575
569
|
exactIn
|
|
576
570
|
};
|
|
577
|
-
options.expirySeconds ??= 5 * 24 * 3600;
|
|
578
571
|
return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => chain.wrappers[SwapType_1.SwapType.TO_BTCLN].createViaInvoiceCreateService(signer, Promise.resolve(service), amountData, candidates, options, additionalParams, abortSignal), amountData, SwapType_1.SwapType.TO_BTCLN);
|
|
579
572
|
}
|
|
580
573
|
/**
|
|
@@ -809,8 +802,8 @@ class Swapper extends events_1.EventEmitter {
|
|
|
809
802
|
const srcToken = typeof (_srcToken) === "string" ? this.getToken(_srcToken) : _srcToken;
|
|
810
803
|
const dstToken = typeof (_dstToken) === "string" ? this.getToken(_dstToken) : _dstToken;
|
|
811
804
|
const amount = _amount == null ? null : (typeof (_amount) === "bigint" ? _amount : (0, Utils_1.fromDecimal)(_amount, exactIn ? srcToken.decimals : dstToken.decimals));
|
|
812
|
-
if (
|
|
813
|
-
if (
|
|
805
|
+
if ((0, Token_1.isBtcToken)(srcToken)) {
|
|
806
|
+
if ((0, Token_1.isSCToken)(dstToken)) {
|
|
814
807
|
if (typeof (dst) !== "string")
|
|
815
808
|
throw new Error("Destination for BTC/BTC-LN -> smart chain swaps must be a smart chain address!");
|
|
816
809
|
if (amount == null)
|
|
@@ -841,8 +834,8 @@ class Swapper extends events_1.EventEmitter {
|
|
|
841
834
|
}
|
|
842
835
|
}
|
|
843
836
|
}
|
|
844
|
-
else {
|
|
845
|
-
if (
|
|
837
|
+
else if ((0, Token_1.isSCToken)(srcToken)) {
|
|
838
|
+
if ((0, Token_1.isBtcToken)(dstToken)) {
|
|
846
839
|
if (typeof (src) !== "string")
|
|
847
840
|
throw new Error("Source address for BTC/BTC-LN -> smart chain swaps must be a smart chain address!");
|
|
848
841
|
if (dstToken.lightning) {
|
|
@@ -1305,9 +1298,9 @@ class Swapper extends events_1.EventEmitter {
|
|
|
1305
1298
|
*/
|
|
1306
1299
|
getToken(tickerOrAddress) {
|
|
1307
1300
|
//Btc tokens - BTC, BTCLN, BTC-LN
|
|
1308
|
-
if (tickerOrAddress === "BTC")
|
|
1301
|
+
if (tickerOrAddress === "BTC" || tickerOrAddress === "BITCOIN-BTC")
|
|
1309
1302
|
return Token_1.BitcoinTokens.BTC;
|
|
1310
|
-
if (tickerOrAddress === "BTCLN" || tickerOrAddress === "BTC-LN")
|
|
1303
|
+
if (tickerOrAddress === "BTCLN" || tickerOrAddress === "BTC-LN" || tickerOrAddress === "LIGHTNING-BTC")
|
|
1311
1304
|
return Token_1.BitcoinTokens.BTCLN;
|
|
1312
1305
|
//Check if the ticker is in format <chainId>-<ticker>, i.e. SOLANA-USDC, STARKNET-WBTC
|
|
1313
1306
|
if (tickerOrAddress.includes("-")) {
|
|
@@ -29,6 +29,7 @@ import { LNURLPay } from "../types/lnurl/LNURLPay";
|
|
|
29
29
|
import { LightningInvoiceCreateService } from "../types/wallets/LightningInvoiceCreateService";
|
|
30
30
|
import { Intermediary } from "../intermediaries/Intermediary";
|
|
31
31
|
import { SwapTypeMapping } from "../utils/SwapUtils";
|
|
32
|
+
import { SwapSide } from "../enums/SwapSide";
|
|
32
33
|
/**
|
|
33
34
|
* Chain-specific wrapper around Swapper for a particular blockchain
|
|
34
35
|
*
|
|
@@ -244,25 +245,25 @@ export declare class SwapperWithChain<T extends MultiChain, ChainIdentifier exte
|
|
|
244
245
|
/**
|
|
245
246
|
* @internal
|
|
246
247
|
*/
|
|
247
|
-
swap(srcToken: BtcToken<true
|
|
248
|
+
swap(srcToken: BtcToken<true> | "BTCLN" | "BTC-LN" | "LIGHTNING-BTC", dstToken: SCToken<ChainIdentifier>, amount: bigint | string, exactIn: boolean | SwapAmountType, src: undefined | string | LNURLWithdraw, dstSmartchainWallet: string, options?: (SupportsSwapType<T[ChainIdentifier], SwapType.FROM_BTCLN_AUTO> extends true ? FromBTCLNAutoOptions : FromBTCLNOptions)): Promise<SupportsSwapType<T[ChainIdentifier], SwapType.FROM_BTCLN_AUTO> extends true ? FromBTCLNAutoSwap<T[ChainIdentifier]> : FromBTCLNSwap<T[ChainIdentifier]>>;
|
|
248
249
|
/**
|
|
249
250
|
* @internal
|
|
250
251
|
*/
|
|
251
|
-
swap(srcToken: BtcToken<false
|
|
252
|
+
swap(srcToken: BtcToken<false> | "BTC" | "BITCOIN-BTC", dstToken: SCToken<ChainIdentifier>, amount: bigint | string, exactIn: boolean | SwapAmountType, src: undefined | string, dstSmartchainWallet: string, options?: (SupportsSwapType<T[ChainIdentifier], SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCOptions : FromBTCOptions)): Promise<(SupportsSwapType<T[ChainIdentifier], SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCSwap<T[ChainIdentifier]> : FromBTCSwap<T[ChainIdentifier]>)>;
|
|
252
253
|
/**
|
|
253
254
|
* @internal
|
|
254
255
|
*/
|
|
255
|
-
swap(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<false
|
|
256
|
+
swap(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<false> | "BTC" | "BITCOIN-BTC", amount: bigint | string, exactIn: boolean | SwapAmountType, src: string, dstAddress: string, options?: ToBTCOptions): Promise<ToBTCSwap<T[ChainIdentifier]>>;
|
|
256
257
|
/**
|
|
257
258
|
* @internal
|
|
258
259
|
*/
|
|
259
|
-
swap(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true
|
|
260
|
+
swap(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true> | "BTCLN" | "BTC-LN" | "LIGHTNING-BTC", amount: bigint | string, exactIn: boolean | SwapAmountType, src: string, dstLnurlPayOrInvoiceCreateService: string | LNURLPay | LightningInvoiceCreateService, options?: ToBTCLNOptions & {
|
|
260
261
|
comment?: string;
|
|
261
262
|
}): Promise<ToBTCLNSwap<T[ChainIdentifier]>>;
|
|
262
263
|
/**
|
|
263
264
|
* @internal
|
|
264
265
|
*/
|
|
265
|
-
swap(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true
|
|
266
|
+
swap(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true> | "BTCLN" | "BTC-LN" | "LIGHTNING-BTC", amount: undefined, exactIn: false | SwapAmountType.EXACT_OUT, src: string, dstLightningInvoice: string, options?: ToBTCLNOptions): Promise<ToBTCLNSwap<T[ChainIdentifier]>>;
|
|
266
267
|
/**
|
|
267
268
|
* Creates a swap from srcToken to dstToken, of a specific token amount, either specifying input amount (exactIn=true)
|
|
268
269
|
* or output amount (exactIn=false), NOTE: For regular SmartChain -> BTC-LN (lightning) swaps the passed amount is ignored and
|
|
@@ -328,14 +329,9 @@ export declare class SwapperWithChain<T extends MultiChain, ChainIdentifier exte
|
|
|
328
329
|
* initiated after this blockheight
|
|
329
330
|
*/
|
|
330
331
|
recoverSwaps(signer: string, startBlockheight?: number): Promise<ISwap<T[ChainIdentifier]>[]>;
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
* @param tickerOrAddress Token to return the object for, can use multiple formats:
|
|
335
|
-
* - a) token ticker, such as `"BTC"`, `"SOL"`, etc.
|
|
336
|
-
* - b) token ticker prefixed with smart chain identifier, such as `"SOLANA-SOL"`, `"SOLANA-USDC"`, etc.
|
|
337
|
-
* - c) token address
|
|
338
|
-
*/
|
|
332
|
+
getToken(ticker: "BTC" | "BITCOIN-BTC"): BtcToken<false>;
|
|
333
|
+
getToken(ticker: "BTCLN" | "BTC-LN" | "LIGHTNING-BTC"): BtcToken<true>;
|
|
334
|
+
getToken(ticker: `${ChainIdentifier}-${string}`): SCToken<ChainIdentifier>;
|
|
339
335
|
getToken(tickerOrAddress: string): Token<ChainIdentifier>;
|
|
340
336
|
/**
|
|
341
337
|
* Returns whether the SDK supports a given swap type on this chain based on currently known LPs
|
|
@@ -374,12 +370,12 @@ export declare class SwapperWithChain<T extends MultiChain, ChainIdentifier exte
|
|
|
374
370
|
*/
|
|
375
371
|
getSwapLimits<A extends Token<ChainIdentifier>, B extends Token<ChainIdentifier>>(srcToken: A, dstToken: B): {
|
|
376
372
|
input: {
|
|
377
|
-
min: TokenAmount<
|
|
378
|
-
max?: TokenAmount<
|
|
373
|
+
min: TokenAmount<A>;
|
|
374
|
+
max?: TokenAmount<A>;
|
|
379
375
|
};
|
|
380
376
|
output: {
|
|
381
|
-
min: TokenAmount<
|
|
382
|
-
max?: TokenAmount<
|
|
377
|
+
min: TokenAmount<B>;
|
|
378
|
+
max?: TokenAmount<B>;
|
|
383
379
|
};
|
|
384
380
|
};
|
|
385
381
|
/**
|
|
@@ -398,7 +394,7 @@ export declare class SwapperWithChain<T extends MultiChain, ChainIdentifier exte
|
|
|
398
394
|
* Returns tokens that you can swap to (if input=true) from a given token,
|
|
399
395
|
* or tokens that you can swap from (if input=false) to a given token
|
|
400
396
|
*/
|
|
401
|
-
getSwapCounterTokens(token: Token, input: boolean): Token<ChainIdentifier>[];
|
|
397
|
+
getSwapCounterTokens(token: Token, input: SwapSide | boolean): Token<ChainIdentifier>[];
|
|
402
398
|
/**
|
|
403
399
|
* Creates a child swapper instance with a signer
|
|
404
400
|
*
|
|
@@ -315,9 +315,9 @@ class SwapperWithChain {
|
|
|
315
315
|
*/
|
|
316
316
|
getToken(tickerOrAddress) {
|
|
317
317
|
//Btc tokens - BTC, BTCLN, BTC-LN
|
|
318
|
-
if (tickerOrAddress === "BTC")
|
|
318
|
+
if (tickerOrAddress === "BTC" || tickerOrAddress === "BITCOIN-BTC")
|
|
319
319
|
return Token_1.BitcoinTokens.BTC;
|
|
320
|
-
if (tickerOrAddress === "BTCLN" || tickerOrAddress === "BTC-LN")
|
|
320
|
+
if (tickerOrAddress === "BTCLN" || tickerOrAddress === "BTC-LN" || tickerOrAddress === "LIGHTNING-BTC")
|
|
321
321
|
return Token_1.BitcoinTokens.BTCLN;
|
|
322
322
|
//Check if the ticker is in format <chainId>-<ticker>, i.e. SOLANA-USDC, STARKNET-WBTC
|
|
323
323
|
if (tickerOrAddress.includes("-")) {
|
|
@@ -28,6 +28,7 @@ import { LightningInvoiceCreateService } from "../types/wallets/LightningInvoice
|
|
|
28
28
|
import { Intermediary } from "../intermediaries/Intermediary";
|
|
29
29
|
import { SpvFromBTCOptions } from "../swaps/spv_swaps/SpvFromBTCWrapper";
|
|
30
30
|
import { SwapTypeMapping } from "../utils/SwapUtils";
|
|
31
|
+
import { SwapSide } from "../enums/SwapSide";
|
|
31
32
|
/**
|
|
32
33
|
* Chain and signer-specific wrapper for automatic signer injection into swap methods
|
|
33
34
|
* @category Core
|
|
@@ -264,14 +265,9 @@ export declare class SwapperWithSigner<T extends MultiChain, ChainIdentifier ext
|
|
|
264
265
|
* initiated after this blockheight
|
|
265
266
|
*/
|
|
266
267
|
recoverSwaps(startBlockheight?: number): Promise<ISwap<T[ChainIdentifier]>[]>;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
* @param tickerOrAddress Token to return the object for, can use multiple formats:
|
|
271
|
-
* - a) token ticker, such as `"BTC"`, `"SOL"`, etc.
|
|
272
|
-
* - b) token ticker prefixed with smart chain identifier, such as `"SOLANA-SOL"`, `"SOLANA-USDC"`, etc.
|
|
273
|
-
* - c) token address
|
|
274
|
-
*/
|
|
268
|
+
getToken(ticker: "BTC" | "BITCOIN-BTC"): BtcToken<false>;
|
|
269
|
+
getToken(ticker: "BTCLN" | "BTC-LN" | "LIGHTNING-BTC"): BtcToken<true>;
|
|
270
|
+
getToken(ticker: `${ChainIdentifier}-${string}`): SCToken<ChainIdentifier>;
|
|
275
271
|
getToken(tickerOrAddress: string): Token<ChainIdentifier>;
|
|
276
272
|
/**
|
|
277
273
|
* Returns whether the SDK supports a given swap type on this chain based on currently known LPs
|
|
@@ -310,17 +306,17 @@ export declare class SwapperWithSigner<T extends MultiChain, ChainIdentifier ext
|
|
|
310
306
|
*/
|
|
311
307
|
getSwapLimits<A extends Token<ChainIdentifier>, B extends Token<ChainIdentifier>>(srcToken: A, dstToken: B): {
|
|
312
308
|
input: {
|
|
313
|
-
min: TokenAmount<
|
|
314
|
-
max?: TokenAmount<
|
|
309
|
+
min: TokenAmount<A>;
|
|
310
|
+
max?: TokenAmount<A>;
|
|
315
311
|
};
|
|
316
312
|
output: {
|
|
317
|
-
min: TokenAmount<
|
|
318
|
-
max?: TokenAmount<
|
|
313
|
+
min: TokenAmount<B>;
|
|
314
|
+
max?: TokenAmount<B>;
|
|
319
315
|
};
|
|
320
316
|
};
|
|
321
317
|
/**
|
|
322
318
|
* Returns tokens that you can swap to (if input=true) from a given token,
|
|
323
319
|
* or tokens that you can swap from (if input=false) to a given token
|
|
324
320
|
*/
|
|
325
|
-
getSwapCounterTokens(token: Token, input: boolean): Token<ChainIdentifier>[];
|
|
321
|
+
getSwapCounterTokens(token: Token, input: SwapSide | boolean): Token<ChainIdentifier>[];
|
|
326
322
|
}
|
|
@@ -48,7 +48,7 @@ export interface IBTCWalletSwap {
|
|
|
48
48
|
* @param wallet Sender's bitcoin wallet
|
|
49
49
|
* @param feeRate Optional fee rate in sats/vB for the transaction
|
|
50
50
|
*/
|
|
51
|
-
estimateBitcoinFee(wallet: IBitcoinWallet | MinimalBitcoinWalletInterface, feeRate?: number): Promise<TokenAmount<
|
|
51
|
+
estimateBitcoinFee(wallet: IBitcoinWallet | MinimalBitcoinWalletInterface, feeRate?: number): Promise<TokenAmount<BtcToken<false>> | null>;
|
|
52
52
|
/**
|
|
53
53
|
* Sends a swap bitcoin transaction via the passed bitcoin wallet
|
|
54
54
|
*
|
package/dist/swaps/ISwap.js
CHANGED
|
@@ -105,6 +105,8 @@ class ISwap {
|
|
|
105
105
|
* @internal
|
|
106
106
|
*/
|
|
107
107
|
waitTillState(targetState, type = "eq", abortSignal) {
|
|
108
|
+
//TODO: This doesn't hold strong reference to the swap, hence if no other strong reference to the
|
|
109
|
+
// swap exists, it will just never resolve!
|
|
108
110
|
return new Promise((resolve, reject) => {
|
|
109
111
|
let listener;
|
|
110
112
|
listener = (swap) => {
|
|
@@ -17,5 +17,5 @@ export interface ISwapWithGasDrop<T extends ChainType> {
|
|
|
17
17
|
* Returns the output of the "gas drop", additional native token received by the user on
|
|
18
18
|
* the destination chain
|
|
19
19
|
*/
|
|
20
|
-
getGasDropOutput(): TokenAmount<
|
|
20
|
+
getGasDropOutput(): TokenAmount<SCToken<T["ChainId"]>>;
|
|
21
21
|
}
|