@tetherto/wdk-wallet 1.0.0-beta.2 → 1.0.0-beta.20
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/AGENTS.md +49 -0
- package/bare.js +3 -3
- package/index.js +12 -2
- package/package.json +16 -3
- package/src/errors.js +318 -3
- package/src/multisig/errors.js +54 -0
- package/src/multisig/index.js +42 -0
- package/src/multisig/multisig-message-signing-read-only.js +63 -0
- package/src/multisig/multisig-message-signing.js +64 -0
- package/src/multisig/multisig-owner-management.js +94 -0
- package/src/multisig/wallet-account-multisig.js +144 -0
- package/src/multisig/wallet-account-read-only-multisig.js +98 -0
- package/src/protocols/bridge-protocol.js +35 -1
- package/src/protocols/errors.js +510 -0
- package/src/protocols/fiat-protocol.js +401 -0
- package/src/protocols/index.js +76 -0
- package/src/protocols/lending-protocol.js +114 -2
- package/src/protocols/sda-protocol.js +643 -0
- package/src/protocols/swap-protocol.js +36 -1
- package/src/protocols/swidge-protocol.js +516 -0
- package/src/signer.js +54 -0
- package/src/wallet-account-read-only-simple.js +162 -0
- package/src/wallet-account-read-only.js +186 -40
- package/src/wallet-account.js +49 -2
- package/src/wallet-manager.js +153 -24
- package/types/index.d.ts +12 -4
- package/types/src/errors.d.ts +220 -2
- package/types/src/multisig/errors.d.ts +33 -0
- package/types/src/multisig/index.d.ts +15 -0
- package/types/src/multisig/multisig-message-signing-read-only.d.ts +53 -0
- package/types/src/multisig/multisig-message-signing.d.ts +40 -0
- package/types/src/multisig/multisig-owner-management.d.ts +65 -0
- package/types/src/multisig/wallet-account-multisig.d.ts +101 -0
- package/types/src/multisig/wallet-account-read-only-multisig.d.ts +83 -0
- package/types/src/protocols/bridge-protocol.d.ts +39 -3
- package/types/src/protocols/errors.d.ts +366 -0
- package/types/src/protocols/fiat-protocol.d.ts +409 -0
- package/types/src/protocols/index.d.ts +64 -0
- package/types/src/protocols/lending-protocol.d.ts +118 -4
- package/types/src/protocols/sda-protocol.d.ts +737 -0
- package/types/src/protocols/swap-protocol.d.ts +44 -4
- package/types/src/protocols/swidge-protocol.d.ts +483 -0
- package/types/src/signer.d.ts +28 -0
- package/types/src/wallet-account-read-only-simple.d.ts +144 -0
- package/types/src/wallet-account-read-only.d.ts +104 -27
- package/types/src/wallet-account.d.ts +44 -4
- package/types/src/wallet-manager.d.ts +102 -15
|
@@ -0,0 +1,643 @@
|
|
|
1
|
+
// Copyright 2024 Tether Operations Limited
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
'use strict'
|
|
15
|
+
|
|
16
|
+
import { NotImplementedError, UnsupportedOperationError } from './errors.js'
|
|
17
|
+
|
|
18
|
+
/** @typedef {import('../wallet-account-read-only.js').IWalletAccountReadOnly} IWalletAccountReadOnly */
|
|
19
|
+
|
|
20
|
+
/** @typedef {import('../wallet-account.js').IWalletAccount} IWalletAccount */
|
|
21
|
+
|
|
22
|
+
/** @typedef {import('./errors.js').AccountRequiredError} AccountRequiredError */
|
|
23
|
+
/** @typedef {import('./errors.js').InvalidTokenError} InvalidTokenError */
|
|
24
|
+
/** @typedef {import('./errors.js').NoSuchElementError} NoSuchElementError */
|
|
25
|
+
/** @typedef {import('./errors.js').ReadOnlyAccountRequiredError} ReadOnlyAccountRequiredError */
|
|
26
|
+
/** @typedef {import('./errors.js').ProviderError} ProviderError */
|
|
27
|
+
/** @typedef {import('./errors.js').ProviderRequiredError} ProviderRequiredError */
|
|
28
|
+
/** @typedef {import('./errors.js').SdaError} SdaError */
|
|
29
|
+
/** @typedef {import('./errors.js').ValueError} ValueError */
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A blockchain identifier: a numeric chain id (e.g. `1`) or a protocol-specific chain name (e.g. `'ethereum'`).
|
|
33
|
+
*
|
|
34
|
+
* @typedef {string | number} Blockchain
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A normalized token reference. `token` is the identifier the protocol expects in SDA calls; `address` is the
|
|
39
|
+
* on-chain contract address when applicable (absent for native gas tokens).
|
|
40
|
+
*
|
|
41
|
+
* @typedef {Object} SdaToken
|
|
42
|
+
* @property {string} token - The protocol-specific token identifier to use in SDA calls.
|
|
43
|
+
* @property {Blockchain} chain - The chain on which the token lives.
|
|
44
|
+
* @property {string} symbol - The token symbol (e.g., 'USDC', 'USDT').
|
|
45
|
+
* @property {number} decimals - The number of decimal places for the token's base unit.
|
|
46
|
+
* @property {string} [address] - The token contract address, if applicable.
|
|
47
|
+
* @property {string} [name] - The token's full name.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Per-route deposit limits, denominated in the base unit of the route's input token. Either bound may be absent
|
|
52
|
+
* when the protocol does not enforce it; a protocol that only enforces limits in another denomination (e.g. USD)
|
|
53
|
+
* omits `limits` rather than converting.
|
|
54
|
+
*
|
|
55
|
+
* @typedef {Object} SdaDepositAddressLimits
|
|
56
|
+
* @property {number | bigint} [min] - Minimum deposit amount, in the input token's base unit.
|
|
57
|
+
* @property {number | bigint} [max] - Maximum deposit amount, in the input token's base unit.
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Optional filters for narrowing route discovery.
|
|
62
|
+
*
|
|
63
|
+
* @typedef {Object} SdaRoutesOptions
|
|
64
|
+
* @property {Blockchain} [sourceChain] - Restrict to routes that accept deposits from this chain.
|
|
65
|
+
* @property {string} [sourceToken] - Restrict to routes that accept this input token.
|
|
66
|
+
* @property {Blockchain} [destinationChain] - Restrict to routes that deliver to this chain.
|
|
67
|
+
* @property {string} [outputAsset] - Restrict to routes that deliver this asset.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A supported conversion route: one or more source chains and their accepted input tokens, the destination chain,
|
|
72
|
+
* and the asset delivered there.
|
|
73
|
+
*
|
|
74
|
+
* @typedef {Object} SdaRoute
|
|
75
|
+
* @property {Blockchain[]} sourceChains - The source chains this route accepts deposits from. A list because some
|
|
76
|
+
* protocols issue one address valid across a VM family.
|
|
77
|
+
* @property {SdaToken[]} inputTokens - The deposit tokens accepted on the source side.
|
|
78
|
+
* @property {Blockchain} destinationChain - The chain the converted asset is delivered to.
|
|
79
|
+
* @property {SdaToken} [outputAsset] - The asset delivered to the destination (e.g., USDT). If unset, the route
|
|
80
|
+
* delivers each input token as its own equivalent on the destination chain.
|
|
81
|
+
* @property {SdaDepositAddressLimits} [limits] - Deposit limits for this route.
|
|
82
|
+
* @property {boolean} [reusable] - Whether addresses issued for this route can receive more than one deposit.
|
|
83
|
+
* @property {number} [estimatedDuration] - Typical end-to-end duration in seconds.
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Options for fetching a deposit quote — a non-binding estimate of what a given deposit would deliver.
|
|
88
|
+
*
|
|
89
|
+
* @typedef {Object} SdaDepositOptions
|
|
90
|
+
* @property {Blockchain} sourceChain - The chain the deposit originates from.
|
|
91
|
+
* @property {string} inputToken - The protocol identifier of the token being deposited.
|
|
92
|
+
* @property {Blockchain} destinationChain - The chain the converted asset is delivered to.
|
|
93
|
+
* @property {string} [outputAsset] - The protocol identifier of the asset to deliver. Omit for protocols that deliver
|
|
94
|
+
* each input token as its own equivalent.
|
|
95
|
+
* @property {number | bigint} inputAmount - The amount to deposit, in the input token's base unit.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The category of a fee charged by the protocol.
|
|
100
|
+
*
|
|
101
|
+
* @typedef {'network' | 'protocol' | 'affiliate' | 'other'} SdaFeeType
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A single itemised fee.
|
|
106
|
+
*
|
|
107
|
+
* @typedef {Object} SdaFee
|
|
108
|
+
* @property {SdaFeeType} type - The category of the fee.
|
|
109
|
+
* @property {bigint} amount - The fee amount, in the fee token's base unit.
|
|
110
|
+
* @property {string} token - The token in which the fee is denominated.
|
|
111
|
+
* @property {Blockchain} [chain] - The chain on which the fee is charged.
|
|
112
|
+
* @property {boolean} [included] - Whether the fee is already reflected in the quoted output amount.
|
|
113
|
+
* @property {string} [description] - A human-readable description of the fee.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* A non-binding estimate of the asset delivered for a given deposit.
|
|
118
|
+
*
|
|
119
|
+
* @typedef {Object} SdaDepositQuote
|
|
120
|
+
* @property {Blockchain} inputChain - The chain the deposit originates from.
|
|
121
|
+
* @property {string} inputToken - The protocol identifier of the deposited token.
|
|
122
|
+
* @property {bigint} inputAmount - The amount deposited, in the input token's base unit.
|
|
123
|
+
* @property {Blockchain} destinationChain - The chain the converted asset is delivered to.
|
|
124
|
+
* @property {string} outputAsset - The protocol identifier of the delivered asset.
|
|
125
|
+
* @property {bigint} outputAmount - The estimated amount delivered, in the destination asset's base unit.
|
|
126
|
+
* @property {SdaFee[]} fees - Itemised fee breakdown.
|
|
127
|
+
* @property {string} [rate] - The effective conversion rate as a string, to avoid precision loss.
|
|
128
|
+
* @property {number} [expiry] - Unix timestamp (seconds) at which the quote expires.
|
|
129
|
+
* @property {string} [id] - The protocol quote identifier, if the protocol issues one.
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Options for creating a deposit address.
|
|
134
|
+
*
|
|
135
|
+
* @typedef {Object} SdaCreateDepositAddressOptions
|
|
136
|
+
* @property {Blockchain[]} sourceChains - One or more source chains the address should accept deposits from. Protocols
|
|
137
|
+
* that issue one address per VM family use the full list; single-chain protocols use a one-element list.
|
|
138
|
+
* @property {Blockchain} destinationChain - The chain the converted asset is delivered to.
|
|
139
|
+
* @property {string} [outputAsset] - The protocol identifier of the asset to deliver (e.g., USDT). Omit for protocols
|
|
140
|
+
* that deliver each input token as its own equivalent.
|
|
141
|
+
* @property {string} [destinationAddress] - The address that receives the delivered asset. Defaults to the bound
|
|
142
|
+
* account's address.
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* A deposit address plus its normalized descriptor: where it accepts deposits from, what it accepts, where it
|
|
147
|
+
* delivers, and its lifecycle metadata.
|
|
148
|
+
*
|
|
149
|
+
* @typedef {Object} SdaDepositAddress
|
|
150
|
+
* @property {string} address - The deposit address the user sends funds to.
|
|
151
|
+
* @property {string} id - The protocol identifier for this SDA, used for status, recovery and disabling.
|
|
152
|
+
* @property {Blockchain[]} sourceChains - The chains this address accepts deposits from.
|
|
153
|
+
* @property {SdaToken[]} supportedInputTokens - The tokens this address accepts.
|
|
154
|
+
* @property {Blockchain} destinationChain - The chain the converted asset is delivered to.
|
|
155
|
+
* @property {SdaToken} [outputAsset] - The asset delivered to the destination. If unset, the address delivers each
|
|
156
|
+
* input token as its own equivalent on the destination chain.
|
|
157
|
+
* @property {string} destinationAddress - The resolved address that receives the delivered asset.
|
|
158
|
+
* @property {SdaDepositAddressLimits} [limits] - Deposit limits for this address.
|
|
159
|
+
* @property {boolean} reusable - Whether the address can receive more than one deposit.
|
|
160
|
+
* @property {number} [expiry] - Unix timestamp (seconds) at which the address's activation expires, when the protocol's
|
|
161
|
+
* address activation is time-limited.
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The lifecycle status of a deposit/transfer through an SDA.
|
|
166
|
+
*
|
|
167
|
+
* @typedef {'pending' | 'detected' | 'processing' | 'completed' | 'failed'
|
|
168
|
+
* | 'refund-pending' | 'refunded' | 'expired'} SdaTransferStatus
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* A single deposit observed at, and processed through, an SDA.
|
|
173
|
+
*
|
|
174
|
+
* @typedef {Object} SdaTransfer
|
|
175
|
+
* @property {string} id - The protocol identifier for this transfer.
|
|
176
|
+
* @property {SdaTransferStatus} status - The current status of the transfer.
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Optional pagination/filtering for transfer history.
|
|
181
|
+
*
|
|
182
|
+
* @typedef {Object} SdaTransfersOptions
|
|
183
|
+
* @property {Blockchain} [sourceChain] - The source chain of the deposit address, required by protocols that key
|
|
184
|
+
* addresses by (address, chain).
|
|
185
|
+
* @property {number} [limit] - The maximum number of transfers to return.
|
|
186
|
+
* @property {number} [skip] - The number of transfers to skip, for offset-based pagination.
|
|
187
|
+
* @property {SdaTransferStatus} [status] - Restrict to transfers in this status.
|
|
188
|
+
*/
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Recover a deposit by the SDA identifier.
|
|
192
|
+
*
|
|
193
|
+
* @typedef {Object} SdaRecoverById
|
|
194
|
+
* @property {string} id - The protocol SDA identifier (the `SdaDepositAddress.id`).
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Recover a deposit by its deposit address.
|
|
199
|
+
*
|
|
200
|
+
* @typedef {Object} SdaRecoverByAddress
|
|
201
|
+
* @property {string} address - The deposit address to reindex.
|
|
202
|
+
* @property {Blockchain} [sourceChain] - The chain of the deposit address, required by protocols that key addresses by
|
|
203
|
+
* (address, chain).
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Options for re-processing a deposit that was not picked up automatically (`reindex`). A caller identifies the
|
|
208
|
+
* deposit either by SDA id or by its deposit address.
|
|
209
|
+
*
|
|
210
|
+
* @typedef {SdaRecoverById | SdaRecoverByAddress} SdaRecoveryOptions
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* The outcome of a recovery attempt.
|
|
215
|
+
*
|
|
216
|
+
* @typedef {Object} SdaRecoveryResult
|
|
217
|
+
* @property {'reindexed' | 'pending' | 'failed'} status - The result of the reindex attempt.
|
|
218
|
+
* @property {string} [address] - The address that was reindexed.
|
|
219
|
+
* @property {string} [id] - The protocol SDA identifier.
|
|
220
|
+
* @property {SdaTransfer} [transfer] - The transfer that was recovered, if one resulted.
|
|
221
|
+
* @property {string} [message] - A human-readable description of the outcome.
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Interface for "Smart Deposit Address" (SDA) protocols: services that issue a deposit address, accept a
|
|
226
|
+
* stablecoin (or native token) from a supported source chain, convert it, and deliver a chosen asset (e.g., USDT)
|
|
227
|
+
* to a chosen destination chain and address.
|
|
228
|
+
*
|
|
229
|
+
* The required core every protocol implements is route discovery and address creation; every other operation is
|
|
230
|
+
* optional.
|
|
231
|
+
*
|
|
232
|
+
* @interface
|
|
233
|
+
*/
|
|
234
|
+
export class ISdaProtocol {
|
|
235
|
+
/**
|
|
236
|
+
* Lists the conversion routes the protocol supports: source chains, accepted input tokens, output assets and
|
|
237
|
+
* per-route deposit limits. A protocol that discovers routes by blockchain pairs might require the `sourceChain`
|
|
238
|
+
* and `destinationChain` options to be set.
|
|
239
|
+
*
|
|
240
|
+
* @param {SdaRoutesOptions} [options] - Optional filters for route discovery.
|
|
241
|
+
* @returns {Promise<SdaRoute[]>} The supported routes.
|
|
242
|
+
* @throws {ValueError} If the protocol discovers routes by blockchain pairs and the source or destination blockchain
|
|
243
|
+
* is not set.
|
|
244
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
245
|
+
* @throws {ProviderError} If the provider fails to fetch the available routes.
|
|
246
|
+
*/
|
|
247
|
+
async getSupportedRoutes (options) {
|
|
248
|
+
throw new NotImplementedError('getSupportedRoutes(options)')
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Fetches a non-binding quote (estimate) for a deposit — what a given deposit would deliver.
|
|
253
|
+
*
|
|
254
|
+
* @param {SdaDepositOptions} options - The quote options.
|
|
255
|
+
* @returns {Promise<SdaDepositQuote>} The quoted deposit details.
|
|
256
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
257
|
+
* @throws {ReadOnlyAccountRequiredError} If the protocol requires a read-only or full account to quote the costs of a deposit.
|
|
258
|
+
* @throws {ValueError} If the deposit options are not valid.
|
|
259
|
+
* @throws {InvalidTokenError} If the input token is not a valid ERC 20 token's address.
|
|
260
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
261
|
+
* @throws {ProviderError} If the provider fails to estimate the costs of the deposit.
|
|
262
|
+
*/
|
|
263
|
+
async quoteDeposit (options) {
|
|
264
|
+
throw new NotImplementedError('quoteDeposit(options)')
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Creates deposit addresses for the given route and destination, ready to receive per the protocol's activation
|
|
269
|
+
* lifecycle — a protocol that activates addresses also activates the created address so it is monitored. Returns
|
|
270
|
+
* one entry per distinct address: a protocol that issues a single address across a chain family returns one entry
|
|
271
|
+
* covering all of `sourceChains`, while a protocol that issues one address per source chain returns one entry each.
|
|
272
|
+
*
|
|
273
|
+
* @param {SdaCreateDepositAddressOptions} options - The address creation options.
|
|
274
|
+
* @returns {Promise<SdaDepositAddress[]>} The created deposit addresses, one per distinct address.
|
|
275
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to create a new deposit address.
|
|
276
|
+
* @throws {ValueError} If the create deposit address options are not valid.
|
|
277
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
278
|
+
* @throws {ProviderError} If the provider fails to create a new deposit address.
|
|
279
|
+
* @throws {SdaError} If the operation fails with an error.
|
|
280
|
+
*/
|
|
281
|
+
async createDepositAddress (options) {
|
|
282
|
+
throw new NotImplementedError('createDepositAddress(options)')
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Derives a deposit address client-side, without any protocol call and without activating or monitoring it —
|
|
287
|
+
* used to verify (derive + compare) or recover an address for a self-custodial protocol.
|
|
288
|
+
*
|
|
289
|
+
* @param {SdaCreateDepositAddressOptions} options - The same options passed to
|
|
290
|
+
* {@link ISdaProtocol#createDepositAddress}; a protocol needing extra derivation inputs declares them on its own
|
|
291
|
+
* options type (which extends `SdaCreateDepositAddressOptions`).
|
|
292
|
+
* @returns {Promise<string>} The derived deposit address.
|
|
293
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
294
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to derive a deposit address.
|
|
295
|
+
* @throws {ValueError} If the create deposit address options are not valid.
|
|
296
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
297
|
+
* @throws {ProviderError} If the provider fails to derive the deposit address.
|
|
298
|
+
* @throws {SdaError} If the operation fails with an error.
|
|
299
|
+
*/
|
|
300
|
+
async deriveDepositAddress (options) {
|
|
301
|
+
throw new NotImplementedError('deriveDepositAddress(options)')
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Looks up an existing deposit address by its identifier — the `SdaDepositAddress.id` returned by
|
|
306
|
+
* {@link ISdaProtocol#createDepositAddress}, which round-trips any chain context the protocol needs.
|
|
307
|
+
*
|
|
308
|
+
* @param {string} id - The deposit-address identifier returned in `SdaDepositAddress.id` (round-trips any chain
|
|
309
|
+
* context the protocol needs).
|
|
310
|
+
* @returns {Promise<SdaDepositAddress>} The deposit address descriptor.
|
|
311
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
312
|
+
* @throws {ValueError} If the id is not valid.
|
|
313
|
+
* @throws {NoSuchElementError} If no deposit address exists for the given id.
|
|
314
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
315
|
+
* @throws {ProviderError} If the provider fails to fetch the deposit's address.
|
|
316
|
+
*/
|
|
317
|
+
async getDepositAddress (id) {
|
|
318
|
+
throw new NotImplementedError('getDepositAddress(id)')
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Refreshes the activation of a deposit address so the protocol keeps monitoring it.
|
|
323
|
+
*
|
|
324
|
+
* @param {string} id - The deposit-address identifier returned in `SdaDepositAddress.id`.
|
|
325
|
+
* @returns {Promise<SdaDepositAddress>} The refreshed deposit address descriptor (with the new `expiry`).
|
|
326
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
327
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to renew a deposit address.
|
|
328
|
+
* @throws {ValueError} If the id is not valid.
|
|
329
|
+
* @throws {NoSuchElementError} If no deposit address exists for the given id.
|
|
330
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
331
|
+
* @throws {ProviderError} If the provider fails to renew the deposit address.
|
|
332
|
+
* @throws {SdaError} If the operation fails with an error.
|
|
333
|
+
*/
|
|
334
|
+
async renewDepositAddress (id) {
|
|
335
|
+
throw new NotImplementedError('renewDepositAddress(id)')
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Lists the deposits observed at a deposit address.
|
|
340
|
+
*
|
|
341
|
+
* @param {string} address - The deposit address to list transfers for.
|
|
342
|
+
* @param {SdaTransfersOptions} [options] - Optional pagination/filtering, plus `sourceChain` for protocols that key
|
|
343
|
+
* addresses by (address, chain).
|
|
344
|
+
* @returns {Promise<SdaTransfer[]>} The transfers for the address.
|
|
345
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
346
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
347
|
+
* @throws {ProviderError} If the provider fails to fetch transfers.
|
|
348
|
+
*/
|
|
349
|
+
async getTransfers (address, options) {
|
|
350
|
+
throw new NotImplementedError('getTransfers(address, options)')
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Lists transfers aggregated by recipient — every deposit routed to the given recipient across all of that
|
|
355
|
+
* recipient's deposit addresses and source chains.
|
|
356
|
+
*
|
|
357
|
+
* @param {Blockchain} destinationChain - The destination chain the transfers are delivered to.
|
|
358
|
+
* @param {string} recipient - The recipient (destination) address to aggregate transfers for.
|
|
359
|
+
* @param {SdaTransfersOptions} [options] - Optional pagination/filtering.
|
|
360
|
+
* @returns {Promise<SdaTransfer[]>} The transfers routed to the recipient.
|
|
361
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
362
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
363
|
+
* @throws {ProviderError} If the provider fails to fetch transfers.
|
|
364
|
+
*/
|
|
365
|
+
async getTransfersByRecipient (destinationChain, recipient, options) {
|
|
366
|
+
throw new NotImplementedError('getTransfersByRecipient(destinationChain, recipient, options)')
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Retrieves a single transfer by its identifier.
|
|
371
|
+
*
|
|
372
|
+
* @param {string} id - The transfer identifier.
|
|
373
|
+
* @returns {Promise<SdaTransfer>} The transfer's current status.
|
|
374
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
375
|
+
* @throws {ValueError} If the id is not valid.
|
|
376
|
+
* @throws {NoSuchElementError} If no transfer exists for the given id.
|
|
377
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
378
|
+
* @throws {ProviderError} If the provider fails to fetch the transfer.
|
|
379
|
+
*/
|
|
380
|
+
async getTransfer (id) {
|
|
381
|
+
throw new NotImplementedError('getTransfer(id)')
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Recovers a deposit or address that was not picked up automatically, using the protocol's recovery mode.
|
|
386
|
+
*
|
|
387
|
+
* @param {SdaRecoveryOptions} options - The recovery options.
|
|
388
|
+
* @returns {Promise<SdaRecoveryResult>} The recovery outcome.
|
|
389
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
390
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to recover a deposit address.
|
|
391
|
+
* @throws {ValueError} If the id is not valid.
|
|
392
|
+
* @throws {NoSuchElementError} If no deposit address exists for the given id or address.
|
|
393
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
394
|
+
* @throws {ProviderError} If the provider fails to recover the deposit address.
|
|
395
|
+
* @throws {SdaError} If the operation fails with an error.
|
|
396
|
+
*/
|
|
397
|
+
async recoverDepositAddress (options) {
|
|
398
|
+
throw new NotImplementedError('recoverDepositAddress(options)')
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Disables a deposit address so it no longer accepts deposits.
|
|
403
|
+
*
|
|
404
|
+
* @param {string} id - The deposit-address identifier returned in `SdaDepositAddress.id` (round-trips any chain
|
|
405
|
+
* context the protocol needs).
|
|
406
|
+
* @returns {Promise<void>} Resolves once the address has been disabled.
|
|
407
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
408
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to disable a deposit address.
|
|
409
|
+
* @throws {ValueError} If the id is not valid.
|
|
410
|
+
* @throws {NoSuchElementError} If no deposit address exists for the given id.
|
|
411
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
412
|
+
* @throws {ProviderError} If the provider fails to disable the deposit address.
|
|
413
|
+
* @throws {SdaError} If the operation fails with an error.
|
|
414
|
+
*/
|
|
415
|
+
async disableDepositAddress (id) {
|
|
416
|
+
throw new NotImplementedError('disableDepositAddress(id)')
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Abstract base class for "Smart Deposit Address" (SDA) protocols.
|
|
422
|
+
*
|
|
423
|
+
* @abstract
|
|
424
|
+
* @implements {ISdaProtocol}
|
|
425
|
+
*/
|
|
426
|
+
export default class SdaProtocol {
|
|
427
|
+
/**
|
|
428
|
+
* Creates a new SDA protocol without binding it to a wallet account.
|
|
429
|
+
*
|
|
430
|
+
* @overload
|
|
431
|
+
* @param {undefined} [account] - The wallet account to use to interact with the protocol.
|
|
432
|
+
*/
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Creates a new read-only SDA protocol.
|
|
436
|
+
*
|
|
437
|
+
* @overload
|
|
438
|
+
* @param {IWalletAccountReadOnly} account - The wallet account to use to interact with the protocol.
|
|
439
|
+
*/
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Creates a new SDA protocol.
|
|
443
|
+
*
|
|
444
|
+
* @overload
|
|
445
|
+
* @param {IWalletAccount} account - The wallet account to use to interact with the protocol.
|
|
446
|
+
*/
|
|
447
|
+
constructor (account) {
|
|
448
|
+
/**
|
|
449
|
+
* The wallet account to use to interact with the protocol. The account's address is the default delivery
|
|
450
|
+
* destination for created addresses.
|
|
451
|
+
*
|
|
452
|
+
* @protected
|
|
453
|
+
* @type {IWalletAccountReadOnly | IWalletAccount | undefined}
|
|
454
|
+
*/
|
|
455
|
+
this._account = account
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Lists the conversion routes the protocol supports: source chains, accepted input tokens, output assets and
|
|
460
|
+
* per-route deposit limits. A protocol that discovers routes by blockchain pairs might require the `sourceChain`
|
|
461
|
+
* and `destinationChain` options to be set.
|
|
462
|
+
*
|
|
463
|
+
* @abstract
|
|
464
|
+
* @param {SdaRoutesOptions} [options] - Optional filters for route discovery.
|
|
465
|
+
* @returns {Promise<SdaRoute[]>} The supported routes.
|
|
466
|
+
* @throws {ValueError} If the protocol discovers routes by blockchain pairs and the source or destination blockchain
|
|
467
|
+
* is not set.
|
|
468
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
469
|
+
* @throws {ProviderError} If the provider fails to fetch the available routes.
|
|
470
|
+
*/
|
|
471
|
+
async getSupportedRoutes (options) {
|
|
472
|
+
throw new NotImplementedError('getSupportedRoutes(options)')
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Fetches a non-binding quote (estimate) for a deposit — what a given deposit would deliver.
|
|
477
|
+
*
|
|
478
|
+
* @param {SdaDepositOptions} options - The quote options.
|
|
479
|
+
* @returns {Promise<SdaDepositQuote>} The quoted deposit details.
|
|
480
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
481
|
+
* @throws {ReadOnlyAccountRequiredError} If the protocol requires a read-only or full account to quote the costs of a deposit.
|
|
482
|
+
* @throws {ValueError} If the deposit options are not valid.
|
|
483
|
+
* @throws {InvalidTokenError} If the input token is not a valid ERC 20 token's address.
|
|
484
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
485
|
+
* @throws {ProviderError} If the provider fails to estimate the costs of the deposit.
|
|
486
|
+
*/
|
|
487
|
+
async quoteDeposit (options) {
|
|
488
|
+
throw new UnsupportedOperationError('quoteDeposit(options)')
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Creates deposit addresses for the given route and destination, ready to receive per the protocol's activation
|
|
493
|
+
* lifecycle — a protocol that activates addresses also activates the created address so it is monitored. Returns
|
|
494
|
+
* one entry per distinct address: a protocol that issues a single address across a chain family returns one entry
|
|
495
|
+
* covering all of `sourceChains`, while a protocol that issues one address per source chain returns one entry each.
|
|
496
|
+
*
|
|
497
|
+
* @abstract
|
|
498
|
+
* @param {SdaCreateDepositAddressOptions} options - The address creation options.
|
|
499
|
+
* @returns {Promise<SdaDepositAddress[]>} The created deposit addresses, one per distinct address.
|
|
500
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to create a new deposit address.
|
|
501
|
+
* @throws {ValueError} If the create deposit address options are not valid.
|
|
502
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
503
|
+
* @throws {ProviderError} If the provider fails to create a new deposit address.
|
|
504
|
+
* @throws {SdaError} If the operation fails with an error.
|
|
505
|
+
*/
|
|
506
|
+
async createDepositAddress (options) {
|
|
507
|
+
throw new NotImplementedError('createDepositAddress(options)')
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Derives a deposit address client-side, without any protocol call and without activating or monitoring it —
|
|
512
|
+
* used to verify (derive + compare) or recover an address for a self-custodial protocol.
|
|
513
|
+
*
|
|
514
|
+
* @param {SdaCreateDepositAddressOptions} options - The same options passed to
|
|
515
|
+
* {@link ISdaProtocol#createDepositAddress}; a protocol needing extra derivation inputs declares them on its own
|
|
516
|
+
* options type (which extends `SdaCreateDepositAddressOptions`).
|
|
517
|
+
* @returns {Promise<string>} The derived deposit address.
|
|
518
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
519
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to derive a deposit address.
|
|
520
|
+
* @throws {ValueError} If the create deposit address options are not valid.
|
|
521
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
522
|
+
* @throws {ProviderError} If the provider fails to derive the deposit address.
|
|
523
|
+
* @throws {SdaError} If the operation fails with an error.
|
|
524
|
+
*/
|
|
525
|
+
async deriveDepositAddress (options) {
|
|
526
|
+
throw new UnsupportedOperationError('deriveDepositAddress(options)')
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Looks up an existing deposit address by its identifier — the `SdaDepositAddress.id` returned by
|
|
531
|
+
* {@link ISdaProtocol#createDepositAddress}, which round-trips any chain context the protocol needs.
|
|
532
|
+
*
|
|
533
|
+
* @param {string} id - The deposit-address identifier returned in `SdaDepositAddress.id` (round-trips any chain
|
|
534
|
+
* context the protocol needs).
|
|
535
|
+
* @returns {Promise<SdaDepositAddress>} The deposit address descriptor.
|
|
536
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
537
|
+
* @throws {ValueError} If the id is not valid.
|
|
538
|
+
* @throws {NoSuchElementError} If no deposit address exists for the given id.
|
|
539
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
540
|
+
* @throws {ProviderError} If the provider fails to fetch the deposit's address.
|
|
541
|
+
*/
|
|
542
|
+
async getDepositAddress (id) {
|
|
543
|
+
throw new UnsupportedOperationError('getDepositAddress(id)')
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Refreshes the activation of a deposit address so the protocol keeps monitoring it.
|
|
548
|
+
*
|
|
549
|
+
* @param {string} id - The deposit-address identifier returned in `SdaDepositAddress.id`.
|
|
550
|
+
* @returns {Promise<SdaDepositAddress>} The refreshed deposit address descriptor (with the new `expiry`).
|
|
551
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
552
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to renew a deposit address.
|
|
553
|
+
* @throws {ValueError} If the id is not valid.
|
|
554
|
+
* @throws {NoSuchElementError} If no deposit address exists for the given id.
|
|
555
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
556
|
+
* @throws {ProviderError} If the provider fails to renew the deposit address.
|
|
557
|
+
* @throws {SdaError} If the operation fails with an error.
|
|
558
|
+
*/
|
|
559
|
+
async renewDepositAddress (id) {
|
|
560
|
+
throw new UnsupportedOperationError('renewDepositAddress(id)')
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Lists the deposits observed at a deposit address.
|
|
565
|
+
*
|
|
566
|
+
* @param {string} address - The deposit address to list transfers for.
|
|
567
|
+
* @param {SdaTransfersOptions} [options] - Optional pagination/filtering, plus `sourceChain` for protocols that key
|
|
568
|
+
* addresses by (address, chain).
|
|
569
|
+
* @returns {Promise<SdaTransfer[]>} The transfers for the address.
|
|
570
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
571
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
572
|
+
* @throws {ProviderError} If the provider fails to fetch transfers.
|
|
573
|
+
*/
|
|
574
|
+
async getTransfers (address, options) {
|
|
575
|
+
throw new UnsupportedOperationError('getTransfers(address, options)')
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Lists transfers aggregated by recipient — every deposit routed to the given recipient across all of that
|
|
580
|
+
* recipient's deposit addresses and source chains.
|
|
581
|
+
*
|
|
582
|
+
* @param {Blockchain} destinationChain - The destination chain the transfers are delivered to.
|
|
583
|
+
* @param {string} recipient - The recipient (destination) address to aggregate transfers for.
|
|
584
|
+
* @param {SdaTransfersOptions} [options] - Optional pagination/filtering.
|
|
585
|
+
* @returns {Promise<SdaTransfer[]>} The transfers routed to the recipient.
|
|
586
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
587
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
588
|
+
* @throws {ProviderError} If the provider fails to fetch transfers.
|
|
589
|
+
*/
|
|
590
|
+
async getTransfersByRecipient (destinationChain, recipient, options) {
|
|
591
|
+
throw new UnsupportedOperationError('getTransfersByRecipient(destinationChain, recipient, options)')
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Retrieves a single transfer by its identifier.
|
|
596
|
+
*
|
|
597
|
+
* @param {string} id - The transfer identifier.
|
|
598
|
+
* @returns {Promise<SdaTransfer>} The transfer's current status.
|
|
599
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
600
|
+
* @throws {ValueError} If the id is not valid.
|
|
601
|
+
* @throws {NoSuchElementError} If no transfer exists for the given id.
|
|
602
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
603
|
+
* @throws {ProviderError} If the provider fails to fetch the transfer.
|
|
604
|
+
*/
|
|
605
|
+
async getTransfer (id) {
|
|
606
|
+
throw new UnsupportedOperationError('getTransfer(id)')
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Recovers a deposit or address that was not picked up automatically, using the protocol's recovery mode.
|
|
611
|
+
*
|
|
612
|
+
* @param {SdaRecoveryOptions} options - The recovery options.
|
|
613
|
+
* @returns {Promise<SdaRecoveryResult>} The recovery outcome.
|
|
614
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
615
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to recover a deposit address.
|
|
616
|
+
* @throws {ValueError} If the id is not valid.
|
|
617
|
+
* @throws {NoSuchElementError} If no deposit address exists for the given id or address.
|
|
618
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
619
|
+
* @throws {ProviderError} If the provider fails to recover the deposit address.
|
|
620
|
+
* @throws {SdaError} If the operation fails with an error.
|
|
621
|
+
*/
|
|
622
|
+
async recoverDepositAddress (options) {
|
|
623
|
+
throw new UnsupportedOperationError('recoverDepositAddress(options)')
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Disables a deposit address so it no longer accepts deposits.
|
|
628
|
+
*
|
|
629
|
+
* @param {string} id - The deposit-address identifier returned in `SdaDepositAddress.id` (round-trips any chain
|
|
630
|
+
* context the protocol needs).
|
|
631
|
+
* @returns {Promise<void>} Resolves once the address has been disabled.
|
|
632
|
+
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
633
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to disable a deposit address.
|
|
634
|
+
* @throws {ValueError} If the id is not valid.
|
|
635
|
+
* @throws {NoSuchElementError} If no deposit address exists for the given id.
|
|
636
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
637
|
+
* @throws {ProviderError} If the provider fails to disable the deposit address.
|
|
638
|
+
* @throws {SdaError} If the operation fails with an error.
|
|
639
|
+
*/
|
|
640
|
+
async disableDepositAddress (id) {
|
|
641
|
+
throw new UnsupportedOperationError('disableDepositAddress(id)')
|
|
642
|
+
}
|
|
643
|
+
}
|