From 5c1bdb2ca0ddf6be46bcb017c516313073d35ae8 Mon Sep 17 00:00:00 2001 From: magj2006 Date: Mon, 28 Oct 2024 20:08:25 +0800 Subject: [PATCH 1/6] update executor options --- src/core/ExocoreGateway.sol | 51 +++++++++++++++++++++------ src/storage/ExocoreGatewayStorage.sol | 11 ++++++ 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/core/ExocoreGateway.sol b/src/core/ExocoreGateway.sol index 61f4b43b..089d7161 100644 --- a/src/core/ExocoreGateway.sol +++ b/src/core/ExocoreGateway.sol @@ -354,7 +354,11 @@ contract ExocoreGateway is } emit LSTTransfer(isDeposit, success, bytes32(token), bytes32(staker), amount); - response = isDeposit ? bytes("") : abi.encodePacked(lzNonce, success); + if (srcChainId == SOLANA_DEVNET_CHAIN_ID || srcChainId == SOLANA_MAINNET_CHAIN_ID) { + response = isDeposit ? bytes("") : abi.encodePacked(lzNonce, success, bytes32(token), bytes32(staker)); + } else { + response = isDeposit ? bytes("") : abi.encodePacked(lzNonce, success); + } } /// @notice Handles NST transfer from a client chain. @@ -419,7 +423,13 @@ contract ExocoreGateway is } emit RewardOperation(isSubmitReward, success, bytes32(token), bytes32(avsOrWithdrawer), amount); - response = isSubmitReward ? bytes("") : abi.encodePacked(lzNonce, success); + if (srcChainId == SOLANA_DEVNET_CHAIN_ID || srcChainId == SOLANA_MAINNET_CHAIN_ID) { + response = isSubmitReward + ? bytes("") + : abi.encodePacked(lzNonce, success, bytes32(token), bytes32(avsOrWithdrawer)); + } else { + response = isSubmitReward ? bytes("") : abi.encodePacked(lzNonce, success); + } } /// @notice Handles delegation request from a client chain. @@ -515,9 +525,18 @@ contract ExocoreGateway is whenNotPaused { bytes memory payload = abi.encodePacked(act, actionArgs); - bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption( - DESTINATION_GAS_LIMIT, DESTINATION_MSG_VALUE - ).addExecutorOrderedExecutionOption(); + bytes memory options = OptionsBuilder.newOptions(); + if (srcChainId == SOLANA_DEVNET_CHAIN_ID || srcChainId == SOLANA_MAINNET_CHAIN_ID) { + if (act == Action.REQUEST_ADD_WHITELIST_TOKEN) { + options = options.addExecutorLzReceiveOption(DESTINATION_GAS_LIMIT, SOLANA_MSG_VALUE); + } else { + options = options.addExecutorLzReceiveOption(DESTINATION_GAS_LIMIT, DESTINATION_MSG_VALUE); + } + } else { + options = options.addExecutorLzReceiveOption(DESTINATION_GAS_LIMIT, DESTINATION_MSG_VALUE) + .addExecutorOrderedExecutionOption(); + } + MessagingFee memory fee = _quote(srcChainId, payload, options, false); address refundAddress = payByApp ? address(this) : msg.sender; @@ -527,11 +546,23 @@ contract ExocoreGateway is } /// @inheritdoc IExocoreGateway - function quote(uint32 srcChainid, bytes calldata _message) public view returns (uint256 nativeFee) { - bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption( - DESTINATION_GAS_LIMIT, DESTINATION_MSG_VALUE - ).addExecutorOrderedExecutionOption(); - MessagingFee memory fee = _quote(srcChainid, _message, options, false); + function quote(uint32 srcChainId, bytes calldata _message) public view returns (uint256 nativeFee) { + bytes memory options = OptionsBuilder.newOptions(); + + if (srcChainId == SOLANA_DEVNET_CHAIN_ID || srcChainId == SOLANA_MAINNET_CHAIN_ID) { + Action act = Action(uint8(_message[0])); + + if (act == Action.REQUEST_ADD_WHITELIST_TOKEN) { + options = options.addExecutorLzReceiveOption(DESTINATION_GAS_LIMIT, SOLANA_MSG_VALUE); + } else { + options = options.addExecutorLzReceiveOption(DESTINATION_GAS_LIMIT, DESTINATION_MSG_VALUE); + } + } else { + options = options.addExecutorLzReceiveOption(DESTINATION_GAS_LIMIT, DESTINATION_MSG_VALUE) + .addExecutorOrderedExecutionOption(); + } + + MessagingFee memory fee = _quote(srcChainId, _message, options, false); return fee.nativeFee; } diff --git a/src/storage/ExocoreGatewayStorage.sol b/src/storage/ExocoreGatewayStorage.sol index 3c99f592..c836bc4d 100644 --- a/src/storage/ExocoreGatewayStorage.sol +++ b/src/storage/ExocoreGatewayStorage.sol @@ -19,6 +19,17 @@ contract ExocoreGatewayStorage is GatewayStorage { /// @dev The msg.value for all the destination chains. uint128 internal constant DESTINATION_MSG_VALUE = 0; + /// constants used for solana mainnet chainId + /// @dev the solana mainnet chain id + uint32 internal constant SOLANA_MAINNET_CHAIN_ID = 30_168; + + /// constants used for solana devnet chainId + /// @dev the solana devnet chain id + uint32 internal constant SOLANA_DEVNET_CHAIN_ID = 40_168; + + /// @dev the msg.value for send addTokenWhiteList message + uint128 internal constant SOLANA_MSG_VALUE = 3_000_000; + /// @notice Emitted when a precompile call fails. /// @param precompile Address of the precompile contract. /// @param nonce The LayerZero nonce From 8458152e6f7f30c2b20341d0d1086d0e0eb207b5 Mon Sep 17 00:00:00 2001 From: magj2006 Date: Mon, 28 Oct 2024 20:08:25 +0800 Subject: [PATCH 2/6] update executor options --- src/core/ExocoreGateway.sol | 50 +++++++++++++++++++++------ src/storage/ExocoreGatewayStorage.sol | 11 ++++++ 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/src/core/ExocoreGateway.sol b/src/core/ExocoreGateway.sol index 61f4b43b..7f8ab8eb 100644 --- a/src/core/ExocoreGateway.sol +++ b/src/core/ExocoreGateway.sol @@ -354,7 +354,11 @@ contract ExocoreGateway is } emit LSTTransfer(isDeposit, success, bytes32(token), bytes32(staker), amount); - response = isDeposit ? bytes("") : abi.encodePacked(lzNonce, success); + if (srcChainId == SOLANA_DEVNET_CHAIN_ID || srcChainId == SOLANA_MAINNET_CHAIN_ID) { + response = isDeposit ? bytes("") : abi.encodePacked(lzNonce, success, bytes32(token), bytes32(staker)); + } else { + response = isDeposit ? bytes("") : abi.encodePacked(lzNonce, success); + } } /// @notice Handles NST transfer from a client chain. @@ -419,7 +423,13 @@ contract ExocoreGateway is } emit RewardOperation(isSubmitReward, success, bytes32(token), bytes32(avsOrWithdrawer), amount); - response = isSubmitReward ? bytes("") : abi.encodePacked(lzNonce, success); + if (srcChainId == SOLANA_DEVNET_CHAIN_ID || srcChainId == SOLANA_MAINNET_CHAIN_ID) { + response = isSubmitReward + ? bytes("") + : abi.encodePacked(lzNonce, success, bytes32(token), bytes32(avsOrWithdrawer)); + } else { + response = isSubmitReward ? bytes("") : abi.encodePacked(lzNonce, success); + } } /// @notice Handles delegation request from a client chain. @@ -515,9 +525,8 @@ contract ExocoreGateway is whenNotPaused { bytes memory payload = abi.encodePacked(act, actionArgs); - bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption( - DESTINATION_GAS_LIMIT, DESTINATION_MSG_VALUE - ).addExecutorOrderedExecutionOption(); + bytes memory options = _buildOptions(srcChainId, act); + MessagingFee memory fee = _quote(srcChainId, payload, options, false); address refundAddress = payByApp ? address(this) : msg.sender; @@ -527,14 +536,35 @@ contract ExocoreGateway is } /// @inheritdoc IExocoreGateway - function quote(uint32 srcChainid, bytes calldata _message) public view returns (uint256 nativeFee) { - bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption( - DESTINATION_GAS_LIMIT, DESTINATION_MSG_VALUE - ).addExecutorOrderedExecutionOption(); - MessagingFee memory fee = _quote(srcChainid, _message, options, false); + function quote(uint32 srcChainId, bytes calldata _message) public view returns (uint256 nativeFee) { + Action act = Action(uint8(_message[0])); + bytes memory options = _buildOptions(srcChainId, act); + + MessagingFee memory fee = _quote(srcChainId, _message, options, false); return fee.nativeFee; } + /// @dev Builds options for interchain messages based on chain and action + /// @param srcChainId The source chain ID + /// @param act The action being performed + /// @return options The built options + function _buildOptions(uint32 srcChainId, Action act) private pure returns (bytes memory) { + bytes memory options = OptionsBuilder.newOptions(); + + if (srcChainId == SOLANA_DEVNET_CHAIN_ID || srcChainId == SOLANA_MAINNET_CHAIN_ID) { + if (act == Action.REQUEST_ADD_WHITELIST_TOKEN) { + options = options.addExecutorLzReceiveOption(DESTINATION_GAS_LIMIT, SOLANA_MSG_VALUE); + } else { + options = options.addExecutorLzReceiveOption(DESTINATION_GAS_LIMIT, DESTINATION_MSG_VALUE); + } + } else { + options = options.addExecutorLzReceiveOption(DESTINATION_GAS_LIMIT, DESTINATION_MSG_VALUE) + .addExecutorOrderedExecutionOption(); + } + + return options; + } + /// @inheritdoc OAppReceiverUpgradeable function nextNonce(uint32 srcEid, bytes32 sender) public diff --git a/src/storage/ExocoreGatewayStorage.sol b/src/storage/ExocoreGatewayStorage.sol index 3c99f592..c836bc4d 100644 --- a/src/storage/ExocoreGatewayStorage.sol +++ b/src/storage/ExocoreGatewayStorage.sol @@ -19,6 +19,17 @@ contract ExocoreGatewayStorage is GatewayStorage { /// @dev The msg.value for all the destination chains. uint128 internal constant DESTINATION_MSG_VALUE = 0; + /// constants used for solana mainnet chainId + /// @dev the solana mainnet chain id + uint32 internal constant SOLANA_MAINNET_CHAIN_ID = 30_168; + + /// constants used for solana devnet chainId + /// @dev the solana devnet chain id + uint32 internal constant SOLANA_DEVNET_CHAIN_ID = 40_168; + + /// @dev the msg.value for send addTokenWhiteList message + uint128 internal constant SOLANA_MSG_VALUE = 3_000_000; + /// @notice Emitted when a precompile call fails. /// @param precompile Address of the precompile contract. /// @param nonce The LayerZero nonce From 27043e4460631ac9d683b4edf02553f4ab516fa2 Mon Sep 17 00:00:00 2001 From: magj2006 Date: Tue, 29 Oct 2024 13:38:59 +0800 Subject: [PATCH 3/6] add test for solana client --- src/core/ExocoreGateway.sol | 20 ++++--- test/foundry/unit/ExocoreGateway.t.sol | 76 ++++++++++++++++++++++++-- 2 files changed, 81 insertions(+), 15 deletions(-) diff --git a/src/core/ExocoreGateway.sol b/src/core/ExocoreGateway.sol index 26e6ff1b..10625df4 100644 --- a/src/core/ExocoreGateway.sol +++ b/src/core/ExocoreGateway.sol @@ -553,17 +553,19 @@ contract ExocoreGateway is function _buildOptions(uint32 srcChainId, Action act) private pure returns (bytes memory) { bytes memory options = OptionsBuilder.newOptions(); - if (srcChainId == SOLANA_DEVNET_CHAIN_ID || srcChainId == SOLANA_MAINNET_CHAIN_ID) { - if (act == Action.REQUEST_ADD_WHITELIST_TOKEN) { - options = options.addExecutorLzReceiveOption(DESTINATION_GAS_LIMIT, SOLANA_WHITELIST_TOKEN_MSG_VALUE); - } else { - options = options.addExecutorLzReceiveOption(DESTINATION_GAS_LIMIT, DESTINATION_MSG_VALUE); - } - } else { - options = options.addExecutorLzReceiveOption(DESTINATION_GAS_LIMIT, DESTINATION_MSG_VALUE) - .addExecutorOrderedExecutionOption(); + bool isSolana = srcChainId == SOLANA_DEVNET_CHAIN_ID || srcChainId == SOLANA_MAINNET_CHAIN_ID; + + if (!isSolana) { + // currently, LZ does not support ordered execution for Solana + options = options.addExecutorOrderedExecutionOption(); } + uint128 value = isSolana && act == Action.REQUEST_ADD_WHITELIST_TOKEN + ? SOLANA_WHITELIST_TOKEN_MSG_VALUE + : DESTINATION_MSG_VALUE; + + options = options.addExecutorLzReceiveOption(DESTINATION_GAS_LIMIT, value); + return options; } diff --git a/test/foundry/unit/ExocoreGateway.t.sol b/test/foundry/unit/ExocoreGateway.t.sol index 3ad8eab2..be79d4db 100644 --- a/test/foundry/unit/ExocoreGateway.t.sol +++ b/test/foundry/unit/ExocoreGateway.t.sol @@ -39,12 +39,17 @@ contract SetUp is Test { ExocoreGateway exocoreGateway; ClientChainGateway clientGateway; + ClientChainGateway solanaClientGateway; + NonShortCircuitEndpointV2Mock exocoreLzEndpoint; NonShortCircuitEndpointV2Mock clientLzEndpoint; + NonShortCircuitEndpointV2Mock solanaClientLzEndpoint; + ERC20 restakeToken; uint16 exocoreChainId = 1; uint16 clientChainId = 2; + uint16 solanaClientChainId = 40_168; struct Player { uint256 privateKey; @@ -64,6 +69,7 @@ contract SetUp is Test { deployer = Player({privateKey: uint256(0xb), addr: vm.addr(uint256(0xb))}); withdrawer = Player({privateKey: uint256(0xc), addr: vm.addr(uint256(0xb))}); clientGateway = ClientChainGateway(payable(address(0xd))); + solanaClientGateway = ClientChainGateway(payable(address(0xe))); // bind precompile mock contracts code to constant precompile address bytes memory AssetsMockCode = vm.getDeployedCode("AssetsMock.sol"); @@ -88,6 +94,7 @@ contract SetUp is Test { exocoreLzEndpoint = new NonShortCircuitEndpointV2Mock(exocoreChainId, exocoreValidatorSet.addr); clientLzEndpoint = new NonShortCircuitEndpointV2Mock(clientChainId, exocoreValidatorSet.addr); + solanaClientLzEndpoint = new NonShortCircuitEndpointV2Mock(solanaClientChainId, exocoreValidatorSet.addr); ProxyAdmin proxyAdmin = new ProxyAdmin(); ExocoreGateway exocoreGatewayLogic = new ExocoreGateway(address(exocoreLzEndpoint)); @@ -108,6 +115,17 @@ contract SetUp is Test { "EVM compatible client chain", "secp256k1" ); + + exocoreLzEndpoint.setDestLzEndpoint(address(solanaClientGateway), address(clientLzEndpoint)); + exocoreGateway.registerOrUpdateClientChain( + solanaClientChainId, + address(solanaClientGateway).toBytes32(), + 20, + "solanaClientChain", + "Non-EVM compatible client chain", + "ed25519" + ); + vm.stopPrank(); // transfer some gas fee to exocore gateway as it has to pay for the relay fee to layerzero endpoint when @@ -116,14 +134,38 @@ contract SetUp is Test { } function generateUID(uint64 nonce, bool fromClientChainToExocore) internal view returns (bytes32 uid) { + uid = generateUID(nonce, fromClientChainToExocore, true); + } + + function generateUID(uint64 nonce, bool fromClientChainToExocore, bool isEVM) internal view returns (bytes32 uid) { if (fromClientChainToExocore) { - uid = GUID.generate( - nonce, clientChainId, address(clientGateway), exocoreChainId, address(exocoreGateway).toBytes32() - ); + if (isEVM) { + uid = GUID.generate( + nonce, clientChainId, address(clientGateway), exocoreChainId, address(exocoreGateway).toBytes32() + ); + } else { + uid = GUID.generate( + nonce, + solanaClientChainId, + address(solanaClientGateway), + exocoreChainId, + address(exocoreGateway).toBytes32() + ); + } } else { - uid = GUID.generate( - nonce, exocoreChainId, address(exocoreGateway), clientChainId, address(clientGateway).toBytes32() - ); + if (isEVM) { + uid = GUID.generate( + nonce, exocoreChainId, address(exocoreGateway), clientChainId, address(clientGateway).toBytes32() + ); + } else { + uid = GUID.generate( + nonce, + exocoreChainId, + address(exocoreGateway), + solanaClientChainId, + address(solanaClientGateway).toBytes32() + ); + } } } @@ -526,6 +568,7 @@ contract AddWhitelistTokens is SetUp { uint256 MESSAGE_LENGTH = 1 + 32 + 16; // action + token address as bytes32 + uint128 tvl limit uint256 nativeFee; + uint256 nativeFeeForSolana; error IncorrectNativeFee(uint256 amount); @@ -534,6 +577,9 @@ contract AddWhitelistTokens is SetUp { function setUp() public virtual override { super.setUp(); nativeFee = exocoreGateway.quote(clientChainId, new bytes(MESSAGE_LENGTH)); + bytes memory message = new bytes(MESSAGE_LENGTH); + message[0] = bytes1(abi.encodePacked(Action.REQUEST_ADD_WHITELIST_TOKEN)); + nativeFeeForSolana = exocoreGateway.quote(solanaClientChainId, message); } function test_RevertWhen_CallerNotOwner() public { @@ -587,6 +633,24 @@ contract AddWhitelistTokens is SetUp { vm.stopPrank(); } + function test_Success_AddWhiteListTokenOnSolana() public { + vm.startPrank(exocoreValidatorSet.addr); + vm.expectEmit(address(exocoreGateway)); + emit WhitelistTokenAdded(solanaClientChainId, bytes32(bytes20(address(restakeToken)))); + vm.expectEmit(address(exocoreGateway)); + emit MessageSent(Action.REQUEST_ADD_WHITELIST_TOKEN, generateUID(1, false, false), 1, nativeFeeForSolana); + exocoreGateway.addWhitelistToken{value: nativeFeeForSolana}( + solanaClientChainId, + bytes32(bytes20(address(restakeToken))), + 9, + "RestakeToken", + "Spl LST token", + "oracleInfo", + 5000 * 1e9 + ); + vm.stopPrank(); + } + } contract UpdateWhitelistTokens is SetUp { From cd0eb2a8b92c77e16291ea2dfbe51a4bdd2253cb Mon Sep 17 00:00:00 2001 From: magj2006 Date: Tue, 29 Oct 2024 17:46:13 +0800 Subject: [PATCH 4/6] add _isSolana(.) function --- src/core/ExocoreGateway.sol | 6 ++--- src/storage/ExocoreGatewayStorage.sol | 8 ++++++ test/foundry/unit/ExocoreGateway.t.sol | 36 +++++++++++--------------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/core/ExocoreGateway.sol b/src/core/ExocoreGateway.sol index 10625df4..36e35421 100644 --- a/src/core/ExocoreGateway.sol +++ b/src/core/ExocoreGateway.sol @@ -553,14 +553,12 @@ contract ExocoreGateway is function _buildOptions(uint32 srcChainId, Action act) private pure returns (bytes memory) { bytes memory options = OptionsBuilder.newOptions(); - bool isSolana = srcChainId == SOLANA_DEVNET_CHAIN_ID || srcChainId == SOLANA_MAINNET_CHAIN_ID; - - if (!isSolana) { + if (!_isSolana(srcChainId)) { // currently, LZ does not support ordered execution for Solana options = options.addExecutorOrderedExecutionOption(); } - uint128 value = isSolana && act == Action.REQUEST_ADD_WHITELIST_TOKEN + uint128 value = _isSolana(srcChainId) && act == Action.REQUEST_ADD_WHITELIST_TOKEN ? SOLANA_WHITELIST_TOKEN_MSG_VALUE : DESTINATION_MSG_VALUE; diff --git a/src/storage/ExocoreGatewayStorage.sol b/src/storage/ExocoreGatewayStorage.sol index 2aff2695..614c9c72 100644 --- a/src/storage/ExocoreGatewayStorage.sol +++ b/src/storage/ExocoreGatewayStorage.sol @@ -139,4 +139,12 @@ contract ExocoreGatewayStorage is GatewayStorage { } } + /** + * @dev return true if chain is either Solana devnet or Solana mainnet + * @param srcChainId remote Chain Id + */ + function _isSolana(uint32 srcChainId) internal pure returns (bool) { + return srcChainId == SOLANA_DEVNET_CHAIN_ID || srcChainId == SOLANA_MAINNET_CHAIN_ID; + } + } diff --git a/test/foundry/unit/ExocoreGateway.t.sol b/test/foundry/unit/ExocoreGateway.t.sol index be79d4db..cc3d155b 100644 --- a/test/foundry/unit/ExocoreGateway.t.sol +++ b/test/foundry/unit/ExocoreGateway.t.sol @@ -134,30 +134,20 @@ contract SetUp is Test { } function generateUID(uint64 nonce, bool fromClientChainToExocore) internal view returns (bytes32 uid) { - uid = generateUID(nonce, fromClientChainToExocore, true); + uid = generateUID(nonce, fromClientChainToExocore, false); } - function generateUID(uint64 nonce, bool fromClientChainToExocore, bool isEVM) internal view returns (bytes32 uid) { + function generateUID(uint64 nonce, bool fromClientChainToExocore, bool isSolanaClient) + internal + view + returns (bytes32 uid) + { if (fromClientChainToExocore) { - if (isEVM) { - uid = GUID.generate( - nonce, clientChainId, address(clientGateway), exocoreChainId, address(exocoreGateway).toBytes32() - ); - } else { - uid = GUID.generate( - nonce, - solanaClientChainId, - address(solanaClientGateway), - exocoreChainId, - address(exocoreGateway).toBytes32() - ); - } + uid = GUID.generate( + nonce, clientChainId, address(clientGateway), exocoreChainId, address(exocoreGateway).toBytes32() + ); } else { - if (isEVM) { - uid = GUID.generate( - nonce, exocoreChainId, address(exocoreGateway), clientChainId, address(clientGateway).toBytes32() - ); - } else { + if (isSolanaClient) { uid = GUID.generate( nonce, exocoreChainId, @@ -165,6 +155,10 @@ contract SetUp is Test { solanaClientChainId, address(solanaClientGateway).toBytes32() ); + } else { + uid = GUID.generate( + nonce, exocoreChainId, address(exocoreGateway), clientChainId, address(clientGateway).toBytes32() + ); } } } @@ -638,7 +632,7 @@ contract AddWhitelistTokens is SetUp { vm.expectEmit(address(exocoreGateway)); emit WhitelistTokenAdded(solanaClientChainId, bytes32(bytes20(address(restakeToken)))); vm.expectEmit(address(exocoreGateway)); - emit MessageSent(Action.REQUEST_ADD_WHITELIST_TOKEN, generateUID(1, false, false), 1, nativeFeeForSolana); + emit MessageSent(Action.REQUEST_ADD_WHITELIST_TOKEN, generateUID(1, false, true), 1, nativeFeeForSolana); exocoreGateway.addWhitelistToken{value: nativeFeeForSolana}( solanaClientChainId, bytes32(bytes20(address(restakeToken))), From b992561f4048a9b7cdae9b608924eaa6a337f7c8 Mon Sep 17 00:00:00 2001 From: magj2006 Date: Tue, 29 Oct 2024 17:46:13 +0800 Subject: [PATCH 5/6] simplifying the generateUID function --- src/core/ExocoreGateway.sol | 4 ++-- test/foundry/unit/ExocoreGateway.t.sol | 18 +++++------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/core/ExocoreGateway.sol b/src/core/ExocoreGateway.sol index 36e35421..23883515 100644 --- a/src/core/ExocoreGateway.sol +++ b/src/core/ExocoreGateway.sol @@ -354,7 +354,7 @@ contract ExocoreGateway is } emit LSTTransfer(isDeposit, success, bytes32(token), bytes32(staker), amount); - if (srcChainId == SOLANA_DEVNET_CHAIN_ID || srcChainId == SOLANA_MAINNET_CHAIN_ID) { + if (_isSolana(srcChainId)) { response = isDeposit ? bytes("") : abi.encodePacked(lzNonce, success, bytes32(token), bytes32(staker)); } else { response = isDeposit ? bytes("") : abi.encodePacked(lzNonce, success); @@ -423,7 +423,7 @@ contract ExocoreGateway is } emit RewardOperation(isSubmitReward, success, bytes32(token), bytes32(avsOrWithdrawer), amount); - if (srcChainId == SOLANA_DEVNET_CHAIN_ID || srcChainId == SOLANA_MAINNET_CHAIN_ID) { + if (_isSolana(srcChainId)) { response = isSubmitReward ? bytes("") : abi.encodePacked(lzNonce, success, bytes32(token), bytes32(avsOrWithdrawer)); diff --git a/test/foundry/unit/ExocoreGateway.t.sol b/test/foundry/unit/ExocoreGateway.t.sol index cc3d155b..bc2d8d07 100644 --- a/test/foundry/unit/ExocoreGateway.t.sol +++ b/test/foundry/unit/ExocoreGateway.t.sol @@ -147,19 +147,11 @@ contract SetUp is Test { nonce, clientChainId, address(clientGateway), exocoreChainId, address(exocoreGateway).toBytes32() ); } else { - if (isSolanaClient) { - uid = GUID.generate( - nonce, - exocoreChainId, - address(exocoreGateway), - solanaClientChainId, - address(solanaClientGateway).toBytes32() - ); - } else { - uid = GUID.generate( - nonce, exocoreChainId, address(exocoreGateway), clientChainId, address(clientGateway).toBytes32() - ); - } + uint16 targetChainId = isSolanaClient ? solanaClientChainId : clientChainId; + bytes32 targetGateway = + isSolanaClient ? address(solanaClientGateway).toBytes32() : address(clientGateway).toBytes32(); + + return GUID.generate(nonce, exocoreChainId, address(exocoreGateway), targetChainId, targetGateway); } } From f5fbb8650983534ca1219429c08e2fed672ad864 Mon Sep 17 00:00:00 2001 From: magj2006 Date: Tue, 29 Oct 2024 17:46:13 +0800 Subject: [PATCH 6/6] simplifying the _buildOptions function --- src/core/ExocoreGateway.sol | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core/ExocoreGateway.sol b/src/core/ExocoreGateway.sol index 23883515..99058203 100644 --- a/src/core/ExocoreGateway.sol +++ b/src/core/ExocoreGateway.sol @@ -552,16 +552,14 @@ contract ExocoreGateway is /// @return options The built options function _buildOptions(uint32 srcChainId, Action act) private pure returns (bytes memory) { bytes memory options = OptionsBuilder.newOptions(); + uint128 value = DESTINATION_MSG_VALUE; if (!_isSolana(srcChainId)) { - // currently, LZ does not support ordered execution for Solana options = options.addExecutorOrderedExecutionOption(); + } else if (act == Action.REQUEST_ADD_WHITELIST_TOKEN) { + value = SOLANA_WHITELIST_TOKEN_MSG_VALUE; } - uint128 value = _isSolana(srcChainId) && act == Action.REQUEST_ADD_WHITELIST_TOKEN - ? SOLANA_WHITELIST_TOKEN_MSG_VALUE - : DESTINATION_MSG_VALUE; - options = options.addExecutorLzReceiveOption(DESTINATION_GAS_LIMIT, value); return options;