@defuse-protocol/intents-sdk 0.78.1 → 0.79.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/dist/index.cjs +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/src/bridges/direct-bridge/direct-bridge.cjs +3 -0
- package/dist/src/bridges/direct-bridge/direct-bridge.js +4 -1
- package/dist/src/bridges/hot-bridge/hot-bridge.cjs +4 -1
- package/dist/src/bridges/hot-bridge/hot-bridge.js +5 -2
- package/dist/src/bridges/omni-bridge/omni-bridge-constants.cjs +5 -1
- package/dist/src/bridges/omni-bridge/omni-bridge-constants.js +3 -1
- package/dist/src/bridges/omni-bridge/omni-bridge.cjs +8 -5
- package/dist/src/bridges/omni-bridge/omni-bridge.js +11 -8
- package/dist/src/bridges/poa-bridge/poa-bridge.cjs +2 -0
- package/dist/src/bridges/poa-bridge/poa-bridge.js +3 -1
- package/dist/src/classes/errors.cjs +11 -0
- package/dist/src/classes/errors.d.cts +9 -1
- package/dist/src/classes/errors.d.ts +9 -1
- package/dist/src/classes/errors.js +11 -1
- package/dist/src/lib/compareAddresses.cjs +116 -0
- package/dist/src/lib/compareAddresses.js +115 -0
- package/dist/src/lib/validateAddress.cjs +2 -0
- package/dist/src/lib/validateAddress.js +2 -0
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -32,6 +32,7 @@ Object.defineProperty(exports, 'BaseError', {
|
|
|
32
32
|
});
|
|
33
33
|
exports.BridgeNameEnum = require_bridge_name_enum.BridgeNameEnum;
|
|
34
34
|
exports.Chains = require_caip2.Chains;
|
|
35
|
+
exports.DestinationAddressMatchesTokenAddressError = require_errors.DestinationAddressMatchesTokenAddressError;
|
|
35
36
|
exports.DestinationExplicitNearAccountDoesntExistError = require_error.DestinationExplicitNearAccountDoesntExistError;
|
|
36
37
|
exports.FeeExceedsAmountError = require_errors.FeeExceedsAmountError;
|
|
37
38
|
exports.HotWithdrawalApiFeeRequestTimeoutError = require_error$1.HotWithdrawalApiFeeRequestTimeoutError;
|
package/dist/index.d.cts
CHANGED
|
@@ -14,7 +14,7 @@ import { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSi
|
|
|
14
14
|
import { createDefaultRoute, createHotBridgeRoute, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute } from "./src/lib/route-config-factory.cjs";
|
|
15
15
|
import { POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE } from "./src/constants/poa-tokens-routable-through-omni-bridge.cjs";
|
|
16
16
|
import { WithdrawalFailedError, WithdrawalFailedErrorType, WithdrawalWatchError, WithdrawalWatchErrorType } from "./src/core/withdrawal-watcher.cjs";
|
|
17
|
-
import { FeeExceedsAmountError, FeeExceedsAmountErrorType, MinWithdrawalAmountError, MinWithdrawalAmountErrorType, TrustlineNotFoundError, TrustlineNotFoundErrorType, UnsupportedAssetIdError, UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, UnsupportedDestinationMemoErrorType } from "./src/classes/errors.cjs";
|
|
17
|
+
import { DestinationAddressMatchesTokenAddressError, DestinationAddressMatchesTokenAddressErrorType, FeeExceedsAmountError, FeeExceedsAmountErrorType, MinWithdrawalAmountError, MinWithdrawalAmountErrorType, TrustlineNotFoundError, TrustlineNotFoundErrorType, UnsupportedAssetIdError, UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, UnsupportedDestinationMemoErrorType } from "./src/classes/errors.cjs";
|
|
18
18
|
import { DestinationExplicitNearAccountDoesntExistError, DestinationExplicitNearAccountDoesntExistErrorType } from "./src/bridges/direct-bridge/error.cjs";
|
|
19
19
|
import { HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalApiFeeRequestTimeoutErrorType, HotWithdrawalNotFoundError, HotWithdrawalNotFoundErrorType } from "./src/bridges/hot-bridge/error.cjs";
|
|
20
20
|
import { InsufficientUtxoForOmniBridgeWithdrawalError, InsufficientUtxoForOmniBridgeWithdrawalErrorType, IntentsNearOmniAvailableBalanceTooLowError, IntentsNearOmniAvailableBalanceTooLowErrorType, InvalidFeeValueError, InvalidFeeValueErrorType, OmniWithdrawalApiFeeRequestTimeoutError, OmniWithdrawalApiFeeRequestTimeoutErrorType, TokenNotFoundInDestinationChainError, TokenNotFoundInDestinationChainErrorType } from "./src/bridges/omni-bridge/error.cjs";
|
|
@@ -22,4 +22,4 @@ import { XrplDepositAuthEnabledError, XrplDepositAuthEnabledErrorType, XrplDesti
|
|
|
22
22
|
import { computeIntentHash } from "./src/intents/intent-hash.cjs";
|
|
23
23
|
import { validateAddress } from "./src/lib/validateAddress.cjs";
|
|
24
24
|
import { AssertionError, AssertionErrorType, BaseError, BaseErrorType, EnvConfig, HttpRequestError, HttpRequestErrorType, ILogger, IntentSettlementError, IntentSettlementErrorType, NearIntentsEnv, PoaWithdrawalInvariantError, PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, PoaWithdrawalPendingErrorType, QuoteError, QuoteErrorType, RelayPublishError, RelayPublishErrorType, RelayPublishRejectedError, RelayPublishRejectedErrorType, RelayPublishResultUnknownError, RelayPublishResultUnknownErrorType, RetryOptions, RpcEndpoint, RpcEndpointConfig, RpcRequestError, RpcRequestErrorType, TimeoutError, TimeoutErrorType } from "@defuse-protocol/internal-utils";
|
|
25
|
-
export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, DestinationExplicitNearAccountDoesntExistError, type DestinationExplicitNearAccountDoesntExistErrorType, type EnvConfig, type Erc191RawPayload, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalApiFeeRequestTimeoutError, type HotWithdrawalApiFeeRequestTimeoutErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, InsufficientUtxoForOmniBridgeWithdrawalError, type InsufficientUtxoForOmniBridgeWithdrawalErrorType, type IntentPayload, IntentPayloadBuilder, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, InvalidFeeValueError, type InvalidFeeValueErrorType, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type Nep413RawPayload, type OmniBridgeRouteConfig, OmniWithdrawalApiFeeRequestTimeoutError, type OmniWithdrawalApiFeeRequestTimeoutErrorType, type OnBeforePublishIntentHook, POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE, type ParsedAssetInfo, type PoaBridgeRouteConfig, PoaWithdrawalInvariantError, type PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, type PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, type PoaWithdrawalPendingErrorType, type ProcessWithdrawalArgs, QuoteError, type QuoteErrorType, type QuoteOptions, RelayPublishError, type RelayPublishErrorType, RelayPublishRejectedError, type RelayPublishRejectedErrorType, RelayPublishResultUnknownError, type RelayPublishResultUnknownErrorType, type RetryOptions, type RouteConfig, RouteEnum, type RouteEnumValues, type RpcEndpoint, type RpcEndpointConfig, 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, WithdrawalFailedError, type WithdrawalFailedErrorType, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, WithdrawalWatchError, type WithdrawalWatchErrorType, XrplDepositAuthEnabledError, type XrplDepositAuthEnabledErrorType, XrplDestinationTagRequiredError, type XrplDestinationTagRequiredErrorType, computeIntentHash, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute, validateAddress as validateAddressFormat };
|
|
25
|
+
export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, DestinationAddressMatchesTokenAddressError, type DestinationAddressMatchesTokenAddressErrorType, DestinationExplicitNearAccountDoesntExistError, type DestinationExplicitNearAccountDoesntExistErrorType, type EnvConfig, type Erc191RawPayload, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalApiFeeRequestTimeoutError, type HotWithdrawalApiFeeRequestTimeoutErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, InsufficientUtxoForOmniBridgeWithdrawalError, type InsufficientUtxoForOmniBridgeWithdrawalErrorType, type IntentPayload, IntentPayloadBuilder, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, InvalidFeeValueError, type InvalidFeeValueErrorType, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type Nep413RawPayload, type OmniBridgeRouteConfig, OmniWithdrawalApiFeeRequestTimeoutError, type OmniWithdrawalApiFeeRequestTimeoutErrorType, type OnBeforePublishIntentHook, POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE, type ParsedAssetInfo, type PoaBridgeRouteConfig, PoaWithdrawalInvariantError, type PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, type PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, type PoaWithdrawalPendingErrorType, type ProcessWithdrawalArgs, QuoteError, type QuoteErrorType, type QuoteOptions, RelayPublishError, type RelayPublishErrorType, RelayPublishRejectedError, type RelayPublishRejectedErrorType, RelayPublishResultUnknownError, type RelayPublishResultUnknownErrorType, type RetryOptions, type RouteConfig, RouteEnum, type RouteEnumValues, type RpcEndpoint, type RpcEndpointConfig, 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, WithdrawalFailedError, type WithdrawalFailedErrorType, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, WithdrawalWatchError, type WithdrawalWatchErrorType, XrplDepositAuthEnabledError, type XrplDepositAuthEnabledErrorType, XrplDestinationTagRequiredError, type XrplDestinationTagRequiredErrorType, computeIntentHash, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute, validateAddress as validateAddressFormat };
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSi
|
|
|
14
14
|
import { createDefaultRoute, createHotBridgeRoute, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute } from "./src/lib/route-config-factory.js";
|
|
15
15
|
import { POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE } from "./src/constants/poa-tokens-routable-through-omni-bridge.js";
|
|
16
16
|
import { WithdrawalFailedError, WithdrawalFailedErrorType, WithdrawalWatchError, WithdrawalWatchErrorType } from "./src/core/withdrawal-watcher.js";
|
|
17
|
-
import { FeeExceedsAmountError, FeeExceedsAmountErrorType, MinWithdrawalAmountError, MinWithdrawalAmountErrorType, TrustlineNotFoundError, TrustlineNotFoundErrorType, UnsupportedAssetIdError, UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, UnsupportedDestinationMemoErrorType } from "./src/classes/errors.js";
|
|
17
|
+
import { DestinationAddressMatchesTokenAddressError, DestinationAddressMatchesTokenAddressErrorType, FeeExceedsAmountError, FeeExceedsAmountErrorType, MinWithdrawalAmountError, MinWithdrawalAmountErrorType, TrustlineNotFoundError, TrustlineNotFoundErrorType, UnsupportedAssetIdError, UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, UnsupportedDestinationMemoErrorType } from "./src/classes/errors.js";
|
|
18
18
|
import { DestinationExplicitNearAccountDoesntExistError, DestinationExplicitNearAccountDoesntExistErrorType } from "./src/bridges/direct-bridge/error.js";
|
|
19
19
|
import { HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalApiFeeRequestTimeoutErrorType, HotWithdrawalNotFoundError, HotWithdrawalNotFoundErrorType } from "./src/bridges/hot-bridge/error.js";
|
|
20
20
|
import { InsufficientUtxoForOmniBridgeWithdrawalError, InsufficientUtxoForOmniBridgeWithdrawalErrorType, IntentsNearOmniAvailableBalanceTooLowError, IntentsNearOmniAvailableBalanceTooLowErrorType, InvalidFeeValueError, InvalidFeeValueErrorType, OmniWithdrawalApiFeeRequestTimeoutError, OmniWithdrawalApiFeeRequestTimeoutErrorType, TokenNotFoundInDestinationChainError, TokenNotFoundInDestinationChainErrorType } from "./src/bridges/omni-bridge/error.js";
|
|
@@ -22,4 +22,4 @@ import { XrplDepositAuthEnabledError, XrplDepositAuthEnabledErrorType, XrplDesti
|
|
|
22
22
|
import { computeIntentHash } from "./src/intents/intent-hash.js";
|
|
23
23
|
import { validateAddress } from "./src/lib/validateAddress.js";
|
|
24
24
|
import { AssertionError, AssertionErrorType, BaseError, BaseErrorType, EnvConfig, HttpRequestError, HttpRequestErrorType, ILogger, IntentSettlementError, IntentSettlementErrorType, NearIntentsEnv, PoaWithdrawalInvariantError, PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, PoaWithdrawalPendingErrorType, QuoteError, QuoteErrorType, RelayPublishError, RelayPublishErrorType, RelayPublishRejectedError, RelayPublishRejectedErrorType, RelayPublishResultUnknownError, RelayPublishResultUnknownErrorType, RetryOptions, RpcEndpoint, RpcEndpointConfig, RpcRequestError, RpcRequestErrorType, TimeoutError, TimeoutErrorType } from "@defuse-protocol/internal-utils";
|
|
25
|
-
export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, DestinationExplicitNearAccountDoesntExistError, type DestinationExplicitNearAccountDoesntExistErrorType, type EnvConfig, type Erc191RawPayload, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalApiFeeRequestTimeoutError, type HotWithdrawalApiFeeRequestTimeoutErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, InsufficientUtxoForOmniBridgeWithdrawalError, type InsufficientUtxoForOmniBridgeWithdrawalErrorType, type IntentPayload, IntentPayloadBuilder, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, InvalidFeeValueError, type InvalidFeeValueErrorType, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type Nep413RawPayload, type OmniBridgeRouteConfig, OmniWithdrawalApiFeeRequestTimeoutError, type OmniWithdrawalApiFeeRequestTimeoutErrorType, type OnBeforePublishIntentHook, POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE, type ParsedAssetInfo, type PoaBridgeRouteConfig, PoaWithdrawalInvariantError, type PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, type PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, type PoaWithdrawalPendingErrorType, type ProcessWithdrawalArgs, QuoteError, type QuoteErrorType, type QuoteOptions, RelayPublishError, type RelayPublishErrorType, RelayPublishRejectedError, type RelayPublishRejectedErrorType, RelayPublishResultUnknownError, type RelayPublishResultUnknownErrorType, type RetryOptions, type RouteConfig, RouteEnum, type RouteEnumValues, type RpcEndpoint, type RpcEndpointConfig, 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, WithdrawalFailedError, type WithdrawalFailedErrorType, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, WithdrawalWatchError, type WithdrawalWatchErrorType, XrplDepositAuthEnabledError, type XrplDepositAuthEnabledErrorType, XrplDestinationTagRequiredError, type XrplDestinationTagRequiredErrorType, computeIntentHash, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute, validateAddress as validateAddressFormat };
|
|
25
|
+
export { AssertionError, type AssertionErrorType, BaseError, type BaseErrorType, type BatchWithdrawalResult, BridgeNameEnum, type BridgeNameEnumValues, type Chain, Chains, DestinationAddressMatchesTokenAddressError, type DestinationAddressMatchesTokenAddressErrorType, DestinationExplicitNearAccountDoesntExistError, type DestinationExplicitNearAccountDoesntExistErrorType, type EnvConfig, type Erc191RawPayload, type FeeEstimation, FeeExceedsAmountError, type FeeExceedsAmountErrorType, type HotBridgeRouteConfig, HotWithdrawalApiFeeRequestTimeoutError, type HotWithdrawalApiFeeRequestTimeoutErrorType, HotWithdrawalNotFoundError, type HotWithdrawalNotFoundErrorType, HttpRequestError, type HttpRequestErrorType, type IIntentSigner, type ILogger, InsufficientUtxoForOmniBridgeWithdrawalError, type InsufficientUtxoForOmniBridgeWithdrawalErrorType, type IntentPayload, IntentPayloadBuilder, type IntentPayloadFactory, type IntentPrimitive, type IntentPublishResult, type IntentRelayParamsFactory, IntentSettlementError, type IntentSettlementErrorType, type IntentSettlementStatus, IntentsNearOmniAvailableBalanceTooLowError, type IntentsNearOmniAvailableBalanceTooLowErrorType, IntentsSDK, type IntentsSDKConfig, type InternalTransferRouteConfig, InvalidFeeValueError, type InvalidFeeValueErrorType, MinWithdrawalAmountError, type MinWithdrawalAmountErrorType, type MultiPayload, type NearIntentsEnv, type NearTxInfo, type NearWithdrawalRouteConfig, type Nep413RawPayload, type OmniBridgeRouteConfig, OmniWithdrawalApiFeeRequestTimeoutError, type OmniWithdrawalApiFeeRequestTimeoutErrorType, type OnBeforePublishIntentHook, POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE, type ParsedAssetInfo, type PoaBridgeRouteConfig, PoaWithdrawalInvariantError, type PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundError, type PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingError, type PoaWithdrawalPendingErrorType, type ProcessWithdrawalArgs, QuoteError, type QuoteErrorType, type QuoteOptions, RelayPublishError, type RelayPublishErrorType, RelayPublishRejectedError, type RelayPublishRejectedErrorType, RelayPublishResultUnknownError, type RelayPublishResultUnknownErrorType, type RetryOptions, type RouteConfig, RouteEnum, type RouteEnumValues, type RpcEndpoint, type RpcEndpointConfig, 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, WithdrawalFailedError, type WithdrawalFailedErrorType, type WithdrawalIdentifier, type WithdrawalParams, type WithdrawalResult, WithdrawalWatchError, type WithdrawalWatchErrorType, XrplDepositAuthEnabledError, type XrplDepositAuthEnabledErrorType, XrplDestinationTagRequiredError, type XrplDestinationTagRequiredErrorType, computeIntentHash, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute, validateAddress as validateAddressFormat };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FeeExceedsAmountError, MinWithdrawalAmountError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError } from "./src/classes/errors.js";
|
|
1
|
+
import { DestinationAddressMatchesTokenAddressError, FeeExceedsAmountError, MinWithdrawalAmountError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError } from "./src/classes/errors.js";
|
|
2
2
|
import { RouteEnum } from "./src/constants/route-enum.js";
|
|
3
3
|
import { Chains } from "./src/lib/caip2.js";
|
|
4
4
|
import { validateAddress } from "./src/lib/validateAddress.js";
|
|
@@ -17,4 +17,4 @@ import { createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSi
|
|
|
17
17
|
import { createDefaultRoute, createHotBridgeRoute, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute } from "./src/lib/route-config-factory.js";
|
|
18
18
|
import { AssertionError, BaseError, HttpRequestError, IntentSettlementError, PoaWithdrawalInvariantError, PoaWithdrawalNotFoundError, PoaWithdrawalPendingError, QuoteError, RelayPublishError, RelayPublishRejectedError, RelayPublishResultUnknownError, RpcRequestError, TimeoutError } from "@defuse-protocol/internal-utils";
|
|
19
19
|
|
|
20
|
-
export { AssertionError, BaseError, BridgeNameEnum, Chains, DestinationExplicitNearAccountDoesntExistError, FeeExceedsAmountError, HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalNotFoundError, HttpRequestError, InsufficientUtxoForOmniBridgeWithdrawalError, IntentPayloadBuilder, IntentSettlementError, IntentsNearOmniAvailableBalanceTooLowError, IntentsSDK, InvalidFeeValueError, MinWithdrawalAmountError, OmniWithdrawalApiFeeRequestTimeoutError, POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE, PoaWithdrawalInvariantError, PoaWithdrawalNotFoundError, PoaWithdrawalPendingError, QuoteError, RelayPublishError, RelayPublishRejectedError, RelayPublishResultUnknownError, RouteEnum, RpcRequestError, TimeoutError, TokenNotFoundInDestinationChainError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError, VersionedNonceBuilder, WithdrawalFailedError, WithdrawalWatchError, XrplDepositAuthEnabledError, XrplDestinationTagRequiredError, computeIntentHash, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute, validateAddress as validateAddressFormat };
|
|
20
|
+
export { AssertionError, BaseError, BridgeNameEnum, Chains, DestinationAddressMatchesTokenAddressError, DestinationExplicitNearAccountDoesntExistError, FeeExceedsAmountError, HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalNotFoundError, HttpRequestError, InsufficientUtxoForOmniBridgeWithdrawalError, IntentPayloadBuilder, IntentSettlementError, IntentsNearOmniAvailableBalanceTooLowError, IntentsSDK, InvalidFeeValueError, MinWithdrawalAmountError, OmniWithdrawalApiFeeRequestTimeoutError, POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE, PoaWithdrawalInvariantError, PoaWithdrawalNotFoundError, PoaWithdrawalPendingError, QuoteError, RelayPublishError, RelayPublishRejectedError, RelayPublishResultUnknownError, RouteEnum, RpcRequestError, TimeoutError, TokenNotFoundInDestinationChainError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError, VersionedNonceBuilder, WithdrawalFailedError, WithdrawalWatchError, XrplDepositAuthEnabledError, XrplDestinationTagRequiredError, computeIntentHash, createDefaultRoute, createHotBridgeRoute, createIntentSignerNEP413, createIntentSignerNearKeyPair, createIntentSignerViem, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute, validateAddress as validateAddressFormat };
|
|
@@ -8,6 +8,7 @@ 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_compareAddresses = require('../../lib/compareAddresses.cjs');
|
|
11
12
|
const require_error = require('./error.cjs');
|
|
12
13
|
let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
13
14
|
let lru_cache = require("lru-cache");
|
|
@@ -73,6 +74,8 @@ var DirectBridge = class {
|
|
|
73
74
|
*/
|
|
74
75
|
async validateWithdrawal(args) {
|
|
75
76
|
if (require_validateAddress.validateAddress(args.destinationAddress, require_caip2.Chains.Near) === false) throw new require_errors.InvalidDestinationAddressForWithdrawalError(args.destinationAddress, require_caip2.Chains.Near);
|
|
77
|
+
const { contractId: tokenAccountId } = _defuse_protocol_internal_utils.utils.parseDefuseAssetId(args.assetId);
|
|
78
|
+
if (require_compareAddresses.compareAddresses(tokenAccountId, args.destinationAddress, require_caip2.Chains.Near)) throw new require_errors.DestinationAddressMatchesTokenAddressError(tokenAccountId, args.assetId);
|
|
76
79
|
if (_defuse_protocol_internal_utils.utils.isImplicitAccount(args.destinationAddress) === false && await this.getCachedAccountExistenceCheck(args.destinationAddress) === false) throw new require_error.DestinationExplicitNearAccountDoesntExistError(args.destinationAddress);
|
|
77
80
|
}
|
|
78
81
|
async estimateWithdrawalFee(args) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InvalidDestinationAddressForWithdrawalError, UnsupportedAssetIdError } from "../../classes/errors.js";
|
|
1
|
+
import { DestinationAddressMatchesTokenAddressError, InvalidDestinationAddressForWithdrawalError, UnsupportedAssetIdError } from "../../classes/errors.js";
|
|
2
2
|
import { RouteEnum } from "../../constants/route-enum.js";
|
|
3
3
|
import { Chains } from "../../lib/caip2.js";
|
|
4
4
|
import { getFeeQuote, getUnderlyingFee } from "../../lib/estimate-fee.js";
|
|
@@ -7,6 +7,7 @@ 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
9
|
import { accountExistsInNEAR, createWithdrawIntentPrimitive, withdrawalParamsInvariant } from "./direct-bridge-utils.js";
|
|
10
|
+
import { compareAddresses } from "../../lib/compareAddresses.js";
|
|
10
11
|
import { DestinationExplicitNearAccountDoesntExistError } from "./error.js";
|
|
11
12
|
import { assert, getNearNep141MinStorageBalance, getNearNep141StorageBalance, utils } from "@defuse-protocol/internal-utils";
|
|
12
13
|
import { LRUCache } from "lru-cache";
|
|
@@ -72,6 +73,8 @@ var DirectBridge = class {
|
|
|
72
73
|
*/
|
|
73
74
|
async validateWithdrawal(args) {
|
|
74
75
|
if (validateAddress(args.destinationAddress, Chains.Near) === false) throw new InvalidDestinationAddressForWithdrawalError(args.destinationAddress, Chains.Near);
|
|
76
|
+
const { contractId: tokenAccountId } = utils.parseDefuseAssetId(args.assetId);
|
|
77
|
+
if (compareAddresses(tokenAccountId, args.destinationAddress, Chains.Near)) throw new DestinationAddressMatchesTokenAddressError(tokenAccountId, args.assetId);
|
|
75
78
|
if (utils.isImplicitAccount(args.destinationAddress) === false && await this.getCachedAccountExistenceCheck(args.destinationAddress) === false) throw new DestinationExplicitNearAccountDoesntExistError(args.destinationAddress);
|
|
76
79
|
}
|
|
77
80
|
async estimateWithdrawalFee(args) {
|
|
@@ -6,6 +6,7 @@ const require_estimate_fee = require('../../lib/estimate-fee.cjs');
|
|
|
6
6
|
const require_parse_defuse_asset_id = require('../../lib/parse-defuse-asset-id.cjs');
|
|
7
7
|
const require_validateAddress = require('../../lib/validateAddress.cjs');
|
|
8
8
|
const require_bridge_name_enum = require('../../constants/bridge-name-enum.cjs');
|
|
9
|
+
const require_compareAddresses = require('../../lib/compareAddresses.cjs');
|
|
9
10
|
const require_error = require('./error.cjs');
|
|
10
11
|
const require_hot_bridge_constants = require('./hot-bridge-constants.cjs');
|
|
11
12
|
const require_hot_bridge_utils = require('./hot-bridge-utils.cjs');
|
|
@@ -122,8 +123,10 @@ var HotBridge = class HotBridge {
|
|
|
122
123
|
(0, _defuse_protocol_internal_utils.assert)(assetInfo != null, "Asset is not supported");
|
|
123
124
|
require_hot_bridge_utils.hotBlockchainInvariant(assetInfo.blockchain);
|
|
124
125
|
if (require_validateAddress.validateAddress(args.destinationAddress, assetInfo.blockchain) === false) throw new require_errors.InvalidDestinationAddressForWithdrawalError(args.destinationAddress, assetInfo.blockchain);
|
|
126
|
+
const nativeAsset = "native" in assetInfo;
|
|
127
|
+
const token = nativeAsset ? "native" : assetInfo.address;
|
|
128
|
+
if (!nativeAsset && require_compareAddresses.compareAddresses(token, args.destinationAddress, assetInfo.blockchain)) throw new require_errors.DestinationAddressMatchesTokenAddressError(token, args.assetId);
|
|
125
129
|
if (assetInfo.blockchain === require_caip2.Chains.Stellar) {
|
|
126
|
-
const token = "native" in assetInfo ? "native" : assetInfo.address;
|
|
127
130
|
if (!await this.hotSdk.stellar.isTrustlineExists(args.destinationAddress, token)) throw new require_errors.TrustlineNotFoundError(args.destinationAddress, args.assetId, assetInfo.blockchain, token);
|
|
128
131
|
}
|
|
129
132
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { InvalidDestinationAddressForWithdrawalError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError } from "../../classes/errors.js";
|
|
1
|
+
import { DestinationAddressMatchesTokenAddressError, InvalidDestinationAddressForWithdrawalError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError } from "../../classes/errors.js";
|
|
2
2
|
import { RouteEnum } from "../../constants/route-enum.js";
|
|
3
3
|
import { Chains } from "../../lib/caip2.js";
|
|
4
4
|
import { getFeeQuote, getUnderlyingFee } from "../../lib/estimate-fee.js";
|
|
5
5
|
import { parseDefuseAssetId } from "../../lib/parse-defuse-asset-id.js";
|
|
6
6
|
import { validateAddress } from "../../lib/validateAddress.js";
|
|
7
7
|
import { BridgeNameEnum } from "../../constants/bridge-name-enum.js";
|
|
8
|
+
import { compareAddresses } from "../../lib/compareAddresses.js";
|
|
8
9
|
import { HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalNotFoundError } from "./error.js";
|
|
9
10
|
import { HotWithdrawStatus, MIN_GAS_AMOUNT } from "./hot-bridge-constants.js";
|
|
10
11
|
import { formatTxHash, getFeeAssetIdForChain, hotBlockchainInvariant, hotNetworkIdToCAIP2, toHotNetworkId } from "./hot-bridge-utils.js";
|
|
@@ -120,8 +121,10 @@ var HotBridge$1 = class HotBridge$1 {
|
|
|
120
121
|
assert(assetInfo != null, "Asset is not supported");
|
|
121
122
|
hotBlockchainInvariant(assetInfo.blockchain);
|
|
122
123
|
if (validateAddress(args.destinationAddress, assetInfo.blockchain) === false) throw new InvalidDestinationAddressForWithdrawalError(args.destinationAddress, assetInfo.blockchain);
|
|
124
|
+
const nativeAsset = "native" in assetInfo;
|
|
125
|
+
const token = nativeAsset ? "native" : assetInfo.address;
|
|
126
|
+
if (!nativeAsset && compareAddresses(token, args.destinationAddress, assetInfo.blockchain)) throw new DestinationAddressMatchesTokenAddressError(token, args.assetId);
|
|
123
127
|
if (assetInfo.blockchain === Chains.Stellar) {
|
|
124
|
-
const token = "native" in assetInfo ? "native" : assetInfo.address;
|
|
125
128
|
if (!await this.hotSdk.stellar.isTrustlineExists(args.destinationAddress, token)) throw new TrustlineNotFoundError(args.destinationAddress, args.assetId, assetInfo.blockchain, token);
|
|
126
129
|
}
|
|
127
130
|
}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
const NEAR_NATIVE_ASSET_ID = "nep141:wrap.near";
|
|
4
4
|
const OMNI_BRIDGE_CONTRACT = "omni.bridge.near";
|
|
5
5
|
const MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR = 500000000000000000000000n;
|
|
6
|
+
const SOL_OMNI_CONTRACT_ID = "sol.omft.near";
|
|
7
|
+
const MIN_AMOUNT_SOL_OMNI_WITHDRAWAL = 890880n;
|
|
6
8
|
const MIN_GAS_AMOUNT = "37400000000000";
|
|
7
9
|
const INTENTS_STORAGE_BALANCE_CACHE_KEY = "INTENTS_STORAGE_BALANCE";
|
|
8
10
|
const FEE_SUBSIDIZED_TOKENS = ["nep141:lsd-usdt.rhealab.near"];
|
|
@@ -10,7 +12,9 @@ const FEE_SUBSIDIZED_TOKENS = ["nep141:lsd-usdt.rhealab.near"];
|
|
|
10
12
|
//#endregion
|
|
11
13
|
exports.FEE_SUBSIDIZED_TOKENS = FEE_SUBSIDIZED_TOKENS;
|
|
12
14
|
exports.INTENTS_STORAGE_BALANCE_CACHE_KEY = INTENTS_STORAGE_BALANCE_CACHE_KEY;
|
|
15
|
+
exports.MIN_AMOUNT_SOL_OMNI_WITHDRAWAL = MIN_AMOUNT_SOL_OMNI_WITHDRAWAL;
|
|
13
16
|
exports.MIN_GAS_AMOUNT = MIN_GAS_AMOUNT;
|
|
14
17
|
exports.MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR = MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR;
|
|
15
18
|
exports.NEAR_NATIVE_ASSET_ID = NEAR_NATIVE_ASSET_ID;
|
|
16
|
-
exports.OMNI_BRIDGE_CONTRACT = OMNI_BRIDGE_CONTRACT;
|
|
19
|
+
exports.OMNI_BRIDGE_CONTRACT = OMNI_BRIDGE_CONTRACT;
|
|
20
|
+
exports.SOL_OMNI_CONTRACT_ID = SOL_OMNI_CONTRACT_ID;
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
const NEAR_NATIVE_ASSET_ID = "nep141:wrap.near";
|
|
3
3
|
const OMNI_BRIDGE_CONTRACT = "omni.bridge.near";
|
|
4
4
|
const MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR = 500000000000000000000000n;
|
|
5
|
+
const SOL_OMNI_CONTRACT_ID = "sol.omft.near";
|
|
6
|
+
const MIN_AMOUNT_SOL_OMNI_WITHDRAWAL = 890880n;
|
|
5
7
|
const MIN_GAS_AMOUNT = "37400000000000";
|
|
6
8
|
const INTENTS_STORAGE_BALANCE_CACHE_KEY = "INTENTS_STORAGE_BALANCE";
|
|
7
9
|
const FEE_SUBSIDIZED_TOKENS = ["nep141:lsd-usdt.rhealab.near"];
|
|
8
10
|
|
|
9
11
|
//#endregion
|
|
10
|
-
export { FEE_SUBSIDIZED_TOKENS, INTENTS_STORAGE_BALANCE_CACHE_KEY, MIN_GAS_AMOUNT, MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR, NEAR_NATIVE_ASSET_ID, OMNI_BRIDGE_CONTRACT };
|
|
12
|
+
export { FEE_SUBSIDIZED_TOKENS, INTENTS_STORAGE_BALANCE_CACHE_KEY, MIN_AMOUNT_SOL_OMNI_WITHDRAWAL, MIN_GAS_AMOUNT, MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR, NEAR_NATIVE_ASSET_ID, OMNI_BRIDGE_CONTRACT, SOL_OMNI_CONTRACT_ID };
|
|
@@ -6,6 +6,7 @@ const require_estimate_fee = require('../../lib/estimate-fee.cjs');
|
|
|
6
6
|
const require_parse_defuse_asset_id = require('../../lib/parse-defuse-asset-id.cjs');
|
|
7
7
|
const require_validateAddress = require('../../lib/validateAddress.cjs');
|
|
8
8
|
const require_bridge_name_enum = require('../../constants/bridge-name-enum.cjs');
|
|
9
|
+
const require_compareAddresses = require('../../lib/compareAddresses.cjs');
|
|
9
10
|
const require_error = require('./error.cjs');
|
|
10
11
|
const require_omni_bridge_constants = require('./omni-bridge-constants.cjs');
|
|
11
12
|
const require_poa_tokens_routable_through_omni_bridge = require('../../constants/poa-tokens-routable-through-omni-bridge.cjs');
|
|
@@ -164,10 +165,12 @@ var OmniBridge = class {
|
|
|
164
165
|
if (require_validateAddress.validateAddress(args.destinationAddress, assetInfo.blockchain) === false) throw new require_errors.InvalidDestinationAddressForWithdrawalError(args.destinationAddress, assetInfo.blockchain);
|
|
165
166
|
const omniChainKind = require_omni_bridge_utils.caip2ToChainKind(assetInfo.blockchain);
|
|
166
167
|
(0, _defuse_protocol_internal_utils.assert)(omniChainKind !== null, `Chain ${assetInfo.blockchain} is not supported by Omni Bridge`);
|
|
167
|
-
const
|
|
168
|
-
if (
|
|
169
|
-
const
|
|
170
|
-
(
|
|
168
|
+
const destTokenOmniAddress = await this.getCachedDestinationTokenAddress(assetInfo.contractId, omniChainKind);
|
|
169
|
+
if (destTokenOmniAddress === null) throw new require_error.TokenNotFoundInDestinationChainError(args.assetId, assetInfo.blockchain);
|
|
170
|
+
const destTokenAddress = (0, _omni_bridge_core.getAddress)(destTokenOmniAddress);
|
|
171
|
+
if (require_compareAddresses.compareAddresses(destTokenAddress, args.destinationAddress, assetInfo.blockchain)) throw new require_errors.DestinationAddressMatchesTokenAddressError(destTokenAddress, args.assetId);
|
|
172
|
+
const decimals = await this.getCachedTokenDecimals(destTokenOmniAddress);
|
|
173
|
+
(0, _defuse_protocol_internal_utils.assert)(decimals !== null, `Failed to retrieve token decimals for address ${destTokenOmniAddress} via OmniBridge contract.
|
|
171
174
|
Ensure the token is supported and the address is correct.`);
|
|
172
175
|
if (!args.skipMinAmountValidation) {
|
|
173
176
|
if ((0, _omni_bridge_core.verifyTransferAmount)(args.amount, 0n, decimals.origin_decimals, decimals.decimals) === false) throw new require_errors.MinWithdrawalAmountError((0, _omni_bridge_core.getMinimumTransferableAmount)(decimals.origin_decimals, decimals.decimals), args.amount, args.assetId);
|
|
@@ -195,7 +198,7 @@ var OmniBridge = class {
|
|
|
195
198
|
const actualAmountWithFee = args.amount + utxoMaxGasFee + utxoProtocolFee;
|
|
196
199
|
if (actualAmountWithFee < minAmount) throw new require_errors.MinWithdrawalAmountError(minAmount, actualAmountWithFee, args.assetId);
|
|
197
200
|
}
|
|
198
|
-
}
|
|
201
|
+
} else if (!args.skipMinAmountValidation && omniChainKind === _omni_bridge_core.ChainKind.Sol && assetInfo.contractId === require_omni_bridge_constants.SOL_OMNI_CONTRACT_ID && args.amount < require_omni_bridge_constants.MIN_AMOUNT_SOL_OMNI_WITHDRAWAL) throw new require_errors.MinWithdrawalAmountError(require_omni_bridge_constants.MIN_AMOUNT_SOL_OMNI_WITHDRAWAL, args.amount, args.assetId);
|
|
199
202
|
}
|
|
200
203
|
async estimateWithdrawalFee(args) {
|
|
201
204
|
const assetInfo = this.makeAssetInfo(args.withdrawalParams.assetId, args.withdrawalParams.routeConfig);
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { InvalidDestinationAddressForWithdrawalError, MinWithdrawalAmountError, UnsupportedAssetIdError } from "../../classes/errors.js";
|
|
1
|
+
import { DestinationAddressMatchesTokenAddressError, InvalidDestinationAddressForWithdrawalError, MinWithdrawalAmountError, UnsupportedAssetIdError } from "../../classes/errors.js";
|
|
2
2
|
import { RouteEnum } from "../../constants/route-enum.js";
|
|
3
3
|
import { Chains } from "../../lib/caip2.js";
|
|
4
4
|
import { getFeeQuote, getUnderlyingFee } from "../../lib/estimate-fee.js";
|
|
5
5
|
import { parseDefuseAssetId } from "../../lib/parse-defuse-asset-id.js";
|
|
6
6
|
import { validateAddress } from "../../lib/validateAddress.js";
|
|
7
7
|
import { BridgeNameEnum } from "../../constants/bridge-name-enum.js";
|
|
8
|
+
import { compareAddresses } from "../../lib/compareAddresses.js";
|
|
8
9
|
import { InsufficientUtxoForOmniBridgeWithdrawalError, IntentsNearOmniAvailableBalanceTooLowError, InvalidFeeValueError, OmniWithdrawalApiFeeRequestTimeoutError, TokenNotFoundInDestinationChainError } from "./error.js";
|
|
9
|
-
import { FEE_SUBSIDIZED_TOKENS, INTENTS_STORAGE_BALANCE_CACHE_KEY, MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR, NEAR_NATIVE_ASSET_ID, OMNI_BRIDGE_CONTRACT } from "./omni-bridge-constants.js";
|
|
10
|
+
import { FEE_SUBSIDIZED_TOKENS, INTENTS_STORAGE_BALANCE_CACHE_KEY, MIN_AMOUNT_SOL_OMNI_WITHDRAWAL, MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR, NEAR_NATIVE_ASSET_ID, OMNI_BRIDGE_CONTRACT, SOL_OMNI_CONTRACT_ID } from "./omni-bridge-constants.js";
|
|
10
11
|
import { POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE } from "../../constants/poa-tokens-routable-through-omni-bridge.js";
|
|
11
12
|
import { caip2ToChainKind, chainKindToCaip2, createWithdrawIntentsPrimitive, getAccountOmniStorageBalance, getBridgedToken, getTokenDecimals, isUtxoChain, poaContractIdToChainKind, validateOmniToken } from "./omni-bridge-utils.js";
|
|
12
13
|
import { assert, getNearNep141MinStorageBalance, getNearNep141StorageBalance, withTimeout } from "@defuse-protocol/internal-utils";
|
|
13
14
|
import { LRUCache } from "lru-cache";
|
|
14
15
|
import TTLCache from "@isaacs/ttlcache";
|
|
15
|
-
import { BridgeAPI, ChainKind, getChain, getMinimumTransferableAmount, isEvmChain, omniAddress, parseOriginChain, verifyTransferAmount } from "@omni-bridge/core";
|
|
16
|
+
import { BridgeAPI, ChainKind, getAddress, getChain, getMinimumTransferableAmount, isEvmChain, omniAddress, parseOriginChain, verifyTransferAmount } from "@omni-bridge/core";
|
|
16
17
|
|
|
17
18
|
//#region src/bridges/omni-bridge/omni-bridge.ts
|
|
18
19
|
var OmniBridge = class {
|
|
@@ -162,10 +163,12 @@ var OmniBridge = class {
|
|
|
162
163
|
if (validateAddress(args.destinationAddress, assetInfo.blockchain) === false) throw new InvalidDestinationAddressForWithdrawalError(args.destinationAddress, assetInfo.blockchain);
|
|
163
164
|
const omniChainKind = caip2ToChainKind(assetInfo.blockchain);
|
|
164
165
|
assert(omniChainKind !== null, `Chain ${assetInfo.blockchain} is not supported by Omni Bridge`);
|
|
165
|
-
const
|
|
166
|
-
if (
|
|
167
|
-
const
|
|
168
|
-
|
|
166
|
+
const destTokenOmniAddress = await this.getCachedDestinationTokenAddress(assetInfo.contractId, omniChainKind);
|
|
167
|
+
if (destTokenOmniAddress === null) throw new TokenNotFoundInDestinationChainError(args.assetId, assetInfo.blockchain);
|
|
168
|
+
const destTokenAddress = getAddress(destTokenOmniAddress);
|
|
169
|
+
if (compareAddresses(destTokenAddress, args.destinationAddress, assetInfo.blockchain)) throw new DestinationAddressMatchesTokenAddressError(destTokenAddress, args.assetId);
|
|
170
|
+
const decimals = await this.getCachedTokenDecimals(destTokenOmniAddress);
|
|
171
|
+
assert(decimals !== null, `Failed to retrieve token decimals for address ${destTokenOmniAddress} via OmniBridge contract.
|
|
169
172
|
Ensure the token is supported and the address is correct.`);
|
|
170
173
|
if (!args.skipMinAmountValidation) {
|
|
171
174
|
if (verifyTransferAmount(args.amount, 0n, decimals.origin_decimals, decimals.decimals) === false) throw new MinWithdrawalAmountError(getMinimumTransferableAmount(decimals.origin_decimals, decimals.decimals), args.amount, args.assetId);
|
|
@@ -193,7 +196,7 @@ var OmniBridge = class {
|
|
|
193
196
|
const actualAmountWithFee = args.amount + utxoMaxGasFee + utxoProtocolFee;
|
|
194
197
|
if (actualAmountWithFee < minAmount) throw new MinWithdrawalAmountError(minAmount, actualAmountWithFee, args.assetId);
|
|
195
198
|
}
|
|
196
|
-
}
|
|
199
|
+
} else if (!args.skipMinAmountValidation && omniChainKind === ChainKind.Sol && assetInfo.contractId === SOL_OMNI_CONTRACT_ID && args.amount < MIN_AMOUNT_SOL_OMNI_WITHDRAWAL) throw new MinWithdrawalAmountError(MIN_AMOUNT_SOL_OMNI_WITHDRAWAL, args.amount, args.assetId);
|
|
197
200
|
}
|
|
198
201
|
async estimateWithdrawalFee(args) {
|
|
199
202
|
const assetInfo = this.makeAssetInfo(args.withdrawalParams.assetId, args.withdrawalParams.routeConfig);
|
|
@@ -6,6 +6,7 @@ const require_estimate_fee = require('../../lib/estimate-fee.cjs');
|
|
|
6
6
|
const require_parse_defuse_asset_id = require('../../lib/parse-defuse-asset-id.cjs');
|
|
7
7
|
const require_validateAddress = require('../../lib/validateAddress.cjs');
|
|
8
8
|
const require_bridge_name_enum = require('../../constants/bridge-name-enum.cjs');
|
|
9
|
+
const require_compareAddresses = require('../../lib/compareAddresses.cjs');
|
|
9
10
|
const require_poa_tokens_routable_through_omni_bridge = require('../../constants/poa-tokens-routable-through-omni-bridge.cjs');
|
|
10
11
|
const require_errors$1 = require('./errors.cjs');
|
|
11
12
|
const require_poa_bridge_utils = require('./poa-bridge-utils.cjs');
|
|
@@ -76,6 +77,7 @@ var PoaBridge = class {
|
|
|
76
77
|
const { tokens } = await this.getCachedSupportedTokens([require_poa_bridge_utils.toPoaNetwork(assetInfo.blockchain)], args.logger);
|
|
77
78
|
const tokenInfo = tokens.find((token) => token.intents_token_id === args.assetId);
|
|
78
79
|
if (tokenInfo == null) throw new require_errors.UnsupportedAssetIdError(args.assetId, "`assetId` is not supported in PoA bridge.");
|
|
80
|
+
if (tokenInfo.origin_chain_address !== "native" && require_compareAddresses.compareAddresses(tokenInfo.origin_chain_address, args.destinationAddress, assetInfo.blockchain)) throw new require_errors.DestinationAddressMatchesTokenAddressError(tokenInfo.origin_chain_address, args.assetId);
|
|
79
81
|
if (!args.skipMinAmountValidation) {
|
|
80
82
|
const minWithdrawalAmount = BigInt(tokenInfo.min_withdrawal_amount);
|
|
81
83
|
if (args.amount < minWithdrawalAmount) throw new require_errors.MinWithdrawalAmountError(minWithdrawalAmount, args.amount, args.assetId);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { InvalidDestinationAddressForWithdrawalError, MinWithdrawalAmountError, UnsupportedAssetIdError } from "../../classes/errors.js";
|
|
1
|
+
import { DestinationAddressMatchesTokenAddressError, InvalidDestinationAddressForWithdrawalError, MinWithdrawalAmountError, UnsupportedAssetIdError } from "../../classes/errors.js";
|
|
2
2
|
import { RouteEnum } from "../../constants/route-enum.js";
|
|
3
3
|
import { Chains } from "../../lib/caip2.js";
|
|
4
4
|
import { getUnderlyingFee } from "../../lib/estimate-fee.js";
|
|
5
5
|
import { parseDefuseAssetId } from "../../lib/parse-defuse-asset-id.js";
|
|
6
6
|
import { validateAddress } from "../../lib/validateAddress.js";
|
|
7
7
|
import { BridgeNameEnum } from "../../constants/bridge-name-enum.js";
|
|
8
|
+
import { compareAddresses } from "../../lib/compareAddresses.js";
|
|
8
9
|
import { POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE } from "../../constants/poa-tokens-routable-through-omni-bridge.js";
|
|
9
10
|
import { XrplDepositAuthEnabledError, XrplDestinationTagRequiredError } from "./errors.js";
|
|
10
11
|
import { contractIdToCaip2, createWithdrawIntentPrimitive, toPoaNetwork } from "./poa-bridge-utils.js";
|
|
@@ -74,6 +75,7 @@ var PoaBridge = class {
|
|
|
74
75
|
const { tokens } = await this.getCachedSupportedTokens([toPoaNetwork(assetInfo.blockchain)], args.logger);
|
|
75
76
|
const tokenInfo = tokens.find((token) => token.intents_token_id === args.assetId);
|
|
76
77
|
if (tokenInfo == null) throw new UnsupportedAssetIdError(args.assetId, "`assetId` is not supported in PoA bridge.");
|
|
78
|
+
if (tokenInfo.origin_chain_address !== "native" && compareAddresses(tokenInfo.origin_chain_address, args.destinationAddress, assetInfo.blockchain)) throw new DestinationAddressMatchesTokenAddressError(tokenInfo.origin_chain_address, args.assetId);
|
|
77
79
|
if (!args.skipMinAmountValidation) {
|
|
78
80
|
const minWithdrawalAmount = BigInt(tokenInfo.min_withdrawal_amount);
|
|
79
81
|
if (args.amount < minWithdrawalAmount) throw new MinWithdrawalAmountError(minWithdrawalAmount, args.amount, args.assetId);
|
|
@@ -66,6 +66,16 @@ var UnsupportedAssetIdError = class extends _defuse_protocol_internal_utils.Base
|
|
|
66
66
|
this.assetId = assetId;
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
|
+
var DestinationAddressMatchesTokenAddressError = class extends _defuse_protocol_internal_utils.BaseError {
|
|
70
|
+
constructor(tokenAddress, assetId) {
|
|
71
|
+
super("Destination address must not be the token contract address.", {
|
|
72
|
+
metaMessages: [`Asset ID: ${assetId}`, `Token address: ${tokenAddress}`],
|
|
73
|
+
name: "DestinationAddressMatchesTokenAddressError"
|
|
74
|
+
});
|
|
75
|
+
this.tokenAddress = tokenAddress;
|
|
76
|
+
this.assetId = assetId;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
69
79
|
var InvalidDestinationAddressForWithdrawalError = class extends _defuse_protocol_internal_utils.BaseError {
|
|
70
80
|
constructor(destinationAddress, destinationChain) {
|
|
71
81
|
super(`Invalid destination address.`, {
|
|
@@ -79,6 +89,7 @@ var InvalidDestinationAddressForWithdrawalError = class extends _defuse_protocol
|
|
|
79
89
|
};
|
|
80
90
|
|
|
81
91
|
//#endregion
|
|
92
|
+
exports.DestinationAddressMatchesTokenAddressError = DestinationAddressMatchesTokenAddressError;
|
|
82
93
|
exports.FeeExceedsAmountError = FeeExceedsAmountError;
|
|
83
94
|
exports.InvalidDestinationAddressForWithdrawalError = InvalidDestinationAddressForWithdrawalError;
|
|
84
95
|
exports.MinWithdrawalAmountError = MinWithdrawalAmountError;
|
|
@@ -44,5 +44,13 @@ declare class UnsupportedAssetIdError extends BaseError {
|
|
|
44
44
|
assetId: string;
|
|
45
45
|
constructor(assetId: string, details: string);
|
|
46
46
|
}
|
|
47
|
+
type DestinationAddressMatchesTokenAddressErrorType = DestinationAddressMatchesTokenAddressError & {
|
|
48
|
+
name: "DestinationAddressMatchesTokenAddressError";
|
|
49
|
+
};
|
|
50
|
+
declare class DestinationAddressMatchesTokenAddressError extends BaseError {
|
|
51
|
+
tokenAddress: string;
|
|
52
|
+
assetId: string;
|
|
53
|
+
constructor(tokenAddress: string, assetId: string);
|
|
54
|
+
}
|
|
47
55
|
//#endregion
|
|
48
|
-
export { FeeExceedsAmountError, FeeExceedsAmountErrorType, MinWithdrawalAmountError, MinWithdrawalAmountErrorType, TrustlineNotFoundError, TrustlineNotFoundErrorType, UnsupportedAssetIdError, UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, UnsupportedDestinationMemoErrorType };
|
|
56
|
+
export { DestinationAddressMatchesTokenAddressError, DestinationAddressMatchesTokenAddressErrorType, FeeExceedsAmountError, FeeExceedsAmountErrorType, MinWithdrawalAmountError, MinWithdrawalAmountErrorType, TrustlineNotFoundError, TrustlineNotFoundErrorType, UnsupportedAssetIdError, UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, UnsupportedDestinationMemoErrorType };
|
|
@@ -44,5 +44,13 @@ declare class UnsupportedAssetIdError extends BaseError {
|
|
|
44
44
|
assetId: string;
|
|
45
45
|
constructor(assetId: string, details: string);
|
|
46
46
|
}
|
|
47
|
+
type DestinationAddressMatchesTokenAddressErrorType = DestinationAddressMatchesTokenAddressError & {
|
|
48
|
+
name: "DestinationAddressMatchesTokenAddressError";
|
|
49
|
+
};
|
|
50
|
+
declare class DestinationAddressMatchesTokenAddressError extends BaseError {
|
|
51
|
+
tokenAddress: string;
|
|
52
|
+
assetId: string;
|
|
53
|
+
constructor(tokenAddress: string, assetId: string);
|
|
54
|
+
}
|
|
47
55
|
//#endregion
|
|
48
|
-
export { FeeExceedsAmountError, FeeExceedsAmountErrorType, MinWithdrawalAmountError, MinWithdrawalAmountErrorType, TrustlineNotFoundError, TrustlineNotFoundErrorType, UnsupportedAssetIdError, UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, UnsupportedDestinationMemoErrorType };
|
|
56
|
+
export { DestinationAddressMatchesTokenAddressError, DestinationAddressMatchesTokenAddressErrorType, FeeExceedsAmountError, FeeExceedsAmountErrorType, MinWithdrawalAmountError, MinWithdrawalAmountErrorType, TrustlineNotFoundError, TrustlineNotFoundErrorType, UnsupportedAssetIdError, UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, UnsupportedDestinationMemoErrorType };
|
|
@@ -65,6 +65,16 @@ var UnsupportedAssetIdError = class extends BaseError {
|
|
|
65
65
|
this.assetId = assetId;
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
|
+
var DestinationAddressMatchesTokenAddressError = class extends BaseError {
|
|
69
|
+
constructor(tokenAddress, assetId) {
|
|
70
|
+
super("Destination address must not be the token contract address.", {
|
|
71
|
+
metaMessages: [`Asset ID: ${assetId}`, `Token address: ${tokenAddress}`],
|
|
72
|
+
name: "DestinationAddressMatchesTokenAddressError"
|
|
73
|
+
});
|
|
74
|
+
this.tokenAddress = tokenAddress;
|
|
75
|
+
this.assetId = assetId;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
68
78
|
var InvalidDestinationAddressForWithdrawalError = class extends BaseError {
|
|
69
79
|
constructor(destinationAddress, destinationChain) {
|
|
70
80
|
super(`Invalid destination address.`, {
|
|
@@ -78,4 +88,4 @@ var InvalidDestinationAddressForWithdrawalError = class extends BaseError {
|
|
|
78
88
|
};
|
|
79
89
|
|
|
80
90
|
//#endregion
|
|
81
|
-
export { FeeExceedsAmountError, InvalidDestinationAddressForWithdrawalError, MinWithdrawalAmountError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError };
|
|
91
|
+
export { DestinationAddressMatchesTokenAddressError, FeeExceedsAmountError, InvalidDestinationAddressForWithdrawalError, MinWithdrawalAmountError, TrustlineNotFoundError, UnsupportedAssetIdError, UnsupportedDestinationMemoError };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_caip2 = require('./caip2.cjs');
|
|
3
|
+
const require_ton_address = require('./ton-address.cjs');
|
|
4
|
+
let viem = require("viem");
|
|
5
|
+
let _noble_hashes_sha2 = require("@noble/hashes/sha2");
|
|
6
|
+
let _scure_base = require("@scure/base");
|
|
7
|
+
|
|
8
|
+
//#region src/lib/compareAddresses.ts
|
|
9
|
+
/**
|
|
10
|
+
* Compares two addresses for equality using each chain's canonical form,
|
|
11
|
+
* e.g. to block transfers to the token's own address. Returns false (not
|
|
12
|
+
* throw) on malformed input.
|
|
13
|
+
*/
|
|
14
|
+
function compareAddresses(a, b, blockchain) {
|
|
15
|
+
try {
|
|
16
|
+
switch (blockchain) {
|
|
17
|
+
case require_caip2.Chains.Ethereum:
|
|
18
|
+
case require_caip2.Chains.Optimism:
|
|
19
|
+
case require_caip2.Chains.BNB:
|
|
20
|
+
case require_caip2.Chains.Gnosis:
|
|
21
|
+
case require_caip2.Chains.Polygon:
|
|
22
|
+
case require_caip2.Chains.Monad:
|
|
23
|
+
case require_caip2.Chains.LayerX:
|
|
24
|
+
case require_caip2.Chains.Adi:
|
|
25
|
+
case require_caip2.Chains.Base:
|
|
26
|
+
case require_caip2.Chains.Arbitrum:
|
|
27
|
+
case require_caip2.Chains.Avalanche:
|
|
28
|
+
case require_caip2.Chains.Berachain:
|
|
29
|
+
case require_caip2.Chains.Plasma:
|
|
30
|
+
case require_caip2.Chains.Scroll:
|
|
31
|
+
case require_caip2.Chains.Abstract:
|
|
32
|
+
case require_caip2.Chains.HyperCore:
|
|
33
|
+
case require_caip2.Chains.HyperEvm: return (0, viem.getAddress)(a) === (0, viem.getAddress)(b);
|
|
34
|
+
case require_caip2.Chains.Aptos:
|
|
35
|
+
case require_caip2.Chains.Movement:
|
|
36
|
+
case require_caip2.Chains.Sui:
|
|
37
|
+
case require_caip2.Chains.Starknet: return compareHexAddress(a, b);
|
|
38
|
+
case require_caip2.Chains.TON: return compareTonAddress(a, b);
|
|
39
|
+
case require_caip2.Chains.Tron: return compareTronAddress(a, b);
|
|
40
|
+
case require_caip2.Chains.Stellar: return a.toUpperCase() === b.toUpperCase();
|
|
41
|
+
case require_caip2.Chains.Near:
|
|
42
|
+
case require_caip2.Chains.Bitcoin:
|
|
43
|
+
case require_caip2.Chains.BitcoinCash:
|
|
44
|
+
case require_caip2.Chains.Zcash:
|
|
45
|
+
case require_caip2.Chains.Dogecoin:
|
|
46
|
+
case require_caip2.Chains.Litecoin:
|
|
47
|
+
case require_caip2.Chains.Solana:
|
|
48
|
+
case require_caip2.Chains.Fogo:
|
|
49
|
+
case require_caip2.Chains.XRPL:
|
|
50
|
+
case require_caip2.Chains.Cardano:
|
|
51
|
+
case require_caip2.Chains.Aleo:
|
|
52
|
+
case require_caip2.Chains.Dash: return a === b;
|
|
53
|
+
default: return false;
|
|
54
|
+
}
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function compareHexAddress(a, b) {
|
|
60
|
+
const normalizedA = normalizeHexAddress(a);
|
|
61
|
+
const normalizedB = normalizeHexAddress(b);
|
|
62
|
+
if (normalizedA === null || normalizedB === null) return false;
|
|
63
|
+
return normalizedA === normalizedB;
|
|
64
|
+
}
|
|
65
|
+
function normalizeHexAddress(address) {
|
|
66
|
+
const withoutPrefix = address.toLowerCase().startsWith("0x") ? address.slice(2) : address;
|
|
67
|
+
if (withoutPrefix.length === 0 || !/^[0-9a-fA-F]+$/.test(withoutPrefix)) return null;
|
|
68
|
+
return withoutPrefix.replace(/^0+/, "").toLowerCase() || "0";
|
|
69
|
+
}
|
|
70
|
+
function compareTonAddress(a, b) {
|
|
71
|
+
const parsedA = require_ton_address.tryParseTonAddress(a);
|
|
72
|
+
const parsedB = require_ton_address.tryParseTonAddress(b);
|
|
73
|
+
if (parsedA === null || parsedB === null) return false;
|
|
74
|
+
return parsedA.workchainId === parsedB.workchainId && bytesEqual(parsedA.address, parsedB.address);
|
|
75
|
+
}
|
|
76
|
+
function compareTronAddress(a, b) {
|
|
77
|
+
const payloadA = decodeTronAddress(a);
|
|
78
|
+
const payloadB = decodeTronAddress(b);
|
|
79
|
+
if (payloadA === null || payloadB === null) return false;
|
|
80
|
+
return bytesEqual(payloadA, payloadB);
|
|
81
|
+
}
|
|
82
|
+
function decodeTronAddress(address) {
|
|
83
|
+
const base58Payload = decodeTronBase58Address(address);
|
|
84
|
+
if (base58Payload !== null) return base58Payload;
|
|
85
|
+
return decodeTronHexAddress(address);
|
|
86
|
+
}
|
|
87
|
+
function decodeTronBase58Address(address) {
|
|
88
|
+
try {
|
|
89
|
+
const decoded = _scure_base.base58.decode(address);
|
|
90
|
+
if (decoded.length !== 25) return null;
|
|
91
|
+
const payload = decoded.subarray(0, 21);
|
|
92
|
+
const checksum = decoded.subarray(21, 25);
|
|
93
|
+
const expectedChecksum = (0, _noble_hashes_sha2.sha256)((0, _noble_hashes_sha2.sha256)(payload)).subarray(0, 4);
|
|
94
|
+
for (let i = 0; i < 4; i++) if (checksum[i] !== expectedChecksum[i]) return null;
|
|
95
|
+
return payload[0] === 65 ? payload : null;
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function decodeTronHexAddress(address) {
|
|
101
|
+
try {
|
|
102
|
+
const decoded = _scure_base.hex.decode(address);
|
|
103
|
+
if (decoded.length !== 21) return null;
|
|
104
|
+
return decoded[0] === 65 ? decoded : null;
|
|
105
|
+
} catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function bytesEqual(a, b) {
|
|
110
|
+
if (a.length !== b.length) return false;
|
|
111
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
exports.compareAddresses = compareAddresses;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Chains } from "./caip2.js";
|
|
2
|
+
import { tryParseTonAddress } from "./ton-address.js";
|
|
3
|
+
import { getAddress } from "viem";
|
|
4
|
+
import { sha256 } from "@noble/hashes/sha2";
|
|
5
|
+
import { base58, hex } from "@scure/base";
|
|
6
|
+
|
|
7
|
+
//#region src/lib/compareAddresses.ts
|
|
8
|
+
/**
|
|
9
|
+
* Compares two addresses for equality using each chain's canonical form,
|
|
10
|
+
* e.g. to block transfers to the token's own address. Returns false (not
|
|
11
|
+
* throw) on malformed input.
|
|
12
|
+
*/
|
|
13
|
+
function compareAddresses(a, b, blockchain) {
|
|
14
|
+
try {
|
|
15
|
+
switch (blockchain) {
|
|
16
|
+
case Chains.Ethereum:
|
|
17
|
+
case Chains.Optimism:
|
|
18
|
+
case Chains.BNB:
|
|
19
|
+
case Chains.Gnosis:
|
|
20
|
+
case Chains.Polygon:
|
|
21
|
+
case Chains.Monad:
|
|
22
|
+
case Chains.LayerX:
|
|
23
|
+
case Chains.Adi:
|
|
24
|
+
case Chains.Base:
|
|
25
|
+
case Chains.Arbitrum:
|
|
26
|
+
case Chains.Avalanche:
|
|
27
|
+
case Chains.Berachain:
|
|
28
|
+
case Chains.Plasma:
|
|
29
|
+
case Chains.Scroll:
|
|
30
|
+
case Chains.Abstract:
|
|
31
|
+
case Chains.HyperCore:
|
|
32
|
+
case Chains.HyperEvm: return getAddress(a) === getAddress(b);
|
|
33
|
+
case Chains.Aptos:
|
|
34
|
+
case Chains.Movement:
|
|
35
|
+
case Chains.Sui:
|
|
36
|
+
case Chains.Starknet: return compareHexAddress(a, b);
|
|
37
|
+
case Chains.TON: return compareTonAddress(a, b);
|
|
38
|
+
case Chains.Tron: return compareTronAddress(a, b);
|
|
39
|
+
case Chains.Stellar: return a.toUpperCase() === b.toUpperCase();
|
|
40
|
+
case Chains.Near:
|
|
41
|
+
case Chains.Bitcoin:
|
|
42
|
+
case Chains.BitcoinCash:
|
|
43
|
+
case Chains.Zcash:
|
|
44
|
+
case Chains.Dogecoin:
|
|
45
|
+
case Chains.Litecoin:
|
|
46
|
+
case Chains.Solana:
|
|
47
|
+
case Chains.Fogo:
|
|
48
|
+
case Chains.XRPL:
|
|
49
|
+
case Chains.Cardano:
|
|
50
|
+
case Chains.Aleo:
|
|
51
|
+
case Chains.Dash: return a === b;
|
|
52
|
+
default: return false;
|
|
53
|
+
}
|
|
54
|
+
} catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function compareHexAddress(a, b) {
|
|
59
|
+
const normalizedA = normalizeHexAddress(a);
|
|
60
|
+
const normalizedB = normalizeHexAddress(b);
|
|
61
|
+
if (normalizedA === null || normalizedB === null) return false;
|
|
62
|
+
return normalizedA === normalizedB;
|
|
63
|
+
}
|
|
64
|
+
function normalizeHexAddress(address) {
|
|
65
|
+
const withoutPrefix = address.toLowerCase().startsWith("0x") ? address.slice(2) : address;
|
|
66
|
+
if (withoutPrefix.length === 0 || !/^[0-9a-fA-F]+$/.test(withoutPrefix)) return null;
|
|
67
|
+
return withoutPrefix.replace(/^0+/, "").toLowerCase() || "0";
|
|
68
|
+
}
|
|
69
|
+
function compareTonAddress(a, b) {
|
|
70
|
+
const parsedA = tryParseTonAddress(a);
|
|
71
|
+
const parsedB = tryParseTonAddress(b);
|
|
72
|
+
if (parsedA === null || parsedB === null) return false;
|
|
73
|
+
return parsedA.workchainId === parsedB.workchainId && bytesEqual(parsedA.address, parsedB.address);
|
|
74
|
+
}
|
|
75
|
+
function compareTronAddress(a, b) {
|
|
76
|
+
const payloadA = decodeTronAddress(a);
|
|
77
|
+
const payloadB = decodeTronAddress(b);
|
|
78
|
+
if (payloadA === null || payloadB === null) return false;
|
|
79
|
+
return bytesEqual(payloadA, payloadB);
|
|
80
|
+
}
|
|
81
|
+
function decodeTronAddress(address) {
|
|
82
|
+
const base58Payload = decodeTronBase58Address(address);
|
|
83
|
+
if (base58Payload !== null) return base58Payload;
|
|
84
|
+
return decodeTronHexAddress(address);
|
|
85
|
+
}
|
|
86
|
+
function decodeTronBase58Address(address) {
|
|
87
|
+
try {
|
|
88
|
+
const decoded = base58.decode(address);
|
|
89
|
+
if (decoded.length !== 25) return null;
|
|
90
|
+
const payload = decoded.subarray(0, 21);
|
|
91
|
+
const checksum = decoded.subarray(21, 25);
|
|
92
|
+
const expectedChecksum = sha256(sha256(payload)).subarray(0, 4);
|
|
93
|
+
for (let i = 0; i < 4; i++) if (checksum[i] !== expectedChecksum[i]) return null;
|
|
94
|
+
return payload[0] === 65 ? payload : null;
|
|
95
|
+
} catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function decodeTronHexAddress(address) {
|
|
100
|
+
try {
|
|
101
|
+
const decoded = hex.decode(address);
|
|
102
|
+
if (decoded.length !== 21) return null;
|
|
103
|
+
return decoded[0] === 65 ? decoded : null;
|
|
104
|
+
} catch {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function bytesEqual(a, b) {
|
|
109
|
+
if (a.length !== b.length) return false;
|
|
110
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
export { compareAddresses };
|
|
@@ -57,6 +57,7 @@ function validateAddress(address, blockchain) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
function validateEthAddress(address) {
|
|
60
|
+
if (address === "0x0000000000000000000000000000000000000000" || address.toLowerCase() === "0x000000000000000000000000000000000000dead") return false;
|
|
60
61
|
return (0, viem.isAddress)(address, { strict: true });
|
|
61
62
|
}
|
|
62
63
|
/**
|
|
@@ -180,6 +181,7 @@ function verifyBchChecksum(address) {
|
|
|
180
181
|
}
|
|
181
182
|
function validateSolAddress(address) {
|
|
182
183
|
try {
|
|
184
|
+
if (address === "11111111111111111111111111111111") return false;
|
|
183
185
|
if (_scure_base.base58.decode(address).length !== 32) return false;
|
|
184
186
|
return true;
|
|
185
187
|
} catch {
|
|
@@ -56,6 +56,7 @@ function validateAddress(address, blockchain) {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
function validateEthAddress(address) {
|
|
59
|
+
if (address === "0x0000000000000000000000000000000000000000" || address.toLowerCase() === "0x000000000000000000000000000000000000dead") return false;
|
|
59
60
|
return isAddress(address, { strict: true });
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
@@ -179,6 +180,7 @@ function verifyBchChecksum(address) {
|
|
|
179
180
|
}
|
|
180
181
|
function validateSolAddress(address) {
|
|
181
182
|
try {
|
|
183
|
+
if (address === "11111111111111111111111111111111") return false;
|
|
182
184
|
if (base58.decode(address).length !== 32) return false;
|
|
183
185
|
return true;
|
|
184
186
|
} catch {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defuse-protocol/intents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.79.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"valibot": "^1.0.0",
|
|
50
50
|
"viem": "^2.0.0",
|
|
51
51
|
"@defuse-protocol/contract-types": "0.6.4",
|
|
52
|
-
"@defuse-protocol/internal-utils": "0.
|
|
52
|
+
"@defuse-protocol/internal-utils": "0.36.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@ton/core": "^0.60.0",
|