@chainflip/redis 1.0.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/README.md +1 -0
- package/dist/index.cjs +227 -0
- package/dist/index.d.cts +387 -0
- package/dist/index.d.ts +387 -0
- package/dist/index.js +201 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
## @chainflip/redis
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var bytes = require('@chainflip/utils/bytes');
|
|
4
|
+
var chainflip = require('@chainflip/utils/chainflip');
|
|
5
|
+
var consts = require('@chainflip/utils/consts');
|
|
6
|
+
var number = require('@chainflip/utils/number');
|
|
7
|
+
var ss58 = require('@chainflip/utils/ss58');
|
|
8
|
+
var string = require('@chainflip/utils/string');
|
|
9
|
+
var assert = require('assert');
|
|
10
|
+
var Redis = require('ioredis');
|
|
11
|
+
var zod = require('zod');
|
|
12
|
+
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
|
|
15
|
+
function _interopNamespace(e) {
|
|
16
|
+
if (e && e.__esModule) return e;
|
|
17
|
+
var n = Object.create(null);
|
|
18
|
+
if (e) {
|
|
19
|
+
Object.keys(e).forEach(function (k) {
|
|
20
|
+
if (k !== 'default') {
|
|
21
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
22
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return e[k]; }
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
n.default = e;
|
|
30
|
+
return Object.freeze(n);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var ss58__namespace = /*#__PURE__*/_interopNamespace(ss58);
|
|
34
|
+
var assert__default = /*#__PURE__*/_interopDefault(assert);
|
|
35
|
+
var Redis__default = /*#__PURE__*/_interopDefault(Redis);
|
|
36
|
+
|
|
37
|
+
// src/index.ts
|
|
38
|
+
|
|
39
|
+
// src/utils.ts
|
|
40
|
+
var snakeToCamelCase = (str) => str.replace(/_(.)/g, (match, group) => group.toUpperCase());
|
|
41
|
+
var transformKeysToCamelCase = (obj) => {
|
|
42
|
+
if (obj == null || typeof obj !== "object") return obj;
|
|
43
|
+
if (Array.isArray(obj)) return obj.map(transformKeysToCamelCase);
|
|
44
|
+
return Object.fromEntries(
|
|
45
|
+
Object.entries(obj).map(([key, value]) => [
|
|
46
|
+
snakeToCamelCase(key),
|
|
47
|
+
transformKeysToCamelCase(value)
|
|
48
|
+
])
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// src/index.ts
|
|
53
|
+
var uncheckedAssetAndChain = zod.z.object({
|
|
54
|
+
asset: zod.z.string(),
|
|
55
|
+
chain: zod.z.string()
|
|
56
|
+
});
|
|
57
|
+
var assetAndChain = uncheckedAssetAndChain.refine(
|
|
58
|
+
(value) => chainflip.isValidAssetAndChain(value),
|
|
59
|
+
{ message: "Invalid asset and chain" }
|
|
60
|
+
).transform((value) => chainflip.getInternalAsset(value));
|
|
61
|
+
var numericString = zod.z.string().regex(/^[0-9]+$/);
|
|
62
|
+
var hexString = zod.z.string().refine((v) => /^0x[0-9a-f]*$/i.test(v));
|
|
63
|
+
var u128 = zod.z.union([zod.z.number(), numericString, hexString]).transform((arg) => BigInt(arg));
|
|
64
|
+
var chainflipAddress = zod.z.string().refine(
|
|
65
|
+
(address) => ss58__namespace.decode(address).ss58Format === consts.CHAINFLIP_SS58_PREFIX,
|
|
66
|
+
(address) => ({ message: `${address} is not a valid Chainflip address` })
|
|
67
|
+
);
|
|
68
|
+
var jsonString = zod.z.string().transform((value) => JSON.parse(value));
|
|
69
|
+
var bitcoinDeposit = zod.z.object({
|
|
70
|
+
tx_id: hexString.transform((value) => bytes.reverseBytes(value).slice(2)),
|
|
71
|
+
vout: zod.z.number().int()
|
|
72
|
+
}).transform((obj) => ({ ...obj, type: "Bitcoin" }));
|
|
73
|
+
var evmDeposit = zod.z.object({ tx_hashes: zod.z.array(hexString) }).transform((obj) => ({ ...obj, type: "EVM" }));
|
|
74
|
+
var polkadotDeposit = zod.z.object({ extrinsic_index: zod.z.number() }).transform((obj) => ({ ...obj, type: "Polkadot" }));
|
|
75
|
+
var depositSchema = jsonString.pipe(
|
|
76
|
+
zod.z.object({
|
|
77
|
+
amount: u128,
|
|
78
|
+
asset: assetAndChain,
|
|
79
|
+
deposit_chain_block_height: zod.z.number(),
|
|
80
|
+
deposit_details: zod.z.union([evmDeposit, bitcoinDeposit, polkadotDeposit]).nullable()
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
var broadcastParsers = {
|
|
84
|
+
Ethereum: zod.z.object({
|
|
85
|
+
tx_out_id: zod.z.object({
|
|
86
|
+
signature: zod.z.object({
|
|
87
|
+
k_times_g_address: zod.z.array(zod.z.number()),
|
|
88
|
+
s: zod.z.array(zod.z.number())
|
|
89
|
+
})
|
|
90
|
+
}),
|
|
91
|
+
tx_ref: zod.z.object({
|
|
92
|
+
hash: hexString
|
|
93
|
+
}).transform(({ hash }) => hash)
|
|
94
|
+
}),
|
|
95
|
+
Polkadot: zod.z.object({
|
|
96
|
+
tx_out_id: zod.z.object({ signature: zod.z.string() }),
|
|
97
|
+
tx_ref: zod.z.object({
|
|
98
|
+
transaction_id: zod.z.object({
|
|
99
|
+
block_number: zod.z.number(),
|
|
100
|
+
extrinsic_index: zod.z.number()
|
|
101
|
+
})
|
|
102
|
+
}).transform(
|
|
103
|
+
({ transaction_id }) => `${transaction_id.block_number}-${transaction_id.extrinsic_index}`
|
|
104
|
+
)
|
|
105
|
+
}),
|
|
106
|
+
Assethub: zod.z.object({
|
|
107
|
+
tx_out_id: zod.z.object({ signature: zod.z.string() }),
|
|
108
|
+
tx_ref: zod.z.object({
|
|
109
|
+
transaction_id: zod.z.object({
|
|
110
|
+
block_number: zod.z.number(),
|
|
111
|
+
extrinsic_index: zod.z.number()
|
|
112
|
+
})
|
|
113
|
+
}).transform(
|
|
114
|
+
({ transaction_id }) => `${transaction_id.block_number}-${transaction_id.extrinsic_index}`
|
|
115
|
+
)
|
|
116
|
+
}),
|
|
117
|
+
Bitcoin: zod.z.object({
|
|
118
|
+
tx_out_id: zod.z.object({ hash: zod.z.string() }),
|
|
119
|
+
tx_ref: zod.z.object({
|
|
120
|
+
hash: zod.z.string().transform((value) => value.startsWith("0x") ? value.slice(2) : value)
|
|
121
|
+
}).transform(({ hash }) => hash)
|
|
122
|
+
}),
|
|
123
|
+
Arbitrum: zod.z.object({
|
|
124
|
+
tx_out_id: zod.z.object({
|
|
125
|
+
signature: zod.z.object({
|
|
126
|
+
k_times_g_address: zod.z.array(zod.z.number()),
|
|
127
|
+
s: zod.z.array(zod.z.number())
|
|
128
|
+
})
|
|
129
|
+
}),
|
|
130
|
+
tx_ref: zod.z.object({
|
|
131
|
+
hash: hexString
|
|
132
|
+
}).transform(({ hash }) => hash)
|
|
133
|
+
})
|
|
134
|
+
};
|
|
135
|
+
var accountFee = zod.z.object({
|
|
136
|
+
account: chainflipAddress,
|
|
137
|
+
bps: zod.z.number()
|
|
138
|
+
}).transform(({ account, bps }) => ({ account, commissionBps: bps }));
|
|
139
|
+
var vaultDepositSchema = jsonString.pipe(
|
|
140
|
+
zod.z.object({
|
|
141
|
+
amount: u128,
|
|
142
|
+
destination_address: zod.z.string(),
|
|
143
|
+
input_asset: assetAndChain,
|
|
144
|
+
output_asset: assetAndChain,
|
|
145
|
+
deposit_chain_block_height: zod.z.number().nullable().optional(),
|
|
146
|
+
affiliate_fees: zod.z.array(accountFee),
|
|
147
|
+
broker_fee: accountFee.optional(),
|
|
148
|
+
max_boost_fee: zod.z.number().optional(),
|
|
149
|
+
dca_params: zod.z.object({
|
|
150
|
+
chunk_interval: zod.z.number(),
|
|
151
|
+
number_of_chunks: zod.z.number()
|
|
152
|
+
}).nullable().optional(),
|
|
153
|
+
refund_params: zod.z.object({
|
|
154
|
+
min_price: u128,
|
|
155
|
+
retry_duration: zod.z.number(),
|
|
156
|
+
refund_address: zod.z.string()
|
|
157
|
+
}).nullable().optional(),
|
|
158
|
+
ccm_deposit_metadata: zod.z.object({
|
|
159
|
+
channel_metadata: zod.z.object({
|
|
160
|
+
ccm_additional_data: zod.z.any(),
|
|
161
|
+
message: zod.z.string(),
|
|
162
|
+
gas_budget: zod.z.union([numericString, hexString]).transform((n) => number.hexEncodeNumber(BigInt(n)))
|
|
163
|
+
})
|
|
164
|
+
}).nullable().optional()
|
|
165
|
+
}).transform(transformKeysToCamelCase)
|
|
166
|
+
);
|
|
167
|
+
var mempoolTransaction = jsonString.pipe(
|
|
168
|
+
zod.z.object({
|
|
169
|
+
confirmations: zod.z.number(),
|
|
170
|
+
value: u128,
|
|
171
|
+
tx_hash: zod.z.string(),
|
|
172
|
+
deposit_chain_block_height: zod.z.number().optional()
|
|
173
|
+
})
|
|
174
|
+
);
|
|
175
|
+
var RedisClient = class {
|
|
176
|
+
client;
|
|
177
|
+
constructor(url) {
|
|
178
|
+
this.client = new Redis__default.default(url);
|
|
179
|
+
}
|
|
180
|
+
async getBroadcast(chain, broadcastId) {
|
|
181
|
+
if (chain === "Solana") return null;
|
|
182
|
+
const key = `broadcast:${chain}:${broadcastId}`;
|
|
183
|
+
const value = await this.client.get(key);
|
|
184
|
+
return value ? broadcastParsers[chain].parse(JSON.parse(value)) : null;
|
|
185
|
+
}
|
|
186
|
+
async getDeposits(asset, address) {
|
|
187
|
+
const { chain } = chainflip.assetConstants[asset];
|
|
188
|
+
const parsedAddress = chain === "Polkadot" ? ss58__namespace.toPublicKey(address) : address;
|
|
189
|
+
const key = `deposit:${chain}:${parsedAddress}`;
|
|
190
|
+
const deposits = await this.client.lrange(key, 0, -1);
|
|
191
|
+
return deposits.map((depositString) => {
|
|
192
|
+
const parsedDeposit = depositSchema.parse(depositString);
|
|
193
|
+
const { deposit_details, ...deposit } = parsedDeposit;
|
|
194
|
+
switch (deposit_details?.type) {
|
|
195
|
+
case "EVM":
|
|
196
|
+
return { ...deposit, tx_refs: deposit_details.tx_hashes };
|
|
197
|
+
case "Bitcoin":
|
|
198
|
+
return { ...deposit, tx_refs: [deposit_details.tx_id] };
|
|
199
|
+
case "Polkadot":
|
|
200
|
+
return {
|
|
201
|
+
...deposit,
|
|
202
|
+
tx_refs: [`${deposit.deposit_chain_block_height}-${deposit_details.extrinsic_index}`]
|
|
203
|
+
};
|
|
204
|
+
default:
|
|
205
|
+
assert__default.default(deposit_details === null, "Invalid deposit details");
|
|
206
|
+
return { ...deposit, tx_refs: [] };
|
|
207
|
+
}
|
|
208
|
+
}).filter((deposit) => deposit.asset === asset).sort((a, b) => a.deposit_chain_block_height - b.deposit_chain_block_height);
|
|
209
|
+
}
|
|
210
|
+
async getMempoolTransaction(chain, address) {
|
|
211
|
+
const key = `mempool:${chain}:${address}`;
|
|
212
|
+
const value = await this.client.get(key);
|
|
213
|
+
return value ? mempoolTransaction.parse(value) : null;
|
|
214
|
+
}
|
|
215
|
+
async getPendingVaultSwap(chain, txId) {
|
|
216
|
+
const unavailableChains = ["Solana", "Polkadot", "Assethub"];
|
|
217
|
+
if (unavailableChains.includes(chain)) return null;
|
|
218
|
+
const redisTxId = chain === "Bitcoin" && string.isHex(`0x${txId}`) ? bytes.reverseBytes(`0x${txId}`) : txId;
|
|
219
|
+
const value = await this.client.get(`vault_deposit:${chain}:${redisTxId}`);
|
|
220
|
+
return value ? vaultDepositSchema.parse(value) : null;
|
|
221
|
+
}
|
|
222
|
+
quit() {
|
|
223
|
+
return this.client.quit();
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
module.exports = RedisClient;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
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
|
+
}>, "Eth" | "Flip" | "Usdc" | "Usdt" | "ArbUsdc" | "ArbEth" | "Btc" | "Dot" | "Sol" | "SolUsdc" | "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: "Polkadot";
|
|
58
|
+
extrinsic_index: number;
|
|
59
|
+
}, {
|
|
60
|
+
extrinsic_index: number;
|
|
61
|
+
}>]>>;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
asset: "Eth" | "Flip" | "Usdc" | "Usdt" | "ArbUsdc" | "ArbEth" | "Btc" | "Dot" | "Sol" | "SolUsdc" | "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: "Polkadot";
|
|
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 Polkadot: 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 Assethub: z.ZodObject<{
|
|
200
|
+
tx_out_id: z.ZodObject<{
|
|
201
|
+
signature: z.ZodString;
|
|
202
|
+
}, "strip", z.ZodTypeAny, {
|
|
203
|
+
signature: string;
|
|
204
|
+
}, {
|
|
205
|
+
signature: string;
|
|
206
|
+
}>;
|
|
207
|
+
tx_ref: z.ZodEffects<z.ZodObject<{
|
|
208
|
+
transaction_id: z.ZodObject<{
|
|
209
|
+
block_number: z.ZodNumber;
|
|
210
|
+
extrinsic_index: z.ZodNumber;
|
|
211
|
+
}, "strip", z.ZodTypeAny, {
|
|
212
|
+
extrinsic_index: number;
|
|
213
|
+
block_number: number;
|
|
214
|
+
}, {
|
|
215
|
+
extrinsic_index: number;
|
|
216
|
+
block_number: number;
|
|
217
|
+
}>;
|
|
218
|
+
}, "strip", z.ZodTypeAny, {
|
|
219
|
+
transaction_id: {
|
|
220
|
+
extrinsic_index: number;
|
|
221
|
+
block_number: number;
|
|
222
|
+
};
|
|
223
|
+
}, {
|
|
224
|
+
transaction_id: {
|
|
225
|
+
extrinsic_index: number;
|
|
226
|
+
block_number: number;
|
|
227
|
+
};
|
|
228
|
+
}>, string, {
|
|
229
|
+
transaction_id: {
|
|
230
|
+
extrinsic_index: number;
|
|
231
|
+
block_number: number;
|
|
232
|
+
};
|
|
233
|
+
}>;
|
|
234
|
+
}, "strip", z.ZodTypeAny, {
|
|
235
|
+
tx_out_id: {
|
|
236
|
+
signature: string;
|
|
237
|
+
};
|
|
238
|
+
tx_ref: string;
|
|
239
|
+
}, {
|
|
240
|
+
tx_out_id: {
|
|
241
|
+
signature: string;
|
|
242
|
+
};
|
|
243
|
+
tx_ref: {
|
|
244
|
+
transaction_id: {
|
|
245
|
+
extrinsic_index: number;
|
|
246
|
+
block_number: number;
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
}>;
|
|
250
|
+
readonly Bitcoin: z.ZodObject<{
|
|
251
|
+
tx_out_id: z.ZodObject<{
|
|
252
|
+
hash: z.ZodString;
|
|
253
|
+
}, "strip", z.ZodTypeAny, {
|
|
254
|
+
hash: string;
|
|
255
|
+
}, {
|
|
256
|
+
hash: string;
|
|
257
|
+
}>;
|
|
258
|
+
tx_ref: z.ZodEffects<z.ZodObject<{
|
|
259
|
+
hash: z.ZodEffects<z.ZodString, string, string>;
|
|
260
|
+
}, "strip", z.ZodTypeAny, {
|
|
261
|
+
hash: string;
|
|
262
|
+
}, {
|
|
263
|
+
hash: string;
|
|
264
|
+
}>, string, {
|
|
265
|
+
hash: string;
|
|
266
|
+
}>;
|
|
267
|
+
}, "strip", z.ZodTypeAny, {
|
|
268
|
+
tx_out_id: {
|
|
269
|
+
hash: string;
|
|
270
|
+
};
|
|
271
|
+
tx_ref: string;
|
|
272
|
+
}, {
|
|
273
|
+
tx_out_id: {
|
|
274
|
+
hash: string;
|
|
275
|
+
};
|
|
276
|
+
tx_ref: {
|
|
277
|
+
hash: string;
|
|
278
|
+
};
|
|
279
|
+
}>;
|
|
280
|
+
readonly Arbitrum: z.ZodObject<{
|
|
281
|
+
tx_out_id: z.ZodObject<{
|
|
282
|
+
signature: z.ZodObject<{
|
|
283
|
+
k_times_g_address: z.ZodArray<z.ZodNumber, "many">;
|
|
284
|
+
s: z.ZodArray<z.ZodNumber, "many">;
|
|
285
|
+
}, "strip", z.ZodTypeAny, {
|
|
286
|
+
k_times_g_address: number[];
|
|
287
|
+
s: number[];
|
|
288
|
+
}, {
|
|
289
|
+
k_times_g_address: number[];
|
|
290
|
+
s: number[];
|
|
291
|
+
}>;
|
|
292
|
+
}, "strip", z.ZodTypeAny, {
|
|
293
|
+
signature: {
|
|
294
|
+
k_times_g_address: number[];
|
|
295
|
+
s: number[];
|
|
296
|
+
};
|
|
297
|
+
}, {
|
|
298
|
+
signature: {
|
|
299
|
+
k_times_g_address: number[];
|
|
300
|
+
s: number[];
|
|
301
|
+
};
|
|
302
|
+
}>;
|
|
303
|
+
tx_ref: z.ZodEffects<z.ZodObject<{
|
|
304
|
+
hash: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
305
|
+
}, "strip", z.ZodTypeAny, {
|
|
306
|
+
hash: `0x${string}`;
|
|
307
|
+
}, {
|
|
308
|
+
hash: string;
|
|
309
|
+
}>, `0x${string}`, {
|
|
310
|
+
hash: string;
|
|
311
|
+
}>;
|
|
312
|
+
}, "strip", z.ZodTypeAny, {
|
|
313
|
+
tx_out_id: {
|
|
314
|
+
signature: {
|
|
315
|
+
k_times_g_address: number[];
|
|
316
|
+
s: number[];
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
tx_ref: `0x${string}`;
|
|
320
|
+
}, {
|
|
321
|
+
tx_out_id: {
|
|
322
|
+
signature: {
|
|
323
|
+
k_times_g_address: number[];
|
|
324
|
+
s: number[];
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
tx_ref: {
|
|
328
|
+
hash: string;
|
|
329
|
+
};
|
|
330
|
+
}>;
|
|
331
|
+
};
|
|
332
|
+
type ChainBroadcast<C extends Exclude<ChainflipChain, 'Solana'>> = z.infer<(typeof broadcastParsers)[C]>;
|
|
333
|
+
type EthereumBroadcast = ChainBroadcast<'Ethereum'>;
|
|
334
|
+
type PolkadotBroadcast = ChainBroadcast<'Polkadot'>;
|
|
335
|
+
type BitcoinBroadcast = ChainBroadcast<'Bitcoin'>;
|
|
336
|
+
type Broadcast = ChainBroadcast<Exclude<ChainflipChain, 'Solana'>>;
|
|
337
|
+
declare class RedisClient {
|
|
338
|
+
private client;
|
|
339
|
+
constructor(url: `redis://${string}` | `rediss://${string}`);
|
|
340
|
+
getBroadcast(chain: 'Ethereum', broadcastId: number | bigint): Promise<EthereumBroadcast | null>;
|
|
341
|
+
getBroadcast(chain: 'Polkadot', broadcastId: number | bigint): Promise<PolkadotBroadcast | null>;
|
|
342
|
+
getBroadcast(chain: 'Bitcoin', broadcastId: number | bigint): Promise<BitcoinBroadcast | null>;
|
|
343
|
+
getBroadcast(chain: 'Arbitrum', broadcastId: number | bigint): Promise<EthereumBroadcast | null>;
|
|
344
|
+
getBroadcast(chain: ChainflipChain, broadcastId: number | bigint): Promise<Broadcast | null>;
|
|
345
|
+
getDeposits(asset: ChainflipAsset, address: string): Promise<PendingDeposit[]>;
|
|
346
|
+
getMempoolTransaction(chain: 'Bitcoin', address: string): Promise<{
|
|
347
|
+
value: bigint;
|
|
348
|
+
confirmations: number;
|
|
349
|
+
tx_hash: string;
|
|
350
|
+
deposit_chain_block_height?: number | undefined;
|
|
351
|
+
} | null>;
|
|
352
|
+
getPendingVaultSwap(chain: ChainflipChain, txId: string): Promise<{
|
|
353
|
+
amount: bigint;
|
|
354
|
+
destinationAddress: string;
|
|
355
|
+
inputAsset: "Eth" | "Flip" | "Usdc" | "Usdt" | "ArbUsdc" | "ArbEth" | "Btc" | "Dot" | "Sol" | "SolUsdc" | "HubDot" | "HubUsdt" | "HubUsdc";
|
|
356
|
+
outputAsset: "Eth" | "Flip" | "Usdc" | "Usdt" | "ArbUsdc" | "ArbEth" | "Btc" | "Dot" | "Sol" | "SolUsdc" | "HubDot" | "HubUsdt" | "HubUsdc";
|
|
357
|
+
affiliateFees: {
|
|
358
|
+
account: string;
|
|
359
|
+
commissionBps: number;
|
|
360
|
+
}[];
|
|
361
|
+
depositChainBlockHeight?: number | null | undefined;
|
|
362
|
+
brokerFee?: {
|
|
363
|
+
account: string;
|
|
364
|
+
commissionBps: number;
|
|
365
|
+
} | undefined;
|
|
366
|
+
maxBoostFee?: number | undefined;
|
|
367
|
+
dcaParams?: {
|
|
368
|
+
chunkInterval: number;
|
|
369
|
+
numberOfChunks: number;
|
|
370
|
+
} | null | undefined;
|
|
371
|
+
refundParams?: {
|
|
372
|
+
minPrice: bigint;
|
|
373
|
+
retryDuration: number;
|
|
374
|
+
refundAddress: string;
|
|
375
|
+
} | null | undefined;
|
|
376
|
+
ccmDepositMetadata?: {
|
|
377
|
+
channelMetadata: {
|
|
378
|
+
message: string;
|
|
379
|
+
gasBudget: `0x${string}`;
|
|
380
|
+
ccmAdditionalData?: any;
|
|
381
|
+
};
|
|
382
|
+
} | null | undefined;
|
|
383
|
+
} | null>;
|
|
384
|
+
quit(): Promise<"OK">;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export { RedisClient as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
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
|
+
}>, "Eth" | "Flip" | "Usdc" | "Usdt" | "ArbUsdc" | "ArbEth" | "Btc" | "Dot" | "Sol" | "SolUsdc" | "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: "Polkadot";
|
|
58
|
+
extrinsic_index: number;
|
|
59
|
+
}, {
|
|
60
|
+
extrinsic_index: number;
|
|
61
|
+
}>]>>;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
asset: "Eth" | "Flip" | "Usdc" | "Usdt" | "ArbUsdc" | "ArbEth" | "Btc" | "Dot" | "Sol" | "SolUsdc" | "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: "Polkadot";
|
|
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 Polkadot: 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 Assethub: z.ZodObject<{
|
|
200
|
+
tx_out_id: z.ZodObject<{
|
|
201
|
+
signature: z.ZodString;
|
|
202
|
+
}, "strip", z.ZodTypeAny, {
|
|
203
|
+
signature: string;
|
|
204
|
+
}, {
|
|
205
|
+
signature: string;
|
|
206
|
+
}>;
|
|
207
|
+
tx_ref: z.ZodEffects<z.ZodObject<{
|
|
208
|
+
transaction_id: z.ZodObject<{
|
|
209
|
+
block_number: z.ZodNumber;
|
|
210
|
+
extrinsic_index: z.ZodNumber;
|
|
211
|
+
}, "strip", z.ZodTypeAny, {
|
|
212
|
+
extrinsic_index: number;
|
|
213
|
+
block_number: number;
|
|
214
|
+
}, {
|
|
215
|
+
extrinsic_index: number;
|
|
216
|
+
block_number: number;
|
|
217
|
+
}>;
|
|
218
|
+
}, "strip", z.ZodTypeAny, {
|
|
219
|
+
transaction_id: {
|
|
220
|
+
extrinsic_index: number;
|
|
221
|
+
block_number: number;
|
|
222
|
+
};
|
|
223
|
+
}, {
|
|
224
|
+
transaction_id: {
|
|
225
|
+
extrinsic_index: number;
|
|
226
|
+
block_number: number;
|
|
227
|
+
};
|
|
228
|
+
}>, string, {
|
|
229
|
+
transaction_id: {
|
|
230
|
+
extrinsic_index: number;
|
|
231
|
+
block_number: number;
|
|
232
|
+
};
|
|
233
|
+
}>;
|
|
234
|
+
}, "strip", z.ZodTypeAny, {
|
|
235
|
+
tx_out_id: {
|
|
236
|
+
signature: string;
|
|
237
|
+
};
|
|
238
|
+
tx_ref: string;
|
|
239
|
+
}, {
|
|
240
|
+
tx_out_id: {
|
|
241
|
+
signature: string;
|
|
242
|
+
};
|
|
243
|
+
tx_ref: {
|
|
244
|
+
transaction_id: {
|
|
245
|
+
extrinsic_index: number;
|
|
246
|
+
block_number: number;
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
}>;
|
|
250
|
+
readonly Bitcoin: z.ZodObject<{
|
|
251
|
+
tx_out_id: z.ZodObject<{
|
|
252
|
+
hash: z.ZodString;
|
|
253
|
+
}, "strip", z.ZodTypeAny, {
|
|
254
|
+
hash: string;
|
|
255
|
+
}, {
|
|
256
|
+
hash: string;
|
|
257
|
+
}>;
|
|
258
|
+
tx_ref: z.ZodEffects<z.ZodObject<{
|
|
259
|
+
hash: z.ZodEffects<z.ZodString, string, string>;
|
|
260
|
+
}, "strip", z.ZodTypeAny, {
|
|
261
|
+
hash: string;
|
|
262
|
+
}, {
|
|
263
|
+
hash: string;
|
|
264
|
+
}>, string, {
|
|
265
|
+
hash: string;
|
|
266
|
+
}>;
|
|
267
|
+
}, "strip", z.ZodTypeAny, {
|
|
268
|
+
tx_out_id: {
|
|
269
|
+
hash: string;
|
|
270
|
+
};
|
|
271
|
+
tx_ref: string;
|
|
272
|
+
}, {
|
|
273
|
+
tx_out_id: {
|
|
274
|
+
hash: string;
|
|
275
|
+
};
|
|
276
|
+
tx_ref: {
|
|
277
|
+
hash: string;
|
|
278
|
+
};
|
|
279
|
+
}>;
|
|
280
|
+
readonly Arbitrum: z.ZodObject<{
|
|
281
|
+
tx_out_id: z.ZodObject<{
|
|
282
|
+
signature: z.ZodObject<{
|
|
283
|
+
k_times_g_address: z.ZodArray<z.ZodNumber, "many">;
|
|
284
|
+
s: z.ZodArray<z.ZodNumber, "many">;
|
|
285
|
+
}, "strip", z.ZodTypeAny, {
|
|
286
|
+
k_times_g_address: number[];
|
|
287
|
+
s: number[];
|
|
288
|
+
}, {
|
|
289
|
+
k_times_g_address: number[];
|
|
290
|
+
s: number[];
|
|
291
|
+
}>;
|
|
292
|
+
}, "strip", z.ZodTypeAny, {
|
|
293
|
+
signature: {
|
|
294
|
+
k_times_g_address: number[];
|
|
295
|
+
s: number[];
|
|
296
|
+
};
|
|
297
|
+
}, {
|
|
298
|
+
signature: {
|
|
299
|
+
k_times_g_address: number[];
|
|
300
|
+
s: number[];
|
|
301
|
+
};
|
|
302
|
+
}>;
|
|
303
|
+
tx_ref: z.ZodEffects<z.ZodObject<{
|
|
304
|
+
hash: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
305
|
+
}, "strip", z.ZodTypeAny, {
|
|
306
|
+
hash: `0x${string}`;
|
|
307
|
+
}, {
|
|
308
|
+
hash: string;
|
|
309
|
+
}>, `0x${string}`, {
|
|
310
|
+
hash: string;
|
|
311
|
+
}>;
|
|
312
|
+
}, "strip", z.ZodTypeAny, {
|
|
313
|
+
tx_out_id: {
|
|
314
|
+
signature: {
|
|
315
|
+
k_times_g_address: number[];
|
|
316
|
+
s: number[];
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
tx_ref: `0x${string}`;
|
|
320
|
+
}, {
|
|
321
|
+
tx_out_id: {
|
|
322
|
+
signature: {
|
|
323
|
+
k_times_g_address: number[];
|
|
324
|
+
s: number[];
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
tx_ref: {
|
|
328
|
+
hash: string;
|
|
329
|
+
};
|
|
330
|
+
}>;
|
|
331
|
+
};
|
|
332
|
+
type ChainBroadcast<C extends Exclude<ChainflipChain, 'Solana'>> = z.infer<(typeof broadcastParsers)[C]>;
|
|
333
|
+
type EthereumBroadcast = ChainBroadcast<'Ethereum'>;
|
|
334
|
+
type PolkadotBroadcast = ChainBroadcast<'Polkadot'>;
|
|
335
|
+
type BitcoinBroadcast = ChainBroadcast<'Bitcoin'>;
|
|
336
|
+
type Broadcast = ChainBroadcast<Exclude<ChainflipChain, 'Solana'>>;
|
|
337
|
+
declare class RedisClient {
|
|
338
|
+
private client;
|
|
339
|
+
constructor(url: `redis://${string}` | `rediss://${string}`);
|
|
340
|
+
getBroadcast(chain: 'Ethereum', broadcastId: number | bigint): Promise<EthereumBroadcast | null>;
|
|
341
|
+
getBroadcast(chain: 'Polkadot', broadcastId: number | bigint): Promise<PolkadotBroadcast | null>;
|
|
342
|
+
getBroadcast(chain: 'Bitcoin', broadcastId: number | bigint): Promise<BitcoinBroadcast | null>;
|
|
343
|
+
getBroadcast(chain: 'Arbitrum', broadcastId: number | bigint): Promise<EthereumBroadcast | null>;
|
|
344
|
+
getBroadcast(chain: ChainflipChain, broadcastId: number | bigint): Promise<Broadcast | null>;
|
|
345
|
+
getDeposits(asset: ChainflipAsset, address: string): Promise<PendingDeposit[]>;
|
|
346
|
+
getMempoolTransaction(chain: 'Bitcoin', address: string): Promise<{
|
|
347
|
+
value: bigint;
|
|
348
|
+
confirmations: number;
|
|
349
|
+
tx_hash: string;
|
|
350
|
+
deposit_chain_block_height?: number | undefined;
|
|
351
|
+
} | null>;
|
|
352
|
+
getPendingVaultSwap(chain: ChainflipChain, txId: string): Promise<{
|
|
353
|
+
amount: bigint;
|
|
354
|
+
destinationAddress: string;
|
|
355
|
+
inputAsset: "Eth" | "Flip" | "Usdc" | "Usdt" | "ArbUsdc" | "ArbEth" | "Btc" | "Dot" | "Sol" | "SolUsdc" | "HubDot" | "HubUsdt" | "HubUsdc";
|
|
356
|
+
outputAsset: "Eth" | "Flip" | "Usdc" | "Usdt" | "ArbUsdc" | "ArbEth" | "Btc" | "Dot" | "Sol" | "SolUsdc" | "HubDot" | "HubUsdt" | "HubUsdc";
|
|
357
|
+
affiliateFees: {
|
|
358
|
+
account: string;
|
|
359
|
+
commissionBps: number;
|
|
360
|
+
}[];
|
|
361
|
+
depositChainBlockHeight?: number | null | undefined;
|
|
362
|
+
brokerFee?: {
|
|
363
|
+
account: string;
|
|
364
|
+
commissionBps: number;
|
|
365
|
+
} | undefined;
|
|
366
|
+
maxBoostFee?: number | undefined;
|
|
367
|
+
dcaParams?: {
|
|
368
|
+
chunkInterval: number;
|
|
369
|
+
numberOfChunks: number;
|
|
370
|
+
} | null | undefined;
|
|
371
|
+
refundParams?: {
|
|
372
|
+
minPrice: bigint;
|
|
373
|
+
retryDuration: number;
|
|
374
|
+
refundAddress: string;
|
|
375
|
+
} | null | undefined;
|
|
376
|
+
ccmDepositMetadata?: {
|
|
377
|
+
channelMetadata: {
|
|
378
|
+
message: string;
|
|
379
|
+
gasBudget: `0x${string}`;
|
|
380
|
+
ccmAdditionalData?: any;
|
|
381
|
+
};
|
|
382
|
+
} | null | undefined;
|
|
383
|
+
} | null>;
|
|
384
|
+
quit(): Promise<"OK">;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export { RedisClient as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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';
|
|
10
|
+
|
|
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
|
+
{ message: "Invalid asset and 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 polkadotDeposit = z.object({ extrinsic_index: z.number() }).transform((obj) => ({ ...obj, type: "Polkadot" }));
|
|
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, polkadotDeposit]).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
|
+
Polkadot: 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
|
+
Assethub: z.object({
|
|
81
|
+
tx_out_id: z.object({ signature: z.string() }),
|
|
82
|
+
tx_ref: z.object({
|
|
83
|
+
transaction_id: z.object({
|
|
84
|
+
block_number: z.number(),
|
|
85
|
+
extrinsic_index: z.number()
|
|
86
|
+
})
|
|
87
|
+
}).transform(
|
|
88
|
+
({ transaction_id }) => `${transaction_id.block_number}-${transaction_id.extrinsic_index}`
|
|
89
|
+
)
|
|
90
|
+
}),
|
|
91
|
+
Bitcoin: z.object({
|
|
92
|
+
tx_out_id: z.object({ hash: z.string() }),
|
|
93
|
+
tx_ref: z.object({
|
|
94
|
+
hash: z.string().transform((value) => value.startsWith("0x") ? value.slice(2) : value)
|
|
95
|
+
}).transform(({ hash }) => hash)
|
|
96
|
+
}),
|
|
97
|
+
Arbitrum: z.object({
|
|
98
|
+
tx_out_id: z.object({
|
|
99
|
+
signature: z.object({
|
|
100
|
+
k_times_g_address: z.array(z.number()),
|
|
101
|
+
s: z.array(z.number())
|
|
102
|
+
})
|
|
103
|
+
}),
|
|
104
|
+
tx_ref: z.object({
|
|
105
|
+
hash: hexString
|
|
106
|
+
}).transform(({ hash }) => hash)
|
|
107
|
+
})
|
|
108
|
+
};
|
|
109
|
+
var accountFee = z.object({
|
|
110
|
+
account: chainflipAddress,
|
|
111
|
+
bps: z.number()
|
|
112
|
+
}).transform(({ account, bps }) => ({ account, commissionBps: bps }));
|
|
113
|
+
var vaultDepositSchema = jsonString.pipe(
|
|
114
|
+
z.object({
|
|
115
|
+
amount: u128,
|
|
116
|
+
destination_address: z.string(),
|
|
117
|
+
input_asset: assetAndChain,
|
|
118
|
+
output_asset: assetAndChain,
|
|
119
|
+
deposit_chain_block_height: z.number().nullable().optional(),
|
|
120
|
+
affiliate_fees: z.array(accountFee),
|
|
121
|
+
broker_fee: accountFee.optional(),
|
|
122
|
+
max_boost_fee: z.number().optional(),
|
|
123
|
+
dca_params: z.object({
|
|
124
|
+
chunk_interval: z.number(),
|
|
125
|
+
number_of_chunks: z.number()
|
|
126
|
+
}).nullable().optional(),
|
|
127
|
+
refund_params: z.object({
|
|
128
|
+
min_price: u128,
|
|
129
|
+
retry_duration: z.number(),
|
|
130
|
+
refund_address: z.string()
|
|
131
|
+
}).nullable().optional(),
|
|
132
|
+
ccm_deposit_metadata: z.object({
|
|
133
|
+
channel_metadata: z.object({
|
|
134
|
+
ccm_additional_data: z.any(),
|
|
135
|
+
message: z.string(),
|
|
136
|
+
gas_budget: z.union([numericString, hexString]).transform((n) => hexEncodeNumber(BigInt(n)))
|
|
137
|
+
})
|
|
138
|
+
}).nullable().optional()
|
|
139
|
+
}).transform(transformKeysToCamelCase)
|
|
140
|
+
);
|
|
141
|
+
var mempoolTransaction = jsonString.pipe(
|
|
142
|
+
z.object({
|
|
143
|
+
confirmations: z.number(),
|
|
144
|
+
value: u128,
|
|
145
|
+
tx_hash: z.string(),
|
|
146
|
+
deposit_chain_block_height: z.number().optional()
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
var RedisClient = class {
|
|
150
|
+
client;
|
|
151
|
+
constructor(url) {
|
|
152
|
+
this.client = new Redis(url);
|
|
153
|
+
}
|
|
154
|
+
async getBroadcast(chain, broadcastId) {
|
|
155
|
+
if (chain === "Solana") return null;
|
|
156
|
+
const key = `broadcast:${chain}:${broadcastId}`;
|
|
157
|
+
const value = await this.client.get(key);
|
|
158
|
+
return value ? broadcastParsers[chain].parse(JSON.parse(value)) : null;
|
|
159
|
+
}
|
|
160
|
+
async getDeposits(asset, address) {
|
|
161
|
+
const { chain } = assetConstants[asset];
|
|
162
|
+
const parsedAddress = chain === "Polkadot" ? ss58.toPublicKey(address) : address;
|
|
163
|
+
const key = `deposit:${chain}:${parsedAddress}`;
|
|
164
|
+
const deposits = await this.client.lrange(key, 0, -1);
|
|
165
|
+
return deposits.map((depositString) => {
|
|
166
|
+
const parsedDeposit = depositSchema.parse(depositString);
|
|
167
|
+
const { deposit_details, ...deposit } = parsedDeposit;
|
|
168
|
+
switch (deposit_details?.type) {
|
|
169
|
+
case "EVM":
|
|
170
|
+
return { ...deposit, tx_refs: deposit_details.tx_hashes };
|
|
171
|
+
case "Bitcoin":
|
|
172
|
+
return { ...deposit, tx_refs: [deposit_details.tx_id] };
|
|
173
|
+
case "Polkadot":
|
|
174
|
+
return {
|
|
175
|
+
...deposit,
|
|
176
|
+
tx_refs: [`${deposit.deposit_chain_block_height}-${deposit_details.extrinsic_index}`]
|
|
177
|
+
};
|
|
178
|
+
default:
|
|
179
|
+
assert(deposit_details === null, "Invalid deposit details");
|
|
180
|
+
return { ...deposit, tx_refs: [] };
|
|
181
|
+
}
|
|
182
|
+
}).filter((deposit) => deposit.asset === asset).sort((a, b) => a.deposit_chain_block_height - b.deposit_chain_block_height);
|
|
183
|
+
}
|
|
184
|
+
async getMempoolTransaction(chain, address) {
|
|
185
|
+
const key = `mempool:${chain}:${address}`;
|
|
186
|
+
const value = await this.client.get(key);
|
|
187
|
+
return value ? mempoolTransaction.parse(value) : null;
|
|
188
|
+
}
|
|
189
|
+
async getPendingVaultSwap(chain, txId) {
|
|
190
|
+
const unavailableChains = ["Solana", "Polkadot", "Assethub"];
|
|
191
|
+
if (unavailableChains.includes(chain)) return null;
|
|
192
|
+
const redisTxId = chain === "Bitcoin" && isHex(`0x${txId}`) ? reverseBytes(`0x${txId}`) : txId;
|
|
193
|
+
const value = await this.client.get(`vault_deposit:${chain}:${redisTxId}`);
|
|
194
|
+
return value ? vaultDepositSchema.parse(value) : null;
|
|
195
|
+
}
|
|
196
|
+
quit() {
|
|
197
|
+
return this.client.quit();
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export { RedisClient as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chainflip/redis",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"repository": "https://github.com/chainflip-io/chainflip-product-toolkit.git",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"registry": "https://registry.npmjs.org/",
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"main": "dist/index.cjs",
|
|
15
|
+
"module": "dist/index.js",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@chainflip/utils": "0.8.2",
|
|
18
|
+
"bignumber.js": "^9.1.2",
|
|
19
|
+
"ioredis": "^5.6.0",
|
|
20
|
+
"zod": "^3.24.2"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"eslint:check": "pnpm eslint --max-warnings 0 './**/*.ts'",
|
|
24
|
+
"prettier:base": "prettier ./** --ignore-path=../../.prettierignore",
|
|
25
|
+
"prettier:check": "pnpm prettier:base --check",
|
|
26
|
+
"prettier:write": "pnpm prettier:base --write",
|
|
27
|
+
"prepublish": "pnpm build && pnpm test run",
|
|
28
|
+
"clean": "rm -rf dist",
|
|
29
|
+
"tsup:build": "tsup ./src/index.ts --format esm,cjs --dts --treeshake",
|
|
30
|
+
"build": "pnpm clean && pnpm tsup:build",
|
|
31
|
+
"test:ci": "CI=1 pnpm t run",
|
|
32
|
+
"test": "vitest"
|
|
33
|
+
}
|
|
34
|
+
}
|