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