@atomiqlabs/sdk 8.4.3 → 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.
Files changed (93) hide show
  1. package/README.md +8 -8
  2. package/dist/enums/SwapSide.d.ts +15 -0
  3. package/dist/enums/SwapSide.js +19 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +2 -0
  6. package/dist/intermediaries/apis/IntermediaryAPI.d.ts +2 -2
  7. package/dist/intermediaries/apis/IntermediaryAPI.js +2 -2
  8. package/dist/storage/UnifiedSwapStorage.d.ts +2 -0
  9. package/dist/swapper/Swapper.d.ts +27 -21
  10. package/dist/swapper/Swapper.js +19 -26
  11. package/dist/swapper/SwapperWithChain.d.ts +14 -18
  12. package/dist/swapper/SwapperWithChain.js +2 -2
  13. package/dist/swapper/SwapperWithSigner.d.ts +9 -13
  14. package/dist/swaps/IBTCWalletSwap.d.ts +1 -1
  15. package/dist/swaps/ISwap.d.ts +14 -0
  16. package/dist/swaps/ISwap.js +2 -0
  17. package/dist/swaps/ISwapWithGasDrop.d.ts +1 -1
  18. package/dist/swaps/ISwapWrapper.d.ts +12 -12
  19. package/dist/swaps/ISwapWrapper.js +22 -14
  20. package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +3 -3
  21. package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +8 -8
  22. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +10 -6
  23. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +10 -0
  24. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +23 -2
  25. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +20 -17
  26. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +8 -4
  27. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +9 -0
  28. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +44 -3
  29. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +9 -14
  30. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +7 -3
  31. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +7 -0
  32. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +20 -2
  33. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +15 -8
  34. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +16 -7
  35. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +13 -0
  36. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +1 -1
  37. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +52 -6
  38. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +20 -30
  39. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +1 -1
  40. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +6 -0
  41. package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +10 -6
  42. package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +8 -0
  43. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +32 -1
  44. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +8 -5
  45. package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +11 -3
  46. package/dist/swaps/trusted/ln/LnForGasSwap.js +12 -0
  47. package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +12 -4
  48. package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +13 -0
  49. package/dist/types/Token.d.ts +65 -25
  50. package/dist/types/Token.js +28 -13
  51. package/dist/types/TokenAmount.d.ts +2 -2
  52. package/dist/types/fees/Fee.d.ts +3 -3
  53. package/dist/types/lnurl/LNURLPay.d.ts +0 -1
  54. package/dist/types/lnurl/LNURLPay.js +0 -1
  55. package/dist/types/lnurl/LNURLWithdraw.d.ts +0 -1
  56. package/dist/types/lnurl/LNURLWithdraw.js +0 -1
  57. package/dist/utils/Utils.d.ts +1 -0
  58. package/dist/utils/Utils.js +17 -1
  59. package/package.json +1 -1
  60. package/src/enums/SwapSide.ts +16 -0
  61. package/src/index.ts +2 -0
  62. package/src/intermediaries/apis/IntermediaryAPI.ts +4 -4
  63. package/src/storage/UnifiedSwapStorage.ts +2 -0
  64. package/src/swapper/Swapper.ts +46 -37
  65. package/src/swapper/SwapperWithChain.ts +15 -10
  66. package/src/swapper/SwapperWithSigner.ts +8 -3
  67. package/src/swaps/IBTCWalletSwap.ts +1 -1
  68. package/src/swaps/ISwap.ts +18 -0
  69. package/src/swaps/ISwapWithGasDrop.ts +1 -1
  70. package/src/swaps/ISwapWrapper.ts +24 -23
  71. package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +3 -3
  72. package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +8 -8
  73. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +18 -6
  74. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +48 -22
  75. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +14 -4
  76. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +56 -20
  77. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +11 -3
  78. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +57 -22
  79. package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +22 -7
  80. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +1 -1
  81. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +80 -37
  82. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +1 -1
  83. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +12 -3
  84. package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +15 -6
  85. package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +53 -11
  86. package/src/swaps/trusted/ln/LnForGasSwap.ts +18 -4
  87. package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +19 -4
  88. package/src/types/Token.ts +98 -32
  89. package/src/types/TokenAmount.ts +5 -7
  90. package/src/types/fees/Fee.ts +3 -3
  91. package/src/types/lnurl/LNURLPay.ts +0 -1
  92. package/src/types/lnurl/LNURLWithdraw.ts +0 -1
  93. package/src/utils/Utils.ts +18 -2
@@ -151,6 +151,10 @@ export declare class LnForGasSwap<T extends ChainType = ChainType> extends ISwap
151
151
  * @inheritDoc
152
152
  */
153
153
  isSuccessful(): boolean;
154
+ /**
155
+ * @inheritDoc
156
+ */
157
+ isInProgress(): boolean;
154
158
  /**
155
159
  * @inheritDoc
156
160
  * @internal
@@ -175,7 +179,7 @@ export declare class LnForGasSwap<T extends ChainType = ChainType> extends ISwap
175
179
  /**
176
180
  * @inheritDoc
177
181
  */
178
- getOutput(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
182
+ getOutput(): TokenAmount<SCToken<T["ChainId"]>, true>;
179
183
  /**
180
184
  * @inheritDoc
181
185
  */
@@ -183,11 +187,11 @@ export declare class LnForGasSwap<T extends ChainType = ChainType> extends ISwap
183
187
  /**
184
188
  * @inheritDoc
185
189
  */
186
- getInput(): TokenAmount<T["ChainId"], BtcToken<true>, true>;
190
+ getInput(): TokenAmount<BtcToken<true>, true>;
187
191
  /**
188
192
  * @inheritDoc
189
193
  */
190
- getInputWithoutFee(): TokenAmount<T["ChainId"], BtcToken<true>, true>;
194
+ getInputWithoutFee(): TokenAmount<BtcToken<true>, true>;
191
195
  /**
192
196
  * Returns the swap fee charged by the intermediary (LP) on this swap
193
197
  *
@@ -209,6 +213,10 @@ export declare class LnForGasSwap<T extends ChainType = ChainType> extends ISwap
209
213
  * @inheritDoc
210
214
  */
211
215
  txsExecute(): Promise<[SwapExecutionActionLightning]>;
216
+ /**
217
+ * @remark Not supported
218
+ */
219
+ execute(): Promise<boolean>;
212
220
  /**
213
221
  * @inheritDoc
214
222
  */
@@ -218,6 +218,12 @@ class LnForGasSwap extends ISwap_1.ISwap {
218
218
  isSuccessful() {
219
219
  return this._state === LnForGasSwapState.FINISHED;
220
220
  }
221
+ /**
222
+ * @inheritDoc
223
+ */
224
+ isInProgress() {
225
+ return (this._state === LnForGasSwapState.PR_CREATED && this.initiated) || this._state === LnForGasSwapState.PR_PAID;
226
+ }
221
227
  /**
222
228
  * @inheritDoc
223
229
  * @internal
@@ -347,6 +353,12 @@ class LnForGasSwap extends ISwap_1.ISwap {
347
353
  }
348
354
  throw new Error("Invalid swap state to obtain execution txns, required PR_CREATED");
349
355
  }
356
+ /**
357
+ * @remark Not supported
358
+ */
359
+ async execute() {
360
+ throw new Error("Not supported");
361
+ }
350
362
  /**
351
363
  * @inheritDoc
352
364
  */
@@ -171,6 +171,10 @@ export declare class OnchainForGasSwap<T extends ChainType = ChainType> extends
171
171
  * @inheritDoc
172
172
  */
173
173
  isSuccessful(): boolean;
174
+ /**
175
+ * @inheritDoc
176
+ */
177
+ isInProgress(): boolean;
174
178
  /**
175
179
  * @inheritDoc
176
180
  * @internal
@@ -195,7 +199,7 @@ export declare class OnchainForGasSwap<T extends ChainType = ChainType> extends
195
199
  /**
196
200
  * @inheritDoc
197
201
  */
198
- getOutput(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
202
+ getOutput(): TokenAmount<SCToken<T["ChainId"]>, true>;
199
203
  /**
200
204
  * @inheritDoc
201
205
  */
@@ -203,11 +207,11 @@ export declare class OnchainForGasSwap<T extends ChainType = ChainType> extends
203
207
  /**
204
208
  * @inheritDoc
205
209
  */
206
- getInput(): TokenAmount<T["ChainId"], BtcToken<false>, true>;
210
+ getInput(): TokenAmount<BtcToken<false>, true>;
207
211
  /**
208
212
  * @inheritDoc
209
213
  */
210
- getInputWithoutFee(): TokenAmount<T["ChainId"], BtcToken<false>, true>;
214
+ getInputWithoutFee(): TokenAmount<BtcToken<false>, true>;
211
215
  /**
212
216
  * Returns the swap fee charged by the intermediary (LP) on this swap
213
217
  *
@@ -251,7 +255,7 @@ export declare class OnchainForGasSwap<T extends ChainType = ChainType> extends
251
255
  /**
252
256
  * @inheritDoc
253
257
  */
254
- estimateBitcoinFee(_bitcoinWallet: IBitcoinWallet | MinimalBitcoinWalletInterface, feeRate?: number): Promise<TokenAmount<any, BtcToken<false>, true> | null>;
258
+ estimateBitcoinFee(_bitcoinWallet: IBitcoinWallet | MinimalBitcoinWalletInterface, feeRate?: number): Promise<TokenAmount<BtcToken<false>, true> | null>;
255
259
  /**
256
260
  * @inheritDoc
257
261
  */
@@ -267,6 +271,10 @@ export declare class OnchainForGasSwap<T extends ChainType = ChainType> extends
267
271
  }): Promise<[
268
272
  SwapExecutionActionBitcoin<"ADDRESS" | "FUNDED_PSBT">
269
273
  ]>;
274
+ /**
275
+ * @remark Not supported
276
+ */
277
+ execute(): Promise<boolean>;
270
278
  /**
271
279
  * @inheritDoc
272
280
  *
@@ -225,6 +225,13 @@ class OnchainForGasSwap extends ISwap_1.ISwap {
225
225
  isSuccessful() {
226
226
  return this._state === OnchainForGasSwapState.FINISHED;
227
227
  }
228
+ /**
229
+ * @inheritDoc
230
+ */
231
+ isInProgress() {
232
+ return (this._state === OnchainForGasSwapState.PR_CREATED && this.txId != null) ||
233
+ (this._state === OnchainForGasSwapState.REFUNDABLE && this.refundAddress != null);
234
+ }
228
235
  /**
229
236
  * @inheritDoc
230
237
  * @internal
@@ -453,6 +460,12 @@ class OnchainForGasSwap extends ISwap_1.ISwap {
453
460
  }
454
461
  throw new Error("Invalid swap state to obtain execution txns, required PR_CREATED or CLAIM_COMMITED");
455
462
  }
463
+ /**
464
+ * @remark Not supported
465
+ */
466
+ async execute() {
467
+ throw new Error("Not supported");
468
+ }
456
469
  /**
457
470
  * @inheritDoc
458
471
  *
@@ -1,15 +1,71 @@
1
+ /**
2
+ * Type for all token types (BTC or smart chain)
3
+ *
4
+ * @category Tokens
5
+ */
6
+ export type Token<ChainIdentifier extends string = string> = {
7
+ /**
8
+ * Chain identifier for the token's chain
9
+ */
10
+ chainId: ChainIdentifier | "BITCOIN" | "LIGHTNING";
11
+ /**
12
+ * Ticker of the token
13
+ */
14
+ ticker: string;
15
+ /**
16
+ * Full name of the token
17
+ */
18
+ name: string;
19
+ /**
20
+ * Actual decimal places of the tokens
21
+ */
22
+ decimals: number;
23
+ /**
24
+ * The decimal places that should be rendered and displayed to the user
25
+ */
26
+ displayDecimals?: number;
27
+ /**
28
+ * Address of the token contract, or `""` for Bitcoin
29
+ */
30
+ address: string;
31
+ /**
32
+ * Legacy chain identifier distinguishing between Smart Chain and Bitcoin tokens
33
+ */
34
+ chain: "SC" | "BTC";
35
+ /**
36
+ * Legacy lightning flag, determines whether a Bitcoin token is an Lightning or on-chain one
37
+ */
38
+ lightning?: boolean;
39
+ /**
40
+ * Equality check between tokens
41
+ */
42
+ equals: (other: Token) => boolean;
43
+ /**
44
+ * Returns the
45
+ */
46
+ toString: () => string;
47
+ };
48
+ /**
49
+ * Type guard for a {@link Token} type, encompassing all tokens (BTC or smart chain)
50
+ *
51
+ * @category Tokens
52
+ */
53
+ export declare function isToken(obj: any): obj is Token;
1
54
  /**
2
55
  * Bitcoin token type (BTC on on-chain or lightning)
3
56
  *
4
57
  * @category Tokens
5
58
  */
6
- export type BtcToken<L = boolean> = {
7
- chain: "BTC";
8
- lightning: L;
59
+ export type BtcToken<L = boolean> = Token & {
60
+ chainId: L extends true ? "LIGHTNING" : "BITCOIN";
9
61
  ticker: "BTC";
10
- decimals: 8;
11
62
  name: L extends true ? "Bitcoin (lightning L2)" : "Bitcoin (on-chain L1)";
12
- displayDecimals?: number;
63
+ decimals: 8;
64
+ displayDecimals: 8;
65
+ address: "";
66
+ chain: "BTC";
67
+ lightning: L;
68
+ toString: () => L extends true ? "BTC-LN" : "BTC";
13
69
  };
14
70
  /**
15
71
  * Type guard for {@link BtcToken} (token on the bitcoin network - lightning or on-chain)
@@ -31,29 +87,13 @@ export declare const BitcoinTokens: {
31
87
  *
32
88
  * @category Tokens
33
89
  */
34
- export type SCToken<ChainIdentifier extends string = string> = {
35
- chain: "SC";
90
+ export type SCToken<ChainIdentifier extends string = string> = Token<ChainIdentifier> & {
36
91
  chainId: ChainIdentifier;
37
- address: string;
38
- ticker: string;
39
- decimals: number;
40
- displayDecimals?: number;
41
- name: string;
92
+ chain: "SC";
93
+ toString: () => `${ChainIdentifier}-${string}`;
42
94
  };
43
95
  /**
44
96
  * Type guard for {@link SCToken} (token on the smart chain)
45
97
  * @category Tokens
46
98
  */
47
- export declare function isSCToken(obj: any): obj is SCToken;
48
- /**
49
- * Union type for all token types (BTC or smart chain)
50
- *
51
- * @category Tokens
52
- */
53
- export type Token<ChainIdentifier extends string = string> = BtcToken | SCToken<ChainIdentifier>;
54
- /**
55
- * Type guard for an union {@link Token} type, encompassing all tokens (BTC or smart chain)
56
- *
57
- * @category Tokens
58
- */
59
- export declare function isToken(obj: any): obj is Token;
99
+ export declare function isSCToken<ChainIdentifier extends string = string>(obj: any, chainIdentifier?: ChainIdentifier[]): obj is SCToken<ChainIdentifier>;
@@ -1,6 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isToken = exports.isSCToken = exports.BitcoinTokens = exports.isBtcToken = void 0;
3
+ exports.isSCToken = exports.BitcoinTokens = exports.isBtcToken = exports.isToken = void 0;
4
+ /**
5
+ * Type guard for a {@link Token} type, encompassing all tokens (BTC or smart chain)
6
+ *
7
+ * @category Tokens
8
+ */
9
+ function isToken(obj) {
10
+ return typeof (obj) === "object" &&
11
+ (obj.chain === "SC" || obj.chain === "BTC") &&
12
+ typeof (obj.ticker) === "string" &&
13
+ typeof (obj.decimals) === "number" &&
14
+ typeof (obj.name) === "string";
15
+ }
16
+ exports.isToken = isToken;
4
17
  /**
5
18
  * Type guard for {@link BtcToken} (token on the bitcoin network - lightning or on-chain)
6
19
  *
@@ -23,39 +36,41 @@ exports.isBtcToken = isBtcToken;
23
36
  exports.BitcoinTokens = {
24
37
  BTC: {
25
38
  chain: "BTC",
39
+ chainId: "BITCOIN",
26
40
  lightning: false,
27
41
  ticker: "BTC",
28
42
  decimals: 8,
29
- name: "Bitcoin (on-chain L1)"
43
+ displayDecimals: 8,
44
+ name: "Bitcoin (on-chain L1)",
45
+ address: "",
46
+ equals: (other) => other.chainId === "BITCOIN" && other.ticker === "BTC",
47
+ toString: () => "BTC"
30
48
  },
31
49
  BTCLN: {
32
50
  chain: "BTC",
51
+ chainId: "LIGHTNING",
33
52
  lightning: true,
34
53
  ticker: "BTC",
35
54
  decimals: 8,
36
- name: "Bitcoin (lightning L2)"
55
+ displayDecimals: 8,
56
+ name: "Bitcoin (lightning L2)",
57
+ address: "",
58
+ equals: (other) => other.chainId === "LIGHTNING" && other.ticker === "BTC",
59
+ toString: () => "BTC-LN"
37
60
  }
38
61
  };
39
62
  /**
40
63
  * Type guard for {@link SCToken} (token on the smart chain)
41
64
  * @category Tokens
42
65
  */
43
- function isSCToken(obj) {
66
+ function isSCToken(obj, chainIdentifier) {
44
67
  return typeof (obj) === "object" &&
45
68
  obj.chain === "SC" &&
46
69
  typeof (obj.chainId) === "string" &&
70
+ (chainIdentifier == null || chainIdentifier.includes(obj.chainId)) &&
47
71
  typeof (obj.address) === "string" &&
48
72
  typeof (obj.ticker) === "string" &&
49
73
  typeof (obj.decimals) === "number" &&
50
74
  typeof (obj.name) === "string";
51
75
  }
52
76
  exports.isSCToken = isSCToken;
53
- /**
54
- * Type guard for an union {@link Token} type, encompassing all tokens (BTC or smart chain)
55
- *
56
- * @category Tokens
57
- */
58
- function isToken(obj) {
59
- return isBtcToken(obj) || isSCToken(obj);
60
- }
61
- exports.isToken = isToken;
@@ -6,7 +6,7 @@ import { PriceInfoType } from "./PriceInfoType";
6
6
  *
7
7
  * @category Tokens
8
8
  */
9
- export type TokenAmount<ChainIdentifier extends string = string, T extends Token<ChainIdentifier> = Token<ChainIdentifier>, Known extends boolean = boolean> = {
9
+ export type TokenAmount<T extends Token = Token, Known extends boolean = boolean> = {
10
10
  /**
11
11
  * Raw amount in base units represented as bigint, might be `undefined` when the amount is unknown
12
12
  */
@@ -66,4 +66,4 @@ export type TokenAmount<ChainIdentifier extends string = string, T extends Token
66
66
  * @category Tokens
67
67
  * @internal
68
68
  */
69
- export declare function toTokenAmount<ChainIdentifier extends string = string, T extends Token<ChainIdentifier> = Token<ChainIdentifier>, Known extends boolean = boolean>(amount: Known extends true ? bigint : null, token: T, prices: ISwapPrice, pricingInfo?: PriceInfoType): TokenAmount<ChainIdentifier, T, Known>;
69
+ export declare function toTokenAmount<T extends Token = Token, Known extends boolean = boolean>(amount: Known extends true ? bigint : null, token: T, prices: ISwapPrice, pricingInfo?: PriceInfoType): TokenAmount<T, Known>;
@@ -11,11 +11,11 @@ export type Fee<ChainIdentifier extends string = string, TSrc extends Token<Chai
11
11
  /**
12
12
  * Fee value equivalent in source token
13
13
  */
14
- amountInSrcToken: TokenAmount<ChainIdentifier, TSrc, true>;
14
+ amountInSrcToken: TokenAmount<TSrc, true>;
15
15
  /**
16
16
  * Fee value equivalent in destination token
17
17
  */
18
- amountInDstToken: TokenAmount<ChainIdentifier, TDst, true>;
18
+ amountInDstToken: TokenAmount<TDst, true>;
19
19
  /**
20
20
  * Fetches the current USD value of the fee
21
21
  *
@@ -44,7 +44,7 @@ export type Fee<ChainIdentifier extends string = string, TSrc extends Token<Chai
44
44
  * base_fee + amount * percentage_fee
45
45
  */
46
46
  composition?: {
47
- base: TokenAmount<ChainIdentifier>;
47
+ base: TokenAmount;
48
48
  percentage: PercentagePPM;
49
49
  };
50
50
  };
@@ -47,7 +47,6 @@ export declare function isLNURLPayParams(obj: any): obj is LNURLPayParams;
47
47
  * Type guard for {@link LNURLPay}
48
48
  *
49
49
  * @category Lightning
50
- * @internal
51
50
  */
52
51
  export declare function isLNURLPay(value: any): value is LNURLPay;
53
52
  /**
@@ -15,7 +15,6 @@ exports.isLNURLPayParams = isLNURLPayParams;
15
15
  * Type guard for {@link LNURLPay}
16
16
  *
17
17
  * @category Lightning
18
- * @internal
19
18
  */
20
19
  function isLNURLPay(value) {
21
20
  return (typeof value === "object" &&
@@ -37,7 +37,6 @@ export type LNURLWithdraw = {
37
37
  * Type guard for {@link LNURLWithdraw}
38
38
  *
39
39
  * @category Lightning
40
- * @internal
41
40
  */
42
41
  export declare function isLNURLWithdraw(value: any): value is LNURLWithdraw;
43
42
  /**
@@ -5,7 +5,6 @@ exports.isLNURLWithdrawParams = exports.isLNURLWithdraw = void 0;
5
5
  * Type guard for {@link LNURLWithdraw}
6
6
  *
7
7
  * @category Lightning
8
- * @internal
9
8
  */
10
9
  function isLNURLWithdraw(value) {
11
10
  return (typeof value === "object" &&
@@ -55,3 +55,4 @@ export declare function randomBytes(bytesLength: number): Buffer;
55
55
  export declare function getTxoHash(outputScriptHex: string, value: number): Buffer;
56
56
  export declare function fromDecimal(amount: string, decimalCount: number): bigint;
57
57
  export declare function toDecimal(amount: bigint, decimalCount: number, cut?: boolean, displayDecimals?: number): string;
58
+ export declare function parseHashValueExact32Bytes(value?: Buffer | string, variableName?: string): Buffer | undefined;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toDecimal = exports.fromDecimal = exports.getTxoHash = exports.randomBytes = exports.toBigInt = exports.bigIntCompare = exports.bigIntMax = exports.bigIntMin = exports.extendAbortController = exports.mapToArray = exports.objectMap = exports.promiseAny = exports.throwIfUndefined = void 0;
3
+ exports.parseHashValueExact32Bytes = exports.toDecimal = exports.fromDecimal = exports.getTxoHash = exports.randomBytes = exports.toBigInt = exports.bigIntCompare = exports.bigIntMax = exports.bigIntMin = exports.extendAbortController = exports.mapToArray = exports.objectMap = exports.promiseAny = exports.throwIfUndefined = void 0;
4
4
  const buffer_1 = require("buffer");
5
5
  const utils_1 = require("@noble/hashes/utils");
6
6
  const sha2_1 = require("@noble/hashes/sha2");
7
7
  const base_1 = require("@atomiqlabs/base");
8
+ const UserError_1 = require("../errors/UserError");
8
9
  /**
9
10
  * Returns a promise that rejects if the passed promise resolves to `undefined` or `null`
10
11
  *
@@ -176,3 +177,18 @@ function toDecimal(amount, decimalCount, cut, displayDecimals) {
176
177
  return amountStr.substring(0, splitPoint) + "." + decimalPart.substring(0, cutTo);
177
178
  }
178
179
  exports.toDecimal = toDecimal;
180
+ function parseHashValueExact32Bytes(value, variableName) {
181
+ let hash;
182
+ if (typeof (value) === "string") {
183
+ if (value.length !== 64)
184
+ throw new UserError_1.UserError(`Invalid ${variableName} length, must be exactly 64 hexadecimal characters!`);
185
+ hash = buffer_1.Buffer.from(value, "hex");
186
+ }
187
+ else {
188
+ hash = value;
189
+ }
190
+ if (hash != null && hash.length !== 32)
191
+ throw new UserError_1.UserError(`Invalid ${variableName} length, must be exactly 32 bytes!`);
192
+ return hash;
193
+ }
194
+ exports.parseHashValueExact32Bytes = parseHashValueExact32Bytes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/sdk",
3
- "version": "8.4.3",
3
+ "version": "8.5.0",
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",
@@ -0,0 +1,16 @@
1
+
2
+ /**
3
+ * Enum representing the side of the swap for querying available input/output tokens
4
+ *
5
+ * @category Core
6
+ */
7
+ export enum SwapSide {
8
+ /**
9
+ * Represents input / source side of the swap
10
+ */
11
+ INPUT = 1,
12
+ /**
13
+ * Represents output / destination side of the swap
14
+ */
15
+ OUTPUT = 0
16
+ }
package/src/index.ts CHANGED
@@ -45,6 +45,7 @@ export {CoinselectAddressTypes} from "./bitcoin/coinselect2";
45
45
  export * from "./enums/FeeType";
46
46
  export * from "./enums/SwapAmountType";
47
47
  export * from "./enums/SwapDirection";
48
+ export * from "./enums/SwapSide";
48
49
  export * from "./enums/SwapType";
49
50
 
50
51
  export * from "./errors/IntermediaryError";
@@ -127,6 +128,7 @@ export * from "./types/wallets/MinimalBitcoinWalletInterface";
127
128
  export * from "./types/wallets/MinimalLightningNetworkWalletInterface";
128
129
  export * from "./types/wallets/LightningInvoiceCreateService";
129
130
 
131
+ export * from "./types/SwapStateInfo";
130
132
  export * from "./types/AmountData";
131
133
  export * from "./types/CustomPriceFunction";
132
134
  export * from "./types/SwapExecutionAction";
@@ -204,9 +204,9 @@ export type FromBTCInit = BaseFromBTCSwapInit & {
204
204
  sequence: bigint,
205
205
  claimerBounty: Promise<{
206
206
  feePerBlock: bigint,
207
- safetyFactor: number,
207
+ safetyFactor: bigint,
208
208
  startTimestamp: bigint,
209
- addBlock: number,
209
+ addBlock: bigint,
210
210
  addFee: bigint
211
211
  }>
212
212
  }
@@ -532,9 +532,9 @@ export class IntermediaryAPI {
532
532
  claimerBounty: init.claimerBounty.then(claimerBounty => {
533
533
  return {
534
534
  feePerBlock: claimerBounty.feePerBlock.toString(10),
535
- safetyFactor: claimerBounty.safetyFactor,
535
+ safetyFactor: claimerBounty.safetyFactor.toString(10),
536
536
  startTimestamp: claimerBounty.startTimestamp.toString(10),
537
- addBlock: claimerBounty.addBlock,
537
+ addBlock: claimerBounty.addBlock.toString(10),
538
538
  addFee: claimerBounty.addFee.toString(10)
539
539
  }
540
540
  }),
@@ -18,6 +18,7 @@ const indexes = [
18
18
  * Simple index types for SDK swap storage
19
19
  *
20
20
  * @category Storage
21
+ * @useDeclaredType
21
22
  */
22
23
  export type UnifiedSwapStorageIndexes = typeof indexes;
23
24
 
@@ -31,6 +32,7 @@ const compositeIndexes = [
31
32
  * Composite index types for SDK swap storage
32
33
  *
33
34
  * @category Storage
35
+ * @useDeclaredType
34
36
  */
35
37
  export type UnifiedSwapStorageCompositeIndexes = typeof compositeIndexes;
36
38