@chainflip/sdk 1.5.1 → 1.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/sdk",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "",
5
5
  "exports": {
6
6
  "./swap": {
@@ -1,86 +0,0 @@
1
- import { z, assetAndChain, numericString, hexString, btcAddress, ccmParamsSchema, affiliateBroker, fillOrKillParams, dotAddress, ethereumAddress } from './chunk-HWJAHLL7.mjs';
2
- import { __name, Chains } from './chunk-3V7QJANN.mjs';
3
- import { HttpClient } from '@chainflip/rpc';
4
- import * as ss58 from '@chainflip/utils/ss58';
5
-
6
- var submitAddress = /* @__PURE__ */ __name((chain, address) => {
7
- if (chain === Chains.Polkadot) {
8
- return address.startsWith("0x") ? z.string().length(66).parse(address) : ss58.toPublicKey(address);
9
- }
10
- return address;
11
- }, "submitAddress");
12
- var validateRequest = /* @__PURE__ */ __name((network, params) => z.tuple([
13
- assetAndChain,
14
- assetAndChain,
15
- z.union([
16
- numericString,
17
- hexString,
18
- btcAddress(network)
19
- ]),
20
- z.number(),
21
- ccmParamsSchema.merge(z.object({
22
- cfParameters: z.union([
23
- hexString,
24
- z.string()
25
- ]).optional()
26
- })).transform(({ message, ...rest }) => ({
27
- message,
28
- cf_parameters: rest.cfParameters,
29
- gas_budget: `0x${BigInt(rest.gasBudget).toString(16)}`
30
- })).optional(),
31
- z.number().optional(),
32
- z.array(affiliateBroker).optional(),
33
- fillOrKillParams.transform(({ retryDurationBlocks, refundAddress, minPriceX128 }) => ({
34
- retry_duration: retryDurationBlocks,
35
- refund_address: refundAddress,
36
- min_price: `0x${BigInt(minPriceX128).toString(16)}`
37
- })).optional()
38
- ]).parse(params), "validateRequest");
39
- var validateResponse = /* @__PURE__ */ __name((network, response) => z.object({
40
- address: z.union([
41
- dotAddress,
42
- ethereumAddress,
43
- btcAddress(network)
44
- ]),
45
- issued_block: z.number(),
46
- channel_id: z.number(),
47
- source_chain_expiry_block: z.bigint(),
48
- channel_opening_fee: z.bigint()
49
- }).transform(({ address, issued_block, channel_id, source_chain_expiry_block, channel_opening_fee }) => ({
50
- address,
51
- issuedBlock: issued_block,
52
- channelId: BigInt(channel_id),
53
- sourceChainExpiryBlock: source_chain_expiry_block,
54
- channelOpeningFee: channel_opening_fee
55
- })).parse(response), "validateResponse");
56
- async function requestSwapDepositAddress(swapRequest, opts, chainflipNetwork) {
57
- const { srcAsset, srcChain, destAsset, destChain, destAddress, maxBoostFeeBps } = swapRequest;
58
- const client = new HttpClient(opts.url);
59
- const params = validateRequest(chainflipNetwork, [
60
- {
61
- asset: srcAsset,
62
- chain: srcChain
63
- },
64
- {
65
- asset: destAsset,
66
- chain: destChain
67
- },
68
- submitAddress(destChain, destAddress),
69
- swapRequest.commissionBps ?? 0,
70
- swapRequest.ccmParams && {
71
- ...swapRequest.ccmParams,
72
- cfParameters: void 0
73
- },
74
- maxBoostFeeBps,
75
- swapRequest.affiliates,
76
- swapRequest.fillOrKillParams && {
77
- ...swapRequest.fillOrKillParams,
78
- refundAddress: submitAddress(srcChain, swapRequest.fillOrKillParams.refundAddress)
79
- }
80
- ]);
81
- const response = await client.sendRequest("broker_requestSwapDepositAddress", ...params);
82
- return validateResponse(chainflipNetwork, response);
83
- }
84
- __name(requestSwapDepositAddress, "requestSwapDepositAddress");
85
-
86
- export { requestSwapDepositAddress };
@@ -1,220 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
-
6
- // ../shared/src/enums.ts
7
- var arrayToMap = /* @__PURE__ */ __name((array) => Object.fromEntries(array.map((key) => [
8
- key,
9
- key
10
- ])), "arrayToMap");
11
- var InternalAssets = arrayToMap([
12
- "Flip",
13
- "Usdc",
14
- "Dot",
15
- "Eth",
16
- "Btc",
17
- "Usdt",
18
- "ArbUsdc",
19
- "ArbEth"
20
- ]);
21
- var Chains = arrayToMap([
22
- "Bitcoin",
23
- "Ethereum",
24
- "Polkadot",
25
- "Arbitrum"
26
- ]);
27
- var Assets = arrayToMap([
28
- "FLIP",
29
- "USDC",
30
- "DOT",
31
- "ETH",
32
- "BTC",
33
- "USDT"
34
- ]);
35
- var ChainflipNetworks = arrayToMap([
36
- "backspin",
37
- "sisyphos",
38
- "perseverance",
39
- "mainnet"
40
- ]);
41
- var isTestnet = /* @__PURE__ */ __name((network) => network !== ChainflipNetworks.mainnet, "isTestnet");
42
- var assetConstants = {
43
- [InternalAssets.Eth]: {
44
- chain: Chains.Ethereum,
45
- asset: Assets.ETH,
46
- name: "Ether",
47
- decimals: 18,
48
- contractId: 1
49
- },
50
- [InternalAssets.Flip]: {
51
- chain: Chains.Ethereum,
52
- asset: Assets.FLIP,
53
- name: "FLIP",
54
- decimals: 18,
55
- contractId: 2
56
- },
57
- [InternalAssets.Usdc]: {
58
- chain: Chains.Ethereum,
59
- asset: Assets.USDC,
60
- name: "USDC",
61
- decimals: 6,
62
- contractId: 3
63
- },
64
- [InternalAssets.Usdt]: {
65
- chain: Chains.Ethereum,
66
- asset: Assets.USDT,
67
- name: "USDT",
68
- decimals: 6,
69
- contractId: 8
70
- },
71
- [InternalAssets.Dot]: {
72
- chain: Chains.Polkadot,
73
- asset: Assets.DOT,
74
- name: "Polkadot",
75
- decimals: 10,
76
- contractId: 4
77
- },
78
- [InternalAssets.Btc]: {
79
- chain: Chains.Bitcoin,
80
- asset: Assets.BTC,
81
- name: "Bitcoin",
82
- decimals: 8,
83
- contractId: 5
84
- },
85
- [InternalAssets.ArbEth]: {
86
- chain: Chains.Arbitrum,
87
- asset: Assets.ETH,
88
- name: "Arbitrum Ether",
89
- decimals: 18,
90
- contractId: 6
91
- },
92
- [InternalAssets.ArbUsdc]: {
93
- chain: Chains.Arbitrum,
94
- asset: Assets.USDC,
95
- name: "Arbitrum USDC",
96
- decimals: 6,
97
- contractId: 7
98
- }
99
- };
100
- var chainConstants = {
101
- [Chains.Ethereum]: {
102
- assets: [
103
- Assets.ETH,
104
- Assets.FLIP,
105
- Assets.USDC,
106
- Assets.USDT
107
- ],
108
- gasAsset: Assets.ETH,
109
- contractId: 1,
110
- blockTimeSeconds: 12
111
- },
112
- [Chains.Polkadot]: {
113
- assets: [
114
- Assets.DOT
115
- ],
116
- gasAsset: Assets.DOT,
117
- contractId: 2,
118
- blockTimeSeconds: 6
119
- },
120
- [Chains.Bitcoin]: {
121
- assets: [
122
- Assets.BTC
123
- ],
124
- gasAsset: Assets.BTC,
125
- contractId: 3,
126
- blockTimeSeconds: 10 * 60
127
- },
128
- [Chains.Arbitrum]: {
129
- assets: [
130
- Assets.ETH,
131
- Assets.USDC
132
- ],
133
- gasAsset: Assets.ETH,
134
- contractId: 4,
135
- blockTimeSeconds: 0.26
136
- }
137
- };
138
- function isValidAssetAndChain(assetAndChain) {
139
- const { asset, chain } = assetAndChain;
140
- if (!(chain in Chains)) return false;
141
- const validAssets = chainConstants[chain].assets;
142
- return validAssets.includes(asset);
143
- }
144
- __name(isValidAssetAndChain, "isValidAssetAndChain");
145
- var readChainAssetValue = /* @__PURE__ */ __name((map, asset) => {
146
- const { chain, asset: symbol } = assetConstants[asset];
147
- const chainValues = map[chain];
148
- return chainValues[symbol];
149
- }, "readChainAssetValue");
150
- function getInternalAsset(asset, assert2 = true) {
151
- if (!isValidAssetAndChain(asset)) {
152
- if (assert2) {
153
- throw new Error(`invalid asset and chain combination: ${JSON.stringify(asset)}`);
154
- }
155
- return null;
156
- }
157
- const map = {
158
- [Chains.Ethereum]: {
159
- [Assets.USDC]: InternalAssets.Usdc,
160
- [Assets.FLIP]: InternalAssets.Flip,
161
- [Assets.ETH]: InternalAssets.Eth,
162
- [Assets.USDT]: InternalAssets.Usdt
163
- },
164
- [Chains.Bitcoin]: {
165
- [Assets.BTC]: InternalAssets.Btc
166
- },
167
- [Chains.Polkadot]: {
168
- [Assets.DOT]: InternalAssets.Dot
169
- },
170
- [Chains.Arbitrum]: {
171
- [Assets.USDC]: InternalAssets.ArbUsdc,
172
- [Assets.ETH]: InternalAssets.ArbEth
173
- }
174
- };
175
- const chain = map[asset.chain];
176
- return chain[asset.asset];
177
- }
178
- __name(getInternalAsset, "getInternalAsset");
179
- function getInternalAssets({ srcAsset, srcChain, destAsset, destChain }, assert2 = true) {
180
- return {
181
- srcAsset: getInternalAsset({
182
- asset: srcAsset,
183
- chain: srcChain
184
- }, assert2),
185
- destAsset: getInternalAsset({
186
- asset: destAsset,
187
- chain: destChain
188
- }, assert2)
189
- };
190
- }
191
- __name(getInternalAssets, "getInternalAssets");
192
- function getAssetAndChain(internalAsset, prefix) {
193
- const { chain, asset } = assetConstants[internalAsset];
194
- if (prefix) {
195
- return {
196
- [`${prefix}Asset`]: asset,
197
- [`${prefix}Chain`]: chain
198
- };
199
- }
200
- return {
201
- chain,
202
- asset
203
- };
204
- }
205
- __name(getAssetAndChain, "getAssetAndChain");
206
-
207
- // ../shared/src/guards.ts
208
- var isString = /* @__PURE__ */ __name((value) => typeof value === "string", "isString");
209
- var isNotNullish = /* @__PURE__ */ __name((value) => value !== null && value !== void 0, "isNotNullish");
210
- function assert(condition, message) {
211
- if (condition) return;
212
- const error = new Error(message);
213
- if (error.stack) {
214
- error.stack = error.stack.replace(/\n.+/, "\n");
215
- }
216
- throw error;
217
- }
218
- __name(assert, "assert");
219
-
220
- export { Assets, ChainflipNetworks, Chains, InternalAssets, __name, __publicField, assert, assetConstants, chainConstants, getAssetAndChain, getInternalAsset, getInternalAssets, isNotNullish, isString, isTestnet, isValidAssetAndChain, readChainAssetValue };