@tcswap/helpers 4.5.15
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/api/index.cjs +4 -0
- package/dist/api/index.cjs.map +16 -0
- package/dist/api/index.js +4 -0
- package/dist/api/index.js.map +16 -0
- package/dist/chunk-pfmeq01a.js +5 -0
- package/dist/chunk-pfmeq01a.js.map +9 -0
- package/dist/chunk-vb4wtm2w.js +4 -0
- package/dist/chunk-vb4wtm2w.js.map +9 -0
- package/dist/contracts.cjs +4 -0
- package/dist/contracts.cjs.map +10 -0
- package/dist/contracts.js +4 -0
- package/dist/contracts.js.map +10 -0
- package/dist/index.cjs +7 -0
- package/dist/index.cjs.map +30 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +30 -0
- package/dist/tokens.cjs +4 -0
- package/dist/tokens.cjs.map +10 -0
- package/dist/tokens.js +4 -0
- package/dist/tokens.js.map +10 -0
- package/dist/types/api/index.d.ts +502 -0
- package/dist/types/api/index.d.ts.map +1 -0
- package/dist/types/api/memoless/endpoints.d.ts +56 -0
- package/dist/types/api/memoless/endpoints.d.ts.map +1 -0
- package/dist/types/api/memoless/types.d.ts +85 -0
- package/dist/types/api/memoless/types.d.ts.map +1 -0
- package/dist/types/api/midgard/endpoints.d.ts +80 -0
- package/dist/types/api/midgard/endpoints.d.ts.map +1 -0
- package/dist/types/api/midgard/types.d.ts +543 -0
- package/dist/types/api/midgard/types.d.ts.map +1 -0
- package/dist/types/api/thornode/endpoints.d.ts +34 -0
- package/dist/types/api/thornode/endpoints.d.ts.map +1 -0
- package/dist/types/api/thornode/types.d.ts +264 -0
- package/dist/types/api/thornode/types.d.ts.map +1 -0
- package/dist/types/api/uswap/endpoints.d.ts +372 -0
- package/dist/types/api/uswap/endpoints.d.ts.map +1 -0
- package/dist/types/api/uswap/types.d.ts +1487 -0
- package/dist/types/api/uswap/types.d.ts.map +1 -0
- package/dist/types/contracts.d.ts +2 -0
- package/dist/types/contracts.d.ts.map +1 -0
- package/dist/types/index.d.ts +32 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/modules/assetValue.d.ts +82 -0
- package/dist/types/modules/assetValue.d.ts.map +1 -0
- package/dist/types/modules/bigIntArithmetics.d.ts +60 -0
- package/dist/types/modules/bigIntArithmetics.d.ts.map +1 -0
- package/dist/types/modules/feeMultiplier.d.ts +48 -0
- package/dist/types/modules/feeMultiplier.d.ts.map +1 -0
- package/dist/types/modules/requestClient.d.ts +33 -0
- package/dist/types/modules/requestClient.d.ts.map +1 -0
- package/dist/types/modules/uSwapConfig.d.ts +249 -0
- package/dist/types/modules/uSwapConfig.d.ts.map +1 -0
- package/dist/types/modules/uSwapError.d.ts +879 -0
- package/dist/types/modules/uSwapError.d.ts.map +1 -0
- package/dist/types/modules/uSwapNumber.d.ts +10 -0
- package/dist/types/modules/uSwapNumber.d.ts.map +1 -0
- package/dist/types/tokens.d.ts +2 -0
- package/dist/types/tokens.d.ts.map +1 -0
- package/dist/types/types/commonTypes.d.ts +16 -0
- package/dist/types/types/commonTypes.d.ts.map +1 -0
- package/dist/types/types/derivationPath.d.ts +4 -0
- package/dist/types/types/derivationPath.d.ts.map +1 -0
- package/dist/types/types/errors/apiV1.d.ts +2 -0
- package/dist/types/types/errors/apiV1.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +6 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/quotes.d.ts +180 -0
- package/dist/types/types/quotes.d.ts.map +1 -0
- package/dist/types/types/sdk.d.ts +35 -0
- package/dist/types/types/sdk.d.ts.map +1 -0
- package/dist/types/types/wallet.d.ts +130 -0
- package/dist/types/types/wallet.d.ts.map +1 -0
- package/dist/types/utils/asset.d.ts +37 -0
- package/dist/types/utils/asset.d.ts.map +1 -0
- package/dist/types/utils/chains.d.ts +13 -0
- package/dist/types/utils/chains.d.ts.map +1 -0
- package/dist/types/utils/derivationPath.d.ts +21 -0
- package/dist/types/utils/derivationPath.d.ts.map +1 -0
- package/dist/types/utils/explorerUrls.d.ts +10 -0
- package/dist/types/utils/explorerUrls.d.ts.map +1 -0
- package/dist/types/utils/liquidity.d.ts +62 -0
- package/dist/types/utils/liquidity.d.ts.map +1 -0
- package/dist/types/utils/memo.d.ts +65 -0
- package/dist/types/utils/memo.d.ts.map +1 -0
- package/dist/types/utils/others.d.ts +15 -0
- package/dist/types/utils/others.d.ts.map +1 -0
- package/dist/types/utils/validators.d.ts +6 -0
- package/dist/types/utils/validators.d.ts.map +1 -0
- package/dist/types/utils/wallets.d.ts +36 -0
- package/dist/types/utils/wallets.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/api/index.ts +15 -0
- package/src/api/memoless/endpoints.ts +62 -0
- package/src/api/memoless/types.ts +83 -0
- package/src/api/midgard/endpoints.ts +352 -0
- package/src/api/midgard/types.ts +515 -0
- package/src/api/thornode/endpoints.ts +109 -0
- package/src/api/thornode/types.ts +247 -0
- package/src/api/uswap/endpoints.ts +252 -0
- package/src/api/uswap/types.ts +626 -0
- package/src/contracts.ts +1 -0
- package/src/index.ts +32 -0
- package/src/modules/__tests__/assetValue.test.ts +2452 -0
- package/src/modules/__tests__/bigIntArithmetics.test.ts +410 -0
- package/src/modules/__tests__/feeMultiplier.test.ts +131 -0
- package/src/modules/__tests__/uSwapConfig.test.ts +429 -0
- package/src/modules/__tests__/uSwapNumber.test.ts +439 -0
- package/src/modules/assetValue.ts +536 -0
- package/src/modules/bigIntArithmetics.ts +366 -0
- package/src/modules/feeMultiplier.ts +84 -0
- package/src/modules/requestClient.ts +116 -0
- package/src/modules/uSwapConfig.ts +189 -0
- package/src/modules/uSwapError.ts +474 -0
- package/src/modules/uSwapNumber.ts +17 -0
- package/src/tokens.ts +1 -0
- package/src/types/commonTypes.ts +10 -0
- package/src/types/derivationPath.ts +11 -0
- package/src/types/errors/apiV1.ts +0 -0
- package/src/types/index.ts +5 -0
- package/src/types/quotes.ts +182 -0
- package/src/types/sdk.ts +38 -0
- package/src/types/wallet.ts +124 -0
- package/src/utils/__tests__/asset.test.ts +186 -0
- package/src/utils/__tests__/derivationPath.test.ts +142 -0
- package/src/utils/__tests__/explorerUrls.test.ts +59 -0
- package/src/utils/__tests__/liquidity.test.ts +302 -0
- package/src/utils/__tests__/memo.test.ts +99 -0
- package/src/utils/__tests__/others.test.ts +169 -0
- package/src/utils/__tests__/validators.test.ts +84 -0
- package/src/utils/__tests__/wallets.test.ts +625 -0
- package/src/utils/asset.ts +399 -0
- package/src/utils/chains.ts +104 -0
- package/src/utils/derivationPath.ts +101 -0
- package/src/utils/explorerUrls.ts +32 -0
- package/src/utils/liquidity.ts +154 -0
- package/src/utils/memo.ts +102 -0
- package/src/utils/others.ts +64 -0
- package/src/utils/validators.ts +36 -0
- package/src/utils/wallets.ts +238 -0
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { ErrorCode, FeeTypeEnum, ProviderName, WarningCodeEnum } from "@tcswap/helpers";
|
|
6
|
+
import { Chain, ChainId } from "@tcswap/types";
|
|
7
|
+
import { array, boolean, coerce, number, object, optional, string, union, unknown, type ZodType, z } from "zod/v4";
|
|
8
|
+
|
|
9
|
+
export enum PriorityLabel {
|
|
10
|
+
CHEAPEST = "CHEAPEST",
|
|
11
|
+
FASTEST = "FASTEST",
|
|
12
|
+
RECOMMENDED = "RECOMMENDED",
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export enum RouteQuoteTxType {
|
|
16
|
+
PSBT = "PSBT",
|
|
17
|
+
EVM = "EVM",
|
|
18
|
+
COSMOS = "COSMOS",
|
|
19
|
+
RADIX = "RADIX",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export enum TxnType {
|
|
23
|
+
approve = "approve",
|
|
24
|
+
claim = "claim",
|
|
25
|
+
deposit = "deposit",
|
|
26
|
+
donate = "donate",
|
|
27
|
+
lending = "lending",
|
|
28
|
+
lp_action = "lp_action",
|
|
29
|
+
native_contract_call = "native_contract_call",
|
|
30
|
+
native_send = "native_send",
|
|
31
|
+
stake = "stake",
|
|
32
|
+
streaming_swap = "streaming_swap",
|
|
33
|
+
swap = "swap",
|
|
34
|
+
thorname_action = "thorname_action",
|
|
35
|
+
token_contract_call = "token_contract_call",
|
|
36
|
+
token_transfer = "token_transfer",
|
|
37
|
+
unknown = "unknown",
|
|
38
|
+
unstake = "unstake",
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export enum ProviderAction {
|
|
42
|
+
swap = "swap",
|
|
43
|
+
aggregation = "aggregation",
|
|
44
|
+
addLiquidity = "addLiquidity",
|
|
45
|
+
withdrawLiquidity = "withdrawLiquidity",
|
|
46
|
+
addSavers = "addSavers",
|
|
47
|
+
withdrawSavers = "withdrawSavers",
|
|
48
|
+
borrow = "borrow",
|
|
49
|
+
repay = "repay",
|
|
50
|
+
name = "name",
|
|
51
|
+
donate = "donate",
|
|
52
|
+
claim = "claim",
|
|
53
|
+
stake = "stake",
|
|
54
|
+
unstake = "unstake",
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export enum TxnStatus {
|
|
58
|
+
unknown = "unknown",
|
|
59
|
+
not_started = "not_started",
|
|
60
|
+
pending = "pending",
|
|
61
|
+
swapping = "swapping",
|
|
62
|
+
completed = "completed",
|
|
63
|
+
refunded = "refunded",
|
|
64
|
+
failed = "failed",
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export enum TrackingStatus {
|
|
68
|
+
not_started = "not_started",
|
|
69
|
+
starting = "starting",
|
|
70
|
+
broadcasted = "broadcasted",
|
|
71
|
+
mempool = "mempool",
|
|
72
|
+
inbound = "inbound",
|
|
73
|
+
outbound = "outbound",
|
|
74
|
+
swapping = "swapping",
|
|
75
|
+
completed = "completed",
|
|
76
|
+
refunded = "refunded",
|
|
77
|
+
partially_refunded = "partially_refunded",
|
|
78
|
+
dropped = "dropped",
|
|
79
|
+
reverted = "reverted",
|
|
80
|
+
replaced = "replaced",
|
|
81
|
+
retries_exceeded = "retries_exceeded",
|
|
82
|
+
parsing_error = "parsing_error",
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
type TokenProviderVersion = { major: number; minor: number; patch: number };
|
|
86
|
+
|
|
87
|
+
export type TokenListProvidersResponse = Array<{
|
|
88
|
+
provider: ProviderName;
|
|
89
|
+
name: string;
|
|
90
|
+
timestamp: string;
|
|
91
|
+
version: TokenProviderVersion;
|
|
92
|
+
keywords: string[];
|
|
93
|
+
count: number;
|
|
94
|
+
url: string;
|
|
95
|
+
}>;
|
|
96
|
+
|
|
97
|
+
export type TokensResponseV2 = {
|
|
98
|
+
chainId: ChainId;
|
|
99
|
+
count: number;
|
|
100
|
+
keywords: string[];
|
|
101
|
+
name: string;
|
|
102
|
+
provider: ProviderName;
|
|
103
|
+
timestamp: string;
|
|
104
|
+
tokens: Token[];
|
|
105
|
+
version: TokenProviderVersion;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const TokenSchema = object({
|
|
109
|
+
address: optional(string()),
|
|
110
|
+
chain: z.enum(Chain).optional(),
|
|
111
|
+
chainId: z.enum(ChainId),
|
|
112
|
+
coingeckoId: optional(string()),
|
|
113
|
+
decimals: coerce.number(),
|
|
114
|
+
extensions: optional(z.looseObject({})),
|
|
115
|
+
identifier: string(),
|
|
116
|
+
logoURI: optional(string()),
|
|
117
|
+
name: optional(string()),
|
|
118
|
+
shortCode: optional(string()),
|
|
119
|
+
symbol: optional(string()),
|
|
120
|
+
ticker: string(),
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
export type Token = z.infer<typeof TokenSchema>;
|
|
124
|
+
|
|
125
|
+
export const TrackingRequestSchema = z
|
|
126
|
+
.object({
|
|
127
|
+
block: z.optional(z.number().describe("Block number. Required for Polkadot chain. e.g. `123456`")),
|
|
128
|
+
chainId: z.optional(z.string().describe("ChainId for the hash. e.g. `thorchain-1`")),
|
|
129
|
+
depositChannelId: z.optional(
|
|
130
|
+
z.string().describe("Deposit channel ID, required for Chainflip if tx was broadcasted without wallet connection"),
|
|
131
|
+
),
|
|
132
|
+
hash: z.optional(
|
|
133
|
+
z
|
|
134
|
+
.string()
|
|
135
|
+
.describe(
|
|
136
|
+
"Hash for the first transaction broadcasted by the end user. e.g. `88D1819378ECD09E5284C54937CDC1E99B52F253C007617A02DD1200710CE677`",
|
|
137
|
+
),
|
|
138
|
+
),
|
|
139
|
+
})
|
|
140
|
+
.refine((data) => (data.hash && data.chainId) || data.depositChannelId, {
|
|
141
|
+
message: "Either `hash` and `chainId` or `depositChannelId` must be provided",
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
export const TrackingRequestQuerySchema = z.object({
|
|
145
|
+
forceUpdate: z
|
|
146
|
+
.string()
|
|
147
|
+
.toLowerCase()
|
|
148
|
+
.transform((x) => x === "true")
|
|
149
|
+
.pipe(z.boolean())
|
|
150
|
+
.optional(),
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
export type TrackingRequest = z.infer<typeof TrackingRequestSchema>;
|
|
154
|
+
|
|
155
|
+
export const ApiV2ErrorSchema = object({ error: string(), message: string() });
|
|
156
|
+
|
|
157
|
+
export const AssetValueSchema = object({
|
|
158
|
+
address: optional(string()),
|
|
159
|
+
chain: z.enum(Chain),
|
|
160
|
+
decimal: optional(number()),
|
|
161
|
+
isGasAsset: boolean(),
|
|
162
|
+
isSynthetic: boolean(),
|
|
163
|
+
symbol: string(),
|
|
164
|
+
tax: optional(object({ buy: number(), sell: number() })),
|
|
165
|
+
ticker: string(),
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
export const TokenDetailsMetadataSchema = object({
|
|
169
|
+
id: string(),
|
|
170
|
+
market_cap: number(),
|
|
171
|
+
name: string(),
|
|
172
|
+
price_change_24h_usd: number(),
|
|
173
|
+
price_change_percentage_24h_usd: number(),
|
|
174
|
+
sparkline_in_7d: array(number()),
|
|
175
|
+
timestamp: string(),
|
|
176
|
+
total_volume: number(),
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
export const PriceResponseSchema = array(
|
|
180
|
+
object({
|
|
181
|
+
cg: TokenDetailsMetadataSchema.optional(),
|
|
182
|
+
identifier: string(),
|
|
183
|
+
price_usd: number(),
|
|
184
|
+
provider: string(),
|
|
185
|
+
timestamp: number(),
|
|
186
|
+
}).partial(),
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
export type PriceResponse = z.infer<typeof PriceResponseSchema>;
|
|
190
|
+
|
|
191
|
+
export const QuoteRequestSchema = object({
|
|
192
|
+
affiliate: optional(string().describe("Affiliate thorname")),
|
|
193
|
+
affiliateFee: optional(
|
|
194
|
+
number()
|
|
195
|
+
.describe("Affiliate fee in basis points")
|
|
196
|
+
.refine((fee) => fee === Math.floor(fee) && fee >= 0, {
|
|
197
|
+
message: "affiliateFee must be a positive integer",
|
|
198
|
+
path: ["affiliateFee"],
|
|
199
|
+
}),
|
|
200
|
+
),
|
|
201
|
+
allowSmartContractReceiver: optional(boolean().describe("Allow smart contract as recipient")),
|
|
202
|
+
allowSmartContractSender: optional(boolean().describe("Allow smart contract as sender")),
|
|
203
|
+
buyAsset: string().describe("Asset to buy"),
|
|
204
|
+
cfBoost: optional(boolean().describe("Set to true to enable CF boost to speed up Chainflip swaps. BTC only.")),
|
|
205
|
+
destinationAddress: optional(string().describe("Address to send asset to")),
|
|
206
|
+
disableSecurityChecks: optional(boolean().describe("Disable security checks")),
|
|
207
|
+
dry: optional(boolean().describe("Set to false to include an transaction object")),
|
|
208
|
+
providers: optional(
|
|
209
|
+
array(
|
|
210
|
+
string()
|
|
211
|
+
.describe("List of providers to use")
|
|
212
|
+
.refine((provider) => ProviderName[provider as ProviderName] !== undefined, {
|
|
213
|
+
message: "Invalid provider",
|
|
214
|
+
path: ["providers"],
|
|
215
|
+
}),
|
|
216
|
+
),
|
|
217
|
+
),
|
|
218
|
+
referrer: optional(string().describe("Referrer address (referral program)")),
|
|
219
|
+
refundAddress: optional(string().describe("Address to refund")),
|
|
220
|
+
sellAmount: string()
|
|
221
|
+
.describe("Amount of asset to sell")
|
|
222
|
+
.refine((amount) => +amount > 0, { message: "sellAmount must be greater than 0", path: ["sellAmount"] }),
|
|
223
|
+
sellAsset: string().describe("Asset to sell"),
|
|
224
|
+
slippage: optional(number().describe("Slippage tolerance as a percentage. Default is 3%.")),
|
|
225
|
+
sourceAddress: optional(string().describe("Address to send asset from")),
|
|
226
|
+
}).refine((data) => data.sellAsset !== data.buyAsset, {
|
|
227
|
+
message: "Must be different",
|
|
228
|
+
path: ["sellAsset", "buyAsset"],
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
export type QuoteRequest = z.infer<typeof QuoteRequestSchema>;
|
|
232
|
+
|
|
233
|
+
export const PriceRequestSchema = object({ metadata: boolean(), tokens: array(object({ identifier: string() })) });
|
|
234
|
+
|
|
235
|
+
export type PriceRequest = z.infer<typeof PriceRequestSchema>;
|
|
236
|
+
|
|
237
|
+
export const DepositChannelParamsSchema = object({ destinationAddress: string() });
|
|
238
|
+
|
|
239
|
+
export const BrokerDepositChannelParamsSchema = DepositChannelParamsSchema.extend({
|
|
240
|
+
affiliateFees: array(object({ brokerAddress: string(), feeBps: number() })).optional(),
|
|
241
|
+
brokerCommissionBps: number().optional(),
|
|
242
|
+
buyAsset: object({ asset: string(), chain: string() }),
|
|
243
|
+
channelMetadata: object({
|
|
244
|
+
cfParameters: string().optional(),
|
|
245
|
+
gasBudget: string().optional(),
|
|
246
|
+
message: string().optional(),
|
|
247
|
+
}).optional(),
|
|
248
|
+
dcaParameters: object({ chunkInterval: number().optional(), numberOfChunks: number().optional() }).optional(),
|
|
249
|
+
maxBoostFeeBps: number().optional(),
|
|
250
|
+
refundParameters: object({
|
|
251
|
+
minPrice: string().optional(),
|
|
252
|
+
refundAddress: string().optional(),
|
|
253
|
+
retryDuration: number().optional(),
|
|
254
|
+
}).optional(),
|
|
255
|
+
sellAsset: object({ asset: string(), chain: string() }),
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
export type BrokerDepositChannelParams = z.infer<typeof BrokerDepositChannelParamsSchema>;
|
|
259
|
+
|
|
260
|
+
export const DepositChannelResponseSchema = object({ channelId: string(), depositAddress: string() });
|
|
261
|
+
|
|
262
|
+
export const NearDepositChannelParamsSchema = DepositChannelParamsSchema.extend({
|
|
263
|
+
affiliateFees: object({ feeBps: number(), nearId: string() }).optional(),
|
|
264
|
+
buyAsset: string(),
|
|
265
|
+
sellAmount: string(),
|
|
266
|
+
sellAsset: string(),
|
|
267
|
+
slippage: coerce.number(),
|
|
268
|
+
sourceAddress: string(),
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
export type NearDepositChannelParams = z.infer<typeof NearDepositChannelParamsSchema>;
|
|
272
|
+
|
|
273
|
+
const NearQuoteResponseSchema = object({
|
|
274
|
+
amountIn: string(),
|
|
275
|
+
amountInFormatted: string(),
|
|
276
|
+
amountInUsd: string(),
|
|
277
|
+
amountOut: string(),
|
|
278
|
+
amountOutFormatted: string(),
|
|
279
|
+
amountOutUsd: string(),
|
|
280
|
+
deadline: string().optional(),
|
|
281
|
+
minAmountIn: string(),
|
|
282
|
+
minAmountOut: string(),
|
|
283
|
+
timeEstimate: number().optional(),
|
|
284
|
+
timeWhenInactive: string().optional(),
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
export const NearDepositChannelResultSchema = NearQuoteResponseSchema.extend({
|
|
288
|
+
depositAddress: string(),
|
|
289
|
+
quote: NearQuoteResponseSchema,
|
|
290
|
+
signature: string(),
|
|
291
|
+
timestamp: string(),
|
|
292
|
+
tx: unknown(),
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
export type NearDepositChannelResult = z.infer<typeof NearDepositChannelResultSchema>;
|
|
296
|
+
|
|
297
|
+
export const NearSwapResponseSchema = object({
|
|
298
|
+
buyAsset: string(),
|
|
299
|
+
buyAssetAmount: string(),
|
|
300
|
+
buyAssetAmountMaxSlippage: string(),
|
|
301
|
+
deadline: string().optional(),
|
|
302
|
+
depositAddress: string(),
|
|
303
|
+
depositAmount: string(),
|
|
304
|
+
depositAsset: string(),
|
|
305
|
+
tx: unknown(),
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
export type NearSwapResponse = z.infer<typeof NearSwapResponseSchema>;
|
|
309
|
+
|
|
310
|
+
export type DepositChannelResponse = z.infer<typeof DepositChannelResponseSchema>;
|
|
311
|
+
|
|
312
|
+
const TxnPayloadSchema = object({
|
|
313
|
+
evmCalldata: z.optional(z.string()),
|
|
314
|
+
intentHash: z.optional(z.string()),
|
|
315
|
+
logs: z.optional(z.unknown()),
|
|
316
|
+
manifest: z.optional(z.unknown()),
|
|
317
|
+
memo: z.optional(z.string()),
|
|
318
|
+
spender: z.optional(z.string()),
|
|
319
|
+
thorname: z.optional(z.string()),
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
export type TxnPayload = z.infer<typeof TxnPayloadSchema>;
|
|
323
|
+
|
|
324
|
+
const TransactionEstimatesSchema = object({
|
|
325
|
+
currentStage: string(),
|
|
326
|
+
inboundConfirmation: number(),
|
|
327
|
+
inboundObservation: number(),
|
|
328
|
+
outboundDelay: number(),
|
|
329
|
+
outboundObservation: number(),
|
|
330
|
+
streamingSwap: number(),
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
export type TransactionEstimates = z.infer<typeof TransactionEstimatesSchema>;
|
|
334
|
+
|
|
335
|
+
const TransactionStreamingDetailsSchema = object({
|
|
336
|
+
count: optional(number()),
|
|
337
|
+
interval: optional(number()),
|
|
338
|
+
quantity: optional(number()),
|
|
339
|
+
subSwapsMap: optional(array(number())),
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
export type TransactionStreamingDetails = z.infer<typeof TransactionStreamingDetailsSchema>;
|
|
343
|
+
|
|
344
|
+
const TxnTransientSchema = z.object({
|
|
345
|
+
currentLegIndex: z.optional(z.number()),
|
|
346
|
+
estimatedTimeToComplete: z.number(),
|
|
347
|
+
estimates: z.optional(TransactionEstimatesSchema),
|
|
348
|
+
providerDetails: z.optional(z.object({ streamingDetails: z.optional(TransactionStreamingDetailsSchema) })),
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
export type TxnTransient = z.infer<typeof TxnTransientSchema>;
|
|
352
|
+
|
|
353
|
+
const TransactionFeesSchema = object({
|
|
354
|
+
affiliate: optional(AssetValueSchema), // e.g. affiliate in memo, other affiliate mechanisms
|
|
355
|
+
liquidity: optional(AssetValueSchema), // fee paid to pool
|
|
356
|
+
network: optional(AssetValueSchema), // gas on ethereum, network fee on thorchain, etc.
|
|
357
|
+
protocol: optional(AssetValueSchema), // extra protocol fees (TS dex aggregation contracts, stargate fees, etc.)
|
|
358
|
+
tax: optional(AssetValueSchema), // taxed tokens
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
export type TransactionFees = z.infer<typeof TransactionFeesSchema>;
|
|
362
|
+
|
|
363
|
+
const TxnMetaAffiliateFeesSchema = object({ affiliate: string(), bps: string(), isReferrer: boolean() });
|
|
364
|
+
|
|
365
|
+
const TxnMetaSchema = object({
|
|
366
|
+
affiliate: optional(string()),
|
|
367
|
+
affiliateFees: optional(array(TxnMetaAffiliateFeesSchema)),
|
|
368
|
+
broadcastedAt: optional(number()),
|
|
369
|
+
explorerUrl: optional(string()),
|
|
370
|
+
fees: optional(TransactionFeesSchema),
|
|
371
|
+
images: optional(
|
|
372
|
+
object({
|
|
373
|
+
chain: optional(string()),
|
|
374
|
+
from: optional(string()),
|
|
375
|
+
provider: optional(string()),
|
|
376
|
+
to: optional(string()),
|
|
377
|
+
}),
|
|
378
|
+
),
|
|
379
|
+
provider: optional(z.enum(ProviderName)),
|
|
380
|
+
providerAction: z.optional(z.enum(ProviderAction)),
|
|
381
|
+
wallet: optional(string()),
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
export type TxnMeta = z.infer<typeof TxnMetaSchema>;
|
|
385
|
+
|
|
386
|
+
const TransactionLegDTOSchema = z.object({
|
|
387
|
+
block: z.number(),
|
|
388
|
+
chainId: z.enum(ChainId),
|
|
389
|
+
finalAddress: z.optional(z.string()),
|
|
390
|
+
finalAsset: z.optional(AssetValueSchema),
|
|
391
|
+
finalisedAt: z.number(),
|
|
392
|
+
fromAddress: z.string(),
|
|
393
|
+
fromAmount: z.string(),
|
|
394
|
+
fromAsset: z.string(),
|
|
395
|
+
hash: z.string(),
|
|
396
|
+
meta: z.optional(TxnMetaSchema),
|
|
397
|
+
payload: z.optional(TxnPayloadSchema),
|
|
398
|
+
status: z.enum(TxnStatus),
|
|
399
|
+
toAddress: z.string(),
|
|
400
|
+
toAmount: z.string(),
|
|
401
|
+
toAsset: z.string(),
|
|
402
|
+
trackingStatus: z.optional(z.enum(TrackingStatus)),
|
|
403
|
+
transient: z.optional(TxnTransientSchema),
|
|
404
|
+
type: z.enum(TxnType),
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
export type TransactionLegDTO = z.infer<typeof TransactionLegDTOSchema>;
|
|
408
|
+
|
|
409
|
+
export const TrackerResponseSchema: z.ZodType<TransactionDTO> = TransactionLegDTOSchema.extend({
|
|
410
|
+
legs: z.array(TransactionLegDTOSchema),
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
export type TrackerResponse = z.infer<typeof TrackerResponseSchema>;
|
|
414
|
+
|
|
415
|
+
export const TransactionSchema = TransactionLegDTOSchema.extend({ legs: array(TransactionLegDTOSchema) });
|
|
416
|
+
|
|
417
|
+
export type TransactionDTO = z.infer<typeof TransactionLegDTOSchema> & { legs: TransactionLegDTO[] };
|
|
418
|
+
|
|
419
|
+
export const TransactionDTOSchema: ZodType<TransactionDTO> = TransactionLegDTOSchema.extend({
|
|
420
|
+
legs: array(TransactionLegDTOSchema),
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
export const FeesSchema = array(
|
|
424
|
+
object({
|
|
425
|
+
amount: string(),
|
|
426
|
+
asset: string(),
|
|
427
|
+
chain: string(),
|
|
428
|
+
protocol: z.enum(ProviderName),
|
|
429
|
+
type: z.enum(FeeTypeEnum),
|
|
430
|
+
}),
|
|
431
|
+
);
|
|
432
|
+
|
|
433
|
+
export type Fees = z.infer<typeof FeesSchema>;
|
|
434
|
+
|
|
435
|
+
export const EstimatedTimeSchema = z.object({
|
|
436
|
+
inbound: z.optional(z.number().describe("Time to receive inbound asset in seconds")),
|
|
437
|
+
outbound: z.optional(z.number().describe("Time to receive outbound asset in seconds")),
|
|
438
|
+
swap: z.optional(z.number().describe("Time to swap assets in seconds")),
|
|
439
|
+
total: z.number().describe("Total time in seconds"),
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
export type EstimatedTime = z.infer<typeof EstimatedTimeSchema>;
|
|
443
|
+
|
|
444
|
+
export const EVMTransactionSchema = object({
|
|
445
|
+
data: string().describe("Data to send"),
|
|
446
|
+
from: string().describe("Address of the sender"),
|
|
447
|
+
to: string().describe("Address of the recipient"),
|
|
448
|
+
value: string().describe("Value to send"),
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
export type EVMTransaction = z.infer<typeof EVMTransactionSchema>;
|
|
452
|
+
|
|
453
|
+
export const EVMTransactionDetailsParamsSchema = array(
|
|
454
|
+
union([
|
|
455
|
+
string(),
|
|
456
|
+
number(),
|
|
457
|
+
array(string()),
|
|
458
|
+
object({ from: string(), value: string() }).describe("Parameters to pass to the contract method"),
|
|
459
|
+
]),
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
export type EVMTransactionDetailsParams = z.infer<typeof EVMTransactionDetailsParamsSchema>;
|
|
463
|
+
|
|
464
|
+
export const EVMTransactionDetailsSchema = object({
|
|
465
|
+
approvalSpender: optional(string().describe("Address of the spender to approve")),
|
|
466
|
+
approvalToken: optional(string().describe("Address of the token to approve spending of")),
|
|
467
|
+
contractAddress: string().describe("Address of the contract to interact with"),
|
|
468
|
+
contractMethod: string().describe("Name of the method to call"),
|
|
469
|
+
contractParamNames: array(string().describe("Names of the parameters to pass to the contract method")),
|
|
470
|
+
contractParams: EVMTransactionDetailsParamsSchema,
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
export type EVMTransactionDetails = z.infer<typeof EVMTransactionDetailsSchema>;
|
|
474
|
+
|
|
475
|
+
const EncodeObjectSchema = object({ typeUrl: string(), value: unknown() });
|
|
476
|
+
|
|
477
|
+
const FeeSchema = object({ amount: array(object({ amount: string(), denom: string() })), gas: string() });
|
|
478
|
+
|
|
479
|
+
export const CosmosTransactionSchema = object({
|
|
480
|
+
accountNumber: number(),
|
|
481
|
+
chainId: z.enum(ChainId),
|
|
482
|
+
fee: FeeSchema,
|
|
483
|
+
memo: string(),
|
|
484
|
+
msgs: array(EncodeObjectSchema),
|
|
485
|
+
sequence: number(),
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
export type CosmosTransaction = z.infer<typeof CosmosTransactionSchema>;
|
|
489
|
+
|
|
490
|
+
export const RouteLegSchema = object({
|
|
491
|
+
affiliate: string().describe("Affiliate address").optional(),
|
|
492
|
+
affiliateFee: number().describe("Affiliate fee").optional(),
|
|
493
|
+
buyAsset: string().describe("Asset to buy"),
|
|
494
|
+
destinationAddress: string().describe("Destination address"),
|
|
495
|
+
estimatedTime: EstimatedTimeSchema.optional(),
|
|
496
|
+
provider: z.enum(ProviderName),
|
|
497
|
+
sellAsset: string().describe("Asset to sell"),
|
|
498
|
+
slipPercentage: number().describe("Slippage as a percentage"),
|
|
499
|
+
sourceAddress: string().describe("Source address"),
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
export type RouteLeg = z.infer<typeof RouteLegSchema>;
|
|
503
|
+
|
|
504
|
+
export const RouteLegWithoutAddressesSchema = RouteLegSchema.omit({
|
|
505
|
+
destinationAddress: true,
|
|
506
|
+
slipPercentage: true,
|
|
507
|
+
sourceAddress: true,
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
export type RouteLegWithoutAddresses = z.infer<typeof RouteLegWithoutAddressesSchema>;
|
|
511
|
+
|
|
512
|
+
export const RouteQuoteMetadataAssetSchema = object({
|
|
513
|
+
asset: string().describe("Asset name"),
|
|
514
|
+
image: string().describe("Asset image"),
|
|
515
|
+
price: number().describe("Price in USD"),
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
export type RouteQuoteMetadataAsset = z.infer<typeof RouteQuoteMetadataAssetSchema>;
|
|
519
|
+
|
|
520
|
+
export const ChainflipMetadataSchema = BrokerDepositChannelParamsSchema;
|
|
521
|
+
|
|
522
|
+
export type ChainflipMetadata = z.infer<typeof ChainflipMetadataSchema>;
|
|
523
|
+
|
|
524
|
+
export const RouteQuoteMetadataSchema = object({
|
|
525
|
+
assets: optional(array(RouteQuoteMetadataAssetSchema)),
|
|
526
|
+
maxStreamingQuantity: number().optional(),
|
|
527
|
+
referrer: string().optional(),
|
|
528
|
+
streamingInterval: number().optional(),
|
|
529
|
+
tags: array(z.enum(PriorityLabel)).optional(),
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
export const RouteQuoteMetadataV2Schema = RouteQuoteMetadataSchema.extend({
|
|
533
|
+
affiliate: optional(string()),
|
|
534
|
+
affiliateFee: optional(string()),
|
|
535
|
+
approvalAddress: optional(string().describe("Approval address for swap")),
|
|
536
|
+
chainflip: ChainflipMetadataSchema.optional(),
|
|
537
|
+
garden: NearDepositChannelParamsSchema.optional(),
|
|
538
|
+
near: NearDepositChannelParamsSchema.optional(),
|
|
539
|
+
priceImpact: optional(number().describe("Price impact")),
|
|
540
|
+
referrer: optional(string()),
|
|
541
|
+
txType: optional(z.enum(RouteQuoteTxType)),
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
export const RouteQuoteWarningSchema = array(
|
|
545
|
+
object({ code: z.enum(WarningCodeEnum), display: string(), tooltip: string().optional() }),
|
|
546
|
+
);
|
|
547
|
+
|
|
548
|
+
export type RouteQuoteWarning = z.infer<typeof RouteQuoteWarningSchema>;
|
|
549
|
+
|
|
550
|
+
const QuoteResponseRouteLegItem = object({
|
|
551
|
+
buyAmount: string().describe("Buy amount"),
|
|
552
|
+
buyAmountMaxSlippage: string().describe("Buy amount max slippage"),
|
|
553
|
+
buyAsset: string().describe("Asset to buy"),
|
|
554
|
+
fees: optional(FeesSchema),
|
|
555
|
+
provider: z.enum(ProviderName),
|
|
556
|
+
sellAmount: string().describe("Sell amount"),
|
|
557
|
+
sellAsset: string().describe("Asset to sell"),
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
export const QuoteResponseRouteItem = object({
|
|
561
|
+
buyAsset: string().describe("Asset to buy"),
|
|
562
|
+
destinationAddress: optional(string().describe("Destination address")),
|
|
563
|
+
estimatedTime: optional(EstimatedTimeSchema),
|
|
564
|
+
expectedBuyAmount: string().describe("Expected Buy amount"),
|
|
565
|
+
expectedBuyAmountMaxSlippage: optional(string().describe("Expected Buy amount max slippage")),
|
|
566
|
+
expiration: optional(string().describe("Expiration")),
|
|
567
|
+
fees: FeesSchema,
|
|
568
|
+
inboundAddress: optional(string().describe("Inbound address")),
|
|
569
|
+
legs: optional(array(QuoteResponseRouteLegItem)),
|
|
570
|
+
memo: optional(string().describe("Memo")),
|
|
571
|
+
meta: optional(RouteQuoteMetadataV2Schema),
|
|
572
|
+
providers: array(z.enum(ProviderName)),
|
|
573
|
+
refundAddress: optional(string().describe("Refund address")),
|
|
574
|
+
sellAmount: string().describe("Sell amount"),
|
|
575
|
+
sellAsset: string().describe("Asset to sell"),
|
|
576
|
+
sourceAddress: optional(string().describe("Source address")),
|
|
577
|
+
targetAddress: optional(string().describe("Target address")),
|
|
578
|
+
tx: optional(union([EVMTransactionSchema, CosmosTransactionSchema, string()])),
|
|
579
|
+
txType: optional(z.enum(RouteQuoteTxType)),
|
|
580
|
+
warnings: optional(RouteQuoteWarningSchema),
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
export const QuoteResponseSchema = object({
|
|
584
|
+
error: optional(string().describe("Error message")),
|
|
585
|
+
providerErrors: optional(
|
|
586
|
+
array(
|
|
587
|
+
object({
|
|
588
|
+
errorCode: optional(z.enum(ErrorCode)),
|
|
589
|
+
message: optional(string()),
|
|
590
|
+
provider: z.enum(ProviderName).optional(),
|
|
591
|
+
}),
|
|
592
|
+
),
|
|
593
|
+
),
|
|
594
|
+
routes: array(QuoteResponseRouteItem),
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
export type QuoteResponse = z.infer<typeof QuoteResponseSchema>;
|
|
598
|
+
export type QuoteResponseRoute = z.infer<typeof QuoteResponseRouteItem>;
|
|
599
|
+
export type QuoteResponseRouteLeg = z.infer<typeof QuoteResponseRouteLegItem>;
|
|
600
|
+
|
|
601
|
+
export const GasSchema = z.object({
|
|
602
|
+
chainId: z.enum(ChainId),
|
|
603
|
+
createdAt: z.date(),
|
|
604
|
+
id: z.number(),
|
|
605
|
+
unit: z.string(),
|
|
606
|
+
value: z.string(),
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
const GasSchemaArray = z.array(GasSchema);
|
|
610
|
+
|
|
611
|
+
export const GasResponseSchema = z.union([GasSchema, GasSchemaArray]);
|
|
612
|
+
|
|
613
|
+
export type GasResponse = z.infer<typeof GasResponseSchema>;
|
|
614
|
+
|
|
615
|
+
const BalanceResponseSchema = array(
|
|
616
|
+
object({
|
|
617
|
+
chain: z.enum(Chain),
|
|
618
|
+
decimal: number(),
|
|
619
|
+
identifier: string(),
|
|
620
|
+
symbol: string(),
|
|
621
|
+
ticker: string(),
|
|
622
|
+
value: string(),
|
|
623
|
+
}),
|
|
624
|
+
);
|
|
625
|
+
|
|
626
|
+
export type BalanceResponse = z.infer<typeof BalanceResponseSchema>;
|
package/src/contracts.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@tcswap/contracts";
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * from "@tcswap/tokens";
|
|
6
|
+
export * from "@tcswap/types";
|
|
7
|
+
/**
|
|
8
|
+
* Modules
|
|
9
|
+
*/
|
|
10
|
+
export * from "./modules/assetValue";
|
|
11
|
+
export * from "./modules/bigIntArithmetics";
|
|
12
|
+
export * from "./modules/feeMultiplier";
|
|
13
|
+
export * from "./modules/requestClient";
|
|
14
|
+
export * from "./modules/uSwapConfig";
|
|
15
|
+
export * from "./modules/uSwapError";
|
|
16
|
+
export * from "./modules/uSwapNumber";
|
|
17
|
+
/**
|
|
18
|
+
* Types
|
|
19
|
+
*/
|
|
20
|
+
export * from "./types";
|
|
21
|
+
/**
|
|
22
|
+
* Utils
|
|
23
|
+
*/
|
|
24
|
+
export * from "./utils/asset";
|
|
25
|
+
export * from "./utils/chains";
|
|
26
|
+
export * from "./utils/derivationPath";
|
|
27
|
+
export * from "./utils/explorerUrls";
|
|
28
|
+
export * from "./utils/liquidity";
|
|
29
|
+
export * from "./utils/memo";
|
|
30
|
+
export * from "./utils/others";
|
|
31
|
+
export * from "./utils/validators";
|
|
32
|
+
export * from "./utils/wallets";
|