Skip to content

Commit

Permalink
add _isSolana(.) function
Browse files Browse the repository at this point in the history
  • Loading branch information
magj2006 committed Oct 29, 2024
1 parent 27043e4 commit cd0eb2a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
6 changes: 2 additions & 4 deletions src/core/ExocoreGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions src/storage/ExocoreGatewayStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
36 changes: 15 additions & 21 deletions test/foundry/unit/ExocoreGateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -134,37 +134,31 @@ 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,
address(exocoreGateway),
solanaClientChainId,
address(solanaClientGateway).toBytes32()
);
} else {
uid = GUID.generate(
nonce, exocoreChainId, address(exocoreGateway), clientChainId, address(clientGateway).toBytes32()
);
}
}
}
Expand Down Expand Up @@ -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))),
Expand Down

0 comments on commit cd0eb2a

Please sign in to comment.