@cosmosapp/pay_sdk 2.0.0 → 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 +18 -0
- package/README.md +65 -0
- package/dist/{chunk-TM4HAKWE.js → chunk-NK5EHEKJ.js} +3 -3
- package/dist/{chunk-TM4HAKWE.js.map → chunk-NK5EHEKJ.js.map} +1 -1
- package/dist/index.cjs +529 -106
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +372 -121
- package/dist/index.d.ts +372 -121
- package/dist/index.js +522 -107
- package/dist/index.js.map +1 -1
- package/dist/{intent-input-BtUp3tFN.d.cts → intent-input-8rZfCrQ0.d.cts} +522 -177
- package/dist/{intent-input-BtUp3tFN.d.ts → intent-input-8rZfCrQ0.d.ts} +522 -177
- package/dist/web/index.cjs +1 -1
- package/dist/web/index.cjs.map +1 -1
- package/dist/web/index.d.cts +2 -2
- package/dist/web/index.d.ts +2 -2
- package/dist/web/index.js +2 -2
- package/llms/15-swaps.md +58 -0
- package/llms/llms-full.txt +61 -0
- package/llms/llms.txt +1 -0
- package/package.json +7 -5
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) {
|
|
@@ -202,7 +297,32 @@ var WebhookEventType = {
|
|
|
202
297
|
PaymentIntentSucceeded: "PAYMENT_INTENT_SUCCEEDED",
|
|
203
298
|
PaymentIntentFailed: "PAYMENT_INTENT_FAILED",
|
|
204
299
|
PaymentIntentCancelled: "PAYMENT_INTENT_CANCELLED",
|
|
205
|
-
PaymentIntentDeleted: "PAYMENT_INTENT_DELETED"
|
|
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"
|
|
206
326
|
};
|
|
207
327
|
var WebhookDeliveryStatus = {
|
|
208
328
|
Pending: "PENDING",
|
|
@@ -226,6 +346,16 @@ var LiquidityOperationKind = {
|
|
|
226
346
|
var LiquidityOperationStatus = {
|
|
227
347
|
Pending: "PENDING",
|
|
228
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
|
+
};
|
|
229
359
|
|
|
230
360
|
// src/structures/LiquidityOperation.ts
|
|
231
361
|
var LiquidityOperation = class extends Base {
|
|
@@ -851,96 +981,260 @@ var KycManager = class extends BaseManager {
|
|
|
851
981
|
}
|
|
852
982
|
};
|
|
853
983
|
|
|
854
|
-
// src/
|
|
855
|
-
var
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
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);
|
|
859
993
|
}
|
|
860
|
-
|
|
861
|
-
|
|
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;
|
|
862
1030
|
}
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
return this.rest.post(`${this.route}/oauth/authorize`, { body: options });
|
|
1031
|
+
/** Whether the swap has reached an outcome that will not change. */
|
|
1032
|
+
get isFinal() {
|
|
1033
|
+
return FINAL.includes(this.status);
|
|
867
1034
|
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
* `pending` means keep waiting; anything else is over.
|
|
871
|
-
*/
|
|
872
|
-
session(state) {
|
|
873
|
-
return this.rest.get(`${this.route}/oauth/sessions/${state}`);
|
|
1035
|
+
get isSucceeded() {
|
|
1036
|
+
return this.status === CrossChainSwapStatus.Succeeded;
|
|
874
1037
|
}
|
|
875
|
-
/**
|
|
876
|
-
|
|
877
|
-
|
|
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());
|
|
878
1042
|
}
|
|
879
1043
|
/**
|
|
880
|
-
*
|
|
881
|
-
*
|
|
1044
|
+
* Report the transaction that paid the deposit address so NEAR Intents starts
|
|
1045
|
+
* without waiting for its indexer. Updates this instance in place.
|
|
882
1046
|
*/
|
|
883
|
-
|
|
884
|
-
|
|
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";
|
|
885
1096
|
}
|
|
886
|
-
/**
|
|
887
|
-
|
|
888
|
-
|
|
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;
|
|
889
1103
|
}
|
|
890
|
-
/**
|
|
891
|
-
|
|
892
|
-
return this.rest.post(`${this.route}/
|
|
1104
|
+
/** A dry quote: output, minimum and commission. Persists nothing. */
|
|
1105
|
+
quote(options) {
|
|
1106
|
+
return this.rest.post(`${this.route}/quote`, {
|
|
893
1107
|
body: options
|
|
894
1108
|
});
|
|
895
1109
|
}
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
* something pays for it, which is why a fresh Pollar wallet can have an address
|
|
900
|
-
* and still not be on the network.
|
|
901
|
-
*/
|
|
902
|
-
activateWallet(options) {
|
|
903
|
-
return this.rest.post(`${this.route}/wallets/activate`, {
|
|
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, {
|
|
904
1113
|
body: options
|
|
905
1114
|
});
|
|
1115
|
+
return this._add(new CrossChainSwap(this.client, data));
|
|
1116
|
+
}
|
|
1117
|
+
async fetch(id) {
|
|
1118
|
+
const data = await this.rest.get(`${this.route}/${id}`);
|
|
1119
|
+
return this._add(new CrossChainSwap(this.client, data));
|
|
906
1120
|
}
|
|
907
|
-
|
|
908
|
-
|
|
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
|
+
});
|
|
1125
|
+
return {
|
|
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
|
|
1130
|
+
};
|
|
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
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
|
|
1142
|
+
// src/managers/DefindexManager.ts
|
|
1143
|
+
var DefindexManager = class {
|
|
1144
|
+
constructor(client) {
|
|
1145
|
+
this.route = "/defindex";
|
|
1146
|
+
this.client = client;
|
|
1147
|
+
}
|
|
1148
|
+
get rest() {
|
|
1149
|
+
return this.client.rest;
|
|
1150
|
+
}
|
|
1151
|
+
vaults() {
|
|
1152
|
+
return this.rest.get(`${this.route}/vaults`);
|
|
1153
|
+
}
|
|
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) {
|
|
909
1165
|
return this.rest.post(
|
|
910
|
-
`${this.route}/
|
|
1166
|
+
`${this.route}/vaults/${encodeURIComponent(vault)}/deposit`,
|
|
1167
|
+
{ body: options }
|
|
911
1168
|
);
|
|
912
1169
|
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
body: options
|
|
917
|
-
|
|
1170
|
+
withdraw(vault, options) {
|
|
1171
|
+
return this.rest.post(
|
|
1172
|
+
`${this.route}/vaults/${encodeURIComponent(vault)}/withdraw`,
|
|
1173
|
+
{ body: options }
|
|
1174
|
+
);
|
|
918
1175
|
}
|
|
919
|
-
/**
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
1176
|
+
/** Submit a signed DeFindex transaction (base64 XDR). */
|
|
1177
|
+
submit(xdr) {
|
|
1178
|
+
return this.rest.post(`${this.route}/submit`, { body: { xdr } });
|
|
1179
|
+
}
|
|
1180
|
+
};
|
|
1181
|
+
|
|
1182
|
+
// src/managers/PluginManager.ts
|
|
1183
|
+
var PluginManager = class {
|
|
1184
|
+
constructor(client) {
|
|
1185
|
+
this.route = "/plugins";
|
|
1186
|
+
this.client = client;
|
|
1187
|
+
}
|
|
1188
|
+
get rest() {
|
|
1189
|
+
return this.client.rest;
|
|
1190
|
+
}
|
|
1191
|
+
async list() {
|
|
1192
|
+
const { data } = await this.rest.get(this.route);
|
|
1193
|
+
return data;
|
|
1194
|
+
}
|
|
1195
|
+
fetch(slug) {
|
|
1196
|
+
return this.rest.get(`${this.route}/${encodeURIComponent(slug)}`);
|
|
1197
|
+
}
|
|
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
|
+
);
|
|
1204
|
+
}
|
|
1205
|
+
uninstall(slug) {
|
|
924
1206
|
return this.rest.delete(
|
|
925
|
-
`${this.route}
|
|
1207
|
+
`${this.route}/${encodeURIComponent(slug)}/installation`
|
|
926
1208
|
);
|
|
927
1209
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
registerUser(options) {
|
|
935
|
-
return this.rest.post(`${this.route}/users`, { body: options });
|
|
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
|
+
);
|
|
936
1216
|
}
|
|
937
|
-
/**
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
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 } }
|
|
1222
|
+
);
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
|
|
1226
|
+
// src/managers/PublicKeyManager.ts
|
|
1227
|
+
var PublicKeyManager = class {
|
|
1228
|
+
constructor(client) {
|
|
1229
|
+
this.route = "/public-key";
|
|
1230
|
+
this.client = client;
|
|
1231
|
+
}
|
|
1232
|
+
get rest() {
|
|
1233
|
+
return this.client.rest;
|
|
1234
|
+
}
|
|
1235
|
+
/** The public key for an environment (`dev` → testnet, `prod` → mainnet). */
|
|
1236
|
+
fetch(env = "dev") {
|
|
1237
|
+
return this.rest.get(this.route, { query: { env } });
|
|
944
1238
|
}
|
|
945
1239
|
};
|
|
946
1240
|
|
|
@@ -1065,6 +1359,13 @@ var PaymentIntentManager = class extends BaseManager {
|
|
|
1065
1359
|
const data = await this.rest.get(`${this.route}/${id}`);
|
|
1066
1360
|
return this._add(new PaymentIntent(this.client, data));
|
|
1067
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
|
+
}
|
|
1068
1369
|
/** List the consumer's payment intents (paginated). */
|
|
1069
1370
|
async list(options = {}) {
|
|
1070
1371
|
const data = await this.rest.get(this.route, {
|
|
@@ -1210,6 +1511,92 @@ var ProductManager = class extends BaseManager {
|
|
|
1210
1511
|
}
|
|
1211
1512
|
};
|
|
1212
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
|
+
|
|
1213
1600
|
// src/structures/Swap.ts
|
|
1214
1601
|
var Swap = class extends Base {
|
|
1215
1602
|
constructor(client, data) {
|
|
@@ -1259,15 +1646,18 @@ var Swap = class extends Base {
|
|
|
1259
1646
|
return !this.destAsset || this.destAsset === "native" ? "XLM" : this.destAsset;
|
|
1260
1647
|
}
|
|
1261
1648
|
/** Re-fetch this swap from the API, returning a fresh instance. */
|
|
1262
|
-
fetch() {
|
|
1263
|
-
return this.client.swaps.fetch(this.id);
|
|
1649
|
+
async fetch() {
|
|
1650
|
+
return await this.client.swaps.fetch(this.id);
|
|
1264
1651
|
}
|
|
1265
1652
|
/**
|
|
1266
1653
|
* Relay the signed transaction for this swap. Mutates this instance from the
|
|
1267
1654
|
* refreshed swap in the outcome and returns the outcome.
|
|
1268
1655
|
*/
|
|
1269
1656
|
async submit(options) {
|
|
1270
|
-
const outcome = await this.client.swaps.submit(
|
|
1657
|
+
const outcome = await this.client.swaps.submit(
|
|
1658
|
+
this.id,
|
|
1659
|
+
options
|
|
1660
|
+
);
|
|
1271
1661
|
this._patch(outcome.swap.toJSON());
|
|
1272
1662
|
return outcome;
|
|
1273
1663
|
}
|
|
@@ -1302,6 +1692,9 @@ var Swap = class extends Base {
|
|
|
1302
1692
|
};
|
|
1303
1693
|
|
|
1304
1694
|
// src/managers/SwapManager.ts
|
|
1695
|
+
function isChainSwapData(data) {
|
|
1696
|
+
return "chain" in data && typeof data.chain === "string";
|
|
1697
|
+
}
|
|
1305
1698
|
var SwapManager = class extends BaseManager {
|
|
1306
1699
|
constructor() {
|
|
1307
1700
|
super(...arguments);
|
|
@@ -1313,50 +1706,67 @@ var SwapManager = class extends BaseManager {
|
|
|
1313
1706
|
body: options
|
|
1314
1707
|
});
|
|
1315
1708
|
}
|
|
1316
|
-
/** Create a swap (unsigned XDR + SEP-7 URI + QR). */
|
|
1317
1709
|
async create(options) {
|
|
1318
|
-
const data = await this.rest.post(this.route, {
|
|
1319
|
-
|
|
1710
|
+
const data = await this.rest.post(this.route, {
|
|
1711
|
+
body: options
|
|
1712
|
+
});
|
|
1713
|
+
return this.materialize(data);
|
|
1320
1714
|
}
|
|
1321
|
-
/** Get a single swap by id. */
|
|
1715
|
+
/** Get a single swap by id, on any chain. */
|
|
1322
1716
|
async fetch(id) {
|
|
1323
|
-
const data = await this.rest.get(
|
|
1324
|
-
|
|
1717
|
+
const data = await this.rest.get(
|
|
1718
|
+
`${this.route}/${id}`
|
|
1719
|
+
);
|
|
1720
|
+
return this.materialize(data);
|
|
1325
1721
|
}
|
|
1326
|
-
/** List the consumer's swaps (paginated). */
|
|
1327
1722
|
async list(options = {}) {
|
|
1328
|
-
const data = await this.rest.get(
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
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
|
+
}
|
|
1333
1732
|
}
|
|
1334
|
-
|
|
1733
|
+
);
|
|
1335
1734
|
return {
|
|
1336
|
-
items: data.data.map((d) => this.
|
|
1735
|
+
items: data.data.map((d) => this.materialize(d)),
|
|
1337
1736
|
total: data.total,
|
|
1338
1737
|
take: data.take,
|
|
1339
1738
|
skip: data.skip
|
|
1340
1739
|
};
|
|
1341
1740
|
}
|
|
1342
1741
|
/**
|
|
1343
|
-
* Relay a signed swap transaction to
|
|
1344
|
-
*
|
|
1742
|
+
* Relay a signed swap transaction to its network: `{ signedXdr }` for a
|
|
1743
|
+
* Stellar swap, `{ signedTransaction }` for a Solana or Monad one.
|
|
1345
1744
|
*/
|
|
1346
1745
|
async submit(id, options) {
|
|
1347
|
-
const data = await this.rest.post(
|
|
1348
|
-
|
|
1349
|
-
{
|
|
1350
|
-
|
|
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;
|
|
1351
1756
|
return {
|
|
1352
|
-
submitted:
|
|
1353
|
-
status:
|
|
1354
|
-
txHash:
|
|
1355
|
-
reason:
|
|
1356
|
-
resultCodes:
|
|
1357
|
-
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))
|
|
1358
1763
|
};
|
|
1359
1764
|
}
|
|
1765
|
+
materialize(data) {
|
|
1766
|
+
return this._add(
|
|
1767
|
+
isChainSwapData(data) ? new ChainSwap(this.client, data) : new Swap(this.client, data)
|
|
1768
|
+
);
|
|
1769
|
+
}
|
|
1360
1770
|
};
|
|
1361
1771
|
|
|
1362
1772
|
// src/structures/WebhookDelivery.ts
|
|
@@ -1641,12 +2051,9 @@ var WebhookManager = class extends BaseManager {
|
|
|
1641
2051
|
"No webhook secret configured. Pass `{ secret }` or set `webhookSecret` on the client."
|
|
1642
2052
|
);
|
|
1643
2053
|
}
|
|
1644
|
-
const event = Webhooks.constructEvent(
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
secret,
|
|
1648
|
-
{ toleranceSeconds: options.toleranceSeconds }
|
|
1649
|
-
);
|
|
2054
|
+
const event = Webhooks.constructEvent(rawBody, signatureHeader, secret, {
|
|
2055
|
+
toleranceSeconds: options.toleranceSeconds
|
|
2056
|
+
});
|
|
1650
2057
|
this.emit(event.type, event);
|
|
1651
2058
|
this.emit(toCamelEvent(event.type), event);
|
|
1652
2059
|
this.emit("event", event);
|
|
@@ -1769,6 +2176,9 @@ var REST = class extends EventEmitter {
|
|
|
1769
2176
|
post(path, options = {}) {
|
|
1770
2177
|
return this.request("POST", path, options);
|
|
1771
2178
|
}
|
|
2179
|
+
put(path, options = {}) {
|
|
2180
|
+
return this.request("PUT", path, options);
|
|
2181
|
+
}
|
|
1772
2182
|
patch(path, options = {}) {
|
|
1773
2183
|
return this.request("PATCH", path, options);
|
|
1774
2184
|
}
|
|
@@ -1960,15 +2370,20 @@ var Client = class extends EventEmitter {
|
|
|
1960
2370
|
this.webhooks = new WebhookManager(this);
|
|
1961
2371
|
this.products = new ProductManager(this);
|
|
1962
2372
|
this.swaps = new SwapManager(this);
|
|
2373
|
+
this.crossChainSwaps = new CrossChainSwapManager(this);
|
|
1963
2374
|
this.liquidity = new LiquidityManager(this);
|
|
1964
2375
|
this.onramp = new OnrampManager(this);
|
|
1965
2376
|
this.offramp = new OfframpManager(this);
|
|
1966
2377
|
this.activity = new ActivityManager(this);
|
|
1967
2378
|
this.kyc = new KycManager(this);
|
|
1968
|
-
this.pollar = new PollarManager(this);
|
|
1969
2379
|
this.customers = new CustomerManager(this);
|
|
1970
2380
|
this.analytics = new AnalyticsManager(this);
|
|
1971
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);
|
|
1972
2387
|
}
|
|
1973
2388
|
/** Update the API key used for subsequent requests. */
|
|
1974
2389
|
setApiKey(apiKey) {
|
|
@@ -1987,6 +2402,6 @@ var Client = class extends EventEmitter {
|
|
|
1987
2402
|
}
|
|
1988
2403
|
};
|
|
1989
2404
|
|
|
1990
|
-
export { ActivityManager, AnalyticsManager, Base, BaseManager, Client, Customer, CustomerManager, HealthManager, KycManager, LiquidityManager, LiquidityOperation, OfframpManager, OnrampManager, PaymentIntent, PaymentIntentKind, PaymentIntentManager, PaymentIntentStatus,
|
|
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 };
|
|
1991
2406
|
//# sourceMappingURL=index.js.map
|
|
1992
2407
|
//# sourceMappingURL=index.js.map
|