@defuse-protocol/intents-sdk 0.72.0 → 0.74.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.
@@ -65,7 +65,8 @@ const CHAIN_MAPPINGS = [
65
65
  [require_caip2.Chains.Bitcoin, _omni_bridge_core.ChainKind.Btc],
66
66
  [require_caip2.Chains.Abstract, _omni_bridge_core.ChainKind.Abs],
67
67
  [require_caip2.Chains.Starknet, _omni_bridge_core.ChainKind.Strk],
68
- [require_caip2.Chains.Fogo, _omni_bridge_core.ChainKind.Fogo]
68
+ [require_caip2.Chains.Fogo, _omni_bridge_core.ChainKind.Fogo],
69
+ [require_caip2.Chains.Polygon, _omni_bridge_core.ChainKind.Pol]
69
70
  ];
70
71
  function caip2ToChainKind(network) {
71
72
  return CHAIN_MAPPINGS.find(([chain]) => chain === network)?.[1] ?? null;
@@ -97,7 +98,7 @@ async function getAccountOmniStorageBalance(nearProvider, accountId) {
97
98
  })])
98
99
  });
99
100
  }
100
- const OmniAddressSchema = valibot.custom((input) => typeof input === "string" && (input.startsWith("eth:") || input.startsWith("near:") || input.startsWith("sol:") || input.startsWith("arb:") || input.startsWith("base:") || input.startsWith("btc:") || input.startsWith("bnb:") || input.startsWith("abs:") || input.startsWith("strk:") || input.startsWith("fogo:")), "Must comply with omni address schema");
101
+ const OmniAddressSchema = valibot.custom((input) => typeof input === "string" && (input.startsWith("eth:") || input.startsWith("near:") || input.startsWith("sol:") || input.startsWith("arb:") || input.startsWith("base:") || input.startsWith("btc:") || input.startsWith("bnb:") || input.startsWith("abs:") || input.startsWith("strk:") || input.startsWith("fogo:") || input.startsWith("pol:")), "Must comply with omni address schema");
101
102
  /**
102
103
  * Converts a token address from one chain to its equivalent on another chain.
103
104
  * @param nearProvider Near provider used for querying the contract
@@ -63,7 +63,8 @@ const CHAIN_MAPPINGS = [
63
63
  [Chains.Bitcoin, ChainKind.Btc],
64
64
  [Chains.Abstract, ChainKind.Abs],
65
65
  [Chains.Starknet, ChainKind.Strk],
66
- [Chains.Fogo, ChainKind.Fogo]
66
+ [Chains.Fogo, ChainKind.Fogo],
67
+ [Chains.Polygon, ChainKind.Pol]
67
68
  ];
68
69
  function caip2ToChainKind(network) {
69
70
  return CHAIN_MAPPINGS.find(([chain]) => chain === network)?.[1] ?? null;
@@ -95,7 +96,7 @@ async function getAccountOmniStorageBalance(nearProvider, accountId) {
95
96
  })])
96
97
  });
97
98
  }
98
- const OmniAddressSchema = v.custom((input) => typeof input === "string" && (input.startsWith("eth:") || input.startsWith("near:") || input.startsWith("sol:") || input.startsWith("arb:") || input.startsWith("base:") || input.startsWith("btc:") || input.startsWith("bnb:") || input.startsWith("abs:") || input.startsWith("strk:") || input.startsWith("fogo:")), "Must comply with omni address schema");
99
+ const OmniAddressSchema = v.custom((input) => typeof input === "string" && (input.startsWith("eth:") || input.startsWith("near:") || input.startsWith("sol:") || input.startsWith("arb:") || input.startsWith("base:") || input.startsWith("btc:") || input.startsWith("bnb:") || input.startsWith("abs:") || input.startsWith("strk:") || input.startsWith("fogo:") || input.startsWith("pol:")), "Must comply with omni address schema");
99
100
  /**
100
101
  * Converts a token address from one chain to its equivalent on another chain.
101
102
  * @param nearProvider Near provider used for querying the contract
@@ -18,7 +18,7 @@ let _omni_bridge_core = require("@omni-bridge/core");
18
18
 
19
19
  //#region src/bridges/omni-bridge/omni-bridge.ts
20
20
  var OmniBridge = class {
21
- constructor({ envConfig, nearProvider, solverRelayApiKey, routeMigratedPoaTokensThroughOmniBridge }) {
21
+ constructor({ envConfig, nearProvider, solverRelayApiKey, routeMigratedPoaTokensThroughOmniBridge, bridgeConfig }) {
22
22
  this.route = require_route_enum.RouteEnum.OmniBridge;
23
23
  this.intentsStorageBalanceCache = new _isaacs_ttlcache.default({
24
24
  max: 1,
@@ -35,6 +35,7 @@ var OmniBridge = class {
35
35
  this.omniBridgeAPI = new _omni_bridge_core.BridgeAPI("mainnet");
36
36
  this.solverRelayApiKey = solverRelayApiKey;
37
37
  this.routeMigratedPoaTokensThroughOmniBridge = routeMigratedPoaTokensThroughOmniBridge ?? false;
38
+ this.bridgeConfig = { prefundedNativeFeeTokens: bridgeConfig?.prefundedNativeFeeTokens ?? [] };
38
39
  }
39
40
  is(routeConfig) {
40
41
  return routeConfig.route === require_route_enum.RouteEnum.OmniBridge;
@@ -156,7 +157,8 @@ var OmniBridge = class {
156
157
  }
157
158
  async validateWithdrawal(args) {
158
159
  const isFeeSubsidized = require_omni_bridge_constants.FEE_SUBSIDIZED_TOKENS.includes(args.assetId);
159
- if (!isFeeSubsidized) (0, _defuse_protocol_internal_utils.assert)(args.feeEstimation.amount > 0n, `Invalid Omni Bridge fee: expected > 0, got ${args.feeEstimation.amount}`);
160
+ const isPrefundedWithdrawal = this.bridgeConfig.prefundedNativeFeeTokens.includes(args.assetId);
161
+ if (!isFeeSubsidized && !isPrefundedWithdrawal) (0, _defuse_protocol_internal_utils.assert)(args.feeEstimation.amount > 0n, `Invalid Omni Bridge fee: expected > 0, got ${args.feeEstimation.amount}`);
160
162
  const assetInfo = this.makeAssetInfo(args.assetId, args.routeConfig);
161
163
  (0, _defuse_protocol_internal_utils.assert)(assetInfo !== null, `Asset ${args.assetId} is not supported by Omni Bridge`);
162
164
  if (require_validateAddress.validateAddress(args.destinationAddress, assetInfo.blockchain) === false) throw new require_errors.InvalidDestinationAddressForWithdrawalError(args.destinationAddress, assetInfo.blockchain);
@@ -224,7 +226,7 @@ var OmniBridge = class {
224
226
  };
225
227
  let amount = 0n;
226
228
  let quote = null;
227
- if (totalAmountToQuote > 0n) {
229
+ if (totalAmountToQuote > 0n && !this.bridgeConfig.prefundedNativeFeeTokens.includes(args.withdrawalParams.assetId)) {
228
230
  quote = await require_estimate_fee.getFeeQuote({
229
231
  feeAmount: totalAmountToQuote,
230
232
  feeAssetId: require_omni_bridge_constants.NEAR_NATIVE_ASSET_ID,
@@ -16,7 +16,7 @@ import { BridgeAPI, ChainKind, getChain, getMinimumTransferableAmount, isEvmChai
16
16
 
17
17
  //#region src/bridges/omni-bridge/omni-bridge.ts
18
18
  var OmniBridge = class {
19
- constructor({ envConfig, nearProvider, solverRelayApiKey, routeMigratedPoaTokensThroughOmniBridge }) {
19
+ constructor({ envConfig, nearProvider, solverRelayApiKey, routeMigratedPoaTokensThroughOmniBridge, bridgeConfig }) {
20
20
  this.route = RouteEnum.OmniBridge;
21
21
  this.intentsStorageBalanceCache = new TTLCache({
22
22
  max: 1,
@@ -33,6 +33,7 @@ var OmniBridge = class {
33
33
  this.omniBridgeAPI = new BridgeAPI("mainnet");
34
34
  this.solverRelayApiKey = solverRelayApiKey;
35
35
  this.routeMigratedPoaTokensThroughOmniBridge = routeMigratedPoaTokensThroughOmniBridge ?? false;
36
+ this.bridgeConfig = { prefundedNativeFeeTokens: bridgeConfig?.prefundedNativeFeeTokens ?? [] };
36
37
  }
37
38
  is(routeConfig) {
38
39
  return routeConfig.route === RouteEnum.OmniBridge;
@@ -154,7 +155,8 @@ var OmniBridge = class {
154
155
  }
155
156
  async validateWithdrawal(args) {
156
157
  const isFeeSubsidized = FEE_SUBSIDIZED_TOKENS.includes(args.assetId);
157
- if (!isFeeSubsidized) assert(args.feeEstimation.amount > 0n, `Invalid Omni Bridge fee: expected > 0, got ${args.feeEstimation.amount}`);
158
+ const isPrefundedWithdrawal = this.bridgeConfig.prefundedNativeFeeTokens.includes(args.assetId);
159
+ if (!isFeeSubsidized && !isPrefundedWithdrawal) assert(args.feeEstimation.amount > 0n, `Invalid Omni Bridge fee: expected > 0, got ${args.feeEstimation.amount}`);
158
160
  const assetInfo = this.makeAssetInfo(args.assetId, args.routeConfig);
159
161
  assert(assetInfo !== null, `Asset ${args.assetId} is not supported by Omni Bridge`);
160
162
  if (validateAddress(args.destinationAddress, assetInfo.blockchain) === false) throw new InvalidDestinationAddressForWithdrawalError(args.destinationAddress, assetInfo.blockchain);
@@ -222,7 +224,7 @@ var OmniBridge = class {
222
224
  };
223
225
  let amount = 0n;
224
226
  let quote = null;
225
- if (totalAmountToQuote > 0n) {
227
+ if (totalAmountToQuote > 0n && !this.bridgeConfig.prefundedNativeFeeTokens.includes(args.withdrawalParams.assetId)) {
226
228
  quote = await getFeeQuote({
227
229
  feeAmount: totalAmountToQuote,
228
230
  feeAssetId: NEAR_NATIVE_ASSET_ID,
@@ -55,7 +55,7 @@ var PoaBridge = class {
55
55
  }
56
56
  createWithdrawalIntents(args) {
57
57
  const relayerFee = require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.PoaBridge, "relayerFee");
58
- (0, _defuse_protocol_internal_utils.assert)(relayerFee > 0n, `Invalid POA bridge relayer fee: expected > 0, got ${relayerFee}`);
58
+ (0, _defuse_protocol_internal_utils.assert)(relayerFee >= 0n, `Invalid POA bridge relayer fee: expected >= 0, got ${relayerFee}`);
59
59
  const intent = require_poa_bridge_utils.createWithdrawIntentPrimitive({
60
60
  ...args.withdrawalParams,
61
61
  amount: args.withdrawalParams.amount + relayerFee,
@@ -109,7 +109,7 @@ var PoaBridge = class {
109
109
  logger: args.logger
110
110
  });
111
111
  const relayerFee = BigInt(estimation.withdrawalFee);
112
- (0, _defuse_protocol_internal_utils.assert)(relayerFee > 0n, `Invalid POA bridge relayer fee: expected > 0, got ${relayerFee}`);
112
+ (0, _defuse_protocol_internal_utils.assert)(relayerFee >= 0n, `Invalid POA bridge relayer fee: expected >= 0, got ${relayerFee}`);
113
113
  return {
114
114
  amount: relayerFee,
115
115
  quote: null,
@@ -53,7 +53,7 @@ var PoaBridge = class {
53
53
  }
54
54
  createWithdrawalIntents(args) {
55
55
  const relayerFee = getUnderlyingFee(args.feeEstimation, RouteEnum.PoaBridge, "relayerFee");
56
- assert(relayerFee > 0n, `Invalid POA bridge relayer fee: expected > 0, got ${relayerFee}`);
56
+ assert(relayerFee >= 0n, `Invalid POA bridge relayer fee: expected >= 0, got ${relayerFee}`);
57
57
  const intent = createWithdrawIntentPrimitive({
58
58
  ...args.withdrawalParams,
59
59
  amount: args.withdrawalParams.amount + relayerFee,
@@ -107,7 +107,7 @@ var PoaBridge = class {
107
107
  logger: args.logger
108
108
  });
109
109
  const relayerFee = BigInt(estimation.withdrawalFee);
110
- assert(relayerFee > 0n, `Invalid POA bridge relayer fee: expected > 0, got ${relayerFee}`);
110
+ assert(relayerFee >= 0n, `Invalid POA bridge relayer fee: expected >= 0, got ${relayerFee}`);
111
111
  return {
112
112
  amount: relayerFee,
113
113
  quote: null,
package/dist/src/sdk.cjs CHANGED
@@ -75,7 +75,8 @@ var IntentsSDK = class {
75
75
  envConfig: this.envConfig,
76
76
  nearProvider,
77
77
  solverRelayApiKey: this.solverRelayApiKey,
78
- routeMigratedPoaTokensThroughOmniBridge: args.features?.routeMigratedPoaTokensThroughOmniBridge
78
+ routeMigratedPoaTokensThroughOmniBridge: args.features?.routeMigratedPoaTokensThroughOmniBridge,
79
+ bridgeConfig: args.bridgeConfigs?.[require_route_enum.RouteEnum.OmniBridge]
79
80
  }),
80
81
  new require_direct_bridge.DirectBridge({
81
82
  envConfig: this.envConfig,
@@ -1,6 +1,6 @@
1
1
  import { IntentHash, IntentPrimitive, MultiPayload } from "./intents/shared-types.cjs";
2
2
  import { IIntentSigner } from "./intents/interfaces/intent-signer.cjs";
3
- import { BatchWithdrawalResult, Bridge, CreateWithdrawalCompletionPromisesParams, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, QuoteOptions, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, WithdrawalParams, WithdrawalResult } from "./shared-types.cjs";
3
+ import { BatchWithdrawalResult, Bridge, BridgeConfigs, CreateWithdrawalCompletionPromisesParams, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, QuoteOptions, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, WithdrawalParams, WithdrawalResult } from "./shared-types.cjs";
4
4
  import { IIntentRelayer } from "./intents/interfaces/intent-relayer.cjs";
5
5
  import { ISaltManager } from "./intents/interfaces/salt-manager.cjs";
6
6
  import { IntentPayloadBuilder } from "./intents/intent-payload-builder.cjs";
@@ -45,6 +45,7 @@ interface IntentsSDKConfig {
45
45
  */
46
46
  routeMigratedPoaTokensThroughOmniBridge?: boolean;
47
47
  };
48
+ bridgeConfigs?: BridgeConfigs;
48
49
  }
49
50
  declare class IntentsSDK implements IIntentsSDK {
50
51
  protected envConfig: EnvConfig;
package/dist/src/sdk.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { IntentHash, IntentPrimitive, MultiPayload } from "./intents/shared-types.js";
2
2
  import { IIntentSigner } from "./intents/interfaces/intent-signer.js";
3
- import { BatchWithdrawalResult, Bridge, CreateWithdrawalCompletionPromisesParams, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, QuoteOptions, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, WithdrawalParams, WithdrawalResult } from "./shared-types.js";
3
+ import { BatchWithdrawalResult, Bridge, BridgeConfigs, CreateWithdrawalCompletionPromisesParams, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, QuoteOptions, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, WithdrawalParams, WithdrawalResult } from "./shared-types.js";
4
4
  import { IIntentRelayer } from "./intents/interfaces/intent-relayer.js";
5
5
  import { ISaltManager } from "./intents/interfaces/salt-manager.js";
6
6
  import { IntentPayloadBuilder } from "./intents/intent-payload-builder.js";
@@ -45,6 +45,7 @@ interface IntentsSDKConfig {
45
45
  */
46
46
  routeMigratedPoaTokensThroughOmniBridge?: boolean;
47
47
  };
48
+ bridgeConfigs?: BridgeConfigs;
48
49
  }
49
50
  declare class IntentsSDK implements IIntentsSDK {
50
51
  protected envConfig: EnvConfig;
package/dist/src/sdk.js CHANGED
@@ -73,7 +73,8 @@ var IntentsSDK = class {
73
73
  envConfig: this.envConfig,
74
74
  nearProvider,
75
75
  solverRelayApiKey: this.solverRelayApiKey,
76
- routeMigratedPoaTokensThroughOmniBridge: args.features?.routeMigratedPoaTokensThroughOmniBridge
76
+ routeMigratedPoaTokensThroughOmniBridge: args.features?.routeMigratedPoaTokensThroughOmniBridge,
77
+ bridgeConfig: args.bridgeConfigs?.[RouteEnum.OmniBridge]
77
78
  }),
78
79
  new DirectBridge({
79
80
  envConfig: this.envConfig,
@@ -262,6 +262,16 @@ interface RouteFeeStructures {
262
262
  /** Internal transfers have no fees */
263
263
  [RouteEnum.InternalTransfer]: null;
264
264
  }
265
+ /**
266
+ * Per-bridge configuration, keyed by route. Each entry is optional and tunes
267
+ * the behaviour of a single bridge; omitting one falls back to that bridge's defaults.
268
+ */
269
+ interface BridgeConfigs {
270
+ [RouteEnum.OmniBridge]?: {
271
+ /** Asset IDs of subsidized tokens whose withdrawal relayer fee is prefunded. */
272
+ prefundedNativeFeeTokens?: string[];
273
+ };
274
+ }
265
275
  /**
266
276
  * Represents the different categories of fees that may apply across various withdrawal operations.
267
277
  * Each route type has an optional fee structure. Uses a mapped type to ensure all RouteEnum values are covered.
@@ -386,4 +396,4 @@ type PartialRPCEndpointMap = { [K in keyof RPCEndpointMap]?: K extends typeof Ch
386
396
  horizon?: RpcEndpoint[];
387
397
  } : RpcEndpoint[] };
388
398
  //#endregion
389
- export { BatchWithdrawalResult, Bridge, CreateWithdrawalCompletionPromisesParams, FeeEstimation, HotBridgeRouteConfig, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, InternalTransferRouteConfig, NearTxInfo, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, ParsedAssetInfo, PartialRPCEndpointMap, PoaBridgeRouteConfig, ProcessWithdrawalArgs, QuoteOptions, RouteConfig, SignAndSendArgs, SignAndSendWithdrawalArgs, SignedIntentsComposition, TxInfo, TxNoInfo, VirtualChainRouteConfig, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult };
399
+ export { BatchWithdrawalResult, Bridge, BridgeConfigs, CreateWithdrawalCompletionPromisesParams, FeeEstimation, HotBridgeRouteConfig, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, InternalTransferRouteConfig, NearTxInfo, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, ParsedAssetInfo, PartialRPCEndpointMap, PoaBridgeRouteConfig, ProcessWithdrawalArgs, QuoteOptions, RouteConfig, SignAndSendArgs, SignAndSendWithdrawalArgs, SignedIntentsComposition, TxInfo, TxNoInfo, VirtualChainRouteConfig, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult };
@@ -262,6 +262,16 @@ interface RouteFeeStructures {
262
262
  /** Internal transfers have no fees */
263
263
  [RouteEnum.InternalTransfer]: null;
264
264
  }
265
+ /**
266
+ * Per-bridge configuration, keyed by route. Each entry is optional and tunes
267
+ * the behaviour of a single bridge; omitting one falls back to that bridge's defaults.
268
+ */
269
+ interface BridgeConfigs {
270
+ [RouteEnum.OmniBridge]?: {
271
+ /** Asset IDs of subsidized tokens whose withdrawal relayer fee is prefunded. */
272
+ prefundedNativeFeeTokens?: string[];
273
+ };
274
+ }
265
275
  /**
266
276
  * Represents the different categories of fees that may apply across various withdrawal operations.
267
277
  * Each route type has an optional fee structure. Uses a mapped type to ensure all RouteEnum values are covered.
@@ -386,4 +396,4 @@ type PartialRPCEndpointMap = { [K in keyof RPCEndpointMap]?: K extends typeof Ch
386
396
  horizon?: RpcEndpoint[];
387
397
  } : RpcEndpoint[] };
388
398
  //#endregion
389
- export { BatchWithdrawalResult, Bridge, CreateWithdrawalCompletionPromisesParams, FeeEstimation, HotBridgeRouteConfig, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, InternalTransferRouteConfig, NearTxInfo, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, ParsedAssetInfo, PartialRPCEndpointMap, PoaBridgeRouteConfig, ProcessWithdrawalArgs, QuoteOptions, RouteConfig, SignAndSendArgs, SignAndSendWithdrawalArgs, SignedIntentsComposition, TxInfo, TxNoInfo, VirtualChainRouteConfig, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult };
399
+ export { BatchWithdrawalResult, Bridge, BridgeConfigs, CreateWithdrawalCompletionPromisesParams, FeeEstimation, HotBridgeRouteConfig, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, InternalTransferRouteConfig, NearTxInfo, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, ParsedAssetInfo, PartialRPCEndpointMap, PoaBridgeRouteConfig, ProcessWithdrawalArgs, QuoteOptions, RouteConfig, SignAndSendArgs, SignAndSendWithdrawalArgs, SignedIntentsComposition, TxInfo, TxNoInfo, VirtualChainRouteConfig, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defuse-protocol/intents-sdk",
3
- "version": "0.72.0",
3
+ "version": "0.74.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "repository": {
@@ -49,8 +49,8 @@
49
49
  "ripple-address-codec": "^5.0.0",
50
50
  "valibot": "^1.0.0",
51
51
  "viem": "^2.0.0",
52
- "@defuse-protocol/internal-utils": "0.35.2",
53
- "@defuse-protocol/contract-types": "0.6.4"
52
+ "@defuse-protocol/contract-types": "0.6.4",
53
+ "@defuse-protocol/internal-utils": "0.35.2"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@ton/core": "^0.60.0",