@chainflip/sdk 0.2.16 → 0.2.18

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,11 +1,11 @@
1
- import { getVaultManagerContractAddress, approve, getTokenContractAddress, checkAllowance, Vault__factory, extractOverrides, getMinimumDepositAmount, getMinimumSwapAmount } from './chunk-LNM2TOMZ.mjs';
2
- import { z, numericString, ethereumAddress, dotAddress, btcAddress, ccmMetadataSchema } from './chunk-DGDQYRRV.mjs';
3
- import { __name, Chains, Assets, ChainflipNetworks, __publicField, assert, isTokenCall, isTokenSwap, chainContractIds, assetContractIds, assetDecimals, isTestnet } from './chunk-NX4K76K7.mjs';
4
- export { Assets, ChainflipNetworks, Chains, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds } from './chunk-NX4K76K7.mjs';
1
+ import { getEnvironment, getVaultManagerContractAddress, approve, getTokenContractAddress, checkAllowance, Vault__factory, extractOverrides } from './chunk-JIK6G4FY.mjs';
2
+ import { numericString, ethereumAddress, dotAddress, btcAddress, ccmMetadataSchema } from './chunk-2HHAR3ZI.mjs';
3
+ import { __name, z, Chains, Assets, ChainflipNetworks, __publicField, assert, isTokenCall, isTokenSwap, chainContractIds, assetContractIds, assetDecimals, isTestnet } from './chunk-6B4B7WKD.mjs';
4
+ export { Assets, ChainflipNetworks, Chains, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds } from './chunk-6B4B7WKD.mjs';
5
5
  import { decodeAddress } from '@polkadot/util-crypto';
6
6
  import axios from 'axios';
7
7
 
8
- // ../../node_modules/.pnpm/@trpc+server@10.43.0/node_modules/@trpc/server/dist/observable-ade1bad8.mjs
8
+ // ../../node_modules/.pnpm/@trpc+server@10.43.1/node_modules/@trpc/server/dist/observable-ade1bad8.mjs
9
9
  function identity(x) {
10
10
  return x;
11
11
  }
@@ -84,7 +84,7 @@ function observable(subscribe) {
84
84
  }
85
85
  __name(observable, "observable");
86
86
 
87
- // ../../node_modules/.pnpm/@trpc+server@10.43.0/node_modules/@trpc/server/dist/observable/index.mjs
87
+ // ../../node_modules/.pnpm/@trpc+server@10.43.1/node_modules/@trpc/server/dist/observable/index.mjs
88
88
  function share(_opts) {
89
89
  return (originalObserver) => {
90
90
  let refCount = 0;
@@ -189,7 +189,7 @@ function observableToPromise(observable2) {
189
189
  }
190
190
  __name(observableToPromise, "observableToPromise");
191
191
 
192
- // ../../node_modules/.pnpm/@trpc+client@10.43.0_@trpc+server@10.43.0/node_modules/@trpc/client/dist/splitLink-4c75f7be.mjs
192
+ // ../../node_modules/.pnpm/@trpc+client@10.43.1_@trpc+server@10.43.1/node_modules/@trpc/client/dist/splitLink-4c75f7be.mjs
193
193
  function createChain(opts) {
194
194
  return observable((observer) => {
195
195
  function execute(index = 0, op = opts.op) {
@@ -213,7 +213,7 @@ function createChain(opts) {
213
213
  }
214
214
  __name(createChain, "createChain");
215
215
 
216
- // ../../node_modules/.pnpm/@trpc+client@10.43.0_@trpc+server@10.43.0/node_modules/@trpc/client/dist/transformResult-ace864b8.mjs
216
+ // ../../node_modules/.pnpm/@trpc+client@10.43.1_@trpc+server@10.43.1/node_modules/@trpc/client/dist/transformResult-ace864b8.mjs
217
217
  function isObject(value) {
218
218
  return !!value && !Array.isArray(value) && typeof value === "object";
219
219
  }
@@ -266,7 +266,7 @@ function transformResult(response, runtime) {
266
266
  }
267
267
  __name(transformResult, "transformResult");
268
268
 
269
- // ../../node_modules/.pnpm/@trpc+client@10.43.0_@trpc+server@10.43.0/node_modules/@trpc/client/dist/TRPCClientError-0de4d231.mjs
269
+ // ../../node_modules/.pnpm/@trpc+client@10.43.1_@trpc+server@10.43.1/node_modules/@trpc/client/dist/TRPCClientError-0de4d231.mjs
270
270
  function isTRPCClientError(cause) {
271
271
  return cause instanceof TRPCClientError || /**
272
272
  * @deprecated
@@ -324,7 +324,7 @@ var _TRPCClientError = class _TRPCClientError extends Error {
324
324
  __name(_TRPCClientError, "TRPCClientError");
325
325
  var TRPCClientError = _TRPCClientError;
326
326
 
327
- // ../../node_modules/.pnpm/@trpc+server@10.43.0/node_modules/@trpc/server/dist/codes-c924c3db.mjs
327
+ // ../../node_modules/.pnpm/@trpc+server@10.43.1/node_modules/@trpc/server/dist/codes-c924c3db.mjs
328
328
  function invert(obj) {
329
329
  const newObj = /* @__PURE__ */ Object.create(null);
330
330
  for (const key in obj) {
@@ -362,7 +362,7 @@ var TRPC_ERROR_CODES_BY_KEY = {
362
362
  };
363
363
  invert(TRPC_ERROR_CODES_BY_KEY);
364
364
 
365
- // ../../node_modules/.pnpm/@trpc+server@10.43.0/node_modules/@trpc/server/dist/index-f91d720c.mjs
365
+ // ../../node_modules/.pnpm/@trpc+server@10.43.1/node_modules/@trpc/server/dist/index-f91d720c.mjs
366
366
  invert(TRPC_ERROR_CODES_BY_KEY);
367
367
  var noop = /* @__PURE__ */ __name(() => {
368
368
  }, "noop");
@@ -400,7 +400,7 @@ var createFlatProxy = /* @__PURE__ */ __name((callback) => {
400
400
  });
401
401
  }, "createFlatProxy");
402
402
 
403
- // ../../node_modules/.pnpm/@trpc+client@10.43.0_@trpc+server@10.43.0/node_modules/@trpc/client/dist/httpUtils-f58ceda1.mjs
403
+ // ../../node_modules/.pnpm/@trpc+client@10.43.1_@trpc+server@10.43.1/node_modules/@trpc/client/dist/httpUtils-f58ceda1.mjs
404
404
  var isFunction = /* @__PURE__ */ __name((fn) => typeof fn === "function", "isFunction");
405
405
  function getFetch(customFetchImpl) {
406
406
  if (customFetchImpl) {
@@ -544,7 +544,7 @@ function httpRequest(opts) {
544
544
  }
545
545
  __name(httpRequest, "httpRequest");
546
546
 
547
- // ../../node_modules/.pnpm/@trpc+client@10.43.0_@trpc+server@10.43.0/node_modules/@trpc/client/dist/httpBatchLink-204206a5.mjs
547
+ // ../../node_modules/.pnpm/@trpc+client@10.43.1_@trpc+server@10.43.1/node_modules/@trpc/client/dist/httpBatchLink-204206a5.mjs
548
548
  var throwFatalError = /* @__PURE__ */ __name(() => {
549
549
  throw new Error("Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new");
550
550
  }, "throwFatalError");
@@ -774,7 +774,7 @@ var batchRequester = /* @__PURE__ */ __name((requesterOpts) => {
774
774
  }, "batchRequester");
775
775
  var httpBatchLink = createHTTPBatchLink(batchRequester);
776
776
 
777
- // ../../node_modules/.pnpm/@trpc+client@10.43.0_@trpc+server@10.43.0/node_modules/@trpc/client/dist/links/httpLink.mjs
777
+ // ../../node_modules/.pnpm/@trpc+client@10.43.1_@trpc+server@10.43.1/node_modules/@trpc/client/dist/links/httpLink.mjs
778
778
  function httpLinkFactory(factoryOpts) {
779
779
  return (opts) => {
780
780
  const resolvedOpts = resolveHTTPLinkOptions(opts);
@@ -826,7 +826,7 @@ function httpLinkFactory(factoryOpts) {
826
826
  }
827
827
  __name(httpLinkFactory, "httpLinkFactory");
828
828
 
829
- // ../../node_modules/.pnpm/@trpc+client@10.43.0_@trpc+server@10.43.0/node_modules/@trpc/client/dist/index.mjs
829
+ // ../../node_modules/.pnpm/@trpc+client@10.43.1_@trpc+server@10.43.1/node_modules/@trpc/client/dist/index.mjs
830
830
  var _TRPCUntypedClient = class _TRPCUntypedClient {
831
831
  $request({ type, input, path, context = {} }) {
832
832
  const chain$ = createChain({
@@ -2326,7 +2326,7 @@ var BACKEND_SERVICE_URLS = {
2326
2326
  };
2327
2327
 
2328
2328
  // src/swap/assets.ts
2329
- var eth$ = /* @__PURE__ */ __name((network) => ({
2329
+ var eth$ = /* @__PURE__ */ __name((network, env) => ({
2330
2330
  id: Assets.ETH,
2331
2331
  chain: Chains.Ethereum,
2332
2332
  contractAddress: void 0,
@@ -2334,10 +2334,10 @@ var eth$ = /* @__PURE__ */ __name((network) => ({
2334
2334
  name: "Ether",
2335
2335
  symbol: "ETH",
2336
2336
  isMainnet: !isTestnet(network),
2337
- minimumDepositAmount: getMinimumDepositAmount(network, Assets.ETH),
2338
- minimumSwapAmount: getMinimumSwapAmount(network, Assets.ETH)
2337
+ minimumDepositAmount: env.ingressEgress.minimumDepositAmounts.Ethereum.ETH.toString(),
2338
+ minimumSwapAmount: env.swapping.minimumSwapAmounts.Ethereum.ETH.toString()
2339
2339
  }), "eth$");
2340
- var usdc$ = /* @__PURE__ */ __name((network) => ({
2340
+ var usdc$ = /* @__PURE__ */ __name((network, env) => ({
2341
2341
  id: Assets.USDC,
2342
2342
  chain: Chains.Ethereum,
2343
2343
  contractAddress: getTokenContractAddress(Assets.USDC, network),
@@ -2345,10 +2345,10 @@ var usdc$ = /* @__PURE__ */ __name((network) => ({
2345
2345
  name: "USDC",
2346
2346
  symbol: "USDC",
2347
2347
  isMainnet: !isTestnet(network),
2348
- minimumDepositAmount: getMinimumDepositAmount(network, Assets.USDC),
2349
- minimumSwapAmount: getMinimumSwapAmount(network, Assets.USDC)
2348
+ minimumDepositAmount: env.ingressEgress.minimumDepositAmounts.Ethereum.USDC.toString(),
2349
+ minimumSwapAmount: env.swapping.minimumSwapAmounts.Ethereum.USDC.toString()
2350
2350
  }), "usdc$");
2351
- var flip$ = /* @__PURE__ */ __name((network) => ({
2351
+ var flip$ = /* @__PURE__ */ __name((network, env) => ({
2352
2352
  id: Assets.FLIP,
2353
2353
  chain: Chains.Ethereum,
2354
2354
  contractAddress: getTokenContractAddress(Assets.FLIP, network),
@@ -2356,10 +2356,10 @@ var flip$ = /* @__PURE__ */ __name((network) => ({
2356
2356
  name: "FLIP",
2357
2357
  symbol: "FLIP",
2358
2358
  isMainnet: !isTestnet(network),
2359
- minimumDepositAmount: getMinimumDepositAmount(network, Assets.FLIP),
2360
- minimumSwapAmount: getMinimumSwapAmount(network, Assets.FLIP)
2359
+ minimumDepositAmount: env.ingressEgress.minimumDepositAmounts.Ethereum.FLIP.toString(),
2360
+ minimumSwapAmount: env.swapping.minimumSwapAmounts.Ethereum.FLIP.toString()
2361
2361
  }), "flip$");
2362
- var dot$ = /* @__PURE__ */ __name((network) => ({
2362
+ var dot$ = /* @__PURE__ */ __name((network, env) => ({
2363
2363
  id: Assets.DOT,
2364
2364
  chain: Chains.Polkadot,
2365
2365
  contractAddress: void 0,
@@ -2367,10 +2367,10 @@ var dot$ = /* @__PURE__ */ __name((network) => ({
2367
2367
  name: "Polkadot",
2368
2368
  symbol: "DOT",
2369
2369
  isMainnet: !isTestnet(network),
2370
- minimumDepositAmount: getMinimumDepositAmount(network, Assets.DOT),
2371
- minimumSwapAmount: getMinimumSwapAmount(network, Assets.DOT)
2370
+ minimumDepositAmount: env.ingressEgress.minimumDepositAmounts.Polkadot.DOT.toString(),
2371
+ minimumSwapAmount: env.swapping.minimumSwapAmounts.Polkadot.DOT.toString()
2372
2372
  }), "dot$");
2373
- var btc$ = /* @__PURE__ */ __name((network) => ({
2373
+ var btc$ = /* @__PURE__ */ __name((network, env) => ({
2374
2374
  id: Assets.BTC,
2375
2375
  chain: Chains.Bitcoin,
2376
2376
  contractAddress: void 0,
@@ -2378,8 +2378,8 @@ var btc$ = /* @__PURE__ */ __name((network) => ({
2378
2378
  name: "Bitcoin",
2379
2379
  symbol: "BTC",
2380
2380
  isMainnet: !isTestnet(network),
2381
- minimumDepositAmount: getMinimumDepositAmount(network, Assets.BTC),
2382
- minimumSwapAmount: getMinimumSwapAmount(network, Assets.BTC)
2381
+ minimumDepositAmount: env.ingressEgress.minimumDepositAmounts.Bitcoin.BTC.toString(),
2382
+ minimumSwapAmount: env.swapping.minimumSwapAmounts.Bitcoin.BTC.toString()
2383
2383
  }), "btc$");
2384
2384
 
2385
2385
  // src/swap/chains.ts
@@ -2424,20 +2424,20 @@ var getPossibleDestinationChains = /* @__PURE__ */ __name(async (sourceChain, ne
2424
2424
  ];
2425
2425
  throw new Error("received unknown chain");
2426
2426
  }, "getPossibleDestinationChains");
2427
- var getAssets = /* @__PURE__ */ __name(async (chain, network) => {
2427
+ var getAssets = /* @__PURE__ */ __name(async (chain, network, env) => {
2428
2428
  if (chain === Chains.Ethereum)
2429
2429
  return [
2430
- eth$(network),
2431
- usdc$(network),
2432
- flip$(network)
2430
+ eth$(network, env),
2431
+ usdc$(network, env),
2432
+ flip$(network, env)
2433
2433
  ];
2434
2434
  if (chain === Chains.Polkadot)
2435
2435
  return [
2436
- dot$(network)
2436
+ dot$(network, env)
2437
2437
  ];
2438
2438
  if (chain === Chains.Bitcoin)
2439
2439
  return [
2440
- btc$(network)
2440
+ btc$(network, env)
2441
2441
  ];
2442
2442
  throw new Error("received unexpected chain");
2443
2443
  }, "getAssets");
@@ -2480,6 +2480,8 @@ var _SwapSDK = class _SwapSDK {
2480
2480
  __publicField(this, "signer");
2481
2481
  __publicField(this, "trpc");
2482
2482
  __publicField(this, "brokerConfig");
2483
+ __publicField(this, "stateChainEnvironment");
2484
+ __publicField(this, "rpcConfig");
2483
2485
  this.network = options.network ?? ChainflipNetworks.perseverance;
2484
2486
  this.baseUrl = options.backendUrl ?? BACKEND_SERVICE_URLS[this.network];
2485
2487
  this.signer = options.signer;
@@ -2492,6 +2494,11 @@ var _SwapSDK = class _SwapSDK {
2492
2494
  })
2493
2495
  ]
2494
2496
  });
2497
+ this.rpcConfig = options.rpcUrl ? {
2498
+ rpcUrl: options.rpcUrl
2499
+ } : {
2500
+ network: this.network
2501
+ };
2495
2502
  }
2496
2503
  getChains(sourceChain) {
2497
2504
  if (sourceChain !== void 0) {
@@ -2499,8 +2506,13 @@ var _SwapSDK = class _SwapSDK {
2499
2506
  }
2500
2507
  return ApiService_default.getChains(this.network);
2501
2508
  }
2502
- getAssets(chain) {
2503
- return ApiService_default.getAssets(chain, this.network);
2509
+ async getStateChainEnvironment() {
2510
+ this.stateChainEnvironment ?? (this.stateChainEnvironment = await getEnvironment(this.rpcConfig));
2511
+ return this.stateChainEnvironment;
2512
+ }
2513
+ async getAssets(chain) {
2514
+ const env = await this.getStateChainEnvironment();
2515
+ return ApiService_default.getAssets(chain, this.network, env);
2504
2516
  }
2505
2517
  getQuote(quoteRequest, options = {}) {
2506
2518
  return ApiService_default.getQuote(this.baseUrl, quoteRequest, options);
@@ -2508,7 +2520,7 @@ var _SwapSDK = class _SwapSDK {
2508
2520
  async requestDepositAddress(depositAddressRequest) {
2509
2521
  let response;
2510
2522
  if (this.brokerConfig !== void 0) {
2511
- const { requestSwapDepositAddress } = await import('./broker-2SDVPKIU.mjs');
2523
+ const { requestSwapDepositAddress } = await import('./broker-TKLJ3YAQ.mjs');
2512
2524
  const result = await requestSwapDepositAddress(depositAddressRequest, this.brokerConfig);
2513
2525
  response = {
2514
2526
  id: `${result.issuedBlock}-${depositAddressRequest.srcChain}-${result.channelId}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/sdk",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "description": "",
5
5
  "exports": {
6
6
  "./swap": {
@@ -44,7 +44,7 @@
44
44
  "@polkadot/util": "^12.5.1",
45
45
  "@polkadot/util-crypto": "^12.5.1",
46
46
  "axios": "^1.6.0",
47
- "ethers": "6.8.0"
47
+ "ethers": "6.8.1"
48
48
  },
49
49
  "devDependencies": {
50
50
  "tsup": "^7.2.0"
@@ -1,91 +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) => {
5
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
- return value;
7
- };
8
-
9
- // ../shared/src/enums.ts
10
- var arrayToMap = /* @__PURE__ */ __name((array) => Object.fromEntries(array.map((key) => [
11
- key,
12
- key
13
- ])), "arrayToMap");
14
- var Chains = arrayToMap([
15
- "Bitcoin",
16
- "Ethereum",
17
- "Polkadot"
18
- ]);
19
- var Assets = arrayToMap([
20
- "FLIP",
21
- "USDC",
22
- "DOT",
23
- "ETH",
24
- "BTC"
25
- ]);
26
- var ChainflipNetworks = arrayToMap([
27
- "backspin",
28
- "sisyphos",
29
- "perseverance",
30
- "mainnet"
31
- ]);
32
- var isTestnet = /* @__PURE__ */ __name((network) => network !== ChainflipNetworks.mainnet, "isTestnet");
33
- var assetChains = {
34
- [Assets.ETH]: Chains.Ethereum,
35
- [Assets.FLIP]: Chains.Ethereum,
36
- [Assets.USDC]: Chains.Ethereum,
37
- [Assets.BTC]: Chains.Bitcoin,
38
- [Assets.DOT]: Chains.Polkadot
39
- };
40
- var assetDecimals = {
41
- [Assets.DOT]: 10,
42
- [Assets.ETH]: 18,
43
- [Assets.FLIP]: 18,
44
- [Assets.USDC]: 6,
45
- [Assets.BTC]: 8
46
- };
47
- var assetContractIds = {
48
- // 0 is reservered for particular cross chain messaging scenarios where we want to pass
49
- // through a message without making a swap.
50
- [Assets.ETH]: 1,
51
- [Assets.FLIP]: 2,
52
- [Assets.USDC]: 3,
53
- [Assets.DOT]: 4,
54
- [Assets.BTC]: 5
55
- };
56
- var chainAssets = {
57
- [Chains.Ethereum]: [
58
- Assets.ETH,
59
- Assets.USDC,
60
- Assets.FLIP
61
- ],
62
- [Chains.Bitcoin]: [
63
- Assets.BTC
64
- ],
65
- [Chains.Polkadot]: [
66
- Assets.DOT
67
- ]
68
- };
69
- var chainContractIds = {
70
- [Chains.Ethereum]: 1,
71
- [Chains.Polkadot]: 2,
72
- [Chains.Bitcoin]: 3
73
- };
74
-
75
- // ../shared/src/guards.ts
76
- var isString = /* @__PURE__ */ __name((value) => typeof value === "string", "isString");
77
- var isNotNullish = /* @__PURE__ */ __name((value) => value !== null && value !== void 0, "isNotNullish");
78
- function assert(condition, message) {
79
- if (condition)
80
- return;
81
- const error = new Error(message);
82
- if (error.stack) {
83
- error.stack = error.stack.replace(/\n.+/, "\n");
84
- }
85
- throw error;
86
- }
87
- __name(assert, "assert");
88
- var isTokenSwap = /* @__PURE__ */ __name((params) => params.srcAsset !== Assets.ETH, "isTokenSwap");
89
- var isTokenCall = /* @__PURE__ */ __name((params) => params.srcAsset !== Assets.ETH, "isTokenCall");
90
-
91
- export { Assets, ChainflipNetworks, Chains, __name, __publicField, assert, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds, isNotNullish, isString, isTestnet, isTokenCall, isTokenSwap };