@chainflip/rpc 1.4.0 → 1.4.1
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.js → Client.mjs} +4 -3
- package/dist/HttpClient.cjs +4 -3
- package/dist/{HttpClient.js → HttpClient.mjs} +4 -3
- package/dist/WsClient.cjs +10 -9
- package/dist/{WsClient.js → WsClient.mjs} +7 -6
- package/dist/common.cjs +18 -17
- package/dist/{common.js → common.mjs} +4 -3
- package/dist/constants.cjs +2 -1
- package/dist/{constants.js → constants.mjs} +2 -1
- package/dist/index.cjs +6 -5
- package/dist/index.mjs +10 -0
- package/dist/parsers.cjs +27 -26
- package/dist/{parsers.js → parsers.mjs} +26 -25
- package/package.json +1 -1
- package/dist/index.js +0 -9
- /package/dist/{types.js → types.mjs} +0 -0
package/dist/Client.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true})
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/Client.ts
|
|
2
|
+
var _commoncjs = require('./common.cjs');
|
|
2
3
|
var _assertion = require('@chainflip/utils/assertion');
|
|
3
|
-
|
|
4
|
+
var Client = class {
|
|
4
5
|
constructor(url) {
|
|
5
6
|
this.url = url;
|
|
6
7
|
}
|
|
@@ -14,19 +15,19 @@ class Client {
|
|
|
14
15
|
const response = await this.send(this.formatRequest(method, params));
|
|
15
16
|
if (!response.success)
|
|
16
17
|
throw response.error;
|
|
17
|
-
const parseResult =
|
|
18
|
+
const parseResult = _commoncjs.rpcResponse.safeParse(response.result);
|
|
18
19
|
_assertion.assert.call(void 0, parseResult.success, "Malformed RPC response received");
|
|
19
20
|
if ("error" in parseResult.data) {
|
|
20
21
|
throw new Error(
|
|
21
22
|
`RPC error [${parseResult.data.error.code}]: ${parseResult.data.error.message}`
|
|
22
23
|
);
|
|
23
24
|
}
|
|
24
|
-
return
|
|
25
|
+
return _commoncjs.rpcResult[method].parse(parseResult.data.result);
|
|
25
26
|
}
|
|
26
27
|
methods() {
|
|
27
|
-
return Object.keys(
|
|
28
|
+
return Object.keys(_commoncjs.rpcResult).sort();
|
|
28
29
|
}
|
|
29
|
-
}
|
|
30
|
+
};
|
|
30
31
|
|
|
31
32
|
|
|
32
33
|
exports.default = Client;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// src/Client.ts
|
|
2
|
+
import { rpcResult, rpcResponse } from "./common.mjs";
|
|
2
3
|
import { assert } from "@chainflip/utils/assertion";
|
|
3
|
-
|
|
4
|
+
var Client = class {
|
|
4
5
|
constructor(url) {
|
|
5
6
|
this.url = url;
|
|
6
7
|
}
|
|
@@ -26,7 +27,7 @@ class Client {
|
|
|
26
27
|
methods() {
|
|
27
28
|
return Object.keys(rpcResult).sort();
|
|
28
29
|
}
|
|
29
|
-
}
|
|
30
|
+
};
|
|
30
31
|
export {
|
|
31
32
|
Client as default
|
|
32
33
|
};
|
package/dist/HttpClient.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/HttpClient.ts
|
|
2
|
+
var _Clientcjs = require('./Client.cjs'); var _Clientcjs2 = _interopRequireDefault(_Clientcjs);
|
|
3
|
+
var HttpClient = class extends _Clientcjs2.default {
|
|
3
4
|
async send(request) {
|
|
4
5
|
const res = await fetch(this.url, {
|
|
5
6
|
body: JSON.stringify(request),
|
|
@@ -18,7 +19,7 @@ class HttpClient extends _Client2.default {
|
|
|
18
19
|
return { success: false, error: new Error("Invalid JSON response") };
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
|
-
}
|
|
22
|
+
};
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
exports.default = HttpClient;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/HttpClient.ts
|
|
2
|
+
import Client from "./Client.mjs";
|
|
3
|
+
var HttpClient = class extends Client {
|
|
3
4
|
async send(request) {
|
|
4
5
|
const res = await fetch(this.url, {
|
|
5
6
|
body: JSON.stringify(request),
|
|
@@ -18,7 +19,7 @@ class HttpClient extends Client {
|
|
|
18
19
|
return { success: false, error: new Error("Invalid JSON response") };
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
|
-
}
|
|
22
|
+
};
|
|
22
23
|
export {
|
|
23
24
|
HttpClient as default
|
|
24
25
|
};
|
package/dist/WsClient.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/WsClient.ts
|
|
2
|
+
var _async = require('@chainflip/utils/async');
|
|
2
3
|
var _crypto = require('crypto');
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
var _Clientcjs = require('./Client.cjs'); var _Clientcjs2 = _interopRequireDefault(_Clientcjs);
|
|
5
|
+
var _commoncjs = require('./common.cjs');
|
|
6
|
+
var READY = "READY";
|
|
7
|
+
var DISCONNECT = "DISCONNECT";
|
|
8
|
+
var WsClient = (_class = class extends _Clientcjs2.default {
|
|
8
9
|
constructor(url, WebSocket = globalThis.WebSocket) {
|
|
9
|
-
super(url);
|
|
10
|
+
super(url);_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);;
|
|
10
11
|
this.WebSocket = WebSocket;
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -51,7 +52,7 @@ class WsClient extends _Client2.default {
|
|
|
51
52
|
}}
|
|
52
53
|
__init5() {this.handleMessage = (data) => {
|
|
53
54
|
const parsedData = JSON.parse(data.data);
|
|
54
|
-
const response =
|
|
55
|
+
const response = _commoncjs.rpcResponse.safeParse(parsedData);
|
|
55
56
|
if (!response.success)
|
|
56
57
|
return;
|
|
57
58
|
const { id } = response.data;
|
|
@@ -101,7 +102,7 @@ class WsClient extends _Client2.default {
|
|
|
101
102
|
}
|
|
102
103
|
return { success: false, error: new Error("max retries exceeded") };
|
|
103
104
|
}
|
|
104
|
-
}
|
|
105
|
+
}, _class);
|
|
105
106
|
|
|
106
107
|
|
|
107
108
|
exports.default = WsClient;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
// src/WsClient.ts
|
|
1
2
|
import { deferredPromise, once, sleep } from "@chainflip/utils/async";
|
|
2
3
|
import { randomUUID } from "crypto";
|
|
3
|
-
import Client from "./Client";
|
|
4
|
-
import { rpcResponse } from "./common";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import Client from "./Client.mjs";
|
|
5
|
+
import { rpcResponse } from "./common.mjs";
|
|
6
|
+
var READY = "READY";
|
|
7
|
+
var DISCONNECT = "DISCONNECT";
|
|
8
|
+
var WsClient = class extends Client {
|
|
8
9
|
constructor(url, WebSocket = globalThis.WebSocket) {
|
|
9
10
|
super(url);
|
|
10
11
|
this.WebSocket = WebSocket;
|
|
@@ -101,7 +102,7 @@ class WsClient extends Client {
|
|
|
101
102
|
}
|
|
102
103
|
return { success: false, error: new Error("max retries exceeded") };
|
|
103
104
|
}
|
|
104
|
-
}
|
|
105
|
+
};
|
|
105
106
|
export {
|
|
106
107
|
WsClient as default
|
|
107
108
|
};
|
package/dist/common.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true})
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/common.ts
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -11,23 +11,24 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var _parsers = require('./parsers');
|
|
15
|
-
const rpcResult = {
|
|
16
|
-
broker_requestSwapDepositAddress: _parsers.brokerRequestSwapDepositAddress,
|
|
17
|
-
cf_boost_pools_depth: _parsers.cfBoostPoolsDepth,
|
|
18
|
-
cf_environment: _parsers.cfEnvironment,
|
|
19
|
-
cf_funding_environment: _parsers.cfFundingEnvironment,
|
|
20
|
-
cf_ingress_egress_environment: _parsers.cfIngressEgressEnvironment,
|
|
21
|
-
cf_supported_assets: _parsers.cfSupportedAsssets,
|
|
22
|
-
cf_swap_rate: _parsers.cfSwapRate,
|
|
23
|
-
cf_swap_rate_v2: _parsers.cfSwapRateV2,
|
|
24
|
-
cf_swapping_environment: _parsers.cfSwappingEnvironment,
|
|
25
|
-
chain_getBlockHash: _parsers.chainGetBlockHash,
|
|
26
|
-
state_getMetadata: _parsers.stateGetMetadata,
|
|
27
|
-
state_getRuntimeVersion: _parsers.stateGetRuntimeVersion
|
|
28
|
-
};
|
|
29
14
|
|
|
15
|
+
var _parserscjs = require('./parsers.cjs');
|
|
16
|
+
|
|
17
|
+
var rpcResult = {
|
|
18
|
+
broker_requestSwapDepositAddress: _parserscjs.brokerRequestSwapDepositAddress,
|
|
19
|
+
cf_boost_pools_depth: _parserscjs.cfBoostPoolsDepth,
|
|
20
|
+
cf_environment: _parserscjs.cfEnvironment,
|
|
21
|
+
cf_funding_environment: _parserscjs.cfFundingEnvironment,
|
|
22
|
+
cf_ingress_egress_environment: _parserscjs.cfIngressEgressEnvironment,
|
|
23
|
+
cf_supported_assets: _parserscjs.cfSupportedAsssets,
|
|
24
|
+
cf_swap_rate: _parserscjs.cfSwapRate,
|
|
25
|
+
cf_swap_rate_v2: _parserscjs.cfSwapRateV2,
|
|
26
|
+
cf_swapping_environment: _parserscjs.cfSwappingEnvironment,
|
|
27
|
+
chain_getBlockHash: _parserscjs.chainGetBlockHash,
|
|
28
|
+
state_getMetadata: _parserscjs.stateGetMetadata,
|
|
29
|
+
state_getRuntimeVersion: _parserscjs.stateGetRuntimeVersion
|
|
30
|
+
};
|
|
30
31
|
|
|
31
32
|
|
|
32
33
|
|
|
33
|
-
exports.rpcResponse =
|
|
34
|
+
exports.rpcResponse = _parserscjs.rpcResponse; exports.rpcResult = rpcResult;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// src/common.ts
|
|
1
2
|
import {
|
|
2
3
|
brokerRequestSwapDepositAddress,
|
|
3
4
|
cfBoostPoolsDepth,
|
|
@@ -11,8 +12,9 @@ import {
|
|
|
11
12
|
chainGetBlockHash,
|
|
12
13
|
stateGetMetadata,
|
|
13
14
|
stateGetRuntimeVersion
|
|
14
|
-
} from "./parsers";
|
|
15
|
-
|
|
15
|
+
} from "./parsers.mjs";
|
|
16
|
+
import { rpcResponse as rpcResponse2 } from "./parsers.mjs";
|
|
17
|
+
var rpcResult = {
|
|
16
18
|
broker_requestSwapDepositAddress: brokerRequestSwapDepositAddress,
|
|
17
19
|
cf_boost_pools_depth: cfBoostPoolsDepth,
|
|
18
20
|
cf_environment: cfEnvironment,
|
|
@@ -26,7 +28,6 @@ const rpcResult = {
|
|
|
26
28
|
state_getMetadata: stateGetMetadata,
|
|
27
29
|
state_getRuntimeVersion: stateGetRuntimeVersion
|
|
28
30
|
};
|
|
29
|
-
import { rpcResponse as rpcResponse2 } from "./parsers";
|
|
30
31
|
export {
|
|
31
32
|
rpcResponse2 as rpcResponse,
|
|
32
33
|
rpcResult
|
package/dist/constants.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true})
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/constants.ts
|
|
2
|
+
var PUBLIC_RPC_ENDPOINTS = {
|
|
2
3
|
mainnet: "https://mainnet-archive.chainflip.io",
|
|
3
4
|
perseverance: "https://archive.perseverance.chainflip.io",
|
|
4
5
|
sisyphos: "https://archive.sisyphos.chainflip.io",
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); }
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); }// src/index.ts
|
|
2
|
+
var _HttpClientcjs = require('./HttpClient.cjs'); var _HttpClientcjs2 = _interopRequireDefault(_HttpClientcjs);
|
|
3
|
+
var _WsClientcjs = require('./WsClient.cjs'); var _WsClientcjs2 = _interopRequireDefault(_WsClientcjs);
|
|
4
|
+
var _typescjs = require('./types.cjs'); _createStarExport(_typescjs);
|
|
5
|
+
var _constantscjs = require('./constants.cjs'); var constants = _interopRequireWildcard(_constantscjs);
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
9
|
-
exports.HttpClient =
|
|
10
|
+
exports.HttpClient = _HttpClientcjs2.default; exports.WsClient = _WsClientcjs2.default; exports.constants = constants;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { default as default2 } from "./HttpClient.mjs";
|
|
3
|
+
import { default as default3 } from "./WsClient.mjs";
|
|
4
|
+
export * from "./types.mjs";
|
|
5
|
+
import * as constants from "./constants.mjs";
|
|
6
|
+
export {
|
|
7
|
+
default2 as HttpClient,
|
|
8
|
+
default3 as WsClient,
|
|
9
|
+
constants
|
|
10
|
+
};
|
package/dist/parsers.cjs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true})
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/parsers.ts
|
|
2
|
+
var _guard = require('@chainflip/utils/guard');
|
|
2
3
|
var _string = require('@chainflip/utils/string');
|
|
3
4
|
var _zod = require('zod');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
var hexString = _zod.z.string().refine(_string.isHex, { message: "Invalid hex string" });
|
|
6
|
+
var u256 = hexString.transform((value) => BigInt(value));
|
|
7
|
+
var numberOrHex = _zod.z.union([_zod.z.number().transform((n) => BigInt(n)), u256]);
|
|
8
|
+
var chainAssetMapFactory = (parser) => _zod.z.object({
|
|
8
9
|
Bitcoin: _zod.z.object({ BTC: parser }),
|
|
9
10
|
Ethereum: _zod.z.object({ ETH: parser, USDC: parser, FLIP: parser, USDT: parser }),
|
|
10
11
|
Polkadot: _zod.z.object({ DOT: parser }),
|
|
11
12
|
Arbitrum: _zod.z.object({ ETH: parser, USDC: parser })
|
|
12
13
|
});
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
var chainMapFactory = (parser) => _zod.z.object({ Bitcoin: parser, Ethereum: parser, Polkadot: parser, Arbitrum: parser });
|
|
15
|
+
var rpcAssetSchema = _zod.z.union([
|
|
15
16
|
_zod.z.object({ chain: _zod.z.literal("Bitcoin"), asset: _zod.z.literal("BTC") }),
|
|
16
17
|
_zod.z.object({ chain: _zod.z.literal("Polkadot"), asset: _zod.z.literal("DOT") }),
|
|
17
18
|
_zod.z.object({ chain: _zod.z.literal("Ethereum"), asset: _zod.z.literal("FLIP") }),
|
|
@@ -21,37 +22,37 @@ const rpcAssetSchema = _zod.z.union([
|
|
|
21
22
|
_zod.z.object({ chain: _zod.z.literal("Arbitrum"), asset: _zod.z.literal("ETH") }),
|
|
22
23
|
_zod.z.object({ chain: _zod.z.literal("Arbitrum"), asset: _zod.z.literal("USDC") })
|
|
23
24
|
]);
|
|
24
|
-
|
|
25
|
+
var rename = (mapping) => (obj) => Object.fromEntries(
|
|
25
26
|
Object.entries(obj).map(([key, value]) => [
|
|
26
27
|
key in mapping ? mapping[key] : key,
|
|
27
28
|
value
|
|
28
29
|
])
|
|
29
30
|
);
|
|
30
|
-
|
|
31
|
+
var rpcBaseResponse = _zod.z.object({
|
|
31
32
|
id: _zod.z.union([_zod.z.string(), _zod.z.number()]),
|
|
32
33
|
jsonrpc: _zod.z.literal("2.0")
|
|
33
34
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
var nonNullish = _zod.z.any().refine(_guard.isNotNullish, { message: "Value must not be null or undefined" });
|
|
36
|
+
var rpcSuccessResponse = rpcBaseResponse.extend({ result: nonNullish });
|
|
37
|
+
var rpcErrorResponse = rpcBaseResponse.extend({
|
|
37
38
|
error: _zod.z.object({ code: _zod.z.number(), message: _zod.z.string() })
|
|
38
39
|
});
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
var rpcResponse = _zod.z.union([rpcSuccessResponse, rpcErrorResponse]);
|
|
41
|
+
var cfSwapRate = _zod.z.object({
|
|
41
42
|
intermediary: numberOrHex.nullable(),
|
|
42
43
|
output: numberOrHex
|
|
43
44
|
});
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
var fee = _zod.z.intersection(rpcAssetSchema, _zod.z.object({ amount: numberOrHex }));
|
|
46
|
+
var cfSwapRateV2 = _zod.z.object({
|
|
46
47
|
egress_fee: fee,
|
|
47
48
|
ingress_fee: fee,
|
|
48
49
|
intermediary: u256.nullable(),
|
|
49
50
|
network_fee: fee,
|
|
50
51
|
output: u256
|
|
51
52
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
var chainGetBlockHash = hexString;
|
|
54
|
+
var stateGetMetadata = hexString;
|
|
55
|
+
var stateGetRuntimeVersion = _zod.z.object({
|
|
55
56
|
specName: _zod.z.string(),
|
|
56
57
|
implName: _zod.z.string(),
|
|
57
58
|
authoringVersion: _zod.z.number(),
|
|
@@ -61,7 +62,7 @@ const stateGetRuntimeVersion = _zod.z.object({
|
|
|
61
62
|
transactionVersion: _zod.z.number(),
|
|
62
63
|
stateVersion: _zod.z.number()
|
|
63
64
|
});
|
|
64
|
-
|
|
65
|
+
var cfIngressEgressEnvironment = _zod.z.object({
|
|
65
66
|
minimum_deposit_amounts: chainAssetMapFactory(numberOrHex),
|
|
66
67
|
ingress_fees: chainAssetMapFactory(numberOrHex.nullable()),
|
|
67
68
|
egress_fees: chainAssetMapFactory(numberOrHex.nullable()),
|
|
@@ -69,24 +70,24 @@ const cfIngressEgressEnvironment = _zod.z.object({
|
|
|
69
70
|
egress_dust_limits: chainAssetMapFactory(numberOrHex),
|
|
70
71
|
channel_opening_fees: chainMapFactory(numberOrHex)
|
|
71
72
|
}).transform(rename({ egress_dust_limits: "minimum_egress_amounts" }));
|
|
72
|
-
|
|
73
|
+
var cfSwappingEnvironment = _zod.z.object({
|
|
73
74
|
maximum_swap_amounts: chainAssetMapFactory(numberOrHex.nullable()),
|
|
74
75
|
network_fee_hundredth_pips: _zod.z.number()
|
|
75
76
|
});
|
|
76
|
-
|
|
77
|
+
var cfFundingEnvironment = _zod.z.object({
|
|
77
78
|
redemption_tax: numberOrHex,
|
|
78
79
|
minimum_funding_amount: numberOrHex
|
|
79
80
|
});
|
|
80
|
-
|
|
81
|
+
var cfEnvironment = _zod.z.object({
|
|
81
82
|
ingress_egress: cfIngressEgressEnvironment,
|
|
82
83
|
swapping: cfSwappingEnvironment,
|
|
83
84
|
funding: cfFundingEnvironment
|
|
84
85
|
});
|
|
85
|
-
|
|
86
|
+
var cfBoostPoolsDepth = _zod.z.array(
|
|
86
87
|
_zod.z.intersection(rpcAssetSchema, _zod.z.object({ tier: _zod.z.number(), available_amount: u256 }))
|
|
87
88
|
);
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
var cfSupportedAsssets = _zod.z.array(rpcAssetSchema);
|
|
90
|
+
var brokerRequestSwapDepositAddress = _zod.z.object({
|
|
90
91
|
address: _zod.z.string(),
|
|
91
92
|
issued_block: _zod.z.number(),
|
|
92
93
|
channel_id: _zod.z.number(),
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
// src/parsers.ts
|
|
1
2
|
import { isNotNullish } from "@chainflip/utils/guard";
|
|
2
3
|
import { isHex } from "@chainflip/utils/string";
|
|
3
4
|
import { z } from "zod";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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) => z.object({
|
|
8
9
|
Bitcoin: z.object({ BTC: parser }),
|
|
9
10
|
Ethereum: z.object({ ETH: parser, USDC: parser, FLIP: parser, USDT: parser }),
|
|
10
11
|
Polkadot: z.object({ DOT: parser }),
|
|
11
12
|
Arbitrum: z.object({ ETH: parser, USDC: parser })
|
|
12
13
|
});
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
var chainMapFactory = (parser) => z.object({ Bitcoin: parser, Ethereum: parser, Polkadot: parser, Arbitrum: parser });
|
|
15
|
+
var rpcAssetSchema = z.union([
|
|
15
16
|
z.object({ chain: z.literal("Bitcoin"), asset: z.literal("BTC") }),
|
|
16
17
|
z.object({ chain: z.literal("Polkadot"), asset: z.literal("DOT") }),
|
|
17
18
|
z.object({ chain: z.literal("Ethereum"), asset: z.literal("FLIP") }),
|
|
@@ -21,37 +22,37 @@ const rpcAssetSchema = z.union([
|
|
|
21
22
|
z.object({ chain: z.literal("Arbitrum"), asset: z.literal("ETH") }),
|
|
22
23
|
z.object({ chain: z.literal("Arbitrum"), asset: z.literal("USDC") })
|
|
23
24
|
]);
|
|
24
|
-
|
|
25
|
+
var rename = (mapping) => (obj) => Object.fromEntries(
|
|
25
26
|
Object.entries(obj).map(([key, value]) => [
|
|
26
27
|
key in mapping ? mapping[key] : key,
|
|
27
28
|
value
|
|
28
29
|
])
|
|
29
30
|
);
|
|
30
|
-
|
|
31
|
+
var rpcBaseResponse = z.object({
|
|
31
32
|
id: z.union([z.string(), z.number()]),
|
|
32
33
|
jsonrpc: z.literal("2.0")
|
|
33
34
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
var nonNullish = z.any().refine(isNotNullish, { message: "Value must not be null or undefined" });
|
|
36
|
+
var rpcSuccessResponse = rpcBaseResponse.extend({ result: nonNullish });
|
|
37
|
+
var rpcErrorResponse = rpcBaseResponse.extend({
|
|
37
38
|
error: z.object({ code: z.number(), message: z.string() })
|
|
38
39
|
});
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
var rpcResponse = z.union([rpcSuccessResponse, rpcErrorResponse]);
|
|
41
|
+
var cfSwapRate = z.object({
|
|
41
42
|
intermediary: numberOrHex.nullable(),
|
|
42
43
|
output: numberOrHex
|
|
43
44
|
});
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
var fee = z.intersection(rpcAssetSchema, z.object({ amount: numberOrHex }));
|
|
46
|
+
var cfSwapRateV2 = z.object({
|
|
46
47
|
egress_fee: fee,
|
|
47
48
|
ingress_fee: fee,
|
|
48
49
|
intermediary: u256.nullable(),
|
|
49
50
|
network_fee: fee,
|
|
50
51
|
output: u256
|
|
51
52
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
var chainGetBlockHash = hexString;
|
|
54
|
+
var stateGetMetadata = hexString;
|
|
55
|
+
var stateGetRuntimeVersion = z.object({
|
|
55
56
|
specName: z.string(),
|
|
56
57
|
implName: z.string(),
|
|
57
58
|
authoringVersion: z.number(),
|
|
@@ -61,7 +62,7 @@ const stateGetRuntimeVersion = z.object({
|
|
|
61
62
|
transactionVersion: z.number(),
|
|
62
63
|
stateVersion: z.number()
|
|
63
64
|
});
|
|
64
|
-
|
|
65
|
+
var cfIngressEgressEnvironment = z.object({
|
|
65
66
|
minimum_deposit_amounts: chainAssetMapFactory(numberOrHex),
|
|
66
67
|
ingress_fees: chainAssetMapFactory(numberOrHex.nullable()),
|
|
67
68
|
egress_fees: chainAssetMapFactory(numberOrHex.nullable()),
|
|
@@ -69,24 +70,24 @@ const cfIngressEgressEnvironment = z.object({
|
|
|
69
70
|
egress_dust_limits: chainAssetMapFactory(numberOrHex),
|
|
70
71
|
channel_opening_fees: chainMapFactory(numberOrHex)
|
|
71
72
|
}).transform(rename({ egress_dust_limits: "minimum_egress_amounts" }));
|
|
72
|
-
|
|
73
|
+
var cfSwappingEnvironment = z.object({
|
|
73
74
|
maximum_swap_amounts: chainAssetMapFactory(numberOrHex.nullable()),
|
|
74
75
|
network_fee_hundredth_pips: z.number()
|
|
75
76
|
});
|
|
76
|
-
|
|
77
|
+
var cfFundingEnvironment = z.object({
|
|
77
78
|
redemption_tax: numberOrHex,
|
|
78
79
|
minimum_funding_amount: numberOrHex
|
|
79
80
|
});
|
|
80
|
-
|
|
81
|
+
var cfEnvironment = z.object({
|
|
81
82
|
ingress_egress: cfIngressEgressEnvironment,
|
|
82
83
|
swapping: cfSwappingEnvironment,
|
|
83
84
|
funding: cfFundingEnvironment
|
|
84
85
|
});
|
|
85
|
-
|
|
86
|
+
var cfBoostPoolsDepth = z.array(
|
|
86
87
|
z.intersection(rpcAssetSchema, z.object({ tier: z.number(), available_amount: u256 }))
|
|
87
88
|
);
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
var cfSupportedAsssets = z.array(rpcAssetSchema);
|
|
90
|
+
var brokerRequestSwapDepositAddress = z.object({
|
|
90
91
|
address: z.string(),
|
|
91
92
|
issued_block: z.number(),
|
|
92
93
|
channel_id: z.number(),
|
package/package.json
CHANGED
package/dist/index.js
DELETED
|
File without changes
|