@cosmosapp/pay_sdk 1.2.1 → 2.1.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/CHANGELOG.md +31 -0
- package/LICENSE +0 -75
- package/NOTICE +8 -0
- package/README.md +73 -13
- package/dist/chunk-AYVWYEOK.js +62 -0
- package/dist/chunk-AYVWYEOK.js.map +1 -0
- package/dist/{chunk-KZNJR223.js → chunk-NK5EHEKJ.js} +5 -3
- package/dist/chunk-NK5EHEKJ.js.map +1 -0
- package/dist/cosmosProvider-CFASjnd5.d.cts +100 -0
- package/dist/cosmosProvider-CFASjnd5.d.ts +100 -0
- package/dist/index.cjs +1311 -152
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +905 -42
- package/dist/index.d.ts +905 -42
- package/dist/index.js +1295 -154
- package/dist/index.js.map +1 -1
- package/dist/intent-input-8rZfCrQ0.d.cts +2042 -0
- package/dist/intent-input-8rZfCrQ0.d.ts +2042 -0
- package/dist/swk/index.cjs +170 -0
- package/dist/swk/index.cjs.map +1 -0
- package/dist/swk/index.d.cts +207 -0
- package/dist/swk/index.d.ts +207 -0
- package/dist/swk/index.js +106 -0
- package/dist/swk/index.js.map +1 -0
- package/dist/web/index.cjs +129 -2
- package/dist/web/index.cjs.map +1 -1
- package/dist/web/index.d.cts +49 -4
- package/dist/web/index.d.ts +49 -4
- package/dist/web/index.js +67 -4
- package/dist/web/index.js.map +1 -1
- package/llms/08-products-customers.md +1 -1
- package/llms/13-types-reference.md +1 -1
- package/llms/15-swaps.md +58 -0
- package/llms/llms-full.txt +63 -2
- package/llms/llms.txt +1 -0
- package/package.json +20 -7
- package/dist/chunk-KZNJR223.js.map +0 -1
- package/dist/intent-input-Ch8ogEg-.d.cts +0 -750
- package/dist/intent-input-Ch8ogEg-.d.ts +0 -750
package/dist/index.js
CHANGED
|
@@ -1,8 +1,86 @@
|
|
|
1
|
-
import { version, DEFAULT_VERSION, DEFAULT_BASE_URL, DEFAULT_TIMEOUT, DEFAULT_RETRIES, Events, CosmosPayAPIError, CosmosPayRequestError, resolveIntentBody, SIGNATURE_HEADER } from './chunk-
|
|
2
|
-
export { AddressBook, Assets, CosmosPayAPIError, CosmosPayRequestError, DEFAULT_BASE_URL, DEFAULT_RETRIES, DEFAULT_TIMEOUT, DEFAULT_VERSION, Events, SIGNATURE_HEADER, TestnetAssets, Wallets, addresses, assertAddress, defineAsset, isAddress, isContractAddress, isMuxedAddress, isNativeAsset, isStellarAddress, resolveAddress, resolveAsset, resolveIntentBody, version } from './chunk-
|
|
1
|
+
import { version, DEFAULT_VERSION, DEFAULT_BASE_URL, DEFAULT_TIMEOUT, DEFAULT_RETRIES, Events, CosmosPayAPIError, CosmosPayRequestError, resolveIntentBody, SIGNATURE_HEADER } from './chunk-NK5EHEKJ.js';
|
|
2
|
+
export { AddressBook, Assets, CosmosPayAPIError, CosmosPayRequestError, DEFAULT_BASE_URL, DEFAULT_RETRIES, DEFAULT_TIMEOUT, DEFAULT_VERSION, Events, SIGNATURE_HEADER, TestnetAssets, Wallets, addresses, assertAddress, defineAsset, isAddress, isContractAddress, isMuxedAddress, isNativeAsset, isStellarAddress, resolveAddress, resolveAsset, resolveIntentBody, version } from './chunk-NK5EHEKJ.js';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import { createHmac, timingSafeEqual } from 'crypto';
|
|
5
5
|
|
|
6
|
+
// src/managers/AliasManager.ts
|
|
7
|
+
var AliasManager = class {
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.route = "/aliases";
|
|
10
|
+
this.client = client;
|
|
11
|
+
}
|
|
12
|
+
get rest() {
|
|
13
|
+
return this.client.rest;
|
|
14
|
+
}
|
|
15
|
+
/** Where to pay a handle: its verified addresses on a network, primary first. */
|
|
16
|
+
resolve(name, options = {}) {
|
|
17
|
+
return this.rest.get(`${this.route}/resolve/${encodeURIComponent(name)}`, {
|
|
18
|
+
query: { network: options.network }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** Whether a handle can be claimed, and if not, why not. */
|
|
22
|
+
availability(name) {
|
|
23
|
+
return this.rest.get(`${this.route}/availability/${encodeURIComponent(name)}`);
|
|
24
|
+
}
|
|
25
|
+
/** Which handles point at an address — the reverse lookup. */
|
|
26
|
+
byAddress(address, options = {}) {
|
|
27
|
+
return this.rest.get(`${this.route}/by-address/${encodeURIComponent(address)}`, {
|
|
28
|
+
query: { network: options.network }
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** A nonce and the exact message to sign, for a claim, a new address or a recovery. */
|
|
32
|
+
createChallenge(options) {
|
|
33
|
+
return this.rest.post(`${this.route}/challenges`, { body: options });
|
|
34
|
+
}
|
|
35
|
+
/** Claim a handle with a signature over a CLAIM challenge. */
|
|
36
|
+
claim(options) {
|
|
37
|
+
return this.rest.post(this.route, { body: options });
|
|
38
|
+
}
|
|
39
|
+
/** The handles this consumer owns (paginated). */
|
|
40
|
+
list(options = {}) {
|
|
41
|
+
return this.rest.get(this.route, {
|
|
42
|
+
query: { take: options.take, skip: options.skip }
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** Point a handle at another address, signed by that address (ADD_ADDRESS challenge). */
|
|
46
|
+
addAddress(name, options) {
|
|
47
|
+
return this.rest.post(`${this.route}/${encodeURIComponent(name)}/addresses`, {
|
|
48
|
+
body: options
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** Remove one address from a handle. */
|
|
52
|
+
removeAddress(name, addressId) {
|
|
53
|
+
return this.rest.delete(
|
|
54
|
+
`${this.route}/${encodeURIComponent(name)}/addresses/${encodeURIComponent(addressId)}`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
/** Release a handle back to the namespace. */
|
|
58
|
+
release(name) {
|
|
59
|
+
return this.rest.delete(`${this.route}/${encodeURIComponent(name)}`);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Start a recovery: the service emails a one-time token to the mailbox the
|
|
63
|
+
* handle was claimed with, if `email` is that mailbox. The answer is the same
|
|
64
|
+
* either way, so it says nothing about who owns the handle; the token only
|
|
65
|
+
* ever reaches the mailbox, never this response.
|
|
66
|
+
*/
|
|
67
|
+
startRecovery(name, email) {
|
|
68
|
+
return this.rest.post(`${this.route}/${encodeURIComponent(name)}/recovery`, {
|
|
69
|
+
body: { email }
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Take a handle over with a new address after losing the old one: the token
|
|
74
|
+
* the owner received by email, plus a signature by the new address over a
|
|
75
|
+
* RECOVER challenge.
|
|
76
|
+
*/
|
|
77
|
+
completeRecovery(name, options) {
|
|
78
|
+
return this.rest.post(`${this.route}/${encodeURIComponent(name)}/recovery/complete`, {
|
|
79
|
+
body: options
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
6
84
|
// src/managers/AnalyticsManager.ts
|
|
7
85
|
var AnalyticsManager = class {
|
|
8
86
|
constructor(client) {
|
|
@@ -29,6 +107,23 @@ var AnalyticsManager = class {
|
|
|
29
107
|
}
|
|
30
108
|
};
|
|
31
109
|
|
|
110
|
+
// src/managers/AssetManager.ts
|
|
111
|
+
var AssetManager = class {
|
|
112
|
+
constructor(client) {
|
|
113
|
+
this.route = "/assets";
|
|
114
|
+
this.client = client;
|
|
115
|
+
}
|
|
116
|
+
get rest() {
|
|
117
|
+
return this.client.rest;
|
|
118
|
+
}
|
|
119
|
+
/** The registry for a network. */
|
|
120
|
+
list(options = {}) {
|
|
121
|
+
return this.rest.get(this.route, {
|
|
122
|
+
query: { network: options.network, verified: options.verified }
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
32
127
|
// src/structures/Base.ts
|
|
33
128
|
var Base = class {
|
|
34
129
|
constructor(client, data) {
|
|
@@ -59,7 +154,6 @@ var Customer = class extends Base {
|
|
|
59
154
|
}
|
|
60
155
|
_patch(data) {
|
|
61
156
|
super._patch(data);
|
|
62
|
-
this.consumerId = data.consumerId;
|
|
63
157
|
this.name = data.name;
|
|
64
158
|
this.alias = data.alias;
|
|
65
159
|
this.note = data.note;
|
|
@@ -73,157 +167,1077 @@ var Customer = class extends Base {
|
|
|
73
167
|
if (data.total !== void 0) this.total = data.total;
|
|
74
168
|
return this;
|
|
75
169
|
}
|
|
76
|
-
/** Re-fetch this customer. */
|
|
77
|
-
fetch() {
|
|
78
|
-
return this.client.customers.fetch(this.id);
|
|
170
|
+
/** Re-fetch this customer. */
|
|
171
|
+
fetch() {
|
|
172
|
+
return this.client.customers.fetch(this.id);
|
|
173
|
+
}
|
|
174
|
+
/** Update this customer. Mutates and returns this. */
|
|
175
|
+
async edit(options) {
|
|
176
|
+
const updated = await this.client.customers.update(this.id, options);
|
|
177
|
+
return this._patch(updated.toJSON());
|
|
178
|
+
}
|
|
179
|
+
/** Delete this customer. */
|
|
180
|
+
delete() {
|
|
181
|
+
return this.client.customers.delete(this.id);
|
|
182
|
+
}
|
|
183
|
+
toJSON() {
|
|
184
|
+
return {
|
|
185
|
+
id: this.id,
|
|
186
|
+
name: this.name,
|
|
187
|
+
alias: this.alias,
|
|
188
|
+
note: this.note,
|
|
189
|
+
email: this.email,
|
|
190
|
+
account: this.account,
|
|
191
|
+
reference: this.reference,
|
|
192
|
+
createdAt: this.createdAt.toISOString(),
|
|
193
|
+
updatedAt: this.updatedAt.toISOString(),
|
|
194
|
+
...this.payments !== null ? { payments: this.payments } : {},
|
|
195
|
+
...this.succeeded !== null ? { succeeded: this.succeeded } : {},
|
|
196
|
+
...this.total !== null ? { total: this.total } : {}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
var BaseManager = class extends EventEmitter {
|
|
201
|
+
constructor(client) {
|
|
202
|
+
super();
|
|
203
|
+
/** Cache of structures keyed by id, populated on fetch/create. */
|
|
204
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
205
|
+
this.client = client;
|
|
206
|
+
}
|
|
207
|
+
/** Shortcut to the shared REST instance. */
|
|
208
|
+
get rest() {
|
|
209
|
+
return this.client.rest;
|
|
210
|
+
}
|
|
211
|
+
/** Store a structure in the cache and return it. */
|
|
212
|
+
_add(structure) {
|
|
213
|
+
this.cache.set(structure.id, structure);
|
|
214
|
+
return structure;
|
|
215
|
+
}
|
|
216
|
+
/** Resolve an id from either a raw id or a structure instance. */
|
|
217
|
+
resolveId(idOrStructure) {
|
|
218
|
+
return typeof idOrStructure === "string" ? idOrStructure : idOrStructure.id;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// src/managers/CustomerManager.ts
|
|
223
|
+
var CustomerManager = class extends BaseManager {
|
|
224
|
+
constructor() {
|
|
225
|
+
super(...arguments);
|
|
226
|
+
this.route = "/customers";
|
|
227
|
+
}
|
|
228
|
+
/** Create a customer. */
|
|
229
|
+
async create(options) {
|
|
230
|
+
const data = await this.rest.post(this.route, { body: options });
|
|
231
|
+
return this._add(new Customer(this.client, data));
|
|
232
|
+
}
|
|
233
|
+
/** List the consumer's customers (with payment stats). */
|
|
234
|
+
async list() {
|
|
235
|
+
const data = await this.rest.get(this.route);
|
|
236
|
+
return data.data.map((d) => this._add(new Customer(this.client, d)));
|
|
237
|
+
}
|
|
238
|
+
/** Get a customer by id. */
|
|
239
|
+
async fetch(id) {
|
|
240
|
+
const data = await this.rest.get(`${this.route}/${id}`);
|
|
241
|
+
return this._add(new Customer(this.client, data));
|
|
242
|
+
}
|
|
243
|
+
/** Update a customer. */
|
|
244
|
+
async update(id, options) {
|
|
245
|
+
const data = await this.rest.patch(`${this.route}/${id}`, {
|
|
246
|
+
body: options
|
|
247
|
+
});
|
|
248
|
+
return this._add(new Customer(this.client, data));
|
|
249
|
+
}
|
|
250
|
+
/** Delete a customer. */
|
|
251
|
+
async delete(id) {
|
|
252
|
+
const result = await this.rest.delete(
|
|
253
|
+
`${this.route}/${id}`
|
|
254
|
+
);
|
|
255
|
+
this.cache.delete(id);
|
|
256
|
+
return result;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// src/managers/HealthManager.ts
|
|
261
|
+
var HealthManager = class {
|
|
262
|
+
constructor(client) {
|
|
263
|
+
this.client = client;
|
|
264
|
+
}
|
|
265
|
+
get rest() {
|
|
266
|
+
return this.client.rest;
|
|
267
|
+
}
|
|
268
|
+
/** Liveness probe — resolves when the service is up. */
|
|
269
|
+
async liveness() {
|
|
270
|
+
await this.rest.get("/health/liveness");
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
/** Readiness probe (checks the database). Returns the health report. */
|
|
274
|
+
readiness() {
|
|
275
|
+
return this.rest.get("/health/readiness");
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// src/types/index.ts
|
|
280
|
+
var PaymentIntentStatus = {
|
|
281
|
+
Pending: "PENDING",
|
|
282
|
+
Submitted: "SUBMITTED",
|
|
283
|
+
Succeeded: "SUCCEEDED",
|
|
284
|
+
Failed: "FAILED",
|
|
285
|
+
Cancelled: "CANCELLED",
|
|
286
|
+
Expired: "EXPIRED"
|
|
287
|
+
};
|
|
288
|
+
var PaymentIntentKind = {
|
|
289
|
+
/** Source account is known → unsigned XDR + `web+stellar:tx` URI. */
|
|
290
|
+
Tx: "TX",
|
|
291
|
+
/** No source → `web+stellar:pay` URI only (wallet picks the source). */
|
|
292
|
+
Pay: "PAY"
|
|
293
|
+
};
|
|
294
|
+
var WebhookEventType = {
|
|
295
|
+
PaymentIntentCreated: "PAYMENT_INTENT_CREATED",
|
|
296
|
+
PaymentIntentUpdated: "PAYMENT_INTENT_UPDATED",
|
|
297
|
+
PaymentIntentSucceeded: "PAYMENT_INTENT_SUCCEEDED",
|
|
298
|
+
PaymentIntentFailed: "PAYMENT_INTENT_FAILED",
|
|
299
|
+
PaymentIntentCancelled: "PAYMENT_INTENT_CANCELLED",
|
|
300
|
+
PaymentIntentDeleted: "PAYMENT_INTENT_DELETED",
|
|
301
|
+
// Fiat (BlindPay), re-emitted once the server syncs them.
|
|
302
|
+
ReceiverUpdated: "RECEIVER_UPDATED",
|
|
303
|
+
PayinCreated: "PAYIN_CREATED",
|
|
304
|
+
PayinUpdated: "PAYIN_UPDATED",
|
|
305
|
+
PayinCompleted: "PAYIN_COMPLETED",
|
|
306
|
+
PayoutCreated: "PAYOUT_CREATED",
|
|
307
|
+
PayoutUpdated: "PAYOUT_UPDATED",
|
|
308
|
+
PayoutCompleted: "PAYOUT_COMPLETED",
|
|
309
|
+
// Same-chain swaps on every chain (Stellar, Solana, Monad).
|
|
310
|
+
SwapCreated: "SWAP_CREATED",
|
|
311
|
+
SwapSubmitted: "SWAP_SUBMITTED",
|
|
312
|
+
SwapSucceeded: "SWAP_SUCCEEDED",
|
|
313
|
+
SwapFailed: "SWAP_FAILED",
|
|
314
|
+
// Liquidity pool operations.
|
|
315
|
+
LiquidityCreated: "LIQUIDITY_CREATED",
|
|
316
|
+
LiquiditySubmitted: "LIQUIDITY_SUBMITTED",
|
|
317
|
+
LiquiditySucceeded: "LIQUIDITY_SUCCEEDED",
|
|
318
|
+
LiquidityFailed: "LIQUIDITY_FAILED",
|
|
319
|
+
// Cross-chain swaps (NEAR Intents).
|
|
320
|
+
CrossChainSwapCreated: "CROSS_CHAIN_SWAP_CREATED",
|
|
321
|
+
CrossChainSwapUpdated: "CROSS_CHAIN_SWAP_UPDATED",
|
|
322
|
+
CrossChainSwapSucceeded: "CROSS_CHAIN_SWAP_SUCCEEDED",
|
|
323
|
+
CrossChainSwapRefunded: "CROSS_CHAIN_SWAP_REFUNDED",
|
|
324
|
+
CrossChainSwapFailed: "CROSS_CHAIN_SWAP_FAILED",
|
|
325
|
+
CrossChainSwapExpired: "CROSS_CHAIN_SWAP_EXPIRED"
|
|
326
|
+
};
|
|
327
|
+
var WebhookDeliveryStatus = {
|
|
328
|
+
Pending: "PENDING",
|
|
329
|
+
Succeeded: "SUCCEEDED",
|
|
330
|
+
Failed: "FAILED"
|
|
331
|
+
};
|
|
332
|
+
var ProductKind = {
|
|
333
|
+
Recurring: "recurring",
|
|
334
|
+
OneTime: "one_time",
|
|
335
|
+
Link: "link"
|
|
336
|
+
};
|
|
337
|
+
var SwapStatus = {
|
|
338
|
+
Pending: "PENDING",
|
|
339
|
+
Submitted: "SUBMITTED",
|
|
340
|
+
Succeeded: "SUCCEEDED",
|
|
341
|
+
Failed: "FAILED",
|
|
342
|
+
Expired: "EXPIRED"
|
|
343
|
+
};
|
|
344
|
+
var LiquidityOperationKind = {
|
|
345
|
+
Deposit: "DEPOSIT"};
|
|
346
|
+
var LiquidityOperationStatus = {
|
|
347
|
+
Pending: "PENDING",
|
|
348
|
+
Succeeded: "SUCCEEDED"};
|
|
349
|
+
var CrossChainSwapStatus = {
|
|
350
|
+
AwaitingDeposit: "AWAITING_DEPOSIT",
|
|
351
|
+
DepositDetected: "DEPOSIT_DETECTED",
|
|
352
|
+
IncompleteDeposit: "INCOMPLETE_DEPOSIT",
|
|
353
|
+
Processing: "PROCESSING",
|
|
354
|
+
Succeeded: "SUCCEEDED",
|
|
355
|
+
Refunded: "REFUNDED",
|
|
356
|
+
Failed: "FAILED",
|
|
357
|
+
Expired: "EXPIRED"
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// src/structures/LiquidityOperation.ts
|
|
361
|
+
var LiquidityOperation = class extends Base {
|
|
362
|
+
constructor(client, data) {
|
|
363
|
+
super(client, data);
|
|
364
|
+
}
|
|
365
|
+
_patch(data) {
|
|
366
|
+
super._patch(data);
|
|
367
|
+
this.kind = data.kind;
|
|
368
|
+
this.status = data.status;
|
|
369
|
+
this.network = data.network;
|
|
370
|
+
this.source = data.source;
|
|
371
|
+
this.poolId = data.poolId;
|
|
372
|
+
this.assetA = data.assetA;
|
|
373
|
+
this.assetAIssuer = data.assetAIssuer ?? null;
|
|
374
|
+
this.assetB = data.assetB;
|
|
375
|
+
this.assetBIssuer = data.assetBIssuer ?? null;
|
|
376
|
+
this.amountA = data.amountA;
|
|
377
|
+
this.amountB = data.amountB;
|
|
378
|
+
this.shares = data.shares ?? null;
|
|
379
|
+
this.minPrice = data.minPrice ?? null;
|
|
380
|
+
this.maxPrice = data.maxPrice ?? null;
|
|
381
|
+
this.slippageBps = data.slippageBps;
|
|
382
|
+
this.idempotencyKey = data.idempotencyKey ?? null;
|
|
383
|
+
this.feeBps = data.feeBps;
|
|
384
|
+
this.feeAmountA = data.feeAmountA;
|
|
385
|
+
this.feeAmountB = data.feeAmountB;
|
|
386
|
+
this.feeWallet = data.feeWallet ?? null;
|
|
387
|
+
this.commissionMemo = data.commissionMemo ?? null;
|
|
388
|
+
this.xdr = data.xdr;
|
|
389
|
+
this.uri = data.uri;
|
|
390
|
+
this.txHash = data.txHash;
|
|
391
|
+
this.qr = data.qr;
|
|
392
|
+
this.expiresAt = data.expiresAt ? new Date(data.expiresAt) : null;
|
|
393
|
+
this.createdAt = new Date(data.createdAt);
|
|
394
|
+
this.updatedAt = new Date(data.updatedAt);
|
|
395
|
+
return this;
|
|
396
|
+
}
|
|
397
|
+
/** True while the envelope still needs a signature. */
|
|
398
|
+
get isPending() {
|
|
399
|
+
return this.status === LiquidityOperationStatus.Pending;
|
|
400
|
+
}
|
|
401
|
+
/** True once the network accepted it. */
|
|
402
|
+
get isSucceeded() {
|
|
403
|
+
return this.status === LiquidityOperationStatus.Succeeded;
|
|
404
|
+
}
|
|
405
|
+
/** True for a deposit, false for a withdrawal. */
|
|
406
|
+
get isDeposit() {
|
|
407
|
+
return this.kind === LiquidityOperationKind.Deposit;
|
|
408
|
+
}
|
|
409
|
+
/** Re-fetch this operation and patch it in place. */
|
|
410
|
+
async fetch() {
|
|
411
|
+
const data = await this.client.liquidity.fetchRaw(this.id);
|
|
412
|
+
return this._patch(data);
|
|
413
|
+
}
|
|
414
|
+
/** Relay the signed envelope to the network and patch this instance with the result. */
|
|
415
|
+
async submit(options) {
|
|
416
|
+
const outcome = await this.client.liquidity.submit(this.id, options);
|
|
417
|
+
this._patch(outcome.operation.toJSON());
|
|
418
|
+
return outcome;
|
|
419
|
+
}
|
|
420
|
+
toJSON() {
|
|
421
|
+
return {
|
|
422
|
+
id: this.id,
|
|
423
|
+
kind: this.kind,
|
|
424
|
+
status: this.status,
|
|
425
|
+
network: this.network,
|
|
426
|
+
source: this.source,
|
|
427
|
+
poolId: this.poolId,
|
|
428
|
+
assetA: this.assetA,
|
|
429
|
+
assetAIssuer: this.assetAIssuer,
|
|
430
|
+
assetB: this.assetB,
|
|
431
|
+
assetBIssuer: this.assetBIssuer,
|
|
432
|
+
amountA: this.amountA,
|
|
433
|
+
amountB: this.amountB,
|
|
434
|
+
shares: this.shares,
|
|
435
|
+
minPrice: this.minPrice,
|
|
436
|
+
maxPrice: this.maxPrice,
|
|
437
|
+
slippageBps: this.slippageBps,
|
|
438
|
+
idempotencyKey: this.idempotencyKey,
|
|
439
|
+
feeBps: this.feeBps,
|
|
440
|
+
feeAmountA: this.feeAmountA,
|
|
441
|
+
feeAmountB: this.feeAmountB,
|
|
442
|
+
feeWallet: this.feeWallet,
|
|
443
|
+
commissionMemo: this.commissionMemo,
|
|
444
|
+
xdr: this.xdr,
|
|
445
|
+
uri: this.uri,
|
|
446
|
+
txHash: this.txHash,
|
|
447
|
+
qr: this.qr,
|
|
448
|
+
expiresAt: this.expiresAt ? this.expiresAt.toISOString() : null,
|
|
449
|
+
createdAt: this.createdAt.toISOString(),
|
|
450
|
+
updatedAt: this.updatedAt.toISOString()
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
// src/managers/LiquidityManager.ts
|
|
456
|
+
var LiquidityManager = class extends BaseManager {
|
|
457
|
+
constructor() {
|
|
458
|
+
super(...arguments);
|
|
459
|
+
this.route = "/liquidity-pools";
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Build a deposit into the pool formed by the two assets → unsigned XDR, SEP-7
|
|
463
|
+
* URI and QR.
|
|
464
|
+
*
|
|
465
|
+
* The pool is DERIVED from the two assets rather than named: a constant-product
|
|
466
|
+
* pool id is a hash of its (assetA, assetB, fee) in CAP-38 order, so there is
|
|
467
|
+
* exactly one pool the pair can form and no id for a caller to get wrong.
|
|
468
|
+
*/
|
|
469
|
+
async deposit(options) {
|
|
470
|
+
const { idempotencyKey, ...body } = options;
|
|
471
|
+
const data = await this.rest.post(`${this.route}/deposit`, {
|
|
472
|
+
body: { ...body, ...idempotencyKey ? { idempotencyKey } : {} },
|
|
473
|
+
// Sent as a header too: the service accepts either, and the header is what
|
|
474
|
+
// makes a retried POST safe when the body was already consumed upstream.
|
|
475
|
+
...idempotencyKey ? { headers: { "Idempotency-Key": idempotencyKey } } : {}
|
|
476
|
+
});
|
|
477
|
+
return this._add(new LiquidityOperation(this.client, data));
|
|
478
|
+
}
|
|
479
|
+
/** Build a withdrawal (burn shares) from a pool → unsigned XDR, SEP-7 URI and QR. */
|
|
480
|
+
async withdraw(options) {
|
|
481
|
+
const { idempotencyKey, ...body } = options;
|
|
482
|
+
const data = await this.rest.post(`${this.route}/withdraw`, {
|
|
483
|
+
body: { ...body, ...idempotencyKey ? { idempotencyKey } : {} },
|
|
484
|
+
...idempotencyKey ? { headers: { "Idempotency-Key": idempotencyKey } } : {}
|
|
485
|
+
});
|
|
486
|
+
return this._add(new LiquidityOperation(this.client, data));
|
|
487
|
+
}
|
|
488
|
+
/** An account's pool share positions, with what each is redeemable for right now. */
|
|
489
|
+
positions(account) {
|
|
490
|
+
return this.rest.get(`${this.route}/positions`, {
|
|
491
|
+
query: { account }
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
/** Browse on-chain pools (Horizon proxy). Filter by asset pair or by holder. */
|
|
495
|
+
async browse(options = {}) {
|
|
496
|
+
const data = await this.rest.get(this.route, {
|
|
497
|
+
query: {
|
|
498
|
+
assetACode: options.assetACode,
|
|
499
|
+
assetAIssuer: options.assetAIssuer,
|
|
500
|
+
assetBCode: options.assetBCode,
|
|
501
|
+
assetBIssuer: options.assetBIssuer,
|
|
502
|
+
account: options.account,
|
|
503
|
+
cursor: options.cursor,
|
|
504
|
+
limit: options.limit
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
return { items: data.data, cursor: data.cursor ?? null };
|
|
508
|
+
}
|
|
509
|
+
/** One on-chain pool by its hex id (Horizon proxy). */
|
|
510
|
+
pool(poolId) {
|
|
511
|
+
return this.rest.get(`${this.route}/${poolId}`);
|
|
512
|
+
}
|
|
513
|
+
/** List this consumer's pool operations (paginated). */
|
|
514
|
+
async operations(options = {}) {
|
|
515
|
+
const data = await this.rest.get(`${this.route}/operations`, {
|
|
516
|
+
query: {
|
|
517
|
+
kind: options.kind,
|
|
518
|
+
status: options.status,
|
|
519
|
+
take: options.take,
|
|
520
|
+
skip: options.skip
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
return {
|
|
524
|
+
items: data.data.map((d) => this._add(new LiquidityOperation(this.client, d))),
|
|
525
|
+
total: data.total,
|
|
526
|
+
take: data.take,
|
|
527
|
+
skip: data.skip
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
/** Get one operation by id, materialized. */
|
|
531
|
+
async fetch(id) {
|
|
532
|
+
return this._add(new LiquidityOperation(this.client, await this.fetchRaw(id)));
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* The raw payload for one operation. Exists so {@link LiquidityOperation.fetch}
|
|
536
|
+
* can patch itself in place instead of materializing a second instance of the
|
|
537
|
+
* thing the caller is already holding.
|
|
538
|
+
*/
|
|
539
|
+
fetchRaw(id) {
|
|
540
|
+
return this.rest.get(`${this.route}/operations/${id}`);
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Relay a signed operation to the network. The service checks the envelope's
|
|
544
|
+
* hash against the one it built, so a signed envelope that is not the one this
|
|
545
|
+
* operation describes is refused rather than broadcast.
|
|
546
|
+
*/
|
|
547
|
+
async submit(id, options) {
|
|
548
|
+
const data = await this.rest.post(
|
|
549
|
+
`${this.route}/operations/${id}/submit`,
|
|
550
|
+
{ body: options }
|
|
551
|
+
);
|
|
552
|
+
return {
|
|
553
|
+
submitted: data.submitted,
|
|
554
|
+
status: data.status,
|
|
555
|
+
txHash: data.txHash ?? null,
|
|
556
|
+
reason: data.reason ?? null,
|
|
557
|
+
resultCodes: data.resultCodes ?? null,
|
|
558
|
+
operation: this._add(new LiquidityOperation(this.client, data.operation))
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
// src/managers/OnrampManager.ts
|
|
564
|
+
var OnrampManager = class {
|
|
565
|
+
constructor(client) {
|
|
566
|
+
this.route = "/onramp";
|
|
567
|
+
this.client = client;
|
|
568
|
+
}
|
|
569
|
+
get rest() {
|
|
570
|
+
return this.client.rest;
|
|
571
|
+
}
|
|
572
|
+
/** Price a payin. The quote expires — check `expires_at` before using it. */
|
|
573
|
+
quote(options) {
|
|
574
|
+
return this.rest.post(`${this.route}/quotes`, { body: options });
|
|
575
|
+
}
|
|
576
|
+
/** Create a payin from a quote. The response carries the funding instructions. */
|
|
577
|
+
createPayin(options) {
|
|
578
|
+
return this.rest.post(`${this.route}/payins`, { body: options });
|
|
579
|
+
}
|
|
580
|
+
/** List this consumer's payins (paginated). */
|
|
581
|
+
async payins(options = {}) {
|
|
582
|
+
const data = await this.rest.get(`${this.route}/payins`, {
|
|
583
|
+
query: { take: options.take, skip: options.skip }
|
|
584
|
+
});
|
|
585
|
+
return { items: data.data, total: data.total, take: data.take, skip: data.skip };
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* One payin. Served from the local mirror, refreshed from the provider when it
|
|
589
|
+
* is stale — so this is the right call to poll, not the provider's own API.
|
|
590
|
+
*/
|
|
591
|
+
payin(id) {
|
|
592
|
+
return this.rest.get(`${this.route}/payins/${id}`);
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Build the unsigned trustline transaction an address needs before it can hold
|
|
596
|
+
* the stablecoin the ramp pays out in.
|
|
597
|
+
*
|
|
598
|
+
* The envelope comes from the gateway, so a wallet signing it must decode and
|
|
599
|
+
* bound it first — the issuer it names is the one the payout will use, and it is
|
|
600
|
+
* not known to the caller in advance.
|
|
601
|
+
*/
|
|
602
|
+
createTrustline(options) {
|
|
603
|
+
return this.rest.post(`${this.route}/trustline`, { body: options });
|
|
604
|
+
}
|
|
605
|
+
/** Open a virtual account (a permanent bank reference) for a verified receiver. */
|
|
606
|
+
createVirtualAccount(receiverId, options) {
|
|
607
|
+
return this.rest.post(
|
|
608
|
+
`${this.route}/receivers/${receiverId}/virtual-accounts`,
|
|
609
|
+
{ body: options }
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
/** A receiver's virtual accounts. */
|
|
613
|
+
virtualAccounts(receiverId, options = {}) {
|
|
614
|
+
return this.rest.get(
|
|
615
|
+
`${this.route}/receivers/${receiverId}/virtual-accounts`,
|
|
616
|
+
{ query: { take: options.take, skip: options.skip } }
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
// src/managers/OfframpManager.ts
|
|
622
|
+
var OfframpManager = class {
|
|
623
|
+
constructor(client) {
|
|
624
|
+
this.route = "/offramp";
|
|
625
|
+
this.client = client;
|
|
626
|
+
}
|
|
627
|
+
get rest() {
|
|
628
|
+
return this.client.rest;
|
|
629
|
+
}
|
|
630
|
+
/** Price a payout. Expires in about five minutes. */
|
|
631
|
+
quote(options) {
|
|
632
|
+
return this.rest.post(`${this.route}/quotes`, { body: options });
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Build the unsigned transfer for a Stellar or Solana payout.
|
|
636
|
+
*
|
|
637
|
+
* What comes back is built by the gateway, not by the caller: bound it against
|
|
638
|
+
* the quote the user confirmed before signing, or the amount that leaves is
|
|
639
|
+
* whatever the response says it is.
|
|
640
|
+
*/
|
|
641
|
+
authorize(options) {
|
|
642
|
+
return this.rest.post(`${this.route}/payouts/authorize`, {
|
|
643
|
+
body: options
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
/** Create the payout from a quote, with the signed transfer attached. */
|
|
647
|
+
createPayout(options) {
|
|
648
|
+
return this.rest.post(`${this.route}/payouts`, { body: options });
|
|
649
|
+
}
|
|
650
|
+
/** List this consumer's payouts (paginated). */
|
|
651
|
+
async payouts(options = {}) {
|
|
652
|
+
const data = await this.rest.get(`${this.route}/payouts`, {
|
|
653
|
+
query: { take: options.take, skip: options.skip }
|
|
654
|
+
});
|
|
655
|
+
return { items: data.data, total: data.total, take: data.take, skip: data.skip };
|
|
656
|
+
}
|
|
657
|
+
/** One payout. Served from the local mirror, refreshed when stale. */
|
|
658
|
+
payout(id) {
|
|
659
|
+
return this.rest.get(`${this.route}/payouts/${id}`);
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Attach a compliance document to a payout — an invoice or proof of funds the
|
|
663
|
+
* rail asks for before it will settle.
|
|
664
|
+
*/
|
|
665
|
+
attachDocument(id, options) {
|
|
666
|
+
return this.rest.post(`${this.route}/payouts/${id}/documents`, {
|
|
667
|
+
body: options
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
// src/managers/ActivityManager.ts
|
|
673
|
+
var ActivityManager = class {
|
|
674
|
+
constructor(client) {
|
|
675
|
+
this.route = "/activity";
|
|
676
|
+
this.client = client;
|
|
677
|
+
}
|
|
678
|
+
get rest() {
|
|
679
|
+
return this.client.rest;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Report a batch of events.
|
|
683
|
+
*
|
|
684
|
+
* Accepts the array directly or the full body. Give each event an `eventId`: the
|
|
685
|
+
* service de-duplicates on it, which is the difference between a retried batch
|
|
686
|
+
* and a double-counted one.
|
|
687
|
+
*/
|
|
688
|
+
report(events) {
|
|
689
|
+
const body = Array.isArray(events) ? { events } : events;
|
|
690
|
+
return this.rest.post(`${this.route}/events`, { body });
|
|
691
|
+
}
|
|
692
|
+
/** Recent events for this consumer, newest first. */
|
|
693
|
+
async events(options = {}) {
|
|
694
|
+
const data = await this.rest.get(`${this.route}/events`, {
|
|
695
|
+
query: {
|
|
696
|
+
take: options.take,
|
|
697
|
+
skip: options.skip,
|
|
698
|
+
source: options.source,
|
|
699
|
+
level: options.level,
|
|
700
|
+
category: options.category,
|
|
701
|
+
type: options.type,
|
|
702
|
+
network: options.network,
|
|
703
|
+
since: options.since,
|
|
704
|
+
until: options.until
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
return { items: data.data, total: data.total, take: data.take, skip: data.skip };
|
|
708
|
+
}
|
|
709
|
+
/** Counts, top event types, top errors and a daily series. */
|
|
710
|
+
summary(options = {}) {
|
|
711
|
+
return this.rest.get(`${this.route}/summary`, {
|
|
712
|
+
query: { days: options.days, source: options.source }
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
// src/structures/Receiver.ts
|
|
718
|
+
var Receiver = class extends Base {
|
|
719
|
+
constructor(client, data) {
|
|
720
|
+
super(client, data);
|
|
721
|
+
}
|
|
722
|
+
_patch(data) {
|
|
723
|
+
super._patch(data);
|
|
724
|
+
this.blindpayId = data.blindpayId;
|
|
725
|
+
this.type = data.type;
|
|
726
|
+
this.kycType = data.kycType ?? null;
|
|
727
|
+
this.kycStatus = data.kycStatus ?? null;
|
|
728
|
+
this.email = data.email ?? null;
|
|
729
|
+
this.name = data.name ?? null;
|
|
730
|
+
this.country = data.country ?? null;
|
|
731
|
+
this.externalId = data.externalId ?? null;
|
|
732
|
+
this.disabled = data.disabled;
|
|
733
|
+
this.dossierVersion = data.dossierVersion;
|
|
734
|
+
this.reviewedVersion = data.reviewedVersion ?? null;
|
|
735
|
+
this.createdAt = new Date(data.createdAt);
|
|
736
|
+
this.updatedAt = new Date(data.updatedAt);
|
|
737
|
+
return this;
|
|
738
|
+
}
|
|
739
|
+
/** True once verification has passed and the ramps will act on this receiver. */
|
|
740
|
+
get isApproved() {
|
|
741
|
+
return this.kycStatus === "approved";
|
|
742
|
+
}
|
|
743
|
+
/** Re-read this receiver, refreshing `kycStatus`, and patch it in place. */
|
|
744
|
+
async fetch() {
|
|
745
|
+
return this._patch(await this.client.kyc.fetchReceiverRaw(this.id));
|
|
746
|
+
}
|
|
747
|
+
/** Update and patch in place. */
|
|
748
|
+
async update(options) {
|
|
749
|
+
const updated = await this.client.kyc.updateReceiver(this.id, options);
|
|
750
|
+
return this._patch(updated.toJSON());
|
|
751
|
+
}
|
|
752
|
+
/** Delete this receiver. */
|
|
753
|
+
delete() {
|
|
754
|
+
return this.client.kyc.deleteReceiver(this.id);
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Approve it out of review (admin-only).
|
|
758
|
+
*
|
|
759
|
+
* Pinned to the dossier THIS instance holds: `expected_version` defaults to
|
|
760
|
+
* {@link Receiver.dossierVersion}, so approving a receiver that was edited since
|
|
761
|
+
* you read it is a `409 kyc_state_invalid` rather than a silent approval of data
|
|
762
|
+
* you never saw. Call {@link Receiver.fetch} and review again, or pass
|
|
763
|
+
* `expected_version` yourself — including `undefined`, which approves whatever
|
|
764
|
+
* is stored now.
|
|
765
|
+
*/
|
|
766
|
+
approve(options = {}) {
|
|
767
|
+
const pinned = "expected_version" in options ? options : { ...options, expected_version: this.dossierVersion };
|
|
768
|
+
return this.client.kyc.approveReceiver(this.id, pinned);
|
|
769
|
+
}
|
|
770
|
+
/** Ask for a terms-of-service link for this receiver. */
|
|
771
|
+
requestTos(options) {
|
|
772
|
+
return this.client.kyc.requestTos(this.id, options);
|
|
773
|
+
}
|
|
774
|
+
/** Enable it with an accepted terms-of-service id, and patch in place. */
|
|
775
|
+
async enable(options) {
|
|
776
|
+
const enabled = await this.client.kyc.enableReceiver(this.id, options);
|
|
777
|
+
return this._patch(enabled.toJSON());
|
|
778
|
+
}
|
|
779
|
+
/** Cut this receiver off from both ramps, or let it back in. */
|
|
780
|
+
async setAccess(disabled) {
|
|
781
|
+
const updated = await this.client.kyc.setReceiverAccess(this.id, { disabled });
|
|
782
|
+
return this._patch(updated.toJSON());
|
|
783
|
+
}
|
|
784
|
+
/** Register a blockchain wallet for this receiver. */
|
|
785
|
+
addWallet(options) {
|
|
786
|
+
return this.client.kyc.addWallet(this.id, options);
|
|
787
|
+
}
|
|
788
|
+
/** This receiver's wallets. */
|
|
789
|
+
wallets(options = {}) {
|
|
790
|
+
return this.client.kyc.wallets(this.id, options);
|
|
791
|
+
}
|
|
792
|
+
/** Add a fiat bank account — where an off-ramp pays out. */
|
|
793
|
+
addBankAccount(options) {
|
|
794
|
+
return this.client.kyc.addBankAccount(this.id, options);
|
|
795
|
+
}
|
|
796
|
+
/** This receiver's bank accounts. */
|
|
797
|
+
bankAccounts(options = {}) {
|
|
798
|
+
return this.client.kyc.bankAccounts(this.id, options);
|
|
799
|
+
}
|
|
800
|
+
toJSON() {
|
|
801
|
+
return {
|
|
802
|
+
id: this.id,
|
|
803
|
+
blindpayId: this.blindpayId,
|
|
804
|
+
type: this.type,
|
|
805
|
+
kycType: this.kycType,
|
|
806
|
+
kycStatus: this.kycStatus,
|
|
807
|
+
email: this.email,
|
|
808
|
+
name: this.name,
|
|
809
|
+
country: this.country,
|
|
810
|
+
externalId: this.externalId,
|
|
811
|
+
disabled: this.disabled,
|
|
812
|
+
dossierVersion: this.dossierVersion,
|
|
813
|
+
reviewedVersion: this.reviewedVersion,
|
|
814
|
+
createdAt: this.createdAt.toISOString(),
|
|
815
|
+
updatedAt: this.updatedAt.toISOString()
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
// src/managers/KycManager.ts
|
|
821
|
+
var KycManager = class extends BaseManager {
|
|
822
|
+
constructor() {
|
|
823
|
+
super(...arguments);
|
|
824
|
+
this.route = "/kyc";
|
|
825
|
+
}
|
|
826
|
+
/* ----------------------------- receivers ------------------------------- */
|
|
827
|
+
/** Create a receiver and start verification. */
|
|
828
|
+
async createReceiver(options) {
|
|
829
|
+
const data = await this.rest.post(`${this.route}/receivers`, { body: options });
|
|
830
|
+
return this._add(new Receiver(this.client, data));
|
|
831
|
+
}
|
|
832
|
+
/** List this consumer's receivers (paginated). */
|
|
833
|
+
async receivers(options = {}) {
|
|
834
|
+
const data = await this.rest.get(`${this.route}/receivers`, {
|
|
835
|
+
query: { take: options.take, skip: options.skip }
|
|
836
|
+
});
|
|
837
|
+
return {
|
|
838
|
+
items: data.data.map((d) => this._add(new Receiver(this.client, d))),
|
|
839
|
+
total: data.total,
|
|
840
|
+
take: data.take,
|
|
841
|
+
skip: data.skip
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
/** One receiver, materialized. Reading it refreshes `kycStatus` upstream. */
|
|
845
|
+
async fetchReceiver(id) {
|
|
846
|
+
return this._add(new Receiver(this.client, await this.fetchReceiverRaw(id)));
|
|
847
|
+
}
|
|
848
|
+
/** The raw payload, so a {@link Receiver} can patch itself in place. */
|
|
849
|
+
fetchReceiverRaw(id) {
|
|
850
|
+
return this.rest.get(`${this.route}/receivers/${id}`);
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Update a receiver — the same fields as creation, all optional. Once the receiver
|
|
854
|
+
* exists at the provider, identity fields need an elevated key; see
|
|
855
|
+
* {@link UpdateReceiverOptions}.
|
|
856
|
+
*/
|
|
857
|
+
async updateReceiver(id, options) {
|
|
858
|
+
const data = await this.rest.patch(`${this.route}/receivers/${id}`, {
|
|
859
|
+
body: options
|
|
860
|
+
});
|
|
861
|
+
return this._add(new Receiver(this.client, data));
|
|
862
|
+
}
|
|
863
|
+
/** Delete a receiver. */
|
|
864
|
+
async deleteReceiver(id) {
|
|
865
|
+
await this.rest.delete(`${this.route}/receivers/${id}`);
|
|
866
|
+
this.cache.delete(id);
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Approve a receiver sitting in review. Admin-only: it is the human gate on a
|
|
870
|
+
* verification the provider could not decide by itself.
|
|
871
|
+
*/
|
|
872
|
+
approveReceiver(id, options = {}) {
|
|
873
|
+
return this.rest.post(`${this.route}/receivers/${id}/approve`, { body: options });
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Ask for a terms-of-service link for an existing receiver. `channel: 'code'`
|
|
877
|
+
* returns the URL to render; `'email'` sends it to the receiver instead.
|
|
878
|
+
*/
|
|
879
|
+
requestTos(id, options) {
|
|
880
|
+
return this.rest.post(`${this.route}/receivers/${id}/tos`, {
|
|
881
|
+
body: options
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
/** Enable an inactive receiver with an accepted terms-of-service id. */
|
|
885
|
+
async enableReceiver(id, options) {
|
|
886
|
+
const data = await this.rest.post(`${this.route}/receivers/${id}/enable`, {
|
|
887
|
+
body: options
|
|
888
|
+
});
|
|
889
|
+
return this._add(new Receiver(this.client, data));
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Cut a receiver off from both ramps, or let it back in. Admin-only, and the
|
|
893
|
+
* fastest lever there is when something is wrong with an account.
|
|
894
|
+
*/
|
|
895
|
+
async setReceiverAccess(id, options) {
|
|
896
|
+
const data = await this.rest.patch(`${this.route}/receivers/${id}/access`, {
|
|
897
|
+
body: options
|
|
898
|
+
});
|
|
899
|
+
return this._add(new Receiver(this.client, data));
|
|
900
|
+
}
|
|
901
|
+
/* ------------------------------ wallets -------------------------------- */
|
|
902
|
+
/**
|
|
903
|
+
* The message a receiver must sign to prove it controls an address. Sign it,
|
|
904
|
+
* then pass the resulting transaction hash as `signature_tx_hash` to
|
|
905
|
+
* {@link addWallet}.
|
|
906
|
+
*/
|
|
907
|
+
walletSignMessage(receiverId) {
|
|
908
|
+
return this.rest.get(
|
|
909
|
+
`${this.route}/receivers/${receiverId}/wallets/sign-message`
|
|
910
|
+
);
|
|
911
|
+
}
|
|
912
|
+
/** Register a blockchain wallet for a receiver. */
|
|
913
|
+
addWallet(receiverId, options) {
|
|
914
|
+
return this.rest.post(`${this.route}/receivers/${receiverId}/wallets`, {
|
|
915
|
+
body: options
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
/** A receiver's wallets (paginated). */
|
|
919
|
+
async wallets(receiverId, options = {}) {
|
|
920
|
+
const data = await this.rest.get(
|
|
921
|
+
`${this.route}/receivers/${receiverId}/wallets`,
|
|
922
|
+
{ query: { take: options.take, skip: options.skip } }
|
|
923
|
+
);
|
|
924
|
+
return { items: data.data, total: data.total, take: data.take, skip: data.skip };
|
|
925
|
+
}
|
|
926
|
+
/** Delete one of a receiver's wallets. */
|
|
927
|
+
async deleteWallet(receiverId, id) {
|
|
928
|
+
await this.rest.delete(`${this.route}/receivers/${receiverId}/wallets/${id}`);
|
|
929
|
+
}
|
|
930
|
+
/* ---------------------------- bank accounts ---------------------------- */
|
|
931
|
+
/** Add a fiat bank account for a receiver — where an off-ramp pays out. */
|
|
932
|
+
addBankAccount(receiverId, options) {
|
|
933
|
+
return this.rest.post(
|
|
934
|
+
`${this.route}/receivers/${receiverId}/bank-accounts`,
|
|
935
|
+
{ body: options }
|
|
936
|
+
);
|
|
937
|
+
}
|
|
938
|
+
/** A receiver's bank accounts (paginated). */
|
|
939
|
+
async bankAccounts(receiverId, options = {}) {
|
|
940
|
+
const data = await this.rest.get(
|
|
941
|
+
`${this.route}/receivers/${receiverId}/bank-accounts`,
|
|
942
|
+
{ query: { take: options.take, skip: options.skip } }
|
|
943
|
+
);
|
|
944
|
+
return { items: data.data, total: data.total, take: data.take, skip: data.skip };
|
|
945
|
+
}
|
|
946
|
+
/** Delete one of a receiver's bank accounts. */
|
|
947
|
+
async deleteBankAccount(receiverId, id) {
|
|
948
|
+
await this.rest.delete(`${this.route}/receivers/${receiverId}/bank-accounts/${id}`);
|
|
949
|
+
}
|
|
950
|
+
/* ------------------------------ the rest ------------------------------- */
|
|
951
|
+
/**
|
|
952
|
+
* Upload a KYC document and get back the `file_url` every `*_file` field
|
|
953
|
+
* expects. Documents are uploaded first and referenced by URL — the receiver
|
|
954
|
+
* payload never carries bytes.
|
|
955
|
+
*/
|
|
956
|
+
upload(file) {
|
|
957
|
+
return this.rest.post(`${this.route}/upload`, { body: file });
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* Start terms-of-service acceptance and get the hosted URL. This is the FIRST
|
|
961
|
+
* step of the flow: the provider will not create a receiver without the `tos_id`
|
|
962
|
+
* it produces.
|
|
963
|
+
*/
|
|
964
|
+
termsOfService(options = {}) {
|
|
965
|
+
return this.rest.post(`${this.route}/terms-of-service`, { body: options });
|
|
966
|
+
}
|
|
967
|
+
/** The bank rails available to this consumer. */
|
|
968
|
+
rails() {
|
|
969
|
+
return this.rest.get(`${this.route}/rails`);
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* The field schema a given rail requires. The authority on which of the ~70
|
|
973
|
+
* rail-specific bank-account fields to send — read it at runtime rather than
|
|
974
|
+
* hard-coding a rail's shape.
|
|
975
|
+
*/
|
|
976
|
+
bankDetails(rail) {
|
|
977
|
+
return this.rest.get(`${this.route}/bank-details`, { query: { rail } });
|
|
978
|
+
}
|
|
979
|
+
get rest() {
|
|
980
|
+
return this.client.rest;
|
|
981
|
+
}
|
|
982
|
+
};
|
|
983
|
+
|
|
984
|
+
// src/structures/CrossChainSwap.ts
|
|
985
|
+
var FINAL = [
|
|
986
|
+
CrossChainSwapStatus.Succeeded,
|
|
987
|
+
CrossChainSwapStatus.Refunded,
|
|
988
|
+
CrossChainSwapStatus.Failed
|
|
989
|
+
];
|
|
990
|
+
var CrossChainSwap = class extends Base {
|
|
991
|
+
constructor(client, data) {
|
|
992
|
+
super(client, data);
|
|
993
|
+
}
|
|
994
|
+
_patch(data) {
|
|
995
|
+
super._patch(data);
|
|
996
|
+
this.status = data.status;
|
|
997
|
+
this.providerStatus = data.providerStatus;
|
|
998
|
+
this.network = data.network;
|
|
999
|
+
this.originChain = data.originChain;
|
|
1000
|
+
this.originAsset = data.originAsset;
|
|
1001
|
+
this.originContract = data.originContract;
|
|
1002
|
+
this.destinationChain = data.destinationChain;
|
|
1003
|
+
this.destinationAsset = data.destinationAsset;
|
|
1004
|
+
this.destinationContract = data.destinationContract;
|
|
1005
|
+
this.amountIn = data.amountIn;
|
|
1006
|
+
this.feeBps = data.feeBps;
|
|
1007
|
+
this.feeAmount = data.feeAmount;
|
|
1008
|
+
this.amountOutEstimated = data.amountOutEstimated;
|
|
1009
|
+
this.amountOutMin = data.amountOutMin;
|
|
1010
|
+
this.slippageBps = data.slippageBps;
|
|
1011
|
+
this.recipient = data.recipient;
|
|
1012
|
+
this.refundTo = data.refundTo;
|
|
1013
|
+
this.depositAddress = data.depositAddress;
|
|
1014
|
+
this.depositMemo = data.depositMemo;
|
|
1015
|
+
this.depositUri = data.depositUri;
|
|
1016
|
+
this.qr = data.qr ?? null;
|
|
1017
|
+
this.depositTxHash = data.depositTxHash;
|
|
1018
|
+
this.amountOut = data.amountOut;
|
|
1019
|
+
this.refundedAmount = data.refundedAmount;
|
|
1020
|
+
this.originTxHashes = data.originTxHashes;
|
|
1021
|
+
this.destinationTxHashes = data.destinationTxHashes;
|
|
1022
|
+
this.timeEstimateSeconds = data.timeEstimateSeconds;
|
|
1023
|
+
this.correlationId = data.correlationId;
|
|
1024
|
+
this.quoteSignature = data.quoteSignature;
|
|
1025
|
+
this.idempotencyKey = data.idempotencyKey;
|
|
1026
|
+
this.expiresAt = new Date(data.expiresAt);
|
|
1027
|
+
this.createdAt = new Date(data.createdAt);
|
|
1028
|
+
this.updatedAt = new Date(data.updatedAt);
|
|
1029
|
+
return this;
|
|
1030
|
+
}
|
|
1031
|
+
/** Whether the swap has reached an outcome that will not change. */
|
|
1032
|
+
get isFinal() {
|
|
1033
|
+
return FINAL.includes(this.status);
|
|
1034
|
+
}
|
|
1035
|
+
get isSucceeded() {
|
|
1036
|
+
return this.status === CrossChainSwapStatus.Succeeded;
|
|
1037
|
+
}
|
|
1038
|
+
/** Re-fetch from the API, updating this instance in place. */
|
|
1039
|
+
async fetch() {
|
|
1040
|
+
const fresh = await this.client.crossChainSwaps.fetch(this.id);
|
|
1041
|
+
return this._patch(fresh.toJSON());
|
|
1042
|
+
}
|
|
1043
|
+
/**
|
|
1044
|
+
* Report the transaction that paid the deposit address so NEAR Intents starts
|
|
1045
|
+
* without waiting for its indexer. Updates this instance in place.
|
|
1046
|
+
*/
|
|
1047
|
+
async reportDeposit(txHash) {
|
|
1048
|
+
const fresh = await this.client.crossChainSwaps.reportDeposit(this.id, txHash);
|
|
1049
|
+
return this._patch(fresh.toJSON());
|
|
1050
|
+
}
|
|
1051
|
+
toJSON() {
|
|
1052
|
+
return {
|
|
1053
|
+
id: this.id,
|
|
1054
|
+
status: this.status,
|
|
1055
|
+
providerStatus: this.providerStatus,
|
|
1056
|
+
network: this.network,
|
|
1057
|
+
originChain: this.originChain,
|
|
1058
|
+
originAsset: this.originAsset,
|
|
1059
|
+
originContract: this.originContract,
|
|
1060
|
+
destinationChain: this.destinationChain,
|
|
1061
|
+
destinationAsset: this.destinationAsset,
|
|
1062
|
+
destinationContract: this.destinationContract,
|
|
1063
|
+
amountIn: this.amountIn,
|
|
1064
|
+
feeBps: this.feeBps,
|
|
1065
|
+
feeAmount: this.feeAmount,
|
|
1066
|
+
amountOutEstimated: this.amountOutEstimated,
|
|
1067
|
+
amountOutMin: this.amountOutMin,
|
|
1068
|
+
slippageBps: this.slippageBps,
|
|
1069
|
+
recipient: this.recipient,
|
|
1070
|
+
refundTo: this.refundTo,
|
|
1071
|
+
depositAddress: this.depositAddress,
|
|
1072
|
+
depositMemo: this.depositMemo,
|
|
1073
|
+
depositUri: this.depositUri,
|
|
1074
|
+
...this.qr ? { qr: this.qr } : {},
|
|
1075
|
+
depositTxHash: this.depositTxHash,
|
|
1076
|
+
amountOut: this.amountOut,
|
|
1077
|
+
refundedAmount: this.refundedAmount,
|
|
1078
|
+
originTxHashes: this.originTxHashes,
|
|
1079
|
+
destinationTxHashes: this.destinationTxHashes,
|
|
1080
|
+
timeEstimateSeconds: this.timeEstimateSeconds,
|
|
1081
|
+
correlationId: this.correlationId,
|
|
1082
|
+
quoteSignature: this.quoteSignature,
|
|
1083
|
+
idempotencyKey: this.idempotencyKey,
|
|
1084
|
+
expiresAt: this.expiresAt.toISOString(),
|
|
1085
|
+
createdAt: this.createdAt.toISOString(),
|
|
1086
|
+
updatedAt: this.updatedAt.toISOString()
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
// src/managers/CrossChainSwapManager.ts
|
|
1092
|
+
var CrossChainSwapManager = class extends BaseManager {
|
|
1093
|
+
constructor() {
|
|
1094
|
+
super(...arguments);
|
|
1095
|
+
this.route = "/cross-chain-swaps";
|
|
1096
|
+
}
|
|
1097
|
+
/** The tokens NEAR Intents can swap on Stellar, Solana and Monad. */
|
|
1098
|
+
async assets() {
|
|
1099
|
+
const { data } = await this.rest.get(
|
|
1100
|
+
`${this.route}/assets`
|
|
1101
|
+
);
|
|
1102
|
+
return data;
|
|
79
1103
|
}
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
1104
|
+
/** A dry quote: output, minimum and commission. Persists nothing. */
|
|
1105
|
+
quote(options) {
|
|
1106
|
+
return this.rest.post(`${this.route}/quote`, {
|
|
1107
|
+
body: options
|
|
1108
|
+
});
|
|
84
1109
|
}
|
|
85
|
-
/**
|
|
86
|
-
|
|
87
|
-
|
|
1110
|
+
/** A live quote: the deposit address, memo and wallet link that fund the swap. */
|
|
1111
|
+
async create(options) {
|
|
1112
|
+
const data = await this.rest.post(this.route, {
|
|
1113
|
+
body: options
|
|
1114
|
+
});
|
|
1115
|
+
return this._add(new CrossChainSwap(this.client, data));
|
|
88
1116
|
}
|
|
89
|
-
|
|
1117
|
+
async fetch(id) {
|
|
1118
|
+
const data = await this.rest.get(`${this.route}/${id}`);
|
|
1119
|
+
return this._add(new CrossChainSwap(this.client, data));
|
|
1120
|
+
}
|
|
1121
|
+
async list(options = {}) {
|
|
1122
|
+
const data = await this.rest.get(this.route, {
|
|
1123
|
+
query: { status: options.status, take: options.take, skip: options.skip }
|
|
1124
|
+
});
|
|
90
1125
|
return {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
note: this.note,
|
|
96
|
-
email: this.email,
|
|
97
|
-
account: this.account,
|
|
98
|
-
reference: this.reference,
|
|
99
|
-
createdAt: this.createdAt.toISOString(),
|
|
100
|
-
updatedAt: this.updatedAt.toISOString(),
|
|
101
|
-
...this.payments !== null ? { payments: this.payments } : {},
|
|
102
|
-
...this.succeeded !== null ? { succeeded: this.succeeded } : {},
|
|
103
|
-
...this.total !== null ? { total: this.total } : {}
|
|
1126
|
+
items: data.data.map((d) => this._add(new CrossChainSwap(this.client, d))),
|
|
1127
|
+
total: data.total,
|
|
1128
|
+
take: data.take,
|
|
1129
|
+
skip: data.skip
|
|
104
1130
|
};
|
|
105
1131
|
}
|
|
1132
|
+
/** Report the transaction that paid the deposit address. */
|
|
1133
|
+
async reportDeposit(id, txHash) {
|
|
1134
|
+
const data = await this.rest.post(
|
|
1135
|
+
`${this.route}/${id}/deposit`,
|
|
1136
|
+
{ body: { txHash } }
|
|
1137
|
+
);
|
|
1138
|
+
return this._add(new CrossChainSwap(this.client, data));
|
|
1139
|
+
}
|
|
106
1140
|
};
|
|
107
|
-
|
|
1141
|
+
|
|
1142
|
+
// src/managers/DefindexManager.ts
|
|
1143
|
+
var DefindexManager = class {
|
|
108
1144
|
constructor(client) {
|
|
109
|
-
|
|
110
|
-
/** Cache of structures keyed by id, populated on fetch/create. */
|
|
111
|
-
this.cache = /* @__PURE__ */ new Map();
|
|
1145
|
+
this.route = "/defindex";
|
|
112
1146
|
this.client = client;
|
|
113
1147
|
}
|
|
114
|
-
/** Shortcut to the shared REST instance. */
|
|
115
1148
|
get rest() {
|
|
116
1149
|
return this.client.rest;
|
|
117
1150
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
this.cache.set(structure.id, structure);
|
|
121
|
-
return structure;
|
|
1151
|
+
vaults() {
|
|
1152
|
+
return this.rest.get(`${this.route}/vaults`);
|
|
122
1153
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
1154
|
+
vault(vault) {
|
|
1155
|
+
return this.rest.get(`${this.route}/vaults/${encodeURIComponent(vault)}`);
|
|
1156
|
+
}
|
|
1157
|
+
/** An account's position in a vault. */
|
|
1158
|
+
balance(vault, account) {
|
|
1159
|
+
return this.rest.get(
|
|
1160
|
+
`${this.route}/vaults/${encodeURIComponent(vault)}/balance`,
|
|
1161
|
+
{ query: { account } }
|
|
1162
|
+
);
|
|
1163
|
+
}
|
|
1164
|
+
deposit(vault, options) {
|
|
1165
|
+
return this.rest.post(
|
|
1166
|
+
`${this.route}/vaults/${encodeURIComponent(vault)}/deposit`,
|
|
1167
|
+
{ body: options }
|
|
1168
|
+
);
|
|
1169
|
+
}
|
|
1170
|
+
withdraw(vault, options) {
|
|
1171
|
+
return this.rest.post(
|
|
1172
|
+
`${this.route}/vaults/${encodeURIComponent(vault)}/withdraw`,
|
|
1173
|
+
{ body: options }
|
|
1174
|
+
);
|
|
1175
|
+
}
|
|
1176
|
+
/** Submit a signed DeFindex transaction (base64 XDR). */
|
|
1177
|
+
submit(xdr) {
|
|
1178
|
+
return this.rest.post(`${this.route}/submit`, { body: { xdr } });
|
|
126
1179
|
}
|
|
127
1180
|
};
|
|
128
1181
|
|
|
129
|
-
// src/managers/
|
|
130
|
-
var
|
|
131
|
-
constructor() {
|
|
132
|
-
|
|
133
|
-
this.
|
|
1182
|
+
// src/managers/PluginManager.ts
|
|
1183
|
+
var PluginManager = class {
|
|
1184
|
+
constructor(client) {
|
|
1185
|
+
this.route = "/plugins";
|
|
1186
|
+
this.client = client;
|
|
134
1187
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const data = await this.rest.post(this.route, { body: options });
|
|
138
|
-
return this._add(new Customer(this.client, data));
|
|
1188
|
+
get rest() {
|
|
1189
|
+
return this.client.rest;
|
|
139
1190
|
}
|
|
140
|
-
/** List the consumer's customers (with payment stats). */
|
|
141
1191
|
async list() {
|
|
142
|
-
const data = await this.rest.get(this.route);
|
|
143
|
-
return data
|
|
1192
|
+
const { data } = await this.rest.get(this.route);
|
|
1193
|
+
return data;
|
|
144
1194
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const data = await this.rest.get(`${this.route}/${id}`);
|
|
148
|
-
return this._add(new Customer(this.client, data));
|
|
1195
|
+
fetch(slug) {
|
|
1196
|
+
return this.rest.get(`${this.route}/${encodeURIComponent(slug)}`);
|
|
149
1197
|
}
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
1198
|
+
/** Install (or re-consent to) a plugin. */
|
|
1199
|
+
install(slug, options) {
|
|
1200
|
+
return this.rest.put(
|
|
1201
|
+
`${this.route}/${encodeURIComponent(slug)}/installation`,
|
|
1202
|
+
{ body: options }
|
|
1203
|
+
);
|
|
156
1204
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
1205
|
+
uninstall(slug) {
|
|
1206
|
+
return this.rest.delete(
|
|
1207
|
+
`${this.route}/${encodeURIComponent(slug)}/installation`
|
|
1208
|
+
);
|
|
1209
|
+
}
|
|
1210
|
+
/** Run a read-only action the plugin declares. */
|
|
1211
|
+
query(slug, action, input) {
|
|
1212
|
+
return this.rest.post(
|
|
1213
|
+
`${this.route}/${encodeURIComponent(slug)}/queries/${encodeURIComponent(action)}`,
|
|
1214
|
+
{ body: { input } }
|
|
1215
|
+
);
|
|
1216
|
+
}
|
|
1217
|
+
/** Run an action that may change the plugin's state. */
|
|
1218
|
+
command(slug, action, input) {
|
|
1219
|
+
return this.rest.post(
|
|
1220
|
+
`${this.route}/${encodeURIComponent(slug)}/commands/${encodeURIComponent(action)}`,
|
|
1221
|
+
{ body: { input } }
|
|
161
1222
|
);
|
|
162
|
-
this.cache.delete(id);
|
|
163
|
-
return result;
|
|
164
1223
|
}
|
|
165
1224
|
};
|
|
166
1225
|
|
|
167
|
-
// src/managers/
|
|
168
|
-
var
|
|
1226
|
+
// src/managers/PublicKeyManager.ts
|
|
1227
|
+
var PublicKeyManager = class {
|
|
169
1228
|
constructor(client) {
|
|
1229
|
+
this.route = "/public-key";
|
|
170
1230
|
this.client = client;
|
|
171
1231
|
}
|
|
172
1232
|
get rest() {
|
|
173
1233
|
return this.client.rest;
|
|
174
1234
|
}
|
|
175
|
-
/**
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return true;
|
|
179
|
-
}
|
|
180
|
-
/** Readiness probe (checks the database). Returns the health report. */
|
|
181
|
-
readiness() {
|
|
182
|
-
return this.rest.get("/health/readiness");
|
|
1235
|
+
/** The public key for an environment (`dev` → testnet, `prod` → mainnet). */
|
|
1236
|
+
fetch(env = "dev") {
|
|
1237
|
+
return this.rest.get(this.route, { query: { env } });
|
|
183
1238
|
}
|
|
184
1239
|
};
|
|
185
1240
|
|
|
186
|
-
// src/types/index.ts
|
|
187
|
-
var PaymentIntentStatus = {
|
|
188
|
-
Pending: "PENDING",
|
|
189
|
-
Submitted: "SUBMITTED",
|
|
190
|
-
Succeeded: "SUCCEEDED",
|
|
191
|
-
Failed: "FAILED",
|
|
192
|
-
Cancelled: "CANCELLED",
|
|
193
|
-
Expired: "EXPIRED"
|
|
194
|
-
};
|
|
195
|
-
var PaymentIntentKind = {
|
|
196
|
-
/** Source account is known → unsigned XDR + `web+stellar:tx` URI. */
|
|
197
|
-
Tx: "TX",
|
|
198
|
-
/** No source → `web+stellar:pay` URI only (wallet picks the source). */
|
|
199
|
-
Pay: "PAY"
|
|
200
|
-
};
|
|
201
|
-
var WebhookEventType = {
|
|
202
|
-
PaymentIntentCreated: "PAYMENT_INTENT_CREATED",
|
|
203
|
-
PaymentIntentUpdated: "PAYMENT_INTENT_UPDATED",
|
|
204
|
-
PaymentIntentSucceeded: "PAYMENT_INTENT_SUCCEEDED",
|
|
205
|
-
PaymentIntentFailed: "PAYMENT_INTENT_FAILED",
|
|
206
|
-
PaymentIntentCancelled: "PAYMENT_INTENT_CANCELLED",
|
|
207
|
-
PaymentIntentDeleted: "PAYMENT_INTENT_DELETED"
|
|
208
|
-
};
|
|
209
|
-
var WebhookDeliveryStatus = {
|
|
210
|
-
Pending: "PENDING",
|
|
211
|
-
Succeeded: "SUCCEEDED",
|
|
212
|
-
Failed: "FAILED"
|
|
213
|
-
};
|
|
214
|
-
var ProductKind = {
|
|
215
|
-
Recurring: "recurring",
|
|
216
|
-
OneTime: "one_time",
|
|
217
|
-
Link: "link"
|
|
218
|
-
};
|
|
219
|
-
var SwapStatus = {
|
|
220
|
-
Pending: "PENDING",
|
|
221
|
-
Submitted: "SUBMITTED",
|
|
222
|
-
Succeeded: "SUCCEEDED",
|
|
223
|
-
Failed: "FAILED",
|
|
224
|
-
Expired: "EXPIRED"
|
|
225
|
-
};
|
|
226
|
-
|
|
227
1241
|
// src/structures/PaymentIntent.ts
|
|
228
1242
|
var PaymentIntent = class extends Base {
|
|
229
1243
|
constructor(client, data) {
|
|
@@ -345,6 +1359,13 @@ var PaymentIntentManager = class extends BaseManager {
|
|
|
345
1359
|
const data = await this.rest.get(`${this.route}/${id}`);
|
|
346
1360
|
return this._add(new PaymentIntent(this.client, data));
|
|
347
1361
|
}
|
|
1362
|
+
/**
|
|
1363
|
+
* Every status change an intent went through, oldest first — who moved it
|
|
1364
|
+
* (`api`, `validate`, `observer`, `system`), when, and with which transaction.
|
|
1365
|
+
*/
|
|
1366
|
+
transitions(id) {
|
|
1367
|
+
return this.rest.get(`${this.route}/${id}/transitions`);
|
|
1368
|
+
}
|
|
348
1369
|
/** List the consumer's payment intents (paginated). */
|
|
349
1370
|
async list(options = {}) {
|
|
350
1371
|
const data = await this.rest.get(this.route, {
|
|
@@ -490,6 +1511,92 @@ var ProductManager = class extends BaseManager {
|
|
|
490
1511
|
}
|
|
491
1512
|
};
|
|
492
1513
|
|
|
1514
|
+
// src/structures/ChainSwap.ts
|
|
1515
|
+
var ChainSwap = class extends Base {
|
|
1516
|
+
constructor(client, data) {
|
|
1517
|
+
super(client, data);
|
|
1518
|
+
}
|
|
1519
|
+
_patch(data) {
|
|
1520
|
+
super._patch(data);
|
|
1521
|
+
this.chain = data.chain;
|
|
1522
|
+
this.network = data.network;
|
|
1523
|
+
this.provider = data.provider;
|
|
1524
|
+
this.status = data.status;
|
|
1525
|
+
this.source = data.source;
|
|
1526
|
+
this.sendAsset = data.sendAsset;
|
|
1527
|
+
this.sendAmount = data.sendAmount;
|
|
1528
|
+
this.destAsset = data.destAsset;
|
|
1529
|
+
this.destEstimated = data.destEstimated;
|
|
1530
|
+
this.destMin = data.destMin;
|
|
1531
|
+
this.feeBps = data.feeBps;
|
|
1532
|
+
this.feeAmount = data.feeAmount;
|
|
1533
|
+
this.slippageBps = data.slippageBps;
|
|
1534
|
+
this.path = data.path;
|
|
1535
|
+
this.transaction = data.transaction;
|
|
1536
|
+
this.approval = data.approval;
|
|
1537
|
+
this.txHash = data.txHash;
|
|
1538
|
+
this.idempotencyKey = data.idempotencyKey;
|
|
1539
|
+
this.expiresAt = new Date(data.expiresAt);
|
|
1540
|
+
this.createdAt = new Date(data.createdAt);
|
|
1541
|
+
this.updatedAt = new Date(data.updatedAt);
|
|
1542
|
+
return this;
|
|
1543
|
+
}
|
|
1544
|
+
/** Whether the swap has settled on-chain. */
|
|
1545
|
+
get isSucceeded() {
|
|
1546
|
+
return this.status === SwapStatus.Succeeded;
|
|
1547
|
+
}
|
|
1548
|
+
/** Whether the swap is still awaiting submission. */
|
|
1549
|
+
get isPending() {
|
|
1550
|
+
return this.status === SwapStatus.Pending;
|
|
1551
|
+
}
|
|
1552
|
+
/** Whether the built transaction can no longer be submitted. */
|
|
1553
|
+
get isStale() {
|
|
1554
|
+
return this.isPending && this.expiresAt.getTime() <= Date.now();
|
|
1555
|
+
}
|
|
1556
|
+
/** Re-fetch this swap from the API. */
|
|
1557
|
+
async fetch() {
|
|
1558
|
+
return await this.client.swaps.fetch(this.id);
|
|
1559
|
+
}
|
|
1560
|
+
/**
|
|
1561
|
+
* Relay the signed transaction. Mutates this instance from the refreshed
|
|
1562
|
+
* swap in the outcome and returns the outcome.
|
|
1563
|
+
*/
|
|
1564
|
+
async submit(options) {
|
|
1565
|
+
const outcome = await this.client.swaps.submit(
|
|
1566
|
+
this.id,
|
|
1567
|
+
options
|
|
1568
|
+
);
|
|
1569
|
+
this._patch(outcome.swap.toJSON());
|
|
1570
|
+
return outcome;
|
|
1571
|
+
}
|
|
1572
|
+
toJSON() {
|
|
1573
|
+
return {
|
|
1574
|
+
id: this.id,
|
|
1575
|
+
chain: this.chain,
|
|
1576
|
+
network: this.network,
|
|
1577
|
+
provider: this.provider,
|
|
1578
|
+
status: this.status,
|
|
1579
|
+
source: this.source,
|
|
1580
|
+
sendAsset: this.sendAsset,
|
|
1581
|
+
sendAmount: this.sendAmount,
|
|
1582
|
+
destAsset: this.destAsset,
|
|
1583
|
+
destEstimated: this.destEstimated,
|
|
1584
|
+
destMin: this.destMin,
|
|
1585
|
+
feeBps: this.feeBps,
|
|
1586
|
+
feeAmount: this.feeAmount,
|
|
1587
|
+
slippageBps: this.slippageBps,
|
|
1588
|
+
path: this.path,
|
|
1589
|
+
transaction: this.transaction,
|
|
1590
|
+
approval: this.approval,
|
|
1591
|
+
txHash: this.txHash,
|
|
1592
|
+
idempotencyKey: this.idempotencyKey,
|
|
1593
|
+
expiresAt: this.expiresAt.toISOString(),
|
|
1594
|
+
createdAt: this.createdAt.toISOString(),
|
|
1595
|
+
updatedAt: this.updatedAt.toISOString()
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
};
|
|
1599
|
+
|
|
493
1600
|
// src/structures/Swap.ts
|
|
494
1601
|
var Swap = class extends Base {
|
|
495
1602
|
constructor(client, data) {
|
|
@@ -539,15 +1646,18 @@ var Swap = class extends Base {
|
|
|
539
1646
|
return !this.destAsset || this.destAsset === "native" ? "XLM" : this.destAsset;
|
|
540
1647
|
}
|
|
541
1648
|
/** Re-fetch this swap from the API, returning a fresh instance. */
|
|
542
|
-
fetch() {
|
|
543
|
-
return this.client.swaps.fetch(this.id);
|
|
1649
|
+
async fetch() {
|
|
1650
|
+
return await this.client.swaps.fetch(this.id);
|
|
544
1651
|
}
|
|
545
1652
|
/**
|
|
546
1653
|
* Relay the signed transaction for this swap. Mutates this instance from the
|
|
547
1654
|
* refreshed swap in the outcome and returns the outcome.
|
|
548
1655
|
*/
|
|
549
1656
|
async submit(options) {
|
|
550
|
-
const outcome = await this.client.swaps.submit(
|
|
1657
|
+
const outcome = await this.client.swaps.submit(
|
|
1658
|
+
this.id,
|
|
1659
|
+
options
|
|
1660
|
+
);
|
|
551
1661
|
this._patch(outcome.swap.toJSON());
|
|
552
1662
|
return outcome;
|
|
553
1663
|
}
|
|
@@ -582,6 +1692,9 @@ var Swap = class extends Base {
|
|
|
582
1692
|
};
|
|
583
1693
|
|
|
584
1694
|
// src/managers/SwapManager.ts
|
|
1695
|
+
function isChainSwapData(data) {
|
|
1696
|
+
return "chain" in data && typeof data.chain === "string";
|
|
1697
|
+
}
|
|
585
1698
|
var SwapManager = class extends BaseManager {
|
|
586
1699
|
constructor() {
|
|
587
1700
|
super(...arguments);
|
|
@@ -593,50 +1706,67 @@ var SwapManager = class extends BaseManager {
|
|
|
593
1706
|
body: options
|
|
594
1707
|
});
|
|
595
1708
|
}
|
|
596
|
-
/** Create a swap (unsigned XDR + SEP-7 URI + QR). */
|
|
597
1709
|
async create(options) {
|
|
598
|
-
const data = await this.rest.post(this.route, {
|
|
599
|
-
|
|
1710
|
+
const data = await this.rest.post(this.route, {
|
|
1711
|
+
body: options
|
|
1712
|
+
});
|
|
1713
|
+
return this.materialize(data);
|
|
600
1714
|
}
|
|
601
|
-
/** Get a single swap by id. */
|
|
1715
|
+
/** Get a single swap by id, on any chain. */
|
|
602
1716
|
async fetch(id) {
|
|
603
|
-
const data = await this.rest.get(
|
|
604
|
-
|
|
1717
|
+
const data = await this.rest.get(
|
|
1718
|
+
`${this.route}/${id}`
|
|
1719
|
+
);
|
|
1720
|
+
return this.materialize(data);
|
|
605
1721
|
}
|
|
606
|
-
/** List the consumer's swaps (paginated). */
|
|
607
1722
|
async list(options = {}) {
|
|
608
|
-
const data = await this.rest.get(
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
1723
|
+
const data = await this.rest.get(
|
|
1724
|
+
this.route,
|
|
1725
|
+
{
|
|
1726
|
+
query: {
|
|
1727
|
+
chain: options.chain,
|
|
1728
|
+
status: options.status,
|
|
1729
|
+
take: options.take,
|
|
1730
|
+
skip: options.skip
|
|
1731
|
+
}
|
|
613
1732
|
}
|
|
614
|
-
|
|
1733
|
+
);
|
|
615
1734
|
return {
|
|
616
|
-
items: data.data.map((d) => this.
|
|
1735
|
+
items: data.data.map((d) => this.materialize(d)),
|
|
617
1736
|
total: data.total,
|
|
618
1737
|
take: data.take,
|
|
619
1738
|
skip: data.skip
|
|
620
1739
|
};
|
|
621
1740
|
}
|
|
622
1741
|
/**
|
|
623
|
-
* Relay a signed swap transaction to
|
|
624
|
-
*
|
|
1742
|
+
* Relay a signed swap transaction to its network: `{ signedXdr }` for a
|
|
1743
|
+
* Stellar swap, `{ signedTransaction }` for a Solana or Monad one.
|
|
625
1744
|
*/
|
|
626
1745
|
async submit(id, options) {
|
|
627
|
-
const data = await this.rest.post(
|
|
628
|
-
|
|
629
|
-
{
|
|
630
|
-
|
|
1746
|
+
const data = await this.rest.post(`${this.route}/${id}/submit`, { body: options });
|
|
1747
|
+
if (isChainSwapData(data.swap)) {
|
|
1748
|
+
return {
|
|
1749
|
+
submitted: data.submitted,
|
|
1750
|
+
status: data.status,
|
|
1751
|
+
txHash: data.txHash,
|
|
1752
|
+
swap: this._add(new ChainSwap(this.client, data.swap))
|
|
1753
|
+
};
|
|
1754
|
+
}
|
|
1755
|
+
const stellar = data;
|
|
631
1756
|
return {
|
|
632
|
-
submitted:
|
|
633
|
-
status:
|
|
634
|
-
txHash:
|
|
635
|
-
reason:
|
|
636
|
-
resultCodes:
|
|
637
|
-
swap: this._add(new Swap(this.client,
|
|
1757
|
+
submitted: stellar.submitted,
|
|
1758
|
+
status: stellar.status,
|
|
1759
|
+
txHash: stellar.txHash ?? null,
|
|
1760
|
+
reason: stellar.reason ?? null,
|
|
1761
|
+
resultCodes: stellar.resultCodes ?? null,
|
|
1762
|
+
swap: this._add(new Swap(this.client, stellar.swap))
|
|
638
1763
|
};
|
|
639
1764
|
}
|
|
1765
|
+
materialize(data) {
|
|
1766
|
+
return this._add(
|
|
1767
|
+
isChainSwapData(data) ? new ChainSwap(this.client, data) : new Swap(this.client, data)
|
|
1768
|
+
);
|
|
1769
|
+
}
|
|
640
1770
|
};
|
|
641
1771
|
|
|
642
1772
|
// src/structures/WebhookDelivery.ts
|
|
@@ -921,12 +2051,9 @@ var WebhookManager = class extends BaseManager {
|
|
|
921
2051
|
"No webhook secret configured. Pass `{ secret }` or set `webhookSecret` on the client."
|
|
922
2052
|
);
|
|
923
2053
|
}
|
|
924
|
-
const event = Webhooks.constructEvent(
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
secret,
|
|
928
|
-
{ toleranceSeconds: options.toleranceSeconds }
|
|
929
|
-
);
|
|
2054
|
+
const event = Webhooks.constructEvent(rawBody, signatureHeader, secret, {
|
|
2055
|
+
toleranceSeconds: options.toleranceSeconds
|
|
2056
|
+
});
|
|
930
2057
|
this.emit(event.type, event);
|
|
931
2058
|
this.emit(toCamelEvent(event.type), event);
|
|
932
2059
|
this.emit("event", event);
|
|
@@ -1049,6 +2176,9 @@ var REST = class extends EventEmitter {
|
|
|
1049
2176
|
post(path, options = {}) {
|
|
1050
2177
|
return this.request("POST", path, options);
|
|
1051
2178
|
}
|
|
2179
|
+
put(path, options = {}) {
|
|
2180
|
+
return this.request("PUT", path, options);
|
|
2181
|
+
}
|
|
1052
2182
|
patch(path, options = {}) {
|
|
1053
2183
|
return this.request("PATCH", path, options);
|
|
1054
2184
|
}
|
|
@@ -1240,9 +2370,20 @@ var Client = class extends EventEmitter {
|
|
|
1240
2370
|
this.webhooks = new WebhookManager(this);
|
|
1241
2371
|
this.products = new ProductManager(this);
|
|
1242
2372
|
this.swaps = new SwapManager(this);
|
|
2373
|
+
this.crossChainSwaps = new CrossChainSwapManager(this);
|
|
2374
|
+
this.liquidity = new LiquidityManager(this);
|
|
2375
|
+
this.onramp = new OnrampManager(this);
|
|
2376
|
+
this.offramp = new OfframpManager(this);
|
|
2377
|
+
this.activity = new ActivityManager(this);
|
|
2378
|
+
this.kyc = new KycManager(this);
|
|
1243
2379
|
this.customers = new CustomerManager(this);
|
|
1244
2380
|
this.analytics = new AnalyticsManager(this);
|
|
1245
2381
|
this.health = new HealthManager(this);
|
|
2382
|
+
this.aliases = new AliasManager(this);
|
|
2383
|
+
this.assets = new AssetManager(this);
|
|
2384
|
+
this.plugins = new PluginManager(this);
|
|
2385
|
+
this.defindex = new DefindexManager(this);
|
|
2386
|
+
this.publicKey = new PublicKeyManager(this);
|
|
1246
2387
|
}
|
|
1247
2388
|
/** Update the API key used for subsequent requests. */
|
|
1248
2389
|
setApiKey(apiKey) {
|
|
@@ -1261,6 +2402,6 @@ var Client = class extends EventEmitter {
|
|
|
1261
2402
|
}
|
|
1262
2403
|
};
|
|
1263
2404
|
|
|
1264
|
-
export { AnalyticsManager, Base, BaseManager, Client, Customer, CustomerManager, HealthManager, PaymentIntent, PaymentIntentKind, PaymentIntentManager, PaymentIntentStatus, Product, ProductKind, ProductManager, REST, Swap, SwapManager, SwapStatus, WebhookDelivery, WebhookDeliveryStatus, WebhookEndpoint, WebhookEventType, WebhookManager, WebhookSignatureError, Webhooks, resolveShared, shared };
|
|
2405
|
+
export { ActivityManager, AliasManager, AnalyticsManager, AssetManager, Base, BaseManager, ChainSwap, Client, CrossChainSwap, CrossChainSwapManager, CrossChainSwapStatus, Customer, CustomerManager, DefindexManager, HealthManager, KycManager, LiquidityManager, LiquidityOperation, OfframpManager, OnrampManager, PaymentIntent, PaymentIntentKind, PaymentIntentManager, PaymentIntentStatus, PluginManager, Product, ProductKind, ProductManager, PublicKeyManager, REST, Receiver, Swap, SwapManager, SwapStatus, WebhookDelivery, WebhookDeliveryStatus, WebhookEndpoint, WebhookEventType, WebhookManager, WebhookSignatureError, Webhooks, resolveShared, shared };
|
|
1265
2406
|
//# sourceMappingURL=index.js.map
|
|
1266
2407
|
//# sourceMappingURL=index.js.map
|