@chainflip/sdk 1.1.1-rc.2 → 1.1.2

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.
@@ -1,5 +1,5 @@
1
- import { chainflipAssetAndChain, numericString, hexString, btcAddress, ccmMetadataSchema, hexStringFromNumber, dotAddress, unsignedInteger } from './chunk-LEMOY2A2.mjs';
2
- import { z, isNotNullish, __name, Assets } from './chunk-O4RYZWBW.mjs';
1
+ import { chainflipAssetAndChain, numericString, hexString, btcAddress, ccmMetadataSchema, hexStringFromNumber, dotAddress, unsignedInteger } from './chunk-Z4OL2TKA.mjs';
2
+ import { z, __name, Assets, isNotNullish } from './chunk-Q7HQVR3T.mjs';
3
3
  import { u8aToHex } from '@polkadot/util';
4
4
  import { decodeAddress } from '@polkadot/util-crypto';
5
5
  import axios from 'axios';
@@ -37,14 +37,14 @@ var rpcResult = z.union([
37
37
  result: z.unknown()
38
38
  })
39
39
  ]);
40
- var requestValidators = {
40
+ var requestValidators = /* @__PURE__ */ __name((network) => ({
41
41
  requestSwapDepositAddress: z.tuple([
42
42
  chainflipAssetAndChain,
43
43
  chainflipAssetAndChain,
44
44
  z.union([
45
45
  numericString,
46
46
  hexString,
47
- btcAddress()
47
+ btcAddress(network)
48
48
  ]),
49
49
  z.number(),
50
50
  ccmMetadataSchema.merge(z.object({
@@ -61,13 +61,13 @@ var requestValidators = {
61
61
  d,
62
62
  transformObjToSnakeCase(e)
63
63
  ].filter(isNotNullish))
64
- };
65
- var responseValidators = {
64
+ }), "requestValidators");
65
+ var responseValidators = /* @__PURE__ */ __name((network) => ({
66
66
  requestSwapDepositAddress: z.object({
67
67
  address: z.union([
68
68
  dotAddress,
69
69
  hexString,
70
- btcAddress()
70
+ btcAddress(network)
71
71
  ]),
72
72
  issued_block: z.number(),
73
73
  channel_id: z.number(),
@@ -79,23 +79,23 @@ var responseValidators = {
79
79
  channelId: BigInt(channel_id),
80
80
  sourceChainExpiryBlock: source_chain_expiry_block
81
81
  }))
82
- };
83
- var makeRpcRequest = /* @__PURE__ */ __name(async (url, method, ...params) => {
82
+ }), "responseValidators");
83
+ var makeRpcRequest = /* @__PURE__ */ __name(async (network, url, method, ...params) => {
84
84
  const res = await axios.post(url.toString(), {
85
85
  jsonrpc: "2.0",
86
86
  id: 1,
87
87
  method: `broker_${method}`,
88
- params: requestValidators[method].parse(params)
88
+ params: requestValidators(network)[method].parse(params)
89
89
  });
90
90
  const result = rpcResult.parse(res.data);
91
91
  if ("error" in result) {
92
92
  throw new Error(`Broker responded with error code ${result.error.code}: ${result.error.message}`);
93
93
  }
94
- return responseValidators[method].parse(result.result);
94
+ return responseValidators(network)[method].parse(result.result);
95
95
  }, "makeRpcRequest");
96
- async function requestSwapDepositAddress(swapRequest, opts) {
96
+ async function requestSwapDepositAddress(swapRequest, opts, chainflipNetwork) {
97
97
  const { srcAsset, srcChain, destAsset, destChain, destAddress } = swapRequest;
98
- return makeRpcRequest(opts.url, "requestSwapDepositAddress", {
98
+ return makeRpcRequest(chainflipNetwork, opts.url, "requestSwapDepositAddress", {
99
99
  asset: srcAsset,
100
100
  chain: srcChain
101
101
  }, {
@@ -1,4 +1,4 @@
1
- import { z, ChainflipNetworks, __name, __publicField, Assets } from './chunk-O4RYZWBW.mjs';
1
+ import { z, ChainflipNetworks, __name, __publicField, Assets } from './chunk-Q7HQVR3T.mjs';
2
2
  import axios from 'axios';
3
3
  import { Interface, Contract } from 'ethers';
4
4
 
@@ -21,12 +21,12 @@ var RPC_URLS = {
21
21
  [ChainflipNetworks.perseverance]: "https://perseverance.chainflip.xyz",
22
22
  [ChainflipNetworks.mainnet]: "https://mainnet-rpc.chainflip.io"
23
23
  };
24
- var createRequest = /* @__PURE__ */ __name((method, responseParser, paramsParser) => async (urlOrNetwork, params) => {
24
+ var createRequest = /* @__PURE__ */ __name((method, responseParser) => async (urlOrNetwork, ...params) => {
25
25
  const url = "network" in urlOrNetwork ? RPC_URLS[urlOrNetwork.network] : urlOrNetwork.rpcUrl;
26
26
  const { data } = await axios.post(url, {
27
27
  jsonrpc: "2.0",
28
28
  method,
29
- params: paramsParser?.parse(params),
29
+ params,
30
30
  id: 1
31
31
  });
32
32
  const result = responseParser.safeParse(data.result);
@@ -127,10 +127,13 @@ createRequest("cf_pool_info", poolsEnvironment);
127
127
  var environment = z.object({
128
128
  ingress_egress: ingressEgressEnvironment,
129
129
  swapping: swappingEnvironment,
130
- funding: fundingEnvironment,
131
- pools: poolsEnvironment
130
+ funding: fundingEnvironment
132
131
  });
133
132
  var getEnvironment = createRequest("cf_environment", environment);
133
+ var swapRate = z.object({
134
+ output: numberOrHex
135
+ });
136
+ createRequest("cf_swap_rate", swapRate);
134
137
  var _abi = [
135
138
  {
136
139
  inputs: [
@@ -1,6 +1,30 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
2
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
8
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __commonJS = (cb, mod) => function __require() {
10
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
4
28
  var __publicField = (obj, key, value) => {
5
29
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
30
  return value;
@@ -66,6 +90,11 @@ var chainAssets = {
66
90
  Assets.DOT
67
91
  ]
68
92
  };
93
+ ({
94
+ [Chains.Ethereum]: Assets.ETH,
95
+ [Chains.Bitcoin]: Assets.BTC,
96
+ [Chains.Polkadot]: Assets.DOT
97
+ });
69
98
  var chainContractIds = {
70
99
  [Chains.Ethereum]: 1,
71
100
  [Chains.Polkadot]: 2,
@@ -3930,4 +3959,4 @@ var z = /* @__PURE__ */ Object.freeze({
3930
3959
  ZodError
3931
3960
  });
3932
3961
 
3933
- export { Assets, ChainflipNetworks, Chains, __name, __publicField, assert, assertIsValidAssetAndChain, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds, isNotNullish, isString, isTestnet, isTokenCall, isTokenSwap, z };
3962
+ export { Assets, ChainflipNetworks, Chains, __commonJS, __name, __publicField, __toESM, assert, assertIsValidAssetAndChain, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds, isNotNullish, isString, isTestnet, isTokenCall, isTokenSwap, z };