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