@atomiqlabs/sdk 8.8.3 → 8.9.1
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/api/index.d.ts +1 -0
- package/api/index.js +3 -0
- package/dist/ApiList.d.ts +37 -0
- package/dist/ApiList.js +30 -0
- package/dist/api/ApiEndpoints.d.ts +393 -0
- package/dist/api/ApiEndpoints.js +2 -0
- package/dist/api/ApiParser.d.ts +10 -0
- package/dist/api/ApiParser.js +134 -0
- package/dist/api/ApiTypes.d.ts +157 -0
- package/dist/api/ApiTypes.js +75 -0
- package/dist/api/SerializedAction.d.ts +40 -0
- package/dist/api/SerializedAction.js +59 -0
- package/dist/api/SwapperApi.d.ts +50 -0
- package/dist/api/SwapperApi.js +431 -0
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.js +24 -0
- package/dist/events/UnifiedSwapEventListener.d.ts +4 -3
- package/dist/events/UnifiedSwapEventListener.js +8 -2
- package/dist/http/HttpUtils.d.ts +4 -2
- package/dist/http/HttpUtils.js +10 -4
- package/dist/http/paramcoders/client/StreamingFetchPromise.d.ts +2 -1
- package/dist/http/paramcoders/client/StreamingFetchPromise.js +3 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/intermediaries/IntermediaryDiscovery.d.ts +7 -2
- package/dist/intermediaries/IntermediaryDiscovery.js +4 -4
- package/dist/intermediaries/apis/IntermediaryAPI.d.ts +171 -14
- package/dist/intermediaries/apis/IntermediaryAPI.js +174 -28
- package/dist/intermediaries/auth/SignedKeyBasedAuth.d.ts +14 -0
- package/dist/intermediaries/auth/SignedKeyBasedAuth.js +68 -0
- package/dist/storage/IUnifiedStorage.d.ts +45 -3
- package/dist/storage/UnifiedSwapStorage.d.ts +8 -2
- package/dist/storage/UnifiedSwapStorage.js +46 -8
- package/dist/swapper/Swapper.d.ts +41 -3
- package/dist/swapper/Swapper.js +93 -48
- package/dist/swapper/SwapperUtils.d.ts +18 -2
- package/dist/swapper/SwapperUtils.js +39 -1
- package/dist/swaps/ISwap.d.ts +70 -9
- package/dist/swaps/ISwap.js +28 -6
- package/dist/swaps/ISwapWrapper.d.ts +11 -1
- package/dist/swaps/ISwapWrapper.js +23 -3
- package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +1 -1
- package/dist/swaps/escrow_swaps/IEscrowSwap.js +4 -2
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +2 -1
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +2 -2
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +3 -2
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +47 -31
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +201 -67
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +6 -6
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +82 -15
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +304 -98
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +6 -6
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +75 -42
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +424 -87
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +7 -7
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +54 -11
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +214 -41
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +2 -1
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +7 -8
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +5 -5
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +76 -19
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +290 -51
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +3 -1
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +5 -5
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +53 -12
- package/dist/swaps/trusted/ln/LnForGasSwap.js +163 -49
- package/dist/swaps/trusted/ln/LnForGasWrapper.js +1 -2
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +14 -13
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +30 -47
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +3 -1
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +4 -4
- package/dist/types/SwapExecutionAction.d.ts +141 -34
- package/dist/types/SwapExecutionAction.js +104 -0
- package/dist/types/SwapExecutionStep.d.ts +144 -0
- package/dist/types/SwapExecutionStep.js +87 -0
- package/dist/types/TokenAmount.d.ts +6 -0
- package/dist/types/TokenAmount.js +26 -1
- package/dist/utils/BitcoinUtils.d.ts +2 -0
- package/dist/utils/BitcoinUtils.js +34 -1
- package/dist/utils/Utils.d.ts +3 -1
- package/dist/utils/Utils.js +7 -1
- package/package.json +7 -4
- package/src/api/ApiEndpoints.ts +427 -0
- package/src/api/ApiParser.ts +138 -0
- package/src/api/ApiTypes.ts +229 -0
- package/src/api/SerializedAction.ts +97 -0
- package/src/api/SwapperApi.ts +545 -0
- package/src/api/index.ts +5 -0
- package/src/events/UnifiedSwapEventListener.ts +11 -3
- package/src/http/HttpUtils.ts +10 -4
- package/src/http/paramcoders/client/StreamingFetchPromise.ts +4 -2
- package/src/index.ts +1 -0
- package/src/intermediaries/IntermediaryDiscovery.ts +9 -2
- package/src/intermediaries/apis/IntermediaryAPI.ts +314 -30
- package/src/intermediaries/auth/SignedKeyBasedAuth.ts +69 -0
- package/src/storage/IUnifiedStorage.ts +45 -4
- package/src/storage/UnifiedSwapStorage.ts +42 -8
- package/src/swapper/Swapper.ts +134 -52
- package/src/swapper/SwapperUtils.ts +42 -2
- package/src/swaps/ISwap.ts +88 -16
- package/src/swaps/ISwapWrapper.ts +28 -3
- package/src/swaps/escrow_swaps/IEscrowSwap.ts +5 -3
- package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +3 -1
- package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +4 -1
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +264 -67
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +6 -4
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +390 -89
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +6 -4
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +548 -94
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +7 -5
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +276 -45
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +7 -6
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +5 -3
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +393 -57
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +5 -3
- package/src/swaps/trusted/ln/LnForGasSwap.ts +211 -47
- package/src/swaps/trusted/ln/LnForGasWrapper.ts +1 -2
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +32 -51
- package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +5 -3
- package/src/types/SwapExecutionAction.ts +266 -43
- package/src/types/SwapExecutionStep.ts +224 -0
- package/src/types/TokenAmount.ts +36 -2
- package/src/utils/BitcoinUtils.ts +32 -0
- package/src/utils/Utils.ts +10 -1
- package/src/intermediaries/apis/TrustedIntermediaryAPI.ts +0 -258
package/src/utils/Utils.ts
CHANGED
|
@@ -103,13 +103,22 @@ export function mapToArray<K, V, Output>(map: Map<K, V>, translator: (key: K, va
|
|
|
103
103
|
* Creates a new abort controller that will abort if the passed abort signal aborts
|
|
104
104
|
*
|
|
105
105
|
* @param abortSignal
|
|
106
|
+
* @param timeoutSeconds
|
|
107
|
+
* @param timeoutMessage
|
|
106
108
|
*/
|
|
107
|
-
export function extendAbortController(abortSignal?: AbortSignal) {
|
|
109
|
+
export function extendAbortController(abortSignal?: AbortSignal, timeoutSeconds?: number, timeoutMessage?: string) {
|
|
108
110
|
const _abortController = new AbortController();
|
|
109
111
|
if(abortSignal!=null) {
|
|
110
112
|
abortSignal.throwIfAborted();
|
|
111
113
|
abortSignal.onabort = () => _abortController.abort(abortSignal.reason);
|
|
112
114
|
}
|
|
115
|
+
if(timeoutSeconds!=null) {
|
|
116
|
+
const timeout = setTimeout(
|
|
117
|
+
() => _abortController.abort(new Error(timeoutMessage ?? "Timed out")),
|
|
118
|
+
timeoutSeconds * 1000
|
|
119
|
+
);
|
|
120
|
+
_abortController.signal.addEventListener("abort", () => clearTimeout(timeout));
|
|
121
|
+
}
|
|
113
122
|
return _abortController;
|
|
114
123
|
}
|
|
115
124
|
|
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
import {RequestError} from "../../errors/RequestError";
|
|
2
|
-
import {FieldTypeEnum, RequestSchemaResult, verifySchema} from "../../http/paramcoders/SchemaVerifier";
|
|
3
|
-
import {httpGet} from "../../http/HttpUtils";
|
|
4
|
-
import {tryWithRetries} from "../../utils/RetryUtils";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export enum AddressStatusResponseCodes {
|
|
8
|
-
EXPIRED=10001,
|
|
9
|
-
PAID=10000,
|
|
10
|
-
AWAIT_PAYMENT=10010,
|
|
11
|
-
AWAIT_CONFIRMATION=10011,
|
|
12
|
-
PENDING=10013,
|
|
13
|
-
TX_SENT=10012,
|
|
14
|
-
REFUNDED=10014,
|
|
15
|
-
DOUBLE_SPENT=10015,
|
|
16
|
-
REFUNDABLE=10016
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type AddressStatusResponse = {
|
|
20
|
-
code: AddressStatusResponseCodes.TX_SENT | AddressStatusResponseCodes.PAID,
|
|
21
|
-
msg: string,
|
|
22
|
-
data: {
|
|
23
|
-
adjustedAmount: string,
|
|
24
|
-
adjustedTotal: string,
|
|
25
|
-
adjustedFee?: string,
|
|
26
|
-
adjustedFeeSats?: string,
|
|
27
|
-
txId: string,
|
|
28
|
-
scTxId: string
|
|
29
|
-
}
|
|
30
|
-
} | {
|
|
31
|
-
code: AddressStatusResponseCodes.AWAIT_CONFIRMATION | AddressStatusResponseCodes.PENDING,
|
|
32
|
-
msg: string,
|
|
33
|
-
data: {
|
|
34
|
-
adjustedAmount: string,
|
|
35
|
-
adjustedTotal: string,
|
|
36
|
-
adjustedFee?: string,
|
|
37
|
-
adjustedFeeSats?: string,
|
|
38
|
-
txId: string
|
|
39
|
-
}
|
|
40
|
-
} | {
|
|
41
|
-
code: AddressStatusResponseCodes.REFUNDABLE,
|
|
42
|
-
msg: string,
|
|
43
|
-
data: {
|
|
44
|
-
adjustedAmount: string
|
|
45
|
-
}
|
|
46
|
-
} | {
|
|
47
|
-
code: AddressStatusResponseCodes.REFUNDED | AddressStatusResponseCodes.DOUBLE_SPENT,
|
|
48
|
-
msg: string,
|
|
49
|
-
data: {
|
|
50
|
-
txId: string
|
|
51
|
-
}
|
|
52
|
-
} | {
|
|
53
|
-
code: AddressStatusResponseCodes.AWAIT_PAYMENT | AddressStatusResponseCodes.EXPIRED,
|
|
54
|
-
msg: string
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export type TrustedFromBTCInit = {
|
|
58
|
-
address: string,
|
|
59
|
-
amount: bigint,
|
|
60
|
-
token: string,
|
|
61
|
-
refundAddress?: string
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const TrustedFromBTCResponseSchema = {
|
|
65
|
-
paymentHash: FieldTypeEnum.String,
|
|
66
|
-
sequence: FieldTypeEnum.BigInt,
|
|
67
|
-
btcAddress: FieldTypeEnum.String,
|
|
68
|
-
amountSats: FieldTypeEnum.BigInt,
|
|
69
|
-
swapFeeSats: FieldTypeEnum.BigInt,
|
|
70
|
-
swapFee: FieldTypeEnum.BigInt,
|
|
71
|
-
total: FieldTypeEnum.BigInt,
|
|
72
|
-
intermediaryKey: FieldTypeEnum.String,
|
|
73
|
-
recommendedFee: FieldTypeEnum.Number,
|
|
74
|
-
expiresAt: FieldTypeEnum.Number
|
|
75
|
-
} as const;
|
|
76
|
-
|
|
77
|
-
export type TrustedFromBTCResponseType = RequestSchemaResult<typeof TrustedFromBTCResponseSchema>;
|
|
78
|
-
|
|
79
|
-
export enum InvoiceStatusResponseCodes {
|
|
80
|
-
EXPIRED=10001,
|
|
81
|
-
PAID=10000,
|
|
82
|
-
AWAIT_PAYMENT=10010,
|
|
83
|
-
PENDING=10011,
|
|
84
|
-
TX_SENT=10012
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export type InvoiceStatusResponse = {
|
|
88
|
-
code: InvoiceStatusResponseCodes.TX_SENT | InvoiceStatusResponseCodes.PAID,
|
|
89
|
-
msg: string,
|
|
90
|
-
data: {
|
|
91
|
-
txId: string
|
|
92
|
-
}
|
|
93
|
-
} | {
|
|
94
|
-
code: Exclude<InvoiceStatusResponseCodes, InvoiceStatusResponseCodes.TX_SENT | InvoiceStatusResponseCodes.PAID>,
|
|
95
|
-
msg: string
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export type TrustedFromBTCLNInit = {
|
|
99
|
-
address: string,
|
|
100
|
-
amount: bigint,
|
|
101
|
-
token: string
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const TrustedFromBTCLNResponseSchema = {
|
|
105
|
-
pr: FieldTypeEnum.String,
|
|
106
|
-
swapFee: FieldTypeEnum.BigInt,
|
|
107
|
-
swapFeeSats: FieldTypeEnum.BigInt,
|
|
108
|
-
total: FieldTypeEnum.BigInt
|
|
109
|
-
} as const;
|
|
110
|
-
|
|
111
|
-
export type TrustedFromBTCLNResponseType = RequestSchemaResult<typeof TrustedFromBTCLNResponseSchema>;
|
|
112
|
-
|
|
113
|
-
export class TrustedIntermediaryAPI {
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Fetches the invoice status from the intermediary node
|
|
117
|
-
*
|
|
118
|
-
* @param url Url of the trusted intermediary
|
|
119
|
-
* @param paymentHash Payment hash of the lightning invoice
|
|
120
|
-
* @param timeout Timeout in milliseconds
|
|
121
|
-
* @param abortSignal
|
|
122
|
-
* @throws {RequestError} if non-200 http response is returned
|
|
123
|
-
*/
|
|
124
|
-
static async getInvoiceStatus(
|
|
125
|
-
url: string,
|
|
126
|
-
paymentHash: string,
|
|
127
|
-
timeout?: number,
|
|
128
|
-
abortSignal?: AbortSignal
|
|
129
|
-
): Promise<InvoiceStatusResponse> {
|
|
130
|
-
return tryWithRetries(() => httpGet<InvoiceStatusResponse>(
|
|
131
|
-
url+"/getInvoiceStatus?paymentHash="+encodeURIComponent(paymentHash),
|
|
132
|
-
timeout, abortSignal
|
|
133
|
-
), undefined, RequestError, abortSignal);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Initiate a trusted swap from BTCLN to SC native currency, retries!
|
|
138
|
-
*
|
|
139
|
-
* @param chainIdentifier
|
|
140
|
-
* @param baseUrl Base url of the trusted swap intermediary
|
|
141
|
-
* @param init Initialization parameters
|
|
142
|
-
* @param timeout Timeout in milliseconds for the request
|
|
143
|
-
* @param abortSignal
|
|
144
|
-
* @throws {RequestError} If the response is non-200
|
|
145
|
-
*/
|
|
146
|
-
static async initTrustedFromBTCLN(
|
|
147
|
-
chainIdentifier: string,
|
|
148
|
-
baseUrl: string,
|
|
149
|
-
init: TrustedFromBTCLNInit,
|
|
150
|
-
timeout?: number,
|
|
151
|
-
abortSignal?: AbortSignal
|
|
152
|
-
): Promise<TrustedFromBTCLNResponseType> {
|
|
153
|
-
const resp = await tryWithRetries(
|
|
154
|
-
() => httpGet<{code: number, msg: string, data?: any}>(
|
|
155
|
-
baseUrl+"/lnforgas/createInvoice" +
|
|
156
|
-
"?address="+encodeURIComponent(init.address) +
|
|
157
|
-
"&amount="+encodeURIComponent(init.amount.toString(10))+
|
|
158
|
-
"&chain="+encodeURIComponent(chainIdentifier)+
|
|
159
|
-
"&token="+encodeURIComponent(init.token),
|
|
160
|
-
timeout,
|
|
161
|
-
abortSignal
|
|
162
|
-
), undefined, RequestError, abortSignal
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
if(resp.code!==10000) throw RequestError.parse(JSON.stringify(resp), 400);
|
|
166
|
-
const res = verifySchema(resp.data, TrustedFromBTCLNResponseSchema);
|
|
167
|
-
if(res==null) throw new Error("Invalid response returned from LP");
|
|
168
|
-
return res;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Fetches the address status from the intermediary node
|
|
173
|
-
*
|
|
174
|
-
* @param url Url of the trusted intermediary
|
|
175
|
-
* @param paymentHash Payment hash of the swap
|
|
176
|
-
* @param sequence Sequence number of the swap
|
|
177
|
-
* @param timeout Timeout in milliseconds
|
|
178
|
-
* @param abortSignal
|
|
179
|
-
* @throws {RequestError} if non-200 http response is returned
|
|
180
|
-
*/
|
|
181
|
-
static async getAddressStatus(
|
|
182
|
-
url: string,
|
|
183
|
-
paymentHash: string,
|
|
184
|
-
sequence: bigint,
|
|
185
|
-
timeout?: number,
|
|
186
|
-
abortSignal?: AbortSignal
|
|
187
|
-
): Promise<AddressStatusResponse> {
|
|
188
|
-
return tryWithRetries(() => httpGet<AddressStatusResponse>(
|
|
189
|
-
url+"/getAddressStatus?paymentHash="+encodeURIComponent(paymentHash)+"&sequence="+encodeURIComponent(sequence.toString(10)),
|
|
190
|
-
timeout, abortSignal
|
|
191
|
-
), undefined, RequestError, abortSignal);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Sets the refund address for an on-chain gas swap
|
|
196
|
-
*
|
|
197
|
-
* @param url Url of the trusted intermediary
|
|
198
|
-
* @param paymentHash Payment hash of the swap
|
|
199
|
-
* @param sequence Sequence number of the swap
|
|
200
|
-
* @param refundAddress Refund address to set for the swap
|
|
201
|
-
* @param timeout Timeout in milliseconds
|
|
202
|
-
* @param abortSignal
|
|
203
|
-
* @throws {RequestError} if non-200 http response is returned
|
|
204
|
-
*/
|
|
205
|
-
static async setRefundAddress(
|
|
206
|
-
url: string,
|
|
207
|
-
paymentHash: string,
|
|
208
|
-
sequence: bigint,
|
|
209
|
-
refundAddress: string,
|
|
210
|
-
timeout?: number,
|
|
211
|
-
abortSignal?: AbortSignal
|
|
212
|
-
): Promise<void> {
|
|
213
|
-
return tryWithRetries(() => httpGet<void>(
|
|
214
|
-
url+"/setRefundAddress" +
|
|
215
|
-
"?paymentHash="+encodeURIComponent(paymentHash)+
|
|
216
|
-
"&sequence="+encodeURIComponent(sequence.toString(10))+
|
|
217
|
-
"&refundAddress="+encodeURIComponent(refundAddress),
|
|
218
|
-
timeout, abortSignal
|
|
219
|
-
), undefined, RequestError, abortSignal);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Initiate a trusted swap from BTC to SC native currency, retries!
|
|
224
|
-
*
|
|
225
|
-
* @param chainIdentifier
|
|
226
|
-
* @param baseUrl Base url of the trusted swap intermediary
|
|
227
|
-
* @param init Initialization parameters
|
|
228
|
-
* @param timeout Timeout in milliseconds for the request
|
|
229
|
-
* @param abortSignal
|
|
230
|
-
* @throws {RequestError} If the response is non-200
|
|
231
|
-
*/
|
|
232
|
-
static async initTrustedFromBTC(
|
|
233
|
-
chainIdentifier: string,
|
|
234
|
-
baseUrl: string,
|
|
235
|
-
init: TrustedFromBTCInit,
|
|
236
|
-
timeout?: number,
|
|
237
|
-
abortSignal?: AbortSignal
|
|
238
|
-
): Promise<TrustedFromBTCResponseType> {
|
|
239
|
-
const resp = await tryWithRetries(
|
|
240
|
-
() => httpGet<{code: number, msg: string, data?: any}>(
|
|
241
|
-
baseUrl+"/frombtc_trusted/getAddress?chain="+encodeURIComponent(chainIdentifier)+
|
|
242
|
-
"&address="+encodeURIComponent(init.address)+
|
|
243
|
-
"&amount="+encodeURIComponent(init.amount.toString(10))+
|
|
244
|
-
(init.refundAddress==null ? "" : "&refundAddress="+encodeURIComponent(init.refundAddress))+
|
|
245
|
-
"&exactIn=true"+
|
|
246
|
-
"&token="+encodeURIComponent(init.token),
|
|
247
|
-
timeout,
|
|
248
|
-
abortSignal
|
|
249
|
-
), undefined, RequestError, abortSignal
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
if(resp.code!==10000) throw RequestError.parse(JSON.stringify(resp), 400);
|
|
253
|
-
const res = verifySchema(resp.data, TrustedFromBTCResponseSchema);
|
|
254
|
-
if(res==null) throw new Error("Invalid response returned from LP");
|
|
255
|
-
return res;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
}
|