I am using OpenZeppelin governor contract through which I want to pass an encoded function to the vault smart contract function:
function submitTransaction(address _owner, address _to, uint _txIndex, uint _value, bytes memory _data) public onlyGovernance {
require(hasRole(CUSTODIAN_ROLE, _owner), "only custodians can submit transaction!");
transactions.push(Transaction({
to: _to,
value: _value,
data: _data,
daoApproval: true,
executed: false,
numConfirmatons: 0
}));
emit SubmitTransaction(msg.sender, _txIndex, _to, _value, _data);
}
function executeTransaction(uint _txIndex) public onlyCustodian txExists(_txIndex) notExecuted(_txIndex) {
Transaction storage transaction = transactions[_txIndex];
require(transaction.numConfirmatons >= numConfirmationsRequired, "cannot execute tx");
require(transaction.daoApproval == true, "transaction not approved by DAO");
transaction.executed = true;
(bool success, ) = transaction.to.call{value: transaction.value}(transaction.data);
require(success, "tx failed");
transaction.daoApproval = false;
emit ExecuteTransaction(msg.sender, _txIndex);
}
function transferTokens(address _to, uint _amount) internal {
require(_amount <= address(this).balance, "amount execceds the available balance");
tokenAddress.transfer(_to, _amount);
}
I have a script to generate encodedFunctions:
const vault = await ethers.getContract("Vault")
const _amount = ethers.parseEther("10000");
const encodedFunctionTransfer = vault.interface.encodeFunctionData(TRANSFER_TOKENS_FUNCTION, [GAURAV_ADDRESS, _amount]);
const encodedSubmitFunctionCall = vault.interface.encodeFunctionData(SUBMIT_TRANSACTION_FUNCTION, [SAGAR_ADDRESS, GAURAV_ADDRESS, SUBMIT_TRANSACTION_ID, WITHDRAW_AMOUNT,encodedFunctionTransfer]);
Here are the constants:
export const SAGAR_ADDRESS = "0x3124475af0ba367fFf33a5DC9BcE78c41f493713"
export const GAURAV_ADDRESS = "0x7032576BCF4a7fc07d083F3c6b1f320a75B17959"
export const SUBMIT_TRANSACTION_FUNCTION = "submitTransaction";
export const TRANSFER_TOKENS_FUNCTION = "transferTokens";
export const WITHDRAW_AMOUNT = 1000;