Solidity API
Wrap
PAUSE_ROLE
bytes32 PAUSE_ROLE
The role ID for addresses that can pause the contract.
WEAK_ADMIN_ROLE
bytes32 WEAK_ADMIN_ROLE
The role ID for addresses that has weak admin power. Weak admin can perform administrative tasks that don't risk user's funds.
maxFeeBPS
uint16 maxFeeBPS
Max protocol/validator fee that can be set by the owner.
paused
bool paused
True if the contracts are paused, false otherwise.
tokenInfos
mapping(address => struct IWrap.TokenInfoStore) tokenInfos
Map token address to token info.
mirrorTokens
mapping(address => address) mirrorTokens
Map mirror token address to token address.
validatorFeeRecipients
mapping(address => address) validatorFeeRecipients
Map validator to its fee recipient.
feeBalance
mapping(address => mapping(uint256 => uint256)) feeBalance
Map tokens to validator index to fee that can be collected.
tokens
address[] tokens
A token in the list might not be active.
Array of all the tokens added.
multisig
struct Multisig.DualMultisig multisig
Dual multisig to manage validators, attestations and request quorum.
depositIndex
uint256 depositIndex
The number of deposits.
validatorFeeBPS
uint16 validatorFeeBPS
Validator fee basis points.
migratedContract
address migratedContract
Address of the migrated contract.
constructor
constructor(struct Multisig.Config config, uint16 _validatorFeeBPS) internal
onDeposit
function onDeposit(address token, uint256 amount) internal virtual returns (uint256 fee)
Hook to execute on deposit.
Parameters
Name | Type | Description |
---|---|---|
token | address | Address of the token being deposited. |
amount | uint256 | The amount being deposited. |
Return Values
Name | Type | Description |
---|---|---|
fee | uint256 | The fee charged to the depositor. |
onExecute
function onExecute(address token, uint256 amount, address to) internal virtual returns (uint256 totalFee, uint256 validatorFee)
Hook to execute on successful bridging.
Parameters
Name | Type | Description |
---|---|---|
token | address | Address of the token being bridged. |
amount | uint256 | The amount being bridged. |
to | address | The address where the bridged are being sent to. |
Return Values
Name | Type | Description |
---|---|---|
totalFee | uint256 | Total fee charged to the user. |
validatorFee | uint256 | Total fee minus the protocol fees. |
onMigrate
function onMigrate(address _newContract) internal virtual
Hook executed before the bridge migration.
Parameters
Name | Type | Description |
---|---|---|
_newContract | address | Address of the new contract. |
isNotPaused
modifier isNotPaused()
Modifier to check if the contract is not paused.
isPaused
modifier isPaused()
Modifier to check if the contract is paused.
notMigrated
modifier notMigrated()
Modifier to check that contract is not already migrated.
isValidTokenAmount
modifier isValidTokenAmount(address token, uint256 amount)
Modifier to make a function callable only when the token and amount is correct.
withValidRecentBlockHash
modifier withValidRecentBlockHash(bytes32 recentBlockHash, uint256 recentBlockNumber)
Modifier to make a function callable only when the recent block hash is valid.
nextExecutionIndex
function nextExecutionIndex() external view returns (uint256)
Returns the index of the request that will be executed next.
validatorInfo
function validatorInfo(address validator) external view returns (struct Multisig.SignerInfo)
Returns info about a given validator.
attesters
function attesters(bytes32 hash) external view returns (uint16[] attesterIndexes, uint16 count)
Returns the number of attesters and their indeces for a given request hash.
calculateFee
function calculateFee(uint256 amount, uint16 feeBPS) internal pure returns (uint256)
Internal function to calculate fees by amount and BPS.
deposit
function deposit(address token, uint256 amount, address to) external returns (uint256 id)
Deposit tokens to bridge to the other side.
Parameters
Name | Type | Description |
---|---|---|
token | address | Token being deposited. |
amount | uint256 | Amount of tokens being deposited. |
to | address | Address to release the tokens to on the other side. |
Return Values
Name | Type | Description |
---|---|---|
id | uint256 | The ID associated to the request. |
hashRequest
function hashRequest(uint256 id, address token, uint256 amount, address to) internal pure returns (bytes32)
Internal function to calculate the hash of the request.
_approveExecute
function _approveExecute(uint256 id, address mirrorToken, uint256 amount, address to) private
Internal function to approve and/or execute a given request.
approveExecute
function approveExecute(uint256 id, address mirrorToken, uint256 amount, address to, bytes32 recentBlockHash, uint256 recentBlockNumber) external
Approve and/or execute a given request.
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | ID associated with the request. |
mirrorToken | address | |
amount | uint256 | Amount of tokens requested. |
to | address | Address to release the funds to. |
recentBlockHash | bytes32 | |
recentBlockNumber | uint256 |
batchApproveExecute
function batchApproveExecute(struct IWrap.RequestInfo[] requests, bytes32 recentBlockHash, uint256 recentBlockNumber) external
Approve and/or execute requests.
Parameters
Name | Type | Description |
---|---|---|
requests | struct IWrap.RequestInfo[] | Requests to approve and/or execute. |
recentBlockHash | bytes32 | |
recentBlockNumber | uint256 |
_configureTokenInfo
function _configureTokenInfo(address token, uint256 minAmount, uint256 maxAmount, uint256 dailyLimit, bool newToken) internal
configureToken
function configureToken(address token, struct IWrap.TokenInfo tokenInfo) external
Set maxAmount to zero to disable the token. Can only be called by the weak-admin.
Update a token's configuration information.
Parameters
Name | Type | Description |
---|---|---|
token | address | |
tokenInfo | struct IWrap.TokenInfo | The token's new configuration info. |
configureValidatorFees
function configureValidatorFees(uint16 _validatorFeeBPS) public
Can only be called by the weak-admin.
Configure validator fees.
Parameters
Name | Type | Description |
---|---|---|
_validatorFeeBPS | uint16 |
_addToken
function _addToken(address token, address mirrorToken, struct IWrap.TokenInfo tokenInfo) internal
Internal function to add a new token.
Parameters
Name | Type | Description |
---|---|---|
token | address | Token that will be deposited in the contract. |
mirrorToken | address | Token that will be deposited in the mirror contract. |
tokenInfo | struct IWrap.TokenInfo | Token info associated with the token. |
configureMultisig
function configureMultisig(struct Multisig.Config config) external
Can only be called by the admin.
Set the multisig configuration.
Parameters
Name | Type | Description |
---|---|---|
config | struct Multisig.Config | Multisig config. |
pause
function pause() external
The contract can be paused by all addresses with pause role but can only be unpaused by the weak-admin.
Pauses the contract.
unpause
function unpause() external
The contract can be paused by all addresses with pause role but can only be unpaused by the weak-admin.
Unpauses the contract.
addValidator
function addValidator(address validator, bool isFirstCommittee, address feeRecipient) external
Can only be called by the admin.
Add a new validator to the contract.
Parameters
Name | Type | Description |
---|---|---|
validator | address | Address of the validator. |
isFirstCommittee | bool | True when adding the validator to the first committee. |
feeRecipient | address | Address of the fee recipient. false when adding the validator to the second committee. |
removeValidator
function removeValidator(address validator) external
Can only be called by the weak-admin. The fees accumulated by the validator are distributed before being removed.
Remove existing validator from the contract.
Parameters
Name | Type | Description |
---|---|---|
validator | address | Address of the validator. |
configureValidatorFeeRecipient
function configureValidatorFeeRecipient(address validator, address feeRecipient) external
Change fee recipient for a validator.
Parameters
Name | Type | Description |
---|---|---|
validator | address | Address of the validator. |
feeRecipient | address | Address of the new fee recipient. |
claimValidatorFees
function claimValidatorFees(address validator) public
Can be triggered by anyone but the fee is transfered to the set feeRecepient for the validator.
Allows to claim accumulated fees for a validator.
Parameters
Name | Type | Description |
---|---|---|
validator | address | Address of the validator. |
forceSetNextExecutionIndex
function forceSetNextExecutionIndex(uint256 index) public
Can only be called by the admin of the contract.
Forcefully set next next execution index.
Parameters
Name | Type | Description |
---|---|---|
index | uint256 | The new next execution index. |
migrate
function migrate(address _newContract) public
This function can only be called once in the lifetime of this contract by the admin.
Migrates the contract to a new address.
Parameters
Name | Type | Description |
---|---|---|
_newContract | address | Address of the new contract. |
WrapDepositRedeem
constructor
constructor(struct Multisig.Config config, uint16 _validatorFeeBPS) public
depositFees
function depositFees(uint256) internal pure returns (uint256 fee)
Internal function to calculate the deposit fees.
onDeposit
function onDeposit(address token, uint256 amount) internal virtual returns (uint256)
Hook to execute on deposit.
Parameters
Name | Type | Description |
---|---|---|
token | address | Address of the token being deposited. |
amount | uint256 | The amount being deposited. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 |
onExecute
function onExecute(address token, uint256 amount, address to) internal virtual returns (uint256 totalFee, uint256 validatorFee)
Hook to execute on successful bridging.
Parameters
Name | Type | Description |
---|---|---|
token | address | Address of the token being bridged. |
amount | uint256 | The amount being bridged. |
to | address | The address where the bridged are being sent to. |
Return Values
Name | Type | Description |
---|---|---|
totalFee | uint256 | Total fee charged to the user. |
validatorFee | uint256 | Total fee minus the protocol fees. |
onMigrate
function onMigrate(address _newContract) internal
Hook executed before the bridge migration.
Parameters
Name | Type | Description |
---|---|---|
_newContract | address | Address of the new contract. |
addToken
function addToken(address token, address mirrorToken, struct IWrap.TokenInfo tokenInfo) external
Set maxAmount to zero to disable the token. Can only be called by the weak-admin.
Allowlist a new token.
Parameters
Name | Type | Description |
---|---|---|
token | address | Address of the token that will be allowlisted. |
mirrorToken | address | Address of the token that will be minted on the other side. |
tokenInfo | struct IWrap.TokenInfo | Information associated with the token. |
WrapMintBurn
accumulatedProtocolFees
mapping(address => uint256) accumulatedProtocolFees
Map token address to accumulated protocol fees.
protocolFeeBPS
uint16 protocolFeeBPS
Protocol fee basis points charged on mint and burn.
TOKEN_PAUSER_ROLE
bytes32 TOKEN_PAUSER_ROLE
TOKEN_MINTER_ROLE
bytes32 TOKEN_MINTER_ROLE
constructor
constructor(struct Multisig.Config config, uint16 _validatorFeeBPS, uint16 _protocolFeeBPS) public
depositFees
function depositFees(uint256 amount) internal view returns (uint256 fee)
Internal function to calculate the deposit fees.
onDeposit
function onDeposit(address token, uint256 amount) internal returns (uint256 fee)
Hook to execute on deposit.
Parameters
Name | Type | Description |
---|---|---|
token | address | Address of the token being deposited. |
amount | uint256 | The amount being deposited. |
Return Values
Name | Type | Description |
---|---|---|
fee | uint256 | The fee charged to the depositor. |
onExecute
function onExecute(address token, uint256 amount, address to) internal returns (uint256 totalFee, uint256 validatorFee)
Hook to execute on successful bridging.
Parameters
Name | Type | Description |
---|---|---|
token | address | Address of the token being bridged. |
amount | uint256 | The amount being bridged. |
to | address | The address where the bridged are being sent to. |
Return Values
Name | Type | Description |
---|---|---|
totalFee | uint256 | Total fee charged to the user. |
validatorFee | uint256 | Total fee minus the protocol fees. |
onMigrate
function onMigrate(address _newContract) internal
Hook executed before the bridge migration.
Parameters
Name | Type | Description |
---|---|---|
_newContract | address | Address of the new contract. |
configureProtocolFees
function configureProtocolFees(uint16 _protocolFeeBPS) public
Can only be called by the weak-admin.
Configure protocol fees.
Parameters
Name | Type | Description |
---|---|---|
_protocolFeeBPS | uint16 |
createAddToken
function createAddToken(string tokenName, string tokenSymbol, address existingToken, address mirrorToken, uint8 mirrorTokenDecimals, struct IWrap.TokenInfo tokenInfo) external returns (address token)
Set maxAmount to zero to disable the token. Can only be called by the weak-admin.
Link a token to its mirror token. A new token will be deployed if existingToken is the zero address. Otherwise the existingToken will be used instead, which means that a contract migration is underway.
Parameters
Name | Type | Description |
---|---|---|
tokenName | string | Name of the token to be created. |
tokenSymbol | string | Symbol of the token to be created. |
existingToken | address | Address of an existing wrapped token that will be used instead of deploying a new token. A new token will be deployed if this is set as the zero address. |
mirrorToken | address | Address of the token that will be deposited in the mirror contract. |
mirrorTokenDecimals | uint8 | Decimals of the mirror token. |
tokenInfo | struct IWrap.TokenInfo | Info associated with the token. |
Return Values
Name | Type | Description |
---|---|---|
token | address | Address of the new wrap token. |
claimProtocolFees
function claimProtocolFees(address token, address recipient) public
Can only be called by the weak-admin.
Allows the weak-admin to claim the accumulated protocol fees.
Parameters
Name | Type | Description |
---|---|---|
token | address | Token to claim protocol fees for. |
recipient | address | Address of the protocol fee recipient. |
WrapToken
_decimals
uint8 _decimals
constructor
constructor(string name_, string symbol_, uint8 decimals_) public
decimals
function decimals() public view virtual returns (uint8)
The number of decimals used to get the token's user representation.
Return Values
Name | Type | Description |
---|---|---|
[0] | uint8 | The number of decimals. |
IERC20MintBurn
mint
function mint(address holder, uint256 amount) external
Mints tokens to the given holder.
Parameters
Name | Type | Description |
---|---|---|
holder | address | Address to mint the tokens to. |
amount | uint256 | Amount of tokens to mint. |
burnFrom
function burnFrom(address holder, uint256 amount) external
Burns tokens on the given holder's account.
Parameters
Name | Type | Description |
---|---|---|
holder | address | Address of the account whose tokens to burn. |
amount | uint256 | Amount of tokens to burn. |
IWrap
ContractPaused
error ContractPaused()
Thrown when an operation is performed on a paused Wrap contract.
ContractNotPaused
error ContractNotPaused()
Thrown when the contract is not paused.
ContractMigrated
error ContractMigrated()
Thrown when the contract is already migrated.
InvalidTokenAmount
error InvalidTokenAmount()
Thrown when the token is not allowlisted or the amount being deposited/approved is not in the range of min/maxAmount.
InvalidTokenConfig
error InvalidTokenConfig()
Thrown when the token config is invalid.
FeeExceedsMaxFee
error FeeExceedsMaxFee()
Thrown when the fee being set is higher than the maximum fee allowed.
InvalidToAddress
error InvalidToAddress()
Thrown when the recipient address is the zero address.
InvalidBlockHash
error InvalidBlockHash()
Thrown when the provided blocknumber is not of the most recent 256 blocks.
DailyLimitExhausted
error DailyLimitExhausted()
Thrown when the daily volume exceeds the dailyLimit.
InvalidFeeRecipient
error InvalidFeeRecipient()
Thrown when the fee recipient address is the zero address.
Deposit
event Deposit(uint256 id, address token, uint256 amount, address to, uint256 fee)
Emitted when a user deposits.
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | ID associated with the request. |
token | address | Token deposited. |
amount | uint256 | Amount of tokens deposited, minus the fee. |
to | address | Address to release the funds to. |
fee | uint256 | Fee subtracted from the original deposited amount. |
Requested
event Requested(uint256 id, address mirrorToken, uint256 amount, address to)
Emitted when a new request is created.
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | ID associated with the request. |
mirrorToken | address | Mirror token requested. |
amount | uint256 | Amount of tokens requested. |
to | address | Address to release the funds to. |
Executed
event Executed(uint256 id, address mirrorToken, address token, uint256 amount, address to, uint256 fee)
Emitted when a request gets executed.
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | ID associated with the request. |
mirrorToken | address | Mirror token requested. |
token | address | Token approved. |
amount | uint256 | Amount approved, minus the fee. |
to | address | Address to release the funds to. |
fee | uint256 | Fee charged on top of the approved amount. |
TokenInfo
struct TokenInfo {
uint256 maxAmount;
uint256 minAmount;
uint256 dailyLimit;
}
TokenInfoStore
struct TokenInfoStore {
uint256 maxAmount;
uint256 minAmount;
uint256 dailyLimit;
uint256 consumedLimit;
uint256 lastUpdated;
}
RequestInfo
struct RequestInfo {
uint256 id;
address token;
uint256 amount;
address to;
}
paused
function paused() external view returns (bool paused)
Returns whether or not the contract has been paused.
Return Values
Name | Type | Description |
---|---|---|
paused | bool | True if the contract is paused, false otherwise. |
depositIndex
function depositIndex() external view returns (uint256)
Returns the number of deposits.
nextExecutionIndex
function nextExecutionIndex() external view returns (uint256)
Returns the index of the request that will be executed next.
validatorInfo
function validatorInfo(address validator) external view returns (struct Multisig.SignerInfo)
Returns info about a given validator.
attesters
function attesters(bytes32 hash) external view returns (uint16[] attesters, uint16 count)
Returns the number of attesters and their indeces for a given request hash.
validatorFeeBPS
function validatorFeeBPS() external view returns (uint16)
Returns the validator fee basis points.
configureToken
function configureToken(address token, struct IWrap.TokenInfo tokenInfo) external
Set maxAmount to zero to disable the token. Can only be called by the weak-admin.
Update a token's configuration information.
Parameters
Name | Type | Description |
---|---|---|
token | address | |
tokenInfo | struct IWrap.TokenInfo | The token's new configuration info. |
configureMultisig
function configureMultisig(struct Multisig.Config config) external
Can only be called by the admin.
Set the multisig configuration.
Parameters
Name | Type | Description |
---|---|---|
config | struct Multisig.Config | Multisig config. |
configureValidatorFees
function configureValidatorFees(uint16 validatorFeeBPS) external
Can only be called by the weak-admin.
Configure validator fees.
Parameters
Name | Type | Description |
---|---|---|
validatorFeeBPS | uint16 | Validator fee in basis points. |
deposit
function deposit(address token, uint256 amount, address to) external returns (uint256)
Deposit tokens to bridge to the other side.
Parameters
Name | Type | Description |
---|---|---|
token | address | Token being deposited. |
amount | uint256 | Amount of tokens being deposited. |
to | address | Address to release the tokens to on the other side. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | The ID associated to the request. |
approveExecute
function approveExecute(uint256 id, address token, uint256 amount, address to, bytes32 recentBlockhash, uint256 recentBlocknumber) external
Approve and/or execute a given request.
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | ID associated with the request. |
token | address | Token requested. |
amount | uint256 | Amount of tokens requested. |
to | address | Address to release the funds to. |
recentBlockhash | bytes32 | Block hash of recentBlocknumber |
recentBlocknumber | uint256 | Recent block number |
batchApproveExecute
function batchApproveExecute(struct IWrap.RequestInfo[] requests, bytes32 recentBlockhash, uint256 recentBlocknumber) external
Approve and/or execute requests.
Parameters
Name | Type | Description |
---|---|---|
requests | struct IWrap.RequestInfo[] | Requests to approve and/or execute. |
recentBlockhash | bytes32 | |
recentBlocknumber | uint256 |
pause
function pause() external
The contract can be paused by all addresses with pause role but can only be unpaused by the weak-admin.
Pauses the contract.
unpause
function unpause() external
The contract can be paused by all addresses with pause role but can only be unpaused by the weak-admin.
Unpauses the contract.
addValidator
function addValidator(address validator, bool isFirstCommittee, address feeRecipient) external
Can only be called by the admin.
Add a new validator to the contract.
Parameters
Name | Type | Description |
---|---|---|
validator | address | Address of the validator. |
isFirstCommittee | bool | True when adding the validator to the first committee. |
feeRecipient | address | Address of the fee recipient. false when adding the validator to the second committee. |
configureValidatorFeeRecipient
function configureValidatorFeeRecipient(address validator, address feeRecipient) external
Change fee recipient for a validator.
Parameters
Name | Type | Description |
---|---|---|
validator | address | Address of the validator. |
feeRecipient | address | Address of the new fee recipient. |
removeValidator
function removeValidator(address validator) external
Can only be called by the weak-admin. The fees accumulated by the validator are distributed before being removed.
Remove existing validator from the contract.
Parameters
Name | Type | Description |
---|---|---|
validator | address | Address of the validator. |
claimValidatorFees
function claimValidatorFees(address validator) external
Can be triggered by anyone but the fee is transfered to the set feeRecepient for the validator.
Allows to claim accumulated fees for a validator.
Parameters
Name | Type | Description |
---|---|---|
validator | address | Address of the validator. |
forceSetNextExecutionIndex
function forceSetNextExecutionIndex(uint256 index) external
Can only be called by the admin of the contract.
Forcefully set next next execution index.
Parameters
Name | Type | Description |
---|---|---|
index | uint256 | The new next execution index. |
migrate
function migrate(address _newContract) external
This function can only be called once in the lifetime of this contract by the admin.
Migrates the contract to a new address.
Parameters
Name | Type | Description |
---|---|---|
_newContract | address | Address of the new contract. |
IWrapDepositRedeem
addToken
function addToken(address token, address mirrorToken, struct IWrap.TokenInfo tokenInfo) external
Set maxAmount to zero to disable the token. Can only be called by the weak-admin.
Allowlist a new token.
Parameters
Name | Type | Description |
---|---|---|
token | address | Address of the token that will be allowlisted. |
mirrorToken | address | Address of the token that will be minted on the other side. |
tokenInfo | struct IWrap.TokenInfo | Information associated with the token. |
IWrapMintBurn
accumulatedProtocolFees
function accumulatedProtocolFees(address token) external view returns (uint256 balance)
Returns the total protocol fees accumulated for a given token.
Parameters
Name | Type | Description |
---|---|---|
token | address | Address of the token for which to check its corresponding accumulated protocol fees. |
Return Values
Name | Type | Description |
---|---|---|
balance | uint256 | Total accumulated protocol fees for the given token. |
protocolFeeBPS
function protocolFeeBPS() external view returns (uint16)
Returns the protocol fee basis points.
configureProtocolFees
function configureProtocolFees(uint16 protocolFeeBPS) external
Can only be called by the weak-admin.
Configure protocol fees.
Parameters
Name | Type | Description |
---|---|---|
protocolFeeBPS | uint16 | Protocol fee in basis points. |
createAddToken
function createAddToken(string tokenName, string tokenSymbol, address existingToken, address mirrorToken, uint8 mirrorTokenDecimals, struct IWrap.TokenInfo tokenInfo) external returns (address)
Set maxAmount to zero to disable the token. Can only be called by the weak-admin.
Link a token to its mirror token. A new token will be deployed if existingToken is the zero address. Otherwise the existingToken will be used instead, which means that a contract migration is underway.
Parameters
Name | Type | Description |
---|---|---|
tokenName | string | Name of the token to be created. |
tokenSymbol | string | Symbol of the token to be created. |
existingToken | address | Address of an existing wrapped token that will be used instead of deploying a new token. A new token will be deployed if this is set as the zero address. |
mirrorToken | address | Address of the token that will be deposited in the mirror contract. |
mirrorTokenDecimals | uint8 | Decimals of the mirror token. |
tokenInfo | struct IWrap.TokenInfo | Info associated with the token. |
Return Values
Name | Type | Description |
---|---|---|
[0] | address | Address of the new wrap token. |
claimProtocolFees
function claimProtocolFees(address token, address recipient) external
Can only be called by the weak-admin.
Allows the weak-admin to claim the accumulated protocol fees.
Parameters
Name | Type | Description |
---|---|---|
token | address | Token to claim protocol fees for. |
recipient | address | Address of the protocol fee recipient. |
Multisig
Implements a multisig with two committees. A separate quorum must be reached in both committees to approve a given request. A request is rejected if either of the two committees rejects it. Each committee cannot have more than 128 members.
SignerAlreadyExists
error SignerAlreadyExists(address signer)
Thrown when an already existing signer is added.
SignerNotActive
error SignerNotActive(address signer)
Thrown when an account that is performing some signer-only action is not an active signer.
MaxCommitteeSizeReached
error MaxCommitteeSizeReached()
Thrown when attempting to add a new signer after the max committee size has been reached.
InvalidConfiguration
error InvalidConfiguration()
Thrown when the configuration parmeters that are being set are not valid.
InvalidId
error InvalidId()
Thrown when a given ID has already been assigned to an apprroved request.
InvalidNextExecutionIndex
error InvalidNextExecutionIndex()
Thrown when the current next execution index is greater equal to the new next execution index.
AddSigner
event AddSigner(address signer, bool isFirstCommittee)
Emitted when a new signer is added.
Parameters
Name | Type | Description |
---|---|---|
signer | address | Address of signer that was added. |
isFirstCommittee | bool | True if the signer was added to the first committee and false if they were added to the second committee. |
RemoveSigner
event RemoveSigner(address signer)
Emitted when an existing signer is removed.
Parameters
Name | Type | Description |
---|---|---|
signer | address | Address of signer that was removed. |
maxCommitteeSize
uint8 maxCommitteeSize
This number cannot be increased further with the current implementation. Our implementation uses bitmasks and the uint8 data type to optimize gas. These data structures will overflow if maxCommitteeSize is greater than 128.
Maximum number of members in each committee.
maxSignersSize
uint16 maxSignersSize
Similarly to maxCommitteeSize, maxSignersSize also cannot be further increased to more than 256.
Maximum number of members in both committees combined.
RequestStatus
enum RequestStatus {
NULL,
Undecided,
Accepted
}
RequestStatusTransition
enum RequestStatusTransition {
Unchanged,
NULLToUndecided,
UndecidedToAccepted
}
SignerStatus
enum SignerStatus {
Uninitialized,
Removed,
FirstCommittee,
SecondCommittee
}
Request
struct Request {
uint8 approvalsFirstCommittee;
uint8 approvalsSecondCommittee;
enum Multisig.RequestStatus status;
uint256 approvers;
}
SignerInfo
struct SignerInfo {
enum Multisig.SignerStatus status;
uint8 index;
}
DualMultisig
struct DualMultisig {
uint8 firstCommitteeAcceptanceQuorum;
uint8 secondCommitteeAcceptanceQuorum;
uint8 firstCommitteeSize;
uint8 secondCommitteeSize;
uint256 nextExecutionIndex;
mapping(address => struct Multisig.SignerInfo) signers;
mapping(bytes32 => struct Multisig.Request) requests;
mapping(uint256 => bytes32) approvedRequests;
}
Config
struct Config {
uint8 firstCommitteeAcceptanceQuorum;
uint8 secondCommitteeAcceptanceQuorum;
}
status
function status(struct Multisig.DualMultisig s, bytes32 hash) internal view returns (enum Multisig.RequestStatus)
Returns a request status for a given request hash.
Parameters
Name | Type | Description |
---|---|---|
s | struct Multisig.DualMultisig | The relevant multisig to check. |
hash | bytes32 | The hash of the request being checked. |
Return Values
Name | Type | Description |
---|---|---|
[0] | enum Multisig.RequestStatus | The status of the request with the given hash. |
isSigner
function isSigner(struct Multisig.DualMultisig s, address signer) internal view returns (bool)
Returns whether or not a given address is a signer in the multisig.
Parameters
Name | Type | Description |
---|---|---|
s | struct Multisig.DualMultisig | The relevant multisig to check. |
signer | address | The address of the potential signer. |
Return Values
Name | Type | Description |
---|---|---|
[0] | bool | True if the provided address is a signer. |
configure
function configure(struct Multisig.DualMultisig s, struct Multisig.Config c) internal
Updates a multisig's configuration.
addSigner
function addSigner(struct Multisig.DualMultisig s, address signer, bool isFirstCommittee) internal
Adds a new signer.
Parameters
Name | Type | Description |
---|---|---|
s | struct Multisig.DualMultisig | The multisig to add the signer to. |
signer | address | The address of the signer to add. |
isFirstCommittee | bool | True if the signer is to be added to the first committee and false if they are to be added to the second committee. |
removeSigner
function removeSigner(struct Multisig.DualMultisig s, address signer) internal
Removes a signer.
Parameters
Name | Type | Description |
---|---|---|
s | struct Multisig.DualMultisig | The multisig to remove the signer from. |
signer | address | The signer to be removed. |
tryApprove
function tryApprove(struct Multisig.DualMultisig s, address signer, bytes32 hash, uint256 id) internal returns (enum Multisig.RequestStatusTransition)
Approve a request if its has not already been approved. Notice that this code assumes that the hash is generated from the ID and other data outside of this function. It is important to include the ID in the hash.
Parameters
Name | Type | Description |
---|---|---|
s | struct Multisig.DualMultisig | The multisig for which to approve the given request. |
signer | address | The signer approving the request. |
hash | bytes32 | The hash of the request being approved. |
id | uint256 |
Return Values
Name | Type | Description |
---|---|---|
[0] | enum Multisig.RequestStatusTransition | The request's status transition. |
getApprovers
function getApprovers(struct Multisig.DualMultisig s, bytes32 hash) internal view returns (uint16[] approvers, uint16 count)
Get approvers for a given request.
Parameters
Name | Type | Description |
---|---|---|
s | struct Multisig.DualMultisig | The multisig to get the approvers for. |
hash | bytes32 | The hash of the request. |
Return Values
Name | Type | Description |
---|---|---|
approvers | uint16[] | List of approvers. |
count | uint16 | Count of approvers. |
forceSetNextExecutionIndex
function forceSetNextExecutionIndex(struct Multisig.DualMultisig s, uint256 index) internal
Forcefully set next next execution index.
Parameters
Name | Type | Description |
---|---|---|
s | struct Multisig.DualMultisig | The multisig to set the next execution index for. |
index | uint256 | The new next execution index. |
tryExecute
function tryExecute(struct Multisig.DualMultisig s, bytes32 hash, uint256 id) internal returns (bool)
Try to execute the next approved request.
Parameters
Name | Type | Description |
---|---|---|
s | struct Multisig.DualMultisig | The multisig whose next request should be executed. |
hash | bytes32 | The hash of the request being executed. |
id | uint256 | The ID of the request being executed. |
Return Values
Name | Type | Description |
---|---|---|
[0] | bool | True if the execution was successful. |