@chainflip/sdk 0.2.21 → 1.1.0-rc.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-N4SMMWKH.mjs';
2
- import { z, isNotNullish, __name, Assets } from './chunk-B2TZXL7C.mjs';
1
+ import { chainflipAssetAndChain, numericString, hexString, btcAddress, ccmMetadataSchema, hexStringFromNumber, dotAddress, unsignedInteger } from './chunk-LEMOY2A2.mjs';
2
+ import { z, isNotNullish, __name, Assets } from './chunk-O4RYZWBW.mjs';
3
3
  import { u8aToHex } from '@polkadot/util';
4
4
  import { decodeAddress } from '@polkadot/util-crypto';
5
5
  import axios from 'axios';
@@ -1,4 +1,4 @@
1
- import { z, ChainflipNetworks, __name, __publicField, Assets } from './chunk-B2TZXL7C.mjs';
1
+ import { z, ChainflipNetworks, __name, __publicField, Assets } from './chunk-O4RYZWBW.mjs';
2
2
  import axios from 'axios';
3
3
  import { Interface, Contract } from 'ethers';
4
4
 
@@ -56,8 +56,10 @@ var chainAssetMap = /* @__PURE__ */ __name((parser) => z.object({
56
56
  })
57
57
  }), "chainAssetMap");
58
58
  var chainAssetNumberMap = chainAssetMap(numberOrHex);
59
+ var chainAssetNumberNullableMap = chainAssetMap(numberOrHex.nullable());
59
60
  var swappingEnvironment = z.object({
60
- minimum_swap_amounts: chainAssetNumberMap
61
+ minimum_swap_amounts: chainAssetNumberMap,
62
+ maximum_swap_amounts: chainAssetNumberNullableMap
61
63
  });
62
64
  createRequest("cf_swapping_environment", swappingEnvironment);
63
65
  var ingressEgressEnvironment = z.object({
@@ -91,11 +93,19 @@ var rpcAsset = z.union([
91
93
  asset: z.literal("USDC")
92
94
  })
93
95
  ]);
94
- var poolInfo = z.object({
96
+ var poolInfo = z.intersection(z.object({
95
97
  limit_order_fee_hundredth_pips: z.number(),
96
- range_order_fee_hundredth_pips: z.number(),
97
- pair_asset: rpcAsset
98
- });
98
+ range_order_fee_hundredth_pips: z.number()
99
+ }), z.union([
100
+ z.object({
101
+ quote_asset: rpcAsset
102
+ }),
103
+ z.object({
104
+ pair_asset: rpcAsset
105
+ }).transform(({ pair_asset }) => ({
106
+ quote_asset: pair_asset
107
+ }))
108
+ ]));
99
109
  var feesInfo = z.object({
100
110
  Bitcoin: z.object({
101
111
  BTC: poolInfo
@@ -1,4 +1,4 @@
1
- import { z, isString, Chains, Assets, assetChains, ChainflipNetworks, __name, assert } from './chunk-B2TZXL7C.mjs';
1
+ import { z, isString, Chains, Assets, assetChains, ChainflipNetworks, __name, assert } from './chunk-O4RYZWBW.mjs';
2
2
  import { hexToU8a } from '@polkadot/util';
3
3
  import { encodeAddress, decodeAddress, base58Decode } from '@polkadot/util-crypto';
4
4
  import * as ethers from 'ethers';
@@ -71,6 +71,19 @@ var chainContractIds = {
71
71
  [Chains.Polkadot]: 2,
72
72
  [Chains.Bitcoin]: 3
73
73
  };
74
+ function assertAsset(asset) {
75
+ if (!(asset in Assets))
76
+ throw new Error("invalid asset");
77
+ }
78
+ __name(assertAsset, "assertAsset");
79
+ function assertIsValidAssetAndChain(assetAndChain) {
80
+ const { asset, chain } = assetAndChain;
81
+ assertAsset(asset);
82
+ if (chain !== assetChains[asset]) {
83
+ throw new Error("invalid asset and chain combination");
84
+ }
85
+ }
86
+ __name(assertIsValidAssetAndChain, "assertIsValidAssetAndChain");
74
87
 
75
88
  // ../shared/src/guards.ts
76
89
  var isString = /* @__PURE__ */ __name((value) => typeof value === "string", "isString");
@@ -3917,4 +3930,4 @@ var z = /* @__PURE__ */ Object.freeze({
3917
3930
  ZodError
3918
3931
  });
3919
3932
 
3920
- export { Assets, ChainflipNetworks, Chains, __name, __publicField, assert, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds, isNotNullish, isString, isTestnet, isTokenCall, isTokenSwap, z };
3933
+ export { Assets, ChainflipNetworks, Chains, __name, __publicField, assert, assertIsValidAssetAndChain, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds, isNotNullish, isString, isTestnet, isTokenCall, isTokenSwap, z };
package/dist/funding.js CHANGED
@@ -4782,8 +4782,10 @@ var chainAssetMap = /* @__PURE__ */ __name((parser) => z.object({
4782
4782
  })
4783
4783
  }), "chainAssetMap");
4784
4784
  var chainAssetNumberMap = chainAssetMap(numberOrHex);
4785
+ var chainAssetNumberNullableMap = chainAssetMap(numberOrHex.nullable());
4785
4786
  var swappingEnvironment = z.object({
4786
- minimum_swap_amounts: chainAssetNumberMap
4787
+ minimum_swap_amounts: chainAssetNumberMap,
4788
+ maximum_swap_amounts: chainAssetNumberNullableMap
4787
4789
  });
4788
4790
  createRequest("cf_swapping_environment", swappingEnvironment);
4789
4791
  var ingressEgressEnvironment = z.object({
@@ -4817,11 +4819,19 @@ var rpcAsset = z.union([
4817
4819
  asset: z.literal("USDC")
4818
4820
  })
4819
4821
  ]);
4820
- var poolInfo = z.object({
4822
+ var poolInfo = z.intersection(z.object({
4821
4823
  limit_order_fee_hundredth_pips: z.number(),
4822
- range_order_fee_hundredth_pips: z.number(),
4823
- pair_asset: rpcAsset
4824
- });
4824
+ range_order_fee_hundredth_pips: z.number()
4825
+ }), z.union([
4826
+ z.object({
4827
+ quote_asset: rpcAsset
4828
+ }),
4829
+ z.object({
4830
+ pair_asset: rpcAsset
4831
+ }).transform(({ pair_asset }) => ({
4832
+ quote_asset: pair_asset
4833
+ }))
4834
+ ]));
4825
4835
  var feesInfo = z.object({
4826
4836
  Bitcoin: z.object({
4827
4837
  BTC: poolInfo
package/dist/funding.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { getFlipBalance, getFundingEnvironment, getStateChainGatewayContractAddress, approve, getTokenContractAddress, checkAllowance, extractOverrides, StateChainGateway__factory } from './chunk-TCRJUCSA.mjs';
2
- import { __name, __publicField, ChainflipNetworks, Assets, assert } from './chunk-B2TZXL7C.mjs';
1
+ import { getFlipBalance, getFundingEnvironment, getStateChainGatewayContractAddress, approve, getTokenContractAddress, checkAllowance, extractOverrides, StateChainGateway__factory } from './chunk-LBKEYET5.mjs';
2
+ import { __name, __publicField, ChainflipNetworks, Assets, assert } from './chunk-O4RYZWBW.mjs';
3
3
 
4
4
  // ../shared/src/stateChainGateway/utils.ts
5
5
  var getStateChainGateway = /* @__PURE__ */ __name((networkOpts) => {
package/dist/swap.d.mts CHANGED
@@ -394,6 +394,7 @@ type AssetData = {
394
394
  isMainnet: boolean;
395
395
  minimumDepositAmount: string;
396
396
  minimumSwapAmount: string;
397
+ maximumSwapAmount: string | null;
397
398
  };
398
399
  }[keyof typeof chainAssets];
399
400
  interface ChainsAndAssets {
@@ -548,6 +549,7 @@ declare class SwapSDK {
548
549
  getStatus(swapStatusRequest: SwapStatusRequest, options?: RequestOptions): Promise<SwapStatusResponse>;
549
550
  executeSwap(params: ExecuteSwapParams, txOpts?: TransactionOptions): Promise<TransactionHash>;
550
551
  approveVault(params: Pick<TokenSwapParams, 'srcAsset' | 'amount'>, txOpts?: TransactionOptions): Promise<TransactionHash | null>;
552
+ private validateSwapAmount;
551
553
  }
552
554
 
553
555
  export { Asset, type AssetData, Chain, type ChainData, ChainflipNetwork, type DepositAddressRequest, type DepositAddressResponse, type QuoteRequest, type QuoteResponse, SwapSDK, type SwapSDKOptions, type SwapStatusRequest, type SwapStatusResponse, chainAssets };
package/dist/swap.d.ts CHANGED
@@ -394,6 +394,7 @@ type AssetData = {
394
394
  isMainnet: boolean;
395
395
  minimumDepositAmount: string;
396
396
  minimumSwapAmount: string;
397
+ maximumSwapAmount: string | null;
397
398
  };
398
399
  }[keyof typeof chainAssets];
399
400
  interface ChainsAndAssets {
@@ -548,6 +549,7 @@ declare class SwapSDK {
548
549
  getStatus(swapStatusRequest: SwapStatusRequest, options?: RequestOptions): Promise<SwapStatusResponse>;
549
550
  executeSwap(params: ExecuteSwapParams, txOpts?: TransactionOptions): Promise<TransactionHash>;
550
551
  approveVault(params: Pick<TokenSwapParams, 'srcAsset' | 'amount'>, txOpts?: TransactionOptions): Promise<TransactionHash | null>;
552
+ private validateSwapAmount;
551
553
  }
552
554
 
553
555
  export { Asset, type AssetData, Chain, type ChainData, ChainflipNetwork, type DepositAddressRequest, type DepositAddressResponse, type QuoteRequest, type QuoteResponse, SwapSDK, type SwapSDKOptions, type SwapStatusRequest, type SwapStatusResponse, chainAssets };
package/dist/swap.js CHANGED
@@ -45,6 +45,17 @@ var __publicField = (obj, key, value) => {
45
45
  };
46
46
 
47
47
  // ../shared/src/enums.ts
48
+ function assertAsset(asset) {
49
+ if (!(asset in exports.Assets))
50
+ throw new Error("invalid asset");
51
+ }
52
+ function assertIsValidAssetAndChain(assetAndChain) {
53
+ const { asset, chain } = assetAndChain;
54
+ assertAsset(asset);
55
+ if (chain !== exports.assetChains[asset]) {
56
+ throw new Error("invalid asset and chain combination");
57
+ }
58
+ }
48
59
  var arrayToMap; exports.Chains = void 0; exports.Assets = void 0; exports.ChainflipNetworks = void 0; var isTestnet; exports.assetChains = void 0; exports.assetDecimals = void 0; exports.assetContractIds = void 0; exports.chainAssets = void 0; exports.chainContractIds = void 0;
49
60
  var init_enums = __esm({
50
61
  "../shared/src/enums.ts"() {
@@ -112,6 +123,8 @@ var init_enums = __esm({
112
123
  [exports.Chains.Polkadot]: 2,
113
124
  [exports.Chains.Bitcoin]: 3
114
125
  };
126
+ __name(assertAsset, "assertAsset");
127
+ __name(assertIsValidAssetAndChain, "assertIsValidAssetAndChain");
115
128
  }
116
129
  });
117
130
 
@@ -6708,8 +6721,10 @@ var chainAssetMap = /* @__PURE__ */ __name((parser) => z.object({
6708
6721
  })
6709
6722
  }), "chainAssetMap");
6710
6723
  var chainAssetNumberMap = chainAssetMap(numberOrHex);
6724
+ var chainAssetNumberNullableMap = chainAssetMap(numberOrHex.nullable());
6711
6725
  var swappingEnvironment = z.object({
6712
- minimum_swap_amounts: chainAssetNumberMap
6726
+ minimum_swap_amounts: chainAssetNumberMap,
6727
+ maximum_swap_amounts: chainAssetNumberNullableMap
6713
6728
  });
6714
6729
  createRequest("cf_swapping_environment", swappingEnvironment);
6715
6730
  var ingressEgressEnvironment = z.object({
@@ -6743,11 +6758,19 @@ var rpcAsset = z.union([
6743
6758
  asset: z.literal("USDC")
6744
6759
  })
6745
6760
  ]);
6746
- var poolInfo = z.object({
6761
+ var poolInfo = z.intersection(z.object({
6747
6762
  limit_order_fee_hundredth_pips: z.number(),
6748
- range_order_fee_hundredth_pips: z.number(),
6749
- pair_asset: rpcAsset
6750
- });
6763
+ range_order_fee_hundredth_pips: z.number()
6764
+ }), z.union([
6765
+ z.object({
6766
+ quote_asset: rpcAsset
6767
+ }),
6768
+ z.object({
6769
+ pair_asset: rpcAsset
6770
+ }).transform(({ pair_asset }) => ({
6771
+ quote_asset: pair_asset
6772
+ }))
6773
+ ]));
6751
6774
  var feesInfo = z.object({
6752
6775
  Bitcoin: z.object({
6753
6776
  BTC: poolInfo
@@ -6771,6 +6794,33 @@ var getEnvironment = createRequest("cf_environment", z.object({
6771
6794
  pools: poolsEnvironment
6772
6795
  }));
6773
6796
 
6797
+ // ../shared/src/rpc/utils.ts
6798
+ init_enums();
6799
+ var readAssetValue = /* @__PURE__ */ __name((minimums, asset) => {
6800
+ const chainMinimums = minimums[asset.chain];
6801
+ return chainMinimums[asset.asset];
6802
+ }, "readAssetValue");
6803
+ var validateSwapAmount = /* @__PURE__ */ __name((swapEnv, asset, amount) => {
6804
+ assertIsValidAssetAndChain(asset);
6805
+ const minAmount = readAssetValue(swapEnv.minimumSwapAmounts, asset);
6806
+ if (amount < minAmount) {
6807
+ return {
6808
+ success: false,
6809
+ reason: `expected amount is below minimum swap amount (${minAmount})`
6810
+ };
6811
+ }
6812
+ const maxAmount = readAssetValue(swapEnv.maximumSwapAmounts, asset);
6813
+ if (maxAmount != null && amount > maxAmount) {
6814
+ return {
6815
+ success: false,
6816
+ reason: `expected amount is above maximum swap amount (${maxAmount})`
6817
+ };
6818
+ }
6819
+ return {
6820
+ success: true
6821
+ };
6822
+ }, "validateSwapAmount");
6823
+
6774
6824
  // ../shared/src/vault/schemas.ts
6775
6825
  init_lib();
6776
6826
  init_enums();
@@ -8312,9 +8362,11 @@ var eth$ = /* @__PURE__ */ __name((network, env) => ({
8312
8362
  decimals: exports.assetDecimals[exports.Assets.ETH],
8313
8363
  name: "Ether",
8314
8364
  symbol: "ETH",
8365
+ chainflipId: "ETH",
8315
8366
  isMainnet: !isTestnet(network),
8316
8367
  minimumDepositAmount: env.ingressEgress.minimumDepositAmounts.Ethereum.ETH.toString(),
8317
- minimumSwapAmount: env.swapping.minimumSwapAmounts.Ethereum.ETH.toString()
8368
+ minimumSwapAmount: env.swapping.minimumSwapAmounts.Ethereum.ETH.toString(),
8369
+ maximumSwapAmount: env.swapping.maximumSwapAmounts.Ethereum.ETH?.toString() ?? null
8318
8370
  }), "eth$");
8319
8371
  var usdc$ = /* @__PURE__ */ __name((network, env) => ({
8320
8372
  id: exports.Assets.USDC,
@@ -8323,9 +8375,11 @@ var usdc$ = /* @__PURE__ */ __name((network, env) => ({
8323
8375
  decimals: exports.assetDecimals[exports.Assets.USDC],
8324
8376
  name: "USDC",
8325
8377
  symbol: "USDC",
8378
+ chainflipId: "USDC",
8326
8379
  isMainnet: !isTestnet(network),
8327
8380
  minimumDepositAmount: env.ingressEgress.minimumDepositAmounts.Ethereum.USDC.toString(),
8328
- minimumSwapAmount: env.swapping.minimumSwapAmounts.Ethereum.USDC.toString()
8381
+ minimumSwapAmount: env.swapping.minimumSwapAmounts.Ethereum.USDC.toString(),
8382
+ maximumSwapAmount: env.swapping.maximumSwapAmounts.Ethereum.USDC?.toString() ?? null
8329
8383
  }), "usdc$");
8330
8384
  var flip$ = /* @__PURE__ */ __name((network, env) => ({
8331
8385
  id: exports.Assets.FLIP,
@@ -8334,9 +8388,11 @@ var flip$ = /* @__PURE__ */ __name((network, env) => ({
8334
8388
  decimals: exports.assetDecimals[exports.Assets.FLIP],
8335
8389
  name: "FLIP",
8336
8390
  symbol: "FLIP",
8391
+ chainflipId: "FLIP",
8337
8392
  isMainnet: !isTestnet(network),
8338
8393
  minimumDepositAmount: env.ingressEgress.minimumDepositAmounts.Ethereum.FLIP.toString(),
8339
- minimumSwapAmount: env.swapping.minimumSwapAmounts.Ethereum.FLIP.toString()
8394
+ minimumSwapAmount: env.swapping.minimumSwapAmounts.Ethereum.FLIP.toString(),
8395
+ maximumSwapAmount: env.swapping.maximumSwapAmounts.Ethereum.FLIP?.toString() ?? null
8340
8396
  }), "flip$");
8341
8397
  var dot$ = /* @__PURE__ */ __name((network, env) => ({
8342
8398
  id: exports.Assets.DOT,
@@ -8345,9 +8401,11 @@ var dot$ = /* @__PURE__ */ __name((network, env) => ({
8345
8401
  decimals: exports.assetDecimals[exports.Assets.DOT],
8346
8402
  name: "Polkadot",
8347
8403
  symbol: "DOT",
8404
+ chainflipId: "DOT",
8348
8405
  isMainnet: !isTestnet(network),
8349
8406
  minimumDepositAmount: env.ingressEgress.minimumDepositAmounts.Polkadot.DOT.toString(),
8350
- minimumSwapAmount: env.swapping.minimumSwapAmounts.Polkadot.DOT.toString()
8407
+ minimumSwapAmount: env.swapping.minimumSwapAmounts.Polkadot.DOT.toString(),
8408
+ maximumSwapAmount: env.swapping.maximumSwapAmounts.Polkadot.DOT?.toString() ?? null
8351
8409
  }), "dot$");
8352
8410
  var btc$ = /* @__PURE__ */ __name((network, env) => ({
8353
8411
  id: exports.Assets.BTC,
@@ -8356,9 +8414,11 @@ var btc$ = /* @__PURE__ */ __name((network, env) => ({
8356
8414
  decimals: exports.assetDecimals[exports.Assets.BTC],
8357
8415
  name: "Bitcoin",
8358
8416
  symbol: "BTC",
8417
+ chainflipId: "BTC",
8359
8418
  isMainnet: !isTestnet(network),
8360
8419
  minimumDepositAmount: env.ingressEgress.minimumDepositAmounts.Bitcoin.BTC.toString(),
8361
- minimumSwapAmount: env.swapping.minimumSwapAmounts.Bitcoin.BTC.toString()
8420
+ minimumSwapAmount: env.swapping.minimumSwapAmounts.Bitcoin.BTC.toString(),
8421
+ maximumSwapAmount: env.swapping.maximumSwapAmounts.Bitcoin.BTC?.toString() ?? null
8362
8422
  }), "btc$");
8363
8423
 
8364
8424
  // src/swap/chains.ts
@@ -8498,6 +8558,11 @@ var _SwapSDK = class _SwapSDK {
8498
8558
  return ApiService_default.getQuote(this.baseUrl, quoteRequest, options);
8499
8559
  }
8500
8560
  async requestDepositAddress(depositAddressRequest) {
8561
+ const { srcChain, srcAsset, amount } = depositAddressRequest;
8562
+ await this.validateSwapAmount({
8563
+ chain: srcChain,
8564
+ asset: srcAsset
8565
+ }, BigInt(amount));
8501
8566
  let response;
8502
8567
  if (this.brokerConfig !== void 0) {
8503
8568
  const { requestSwapDepositAddress: requestSwapDepositAddress2 } = await Promise.resolve().then(() => (init_broker(), broker_exports));
@@ -8522,6 +8587,11 @@ var _SwapSDK = class _SwapSDK {
8522
8587
  return ApiService_default.getStatus(this.baseUrl, swapStatusRequest, options);
8523
8588
  }
8524
8589
  async executeSwap(params, txOpts = {}) {
8590
+ const { srcChain, srcAsset, amount } = params;
8591
+ await this.validateSwapAmount({
8592
+ chain: srcChain,
8593
+ asset: srcAsset
8594
+ }, BigInt(amount));
8525
8595
  assert(this.signer, "No signer provided");
8526
8596
  const receipt = await executeSwap_default(params, {
8527
8597
  network: this.network,
@@ -8539,6 +8609,12 @@ var _SwapSDK = class _SwapSDK {
8539
8609
  }, txOpts);
8540
8610
  return receipt ? receipt.hash : null;
8541
8611
  }
8612
+ async validateSwapAmount(asset, amount) {
8613
+ const stateChainEnv = await this.getStateChainEnvironment();
8614
+ const result = validateSwapAmount(stateChainEnv.swapping, asset, amount);
8615
+ if (!result.success)
8616
+ throw new Error(result.reason);
8617
+ }
8542
8618
  };
8543
8619
  __name(_SwapSDK, "SwapSDK");
8544
8620
  var SwapSDK = _SwapSDK;
package/dist/swap.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { getEnvironment, getVaultManagerContractAddress, approve, getTokenContractAddress, checkAllowance, Vault__factory, extractOverrides } from './chunk-TCRJUCSA.mjs';
2
- import { numericString, ethereumAddress, dotAddress, btcAddress, ccmMetadataSchema } from './chunk-N4SMMWKH.mjs';
3
- import { __name, z, Chains, Assets, ChainflipNetworks, __publicField, assert, isTokenCall, isTokenSwap, chainContractIds, assetContractIds, assetDecimals, isTestnet } from './chunk-B2TZXL7C.mjs';
4
- export { Assets, ChainflipNetworks, Chains, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds } from './chunk-B2TZXL7C.mjs';
1
+ import { getEnvironment, getVaultManagerContractAddress, approve, getTokenContractAddress, checkAllowance, Vault__factory, extractOverrides } from './chunk-LBKEYET5.mjs';
2
+ import { numericString, ethereumAddress, dotAddress, btcAddress, ccmMetadataSchema } from './chunk-LEMOY2A2.mjs';
3
+ import { __name, z, Chains, Assets, ChainflipNetworks, __publicField, assert, assertIsValidAssetAndChain, isTokenCall, isTokenSwap, chainContractIds, assetContractIds, assetDecimals, isTestnet } from './chunk-O4RYZWBW.mjs';
4
+ export { Assets, ChainflipNetworks, Chains, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds } from './chunk-O4RYZWBW.mjs';
5
5
  import { decodeAddress } from '@polkadot/util-crypto';
6
6
  import axios from 'axios';
7
7
 
@@ -2173,6 +2173,32 @@ SuperJSON.registerClass;
2173
2173
  SuperJSON.registerCustom;
2174
2174
  SuperJSON.registerSymbol;
2175
2175
  SuperJSON.allowErrorProps;
2176
+
2177
+ // ../shared/src/rpc/utils.ts
2178
+ var readAssetValue = /* @__PURE__ */ __name((minimums, asset) => {
2179
+ const chainMinimums = minimums[asset.chain];
2180
+ return chainMinimums[asset.asset];
2181
+ }, "readAssetValue");
2182
+ var validateSwapAmount = /* @__PURE__ */ __name((swapEnv, asset, amount) => {
2183
+ assertIsValidAssetAndChain(asset);
2184
+ const minAmount = readAssetValue(swapEnv.minimumSwapAmounts, asset);
2185
+ if (amount < minAmount) {
2186
+ return {
2187
+ success: false,
2188
+ reason: `expected amount is below minimum swap amount (${minAmount})`
2189
+ };
2190
+ }
2191
+ const maxAmount = readAssetValue(swapEnv.maximumSwapAmounts, asset);
2192
+ if (maxAmount != null && amount > maxAmount) {
2193
+ return {
2194
+ success: false,
2195
+ reason: `expected amount is above maximum swap amount (${maxAmount})`
2196
+ };
2197
+ }
2198
+ return {
2199
+ success: true
2200
+ };
2201
+ }, "validateSwapAmount");
2176
2202
  var bytesToHex = /* @__PURE__ */ __name((arr) => `0x${[
2177
2203
  ...arr
2178
2204
  ].map((v) => v.toString(16).padStart(2, "0")).join("")}`, "bytesToHex");
@@ -2333,9 +2359,11 @@ var eth$ = /* @__PURE__ */ __name((network, env) => ({
2333
2359
  decimals: assetDecimals[Assets.ETH],
2334
2360
  name: "Ether",
2335
2361
  symbol: "ETH",
2362
+ chainflipId: "ETH",
2336
2363
  isMainnet: !isTestnet(network),
2337
2364
  minimumDepositAmount: env.ingressEgress.minimumDepositAmounts.Ethereum.ETH.toString(),
2338
- minimumSwapAmount: env.swapping.minimumSwapAmounts.Ethereum.ETH.toString()
2365
+ minimumSwapAmount: env.swapping.minimumSwapAmounts.Ethereum.ETH.toString(),
2366
+ maximumSwapAmount: env.swapping.maximumSwapAmounts.Ethereum.ETH?.toString() ?? null
2339
2367
  }), "eth$");
2340
2368
  var usdc$ = /* @__PURE__ */ __name((network, env) => ({
2341
2369
  id: Assets.USDC,
@@ -2344,9 +2372,11 @@ var usdc$ = /* @__PURE__ */ __name((network, env) => ({
2344
2372
  decimals: assetDecimals[Assets.USDC],
2345
2373
  name: "USDC",
2346
2374
  symbol: "USDC",
2375
+ chainflipId: "USDC",
2347
2376
  isMainnet: !isTestnet(network),
2348
2377
  minimumDepositAmount: env.ingressEgress.minimumDepositAmounts.Ethereum.USDC.toString(),
2349
- minimumSwapAmount: env.swapping.minimumSwapAmounts.Ethereum.USDC.toString()
2378
+ minimumSwapAmount: env.swapping.minimumSwapAmounts.Ethereum.USDC.toString(),
2379
+ maximumSwapAmount: env.swapping.maximumSwapAmounts.Ethereum.USDC?.toString() ?? null
2350
2380
  }), "usdc$");
2351
2381
  var flip$ = /* @__PURE__ */ __name((network, env) => ({
2352
2382
  id: Assets.FLIP,
@@ -2355,9 +2385,11 @@ var flip$ = /* @__PURE__ */ __name((network, env) => ({
2355
2385
  decimals: assetDecimals[Assets.FLIP],
2356
2386
  name: "FLIP",
2357
2387
  symbol: "FLIP",
2388
+ chainflipId: "FLIP",
2358
2389
  isMainnet: !isTestnet(network),
2359
2390
  minimumDepositAmount: env.ingressEgress.minimumDepositAmounts.Ethereum.FLIP.toString(),
2360
- minimumSwapAmount: env.swapping.minimumSwapAmounts.Ethereum.FLIP.toString()
2391
+ minimumSwapAmount: env.swapping.minimumSwapAmounts.Ethereum.FLIP.toString(),
2392
+ maximumSwapAmount: env.swapping.maximumSwapAmounts.Ethereum.FLIP?.toString() ?? null
2361
2393
  }), "flip$");
2362
2394
  var dot$ = /* @__PURE__ */ __name((network, env) => ({
2363
2395
  id: Assets.DOT,
@@ -2366,9 +2398,11 @@ var dot$ = /* @__PURE__ */ __name((network, env) => ({
2366
2398
  decimals: assetDecimals[Assets.DOT],
2367
2399
  name: "Polkadot",
2368
2400
  symbol: "DOT",
2401
+ chainflipId: "DOT",
2369
2402
  isMainnet: !isTestnet(network),
2370
2403
  minimumDepositAmount: env.ingressEgress.minimumDepositAmounts.Polkadot.DOT.toString(),
2371
- minimumSwapAmount: env.swapping.minimumSwapAmounts.Polkadot.DOT.toString()
2404
+ minimumSwapAmount: env.swapping.minimumSwapAmounts.Polkadot.DOT.toString(),
2405
+ maximumSwapAmount: env.swapping.maximumSwapAmounts.Polkadot.DOT?.toString() ?? null
2372
2406
  }), "dot$");
2373
2407
  var btc$ = /* @__PURE__ */ __name((network, env) => ({
2374
2408
  id: Assets.BTC,
@@ -2377,9 +2411,11 @@ var btc$ = /* @__PURE__ */ __name((network, env) => ({
2377
2411
  decimals: assetDecimals[Assets.BTC],
2378
2412
  name: "Bitcoin",
2379
2413
  symbol: "BTC",
2414
+ chainflipId: "BTC",
2380
2415
  isMainnet: !isTestnet(network),
2381
2416
  minimumDepositAmount: env.ingressEgress.minimumDepositAmounts.Bitcoin.BTC.toString(),
2382
- minimumSwapAmount: env.swapping.minimumSwapAmounts.Bitcoin.BTC.toString()
2417
+ minimumSwapAmount: env.swapping.minimumSwapAmounts.Bitcoin.BTC.toString(),
2418
+ maximumSwapAmount: env.swapping.maximumSwapAmounts.Bitcoin.BTC?.toString() ?? null
2383
2419
  }), "btc$");
2384
2420
 
2385
2421
  // src/swap/chains.ts
@@ -2518,9 +2554,14 @@ var _SwapSDK = class _SwapSDK {
2518
2554
  return ApiService_default.getQuote(this.baseUrl, quoteRequest, options);
2519
2555
  }
2520
2556
  async requestDepositAddress(depositAddressRequest) {
2557
+ const { srcChain, srcAsset, amount } = depositAddressRequest;
2558
+ await this.validateSwapAmount({
2559
+ chain: srcChain,
2560
+ asset: srcAsset
2561
+ }, BigInt(amount));
2521
2562
  let response;
2522
2563
  if (this.brokerConfig !== void 0) {
2523
- const { requestSwapDepositAddress } = await import('./broker-LHEVQ6DT.mjs');
2564
+ const { requestSwapDepositAddress } = await import('./broker-EAUQOE44.mjs');
2524
2565
  const result = await requestSwapDepositAddress(depositAddressRequest, this.brokerConfig);
2525
2566
  response = {
2526
2567
  id: `${result.issuedBlock}-${depositAddressRequest.srcChain}-${result.channelId}`,
@@ -2542,6 +2583,11 @@ var _SwapSDK = class _SwapSDK {
2542
2583
  return ApiService_default.getStatus(this.baseUrl, swapStatusRequest, options);
2543
2584
  }
2544
2585
  async executeSwap(params, txOpts = {}) {
2586
+ const { srcChain, srcAsset, amount } = params;
2587
+ await this.validateSwapAmount({
2588
+ chain: srcChain,
2589
+ asset: srcAsset
2590
+ }, BigInt(amount));
2545
2591
  assert(this.signer, "No signer provided");
2546
2592
  const receipt = await executeSwap_default(params, {
2547
2593
  network: this.network,
@@ -2559,6 +2605,12 @@ var _SwapSDK = class _SwapSDK {
2559
2605
  }, txOpts);
2560
2606
  return receipt ? receipt.hash : null;
2561
2607
  }
2608
+ async validateSwapAmount(asset, amount) {
2609
+ const stateChainEnv = await this.getStateChainEnvironment();
2610
+ const result = validateSwapAmount(stateChainEnv.swapping, asset, amount);
2611
+ if (!result.success)
2612
+ throw new Error(result.reason);
2613
+ }
2562
2614
  };
2563
2615
  __name(_SwapSDK, "SwapSDK");
2564
2616
  var SwapSDK = _SwapSDK;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/sdk",
3
- "version": "0.2.21",
3
+ "version": "1.1.0-rc.2",
4
4
  "description": "",
5
5
  "exports": {
6
6
  "./swap": {