@chainflip/rpc 1.6.4 → 1.6.6
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/Client.cjs +7 -6
- package/dist/Client.d.cts +1 -1
- package/dist/Client.d.ts +1 -1
- package/dist/{Client.js → Client.mjs} +4 -3
- package/dist/HttpClient.cjs +4 -3
- package/dist/HttpClient.d.cts +1 -1
- package/dist/HttpClient.d.ts +1 -1
- package/dist/{HttpClient.js → HttpClient.mjs} +4 -3
- package/dist/WsClient.cjs +10 -9
- package/dist/WsClient.d.cts +1 -1
- package/dist/WsClient.d.ts +1 -1
- package/dist/{WsClient.js → WsClient.mjs} +7 -6
- package/dist/common.cjs +34 -17
- package/dist/common.d.cts +12273 -1759
- package/dist/common.d.ts +12273 -1759
- package/dist/{common.js → common.mjs} +23 -6
- package/dist/constants.cjs +3 -2
- package/dist/{constants.js → constants.mjs} +3 -2
- package/dist/index.cjs +6 -5
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +10 -0
- package/dist/parsers.cjs +227 -37
- package/dist/parsers.d.cts +12194 -347
- package/dist/parsers.d.ts +12194 -347
- package/dist/parsers.mjs +303 -0
- package/dist/types.d.cts +24 -3
- package/dist/types.d.ts +24 -3
- package/package.json +9 -9
- package/dist/index.js +0 -9
- package/dist/parsers.js +0 -113
- /package/dist/{types.js → types.mjs} +0 -0
package/dist/parsers.mjs
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
// src/parsers.ts
|
|
2
|
+
import { isNotNullish } from "@chainflip/utils/guard";
|
|
3
|
+
import { isHex } from "@chainflip/utils/string";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
var hexString = z.string().refine(isHex, { message: "Invalid hex string" });
|
|
6
|
+
var u256 = hexString.transform((value) => BigInt(value));
|
|
7
|
+
var numberOrHex = z.union([z.number().transform((n) => BigInt(n)), u256]);
|
|
8
|
+
var chainAssetMapFactory = (parser, defaultValue) => z.object({
|
|
9
|
+
Bitcoin: z.object({ BTC: parser }),
|
|
10
|
+
Ethereum: z.object({ ETH: parser, USDC: parser, FLIP: parser, USDT: parser }),
|
|
11
|
+
Polkadot: z.object({ DOT: parser }),
|
|
12
|
+
Arbitrum: z.object({ ETH: parser, USDC: parser }),
|
|
13
|
+
Solana: z.object({ SOL: parser.default(defaultValue), USDC: parser.default(defaultValue) }).default({ SOL: defaultValue, USDC: defaultValue })
|
|
14
|
+
});
|
|
15
|
+
var chainBaseAssetMapFactory = (parser, defaultValue) => z.object({
|
|
16
|
+
Bitcoin: z.object({ BTC: parser }),
|
|
17
|
+
Ethereum: z.object({ ETH: parser, FLIP: parser, USDT: parser }),
|
|
18
|
+
Polkadot: z.object({ DOT: parser }),
|
|
19
|
+
Arbitrum: z.object({ ETH: parser, USDC: parser }),
|
|
20
|
+
Solana: z.object({ SOL: parser.default(defaultValue), USDC: parser.default(defaultValue) }).default({ SOL: defaultValue, USDC: defaultValue })
|
|
21
|
+
});
|
|
22
|
+
var chainMapFactory = (parser, defaultValue) => z.object({
|
|
23
|
+
Bitcoin: parser,
|
|
24
|
+
Ethereum: parser,
|
|
25
|
+
Polkadot: parser,
|
|
26
|
+
Arbitrum: parser,
|
|
27
|
+
Solana: parser.default(defaultValue)
|
|
28
|
+
});
|
|
29
|
+
var rpcAssetSchema = z.union([
|
|
30
|
+
z.object({ chain: z.literal("Bitcoin"), asset: z.literal("BTC") }),
|
|
31
|
+
z.object({ chain: z.literal("Polkadot"), asset: z.literal("DOT") }),
|
|
32
|
+
z.object({ chain: z.literal("Ethereum"), asset: z.literal("FLIP") }),
|
|
33
|
+
z.object({ chain: z.literal("Ethereum"), asset: z.literal("ETH") }),
|
|
34
|
+
z.object({ chain: z.literal("Ethereum"), asset: z.literal("USDC") }),
|
|
35
|
+
z.object({ chain: z.literal("Ethereum"), asset: z.literal("USDT") }),
|
|
36
|
+
z.object({ chain: z.literal("Arbitrum"), asset: z.literal("ETH") }),
|
|
37
|
+
z.object({ chain: z.literal("Arbitrum"), asset: z.literal("USDC") }),
|
|
38
|
+
z.object({ chain: z.literal("Solana"), asset: z.literal("SOL") }),
|
|
39
|
+
z.object({ chain: z.literal("Solana"), asset: z.literal("USDC") })
|
|
40
|
+
]);
|
|
41
|
+
var rename = (mapping) => (obj) => Object.fromEntries(
|
|
42
|
+
Object.entries(obj).map(([key, value]) => [
|
|
43
|
+
key in mapping ? mapping[key] : key,
|
|
44
|
+
value
|
|
45
|
+
])
|
|
46
|
+
);
|
|
47
|
+
var rpcBaseResponse = z.object({
|
|
48
|
+
id: z.union([z.string(), z.number()]),
|
|
49
|
+
jsonrpc: z.literal("2.0")
|
|
50
|
+
});
|
|
51
|
+
var nonNullish = z.any().refine(isNotNullish, { message: "Value must not be null or undefined" });
|
|
52
|
+
var rpcSuccessResponse = rpcBaseResponse.extend({ result: nonNullish });
|
|
53
|
+
var rpcErrorResponse = rpcBaseResponse.extend({
|
|
54
|
+
error: z.object({ code: z.number(), message: z.string() })
|
|
55
|
+
});
|
|
56
|
+
var rpcResponse = z.union([rpcSuccessResponse, rpcErrorResponse]);
|
|
57
|
+
var cfSwapRate = z.object({
|
|
58
|
+
intermediary: numberOrHex.nullable(),
|
|
59
|
+
output: numberOrHex
|
|
60
|
+
});
|
|
61
|
+
var fee = z.intersection(rpcAssetSchema, z.object({ amount: numberOrHex }));
|
|
62
|
+
var cfSwapRateV2 = z.object({
|
|
63
|
+
egress_fee: fee,
|
|
64
|
+
ingress_fee: fee,
|
|
65
|
+
intermediary: u256.nullable(),
|
|
66
|
+
network_fee: fee,
|
|
67
|
+
output: u256
|
|
68
|
+
});
|
|
69
|
+
var chainGetBlockHash = hexString;
|
|
70
|
+
var stateGetMetadata = hexString;
|
|
71
|
+
var stateGetRuntimeVersion = z.object({
|
|
72
|
+
specName: z.string(),
|
|
73
|
+
implName: z.string(),
|
|
74
|
+
authoringVersion: z.number(),
|
|
75
|
+
specVersion: z.number(),
|
|
76
|
+
implVersion: z.number(),
|
|
77
|
+
apis: z.array(z.tuple([hexString, z.number()])),
|
|
78
|
+
transactionVersion: z.number(),
|
|
79
|
+
stateVersion: z.number()
|
|
80
|
+
});
|
|
81
|
+
var cfIngressEgressEnvironment = z.object({
|
|
82
|
+
minimum_deposit_amounts: chainAssetMapFactory(numberOrHex, 0),
|
|
83
|
+
ingress_fees: chainAssetMapFactory(numberOrHex.nullable(), null),
|
|
84
|
+
egress_fees: chainAssetMapFactory(numberOrHex.nullable(), null),
|
|
85
|
+
witness_safety_margins: chainMapFactory(z.number().nullable(), null),
|
|
86
|
+
egress_dust_limits: chainAssetMapFactory(numberOrHex, 0),
|
|
87
|
+
channel_opening_fees: chainMapFactory(numberOrHex, 0),
|
|
88
|
+
// TODO(1.6): no longer optional
|
|
89
|
+
max_swap_retry_duration_blocks: chainMapFactory(z.number(), 0).optional().default({ Arbitrum: 0, Bitcoin: 0, Ethereum: 0, Polkadot: 0, Solana: 0 })
|
|
90
|
+
}).transform(rename({ egress_dust_limits: "minimum_egress_amounts" }));
|
|
91
|
+
var cfSwappingEnvironment = z.object({
|
|
92
|
+
maximum_swap_amounts: chainAssetMapFactory(numberOrHex.nullable(), null),
|
|
93
|
+
network_fee_hundredth_pips: z.number()
|
|
94
|
+
});
|
|
95
|
+
var cfFundingEnvironment = z.object({
|
|
96
|
+
redemption_tax: numberOrHex,
|
|
97
|
+
minimum_funding_amount: numberOrHex
|
|
98
|
+
});
|
|
99
|
+
var defaultFeeInfo = {
|
|
100
|
+
limit_order_fee_hundredth_pips: 0,
|
|
101
|
+
range_order_fee_hundredth_pips: 0,
|
|
102
|
+
range_order_total_fees_earned: { base: "0x0", quote: "0x0" },
|
|
103
|
+
limit_order_total_fees_earned: { base: "0x0", quote: "0x0" },
|
|
104
|
+
range_total_swap_inputs: { base: "0x0", quote: "0x0" },
|
|
105
|
+
limit_total_swap_inputs: { base: "0x0", quote: "0x0" },
|
|
106
|
+
quote_asset: { chain: "Ethereum", asset: "USDC" }
|
|
107
|
+
};
|
|
108
|
+
var cfPoolsEnvironment = z.object({
|
|
109
|
+
fees: chainBaseAssetMapFactory(
|
|
110
|
+
z.object({
|
|
111
|
+
limit_order_fee_hundredth_pips: z.number(),
|
|
112
|
+
range_order_fee_hundredth_pips: z.number(),
|
|
113
|
+
range_order_total_fees_earned: z.object({ base: u256, quote: u256 }),
|
|
114
|
+
limit_order_total_fees_earned: z.object({ base: u256, quote: u256 }),
|
|
115
|
+
range_total_swap_inputs: z.object({ base: u256, quote: u256 }),
|
|
116
|
+
limit_total_swap_inputs: z.object({ base: u256, quote: u256 }),
|
|
117
|
+
quote_asset: z.object({ chain: z.literal("Ethereum"), asset: z.literal("USDC") })
|
|
118
|
+
}).nullable().transform((info) => info ?? structuredClone(defaultFeeInfo)),
|
|
119
|
+
structuredClone(defaultFeeInfo)
|
|
120
|
+
)
|
|
121
|
+
});
|
|
122
|
+
var cfEnvironment = z.object({
|
|
123
|
+
ingress_egress: cfIngressEgressEnvironment,
|
|
124
|
+
swapping: cfSwappingEnvironment,
|
|
125
|
+
funding: cfFundingEnvironment,
|
|
126
|
+
pools: cfPoolsEnvironment
|
|
127
|
+
});
|
|
128
|
+
var cfBoostPoolsDepth = z.array(
|
|
129
|
+
z.intersection(rpcAssetSchema, z.object({ tier: z.number(), available_amount: u256 }))
|
|
130
|
+
);
|
|
131
|
+
var orderInfoSchema = z.object({
|
|
132
|
+
depth: numberOrHex,
|
|
133
|
+
price: numberOrHex.nullable()
|
|
134
|
+
});
|
|
135
|
+
var assetInfoSchema = z.object({
|
|
136
|
+
limit_orders: orderInfoSchema,
|
|
137
|
+
range_orders: orderInfoSchema
|
|
138
|
+
});
|
|
139
|
+
var cfPoolDepth = z.object({
|
|
140
|
+
asks: assetInfoSchema,
|
|
141
|
+
bids: assetInfoSchema
|
|
142
|
+
}).nullable();
|
|
143
|
+
var cfSupportedAssets = z.array(z.object({ chain: z.string(), asset: z.string() })).transform(
|
|
144
|
+
(assets) => assets.filter((asset) => rpcAssetSchema.safeParse(asset).success)
|
|
145
|
+
);
|
|
146
|
+
var brokerRequestSwapDepositAddress = z.object({
|
|
147
|
+
address: z.string(),
|
|
148
|
+
issued_block: z.number(),
|
|
149
|
+
channel_id: z.number(),
|
|
150
|
+
source_chain_expiry_block: numberOrHex,
|
|
151
|
+
channel_opening_fee: u256
|
|
152
|
+
});
|
|
153
|
+
var unregistered = z.object({
|
|
154
|
+
role: z.literal("unregistered"),
|
|
155
|
+
flip_balance: numberOrHex
|
|
156
|
+
});
|
|
157
|
+
var broker = z.object({
|
|
158
|
+
role: z.literal("broker"),
|
|
159
|
+
flip_balance: numberOrHex,
|
|
160
|
+
earned_fees: chainAssetMapFactory(numberOrHex, 0)
|
|
161
|
+
});
|
|
162
|
+
var boostBalances = z.array(
|
|
163
|
+
z.object({
|
|
164
|
+
fee_tier: z.number(),
|
|
165
|
+
total_balance: u256,
|
|
166
|
+
available_balance: u256,
|
|
167
|
+
in_use_balance: u256,
|
|
168
|
+
is_withdrawing: z.boolean()
|
|
169
|
+
})
|
|
170
|
+
);
|
|
171
|
+
var liquidityProvider = z.object({
|
|
172
|
+
role: z.literal("liquidity_provider"),
|
|
173
|
+
balances: chainAssetMapFactory(numberOrHex, "0x0"),
|
|
174
|
+
refund_addresses: chainMapFactory(z.string().nullable(), null),
|
|
175
|
+
flip_balance: numberOrHex,
|
|
176
|
+
earned_fees: chainAssetMapFactory(numberOrHex, 0),
|
|
177
|
+
boost_balances: chainAssetMapFactory(boostBalances, [])
|
|
178
|
+
});
|
|
179
|
+
var validator = z.object({
|
|
180
|
+
role: z.literal("validator"),
|
|
181
|
+
flip_balance: numberOrHex,
|
|
182
|
+
bond: numberOrHex,
|
|
183
|
+
last_heartbeat: z.number(),
|
|
184
|
+
reputation_points: z.number(),
|
|
185
|
+
keyholder_epochs: z.array(z.number()),
|
|
186
|
+
is_current_authority: z.boolean(),
|
|
187
|
+
is_current_backup: z.boolean(),
|
|
188
|
+
is_qualified: z.boolean(),
|
|
189
|
+
is_online: z.boolean(),
|
|
190
|
+
is_bidding: z.boolean(),
|
|
191
|
+
bound_redeem_address: hexString.nullable(),
|
|
192
|
+
apy_bp: z.number().nullable(),
|
|
193
|
+
restricted_balances: z.record(hexString, numberOrHex)
|
|
194
|
+
});
|
|
195
|
+
var cfAccountInfo = z.union([unregistered, broker, liquidityProvider, validator]);
|
|
196
|
+
var cfAccounts = z.array(z.tuple([z.string(), z.string()]));
|
|
197
|
+
var cfPoolPriceV2 = z.object({
|
|
198
|
+
sell: numberOrHex.nullable(),
|
|
199
|
+
buy: numberOrHex.nullable(),
|
|
200
|
+
range_order: numberOrHex,
|
|
201
|
+
base_asset: rpcAssetSchema,
|
|
202
|
+
quote_asset: rpcAssetSchema
|
|
203
|
+
});
|
|
204
|
+
var orderId = numberOrHex.transform((n) => String(n));
|
|
205
|
+
var limitOrder = z.object({
|
|
206
|
+
id: orderId,
|
|
207
|
+
tick: z.number(),
|
|
208
|
+
sell_amount: numberOrHex,
|
|
209
|
+
fees_earned: numberOrHex,
|
|
210
|
+
original_sell_amount: numberOrHex,
|
|
211
|
+
lp: z.string()
|
|
212
|
+
});
|
|
213
|
+
var ask = limitOrder.transform((order) => ({
|
|
214
|
+
...order,
|
|
215
|
+
type: "ask"
|
|
216
|
+
}));
|
|
217
|
+
var bid = limitOrder.transform((order) => ({
|
|
218
|
+
...order,
|
|
219
|
+
type: "bid"
|
|
220
|
+
}));
|
|
221
|
+
var rangeOrder = z.object({
|
|
222
|
+
id: orderId,
|
|
223
|
+
range: z.object({ start: z.number(), end: z.number() }),
|
|
224
|
+
liquidity: numberOrHex,
|
|
225
|
+
fees_earned: z.object({ base: numberOrHex, quote: numberOrHex }),
|
|
226
|
+
lp: z.string()
|
|
227
|
+
}).transform((order) => ({ ...order, type: "range" }));
|
|
228
|
+
var cfPoolOrders = z.object({
|
|
229
|
+
limit_orders: z.object({
|
|
230
|
+
asks: z.array(ask),
|
|
231
|
+
bids: z.array(bid)
|
|
232
|
+
}),
|
|
233
|
+
range_orders: z.array(rangeOrder)
|
|
234
|
+
});
|
|
235
|
+
var boostPoolAmount = z.object({
|
|
236
|
+
account_id: z.string(),
|
|
237
|
+
amount: u256
|
|
238
|
+
});
|
|
239
|
+
var cfBoostPoolDetails = z.array(
|
|
240
|
+
z.intersection(
|
|
241
|
+
rpcAssetSchema,
|
|
242
|
+
z.object({
|
|
243
|
+
fee_tier: z.number(),
|
|
244
|
+
available_amounts: z.array(boostPoolAmount),
|
|
245
|
+
deposits_pending_finalization: z.array(
|
|
246
|
+
z.object({
|
|
247
|
+
deposit_id: z.number().transform(BigInt),
|
|
248
|
+
owed_amounts: z.array(boostPoolAmount)
|
|
249
|
+
})
|
|
250
|
+
),
|
|
251
|
+
pending_withdrawals: z.array(
|
|
252
|
+
z.object({
|
|
253
|
+
account_id: z.string(),
|
|
254
|
+
pending_deposits: z.array(z.bigint())
|
|
255
|
+
})
|
|
256
|
+
)
|
|
257
|
+
})
|
|
258
|
+
)
|
|
259
|
+
);
|
|
260
|
+
var cfBoostPoolPendingFees = z.array(
|
|
261
|
+
z.intersection(
|
|
262
|
+
rpcAssetSchema,
|
|
263
|
+
z.object({
|
|
264
|
+
fee_tier: z.number(),
|
|
265
|
+
pending_fees: z.array(
|
|
266
|
+
z.object({
|
|
267
|
+
deposit_id: z.number().transform(BigInt),
|
|
268
|
+
fees: z.array(boostPoolAmount)
|
|
269
|
+
})
|
|
270
|
+
)
|
|
271
|
+
})
|
|
272
|
+
)
|
|
273
|
+
);
|
|
274
|
+
export {
|
|
275
|
+
broker,
|
|
276
|
+
brokerRequestSwapDepositAddress,
|
|
277
|
+
cfAccountInfo,
|
|
278
|
+
cfAccounts,
|
|
279
|
+
cfBoostPoolDetails,
|
|
280
|
+
cfBoostPoolPendingFees,
|
|
281
|
+
cfBoostPoolsDepth,
|
|
282
|
+
cfEnvironment,
|
|
283
|
+
cfFundingEnvironment,
|
|
284
|
+
cfIngressEgressEnvironment,
|
|
285
|
+
cfPoolDepth,
|
|
286
|
+
cfPoolOrders,
|
|
287
|
+
cfPoolPriceV2,
|
|
288
|
+
cfPoolsEnvironment,
|
|
289
|
+
cfSupportedAssets,
|
|
290
|
+
cfSwapRate,
|
|
291
|
+
cfSwapRateV2,
|
|
292
|
+
cfSwappingEnvironment,
|
|
293
|
+
chainGetBlockHash,
|
|
294
|
+
hexString,
|
|
295
|
+
liquidityProvider,
|
|
296
|
+
numberOrHex,
|
|
297
|
+
rpcResponse,
|
|
298
|
+
stateGetMetadata,
|
|
299
|
+
stateGetRuntimeVersion,
|
|
300
|
+
u256,
|
|
301
|
+
unregistered,
|
|
302
|
+
validator
|
|
303
|
+
};
|
package/dist/types.d.cts
CHANGED
|
@@ -1,24 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { RpcResult, RpcResponse } from './common.cjs';
|
|
2
3
|
export { RpcMethod, RpcRequest as RpcParams } from './common.cjs';
|
|
3
|
-
import '
|
|
4
|
-
|
|
4
|
+
import { unregistered, broker, validator, liquidityProvider } from './parsers.cjs';
|
|
5
|
+
export { RpcLimitOrder, RpcRangeOrder } from './parsers.cjs';
|
|
5
6
|
import '@chainflip/utils/types';
|
|
6
7
|
|
|
8
|
+
type CfAccountInfo = RpcResult<'cf_account_info'>;
|
|
9
|
+
type CfBoostPoolDetails = RpcResult<'cf_boost_pool_details'>;
|
|
10
|
+
type CfBoostPoolPendingFees = RpcResult<'cf_boost_pool_pending_fees'>;
|
|
7
11
|
type CfBoostPoolsDepth = RpcResult<'cf_boost_pools_depth'>;
|
|
8
12
|
type CfEnvironment = RpcResult<'cf_environment'>;
|
|
9
13
|
type CfFundingEnvironment = RpcResult<'cf_funding_environment'>;
|
|
10
14
|
type CfIngressEgressEnvironment = RpcResult<'cf_ingress_egress_environment'>;
|
|
15
|
+
type CfPoolOrders = RpcResult<'cf_pool_orders'>;
|
|
16
|
+
type CfPoolPriceV2 = RpcResult<'cf_pool_price_v2'>;
|
|
17
|
+
type CfPoolsEnvironment = RpcResult<'cf_pools_environment'>;
|
|
11
18
|
type CfSupportedAssets = RpcResult<'cf_supported_assets'>;
|
|
12
19
|
type CfSwappingEnvironment = RpcResult<'cf_swapping_environment'>;
|
|
13
20
|
type CfSwapRate = RpcResult<'cf_swap_rate'>;
|
|
14
21
|
type CfSwapRateV2 = RpcResult<'cf_swap_rate_v2'>;
|
|
22
|
+
type CfPoolDepth = RpcResult<'cf_pool_depth'>;
|
|
23
|
+
type CfAccounts = RpcResult<'cf_accounts'>;
|
|
24
|
+
type CfAccountInfoResponse = RpcResponse<'cf_account_info'>;
|
|
25
|
+
type CfBoostPoolDetailsResponse = RpcResponse<'cf_boost_pool_details'>;
|
|
26
|
+
type CfBoostPoolPendingFeesResponse = RpcResponse<'cf_boost_pool_pending_fees'>;
|
|
15
27
|
type CfBoostPoolsDepthResponse = RpcResponse<'cf_boost_pools_depth'>;
|
|
16
28
|
type CfEnvironmentResponse = RpcResponse<'cf_environment'>;
|
|
17
29
|
type CfFundingEnvironmentResponse = RpcResponse<'cf_funding_environment'>;
|
|
18
30
|
type CfIngressEgressEnvironmentResponse = RpcResponse<'cf_ingress_egress_environment'>;
|
|
31
|
+
type CfPoolOrdersResponse = RpcResponse<'cf_pool_orders'>;
|
|
32
|
+
type CfPoolPriceV2Response = RpcResponse<'cf_pool_price_v2'>;
|
|
33
|
+
type CfPoolsEnvironmentResponse = RpcResponse<'cf_pools_environment'>;
|
|
19
34
|
type CfSupportedAssetsResponse = RpcResponse<'cf_supported_assets'>;
|
|
20
35
|
type CfSwappingEnvironmentResponse = RpcResponse<'cf_swapping_environment'>;
|
|
21
36
|
type CfSwapRateResponse = RpcResponse<'cf_swap_rate'>;
|
|
22
37
|
type CfSwapRateV2Response = RpcResponse<'cf_swap_rate_v2'>;
|
|
38
|
+
type CfPoolDepthResponse = RpcResponse<'cf_pool_depth'>;
|
|
39
|
+
type CfAccountsResponse = RpcResponse<'cf_accounts'>;
|
|
40
|
+
type CfUnregisteredAccount = z.output<typeof unregistered>;
|
|
41
|
+
type CfBrokerAccount = z.output<typeof broker>;
|
|
42
|
+
type CfValidatorAccount = z.output<typeof validator>;
|
|
43
|
+
type CfLiquidityProviderAccount = z.output<typeof liquidityProvider>;
|
|
23
44
|
|
|
24
|
-
export { type CfBoostPoolsDepth, type CfBoostPoolsDepthResponse, type CfEnvironment, type CfEnvironmentResponse, type CfFundingEnvironment, type CfFundingEnvironmentResponse, type CfIngressEgressEnvironment, type CfIngressEgressEnvironmentResponse, type CfSupportedAssets, type CfSupportedAssetsResponse, type CfSwapRate, type CfSwapRateResponse, type CfSwapRateV2, type CfSwapRateV2Response, type CfSwappingEnvironment, type CfSwappingEnvironmentResponse, RpcResult };
|
|
45
|
+
export { type CfAccountInfo, type CfAccountInfoResponse, type CfAccounts, type CfAccountsResponse, type CfBoostPoolDetails, type CfBoostPoolDetailsResponse, type CfBoostPoolPendingFees, type CfBoostPoolPendingFeesResponse, type CfBoostPoolsDepth, type CfBoostPoolsDepthResponse, type CfBrokerAccount, type CfEnvironment, type CfEnvironmentResponse, type CfFundingEnvironment, type CfFundingEnvironmentResponse, type CfIngressEgressEnvironment, type CfIngressEgressEnvironmentResponse, type CfLiquidityProviderAccount, type CfPoolDepth, type CfPoolDepthResponse, type CfPoolOrders, type CfPoolOrdersResponse, type CfPoolPriceV2, type CfPoolPriceV2Response, type CfPoolsEnvironment, type CfPoolsEnvironmentResponse, type CfSupportedAssets, type CfSupportedAssetsResponse, type CfSwapRate, type CfSwapRateResponse, type CfSwapRateV2, type CfSwapRateV2Response, type CfSwappingEnvironment, type CfSwappingEnvironmentResponse, type CfUnregisteredAccount, type CfValidatorAccount, RpcResult };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,24 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { RpcResult, RpcResponse } from './common.js';
|
|
2
3
|
export { RpcMethod, RpcRequest as RpcParams } from './common.js';
|
|
3
|
-
import '
|
|
4
|
-
|
|
4
|
+
import { unregistered, broker, validator, liquidityProvider } from './parsers.js';
|
|
5
|
+
export { RpcLimitOrder, RpcRangeOrder } from './parsers.js';
|
|
5
6
|
import '@chainflip/utils/types';
|
|
6
7
|
|
|
8
|
+
type CfAccountInfo = RpcResult<'cf_account_info'>;
|
|
9
|
+
type CfBoostPoolDetails = RpcResult<'cf_boost_pool_details'>;
|
|
10
|
+
type CfBoostPoolPendingFees = RpcResult<'cf_boost_pool_pending_fees'>;
|
|
7
11
|
type CfBoostPoolsDepth = RpcResult<'cf_boost_pools_depth'>;
|
|
8
12
|
type CfEnvironment = RpcResult<'cf_environment'>;
|
|
9
13
|
type CfFundingEnvironment = RpcResult<'cf_funding_environment'>;
|
|
10
14
|
type CfIngressEgressEnvironment = RpcResult<'cf_ingress_egress_environment'>;
|
|
15
|
+
type CfPoolOrders = RpcResult<'cf_pool_orders'>;
|
|
16
|
+
type CfPoolPriceV2 = RpcResult<'cf_pool_price_v2'>;
|
|
17
|
+
type CfPoolsEnvironment = RpcResult<'cf_pools_environment'>;
|
|
11
18
|
type CfSupportedAssets = RpcResult<'cf_supported_assets'>;
|
|
12
19
|
type CfSwappingEnvironment = RpcResult<'cf_swapping_environment'>;
|
|
13
20
|
type CfSwapRate = RpcResult<'cf_swap_rate'>;
|
|
14
21
|
type CfSwapRateV2 = RpcResult<'cf_swap_rate_v2'>;
|
|
22
|
+
type CfPoolDepth = RpcResult<'cf_pool_depth'>;
|
|
23
|
+
type CfAccounts = RpcResult<'cf_accounts'>;
|
|
24
|
+
type CfAccountInfoResponse = RpcResponse<'cf_account_info'>;
|
|
25
|
+
type CfBoostPoolDetailsResponse = RpcResponse<'cf_boost_pool_details'>;
|
|
26
|
+
type CfBoostPoolPendingFeesResponse = RpcResponse<'cf_boost_pool_pending_fees'>;
|
|
15
27
|
type CfBoostPoolsDepthResponse = RpcResponse<'cf_boost_pools_depth'>;
|
|
16
28
|
type CfEnvironmentResponse = RpcResponse<'cf_environment'>;
|
|
17
29
|
type CfFundingEnvironmentResponse = RpcResponse<'cf_funding_environment'>;
|
|
18
30
|
type CfIngressEgressEnvironmentResponse = RpcResponse<'cf_ingress_egress_environment'>;
|
|
31
|
+
type CfPoolOrdersResponse = RpcResponse<'cf_pool_orders'>;
|
|
32
|
+
type CfPoolPriceV2Response = RpcResponse<'cf_pool_price_v2'>;
|
|
33
|
+
type CfPoolsEnvironmentResponse = RpcResponse<'cf_pools_environment'>;
|
|
19
34
|
type CfSupportedAssetsResponse = RpcResponse<'cf_supported_assets'>;
|
|
20
35
|
type CfSwappingEnvironmentResponse = RpcResponse<'cf_swapping_environment'>;
|
|
21
36
|
type CfSwapRateResponse = RpcResponse<'cf_swap_rate'>;
|
|
22
37
|
type CfSwapRateV2Response = RpcResponse<'cf_swap_rate_v2'>;
|
|
38
|
+
type CfPoolDepthResponse = RpcResponse<'cf_pool_depth'>;
|
|
39
|
+
type CfAccountsResponse = RpcResponse<'cf_accounts'>;
|
|
40
|
+
type CfUnregisteredAccount = z.output<typeof unregistered>;
|
|
41
|
+
type CfBrokerAccount = z.output<typeof broker>;
|
|
42
|
+
type CfValidatorAccount = z.output<typeof validator>;
|
|
43
|
+
type CfLiquidityProviderAccount = z.output<typeof liquidityProvider>;
|
|
23
44
|
|
|
24
|
-
export { type CfBoostPoolsDepth, type CfBoostPoolsDepthResponse, type CfEnvironment, type CfEnvironmentResponse, type CfFundingEnvironment, type CfFundingEnvironmentResponse, type CfIngressEgressEnvironment, type CfIngressEgressEnvironmentResponse, type CfSupportedAssets, type CfSupportedAssetsResponse, type CfSwapRate, type CfSwapRateResponse, type CfSwapRateV2, type CfSwapRateV2Response, type CfSwappingEnvironment, type CfSwappingEnvironmentResponse, RpcResult };
|
|
45
|
+
export { type CfAccountInfo, type CfAccountInfoResponse, type CfAccounts, type CfAccountsResponse, type CfBoostPoolDetails, type CfBoostPoolDetailsResponse, type CfBoostPoolPendingFees, type CfBoostPoolPendingFeesResponse, type CfBoostPoolsDepth, type CfBoostPoolsDepthResponse, type CfBrokerAccount, type CfEnvironment, type CfEnvironmentResponse, type CfFundingEnvironment, type CfFundingEnvironmentResponse, type CfIngressEgressEnvironment, type CfIngressEgressEnvironmentResponse, type CfLiquidityProviderAccount, type CfPoolDepth, type CfPoolDepthResponse, type CfPoolOrders, type CfPoolOrdersResponse, type CfPoolPriceV2, type CfPoolPriceV2Response, type CfPoolsEnvironment, type CfPoolsEnvironmentResponse, type CfSupportedAssets, type CfSupportedAssetsResponse, type CfSwapRate, type CfSwapRateResponse, type CfSwapRateV2, type CfSwapRateV2Response, type CfSwappingEnvironment, type CfSwappingEnvironmentResponse, type CfUnregisteredAccount, type CfValidatorAccount, RpcResult };
|
package/package.json
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainflip/rpc",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.6",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"clean": "rm -rf dist",
|
|
7
|
-
"prepublish": "pnpm test run && pnpm build",
|
|
8
|
-
"build": "pnpm clean && pnpm tsup",
|
|
9
|
-
"test": "vitest",
|
|
10
|
-
"coverage": "vitest run --coverage"
|
|
11
|
-
},
|
|
12
5
|
"dependencies": {
|
|
13
6
|
"@chainflip/utils": "^0.3.0",
|
|
14
7
|
"zod": "^3.22.8"
|
|
@@ -48,5 +41,12 @@
|
|
|
48
41
|
"publishConfig": {
|
|
49
42
|
"registry": "https://registry.npmjs.org/",
|
|
50
43
|
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"clean": "rm -rf dist",
|
|
47
|
+
"prepublish": "pnpm test run && pnpm build",
|
|
48
|
+
"build": "pnpm clean && pnpm tsup",
|
|
49
|
+
"test": "vitest",
|
|
50
|
+
"coverage": "vitest run --coverage"
|
|
51
51
|
}
|
|
52
|
-
}
|
|
52
|
+
}
|
package/dist/index.js
DELETED
package/dist/parsers.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { isNotNullish } from "@chainflip/utils/guard";
|
|
2
|
-
import { isHex } from "@chainflip/utils/string";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
const hexString = z.string().refine(isHex, { message: "Invalid hex string" });
|
|
5
|
-
const u256 = hexString.transform((value) => BigInt(value));
|
|
6
|
-
const numberOrHex = z.union([z.number().transform((n) => BigInt(n)), u256]);
|
|
7
|
-
const chainAssetMapFactory = (parser) => z.object({
|
|
8
|
-
Bitcoin: z.object({ BTC: parser }),
|
|
9
|
-
Ethereum: z.object({ ETH: parser, USDC: parser, FLIP: parser, USDT: parser }),
|
|
10
|
-
Polkadot: z.object({ DOT: parser }),
|
|
11
|
-
Arbitrum: z.object({ ETH: parser, USDC: parser })
|
|
12
|
-
});
|
|
13
|
-
const chainMapFactory = (parser) => z.object({ Bitcoin: parser, Ethereum: parser, Polkadot: parser, Arbitrum: parser });
|
|
14
|
-
const rpcAssetSchema = z.union([
|
|
15
|
-
z.object({ chain: z.literal("Bitcoin"), asset: z.literal("BTC") }),
|
|
16
|
-
z.object({ chain: z.literal("Polkadot"), asset: z.literal("DOT") }),
|
|
17
|
-
z.object({ chain: z.literal("Ethereum"), asset: z.literal("FLIP") }),
|
|
18
|
-
z.object({ chain: z.literal("Ethereum"), asset: z.literal("ETH") }),
|
|
19
|
-
z.object({ chain: z.literal("Ethereum"), asset: z.literal("USDC") }),
|
|
20
|
-
z.object({ chain: z.literal("Ethereum"), asset: z.literal("USDT") }),
|
|
21
|
-
z.object({ chain: z.literal("Arbitrum"), asset: z.literal("ETH") }),
|
|
22
|
-
z.object({ chain: z.literal("Arbitrum"), asset: z.literal("USDC") })
|
|
23
|
-
]);
|
|
24
|
-
const rename = (mapping) => (obj) => Object.fromEntries(
|
|
25
|
-
Object.entries(obj).map(([key, value]) => [
|
|
26
|
-
key in mapping ? mapping[key] : key,
|
|
27
|
-
value
|
|
28
|
-
])
|
|
29
|
-
);
|
|
30
|
-
const rpcBaseResponse = z.object({
|
|
31
|
-
id: z.union([z.string(), z.number()]),
|
|
32
|
-
jsonrpc: z.literal("2.0")
|
|
33
|
-
});
|
|
34
|
-
const nonNullish = z.any().refine(isNotNullish, { message: "Value must not be null or undefined" });
|
|
35
|
-
const rpcSuccessResponse = rpcBaseResponse.extend({ result: nonNullish });
|
|
36
|
-
const rpcErrorResponse = rpcBaseResponse.extend({
|
|
37
|
-
error: z.object({ code: z.number(), message: z.string() })
|
|
38
|
-
});
|
|
39
|
-
const rpcResponse = z.union([rpcSuccessResponse, rpcErrorResponse]);
|
|
40
|
-
const cfSwapRate = z.object({
|
|
41
|
-
intermediary: numberOrHex.nullable(),
|
|
42
|
-
output: numberOrHex
|
|
43
|
-
});
|
|
44
|
-
const fee = z.intersection(rpcAssetSchema, z.object({ amount: numberOrHex }));
|
|
45
|
-
const cfSwapRateV2 = z.object({
|
|
46
|
-
egress_fee: fee,
|
|
47
|
-
ingress_fee: fee,
|
|
48
|
-
intermediary: u256.nullable(),
|
|
49
|
-
network_fee: fee,
|
|
50
|
-
output: u256
|
|
51
|
-
});
|
|
52
|
-
const chainGetBlockHash = hexString;
|
|
53
|
-
const stateGetMetadata = hexString;
|
|
54
|
-
const stateGetRuntimeVersion = z.object({
|
|
55
|
-
specName: z.string(),
|
|
56
|
-
implName: z.string(),
|
|
57
|
-
authoringVersion: z.number(),
|
|
58
|
-
specVersion: z.number(),
|
|
59
|
-
implVersion: z.number(),
|
|
60
|
-
apis: z.array(z.tuple([hexString, z.number()])),
|
|
61
|
-
transactionVersion: z.number(),
|
|
62
|
-
stateVersion: z.number()
|
|
63
|
-
});
|
|
64
|
-
const cfIngressEgressEnvironment = z.object({
|
|
65
|
-
minimum_deposit_amounts: chainAssetMapFactory(numberOrHex),
|
|
66
|
-
ingress_fees: chainAssetMapFactory(numberOrHex.nullable()),
|
|
67
|
-
egress_fees: chainAssetMapFactory(numberOrHex.nullable()),
|
|
68
|
-
witness_safety_margins: chainMapFactory(z.number().nullable()),
|
|
69
|
-
egress_dust_limits: chainAssetMapFactory(numberOrHex),
|
|
70
|
-
channel_opening_fees: chainMapFactory(numberOrHex)
|
|
71
|
-
}).transform(rename({ egress_dust_limits: "minimum_egress_amounts" }));
|
|
72
|
-
const cfSwappingEnvironment = z.object({
|
|
73
|
-
maximum_swap_amounts: chainAssetMapFactory(numberOrHex.nullable()),
|
|
74
|
-
network_fee_hundredth_pips: z.number()
|
|
75
|
-
});
|
|
76
|
-
const cfFundingEnvironment = z.object({
|
|
77
|
-
redemption_tax: numberOrHex,
|
|
78
|
-
minimum_funding_amount: numberOrHex
|
|
79
|
-
});
|
|
80
|
-
const cfEnvironment = z.object({
|
|
81
|
-
ingress_egress: cfIngressEgressEnvironment,
|
|
82
|
-
swapping: cfSwappingEnvironment,
|
|
83
|
-
funding: cfFundingEnvironment
|
|
84
|
-
});
|
|
85
|
-
const cfBoostPoolsDepth = z.array(
|
|
86
|
-
z.intersection(rpcAssetSchema, z.object({ tier: z.number(), available_amount: u256 }))
|
|
87
|
-
);
|
|
88
|
-
const cfSupportedAsssets = z.array(rpcAssetSchema);
|
|
89
|
-
const brokerRequestSwapDepositAddress = z.object({
|
|
90
|
-
address: z.string(),
|
|
91
|
-
issued_block: z.number(),
|
|
92
|
-
channel_id: z.number(),
|
|
93
|
-
source_chain_expiry_block: numberOrHex,
|
|
94
|
-
channel_opening_fee: u256
|
|
95
|
-
});
|
|
96
|
-
export {
|
|
97
|
-
brokerRequestSwapDepositAddress,
|
|
98
|
-
cfBoostPoolsDepth,
|
|
99
|
-
cfEnvironment,
|
|
100
|
-
cfFundingEnvironment,
|
|
101
|
-
cfIngressEgressEnvironment,
|
|
102
|
-
cfSupportedAsssets,
|
|
103
|
-
cfSwapRate,
|
|
104
|
-
cfSwapRateV2,
|
|
105
|
-
cfSwappingEnvironment,
|
|
106
|
-
chainGetBlockHash,
|
|
107
|
-
hexString,
|
|
108
|
-
numberOrHex,
|
|
109
|
-
rpcResponse,
|
|
110
|
-
stateGetMetadata,
|
|
111
|
-
stateGetRuntimeVersion,
|
|
112
|
-
u256
|
|
113
|
-
};
|
|
File without changes
|