@chainflip/rpc 2.0.7 → 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/parsers.mjs CHANGED
@@ -1,760 +1,752 @@
1
- // src/parsers.ts
1
+ import { z } from "zod";
2
2
  import { bytesToHex } from "@chainflip/utils/bytes";
3
3
  import { priceAssets } from "@chainflip/utils/chainflip";
4
4
  import { isUndefined } from "@chainflip/utils/guard";
5
5
  import { isHex } from "@chainflip/utils/string";
6
- import { z } from "zod";
7
- var accountId = z.string().refine((val) => val.startsWith("cF"));
8
- var hexString = z.string().refine(isHex, { message: "Invalid hex string" });
9
- var u256 = hexString.transform((value) => BigInt(value));
10
- var numericString = z.string().regex(/^[0-9]+$/);
11
- var numberOrHex = z.union([z.number(), u256, numericString]).transform((n) => BigInt(n));
12
- var chainAssetMapFactory = (parser, _defaultValue) => z.object({
13
- Bitcoin: z.object({ BTC: parser }),
14
- Ethereum: z.object({ ETH: parser, USDC: parser, FLIP: parser, USDT: parser }),
15
- Polkadot: z.object({ DOT: parser }),
16
- Arbitrum: z.object({ ETH: parser, USDC: parser }),
17
- Solana: z.object({ SOL: parser, USDC: parser }),
18
- Assethub: z.object({ DOT: parser, USDC: parser, USDT: parser })
19
- }).omit({ Polkadot: true });
20
- var chainBaseAssetMapFactory = (parser, _defaultValue) => z.object({
21
- Bitcoin: z.object({ BTC: parser }),
22
- Ethereum: z.object({ ETH: parser, FLIP: parser, USDT: parser }),
23
- Polkadot: z.object({ DOT: parser }),
24
- Arbitrum: z.object({ ETH: parser, USDC: parser }),
25
- Solana: z.object({ SOL: parser, USDC: parser }),
26
- Assethub: z.object({ DOT: parser, USDC: parser, USDT: parser })
27
- }).omit({ Polkadot: true });
28
- var chainMapFactory = (parser, _defaultValue) => z.object({
29
- Bitcoin: parser,
30
- Ethereum: parser,
31
- Polkadot: parser,
32
- Arbitrum: parser,
33
- Solana: parser,
34
- Assethub: parser
35
- }).omit({ Polkadot: true });
36
- var rpcAssetSchema = z.union([
37
- z.object({ chain: z.literal("Bitcoin"), asset: z.literal("BTC") }),
38
- z.object({ chain: z.literal("Polkadot"), asset: z.literal("DOT") }),
39
- z.object({ chain: z.literal("Ethereum"), asset: z.literal("FLIP") }),
40
- z.object({ chain: z.literal("Ethereum"), asset: z.literal("ETH") }),
41
- z.object({ chain: z.literal("Ethereum"), asset: z.literal("USDC") }),
42
- z.object({ chain: z.literal("Ethereum"), asset: z.literal("USDT") }),
43
- z.object({ chain: z.literal("Arbitrum"), asset: z.literal("ETH") }),
44
- z.object({ chain: z.literal("Arbitrum"), asset: z.literal("USDC") }),
45
- z.object({ chain: z.literal("Solana"), asset: z.literal("SOL") }),
46
- z.object({ chain: z.literal("Solana"), asset: z.literal("USDC") }),
47
- z.object({ chain: z.literal("Assethub"), asset: z.literal("DOT") }),
48
- z.object({ chain: z.literal("Assethub"), asset: z.literal("USDC") }),
49
- z.object({ chain: z.literal("Assethub"), asset: z.literal("USDT") })
6
+
7
+ //#region src/parsers.ts
8
+ const accountId = z.string().refine((val) => val.startsWith("cF"));
9
+ const hexString = z.string().refine(isHex, { message: "Invalid hex string" });
10
+ const u256 = hexString.transform((value) => BigInt(value));
11
+ const numericString = z.string().regex(/^[0-9]+$/);
12
+ const numberOrHex = z.union([
13
+ z.number(),
14
+ u256,
15
+ numericString
16
+ ]).transform((n) => BigInt(n));
17
+ const chainAssetMapFactory = (parser, defaultValue) => z.object({
18
+ Bitcoin: z.object({ BTC: parser }),
19
+ Ethereum: z.object({
20
+ ETH: parser,
21
+ USDC: parser,
22
+ FLIP: parser,
23
+ USDT: parser,
24
+ WBTC: parser.default(defaultValue)
25
+ }),
26
+ Arbitrum: z.object({
27
+ ETH: parser,
28
+ USDC: parser,
29
+ USDT: parser.default(defaultValue)
30
+ }),
31
+ Solana: z.object({
32
+ SOL: parser,
33
+ USDC: parser,
34
+ USDT: parser.default(defaultValue)
35
+ }),
36
+ Assethub: z.object({
37
+ DOT: parser,
38
+ USDC: parser,
39
+ USDT: parser
40
+ })
41
+ });
42
+ const chainBaseAssetMapFactory = (parser, defaultValue) => z.object({
43
+ Bitcoin: z.object({ BTC: parser }),
44
+ Ethereum: z.object({
45
+ ETH: parser,
46
+ FLIP: parser,
47
+ USDT: parser,
48
+ WBTC: parser.default(defaultValue)
49
+ }),
50
+ Arbitrum: z.object({
51
+ ETH: parser,
52
+ USDC: parser,
53
+ USDT: parser.default(defaultValue)
54
+ }),
55
+ Solana: z.object({
56
+ SOL: parser,
57
+ USDC: parser,
58
+ USDT: parser.default(defaultValue)
59
+ }),
60
+ Assethub: z.object({
61
+ DOT: parser,
62
+ USDC: parser,
63
+ USDT: parser
64
+ })
65
+ });
66
+ const chainMapFactory = (parser, _defaultValue) => z.object({
67
+ Bitcoin: parser,
68
+ Ethereum: parser,
69
+ Arbitrum: parser,
70
+ Solana: parser,
71
+ Assethub: parser
72
+ });
73
+ const rpcAssetSchema = z.union([
74
+ z.object({
75
+ chain: z.literal("Bitcoin"),
76
+ asset: z.literal("BTC")
77
+ }),
78
+ z.object({
79
+ chain: z.literal("Polkadot"),
80
+ asset: z.literal("DOT")
81
+ }),
82
+ z.object({
83
+ chain: z.literal("Ethereum"),
84
+ asset: z.literal("FLIP")
85
+ }),
86
+ z.object({
87
+ chain: z.literal("Ethereum"),
88
+ asset: z.literal("ETH")
89
+ }),
90
+ z.object({
91
+ chain: z.literal("Ethereum"),
92
+ asset: z.literal("USDC")
93
+ }),
94
+ z.object({
95
+ chain: z.literal("Ethereum"),
96
+ asset: z.literal("USDT")
97
+ }),
98
+ z.object({
99
+ chain: z.literal("Ethereum"),
100
+ asset: z.literal("WBTC")
101
+ }),
102
+ z.object({
103
+ chain: z.literal("Arbitrum"),
104
+ asset: z.literal("ETH")
105
+ }),
106
+ z.object({
107
+ chain: z.literal("Arbitrum"),
108
+ asset: z.literal("USDC")
109
+ }),
110
+ z.object({
111
+ chain: z.literal("Arbitrum"),
112
+ asset: z.literal("USDT")
113
+ }),
114
+ z.object({
115
+ chain: z.literal("Solana"),
116
+ asset: z.literal("SOL")
117
+ }),
118
+ z.object({
119
+ chain: z.literal("Solana"),
120
+ asset: z.literal("USDC")
121
+ }),
122
+ z.object({
123
+ chain: z.literal("Solana"),
124
+ asset: z.literal("USDT")
125
+ }),
126
+ z.object({
127
+ chain: z.literal("Assethub"),
128
+ asset: z.literal("DOT")
129
+ }),
130
+ z.object({
131
+ chain: z.literal("Assethub"),
132
+ asset: z.literal("USDC")
133
+ }),
134
+ z.object({
135
+ chain: z.literal("Assethub"),
136
+ asset: z.literal("USDT")
137
+ })
50
138
  ]);
51
- var networkFee = z.object({
52
- standard_rate_and_minimum: z.object({
53
- rate: numberOrHex,
54
- minimum: numberOrHex
55
- }),
56
- rates: chainAssetMapFactory(numberOrHex, 0)
57
- });
58
- var networkFees = z.object({
59
- regular_network_fee: networkFee,
60
- internal_swap_network_fee: networkFee
61
- });
62
- var rename = (mapping) => (obj) => Object.fromEntries(
63
- Object.entries(obj).map(([key, value]) => [
64
- key in mapping ? mapping[key] : key,
65
- value
66
- ])
67
- );
68
- var rpcBaseResponse = z.object({
69
- id: z.string(),
70
- jsonrpc: z.literal("2.0")
71
- });
72
- var notUndefined = z.any().refine((v) => !isUndefined(v), { message: "Value must not be undefined" });
73
- var rpcSuccessResponse = rpcBaseResponse.extend({ result: notUndefined });
74
- var rpcErrorResponse = rpcBaseResponse.extend({
75
- error: z.object({ code: z.number(), message: z.string() })
76
- });
77
- var rpcResponse = z.union([rpcSuccessResponse, rpcErrorResponse]);
78
- var cfSwapRate = z.object({
79
- intermediary: numberOrHex.nullable(),
80
- output: numberOrHex
81
- });
82
- var fee = z.intersection(rpcAssetSchema, z.object({ amount: numberOrHex }));
83
- var cfSwapRateV2 = z.object({
84
- egress_fee: fee,
85
- ingress_fee: fee,
86
- intermediary: u256.nullable(),
87
- network_fee: fee,
88
- output: u256
89
- });
90
- var cfSwapRateV3 = cfSwapRateV2.extend({
91
- broker_commission: fee
92
- });
93
- var chainGetBlockHash = hexString;
94
- var stateGetMetadata = hexString;
95
- var stateGetRuntimeVersion = z.object({
96
- specName: z.string(),
97
- implName: z.string(),
98
- authoringVersion: z.number(),
99
- specVersion: z.number(),
100
- implVersion: z.number(),
101
- apis: z.array(z.tuple([hexString, z.number()])),
102
- transactionVersion: z.number(),
103
- stateVersion: z.number()
104
- });
105
- var cfIngressEgressEnvironment = z.object({
106
- minimum_deposit_amounts: chainAssetMapFactory(numberOrHex, 0),
107
- ingress_fees: chainAssetMapFactory(numberOrHex.nullable(), null),
108
- egress_fees: chainAssetMapFactory(numberOrHex.nullable(), null),
109
- witness_safety_margins: chainMapFactory(z.number().nullable(), null),
110
- egress_dust_limits: chainAssetMapFactory(numberOrHex, 0),
111
- channel_opening_fees: chainMapFactory(numberOrHex, 0),
112
- ingress_delays: chainMapFactory(z.number(), 0).optional(),
113
- // TODO(1.12): remove after all networks upgraded
114
- boost_delays: chainMapFactory(z.number(), 0).optional()
115
- // TODO(1.12): remove after all networks upgraded
139
+ const networkFee = z.object({
140
+ standard_rate_and_minimum: z.object({
141
+ rate: numberOrHex,
142
+ minimum: numberOrHex
143
+ }),
144
+ rates: chainAssetMapFactory(numberOrHex, 0)
145
+ });
146
+ const networkFees = z.object({
147
+ regular_network_fee: networkFee,
148
+ internal_swap_network_fee: networkFee
149
+ });
150
+ const rename = (mapping) => (obj) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [key in mapping ? mapping[key] : key, value]));
151
+ const rpcBaseResponse = z.object({
152
+ id: z.string(),
153
+ jsonrpc: z.literal("2.0")
154
+ });
155
+ const notUndefined = z.any().refine((v) => !isUndefined(v), { message: "Value must not be undefined" });
156
+ const rpcSuccessResponse = rpcBaseResponse.extend({ result: notUndefined });
157
+ const rpcErrorResponse = rpcBaseResponse.extend({ error: z.object({
158
+ code: z.number(),
159
+ message: z.string()
160
+ }) });
161
+ const rpcResponse = z.union([rpcSuccessResponse, rpcErrorResponse]);
162
+ const cfSwapRate = z.object({
163
+ intermediary: numberOrHex.nullable(),
164
+ output: numberOrHex
165
+ });
166
+ const fee = z.intersection(rpcAssetSchema, z.object({ amount: numberOrHex }));
167
+ const cfSwapRateV2 = z.object({
168
+ egress_fee: fee,
169
+ ingress_fee: fee,
170
+ intermediary: u256.nullable(),
171
+ network_fee: fee,
172
+ output: u256
173
+ });
174
+ const cfSwapRateV3 = cfSwapRateV2.extend({ broker_commission: fee });
175
+ const chainGetBlockHash = hexString;
176
+ const stateGetMetadata = hexString;
177
+ const stateGetRuntimeVersion = z.object({
178
+ specName: z.string(),
179
+ implName: z.string(),
180
+ authoringVersion: z.number(),
181
+ specVersion: z.number(),
182
+ implVersion: z.number(),
183
+ apis: z.array(z.tuple([hexString, z.number()])),
184
+ transactionVersion: z.number(),
185
+ stateVersion: z.number()
186
+ });
187
+ const cfIngressEgressEnvironment = z.object({
188
+ minimum_deposit_amounts: chainAssetMapFactory(numberOrHex, 0),
189
+ ingress_fees: chainAssetMapFactory(numberOrHex.nullable(), null),
190
+ egress_fees: chainAssetMapFactory(numberOrHex.nullable(), null),
191
+ witness_safety_margins: chainMapFactory(z.number().nullable(), null),
192
+ egress_dust_limits: chainAssetMapFactory(numberOrHex, 0),
193
+ channel_opening_fees: chainMapFactory(numberOrHex, 0),
194
+ ingress_delays: chainMapFactory(z.number(), 0).optional(),
195
+ boost_delays: chainMapFactory(z.number(), 0).optional()
116
196
  }).transform(rename({ egress_dust_limits: "minimum_egress_amounts" }));
117
- var cfSwappingEnvironment = z.object({
118
- maximum_swap_amounts: chainAssetMapFactory(numberOrHex.nullable(), null),
119
- network_fee_hundredth_pips: z.number(),
120
- swap_retry_delay_blocks: z.number().optional(),
121
- max_swap_retry_duration_blocks: z.number().optional(),
122
- max_swap_request_duration_blocks: z.number().optional(),
123
- minimum_chunk_size: chainAssetMapFactory(numberOrHex.nullable(), null).optional(),
124
- network_fees: networkFees
125
- });
126
- var cfFundingEnvironment = z.object({
127
- redemption_tax: numberOrHex,
128
- minimum_funding_amount: numberOrHex
129
- });
130
- var defaultFeeInfo = () => ({
131
- limit_order_fee_hundredth_pips: 0,
132
- range_order_fee_hundredth_pips: 0,
133
- range_order_total_fees_earned: { base: "0x0", quote: "0x0" },
134
- limit_order_total_fees_earned: { base: "0x0", quote: "0x0" },
135
- range_total_swap_inputs: { base: "0x0", quote: "0x0" },
136
- limit_total_swap_inputs: { base: "0x0", quote: "0x0" },
137
- quote_asset: { chain: "Ethereum", asset: "USDC" }
138
- });
139
- var cfPoolsEnvironment = z.object({
140
- fees: chainBaseAssetMapFactory(
141
- z.object({
142
- limit_order_fee_hundredth_pips: z.number(),
143
- range_order_fee_hundredth_pips: z.number(),
144
- range_order_total_fees_earned: z.object({ base: u256, quote: u256 }),
145
- limit_order_total_fees_earned: z.object({ base: u256, quote: u256 }),
146
- range_total_swap_inputs: z.object({ base: u256, quote: u256 }),
147
- limit_total_swap_inputs: z.object({ base: u256, quote: u256 }),
148
- quote_asset: z.object({ chain: z.literal("Ethereum"), asset: z.literal("USDC") })
149
- }).nullable().transform((info) => info ?? defaultFeeInfo()),
150
- defaultFeeInfo()
151
- )
152
- });
153
- var cfEnvironment = z.object({
154
- ingress_egress: cfIngressEgressEnvironment,
155
- swapping: cfSwappingEnvironment,
156
- funding: cfFundingEnvironment,
157
- pools: cfPoolsEnvironment
158
- });
159
- var cfBoostPoolsDepth = z.array(
160
- z.intersection(rpcAssetSchema, z.object({ tier: z.number(), available_amount: u256 }))
161
- );
162
- var orderInfoSchema = z.object({
163
- depth: numberOrHex,
164
- price: numberOrHex.nullable()
165
- });
166
- var assetInfoSchema = z.object({
167
- limit_orders: orderInfoSchema,
168
- range_orders: orderInfoSchema
169
- });
170
- var cfPoolDepth = z.object({
171
- asks: assetInfoSchema,
172
- bids: assetInfoSchema
197
+ const cfSwappingEnvironment = z.object({
198
+ maximum_swap_amounts: chainAssetMapFactory(numberOrHex.nullable(), null),
199
+ network_fee_hundredth_pips: z.number(),
200
+ swap_retry_delay_blocks: z.number().optional(),
201
+ max_swap_retry_duration_blocks: z.number().optional(),
202
+ max_swap_request_duration_blocks: z.number().optional(),
203
+ minimum_chunk_size: chainAssetMapFactory(numberOrHex.nullable(), null).optional(),
204
+ network_fees: networkFees
205
+ });
206
+ const cfFundingEnvironment = z.object({
207
+ redemption_tax: numberOrHex,
208
+ minimum_funding_amount: numberOrHex
209
+ });
210
+ const defaultFeeInfo = () => ({
211
+ limit_order_fee_hundredth_pips: 0,
212
+ range_order_fee_hundredth_pips: 0,
213
+ range_order_total_fees_earned: {
214
+ base: "0x0",
215
+ quote: "0x0"
216
+ },
217
+ limit_order_total_fees_earned: {
218
+ base: "0x0",
219
+ quote: "0x0"
220
+ },
221
+ range_total_swap_inputs: {
222
+ base: "0x0",
223
+ quote: "0x0"
224
+ },
225
+ limit_total_swap_inputs: {
226
+ base: "0x0",
227
+ quote: "0x0"
228
+ },
229
+ quote_asset: {
230
+ chain: "Ethereum",
231
+ asset: "USDC"
232
+ }
233
+ });
234
+ const cfPoolsEnvironment = z.object({ fees: chainBaseAssetMapFactory(z.object({
235
+ limit_order_fee_hundredth_pips: z.number(),
236
+ range_order_fee_hundredth_pips: z.number(),
237
+ range_order_total_fees_earned: z.object({
238
+ base: u256,
239
+ quote: u256
240
+ }),
241
+ limit_order_total_fees_earned: z.object({
242
+ base: u256,
243
+ quote: u256
244
+ }),
245
+ range_total_swap_inputs: z.object({
246
+ base: u256,
247
+ quote: u256
248
+ }),
249
+ limit_total_swap_inputs: z.object({
250
+ base: u256,
251
+ quote: u256
252
+ }),
253
+ quote_asset: z.object({
254
+ chain: z.literal("Ethereum"),
255
+ asset: z.literal("USDC")
256
+ })
257
+ }).nullable().transform((info) => info ?? defaultFeeInfo()), defaultFeeInfo()) });
258
+ const cfEnvironment = z.object({
259
+ ingress_egress: cfIngressEgressEnvironment,
260
+ swapping: cfSwappingEnvironment,
261
+ funding: cfFundingEnvironment,
262
+ pools: cfPoolsEnvironment
263
+ });
264
+ const cfBoostPoolsDepth = z.array(z.intersection(rpcAssetSchema, z.object({
265
+ tier: z.number(),
266
+ available_amount: u256
267
+ })));
268
+ const orderInfoSchema = z.object({
269
+ depth: numberOrHex,
270
+ price: numberOrHex.nullable()
271
+ });
272
+ const assetInfoSchema = z.object({
273
+ limit_orders: orderInfoSchema,
274
+ range_orders: orderInfoSchema
275
+ });
276
+ const cfPoolDepth = z.object({
277
+ asks: assetInfoSchema,
278
+ bids: assetInfoSchema
173
279
  }).nullable();
174
- var cfSupportedAssets = z.array(z.object({ chain: z.string(), asset: z.string() })).transform(
175
- (assets) => assets.filter((asset) => rpcAssetSchema.safeParse(asset).success)
176
- );
177
- var brokerRequestSwapDepositAddress = z.object({
178
- address: z.string(),
179
- issued_block: z.number(),
180
- channel_id: z.number(),
181
- source_chain_expiry_block: numberOrHex,
182
- channel_opening_fee: u256
183
- });
184
- var brokerRequestAccountCreationDepositAddress = z.object({
185
- issued_block: z.number(),
186
- channel_id: z.number(),
187
- address: z.string(),
188
- requested_for: accountId,
189
- deposit_chain_expiry_block: numberOrHex,
190
- channel_opening_fee: u256,
191
- refund_address: z.string()
192
- });
193
- var evmBrokerRequestSwapParameterEncoding = z.object({
194
- to: hexString,
195
- calldata: hexString,
196
- value: numberOrHex,
197
- source_token_address: hexString.optional()
198
- });
199
- var requestSwapParameterEncoding = z.discriminatedUnion("chain", [
200
- z.object({
201
- chain: z.literal("Bitcoin"),
202
- nulldata_payload: hexString,
203
- deposit_address: z.string()
204
- }),
205
- evmBrokerRequestSwapParameterEncoding.extend({
206
- chain: z.literal("Ethereum")
207
- }),
208
- evmBrokerRequestSwapParameterEncoding.extend({
209
- chain: z.literal("Arbitrum")
210
- }),
211
- z.object({
212
- chain: z.literal("Solana"),
213
- program_id: z.string(),
214
- data: hexString,
215
- accounts: z.array(
216
- z.object({
217
- pubkey: z.string(),
218
- is_signer: z.boolean(),
219
- is_writable: z.boolean()
220
- })
221
- )
222
- })
280
+ const cfSupportedAssets = z.array(z.object({
281
+ chain: z.string(),
282
+ asset: z.string()
283
+ })).transform((assets) => assets.filter((asset) => rpcAssetSchema.safeParse(asset).success));
284
+ const brokerRequestSwapDepositAddress = z.object({
285
+ address: z.string(),
286
+ issued_block: z.number(),
287
+ channel_id: z.number(),
288
+ source_chain_expiry_block: numberOrHex,
289
+ channel_opening_fee: u256
290
+ });
291
+ const brokerRequestAccountCreationDepositAddress = z.object({
292
+ issued_block: z.number(),
293
+ channel_id: z.number(),
294
+ address: z.string(),
295
+ requested_for: accountId,
296
+ deposit_chain_expiry_block: numberOrHex,
297
+ channel_opening_fee: u256,
298
+ refund_address: z.string()
299
+ });
300
+ const evmBrokerRequestSwapParameterEncoding = z.object({
301
+ to: hexString,
302
+ calldata: hexString,
303
+ value: numberOrHex,
304
+ source_token_address: hexString.optional()
305
+ });
306
+ const requestSwapParameterEncoding = z.discriminatedUnion("chain", [
307
+ z.object({
308
+ chain: z.literal("Bitcoin"),
309
+ nulldata_payload: hexString,
310
+ deposit_address: z.string()
311
+ }),
312
+ evmBrokerRequestSwapParameterEncoding.extend({ chain: z.literal("Ethereum") }),
313
+ evmBrokerRequestSwapParameterEncoding.extend({ chain: z.literal("Arbitrum") }),
314
+ z.object({
315
+ chain: z.literal("Solana"),
316
+ program_id: z.string(),
317
+ data: hexString,
318
+ accounts: z.array(z.object({
319
+ pubkey: z.string(),
320
+ is_signer: z.boolean(),
321
+ is_writable: z.boolean()
322
+ }))
323
+ })
223
324
  ]);
224
- var delegationStatus = z.object({
225
- operator: accountId,
226
- bid: numberOrHex
227
- });
228
- var accountInfoCommon = {
229
- vanity_name: z.string().optional(),
230
- flip_balance: numberOrHex,
231
- asset_balances: chainAssetMapFactory(numberOrHex, 0),
232
- bond: numberOrHex,
233
- estimated_redeemable_balance: numberOrHex,
234
- bound_redeem_address: hexString.optional(),
235
- restricted_balances: z.record(hexString, numberOrHex).optional(),
236
- current_delegation_status: delegationStatus.optional(),
237
- upcoming_delegation_status: delegationStatus.optional()
325
+ const delegationStatus = z.object({
326
+ operator: accountId,
327
+ bid: numberOrHex
328
+ });
329
+ const accountInfoCommon = {
330
+ vanity_name: z.string().optional(),
331
+ flip_balance: numberOrHex,
332
+ asset_balances: chainAssetMapFactory(numberOrHex, 0),
333
+ bond: numberOrHex,
334
+ estimated_redeemable_balance: numberOrHex,
335
+ bound_redeem_address: hexString.optional(),
336
+ restricted_balances: z.record(hexString, numberOrHex).optional(),
337
+ current_delegation_status: delegationStatus.optional(),
338
+ upcoming_delegation_status: delegationStatus.optional()
238
339
  };
239
- var unregistered = z.object({
240
- role: z.literal("unregistered"),
241
- ...accountInfoCommon
242
- });
243
- var broker = z.object({
244
- role: z.literal("broker"),
245
- ...accountInfoCommon,
246
- earned_fees: chainAssetMapFactory(numberOrHex, 0),
247
- btc_vault_deposit_address: z.string().nullable().optional(),
248
- affiliates: z.array(z.object({ account_id: accountId, short_id: z.number(), withdrawal_address: hexString })).optional().default([])
249
- });
250
- var operator = z.object({
251
- role: z.literal("operator"),
252
- ...accountInfoCommon,
253
- managed_validators: z.record(accountId, numberOrHex),
254
- delegators: z.record(accountId, numberOrHex),
255
- settings: z.object({
256
- fee_bps: z.number(),
257
- delegation_acceptance: z.enum(["Allow", "Deny"])
258
- }),
259
- allowed: z.array(accountId).optional().default([]),
260
- blocked: z.array(accountId).optional().default([]),
261
- active_delegation: z.object({
262
- operator: accountId,
263
- validators: z.record(accountId, numberOrHex),
264
- delegators: z.record(accountId, numberOrHex),
265
- delegation_fee_bps: z.number()
266
- }).optional()
267
- });
268
- var boostBalances = z.array(
269
- z.object({
270
- fee_tier: z.number(),
271
- total_balance: u256,
272
- available_balance: u256,
273
- in_use_balance: u256,
274
- is_withdrawing: z.boolean()
275
- })
276
- );
277
- var liquidityProvider = z.object({
278
- role: z.literal("liquidity_provider"),
279
- ...accountInfoCommon,
280
- refund_addresses: chainMapFactory(z.string().nullable(), null),
281
- earned_fees: chainAssetMapFactory(numberOrHex, 0),
282
- boost_balances: chainAssetMapFactory(boostBalances, []),
283
- lending_positions: z.array(
284
- z.intersection(
285
- rpcAssetSchema,
286
- z.object({
287
- total_amount: numberOrHex,
288
- available_amount: numberOrHex
289
- })
290
- )
291
- ).optional(),
292
- collateral_balances: z.array(
293
- z.intersection(
294
- rpcAssetSchema,
295
- z.object({
296
- amount: numberOrHex
297
- })
298
- )
299
- ).optional()
300
- });
301
- var validator = z.object({
302
- role: z.literal("validator"),
303
- ...accountInfoCommon,
304
- last_heartbeat: z.number(),
305
- reputation_points: z.number(),
306
- keyholder_epochs: z.array(z.number()),
307
- is_current_authority: z.boolean(),
308
- is_current_backup: z.boolean(),
309
- is_qualified: z.boolean(),
310
- is_online: z.boolean(),
311
- is_bidding: z.boolean(),
312
- apy_bp: z.number().nullable(),
313
- operator: accountId.optional()
314
- });
315
- var cfAccountInfo = z.discriminatedUnion("role", [unregistered, broker, operator, liquidityProvider, validator]).transform((account) => {
316
- switch (account.role) {
317
- case "broker":
318
- case "validator":
319
- case "unregistered":
320
- case "liquidity_provider":
321
- return account;
322
- case "operator": {
323
- const { managed_validators, delegators, settings, ...rest } = account;
324
- return {
325
- ...rest,
326
- upcoming_delegation: {
327
- validators: managed_validators,
328
- delegators,
329
- delegation_fee_bps: settings.fee_bps,
330
- delegation_acceptance: settings.delegation_acceptance
331
- }
332
- };
333
- }
334
- }
335
- });
336
- var cfAccounts = z.array(z.tuple([accountId, z.string()]));
337
- var cfPoolPriceV2 = z.object({
338
- sell: numberOrHex.nullable(),
339
- buy: numberOrHex.nullable(),
340
- range_order: numberOrHex,
341
- base_asset: rpcAssetSchema,
342
- quote_asset: rpcAssetSchema
343
- });
344
- var orderId = numberOrHex.transform((n) => String(n));
345
- var limitOrder = z.object({
346
- id: orderId,
347
- tick: z.number(),
348
- sell_amount: numberOrHex,
349
- fees_earned: numberOrHex,
350
- original_sell_amount: numberOrHex,
351
- lp: z.string()
352
- });
353
- var ask = limitOrder.transform((order) => ({
354
- ...order,
355
- type: "ask"
340
+ const unregistered = z.object({
341
+ role: z.literal("unregistered"),
342
+ ...accountInfoCommon
343
+ });
344
+ const broker = z.object({
345
+ role: z.literal("broker"),
346
+ ...accountInfoCommon,
347
+ earned_fees: chainAssetMapFactory(numberOrHex, 0),
348
+ btc_vault_deposit_address: z.string().nullable().optional(),
349
+ affiliates: z.array(z.object({
350
+ account_id: accountId,
351
+ short_id: z.number(),
352
+ withdrawal_address: hexString
353
+ })).optional().default([])
354
+ });
355
+ const operator = z.object({
356
+ role: z.literal("operator"),
357
+ ...accountInfoCommon,
358
+ managed_validators: z.record(accountId, numberOrHex),
359
+ delegators: z.record(accountId, numberOrHex),
360
+ settings: z.object({
361
+ fee_bps: z.number(),
362
+ delegation_acceptance: z.enum(["Allow", "Deny"])
363
+ }),
364
+ allowed: z.array(accountId).optional().default([]),
365
+ blocked: z.array(accountId).optional().default([]),
366
+ active_delegation: z.object({
367
+ operator: accountId,
368
+ validators: z.record(accountId, numberOrHex),
369
+ delegators: z.record(accountId, numberOrHex),
370
+ delegation_fee_bps: z.number()
371
+ }).optional()
372
+ });
373
+ const boostBalances = z.array(z.object({
374
+ fee_tier: z.number(),
375
+ total_balance: u256,
376
+ available_balance: u256,
377
+ in_use_balance: u256,
378
+ is_withdrawing: z.boolean()
379
+ }));
380
+ const liquidityProvider = z.object({
381
+ role: z.literal("liquidity_provider"),
382
+ ...accountInfoCommon,
383
+ refund_addresses: chainMapFactory(z.string().nullable(), null),
384
+ earned_fees: chainAssetMapFactory(numberOrHex, 0),
385
+ boost_balances: chainAssetMapFactory(boostBalances, []),
386
+ lending_positions: z.array(z.intersection(rpcAssetSchema, z.object({
387
+ total_amount: numberOrHex,
388
+ available_amount: numberOrHex
389
+ }))).optional(),
390
+ collateral_balances: z.array(z.intersection(rpcAssetSchema, z.object({ amount: numberOrHex }))).optional()
391
+ });
392
+ const validator = z.object({
393
+ role: z.literal("validator"),
394
+ ...accountInfoCommon,
395
+ last_heartbeat: z.number(),
396
+ reputation_points: z.number(),
397
+ keyholder_epochs: z.array(z.number()),
398
+ is_current_authority: z.boolean(),
399
+ is_current_backup: z.boolean(),
400
+ is_qualified: z.boolean(),
401
+ is_online: z.boolean(),
402
+ is_bidding: z.boolean(),
403
+ apy_bp: z.number().nullable(),
404
+ operator: accountId.optional()
405
+ });
406
+ const cfAccountInfo = z.discriminatedUnion("role", [
407
+ unregistered,
408
+ broker,
409
+ operator,
410
+ liquidityProvider,
411
+ validator
412
+ ]).transform((account) => {
413
+ switch (account.role) {
414
+ case "broker":
415
+ case "validator":
416
+ case "unregistered":
417
+ case "liquidity_provider": return account;
418
+ case "operator": {
419
+ const { managed_validators, delegators, settings, ...rest } = account;
420
+ return {
421
+ ...rest,
422
+ upcoming_delegation: {
423
+ validators: managed_validators,
424
+ delegators,
425
+ delegation_fee_bps: settings.fee_bps,
426
+ delegation_acceptance: settings.delegation_acceptance
427
+ }
428
+ };
429
+ }
430
+ }
431
+ });
432
+ const cfAccounts = z.array(z.tuple([accountId, z.string()]));
433
+ const cfPoolPriceV2 = z.object({
434
+ sell: numberOrHex.nullable(),
435
+ buy: numberOrHex.nullable(),
436
+ range_order: numberOrHex,
437
+ base_asset: rpcAssetSchema,
438
+ quote_asset: rpcAssetSchema
439
+ });
440
+ const orderId = numberOrHex.transform((n) => String(n));
441
+ const limitOrder = z.object({
442
+ id: orderId,
443
+ tick: z.number(),
444
+ sell_amount: numberOrHex,
445
+ fees_earned: numberOrHex,
446
+ original_sell_amount: numberOrHex,
447
+ lp: z.string()
448
+ });
449
+ const ask = limitOrder.transform((order) => ({
450
+ ...order,
451
+ type: "ask"
452
+ }));
453
+ const bid = limitOrder.transform((order) => ({
454
+ ...order,
455
+ type: "bid"
356
456
  }));
357
- var bid = limitOrder.transform((order) => ({
358
- ...order,
359
- type: "bid"
457
+ const rangeOrder = z.object({
458
+ id: orderId,
459
+ range: z.object({
460
+ start: z.number(),
461
+ end: z.number()
462
+ }),
463
+ liquidity: numberOrHex,
464
+ fees_earned: z.object({
465
+ base: numberOrHex,
466
+ quote: numberOrHex
467
+ }),
468
+ lp: z.string()
469
+ }).transform((order) => ({
470
+ ...order,
471
+ type: "range"
360
472
  }));
361
- var rangeOrder = z.object({
362
- id: orderId,
363
- range: z.object({ start: z.number(), end: z.number() }),
364
- liquidity: numberOrHex,
365
- fees_earned: z.object({ base: numberOrHex, quote: numberOrHex }),
366
- lp: z.string()
367
- }).transform((order) => ({ ...order, type: "range" }));
368
- var cfPoolOrders = z.object({
369
- limit_orders: z.object({
370
- asks: z.array(ask),
371
- bids: z.array(bid)
372
- }),
373
- range_orders: z.array(rangeOrder)
374
- });
375
- var boostPoolAmount = z.object({
376
- account_id: z.string(),
377
- amount: u256
378
- });
379
- var cfBoostPoolDetails = z.array(
380
- z.intersection(
381
- rpcAssetSchema,
382
- z.object({
383
- fee_tier: z.number(),
384
- available_amounts: z.array(boostPoolAmount),
385
- deposits_pending_finalization: z.array(
386
- z.object({
387
- deposit_id: numberOrHex,
388
- owed_amounts: z.array(boostPoolAmount)
389
- })
390
- ),
391
- pending_withdrawals: z.array(
392
- z.object({
393
- account_id: z.string(),
394
- pending_deposits: z.array(numberOrHex)
395
- })
396
- ),
397
- network_fee_deduction_percent: z.number().optional()
398
- })
399
- )
400
- );
401
- var cfBoostPoolPendingFees = z.array(
402
- z.intersection(
403
- rpcAssetSchema,
404
- z.object({
405
- fee_tier: z.number(),
406
- pending_fees: z.array(
407
- z.object({
408
- deposit_id: z.number().transform(BigInt),
409
- fees: z.array(boostPoolAmount)
410
- })
411
- )
412
- })
413
- )
414
- );
415
- var lpTotalBalances = chainAssetMapFactory(numberOrHex, 0);
416
- var cfFailedCallEvm = z.object({
417
- contract: hexString,
418
- data: z.string()
419
- });
420
- var range = (parser) => z.tuple([parser, parser]);
421
- var cfAuctionState = z.object({
422
- epoch_duration: z.number(),
423
- current_epoch_started_at: z.number(),
424
- redemption_period_as_percentage: z.number(),
425
- min_funding: numberOrHex,
426
- auction_size_range: range(z.number()),
427
- min_active_bid: numberOrHex.nullable(),
428
- min_bid: numberOrHex
473
+ const cfPoolOrders = z.object({
474
+ limit_orders: z.object({
475
+ asks: z.array(ask),
476
+ bids: z.array(bid)
477
+ }),
478
+ range_orders: z.array(rangeOrder)
479
+ });
480
+ const boostPoolAmount = z.object({
481
+ account_id: z.string(),
482
+ amount: u256
483
+ });
484
+ const cfBoostPoolDetails = z.array(z.intersection(rpcAssetSchema, z.object({
485
+ fee_tier: z.number(),
486
+ available_amounts: z.array(boostPoolAmount),
487
+ deposits_pending_finalization: z.array(z.object({
488
+ deposit_id: numberOrHex,
489
+ owed_amounts: z.array(boostPoolAmount)
490
+ })),
491
+ pending_withdrawals: z.array(z.object({
492
+ account_id: z.string(),
493
+ pending_deposits: z.array(numberOrHex)
494
+ })),
495
+ network_fee_deduction_percent: z.number().optional()
496
+ })));
497
+ const cfBoostPoolPendingFees = z.array(z.intersection(rpcAssetSchema, z.object({
498
+ fee_tier: z.number(),
499
+ pending_fees: z.array(z.object({
500
+ deposit_id: z.number().transform(BigInt),
501
+ fees: z.array(boostPoolAmount)
502
+ }))
503
+ })));
504
+ const lpTotalBalances = chainAssetMapFactory(numberOrHex, 0);
505
+ const cfFailedCallEvm = z.object({
506
+ contract: hexString,
507
+ data: z.string()
508
+ });
509
+ const range = (parser) => z.tuple([parser, parser]);
510
+ const cfAuctionState = z.object({
511
+ epoch_duration: z.number(),
512
+ current_epoch_started_at: z.number(),
513
+ redemption_period_as_percentage: z.number(),
514
+ min_funding: numberOrHex,
515
+ auction_size_range: range(z.number()),
516
+ min_active_bid: numberOrHex.nullable(),
517
+ min_bid: numberOrHex
429
518
  }).transform(rename({ epoch_duration: "epoch_duration_blocks" }));
430
- var cfMonitoringSimulateAuction = z.object({
431
- auction_outcome: z.object({
432
- winners: z.array(accountId),
433
- bond: numberOrHex
434
- }),
435
- operators_info: z.record(
436
- accountId,
437
- z.object({
438
- operator: accountId,
439
- validators: z.record(accountId, numberOrHex),
440
- delegators: z.record(accountId, numberOrHex),
441
- delegation_fee_bps: z.number()
442
- })
443
- ),
444
- new_validators: z.array(accountId),
445
- current_mab: numberOrHex
446
- });
447
- var cfFlipSuppy = range(numberOrHex).transform(([totalIssuance, offchainFunds]) => ({
448
- totalIssuance,
449
- offchainFunds
519
+ const cfMonitoringSimulateAuction = z.object({
520
+ auction_outcome: z.object({
521
+ winners: z.array(accountId),
522
+ bond: numberOrHex
523
+ }),
524
+ operators_info: z.record(accountId, z.object({
525
+ operator: accountId,
526
+ validators: z.record(accountId, numberOrHex),
527
+ delegators: z.record(accountId, numberOrHex),
528
+ delegation_fee_bps: z.number()
529
+ })),
530
+ new_validators: z.array(accountId),
531
+ current_mab: numberOrHex
532
+ });
533
+ const cfFlipSuppy = range(numberOrHex).transform(([totalIssuance, offchainFunds]) => ({
534
+ totalIssuance,
535
+ offchainFunds
450
536
  }));
451
- var ethereumAddress = z.string().transform((address) => `0x${address}`);
452
- var cfPoolOrderbook = z.object({
453
- bids: z.array(z.object({ amount: u256, sqrt_price: u256 })),
454
- asks: z.array(z.object({ amount: u256, sqrt_price: u256 }))
455
- });
456
- var cfTradingStrategy = z.object({
457
- lp_id: z.string(),
458
- strategy_id: z.string(),
459
- strategy: z.union([
460
- z.object({
461
- TickZeroCentered: z.object({
462
- spread_tick: z.number(),
463
- base_asset: rpcAssetSchema
464
- })
465
- }),
466
- z.object({
467
- SimpleBuySell: z.object({
468
- buy_tick: z.number(),
469
- sell_tick: z.number(),
470
- base_asset: rpcAssetSchema
471
- })
472
- }),
473
- z.object({
474
- InventoryBased: z.object({
475
- min_buy_tick: z.number(),
476
- max_buy_tick: z.number(),
477
- min_sell_tick: z.number(),
478
- max_sell_tick: z.number(),
479
- base_asset: rpcAssetSchema
480
- })
481
- })
482
- ]),
483
- balance: z.array(z.tuple([rpcAssetSchema, numberOrHex]))
484
- });
485
- var cfGetTradingStrategies = z.array(cfTradingStrategy).default([]);
486
- var cfGetTradingStrategyLimits = z.object({
487
- minimum_deployment_amount: chainAssetMapFactory(z.number().nullable(), null),
488
- minimum_added_funds_amount: chainAssetMapFactory(z.number().nullable(), null)
489
- });
490
- var cfAvailablePools = z.array(
491
- z.object({
492
- base: rpcAssetSchema.refine(
493
- (a) => a.chain !== "Ethereum" || a.asset !== "USDC"
494
- ),
495
- quote: z.object({ chain: z.literal("Ethereum"), asset: z.literal("USDC") })
496
- })
497
- );
498
- var cfOraclePrices = z.array(
499
- z.object({
500
- price: numberOrHex,
501
- updated_at_oracle_timestamp: z.number(),
502
- updated_at_statechain_block: z.number(),
503
- base_asset: z.enum(priceAssets),
504
- quote_asset: z.enum(priceAssets),
505
- price_status: z.enum(["UpToDate", "Stale", "MaybeStale"]).optional()
506
- // TODO remove `optional` after backspin updates
507
- })
508
- );
509
- var broadcastPalletSafeModeStatuses = z.object({
510
- retry_enabled: z.boolean(),
511
- egress_witnessing_enabled: z.boolean()
512
- });
513
- var ingressEgressPalletSafeModeStatuses = z.object({
514
- boost_deposits_enabled: z.boolean(),
515
- deposit_channel_creation_enabled: z.boolean(),
516
- deposit_channel_witnessing_enabled: z.boolean(),
517
- vault_deposit_witnessing_enabled: z.boolean()
518
- });
519
- var cfSafeModeStatuses = z.object({
520
- emissions: z.object({
521
- emissions_sync_enabled: z.boolean()
522
- }),
523
- funding: z.object({
524
- redeem_enabled: z.boolean()
525
- }),
526
- swapping: z.object({
527
- swaps_enabled: z.boolean(),
528
- withdrawals_enabled: z.boolean(),
529
- broker_registration_enabled: z.boolean()
530
- }),
531
- liquidity_provider: z.object({
532
- deposit_enabled: z.boolean(),
533
- withdrawal_enabled: z.boolean(),
534
- internal_swaps_enabled: z.boolean()
535
- }),
536
- validator: z.object({
537
- authority_rotation_enabled: z.boolean(),
538
- start_bidding_enabled: z.boolean(),
539
- stop_bidding_enabled: z.boolean()
540
- }),
541
- pools: z.object({
542
- range_order_update_enabled: z.boolean(),
543
- limit_order_update_enabled: z.boolean()
544
- }),
545
- trading_strategies: z.object({
546
- strategy_updates_enabled: z.boolean(),
547
- strategy_closure_enabled: z.boolean(),
548
- strategy_execution_enabled: z.boolean()
549
- }),
550
- reputation: z.object({
551
- reporting_enabled: z.boolean()
552
- }),
553
- asset_balances: z.object({
554
- reconciliation_enabled: z.boolean()
555
- }),
556
- threshold_signature_evm: z.object({
557
- slashing_enabled: z.boolean()
558
- }),
559
- threshold_signature_bitcoin: z.object({
560
- slashing_enabled: z.boolean()
561
- }),
562
- threshold_signature_polkadot: z.object({
563
- slashing_enabled: z.boolean()
564
- }),
565
- threshold_signature_solana: z.object({
566
- slashing_enabled: z.boolean()
567
- }),
568
- lending_pools: z.object({
569
- add_boost_funds_enabled: z.boolean(),
570
- stop_boosting_enabled: z.boolean(),
571
- // TODO(1.12): remove `optional` after all networks upgraded
572
- borrowing_enabled: z.array(rpcAssetSchema).optional(),
573
- add_lender_funds_enabled: z.array(rpcAssetSchema).optional(),
574
- withdraw_lender_funds_enabled: z.array(rpcAssetSchema).optional(),
575
- add_collateral_enabled: z.array(rpcAssetSchema).optional(),
576
- remove_collateral_enabled: z.array(rpcAssetSchema).optional()
577
- }),
578
- broadcast_ethereum: broadcastPalletSafeModeStatuses,
579
- broadcast_bitcoin: broadcastPalletSafeModeStatuses,
580
- broadcast_polkadot: broadcastPalletSafeModeStatuses,
581
- broadcast_arbitrum: broadcastPalletSafeModeStatuses,
582
- broadcast_solana: broadcastPalletSafeModeStatuses,
583
- broadcast_assethub: broadcastPalletSafeModeStatuses,
584
- ingress_egress_ethereum: ingressEgressPalletSafeModeStatuses,
585
- ingress_egress_bitcoin: ingressEgressPalletSafeModeStatuses,
586
- ingress_egress_polkadot: ingressEgressPalletSafeModeStatuses,
587
- ingress_egress_arbitrum: ingressEgressPalletSafeModeStatuses,
588
- ingress_egress_solana: ingressEgressPalletSafeModeStatuses,
589
- ingress_egress_assethub: ingressEgressPalletSafeModeStatuses,
590
- witnesser: z.enum(["CodeRed", "CodeGreen", "CodeAmber"]),
591
- elections_generic: z.object({
592
- oracle_price_elections: z.boolean()
593
- })
594
- });
595
- var cfLendingPools = z.array(
596
- z.object({
597
- asset: rpcAssetSchema,
598
- total_amount: numberOrHex,
599
- available_amount: numberOrHex,
600
- utilisation_rate: z.number(),
601
- current_interest_rate: z.number(),
602
- origination_fee: z.number(),
603
- liquidation_fee: z.number(),
604
- interest_rate_curve: z.object({
605
- interest_at_zero_utilisation: z.number(),
606
- junction_utilisation: z.number(),
607
- interest_at_junction_utilisation: z.number(),
608
- interest_at_max_utilisation: z.number()
609
- })
610
- })
611
- );
612
- var cfLendingConfig = z.object({
613
- ltv_thresholds: z.object({
614
- target: z.number(),
615
- topup: z.number().nullable(),
616
- soft_liquidation: z.number(),
617
- soft_liquidation_abort: z.number(),
618
- hard_liquidation: z.number(),
619
- hard_liquidation_abort: z.number(),
620
- low_ltv: z.number().nullable()
621
- }),
622
- network_fee_contributions: z.object({
623
- extra_interest: z.number(),
624
- low_ltv_penalty_max: z.number().nullable(),
625
- from_origination_fee: z.number(),
626
- from_liquidation_fee: z.number()
627
- }),
628
- fee_swap_interval_blocks: z.number(),
629
- interest_payment_interval_blocks: z.number(),
630
- fee_swap_threshold_usd: numberOrHex,
631
- interest_collection_threshold_usd: numberOrHex,
632
- soft_liquidation_swap_chunk_size_usd: numberOrHex,
633
- hard_liquidation_swap_chunk_size_usd: numberOrHex,
634
- soft_liquidation_max_oracle_slippage: z.number(),
635
- hard_liquidation_max_oracle_slippage: z.number(),
636
- fee_swap_max_oracle_slippage: z.number(),
637
- minimum_loan_amount_usd: numberOrHex,
638
- minimum_supply_amount_usd: numberOrHex,
639
- minimum_update_loan_amount_usd: numberOrHex,
640
- minimum_update_collateral_amount_usd: numberOrHex
641
- });
642
- var cfLoanAccount = z.object({
643
- account: accountId,
644
- collateral_topup_asset: rpcAssetSchema.nullable(),
645
- ltv_ratio: numberOrHex.nullable(),
646
- collateral: z.array(
647
- z.intersection(
648
- rpcAssetSchema,
649
- z.object({
650
- amount: numberOrHex
651
- })
652
- )
653
- ),
654
- loans: z.array(
655
- z.object({
656
- loan_id: z.number(),
657
- asset: rpcAssetSchema,
658
- principal_amount: numberOrHex
659
- })
660
- ),
661
- liquidation_status: z.object({
662
- liquidation_swaps: z.array(
663
- z.object({
664
- swap_request_id: z.number(),
665
- loan_id: z.number()
666
- })
667
- ),
668
- liquidation_type: z.enum(["SoftVoluntary", "Soft", "Hard"])
669
- }).nullable()
670
- });
671
- var cfLoanAccounts = z.array(cfLoanAccount);
672
- var cfLendingPoolSupplyBalances = z.array(
673
- z.intersection(
674
- rpcAssetSchema,
675
- z.object({
676
- positions: z.array(
677
- z.object({
678
- lp_id: accountId,
679
- total_amount: numberOrHex
680
- })
681
- )
682
- })
683
- )
684
- );
685
- var cfVaultAddresses = z.object({
686
- ethereum: z.object({ Eth: z.array(z.number()).length(20).transform(bytesToHex) }),
687
- arbitrum: z.object({ Arb: z.array(z.number()).length(20).transform(bytesToHex) }),
688
- bitcoin: z.array(
689
- z.tuple([
690
- accountId,
691
- z.object({
692
- Btc: z.array(z.number()).transform((bytes) => new TextDecoder().decode(new Uint8Array(bytes)))
693
- })
694
- ])
695
- )
537
+ const ethereumAddress = z.string().transform((address) => `0x${address}`);
538
+ const cfPoolOrderbook = z.object({
539
+ bids: z.array(z.object({
540
+ amount: u256,
541
+ sqrt_price: u256
542
+ })),
543
+ asks: z.array(z.object({
544
+ amount: u256,
545
+ sqrt_price: u256
546
+ }))
547
+ });
548
+ const cfTradingStrategy = z.object({
549
+ lp_id: z.string(),
550
+ strategy_id: z.string(),
551
+ strategy: z.union([
552
+ z.object({ TickZeroCentered: z.object({
553
+ spread_tick: z.number(),
554
+ base_asset: rpcAssetSchema
555
+ }) }),
556
+ z.object({ SimpleBuySell: z.object({
557
+ buy_tick: z.number(),
558
+ sell_tick: z.number(),
559
+ base_asset: rpcAssetSchema
560
+ }) }),
561
+ z.object({ InventoryBased: z.object({
562
+ min_buy_tick: z.number(),
563
+ max_buy_tick: z.number(),
564
+ min_sell_tick: z.number(),
565
+ max_sell_tick: z.number(),
566
+ base_asset: rpcAssetSchema
567
+ }) })
568
+ ]),
569
+ balance: z.array(z.tuple([rpcAssetSchema, numberOrHex]))
570
+ });
571
+ const cfGetTradingStrategies = z.array(cfTradingStrategy).default([]);
572
+ const cfGetTradingStrategyLimits = z.object({
573
+ minimum_deployment_amount: chainAssetMapFactory(z.number().nullable(), null),
574
+ minimum_added_funds_amount: chainAssetMapFactory(z.number().nullable(), null)
575
+ });
576
+ const cfAvailablePools = z.array(z.object({
577
+ base: rpcAssetSchema.refine((a) => a.chain !== "Ethereum" || a.asset !== "USDC"),
578
+ quote: z.object({
579
+ chain: z.literal("Ethereum"),
580
+ asset: z.literal("USDC")
581
+ })
582
+ }));
583
+ const cfOraclePrices = z.array(z.object({
584
+ price: numberOrHex,
585
+ updated_at_oracle_timestamp: z.number(),
586
+ updated_at_statechain_block: z.number(),
587
+ base_asset: z.enum(priceAssets),
588
+ quote_asset: z.enum(priceAssets),
589
+ price_status: z.enum([
590
+ "UpToDate",
591
+ "Stale",
592
+ "MaybeStale"
593
+ ]).optional()
594
+ }));
595
+ const broadcastPalletSafeModeStatuses = z.object({
596
+ retry_enabled: z.boolean(),
597
+ egress_witnessing_enabled: z.boolean()
598
+ });
599
+ const ingressEgressPalletSafeModeStatuses = z.object({
600
+ boost_deposits_enabled: z.boolean(),
601
+ deposit_channel_creation_enabled: z.boolean(),
602
+ deposit_channel_witnessing_enabled: z.boolean(),
603
+ vault_deposit_witnessing_enabled: z.boolean()
604
+ });
605
+ const cfSafeModeStatuses = z.object({
606
+ emissions: z.object({ emissions_sync_enabled: z.boolean() }),
607
+ funding: z.object({ redeem_enabled: z.boolean() }),
608
+ swapping: z.object({
609
+ swaps_enabled: z.boolean(),
610
+ withdrawals_enabled: z.boolean(),
611
+ broker_registration_enabled: z.boolean()
612
+ }),
613
+ liquidity_provider: z.object({
614
+ deposit_enabled: z.boolean(),
615
+ withdrawal_enabled: z.boolean(),
616
+ internal_swaps_enabled: z.boolean()
617
+ }),
618
+ validator: z.object({
619
+ authority_rotation_enabled: z.boolean(),
620
+ start_bidding_enabled: z.boolean(),
621
+ stop_bidding_enabled: z.boolean()
622
+ }),
623
+ pools: z.object({
624
+ range_order_update_enabled: z.boolean(),
625
+ limit_order_update_enabled: z.boolean()
626
+ }),
627
+ trading_strategies: z.object({
628
+ strategy_updates_enabled: z.boolean(),
629
+ strategy_closure_enabled: z.boolean(),
630
+ strategy_execution_enabled: z.boolean()
631
+ }),
632
+ reputation: z.object({ reporting_enabled: z.boolean() }),
633
+ asset_balances: z.object({ reconciliation_enabled: z.boolean() }),
634
+ threshold_signature_evm: z.object({ slashing_enabled: z.boolean() }),
635
+ threshold_signature_bitcoin: z.object({ slashing_enabled: z.boolean() }),
636
+ threshold_signature_polkadot: z.object({ slashing_enabled: z.boolean() }),
637
+ threshold_signature_solana: z.object({ slashing_enabled: z.boolean() }),
638
+ lending_pools: z.object({
639
+ add_boost_funds_enabled: z.boolean(),
640
+ stop_boosting_enabled: z.boolean(),
641
+ borrowing_enabled: z.array(rpcAssetSchema).optional(),
642
+ add_lender_funds_enabled: z.array(rpcAssetSchema).optional(),
643
+ withdraw_lender_funds_enabled: z.array(rpcAssetSchema).optional(),
644
+ add_collateral_enabled: z.array(rpcAssetSchema).optional(),
645
+ remove_collateral_enabled: z.array(rpcAssetSchema).optional()
646
+ }),
647
+ broadcast_ethereum: broadcastPalletSafeModeStatuses,
648
+ broadcast_bitcoin: broadcastPalletSafeModeStatuses,
649
+ broadcast_polkadot: broadcastPalletSafeModeStatuses,
650
+ broadcast_arbitrum: broadcastPalletSafeModeStatuses,
651
+ broadcast_solana: broadcastPalletSafeModeStatuses,
652
+ broadcast_assethub: broadcastPalletSafeModeStatuses,
653
+ ingress_egress_ethereum: ingressEgressPalletSafeModeStatuses,
654
+ ingress_egress_bitcoin: ingressEgressPalletSafeModeStatuses,
655
+ ingress_egress_polkadot: ingressEgressPalletSafeModeStatuses,
656
+ ingress_egress_arbitrum: ingressEgressPalletSafeModeStatuses,
657
+ ingress_egress_solana: ingressEgressPalletSafeModeStatuses,
658
+ ingress_egress_assethub: ingressEgressPalletSafeModeStatuses,
659
+ witnesser: z.enum([
660
+ "CodeRed",
661
+ "CodeGreen",
662
+ "CodeAmber"
663
+ ]),
664
+ elections_generic: z.object({ oracle_price_elections: z.boolean() })
665
+ });
666
+ const cfLendingPools = z.array(z.object({
667
+ asset: rpcAssetSchema,
668
+ total_amount: numberOrHex,
669
+ available_amount: numberOrHex,
670
+ utilisation_rate: z.number(),
671
+ current_interest_rate: z.number(),
672
+ origination_fee: z.number(),
673
+ liquidation_fee: z.number(),
674
+ interest_rate_curve: z.object({
675
+ interest_at_zero_utilisation: z.number(),
676
+ junction_utilisation: z.number(),
677
+ interest_at_junction_utilisation: z.number(),
678
+ interest_at_max_utilisation: z.number()
679
+ })
680
+ }));
681
+ const cfLendingConfig = z.object({
682
+ ltv_thresholds: z.object({
683
+ target: z.number(),
684
+ topup: z.number().nullable(),
685
+ soft_liquidation: z.number(),
686
+ soft_liquidation_abort: z.number(),
687
+ hard_liquidation: z.number(),
688
+ hard_liquidation_abort: z.number(),
689
+ low_ltv: z.number().nullable()
690
+ }),
691
+ network_fee_contributions: z.object({
692
+ extra_interest: z.number(),
693
+ low_ltv_penalty_max: z.number().nullable(),
694
+ from_origination_fee: z.number(),
695
+ from_liquidation_fee: z.number()
696
+ }),
697
+ fee_swap_interval_blocks: z.number(),
698
+ interest_payment_interval_blocks: z.number(),
699
+ fee_swap_threshold_usd: numberOrHex,
700
+ interest_collection_threshold_usd: numberOrHex,
701
+ soft_liquidation_swap_chunk_size_usd: numberOrHex,
702
+ hard_liquidation_swap_chunk_size_usd: numberOrHex,
703
+ soft_liquidation_max_oracle_slippage: z.number(),
704
+ hard_liquidation_max_oracle_slippage: z.number(),
705
+ fee_swap_max_oracle_slippage: z.number(),
706
+ minimum_loan_amount_usd: numberOrHex,
707
+ minimum_supply_amount_usd: numberOrHex,
708
+ minimum_update_loan_amount_usd: numberOrHex,
709
+ minimum_update_collateral_amount_usd: numberOrHex
710
+ });
711
+ const cfLoanAccount = z.object({
712
+ account: accountId,
713
+ collateral_topup_asset: rpcAssetSchema.nullable(),
714
+ ltv_ratio: numberOrHex.nullable(),
715
+ collateral: z.array(z.intersection(rpcAssetSchema, z.object({ amount: numberOrHex }))),
716
+ loans: z.array(z.object({
717
+ loan_id: z.number(),
718
+ asset: rpcAssetSchema,
719
+ principal_amount: numberOrHex
720
+ })),
721
+ liquidation_status: z.object({
722
+ liquidation_swaps: z.array(z.object({
723
+ swap_request_id: z.number(),
724
+ loan_id: z.number()
725
+ })),
726
+ liquidation_type: z.enum([
727
+ "SoftVoluntary",
728
+ "Soft",
729
+ "Hard"
730
+ ])
731
+ }).nullable()
732
+ });
733
+ const cfLoanAccounts = z.array(cfLoanAccount);
734
+ const cfLendingPoolSupplyBalances = z.array(z.intersection(rpcAssetSchema, z.object({ positions: z.array(z.object({
735
+ lp_id: accountId,
736
+ total_amount: numberOrHex
737
+ })) })));
738
+ const cfVaultAddresses = z.object({
739
+ ethereum: z.object({ Eth: z.array(z.number()).length(20).transform(bytesToHex) }),
740
+ arbitrum: z.object({ Arb: z.array(z.number()).length(20).transform(bytesToHex) }),
741
+ bitcoin: z.array(z.tuple([accountId, z.object({ Btc: z.array(z.number()).transform((bytes) => new TextDecoder().decode(new Uint8Array(bytes))) })]))
696
742
  }).transform(({ ethereum, arbitrum, bitcoin }) => {
697
- const bitcoinAddresses = new Map(
698
- bitcoin.map(([brokerId, { Btc }]) => [brokerId, Btc])
699
- );
700
- return {
701
- Ethereum: ethereum.Eth,
702
- Arbitrum: arbitrum.Arb,
703
- Bitcoin: bitcoinAddresses
704
- };
705
- });
706
- export {
707
- accountInfoCommon,
708
- broker,
709
- brokerRequestAccountCreationDepositAddress,
710
- brokerRequestSwapDepositAddress,
711
- cfAccountInfo,
712
- cfAccounts,
713
- cfAuctionState,
714
- cfAvailablePools,
715
- cfBoostPoolDetails,
716
- cfBoostPoolPendingFees,
717
- cfBoostPoolsDepth,
718
- cfEnvironment,
719
- cfFailedCallEvm,
720
- cfFlipSuppy,
721
- cfFundingEnvironment,
722
- cfGetTradingStrategies,
723
- cfGetTradingStrategyLimits,
724
- cfIngressEgressEnvironment,
725
- cfLendingConfig,
726
- cfLendingPoolSupplyBalances,
727
- cfLendingPools,
728
- cfLoanAccount,
729
- cfLoanAccounts,
730
- cfMonitoringSimulateAuction,
731
- cfOraclePrices,
732
- cfPoolDepth,
733
- cfPoolOrderbook,
734
- cfPoolOrders,
735
- cfPoolPriceV2,
736
- cfPoolsEnvironment,
737
- cfSafeModeStatuses,
738
- cfSupportedAssets,
739
- cfSwapRate,
740
- cfSwapRateV2,
741
- cfSwapRateV3,
742
- cfSwappingEnvironment,
743
- cfTradingStrategy,
744
- cfVaultAddresses,
745
- chainGetBlockHash,
746
- ethereumAddress,
747
- hexString,
748
- liquidityProvider,
749
- lpTotalBalances,
750
- numberOrHex,
751
- numericString,
752
- operator,
753
- requestSwapParameterEncoding,
754
- rpcResponse,
755
- stateGetMetadata,
756
- stateGetRuntimeVersion,
757
- u256,
758
- unregistered,
759
- validator
760
- };
743
+ const bitcoinAddresses = new Map(bitcoin.map(([brokerId, { Btc }]) => [brokerId, Btc]));
744
+ return {
745
+ Ethereum: ethereum.Eth,
746
+ Arbitrum: arbitrum.Arb,
747
+ Bitcoin: bitcoinAddresses
748
+ };
749
+ });
750
+
751
+ //#endregion
752
+ export { accountInfoCommon, broker, brokerRequestAccountCreationDepositAddress, brokerRequestSwapDepositAddress, cfAccountInfo, cfAccounts, cfAuctionState, cfAvailablePools, cfBoostPoolDetails, cfBoostPoolPendingFees, cfBoostPoolsDepth, cfEnvironment, cfFailedCallEvm, cfFlipSuppy, cfFundingEnvironment, cfGetTradingStrategies, cfGetTradingStrategyLimits, cfIngressEgressEnvironment, cfLendingConfig, cfLendingPoolSupplyBalances, cfLendingPools, cfLoanAccount, cfLoanAccounts, cfMonitoringSimulateAuction, cfOraclePrices, cfPoolDepth, cfPoolOrderbook, cfPoolOrders, cfPoolPriceV2, cfPoolsEnvironment, cfSafeModeStatuses, cfSupportedAssets, cfSwapRate, cfSwapRateV2, cfSwapRateV3, cfSwappingEnvironment, cfTradingStrategy, cfVaultAddresses, chainGetBlockHash, ethereumAddress, hexString, liquidityProvider, lpTotalBalances, numberOrHex, numericString, operator, requestSwapParameterEncoding, rpcResponse, stateGetMetadata, stateGetRuntimeVersion, u256, unregistered, validator };