@atomiqlabs/sdk 8.4.4 → 8.6.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 +36 -24
- package/dist/swapper/Swapper.js +20 -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 +4 -2
- 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 +13 -17
- 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 +8 -6
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +12 -3
- 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 +56 -40
- 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 +5 -3
- 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 +57 -21
- 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 +21 -9
- 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
|
|
@@ -123,9 +123,15 @@ export type SwapperOptions = {
|
|
|
123
123
|
*/
|
|
124
124
|
dontFetchLPs?: boolean;
|
|
125
125
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
126
|
+
* Defaults to `true`, this means every swap regardless of it being initiated (i.e. when `commit()`, `execute()` or
|
|
127
|
+
* `waitTillPayment` is called) is saved to the persistent storage. This is a reasonable default for when you
|
|
128
|
+
* want to only create a swap, and then later on retrieve it with the `swapper.getSwapById()` function.
|
|
129
|
+
*
|
|
130
|
+
* Setting this to `false` means the SDK only saves and persists swaps that are considered initiated, i.e. when
|
|
131
|
+
* `commit()`, `execute()` or `waitTillPayment` is called (or their respective txs... prefixed variations). This
|
|
132
|
+
* might save calls to the persistent storage for swaps that are never initiated. This is useful in e.g.
|
|
133
|
+
* frontend implementations where the frontend holds the swap object reference until it is initiated anyway, not
|
|
134
|
+
* necessitating the saving of the swap data to the persistent storage until it is actually initiated.
|
|
129
135
|
*/
|
|
130
136
|
saveUninitializedSwaps?: boolean;
|
|
131
137
|
/**
|
|
@@ -168,6 +174,17 @@ type MultiChainData<T extends MultiChain> = {
|
|
|
168
174
|
type CtorMultiChainData<T extends MultiChain> = {
|
|
169
175
|
[chainIdentifier in keyof T]: ChainData<T[chainIdentifier]>;
|
|
170
176
|
};
|
|
177
|
+
type SwapperCtorTokens<T extends MultiChain = MultiChain> = {
|
|
178
|
+
ticker: string;
|
|
179
|
+
name: string;
|
|
180
|
+
chains: {
|
|
181
|
+
[chainId in ChainIds<T>]?: {
|
|
182
|
+
address: string;
|
|
183
|
+
decimals: number;
|
|
184
|
+
displayDecimals?: number;
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
}[];
|
|
171
188
|
/**
|
|
172
189
|
* Type extracting chain identifiers from a MultiChain type
|
|
173
190
|
* @category Core
|
|
@@ -246,7 +263,7 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
246
263
|
/**
|
|
247
264
|
* @internal
|
|
248
265
|
*/
|
|
249
|
-
constructor(bitcoinRpc: BitcoinRpcWithAddressIndex<any>, lightningApi: LightningNetworkApi, bitcoinSynchronizer: (btcRelay: BtcRelay<any, any, any>) => RelaySynchronizer<any, any, any>, chainsData: CtorMultiChainData<T>, pricing: ISwapPrice<T>, tokens:
|
|
266
|
+
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
267
|
private _init;
|
|
251
268
|
private initPromise?;
|
|
252
269
|
private initialized;
|
|
@@ -459,25 +476,25 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
459
476
|
/**
|
|
460
477
|
* @internal
|
|
461
478
|
*/
|
|
462
|
-
swap<C extends ChainIds<T>>(srcToken: BtcToken<true
|
|
479
|
+
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
480
|
/**
|
|
464
481
|
* @internal
|
|
465
482
|
*/
|
|
466
|
-
swap<C extends ChainIds<T>>(srcToken: BtcToken<false
|
|
483
|
+
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
484
|
/**
|
|
468
485
|
* @internal
|
|
469
486
|
*/
|
|
470
|
-
swap<C extends ChainIds<T>>(srcToken: SCToken<C
|
|
487
|
+
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
488
|
/**
|
|
472
489
|
* @internal
|
|
473
490
|
*/
|
|
474
|
-
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: bigint | string, exactIn: boolean | SwapAmountType, src: string, dstLnurlPayOrInvoiceCreateService: string | LNURLPay | LightningInvoiceCreateService, options?: ToBTCLNOptions & {
|
|
475
492
|
comment?: string;
|
|
476
493
|
}): Promise<ToBTCLNSwap<T[C]>>;
|
|
477
494
|
/**
|
|
478
495
|
* @internal
|
|
479
496
|
*/
|
|
480
|
-
swap<C extends ChainIds<T>>(srcToken: SCToken<C
|
|
497
|
+
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
498
|
/**
|
|
482
499
|
* Creates a swap from srcToken to dstToken, of a specific token amount, either specifying input amount (if `exactIn=true`)
|
|
483
500
|
* or output amount (if `exactIn=false`), NOTE: For regular Smart chain -> BTC-LN (lightning) swaps the passed amount is ignored and
|
|
@@ -576,14 +593,9 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
576
593
|
* initiated after this blockheight
|
|
577
594
|
*/
|
|
578
595
|
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
|
-
*/
|
|
596
|
+
getToken(ticker: "BTC" | "BITCOIN-BTC"): BtcToken<false>;
|
|
597
|
+
getToken(ticker: "BTCLN" | "BTC-LN" | "LIGHTNING-BTC"): BtcToken<true>;
|
|
598
|
+
getToken<ChainIdentifier extends ChainIds<T>>(ticker: `${ChainIdentifier}-${string}`): SCToken<ChainIdentifier>;
|
|
587
599
|
getToken(tickerOrAddress: string): Token<ChainIds<T>>;
|
|
588
600
|
/**
|
|
589
601
|
* Creates a child swapper instance with a given smart chain
|
|
@@ -650,12 +662,12 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
650
662
|
*/
|
|
651
663
|
getSwapLimits<C extends ChainIds<T>, A extends Token<C>, B extends Token<C>>(srcToken: A, dstToken: B): {
|
|
652
664
|
input: {
|
|
653
|
-
min: TokenAmount<
|
|
654
|
-
max?: TokenAmount<
|
|
665
|
+
min: TokenAmount<A>;
|
|
666
|
+
max?: TokenAmount<A>;
|
|
655
667
|
};
|
|
656
668
|
output: {
|
|
657
|
-
min: TokenAmount<
|
|
658
|
-
max?: TokenAmount<
|
|
669
|
+
min: TokenAmount<B>;
|
|
670
|
+
max?: TokenAmount<B>;
|
|
659
671
|
};
|
|
660
672
|
};
|
|
661
673
|
/**
|
|
@@ -663,7 +675,7 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
663
675
|
*
|
|
664
676
|
* @param input Whether to return input tokens or output tokens
|
|
665
677
|
*/
|
|
666
|
-
getSupportedTokens(input: boolean): Token[];
|
|
678
|
+
getSupportedTokens(input: SwapSide | boolean): Token[];
|
|
667
679
|
/**
|
|
668
680
|
* Returns a set of supported tokens by all the intermediaries offering a specific swap service
|
|
669
681
|
*
|
|
@@ -681,6 +693,6 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
681
693
|
* Returns tokens that you can swap to (if input=true) from a given token,
|
|
682
694
|
* or tokens that you can swap from (if input=false) to a given token
|
|
683
695
|
*/
|
|
684
|
-
getSwapCounterTokens(token: Token, input: boolean): Token[];
|
|
696
|
+
getSwapCounterTokens(token: Token, input: SwapSide | boolean): Token[];
|
|
685
697
|
}
|
|
686
698
|
export {};
|
package/dist/swapper/Swapper.js
CHANGED
|
@@ -63,6 +63,7 @@ class Swapper extends events_1.EventEmitter {
|
|
|
63
63
|
this.SwapTypeInfo = SwapUtils_1.SwapProtocolInfo;
|
|
64
64
|
const storagePrefix = options?.storagePrefix ?? "atomiq-";
|
|
65
65
|
options ??= {};
|
|
66
|
+
options.saveUninitializedSwaps ??= true;
|
|
66
67
|
options.bitcoinNetwork = options.bitcoinNetwork == null ? base_1.BitcoinNetwork.TESTNET : options.bitcoinNetwork;
|
|
67
68
|
const swapStorage = options.swapStorage ??= (name) => new IndexedDBUnifiedStorage_1.IndexedDBUnifiedStorage(name);
|
|
68
69
|
this.options = options;
|
|
@@ -92,7 +93,9 @@ class Swapper extends events_1.EventEmitter {
|
|
|
92
93
|
name: tokenData.name,
|
|
93
94
|
decimals: chainData.decimals,
|
|
94
95
|
displayDecimals: chainData.displayDecimals,
|
|
95
|
-
address: chainData.address
|
|
96
|
+
address: chainData.address,
|
|
97
|
+
equals: (other) => other.chainId === chainId && other.ticker === tokenData.ticker && other.address === chainData.address,
|
|
98
|
+
toString: () => `${chainId}-${tokenData.ticker}`
|
|
96
99
|
};
|
|
97
100
|
}
|
|
98
101
|
}
|
|
@@ -100,49 +103,49 @@ class Swapper extends events_1.EventEmitter {
|
|
|
100
103
|
this.emit("swapState", swap);
|
|
101
104
|
};
|
|
102
105
|
this._chains = (0, Utils_1.objectMap)(chainsData, (chainData, key) => {
|
|
103
|
-
const { swapContract, chainEvents, btcRelay, chainInterface, spvVaultContract, spvVaultWithdrawalDataConstructor } = chainData;
|
|
106
|
+
const { swapContract, chainEvents, btcRelay, chainInterface, spvVaultContract, spvVaultWithdrawalDataConstructor, chainId } = chainData;
|
|
104
107
|
const synchronizer = bitcoinSynchronizer(btcRelay);
|
|
105
|
-
const storageHandler = swapStorage(storagePrefix +
|
|
108
|
+
const storageHandler = swapStorage(storagePrefix + chainId);
|
|
106
109
|
const unifiedSwapStorage = new UnifiedSwapStorage_1.UnifiedSwapStorage(storageHandler, this.options.noSwapCache);
|
|
107
110
|
const unifiedChainEvents = new UnifiedSwapEventListener_1.UnifiedSwapEventListener(unifiedSwapStorage, chainEvents);
|
|
108
111
|
const wrappers = {};
|
|
109
|
-
wrappers[SwapType_1.SwapType.TO_BTCLN] = new ToBTCLNWrapper_1.ToBTCLNWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing,
|
|
112
|
+
wrappers[SwapType_1.SwapType.TO_BTCLN] = new ToBTCLNWrapper_1.ToBTCLNWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing, this._tokens[chainId], chainData.swapDataConstructor, {
|
|
110
113
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
111
114
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
112
115
|
});
|
|
113
|
-
wrappers[SwapType_1.SwapType.TO_BTC] = new ToBTCWrapper_1.ToBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing,
|
|
116
|
+
wrappers[SwapType_1.SwapType.TO_BTC] = new ToBTCWrapper_1.ToBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing, this._tokens[chainId], chainData.swapDataConstructor, this._bitcoinRpc, {
|
|
114
117
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
115
118
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
116
119
|
bitcoinNetwork: this._btcNetwork
|
|
117
120
|
});
|
|
118
|
-
wrappers[SwapType_1.SwapType.FROM_BTCLN] = new FromBTCLNWrapper_1.FromBTCLNWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing,
|
|
121
|
+
wrappers[SwapType_1.SwapType.FROM_BTCLN] = new FromBTCLNWrapper_1.FromBTCLNWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing, this._tokens[chainId], chainData.swapDataConstructor, lightningApi, {
|
|
119
122
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
120
123
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
121
124
|
unsafeSkipLnNodeCheck: this.bitcoinNetwork === base_1.BitcoinNetwork.TESTNET4 || this.bitcoinNetwork === base_1.BitcoinNetwork.REGTEST
|
|
122
125
|
});
|
|
123
|
-
wrappers[SwapType_1.SwapType.FROM_BTC] = new FromBTCWrapper_1.FromBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing,
|
|
126
|
+
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
127
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
125
128
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
126
129
|
bitcoinNetwork: this._btcNetwork
|
|
127
130
|
});
|
|
128
|
-
wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTCLN] = new LnForGasWrapper_1.LnForGasWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing,
|
|
131
|
+
wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTCLN] = new LnForGasWrapper_1.LnForGasWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], {
|
|
129
132
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
130
133
|
postRequestTimeout: this.options.postRequestTimeout
|
|
131
134
|
});
|
|
132
|
-
wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTC] = new OnchainForGasWrapper_1.OnchainForGasWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing,
|
|
135
|
+
wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTC] = new OnchainForGasWrapper_1.OnchainForGasWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], bitcoinRpc, {
|
|
133
136
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
134
137
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
135
138
|
bitcoinNetwork: this._btcNetwork
|
|
136
139
|
});
|
|
137
140
|
if (spvVaultContract != null) {
|
|
138
|
-
wrappers[SwapType_1.SwapType.SPV_VAULT_FROM_BTC] = new SpvFromBTCWrapper_1.SpvFromBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, spvVaultContract, pricing,
|
|
141
|
+
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
142
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
140
143
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
141
144
|
bitcoinNetwork: this._btcNetwork
|
|
142
145
|
});
|
|
143
146
|
}
|
|
144
147
|
if (swapContract.supportsInitWithoutClaimer) {
|
|
145
|
-
wrappers[SwapType_1.SwapType.FROM_BTCLN_AUTO] = new FromBTCLNAutoWrapper_1.FromBTCLNAutoWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing,
|
|
148
|
+
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
149
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
147
150
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
148
151
|
unsafeSkipLnNodeCheck: this.bitcoinNetwork === base_1.BitcoinNetwork.TESTNET4 || this.bitcoinNetwork === base_1.BitcoinNetwork.REGTEST
|
|
@@ -478,9 +481,6 @@ class Swapper extends events_1.EventEmitter {
|
|
|
478
481
|
if (!this._chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
|
|
479
482
|
throw new Error("Invalid " + chainIdentifier + " address");
|
|
480
483
|
signer = this._chains[chainIdentifier].chainInterface.normalizeAddress(signer);
|
|
481
|
-
options ??= {};
|
|
482
|
-
options.confirmationTarget ??= 3;
|
|
483
|
-
options.confirmations ??= 2;
|
|
484
484
|
const amountData = {
|
|
485
485
|
amount,
|
|
486
486
|
token: tokenAddress,
|
|
@@ -502,7 +502,6 @@ class Swapper extends events_1.EventEmitter {
|
|
|
502
502
|
async createToBTCLNSwap(chainIdentifier, signer, tokenAddress, paymentRequest, additionalParams = this.options.defaultAdditionalParameters, options) {
|
|
503
503
|
if (this._chains[chainIdentifier] == null)
|
|
504
504
|
throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
|
|
505
|
-
options ??= {};
|
|
506
505
|
if (paymentRequest.startsWith("lightning:"))
|
|
507
506
|
paymentRequest = paymentRequest.substring(10);
|
|
508
507
|
if (!this.Utils.isValidLightningInvoice(paymentRequest))
|
|
@@ -518,7 +517,6 @@ class Swapper extends events_1.EventEmitter {
|
|
|
518
517
|
token: tokenAddress,
|
|
519
518
|
exactIn: false
|
|
520
519
|
};
|
|
521
|
-
options.expirySeconds ??= 5 * 24 * 3600;
|
|
522
520
|
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
521
|
}
|
|
524
522
|
/**
|
|
@@ -546,8 +544,6 @@ class Swapper extends events_1.EventEmitter {
|
|
|
546
544
|
token: tokenAddress,
|
|
547
545
|
exactIn
|
|
548
546
|
};
|
|
549
|
-
options ??= {};
|
|
550
|
-
options.expirySeconds ??= 5 * 24 * 3600;
|
|
551
547
|
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
548
|
}
|
|
553
549
|
/**
|
|
@@ -568,13 +564,11 @@ class Swapper extends events_1.EventEmitter {
|
|
|
568
564
|
if (!this._chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
|
|
569
565
|
throw new Error("Invalid " + chainIdentifier + " address");
|
|
570
566
|
signer = this._chains[chainIdentifier].chainInterface.normalizeAddress(signer);
|
|
571
|
-
options ??= {};
|
|
572
567
|
const amountData = {
|
|
573
568
|
amount,
|
|
574
569
|
token: tokenAddress,
|
|
575
570
|
exactIn
|
|
576
571
|
};
|
|
577
|
-
options.expirySeconds ??= 5 * 24 * 3600;
|
|
578
572
|
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
573
|
}
|
|
580
574
|
/**
|
|
@@ -809,8 +803,8 @@ class Swapper extends events_1.EventEmitter {
|
|
|
809
803
|
const srcToken = typeof (_srcToken) === "string" ? this.getToken(_srcToken) : _srcToken;
|
|
810
804
|
const dstToken = typeof (_dstToken) === "string" ? this.getToken(_dstToken) : _dstToken;
|
|
811
805
|
const amount = _amount == null ? null : (typeof (_amount) === "bigint" ? _amount : (0, Utils_1.fromDecimal)(_amount, exactIn ? srcToken.decimals : dstToken.decimals));
|
|
812
|
-
if (
|
|
813
|
-
if (
|
|
806
|
+
if ((0, Token_1.isBtcToken)(srcToken)) {
|
|
807
|
+
if ((0, Token_1.isSCToken)(dstToken)) {
|
|
814
808
|
if (typeof (dst) !== "string")
|
|
815
809
|
throw new Error("Destination for BTC/BTC-LN -> smart chain swaps must be a smart chain address!");
|
|
816
810
|
if (amount == null)
|
|
@@ -841,8 +835,8 @@ class Swapper extends events_1.EventEmitter {
|
|
|
841
835
|
}
|
|
842
836
|
}
|
|
843
837
|
}
|
|
844
|
-
else {
|
|
845
|
-
if (
|
|
838
|
+
else if ((0, Token_1.isSCToken)(srcToken)) {
|
|
839
|
+
if ((0, Token_1.isBtcToken)(dstToken)) {
|
|
846
840
|
if (typeof (src) !== "string")
|
|
847
841
|
throw new Error("Source address for BTC/BTC-LN -> smart chain swaps must be a smart chain address!");
|
|
848
842
|
if (dstToken.lightning) {
|
|
@@ -1305,9 +1299,9 @@ class Swapper extends events_1.EventEmitter {
|
|
|
1305
1299
|
*/
|
|
1306
1300
|
getToken(tickerOrAddress) {
|
|
1307
1301
|
//Btc tokens - BTC, BTCLN, BTC-LN
|
|
1308
|
-
if (tickerOrAddress === "BTC")
|
|
1302
|
+
if (tickerOrAddress === "BTC" || tickerOrAddress === "BITCOIN-BTC")
|
|
1309
1303
|
return Token_1.BitcoinTokens.BTC;
|
|
1310
|
-
if (tickerOrAddress === "BTCLN" || tickerOrAddress === "BTC-LN")
|
|
1304
|
+
if (tickerOrAddress === "BTCLN" || tickerOrAddress === "BTC-LN" || tickerOrAddress === "LIGHTNING-BTC")
|
|
1311
1305
|
return Token_1.BitcoinTokens.BTCLN;
|
|
1312
1306
|
//Check if the ticker is in format <chainId>-<ticker>, i.e. SOLANA-USDC, STARKNET-WBTC
|
|
1313
1307
|
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
|
*
|