@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,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
import { combineCodec, getAddressDecoder, getAddressEncoder, getStructDecoder, getStructEncoder, } from '@solana/kit';
|
|
9
|
+
export function getGuardCreatedEncoder() {
|
|
10
|
+
return getStructEncoder([
|
|
11
|
+
['guardId', getAddressEncoder()],
|
|
12
|
+
['collateralMint', getAddressEncoder()],
|
|
13
|
+
['stablecoinMint', getAddressEncoder()],
|
|
14
|
+
['auctioneerPubKey', getAddressEncoder()],
|
|
15
|
+
]);
|
|
16
|
+
}
|
|
17
|
+
export function getGuardCreatedDecoder() {
|
|
18
|
+
return getStructDecoder([
|
|
19
|
+
['guardId', getAddressDecoder()],
|
|
20
|
+
['collateralMint', getAddressDecoder()],
|
|
21
|
+
['stablecoinMint', getAddressDecoder()],
|
|
22
|
+
['auctioneerPubKey', getAddressDecoder()],
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
25
|
+
export function getGuardCreatedCodec() {
|
|
26
|
+
return combineCodec(getGuardCreatedEncoder(), getGuardCreatedDecoder());
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=guardCreated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guardCreated.js","sourceRoot":"","sources":["../../../../../../src/core/solana/generated/types/guardCreated.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAGL,YAAY,EAGZ,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAWrB,MAAM,UAAU,sBAAsB;IACpC,OAAO,gBAAgB,CAAC;QACtB,CAAC,SAAS,EAAE,iBAAiB,EAAE,CAAC;QAChC,CAAC,gBAAgB,EAAE,iBAAiB,EAAE,CAAC;QACvC,CAAC,gBAAgB,EAAE,iBAAiB,EAAE,CAAC;QACvC,CAAC,kBAAkB,EAAE,iBAAiB,EAAE,CAAC;KAC1C,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,gBAAgB,CAAC;QACtB,CAAC,SAAS,EAAE,iBAAiB,EAAE,CAAC;QAChC,CAAC,gBAAgB,EAAE,iBAAiB,EAAE,CAAC;QACvC,CAAC,gBAAgB,EAAE,iBAAiB,EAAE,CAAC;QACvC,CAAC,kBAAkB,EAAE,iBAAiB,EAAE,CAAC;KAC1C,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,oBAAoB;IAClC,OAAO,YAAY,CAAC,sBAAsB,EAAE,EAAE,sBAAsB,EAAE,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
export * from './adminUpdated.js';
|
|
9
|
+
export * from './auctioneerPubkeyUpdated.js';
|
|
10
|
+
export * from './executionStarted.js';
|
|
11
|
+
export * from './guardCreated.js';
|
|
12
|
+
export * from './orderCancelled.js';
|
|
13
|
+
export * from './orderCreated.js';
|
|
14
|
+
export * from './orderFulfilled.js';
|
|
15
|
+
export * from './tokenInSwapped.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/core/solana/generated/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
import { combineCodec, getAddressDecoder, getAddressEncoder, getStructDecoder, getStructEncoder, } from '@solana/kit';
|
|
9
|
+
export function getOrderCancelledEncoder() {
|
|
10
|
+
return getStructEncoder([['orderId', getAddressEncoder()]]);
|
|
11
|
+
}
|
|
12
|
+
export function getOrderCancelledDecoder() {
|
|
13
|
+
return getStructDecoder([['orderId', getAddressDecoder()]]);
|
|
14
|
+
}
|
|
15
|
+
export function getOrderCancelledCodec() {
|
|
16
|
+
return combineCodec(getOrderCancelledEncoder(), getOrderCancelledDecoder());
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=orderCancelled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orderCancelled.js","sourceRoot":"","sources":["../../../../../../src/core/solana/generated/types/orderCancelled.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAGL,YAAY,EAGZ,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAMrB,MAAM,UAAU,wBAAwB;IACtC,OAAO,gBAAgB,CAAC,CAAC,CAAC,SAAS,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,OAAO,gBAAgB,CAAC,CAAC,CAAC,SAAS,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,YAAY,CAAC,wBAAwB,EAAE,EAAE,wBAAwB,EAAE,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
import { combineCodec, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, } from '@solana/kit';
|
|
9
|
+
export function getOrderCreatedEncoder() {
|
|
10
|
+
return getStructEncoder([
|
|
11
|
+
['orderId', getAddressEncoder()],
|
|
12
|
+
['user', getAddressEncoder()],
|
|
13
|
+
['guard', getAddressEncoder()],
|
|
14
|
+
['tokenInMint', getAddressEncoder()],
|
|
15
|
+
['amountIn', getU64Encoder()],
|
|
16
|
+
['minStablecoinsAmount', getU64Encoder()],
|
|
17
|
+
['deadline', getU32Encoder()],
|
|
18
|
+
['executionDetailsHash', fixEncoderSize(getBytesEncoder(), 32)],
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
21
|
+
export function getOrderCreatedDecoder() {
|
|
22
|
+
return getStructDecoder([
|
|
23
|
+
['orderId', getAddressDecoder()],
|
|
24
|
+
['user', getAddressDecoder()],
|
|
25
|
+
['guard', getAddressDecoder()],
|
|
26
|
+
['tokenInMint', getAddressDecoder()],
|
|
27
|
+
['amountIn', getU64Decoder()],
|
|
28
|
+
['minStablecoinsAmount', getU64Decoder()],
|
|
29
|
+
['deadline', getU32Decoder()],
|
|
30
|
+
['executionDetailsHash', fixDecoderSize(getBytesDecoder(), 32)],
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
export function getOrderCreatedCodec() {
|
|
34
|
+
return combineCodec(getOrderCreatedEncoder(), getOrderCreatedDecoder());
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=orderCreated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orderCreated.js","sourceRoot":"","sources":["../../../../../../src/core/solana/generated/types/orderCreated.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAGL,YAAY,EAGZ,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,aAAa,EACb,aAAa,GAEd,MAAM,aAAa,CAAC;AAwBrB,MAAM,UAAU,sBAAsB;IACpC,OAAO,gBAAgB,CAAC;QACtB,CAAC,SAAS,EAAE,iBAAiB,EAAE,CAAC;QAChC,CAAC,MAAM,EAAE,iBAAiB,EAAE,CAAC;QAC7B,CAAC,OAAO,EAAE,iBAAiB,EAAE,CAAC;QAC9B,CAAC,aAAa,EAAE,iBAAiB,EAAE,CAAC;QACpC,CAAC,UAAU,EAAE,aAAa,EAAE,CAAC;QAC7B,CAAC,sBAAsB,EAAE,aAAa,EAAE,CAAC;QACzC,CAAC,UAAU,EAAE,aAAa,EAAE,CAAC;QAC7B,CAAC,sBAAsB,EAAE,cAAc,CAAC,eAAe,EAAE,EAAE,EAAE,CAAC,CAAC;KAChE,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,gBAAgB,CAAC;QACtB,CAAC,SAAS,EAAE,iBAAiB,EAAE,CAAC;QAChC,CAAC,MAAM,EAAE,iBAAiB,EAAE,CAAC;QAC7B,CAAC,OAAO,EAAE,iBAAiB,EAAE,CAAC;QAC9B,CAAC,aAAa,EAAE,iBAAiB,EAAE,CAAC;QACpC,CAAC,UAAU,EAAE,aAAa,EAAE,CAAC;QAC7B,CAAC,sBAAsB,EAAE,aAAa,EAAE,CAAC;QACzC,CAAC,UAAU,EAAE,aAAa,EAAE,CAAC;QAC7B,CAAC,sBAAsB,EAAE,cAAc,CAAC,eAAe,EAAE,EAAE,EAAE,CAAC,CAAC;KAChE,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,oBAAoB;IAClC,OAAO,YAAY,CAAC,sBAAsB,EAAE,EAAE,sBAAsB,EAAE,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
import { combineCodec, getAddressDecoder, getAddressEncoder, getStructDecoder, getStructEncoder, } from '@solana/kit';
|
|
9
|
+
export function getOrderFulfilledEncoder() {
|
|
10
|
+
return getStructEncoder([['orderId', getAddressEncoder()]]);
|
|
11
|
+
}
|
|
12
|
+
export function getOrderFulfilledDecoder() {
|
|
13
|
+
return getStructDecoder([['orderId', getAddressDecoder()]]);
|
|
14
|
+
}
|
|
15
|
+
export function getOrderFulfilledCodec() {
|
|
16
|
+
return combineCodec(getOrderFulfilledEncoder(), getOrderFulfilledDecoder());
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=orderFulfilled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orderFulfilled.js","sourceRoot":"","sources":["../../../../../../src/core/solana/generated/types/orderFulfilled.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAGL,YAAY,EAGZ,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAMrB,MAAM,UAAU,wBAAwB;IACtC,OAAO,gBAAgB,CAAC,CAAC,CAAC,SAAS,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,OAAO,gBAAgB,CAAC,CAAC,CAAC,SAAS,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,YAAY,CAAC,wBAAwB,EAAE,EAAE,wBAAwB,EAAE,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
import { combineCodec, getAddressDecoder, getAddressEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, } from '@solana/kit';
|
|
9
|
+
export function getTokenInSwappedEncoder() {
|
|
10
|
+
return getStructEncoder([
|
|
11
|
+
['orderId', getAddressEncoder()],
|
|
12
|
+
['solver', getAddressEncoder()],
|
|
13
|
+
['stablecoinsAmount', getU64Encoder()],
|
|
14
|
+
]);
|
|
15
|
+
}
|
|
16
|
+
export function getTokenInSwappedDecoder() {
|
|
17
|
+
return getStructDecoder([
|
|
18
|
+
['orderId', getAddressDecoder()],
|
|
19
|
+
['solver', getAddressDecoder()],
|
|
20
|
+
['stablecoinsAmount', getU64Decoder()],
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
23
|
+
export function getTokenInSwappedCodec() {
|
|
24
|
+
return combineCodec(getTokenInSwappedEncoder(), getTokenInSwappedDecoder());
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=tokenInSwapped.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenInSwapped.js","sourceRoot":"","sources":["../../../../../../src/core/solana/generated/types/tokenInSwapped.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAGL,YAAY,EAGZ,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,aAAa,GACd,MAAM,aAAa,CAAC;AAcrB,MAAM,UAAU,wBAAwB;IACtC,OAAO,gBAAgB,CAAC;QACtB,CAAC,SAAS,EAAE,iBAAiB,EAAE,CAAC;QAChC,CAAC,QAAQ,EAAE,iBAAiB,EAAE,CAAC;QAC/B,CAAC,mBAAmB,EAAE,aAAa,EAAE,CAAC;KACvC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,OAAO,gBAAgB,CAAC;QACtB,CAAC,SAAS,EAAE,iBAAiB,EAAE,CAAC;QAChC,CAAC,QAAQ,EAAE,iBAAiB,EAAE,CAAC;QAC/B,CAAC,mBAAmB,EAAE,aAAa,EAAE,CAAC;KACvC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,YAAY,CAAC,wBAAwB,EAAE,EAAE,wBAAwB,EAAE,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { address, createNoopSigner, fetchEncodedAccount, generateKeyPairSigner, getAddressEncoder, getProgramDerivedAddress, } from '@solana/kit';
|
|
2
|
+
import { getTransferSolInstruction, SYSTEM_PROGRAM_ADDRESS } from '@solana-program/system';
|
|
3
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ADDRESS, fetchMint, getCreateAssociatedTokenInstructionAsync, getSyncNativeInstruction, } from '@solana-program/token';
|
|
4
|
+
import { ChainID } from '../../chains.js';
|
|
5
|
+
import { NATIVE_SOLANA_TOKEN_ADDRESS, SRC_CHAIN_GUARD, WRAPPED_SOL_MINT_ADDRESS } from '../../constants.js';
|
|
6
|
+
import { getDefaultSolanaRPC } from './client.js';
|
|
7
|
+
import { getCreateOrderInstruction } from './generated/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Generates Solana order instructions for creating an order
|
|
10
|
+
* @param order The order to generate instructions
|
|
11
|
+
* @returns Object containing the order public key and instructions
|
|
12
|
+
*/
|
|
13
|
+
export async function getSolanaOrderInstructions(order) {
|
|
14
|
+
const rpc = getDefaultSolanaRPC();
|
|
15
|
+
const orderSigner = await generateKeyPairSigner();
|
|
16
|
+
const signer = createNoopSigner(order.user);
|
|
17
|
+
let tokenInMint = address(order.sourceTokenAddress);
|
|
18
|
+
const orderUserAddress = address(order.user);
|
|
19
|
+
const spendingNative = tokenInMint === NATIVE_SOLANA_TOKEN_ADDRESS;
|
|
20
|
+
if (spendingNative) {
|
|
21
|
+
tokenInMint = WRAPPED_SOL_MINT_ADDRESS;
|
|
22
|
+
}
|
|
23
|
+
const tokenMintProgram = await fetchMint(rpc, tokenInMint);
|
|
24
|
+
const guardAddress = address(SRC_CHAIN_GUARD[ChainID.Solana]);
|
|
25
|
+
const addressEncoder = getAddressEncoder();
|
|
26
|
+
const [tokenInProgramAccount] = await getProgramDerivedAddress({
|
|
27
|
+
programAddress: ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
28
|
+
seeds: [
|
|
29
|
+
addressEncoder.encode(orderUserAddress),
|
|
30
|
+
addressEncoder.encode(tokenMintProgram.programAddress),
|
|
31
|
+
addressEncoder.encode(tokenInMint),
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
const [guardProgramAccount] = await getProgramDerivedAddress({
|
|
35
|
+
programAddress: ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
36
|
+
seeds: [
|
|
37
|
+
// Owner
|
|
38
|
+
addressEncoder.encode(guardAddress),
|
|
39
|
+
// Token program
|
|
40
|
+
addressEncoder.encode(tokenMintProgram.programAddress),
|
|
41
|
+
// mint address
|
|
42
|
+
addressEncoder.encode(tokenInMint),
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
const instructions = [];
|
|
46
|
+
// Handle native SOL
|
|
47
|
+
if (spendingNative) {
|
|
48
|
+
order.sourceTokenAddress = WRAPPED_SOL_MINT_ADDRESS;
|
|
49
|
+
const userTokenInAccount = await fetchEncodedAccount(rpc, tokenInProgramAccount);
|
|
50
|
+
if (!userTokenInAccount.exists) {
|
|
51
|
+
const createAccountIx = await getCreateAssociatedTokenInstructionAsync({
|
|
52
|
+
payer: signer,
|
|
53
|
+
ata: tokenInProgramAccount,
|
|
54
|
+
owner: orderUserAddress,
|
|
55
|
+
mint: tokenMintProgram.address,
|
|
56
|
+
tokenProgram: tokenMintProgram.programAddress,
|
|
57
|
+
});
|
|
58
|
+
instructions.push(createAccountIx);
|
|
59
|
+
}
|
|
60
|
+
const transferIx = getTransferSolInstruction({
|
|
61
|
+
source: signer,
|
|
62
|
+
destination: userTokenInAccount.address,
|
|
63
|
+
amount: order.sourceTokenAmount,
|
|
64
|
+
});
|
|
65
|
+
const syncNativeIx = getSyncNativeInstruction({
|
|
66
|
+
account: userTokenInAccount.address,
|
|
67
|
+
});
|
|
68
|
+
instructions.push(transferIx, syncNativeIx);
|
|
69
|
+
}
|
|
70
|
+
const executionHashUint8Array = order.executionDetailsHashToBytes();
|
|
71
|
+
const createOrderIx = getCreateOrderInstruction({
|
|
72
|
+
user: signer,
|
|
73
|
+
order: orderSigner,
|
|
74
|
+
guard: address(SRC_CHAIN_GUARD[ChainID.Solana]),
|
|
75
|
+
systemProgram: SYSTEM_PROGRAM_ADDRESS,
|
|
76
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
77
|
+
tokenInMint: tokenInMint,
|
|
78
|
+
userTokenInAccount: tokenInProgramAccount,
|
|
79
|
+
guardTokenInAccount: guardProgramAccount,
|
|
80
|
+
tokenInProgram: tokenMintProgram.programAddress,
|
|
81
|
+
amountIn: order.sourceTokenAmount,
|
|
82
|
+
deadline: order.deadline,
|
|
83
|
+
executionDetailsHash: executionHashUint8Array,
|
|
84
|
+
minStablecoinsAmount: order.minStablecoinAmount,
|
|
85
|
+
});
|
|
86
|
+
instructions.push(createOrderIx);
|
|
87
|
+
return {
|
|
88
|
+
instructions,
|
|
89
|
+
orderKeyPair: orderSigner,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=order-instructions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-instructions.js","sourceRoot":"","sources":["../../../../src/core/solana/order-instructions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EACP,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,wBAAwB,GAGzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAC3F,OAAO,EACL,gCAAgC,EAChC,SAAS,EACT,wCAAwC,EACxC,wBAAwB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAE5G,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEjE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,KAAY;IAI3D,MAAM,GAAG,GAAG,mBAAmB,EAAE,CAAC;IAClC,MAAM,WAAW,GAAG,MAAM,qBAAqB,EAAE,CAAC;IAClD,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,IAAe,CAAC,CAAC;IAEvD,IAAI,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAEpD,MAAM,gBAAgB,GAAG,OAA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AAY,EAAE,WAAW;KAC1B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { appendTransactionMessageInstructions, compileTransaction, createKeyPairFromBytes, createNoopSigner, createSignerFromKeyPair, createTransactionMessage, getBase58Encoder, pipe, setTransactionMessageFeePayerSigner, setTransactionMessageLifetimeUsingBlockhash, signTransaction, } from '@solana/kit';
|
|
2
|
+
import { Order } from '../order.js';
|
|
3
|
+
import { BaseSDK } from '../sdk.js';
|
|
4
|
+
import { createSolanaClient } from './client.js';
|
|
5
|
+
import { getSolanaOrderInstructions } from './order-instructions.js';
|
|
6
|
+
/**
|
|
7
|
+
* Solana-specific SDK implementation
|
|
8
|
+
*
|
|
9
|
+
* Handles Solana-specific aspects of cross-chain swaps using Solana blockchain.
|
|
10
|
+
* Uses @solana/kit for transaction creation, signing, and submission.
|
|
11
|
+
* Supports cross-chain swaps from Solana to other supported chains.
|
|
12
|
+
*/
|
|
13
|
+
export class SolanaSDK extends BaseSDK {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new instance of the Solana SDK
|
|
16
|
+
*
|
|
17
|
+
* @param config Solana configuration including privateKey, commitment level, and optional RPC URL
|
|
18
|
+
*/
|
|
19
|
+
constructor(config) {
|
|
20
|
+
super();
|
|
21
|
+
/** Configuration for Solana connection and authentication */
|
|
22
|
+
Object.defineProperty(this, "config", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
28
|
+
/** Client for Solana RPC interactions and transaction handling */
|
|
29
|
+
Object.defineProperty(this, "client", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: void 0
|
|
34
|
+
});
|
|
35
|
+
this.config = config;
|
|
36
|
+
this.client = createSolanaClient(config);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets the user's Solana wallet address derived from their private key
|
|
40
|
+
*
|
|
41
|
+
* Uses @solana/kit to securely derive the wallet address from the private key
|
|
42
|
+
*
|
|
43
|
+
* @returns Promise resolving to the user's Solana address as a Base58-encoded string
|
|
44
|
+
* @throws {SolanaError} If address derivation fails
|
|
45
|
+
*/
|
|
46
|
+
async getUserAddress() {
|
|
47
|
+
const signer = await this.getUserSigner();
|
|
48
|
+
return signer.address;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a CryptoKeyPair from the user's private key
|
|
52
|
+
*
|
|
53
|
+
* Converts the Base58-encoded private key to the format required by WebCrypto API
|
|
54
|
+
*
|
|
55
|
+
* @returns Promise resolving to a CryptoKeyPair for transaction signing
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
async getUserCryptoKeypair() {
|
|
59
|
+
const encoder = getBase58Encoder();
|
|
60
|
+
const bytesWithPrefix = encoder.encode(this.config.privateKey);
|
|
61
|
+
return createKeyPairFromBytes(bytesWithPrefix);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Creates a KeyPairSigner from the user's crypto keypair
|
|
65
|
+
*
|
|
66
|
+
* The KeyPairSigner is used for transaction signing and verification
|
|
67
|
+
*
|
|
68
|
+
* @returns Promise resolving to a KeyPairSigner for transaction operations
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
async getUserSigner() {
|
|
72
|
+
const signer = await this.getUserCryptoKeypair();
|
|
73
|
+
return createSignerFromKeyPair(signer);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Prepares a Solana order for submission
|
|
77
|
+
*
|
|
78
|
+
* This method:
|
|
79
|
+
* 1. Gets the user's signer from their private key
|
|
80
|
+
* 2. Generates Solana-specific instructions for the order
|
|
81
|
+
* 3. Creates, signs, and submits the transaction to the Solana blockchain
|
|
82
|
+
* 4. Returns the prepared order with the orderPubkey for tracking
|
|
83
|
+
*
|
|
84
|
+
* @param order The validated order to prepare
|
|
85
|
+
* @returns Promise resolving to a prepared order with Solana-specific data
|
|
86
|
+
* @protected
|
|
87
|
+
*/
|
|
88
|
+
async prepareOrder(order) {
|
|
89
|
+
const signer = await this.getUserSigner();
|
|
90
|
+
const signerKeyPair = await this.getUserCryptoKeypair();
|
|
91
|
+
const { orderKeyPair, instructions } = await getSolanaOrderInstructions(order);
|
|
92
|
+
const noopSigner = createNoopSigner(signer.address);
|
|
93
|
+
const { value: latestBlockhash } = await this.client.rpc
|
|
94
|
+
.getLatestBlockhash({ commitment: this.config.commitment })
|
|
95
|
+
.send();
|
|
96
|
+
// TODO: Think if we should include transaction message on getSolanaOrderInstructions
|
|
97
|
+
const transactionMessage = pipe(createTransactionMessage({ version: 0 }), (tx) => setTransactionMessageFeePayerSigner(noopSigner, tx), (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx), (tx) => appendTransactionMessageInstructions(instructions, tx));
|
|
98
|
+
const myTx = compileTransaction(transactionMessage);
|
|
99
|
+
const signature = await signTransaction([signerKeyPair, orderKeyPair.keyPair], myTx);
|
|
100
|
+
await this.client.sendAndConfirmTransaction(signature, {
|
|
101
|
+
commitment: this.config.commitment,
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
order,
|
|
105
|
+
preparedData: {
|
|
106
|
+
orderPubkey: orderKeyPair.address,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../../../src/core/solana/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oCAAoC,EACpC,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAEhB,IAAI,EACJ,mCAAmC,EACnC,2CAA2C,EAC3C,eAAe,GAChB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,KAAK,EAAE,MAAM,a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AE,GAAG,MAAM,0BAA0B,CAAC,KAAK,CAAC,CAAC;QAE/E,MAAM,UAAU,GAAG,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAEpD,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG;aACrD,kBAAkB,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;aAC1D,IAAI,EAAE,CAAC;QAEV,qFAAqF;QACrF,MAAM,kBAAkB,GAAG,IAAI,CAC7B,wBAAwB,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EACxC,CAAC,EAAE,EAAE,EAAE,CAAC,mCAAmC,CAAC,UAAU,EAAE,EAAE,CAAC,EAC3D,CAAC,EAAE,EAAE,EAAE,CAAC,2CAA2C,CAAC,eAAe,EAAE,EAAE,CAAC,EACxE,CAAC,EAAE,EAAE,EAAE,CAAC,oCAAoC,CAAC,YAAY,EAAE,EAAE,CAAC,CAC/D,CAAC;QAEF,MAAM,IAAI,GAAG,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;QAEpD,MAAM,SAAS,GAAG,MAAM,eAAe,CAAC,CAAC,aAAa,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;QAErF,MAAM,IAAI,CAAC,MAAM,CAAC,yBAAyB,CAAC,SAAS,EAAE;YACrD,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU;SACnC,CAAC,CAAC;QAEH,OAAO;YACL,KAAK;YACL,YAAY,EAAE;gBACZ,WAAW,EAAE,YAAY,CAAC,OAAO;aAClC;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isAddress as isSolanaAddress } from '@solana/kit';
|
|
2
|
+
import { MAX_UINT_64 } from '../../constants.js';
|
|
3
|
+
import { BaseValidator } from '../../utils/base-validator.js';
|
|
4
|
+
export class SolanaValidator extends BaseValidator {
|
|
5
|
+
isValidAddress(address) {
|
|
6
|
+
return isSolanaAddress(address);
|
|
7
|
+
}
|
|
8
|
+
isValidTokenAddress(tokenAddress) {
|
|
9
|
+
return isSolanaAddress(tokenAddress);
|
|
10
|
+
}
|
|
11
|
+
isValidAmount(amount) {
|
|
12
|
+
return amount > 0n && amount < MAX_UINT_64;
|
|
13
|
+
}
|
|
14
|
+
getChainName() {
|
|
15
|
+
return 'Solana';
|
|
16
|
+
}
|
|
17
|
+
async chainSpecificValidation() {
|
|
18
|
+
// No chain-specific validation implemented for now for Solana
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../../../src/core/solana/validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,MAAM,OAAO,eAAgB,SAAQ,aAAa;IAChD,cAAc,CAAC,OAAe;QAC5B,OAAO,eAAe,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAED,mBAAmB,CAAC,YAAoB;QACtC,OAAO,eAAe,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;IAED,aAAa,CAAC,MAAc;QAC1B,OAAO,MAAM,GAAG,EAAE,IAAI,MAAM,GAAG,WAAW,CAAC;IAC7C,CAAC;IAES,YAAY;QACpB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,uBAAuB;QAClC,8DAA8D;QAC9D,OAAO;IACT,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../src/core/sui/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/D,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,EAAE,GAAG,EAAE,cAAc,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
2
|
+
import { normalizeSuiObjectId, SUI_TYPE_ARG } from '@mysten/sui/utils';
|
|
3
|
+
import { ChainID } from '../../chains.js';
|
|
4
|
+
import { SRC_CHAIN_GUARD, SUI_GUARD_COLLATERAL_TYPE, SUI_GUARD_STABLECOIN_TYPE, SUI_PACKAGE_ID, } from '../../constants.js';
|
|
5
|
+
import { ValidationError } from '../../errors/index.js';
|
|
6
|
+
import { createSuiClient } from './client.js';
|
|
7
|
+
/**
|
|
8
|
+
* Generates Sui order transaction for creating an order
|
|
9
|
+
* @param order The order to generate transaction for
|
|
10
|
+
* @returns Object containing the transaction
|
|
11
|
+
*/
|
|
12
|
+
export async function getSuiOrderTransaction(order) {
|
|
13
|
+
const userAddress = order.user;
|
|
14
|
+
const client = createSuiClient();
|
|
15
|
+
const coins = await client.getCoins({
|
|
16
|
+
owner: userAddress,
|
|
17
|
+
coinType: order.sourceTokenAddress,
|
|
18
|
+
});
|
|
19
|
+
const guardAddress = SRC_CHAIN_GUARD[ChainID.Sui];
|
|
20
|
+
const sourceTokenInCoins = coins.data.sort((a, b) => Number(b.balance) - Number(a.balance));
|
|
21
|
+
if (sourceTokenInCoins.length === 0) {
|
|
22
|
+
throw new ValidationError(`No token (${order.sourceTokenAddress}) to create order`);
|
|
23
|
+
}
|
|
24
|
+
const coinsInSum = sourceTokenInCoins.reduce((acc, coin) => acc + BigInt(coin.balance), 0n);
|
|
25
|
+
if (coinsInSum < order.sourceTokenAmount) {
|
|
26
|
+
throw new ValidationError(`Insufficient balance to create order. Total coins is ${coinsInSum}, but order requires ${order.sourceTokenAmount}`);
|
|
27
|
+
}
|
|
28
|
+
const spendingGasCoin = normalizeSuiObjectId(order.sourceTokenAddress) === normalizeSuiObjectId(SUI_TYPE_ARG);
|
|
29
|
+
const tx = new Transaction();
|
|
30
|
+
const coinInArg = spendingGasCoin ? tx.gas : sourceTokenInCoins[0].coinObjectId;
|
|
31
|
+
if (sourceTokenInCoins.length > 1) {
|
|
32
|
+
// Merging coins IN into a single object just in case
|
|
33
|
+
tx.mergeCoins(
|
|
34
|
+
// merge into 1st coin object
|
|
35
|
+
coinInArg,
|
|
36
|
+
// merge the rest of coins
|
|
37
|
+
sourceTokenInCoins.slice(1).map((coin) => coin.coinObjectId));
|
|
38
|
+
}
|
|
39
|
+
const [coinIn] = tx.splitCoins(coinInArg, [order.sourceTokenAmount]);
|
|
40
|
+
tx.moveCall({
|
|
41
|
+
package: SUI_PACKAGE_ID,
|
|
42
|
+
module: 'source_chain_guard',
|
|
43
|
+
function: 'create_order',
|
|
44
|
+
arguments: [
|
|
45
|
+
tx.object(guardAddress),
|
|
46
|
+
coinIn,
|
|
47
|
+
tx.pure.u64(order.minStablecoinAmount),
|
|
48
|
+
tx.pure.u64(order.deadline * 1000), // Convert to milliseconds
|
|
49
|
+
tx.pure.vector('u8', order.executionDetailsHashToBytes()),
|
|
50
|
+
],
|
|
51
|
+
typeArguments: [SUI_GUARD_COLLATERAL_TYPE, order.sourceTokenAddress, SUI_GUARD_STABLECOIN_TYPE],
|
|
52
|
+
});
|
|
53
|
+
tx.setSender(userAddress);
|
|
54
|
+
return tx;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=order-transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-transaction.js","sourceRoot":"","sources":["../../../../src/core/sui/order-transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,mBAAm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;KAChG,CAAC,CAAC;IAEH,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1B,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
2
|
+
import { OrderCreationError } from '../../errors/index.js';
|
|
3
|
+
import { Order } from '../order.js';
|
|
4
|
+
import { BaseSDK } from '../sdk.js';
|
|
5
|
+
import { createSuiClient } from './client.js';
|
|
6
|
+
import { getSuiOrderTransaction } from './order-transaction.js';
|
|
7
|
+
/**
|
|
8
|
+
* Sui-specific SDK implementation
|
|
9
|
+
*
|
|
10
|
+
* Handles Sui-specific aspects of cross-chain swaps using the Sui blockchain.
|
|
11
|
+
* Uses @mysten/sui libraries for transaction creation, signing, and submission.
|
|
12
|
+
* Supports cross-chain swaps from Sui to other supported chains.
|
|
13
|
+
*/
|
|
14
|
+
export class SuiSDK extends BaseSDK {
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new instance of the Sui SDK
|
|
17
|
+
*
|
|
18
|
+
* @param config Sui configuration including privateKey and optional RPC URL
|
|
19
|
+
*/
|
|
20
|
+
constructor(config) {
|
|
21
|
+
super();
|
|
22
|
+
/** Configuration for Sui connection and authentication */
|
|
23
|
+
Object.defineProperty(this, "config", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
/** Client for Sui RPC interactions and transaction handling */
|
|
30
|
+
Object.defineProperty(this, "client", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true,
|
|
34
|
+
value: void 0
|
|
35
|
+
});
|
|
36
|
+
this.config = config;
|
|
37
|
+
this.client = createSuiClient();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Gets the user's Sui wallet address derived from their private key
|
|
41
|
+
*
|
|
42
|
+
* Uses Ed25519Keypair to securely derive the wallet address from the private key
|
|
43
|
+
*
|
|
44
|
+
* @returns Promise resolving to the user's Sui address as a hex string
|
|
45
|
+
*/
|
|
46
|
+
async getUserAddress() {
|
|
47
|
+
return this.getKeyPair().toSuiAddress();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates an Ed25519Keypair from the user's private key
|
|
51
|
+
*
|
|
52
|
+
* The keypair is used for transaction signing and address derivation
|
|
53
|
+
*
|
|
54
|
+
* @returns Ed25519Keypair for cryptographic operations
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
getKeyPair() {
|
|
58
|
+
return Ed25519Keypair.fromSecretKey(this.config.privateKey);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Prepares a Sui order for submission
|
|
62
|
+
*
|
|
63
|
+
* This method:
|
|
64
|
+
* 1. Gets the user's keypair from their private key
|
|
65
|
+
* 2. Generates Sui-specific transaction for the order
|
|
66
|
+
* 3. Signs and executes the transaction on the Sui blockchain
|
|
67
|
+
* 4. Returns the prepared order with the transaction hash for tracking
|
|
68
|
+
*
|
|
69
|
+
* @param order The validated order to prepare
|
|
70
|
+
* @returns Promise resolving to a prepared order with Sui-specific data
|
|
71
|
+
* @protected
|
|
72
|
+
*/
|
|
73
|
+
async prepareOrder(order) {
|
|
74
|
+
try {
|
|
75
|
+
const signer = this.getKeyPair();
|
|
76
|
+
const transaction = await getSuiOrderTransaction(order);
|
|
77
|
+
const tx = await this.client.signAndExecuteTransaction({
|
|
78
|
+
signer,
|
|
79
|
+
transaction,
|
|
80
|
+
});
|
|
81
|
+
await this.client.waitForTransaction({ digest: tx.digest });
|
|
82
|
+
return {
|
|
83
|
+
order,
|
|
84
|
+
preparedData: {
|
|
85
|
+
transactionHash: tx.digest,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
throw new OrderCreationError('Failed to prepare Sui order', error);
|
|
91
|
+
}
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CAAC,yBAAyB,CAAC;gBACrD,MAAM;gBACN,WAAW;aACZ,CAAC,CAAC;YAEH,MAAM,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;YAE5D,OAAO;gBACL,KAAK;gBACL,YAAY,EAAE;oBACZ,eAAe,EAAE,EAAE,CAAC,MAAM;iBAC3B;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,kBAAkB,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isValidSuiAddress, normalizeSuiAddress } from '@mysten/sui/utils';
|
|
2
|
+
import { MAX_UINT_64 } from '../../constants.js';
|
|
3
|
+
import { BaseValidator } from '../../utils/base-validator.js';
|
|
4
|
+
const SUI_TOKEN_ADDRESS_REGEX = /^0x[a-fA-F0-9]{64}::\w+::\w+$/;
|
|
5
|
+
export class SuiValidator extends BaseValidator {
|
|
6
|
+
isValidAddress(address) {
|
|
7
|
+
return isValidSuiAddress(normalizeSuiAddress(address));
|
|
8
|
+
}
|
|
9
|
+
isValidTokenAddress(tokenAddress) {
|
|
10
|
+
const [address] = tokenAddress.split('::');
|
|
11
|
+
const isValidAddress = address !== undefined ? this.isValidAddress(address) : false;
|
|
12
|
+
return isValidAddress && SUI_TOKEN_ADDRESS_REGEX.test(tokenAddress);
|
|
13
|
+
}
|
|
14
|
+
isValidAmount(amount) {
|
|
15
|
+
return amount > 0n && amount < MAX_UINT_64;
|
|
16
|
+
}
|
|
17
|
+
getChainName() {
|
|
18
|
+
return 'Sui';
|
|
19
|
+
}
|
|
20
|
+
async chainSpecificValidation() {
|
|
21
|
+
// No chain-specific validation implemented for now for Sui
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../../../src/core/sui/validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,MAAM,uBAAuB,GAAG,+BAA+B,CAAC;AAEhE,MAAM,OAAO,YAAa,SAAQ,aAAa;IAC7C,cAAc,CAAC,OAAe;QAC5B,OAAO,iBAAiB,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,mBAAmB,CAAC,YAAoB;QACtC,MAAM,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAE3C,MAAM,cAAc,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAEpF,OAAO,cAAc,IAAI,uBAAuB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACtE,CAAC;IAED,aAAa,CAAC,MAAc;QAC1B,OAAO,MAAM,GAAG,EAAE,IAAI,MAAM,GAAG,WAAW,CAAC;IAC7C,CAAC;IAES,YAAY;QACpB,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,KAAK,CAAC,uBAAuB;QAClC,2DAA2D;QAC3D,OAAO;IACT,CAAC;CACF"}
|