@chainflip/redis 1.0.2-wbtc-dev.2 → 2.1.0-beta.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.
@@ -0,0 +1,114 @@
1
+ import { transformKeysToCamelCase } from "./utils.js";
2
+ import { reverseBytes } from "@chainflip/utils/bytes";
3
+ import { getInternalAsset, isValidAssetAndChain } from "@chainflip/utils/chainflip";
4
+ import * as ss58 from "@chainflip/utils/ss58";
5
+ import { CHAINFLIP_SS58_PREFIX } from "@chainflip/utils/consts";
6
+ import { hexEncodeNumber } from "@chainflip/utils/number";
7
+ import { z } from "zod";
8
+
9
+ //#region src/parsers.ts
10
+ const assetAndChain = z.object({
11
+ asset: z.string(),
12
+ chain: z.string()
13
+ }).refine((value) => isValidAssetAndChain(value), (value) => ({ message: `Invalid asset and chain : ${value.asset} on ${value.chain}` })).transform((value) => getInternalAsset(value));
14
+ const numericString = z.string().regex(/^[0-9]+$/);
15
+ const hexString = z.string().refine((v) => /^0x[0-9a-f]*$/i.test(v));
16
+ const u128 = z.union([
17
+ z.number(),
18
+ numericString,
19
+ hexString
20
+ ]).transform((arg) => BigInt(arg));
21
+ const chainflipAddress = z.string().refine((address) => ss58.decode(address).ss58Format === CHAINFLIP_SS58_PREFIX, (address) => ({ message: `${address} is not a valid Chainflip address` }));
22
+ const jsonString = z.string().transform((value) => JSON.parse(value));
23
+ const bitcoinDeposit = z.object({
24
+ tx_id: hexString.transform((value) => reverseBytes(value).slice(2)),
25
+ vout: z.number().int()
26
+ }).transform((obj) => ({
27
+ ...obj,
28
+ type: "Bitcoin"
29
+ }));
30
+ const evmDeposit = z.object({ tx_hashes: z.array(hexString) }).transform((obj) => ({
31
+ ...obj,
32
+ type: "EVM"
33
+ }));
34
+ const assethubDeposit = z.object({ extrinsic_index: z.number() }).transform((obj) => ({
35
+ ...obj,
36
+ type: "Assethub"
37
+ }));
38
+ const depositSchema = jsonString.pipe(z.object({
39
+ amount: u128,
40
+ asset: assetAndChain,
41
+ deposit_chain_block_height: z.number(),
42
+ deposit_details: z.union([
43
+ evmDeposit,
44
+ bitcoinDeposit,
45
+ assethubDeposit
46
+ ]).nullable()
47
+ }));
48
+ const broadcastParsers = {
49
+ Ethereum: z.object({
50
+ tx_out_id: z.object({ signature: z.object({
51
+ k_times_g_address: z.array(z.number()),
52
+ s: z.array(z.number())
53
+ }) }),
54
+ tx_ref: z.object({ hash: hexString }).transform(({ hash }) => hash)
55
+ }),
56
+ Assethub: z.object({
57
+ tx_out_id: z.object({ signature: z.string() }),
58
+ tx_ref: z.object({ transaction_id: z.object({
59
+ block_number: z.number(),
60
+ extrinsic_index: z.number()
61
+ }) }).transform(({ transaction_id }) => `${transaction_id.block_number}-${transaction_id.extrinsic_index}`)
62
+ }),
63
+ Bitcoin: z.object({
64
+ tx_out_id: z.object({ hash: z.string() }),
65
+ tx_ref: z.object({ hash: z.string().transform((value) => value.startsWith("0x") ? value.slice(2) : value) }).transform(({ hash }) => hash)
66
+ }),
67
+ Arbitrum: z.object({
68
+ tx_out_id: z.object({ signature: z.object({
69
+ k_times_g_address: z.array(z.number()),
70
+ s: z.array(z.number())
71
+ }) }),
72
+ tx_ref: z.object({ hash: hexString }).transform(({ hash }) => hash)
73
+ })
74
+ };
75
+ const accountFee = z.object({
76
+ account: chainflipAddress,
77
+ bps: z.number()
78
+ }).transform(({ account, bps }) => ({
79
+ account,
80
+ commissionBps: bps
81
+ }));
82
+ const vaultDepositSchema = jsonString.pipe(z.object({
83
+ amount: u128,
84
+ destination_address: z.string(),
85
+ input_asset: assetAndChain,
86
+ output_asset: assetAndChain,
87
+ deposit_chain_block_height: z.number().nullable().optional(),
88
+ affiliate_fees: z.array(accountFee),
89
+ broker_fee: accountFee.optional(),
90
+ max_boost_fee: z.number().optional(),
91
+ dca_params: z.object({
92
+ chunk_interval: z.number(),
93
+ number_of_chunks: z.number()
94
+ }).nullable().optional(),
95
+ refund_params: z.object({
96
+ min_price: u128,
97
+ retry_duration: z.number(),
98
+ refund_address: z.string()
99
+ }).nullable().optional(),
100
+ ccm_deposit_metadata: z.object({ channel_metadata: z.object({
101
+ ccm_additional_data: z.any(),
102
+ message: z.string(),
103
+ gas_budget: z.union([numericString, hexString]).transform((n) => hexEncodeNumber(BigInt(n)))
104
+ }) }).nullable().optional()
105
+ }).transform(transformKeysToCamelCase));
106
+ const mempoolTransaction = jsonString.pipe(z.object({
107
+ confirmations: z.number(),
108
+ value: u128,
109
+ tx_hash: z.string(),
110
+ deposit_chain_block_height: z.number().optional()
111
+ }));
112
+
113
+ //#endregion
114
+ export { broadcastParsers, depositSchema, mempoolTransaction, vaultDepositSchema };
package/dist/utils.cjs ADDED
@@ -0,0 +1,12 @@
1
+
2
+ //#region src/utils.ts
3
+ const snakeToCamelCase = (str) => str.replace(/_(.)/g, (match, group) => group.toUpperCase());
4
+ const transformKeysToCamelCase = (obj) => {
5
+ if (obj == null || typeof obj !== "object") return obj;
6
+ if (Array.isArray(obj)) return obj.map(transformKeysToCamelCase);
7
+ return Object.fromEntries(Object.entries(obj).map(([key, value]) => [snakeToCamelCase(key), transformKeysToCamelCase(value)]));
8
+ };
9
+
10
+ //#endregion
11
+ exports.snakeToCamelCase = snakeToCamelCase;
12
+ exports.transformKeysToCamelCase = transformKeysToCamelCase;
@@ -0,0 +1,7 @@
1
+ //#region src/utils.d.ts
2
+ type SnakeToCamelCase<T extends string> = T extends `${infer P}_${infer S}` ? `${P}${Capitalize<SnakeToCamelCase<S>>}` : T;
3
+ declare const snakeToCamelCase: <const T extends string>(str: T) => SnakeToCamelCase<T>;
4
+ type CamelCasedKeys<T> = T extends Record<string, unknown> ? { [K in keyof T as K extends string ? SnakeToCamelCase<K> : K]: CamelCasedKeys<T[K]> } : T extends (infer U)[] ? CamelCasedKeys<U>[] : T;
5
+ declare const transformKeysToCamelCase: <T>(obj: T) => CamelCasedKeys<T>;
6
+ //#endregion
7
+ export { snakeToCamelCase, transformKeysToCamelCase };
package/dist/utils.js ADDED
@@ -0,0 +1,10 @@
1
+ //#region src/utils.ts
2
+ const snakeToCamelCase = (str) => str.replace(/_(.)/g, (match, group) => group.toUpperCase());
3
+ const transformKeysToCamelCase = (obj) => {
4
+ if (obj == null || typeof obj !== "object") return obj;
5
+ if (Array.isArray(obj)) return obj.map(transformKeysToCamelCase);
6
+ return Object.fromEntries(Object.entries(obj).map(([key, value]) => [snakeToCamelCase(key), transformKeysToCamelCase(value)]));
7
+ };
8
+
9
+ //#endregion
10
+ export { snakeToCamelCase, transformKeysToCamelCase };
package/package.json CHANGED
@@ -1,19 +1,7 @@
1
1
  {
2
2
  "name": "@chainflip/redis",
3
- "version": "1.0.2-wbtc-dev.2",
3
+ "version": "2.1.0-beta.0",
4
4
  "type": "module",
5
- "scripts": {
6
- "eslint:check": "pnpm eslint --max-warnings 0 './**/*.ts'",
7
- "prettier:base": "prettier ./** --ignore-path=../../.prettierignore",
8
- "prettier:check": "pnpm prettier:base --check",
9
- "prettier:write": "pnpm prettier:base --write",
10
- "prepublish": "pnpm build && pnpm test run",
11
- "clean": "rm -rf dist",
12
- "tsup:build": "tsup ./src/index.ts --format esm,cjs --dts --treeshake",
13
- "build": "pnpm clean && pnpm tsup:build",
14
- "test:ci": "CI=1 pnpm t run",
15
- "test": "vitest"
16
- },
17
5
  "repository": "https://github.com/chainflip-io/chainflip-product-toolkit.git",
18
6
  "publishConfig": {
19
7
  "registry": "https://registry.npmjs.org/",
@@ -26,7 +14,7 @@
26
14
  "exports": {
27
15
  ".": {
28
16
  "require": {
29
- "types": "./dist/index.d.cts",
17
+ "types": "./dist/index.d.ts",
30
18
  "default": "./dist/index.cjs"
31
19
  },
32
20
  "import": {
@@ -38,7 +26,17 @@
38
26
  "dependencies": {
39
27
  "@chainflip/utils": "0.11.2-wbtc-dev.2",
40
28
  "bignumber.js": "^9.3.1",
41
- "ioredis": "^5.8.2",
29
+ "ioredis": "^5.9.2",
42
30
  "zod": "^3.25.75"
31
+ },
32
+ "scripts": {
33
+ "eslint:check": "pnpm eslint --max-warnings 0 './**/*.ts'",
34
+ "prettier:base": "prettier ./** --ignore-path=../../.prettierignore",
35
+ "prettier:check": "pnpm prettier:base --check",
36
+ "prettier:write": "pnpm prettier:base --write",
37
+ "prepublish": "pnpm build && pnpm test run",
38
+ "build": "tsdown",
39
+ "test:ci": "CI=1 pnpm t run",
40
+ "test": "vitest"
43
41
  }
44
- }
42
+ }
package/dist/index.d.cts DELETED
@@ -1,336 +0,0 @@
1
- import { ChainflipChain, ChainflipAsset, AssetAndChain } from '@chainflip/utils/chainflip';
2
- import { z } from 'zod';
3
-
4
- declare const depositSchema: z.ZodPipeline<z.ZodEffects<z.ZodString, unknown, string>, z.ZodObject<{
5
- amount: z.ZodEffects<z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodEffects<z.ZodString, `0x${string}`, string>]>, bigint, string | number>;
6
- asset: z.ZodEffects<z.ZodEffects<z.ZodObject<{
7
- asset: z.ZodString;
8
- chain: z.ZodString;
9
- }, "strip", z.ZodTypeAny, {
10
- asset: string;
11
- chain: string;
12
- }, {
13
- asset: string;
14
- chain: string;
15
- }>, AssetAndChain, {
16
- asset: string;
17
- chain: string;
18
- }>, "Usdc" | "Usdt" | "Wbtc" | "Flip" | "Eth" | "Dot" | "Btc" | "ArbUsdc" | "ArbUsdt" | "ArbEth" | "Sol" | "SolUsdc" | "SolUsdt" | "HubDot" | "HubUsdt" | "HubUsdc", {
19
- asset: string;
20
- chain: string;
21
- }>;
22
- deposit_chain_block_height: z.ZodNumber;
23
- deposit_details: z.ZodNullable<z.ZodUnion<[z.ZodEffects<z.ZodObject<{
24
- tx_hashes: z.ZodArray<z.ZodEffects<z.ZodString, `0x${string}`, string>, "many">;
25
- }, "strip", z.ZodTypeAny, {
26
- tx_hashes: `0x${string}`[];
27
- }, {
28
- tx_hashes: string[];
29
- }>, {
30
- type: "EVM";
31
- tx_hashes: `0x${string}`[];
32
- }, {
33
- tx_hashes: string[];
34
- }>, z.ZodEffects<z.ZodObject<{
35
- tx_id: z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, string, string>;
36
- vout: z.ZodNumber;
37
- }, "strip", z.ZodTypeAny, {
38
- tx_id: string;
39
- vout: number;
40
- }, {
41
- tx_id: string;
42
- vout: number;
43
- }>, {
44
- type: "Bitcoin";
45
- tx_id: string;
46
- vout: number;
47
- }, {
48
- tx_id: string;
49
- vout: number;
50
- }>, z.ZodEffects<z.ZodObject<{
51
- extrinsic_index: z.ZodNumber;
52
- }, "strip", z.ZodTypeAny, {
53
- extrinsic_index: number;
54
- }, {
55
- extrinsic_index: number;
56
- }>, {
57
- type: "Assethub";
58
- extrinsic_index: number;
59
- }, {
60
- extrinsic_index: number;
61
- }>]>>;
62
- }, "strip", z.ZodTypeAny, {
63
- asset: "Usdc" | "Usdt" | "Wbtc" | "Flip" | "Eth" | "Dot" | "Btc" | "ArbUsdc" | "ArbUsdt" | "ArbEth" | "Sol" | "SolUsdc" | "SolUsdt" | "HubDot" | "HubUsdt" | "HubUsdc";
64
- amount: bigint;
65
- deposit_chain_block_height: number;
66
- deposit_details: {
67
- type: "Bitcoin";
68
- tx_id: string;
69
- vout: number;
70
- } | {
71
- type: "EVM";
72
- tx_hashes: `0x${string}`[];
73
- } | {
74
- type: "Assethub";
75
- extrinsic_index: number;
76
- } | null;
77
- }, {
78
- asset: {
79
- asset: string;
80
- chain: string;
81
- };
82
- amount: string | number;
83
- deposit_chain_block_height: number;
84
- deposit_details: {
85
- tx_id: string;
86
- vout: number;
87
- } | {
88
- tx_hashes: string[];
89
- } | {
90
- extrinsic_index: number;
91
- } | null;
92
- }>>;
93
- type PendingDeposit = Omit<z.output<typeof depositSchema>, 'deposit_details'> & {
94
- tx_refs: string[];
95
- };
96
- declare const broadcastParsers: {
97
- readonly Ethereum: z.ZodObject<{
98
- tx_out_id: z.ZodObject<{
99
- signature: z.ZodObject<{
100
- k_times_g_address: z.ZodArray<z.ZodNumber, "many">;
101
- s: z.ZodArray<z.ZodNumber, "many">;
102
- }, "strip", z.ZodTypeAny, {
103
- k_times_g_address: number[];
104
- s: number[];
105
- }, {
106
- k_times_g_address: number[];
107
- s: number[];
108
- }>;
109
- }, "strip", z.ZodTypeAny, {
110
- signature: {
111
- k_times_g_address: number[];
112
- s: number[];
113
- };
114
- }, {
115
- signature: {
116
- k_times_g_address: number[];
117
- s: number[];
118
- };
119
- }>;
120
- tx_ref: z.ZodEffects<z.ZodObject<{
121
- hash: z.ZodEffects<z.ZodString, `0x${string}`, string>;
122
- }, "strip", z.ZodTypeAny, {
123
- hash: `0x${string}`;
124
- }, {
125
- hash: string;
126
- }>, `0x${string}`, {
127
- hash: string;
128
- }>;
129
- }, "strip", z.ZodTypeAny, {
130
- tx_out_id: {
131
- signature: {
132
- k_times_g_address: number[];
133
- s: number[];
134
- };
135
- };
136
- tx_ref: `0x${string}`;
137
- }, {
138
- tx_out_id: {
139
- signature: {
140
- k_times_g_address: number[];
141
- s: number[];
142
- };
143
- };
144
- tx_ref: {
145
- hash: string;
146
- };
147
- }>;
148
- readonly Assethub: z.ZodObject<{
149
- tx_out_id: z.ZodObject<{
150
- signature: z.ZodString;
151
- }, "strip", z.ZodTypeAny, {
152
- signature: string;
153
- }, {
154
- signature: string;
155
- }>;
156
- tx_ref: z.ZodEffects<z.ZodObject<{
157
- transaction_id: z.ZodObject<{
158
- block_number: z.ZodNumber;
159
- extrinsic_index: z.ZodNumber;
160
- }, "strip", z.ZodTypeAny, {
161
- extrinsic_index: number;
162
- block_number: number;
163
- }, {
164
- extrinsic_index: number;
165
- block_number: number;
166
- }>;
167
- }, "strip", z.ZodTypeAny, {
168
- transaction_id: {
169
- extrinsic_index: number;
170
- block_number: number;
171
- };
172
- }, {
173
- transaction_id: {
174
- extrinsic_index: number;
175
- block_number: number;
176
- };
177
- }>, string, {
178
- transaction_id: {
179
- extrinsic_index: number;
180
- block_number: number;
181
- };
182
- }>;
183
- }, "strip", z.ZodTypeAny, {
184
- tx_out_id: {
185
- signature: string;
186
- };
187
- tx_ref: string;
188
- }, {
189
- tx_out_id: {
190
- signature: string;
191
- };
192
- tx_ref: {
193
- transaction_id: {
194
- extrinsic_index: number;
195
- block_number: number;
196
- };
197
- };
198
- }>;
199
- readonly Bitcoin: z.ZodObject<{
200
- tx_out_id: z.ZodObject<{
201
- hash: z.ZodString;
202
- }, "strip", z.ZodTypeAny, {
203
- hash: string;
204
- }, {
205
- hash: string;
206
- }>;
207
- tx_ref: z.ZodEffects<z.ZodObject<{
208
- hash: z.ZodEffects<z.ZodString, string, string>;
209
- }, "strip", z.ZodTypeAny, {
210
- hash: string;
211
- }, {
212
- hash: string;
213
- }>, string, {
214
- hash: string;
215
- }>;
216
- }, "strip", z.ZodTypeAny, {
217
- tx_out_id: {
218
- hash: string;
219
- };
220
- tx_ref: string;
221
- }, {
222
- tx_out_id: {
223
- hash: string;
224
- };
225
- tx_ref: {
226
- hash: string;
227
- };
228
- }>;
229
- readonly Arbitrum: z.ZodObject<{
230
- tx_out_id: z.ZodObject<{
231
- signature: z.ZodObject<{
232
- k_times_g_address: z.ZodArray<z.ZodNumber, "many">;
233
- s: z.ZodArray<z.ZodNumber, "many">;
234
- }, "strip", z.ZodTypeAny, {
235
- k_times_g_address: number[];
236
- s: number[];
237
- }, {
238
- k_times_g_address: number[];
239
- s: number[];
240
- }>;
241
- }, "strip", z.ZodTypeAny, {
242
- signature: {
243
- k_times_g_address: number[];
244
- s: number[];
245
- };
246
- }, {
247
- signature: {
248
- k_times_g_address: number[];
249
- s: number[];
250
- };
251
- }>;
252
- tx_ref: z.ZodEffects<z.ZodObject<{
253
- hash: z.ZodEffects<z.ZodString, `0x${string}`, string>;
254
- }, "strip", z.ZodTypeAny, {
255
- hash: `0x${string}`;
256
- }, {
257
- hash: string;
258
- }>, `0x${string}`, {
259
- hash: string;
260
- }>;
261
- }, "strip", z.ZodTypeAny, {
262
- tx_out_id: {
263
- signature: {
264
- k_times_g_address: number[];
265
- s: number[];
266
- };
267
- };
268
- tx_ref: `0x${string}`;
269
- }, {
270
- tx_out_id: {
271
- signature: {
272
- k_times_g_address: number[];
273
- s: number[];
274
- };
275
- };
276
- tx_ref: {
277
- hash: string;
278
- };
279
- }>;
280
- };
281
- type ChainBroadcast<C extends Exclude<ChainflipChain, 'Solana' | 'Polkadot'>> = z.infer<(typeof broadcastParsers)[C]>;
282
- type EthereumBroadcast = ChainBroadcast<'Ethereum'>;
283
- type AssethubBroadcast = ChainBroadcast<'Assethub'>;
284
- type BitcoinBroadcast = ChainBroadcast<'Bitcoin'>;
285
- type Broadcast = ChainBroadcast<Exclude<ChainflipChain, 'Solana' | 'Polkadot'>>;
286
- declare class RedisClient {
287
- private client;
288
- constructor(url: `redis://${string}` | `rediss://${string}`);
289
- getBroadcast(chain: 'Ethereum', broadcastId: number | bigint): Promise<EthereumBroadcast | null>;
290
- getBroadcast(chain: 'Assethub', broadcastId: number | bigint): Promise<AssethubBroadcast | null>;
291
- getBroadcast(chain: 'Bitcoin', broadcastId: number | bigint): Promise<BitcoinBroadcast | null>;
292
- getBroadcast(chain: 'Arbitrum', broadcastId: number | bigint): Promise<EthereumBroadcast | null>;
293
- getBroadcast(chain: ChainflipChain, broadcastId: number | bigint): Promise<Broadcast | null>;
294
- getDeposits(asset: ChainflipAsset, address: string): Promise<PendingDeposit[]>;
295
- getMempoolTransaction(chain: 'Bitcoin', address: string): Promise<{
296
- value: bigint;
297
- confirmations: number;
298
- tx_hash: string;
299
- deposit_chain_block_height?: number | undefined;
300
- } | null>;
301
- getPendingVaultSwap(chain: ChainflipChain, txId: string): Promise<{
302
- amount: bigint;
303
- destinationAddress: string;
304
- inputAsset: "Usdc" | "Usdt" | "Wbtc" | "Flip" | "Eth" | "Dot" | "Btc" | "ArbUsdc" | "ArbUsdt" | "ArbEth" | "Sol" | "SolUsdc" | "SolUsdt" | "HubDot" | "HubUsdt" | "HubUsdc";
305
- outputAsset: "Usdc" | "Usdt" | "Wbtc" | "Flip" | "Eth" | "Dot" | "Btc" | "ArbUsdc" | "ArbUsdt" | "ArbEth" | "Sol" | "SolUsdc" | "SolUsdt" | "HubDot" | "HubUsdt" | "HubUsdc";
306
- affiliateFees: {
307
- account: string;
308
- commissionBps: number;
309
- }[];
310
- depositChainBlockHeight?: number | null | undefined;
311
- brokerFee?: {
312
- account: string;
313
- commissionBps: number;
314
- } | undefined;
315
- maxBoostFee?: number | undefined;
316
- dcaParams?: {
317
- chunkInterval: number;
318
- numberOfChunks: number;
319
- } | null | undefined;
320
- refundParams?: {
321
- minPrice: bigint;
322
- retryDuration: number;
323
- refundAddress: string;
324
- } | null | undefined;
325
- ccmDepositMetadata?: {
326
- channelMetadata: {
327
- message: string;
328
- gasBudget: `0x${string}`;
329
- ccmAdditionalData?: any;
330
- };
331
- } | null | undefined;
332
- } | null>;
333
- quit(): Promise<"OK">;
334
- }
335
-
336
- export { RedisClient as default };