SimpleApprovalWorkflow

Git Source

Basic approval workflow for entity wallets

Supports role-based approvals and executive limits without complex governance

State Variables

companyName

string public companyName;

entityWallet

address public entityWallet;

approvalRules

mapping(bytes4 => ApprovalRule) public approvalRules;

approvers

mapping(address => Approver) public approvers;

approverList

address[] public approverList;

pendingApprovals

mapping(uint256 => PendingApproval) public pendingApprovals;

nextApprovalId

uint256 public nextApprovalId;

requireDualApproval

bool public requireDualApproval;

defaultTimelock

uint256 public defaultTimelock;

approvalExpiry

uint256 public approvalExpiry;

Functions

constructor

constructor(address _entityWallet, string memory _companyName, bool _requireDualApproval);

requestApproval

Request approval for a transaction

function requestApproval(address target, bytes calldata data, uint256 value) external returns (uint256 approvalId);

Parameters

Name
Type
Description

target

address

Address to call

data

bytes

Transaction data

value

uint256

Transaction value

Returns

Name
Type
Description

approvalId

uint256

ID of the approval request

grantApproval

Grant approval for a pending transaction

function grantApproval(uint256 approvalId) external;

Parameters

Name
Type
Description

approvalId

uint256

ID of the approval to approve

executeApproval

Execute an approved transaction

function executeApproval(uint256 approvalId) external;

Parameters

Name
Type
Description

approvalId

uint256

ID of the approval to execute

addApprover

Add a new approver

function addApprover(address approver, string memory name, string memory role, uint256 individualLimit) external;

Parameters

Name
Type
Description

approver

address

Address of the approver

name

string

Display name

role

string

Role (CEO, CFO, etc.)

individualLimit

uint256

Amount they can approve alone

removeApprover

Remove an approver

function removeApprover(address approver) external;

Parameters

Name
Type
Description

approver

address

Address to remove

setApprovalRule

Update approval rule for a transaction type

function setApprovalRule(bytes4 selector, uint256 maxAmount, uint256 requiredCount, uint256 timelock) external;

Parameters

Name
Type
Description

selector

bytes4

Function selector

maxAmount

uint256

Maximum amount for this rule

requiredCount

uint256

Number of approvals required

timelock

uint256

Timelock in seconds

getApprovalStatus

Get approval status for a pending transaction

function getApprovalStatus(uint256 approvalId)
    external
    view
    returns (PendingApproval memory approval, bool canExecute);

Parameters

Name
Type
Description

approvalId

uint256

ID of the approval

Returns

Name
Type
Description

approval

PendingApproval

The approval details

canExecute

bool

Whether it can be executed now

getActiveApprovers

Get all active approvers

function getActiveApprovers() external view returns (address[] memory addresses, Approver[] memory details);

Returns

Name
Type
Description

addresses

address[]

Array of active approver addresses

details

Approver[]

Array of approver details

_executeImmediately

function _executeImmediately(address target, bytes calldata data, uint256 value)
    internal
    returns (uint256 approvalId);

_executeApproval

function _executeApproval(uint256 approvalId) internal;

_getRequiredApprovals

function _getRequiredApprovals(PendingApproval memory approval) internal view returns (uint256);

_getActiveApprovers

function _getActiveApprovers() internal view returns (address[] memory);

_isAdmin

function _isAdmin(address account) internal view returns (bool);

_setDefaultApprovalRules

function _setDefaultApprovalRules() internal;

Events

ApprovalRequested

event ApprovalRequested(
    uint256 indexed approvalId, address indexed requester, address indexed target, uint256 value, bytes4 selector
);

ApprovalGranted

event ApprovalGranted(
    uint256 indexed approvalId, address indexed approver, uint256 approvalsCount, uint256 requiredCount
);

TransactionExecuted

event TransactionExecuted(uint256 indexed approvalId, address indexed executor, bool success);

ApproverAdded

event ApproverAdded(address indexed approver, string role, uint256 individualLimit);

ApproverRemoved

event ApproverRemoved(address indexed approver);

ApprovalRuleUpdated

event ApprovalRuleUpdated(bytes4 indexed selector, uint256 maxAmount, uint256 requiredCount);

Errors

UnauthorizedApprover

error UnauthorizedApprover();

InsufficientApprovals

error InsufficientApprovals();

ApprovalExpired

error ApprovalExpired();

ApprovalAlreadyExecuted

error ApprovalAlreadyExecuted();

ExceedsIndividualLimit

error ExceedsIndividualLimit();

InvalidApprovalRule

error InvalidApprovalRule();

DuplicateApproval

error DuplicateApproval();

Structs

ApprovalRule

struct ApprovalRule {
    uint256 maxAmount;
    address[] requiredApprovers;
    uint256 requiredCount;
    uint256 timelock;
}

PendingApproval

struct PendingApproval {
    address wallet;
    address target;
    bytes data;
    uint256 value;
    address requester;
    uint256 requestTime;
    address[] approvers;
    bool executed;
    uint256 expiryTime;
}

Approver

struct Approver {
    string name;
    string role;
    uint256 individualLimit;
    bool isActive;
}

Last updated

Was this helpful?