@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.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) {
|
|
@@ -204,7 +299,32 @@ var WebhookEventType = {
|
|
|
204
299
|
PaymentIntentSucceeded: "PAYMENT_INTENT_SUCCEEDED",
|
|
205
300
|
PaymentIntentFailed: "PAYMENT_INTENT_FAILED",
|
|
206
301
|
PaymentIntentCancelled: "PAYMENT_INTENT_CANCELLED",
|
|
207
|
-
PaymentIntentDeleted: "PAYMENT_INTENT_DELETED"
|
|
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"
|
|
208
328
|
};
|
|
209
329
|
var WebhookDeliveryStatus = {
|
|
210
330
|
Pending: "PENDING",
|
|
@@ -228,6 +348,16 @@ var LiquidityOperationKind = {
|
|
|
228
348
|
var LiquidityOperationStatus = {
|
|
229
349
|
Pending: "PENDING",
|
|
230
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
|
+
};
|
|
231
361
|
|
|
232
362
|
// src/structures/LiquidityOperation.ts
|
|
233
363
|
var LiquidityOperation = class extends Base {
|
|
@@ -853,96 +983,260 @@ var KycManager = class extends BaseManager {
|
|
|
853
983
|
}
|
|
854
984
|
};
|
|
855
985
|
|
|
856
|
-
// src/
|
|
857
|
-
var
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
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);
|
|
861
995
|
}
|
|
862
|
-
|
|
863
|
-
|
|
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;
|
|
864
1032
|
}
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
return this.rest.post(`${this.route}/oauth/authorize`, { body: options });
|
|
1033
|
+
/** Whether the swap has reached an outcome that will not change. */
|
|
1034
|
+
get isFinal() {
|
|
1035
|
+
return FINAL.includes(this.status);
|
|
869
1036
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
* `pending` means keep waiting; anything else is over.
|
|
873
|
-
*/
|
|
874
|
-
session(state) {
|
|
875
|
-
return this.rest.get(`${this.route}/oauth/sessions/${state}`);
|
|
1037
|
+
get isSucceeded() {
|
|
1038
|
+
return this.status === CrossChainSwapStatus.Succeeded;
|
|
876
1039
|
}
|
|
877
|
-
/**
|
|
878
|
-
|
|
879
|
-
|
|
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());
|
|
880
1044
|
}
|
|
881
1045
|
/**
|
|
882
|
-
*
|
|
883
|
-
*
|
|
1046
|
+
* Report the transaction that paid the deposit address so NEAR Intents starts
|
|
1047
|
+
* without waiting for its indexer. Updates this instance in place.
|
|
884
1048
|
*/
|
|
885
|
-
|
|
886
|
-
|
|
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";
|
|
887
1098
|
}
|
|
888
|
-
/**
|
|
889
|
-
|
|
890
|
-
|
|
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;
|
|
891
1105
|
}
|
|
892
|
-
/**
|
|
893
|
-
|
|
894
|
-
return this.rest.post(`${this.route}/
|
|
1106
|
+
/** A dry quote: output, minimum and commission. Persists nothing. */
|
|
1107
|
+
quote(options) {
|
|
1108
|
+
return this.rest.post(`${this.route}/quote`, {
|
|
895
1109
|
body: options
|
|
896
1110
|
});
|
|
897
1111
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
* something pays for it, which is why a fresh Pollar wallet can have an address
|
|
902
|
-
* and still not be on the network.
|
|
903
|
-
*/
|
|
904
|
-
activateWallet(options) {
|
|
905
|
-
return this.rest.post(`${this.route}/wallets/activate`, {
|
|
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, {
|
|
906
1115
|
body: options
|
|
907
1116
|
});
|
|
1117
|
+
return this._add(new CrossChainSwap(this.client, data));
|
|
1118
|
+
}
|
|
1119
|
+
async fetch(id) {
|
|
1120
|
+
const data = await this.rest.get(`${this.route}/${id}`);
|
|
1121
|
+
return this._add(new CrossChainSwap(this.client, data));
|
|
908
1122
|
}
|
|
909
|
-
|
|
910
|
-
|
|
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
|
+
});
|
|
1127
|
+
return {
|
|
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
|
|
1132
|
+
};
|
|
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
|
+
}
|
|
1142
|
+
};
|
|
1143
|
+
|
|
1144
|
+
// src/managers/DefindexManager.ts
|
|
1145
|
+
var DefindexManager = class {
|
|
1146
|
+
constructor(client) {
|
|
1147
|
+
this.route = "/defindex";
|
|
1148
|
+
this.client = client;
|
|
1149
|
+
}
|
|
1150
|
+
get rest() {
|
|
1151
|
+
return this.client.rest;
|
|
1152
|
+
}
|
|
1153
|
+
vaults() {
|
|
1154
|
+
return this.rest.get(`${this.route}/vaults`);
|
|
1155
|
+
}
|
|
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) {
|
|
911
1167
|
return this.rest.post(
|
|
912
|
-
`${this.route}/
|
|
1168
|
+
`${this.route}/vaults/${encodeURIComponent(vault)}/deposit`,
|
|
1169
|
+
{ body: options }
|
|
913
1170
|
);
|
|
914
1171
|
}
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
body: options
|
|
919
|
-
|
|
1172
|
+
withdraw(vault, options) {
|
|
1173
|
+
return this.rest.post(
|
|
1174
|
+
`${this.route}/vaults/${encodeURIComponent(vault)}/withdraw`,
|
|
1175
|
+
{ body: options }
|
|
1176
|
+
);
|
|
920
1177
|
}
|
|
921
|
-
/**
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
1178
|
+
/** Submit a signed DeFindex transaction (base64 XDR). */
|
|
1179
|
+
submit(xdr) {
|
|
1180
|
+
return this.rest.post(`${this.route}/submit`, { body: { xdr } });
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
|
|
1184
|
+
// src/managers/PluginManager.ts
|
|
1185
|
+
var PluginManager = class {
|
|
1186
|
+
constructor(client) {
|
|
1187
|
+
this.route = "/plugins";
|
|
1188
|
+
this.client = client;
|
|
1189
|
+
}
|
|
1190
|
+
get rest() {
|
|
1191
|
+
return this.client.rest;
|
|
1192
|
+
}
|
|
1193
|
+
async list() {
|
|
1194
|
+
const { data } = await this.rest.get(this.route);
|
|
1195
|
+
return data;
|
|
1196
|
+
}
|
|
1197
|
+
fetch(slug) {
|
|
1198
|
+
return this.rest.get(`${this.route}/${encodeURIComponent(slug)}`);
|
|
1199
|
+
}
|
|
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
|
+
);
|
|
1206
|
+
}
|
|
1207
|
+
uninstall(slug) {
|
|
926
1208
|
return this.rest.delete(
|
|
927
|
-
`${this.route}
|
|
1209
|
+
`${this.route}/${encodeURIComponent(slug)}/installation`
|
|
928
1210
|
);
|
|
929
1211
|
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
registerUser(options) {
|
|
937
|
-
return this.rest.post(`${this.route}/users`, { body: options });
|
|
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
|
+
);
|
|
938
1218
|
}
|
|
939
|
-
/**
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
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 } }
|
|
1224
|
+
);
|
|
1225
|
+
}
|
|
1226
|
+
};
|
|
1227
|
+
|
|
1228
|
+
// src/managers/PublicKeyManager.ts
|
|
1229
|
+
var PublicKeyManager = class {
|
|
1230
|
+
constructor(client) {
|
|
1231
|
+
this.route = "/public-key";
|
|
1232
|
+
this.client = client;
|
|
1233
|
+
}
|
|
1234
|
+
get rest() {
|
|
1235
|
+
return this.client.rest;
|
|
1236
|
+
}
|
|
1237
|
+
/** The public key for an environment (`dev` → testnet, `prod` → mainnet). */
|
|
1238
|
+
fetch(env = "dev") {
|
|
1239
|
+
return this.rest.get(this.route, { query: { env } });
|
|
946
1240
|
}
|
|
947
1241
|
};
|
|
948
1242
|
|
|
@@ -1213,6 +1507,13 @@ var PaymentIntentManager = class extends BaseManager {
|
|
|
1213
1507
|
const data = await this.rest.get(`${this.route}/${id}`);
|
|
1214
1508
|
return this._add(new PaymentIntent(this.client, data));
|
|
1215
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
|
+
}
|
|
1216
1517
|
/** List the consumer's payment intents (paginated). */
|
|
1217
1518
|
async list(options = {}) {
|
|
1218
1519
|
const data = await this.rest.get(this.route, {
|
|
@@ -1358,6 +1659,92 @@ var ProductManager = class extends BaseManager {
|
|
|
1358
1659
|
}
|
|
1359
1660
|
};
|
|
1360
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
|
+
|
|
1361
1748
|
// src/structures/Swap.ts
|
|
1362
1749
|
var Swap = class extends Base {
|
|
1363
1750
|
constructor(client, data) {
|
|
@@ -1407,15 +1794,18 @@ var Swap = class extends Base {
|
|
|
1407
1794
|
return !this.destAsset || this.destAsset === "native" ? "XLM" : this.destAsset;
|
|
1408
1795
|
}
|
|
1409
1796
|
/** Re-fetch this swap from the API, returning a fresh instance. */
|
|
1410
|
-
fetch() {
|
|
1411
|
-
return this.client.swaps.fetch(this.id);
|
|
1797
|
+
async fetch() {
|
|
1798
|
+
return await this.client.swaps.fetch(this.id);
|
|
1412
1799
|
}
|
|
1413
1800
|
/**
|
|
1414
1801
|
* Relay the signed transaction for this swap. Mutates this instance from the
|
|
1415
1802
|
* refreshed swap in the outcome and returns the outcome.
|
|
1416
1803
|
*/
|
|
1417
1804
|
async submit(options) {
|
|
1418
|
-
const outcome = await this.client.swaps.submit(
|
|
1805
|
+
const outcome = await this.client.swaps.submit(
|
|
1806
|
+
this.id,
|
|
1807
|
+
options
|
|
1808
|
+
);
|
|
1419
1809
|
this._patch(outcome.swap.toJSON());
|
|
1420
1810
|
return outcome;
|
|
1421
1811
|
}
|
|
@@ -1450,6 +1840,9 @@ var Swap = class extends Base {
|
|
|
1450
1840
|
};
|
|
1451
1841
|
|
|
1452
1842
|
// src/managers/SwapManager.ts
|
|
1843
|
+
function isChainSwapData(data) {
|
|
1844
|
+
return "chain" in data && typeof data.chain === "string";
|
|
1845
|
+
}
|
|
1453
1846
|
var SwapManager = class extends BaseManager {
|
|
1454
1847
|
constructor() {
|
|
1455
1848
|
super(...arguments);
|
|
@@ -1461,50 +1854,67 @@ var SwapManager = class extends BaseManager {
|
|
|
1461
1854
|
body: options
|
|
1462
1855
|
});
|
|
1463
1856
|
}
|
|
1464
|
-
/** Create a swap (unsigned XDR + SEP-7 URI + QR). */
|
|
1465
1857
|
async create(options) {
|
|
1466
|
-
const data = await this.rest.post(this.route, {
|
|
1467
|
-
|
|
1858
|
+
const data = await this.rest.post(this.route, {
|
|
1859
|
+
body: options
|
|
1860
|
+
});
|
|
1861
|
+
return this.materialize(data);
|
|
1468
1862
|
}
|
|
1469
|
-
/** Get a single swap by id. */
|
|
1863
|
+
/** Get a single swap by id, on any chain. */
|
|
1470
1864
|
async fetch(id) {
|
|
1471
|
-
const data = await this.rest.get(
|
|
1472
|
-
|
|
1865
|
+
const data = await this.rest.get(
|
|
1866
|
+
`${this.route}/${id}`
|
|
1867
|
+
);
|
|
1868
|
+
return this.materialize(data);
|
|
1473
1869
|
}
|
|
1474
|
-
/** List the consumer's swaps (paginated). */
|
|
1475
1870
|
async list(options = {}) {
|
|
1476
|
-
const data = await this.rest.get(
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
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
|
+
}
|
|
1481
1880
|
}
|
|
1482
|
-
|
|
1881
|
+
);
|
|
1483
1882
|
return {
|
|
1484
|
-
items: data.data.map((d) => this.
|
|
1883
|
+
items: data.data.map((d) => this.materialize(d)),
|
|
1485
1884
|
total: data.total,
|
|
1486
1885
|
take: data.take,
|
|
1487
1886
|
skip: data.skip
|
|
1488
1887
|
};
|
|
1489
1888
|
}
|
|
1490
1889
|
/**
|
|
1491
|
-
* Relay a signed swap transaction to
|
|
1492
|
-
*
|
|
1890
|
+
* Relay a signed swap transaction to its network: `{ signedXdr }` for a
|
|
1891
|
+
* Stellar swap, `{ signedTransaction }` for a Solana or Monad one.
|
|
1493
1892
|
*/
|
|
1494
1893
|
async submit(id, options) {
|
|
1495
|
-
const data = await this.rest.post(
|
|
1496
|
-
|
|
1497
|
-
{
|
|
1498
|
-
|
|
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;
|
|
1499
1904
|
return {
|
|
1500
|
-
submitted:
|
|
1501
|
-
status:
|
|
1502
|
-
txHash:
|
|
1503
|
-
reason:
|
|
1504
|
-
resultCodes:
|
|
1505
|
-
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))
|
|
1506
1911
|
};
|
|
1507
1912
|
}
|
|
1913
|
+
materialize(data) {
|
|
1914
|
+
return this._add(
|
|
1915
|
+
isChainSwapData(data) ? new ChainSwap(this.client, data) : new Swap(this.client, data)
|
|
1916
|
+
);
|
|
1917
|
+
}
|
|
1508
1918
|
};
|
|
1509
1919
|
|
|
1510
1920
|
// src/structures/WebhookDelivery.ts
|
|
@@ -1619,7 +2029,7 @@ var WebhookEndpoint = class extends Base {
|
|
|
1619
2029
|
};
|
|
1620
2030
|
|
|
1621
2031
|
// src/util/Constants.ts
|
|
1622
|
-
var version = "2.
|
|
2032
|
+
var version = "2.1.0";
|
|
1623
2033
|
var DEFAULT_BASE_URL = "https://api.cosmospay.lat/cosmos-api";
|
|
1624
2034
|
var DEFAULT_VERSION = "v1";
|
|
1625
2035
|
var DEFAULT_TIMEOUT = 3e4;
|
|
@@ -1805,12 +2215,9 @@ var WebhookManager = class extends BaseManager {
|
|
|
1805
2215
|
"No webhook secret configured. Pass `{ secret }` or set `webhookSecret` on the client."
|
|
1806
2216
|
);
|
|
1807
2217
|
}
|
|
1808
|
-
const event = Webhooks.constructEvent(
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
secret,
|
|
1812
|
-
{ toleranceSeconds: options.toleranceSeconds }
|
|
1813
|
-
);
|
|
2218
|
+
const event = Webhooks.constructEvent(rawBody, signatureHeader, secret, {
|
|
2219
|
+
toleranceSeconds: options.toleranceSeconds
|
|
2220
|
+
});
|
|
1814
2221
|
this.emit(event.type, event);
|
|
1815
2222
|
this.emit(toCamelEvent(event.type), event);
|
|
1816
2223
|
this.emit("event", event);
|
|
@@ -1979,6 +2386,9 @@ var REST = class extends events.EventEmitter {
|
|
|
1979
2386
|
post(path, options = {}) {
|
|
1980
2387
|
return this.request("POST", path, options);
|
|
1981
2388
|
}
|
|
2389
|
+
put(path, options = {}) {
|
|
2390
|
+
return this.request("PUT", path, options);
|
|
2391
|
+
}
|
|
1982
2392
|
patch(path, options = {}) {
|
|
1983
2393
|
return this.request("PATCH", path, options);
|
|
1984
2394
|
}
|
|
@@ -2170,15 +2580,20 @@ var Client = class extends events.EventEmitter {
|
|
|
2170
2580
|
this.webhooks = new WebhookManager(this);
|
|
2171
2581
|
this.products = new ProductManager(this);
|
|
2172
2582
|
this.swaps = new SwapManager(this);
|
|
2583
|
+
this.crossChainSwaps = new CrossChainSwapManager(this);
|
|
2173
2584
|
this.liquidity = new LiquidityManager(this);
|
|
2174
2585
|
this.onramp = new OnrampManager(this);
|
|
2175
2586
|
this.offramp = new OfframpManager(this);
|
|
2176
2587
|
this.activity = new ActivityManager(this);
|
|
2177
2588
|
this.kyc = new KycManager(this);
|
|
2178
|
-
this.pollar = new PollarManager(this);
|
|
2179
2589
|
this.customers = new CustomerManager(this);
|
|
2180
2590
|
this.analytics = new AnalyticsManager(this);
|
|
2181
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);
|
|
2182
2597
|
}
|
|
2183
2598
|
/** Update the API key used for subsequent requests. */
|
|
2184
2599
|
setApiKey(apiKey) {
|
|
@@ -2210,19 +2625,26 @@ var Wallets = {
|
|
|
2210
2625
|
|
|
2211
2626
|
exports.ActivityManager = ActivityManager;
|
|
2212
2627
|
exports.AddressBook = AddressBook;
|
|
2628
|
+
exports.AliasManager = AliasManager;
|
|
2213
2629
|
exports.AnalyticsManager = AnalyticsManager;
|
|
2630
|
+
exports.AssetManager = AssetManager;
|
|
2214
2631
|
exports.Assets = Assets;
|
|
2215
2632
|
exports.Base = Base;
|
|
2216
2633
|
exports.BaseManager = BaseManager;
|
|
2634
|
+
exports.ChainSwap = ChainSwap;
|
|
2217
2635
|
exports.Client = Client;
|
|
2218
2636
|
exports.CosmosPayAPIError = CosmosPayAPIError;
|
|
2219
2637
|
exports.CosmosPayRequestError = CosmosPayRequestError;
|
|
2638
|
+
exports.CrossChainSwap = CrossChainSwap;
|
|
2639
|
+
exports.CrossChainSwapManager = CrossChainSwapManager;
|
|
2640
|
+
exports.CrossChainSwapStatus = CrossChainSwapStatus;
|
|
2220
2641
|
exports.Customer = Customer;
|
|
2221
2642
|
exports.CustomerManager = CustomerManager;
|
|
2222
2643
|
exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
|
|
2223
2644
|
exports.DEFAULT_RETRIES = DEFAULT_RETRIES;
|
|
2224
2645
|
exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
|
|
2225
2646
|
exports.DEFAULT_VERSION = DEFAULT_VERSION;
|
|
2647
|
+
exports.DefindexManager = DefindexManager;
|
|
2226
2648
|
exports.Events = Events;
|
|
2227
2649
|
exports.HealthManager = HealthManager;
|
|
2228
2650
|
exports.KycManager = KycManager;
|
|
@@ -2234,10 +2656,11 @@ exports.PaymentIntent = PaymentIntent;
|
|
|
2234
2656
|
exports.PaymentIntentKind = PaymentIntentKind;
|
|
2235
2657
|
exports.PaymentIntentManager = PaymentIntentManager;
|
|
2236
2658
|
exports.PaymentIntentStatus = PaymentIntentStatus;
|
|
2237
|
-
exports.
|
|
2659
|
+
exports.PluginManager = PluginManager;
|
|
2238
2660
|
exports.Product = Product;
|
|
2239
2661
|
exports.ProductKind = ProductKind;
|
|
2240
2662
|
exports.ProductManager = ProductManager;
|
|
2663
|
+
exports.PublicKeyManager = PublicKeyManager;
|
|
2241
2664
|
exports.REST = REST;
|
|
2242
2665
|
exports.Receiver = Receiver;
|
|
2243
2666
|
exports.SIGNATURE_HEADER = SIGNATURE_HEADER;
|