@chainflip/sdk 1.4.0-alpha.2 → 1.4.0-alpha.4

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/swap.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { getEnvironment, getSupportedAssets, getVaultContractAddress, approve, getTokenContractAddress, getEvmChainId, checkAllowance, extractOverrides, Vault__factory } from './chunk-4HLERQ4Y.mjs';
2
- import { ccmMetadataSchema } from './chunk-KHC24Z3O.mjs';
3
- import { __name, ChainflipNetworks, __publicField, Chains, assetConstants, getInternalAsset, isNotNullish, assert, readChainAssetValue, isTestnet, assertValidAddress, chainConstants, getInternalAssets, dotAddress } from './chunk-LQGUI52U.mjs';
4
- export { Assets, InternalAssets as ChainflipIds, ChainflipNetworks, Chains, getInternalAsset as getChainflipId } from './chunk-LQGUI52U.mjs';
1
+ import { getEnvironment, getSupportedAssets, getVaultContractAddress, approve, getTokenContractAddress, getEvmChainId, checkAllowance, extractOverrides, Vault__factory } from './chunk-LFAWGKTO.mjs';
2
+ import { assertValidAddress, ccmMetadataSchema, dotAddress } from './chunk-M2KPIR26.mjs';
3
+ import { __name, ChainflipNetworks, __publicField, Chains, assetConstants, getInternalAsset, isNotNullish, assert, readChainAssetValue, isTestnet, chainConstants, getInternalAssets } from './chunk-VT6GEMQN.mjs';
4
+ export { Assets, InternalAssets as ChainflipIds, ChainflipNetworks, Chains, getInternalAsset as getChainflipId } from './chunk-VT6GEMQN.mjs';
5
5
  import { bytesToHex } from '@chainflip/utils/bytes';
6
6
  import * as ss58 from '@chainflip/utils/ss58';
7
7
  import axios from 'axios';
@@ -2496,7 +2496,7 @@ var _SwapSDK = class _SwapSDK {
2496
2496
  }, BigInt(amount));
2497
2497
  let response;
2498
2498
  if (this.options.broker !== void 0) {
2499
- const { requestSwapDepositAddress } = await import('./broker-XWF7RRDY.mjs');
2499
+ const { requestSwapDepositAddress } = await import('./broker-ZOUQBZB6.mjs');
2500
2500
  const result = await requestSwapDepositAddress(depositAddressRequest, {
2501
2501
  ...this.options.broker,
2502
2502
  commissionBps: brokerCommissionBps ?? this.options.broker.commissionBps,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/sdk",
3
- "version": "1.4.0-alpha.2",
3
+ "version": "1.4.0-alpha.4",
4
4
  "description": "",
5
5
  "exports": {
6
6
  "./swap": {
@@ -32,7 +32,7 @@
32
32
  "author": "",
33
33
  "license": "ISC",
34
34
  "engines": {
35
- "node": "^18 || ^20.11.0",
35
+ "node": "^18 || ^20 || ^22.3.0",
36
36
  "pnpm": ">=9"
37
37
  },
38
38
  "repository": "https://github.com/chainflip-io/chainflip-sdk-monorepo.git",
@@ -41,7 +41,8 @@
41
41
  "access": "public"
42
42
  },
43
43
  "dependencies": {
44
- "@chainflip/utils": "^0.1.4",
44
+ "@chainflip/rpc": "^1.4.2",
45
+ "@chainflip/utils": "^0.2.1",
45
46
  "axios": "^1.6.8",
46
47
  "ethers": "^6.11.1"
47
48
  },
@@ -1,124 +0,0 @@
1
- import { ccmMetadataSchema, affiliateBroker } from './chunk-KHC24Z3O.mjs';
2
- import { z, __name, Chains, uncheckedAssetAndChain, numericString, hexString, btcAddress, hexStringFromNumber, dotAddress, ethereumAddress, unsignedInteger, u128 } from './chunk-LQGUI52U.mjs';
3
- import { bytesToHex } from '@chainflip/utils/bytes';
4
- import * as ss58 from '@chainflip/utils/ss58';
5
- import axios from 'axios';
6
-
7
- // ../shared/src/strings.ts
8
- var camelToSnakeCase = /* @__PURE__ */ __name((str) => str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`), "camelToSnakeCase");
9
-
10
- // ../shared/src/broker.ts
11
- var transformObjToSnakeCase = /* @__PURE__ */ __name((obj) => {
12
- if (!obj)
13
- return void 0;
14
- const newObj = {};
15
- for (const key in obj) {
16
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
17
- newObj[camelToSnakeCase(key)] = obj[key];
18
- }
19
- }
20
- return newObj;
21
- }, "transformObjToSnakeCase");
22
- var submitAddress = /* @__PURE__ */ __name((chain, address) => {
23
- if (chain === Chains.Polkadot) {
24
- return address.startsWith("0x") ? z.string().length(66).parse(address) : bytesToHex(ss58.decode(address).data);
25
- }
26
- return address;
27
- }, "submitAddress");
28
- var rpcResult = z.union([
29
- z.object({
30
- error: z.object({
31
- code: z.number().optional(),
32
- message: z.string().optional(),
33
- data: z.unknown().optional()
34
- })
35
- }),
36
- z.object({
37
- result: z.unknown()
38
- })
39
- ]);
40
- var requestValidators = /* @__PURE__ */ __name((network) => ({
41
- requestSwapDepositAddress: z.tuple([
42
- uncheckedAssetAndChain,
43
- uncheckedAssetAndChain,
44
- z.union([
45
- numericString,
46
- hexString,
47
- btcAddress(network)
48
- ]),
49
- z.number(),
50
- ccmMetadataSchema.merge(z.object({
51
- gasBudget: hexStringFromNumber,
52
- cfParameters: z.union([
53
- hexString,
54
- z.string()
55
- ]).optional()
56
- })).optional(),
57
- z.number().optional(),
58
- z.array(affiliateBroker).optional()
59
- ]).transform(([a, b, c, d, e, f, g]) => g ? [
60
- a,
61
- b,
62
- c,
63
- d,
64
- transformObjToSnakeCase(e),
65
- f,
66
- g
67
- ] : [
68
- a,
69
- b,
70
- c,
71
- d,
72
- transformObjToSnakeCase(e),
73
- f
74
- ])
75
- }), "requestValidators");
76
- var responseValidators = /* @__PURE__ */ __name((network) => ({
77
- requestSwapDepositAddress: z.object({
78
- address: z.union([
79
- dotAddress,
80
- ethereumAddress,
81
- btcAddress(network)
82
- ]),
83
- issued_block: z.number(),
84
- channel_id: z.number(),
85
- expiry_block: z.number().int().safe().positive().optional(),
86
- source_chain_expiry_block: unsignedInteger.optional(),
87
- channel_opening_fee: u128.optional().default(0)
88
- }).transform(({ address, issued_block, channel_id, source_chain_expiry_block, channel_opening_fee }) => ({
89
- address,
90
- issuedBlock: issued_block,
91
- channelId: BigInt(channel_id),
92
- sourceChainExpiryBlock: source_chain_expiry_block,
93
- channelOpeningFee: channel_opening_fee
94
- }))
95
- }), "responseValidators");
96
- var makeRpcRequest = /* @__PURE__ */ __name(async (network, url, method, ...params) => {
97
- const res = await axios.post(url.toString(), {
98
- jsonrpc: "2.0",
99
- id: 1,
100
- method: `broker_${method}`,
101
- params: requestValidators(network)[method].parse(params)
102
- });
103
- const result = rpcResult.parse(res.data);
104
- if ("error" in result) {
105
- throw new Error(`Broker responded with error code ${result.error.code}: ${result.error.message}`);
106
- }
107
- return responseValidators(network)[method].parse(result.result);
108
- }, "makeRpcRequest");
109
- async function requestSwapDepositAddress(swapRequest, opts, chainflipNetwork) {
110
- const { srcAsset, srcChain, destAsset, destChain, destAddress, maxBoostFeeBps } = swapRequest;
111
- return makeRpcRequest(chainflipNetwork, opts.url, "requestSwapDepositAddress", {
112
- asset: srcAsset,
113
- chain: srcChain
114
- }, {
115
- asset: destAsset,
116
- chain: destChain
117
- }, submitAddress(destChain, destAddress), opts.commissionBps, swapRequest.ccmMetadata && {
118
- ...swapRequest.ccmMetadata,
119
- cfParameters: void 0
120
- }, maxBoostFeeBps, opts.affiliates);
121
- }
122
- __name(requestSwapDepositAddress, "requestSwapDepositAddress");
123
-
124
- export { requestSwapDepositAddress };
@@ -1,65 +0,0 @@
1
- import { z, chain, asset, numericString, numericOrEmptyString, getInternalAssets, hexStringWithMaxByteSize, chainflipAddress, number } from './chunk-LQGUI52U.mjs';
2
-
3
- // ../shared/src/schemas.ts
4
- z.object({
5
- srcChain: chain,
6
- srcAsset: asset,
7
- destChain: chain,
8
- destAsset: asset,
9
- amount: numericString.transform((n) => BigInt(n)),
10
- brokerCommissionBps: numericOrEmptyString.transform((v) => Number(v)).optional()
11
- }).transform((args, ctx) => {
12
- const { srcAsset, destAsset } = getInternalAssets(args, false);
13
- if (srcAsset === null) {
14
- ctx.addIssue({
15
- message: `invalid asset and chain combination: ${JSON.stringify({
16
- asset: args.srcAsset,
17
- chain: args.srcChain
18
- })}`,
19
- code: z.ZodIssueCode.custom
20
- });
21
- return z.NEVER;
22
- }
23
- if (destAsset === null) {
24
- ctx.addIssue({
25
- message: `invalid asset and chain combination: ${JSON.stringify({
26
- asset: args.destAsset,
27
- chain: args.destChain
28
- })}`,
29
- code: z.ZodIssueCode.custom
30
- });
31
- return z.NEVER;
32
- }
33
- return {
34
- srcAsset,
35
- destAsset,
36
- amount: args.amount,
37
- brokerCommissionBps: args.brokerCommissionBps
38
- };
39
- });
40
- var ccmMetadataSchema = z.object({
41
- gasBudget: numericString,
42
- message: hexStringWithMaxByteSize(1024 * 10)
43
- });
44
- var affiliateBroker = z.object({
45
- account: chainflipAddress,
46
- commissionBps: number
47
- }).transform(({ account, commissionBps: bps }) => ({
48
- account,
49
- bps
50
- }));
51
- z.object({
52
- srcAsset: asset,
53
- destAsset: asset,
54
- srcChain: chain,
55
- destChain: chain,
56
- destAddress: z.string(),
57
- amount: numericString,
58
- ccmMetadata: ccmMetadataSchema.optional(),
59
- maxBoostFeeBps: z.number().optional()
60
- }).transform(({ amount, ...rest }) => ({
61
- ...rest,
62
- expectedDepositAmount: amount
63
- }));
64
-
65
- export { affiliateBroker, ccmMetadataSchema };