@chainflip/rpc 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,113 @@
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
+ };
package/dist/types.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,24 @@
1
+ import { RpcResult, RpcResponse } from './common.cjs';
2
+ export { RpcMethod, RpcRequest as RpcParams } from './common.cjs';
3
+ import 'zod';
4
+ import './parsers.cjs';
5
+ import '@chainflip/utils/types';
6
+
7
+ type CfBoostPoolsDepth = RpcResult<'cf_boost_pools_depth'>;
8
+ type CfEnvironment = RpcResult<'cf_environment'>;
9
+ type CfFundingEnvironment = RpcResult<'cf_funding_environment'>;
10
+ type CfIngressEgressEnvironment = RpcResult<'cf_ingress_egress_environment'>;
11
+ type CfSupportedAssets = RpcResult<'cf_supported_assets'>;
12
+ type CfSwappingEnvironment = RpcResult<'cf_swapping_environment'>;
13
+ type CfSwapRate = RpcResult<'cf_swap_rate'>;
14
+ type CfSwapRateV2 = RpcResult<'cf_swap_rate_v2'>;
15
+ type CfBoostPoolsDepthResponse = RpcResponse<'cf_boost_pools_depth'>;
16
+ type CfEnvironmentResponse = RpcResponse<'cf_environment'>;
17
+ type CfFundingEnvironmentResponse = RpcResponse<'cf_funding_environment'>;
18
+ type CfIngressEgressEnvironmentResponse = RpcResponse<'cf_ingress_egress_environment'>;
19
+ type CfSupportedAssetsResponse = RpcResponse<'cf_supported_assets'>;
20
+ type CfSwappingEnvironmentResponse = RpcResponse<'cf_swapping_environment'>;
21
+ type CfSwapRateResponse = RpcResponse<'cf_swap_rate'>;
22
+ type CfSwapRateV2Response = RpcResponse<'cf_swap_rate_v2'>;
23
+
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 };
@@ -0,0 +1,24 @@
1
+ import { RpcResult, RpcResponse } from './common.js';
2
+ export { RpcMethod, RpcRequest as RpcParams } from './common.js';
3
+ import 'zod';
4
+ import './parsers.js';
5
+ import '@chainflip/utils/types';
6
+
7
+ type CfBoostPoolsDepth = RpcResult<'cf_boost_pools_depth'>;
8
+ type CfEnvironment = RpcResult<'cf_environment'>;
9
+ type CfFundingEnvironment = RpcResult<'cf_funding_environment'>;
10
+ type CfIngressEgressEnvironment = RpcResult<'cf_ingress_egress_environment'>;
11
+ type CfSupportedAssets = RpcResult<'cf_supported_assets'>;
12
+ type CfSwappingEnvironment = RpcResult<'cf_swapping_environment'>;
13
+ type CfSwapRate = RpcResult<'cf_swap_rate'>;
14
+ type CfSwapRateV2 = RpcResult<'cf_swap_rate_v2'>;
15
+ type CfBoostPoolsDepthResponse = RpcResponse<'cf_boost_pools_depth'>;
16
+ type CfEnvironmentResponse = RpcResponse<'cf_environment'>;
17
+ type CfFundingEnvironmentResponse = RpcResponse<'cf_funding_environment'>;
18
+ type CfIngressEgressEnvironmentResponse = RpcResponse<'cf_ingress_egress_environment'>;
19
+ type CfSupportedAssetsResponse = RpcResponse<'cf_supported_assets'>;
20
+ type CfSwappingEnvironmentResponse = RpcResponse<'cf_swapping_environment'>;
21
+ type CfSwapRateResponse = RpcResponse<'cf_swap_rate'>;
22
+ type CfSwapRateV2Response = RpcResponse<'cf_swap_rate_v2'>;
23
+
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 };
package/dist/types.js ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@chainflip/rpc",
3
+ "version": "1.4.0",
4
+ "type": "module",
5
+ "dependencies": {
6
+ "@chainflip/utils": "^0.1.3",
7
+ "zod": "^3.22.8"
8
+ },
9
+ "devDependencies": {
10
+ "@types/node": "^20.12.7",
11
+ "@types/ws": "^8.5.10",
12
+ "ws": "^8.17.0"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md"
17
+ ],
18
+ "exports": {
19
+ "./*": {
20
+ "require": {
21
+ "types": "./dist/*.d.cts",
22
+ "default": "./dist/*.cjs"
23
+ },
24
+ "import": {
25
+ "types": "./dist/*.d.ts",
26
+ "default": "./dist/*.js"
27
+ }
28
+ },
29
+ ".": {
30
+ "require": {
31
+ "types": "./dist/index.d.cts",
32
+ "default": "./dist/index.cjs"
33
+ },
34
+ "import": {
35
+ "types": "./dist/index.d.ts",
36
+ "default": "./dist/index.js"
37
+ }
38
+ }
39
+ },
40
+ "repository": "https://github.com/chainflip-io/chainflip-product-toolkit.git",
41
+ "publishConfig": {
42
+ "registry": "https://registry.npmjs.org/",
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
+ }
52
+ }