@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.
package/dist/index.d.ts CHANGED
@@ -1,336 +1,54 @@
1
- import { ChainflipChain, ChainflipAsset, AssetAndChain } from '@chainflip/utils/chainflip';
2
- import { z } from 'zod';
1
+ import { AssethubBroadcast, BitcoinBroadcast, Broadcast, EthereumBroadcast, PendingDeposit } from "./parsers.js";
2
+ import { ChainflipAsset, ChainflipChain } from "@chainflip/utils/chainflip";
3
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'>>;
4
+ //#region src/index.d.ts
286
5
  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">;
6
+ private client;
7
+ constructor(url: `redis://${string}` | `rediss://${string}`);
8
+ getBroadcast(chain: 'Ethereum', broadcastId: number | bigint): Promise<EthereumBroadcast | null>;
9
+ getBroadcast(chain: 'Assethub', broadcastId: number | bigint): Promise<AssethubBroadcast | null>;
10
+ getBroadcast(chain: 'Bitcoin', broadcastId: number | bigint): Promise<BitcoinBroadcast | null>;
11
+ getBroadcast(chain: 'Arbitrum', broadcastId: number | bigint): Promise<EthereumBroadcast | null>;
12
+ getBroadcast(chain: ChainflipChain, broadcastId: number | bigint): Promise<Broadcast | null>;
13
+ getDeposits(asset: ChainflipAsset, address: string): Promise<PendingDeposit[]>;
14
+ getMempoolTransaction(chain: 'Bitcoin', address: string): Promise<{
15
+ value: bigint;
16
+ confirmations: number;
17
+ tx_hash: string;
18
+ deposit_chain_block_height?: number | undefined;
19
+ } | null>;
20
+ getPendingVaultSwap(chain: ChainflipChain, txId: string): Promise<{
21
+ amount: bigint;
22
+ destinationAddress: string;
23
+ inputAsset: "Usdc" | "Usdt" | "Wbtc" | "Flip" | "Eth" | "Dot" | "Btc" | "ArbUsdc" | "ArbUsdt" | "ArbEth" | "Sol" | "SolUsdc" | "SolUsdt" | "HubDot" | "HubUsdt" | "HubUsdc";
24
+ outputAsset: "Usdc" | "Usdt" | "Wbtc" | "Flip" | "Eth" | "Dot" | "Btc" | "ArbUsdc" | "ArbUsdt" | "ArbEth" | "Sol" | "SolUsdc" | "SolUsdt" | "HubDot" | "HubUsdt" | "HubUsdc";
25
+ affiliateFees: {
26
+ account: string;
27
+ commissionBps: number;
28
+ }[];
29
+ depositChainBlockHeight?: number | null | undefined;
30
+ brokerFee?: {
31
+ account: string;
32
+ commissionBps: number;
33
+ } | undefined;
34
+ maxBoostFee?: number | undefined;
35
+ dcaParams?: {
36
+ chunkInterval: number;
37
+ numberOfChunks: number;
38
+ } | null | undefined;
39
+ refundParams?: {
40
+ minPrice: bigint;
41
+ retryDuration: number;
42
+ refundAddress: string;
43
+ } | null | undefined;
44
+ ccmDepositMetadata?: {
45
+ channelMetadata: {
46
+ message: string;
47
+ gasBudget: `0x${string}`;
48
+ ccmAdditionalData?: any;
49
+ };
50
+ } | null | undefined;
51
+ } | null>;
52
+ quit(): Promise<"OK">;
334
53
  }
335
-
336
- export { RedisClient as default };
54
+ export = RedisClient;
package/dist/index.js CHANGED
@@ -1,190 +1,65 @@
1
- import { reverseBytes } from '@chainflip/utils/bytes';
2
- import { isValidAssetAndChain, getInternalAsset, assetConstants } from '@chainflip/utils/chainflip';
3
- import { CHAINFLIP_SS58_PREFIX } from '@chainflip/utils/consts';
4
- import { hexEncodeNumber } from '@chainflip/utils/number';
5
- import * as ss58 from '@chainflip/utils/ss58';
6
- import { isHex } from '@chainflip/utils/string';
7
- import assert from 'assert';
8
- import Redis from 'ioredis';
9
- import { z } from 'zod';
1
+ import { broadcastParsers, depositSchema, mempoolTransaction, vaultDepositSchema } from "./parsers.js";
2
+ import { reverseBytes } from "@chainflip/utils/bytes";
3
+ import { assetConstants } from "@chainflip/utils/chainflip";
4
+ import * as ss58 from "@chainflip/utils/ss58";
5
+ import { isHex } from "@chainflip/utils/string";
6
+ import assert from "assert";
7
+ import Redis from "ioredis";
10
8
 
11
- // src/index.ts
12
-
13
- // src/utils.ts
14
- var snakeToCamelCase = (str) => str.replace(/_(.)/g, (match, group) => group.toUpperCase());
15
- var transformKeysToCamelCase = (obj) => {
16
- if (obj == null || typeof obj !== "object") return obj;
17
- if (Array.isArray(obj)) return obj.map(transformKeysToCamelCase);
18
- return Object.fromEntries(
19
- Object.entries(obj).map(([key, value]) => [
20
- snakeToCamelCase(key),
21
- transformKeysToCamelCase(value)
22
- ])
23
- );
24
- };
25
-
26
- // src/index.ts
27
- var uncheckedAssetAndChain = z.object({
28
- asset: z.string(),
29
- chain: z.string()
30
- });
31
- var assetAndChain = uncheckedAssetAndChain.refine(
32
- (value) => isValidAssetAndChain(value),
33
- (value) => ({ message: `Invalid asset and chain : ${value.asset} on ${value.chain}` })
34
- ).transform((value) => getInternalAsset(value));
35
- var numericString = z.string().regex(/^[0-9]+$/);
36
- var hexString = z.string().refine((v) => /^0x[0-9a-f]*$/i.test(v));
37
- var u128 = z.union([z.number(), numericString, hexString]).transform((arg) => BigInt(arg));
38
- var chainflipAddress = z.string().refine(
39
- (address) => ss58.decode(address).ss58Format === CHAINFLIP_SS58_PREFIX,
40
- (address) => ({ message: `${address} is not a valid Chainflip address` })
41
- );
42
- var jsonString = z.string().transform((value) => JSON.parse(value));
43
- var bitcoinDeposit = z.object({
44
- tx_id: hexString.transform((value) => reverseBytes(value).slice(2)),
45
- vout: z.number().int()
46
- }).transform((obj) => ({ ...obj, type: "Bitcoin" }));
47
- var evmDeposit = z.object({ tx_hashes: z.array(hexString) }).transform((obj) => ({ ...obj, type: "EVM" }));
48
- var assethubDeposit = z.object({ extrinsic_index: z.number() }).transform((obj) => ({ ...obj, type: "Assethub" }));
49
- var depositSchema = jsonString.pipe(
50
- z.object({
51
- amount: u128,
52
- asset: assetAndChain,
53
- deposit_chain_block_height: z.number(),
54
- deposit_details: z.union([evmDeposit, bitcoinDeposit, assethubDeposit]).nullable()
55
- })
56
- );
57
- var broadcastParsers = {
58
- Ethereum: z.object({
59
- tx_out_id: z.object({
60
- signature: z.object({
61
- k_times_g_address: z.array(z.number()),
62
- s: z.array(z.number())
63
- })
64
- }),
65
- tx_ref: z.object({
66
- hash: hexString
67
- }).transform(({ hash }) => hash)
68
- }),
69
- Assethub: z.object({
70
- tx_out_id: z.object({ signature: z.string() }),
71
- tx_ref: z.object({
72
- transaction_id: z.object({
73
- block_number: z.number(),
74
- extrinsic_index: z.number()
75
- })
76
- }).transform(
77
- ({ transaction_id }) => `${transaction_id.block_number}-${transaction_id.extrinsic_index}`
78
- )
79
- }),
80
- Bitcoin: z.object({
81
- tx_out_id: z.object({ hash: z.string() }),
82
- tx_ref: z.object({
83
- hash: z.string().transform((value) => value.startsWith("0x") ? value.slice(2) : value)
84
- }).transform(({ hash }) => hash)
85
- }),
86
- Arbitrum: z.object({
87
- tx_out_id: z.object({
88
- signature: z.object({
89
- k_times_g_address: z.array(z.number()),
90
- s: z.array(z.number())
91
- })
92
- }),
93
- tx_ref: z.object({
94
- hash: hexString
95
- }).transform(({ hash }) => hash)
96
- })
97
- };
98
- var accountFee = z.object({
99
- account: chainflipAddress,
100
- bps: z.number()
101
- }).transform(({ account, bps }) => ({ account, commissionBps: bps }));
102
- var vaultDepositSchema = jsonString.pipe(
103
- z.object({
104
- amount: u128,
105
- destination_address: z.string(),
106
- input_asset: assetAndChain,
107
- output_asset: assetAndChain,
108
- deposit_chain_block_height: z.number().nullable().optional(),
109
- affiliate_fees: z.array(accountFee),
110
- broker_fee: accountFee.optional(),
111
- max_boost_fee: z.number().optional(),
112
- dca_params: z.object({
113
- chunk_interval: z.number(),
114
- number_of_chunks: z.number()
115
- }).nullable().optional(),
116
- refund_params: z.object({
117
- min_price: u128,
118
- retry_duration: z.number(),
119
- refund_address: z.string()
120
- }).nullable().optional(),
121
- ccm_deposit_metadata: z.object({
122
- channel_metadata: z.object({
123
- ccm_additional_data: z.any(),
124
- message: z.string(),
125
- gas_budget: z.union([numericString, hexString]).transform((n) => hexEncodeNumber(BigInt(n)))
126
- })
127
- }).nullable().optional()
128
- }).transform(transformKeysToCamelCase)
129
- );
130
- var mempoolTransaction = jsonString.pipe(
131
- z.object({
132
- confirmations: z.number(),
133
- value: u128,
134
- tx_hash: z.string(),
135
- deposit_chain_block_height: z.number().optional()
136
- })
137
- );
9
+ //#region src/index.ts
138
10
  var RedisClient = class {
139
- client;
140
- constructor(url) {
141
- this.client = new Redis(url);
142
- }
143
- async getBroadcast(chain, broadcastId) {
144
- if (chain === "Solana" || chain === "Polkadot") return null;
145
- const key = `broadcast:${chain}:${broadcastId}`;
146
- const value = await this.client.get(key);
147
- return value ? broadcastParsers[chain].parse(JSON.parse(value)) : null;
148
- }
149
- async getDeposits(asset, address) {
150
- const { chain } = assetConstants[asset];
151
- const parsedAddress = chain === "Assethub" ? ss58.toPublicKey(address) : address;
152
- const key = `deposit:${chain}:${parsedAddress}`;
153
- const deposits = await this.client.lrange(key, 0, -1);
154
- return deposits.map((depositString) => {
155
- const parsedDeposit = depositSchema.parse(depositString);
156
- const { deposit_details, ...deposit } = parsedDeposit;
157
- switch (deposit_details?.type) {
158
- case "EVM":
159
- return { ...deposit, tx_refs: deposit_details.tx_hashes };
160
- case "Bitcoin":
161
- return { ...deposit, tx_refs: [deposit_details.tx_id] };
162
- case "Assethub":
163
- return {
164
- ...deposit,
165
- tx_refs: [`${deposit.deposit_chain_block_height}-${deposit_details.extrinsic_index}`]
166
- };
167
- default:
168
- assert(deposit_details === null, "Invalid deposit details");
169
- return { ...deposit, tx_refs: [] };
170
- }
171
- }).filter((deposit) => deposit.asset === asset).sort((a, b) => a.deposit_chain_block_height - b.deposit_chain_block_height);
172
- }
173
- async getMempoolTransaction(chain, address) {
174
- const key = `mempool:${chain}:${address}`;
175
- const value = await this.client.get(key);
176
- return value ? mempoolTransaction.parse(value) : null;
177
- }
178
- async getPendingVaultSwap(chain, txId) {
179
- const unavailableChains = ["Solana", "Assethub"];
180
- if (unavailableChains.includes(chain)) return null;
181
- const redisTxId = chain === "Bitcoin" && isHex(`0x${txId}`) ? reverseBytes(`0x${txId}`) : txId;
182
- const value = await this.client.get(`vault_deposit:${chain}:${redisTxId}`);
183
- return value ? vaultDepositSchema.parse(value) : null;
184
- }
185
- quit() {
186
- return this.client.quit();
187
- }
11
+ client;
12
+ constructor(url) {
13
+ this.client = new Redis(url);
14
+ }
15
+ async getBroadcast(chain, broadcastId) {
16
+ if (chain === "Solana" || chain === "Polkadot") return null;
17
+ const key = `broadcast:${chain}:${broadcastId}`;
18
+ const value = await this.client.get(key);
19
+ return value ? broadcastParsers[chain].parse(JSON.parse(value)) : null;
20
+ }
21
+ async getDeposits(asset, address) {
22
+ const { chain } = assetConstants[asset];
23
+ const key = `deposit:${chain}:${chain === "Assethub" ? ss58.toPublicKey(address) : address}`;
24
+ return (await this.client.lrange(key, 0, -1)).map((depositString) => {
25
+ const { deposit_details, ...deposit } = depositSchema.parse(depositString);
26
+ switch (deposit_details?.type) {
27
+ case "EVM": return {
28
+ ...deposit,
29
+ tx_refs: deposit_details.tx_hashes
30
+ };
31
+ case "Bitcoin": return {
32
+ ...deposit,
33
+ tx_refs: [deposit_details.tx_id]
34
+ };
35
+ case "Assethub": return {
36
+ ...deposit,
37
+ tx_refs: [`${deposit.deposit_chain_block_height}-${deposit_details.extrinsic_index}`]
38
+ };
39
+ default:
40
+ assert(deposit_details === null, "Invalid deposit details");
41
+ return {
42
+ ...deposit,
43
+ tx_refs: []
44
+ };
45
+ }
46
+ }).filter((deposit) => deposit.asset === asset).sort((a, b) => a.deposit_chain_block_height - b.deposit_chain_block_height);
47
+ }
48
+ async getMempoolTransaction(chain, address) {
49
+ const key = `mempool:${chain}:${address}`;
50
+ const value = await this.client.get(key);
51
+ return value ? mempoolTransaction.parse(value) : null;
52
+ }
53
+ async getPendingVaultSwap(chain, txId) {
54
+ if (["Solana", "Assethub"].includes(chain)) return null;
55
+ const redisTxId = chain === "Bitcoin" && isHex(`0x${txId}`) ? reverseBytes(`0x${txId}`) : txId;
56
+ const value = await this.client.get(`vault_deposit:${chain}:${redisTxId}`);
57
+ return value ? vaultDepositSchema.parse(value) : null;
58
+ }
59
+ quit() {
60
+ return this.client.quit();
61
+ }
188
62
  };
189
63
 
190
- export { RedisClient as default };
64
+ //#endregion
65
+ export { RedisClient as default };