@swapkit/helpers 1.0.0-rc.100 → 1.0.0-rc.102
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/dist/index.js +381 -4
- package/dist/index.js.map +9 -8
- package/package.json +8 -6
- package/src/helpers/web3wallets.ts +25 -2
- package/src/modules/requestClient.ts +3 -4
- package/src/modules/swapKitError.ts +5 -0
- package/src/types/index.ts +1 -0
- package/src/types/quotes.ts +391 -0
- package/src/types/sdk.ts +86 -4
- package/src/types/wallet.ts +31 -0
package/package.json
CHANGED
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
3
|
"description": "SwapKit - Helpers",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"ky": "1.2.3"
|
|
5
|
+
"ky": "1.2.3",
|
|
6
|
+
"zod": "3.23.8"
|
|
6
7
|
},
|
|
7
8
|
"devDependencies": {
|
|
8
|
-
"@swapkit/tokens": "1.0.0-rc.
|
|
9
|
-
"bun-types": "1.1.
|
|
9
|
+
"@swapkit/tokens": "1.0.0-rc.52",
|
|
10
|
+
"bun-types": "1.1.8",
|
|
10
11
|
"ethers": "6.11.1"
|
|
11
12
|
},
|
|
12
13
|
"peerDependencies": {
|
|
13
|
-
"@swapkit/tokens": "1.0.0-rc.
|
|
14
|
-
"ky": "1.2.3"
|
|
14
|
+
"@swapkit/tokens": "1.0.0-rc.52",
|
|
15
|
+
"ky": "1.2.3",
|
|
16
|
+
"zod": "3.23.8"
|
|
15
17
|
},
|
|
16
18
|
"files": [
|
|
17
19
|
"src/",
|
|
@@ -36,5 +38,5 @@
|
|
|
36
38
|
},
|
|
37
39
|
"type": "module",
|
|
38
40
|
"types": "./src/index.ts",
|
|
39
|
-
"version": "1.0.0-rc.
|
|
41
|
+
"version": "1.0.0-rc.102"
|
|
40
42
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { BrowserProvider } from "ethers";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ChainId,
|
|
4
|
+
type EIP6963AnnounceProviderEvent,
|
|
5
|
+
type EIP6963Provider,
|
|
6
|
+
WalletOption,
|
|
7
|
+
} from "../types";
|
|
3
8
|
|
|
4
9
|
export type EthereumWindowProvider = BrowserProvider & {
|
|
5
10
|
__XDEFI?: boolean;
|
|
@@ -142,7 +147,7 @@ export const isDetected = (walletOption: WalletOption) => {
|
|
|
142
147
|
return listWeb3EVMWallets().includes(walletOption);
|
|
143
148
|
};
|
|
144
149
|
|
|
145
|
-
const listWeb3EVMWallets = () => {
|
|
150
|
+
export const listWeb3EVMWallets = () => {
|
|
146
151
|
const metamaskEnabled = window?.ethereum && !window.ethereum?.isBraveWallet;
|
|
147
152
|
// @ts-ignore that should be implemented in xdefi and hooked up via swapkit core
|
|
148
153
|
const xdefiEnabled = window?.xfi || window?.ethereum?.__XDEFI;
|
|
@@ -164,6 +169,24 @@ const listWeb3EVMWallets = () => {
|
|
|
164
169
|
return wallets;
|
|
165
170
|
};
|
|
166
171
|
|
|
172
|
+
export function getEIP6963Wallets() {
|
|
173
|
+
const providers: EIP6963Provider[] = [];
|
|
174
|
+
|
|
175
|
+
function onAnnouncement(event: EIP6963AnnounceProviderEvent) {
|
|
176
|
+
if (providers.map((p) => p.info.uuid).includes(event.detail.info.uuid)) return;
|
|
177
|
+
providers.push(event.detail);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
window.addEventListener("eip6963:announceProvider", onAnnouncement);
|
|
181
|
+
window.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
182
|
+
|
|
183
|
+
function removeEIP6963EventListener() {
|
|
184
|
+
window.removeEventListener("eip6963:announceProvider", onAnnouncement);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return { providers, removeEIP6963EventListener };
|
|
188
|
+
}
|
|
189
|
+
|
|
167
190
|
export const okxMobileEnabled = () => {
|
|
168
191
|
const ua = navigator.userAgent;
|
|
169
192
|
const isIOS = /iphone|ipad|ipod|ios/i.test(ua);
|
|
@@ -21,10 +21,9 @@ function getKyClient() {
|
|
|
21
21
|
return kyClient;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const getTypedBaseRequestClient = (
|
|
25
|
-
get: <T>(url: string | URL | Request, options?: Options) =>
|
|
26
|
-
post: <T>(url: string | URL | Request, options?: Options) =>
|
|
27
|
-
kyClient.post(url, options).json<T>(),
|
|
24
|
+
const getTypedBaseRequestClient = (ky: KyInstance) => ({
|
|
25
|
+
get: <T>(url: string | URL | Request, options?: Options) => ky.get(url, options).json<T>(),
|
|
26
|
+
post: <T>(url: string | URL | Request, options?: Options) => ky.post(url, options).json<T>(),
|
|
28
27
|
});
|
|
29
28
|
|
|
30
29
|
export const RequestClient = {
|
package/src/types/index.ts
CHANGED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export enum WarningCodeEnum {
|
|
4
|
+
highSlippage = "highSlippage",
|
|
5
|
+
highPriceImpact = "highPriceImpact",
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const EVMTransactionDetailsParamsSchema = z.array(
|
|
9
|
+
z.union([
|
|
10
|
+
z.string(),
|
|
11
|
+
z.number(),
|
|
12
|
+
z.array(z.string()),
|
|
13
|
+
z
|
|
14
|
+
.object({
|
|
15
|
+
from: z.string(),
|
|
16
|
+
value: z.string(),
|
|
17
|
+
})
|
|
18
|
+
.describe("Parameters to pass to the contract method"),
|
|
19
|
+
]),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export type EVMTransactionDetailsParams = z.infer<typeof EVMTransactionDetailsParamsSchema>;
|
|
23
|
+
|
|
24
|
+
export const EVMTransactionDetailsSchema = z.object({
|
|
25
|
+
contractAddress: z.string({
|
|
26
|
+
description: "Address of the contract to interact with",
|
|
27
|
+
}),
|
|
28
|
+
contractMethod: z.string({
|
|
29
|
+
description: "Name of the method to call",
|
|
30
|
+
}),
|
|
31
|
+
contractParams: EVMTransactionDetailsParamsSchema,
|
|
32
|
+
// contractParamsStreaming: z.array(
|
|
33
|
+
// z.string({
|
|
34
|
+
// description:
|
|
35
|
+
// "If making a streaming swap through THORChain, parameters to pass to the contract method",
|
|
36
|
+
// }),
|
|
37
|
+
// ),
|
|
38
|
+
contractParamNames: z.array(
|
|
39
|
+
z.string({
|
|
40
|
+
description: "Names of the parameters to pass to the contract method",
|
|
41
|
+
}),
|
|
42
|
+
),
|
|
43
|
+
approvalToken: z.optional(
|
|
44
|
+
z.string({
|
|
45
|
+
description: "Address of the token to approve spending of",
|
|
46
|
+
}),
|
|
47
|
+
),
|
|
48
|
+
approvalSpender: z.optional(
|
|
49
|
+
z.string({
|
|
50
|
+
description: "Address of the spender to approve",
|
|
51
|
+
}),
|
|
52
|
+
),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export type EVMTransactionDetails = z.infer<typeof EVMTransactionDetailsSchema>;
|
|
56
|
+
|
|
57
|
+
export const EstimatedTimeSchema = z.object({
|
|
58
|
+
inbound: z.optional(
|
|
59
|
+
z.number({
|
|
60
|
+
description: "Time to receive inbound asset in seconds",
|
|
61
|
+
}),
|
|
62
|
+
),
|
|
63
|
+
swap: z.optional(
|
|
64
|
+
z.number({
|
|
65
|
+
description: "Time to swap assets in seconds",
|
|
66
|
+
}),
|
|
67
|
+
),
|
|
68
|
+
outbound: z.optional(
|
|
69
|
+
z.number({
|
|
70
|
+
description: "Time to receive outbound asset in seconds",
|
|
71
|
+
}),
|
|
72
|
+
),
|
|
73
|
+
total: z.number({
|
|
74
|
+
description: "Total time in seconds",
|
|
75
|
+
}),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export type EstimatedTime = z.infer<typeof EstimatedTimeSchema>;
|
|
79
|
+
|
|
80
|
+
export enum ProviderName {
|
|
81
|
+
CHAINFLIP = "CHAINFLIP",
|
|
82
|
+
TRADERJOE_V1 = "TRADERJOE_V1",
|
|
83
|
+
PANGOLIN_V1 = "PANGOLIN_V1",
|
|
84
|
+
UNISWAP_V2 = "UNISWAP_V2",
|
|
85
|
+
THORCHAIN = "THORCHAIN",
|
|
86
|
+
THORCHAIN_STREAMING = "THORCHAIN_STREAMING",
|
|
87
|
+
MAYACHAIN = "MAYACHAIN",
|
|
88
|
+
ONEINCH = "ONEINCH",
|
|
89
|
+
SUSHISWAP_V2 = "SUSHISWAP_V2",
|
|
90
|
+
WOOFI_V2 = "WOOFI_V2",
|
|
91
|
+
PANCAKESWAP = "PANCAKESWAP",
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export enum FeeTypeEnum {
|
|
95
|
+
LIQUIDITY = "liquidity",
|
|
96
|
+
NETWORK = "network",
|
|
97
|
+
INBOUND = "inbound",
|
|
98
|
+
OUTBOUND = "outbound",
|
|
99
|
+
AFFILIATE = "affiliate",
|
|
100
|
+
TAX = "tax",
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const FeesSchema = z.array(
|
|
104
|
+
z.object({
|
|
105
|
+
type: z.nativeEnum(FeeTypeEnum),
|
|
106
|
+
amount: z.string(),
|
|
107
|
+
asset: z.string(),
|
|
108
|
+
chain: z.string(),
|
|
109
|
+
protocol: z.nativeEnum(ProviderName),
|
|
110
|
+
}),
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
export type Fees = z.infer<typeof FeesSchema>;
|
|
114
|
+
|
|
115
|
+
export const RouteLegSchema = z.object({
|
|
116
|
+
sellAsset: z.string({
|
|
117
|
+
description: "Asset to sell",
|
|
118
|
+
}),
|
|
119
|
+
buyAsset: z.string({
|
|
120
|
+
description: "Asset to buy",
|
|
121
|
+
}),
|
|
122
|
+
provider: z.nativeEnum(ProviderName),
|
|
123
|
+
sourceAddress: z.string({
|
|
124
|
+
description: "Source address",
|
|
125
|
+
}),
|
|
126
|
+
destinationAddress: z.string({
|
|
127
|
+
description: "Destination address",
|
|
128
|
+
}),
|
|
129
|
+
estimatedTime: EstimatedTimeSchema.optional(),
|
|
130
|
+
affiliate: z
|
|
131
|
+
.string({
|
|
132
|
+
description: "Affiliate address",
|
|
133
|
+
})
|
|
134
|
+
.optional(),
|
|
135
|
+
affiliateFee: z
|
|
136
|
+
.number({
|
|
137
|
+
description: "Affiliate fee",
|
|
138
|
+
})
|
|
139
|
+
.optional(),
|
|
140
|
+
slipPercentage: z.number({
|
|
141
|
+
description: "Slippage as a percentage",
|
|
142
|
+
}),
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
export type RouteLeg = z.infer<typeof RouteLegSchema>;
|
|
146
|
+
|
|
147
|
+
export const RouteLegWithoutAddressesSchema = RouteLegSchema.omit({
|
|
148
|
+
sourceAddress: true,
|
|
149
|
+
destinationAddress: true,
|
|
150
|
+
slipPercentage: true,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
export type RouteLegWithoutAddresses = z.infer<typeof RouteLegWithoutAddressesSchema>;
|
|
154
|
+
|
|
155
|
+
export const RouteQuoteMetadataAssetSchema = z.object({
|
|
156
|
+
name: z.string({
|
|
157
|
+
description: "Asset name",
|
|
158
|
+
}),
|
|
159
|
+
price: z.number({
|
|
160
|
+
description: "Price in USD",
|
|
161
|
+
}),
|
|
162
|
+
image: z.string({
|
|
163
|
+
description: "Asset image",
|
|
164
|
+
}),
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
export type RouteQuoteMetadataAsset = z.infer<typeof RouteQuoteMetadataAssetSchema>;
|
|
168
|
+
|
|
169
|
+
export const RouteQuoteMetadataSchema = z.object({
|
|
170
|
+
priceImpact: z.number({
|
|
171
|
+
description: "Price impact",
|
|
172
|
+
}),
|
|
173
|
+
assets: z.optional(z.array(RouteQuoteMetadataAssetSchema)),
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
export const RouteQuoteWarningSchema = z.array(
|
|
177
|
+
z.object({
|
|
178
|
+
code: z.nativeEnum(WarningCodeEnum),
|
|
179
|
+
display: z.string(),
|
|
180
|
+
tooltip: z.string().optional(),
|
|
181
|
+
}),
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
export const RouteQuoteLegSchema = z.object({
|
|
185
|
+
sellAsset: z.string({
|
|
186
|
+
description: "Asset to sell",
|
|
187
|
+
}),
|
|
188
|
+
buyAsset: z.string({
|
|
189
|
+
description: "Asset to buy",
|
|
190
|
+
}),
|
|
191
|
+
provider: z.nativeEnum(ProviderName),
|
|
192
|
+
buyAmount: z.string({
|
|
193
|
+
description: "Amount of asset to buy",
|
|
194
|
+
}),
|
|
195
|
+
buyAmountMaxSlippage: z.string({
|
|
196
|
+
description: "Amount of asset to buy",
|
|
197
|
+
}),
|
|
198
|
+
sellAmount: z.string({
|
|
199
|
+
description: "Amount of asset to sell",
|
|
200
|
+
}),
|
|
201
|
+
sourceAddress: z.string({
|
|
202
|
+
description: "Source address",
|
|
203
|
+
}),
|
|
204
|
+
destinationAddress: z.string({
|
|
205
|
+
description: "Destination address",
|
|
206
|
+
}),
|
|
207
|
+
slippageBps: z.number({
|
|
208
|
+
description: "Slippage in bps",
|
|
209
|
+
}),
|
|
210
|
+
targetAddress: z.optional(
|
|
211
|
+
z.string({
|
|
212
|
+
description: "Target address for contract call or transfer address",
|
|
213
|
+
}),
|
|
214
|
+
),
|
|
215
|
+
inboundAddress: z.optional(
|
|
216
|
+
z.string({
|
|
217
|
+
description: "Inbound address",
|
|
218
|
+
}),
|
|
219
|
+
),
|
|
220
|
+
routerAddress: z.optional(
|
|
221
|
+
z.string({
|
|
222
|
+
description: "Inbound address",
|
|
223
|
+
}),
|
|
224
|
+
),
|
|
225
|
+
contractMethod: z.optional(
|
|
226
|
+
z.string({
|
|
227
|
+
description: "Contract method",
|
|
228
|
+
}),
|
|
229
|
+
),
|
|
230
|
+
fees: z.optional(FeesSchema),
|
|
231
|
+
estimatedTime: z.optional(EstimatedTimeSchema),
|
|
232
|
+
memo: z.optional(
|
|
233
|
+
z.string({
|
|
234
|
+
description: "Memo",
|
|
235
|
+
}),
|
|
236
|
+
),
|
|
237
|
+
expiration: z.optional(
|
|
238
|
+
z.string({
|
|
239
|
+
description: "Expiration",
|
|
240
|
+
}),
|
|
241
|
+
),
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
export type RouteQuoteLeg = z.infer<typeof RouteQuoteLegSchema>;
|
|
245
|
+
|
|
246
|
+
export const RouteQuoteSchema = z.object({
|
|
247
|
+
providers: z.array(z.nativeEnum(ProviderName)),
|
|
248
|
+
sellAsset: z.string({
|
|
249
|
+
description: "Asset to sell",
|
|
250
|
+
}),
|
|
251
|
+
sellAmount: z.string({
|
|
252
|
+
description: "sell amount",
|
|
253
|
+
}),
|
|
254
|
+
buyAsset: z.string({
|
|
255
|
+
description: "Asset to buy",
|
|
256
|
+
}),
|
|
257
|
+
expectedBuyAmount: z.string({
|
|
258
|
+
description: "Expected Buy amount",
|
|
259
|
+
}),
|
|
260
|
+
expectedBuyAmountMaxSlippage: z.string({
|
|
261
|
+
description: "Expected Buy amount max slippage",
|
|
262
|
+
}),
|
|
263
|
+
sourceAddress: z.string({
|
|
264
|
+
description: "Source address",
|
|
265
|
+
}),
|
|
266
|
+
destinationAddress: z.string({
|
|
267
|
+
description: "Destination address",
|
|
268
|
+
}),
|
|
269
|
+
targetAddress: z.optional(
|
|
270
|
+
z.string({
|
|
271
|
+
description: "Target address",
|
|
272
|
+
}),
|
|
273
|
+
),
|
|
274
|
+
routerAddress: z.optional(
|
|
275
|
+
z.string({
|
|
276
|
+
description: "Router address",
|
|
277
|
+
}),
|
|
278
|
+
),
|
|
279
|
+
inboundAddress: z.optional(
|
|
280
|
+
z.string({
|
|
281
|
+
description: "Inbound address",
|
|
282
|
+
}),
|
|
283
|
+
),
|
|
284
|
+
expiration: z.optional(
|
|
285
|
+
z.string({
|
|
286
|
+
description: "Expiration",
|
|
287
|
+
}),
|
|
288
|
+
),
|
|
289
|
+
memo: z.optional(
|
|
290
|
+
z.string({
|
|
291
|
+
description: "Memo",
|
|
292
|
+
}),
|
|
293
|
+
),
|
|
294
|
+
evmTransactionDetails: z.optional(EVMTransactionDetailsSchema),
|
|
295
|
+
routePathArray: z.optional(z.array(z.string())),
|
|
296
|
+
estimatedTime: z.optional(EstimatedTimeSchema),
|
|
297
|
+
totalSlippageBps: z.number({
|
|
298
|
+
description: "Total slippage in bps",
|
|
299
|
+
}),
|
|
300
|
+
legs: z.array(RouteQuoteLegSchema),
|
|
301
|
+
// TODO use enum
|
|
302
|
+
errorCode: z.optional(z.string()),
|
|
303
|
+
warnings: RouteQuoteWarningSchema,
|
|
304
|
+
meta: RouteQuoteMetadataSchema,
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
export type RouteQuote = z.infer<typeof RouteQuoteSchema>;
|
|
308
|
+
|
|
309
|
+
const QuoteResponseRouteLegItem = z.object({
|
|
310
|
+
provider: z.nativeEnum(ProviderName),
|
|
311
|
+
sellAsset: z.string({
|
|
312
|
+
description: "Asset to sell",
|
|
313
|
+
}),
|
|
314
|
+
sellAmount: z.string({
|
|
315
|
+
description: "Sell amount",
|
|
316
|
+
}),
|
|
317
|
+
buyAsset: z.string({
|
|
318
|
+
description: "Asset to buy",
|
|
319
|
+
}),
|
|
320
|
+
buyAmount: z.string({
|
|
321
|
+
description: "Buy amount",
|
|
322
|
+
}),
|
|
323
|
+
buyAmountMaxSlippage: z.string({
|
|
324
|
+
description: "Buy amount max slippage",
|
|
325
|
+
}),
|
|
326
|
+
fees: z.optional(FeesSchema), // TODO remove optionality
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
const QuoteResponseRouteItem = z.object({
|
|
330
|
+
providers: z.array(z.nativeEnum(ProviderName)),
|
|
331
|
+
sellAsset: z.string({
|
|
332
|
+
description: "Asset to sell",
|
|
333
|
+
}),
|
|
334
|
+
sellAmount: z.string({
|
|
335
|
+
description: "sell amount",
|
|
336
|
+
}),
|
|
337
|
+
buyAsset: z.string({
|
|
338
|
+
description: "Asset to buy",
|
|
339
|
+
}),
|
|
340
|
+
expectedBuyAmount: z.string({
|
|
341
|
+
description: "Expected Buy amount",
|
|
342
|
+
}),
|
|
343
|
+
expectedBuyAmountMaxSlippage: z.string({
|
|
344
|
+
description: "Expected Buy amount max slippage",
|
|
345
|
+
}),
|
|
346
|
+
sourceAddress: z.string({
|
|
347
|
+
description: "Source address",
|
|
348
|
+
}),
|
|
349
|
+
destinationAddress: z.string({
|
|
350
|
+
description: "Destination address",
|
|
351
|
+
}),
|
|
352
|
+
targetAddress: z.optional(
|
|
353
|
+
z.string({
|
|
354
|
+
description: "Target address",
|
|
355
|
+
}),
|
|
356
|
+
),
|
|
357
|
+
expiration: z.optional(
|
|
358
|
+
z.string({
|
|
359
|
+
description: "Expiration",
|
|
360
|
+
}),
|
|
361
|
+
),
|
|
362
|
+
memo: z.optional(
|
|
363
|
+
z.string({
|
|
364
|
+
description: "Memo",
|
|
365
|
+
}),
|
|
366
|
+
),
|
|
367
|
+
evmTransactionDetails: z.optional(EVMTransactionDetailsSchema),
|
|
368
|
+
estimatedTime: z.optional(EstimatedTimeSchema), // TODO remove optionality
|
|
369
|
+
totalSlippageBps: z.number({
|
|
370
|
+
description: "Total slippage in bps",
|
|
371
|
+
}),
|
|
372
|
+
legs: z.array(QuoteResponseRouteLegItem),
|
|
373
|
+
warnings: RouteQuoteWarningSchema,
|
|
374
|
+
meta: RouteQuoteMetadataSchema,
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
export const QuoteResponseSchema = z.object({
|
|
378
|
+
quoteId: z.string({
|
|
379
|
+
description: "Quote ID",
|
|
380
|
+
}),
|
|
381
|
+
routes: z.array(QuoteResponseRouteItem),
|
|
382
|
+
error: z.optional(
|
|
383
|
+
z.string({
|
|
384
|
+
description: "Error message",
|
|
385
|
+
}),
|
|
386
|
+
),
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
export type QuoteResponse = z.infer<typeof QuoteResponseSchema>;
|
|
390
|
+
export type QuoteResponseRoute = z.infer<typeof QuoteResponseRouteItem>;
|
|
391
|
+
export type QuoteResponseRouteLeg = z.infer<typeof QuoteResponseRouteLegItem>;
|
package/src/types/sdk.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import type { AssetValue } from "../modules/assetValue";
|
|
3
|
+
import type { QuoteResponseRoute } from "./quotes";
|
|
2
4
|
|
|
3
5
|
export type GenericSwapParams = {
|
|
4
|
-
buyAsset
|
|
5
|
-
sellAsset
|
|
6
|
-
recipient
|
|
6
|
+
buyAsset?: AssetValue;
|
|
7
|
+
sellAsset?: AssetValue;
|
|
8
|
+
recipient?: string;
|
|
9
|
+
feeOptionKey?: FeeOption;
|
|
10
|
+
route: QuoteResponseRoute;
|
|
7
11
|
};
|
|
8
12
|
|
|
9
13
|
export type SwapParams<PluginNames = string, T = GenericSwapParams> = T & {
|
|
10
|
-
pluginName
|
|
14
|
+
pluginName?: PluginNames;
|
|
11
15
|
};
|
|
12
16
|
|
|
13
17
|
export enum FeeOption {
|
|
@@ -42,3 +46,81 @@ export enum MemoType {
|
|
|
42
46
|
OPEN_LOAN = "$+",
|
|
43
47
|
CLOSE_LOAN = "$-",
|
|
44
48
|
}
|
|
49
|
+
|
|
50
|
+
export const QuoteRequestSchema = z
|
|
51
|
+
.object({
|
|
52
|
+
sellAsset: z.string({
|
|
53
|
+
description: "Asset to sell",
|
|
54
|
+
}),
|
|
55
|
+
buyAsset: z.string({
|
|
56
|
+
description: "Asset to buy",
|
|
57
|
+
}),
|
|
58
|
+
sellAmount: z
|
|
59
|
+
.number({
|
|
60
|
+
description: "Amount of asset to sell",
|
|
61
|
+
})
|
|
62
|
+
.refine((amount) => amount > 0, {
|
|
63
|
+
message: "sellAmount must be greater than 0",
|
|
64
|
+
path: ["sellAmount"],
|
|
65
|
+
}),
|
|
66
|
+
providers: z.optional(
|
|
67
|
+
z.array(
|
|
68
|
+
z.string({
|
|
69
|
+
description: "List of providers to use",
|
|
70
|
+
}),
|
|
71
|
+
),
|
|
72
|
+
),
|
|
73
|
+
sourceAddress: z.optional(
|
|
74
|
+
z.string({
|
|
75
|
+
description: "Address to send asset from",
|
|
76
|
+
}),
|
|
77
|
+
),
|
|
78
|
+
destinationAddress: z.optional(
|
|
79
|
+
z.string({
|
|
80
|
+
description: "Address to send asset to",
|
|
81
|
+
}),
|
|
82
|
+
),
|
|
83
|
+
slippage: z.optional(
|
|
84
|
+
z.number({
|
|
85
|
+
description: "Slippage tolerance as a percentage. Default is 3%.",
|
|
86
|
+
}),
|
|
87
|
+
),
|
|
88
|
+
affiliate: z.optional(
|
|
89
|
+
z.string({
|
|
90
|
+
description: "Affiliate thorname",
|
|
91
|
+
}),
|
|
92
|
+
),
|
|
93
|
+
affiliateFee: z.optional(
|
|
94
|
+
z
|
|
95
|
+
.number({
|
|
96
|
+
description: "Affiliate fee in basis points",
|
|
97
|
+
})
|
|
98
|
+
.refine(
|
|
99
|
+
(fee) => {
|
|
100
|
+
return fee === Math.floor(fee) && fee >= 0;
|
|
101
|
+
},
|
|
102
|
+
{ message: "affiliateFee must be a positive integer", path: ["affiliateFee"] },
|
|
103
|
+
),
|
|
104
|
+
),
|
|
105
|
+
allowSmartContractSender: z.optional(
|
|
106
|
+
z.boolean({
|
|
107
|
+
description: "Allow smart contract as sender",
|
|
108
|
+
}),
|
|
109
|
+
),
|
|
110
|
+
allowSmartContractReceiver: z.optional(
|
|
111
|
+
z.boolean({
|
|
112
|
+
description: "Allow smart contract as recipient",
|
|
113
|
+
}),
|
|
114
|
+
),
|
|
115
|
+
disableSecurityChecks: z.optional(
|
|
116
|
+
z.boolean({
|
|
117
|
+
description: "Disable security checks",
|
|
118
|
+
}),
|
|
119
|
+
),
|
|
120
|
+
})
|
|
121
|
+
.refine((data) => data.sellAsset !== data.buyAsset, {
|
|
122
|
+
message: "Must be different",
|
|
123
|
+
path: ["sellAsset", "buyAsset"],
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
export type QuoteRequest = z.infer<typeof QuoteRequestSchema>;
|
package/src/types/wallet.ts
CHANGED
|
@@ -2,9 +2,16 @@ import type { CosmosWallets, ThorchainWallets } from "@swapkit/toolbox-cosmos";
|
|
|
2
2
|
import type { EVMWallets } from "@swapkit/toolbox-evm";
|
|
3
3
|
import type { SubstrateWallets } from "@swapkit/toolbox-substrate";
|
|
4
4
|
import type { UTXOWallets } from "@swapkit/toolbox-utxo";
|
|
5
|
+
import type { Eip1193Provider } from "ethers";
|
|
5
6
|
import type { AssetValue } from "../modules/assetValue";
|
|
6
7
|
import type { Chain } from "./chains";
|
|
7
8
|
|
|
9
|
+
declare global {
|
|
10
|
+
interface WindowEventMap {
|
|
11
|
+
"eip6963:announceProvider": CustomEvent;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
export enum WalletOption {
|
|
9
16
|
KEYSTORE = "KEYSTORE",
|
|
10
17
|
KEEPKEY = "KEEPKEY",
|
|
@@ -20,6 +27,8 @@ export enum WalletOption {
|
|
|
20
27
|
OKX_MOBILE = "OKX_MOBILE",
|
|
21
28
|
BRAVE = "BRAVE",
|
|
22
29
|
WALLETCONNECT = "WALLETCONNECT",
|
|
30
|
+
EIP6963 = "EIP6963",
|
|
31
|
+
EXODUS = "EXODUS",
|
|
23
32
|
}
|
|
24
33
|
|
|
25
34
|
export enum LedgerErrorCode {
|
|
@@ -45,3 +54,25 @@ export type BaseWallet<T extends EmptyWallet | unknown> = {
|
|
|
45
54
|
export type Wallet = BaseWallet<
|
|
46
55
|
EVMWallets & CosmosWallets & ThorchainWallets & UTXOWallets & SubstrateWallets
|
|
47
56
|
>;
|
|
57
|
+
|
|
58
|
+
export type EIP6963ProviderInfo = {
|
|
59
|
+
walletId: string;
|
|
60
|
+
uuid: string;
|
|
61
|
+
name: string;
|
|
62
|
+
icon: string;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type EIP6963ProviderDetail = {
|
|
66
|
+
info: EIP6963ProviderInfo;
|
|
67
|
+
provider: Eip1193Provider;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type EIP6963Provider = {
|
|
71
|
+
info: EIP6963ProviderInfo;
|
|
72
|
+
provider: Eip1193Provider;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// This type represents the structure of an event dispatched by a wallet to announce its presence based on EIP-6963.
|
|
76
|
+
export type EIP6963AnnounceProviderEvent = Event & {
|
|
77
|
+
detail: EIP6963Provider;
|
|
78
|
+
};
|