@defuse-protocol/intents-sdk 0.26.4 → 0.28.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.
package/README.md CHANGED
@@ -26,6 +26,7 @@ interacting with various bridge implementations across multiple blockchains.
26
26
  - [Asset Information Parsing](#asset-information-parsing)
27
27
  - [Waiting for Completion](#waiting-for-completion)
28
28
  - [Error Handling](#error-handling)
29
+ - [Atomic Multi-Intent Publishing](#atomic-multi-intent-publishing)
29
30
  - [Supported Networks](#supported-networks)
30
31
  - [Development](#development)
31
32
 
@@ -808,6 +809,39 @@ try {
808
809
  }
809
810
  ```
810
811
 
812
+ ### Atomic Multi-Intent Publishing
813
+
814
+ Include pre-signed intents (from other users or prior operations) to be published atomically with your new intent.
815
+ Useful for multi-user coordination and batch operations.
816
+
817
+ ```typescript
818
+ import type { MultiPayload } from '@defuse-protocol/intents-sdk';
819
+
820
+ // Include pre-signed intents before/after your new intent
821
+ await sdk.signAndSendIntent({
822
+ intents: [{ intent: "transfer", receiver_id: "alice.near", tokens: {...} }],
823
+ signedIntents: {
824
+ before: [preSigned1], // Execute before new intent
825
+ after: [preSigned2] // Execute after new intent
826
+ }
827
+ });
828
+
829
+ // Also works with withdrawals
830
+ await sdk.processWithdrawal({
831
+ withdrawalParams: {...},
832
+ intent: {
833
+ signedIntents: {
834
+ before: [preSigned1],
835
+ after: [preSigned2]
836
+ }
837
+ }
838
+ });
839
+ ```
840
+
841
+ **Key Points:**
842
+ - All intents execute atomically in order: `before` → new intent → `after`
843
+ - Returned `intentHash` is for your newly created intent, not the included ones
844
+
811
845
  ## Supported Networks
812
846
 
813
847
  For a list of supported chains, see
package/dist/index.cjs CHANGED
@@ -3,8 +3,9 @@ const require_route_enum = require('./src/constants/route-enum.cjs');
3
3
  const require_errors = require('./src/classes/errors.cjs');
4
4
  const require_caip2 = require('./src/lib/caip2.cjs');
5
5
  const require_bridge_name_enum = require('./src/constants/bridge-name-enum.cjs');
6
- const require_error = require('./src/bridges/hot-bridge/error.cjs');
7
- const require_error$1 = require('./src/bridges/omni-bridge/error.cjs');
6
+ const require_error = require('./src/bridges/direct-bridge/error.cjs');
7
+ const require_error$1 = require('./src/bridges/hot-bridge/error.cjs');
8
+ const require_error$2 = require('./src/bridges/omni-bridge/error.cjs');
8
9
  const require_route_config_factory = require('./src/lib/route-config-factory.cjs');
9
10
  const require_sdk = require('./src/sdk.cjs');
10
11
  const require_factories = require('./src/intents/intent-signer-impl/factories.cjs');
@@ -25,11 +26,12 @@ Object.defineProperty(exports, 'BaseError', {
25
26
  });
26
27
  exports.BridgeNameEnum = require_bridge_name_enum.BridgeNameEnum;
27
28
  exports.Chains = require_caip2.Chains;
28
- exports.FailedToFetchFeeError = require_error$1.FailedToFetchFeeError;
29
+ exports.DestinationExplicitNearAccountDoesntExistError = require_error.DestinationExplicitNearAccountDoesntExistError;
30
+ exports.FailedToFetchFeeError = require_error$2.FailedToFetchFeeError;
29
31
  exports.FeeExceedsAmountError = require_errors.FeeExceedsAmountError;
30
- exports.HotWithdrawalCancelledError = require_error.HotWithdrawalCancelledError;
31
- exports.HotWithdrawalNotFoundError = require_error.HotWithdrawalNotFoundError;
32
- exports.HotWithdrawalPendingError = require_error.HotWithdrawalPendingError;
32
+ exports.HotWithdrawalCancelledError = require_error$1.HotWithdrawalCancelledError;
33
+ exports.HotWithdrawalNotFoundError = require_error$1.HotWithdrawalNotFoundError;
34
+ exports.HotWithdrawalPendingError = require_error$1.HotWithdrawalPendingError;
33
35
  Object.defineProperty(exports, 'HttpRequestError', {
34
36
  enumerable: true,
35
37
  get: function () {
@@ -42,12 +44,12 @@ Object.defineProperty(exports, 'IntentSettlementError', {
42
44
  return __defuse_protocol_internal_utils.IntentSettlementError;
43
45
  }
44
46
  });
45
- exports.IntentsNearOmniAvailableBalanceTooLowError = require_error$1.IntentsNearOmniAvailableBalanceTooLowError;
47
+ exports.IntentsNearOmniAvailableBalanceTooLowError = require_error$2.IntentsNearOmniAvailableBalanceTooLowError;
46
48
  exports.IntentsSDK = require_sdk.IntentsSDK;
47
49
  exports.MinWithdrawalAmountError = require_errors.MinWithdrawalAmountError;
48
- exports.OmniTokenNormalisationCheckError = require_error$1.OmniTokenNormalisationCheckError;
49
- exports.OmniTransferDestinationChainHashNotFoundError = require_error$1.OmniTransferDestinationChainHashNotFoundError;
50
- exports.OmniTransferNotFoundError = require_error$1.OmniTransferNotFoundError;
50
+ exports.OmniTokenNormalisationCheckError = require_error$2.OmniTokenNormalisationCheckError;
51
+ exports.OmniTransferDestinationChainHashNotFoundError = require_error$2.OmniTransferDestinationChainHashNotFoundError;
52
+ exports.OmniTransferNotFoundError = require_error$2.OmniTransferNotFoundError;
51
53
  Object.defineProperty(exports, 'PoaWithdrawalInvariantError', {
52
54
  enumerable: true,
53
55
  get: function () {
@@ -91,7 +93,7 @@ Object.defineProperty(exports, 'TimeoutError', {
91
93
  return __defuse_protocol_internal_utils.TimeoutError;
92
94
  }
93
95
  });
94
- exports.TokenNotFoundInDestinationChainError = require_error$1.TokenNotFoundInDestinationChainError;
96
+ exports.TokenNotFoundInDestinationChainError = require_error$2.TokenNotFoundInDestinationChainError;
95
97
  exports.TrustlineNotFoundError = require_errors.TrustlineNotFoundError;
96
98
  exports.UnsupportedAssetIdError = require_errors.UnsupportedAssetIdError;
97
99
  exports.UnsupportedDestinationMemoError = require_errors.UnsupportedDestinationMemoError;
package/dist/index.d.cts CHANGED
@@ -4,12 +4,13 @@ import { IntentPayload, IntentPayloadFactory, IntentPrimitive, IntentRelayParams
4
4
  import { IIntentSigner } from "./src/intents/interfaces/intent-signer.cjs";
5
5
  import { OnBeforePublishIntentHook } from "./src/intents/intent-executer-impl/intent-executer.cjs";
6
6
  import { Chain, Chains } from "./src/lib/caip2.cjs";
7
- import { BatchWithdrawalResult, FeeEstimation, HotBridgeRouteConfig, IntentPublishResult, IntentSettlementStatus, InternalTransferRouteConfig, NearTxInfo, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, ParsedAssetInfo, PoaBridgeRouteConfig, ProcessWithdrawalArgs, RouteConfig, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, VirtualChainRouteConfig, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult } from "./src/shared-types.cjs";
7
+ import { BatchWithdrawalResult, FeeEstimation, HotBridgeRouteConfig, IntentPublishResult, IntentSettlementStatus, InternalTransferRouteConfig, NearTxInfo, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, ParsedAssetInfo, PoaBridgeRouteConfig, ProcessWithdrawalArgs, RouteConfig, SignAndSendArgs, SignAndSendWithdrawalArgs, SignedIntentsComposition, TxInfo, TxNoInfo, VirtualChainRouteConfig, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult } from "./src/shared-types.cjs";
8
8
  import { IntentsSDK, IntentsSDKConfig } from "./src/sdk.cjs";
9
9
  import { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem } from "./src/intents/intent-signer-impl/factories.cjs";
10
10
  import { createDefaultRoute, createHotBridgeRoute, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute } from "./src/lib/route-config-factory.cjs";
11
11
  import { FeeExceedsAmountError, FeeExceedsAmountErrorType, MinWithdrawalAmountError, MinWithdrawalAmountErrorType, TrustlineNotFoundError, TrustlineNotFoundErrorType, UnsupportedAssetIdError, UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, UnsupportedDestinationMemoErrorType } from "./src/classes/errors.cjs";
12
+ import { DestinationExplicitNearAccountDoesntExistError, DestinationExplicitNearAccountDoesntExistErrorType } from "./src/bridges/direct-bridge/error.cjs";
12
13
  import { HotWithdrawalCancelledError, HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, HotWithdrawalPendingErrorType } from "./src/bridges/hot-bridge/error.cjs";
13
14
  import { FailedToFetchFeeError, FailedToFetchFeeErrorType, IntentsNearOmniAvailableBalanceTooLowError, IntentsNearOmniAvailableBalanceTooLowErrorType, OmniTokenNormalisationCheckError, OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, OmniTransferNotFoundErrorType, TokenNotFoundInDestinationChainError, TokenNotFoundInDestinationChainErrorType } from "./src/bridges/omni-bridge/error.cjs";
14
15
  import { AssertionError, AssertionErrorType, BaseError, BaseErrorType, HttpRequestError, HttpRequestErrorType, ILogger, IntentSettlementError, IntentSettlementErrorType, NearIntentsEnv, PoaWithdrawalInvariantError, PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, PoaWithdrawalPendingErrorType, QuoteError, QuoteErrorType, RelayPublishError, RelayPublishErrorType, RetryOptions, RpcRequestError, RpcRequestErrorType, TimeoutError, TimeoutErrorType } from "@defuse-protocol/internal-utils";
15
- export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, FailedToFetchFeeError, type FailedToFetchFeeErrorType, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalCancelledError, type HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, type HotWithdrawalPendingErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, type IntentPayload, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type OmniBridgeRouteConfig, OmniTokenNormalisationCheckError, type OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, type OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, type OmniTransferNotFoundErrorType, type OnBeforePublishIntentHook, type ParsedAssetInfo, type PoaBridgeRouteConfig, PoaWithdrawalInvariantError, type PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, type PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, type PoaWithdrawalPendingErrorType, type ProcessWithdrawalArgs, QuoteError, type QuoteErrorType, RelayPublishError, type RelayPublishErrorType, type RetryOptions, type RouteConfig, RouteEnum, type RouteEnumValues, RpcRequestError, type RpcRequestErrorType, type SignAndSendWithdrawalArgs, TimeoutError, type TimeoutErrorType, TokenNotFoundInDestinationChainError, type TokenNotFoundInDestinationChainErrorType, TrustlineNotFoundError, type TrustlineNotFoundErrorType, type TxInfo, type TxNoInfo, UnsupportedAssetIdError, type UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, type UnsupportedDestinationMemoErrorType, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
16
+ export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, DestinationExplicitNearAccountDoesntExistError, type DestinationExplicitNearAccountDoesntExistErrorType, FailedToFetchFeeError, type FailedToFetchFeeErrorType, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalCancelledError, type HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, type HotWithdrawalPendingErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, type IntentPayload, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type OmniBridgeRouteConfig, OmniTokenNormalisationCheckError, type OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, type OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, type OmniTransferNotFoundErrorType, type OnBeforePublishIntentHook, type ParsedAssetInfo, type PoaBridgeRouteConfig, PoaWithdrawalInvariantError, type PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, type PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, type PoaWithdrawalPendingErrorType, type ProcessWithdrawalArgs, QuoteError, type QuoteErrorType, RelayPublishError, type RelayPublishErrorType, type RetryOptions, type RouteConfig, RouteEnum, type RouteEnumValues, RpcRequestError, type RpcRequestErrorType, type SignAndSendArgs, type SignAndSendWithdrawalArgs, type SignedIntentsComposition, TimeoutError, type TimeoutErrorType, TokenNotFoundInDestinationChainError, type TokenNotFoundInDestinationChainErrorType, TrustlineNotFoundError, type TrustlineNotFoundErrorType, type TxInfo, type TxNoInfo, UnsupportedAssetIdError, type UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, type UnsupportedDestinationMemoErrorType, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
package/dist/index.d.ts CHANGED
@@ -4,12 +4,13 @@ import { IntentPayload, IntentPayloadFactory, IntentPrimitive, IntentRelayParams
4
4
  import { IIntentSigner } from "./src/intents/interfaces/intent-signer.js";
5
5
  import { OnBeforePublishIntentHook } from "./src/intents/intent-executer-impl/intent-executer.js";
6
6
  import { Chain, Chains } from "./src/lib/caip2.js";
7
- import { BatchWithdrawalResult, FeeEstimation, HotBridgeRouteConfig, IntentPublishResult, IntentSettlementStatus, InternalTransferRouteConfig, NearTxInfo, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, ParsedAssetInfo, PoaBridgeRouteConfig, ProcessWithdrawalArgs, RouteConfig, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, VirtualChainRouteConfig, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult } from "./src/shared-types.js";
7
+ import { BatchWithdrawalResult, FeeEstimation, HotBridgeRouteConfig, IntentPublishResult, IntentSettlementStatus, InternalTransferRouteConfig, NearTxInfo, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, ParsedAssetInfo, PoaBridgeRouteConfig, ProcessWithdrawalArgs, RouteConfig, SignAndSendArgs, SignAndSendWithdrawalArgs, SignedIntentsComposition, TxInfo, TxNoInfo, VirtualChainRouteConfig, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult } from "./src/shared-types.js";
8
8
  import { IntentsSDK, IntentsSDKConfig } from "./src/sdk.js";
9
9
  import { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem } from "./src/intents/intent-signer-impl/factories.js";
10
10
  import { createDefaultRoute, createHotBridgeRoute, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute } from "./src/lib/route-config-factory.js";
11
11
  import { FeeExceedsAmountError, FeeExceedsAmountErrorType, MinWithdrawalAmountError, MinWithdrawalAmountErrorType, TrustlineNotFoundError, TrustlineNotFoundErrorType, UnsupportedAssetIdError, UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, UnsupportedDestinationMemoErrorType } from "./src/classes/errors.js";
12
+ import { DestinationExplicitNearAccountDoesntExistError, DestinationExplicitNearAccountDoesntExistErrorType } from "./src/bridges/direct-bridge/error.js";
12
13
  import { HotWithdrawalCancelledError, HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, HotWithdrawalPendingErrorType } from "./src/bridges/hot-bridge/error.js";
13
14
  import { FailedToFetchFeeError, FailedToFetchFeeErrorType, IntentsNearOmniAvailableBalanceTooLowError, IntentsNearOmniAvailableBalanceTooLowErrorType, OmniTokenNormalisationCheckError, OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, OmniTransferNotFoundErrorType, TokenNotFoundInDestinationChainError, TokenNotFoundInDestinationChainErrorType } from "./src/bridges/omni-bridge/error.js";
14
15
  import { AssertionError, AssertionErrorType, BaseError, BaseErrorType, HttpRequestError, HttpRequestErrorType, ILogger, IntentSettlementError, IntentSettlementErrorType, NearIntentsEnv, PoaWithdrawalInvariantError, PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, PoaWithdrawalPendingErrorType, QuoteError, QuoteErrorType, RelayPublishError, RelayPublishErrorType, RetryOptions, RpcRequestError, RpcRequestErrorType, TimeoutError, TimeoutErrorType } from "@defuse-protocol/internal-utils";
15
- export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, FailedToFetchFeeError, type FailedToFetchFeeErrorType, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalCancelledError, type HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, type HotWithdrawalPendingErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, type IntentPayload, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type OmniBridgeRouteConfig, OmniTokenNormalisationCheckError, type OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, type OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, type OmniTransferNotFoundErrorType, type OnBeforePublishIntentHook, type ParsedAssetInfo, type PoaBridgeRouteConfig, PoaWithdrawalInvariantError, type PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, type PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, type PoaWithdrawalPendingErrorType, type ProcessWithdrawalArgs, QuoteError, type QuoteErrorType, RelayPublishError, type RelayPublishErrorType, type RetryOptions, type RouteConfig, RouteEnum, type RouteEnumValues, RpcRequestError, type RpcRequestErrorType, type SignAndSendWithdrawalArgs, TimeoutError, type TimeoutErrorType, TokenNotFoundInDestinationChainError, type TokenNotFoundInDestinationChainErrorType, TrustlineNotFoundError, type TrustlineNotFoundErrorType, type TxInfo, type TxNoInfo, UnsupportedAssetIdError, type UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, type UnsupportedDestinationMemoErrorType, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
16
+ export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, DestinationExplicitNearAccountDoesntExistError, type DestinationExplicitNearAccountDoesntExistErrorType, FailedToFetchFeeError, type FailedToFetchFeeErrorType, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalCancelledError, type HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, type HotWithdrawalPendingErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, type IntentPayload, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type OmniBridgeRouteConfig, OmniTokenNormalisationCheckError, type OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, type OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, type OmniTransferNotFoundErrorType, type OnBeforePublishIntentHook, type ParsedAssetInfo, type PoaBridgeRouteConfig, PoaWithdrawalInvariantError, type PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, type PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, type PoaWithdrawalPendingErrorType, type ProcessWithdrawalArgs, QuoteError, type QuoteErrorType, RelayPublishError, type RelayPublishErrorType, type RetryOptions, type RouteConfig, RouteEnum, type RouteEnumValues, RpcRequestError, type RpcRequestErrorType, type SignAndSendArgs, type SignAndSendWithdrawalArgs, type SignedIntentsComposition, TimeoutError, type TimeoutErrorType, TokenNotFoundInDestinationChainError, type TokenNotFoundInDestinationChainErrorType, TrustlineNotFoundError, type TrustlineNotFoundErrorType, type TxInfo, type TxNoInfo, UnsupportedAssetIdError, type UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, type UnsupportedDestinationMemoErrorType, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import { RouteEnum } from "./src/constants/route-enum.js";
2
2
  import { FeeExceedsAmountError, MinWithdrawalAmountError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError } from "./src/classes/errors.js";
3
3
  import { Chains } from "./src/lib/caip2.js";
4
4
  import { BridgeNameEnum } from "./src/constants/bridge-name-enum.js";
5
+ import { DestinationExplicitNearAccountDoesntExistError } from "./src/bridges/direct-bridge/error.js";
5
6
  import { HotWithdrawalCancelledError, HotWithdrawalNotFoundError, HotWithdrawalPendingError } from "./src/bridges/hot-bridge/error.js";
6
7
  import { FailedToFetchFeeError, IntentsNearOmniAvailableBalanceTooLowError, OmniTokenNormalisationCheckError, OmniTransferDestinationChainHashNotFoundError, OmniTransferNotFoundError, TokenNotFoundInDestinationChainError } from "./src/bridges/omni-bridge/error.js";
7
8
  import { createDefaultRoute, createHotBridgeRoute, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute } from "./src/lib/route-config-factory.js";
@@ -9,4 +10,4 @@ import { IntentsSDK } from "./src/sdk.js";
9
10
  import { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem } from "./src/intents/intent-signer-impl/factories.js";
10
11
  import { AssertionError, BaseError, HttpRequestError, IntentSettlementError, PoaWithdrawalInvariantError, PoaWithdrawalNotFoundError, PoaWithdrawalPendingError, QuoteError, RelayPublishError, RpcRequestError, TimeoutError } from "@defuse-protocol/internal-utils";
11
12
 
12
- export { AssertionError, BaseError, BridgeNameEnum, Chains, FailedToFetchFeeError, FeeExceedsAmountError, HotWithdrawalCancelledError, HotWithdrawalNotFoundError, HotWithdrawalPendingError, HttpRequestError, IntentSettlementError, IntentsNearOmniAvailableBalanceTooLowError, IntentsSDK, MinWithdrawalAmountError, OmniTokenNormalisationCheckError, OmniTransferDestinationChainHashNotFoundError, OmniTransferNotFoundError, PoaWithdrawalInvariantError, PoaWithdrawalNotFoundError, PoaWithdrawalPendingError, QuoteError, RelayPublishError, RouteEnum, RpcRequestError, TimeoutError, TokenNotFoundInDestinationChainError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
13
+ export { AssertionError, BaseError, BridgeNameEnum, Chains, DestinationExplicitNearAccountDoesntExistError, FailedToFetchFeeError, FeeExceedsAmountError, HotWithdrawalCancelledError, HotWithdrawalNotFoundError, HotWithdrawalPendingError, HttpRequestError, IntentSettlementError, IntentsNearOmniAvailableBalanceTooLowError, IntentsSDK, MinWithdrawalAmountError, OmniTokenNormalisationCheckError, OmniTransferDestinationChainHashNotFoundError, OmniTransferNotFoundError, PoaWithdrawalInvariantError, PoaWithdrawalNotFoundError, PoaWithdrawalPendingError, QuoteError, RelayPublishError, RouteEnum, RpcRequestError, TimeoutError, TokenNotFoundInDestinationChainError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
@@ -3,6 +3,8 @@ const require_route_enum = require('../../constants/route-enum.cjs');
3
3
  const require_direct_bridge_constants = require('./direct-bridge-constants.cjs');
4
4
  let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
5
5
  __defuse_protocol_internal_utils = require_rolldown_runtime.__toESM(__defuse_protocol_internal_utils);
6
+ let near_api_js_lib_providers = require("near-api-js/lib/providers");
7
+ near_api_js_lib_providers = require_rolldown_runtime.__toESM(near_api_js_lib_providers);
6
8
 
7
9
  //#region src/bridges/direct-bridge/direct-bridge-utils.ts
8
10
  function createWithdrawIntentPrimitive(params) {
@@ -25,7 +27,21 @@ function createWithdrawIntentPrimitive(params) {
25
27
  function withdrawalParamsInvariant(params) {
26
28
  (0, __defuse_protocol_internal_utils.assert)(!params.routeConfig ? true : params.routeConfig.route === require_route_enum.RouteEnum.NearWithdrawal, "Bridge is not direct");
27
29
  }
30
+ async function accountExistsInNEAR(provider, accountId) {
31
+ try {
32
+ await (0, __defuse_protocol_internal_utils.unwrapNearFailoverRpcProvider)(provider).query({
33
+ request_type: "view_account",
34
+ account_id: accountId,
35
+ finality: "final"
36
+ });
37
+ return true;
38
+ } catch (error) {
39
+ if (error instanceof near_api_js_lib_providers.TypedError && error.type === "AccountDoesNotExist") return false;
40
+ throw error;
41
+ }
42
+ }
28
43
 
29
44
  //#endregion
45
+ exports.accountExistsInNEAR = accountExistsInNEAR;
30
46
  exports.createWithdrawIntentPrimitive = createWithdrawIntentPrimitive;
31
47
  exports.withdrawalParamsInvariant = withdrawalParamsInvariant;
@@ -1,6 +1,7 @@
1
1
  import { RouteEnum } from "../../constants/route-enum.js";
2
2
  import { NEAR_NATIVE_ASSET_ID } from "./direct-bridge-constants.js";
3
- import { assert, utils } from "@defuse-protocol/internal-utils";
3
+ import { assert, unwrapNearFailoverRpcProvider, utils } from "@defuse-protocol/internal-utils";
4
+ import { TypedError } from "near-api-js/lib/providers";
4
5
 
5
6
  //#region src/bridges/direct-bridge/direct-bridge-utils.ts
6
7
  function createWithdrawIntentPrimitive(params) {
@@ -23,6 +24,19 @@ function createWithdrawIntentPrimitive(params) {
23
24
  function withdrawalParamsInvariant(params) {
24
25
  assert(!params.routeConfig ? true : params.routeConfig.route === RouteEnum.NearWithdrawal, "Bridge is not direct");
25
26
  }
27
+ async function accountExistsInNEAR(provider, accountId) {
28
+ try {
29
+ await unwrapNearFailoverRpcProvider(provider).query({
30
+ request_type: "view_account",
31
+ account_id: accountId,
32
+ finality: "final"
33
+ });
34
+ return true;
35
+ } catch (error) {
36
+ if (error instanceof TypedError && error.type === "AccountDoesNotExist") return false;
37
+ throw error;
38
+ }
39
+ }
26
40
 
27
41
  //#endregion
28
- export { createWithdrawIntentPrimitive, withdrawalParamsInvariant };
42
+ export { accountExistsInNEAR, createWithdrawIntentPrimitive, withdrawalParamsInvariant };
@@ -8,12 +8,23 @@ const require_validateAddress = require('../../lib/validateAddress.cjs');
8
8
  const require_bridge_name_enum = require('../../constants/bridge-name-enum.cjs');
9
9
  const require_direct_bridge_constants = require('./direct-bridge-constants.cjs');
10
10
  const require_direct_bridge_utils = require('./direct-bridge-utils.cjs');
11
+ const require_error = require('./error.cjs');
11
12
  let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
12
13
  __defuse_protocol_internal_utils = require_rolldown_runtime.__toESM(__defuse_protocol_internal_utils);
14
+ let lru_cache = require("lru-cache");
15
+ lru_cache = require_rolldown_runtime.__toESM(lru_cache);
13
16
 
14
17
  //#region src/bridges/direct-bridge/direct-bridge.ts
15
18
  var DirectBridge = class {
16
19
  constructor({ env, nearProvider, solverRelayApiKey }) {
20
+ this.storageDepositCache = new lru_cache.LRUCache({
21
+ max: 100,
22
+ ttl: 36e5
23
+ });
24
+ this.accountExistenceCache = new lru_cache.LRUCache({
25
+ max: 100,
26
+ ttl: 36e5
27
+ });
17
28
  this.env = env;
18
29
  this.nearProvider = nearProvider;
19
30
  this.solverRelayApiKey = solverRelayApiKey;
@@ -62,6 +73,7 @@ var DirectBridge = class {
62
73
  */
63
74
  async validateWithdrawal(args) {
64
75
  if (require_validateAddress.validateAddress(args.destinationAddress, require_caip2.Chains.Near) === false) throw new require_errors.InvalidDestinationAddressForWithdrawalError(args.destinationAddress, require_caip2.Chains.Near);
76
+ if (__defuse_protocol_internal_utils.utils.isImplicitAccount(args.destinationAddress) === false && await this.getCachedAccountExistenceCheck(args.destinationAddress) === false) throw new require_error.DestinationExplicitNearAccountDoesntExistError(args.destinationAddress);
65
77
  }
66
78
  async estimateWithdrawalFee(args) {
67
79
  require_direct_bridge_utils.withdrawalParamsInvariant(args.withdrawalParams);
@@ -71,14 +83,7 @@ var DirectBridge = class {
71
83
  amount: 0n,
72
84
  quote: null
73
85
  };
74
- const [minStorageBalance, userStorageBalance] = await Promise.all([(0, __defuse_protocol_internal_utils.getNearNep141MinStorageBalance)({
75
- contractId: tokenAccountId,
76
- nearProvider: this.nearProvider
77
- }), (0, __defuse_protocol_internal_utils.getNearNep141StorageBalance)({
78
- contractId: tokenAccountId,
79
- accountId: args.withdrawalParams.destinationAddress,
80
- nearProvider: this.nearProvider
81
- })]);
86
+ const [minStorageBalance, userStorageBalance] = await this.getCachedStorageDepositValue(tokenAccountId, args.withdrawalParams.destinationAddress);
82
87
  if (minStorageBalance <= userStorageBalance) return {
83
88
  amount: 0n,
84
89
  quote: null
@@ -99,6 +104,34 @@ var DirectBridge = class {
99
104
  quote: feeQuote
100
105
  };
101
106
  }
107
+ /**
108
+ * Gets storage deposit for a token to avoid frequent RPC calls.
109
+ */
110
+ async getCachedStorageDepositValue(contractId, accountId) {
111
+ const key = `${contractId}${accountId}`;
112
+ const cached = this.storageDepositCache.get(key);
113
+ if (cached !== void 0) return cached;
114
+ const result = await Promise.all([(0, __defuse_protocol_internal_utils.getNearNep141MinStorageBalance)({
115
+ contractId,
116
+ nearProvider: this.nearProvider
117
+ }), (0, __defuse_protocol_internal_utils.getNearNep141StorageBalance)({
118
+ contractId,
119
+ accountId,
120
+ nearProvider: this.nearProvider
121
+ })]);
122
+ if (result[1] >= result[0]) this.storageDepositCache.set(key, result);
123
+ return result;
124
+ }
125
+ /**
126
+ * Checks account existence to avoid frequent RPC calls.
127
+ */
128
+ async getCachedAccountExistenceCheck(accountId) {
129
+ const cached = this.accountExistenceCache.get(accountId);
130
+ if (cached !== void 0) return cached;
131
+ const exist = await require_direct_bridge_utils.accountExistsInNEAR(this.nearProvider, accountId);
132
+ if (exist) this.accountExistenceCache.set(accountId, exist);
133
+ return exist;
134
+ }
102
135
  async waitForWithdrawalCompletion(args) {
103
136
  return { hash: args.tx.hash };
104
137
  }
@@ -6,12 +6,22 @@ import { Chains } from "../../lib/caip2.js";
6
6
  import { validateAddress } from "../../lib/validateAddress.js";
7
7
  import { BridgeNameEnum } from "../../constants/bridge-name-enum.js";
8
8
  import { NEAR_NATIVE_ASSET_ID } from "./direct-bridge-constants.js";
9
- import { createWithdrawIntentPrimitive, withdrawalParamsInvariant } from "./direct-bridge-utils.js";
9
+ import { accountExistsInNEAR, createWithdrawIntentPrimitive, withdrawalParamsInvariant } from "./direct-bridge-utils.js";
10
+ import { DestinationExplicitNearAccountDoesntExistError } from "./error.js";
10
11
  import { assert, getNearNep141MinStorageBalance, getNearNep141StorageBalance, utils } from "@defuse-protocol/internal-utils";
12
+ import { LRUCache } from "lru-cache";
11
13
 
12
14
  //#region src/bridges/direct-bridge/direct-bridge.ts
13
15
  var DirectBridge = class {
14
16
  constructor({ env, nearProvider, solverRelayApiKey }) {
17
+ this.storageDepositCache = new LRUCache({
18
+ max: 100,
19
+ ttl: 36e5
20
+ });
21
+ this.accountExistenceCache = new LRUCache({
22
+ max: 100,
23
+ ttl: 36e5
24
+ });
15
25
  this.env = env;
16
26
  this.nearProvider = nearProvider;
17
27
  this.solverRelayApiKey = solverRelayApiKey;
@@ -60,6 +70,7 @@ var DirectBridge = class {
60
70
  */
61
71
  async validateWithdrawal(args) {
62
72
  if (validateAddress(args.destinationAddress, Chains.Near) === false) throw new InvalidDestinationAddressForWithdrawalError(args.destinationAddress, Chains.Near);
73
+ if (utils.isImplicitAccount(args.destinationAddress) === false && await this.getCachedAccountExistenceCheck(args.destinationAddress) === false) throw new DestinationExplicitNearAccountDoesntExistError(args.destinationAddress);
63
74
  }
64
75
  async estimateWithdrawalFee(args) {
65
76
  withdrawalParamsInvariant(args.withdrawalParams);
@@ -69,14 +80,7 @@ var DirectBridge = class {
69
80
  amount: 0n,
70
81
  quote: null
71
82
  };
72
- const [minStorageBalance, userStorageBalance] = await Promise.all([getNearNep141MinStorageBalance({
73
- contractId: tokenAccountId,
74
- nearProvider: this.nearProvider
75
- }), getNearNep141StorageBalance({
76
- contractId: tokenAccountId,
77
- accountId: args.withdrawalParams.destinationAddress,
78
- nearProvider: this.nearProvider
79
- })]);
83
+ const [minStorageBalance, userStorageBalance] = await this.getCachedStorageDepositValue(tokenAccountId, args.withdrawalParams.destinationAddress);
80
84
  if (minStorageBalance <= userStorageBalance) return {
81
85
  amount: 0n,
82
86
  quote: null
@@ -97,6 +101,34 @@ var DirectBridge = class {
97
101
  quote: feeQuote
98
102
  };
99
103
  }
104
+ /**
105
+ * Gets storage deposit for a token to avoid frequent RPC calls.
106
+ */
107
+ async getCachedStorageDepositValue(contractId, accountId) {
108
+ const key = `${contractId}${accountId}`;
109
+ const cached = this.storageDepositCache.get(key);
110
+ if (cached !== void 0) return cached;
111
+ const result = await Promise.all([getNearNep141MinStorageBalance({
112
+ contractId,
113
+ nearProvider: this.nearProvider
114
+ }), getNearNep141StorageBalance({
115
+ contractId,
116
+ accountId,
117
+ nearProvider: this.nearProvider
118
+ })]);
119
+ if (result[1] >= result[0]) this.storageDepositCache.set(key, result);
120
+ return result;
121
+ }
122
+ /**
123
+ * Checks account existence to avoid frequent RPC calls.
124
+ */
125
+ async getCachedAccountExistenceCheck(accountId) {
126
+ const cached = this.accountExistenceCache.get(accountId);
127
+ if (cached !== void 0) return cached;
128
+ const exist = await accountExistsInNEAR(this.nearProvider, accountId);
129
+ if (exist) this.accountExistenceCache.set(accountId, exist);
130
+ return exist;
131
+ }
100
132
  async waitForWithdrawalCompletion(args) {
101
133
  return { hash: args.tx.hash };
102
134
  }
@@ -0,0 +1,17 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
3
+ __defuse_protocol_internal_utils = require_rolldown_runtime.__toESM(__defuse_protocol_internal_utils);
4
+
5
+ //#region src/bridges/direct-bridge/error.ts
6
+ var DestinationExplicitNearAccountDoesntExistError = class extends __defuse_protocol_internal_utils.BaseError {
7
+ constructor(accountId) {
8
+ super("Destination explicit NEAR account doesn't exist.", {
9
+ metaMessages: [`Account Id: ${accountId}`],
10
+ name: "DestinationExplicitNearAccountDoesntExistError"
11
+ });
12
+ this.accountId = accountId;
13
+ }
14
+ };
15
+
16
+ //#endregion
17
+ exports.DestinationExplicitNearAccountDoesntExistError = DestinationExplicitNearAccountDoesntExistError;
@@ -0,0 +1,12 @@
1
+ import { BaseError } from "@defuse-protocol/internal-utils";
2
+
3
+ //#region src/bridges/direct-bridge/error.d.ts
4
+ type DestinationExplicitNearAccountDoesntExistErrorType = DestinationExplicitNearAccountDoesntExistError & {
5
+ name: "DestinationExplicitNearAccountDoesntExistError";
6
+ };
7
+ declare class DestinationExplicitNearAccountDoesntExistError extends BaseError {
8
+ accountId: string;
9
+ constructor(accountId: string);
10
+ }
11
+ //#endregion
12
+ export { DestinationExplicitNearAccountDoesntExistError, DestinationExplicitNearAccountDoesntExistErrorType };
@@ -0,0 +1,12 @@
1
+ import { BaseError } from "@defuse-protocol/internal-utils";
2
+
3
+ //#region src/bridges/direct-bridge/error.d.ts
4
+ type DestinationExplicitNearAccountDoesntExistErrorType = DestinationExplicitNearAccountDoesntExistError & {
5
+ name: "DestinationExplicitNearAccountDoesntExistError";
6
+ };
7
+ declare class DestinationExplicitNearAccountDoesntExistError extends BaseError {
8
+ accountId: string;
9
+ constructor(accountId: string);
10
+ }
11
+ //#endregion
12
+ export { DestinationExplicitNearAccountDoesntExistError, DestinationExplicitNearAccountDoesntExistErrorType };
@@ -0,0 +1,15 @@
1
+ import { BaseError } from "@defuse-protocol/internal-utils";
2
+
3
+ //#region src/bridges/direct-bridge/error.ts
4
+ var DestinationExplicitNearAccountDoesntExistError = class extends BaseError {
5
+ constructor(accountId) {
6
+ super("Destination explicit NEAR account doesn't exist.", {
7
+ metaMessages: [`Account Id: ${accountId}`],
8
+ name: "DestinationExplicitNearAccountDoesntExistError"
9
+ });
10
+ this.accountId = accountId;
11
+ }
12
+ };
13
+
14
+ //#endregion
15
+ export { DestinationExplicitNearAccountDoesntExistError };
@@ -10,14 +10,14 @@ const require_omni_bridge_constants = require('./omni-bridge-constants.cjs');
10
10
  const require_omni_bridge_utils = require('./omni-bridge-utils.cjs');
11
11
  let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
12
12
  __defuse_protocol_internal_utils = require_rolldown_runtime.__toESM(__defuse_protocol_internal_utils);
13
+ let lru_cache = require("lru-cache");
14
+ lru_cache = require_rolldown_runtime.__toESM(lru_cache);
13
15
  let __lifeomic_attempt = require("@lifeomic/attempt");
14
16
  __lifeomic_attempt = require_rolldown_runtime.__toESM(__lifeomic_attempt);
15
17
  let __isaacs_ttlcache = require("@isaacs/ttlcache");
16
18
  __isaacs_ttlcache = require_rolldown_runtime.__toESM(__isaacs_ttlcache);
17
19
  let omni_bridge_sdk = require("omni-bridge-sdk");
18
20
  omni_bridge_sdk = require_rolldown_runtime.__toESM(omni_bridge_sdk);
19
- let lru_cache = require("lru-cache");
20
- lru_cache = require_rolldown_runtime.__toESM(lru_cache);
21
21
 
22
22
  //#region src/bridges/omni-bridge/omni-bridge.ts
23
23
  var OmniBridge = class {
@@ -8,10 +8,10 @@ import { FailedToFetchFeeError, IntentsNearOmniAvailableBalanceTooLowError, Omni
8
8
  import { MIN_ALLOWED_STORAGE_BALANCE_FOR_INTENTS_NEAR, NEAR_NATIVE_ASSET_ID, OMNI_BRIDGE_CONTRACT } from "./omni-bridge-constants.js";
9
9
  import { caip2ToChainKind, chainKindToCaip2, createWithdrawIntentsPrimitive, getAccountOmniStorageBalance, getBridgedToken, getTokenDecimals, validateOmniToken } from "./omni-bridge-utils.js";
10
10
  import { RETRY_CONFIGS, assert, configsByEnvironment, getNearNep141MinStorageBalance, getNearNep141StorageBalance } from "@defuse-protocol/internal-utils";
11
+ import { LRUCache } from "lru-cache";
11
12
  import { retry } from "@lifeomic/attempt";
12
13
  import TTLCache from "@isaacs/ttlcache";
13
14
  import { ChainKind, OmniBridgeAPI, getChain, getMinimumTransferableAmount, isEvmChain, omniAddress, parseOriginChain, verifyTransferAmount } from "omni-bridge-sdk";
14
- import { LRUCache } from "lru-cache";
15
15
 
16
16
  //#region src/bridges/omni-bridge/omni-bridge.ts
17
17
  var OmniBridge = class {
@@ -14,7 +14,7 @@ var IntentExecuter = class {
14
14
  this.intentSigner = args.intentSigner;
15
15
  this.onBeforePublishIntent = args.onBeforePublishIntent;
16
16
  }
17
- async signAndSendIntent({ relayParams: relayParamsFactory,...intentParams }) {
17
+ async signAndSendIntent({ relayParams: relayParamsFactory, signedIntents,...intentParams }) {
18
18
  const verifyingContract = __defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID;
19
19
  let intentPayload = require_intent_payload_factory.defaultIntentPayloadFactory({
20
20
  verifying_contract: verifyingContract,
@@ -32,6 +32,14 @@ var IntentExecuter = class {
32
32
  relayParams
33
33
  });
34
34
  }
35
+ const composedPayloads = composeMultiPayloads(multiPayload, signedIntents);
36
+ if (composedPayloads.length > 1) {
37
+ const quoteHashes = relayParams.quoteHashes ?? [];
38
+ return { ticket: (await this.intentRelayer.publishIntents({
39
+ multiPayloads: composedPayloads,
40
+ quoteHashes
41
+ }, { logger: this.logger }))[signedIntents?.before?.length ?? 0] };
42
+ }
35
43
  return { ticket: await this.intentRelayer.publishIntent({
36
44
  multiPayload,
37
45
  ...relayParams
@@ -50,6 +58,21 @@ async function mergeIntentPayloads(basePayload, intentPayloadFactory) {
50
58
  intents: Array.from(new Set([...customPayloadIntents, ...basePayload.intents]))
51
59
  };
52
60
  }
61
+ /**
62
+ * Composes a new MultiPayload with pre-signed intents for atomic execution.
63
+ *
64
+ * @param newPayload - The newly signed MultiPayload
65
+ * @param signedIntents - Optional configuration with before/after intents
66
+ * @returns Array of MultiPayloads in execution order: [before...] -> newPayload -> [after...]
67
+ */
68
+ function composeMultiPayloads(newPayload, signedIntents) {
69
+ if (!signedIntents) return [newPayload];
70
+ const result = [];
71
+ if (signedIntents.before && signedIntents.before.length > 0) result.push(...signedIntents.before);
72
+ result.push(newPayload);
73
+ if (signedIntents.after && signedIntents.after.length > 0) result.push(...signedIntents.after);
74
+ return result;
75
+ }
53
76
 
54
77
  //#endregion
55
78
  exports.IntentExecuter = IntentExecuter;
@@ -12,7 +12,7 @@ var IntentExecuter = class {
12
12
  this.intentSigner = args.intentSigner;
13
13
  this.onBeforePublishIntent = args.onBeforePublishIntent;
14
14
  }
15
- async signAndSendIntent({ relayParams: relayParamsFactory,...intentParams }) {
15
+ async signAndSendIntent({ relayParams: relayParamsFactory, signedIntents,...intentParams }) {
16
16
  const verifyingContract = configsByEnvironment[this.env].contractID;
17
17
  let intentPayload = defaultIntentPayloadFactory({
18
18
  verifying_contract: verifyingContract,
@@ -30,6 +30,14 @@ var IntentExecuter = class {
30
30
  relayParams
31
31
  });
32
32
  }
33
+ const composedPayloads = composeMultiPayloads(multiPayload, signedIntents);
34
+ if (composedPayloads.length > 1) {
35
+ const quoteHashes = relayParams.quoteHashes ?? [];
36
+ return { ticket: (await this.intentRelayer.publishIntents({
37
+ multiPayloads: composedPayloads,
38
+ quoteHashes
39
+ }, { logger: this.logger }))[signedIntents?.before?.length ?? 0] };
40
+ }
33
41
  return { ticket: await this.intentRelayer.publishIntent({
34
42
  multiPayload,
35
43
  ...relayParams
@@ -48,6 +56,21 @@ async function mergeIntentPayloads(basePayload, intentPayloadFactory) {
48
56
  intents: Array.from(new Set([...customPayloadIntents, ...basePayload.intents]))
49
57
  };
50
58
  }
59
+ /**
60
+ * Composes a new MultiPayload with pre-signed intents for atomic execution.
61
+ *
62
+ * @param newPayload - The newly signed MultiPayload
63
+ * @param signedIntents - Optional configuration with before/after intents
64
+ * @returns Array of MultiPayloads in execution order: [before...] -> newPayload -> [after...]
65
+ */
66
+ function composeMultiPayloads(newPayload, signedIntents) {
67
+ if (!signedIntents) return [newPayload];
68
+ const result = [];
69
+ if (signedIntents.before && signedIntents.before.length > 0) result.push(...signedIntents.before);
70
+ result.push(newPayload);
71
+ if (signedIntents.after && signedIntents.after.length > 0) result.push(...signedIntents.after);
72
+ return result;
73
+ }
51
74
 
52
75
  //#endregion
53
76
  export { IntentExecuter };
@@ -1,12 +1,37 @@
1
- import { RelayParamsDefault } from "../shared-types.cjs";
1
+ import { MultiPayload, RelayParamsDefault } from "../shared-types.cjs";
2
2
  import { NearTxInfo } from "../../shared-types.cjs";
3
3
  import { ILogger } from "@defuse-protocol/internal-utils";
4
4
 
5
5
  //#region src/intents/interfaces/intent-relayer.d.ts
6
6
  interface IIntentRelayer<Ticket, RelayParams = RelayParamsDefault> {
7
+ /**
8
+ * Publishes a single intent to the relayer.
9
+ * @param params - The relay parameters including the signed multi-payload
10
+ * @param ctx - Optional context with logger
11
+ * @returns A ticket (typically an intent hash) for tracking the intent
12
+ */
7
13
  publishIntent(params: RelayParams, ctx?: {
8
14
  logger?: ILogger;
9
15
  }): Promise<Ticket>;
16
+ /**
17
+ * Publishes multiple intents atomically to the relayer.
18
+ * All intents will be executed together or not at all.
19
+ * @param params - Parameters including array of multi-payloads and quote hashes
20
+ * @param ctx - Optional context with logger
21
+ * @returns Array of tickets (typically intent hashes) for tracking the intents
22
+ */
23
+ publishIntents(params: {
24
+ multiPayloads: MultiPayload[];
25
+ quoteHashes: string[];
26
+ }, ctx?: {
27
+ logger?: ILogger;
28
+ }): Promise<Ticket[]>;
29
+ /**
30
+ * Waits for an intent to be settled on-chain.
31
+ * @param ticket - The ticket returned from publishIntent
32
+ * @param ctx - Optional context with logger
33
+ * @returns Transaction information once settled
34
+ */
10
35
  waitForSettlement(ticket: Ticket, ctx?: {
11
36
  logger?: ILogger;
12
37
  }): Promise<{
@@ -1,12 +1,37 @@
1
- import { RelayParamsDefault } from "../shared-types.js";
1
+ import { MultiPayload, RelayParamsDefault } from "../shared-types.js";
2
2
  import { NearTxInfo } from "../../shared-types.js";
3
3
  import { ILogger } from "@defuse-protocol/internal-utils";
4
4
 
5
5
  //#region src/intents/interfaces/intent-relayer.d.ts
6
6
  interface IIntentRelayer<Ticket, RelayParams = RelayParamsDefault> {
7
+ /**
8
+ * Publishes a single intent to the relayer.
9
+ * @param params - The relay parameters including the signed multi-payload
10
+ * @param ctx - Optional context with logger
11
+ * @returns A ticket (typically an intent hash) for tracking the intent
12
+ */
7
13
  publishIntent(params: RelayParams, ctx?: {
8
14
  logger?: ILogger;
9
15
  }): Promise<Ticket>;
16
+ /**
17
+ * Publishes multiple intents atomically to the relayer.
18
+ * All intents will be executed together or not at all.
19
+ * @param params - Parameters including array of multi-payloads and quote hashes
20
+ * @param ctx - Optional context with logger
21
+ * @returns Array of tickets (typically intent hashes) for tracking the intents
22
+ */
23
+ publishIntents(params: {
24
+ multiPayloads: MultiPayload[];
25
+ quoteHashes: string[];
26
+ }, ctx?: {
27
+ logger?: ILogger;
28
+ }): Promise<Ticket[]>;
29
+ /**
30
+ * Waits for an intent to be settled on-chain.
31
+ * @param ticket - The ticket returned from publishIntent
32
+ * @param ctx - Optional context with logger
33
+ * @returns Transaction information once settled
34
+ */
10
35
  waitForSettlement(ticket: Ticket, ctx?: {
11
36
  logger?: ILogger;
12
37
  }): Promise<{
@@ -14,7 +14,10 @@ async function getFeeQuote({ feeAmount, feeAssetId, tokenAssetId, quoteOptions,
14
14
  defuse_asset_identifier_in: tokenAssetId,
15
15
  defuse_asset_identifier_out: feeAssetId,
16
16
  exact_amount_out: feeAmount.toString(),
17
- wait_ms: quoteOptions?.waitMs
17
+ wait_ms: quoteOptions?.waitMs,
18
+ min_wait_ms: quoteOptions?.minWaitMs,
19
+ max_wait_ms: quoteOptions?.maxWaitMs,
20
+ trusted_metadata: quoteOptions?.trustedMetadata
18
21
  },
19
22
  config: {
20
23
  baseURL: __defuse_protocol_internal_utils.configsByEnvironment[env].solverRelayBaseURL,
@@ -45,7 +48,10 @@ async function getFeeQuote({ feeAmount, feeAssetId, tokenAssetId, quoteOptions,
45
48
  defuse_asset_identifier_in: tokenAssetId,
46
49
  defuse_asset_identifier_out: feeAssetId,
47
50
  exact_amount_in: exactAmountIn.toString(),
48
- wait_ms: quoteOptions?.waitMs
51
+ wait_ms: quoteOptions?.waitMs,
52
+ min_wait_ms: quoteOptions?.minWaitMs,
53
+ max_wait_ms: quoteOptions?.maxWaitMs,
54
+ trusted_metadata: quoteOptions?.trustedMetadata
49
55
  },
50
56
  config: {
51
57
  baseURL: __defuse_protocol_internal_utils.configsByEnvironment[env].solverRelayBaseURL,
@@ -12,7 +12,10 @@ async function getFeeQuote({ feeAmount, feeAssetId, tokenAssetId, quoteOptions,
12
12
  defuse_asset_identifier_in: tokenAssetId,
13
13
  defuse_asset_identifier_out: feeAssetId,
14
14
  exact_amount_out: feeAmount.toString(),
15
- wait_ms: quoteOptions?.waitMs
15
+ wait_ms: quoteOptions?.waitMs,
16
+ min_wait_ms: quoteOptions?.minWaitMs,
17
+ max_wait_ms: quoteOptions?.maxWaitMs,
18
+ trusted_metadata: quoteOptions?.trustedMetadata
16
19
  },
17
20
  config: {
18
21
  baseURL: configsByEnvironment[env].solverRelayBaseURL,
@@ -43,7 +46,10 @@ async function getFeeQuote({ feeAmount, feeAssetId, tokenAssetId, quoteOptions,
43
46
  defuse_asset_identifier_in: tokenAssetId,
44
47
  defuse_asset_identifier_out: feeAssetId,
45
48
  exact_amount_in: exactAmountIn.toString(),
46
- wait_ms: quoteOptions?.waitMs
49
+ wait_ms: quoteOptions?.waitMs,
50
+ min_wait_ms: quoteOptions?.minWaitMs,
51
+ max_wait_ms: quoteOptions?.maxWaitMs,
52
+ trusted_metadata: quoteOptions?.trustedMetadata
47
53
  },
48
54
  config: {
49
55
  baseURL: configsByEnvironment[env].solverRelayBaseURL,
package/dist/src/sdk.cjs CHANGED
@@ -181,7 +181,8 @@ var IntentsSDK = class {
181
181
  onBeforePublishIntent: args.onBeforePublishIntent
182
182
  }).signAndSendIntent({
183
183
  intents: args.intents,
184
- relayParams: args.relayParams
184
+ relayParams: args.relayParams,
185
+ signedIntents: args.signedIntents
185
186
  });
186
187
  return { intentHash: ticket };
187
188
  }
@@ -219,7 +220,8 @@ var IntentsSDK = class {
219
220
  onBeforePublishIntent: args.intent?.onBeforePublishIntent,
220
221
  relayParams: relayParamsFn,
221
222
  payload: args.intent?.payload,
222
- logger: args.logger
223
+ logger: args.logger,
224
+ signedIntents: args.intent?.signedIntents
223
225
  });
224
226
  }
225
227
  async waitForIntentSettlement(args) {
@@ -1,6 +1,6 @@
1
1
  import { IntentHash, IntentPrimitive } from "./intents/shared-types.cjs";
2
2
  import { IIntentSigner } from "./intents/interfaces/intent-signer.cjs";
3
- import { BatchWithdrawalResult, Bridge, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult } from "./shared-types.cjs";
3
+ import { BatchWithdrawalResult, Bridge, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, QuoteOptions, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult } from "./shared-types.cjs";
4
4
  import { IIntentRelayer } from "./intents/interfaces/intent-relayer.cjs";
5
5
  import { ILogger, NearIntentsEnv, RetryOptions } from "@defuse-protocol/internal-utils";
6
6
 
@@ -29,23 +29,17 @@ declare class IntentsSDK implements IIntentsSDK {
29
29
  }): Promise<IntentPrimitive[]>;
30
30
  estimateWithdrawalFee(args: {
31
31
  withdrawalParams: WithdrawalParams;
32
- quoteOptions?: {
33
- waitMs: number;
34
- };
32
+ quoteOptions?: QuoteOptions;
35
33
  logger?: ILogger;
36
34
  }): Promise<FeeEstimation>;
37
35
  estimateWithdrawalFee(args: {
38
36
  withdrawalParams: WithdrawalParams[];
39
- quoteOptions?: {
40
- waitMs: number;
41
- };
37
+ quoteOptions?: QuoteOptions;
42
38
  logger?: ILogger;
43
39
  }): Promise<FeeEstimation[]>;
44
40
  protected _estimateWithdrawalFee(args: {
45
41
  withdrawalParams: WithdrawalParams;
46
- quoteOptions?: {
47
- waitMs: number;
48
- };
42
+ quoteOptions?: QuoteOptions;
49
43
  logger?: ILogger;
50
44
  }): Promise<FeeEstimation>;
51
45
  protected getWithdrawalsIdentifiers({
package/dist/src/sdk.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { IntentHash, IntentPrimitive } from "./intents/shared-types.js";
2
2
  import { IIntentSigner } from "./intents/interfaces/intent-signer.js";
3
- import { BatchWithdrawalResult, Bridge, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult } from "./shared-types.js";
3
+ import { BatchWithdrawalResult, Bridge, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, QuoteOptions, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult } from "./shared-types.js";
4
4
  import { IIntentRelayer } from "./intents/interfaces/intent-relayer.js";
5
5
  import { ILogger, NearIntentsEnv, RetryOptions } from "@defuse-protocol/internal-utils";
6
6
 
@@ -29,23 +29,17 @@ declare class IntentsSDK implements IIntentsSDK {
29
29
  }): Promise<IntentPrimitive[]>;
30
30
  estimateWithdrawalFee(args: {
31
31
  withdrawalParams: WithdrawalParams;
32
- quoteOptions?: {
33
- waitMs: number;
34
- };
32
+ quoteOptions?: QuoteOptions;
35
33
  logger?: ILogger;
36
34
  }): Promise<FeeEstimation>;
37
35
  estimateWithdrawalFee(args: {
38
36
  withdrawalParams: WithdrawalParams[];
39
- quoteOptions?: {
40
- waitMs: number;
41
- };
37
+ quoteOptions?: QuoteOptions;
42
38
  logger?: ILogger;
43
39
  }): Promise<FeeEstimation[]>;
44
40
  protected _estimateWithdrawalFee(args: {
45
41
  withdrawalParams: WithdrawalParams;
46
- quoteOptions?: {
47
- waitMs: number;
48
- };
42
+ quoteOptions?: QuoteOptions;
49
43
  logger?: ILogger;
50
44
  }): Promise<FeeEstimation>;
51
45
  protected getWithdrawalsIdentifiers({
package/dist/src/sdk.js CHANGED
@@ -177,7 +177,8 @@ var IntentsSDK = class {
177
177
  onBeforePublishIntent: args.onBeforePublishIntent
178
178
  }).signAndSendIntent({
179
179
  intents: args.intents,
180
- relayParams: args.relayParams
180
+ relayParams: args.relayParams,
181
+ signedIntents: args.signedIntents
181
182
  });
182
183
  return { intentHash: ticket };
183
184
  }
@@ -215,7 +216,8 @@ var IntentsSDK = class {
215
216
  onBeforePublishIntent: args.intent?.onBeforePublishIntent,
216
217
  relayParams: relayParamsFn,
217
218
  payload: args.intent?.payload,
218
- logger: args.logger
219
+ logger: args.logger,
220
+ signedIntents: args.intent?.signedIntents
219
221
  });
220
222
  }
221
223
  async waitForIntentSettlement(args) {
@@ -1,7 +1,7 @@
1
1
  import { HotBridgeEVMChain } from "./bridges/hot-bridge/hot-bridge-chains.cjs";
2
2
  import { BridgeNameEnumValues } from "./constants/bridge-name-enum.cjs";
3
3
  import { RouteEnum } from "./constants/route-enum.cjs";
4
- import { IntentHash, IntentPayloadFactory, IntentPrimitive, IntentRelayParamsFactory } from "./intents/shared-types.cjs";
4
+ import { IntentHash, IntentPayloadFactory, IntentPrimitive, IntentRelayParamsFactory, MultiPayload } from "./intents/shared-types.cjs";
5
5
  import { IIntentSigner } from "./intents/interfaces/intent-signer.cjs";
6
6
  import { OnBeforePublishIntentHook } from "./intents/intent-executer-impl/intent-executer.cjs";
7
7
  import { Chain, Chains } from "./lib/caip2.cjs";
@@ -24,12 +24,63 @@ interface BatchWithdrawalResult {
24
24
  destinationTx: (TxInfo | TxNoInfo)[];
25
25
  }
26
26
  type IntentSettlementStatus = solverRelay.GetStatusReturnType;
27
+ /**
28
+ * Configuration for including pre-signed intents to be published atomically.
29
+ *
30
+ * Pre-signed intents can be included in two ways:
31
+ * - `before`: Pre-signed intents that execute before the newly created intent
32
+ * - `after`: Pre-signed intents that execute after the newly created intent
33
+ *
34
+ * The execution order is guaranteed: before → new intent → after
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // Include pre-signed intents from other users
39
+ * const signedIntents: SignedIntents = {
40
+ * before: [signedIntent1, signedIntent2],
41
+ * after: [cleanupIntent],
42
+ * };
43
+ *
44
+ * await sdk.signAndSendIntent({
45
+ * intents: [myNewIntent],
46
+ * signedIntents,
47
+ * });
48
+ * ```
49
+ */
50
+ interface SignedIntentsComposition {
51
+ /**
52
+ * Pre-signed intents (MultiPayload) to execute before the newly created intent.
53
+ * Useful for dependencies that must be executed first.
54
+ */
55
+ before?: MultiPayload[];
56
+ /**
57
+ * Pre-signed intents (MultiPayload) to execute after the newly created intent.
58
+ * Useful for cleanup or follow-up actions.
59
+ */
60
+ after?: MultiPayload[];
61
+ }
27
62
  interface SignAndSendArgs {
28
63
  intents: IntentPrimitive[];
64
+ /**
65
+ * Factory function to modify the intent payload draft before signing.
66
+ * Use this to add or modify intent primitives in the payload.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * payload: (draft) => ({
71
+ * intents: [...draft.intents, { intent: "transfer", ... }]
72
+ * })
73
+ * ```
74
+ */
29
75
  payload?: IntentPayloadFactory;
30
76
  relayParams?: IntentRelayParamsFactory;
31
77
  signer?: IIntentSigner;
32
78
  onBeforePublishIntent?: OnBeforePublishIntentHook;
79
+ /**
80
+ * Pre-signed intents for atomic execution.
81
+ * The newly created intent will be published together with these pre-signed intents.
82
+ */
83
+ signedIntents?: SignedIntentsComposition;
33
84
  logger?: ILogger;
34
85
  }
35
86
  type SignAndSendWithdrawalArgs<T extends WithdrawalParams | WithdrawalParams[]> = {
@@ -43,10 +94,16 @@ type ProcessWithdrawalArgs<T extends WithdrawalParams | WithdrawalParams[]> = {
43
94
  withdrawalParams: T;
44
95
  feeEstimation?: T extends WithdrawalParams[] ? FeeEstimation[] : FeeEstimation;
45
96
  intent?: {
97
+ /** @see SignAndSendArgs.payload */
46
98
  payload?: IntentPayloadFactory;
99
+ /** @see SignAndSendArgs.relayParams */
47
100
  relayParams?: IntentRelayParamsFactory;
101
+ /** @see SignAndSendArgs.signer */
48
102
  signer?: IIntentSigner;
103
+ /** @see SignAndSendArgs.onBeforePublishIntent */
49
104
  onBeforePublishIntent?: OnBeforePublishIntentHook;
105
+ /** @see SignAndSendArgs.signedIntents */
106
+ signedIntents?: SignedIntentsComposition;
50
107
  };
51
108
  referral?: string;
52
109
  retryOptions?: RetryOptions;
@@ -65,16 +122,12 @@ interface IIntentsSDK {
65
122
  }): Promise<IntentSettlementStatus>;
66
123
  estimateWithdrawalFee(args: {
67
124
  withdrawalParams: WithdrawalParams;
68
- quoteOptions?: {
69
- waitMs: number;
70
- };
125
+ quoteOptions?: QuoteOptions;
71
126
  logger?: ILogger;
72
127
  }): Promise<FeeEstimation>;
73
128
  estimateWithdrawalFee(args: {
74
129
  withdrawalParams: WithdrawalParams[];
75
- quoteOptions?: {
76
- waitMs: number;
77
- };
130
+ quoteOptions?: QuoteOptions;
78
131
  logger?: ILogger;
79
132
  }): Promise<FeeEstimation[]>;
80
133
  signAndSendWithdrawalIntent(args: SignAndSendWithdrawalArgs<WithdrawalParams> | SignAndSendWithdrawalArgs<WithdrawalParams[]>): Promise<IntentPublishResult>;
@@ -102,6 +155,12 @@ interface IIntentsSDK {
102
155
  processWithdrawal(args: ProcessWithdrawalArgs<WithdrawalParams>): Promise<WithdrawalResult>;
103
156
  processWithdrawal(args: ProcessWithdrawalArgs<WithdrawalParams[]>): Promise<BatchWithdrawalResult>;
104
157
  }
158
+ interface QuoteOptions {
159
+ waitMs?: number;
160
+ minWaitMs?: number;
161
+ maxWaitMs?: number;
162
+ trustedMetadata?: unknown;
163
+ }
105
164
  interface NearTxInfo {
106
165
  hash: string;
107
166
  accountId: string;
@@ -174,9 +233,7 @@ interface Bridge {
174
233
  }): Promise<void>;
175
234
  estimateWithdrawalFee<T extends Pick<WithdrawalParams, "assetId" | "destinationAddress" | "routeConfig">>(args: {
176
235
  withdrawalParams: T;
177
- quoteOptions?: {
178
- waitMs: number;
179
- };
236
+ quoteOptions?: QuoteOptions;
180
237
  logger?: ILogger;
181
238
  }): Promise<FeeEstimation>;
182
239
  createWithdrawalIntents(args: {
@@ -221,4 +278,4 @@ type RPCEndpointMap = Record<typeof Chains.Near | HotBridgeEVMChain, string[]> &
221
278
  type DeepPartial<T> = T extends object ? T extends Array<infer U> ? Array<DeepPartial<U>> : T extends Function ? T : { [P in keyof T]?: DeepPartial<T[P]> } : T;
222
279
  type PartialRPCEndpointMap = DeepPartial<RPCEndpointMap>;
223
280
  //#endregion
224
- export { BatchWithdrawalResult, Bridge, FeeEstimation, HotBridgeRouteConfig, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, InternalTransferRouteConfig, NearTxInfo, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, ParsedAssetInfo, PartialRPCEndpointMap, PoaBridgeRouteConfig, ProcessWithdrawalArgs, RouteConfig, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, VirtualChainRouteConfig, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult };
281
+ export { BatchWithdrawalResult, Bridge, FeeEstimation, HotBridgeRouteConfig, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, InternalTransferRouteConfig, NearTxInfo, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, ParsedAssetInfo, PartialRPCEndpointMap, PoaBridgeRouteConfig, ProcessWithdrawalArgs, QuoteOptions, RouteConfig, SignAndSendArgs, SignAndSendWithdrawalArgs, SignedIntentsComposition, TxInfo, TxNoInfo, VirtualChainRouteConfig, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult };
@@ -1,7 +1,7 @@
1
1
  import { HotBridgeEVMChain } from "./bridges/hot-bridge/hot-bridge-chains.js";
2
2
  import { BridgeNameEnumValues } from "./constants/bridge-name-enum.js";
3
3
  import { RouteEnum } from "./constants/route-enum.js";
4
- import { IntentHash, IntentPayloadFactory, IntentPrimitive, IntentRelayParamsFactory } from "./intents/shared-types.js";
4
+ import { IntentHash, IntentPayloadFactory, IntentPrimitive, IntentRelayParamsFactory, MultiPayload } from "./intents/shared-types.js";
5
5
  import { IIntentSigner } from "./intents/interfaces/intent-signer.js";
6
6
  import { OnBeforePublishIntentHook } from "./intents/intent-executer-impl/intent-executer.js";
7
7
  import { Chain, Chains } from "./lib/caip2.js";
@@ -24,12 +24,63 @@ interface BatchWithdrawalResult {
24
24
  destinationTx: (TxInfo | TxNoInfo)[];
25
25
  }
26
26
  type IntentSettlementStatus = solverRelay.GetStatusReturnType;
27
+ /**
28
+ * Configuration for including pre-signed intents to be published atomically.
29
+ *
30
+ * Pre-signed intents can be included in two ways:
31
+ * - `before`: Pre-signed intents that execute before the newly created intent
32
+ * - `after`: Pre-signed intents that execute after the newly created intent
33
+ *
34
+ * The execution order is guaranteed: before → new intent → after
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // Include pre-signed intents from other users
39
+ * const signedIntents: SignedIntents = {
40
+ * before: [signedIntent1, signedIntent2],
41
+ * after: [cleanupIntent],
42
+ * };
43
+ *
44
+ * await sdk.signAndSendIntent({
45
+ * intents: [myNewIntent],
46
+ * signedIntents,
47
+ * });
48
+ * ```
49
+ */
50
+ interface SignedIntentsComposition {
51
+ /**
52
+ * Pre-signed intents (MultiPayload) to execute before the newly created intent.
53
+ * Useful for dependencies that must be executed first.
54
+ */
55
+ before?: MultiPayload[];
56
+ /**
57
+ * Pre-signed intents (MultiPayload) to execute after the newly created intent.
58
+ * Useful for cleanup or follow-up actions.
59
+ */
60
+ after?: MultiPayload[];
61
+ }
27
62
  interface SignAndSendArgs {
28
63
  intents: IntentPrimitive[];
64
+ /**
65
+ * Factory function to modify the intent payload draft before signing.
66
+ * Use this to add or modify intent primitives in the payload.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * payload: (draft) => ({
71
+ * intents: [...draft.intents, { intent: "transfer", ... }]
72
+ * })
73
+ * ```
74
+ */
29
75
  payload?: IntentPayloadFactory;
30
76
  relayParams?: IntentRelayParamsFactory;
31
77
  signer?: IIntentSigner;
32
78
  onBeforePublishIntent?: OnBeforePublishIntentHook;
79
+ /**
80
+ * Pre-signed intents for atomic execution.
81
+ * The newly created intent will be published together with these pre-signed intents.
82
+ */
83
+ signedIntents?: SignedIntentsComposition;
33
84
  logger?: ILogger;
34
85
  }
35
86
  type SignAndSendWithdrawalArgs<T extends WithdrawalParams | WithdrawalParams[]> = {
@@ -43,10 +94,16 @@ type ProcessWithdrawalArgs<T extends WithdrawalParams | WithdrawalParams[]> = {
43
94
  withdrawalParams: T;
44
95
  feeEstimation?: T extends WithdrawalParams[] ? FeeEstimation[] : FeeEstimation;
45
96
  intent?: {
97
+ /** @see SignAndSendArgs.payload */
46
98
  payload?: IntentPayloadFactory;
99
+ /** @see SignAndSendArgs.relayParams */
47
100
  relayParams?: IntentRelayParamsFactory;
101
+ /** @see SignAndSendArgs.signer */
48
102
  signer?: IIntentSigner;
103
+ /** @see SignAndSendArgs.onBeforePublishIntent */
49
104
  onBeforePublishIntent?: OnBeforePublishIntentHook;
105
+ /** @see SignAndSendArgs.signedIntents */
106
+ signedIntents?: SignedIntentsComposition;
50
107
  };
51
108
  referral?: string;
52
109
  retryOptions?: RetryOptions;
@@ -65,16 +122,12 @@ interface IIntentsSDK {
65
122
  }): Promise<IntentSettlementStatus>;
66
123
  estimateWithdrawalFee(args: {
67
124
  withdrawalParams: WithdrawalParams;
68
- quoteOptions?: {
69
- waitMs: number;
70
- };
125
+ quoteOptions?: QuoteOptions;
71
126
  logger?: ILogger;
72
127
  }): Promise<FeeEstimation>;
73
128
  estimateWithdrawalFee(args: {
74
129
  withdrawalParams: WithdrawalParams[];
75
- quoteOptions?: {
76
- waitMs: number;
77
- };
130
+ quoteOptions?: QuoteOptions;
78
131
  logger?: ILogger;
79
132
  }): Promise<FeeEstimation[]>;
80
133
  signAndSendWithdrawalIntent(args: SignAndSendWithdrawalArgs<WithdrawalParams> | SignAndSendWithdrawalArgs<WithdrawalParams[]>): Promise<IntentPublishResult>;
@@ -102,6 +155,12 @@ interface IIntentsSDK {
102
155
  processWithdrawal(args: ProcessWithdrawalArgs<WithdrawalParams>): Promise<WithdrawalResult>;
103
156
  processWithdrawal(args: ProcessWithdrawalArgs<WithdrawalParams[]>): Promise<BatchWithdrawalResult>;
104
157
  }
158
+ interface QuoteOptions {
159
+ waitMs?: number;
160
+ minWaitMs?: number;
161
+ maxWaitMs?: number;
162
+ trustedMetadata?: unknown;
163
+ }
105
164
  interface NearTxInfo {
106
165
  hash: string;
107
166
  accountId: string;
@@ -174,9 +233,7 @@ interface Bridge {
174
233
  }): Promise<void>;
175
234
  estimateWithdrawalFee<T extends Pick<WithdrawalParams, "assetId" | "destinationAddress" | "routeConfig">>(args: {
176
235
  withdrawalParams: T;
177
- quoteOptions?: {
178
- waitMs: number;
179
- };
236
+ quoteOptions?: QuoteOptions;
180
237
  logger?: ILogger;
181
238
  }): Promise<FeeEstimation>;
182
239
  createWithdrawalIntents(args: {
@@ -221,4 +278,4 @@ type RPCEndpointMap = Record<typeof Chains.Near | HotBridgeEVMChain, string[]> &
221
278
  type DeepPartial<T> = T extends object ? T extends Array<infer U> ? Array<DeepPartial<U>> : T extends Function ? T : { [P in keyof T]?: DeepPartial<T[P]> } : T;
222
279
  type PartialRPCEndpointMap = DeepPartial<RPCEndpointMap>;
223
280
  //#endregion
224
- export { BatchWithdrawalResult, Bridge, FeeEstimation, HotBridgeRouteConfig, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, InternalTransferRouteConfig, NearTxInfo, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, ParsedAssetInfo, PartialRPCEndpointMap, PoaBridgeRouteConfig, ProcessWithdrawalArgs, RouteConfig, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, VirtualChainRouteConfig, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult };
281
+ export { BatchWithdrawalResult, Bridge, 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.26.4",
3
+ "version": "0.28.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -39,7 +39,7 @@
39
39
  "valibot": "^1.0.0",
40
40
  "viem": "^2.0.0",
41
41
  "@defuse-protocol/contract-types": "0.1.2",
42
- "@defuse-protocol/internal-utils": "0.15.2"
42
+ "@defuse-protocol/internal-utils": "0.17.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "tsdown": "0.15.5",