@defuse-protocol/intents-sdk 0.29.1 → 0.30.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 +18 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +1 -1
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +1 -1
- package/dist/src/intents/intent-executer-impl/intent-executer.cjs +6 -5
- package/dist/src/intents/intent-executer-impl/intent-executer.js +6 -5
- package/dist/src/intents/intent-payload-builder.cjs +205 -0
- package/dist/src/intents/intent-payload-builder.d.cts +158 -0
- package/dist/src/intents/intent-payload-builder.d.ts +158 -0
- package/dist/src/intents/intent-payload-builder.js +203 -0
- package/dist/src/intents/intent-payload-factory.cjs +2 -1
- package/dist/src/intents/intent-payload-factory.js +2 -2
- package/dist/src/sdk.cjs +31 -0
- package/dist/src/sdk.d.cts +26 -0
- package/dist/src/sdk.d.ts +26 -0
- package/dist/src/sdk.js +31 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ interacting with various bridge implementations across multiple blockchains.
|
|
|
19
19
|
- [Advanced Usage](#advanced-usage)
|
|
20
20
|
- [Custom RPC URLs](#custom-rpc-urls)
|
|
21
21
|
- [Other Intent Signers](#other-intent-signers)
|
|
22
|
+
- [Intent Payload Builder](#intent-payload-builder)
|
|
22
23
|
- [Intent Publishing Hooks](#intent-publishing-hooks)
|
|
23
24
|
- [Batch Withdrawals](#batch-withdrawals)
|
|
24
25
|
- [Intent Management](#intent-management)
|
|
@@ -403,6 +404,23 @@ const signer = createIntentSignerViem({ signer: account });
|
|
|
403
404
|
sdk.setIntentSigner(signer);
|
|
404
405
|
```
|
|
405
406
|
|
|
407
|
+
### Intent Payload Builder
|
|
408
|
+
|
|
409
|
+
For API builders who need to generate intent payloads based on user metadata (e.g., generating payloads server-side for users to sign with MetaMask), the SDK provides a fluent `IntentPayloadBuilder`:
|
|
410
|
+
|
|
411
|
+
```typescript
|
|
412
|
+
// Build an intent payload for your users
|
|
413
|
+
const payload = await sdk.intentBuilder()
|
|
414
|
+
.setSigner('0x742d35cc6634c0532925a3b8d84b2021f90a51a3') // User's EVM address
|
|
415
|
+
.setDeadline(new Date(Date.now() + 5 * 60 * 1000)) // 5 minutes
|
|
416
|
+
.addIntent({
|
|
417
|
+
intent: "transfer",
|
|
418
|
+
tokens: { "token.near": "100" },
|
|
419
|
+
receiver_id: "receiver.near",
|
|
420
|
+
})
|
|
421
|
+
.build();
|
|
422
|
+
```
|
|
423
|
+
|
|
406
424
|
### Intent Publishing Hooks
|
|
407
425
|
|
|
408
426
|
Use the `onBeforePublishIntent` hook to intercept and process intent data before it's published to the relayer. This is
|
package/dist/index.cjs
CHANGED
|
@@ -8,6 +8,7 @@ const require_error$1 = require('./src/bridges/hot-bridge/error.cjs');
|
|
|
8
8
|
const require_error$2 = require('./src/bridges/omni-bridge/error.cjs');
|
|
9
9
|
const require_expirable_nonce = require('./src/intents/expirable-nonce.cjs');
|
|
10
10
|
const require_route_config_factory = require('./src/lib/route-config-factory.cjs');
|
|
11
|
+
const require_intent_payload_builder = require('./src/intents/intent-payload-builder.cjs');
|
|
11
12
|
const require_sdk = require('./src/sdk.cjs');
|
|
12
13
|
const require_factories = require('./src/intents/intent-signer-impl/factories.cjs');
|
|
13
14
|
let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
@@ -39,6 +40,7 @@ Object.defineProperty(exports, 'HttpRequestError', {
|
|
|
39
40
|
return __defuse_protocol_internal_utils.HttpRequestError;
|
|
40
41
|
}
|
|
41
42
|
});
|
|
43
|
+
exports.IntentPayloadBuilder = require_intent_payload_builder.IntentPayloadBuilder;
|
|
42
44
|
Object.defineProperty(exports, 'IntentSettlementError', {
|
|
43
45
|
enumerable: true,
|
|
44
46
|
get: function () {
|
package/dist/index.d.cts
CHANGED
|
@@ -6,6 +6,7 @@ import { IIntentSigner } from "./src/intents/interfaces/intent-signer.cjs";
|
|
|
6
6
|
import { OnBeforePublishIntentHook } from "./src/intents/intent-executer-impl/intent-executer.cjs";
|
|
7
7
|
import { Chain, Chains } from "./src/lib/caip2.cjs";
|
|
8
8
|
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";
|
|
9
|
+
import { IntentPayloadBuilder } from "./src/intents/intent-payload-builder.cjs";
|
|
9
10
|
import { IntentsSDK, IntentsSDKConfig } from "./src/sdk.cjs";
|
|
10
11
|
import { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem } from "./src/intents/intent-signer-impl/factories.cjs";
|
|
11
12
|
import { createDefaultRoute, createHotBridgeRoute, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute } from "./src/lib/route-config-factory.cjs";
|
|
@@ -14,4 +15,4 @@ import { DestinationExplicitNearAccountDoesntExistError, DestinationExplicitNear
|
|
|
14
15
|
import { HotWithdrawalCancelledError, HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, HotWithdrawalPendingErrorType } from "./src/bridges/hot-bridge/error.cjs";
|
|
15
16
|
import { FailedToFetchFeeError, FailedToFetchFeeErrorType, IntentsNearOmniAvailableBalanceTooLowError, IntentsNearOmniAvailableBalanceTooLowErrorType, OmniTokenNormalisationCheckError, OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, OmniTransferNotFoundErrorType, TokenNotFoundInDestinationChainError, TokenNotFoundInDestinationChainErrorType } from "./src/bridges/omni-bridge/error.cjs";
|
|
16
17
|
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";
|
|
17
|
-
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, VersionedNonceBuilder, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
|
|
18
|
+
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, IntentPayloadBuilder, 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, VersionedNonceBuilder, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { IIntentSigner } from "./src/intents/interfaces/intent-signer.js";
|
|
|
6
6
|
import { OnBeforePublishIntentHook } from "./src/intents/intent-executer-impl/intent-executer.js";
|
|
7
7
|
import { Chain, Chains } from "./src/lib/caip2.js";
|
|
8
8
|
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";
|
|
9
|
+
import { IntentPayloadBuilder } from "./src/intents/intent-payload-builder.js";
|
|
9
10
|
import { IntentsSDK, IntentsSDKConfig } from "./src/sdk.js";
|
|
10
11
|
import { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem } from "./src/intents/intent-signer-impl/factories.js";
|
|
11
12
|
import { createDefaultRoute, createHotBridgeRoute, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute } from "./src/lib/route-config-factory.js";
|
|
@@ -14,4 +15,4 @@ import { DestinationExplicitNearAccountDoesntExistError, DestinationExplicitNear
|
|
|
14
15
|
import { HotWithdrawalCancelledError, HotWithdrawalCancelledErrorType, HotWithdrawalNotFoundError, HotWithdrawalNotFoundErrorType, HotWithdrawalPendingError, HotWithdrawalPendingErrorType } from "./src/bridges/hot-bridge/error.js";
|
|
15
16
|
import { FailedToFetchFeeError, FailedToFetchFeeErrorType, IntentsNearOmniAvailableBalanceTooLowError, IntentsNearOmniAvailableBalanceTooLowErrorType, OmniTokenNormalisationCheckError, OmniTokenNormalisationCheckErrorType, OmniTransferDestinationChainHashNotFoundError, OmniTransferDestinationChainHashNotFoundErrorType, OmniTransferNotFoundError, OmniTransferNotFoundErrorType, TokenNotFoundInDestinationChainError, TokenNotFoundInDestinationChainErrorType } from "./src/bridges/omni-bridge/error.js";
|
|
16
17
|
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";
|
|
17
|
-
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, VersionedNonceBuilder, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
|
|
18
|
+
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, IntentPayloadBuilder, 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, VersionedNonceBuilder, type VirtualChainRouteConfig, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
|
package/dist/index.js
CHANGED
|
@@ -7,8 +7,9 @@ import { HotWithdrawalCancelledError, HotWithdrawalNotFoundError, HotWithdrawalP
|
|
|
7
7
|
import { FailedToFetchFeeError, IntentsNearOmniAvailableBalanceTooLowError, OmniTokenNormalisationCheckError, OmniTransferDestinationChainHashNotFoundError, OmniTransferNotFoundError, TokenNotFoundInDestinationChainError } from "./src/bridges/omni-bridge/error.js";
|
|
8
8
|
import { VersionedNonceBuilder } from "./src/intents/expirable-nonce.js";
|
|
9
9
|
import { createDefaultRoute, createHotBridgeRoute, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute } from "./src/lib/route-config-factory.js";
|
|
10
|
+
import { IntentPayloadBuilder } from "./src/intents/intent-payload-builder.js";
|
|
10
11
|
import { IntentsSDK } from "./src/sdk.js";
|
|
11
12
|
import { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem } from "./src/intents/intent-signer-impl/factories.js";
|
|
12
13
|
import { AssertionError, BaseError, HttpRequestError, IntentSettlementError, PoaWithdrawalInvariantError, PoaWithdrawalNotFoundError, PoaWithdrawalPendingError, QuoteError, RelayPublishError, RpcRequestError, TimeoutError } from "@defuse-protocol/internal-utils";
|
|
13
14
|
|
|
14
|
-
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, VersionedNonceBuilder, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
|
|
15
|
+
export { AssertionError, BaseError, BridgeNameEnum, Chains, DestinationExplicitNearAccountDoesntExistError, FailedToFetchFeeError, FeeExceedsAmountError, HotWithdrawalCancelledError, HotWithdrawalNotFoundError, HotWithdrawalPendingError, HttpRequestError, IntentPayloadBuilder, IntentSettlementError, IntentsNearOmniAvailableBalanceTooLowError, IntentsSDK, MinWithdrawalAmountError, OmniTokenNormalisationCheckError, OmniTransferDestinationChainHashNotFoundError, OmniTransferNotFoundError, PoaWithdrawalInvariantError, PoaWithdrawalNotFoundError, PoaWithdrawalPendingError, QuoteError, RelayPublishError, RouteEnum, RpcRequestError, TimeoutError, TokenNotFoundInDestinationChainError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError, VersionedNonceBuilder, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
|
|
@@ -25,7 +25,7 @@ function createWithdrawIntentsPrimitive(params) {
|
|
|
25
25
|
});
|
|
26
26
|
(0, __defuse_protocol_internal_utils.assert)(standard === "nep141", "Only NEP-141 is supported");
|
|
27
27
|
return [{
|
|
28
|
-
|
|
28
|
+
deposit_for_account_id: implicitAccount,
|
|
29
29
|
amount: params.nativeFee.toString(),
|
|
30
30
|
contract_id: require_omni_bridge_constants.OMNI_BRIDGE_CONTRACT,
|
|
31
31
|
intent: "storage_deposit"
|
|
@@ -21,7 +21,7 @@ function createWithdrawIntentsPrimitive(params) {
|
|
|
21
21
|
});
|
|
22
22
|
assert(standard === "nep141", "Only NEP-141 is supported");
|
|
23
23
|
return [{
|
|
24
|
-
|
|
24
|
+
deposit_for_account_id: implicitAccount,
|
|
25
25
|
amount: params.nativeFee.toString(),
|
|
26
26
|
contract_id: OMNI_BRIDGE_CONTRACT,
|
|
27
27
|
intent: "storage_deposit"
|
|
@@ -20,7 +20,7 @@ var IntentExecuter = class {
|
|
|
20
20
|
verifying_contract: verifyingContract,
|
|
21
21
|
...intentParams
|
|
22
22
|
});
|
|
23
|
-
if (this.intentPayloadFactory) intentPayload = await mergeIntentPayloads(intentPayload, this.intentPayloadFactory);
|
|
23
|
+
if (this.intentPayloadFactory) intentPayload = await mergeIntentPayloads(intentPayload, this.intentPayloadFactory, salt);
|
|
24
24
|
const multiPayload = await this.intentSigner.signIntent(intentPayload);
|
|
25
25
|
const relayParams = relayParamsFactory ? await relayParamsFactory() : {};
|
|
26
26
|
if (this.onBeforePublishIntent) {
|
|
@@ -49,14 +49,15 @@ var IntentExecuter = class {
|
|
|
49
49
|
return this.intentRelayer.waitForSettlement(ticket, { logger: this.logger });
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
-
async function mergeIntentPayloads(
|
|
53
|
-
const customPayload = await intentPayloadFactory(
|
|
52
|
+
async function mergeIntentPayloads(defaultPayload, intentPayloadFactory, salt) {
|
|
53
|
+
const customPayload = await intentPayloadFactory(defaultPayload);
|
|
54
54
|
const customPayloadIntents = customPayload.intents ?? [];
|
|
55
|
-
|
|
55
|
+
const { nonce: _nonce,...basePayload } = defaultPayload;
|
|
56
|
+
return require_intent_payload_factory.defaultIntentPayloadFactory(salt, {
|
|
56
57
|
...basePayload,
|
|
57
58
|
...customPayload,
|
|
58
59
|
intents: Array.from(new Set([...customPayloadIntents, ...basePayload.intents]))
|
|
59
|
-
};
|
|
60
|
+
});
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
63
|
* Composes a new MultiPayload with pre-signed intents for atomic execution.
|
|
@@ -18,7 +18,7 @@ var IntentExecuter = class {
|
|
|
18
18
|
verifying_contract: verifyingContract,
|
|
19
19
|
...intentParams
|
|
20
20
|
});
|
|
21
|
-
if (this.intentPayloadFactory) intentPayload = await mergeIntentPayloads(intentPayload, this.intentPayloadFactory);
|
|
21
|
+
if (this.intentPayloadFactory) intentPayload = await mergeIntentPayloads(intentPayload, this.intentPayloadFactory, salt);
|
|
22
22
|
const multiPayload = await this.intentSigner.signIntent(intentPayload);
|
|
23
23
|
const relayParams = relayParamsFactory ? await relayParamsFactory() : {};
|
|
24
24
|
if (this.onBeforePublishIntent) {
|
|
@@ -47,14 +47,15 @@ var IntentExecuter = class {
|
|
|
47
47
|
return this.intentRelayer.waitForSettlement(ticket, { logger: this.logger });
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
-
async function mergeIntentPayloads(
|
|
51
|
-
const customPayload = await intentPayloadFactory(
|
|
50
|
+
async function mergeIntentPayloads(defaultPayload, intentPayloadFactory, salt) {
|
|
51
|
+
const customPayload = await intentPayloadFactory(defaultPayload);
|
|
52
52
|
const customPayloadIntents = customPayload.intents ?? [];
|
|
53
|
-
|
|
53
|
+
const { nonce: _nonce,...basePayload } = defaultPayload;
|
|
54
|
+
return defaultIntentPayloadFactory(salt, {
|
|
54
55
|
...basePayload,
|
|
55
56
|
...customPayload,
|
|
56
57
|
intents: Array.from(new Set([...customPayloadIntents, ...basePayload.intents]))
|
|
57
|
-
};
|
|
58
|
+
});
|
|
58
59
|
}
|
|
59
60
|
/**
|
|
60
61
|
* Composes a new MultiPayload with pre-signed intents for atomic execution.
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_expirable_nonce = require('./expirable-nonce.cjs');
|
|
3
|
+
const require_intent_payload_factory = require('./intent-payload-factory.cjs');
|
|
4
|
+
let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
5
|
+
__defuse_protocol_internal_utils = require_rolldown_runtime.__toESM(__defuse_protocol_internal_utils);
|
|
6
|
+
|
|
7
|
+
//#region src/intents/intent-payload-builder.ts
|
|
8
|
+
/**
|
|
9
|
+
* Fluent builder for constructing intent payloads with environment context.
|
|
10
|
+
* Provides a convenient API for generating intents that can be signed with different standards.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const sdk = new IntentsSDK({ env: 'production', referral: 'my-app' });
|
|
15
|
+
*
|
|
16
|
+
* // Build an intent payload
|
|
17
|
+
* const payload = await sdk.intentBuilder()
|
|
18
|
+
* .setSigner('0x1234...') // EVM address or NEAR account
|
|
19
|
+
* .setDeadline(new Date(Date.now() + 5 * 60 * 1000)) // 5 minutes
|
|
20
|
+
* .addIntent({
|
|
21
|
+
* intent: 'ft_withdraw',
|
|
22
|
+
* token: 'usdc.omft.near',
|
|
23
|
+
* amount: '1000000',
|
|
24
|
+
* receiver_id: 'user.near'
|
|
25
|
+
* })
|
|
26
|
+
* .build();
|
|
27
|
+
*
|
|
28
|
+
* // Sign with your preferred method
|
|
29
|
+
* const multiPayload = await signer.signIntent(payload);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
var IntentPayloadBuilder = class IntentPayloadBuilder {
|
|
33
|
+
constructor(config) {
|
|
34
|
+
this.intents = [];
|
|
35
|
+
this.env = config.env;
|
|
36
|
+
this.saltManager = config.saltManager;
|
|
37
|
+
this.verifyingContract = __defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Set the signer ID (address or account that will sign the intent).
|
|
41
|
+
* Can be an EVM address (for ERC191) or NEAR account ID (for NEP413).
|
|
42
|
+
*
|
|
43
|
+
* @param signerId - The identifier of the signer (must be a valid NEAR account ID)
|
|
44
|
+
* @returns The builder instance for chaining with updated type
|
|
45
|
+
* @throws Error if signerId is not a valid NEAR account ID
|
|
46
|
+
*/
|
|
47
|
+
setSigner(signerId) {
|
|
48
|
+
if (!__defuse_protocol_internal_utils.utils.validateNearAddress(signerId)) throw new Error(`Invalid signer_id: "${signerId}" is not a valid NEAR account ID`);
|
|
49
|
+
this.signerId = signerId;
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Set the deadline for the intent expiration.
|
|
54
|
+
* If not set, defaults to 1 minute from build time.
|
|
55
|
+
*
|
|
56
|
+
* @param deadline - The expiration time for the intent
|
|
57
|
+
* @returns The builder instance for chaining
|
|
58
|
+
*/
|
|
59
|
+
setDeadline(deadline) {
|
|
60
|
+
this.deadline = deadline;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Add an intent to the payload.
|
|
65
|
+
* Multiple intents can be added and will execute atomically.
|
|
66
|
+
*
|
|
67
|
+
* @param intent - The intent primitive to add
|
|
68
|
+
* @returns The builder instance for chaining
|
|
69
|
+
*/
|
|
70
|
+
addIntent(intent) {
|
|
71
|
+
this.intents.push(intent);
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Add multiple intents to the payload at once.
|
|
76
|
+
*
|
|
77
|
+
* @param intents - Array of intent primitives to add
|
|
78
|
+
* @returns The builder instance for chaining
|
|
79
|
+
*/
|
|
80
|
+
addIntents(intents) {
|
|
81
|
+
this.intents.push(...intents);
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Override the verifying contract address.
|
|
86
|
+
* Use with caution - normally this is automatically set based on environment.
|
|
87
|
+
*
|
|
88
|
+
* @param contractAddress - The contract address to use
|
|
89
|
+
* @returns The builder instance for chaining
|
|
90
|
+
*/
|
|
91
|
+
setVerifyingContract(contractAddress) {
|
|
92
|
+
this.verifyingContract = contractAddress;
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Set a custom nonce. If not provided, a nonce will be automatically generated.
|
|
97
|
+
* The nonce must be a valid versioned nonce format.
|
|
98
|
+
*
|
|
99
|
+
* @param nonce - Custom nonce string (base64 encoded)
|
|
100
|
+
* @returns The builder instance for chaining
|
|
101
|
+
*/
|
|
102
|
+
setNonce(nonce) {
|
|
103
|
+
this.customNonce = nonce;
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Clear all intents from the builder.
|
|
108
|
+
*
|
|
109
|
+
* @returns The builder instance for chaining
|
|
110
|
+
*/
|
|
111
|
+
clearIntents() {
|
|
112
|
+
this.intents = [];
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Reset the builder to its initial state.
|
|
117
|
+
* Keeps environment and salt manager but clears all user-set values.
|
|
118
|
+
*
|
|
119
|
+
* @returns The builder instance for chaining
|
|
120
|
+
*/
|
|
121
|
+
reset() {
|
|
122
|
+
this.signerId = void 0;
|
|
123
|
+
this.deadline = void 0;
|
|
124
|
+
this.intents = [];
|
|
125
|
+
this.customNonce = void 0;
|
|
126
|
+
this.verifyingContract = __defuse_protocol_internal_utils.configsByEnvironment[this.env].contractID;
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Build the intent payload using a custom salt.
|
|
131
|
+
* Use this method if you need explicit control over the salt.
|
|
132
|
+
*
|
|
133
|
+
* @param salt - The salt to use for nonce generation
|
|
134
|
+
* @returns The constructed intent payload with appropriate typing
|
|
135
|
+
*/
|
|
136
|
+
buildWithSalt(salt) {
|
|
137
|
+
const deadline = this.deadline ?? new Date(Date.now() + require_intent_payload_factory.DEFAULT_DEADLINE_MS);
|
|
138
|
+
const nonce = this.customNonce ?? require_expirable_nonce.VersionedNonceBuilder.encodeNonce(salt, deadline);
|
|
139
|
+
return {
|
|
140
|
+
verifying_contract: this.verifyingContract,
|
|
141
|
+
signer_id: this.signerId,
|
|
142
|
+
deadline: deadline.toISOString(),
|
|
143
|
+
nonce,
|
|
144
|
+
intents: [...this.intents]
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Build the intent payload. Automatically fetches a fresh salt if needed.
|
|
149
|
+
* This is the recommended method for most use cases.
|
|
150
|
+
*
|
|
151
|
+
* @returns Promise resolving to the constructed intent payload with appropriate typing
|
|
152
|
+
*/
|
|
153
|
+
async build() {
|
|
154
|
+
const salt = await this.saltManager.getCachedSalt();
|
|
155
|
+
return this.buildWithSalt(salt);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Build and sign the intent payload in one step.
|
|
159
|
+
* Convenience method that combines build() and signing.
|
|
160
|
+
*
|
|
161
|
+
* @param signer - The intent signer to use
|
|
162
|
+
* @returns Promise resolving to the signed multi-payload
|
|
163
|
+
*/
|
|
164
|
+
async buildAndSign(signer) {
|
|
165
|
+
const payload = await this.build();
|
|
166
|
+
return signer.signIntent(payload);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Create a new builder instance with the same configuration.
|
|
170
|
+
* Useful when you need multiple independent builders.
|
|
171
|
+
*
|
|
172
|
+
* @returns A new IntentPayloadBuilder instance
|
|
173
|
+
*/
|
|
174
|
+
clone() {
|
|
175
|
+
const builder = new IntentPayloadBuilder({
|
|
176
|
+
env: this.env,
|
|
177
|
+
saltManager: this.saltManager
|
|
178
|
+
});
|
|
179
|
+
builder.verifyingContract = this.verifyingContract;
|
|
180
|
+
builder.signerId = this.signerId;
|
|
181
|
+
builder.deadline = this.deadline;
|
|
182
|
+
builder.intents = [...this.intents];
|
|
183
|
+
builder.customNonce = this.customNonce;
|
|
184
|
+
return builder;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Get the current state of the builder as a plain object.
|
|
188
|
+
* Useful for debugging or inspecting the builder configuration.
|
|
189
|
+
*
|
|
190
|
+
* @returns Object containing the current builder state
|
|
191
|
+
*/
|
|
192
|
+
getState() {
|
|
193
|
+
return {
|
|
194
|
+
env: this.env,
|
|
195
|
+
verifyingContract: this.verifyingContract,
|
|
196
|
+
signerId: this.signerId,
|
|
197
|
+
deadline: this.deadline,
|
|
198
|
+
intents: [...this.intents],
|
|
199
|
+
customNonce: this.customNonce
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
//#endregion
|
|
205
|
+
exports.IntentPayloadBuilder = IntentPayloadBuilder;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { Salt } from "./expirable-nonce.cjs";
|
|
2
|
+
import { IntentPayload, IntentPrimitive, MultiPayload } from "./shared-types.cjs";
|
|
3
|
+
import { IIntentSigner } from "./interfaces/intent-signer.cjs";
|
|
4
|
+
import { ISaltManager } from "./interfaces/salt-manager.cjs";
|
|
5
|
+
import { NearIntentsEnv } from "@defuse-protocol/internal-utils";
|
|
6
|
+
|
|
7
|
+
//#region src/intents/intent-payload-builder.d.ts
|
|
8
|
+
interface IntentPayloadBuilderConfig {
|
|
9
|
+
env: NearIntentsEnv;
|
|
10
|
+
saltManager: ISaltManager;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Type helper to make signer_id required when HasSigner is true
|
|
14
|
+
*/
|
|
15
|
+
type IntentPayloadWithSigner<HasSigner extends boolean> = HasSigner extends true ? IntentPayload & {
|
|
16
|
+
signer_id: string;
|
|
17
|
+
} : IntentPayload;
|
|
18
|
+
/**
|
|
19
|
+
* Fluent builder for constructing intent payloads with environment context.
|
|
20
|
+
* Provides a convenient API for generating intents that can be signed with different standards.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const sdk = new IntentsSDK({ env: 'production', referral: 'my-app' });
|
|
25
|
+
*
|
|
26
|
+
* // Build an intent payload
|
|
27
|
+
* const payload = await sdk.intentBuilder()
|
|
28
|
+
* .setSigner('0x1234...') // EVM address or NEAR account
|
|
29
|
+
* .setDeadline(new Date(Date.now() + 5 * 60 * 1000)) // 5 minutes
|
|
30
|
+
* .addIntent({
|
|
31
|
+
* intent: 'ft_withdraw',
|
|
32
|
+
* token: 'usdc.omft.near',
|
|
33
|
+
* amount: '1000000',
|
|
34
|
+
* receiver_id: 'user.near'
|
|
35
|
+
* })
|
|
36
|
+
* .build();
|
|
37
|
+
*
|
|
38
|
+
* // Sign with your preferred method
|
|
39
|
+
* const multiPayload = await signer.signIntent(payload);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare class IntentPayloadBuilder<HasSigner extends boolean = false> {
|
|
43
|
+
private env;
|
|
44
|
+
private saltManager;
|
|
45
|
+
private verifyingContract;
|
|
46
|
+
private signerId?;
|
|
47
|
+
private deadline?;
|
|
48
|
+
private intents;
|
|
49
|
+
private customNonce?;
|
|
50
|
+
constructor(config: IntentPayloadBuilderConfig);
|
|
51
|
+
/**
|
|
52
|
+
* Set the signer ID (address or account that will sign the intent).
|
|
53
|
+
* Can be an EVM address (for ERC191) or NEAR account ID (for NEP413).
|
|
54
|
+
*
|
|
55
|
+
* @param signerId - The identifier of the signer (must be a valid NEAR account ID)
|
|
56
|
+
* @returns The builder instance for chaining with updated type
|
|
57
|
+
* @throws Error if signerId is not a valid NEAR account ID
|
|
58
|
+
*/
|
|
59
|
+
setSigner(signerId: string): IntentPayloadBuilder<true>;
|
|
60
|
+
/**
|
|
61
|
+
* Set the deadline for the intent expiration.
|
|
62
|
+
* If not set, defaults to 1 minute from build time.
|
|
63
|
+
*
|
|
64
|
+
* @param deadline - The expiration time for the intent
|
|
65
|
+
* @returns The builder instance for chaining
|
|
66
|
+
*/
|
|
67
|
+
setDeadline(deadline: Date): this;
|
|
68
|
+
/**
|
|
69
|
+
* Add an intent to the payload.
|
|
70
|
+
* Multiple intents can be added and will execute atomically.
|
|
71
|
+
*
|
|
72
|
+
* @param intent - The intent primitive to add
|
|
73
|
+
* @returns The builder instance for chaining
|
|
74
|
+
*/
|
|
75
|
+
addIntent(intent: IntentPrimitive): this;
|
|
76
|
+
/**
|
|
77
|
+
* Add multiple intents to the payload at once.
|
|
78
|
+
*
|
|
79
|
+
* @param intents - Array of intent primitives to add
|
|
80
|
+
* @returns The builder instance for chaining
|
|
81
|
+
*/
|
|
82
|
+
addIntents(intents: IntentPrimitive[]): this;
|
|
83
|
+
/**
|
|
84
|
+
* Override the verifying contract address.
|
|
85
|
+
* Use with caution - normally this is automatically set based on environment.
|
|
86
|
+
*
|
|
87
|
+
* @param contractAddress - The contract address to use
|
|
88
|
+
* @returns The builder instance for chaining
|
|
89
|
+
*/
|
|
90
|
+
setVerifyingContract(contractAddress: string): this;
|
|
91
|
+
/**
|
|
92
|
+
* Set a custom nonce. If not provided, a nonce will be automatically generated.
|
|
93
|
+
* The nonce must be a valid versioned nonce format.
|
|
94
|
+
*
|
|
95
|
+
* @param nonce - Custom nonce string (base64 encoded)
|
|
96
|
+
* @returns The builder instance for chaining
|
|
97
|
+
*/
|
|
98
|
+
setNonce(nonce: string): this;
|
|
99
|
+
/**
|
|
100
|
+
* Clear all intents from the builder.
|
|
101
|
+
*
|
|
102
|
+
* @returns The builder instance for chaining
|
|
103
|
+
*/
|
|
104
|
+
clearIntents(): this;
|
|
105
|
+
/**
|
|
106
|
+
* Reset the builder to its initial state.
|
|
107
|
+
* Keeps environment and salt manager but clears all user-set values.
|
|
108
|
+
*
|
|
109
|
+
* @returns The builder instance for chaining
|
|
110
|
+
*/
|
|
111
|
+
reset(): IntentPayloadBuilder<false>;
|
|
112
|
+
/**
|
|
113
|
+
* Build the intent payload using a custom salt.
|
|
114
|
+
* Use this method if you need explicit control over the salt.
|
|
115
|
+
*
|
|
116
|
+
* @param salt - The salt to use for nonce generation
|
|
117
|
+
* @returns The constructed intent payload with appropriate typing
|
|
118
|
+
*/
|
|
119
|
+
buildWithSalt(salt: Salt): IntentPayloadWithSigner<HasSigner>;
|
|
120
|
+
/**
|
|
121
|
+
* Build the intent payload. Automatically fetches a fresh salt if needed.
|
|
122
|
+
* This is the recommended method for most use cases.
|
|
123
|
+
*
|
|
124
|
+
* @returns Promise resolving to the constructed intent payload with appropriate typing
|
|
125
|
+
*/
|
|
126
|
+
build(): Promise<IntentPayloadWithSigner<HasSigner>>;
|
|
127
|
+
/**
|
|
128
|
+
* Build and sign the intent payload in one step.
|
|
129
|
+
* Convenience method that combines build() and signing.
|
|
130
|
+
*
|
|
131
|
+
* @param signer - The intent signer to use
|
|
132
|
+
* @returns Promise resolving to the signed multi-payload
|
|
133
|
+
*/
|
|
134
|
+
buildAndSign(signer: IIntentSigner): Promise<MultiPayload>;
|
|
135
|
+
/**
|
|
136
|
+
* Create a new builder instance with the same configuration.
|
|
137
|
+
* Useful when you need multiple independent builders.
|
|
138
|
+
*
|
|
139
|
+
* @returns A new IntentPayloadBuilder instance
|
|
140
|
+
*/
|
|
141
|
+
clone(): IntentPayloadBuilder<HasSigner>;
|
|
142
|
+
/**
|
|
143
|
+
* Get the current state of the builder as a plain object.
|
|
144
|
+
* Useful for debugging or inspecting the builder configuration.
|
|
145
|
+
*
|
|
146
|
+
* @returns Object containing the current builder state
|
|
147
|
+
*/
|
|
148
|
+
getState(): {
|
|
149
|
+
env: NearIntentsEnv;
|
|
150
|
+
verifyingContract: string;
|
|
151
|
+
signerId?: string;
|
|
152
|
+
deadline?: Date;
|
|
153
|
+
intents: IntentPrimitive[];
|
|
154
|
+
customNonce?: string;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
158
|
+
export { IntentPayloadBuilder };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { Salt } from "./expirable-nonce.js";
|
|
2
|
+
import { IntentPayload, IntentPrimitive, MultiPayload } from "./shared-types.js";
|
|
3
|
+
import { IIntentSigner } from "./interfaces/intent-signer.js";
|
|
4
|
+
import { ISaltManager } from "./interfaces/salt-manager.js";
|
|
5
|
+
import { NearIntentsEnv } from "@defuse-protocol/internal-utils";
|
|
6
|
+
|
|
7
|
+
//#region src/intents/intent-payload-builder.d.ts
|
|
8
|
+
interface IntentPayloadBuilderConfig {
|
|
9
|
+
env: NearIntentsEnv;
|
|
10
|
+
saltManager: ISaltManager;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Type helper to make signer_id required when HasSigner is true
|
|
14
|
+
*/
|
|
15
|
+
type IntentPayloadWithSigner<HasSigner extends boolean> = HasSigner extends true ? IntentPayload & {
|
|
16
|
+
signer_id: string;
|
|
17
|
+
} : IntentPayload;
|
|
18
|
+
/**
|
|
19
|
+
* Fluent builder for constructing intent payloads with environment context.
|
|
20
|
+
* Provides a convenient API for generating intents that can be signed with different standards.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const sdk = new IntentsSDK({ env: 'production', referral: 'my-app' });
|
|
25
|
+
*
|
|
26
|
+
* // Build an intent payload
|
|
27
|
+
* const payload = await sdk.intentBuilder()
|
|
28
|
+
* .setSigner('0x1234...') // EVM address or NEAR account
|
|
29
|
+
* .setDeadline(new Date(Date.now() + 5 * 60 * 1000)) // 5 minutes
|
|
30
|
+
* .addIntent({
|
|
31
|
+
* intent: 'ft_withdraw',
|
|
32
|
+
* token: 'usdc.omft.near',
|
|
33
|
+
* amount: '1000000',
|
|
34
|
+
* receiver_id: 'user.near'
|
|
35
|
+
* })
|
|
36
|
+
* .build();
|
|
37
|
+
*
|
|
38
|
+
* // Sign with your preferred method
|
|
39
|
+
* const multiPayload = await signer.signIntent(payload);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare class IntentPayloadBuilder<HasSigner extends boolean = false> {
|
|
43
|
+
private env;
|
|
44
|
+
private saltManager;
|
|
45
|
+
private verifyingContract;
|
|
46
|
+
private signerId?;
|
|
47
|
+
private deadline?;
|
|
48
|
+
private intents;
|
|
49
|
+
private customNonce?;
|
|
50
|
+
constructor(config: IntentPayloadBuilderConfig);
|
|
51
|
+
/**
|
|
52
|
+
* Set the signer ID (address or account that will sign the intent).
|
|
53
|
+
* Can be an EVM address (for ERC191) or NEAR account ID (for NEP413).
|
|
54
|
+
*
|
|
55
|
+
* @param signerId - The identifier of the signer (must be a valid NEAR account ID)
|
|
56
|
+
* @returns The builder instance for chaining with updated type
|
|
57
|
+
* @throws Error if signerId is not a valid NEAR account ID
|
|
58
|
+
*/
|
|
59
|
+
setSigner(signerId: string): IntentPayloadBuilder<true>;
|
|
60
|
+
/**
|
|
61
|
+
* Set the deadline for the intent expiration.
|
|
62
|
+
* If not set, defaults to 1 minute from build time.
|
|
63
|
+
*
|
|
64
|
+
* @param deadline - The expiration time for the intent
|
|
65
|
+
* @returns The builder instance for chaining
|
|
66
|
+
*/
|
|
67
|
+
setDeadline(deadline: Date): this;
|
|
68
|
+
/**
|
|
69
|
+
* Add an intent to the payload.
|
|
70
|
+
* Multiple intents can be added and will execute atomically.
|
|
71
|
+
*
|
|
72
|
+
* @param intent - The intent primitive to add
|
|
73
|
+
* @returns The builder instance for chaining
|
|
74
|
+
*/
|
|
75
|
+
addIntent(intent: IntentPrimitive): this;
|
|
76
|
+
/**
|
|
77
|
+
* Add multiple intents to the payload at once.
|
|
78
|
+
*
|
|
79
|
+
* @param intents - Array of intent primitives to add
|
|
80
|
+
* @returns The builder instance for chaining
|
|
81
|
+
*/
|
|
82
|
+
addIntents(intents: IntentPrimitive[]): this;
|
|
83
|
+
/**
|
|
84
|
+
* Override the verifying contract address.
|
|
85
|
+
* Use with caution - normally this is automatically set based on environment.
|
|
86
|
+
*
|
|
87
|
+
* @param contractAddress - The contract address to use
|
|
88
|
+
* @returns The builder instance for chaining
|
|
89
|
+
*/
|
|
90
|
+
setVerifyingContract(contractAddress: string): this;
|
|
91
|
+
/**
|
|
92
|
+
* Set a custom nonce. If not provided, a nonce will be automatically generated.
|
|
93
|
+
* The nonce must be a valid versioned nonce format.
|
|
94
|
+
*
|
|
95
|
+
* @param nonce - Custom nonce string (base64 encoded)
|
|
96
|
+
* @returns The builder instance for chaining
|
|
97
|
+
*/
|
|
98
|
+
setNonce(nonce: string): this;
|
|
99
|
+
/**
|
|
100
|
+
* Clear all intents from the builder.
|
|
101
|
+
*
|
|
102
|
+
* @returns The builder instance for chaining
|
|
103
|
+
*/
|
|
104
|
+
clearIntents(): this;
|
|
105
|
+
/**
|
|
106
|
+
* Reset the builder to its initial state.
|
|
107
|
+
* Keeps environment and salt manager but clears all user-set values.
|
|
108
|
+
*
|
|
109
|
+
* @returns The builder instance for chaining
|
|
110
|
+
*/
|
|
111
|
+
reset(): IntentPayloadBuilder<false>;
|
|
112
|
+
/**
|
|
113
|
+
* Build the intent payload using a custom salt.
|
|
114
|
+
* Use this method if you need explicit control over the salt.
|
|
115
|
+
*
|
|
116
|
+
* @param salt - The salt to use for nonce generation
|
|
117
|
+
* @returns The constructed intent payload with appropriate typing
|
|
118
|
+
*/
|
|
119
|
+
buildWithSalt(salt: Salt): IntentPayloadWithSigner<HasSigner>;
|
|
120
|
+
/**
|
|
121
|
+
* Build the intent payload. Automatically fetches a fresh salt if needed.
|
|
122
|
+
* This is the recommended method for most use cases.
|
|
123
|
+
*
|
|
124
|
+
* @returns Promise resolving to the constructed intent payload with appropriate typing
|
|
125
|
+
*/
|
|
126
|
+
build(): Promise<IntentPayloadWithSigner<HasSigner>>;
|
|
127
|
+
/**
|
|
128
|
+
* Build and sign the intent payload in one step.
|
|
129
|
+
* Convenience method that combines build() and signing.
|
|
130
|
+
*
|
|
131
|
+
* @param signer - The intent signer to use
|
|
132
|
+
* @returns Promise resolving to the signed multi-payload
|
|
133
|
+
*/
|
|
134
|
+
buildAndSign(signer: IIntentSigner): Promise<MultiPayload>;
|
|
135
|
+
/**
|
|
136
|
+
* Create a new builder instance with the same configuration.
|
|
137
|
+
* Useful when you need multiple independent builders.
|
|
138
|
+
*
|
|
139
|
+
* @returns A new IntentPayloadBuilder instance
|
|
140
|
+
*/
|
|
141
|
+
clone(): IntentPayloadBuilder<HasSigner>;
|
|
142
|
+
/**
|
|
143
|
+
* Get the current state of the builder as a plain object.
|
|
144
|
+
* Useful for debugging or inspecting the builder configuration.
|
|
145
|
+
*
|
|
146
|
+
* @returns Object containing the current builder state
|
|
147
|
+
*/
|
|
148
|
+
getState(): {
|
|
149
|
+
env: NearIntentsEnv;
|
|
150
|
+
verifyingContract: string;
|
|
151
|
+
signerId?: string;
|
|
152
|
+
deadline?: Date;
|
|
153
|
+
intents: IntentPrimitive[];
|
|
154
|
+
customNonce?: string;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
158
|
+
export { IntentPayloadBuilder };
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { VersionedNonceBuilder } from "./expirable-nonce.js";
|
|
2
|
+
import { DEFAULT_DEADLINE_MS } from "./intent-payload-factory.js";
|
|
3
|
+
import { configsByEnvironment, utils } from "@defuse-protocol/internal-utils";
|
|
4
|
+
|
|
5
|
+
//#region src/intents/intent-payload-builder.ts
|
|
6
|
+
/**
|
|
7
|
+
* Fluent builder for constructing intent payloads with environment context.
|
|
8
|
+
* Provides a convenient API for generating intents that can be signed with different standards.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const sdk = new IntentsSDK({ env: 'production', referral: 'my-app' });
|
|
13
|
+
*
|
|
14
|
+
* // Build an intent payload
|
|
15
|
+
* const payload = await sdk.intentBuilder()
|
|
16
|
+
* .setSigner('0x1234...') // EVM address or NEAR account
|
|
17
|
+
* .setDeadline(new Date(Date.now() + 5 * 60 * 1000)) // 5 minutes
|
|
18
|
+
* .addIntent({
|
|
19
|
+
* intent: 'ft_withdraw',
|
|
20
|
+
* token: 'usdc.omft.near',
|
|
21
|
+
* amount: '1000000',
|
|
22
|
+
* receiver_id: 'user.near'
|
|
23
|
+
* })
|
|
24
|
+
* .build();
|
|
25
|
+
*
|
|
26
|
+
* // Sign with your preferred method
|
|
27
|
+
* const multiPayload = await signer.signIntent(payload);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
var IntentPayloadBuilder = class IntentPayloadBuilder {
|
|
31
|
+
constructor(config) {
|
|
32
|
+
this.intents = [];
|
|
33
|
+
this.env = config.env;
|
|
34
|
+
this.saltManager = config.saltManager;
|
|
35
|
+
this.verifyingContract = configsByEnvironment[this.env].contractID;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Set the signer ID (address or account that will sign the intent).
|
|
39
|
+
* Can be an EVM address (for ERC191) or NEAR account ID (for NEP413).
|
|
40
|
+
*
|
|
41
|
+
* @param signerId - The identifier of the signer (must be a valid NEAR account ID)
|
|
42
|
+
* @returns The builder instance for chaining with updated type
|
|
43
|
+
* @throws Error if signerId is not a valid NEAR account ID
|
|
44
|
+
*/
|
|
45
|
+
setSigner(signerId) {
|
|
46
|
+
if (!utils.validateNearAddress(signerId)) throw new Error(`Invalid signer_id: "${signerId}" is not a valid NEAR account ID`);
|
|
47
|
+
this.signerId = signerId;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Set the deadline for the intent expiration.
|
|
52
|
+
* If not set, defaults to 1 minute from build time.
|
|
53
|
+
*
|
|
54
|
+
* @param deadline - The expiration time for the intent
|
|
55
|
+
* @returns The builder instance for chaining
|
|
56
|
+
*/
|
|
57
|
+
setDeadline(deadline) {
|
|
58
|
+
this.deadline = deadline;
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Add an intent to the payload.
|
|
63
|
+
* Multiple intents can be added and will execute atomically.
|
|
64
|
+
*
|
|
65
|
+
* @param intent - The intent primitive to add
|
|
66
|
+
* @returns The builder instance for chaining
|
|
67
|
+
*/
|
|
68
|
+
addIntent(intent) {
|
|
69
|
+
this.intents.push(intent);
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Add multiple intents to the payload at once.
|
|
74
|
+
*
|
|
75
|
+
* @param intents - Array of intent primitives to add
|
|
76
|
+
* @returns The builder instance for chaining
|
|
77
|
+
*/
|
|
78
|
+
addIntents(intents) {
|
|
79
|
+
this.intents.push(...intents);
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Override the verifying contract address.
|
|
84
|
+
* Use with caution - normally this is automatically set based on environment.
|
|
85
|
+
*
|
|
86
|
+
* @param contractAddress - The contract address to use
|
|
87
|
+
* @returns The builder instance for chaining
|
|
88
|
+
*/
|
|
89
|
+
setVerifyingContract(contractAddress) {
|
|
90
|
+
this.verifyingContract = contractAddress;
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Set a custom nonce. If not provided, a nonce will be automatically generated.
|
|
95
|
+
* The nonce must be a valid versioned nonce format.
|
|
96
|
+
*
|
|
97
|
+
* @param nonce - Custom nonce string (base64 encoded)
|
|
98
|
+
* @returns The builder instance for chaining
|
|
99
|
+
*/
|
|
100
|
+
setNonce(nonce) {
|
|
101
|
+
this.customNonce = nonce;
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Clear all intents from the builder.
|
|
106
|
+
*
|
|
107
|
+
* @returns The builder instance for chaining
|
|
108
|
+
*/
|
|
109
|
+
clearIntents() {
|
|
110
|
+
this.intents = [];
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Reset the builder to its initial state.
|
|
115
|
+
* Keeps environment and salt manager but clears all user-set values.
|
|
116
|
+
*
|
|
117
|
+
* @returns The builder instance for chaining
|
|
118
|
+
*/
|
|
119
|
+
reset() {
|
|
120
|
+
this.signerId = void 0;
|
|
121
|
+
this.deadline = void 0;
|
|
122
|
+
this.intents = [];
|
|
123
|
+
this.customNonce = void 0;
|
|
124
|
+
this.verifyingContract = configsByEnvironment[this.env].contractID;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Build the intent payload using a custom salt.
|
|
129
|
+
* Use this method if you need explicit control over the salt.
|
|
130
|
+
*
|
|
131
|
+
* @param salt - The salt to use for nonce generation
|
|
132
|
+
* @returns The constructed intent payload with appropriate typing
|
|
133
|
+
*/
|
|
134
|
+
buildWithSalt(salt) {
|
|
135
|
+
const deadline = this.deadline ?? new Date(Date.now() + DEFAULT_DEADLINE_MS);
|
|
136
|
+
const nonce = this.customNonce ?? VersionedNonceBuilder.encodeNonce(salt, deadline);
|
|
137
|
+
return {
|
|
138
|
+
verifying_contract: this.verifyingContract,
|
|
139
|
+
signer_id: this.signerId,
|
|
140
|
+
deadline: deadline.toISOString(),
|
|
141
|
+
nonce,
|
|
142
|
+
intents: [...this.intents]
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Build the intent payload. Automatically fetches a fresh salt if needed.
|
|
147
|
+
* This is the recommended method for most use cases.
|
|
148
|
+
*
|
|
149
|
+
* @returns Promise resolving to the constructed intent payload with appropriate typing
|
|
150
|
+
*/
|
|
151
|
+
async build() {
|
|
152
|
+
const salt = await this.saltManager.getCachedSalt();
|
|
153
|
+
return this.buildWithSalt(salt);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Build and sign the intent payload in one step.
|
|
157
|
+
* Convenience method that combines build() and signing.
|
|
158
|
+
*
|
|
159
|
+
* @param signer - The intent signer to use
|
|
160
|
+
* @returns Promise resolving to the signed multi-payload
|
|
161
|
+
*/
|
|
162
|
+
async buildAndSign(signer) {
|
|
163
|
+
const payload = await this.build();
|
|
164
|
+
return signer.signIntent(payload);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Create a new builder instance with the same configuration.
|
|
168
|
+
* Useful when you need multiple independent builders.
|
|
169
|
+
*
|
|
170
|
+
* @returns A new IntentPayloadBuilder instance
|
|
171
|
+
*/
|
|
172
|
+
clone() {
|
|
173
|
+
const builder = new IntentPayloadBuilder({
|
|
174
|
+
env: this.env,
|
|
175
|
+
saltManager: this.saltManager
|
|
176
|
+
});
|
|
177
|
+
builder.verifyingContract = this.verifyingContract;
|
|
178
|
+
builder.signerId = this.signerId;
|
|
179
|
+
builder.deadline = this.deadline;
|
|
180
|
+
builder.intents = [...this.intents];
|
|
181
|
+
builder.customNonce = this.customNonce;
|
|
182
|
+
return builder;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get the current state of the builder as a plain object.
|
|
186
|
+
* Useful for debugging or inspecting the builder configuration.
|
|
187
|
+
*
|
|
188
|
+
* @returns Object containing the current builder state
|
|
189
|
+
*/
|
|
190
|
+
getState() {
|
|
191
|
+
return {
|
|
192
|
+
env: this.env,
|
|
193
|
+
verifyingContract: this.verifyingContract,
|
|
194
|
+
signerId: this.signerId,
|
|
195
|
+
deadline: this.deadline,
|
|
196
|
+
intents: [...this.intents],
|
|
197
|
+
customNonce: this.customNonce
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
//#endregion
|
|
203
|
+
export { IntentPayloadBuilder };
|
|
@@ -4,7 +4,7 @@ const require_expirable_nonce = require('./expirable-nonce.cjs');
|
|
|
4
4
|
const DEFAULT_DEADLINE_MS = 60 * 1e3;
|
|
5
5
|
function defaultIntentPayloadFactory(salt, { intents, verifying_contract,...params }) {
|
|
6
6
|
params = Object.fromEntries(Object.entries(params).filter(([, value]) => value !== void 0));
|
|
7
|
-
const deadline = new Date(Date.now() + DEFAULT_DEADLINE_MS);
|
|
7
|
+
const deadline = params.deadline != null ? new Date(params.deadline) : new Date(Date.now() + DEFAULT_DEADLINE_MS);
|
|
8
8
|
return {
|
|
9
9
|
verifying_contract,
|
|
10
10
|
deadline: deadline.toISOString(),
|
|
@@ -16,4 +16,5 @@ function defaultIntentPayloadFactory(salt, { intents, verifying_contract,...para
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
//#endregion
|
|
19
|
+
exports.DEFAULT_DEADLINE_MS = DEFAULT_DEADLINE_MS;
|
|
19
20
|
exports.defaultIntentPayloadFactory = defaultIntentPayloadFactory;
|
|
@@ -4,7 +4,7 @@ import { VersionedNonceBuilder } from "./expirable-nonce.js";
|
|
|
4
4
|
const DEFAULT_DEADLINE_MS = 60 * 1e3;
|
|
5
5
|
function defaultIntentPayloadFactory(salt, { intents, verifying_contract,...params }) {
|
|
6
6
|
params = Object.fromEntries(Object.entries(params).filter(([, value]) => value !== void 0));
|
|
7
|
-
const deadline = new Date(Date.now() + DEFAULT_DEADLINE_MS);
|
|
7
|
+
const deadline = params.deadline != null ? new Date(params.deadline) : new Date(Date.now() + DEFAULT_DEADLINE_MS);
|
|
8
8
|
return {
|
|
9
9
|
verifying_contract,
|
|
10
10
|
deadline: deadline.toISOString(),
|
|
@@ -16,4 +16,4 @@ function defaultIntentPayloadFactory(salt, { intents, verifying_contract,...para
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
//#endregion
|
|
19
|
-
export { defaultIntentPayloadFactory };
|
|
19
|
+
export { DEFAULT_DEADLINE_MS, defaultIntentPayloadFactory };
|
package/dist/src/sdk.cjs
CHANGED
|
@@ -16,6 +16,7 @@ const require_array = require('./lib/array.cjs');
|
|
|
16
16
|
const require_configure_rpc_config = require('./lib/configure-rpc-config.cjs');
|
|
17
17
|
const require_route_config = require('./lib/route-config.cjs');
|
|
18
18
|
const require_salt_manager = require('./intents/salt-manager.cjs');
|
|
19
|
+
const require_intent_payload_builder = require('./intents/intent-payload-builder.cjs');
|
|
19
20
|
let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
20
21
|
__defuse_protocol_internal_utils = require_rolldown_runtime.__toESM(__defuse_protocol_internal_utils);
|
|
21
22
|
let __hot_labs_omni_sdk = require("@hot-labs/omni-sdk");
|
|
@@ -84,6 +85,36 @@ var IntentsSDK = class {
|
|
|
84
85
|
setIntentSigner(signer) {
|
|
85
86
|
this.intentSigner = signer;
|
|
86
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Create a new intent payload builder with environment context.
|
|
90
|
+
* Use this to build custom intent payloads for your API or advanced use cases.
|
|
91
|
+
*
|
|
92
|
+
* @returns A new IntentPayloadBuilder instance configured with the SDK's environment
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* // Build a custom intent payload
|
|
97
|
+
* const payload = await sdk.intentBuilder()
|
|
98
|
+
* .setSigner('0x1234...') // User's EVM address
|
|
99
|
+
* .setDeadline(new Date(Date.now() + 5 * 60 * 1000))
|
|
100
|
+
* .addIntent({
|
|
101
|
+
* intent: 'ft_withdraw',
|
|
102
|
+
* token: 'usdc.omft.near',
|
|
103
|
+
* amount: '1000000',
|
|
104
|
+
* receiver_id: 'user.near'
|
|
105
|
+
* })
|
|
106
|
+
* .build();
|
|
107
|
+
*
|
|
108
|
+
* // Return to user for signing with their preferred method (MetaMask, etc.)
|
|
109
|
+
* return payload;
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
intentBuilder() {
|
|
113
|
+
return new require_intent_payload_builder.IntentPayloadBuilder({
|
|
114
|
+
env: this.env,
|
|
115
|
+
saltManager: this.saltManager
|
|
116
|
+
});
|
|
117
|
+
}
|
|
87
118
|
async createWithdrawalIntents(args) {
|
|
88
119
|
for (const bridge of this.bridges) if (await bridge.supports(args.withdrawalParams)) {
|
|
89
120
|
const actualAmount = args.withdrawalParams.feeInclusive ? args.withdrawalParams.amount - args.feeEstimation.amount : args.withdrawalParams.amount;
|
package/dist/src/sdk.d.cts
CHANGED
|
@@ -3,6 +3,7 @@ import { IIntentSigner } from "./intents/interfaces/intent-signer.cjs";
|
|
|
3
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 { ISaltManager } from "./intents/interfaces/salt-manager.cjs";
|
|
6
|
+
import { IntentPayloadBuilder } from "./intents/intent-payload-builder.cjs";
|
|
6
7
|
import { ILogger, NearIntentsEnv, RetryOptions } from "@defuse-protocol/internal-utils";
|
|
7
8
|
|
|
8
9
|
//#region src/sdk.d.ts
|
|
@@ -23,6 +24,31 @@ declare class IntentsSDK implements IIntentsSDK {
|
|
|
23
24
|
protected saltManager: ISaltManager;
|
|
24
25
|
constructor(args: IntentsSDKConfig);
|
|
25
26
|
setIntentSigner(signer: IIntentSigner): void;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new intent payload builder with environment context.
|
|
29
|
+
* Use this to build custom intent payloads for your API or advanced use cases.
|
|
30
|
+
*
|
|
31
|
+
* @returns A new IntentPayloadBuilder instance configured with the SDK's environment
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Build a custom intent payload
|
|
36
|
+
* const payload = await sdk.intentBuilder()
|
|
37
|
+
* .setSigner('0x1234...') // User's EVM address
|
|
38
|
+
* .setDeadline(new Date(Date.now() + 5 * 60 * 1000))
|
|
39
|
+
* .addIntent({
|
|
40
|
+
* intent: 'ft_withdraw',
|
|
41
|
+
* token: 'usdc.omft.near',
|
|
42
|
+
* amount: '1000000',
|
|
43
|
+
* receiver_id: 'user.near'
|
|
44
|
+
* })
|
|
45
|
+
* .build();
|
|
46
|
+
*
|
|
47
|
+
* // Return to user for signing with their preferred method (MetaMask, etc.)
|
|
48
|
+
* return payload;
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
intentBuilder(): IntentPayloadBuilder;
|
|
26
52
|
createWithdrawalIntents(args: {
|
|
27
53
|
withdrawalParams: WithdrawalParams;
|
|
28
54
|
feeEstimation: FeeEstimation;
|
package/dist/src/sdk.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { IIntentSigner } from "./intents/interfaces/intent-signer.js";
|
|
|
3
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 { ISaltManager } from "./intents/interfaces/salt-manager.js";
|
|
6
|
+
import { IntentPayloadBuilder } from "./intents/intent-payload-builder.js";
|
|
6
7
|
import { ILogger, NearIntentsEnv, RetryOptions } from "@defuse-protocol/internal-utils";
|
|
7
8
|
|
|
8
9
|
//#region src/sdk.d.ts
|
|
@@ -23,6 +24,31 @@ declare class IntentsSDK implements IIntentsSDK {
|
|
|
23
24
|
protected saltManager: ISaltManager;
|
|
24
25
|
constructor(args: IntentsSDKConfig);
|
|
25
26
|
setIntentSigner(signer: IIntentSigner): void;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new intent payload builder with environment context.
|
|
29
|
+
* Use this to build custom intent payloads for your API or advanced use cases.
|
|
30
|
+
*
|
|
31
|
+
* @returns A new IntentPayloadBuilder instance configured with the SDK's environment
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Build a custom intent payload
|
|
36
|
+
* const payload = await sdk.intentBuilder()
|
|
37
|
+
* .setSigner('0x1234...') // User's EVM address
|
|
38
|
+
* .setDeadline(new Date(Date.now() + 5 * 60 * 1000))
|
|
39
|
+
* .addIntent({
|
|
40
|
+
* intent: 'ft_withdraw',
|
|
41
|
+
* token: 'usdc.omft.near',
|
|
42
|
+
* amount: '1000000',
|
|
43
|
+
* receiver_id: 'user.near'
|
|
44
|
+
* })
|
|
45
|
+
* .build();
|
|
46
|
+
*
|
|
47
|
+
* // Return to user for signing with their preferred method (MetaMask, etc.)
|
|
48
|
+
* return payload;
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
intentBuilder(): IntentPayloadBuilder;
|
|
26
52
|
createWithdrawalIntents(args: {
|
|
27
53
|
withdrawalParams: WithdrawalParams;
|
|
28
54
|
feeEstimation: FeeEstimation;
|
package/dist/src/sdk.js
CHANGED
|
@@ -15,6 +15,7 @@ import { zip } from "./lib/array.js";
|
|
|
15
15
|
import { configureEvmRpcUrls, configureStellarRpcUrls } from "./lib/configure-rpc-config.js";
|
|
16
16
|
import { determineRouteConfig } from "./lib/route-config.js";
|
|
17
17
|
import { SaltManager } from "./intents/salt-manager.js";
|
|
18
|
+
import { IntentPayloadBuilder } from "./intents/intent-payload-builder.js";
|
|
18
19
|
import { PUBLIC_NEAR_RPC_URLS, RETRY_CONFIGS, RelayPublishError, assert, configsByEnvironment, nearFailoverRpcProvider, solverRelay } from "@defuse-protocol/internal-utils";
|
|
19
20
|
import { HotBridge } from "@hot-labs/omni-sdk";
|
|
20
21
|
import { stringify } from "viem";
|
|
@@ -80,6 +81,36 @@ var IntentsSDK = class {
|
|
|
80
81
|
setIntentSigner(signer) {
|
|
81
82
|
this.intentSigner = signer;
|
|
82
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Create a new intent payload builder with environment context.
|
|
86
|
+
* Use this to build custom intent payloads for your API or advanced use cases.
|
|
87
|
+
*
|
|
88
|
+
* @returns A new IntentPayloadBuilder instance configured with the SDK's environment
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* // Build a custom intent payload
|
|
93
|
+
* const payload = await sdk.intentBuilder()
|
|
94
|
+
* .setSigner('0x1234...') // User's EVM address
|
|
95
|
+
* .setDeadline(new Date(Date.now() + 5 * 60 * 1000))
|
|
96
|
+
* .addIntent({
|
|
97
|
+
* intent: 'ft_withdraw',
|
|
98
|
+
* token: 'usdc.omft.near',
|
|
99
|
+
* amount: '1000000',
|
|
100
|
+
* receiver_id: 'user.near'
|
|
101
|
+
* })
|
|
102
|
+
* .build();
|
|
103
|
+
*
|
|
104
|
+
* // Return to user for signing with their preferred method (MetaMask, etc.)
|
|
105
|
+
* return payload;
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
intentBuilder() {
|
|
109
|
+
return new IntentPayloadBuilder({
|
|
110
|
+
env: this.env,
|
|
111
|
+
saltManager: this.saltManager
|
|
112
|
+
});
|
|
113
|
+
}
|
|
83
114
|
async createWithdrawalIntents(args) {
|
|
84
115
|
for (const bridge of this.bridges) if (await bridge.supports(args.withdrawalParams)) {
|
|
85
116
|
const actualAmount = args.withdrawalParams.feeInclusive ? args.withdrawalParams.amount - args.feeEstimation.amount : args.withdrawalParams.amount;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defuse-protocol/intents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"ripple-address-codec": "^5.0.0",
|
|
39
39
|
"valibot": "^1.0.0",
|
|
40
40
|
"viem": "^2.0.0",
|
|
41
|
-
"@defuse-protocol/contract-types": "0.
|
|
42
|
-
"@defuse-protocol/internal-utils": "0.18.
|
|
41
|
+
"@defuse-protocol/contract-types": "0.3.0",
|
|
42
|
+
"@defuse-protocol/internal-utils": "0.18.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"tsdown": "0.15.5",
|