@pegaroute/sdk 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +199 -2
- package/dist/index-CeY_5Z4u.d.ts +1070 -0
- package/dist/index.d.ts +499 -0
- package/dist/index.js +901 -0
- package/dist/types-Cz8gDMIR.js +64 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +2 -0
- package/package.json +63 -4
|
@@ -0,0 +1,1070 @@
|
|
|
1
|
+
//#region src/types/discovery.d.ts
|
|
2
|
+
/** A chain Pegaroute can route to or from. */
|
|
3
|
+
interface Chain {
|
|
4
|
+
/** Chain ID to use in quote and swap requests, e.g. `"ETH"`. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** Display name, e.g. `"Ethereum"`. */
|
|
7
|
+
name: string;
|
|
8
|
+
/** EVM chain ID, or `null` for non-EVM chains. */
|
|
9
|
+
chainId: number | null;
|
|
10
|
+
}
|
|
11
|
+
/** Response of `chains.list()`. */
|
|
12
|
+
interface ChainsResponse {
|
|
13
|
+
/** Every chain Pegaroute can route to or from. */
|
|
14
|
+
chains: Chain[];
|
|
15
|
+
}
|
|
16
|
+
/** A token Pegaroute recognises on a chain. Decimals are not included: use the swap's `TokenAmount` values instead. */
|
|
17
|
+
interface Token {
|
|
18
|
+
/** Token ID to use in quote and swap requests, e.g. `"SOL"` or `"USDC-0xA0b8…"`. */
|
|
19
|
+
id: string;
|
|
20
|
+
/** Display symbol, e.g. `"USDC"`. */
|
|
21
|
+
symbol: string;
|
|
22
|
+
}
|
|
23
|
+
/** Response of `tokens.list(chain)`. */
|
|
24
|
+
interface TokensResponse {
|
|
25
|
+
/** Canonical ID of the requested chain (the lookup ignores case). */
|
|
26
|
+
chain: string;
|
|
27
|
+
/** Tokens Pegaroute recognises on that chain. */
|
|
28
|
+
tokens: Token[];
|
|
29
|
+
}
|
|
30
|
+
/** Provider integration types Pegaroute is known to use. */
|
|
31
|
+
type KnownProviderType = "cross-chain-amm" | "cross-chain-aggregator" | "dex-aggregator" | "api-provider";
|
|
32
|
+
/** Any provider integration type, including ones added after this SDK version. */
|
|
33
|
+
type ProviderType = KnownProviderType | (string & {});
|
|
34
|
+
/**
|
|
35
|
+
* A provider's documented affiliate (referrer) fee range.
|
|
36
|
+
* Each value is given both in basis points and as a percent.
|
|
37
|
+
*/
|
|
38
|
+
interface ProviderAffiliateFeeStructure {
|
|
39
|
+
/** Minimum fee in basis points, when the provider documents one. */
|
|
40
|
+
minBps?: number;
|
|
41
|
+
/** Minimum fee as a percent, when the provider documents one. */
|
|
42
|
+
minPercent?: number;
|
|
43
|
+
/** Minimum non-zero fee in basis points; zero (no fee) stays valid. */
|
|
44
|
+
minBpsWhenSet?: number;
|
|
45
|
+
/** Minimum non-zero fee as a percent; zero (no fee) stays valid. */
|
|
46
|
+
minPercentWhenSet?: number;
|
|
47
|
+
/** Maximum fee in basis points. */
|
|
48
|
+
maxBps: number;
|
|
49
|
+
/** Maximum fee as a percent. */
|
|
50
|
+
maxPercent: number;
|
|
51
|
+
/** Fee the provider applies when none is requested, in basis points. */
|
|
52
|
+
defaultBps?: number;
|
|
53
|
+
/** Fee the provider applies when none is requested, as a percent. */
|
|
54
|
+
defaultPercent?: number;
|
|
55
|
+
}
|
|
56
|
+
/** The provider's cut of the affiliate fee (a share of the fee, not of the swap amount). */
|
|
57
|
+
interface ProviderTakeStructure {
|
|
58
|
+
/** Provider's cut in basis points of the affiliate fee. */
|
|
59
|
+
bpsOfAffiliateFee: number;
|
|
60
|
+
/** Provider's cut as a percent of the affiliate fee. */
|
|
61
|
+
percentOfAffiliateFee: number;
|
|
62
|
+
}
|
|
63
|
+
/** A provider's documented affiliate fee range and its cut of that fee. */
|
|
64
|
+
interface ProviderFeeStructure {
|
|
65
|
+
/** The affiliate fee range the provider accepts. */
|
|
66
|
+
affiliateFee: ProviderAffiliateFeeStructure;
|
|
67
|
+
/** Provider's cut of the affiliate fee, or `null` when it takes none. */
|
|
68
|
+
providerTake: ProviderTakeStructure | null;
|
|
69
|
+
}
|
|
70
|
+
/** A provider's live status, as returned by `health()`. */
|
|
71
|
+
interface ProviderHealth {
|
|
72
|
+
/** Provider name, e.g. `"thorchain"`. */
|
|
73
|
+
name: string;
|
|
74
|
+
/** Provider integration type. */
|
|
75
|
+
type: ProviderType;
|
|
76
|
+
/** Whether the provider's last health check succeeded. */
|
|
77
|
+
available: boolean;
|
|
78
|
+
/** Whether the provider is switched on for new quotes. */
|
|
79
|
+
routingEnabled: boolean;
|
|
80
|
+
/** Pegaroute's circuit breaker for this provider: `open` means requests to it are currently paused. */
|
|
81
|
+
circuitState: "closed" | "open" | "half-open";
|
|
82
|
+
/** Latency of the last health check, in milliseconds. */
|
|
83
|
+
latencyMs: number;
|
|
84
|
+
/** Chains the provider has halted. */
|
|
85
|
+
haltedChains: string[];
|
|
86
|
+
/** When the provider was last checked (ISO 8601). */
|
|
87
|
+
lastChecked: string;
|
|
88
|
+
/** Pegaroute's maximum affiliate fee for this provider in basis points, or `null` when none is configured. */
|
|
89
|
+
maxAffiliateBps: number | null;
|
|
90
|
+
/** The provider's documented fee range, or `null` when unknown. */
|
|
91
|
+
feeStructure: ProviderFeeStructure | null;
|
|
92
|
+
}
|
|
93
|
+
/** A provider, as returned by `providers.list()`. */
|
|
94
|
+
interface ProviderInfo extends ProviderHealth {
|
|
95
|
+
/**
|
|
96
|
+
* Chain IDs the provider can route in principle. A quote is still the source of truth for current availability.
|
|
97
|
+
*/
|
|
98
|
+
supportedChains: string[];
|
|
99
|
+
/** Only returned to Pegaroute operators; always `null` for API keys. */
|
|
100
|
+
configuredReferral: null;
|
|
101
|
+
}
|
|
102
|
+
/** Options for `providers.list()`. */
|
|
103
|
+
interface ListProvidersParams {
|
|
104
|
+
/** Also return providers that are switched off (`routingEnabled: false`). Default `false`. */
|
|
105
|
+
includeDisabled?: boolean;
|
|
106
|
+
}
|
|
107
|
+
/** Response of `providers.list()`. */
|
|
108
|
+
interface ProvidersResponse {
|
|
109
|
+
/**
|
|
110
|
+
* The providers that are switched on, with their live status. Providers that are switched off
|
|
111
|
+
* (`routingEnabled: false`) are also listed when you call `providers.list({ includeDisabled: true })`.
|
|
112
|
+
*/
|
|
113
|
+
providers: ProviderInfo[];
|
|
114
|
+
}
|
|
115
|
+
/** Response of `health()`. */
|
|
116
|
+
interface HealthResponse {
|
|
117
|
+
/** `degraded` when the database is down or an enabled provider is unavailable. */
|
|
118
|
+
status: "ok" | "degraded";
|
|
119
|
+
/** Server time (ISO 8601). */
|
|
120
|
+
timestamp: string;
|
|
121
|
+
/** Database connectivity. Reports `connected: false` when Pegaroute runs without a database. */
|
|
122
|
+
db: {
|
|
123
|
+
/** Whether the database answered. */
|
|
124
|
+
connected: boolean;
|
|
125
|
+
/** Latency of the database check, in milliseconds. */
|
|
126
|
+
latencyMs: number;
|
|
127
|
+
};
|
|
128
|
+
/** Write-ahead log backlog. `pendingEntries` is `-1` when it can't be read. */
|
|
129
|
+
wal: {
|
|
130
|
+
/** Writes buffered while the database was unavailable and not yet replayed, or `-1` when unknown. */
|
|
131
|
+
pendingEntries: number;
|
|
132
|
+
};
|
|
133
|
+
/** Status of every provider, including disabled ones. */
|
|
134
|
+
providers: ProviderHealth[];
|
|
135
|
+
}
|
|
136
|
+
/** Response of `ping()`. */
|
|
137
|
+
interface PingResponse {
|
|
138
|
+
/** Always `"pong"`. */
|
|
139
|
+
response: "pong";
|
|
140
|
+
/** Server time (ISO 8601). */
|
|
141
|
+
timestamp: string;
|
|
142
|
+
/** Service name, `"pegaroute"`. */
|
|
143
|
+
service: string;
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/types/common.d.ts
|
|
147
|
+
/** Providers Pegaroute is known to route through. Other names may appear as providers are added. */
|
|
148
|
+
type KnownProvider = "thorchain" | "maya" | "openocean" | "instaswap" | "squid";
|
|
149
|
+
/** Any provider name, including ones added after this SDK version. */
|
|
150
|
+
type Provider = KnownProvider | (string & {});
|
|
151
|
+
/**
|
|
152
|
+
* Confidential execution mode for a swap.
|
|
153
|
+
*
|
|
154
|
+
* - `false` (or omitted): public execution.
|
|
155
|
+
* - `true`: confidential execution, falling back to zkproof.
|
|
156
|
+
* - `"zk"`: zkproof execution only.
|
|
157
|
+
*
|
|
158
|
+
* Other strings are reserved for provider modes added in the future.
|
|
159
|
+
*/
|
|
160
|
+
type PrivateSwapMode = boolean | "zk" | (string & {});
|
|
161
|
+
/**
|
|
162
|
+
* An exact on-chain amount, in two forms.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* { display: "1000", baseUnits: "1000000000" } // 1000 USDC (6 decimals)
|
|
166
|
+
*/
|
|
167
|
+
interface TokenAmount {
|
|
168
|
+
/** Human-readable rendering of `baseUnits` for UI. Never rebuild `baseUnits` from it. */
|
|
169
|
+
display: string;
|
|
170
|
+
/** Exact integer in the token's smallest unit. Pass it unchanged to transfers, approvals and allowance checks. */
|
|
171
|
+
baseUnits: string;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Fees for a route, as human-readable decimal strings.
|
|
175
|
+
*
|
|
176
|
+
* Amounts are in destination-asset units (THORChain/Maya), or in USD when `unit` is `"USD"` (Instaswap/Squid).
|
|
177
|
+
* Read `total` for the full fee the user pays.
|
|
178
|
+
*/
|
|
179
|
+
interface QuoteFees {
|
|
180
|
+
/** Pegaroute's affiliate fee. For Instaswap and Squid this excludes the integrator's share (see `subAffiliate`). */
|
|
181
|
+
affiliate: string;
|
|
182
|
+
/** Liquidity and other route fees. On Squid this includes Squid's own platform share. */
|
|
183
|
+
liquidity: string;
|
|
184
|
+
/** Outbound gas fee on the destination chain (`"0"` when not applicable). */
|
|
185
|
+
outbound: string;
|
|
186
|
+
/** Sum of `affiliate`, `liquidity`, `outbound` and `subAffiliate` (when present). */
|
|
187
|
+
total: string;
|
|
188
|
+
/** Present when all fee amounts are in USD instead of asset units. */
|
|
189
|
+
unit?: "USD";
|
|
190
|
+
/** The integrator's USD share, excluded from `affiliate` (Instaswap/Squid only). */
|
|
191
|
+
subAffiliate?: string;
|
|
192
|
+
/** Total provider-facing fee in basis points, when the provider reports it. */
|
|
193
|
+
totalBps?: number;
|
|
194
|
+
/** Slippage in basis points, when the provider reports it. */
|
|
195
|
+
slippageBps?: number;
|
|
196
|
+
}
|
|
197
|
+
/** How the affiliate fee on a swap was split between Pegaroute and the integrator, in basis points. */
|
|
198
|
+
interface AffiliateFeeBreakdown {
|
|
199
|
+
/** Pegaroute's configured share, before the provider cap is applied. */
|
|
200
|
+
configuredPegasusShareBps: number;
|
|
201
|
+
/** The integrator's configured share, before the provider cap is applied. */
|
|
202
|
+
configuredIntegratorFeeBps: number;
|
|
203
|
+
/** The provider's maximum affiliate/referrer fee. */
|
|
204
|
+
providerAffiliateCapBps: number;
|
|
205
|
+
/** The affiliate fee actually sent to the provider, after the cap. */
|
|
206
|
+
effectiveAffiliateFeeBps: number;
|
|
207
|
+
/** Pegaroute's share after the cap. */
|
|
208
|
+
realizedPegasusFeeBps: number;
|
|
209
|
+
/** The integrator's share after the cap. */
|
|
210
|
+
realizedIntegratorFeeBps: number;
|
|
211
|
+
/** Which provider fee config was used for this route. */
|
|
212
|
+
feeSource: string;
|
|
213
|
+
/** Pegaroute's real net revenue, after any provider revenue share. */
|
|
214
|
+
pegasusNetBps?: number;
|
|
215
|
+
/** Pegaroute's net revenue in USD, when the provider reports it (Instaswap). */
|
|
216
|
+
pegasusNetUsd?: string;
|
|
217
|
+
}
|
|
218
|
+
/** The OpenOcean meta-aggregator (Jupiter, Titan, Cetus, …) behind a Solana or Sui route. */
|
|
219
|
+
interface OpenOceanRouteMeta {
|
|
220
|
+
/** Index of the winning aggregator, e.g. Solana `10` = Titan, `6` = Jupiter. */
|
|
221
|
+
dexId?: number;
|
|
222
|
+
/** Name of the winning aggregator, e.g. `"Titan"`. */
|
|
223
|
+
dexCode?: string;
|
|
224
|
+
/** Every aggregator OpenOcean considered for the quote. */
|
|
225
|
+
dexes?: Array<{
|
|
226
|
+
/** Index of the aggregator. */
|
|
227
|
+
dexId?: number;
|
|
228
|
+
/** Name of the aggregator. */
|
|
229
|
+
dexCode?: string;
|
|
230
|
+
}>;
|
|
231
|
+
}
|
|
232
|
+
/** The route a swap was executed on. Returned by `swaps.create`, `swaps.get` and `transactions.list`. */
|
|
233
|
+
interface RouteInfo {
|
|
234
|
+
/** The provider executing the swap. */
|
|
235
|
+
provider: Provider;
|
|
236
|
+
/** Route chosen inside the provider (e.g. `"Chainflip"`), when the provider exposes one. */
|
|
237
|
+
subprovider?: string;
|
|
238
|
+
/** Confidential execution mode of the swap. */
|
|
239
|
+
private?: PrivateSwapMode;
|
|
240
|
+
/** Expected output amount in the destination token, as a human-readable decimal. */
|
|
241
|
+
expectedOutput: string;
|
|
242
|
+
/** Fees for this route. */
|
|
243
|
+
fees: QuoteFees;
|
|
244
|
+
/** Estimated time to complete, in seconds. */
|
|
245
|
+
estimatedTimeSeconds: number;
|
|
246
|
+
/** OpenOcean aggregator behind the route (Solana/Sui only). */
|
|
247
|
+
openOceanRoute?: OpenOceanRouteMeta;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* A refund observed for a failed swap.
|
|
251
|
+
*
|
|
252
|
+
* `status` here is the refund's own lifecycle, separate from the swap's status: a swap can already be
|
|
253
|
+
* `refunded` (internal) / `fail` (external) while the refund is still `pending` or `broadcasting`.
|
|
254
|
+
*/
|
|
255
|
+
interface RefundInfo {
|
|
256
|
+
/** Refund lifecycle state. */
|
|
257
|
+
status: "pending" | "broadcasting" | "completed";
|
|
258
|
+
/** Refund transaction hash, once known. */
|
|
259
|
+
txHash?: string;
|
|
260
|
+
/** Chain the refund is sent on. */
|
|
261
|
+
chain: string;
|
|
262
|
+
/** Amount refunded, as a human-readable decimal. */
|
|
263
|
+
amount: string;
|
|
264
|
+
/** The original source amount of the swap. */
|
|
265
|
+
originalAmount: string;
|
|
266
|
+
/** Amount deducted from the refund (e.g. network fees). */
|
|
267
|
+
feeDeducted: string;
|
|
268
|
+
/** What the deducted amount was for. */
|
|
269
|
+
feeDescription: string;
|
|
270
|
+
/** Address the refund was actually sent to. May differ from the refund address requested on the swap. */
|
|
271
|
+
refundAddress: string;
|
|
272
|
+
/** When the refund completed (ISO 8601), once known. */
|
|
273
|
+
completedAt?: string;
|
|
274
|
+
}
|
|
275
|
+
/** Progress of a streaming swap, which executes as several smaller sub-swaps. */
|
|
276
|
+
interface StreamingProgress {
|
|
277
|
+
/** Sub-swaps finished so far. */
|
|
278
|
+
completedSubSwaps: number;
|
|
279
|
+
/** Total sub-swaps planned. */
|
|
280
|
+
totalSubSwaps: number;
|
|
281
|
+
/** When the last sub-swap happened (ISO 8601). */
|
|
282
|
+
lastSubSwapTimestamp?: string;
|
|
283
|
+
/** Output received so far, as a human-readable decimal. */
|
|
284
|
+
partialOutput?: string;
|
|
285
|
+
/** Amount refunded so far, when some sub-swaps could not execute. */
|
|
286
|
+
partialRefund?: {
|
|
287
|
+
/** Amount refunded, in the same format as `partialOutput`. */
|
|
288
|
+
amount: string;
|
|
289
|
+
/** Chain the refund was sent on. */
|
|
290
|
+
chain: string;
|
|
291
|
+
/** Token refunded. */
|
|
292
|
+
token: string;
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region src/types/errors.d.ts
|
|
297
|
+
/** Error codes Pegaroute is known to return. Other strings may appear as the API evolves. */
|
|
298
|
+
type KnownErrorCode = "VALIDATION_ERROR" | "UNAUTHORIZED" | "NOT_FOUND" | "UNSUPPORTED_PAIR" | "AMOUNT_TOO_LOW" | "INVALID_ADDRESS" | "INVALID_AMOUNT" | "QUOTE_MISMATCH" | "QUOTE_EXPIRED" | "PROVIDER_REJECTED" | "PROVIDER_CHANGED" | "PROVIDER_UNAVAILABLE" | "PROVIDER_TIMEOUT" | "MEMO_TOO_LONG" | "SLIPPAGE_EXCEEDED" | "RATE_LIMITED" | "CHAIN_HALTED" | "CHAIN_DISABLED" | "MISSING_QUOTE_DATA" | "BROADCAST_FAILED" | "INTERNAL_ERROR" | "CONNECTION_ERROR" | "TIMEOUT" | "INVALID_RESPONSE" | "WAIT_TIMEOUT" | "UNKNOWN_ERROR";
|
|
299
|
+
/** Any error code, including unknown ones returned by the API as it evolves. */
|
|
300
|
+
type ErrorCode = KnownErrorCode | (string & {});
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src/types/quotes.d.ts
|
|
303
|
+
/**
|
|
304
|
+
* What to quote. Chain and token IDs come from `chains.list()` and `tokens.list(chain)`; case is ignored.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* { fromChain: "ETH", fromToken: "ETH", toChain: "BTC", toToken: "BTC", amount: "0.5" }
|
|
308
|
+
*/
|
|
309
|
+
interface GetQuoteParams {
|
|
310
|
+
/** Source chain ID, e.g. `"ETH"`. */
|
|
311
|
+
fromChain: string;
|
|
312
|
+
/** Source token ID, e.g. `"ETH"` or `"USDC-0xA0b8…"`. */
|
|
313
|
+
fromToken: string;
|
|
314
|
+
/** Destination chain ID, e.g. `"BTC"`. */
|
|
315
|
+
toChain: string;
|
|
316
|
+
/** Destination token ID, e.g. `"BTC"`. */
|
|
317
|
+
toToken: string;
|
|
318
|
+
/** Amount of the source token, as a human-readable decimal, e.g. `"0.5"`. */
|
|
319
|
+
amount: string;
|
|
320
|
+
/** Confidential execution mode. Routes from providers that don't support it are left out. */
|
|
321
|
+
private?: PrivateSwapMode;
|
|
322
|
+
/** Real recipient address, for providers that need one to quote. A placeholder is used when omitted. */
|
|
323
|
+
destinationAddress?: string;
|
|
324
|
+
/** Address sending the funds. Required when `refundAddress` is set; the quote is bound to it. */
|
|
325
|
+
senderAddress?: string;
|
|
326
|
+
/**
|
|
327
|
+
* Where refunds should go, if not the sender. Providers that can't refund to a different address
|
|
328
|
+
* are left out of `routes` and listed in `warnings`.
|
|
329
|
+
*/
|
|
330
|
+
refundAddress?: string;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* One way to execute the swap, from one provider.
|
|
334
|
+
*
|
|
335
|
+
* `memo`, `inboundAddress`, `router` and `gasRate` are a preview only. `swaps.create` rebuilds them (the memo gets
|
|
336
|
+
* the real destination address, the vault address is refreshed), so sign with the `execution` it returns,
|
|
337
|
+
* e.g. `execution.memo`, never with these fields.
|
|
338
|
+
*/
|
|
339
|
+
interface QuoteRoute {
|
|
340
|
+
/** Provider offering this route. Pass it as `routeProvider` to `swaps.create` to choose this route. */
|
|
341
|
+
provider: Provider;
|
|
342
|
+
/** Route chosen inside the provider (e.g. `"Chainflip"`), when the provider exposes one. */
|
|
343
|
+
subprovider?: string;
|
|
344
|
+
/** Confidential execution mode of this route. */
|
|
345
|
+
private?: PrivateSwapMode;
|
|
346
|
+
/** The provider's integration type. */
|
|
347
|
+
providerType: ProviderType;
|
|
348
|
+
/** Expected output in the destination token, as a human-readable decimal, after fees. */
|
|
349
|
+
expectedOutput: string;
|
|
350
|
+
/** Estimated time to complete, in seconds. */
|
|
351
|
+
estimatedTimeSeconds: number;
|
|
352
|
+
/** Fees for this route. */
|
|
353
|
+
fees: QuoteFees;
|
|
354
|
+
/** The provider's own quote expiry (ISO 8601 or Unix seconds), if it has one. Use the quote's `expiresAt` instead. */
|
|
355
|
+
expiry: string | null;
|
|
356
|
+
/** Transaction memo (THORChain/Maya), if any. */
|
|
357
|
+
memo: string | null;
|
|
358
|
+
/** Vault address funds are sent to, if any. */
|
|
359
|
+
inboundAddress: string | null;
|
|
360
|
+
/** Router contract address (EVM), when the provider exposes one. */
|
|
361
|
+
router: string | null;
|
|
362
|
+
/** Recommended fee rate for UTXO transactions, if any. */
|
|
363
|
+
gasRate: string | null;
|
|
364
|
+
/** Minimum swap amount in the source token, as a human-readable decimal, if the provider has one. */
|
|
365
|
+
minAmount: string | null;
|
|
366
|
+
/** The fee applied to this route after provider caps. */
|
|
367
|
+
resolvedFee: {
|
|
368
|
+
/** Effective fee in basis points. */
|
|
369
|
+
feeBps: number;
|
|
370
|
+
};
|
|
371
|
+
/** OpenOcean aggregator behind the route (Solana/Sui only). */
|
|
372
|
+
openOceanRoute?: OpenOceanRouteMeta;
|
|
373
|
+
}
|
|
374
|
+
/** Why a provider didn't return a route. */
|
|
375
|
+
interface RouteWarning {
|
|
376
|
+
/** The provider that failed. Rarely empty, e.g. when no provider is enabled. */
|
|
377
|
+
provider: string;
|
|
378
|
+
/** Same codes as API errors, e.g. `PROVIDER_TIMEOUT` or `UNSUPPORTED_PAIR`. */
|
|
379
|
+
code: ErrorCode;
|
|
380
|
+
/** Technical message for logs. */
|
|
381
|
+
message: string;
|
|
382
|
+
/** Message that is safe to show to end users. */
|
|
383
|
+
userMessage: string;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Response of `quotes.get()`.
|
|
387
|
+
*
|
|
388
|
+
* A 200 response can have no routes: check `warnings` to see why each provider was left out.
|
|
389
|
+
*/
|
|
390
|
+
interface QuoteResponse {
|
|
391
|
+
/** Pass to `swaps.create` to execute on these terms. */
|
|
392
|
+
quoteId: string;
|
|
393
|
+
/** When the quote expires (ISO 8601). After that, `swaps.create` throws `QuoteExpiredError`. */
|
|
394
|
+
expiresAt: string;
|
|
395
|
+
/** Available routes, best first: highest output, then fastest, then lowest slippage. */
|
|
396
|
+
routes: QuoteRoute[];
|
|
397
|
+
/** One entry per provider that was tried but didn't return a route. */
|
|
398
|
+
warnings: RouteWarning[];
|
|
399
|
+
}
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region src/types/execution.d.ts
|
|
402
|
+
/** An ERC-20 approval that must be sent before an EVM `contract-call`. */
|
|
403
|
+
interface EvmApproval {
|
|
404
|
+
/** Address to approve (router or spender contract). */
|
|
405
|
+
spender: string;
|
|
406
|
+
/** ERC-20 token contract address. */
|
|
407
|
+
tokenAddress: string;
|
|
408
|
+
/** Exact amount to approve. */
|
|
409
|
+
amount: TokenAmount;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Sign and send an EVM transaction.
|
|
413
|
+
*
|
|
414
|
+
* - `contract-call`: send `to` / `data` / `value`, after the `approval` if there is one.
|
|
415
|
+
* - `native-transfer`: send `value` of the native gas token to `to`.
|
|
416
|
+
* - `erc20-transfer`: send `transferAmount` of the source token to `to`.
|
|
417
|
+
*/
|
|
418
|
+
interface EvmSwapExecution {
|
|
419
|
+
/** Execution family: an EVM chain. */
|
|
420
|
+
family: "evm";
|
|
421
|
+
/** How to send it: call a contract, send the native gas token, or send an ERC-20 token. */
|
|
422
|
+
mode: "contract-call" | "native-transfer" | "erc20-transfer";
|
|
423
|
+
/** When present, sign `message` with EIP-191 `personal_sign` first and submit the signature with the tx hash. */
|
|
424
|
+
signature?: {
|
|
425
|
+
method: "personal_sign";
|
|
426
|
+
message: string;
|
|
427
|
+
};
|
|
428
|
+
/** EVM chain ID the transaction must be sent on. */
|
|
429
|
+
chainId: number;
|
|
430
|
+
/** Recipient: a contract for `contract-call`, otherwise the deposit address. */
|
|
431
|
+
to: string;
|
|
432
|
+
/** Calldata for `contract-call`; `null` otherwise. */
|
|
433
|
+
data: string | null;
|
|
434
|
+
/** Native gas token amount to send with the transaction, if any. */
|
|
435
|
+
value: TokenAmount | null;
|
|
436
|
+
/** Suggested gas limit, if the provider supplies one. */
|
|
437
|
+
gasLimit: string | null;
|
|
438
|
+
/** Opaque memo or deposit instructions, if any. */
|
|
439
|
+
memo: string | null;
|
|
440
|
+
/** ERC-20 approval required before a `contract-call`; `null` otherwise. */
|
|
441
|
+
approval: EvmApproval | null;
|
|
442
|
+
/** Exact ERC-20 amount for `erc20-transfer`; `null` otherwise. */
|
|
443
|
+
transferAmount: TokenAmount | null;
|
|
444
|
+
}
|
|
445
|
+
/** Send `amount` to `to` with `memo` as an OP_RETURN output. Used for BTC, LTC, BCH, DOGE, DASH and ZEC. */
|
|
446
|
+
interface UtxoSwapExecution {
|
|
447
|
+
/** Execution family: a Bitcoin-like chain. */
|
|
448
|
+
family: "utxo";
|
|
449
|
+
/** Send a payment with an OP_RETURN memo. */
|
|
450
|
+
mode: "payment-with-memo";
|
|
451
|
+
/** Deposit address. */
|
|
452
|
+
to: string;
|
|
453
|
+
/** Exact amount to send. */
|
|
454
|
+
amount: TokenAmount;
|
|
455
|
+
/** Memo to include as OP_RETURN, if any. */
|
|
456
|
+
memo: string | null;
|
|
457
|
+
/** Advisory fee-rate hint (THORChain/Maya). The wallet chooses the actual fee. */
|
|
458
|
+
gasRate: string | null;
|
|
459
|
+
}
|
|
460
|
+
/** Send a standard Cosmos `MsgSend` to the provider's inbound address. */
|
|
461
|
+
interface CosmosBankSendSwapExecution {
|
|
462
|
+
/** Execution family: a Cosmos chain. */
|
|
463
|
+
family: "cosmos";
|
|
464
|
+
/** Send a `MsgSend`. */
|
|
465
|
+
mode: "bank-send";
|
|
466
|
+
/** Inbound address. */
|
|
467
|
+
to: string;
|
|
468
|
+
/** Exact amount to send. */
|
|
469
|
+
amount: TokenAmount;
|
|
470
|
+
/** Transaction memo, if any. */
|
|
471
|
+
memo: string | null;
|
|
472
|
+
}
|
|
473
|
+
/** Send a native `MsgDeposit` on THORChain or Maya. */
|
|
474
|
+
interface CosmosMsgDepositSwapExecution {
|
|
475
|
+
/** Execution family: THORChain and Maya are Cosmos chains. */
|
|
476
|
+
family: "cosmos";
|
|
477
|
+
/** Send a `MsgDeposit`. */
|
|
478
|
+
mode: "msg-deposit";
|
|
479
|
+
/** Inbound address. */
|
|
480
|
+
to: string;
|
|
481
|
+
/** Protocol asset for the deposit coin, e.g. `"THOR.RUNE"`. */
|
|
482
|
+
asset: string;
|
|
483
|
+
/** Decimals to write into the deposit coin. */
|
|
484
|
+
assetDecimals: number;
|
|
485
|
+
/** Exact amount to deposit. */
|
|
486
|
+
amount: TokenAmount;
|
|
487
|
+
/** Transaction memo, if any. */
|
|
488
|
+
memo: string | null;
|
|
489
|
+
}
|
|
490
|
+
/** Sign and broadcast a provider-built Cosmos message (IBC transfer or CosmWasm execute) unchanged. */
|
|
491
|
+
interface CosmosMsgExecuteSwapExecution {
|
|
492
|
+
/** Execution family: a Cosmos chain. */
|
|
493
|
+
family: "cosmos";
|
|
494
|
+
/** Broadcast `messageJson` unchanged. */
|
|
495
|
+
mode: "msg-execute";
|
|
496
|
+
/** JSON-encoded `{ typeUrl, value }` message. Pass it through as-is; never rebuild it. */
|
|
497
|
+
messageJson: string;
|
|
498
|
+
/** Transaction memo, if any. */
|
|
499
|
+
memo: string | null;
|
|
500
|
+
/** Advisory gas price, e.g. `"0.025uosmo"`. The wallet chooses the actual fee. */
|
|
501
|
+
gasPrice: string | null;
|
|
502
|
+
/** Advisory gas simulation multiplier, if the provider supplies one. */
|
|
503
|
+
gasMultiplier: number | null;
|
|
504
|
+
}
|
|
505
|
+
/** Sign a fully built transaction: Solana base64, Sui transaction, Bitcoin hex PSBT or Stellar XDR. */
|
|
506
|
+
interface SerializedSwapExecution {
|
|
507
|
+
/** Execution family: says how `serializedTransaction` is encoded. */
|
|
508
|
+
family: "solana" | "sui" | "utxo" | "stellar";
|
|
509
|
+
/** Sign `serializedTransaction`. */
|
|
510
|
+
mode: "serialized-tx";
|
|
511
|
+
/** The encoded transaction to sign. */
|
|
512
|
+
serializedTransaction: string;
|
|
513
|
+
/** Minimum swap output encoded in the transaction (not the input amount), if known. */
|
|
514
|
+
minOut: TokenAmount | null;
|
|
515
|
+
}
|
|
516
|
+
/** Sign a JSON-described XRPL or Stellar payment. */
|
|
517
|
+
interface JsonSwapExecution {
|
|
518
|
+
/** Execution family: XRPL or Stellar. */
|
|
519
|
+
family: "xrp" | "stellar";
|
|
520
|
+
/** Sign the payment in `transactionJson`. */
|
|
521
|
+
mode: "transaction-json";
|
|
522
|
+
/** Destination address. */
|
|
523
|
+
to: string;
|
|
524
|
+
/** JSON-encoded payment fields. Keep every memo field. */
|
|
525
|
+
transactionJson: string;
|
|
526
|
+
}
|
|
527
|
+
/** Send `amount` to a deposit address on a chain with its own execution family. */
|
|
528
|
+
interface NamedDepositSwapExecution {
|
|
529
|
+
/** Execution family of the chain to deposit on. */
|
|
530
|
+
family: "solana" | "sui" | "xrp" | "tron" | "near" | "hypercore" | "cardano";
|
|
531
|
+
/** Send `amount` to the deposit address `to`. */
|
|
532
|
+
mode: "deposit-transfer";
|
|
533
|
+
/** Deposit address. */
|
|
534
|
+
to: string;
|
|
535
|
+
/** Exact amount to send. */
|
|
536
|
+
amount: TokenAmount;
|
|
537
|
+
/** Memo to attach, if any. */
|
|
538
|
+
memo: string | null;
|
|
539
|
+
}
|
|
540
|
+
/** Send `amount` to a deposit address on a chain without a dedicated execution family (see `chain`). */
|
|
541
|
+
interface OtherDepositSwapExecution {
|
|
542
|
+
/** No dedicated execution family: `chain` says which chain. */
|
|
543
|
+
family: "other";
|
|
544
|
+
/** Send `amount` to the deposit address `to`. */
|
|
545
|
+
mode: "deposit-transfer";
|
|
546
|
+
/** Pegaroute chain ID, e.g. `"APTOS"`. */
|
|
547
|
+
chain: string;
|
|
548
|
+
/** Deposit address. */
|
|
549
|
+
to: string;
|
|
550
|
+
/** Exact amount to send. */
|
|
551
|
+
amount: TokenAmount;
|
|
552
|
+
/** Memo to attach, if any. */
|
|
553
|
+
memo: string | null;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* What the user's wallet must sign to fund a swap. Switch on `family` and `mode`, never on the provider name.
|
|
557
|
+
*
|
|
558
|
+
* @example
|
|
559
|
+
* if (isExecutionFamily(execution, "evm")) {
|
|
560
|
+
* // execution is EvmSwapExecution
|
|
561
|
+
* } else if (isExecutionFamily(execution, "utxo")) {
|
|
562
|
+
* // execution.mode is "payment-with-memo" | "serialized-tx"
|
|
563
|
+
* }
|
|
564
|
+
*/
|
|
565
|
+
type SwapExecution = EvmSwapExecution | UtxoSwapExecution | CosmosBankSendSwapExecution | CosmosMsgDepositSwapExecution | CosmosMsgExecuteSwapExecution | SerializedSwapExecution | JsonSwapExecution | NamedDepositSwapExecution | OtherDepositSwapExecution;
|
|
566
|
+
/** Every execution family, e.g. `"evm"` or `"utxo"`. */
|
|
567
|
+
type ExecutionFamily = SwapExecution["family"];
|
|
568
|
+
/**
|
|
569
|
+
* The execution variants of one family, with `family` narrowed to it.
|
|
570
|
+
*
|
|
571
|
+
* `Extract` can't be used here: variants shared by several families (e.g. `SerializedSwapExecution`)
|
|
572
|
+
* would be dropped. The intersection keeps them and removes variants of other families.
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ExecutionOfFamily<"utxo"> // UtxoSwapExecution | (SerializedSwapExecution & { family: "utxo" })
|
|
576
|
+
*/
|
|
577
|
+
type ExecutionOfFamily<F extends ExecutionFamily> = SwapExecution & {
|
|
578
|
+
family: F;
|
|
579
|
+
};
|
|
580
|
+
/** Every execution mode, e.g. `"contract-call"` or `"deposit-transfer"`. */
|
|
581
|
+
type ExecutionMode = SwapExecution["mode"];
|
|
582
|
+
/**
|
|
583
|
+
* The execution variants of one mode, across all families, with `mode` narrowed to it.
|
|
584
|
+
*
|
|
585
|
+
* Uses an intersection for the same reason as {@link ExecutionOfFamily}: `EvmSwapExecution` covers three modes.
|
|
586
|
+
*
|
|
587
|
+
* @example
|
|
588
|
+
* ExecutionOfMode<"deposit-transfer"> // NamedDepositSwapExecution | OtherDepositSwapExecution
|
|
589
|
+
*/
|
|
590
|
+
type ExecutionOfMode<M extends ExecutionMode> = SwapExecution & {
|
|
591
|
+
mode: M;
|
|
592
|
+
};
|
|
593
|
+
/**
|
|
594
|
+
* Narrows an execution to the variants of one mode, whatever the family.
|
|
595
|
+
* Within a single family, a `switch` on `mode` is usually clearer.
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* if (isExecutionMode(execution, "deposit-transfer")) {
|
|
599
|
+
* showDepositAddress(execution.to, execution.amount.display, execution.memo); // any chain
|
|
600
|
+
* }
|
|
601
|
+
*/
|
|
602
|
+
declare function isExecutionMode<M extends ExecutionMode>(execution: SwapExecution, mode: M): execution is ExecutionOfMode<M>;
|
|
603
|
+
/**
|
|
604
|
+
* Narrows an execution to the variants of one family.
|
|
605
|
+
*
|
|
606
|
+
* @example
|
|
607
|
+
* if (isExecutionFamily(execution, "evm")) {
|
|
608
|
+
* // execution.mode is "contract-call" | "native-transfer" | "erc20-transfer"
|
|
609
|
+
* }
|
|
610
|
+
*/
|
|
611
|
+
declare function isExecutionFamily<F extends ExecutionFamily>(execution: SwapExecution, family: F): execution is ExecutionOfFamily<F>;
|
|
612
|
+
//#endregion
|
|
613
|
+
//#region src/types/status.d.ts
|
|
614
|
+
/**
|
|
615
|
+
* The public swap status. Use this one for business logic.
|
|
616
|
+
*
|
|
617
|
+
* Returned as `status` by `swaps.get`, `transactions.list` and webhooks.
|
|
618
|
+
*/
|
|
619
|
+
type SwapStatus = "pending" | "executing" | "success" | "fail";
|
|
620
|
+
/**
|
|
621
|
+
* Pegaroute's detailed internal status, meant for debugging. Steps can be skipped (e.g. `pending` → `completed`).
|
|
622
|
+
*
|
|
623
|
+
* Returned as `internalStatus` by `swaps.get`, `transactions.list` and webhooks, as `status` by
|
|
624
|
+
* `swaps.submitTxHash` (`"submitted"`) and in `swaps.events`. The `transactions.list({ status })` filter takes these values.
|
|
625
|
+
*/
|
|
626
|
+
type InternalSwapStatus = "pending" | "submitted" | "executing" | "confirming" | "completed" | "failed" | "refunded";
|
|
627
|
+
/**
|
|
628
|
+
* Converts an internal status to the public one.
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* toExternalStatus("submitted"); // "executing"
|
|
632
|
+
* toExternalStatus("refunded"); // "fail" — check the swap's `refund` for details
|
|
633
|
+
*/
|
|
634
|
+
declare function toExternalStatus(status: InternalSwapStatus): SwapStatus;
|
|
635
|
+
/**
|
|
636
|
+
* Whether a swap in this status is finished and will not change status again. Accepts either status set.
|
|
637
|
+
*
|
|
638
|
+
* A `refunded` swap's `refund` object may still progress (e.g. `pending` → `completed`) after this returns `true`.
|
|
639
|
+
*/
|
|
640
|
+
declare function isTerminalStatus(status: SwapStatus | InternalSwapStatus): boolean;
|
|
641
|
+
//#endregion
|
|
642
|
+
//#region src/types/swaps.d.ts
|
|
643
|
+
/**
|
|
644
|
+
* What to swap. Pass the `quoteId` and chosen route's `provider` from `quotes.get()` to execute on the quoted terms.
|
|
645
|
+
* Without a `quoteId`, Pegaroute quotes again and picks the best route itself.
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
* {
|
|
649
|
+
* fromChain: "ETH", fromToken: "ETH", toChain: "BTC", toToken: "BTC", amount: "0.5",
|
|
650
|
+
* senderAddress: "0xabc…", destinationAddress: "bc1q…",
|
|
651
|
+
* quoteId: quote.quoteId, routeProvider: quote.routes[0].provider,
|
|
652
|
+
* }
|
|
653
|
+
*/
|
|
654
|
+
interface CreateSwapParams {
|
|
655
|
+
/** Source chain ID, e.g. `"ETH"`. Must match the quote. */
|
|
656
|
+
fromChain: string;
|
|
657
|
+
/** Source token ID, e.g. `"ETH"`. Must match the quote. */
|
|
658
|
+
fromToken: string;
|
|
659
|
+
/** Destination chain ID, e.g. `"BTC"`. Must match the quote. */
|
|
660
|
+
toChain: string;
|
|
661
|
+
/** Destination token ID, e.g. `"BTC"`. Must match the quote. */
|
|
662
|
+
toToken: string;
|
|
663
|
+
/** Amount of the source token, as a human-readable decimal, e.g. `"0.5"`. Must match the quote. */
|
|
664
|
+
amount: string;
|
|
665
|
+
/** Address that receives the swapped funds. */
|
|
666
|
+
destinationAddress: string;
|
|
667
|
+
/** Address sending the funds. Must match the quote's `senderAddress`, if it had one. */
|
|
668
|
+
senderAddress: string;
|
|
669
|
+
/** Where refunds should go, if not the sender. Must match the quote's `refundAddress`, if it had one. */
|
|
670
|
+
refundAddress?: string;
|
|
671
|
+
/** Maximum slippage as a fraction between 0 and 1, e.g. `0.01` for 1%. Uses the provider's default when omitted. */
|
|
672
|
+
slippageTolerance?: number;
|
|
673
|
+
/** Execute as a streaming swap (several smaller sub-swaps), where the provider supports it. */
|
|
674
|
+
streaming?: boolean;
|
|
675
|
+
/** The `quoteId` from `quotes.get()`. Throws `QuoteExpiredError` if it expired and no route is still valid. */
|
|
676
|
+
quoteId?: string;
|
|
677
|
+
/** The chosen route's `provider` from the quote. Without it, the best route is used. */
|
|
678
|
+
routeProvider?: Provider;
|
|
679
|
+
/** Confidential execution mode. Must match the quote. */
|
|
680
|
+
private?: PrivateSwapMode;
|
|
681
|
+
}
|
|
682
|
+
/** The provider executing a swap, with its own reference for the swap. */
|
|
683
|
+
interface SwapProviderInfo {
|
|
684
|
+
/** Provider name, e.g. `"thorchain"`. */
|
|
685
|
+
name: Provider;
|
|
686
|
+
/** The provider's own ID for the swap (e.g. an Instaswap txid or Squid quote ID), if it has one. */
|
|
687
|
+
referenceId: string | null;
|
|
688
|
+
/** Extra provider metadata for UI and debugging (e.g. OpenOcean route, warnings). Never needed to sign. */
|
|
689
|
+
details: Record<string, unknown> | null;
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Response of `swaps.create()`.
|
|
693
|
+
*
|
|
694
|
+
* Send `execution` to the frontend for signing, then report the tx hash with `swaps.submitTxHash()`.
|
|
695
|
+
*/
|
|
696
|
+
interface CreateSwapResponse {
|
|
697
|
+
/** Swap ID. Use it with `swaps.get`, `swaps.events` and `swaps.submitTxHash`. */
|
|
698
|
+
transactionId: string;
|
|
699
|
+
/** External status of the new swap. `"pending"` today. */
|
|
700
|
+
status: SwapStatus;
|
|
701
|
+
/** The integration type of the selected provider. */
|
|
702
|
+
providerType: ProviderType;
|
|
703
|
+
/** The route the swap will execute on. */
|
|
704
|
+
route: RouteInfo;
|
|
705
|
+
/** What the user must sign. Switch on `family` and `mode`, never on the provider name. */
|
|
706
|
+
execution: SwapExecution;
|
|
707
|
+
/** The provider executing the swap. */
|
|
708
|
+
provider: SwapProviderInfo;
|
|
709
|
+
}
|
|
710
|
+
/** The provider's own status for a swap, when it reports one. */
|
|
711
|
+
interface ProviderStatusInfo {
|
|
712
|
+
/** The provider's native status value. */
|
|
713
|
+
status: string;
|
|
714
|
+
/** Whether the user must act (e.g. top up a deposit) before the swap can continue. */
|
|
715
|
+
actionRequired: boolean;
|
|
716
|
+
/** Short explanation of the status. */
|
|
717
|
+
message: string;
|
|
718
|
+
/** Provider or chain explorer link, when available. */
|
|
719
|
+
explorerUrl?: string;
|
|
720
|
+
}
|
|
721
|
+
/** One fee line in an Instaswap deposit quote. */
|
|
722
|
+
interface InstaswapFeeLine {
|
|
723
|
+
/** Fee kind as Instaswap names it, e.g. `"subAffiliate"`. */
|
|
724
|
+
type?: string;
|
|
725
|
+
/** Display label for the fee. */
|
|
726
|
+
name?: string;
|
|
727
|
+
/** Fee in USD. A JavaScript number as Pegaroute sends it: for display only, may be imprecise. */
|
|
728
|
+
amountUsd?: number;
|
|
729
|
+
/** Asset the fee is charged in. */
|
|
730
|
+
asset?: string;
|
|
731
|
+
/** Fee in `asset`. A JavaScript number as Pegaroute sends it: for display only, may be imprecise. */
|
|
732
|
+
amount?: number;
|
|
733
|
+
}
|
|
734
|
+
/** Instaswap's deposit details for a swap, kept so a deposit UI can be shown again after a reload. */
|
|
735
|
+
interface InstaswapSwapLiteSnapshot {
|
|
736
|
+
/** Instaswap's swap ID. */
|
|
737
|
+
txid: string;
|
|
738
|
+
/** Estimated output amount. */
|
|
739
|
+
estimatedOut?: number;
|
|
740
|
+
/** Estimated output value in USD. */
|
|
741
|
+
estimatedOutUsd?: number;
|
|
742
|
+
/** Amount to deposit. For display only: sign with the amounts in `execution`. */
|
|
743
|
+
depositAmount?: number;
|
|
744
|
+
/** Exact amount to deposit, as a human-readable decimal. For display only: sign with the amounts in `execution`. */
|
|
745
|
+
depositAmountExact?: string;
|
|
746
|
+
/** Deposit value in USD. */
|
|
747
|
+
depositAmountUsd?: number;
|
|
748
|
+
/** Fee lines. */
|
|
749
|
+
feeBreakdown?: InstaswapFeeLine[];
|
|
750
|
+
/** Estimated time to complete, in seconds. */
|
|
751
|
+
etaSeconds?: number;
|
|
752
|
+
/** Address to deposit to. */
|
|
753
|
+
depositAddress: string;
|
|
754
|
+
/** Symbol of the token to deposit, e.g. `"BTC"`. */
|
|
755
|
+
depositTokenSymbol?: string;
|
|
756
|
+
/** When the deposit window closes (ISO 8601), if it does. */
|
|
757
|
+
expiresAt?: string | null;
|
|
758
|
+
/** Deposit instructions to show the user. */
|
|
759
|
+
instructions?: string;
|
|
760
|
+
}
|
|
761
|
+
/** The source side of a swap. */
|
|
762
|
+
interface SwapInput {
|
|
763
|
+
/** Source chain ID. */
|
|
764
|
+
chain: string;
|
|
765
|
+
/** Source token ID. */
|
|
766
|
+
token: string;
|
|
767
|
+
/** Amount sent, as a human-readable decimal. */
|
|
768
|
+
amount: string;
|
|
769
|
+
/** Address sending the funds. */
|
|
770
|
+
address?: string;
|
|
771
|
+
/** Where refunds go. Falls back to `address` for older swaps. */
|
|
772
|
+
refundAddress?: string;
|
|
773
|
+
/** Source transaction hash, once reported with `swaps.submitTxHash()` or detected. */
|
|
774
|
+
txHash?: string;
|
|
775
|
+
/** The provider's own ID for the swap, if it has one. */
|
|
776
|
+
providerReferenceId?: string;
|
|
777
|
+
/** The provider's latest status for the swap, when it reports one. */
|
|
778
|
+
providerStatus?: ProviderStatusInfo;
|
|
779
|
+
/** Instaswap deposit details (Instaswap swaps only). */
|
|
780
|
+
instaswapSwapLite?: InstaswapSwapLiteSnapshot;
|
|
781
|
+
}
|
|
782
|
+
/** The destination side of a swap. */
|
|
783
|
+
interface SwapOutput {
|
|
784
|
+
/** Destination chain ID. */
|
|
785
|
+
chain: string;
|
|
786
|
+
/** Destination token ID. */
|
|
787
|
+
token: string;
|
|
788
|
+
/** Address receiving the funds. */
|
|
789
|
+
address: string;
|
|
790
|
+
/** Amount received, as a human-readable decimal, once known. */
|
|
791
|
+
amount?: string;
|
|
792
|
+
/** Destination transaction hash, once known. */
|
|
793
|
+
txHash?: string;
|
|
794
|
+
}
|
|
795
|
+
/** When a swap reached each stage (ISO 8601). Stages can be skipped. */
|
|
796
|
+
interface SwapTimestamps {
|
|
797
|
+
/** When the swap was created. */
|
|
798
|
+
created: string;
|
|
799
|
+
/** When the source tx hash was reported. */
|
|
800
|
+
submitted?: string;
|
|
801
|
+
/** When the source transaction was confirmed. */
|
|
802
|
+
confirmed?: string;
|
|
803
|
+
/** When the swap finished, whatever the outcome. */
|
|
804
|
+
completed?: string;
|
|
805
|
+
}
|
|
806
|
+
/** Why a swap failed. */
|
|
807
|
+
interface SwapFailure {
|
|
808
|
+
/** Same codes as API errors, e.g. `SLIPPAGE_EXCEEDED`. */
|
|
809
|
+
code: ErrorCode;
|
|
810
|
+
/** Technical message for logs. */
|
|
811
|
+
message: string;
|
|
812
|
+
/** Message that is safe to show to end users. */
|
|
813
|
+
userMessage: string;
|
|
814
|
+
/** Provider that caused the failure, when it is provider-specific. */
|
|
815
|
+
provider?: string;
|
|
816
|
+
}
|
|
817
|
+
/** Response of `swaps.get()`: the swap's current state. */
|
|
818
|
+
interface GetSwapResponse {
|
|
819
|
+
/** Swap ID. */
|
|
820
|
+
transactionId: string;
|
|
821
|
+
/** External status. Use this one for business logic. */
|
|
822
|
+
status: SwapStatus;
|
|
823
|
+
/** Internal status, for debugging. */
|
|
824
|
+
internalStatus: InternalSwapStatus;
|
|
825
|
+
/** The route the swap executes on. */
|
|
826
|
+
route: RouteInfo;
|
|
827
|
+
/** The source side of the swap. */
|
|
828
|
+
input: SwapInput;
|
|
829
|
+
/** The destination side of the swap. */
|
|
830
|
+
output: SwapOutput;
|
|
831
|
+
/** Fees for the swap. */
|
|
832
|
+
fees: QuoteFees;
|
|
833
|
+
/** How the affiliate fee was split, when recorded. */
|
|
834
|
+
affiliateFeeBreakdown?: AffiliateFeeBreakdown;
|
|
835
|
+
/** When the swap reached each stage. */
|
|
836
|
+
timestamps: SwapTimestamps;
|
|
837
|
+
/** Why the swap failed, or `null`. */
|
|
838
|
+
error: SwapFailure | null;
|
|
839
|
+
/** The refund for a failed swap, or `null`. */
|
|
840
|
+
refund: RefundInfo | null;
|
|
841
|
+
/** Progress of a streaming swap, or `null` for a regular swap. */
|
|
842
|
+
streamingProgress: StreamingProgress | null;
|
|
843
|
+
/** What the user must sign, when it can be rebuilt (e.g. an Instaswap deposit). Same shape as `swaps.create()`. */
|
|
844
|
+
execution?: SwapExecution;
|
|
845
|
+
/** The provider executing the swap. Present together with `execution`. */
|
|
846
|
+
provider?: SwapProviderInfo;
|
|
847
|
+
}
|
|
848
|
+
/** One entry in a swap's audit log. */
|
|
849
|
+
interface SwapEvent {
|
|
850
|
+
/** Event ID. */
|
|
851
|
+
id: string;
|
|
852
|
+
/** Internal status before the event; `"none"` for the swap's creation. */
|
|
853
|
+
fromStatus: InternalSwapStatus | "none";
|
|
854
|
+
/** Internal status after the event. Equal to `fromStatus` for audit entries that don't change status. */
|
|
855
|
+
toStatus: InternalSwapStatus;
|
|
856
|
+
/** When the event happened (ISO 8601). */
|
|
857
|
+
timestamp: string;
|
|
858
|
+
/** Extra context recorded with the event, e.g. `{ txHash }`, or `null`. */
|
|
859
|
+
metadata: Record<string, unknown> | null;
|
|
860
|
+
}
|
|
861
|
+
/** Response of `swaps.events()`. */
|
|
862
|
+
interface SwapEventsResponse {
|
|
863
|
+
/** Swap ID. */
|
|
864
|
+
transactionId: string;
|
|
865
|
+
/** Events, oldest first. */
|
|
866
|
+
events: SwapEvent[];
|
|
867
|
+
}
|
|
868
|
+
/** The source transaction to report for a swap. */
|
|
869
|
+
interface SubmitTxHashParams {
|
|
870
|
+
/** Hash of the signed and broadcast source transaction. */
|
|
871
|
+
txHash: string;
|
|
872
|
+
/**
|
|
873
|
+
* The EIP-191 `personal_sign` signature (`0x` + 130 hex chars), required when the swap's
|
|
874
|
+
* `execution.signature` asked for one. Leave it out otherwise.
|
|
875
|
+
*/
|
|
876
|
+
signature?: string;
|
|
877
|
+
}
|
|
878
|
+
/** Response of `swaps.submitTxHash()`. */
|
|
879
|
+
interface SubmitTxHashResponse {
|
|
880
|
+
/** Swap ID. */
|
|
881
|
+
transactionId: string;
|
|
882
|
+
/** Internal status after reporting the hash. `"submitted"` today (external `"executing"`). */
|
|
883
|
+
status: InternalSwapStatus;
|
|
884
|
+
/** The reported hash. */
|
|
885
|
+
txHash: string;
|
|
886
|
+
}
|
|
887
|
+
//#endregion
|
|
888
|
+
//#region src/types/transactions.d.ts
|
|
889
|
+
/**
|
|
890
|
+
* Filters for `transactions.list()`. All are optional.
|
|
891
|
+
*
|
|
892
|
+
* @example
|
|
893
|
+
* { status: "failed", provider: "thorchain", startTime: "2026-09-01T00:00:00Z", count: 100 }
|
|
894
|
+
*/
|
|
895
|
+
interface ListTransactionsParams {
|
|
896
|
+
/** Only swaps in this **internal** status, e.g. `"failed"` (not the external `"fail"`). */
|
|
897
|
+
status?: InternalSwapStatus;
|
|
898
|
+
/** Only swaps executed by this provider; case is ignored. */
|
|
899
|
+
provider?: Provider;
|
|
900
|
+
/** Only swaps created at or after this time (ISO 8601). */
|
|
901
|
+
startTime?: string;
|
|
902
|
+
/** Only swaps created at or before this time (ISO 8601). */
|
|
903
|
+
endTime?: string;
|
|
904
|
+
/** Page size, from 1 to 200. Default 50. */
|
|
905
|
+
count?: number;
|
|
906
|
+
/** Start after this cursor (a previous page's `pagination.nextCursor`). Not needed when iterating with `for await`. */
|
|
907
|
+
cursor?: string;
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* A swap as listed by `transactions.list()`: the same data as `swaps.get()` under different field names,
|
|
911
|
+
* plus Pegaroute's affiliate-fee verification data.
|
|
912
|
+
*/
|
|
913
|
+
interface Transaction {
|
|
914
|
+
/** Swap ID (`transactionId` elsewhere). */
|
|
915
|
+
id: string;
|
|
916
|
+
/** The integration the swap belongs to (the one your API key is scoped to). */
|
|
917
|
+
integrationId: string;
|
|
918
|
+
/** External status. Use this one for business logic. */
|
|
919
|
+
status: SwapStatus;
|
|
920
|
+
/** Internal status, for debugging. */
|
|
921
|
+
internalStatus: InternalSwapStatus;
|
|
922
|
+
/** The source side of the swap (`input` in `swaps.get()`). */
|
|
923
|
+
source: SwapInput;
|
|
924
|
+
/** The destination side of the swap (`output` in `swaps.get()`). */
|
|
925
|
+
destination: SwapOutput;
|
|
926
|
+
/** The route the swap executes on. */
|
|
927
|
+
route: RouteInfo;
|
|
928
|
+
/** Fees for the swap. */
|
|
929
|
+
fees: QuoteFees;
|
|
930
|
+
/** How the affiliate fee was split, when recorded. */
|
|
931
|
+
affiliateFeeBreakdown?: AffiliateFeeBreakdown;
|
|
932
|
+
/** Why the swap failed, if it did. */
|
|
933
|
+
error?: SwapFailure;
|
|
934
|
+
/** The refund for a failed swap, if there is one. */
|
|
935
|
+
refund?: RefundInfo;
|
|
936
|
+
/** When the swap reached each stage. */
|
|
937
|
+
timestamps: SwapTimestamps;
|
|
938
|
+
/** The exact THORChain/Maya memo built for the swap, when the route uses one. */
|
|
939
|
+
expectedMemo?: string;
|
|
940
|
+
/** Affiliates parsed from `expectedMemo`; empty when there is none. */
|
|
941
|
+
expectedAffiliateEntries: ExpectedAffiliateEntry[];
|
|
942
|
+
/** Referrer address the provider is expected to credit (e.g. OpenOcean), when set. */
|
|
943
|
+
expectedReferrerAddress?: string;
|
|
944
|
+
/** ID of the affiliate configuration used for the swap (THORChain/Maya only). */
|
|
945
|
+
selectedProviderAffiliateCompositionId?: string;
|
|
946
|
+
/** When the on-chain memo was last checked against `expectedMemo` (ISO 8601). */
|
|
947
|
+
memoVerifiedAt?: string;
|
|
948
|
+
}
|
|
949
|
+
/** One affiliate in a swap's memo, as Pegaroute expects the provider to pay it. */
|
|
950
|
+
interface ExpectedAffiliateEntry {
|
|
951
|
+
/** Position in the memo's affiliate list, starting at 0. */
|
|
952
|
+
position: number;
|
|
953
|
+
/** Affiliate name as written in the memo. */
|
|
954
|
+
name: string;
|
|
955
|
+
/** Fee in basis points, or `null` when unknown. */
|
|
956
|
+
bps: number | null;
|
|
957
|
+
/** Whether `bps` was written in the memo (`"explicit"`) or is the affiliate name's default (`"name_default"`). */
|
|
958
|
+
bpsSource: "explicit" | "name_default";
|
|
959
|
+
/** Pegaroute's ID for the affiliate, when it is one of the configured ones. */
|
|
960
|
+
affiliateId?: string;
|
|
961
|
+
/** Whose affiliate it is: Pegaroute's (`"operator"`) or the integrator's (`"client"`). */
|
|
962
|
+
scope?: "operator" | "client";
|
|
963
|
+
}
|
|
964
|
+
/** Where a page sits in a cursor-paginated list. */
|
|
965
|
+
interface CursorPagination {
|
|
966
|
+
/** Pass as `cursor` to get the next page; `null` on the last page. */
|
|
967
|
+
nextCursor: string | null;
|
|
968
|
+
/** Whether more pages follow. */
|
|
969
|
+
hasMore: boolean;
|
|
970
|
+
}
|
|
971
|
+
/** One page of `transactions.list()`, newest swaps first. */
|
|
972
|
+
interface TransactionsResponse {
|
|
973
|
+
/** The swaps on this page. */
|
|
974
|
+
transactions: Transaction[];
|
|
975
|
+
/** Whether more pages follow, and the cursor to fetch the next one. */
|
|
976
|
+
pagination: CursorPagination;
|
|
977
|
+
}
|
|
978
|
+
//#endregion
|
|
979
|
+
//#region src/types/webhooks.d.ts
|
|
980
|
+
/**
|
|
981
|
+
* Events Pegaroute sends when a swap changes. Every one carries the same {@link TransactionWebhookData}.
|
|
982
|
+
*
|
|
983
|
+
* - `transaction.status_changed`: any other status change (e.g. `pending` → `submitted`).
|
|
984
|
+
* - `transaction.completed`: the swap succeeded.
|
|
985
|
+
* - `transaction.partially_completed`: a streaming swap completed with part of the amount refunded.
|
|
986
|
+
* - `transaction.failed`: the swap failed.
|
|
987
|
+
* - `transaction.refunded`: the swap failed and its funds were refunded.
|
|
988
|
+
* - `transaction.refund_initiated`: a refund started; the swap's status may not be terminal yet.
|
|
989
|
+
*/
|
|
990
|
+
type TransactionWebhookEventType = "transaction.status_changed" | "transaction.completed" | "transaction.partially_completed" | "transaction.failed" | "transaction.refunded" | "transaction.refund_initiated";
|
|
991
|
+
/** Streaming progress as webhooks send it: the usual progress plus which sub-swap failed. */
|
|
992
|
+
interface WebhookStreamingProgress extends StreamingProgress {
|
|
993
|
+
/**
|
|
994
|
+
* Which sub-swap failed, for failed, refunded or partially refunded streaming swaps:
|
|
995
|
+
* `"first"` (nothing executed, full refund) or `"subsequent"` (partial output plus partial refund).
|
|
996
|
+
* `null` when nothing failed.
|
|
997
|
+
*/
|
|
998
|
+
failureContext: "first" | "subsequent" | null;
|
|
999
|
+
}
|
|
1000
|
+
/** The swap carried by every `transaction.*` webhook: its state after the change, plus the status it changed from. */
|
|
1001
|
+
interface TransactionWebhookData {
|
|
1002
|
+
/** Swap ID. */
|
|
1003
|
+
transactionId: string;
|
|
1004
|
+
/** External status after the change. Use this one for business logic. */
|
|
1005
|
+
status: SwapStatus;
|
|
1006
|
+
/** Internal status after the change, for debugging. */
|
|
1007
|
+
internalStatus: InternalSwapStatus;
|
|
1008
|
+
/** External status before the change. */
|
|
1009
|
+
previousStatus: SwapStatus;
|
|
1010
|
+
/** Internal status before the change, for debugging. */
|
|
1011
|
+
internalPreviousStatus: InternalSwapStatus;
|
|
1012
|
+
/** The route the swap executes on (fewer fields than `swaps.get()`). */
|
|
1013
|
+
route: Pick<RouteInfo, "provider" | "subprovider" | "private">;
|
|
1014
|
+
/** The source side of the swap (fewer fields than `swaps.get()`). */
|
|
1015
|
+
input: Pick<SwapInput, "chain" | "token" | "amount" | "address" | "refundAddress" | "txHash">;
|
|
1016
|
+
/** The destination side of the swap. */
|
|
1017
|
+
output: SwapOutput;
|
|
1018
|
+
/** Fees for the swap. */
|
|
1019
|
+
fees: QuoteFees;
|
|
1020
|
+
/** When the swap reached each stage. */
|
|
1021
|
+
timestamps: SwapTimestamps;
|
|
1022
|
+
/** Why the swap failed, or `null`. */
|
|
1023
|
+
error: SwapFailure | null;
|
|
1024
|
+
/** The refund for a failed swap, or `null`. */
|
|
1025
|
+
refund: RefundInfo | null;
|
|
1026
|
+
/** Progress of a streaming swap, or `null` for a regular swap. */
|
|
1027
|
+
streamingProgress: WebhookStreamingProgress | null;
|
|
1028
|
+
}
|
|
1029
|
+
/** A webhook about a swap. Narrow on `event` to react to a specific change. */
|
|
1030
|
+
interface TransactionWebhookEvent {
|
|
1031
|
+
/** What happened. */
|
|
1032
|
+
event: TransactionWebhookEventType;
|
|
1033
|
+
/** When Pegaroute created the event (ISO 8601). Retries resend the same value. */
|
|
1034
|
+
timestamp: string;
|
|
1035
|
+
/** The swap after the change. */
|
|
1036
|
+
data: TransactionWebhookData;
|
|
1037
|
+
}
|
|
1038
|
+
/** A test webhook, sent from the Pegaroute UI to check your endpoint. */
|
|
1039
|
+
interface TestWebhookEvent {
|
|
1040
|
+
/** What happened. */
|
|
1041
|
+
event: "webhook.test";
|
|
1042
|
+
/** When Pegaroute created the event (ISO 8601). */
|
|
1043
|
+
timestamp: string;
|
|
1044
|
+
/** Who sent the test, and for which integration. */
|
|
1045
|
+
data: {
|
|
1046
|
+
/** Your integration's ID. */
|
|
1047
|
+
integrationId: string;
|
|
1048
|
+
/** Always `"Pegaroute test webhook"` today. */
|
|
1049
|
+
message: string;
|
|
1050
|
+
/** Who sent the test: the operator's email, or `"operator_pat"`. */
|
|
1051
|
+
generatedBy: string;
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Any webhook Pegaroute sends, as returned by `verifyWebhook`. Narrow on `event`.
|
|
1056
|
+
*
|
|
1057
|
+
* Delivery is at-least-once: the same event can arrive more than once, so make handlers idempotent.
|
|
1058
|
+
*
|
|
1059
|
+
* @example
|
|
1060
|
+
* switch (event.event) {
|
|
1061
|
+
* case "transaction.completed":
|
|
1062
|
+
* markPaid(event.data.transactionId);
|
|
1063
|
+
* break;
|
|
1064
|
+
* case "webhook.test":
|
|
1065
|
+
* break;
|
|
1066
|
+
* }
|
|
1067
|
+
*/
|
|
1068
|
+
type WebhookEvent = TransactionWebhookEvent | TestWebhookEvent;
|
|
1069
|
+
//#endregion
|
|
1070
|
+
export { KnownErrorCode as $, toExternalStatus as A, JsonSwapExecution as B, SwapInput as C, Token as Ct, InternalSwapStatus as D, SwapTimestamps as E, EvmSwapExecution as F, UtxoSwapExecution as G, OtherDepositSwapExecution as H, ExecutionFamily as I, GetQuoteParams as J, isExecutionFamily as K, ExecutionMode as L, CosmosMsgDepositSwapExecution as M, CosmosMsgExecuteSwapExecution as N, SwapStatus as O, EvmApproval as P, ErrorCode as Q, ExecutionOfFamily as R, SwapFailure as S, ProvidersResponse as St, SwapProviderInfo as T, SerializedSwapExecution as U, NamedDepositSwapExecution as V, SwapExecution as W, QuoteRoute as X, QuoteResponse as Y, RouteWarning as Z, ProviderStatusInfo as _, ProviderFeeStructure as _t, WebhookEvent as a, QuoteFees as at, SwapEvent as b, ProviderTakeStructure as bt, ExpectedAffiliateEntry as c, StreamingProgress as ct, TransactionsResponse as d, ChainsResponse as dt, AffiliateFeeBreakdown as et, CreateSwapParams as f, HealthResponse as ft, InstaswapSwapLiteSnapshot as g, ProviderAffiliateFeeStructure as gt, InstaswapFeeLine as h, PingResponse as ht, TransactionWebhookEventType as i, Provider as it, CosmosBankSendSwapExecution as j, isTerminalStatus as k, ListTransactionsParams as l, TokenAmount as lt, GetSwapResponse as m, ListProvidersParams as mt, TransactionWebhookData as n, OpenOceanRouteMeta as nt, WebhookStreamingProgress as o, RefundInfo as ot, CreateSwapResponse as p, KnownProviderType as pt, isExecutionMode as q, TransactionWebhookEvent as r, PrivateSwapMode as rt, CursorPagination as s, RouteInfo as st, TestWebhookEvent as t, KnownProvider as tt, Transaction as u, Chain as ut, SubmitTxHashParams as v, ProviderHealth as vt, SwapOutput as w, TokensResponse as wt, SwapEventsResponse as x, ProviderType as xt, SubmitTxHashResponse as y, ProviderInfo as yt, ExecutionOfMode as z };
|