@defuse-protocol/intents-sdk 0.37.2 → 0.38.0

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.
@@ -42,23 +42,22 @@ function createWithdrawIntentsPrimitive(params) {
42
42
  })
43
43
  }];
44
44
  }
45
+ /**
46
+ * Mapping between CAIP-2 chain identifiers and Omni Bridge ChainKind.
47
+ * This serves as a single source of truth for bidirectional chain conversions.
48
+ */
49
+ const CHAIN_MAPPINGS = [
50
+ [require_caip2.Chains.Ethereum, omni_bridge_sdk.ChainKind.Eth],
51
+ [require_caip2.Chains.Base, omni_bridge_sdk.ChainKind.Base],
52
+ [require_caip2.Chains.Arbitrum, omni_bridge_sdk.ChainKind.Arb],
53
+ [require_caip2.Chains.Solana, omni_bridge_sdk.ChainKind.Sol],
54
+ [require_caip2.Chains.BNB, omni_bridge_sdk.ChainKind.Bnb]
55
+ ];
45
56
  function caip2ToChainKind(network) {
46
- switch (network) {
47
- case require_caip2.Chains.Ethereum: return omni_bridge_sdk.ChainKind.Eth;
48
- case require_caip2.Chains.Base: return omni_bridge_sdk.ChainKind.Base;
49
- case require_caip2.Chains.Arbitrum: return omni_bridge_sdk.ChainKind.Arb;
50
- case require_caip2.Chains.Solana: return omni_bridge_sdk.ChainKind.Sol;
51
- default: return null;
52
- }
57
+ return CHAIN_MAPPINGS.find(([chain]) => chain === network)?.[1] ?? null;
53
58
  }
54
59
  function chainKindToCaip2(network) {
55
- switch (network) {
56
- case omni_bridge_sdk.ChainKind.Eth: return require_caip2.Chains.Ethereum;
57
- case omni_bridge_sdk.ChainKind.Base: return require_caip2.Chains.Base;
58
- case omni_bridge_sdk.ChainKind.Arb: return require_caip2.Chains.Arbitrum;
59
- case omni_bridge_sdk.ChainKind.Sol: return require_caip2.Chains.Solana;
60
- default: return null;
61
- }
60
+ return CHAIN_MAPPINGS.find(([_, kind]) => kind === network)?.[0] ?? null;
62
61
  }
63
62
  function validateOmniToken(nearAddress) {
64
63
  if (nearAddress.endsWith(".testnet")) return false;
@@ -38,23 +38,22 @@ function createWithdrawIntentsPrimitive(params) {
38
38
  })
39
39
  }];
40
40
  }
41
+ /**
42
+ * Mapping between CAIP-2 chain identifiers and Omni Bridge ChainKind.
43
+ * This serves as a single source of truth for bidirectional chain conversions.
44
+ */
45
+ const CHAIN_MAPPINGS = [
46
+ [Chains.Ethereum, ChainKind.Eth],
47
+ [Chains.Base, ChainKind.Base],
48
+ [Chains.Arbitrum, ChainKind.Arb],
49
+ [Chains.Solana, ChainKind.Sol],
50
+ [Chains.BNB, ChainKind.Bnb]
51
+ ];
41
52
  function caip2ToChainKind(network) {
42
- switch (network) {
43
- case Chains.Ethereum: return ChainKind.Eth;
44
- case Chains.Base: return ChainKind.Base;
45
- case Chains.Arbitrum: return ChainKind.Arb;
46
- case Chains.Solana: return ChainKind.Sol;
47
- default: return null;
48
- }
53
+ return CHAIN_MAPPINGS.find(([chain]) => chain === network)?.[1] ?? null;
49
54
  }
50
55
  function chainKindToCaip2(network) {
51
- switch (network) {
52
- case ChainKind.Eth: return Chains.Ethereum;
53
- case ChainKind.Base: return Chains.Base;
54
- case ChainKind.Arb: return Chains.Arbitrum;
55
- case ChainKind.Sol: return Chains.Solana;
56
- default: return null;
57
- }
56
+ return CHAIN_MAPPINGS.find(([_, kind]) => kind === network)?.[0] ?? null;
58
57
  }
59
58
  function validateOmniToken(nearAddress) {
60
59
  if (nearAddress.endsWith(".testnet")) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defuse-protocol/intents-sdk",
3
- "version": "0.37.2",
3
+ "version": "0.38.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,