Multiple VoteExecutor contracts on different chains
Executing votes on multiple chains
As described in previous sections, once the data is submitted and approved on Ethereum Mainnet, there are actions that must occur on other chains - such as Polygon.
We have satellite contracts that receive data through cross chain messaging, which then execute what is necessary.
At the end of executeSpecificData, there is an AnyCall (Multichain Crosschain Messaging) to the next executor in the list (on a different chain such as Polygon).
Then the satellite 'slave' contract on a different chain receives the call
VoteExecutorSlave.sol
/// @notice Receives SMPC call from Multichain and executes command after security checks/// @dev Format of function name and return params are necessary (see docs: https://docs.multichain.org/developer-guide/anycall/anycall-v6/how-to-integrate-anycall-v6)
// Carry out two security checks:// 1.) Confirm that the hash has been signed by the multisig // 2.) Confirm that anyCall has been triggered by our VoteExecutorMaster contract/// @param _data Data sent through by SMPC/// @return success Required by Multichain/// @return result Required by MultichainfunctionanyExecute(bytesmemory_data) externalreturns (bool success,bytesmemory result) { (bytesmemory message,bytes[] memory signs) = abi.decode(_data, (bytes,bytes[])); (bytes32 hashed, Message[] memory _messages, uint256 timestamp) = abi.decode(message, (bytes32, Message[], uint256));
require(hashed ==keccak256(abi.encode(_messages, timestamp)),"Hash doesn't match");require(_checkSignedHashes(signs, hashed),"Hash has not been approved"); require(IAnyCallExecutor(messagingInfo.anyCallExecutor).context().from == voteExecutorMaster, "Origin of message invalid");
require(hashExecutionTime[hashed] ==0,"Duplicate hash" );execute(_messages); executionHistory.push(_data); hashExecutionTime[hashed] = block.timestamp;if (messagingInfo.nextChain !=0) { IAnyCall(messagingInfo.anyCallAddress).anyCall(messagingInfo.nextChainExecutor, _data, address(0), messagingInfo.nextChain, 0);
} success=true; result="";emitMessageReceived(hashed);}
This contract carries out a couple security checks:
That the data is correctly parseable
That the Multichain call has indeed originated from our contract (check through Multichain contracts for legitimacy)
That the data has indeed been approved by the DAO multisig (to confirm that cross chain messaging has not been malicious)
This ensures that the data has not been manipulated on transit between chains.
Then, analagous to how execution for data works on the main chain, the VoteExecutorSlave executes the data necessary for the current chain (Polygon for example).
Executing
/// @notice Executes all messages received after authentication/// @dev Loops through each command in the array and executes it./// @param _messages Array of messagesfunctionexecute(Message[] memory_messages) internal {for (uint256 i; i < _messages.length; i++) { Message memory currentMessage = _messages[i];if (currentMessage.commandIndex ==0) { (string memory ibAlluoSymbol, uint256 newAnnualInterest, uint256 newInterestPerSecond) = abi.decode(currentMessage.commandData, (string, uint256, uint256));
_changeAPY(newAnnualInterest, newInterestPerSecond, ibAlluoSymbol); }elseif(currentMessage.commandIndex ==2) {// Handle all withdrawals first and then add all deposit actions to an array to be executed afterwards (address strategyAddress, uint256 delta, uint256 chainId, address strategyPrimaryToken, address exitToken, bytes memory data) = abi.decode(currentMessage.commandData, (address, uint256, uint256, address,address, bytes));
if (chainId == generalBridgingInfo.currentChain) {IAlluoStrategy(strategyAddress).exitAll(data, delta, strategyPrimaryToken,address(this),false); } }elseif(currentMessage.commandIndex ==3) {// Add all deposits to the queue. (address strategyAddress, uint256 delta, uint256 chainId, address strategyPrimaryToken, address entryToken, bytes memory data) = abi.decode(currentMessage.commandData, (address, uint256, uint256, address,address, bytes));
if (chainId == generalBridgingInfo.currentChain) { console.log("Deposit added", strategyAddress, delta); tokenToDepositQueue[strategyPrimaryToken].depositList.push(Deposit(strategyAddress, delta, strategyPrimaryToken, entryToken, data));
} } }ataa}