@shogun-sdk/intents-sdk 1.0.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 +124 -0
- package/dist/_esm/chains.js +46 -0
- package/dist/_esm/chains.js.map +1 -0
- package/dist/_esm/config.js +2 -0
- package/dist/_esm/config.js.map +1 -0
- package/dist/_esm/constants.js +46 -0
- package/dist/_esm/constants.js.map +1 -0
- package/dist/_esm/core/evm/abi/erc20.js +313 -0
- package/dist/_esm/core/evm/abi/erc20.js.map +1 -0
- package/dist/_esm/core/evm/abi/source-chain-guard.js +1716 -0
- package/dist/_esm/core/evm/abi/source-chain-guard.js.map +1 -0
- package/dist/_esm/core/evm/intent-provider.js +59 -0
- package/dist/_esm/core/evm/intent-provider.js.map +1 -0
- package/dist/_esm/core/evm/order-signature.js +19 -0
- package/dist/_esm/core/evm/order-signature.js.map +1 -0
- package/dist/_esm/core/evm/permit2.js +31 -0
- package/dist/_esm/core/evm/permit2.js.map +1 -0
- package/dist/_esm/core/evm/sdk.js +79 -0
- package/dist/_esm/core/evm/sdk.js.map +1 -0
- package/dist/_esm/core/evm/validator.js +46 -0
- package/dist/_esm/core/evm/validator.js.map +1 -0
- package/dist/_esm/core/evm/viem-provider.js +76 -0
- package/dist/_esm/core/evm/viem-provider.js.map +1 -0
- package/dist/_esm/core/order.js +190 -0
- package/dist/_esm/core/order.js.map +1 -0
- package/dist/_esm/core/sdk.js +120 -0
- package/dist/_esm/core/sdk.js.map +1 -0
- package/dist/_esm/core/solana/client.js +19 -0
- package/dist/_esm/core/solana/client.js.map +1 -0
- package/dist/_esm/core/solana/generated/accounts/adminSingleton.js +56 -0
- package/dist/_esm/core/solana/generated/accounts/adminSingleton.js.map +1 -0
- package/dist/_esm/core/solana/generated/accounts/guard.js +62 -0
- package/dist/_esm/core/solana/generated/accounts/guard.js.map +1 -0
- package/dist/_esm/core/solana/generated/accounts/index.js +11 -0
- package/dist/_esm/core/solana/generated/accounts/index.js.map +1 -0
- package/dist/_esm/core/solana/generated/accounts/order.js +78 -0
- package/dist/_esm/core/solana/generated/accounts/order.js.map +1 -0
- package/dist/_esm/core/solana/generated/errors/index.js +9 -0
- package/dist/_esm/core/solana/generated/errors/index.js.map +1 -0
- package/dist/_esm/core/solana/generated/errors/sourceChainGuard.js +35 -0
- package/dist/_esm/core/solana/generated/errors/sourceChainGuard.js.map +1 -0
- package/dist/_esm/core/solana/generated/index.js +13 -0
- package/dist/_esm/core/solana/generated/index.js.map +1 -0
- package/dist/_esm/core/solana/generated/instructions/cancelOrder.js +125 -0
- package/dist/_esm/core/solana/generated/instructions/cancelOrder.js.map +1 -0
- package/dist/_esm/core/solana/generated/instructions/claimTokens.js +142 -0
- package/dist/_esm/core/solana/generated/instructions/claimTokens.js.map +1 -0
- package/dist/_esm/core/solana/generated/instructions/collectProtocolFees.js +146 -0
- package/dist/_esm/core/solana/generated/instructions/collectProtocolFees.js.map +1 -0
- package/dist/_esm/core/solana/generated/instructions/createGuard.js +236 -0
- package/dist/_esm/core/solana/generated/instructions/createGuard.js.map +1 -0
- package/dist/_esm/core/solana/generated/instructions/createOrder.js +182 -0
- package/dist/_esm/core/solana/generated/instructions/createOrder.js.map +1 -0
- package/dist/_esm/core/solana/generated/instructions/index.js +19 -0
- package/dist/_esm/core/solana/generated/instructions/index.js.map +1 -0
- package/dist/_esm/core/solana/generated/instructions/initialize.js +109 -0
- package/dist/_esm/core/solana/generated/instructions/initialize.js.map +1 -0
- package/dist/_esm/core/solana/generated/instructions/preStartOrderExecution.js +123 -0
- package/dist/_esm/core/solana/generated/instructions/preStartOrderExecution.js.map +1 -0
- package/dist/_esm/core/solana/generated/instructions/setAdmin.js +98 -0
- package/dist/_esm/core/solana/generated/instructions/setAdmin.js.map +1 -0
- package/dist/_esm/core/solana/generated/instructions/setAuctioneerPubKey.js +104 -0
- package/dist/_esm/core/solana/generated/instructions/setAuctioneerPubKey.js.map +1 -0
- package/dist/_esm/core/solana/generated/instructions/startOrderExecution.js +105 -0
- package/dist/_esm/core/solana/generated/instructions/startOrderExecution.js.map +1 -0
- package/dist/_esm/core/solana/generated/instructions/startOrderExecutionAfterSwap.js +113 -0
- package/dist/_esm/core/solana/generated/instructions/startOrderExecutionAfterSwap.js.map +1 -0
- package/dist/_esm/core/solana/generated/programs/index.js +9 -0
- package/dist/_esm/core/solana/generated/programs/index.js.map +1 -0
- package/dist/_esm/core/solana/generated/programs/sourceChainGuard.js +82 -0
- package/dist/_esm/core/solana/generated/programs/sourceChainGuard.js.map +1 -0
- package/dist/_esm/core/solana/generated/shared/index.js +82 -0
- package/dist/_esm/core/solana/generated/shared/index.js.map +1 -0
- package/dist/_esm/core/solana/generated/types/adminUpdated.js +18 -0
- package/dist/_esm/core/solana/generated/types/adminUpdated.js.map +1 -0
- package/dist/_esm/core/solana/generated/types/auctioneerPubkeyUpdated.js +24 -0
- package/dist/_esm/core/solana/generated/types/auctioneerPubkeyUpdated.js.map +1 -0
- package/dist/_esm/core/solana/generated/types/executionStarted.js +30 -0
- package/dist/_esm/core/solana/generated/types/executionStarted.js.map +1 -0
- package/dist/_esm/core/solana/generated/types/guardCreated.js +28 -0
- package/dist/_esm/core/solana/generated/types/guardCreated.js.map +1 -0
- package/dist/_esm/core/solana/generated/types/index.js +16 -0
- package/dist/_esm/core/solana/generated/types/index.js.map +1 -0
- package/dist/_esm/core/solana/generated/types/orderCancelled.js +18 -0
- package/dist/_esm/core/solana/generated/types/orderCancelled.js.map +1 -0
- package/dist/_esm/core/solana/generated/types/orderCreated.js +36 -0
- package/dist/_esm/core/solana/generated/types/orderCreated.js.map +1 -0
- package/dist/_esm/core/solana/generated/types/orderFulfilled.js +18 -0
- package/dist/_esm/core/solana/generated/types/orderFulfilled.js.map +1 -0
- package/dist/_esm/core/solana/generated/types/tokenInSwapped.js +26 -0
- package/dist/_esm/core/solana/generated/types/tokenInSwapped.js.map +1 -0
- package/dist/_esm/core/solana/order-instructions.js +92 -0
- package/dist/_esm/core/solana/order-instructions.js.map +1 -0
- package/dist/_esm/core/solana/sdk.js +111 -0
- package/dist/_esm/core/solana/sdk.js.map +1 -0
- package/dist/_esm/core/solana/validator.js +22 -0
- package/dist/_esm/core/solana/validator.js.map +1 -0
- package/dist/_esm/core/sui/client.js +3 -0
- package/dist/_esm/core/sui/client.js.map +1 -0
- package/dist/_esm/core/sui/order-transaction.js +56 -0
- package/dist/_esm/core/sui/order-transaction.js.map +1 -0
- package/dist/_esm/core/sui/sdk.js +94 -0
- package/dist/_esm/core/sui/sdk.js.map +1 -0
- package/dist/_esm/core/sui/validator.js +25 -0
- package/dist/_esm/core/sui/validator.js.map +1 -0
- package/dist/_esm/errors/index.js +94 -0
- package/dist/_esm/errors/index.js.map +1 -0
- package/dist/_esm/index.js +7 -0
- package/dist/_esm/index.js.map +1 -0
- package/dist/_esm/package.json +1 -0
- package/dist/_esm/types/intent.js +2 -0
- package/dist/_esm/types/intent.js.map +1 -0
- package/dist/_esm/utils/base-validator.js +51 -0
- package/dist/_esm/utils/base-validator.js.map +1 -0
- package/dist/_esm/utils/logger.js +109 -0
- package/dist/_esm/utils/logger.js.map +1 -0
- package/dist/_esm/utils/order-validator.js +75 -0
- package/dist/_esm/utils/order-validator.js.map +1 -0
- package/dist/_esm/utils/parsers.js +10 -0
- package/dist/_esm/utils/parsers.js.map +1 -0
- package/dist/_esm/utils/type-utils.js +2 -0
- package/dist/_esm/utils/type-utils.js.map +1 -0
- package/dist/_types/chains.d.ts +69 -0
- package/dist/_types/chains.d.ts.map +1 -0
- package/dist/_types/config.d.ts +21 -0
- package/dist/_types/config.d.ts.map +1 -0
- package/dist/_types/constants.d.ts +18 -0
- package/dist/_types/constants.d.ts.map +1 -0
- package/dist/_types/core/evm/abi/erc20.d.ts +240 -0
- package/dist/_types/core/evm/abi/erc20.d.ts.map +1 -0
- package/dist/_types/core/evm/abi/source-chain-guard.d.ts +1343 -0
- package/dist/_types/core/evm/abi/source-chain-guard.d.ts.map +1 -0
- package/dist/_types/core/evm/intent-provider.d.ts +12 -0
- package/dist/_types/core/evm/intent-provider.d.ts.map +1 -0
- package/dist/_types/core/evm/order-signature.d.ts +19 -0
- package/dist/_types/core/evm/order-signature.d.ts.map +1 -0
- package/dist/_types/core/evm/permit2.d.ts +75 -0
- package/dist/_types/core/evm/permit2.d.ts.map +1 -0
- package/dist/_types/core/evm/sdk.d.ts +50 -0
- package/dist/_types/core/evm/sdk.d.ts.map +1 -0
- package/dist/_types/core/evm/validator.d.ts +13 -0
- package/dist/_types/core/evm/validator.d.ts.map +1 -0
- package/dist/_types/core/evm/viem-provider.d.ts +9657 -0
- package/dist/_types/core/evm/viem-provider.d.ts.map +1 -0
- package/dist/_types/core/order.d.ts +122 -0
- package/dist/_types/core/order.d.ts.map +1 -0
- package/dist/_types/core/sdk.d.ts +86 -0
- package/dist/_types/core/sdk.d.ts.map +1 -0
- package/dist/_types/core/solana/client.d.ts +11 -0
- package/dist/_types/core/solana/client.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/accounts/adminSingleton.d.ts +36 -0
- package/dist/_types/core/solana/generated/accounts/adminSingleton.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/accounts/guard.d.ts +48 -0
- package/dist/_types/core/solana/generated/accounts/guard.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/accounts/index.d.ts +11 -0
- package/dist/_types/core/solana/generated/accounts/index.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/accounts/order.d.ts +92 -0
- package/dist/_types/core/solana/generated/accounts/order.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/errors/index.d.ts +9 -0
- package/dist/_types/core/solana/generated/errors/index.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/errors/sourceChainGuard.d.ts +27 -0
- package/dist/_types/core/solana/generated/errors/sourceChainGuard.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/index.d.ts +13 -0
- package/dist/_types/core/solana/generated/index.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/instructions/cancelOrder.d.ts +108 -0
- package/dist/_types/core/solana/generated/instructions/cancelOrder.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/instructions/claimTokens.d.ts +131 -0
- package/dist/_types/core/solana/generated/instructions/claimTokens.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/instructions/collectProtocolFees.d.ts +91 -0
- package/dist/_types/core/solana/generated/instructions/collectProtocolFees.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/instructions/createGuard.d.ts +133 -0
- package/dist/_types/core/solana/generated/instructions/createGuard.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/instructions/createOrder.d.ts +122 -0
- package/dist/_types/core/solana/generated/instructions/createOrder.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/instructions/index.d.ts +19 -0
- package/dist/_types/core/solana/generated/instructions/index.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/instructions/initialize.d.ts +63 -0
- package/dist/_types/core/solana/generated/instructions/initialize.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/instructions/preStartOrderExecution.d.ts +105 -0
- package/dist/_types/core/solana/generated/instructions/preStartOrderExecution.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/instructions/setAdmin.d.ts +61 -0
- package/dist/_types/core/solana/generated/instructions/setAdmin.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/instructions/setAuctioneerPubKey.d.ts +68 -0
- package/dist/_types/core/solana/generated/instructions/setAuctioneerPubKey.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/instructions/startOrderExecution.d.ts +85 -0
- package/dist/_types/core/solana/generated/instructions/startOrderExecution.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/instructions/startOrderExecutionAfterSwap.d.ts +95 -0
- package/dist/_types/core/solana/generated/instructions/startOrderExecutionAfterSwap.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/programs/index.d.ts +9 -0
- package/dist/_types/core/solana/generated/programs/index.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/programs/sourceChainGuard.d.ts +59 -0
- package/dist/_types/core/solana/generated/programs/sourceChainGuard.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/shared/index.d.ts +52 -0
- package/dist/_types/core/solana/generated/shared/index.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/types/adminUpdated.d.ts +16 -0
- package/dist/_types/core/solana/generated/types/adminUpdated.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/types/auctioneerPubkeyUpdated.d.ts +17 -0
- package/dist/_types/core/solana/generated/types/auctioneerPubkeyUpdated.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/types/executionStarted.d.ts +26 -0
- package/dist/_types/core/solana/generated/types/executionStarted.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/types/guardCreated.d.ts +19 -0
- package/dist/_types/core/solana/generated/types/guardCreated.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/types/index.d.ts +16 -0
- package/dist/_types/core/solana/generated/types/index.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/types/orderCancelled.d.ts +16 -0
- package/dist/_types/core/solana/generated/types/orderCancelled.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/types/orderCreated.d.ts +32 -0
- package/dist/_types/core/solana/generated/types/orderCreated.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/types/orderFulfilled.d.ts +16 -0
- package/dist/_types/core/solana/generated/types/orderFulfilled.d.ts.map +1 -0
- package/dist/_types/core/solana/generated/types/tokenInSwapped.d.ts +22 -0
- package/dist/_types/core/solana/generated/types/tokenInSwapped.d.ts.map +1 -0
- package/dist/_types/core/solana/order-instructions.d.ts +12 -0
- package/dist/_types/core/solana/order-instructions.d.ts.map +1 -0
- package/dist/_types/core/solana/sdk.d.ts +65 -0
- package/dist/_types/core/solana/sdk.d.ts.map +1 -0
- package/dist/_types/core/solana/validator.d.ts +9 -0
- package/dist/_types/core/solana/validator.d.ts.map +1 -0
- package/dist/_types/core/sui/client.d.ts +3 -0
- package/dist/_types/core/sui/client.d.ts.map +1 -0
- package/dist/_types/core/sui/order-transaction.d.ts +9 -0
- package/dist/_types/core/sui/order-transaction.d.ts.map +1 -0
- package/dist/_types/core/sui/sdk.d.ts +55 -0
- package/dist/_types/core/sui/sdk.d.ts.map +1 -0
- package/dist/_types/core/sui/validator.d.ts +9 -0
- package/dist/_types/core/sui/validator.d.ts.map +1 -0
- package/dist/_types/errors/index.d.ts +32 -0
- package/dist/_types/errors/index.d.ts.map +1 -0
- package/dist/_types/index.d.ts +10 -0
- package/dist/_types/index.d.ts.map +1 -0
- package/dist/_types/types/intent.d.ts +129 -0
- package/dist/_types/types/intent.d.ts.map +1 -0
- package/dist/_types/utils/base-validator.d.ts +28 -0
- package/dist/_types/utils/base-validator.d.ts.map +1 -0
- package/dist/_types/utils/logger.d.ts +35 -0
- package/dist/_types/utils/logger.d.ts.map +1 -0
- package/dist/_types/utils/order-validator.d.ts +40 -0
- package/dist/_types/utils/order-validator.d.ts.map +1 -0
- package/dist/_types/utils/parsers.d.ts +4 -0
- package/dist/_types/utils/parsers.d.ts.map +1 -0
- package/dist/_types/utils/type-utils.d.ts +2 -0
- package/dist/_types/utils/type-utils.d.ts.map +1 -0
- package/package.json +62 -0
- package/src/chains.ts +77 -0
- package/src/config.ts +24 -0
- package/src/constants.ts +61 -0
- package/src/core/evm/abi/erc20.ts +312 -0
- package/src/core/evm/abi/source-chain-guard.ts +1715 -0
- package/src/core/evm/intent-provider.ts +63 -0
- package/src/core/evm/order-signature.ts +33 -0
- package/src/core/evm/permit2.ts +60 -0
- package/src/core/evm/sdk.ts +74 -0
- package/src/core/evm/validator.ts +60 -0
- package/src/core/evm/viem-provider.ts +79 -0
- package/src/core/order.ts +186 -0
- package/src/core/sdk.ts +154 -0
- package/src/core/solana/client.ts +37 -0
- package/src/core/solana/generated/accounts/adminSingleton.ts +136 -0
- package/src/core/solana/generated/accounts/guard.ts +156 -0
- package/src/core/solana/generated/accounts/index.ts +11 -0
- package/src/core/solana/generated/accounts/order.ts +218 -0
- package/src/core/solana/generated/errors/index.ts +9 -0
- package/src/core/solana/generated/errors/sourceChainGuard.ts +52 -0
- package/src/core/solana/generated/index.ts +13 -0
- package/src/core/solana/generated/instructions/cancelOrder.ts +357 -0
- package/src/core/solana/generated/instructions/claimTokens.ts +419 -0
- package/src/core/solana/generated/instructions/collectProtocolFees.ts +383 -0
- package/src/core/solana/generated/instructions/createGuard.ts +569 -0
- package/src/core/solana/generated/instructions/createOrder.ts +480 -0
- package/src/core/solana/generated/instructions/index.ts +19 -0
- package/src/core/solana/generated/instructions/initialize.ts +231 -0
- package/src/core/solana/generated/instructions/preStartOrderExecution.ts +362 -0
- package/src/core/solana/generated/instructions/setAdmin.ts +211 -0
- package/src/core/solana/generated/instructions/setAuctioneerPubKey.ts +241 -0
- package/src/core/solana/generated/instructions/startOrderExecution.ts +293 -0
- package/src/core/solana/generated/instructions/startOrderExecutionAfterSwap.ts +323 -0
- package/src/core/solana/generated/programs/index.ts +9 -0
- package/src/core/solana/generated/programs/sourceChainGuard.ts +223 -0
- package/src/core/solana/generated/shared/index.ts +124 -0
- package/src/core/solana/generated/types/adminUpdated.ts +35 -0
- package/src/core/solana/generated/types/auctioneerPubkeyUpdated.ts +44 -0
- package/src/core/solana/generated/types/executionStarted.ts +63 -0
- package/src/core/solana/generated/types/guardCreated.ts +50 -0
- package/src/core/solana/generated/types/index.ts +16 -0
- package/src/core/solana/generated/types/orderCancelled.ts +35 -0
- package/src/core/solana/generated/types/orderCreated.ts +80 -0
- package/src/core/solana/generated/types/orderFulfilled.ts +35 -0
- package/src/core/solana/generated/types/tokenInSwapped.ts +53 -0
- package/src/core/solana/order-instructions.ts +131 -0
- package/src/core/solana/sdk.ts +135 -0
- package/src/core/solana/validator.ts +26 -0
- package/src/core/sui/client.ts +3 -0
- package/src/core/sui/order-transaction.ts +78 -0
- package/src/core/sui/sdk.ts +95 -0
- package/src/core/sui/validator.ts +32 -0
- package/src/errors/index.ts +106 -0
- package/src/index.ts +10 -0
- package/src/types/intent.ts +143 -0
- package/src/utils/base-validator.ts +64 -0
- package/src/utils/logger.ts +128 -0
- package/src/utils/order-validator.ts +103 -0
- package/src/utils/parsers.ts +8 -0
- package/src/utils/type-utils.ts +1 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type Address } from 'viem';
|
|
2
|
+
import { type SupportedEvmChain } from '../../chains.js';
|
|
3
|
+
import type { EVMConfig } from '../../config.js';
|
|
4
|
+
import { SRC_CHAIN_GUARD } from '../../constants.js';
|
|
5
|
+
import type { PreparedOrder } from '../../types/intent.js';
|
|
6
|
+
import type { Order } from '../order.js';
|
|
7
|
+
import { getEvmOrderTypedData } from './order-signature.js';
|
|
8
|
+
import { type PermitTransferFrom } from './permit2.js';
|
|
9
|
+
import { ChainProvider } from './viem-provider.js';
|
|
10
|
+
|
|
11
|
+
export class EVMIntentProvider {
|
|
12
|
+
private provider: ChainProvider;
|
|
13
|
+
|
|
14
|
+
constructor(config: EVMConfig) {
|
|
15
|
+
this.provider = new ChainProvider(config);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async prepare(order: Order): Promise<PreparedOrder> {
|
|
19
|
+
const { orderTypedData: dataToSign, nonce } = await getEvmOrderTypedData(order);
|
|
20
|
+
|
|
21
|
+
const signature = await this.provider.walletClient.signTypedData({
|
|
22
|
+
message: dataToSign.message,
|
|
23
|
+
primaryType: dataToSign.primaryType,
|
|
24
|
+
types: dataToSign.types,
|
|
25
|
+
domain: dataToSign.domain,
|
|
26
|
+
account: this.provider.getAccount(),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
order,
|
|
31
|
+
preparedData: {
|
|
32
|
+
nonce: nonce.toString(),
|
|
33
|
+
signature: signature.slice(2),
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static getPermissionMessage(order: Order, nonce: bigint): PermitTransferFrom {
|
|
39
|
+
return {
|
|
40
|
+
permitted: {
|
|
41
|
+
token: order.sourceTokenAddress as Address,
|
|
42
|
+
amount: order.sourceTokenAmount,
|
|
43
|
+
},
|
|
44
|
+
spender: SRC_CHAIN_GUARD[order.sourceChainId as SupportedEvmChain] as Address,
|
|
45
|
+
nonce,
|
|
46
|
+
deadline: BigInt(order.deadline),
|
|
47
|
+
witness: {
|
|
48
|
+
user: order.user as Address,
|
|
49
|
+
tokenIn: order.sourceTokenAddress as Address,
|
|
50
|
+
srcChainId: order.sourceChainId,
|
|
51
|
+
deadline: order.deadline,
|
|
52
|
+
amountIn: order.sourceTokenAmount,
|
|
53
|
+
minStablecoinsAmount: order.minStablecoinAmount,
|
|
54
|
+
nonce,
|
|
55
|
+
executionDetailsHash: order.getExecutionDetailsHash(),
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static getRandomNonce(): bigint {
|
|
61
|
+
return BigInt(Math.floor(Math.random() * 1000000000000));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { TypedDataDomain } from 'viem';
|
|
2
|
+
import type { SupportedEvmChain } from '../../chains.js';
|
|
3
|
+
import type { Order } from '../order.js';
|
|
4
|
+
import { EVMIntentProvider } from './intent-provider.js';
|
|
5
|
+
import { PERMIT2_DOMAIN, PERMIT2_TYPES, type PermitTransferFrom } from './permit2.js';
|
|
6
|
+
|
|
7
|
+
export type EvmOrderTypedData = {
|
|
8
|
+
domain: TypedDataDomain;
|
|
9
|
+
types: typeof PERMIT2_TYPES;
|
|
10
|
+
primaryType: 'PermitWitnessTransferFrom';
|
|
11
|
+
message: PermitTransferFrom;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Generates typed data for EVM order signatures
|
|
16
|
+
* @param order The order to generate typed data for
|
|
17
|
+
* @returns Object containing the typed data and nonce
|
|
18
|
+
*/
|
|
19
|
+
export async function getEvmOrderTypedData(
|
|
20
|
+
order: Order,
|
|
21
|
+
): Promise<{ orderTypedData: EvmOrderTypedData; nonce: bigint }> {
|
|
22
|
+
const randomNonce = EVMIntentProvider.getRandomNonce();
|
|
23
|
+
const permissionMessage = EVMIntentProvider.getPermissionMessage(order, randomNonce);
|
|
24
|
+
|
|
25
|
+
const orderTypedData = {
|
|
26
|
+
domain: PERMIT2_DOMAIN(order.sourceChainId as SupportedEvmChain),
|
|
27
|
+
types: PERMIT2_TYPES,
|
|
28
|
+
primaryType: 'PermitWitnessTransferFrom',
|
|
29
|
+
message: permissionMessage,
|
|
30
|
+
} as EvmOrderTypedData;
|
|
31
|
+
|
|
32
|
+
return { orderTypedData, nonce: randomNonce };
|
|
33
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Address, Hex, TypedDataDomain } from 'viem';
|
|
2
|
+
import type { SupportedEvmChain } from '../../chains.js';
|
|
3
|
+
import { PERMIT2_ADDRESS } from '../../constants.js';
|
|
4
|
+
|
|
5
|
+
export type TokenPermissions = {
|
|
6
|
+
token: Address;
|
|
7
|
+
amount: bigint;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type OrderInfo = {
|
|
11
|
+
user: Address;
|
|
12
|
+
tokenIn: Address;
|
|
13
|
+
srcChainId: number;
|
|
14
|
+
deadline: number;
|
|
15
|
+
amountIn: bigint;
|
|
16
|
+
minStablecoinsAmount: bigint;
|
|
17
|
+
executionDetailsHash: Hex;
|
|
18
|
+
nonce: bigint;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type PermitTransferFrom = {
|
|
22
|
+
permitted: TokenPermissions;
|
|
23
|
+
spender: Address;
|
|
24
|
+
nonce: bigint;
|
|
25
|
+
deadline: bigint;
|
|
26
|
+
witness: OrderInfo;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const TOKEN_PERMISSIONS = [
|
|
30
|
+
{ name: 'token', type: 'address' },
|
|
31
|
+
{ name: 'amount', type: 'uint256' },
|
|
32
|
+
] as const;
|
|
33
|
+
|
|
34
|
+
export const PERMIT2_TYPES = {
|
|
35
|
+
TokenPermissions: TOKEN_PERMISSIONS,
|
|
36
|
+
OrderInfo: [
|
|
37
|
+
{ name: 'user', type: 'address' },
|
|
38
|
+
{ name: 'tokenIn', type: 'address' },
|
|
39
|
+
{ name: 'srcChainId', type: 'uint32' },
|
|
40
|
+
{ name: 'deadline', type: 'uint32' },
|
|
41
|
+
{ name: 'amountIn', type: 'uint128' },
|
|
42
|
+
{ name: 'minStablecoinsAmount', type: 'uint128' },
|
|
43
|
+
{ name: 'executionDetailsHash', type: 'bytes32' },
|
|
44
|
+
{ name: 'nonce', type: 'uint256' },
|
|
45
|
+
],
|
|
46
|
+
PermitWitnessTransferFrom: [
|
|
47
|
+
{ name: 'permitted', type: 'TokenPermissions' },
|
|
48
|
+
{ name: 'spender', type: 'address' },
|
|
49
|
+
{ name: 'nonce', type: 'uint256' },
|
|
50
|
+
{ name: 'deadline', type: 'uint256' },
|
|
51
|
+
{ name: 'witness', type: 'OrderInfo' },
|
|
52
|
+
],
|
|
53
|
+
} as const;
|
|
54
|
+
|
|
55
|
+
export const PERMIT2_DOMAIN = (chainId: SupportedEvmChain) =>
|
|
56
|
+
({
|
|
57
|
+
name: 'Permit2',
|
|
58
|
+
chainId,
|
|
59
|
+
verifyingContract: PERMIT2_ADDRESS[chainId],
|
|
60
|
+
}) as TypedDataDomain;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/core/evm/sdk.ts
|
|
2
|
+
|
|
3
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
4
|
+
import type { EVMConfig } from '../../config.js';
|
|
5
|
+
import { EVMError, OrderCreationError } from '../../errors/index.js';
|
|
6
|
+
import type { PreparedOrder } from '../../types/intent.js';
|
|
7
|
+
import type { Order } from '../order.js';
|
|
8
|
+
import { BaseSDK } from '../sdk.js';
|
|
9
|
+
import { EVMIntentProvider } from './intent-provider.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* EVM-specific SDK implementation
|
|
13
|
+
*
|
|
14
|
+
* Handles EVM-specific aspects of cross-chain swaps for Ethereum-compatible chains:
|
|
15
|
+
* - Arbitrum
|
|
16
|
+
* - Optimism
|
|
17
|
+
* - Base
|
|
18
|
+
*
|
|
19
|
+
* Uses viem for blockchain interactions and EIP-712 signatures for order authorization.
|
|
20
|
+
*/
|
|
21
|
+
export class EVMSDK extends BaseSDK {
|
|
22
|
+
/** Configuration for EVM chain connections and authentication */
|
|
23
|
+
private readonly config: EVMConfig;
|
|
24
|
+
/** Provider for EVM-specific order preparation and submission */
|
|
25
|
+
private readonly evmIntentProvider: EVMIntentProvider;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new instance of the EVM SDK
|
|
29
|
+
*
|
|
30
|
+
* @param config EVM configuration including chainId, privateKey, and optional RPC URL
|
|
31
|
+
*/
|
|
32
|
+
constructor(config: EVMConfig) {
|
|
33
|
+
super();
|
|
34
|
+
this.config = config;
|
|
35
|
+
this.evmIntentProvider = new EVMIntentProvider(config);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Gets the user's Ethereum address derived from their private key
|
|
40
|
+
*
|
|
41
|
+
* Uses viem's privateKeyToAccount function to derive the address securely
|
|
42
|
+
*
|
|
43
|
+
* @returns Promise resolving to the user's Ethereum address as a 0x-prefixed string
|
|
44
|
+
* @throws {EVMError} If address derivation fails
|
|
45
|
+
*/
|
|
46
|
+
public async getUserAddress(): Promise<string> {
|
|
47
|
+
try {
|
|
48
|
+
return privateKeyToAccount(this.config.privateKey).address;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
throw new EVMError('Failed to get user address', error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Prepares an EVM order for submission
|
|
56
|
+
*
|
|
57
|
+
* This method:
|
|
58
|
+
* 1. Validates token balances and allowances
|
|
59
|
+
* 2. Creates and signs the EIP-712 typed data for Permit2
|
|
60
|
+
* 3. Prepares the order for submission to the auctioneer
|
|
61
|
+
*
|
|
62
|
+
* @param order The validated order to prepare
|
|
63
|
+
* @returns Promise resolving to a prepared order with EVM-specific signature data
|
|
64
|
+
* @throws {OrderCreationError} If order preparation fails
|
|
65
|
+
* @protected
|
|
66
|
+
*/
|
|
67
|
+
protected prepareOrder(order: Order): Promise<PreparedOrder> {
|
|
68
|
+
try {
|
|
69
|
+
return this.evmIntentProvider.prepare(order);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
throw new OrderCreationError('Failed to prepare EVM order', error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type Address, getContract, isAddress as isEvmAddress } from 'viem';
|
|
2
|
+
import type { SupportedEvmChain } from '../../chains.js';
|
|
3
|
+
import { MAX_UINT_128, PERMIT2_ADDRESS } from '../../constants.js';
|
|
4
|
+
import { InsufficientAllowanceError, InsufficientBalanceError } from '../../errors/index.js';
|
|
5
|
+
import { BaseValidator } from '../../utils/base-validator.js';
|
|
6
|
+
import type { OrderInput } from '../order.js';
|
|
7
|
+
import { ERC20ABI } from './abi/erc20.js';
|
|
8
|
+
import { ChainProvider } from './viem-provider.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Chain-specific validator implementations
|
|
12
|
+
*/
|
|
13
|
+
export class EvmValidator extends BaseValidator {
|
|
14
|
+
isValidAddress(address: string): boolean {
|
|
15
|
+
return isEvmAddress(address);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
isValidTokenAddress(tokenAddress: string): boolean {
|
|
19
|
+
return isEvmAddress(tokenAddress);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
isValidAmount(amount: bigint): boolean {
|
|
23
|
+
return amount > 0n && amount < MAX_UINT_128;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
protected getChainName(): string {
|
|
27
|
+
return 'EVM';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public async chainSpecificValidation(order: OrderInput): Promise<void> {
|
|
31
|
+
const chain = order.sourceChainId as SupportedEvmChain;
|
|
32
|
+
const client = ChainProvider.getClient(chain);
|
|
33
|
+
const user = order.user as Address;
|
|
34
|
+
|
|
35
|
+
const ERC20Contract = getContract({
|
|
36
|
+
address: order.sourceTokenAddress as Address,
|
|
37
|
+
abi: ERC20ABI,
|
|
38
|
+
client: {
|
|
39
|
+
public: client,
|
|
40
|
+
chain,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
const balance = await ERC20Contract.read.balanceOf([user]);
|
|
44
|
+
|
|
45
|
+
if (balance < order.sourceTokenAmount) {
|
|
46
|
+
throw new InsufficientBalanceError(
|
|
47
|
+
`Insufficient balance for token ${order.sourceTokenAddress}. Current balance: ${balance}. Required balance: ${order.sourceTokenAmount}`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const permit2Address = PERMIT2_ADDRESS[chain];
|
|
52
|
+
const allowance = await ERC20Contract.read.allowance([user, permit2Address]);
|
|
53
|
+
|
|
54
|
+
if (allowance < order.sourceTokenAmount) {
|
|
55
|
+
throw new InsufficientAllowanceError(
|
|
56
|
+
`Insufficient allowance for token ${order.sourceTokenAddress} on permit2 address ${permit2Address}. Current allowance: ${allowance}. Required allowance: ${order.sourceTokenAmount}`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Account,
|
|
3
|
+
type Address,
|
|
4
|
+
type Chain,
|
|
5
|
+
type Client,
|
|
6
|
+
createClient,
|
|
7
|
+
createWalletClient,
|
|
8
|
+
getContract,
|
|
9
|
+
type Hex,
|
|
10
|
+
http,
|
|
11
|
+
type Transport,
|
|
12
|
+
type WalletClient,
|
|
13
|
+
} from 'viem';
|
|
14
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
15
|
+
import { arbitrum, base, optimism } from 'viem/chains';
|
|
16
|
+
import { ChainID, type SupportedEvmChain } from '../../chains.js';
|
|
17
|
+
import type { EVMConfig } from '../../config.js';
|
|
18
|
+
import { ERC20ABI } from './abi/erc20.js';
|
|
19
|
+
|
|
20
|
+
const chainIdToProviderChainMap = {
|
|
21
|
+
[ChainID.Arbitrum]: arbitrum,
|
|
22
|
+
[ChainID.Optimism]: optimism,
|
|
23
|
+
[ChainID.Base]: base,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export class ChainProvider {
|
|
27
|
+
private readonly privateKey: Hex;
|
|
28
|
+
public readonly chainId: SupportedEvmChain;
|
|
29
|
+
public readonly publicClient: Client;
|
|
30
|
+
public readonly walletClient: WalletClient<Transport, Chain, Account>;
|
|
31
|
+
|
|
32
|
+
constructor(config: EVMConfig) {
|
|
33
|
+
this.privateKey = config.privateKey as Hex;
|
|
34
|
+
this.chainId = config.chainId;
|
|
35
|
+
|
|
36
|
+
this.publicClient = this.getClient(config.rpcProviderUrl);
|
|
37
|
+
this.walletClient = this.getWalletClient(config.rpcProviderUrl);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static getClient(chainId: SupportedEvmChain, rpcProviderUrl?: string): Client {
|
|
41
|
+
const chain = chainIdToProviderChainMap[chainId];
|
|
42
|
+
|
|
43
|
+
return createClient({
|
|
44
|
+
chain,
|
|
45
|
+
transport: http(rpcProviderUrl),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
getClient(rpcProviderUrl?: string): Client {
|
|
50
|
+
return ChainProvider.getClient(this.chainId, rpcProviderUrl);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getAccount(): Account {
|
|
54
|
+
return privateKeyToAccount(this.privateKey);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getWalletClient(rpcProviderUrl?: string): WalletClient<Transport, Chain, Account> {
|
|
58
|
+
const chain = chainIdToProviderChainMap[this.chainId];
|
|
59
|
+
|
|
60
|
+
return createWalletClient({
|
|
61
|
+
account: privateKeyToAccount(this.privateKey),
|
|
62
|
+
chain,
|
|
63
|
+
transport: http(rpcProviderUrl),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
getERC20Contract(tokenAddress: Address) {
|
|
68
|
+
return getContract({
|
|
69
|
+
address: tokenAddress,
|
|
70
|
+
abi: ERC20ABI,
|
|
71
|
+
client: {
|
|
72
|
+
wallet: this.walletClient,
|
|
73
|
+
public: this.publicClient,
|
|
74
|
+
chain: chainIdToProviderChainMap[this.chainId],
|
|
75
|
+
account: this.walletClient.account,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { sha256, toBytes } from 'viem';
|
|
2
|
+
import { type SupportedChain } from '../chains.js';
|
|
3
|
+
import { ValidationError } from '../errors/index.js';
|
|
4
|
+
import { type ExecutionDetails, type Hash } from '../types/intent.js';
|
|
5
|
+
import { OrderValidator } from '../utils/order-validator.js';
|
|
6
|
+
import { Parsers } from '../utils/parsers.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Input parameters for creating a cross-chain order
|
|
10
|
+
*/
|
|
11
|
+
export type OrderInput = {
|
|
12
|
+
/** User's wallet address that initiates the order */
|
|
13
|
+
user: string;
|
|
14
|
+
/** Source chain ID where tokens will be sent from */
|
|
15
|
+
sourceChainId: SupportedChain;
|
|
16
|
+
/** Token address on the source chain to be swapped */
|
|
17
|
+
sourceTokenAddress: string;
|
|
18
|
+
/** Amount of source tokens to swap with decimals */
|
|
19
|
+
sourceTokenAmount: bigint;
|
|
20
|
+
/** Destination chain ID where tokens will be received */
|
|
21
|
+
destinationChainId: SupportedChain;
|
|
22
|
+
/** Token address on the destination chain to receive */
|
|
23
|
+
destinationTokenAddress: string;
|
|
24
|
+
/** Minimum amount of destination tokens to receive */
|
|
25
|
+
destinationTokenMinAmount: bigint;
|
|
26
|
+
/** Recipient wallet address on the destination chain */
|
|
27
|
+
destinationAddress: string;
|
|
28
|
+
/** Minimum amount of stablecoins in the intermediate swap */
|
|
29
|
+
minStablecoinAmount: bigint;
|
|
30
|
+
/** Timestamp (in seconds) after which the order expires */
|
|
31
|
+
deadline: number;
|
|
32
|
+
/** Extra transfers to be made */
|
|
33
|
+
extraTransfers?: ExtraTransfer[];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type ExtraTransfer = {
|
|
37
|
+
/** Token address */
|
|
38
|
+
token: string;
|
|
39
|
+
/** Receiver address */
|
|
40
|
+
receiver: string;
|
|
41
|
+
/** Amount of tokens to transfer */
|
|
42
|
+
amount: bigint;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Represents a cross-chain swap order
|
|
47
|
+
* Contains all the information needed to execute the order on both source and destination chains
|
|
48
|
+
*/
|
|
49
|
+
export class Order {
|
|
50
|
+
/** User's wallet address that initiates the order */
|
|
51
|
+
public user: string;
|
|
52
|
+
/** Source chain ID where tokens will be sent from */
|
|
53
|
+
public sourceChainId: SupportedChain;
|
|
54
|
+
/** Token address on the source chain to be swapped */
|
|
55
|
+
public sourceTokenAddress: string;
|
|
56
|
+
/** Amount of source tokens to swap */
|
|
57
|
+
public sourceTokenAmount: bigint;
|
|
58
|
+
/** Destination chain ID where tokens will be received */
|
|
59
|
+
public destinationChainId: SupportedChain;
|
|
60
|
+
/** Token address on the destination chain to receive */
|
|
61
|
+
public destinationTokenAddress: string;
|
|
62
|
+
/** Minimum amount of destination tokens to receive */
|
|
63
|
+
public destinationTokenMinAmount: bigint;
|
|
64
|
+
/** Recipient wallet address on the destination chain */
|
|
65
|
+
public destinationAddress: string;
|
|
66
|
+
/** Minimum amount of stablecoins in the intermediate swap */
|
|
67
|
+
public minStablecoinAmount: bigint;
|
|
68
|
+
/** Timestamp (in seconds) after which the order expires */
|
|
69
|
+
public deadline: number;
|
|
70
|
+
/** Extra transfers to be made */
|
|
71
|
+
public extraTransfers?: ExtraTransfer[];
|
|
72
|
+
|
|
73
|
+
constructor(input: OrderInput) {
|
|
74
|
+
this.user = input.user;
|
|
75
|
+
this.sourceChainId = input.sourceChainId;
|
|
76
|
+
this.sourceTokenAddress = input.sourceTokenAddress;
|
|
77
|
+
this.sourceTokenAmount = input.sourceTokenAmount;
|
|
78
|
+
this.destinationChainId = input.destinationChainId;
|
|
79
|
+
this.destinationTokenAddress = input.destinationTokenAddress;
|
|
80
|
+
this.destinationTokenMinAmount = input.destinationTokenMinAmount;
|
|
81
|
+
this.destinationAddress = input.destinationAddress;
|
|
82
|
+
this.minStablecoinAmount = input.minStablecoinAmount;
|
|
83
|
+
this.deadline = input.deadline;
|
|
84
|
+
this.extraTransfers = input.extraTransfers;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Factory method to create and validate a new Order instance
|
|
89
|
+
* @param input Order parameters
|
|
90
|
+
* @returns Validated Order instance
|
|
91
|
+
* @throws {ValidationError} If order validation fails
|
|
92
|
+
*/
|
|
93
|
+
public static async create(input: OrderInput): Promise<Order> {
|
|
94
|
+
await new OrderValidator().validateOrder(input);
|
|
95
|
+
|
|
96
|
+
const order = new Order({
|
|
97
|
+
...input,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return order;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Gets the execution details for the destination chain
|
|
105
|
+
* These details are used to complete the order on the destination chain
|
|
106
|
+
* @returns Structured execution details object
|
|
107
|
+
*/
|
|
108
|
+
public getExecutionDetails(): ExecutionDetails {
|
|
109
|
+
return {
|
|
110
|
+
destChainId: this.destinationChainId,
|
|
111
|
+
tokenOut: this.destinationTokenAddress,
|
|
112
|
+
destinationAddress: this.destinationAddress,
|
|
113
|
+
amountOutMin: this.destinationTokenMinAmount,
|
|
114
|
+
extraTransfers: this.extraTransfers,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public executionDetailsHashToBytes(): Uint8Array {
|
|
119
|
+
const executionDetailsHash = this.getExecutionDetailsHash().slice(2);
|
|
120
|
+
|
|
121
|
+
const executionHashByteSlice = Buffer.from(executionDetailsHash, 'hex');
|
|
122
|
+
|
|
123
|
+
return new Uint8Array(executionHashByteSlice);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Generates a cryptographic hash of the execution details
|
|
128
|
+
* This hash is used to verify order integrity across chains
|
|
129
|
+
* @returns SHA-256 hash of the execution details as a 0x-prefixed hex string
|
|
130
|
+
* @throws {ValidationError} If hash generation fails
|
|
131
|
+
*/
|
|
132
|
+
public getExecutionDetailsHash(): Hash {
|
|
133
|
+
try {
|
|
134
|
+
const executionDetails = this.getExecutionDetails();
|
|
135
|
+
const executionDetailsString = JSON.stringify(executionDetails, Parsers.bigIntReplacer);
|
|
136
|
+
|
|
137
|
+
const bytes = toBytes(executionDetailsString);
|
|
138
|
+
return sha256(bytes);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
throw new ValidationError(
|
|
141
|
+
'Failed to generate execution details hash',
|
|
142
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Converts the order to the format required for source chain processing
|
|
149
|
+
* Used when sending the order to the auctioneer for execution
|
|
150
|
+
* @returns Object containing source chain-specific data
|
|
151
|
+
*/
|
|
152
|
+
public toSourceChainData() {
|
|
153
|
+
return {
|
|
154
|
+
user: this.user,
|
|
155
|
+
srcChainId: this.sourceChainId,
|
|
156
|
+
tokenIn: this.sourceTokenAddress,
|
|
157
|
+
amountIn: this.sourceTokenAmount,
|
|
158
|
+
minStablecoinsAmount: this.minStablecoinAmount,
|
|
159
|
+
deadline: this.deadline,
|
|
160
|
+
executionDetailsHash: this.getExecutionDetailsHash(),
|
|
161
|
+
extraTransfers: this.extraTransfers,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Serializes the order to a JSON-compatible object
|
|
167
|
+
* Converts bigint values to strings to ensure proper JSON serialization
|
|
168
|
+
* @returns JSON-serializable representation of the order
|
|
169
|
+
*/
|
|
170
|
+
public toJSON() {
|
|
171
|
+
return {
|
|
172
|
+
user: this.user,
|
|
173
|
+
sourceChainId: this.sourceChainId as number,
|
|
174
|
+
sourceTokenAddress: this.sourceTokenAddress,
|
|
175
|
+
sourceTokenAmount: this.sourceTokenAmount.toString(),
|
|
176
|
+
destinationChainId: this.destinationChainId as number,
|
|
177
|
+
destinationTokenAddress: this.destinationTokenAddress,
|
|
178
|
+
destinationTokenMinAmount: this.destinationTokenMinAmount.toString(),
|
|
179
|
+
destinationAddress: this.destinationAddress,
|
|
180
|
+
minStablecoinAmount: this.minStablecoinAmount.toString(),
|
|
181
|
+
deadline: this.deadline,
|
|
182
|
+
executionDetailsHash: this.getExecutionDetailsHash(),
|
|
183
|
+
extraTransfers: this.extraTransfers,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|