crossbell-bridge
Contents
ICrossbellGateway
This is the interface for the crossbell bridge gateway contract. You'll find all the events and external functions.
Functions
initialize
Initializes the CrossbellGateway.
function initialize(
address validator,
address admin,
address[] calldata crossbellTokens,
uint256[] calldata chainIds,
address[] calldata mainchainTokens,
uint8[] calldata mainchainTokenDecimals
) external;
Parameters
Name | Type | Description |
---|---|---|
validator | address | Address of validator contract. |
admin | address | Address of gateway admin. |
crossbellTokens | address[] | Addresses of crossbell tokens. |
chainIds | uint256[] | The chain IDs of mainchain networks. |
mainchainTokens | address[] | Addresses of mainchain tokens. |
mainchainTokenDecimals | uint8[] | Decimals of mainchain tokens. |
pause
Pauses interaction with the gateway contract
function pause() external;
unpause
Resumes interaction with the gateway contract
function unpause() external;
mapTokens
Maps mainchain tokens to Crossbell network.
function mapTokens(
address[] calldata crossbellTokens,
uint256[] calldata chainIds,
address[] calldata mainchainTokens,
uint8[] calldata mainchainTokenDecimals
) external;
Parameters
Name | Type | Description |
---|---|---|
crossbellTokens | address[] | Addresses of crossbell tokens. |
chainIds | uint256[] | The chain IDs of mainchain networks. |
mainchainTokens | address[] | Addresses of mainchain tokens. |
mainchainTokenDecimals | uint8[] | Decimals of mainchain tokens. |
batchAckDeposit
Tries bulk deposit.
function batchAckDeposit(
uint256[] calldata chainIds,
uint256[] calldata depositIds,
address[] calldata recipients,
address[] calldata tokens,
uint256[] calldata amounts,
bytes32[] calldata depositHashes
) external;
batchSubmitWithdrawalSignatures
Tries bulk submit withdrawal signatures. Note that the caller must be a validator.
function batchSubmitWithdrawalSignatures(
uint256[] calldata chainIds,
uint256[] calldata withdrawalIds,
bytes[] calldata sigs
) external;
ackDeposit
Acknowledges a deposit. Note that the caller must be a validator.
function ackDeposit(
uint256 chainId,
uint256 depositId,
address recipient,
address token,
uint256 amount,
bytes32 depositHash
) external;
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The chain ID of mainchain network. |
depositId | uint256 | Deposit identifier id. |
recipient | address | Address to receive deposit on crossbell network. |
token | address | Token address to deposit on crossbell network. |
amount | uint256 | Token amount to deposit on crossbell network. |
depositHash | bytes32 | Hash of deposit info. |
requestWithdrawal
Locks the assets and request withdrawal.
function requestWithdrawal(uint256 chainId, address recipient, address token, uint256 amount, uint256 fee)
external
returns (uint256 withdrawalId);
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The chain ID of mainchain network. |
recipient | address | Address to receive withdrawal on mainchain network. |
token | address | Token address to lock from crossbell network. |
amount | uint256 | Token amount to lock from crossbell network. |
fee | uint256 | Fee amount to pay. This is subtracted from the amount . |
Returns
Name | Type | Description |
---|---|---|
withdrawalId | uint256 | The newly generated withdrawalId. |
submitWithdrawalSignature
Submits validator signature for withdrawal. Note that the caller must be a validator.
function submitWithdrawalSignature(uint256 chainId, uint256 withdrawalId, bytes calldata sig) external;
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The chain ID of mainchain network. |
withdrawalId | uint256 | WithdrawalId. |
sig | bytes | Validator signature for the withdrawal. |
getMainchainToken
Returns mapped token on mainchain.
function getMainchainToken(uint256 chainId, address crossbellToken)
external
view
returns (DataTypes.MappedToken memory token);
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The chain ID of mainchain network. |
crossbellToken | address | Token address on crossbell. |
Returns
Name | Type | Description |
---|---|---|
token | DataTypes.MappedToken | Mapped token on mainchain chain. |
getValidatorAcknowledgementHash
Returns the acknowledge depositHash by validator.
function getValidatorAcknowledgementHash(uint256 chainId, uint256 id, address validator)
external
view
returns (bytes32);
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The chain ID of mainchain network. |
id | uint256 | DepositId. |
validator | address | Validator address. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | bytes32 depositHash if validator has acknowledged, otherwise 0. |
getAcknowledgementStatus
Returns the acknowledge status of deposit by validators.
function getAcknowledgementStatus(uint256 chainId, uint256 id, bytes32 hash) external view returns (DataTypes.Status);
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The chain ID of mainchain network. |
id | uint256 | DepositId. |
hash | bytes32 | depositHash. |
Returns
Name | Type | Description |
---|---|---|
<none> | DataTypes.Status | DataTypes.Status Acknowledgement status. |
getAcknowledgementCount
Returns the acknowledge count of deposit by validators.
function getAcknowledgementCount(uint256 chainId, uint256 id, bytes32 hash) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The chain ID of mainchain network. |
id | uint256 | DepositId. |
hash | bytes32 | depositHash. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | uint256 Acknowledgement count. |
getWithdrawalSignatures
Returns withdrawal signatures.
function getWithdrawalSignatures(uint256 chainId, uint256 withdrawalId)
external
view
returns (address[] memory signers, bytes[] memory sigs);
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The chain ID of mainchain network. |
withdrawalId | uint256 | Withdrawal Id to query. |
Returns
Name | Type | Description |
---|---|---|
signers | address[] | Signer addresses. |
sigs | bytes[] | Signer signatures. |
getValidatorContract
Returns the address of the validator contract.
function getValidatorContract() external view returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | The validator contract address. |
getDepositEntry
Returns the deposit entry.
function getDepositEntry(uint256 chainId, uint256 depositId) external view returns (DataTypes.DepositEntry memory);
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The chain ID of mainchain network. |
depositId | uint256 | Deposit Id to query. |
Returns
Name | Type | Description |
---|---|---|
<none> | DataTypes.DepositEntry | DataTypes.DepositEntry Deposit entry. |
getWithdrawalCount
Returns the withdrawal count of different mainchain networks.
function getWithdrawalCount(uint256 chainId) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The chain ID of mainchain network. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Withdrawal count. |
getWithdrawalEntry
Returns the withdrawal entry.
function getWithdrawalEntry(uint256 chainId, uint256 withdrawalId)
external
view
returns (DataTypes.WithdrawalEntry memory);
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The chain ID of mainchain network. |
withdrawalId | uint256 | Withdrawal Id to query. |
Returns
Name | Type | Description |
---|---|---|
<none> | DataTypes.WithdrawalEntry | DataTypes.WithdrawalEntry Withdrawal entry. |
Events
TokenMapped
Emitted when the tokens are mapped.
event TokenMapped(
address[] crossbellTokens, uint256[] chainIds, address[] mainchainTokens, uint8[] mainchainTokenDecimals
);
Parameters
Name | Type | Description |
---|---|---|
crossbellTokens | address[] | Addresses of crossbell tokens. |
chainIds | uint256[] | The chain IDs of mainchain networks. |
mainchainTokens | address[] | Addresses of mainchain tokens. |
mainchainTokenDecimals | uint8[] | Decimals of mainchain tokens. |
Deposited
Emitted when the assets are deposited.
event Deposited(
uint256 indexed chainId, uint256 indexed depositId, address indexed recipient, address token, uint256 amount
);
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The chain ID of mainchain network. |
depositId | uint256 | Deposit identifier id. |
recipient | address | The address of account to receive the deposit. |
token | address | The address of token to deposit. |
amount | uint256 | The amount of token to deposit. |
AckDeposit
Emitted when the deposit is acknowledged by a validator.
event AckDeposit(
uint256 indexed chainId,
uint256 indexed depositId,
address indexed validator,
address recipient,
address token,
uint256 amount
);
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The ChainId of mainchain network. |
depositId | uint256 | Deposit identifier id. |
validator | address | |
recipient | address | The address of account to receive the deposit. |
token | address | The address of token to deposit. |
amount | uint256 | The amount of token to deposit. |
RequestWithdrawal
Emitted when the withdrawal is requested.
event RequestWithdrawal(
uint256 indexed chainId,
uint256 indexed withdrawalId,
address indexed recipient,
address token,
uint256 amount,
uint256 fee
);
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The ChainId of mainchain network. |
withdrawalId | uint256 | Withdrawal identifier id. |
recipient | address | The address of account to receive the withdrawal. |
token | address | The address of token to withdraw on mainchain network. |
amount | uint256 | The amount of token to withdraw on mainchain network. Note that validator should use this `amount' for submitting signature. |
fee | uint256 | The fee amount to pay for the withdrawal tx sender on mainchain network. |
SubmitWithdrawalSignature
Emitted when a withdrawal signature is submitted by validator.
event SubmitWithdrawalSignature(
uint256 indexed chainId, uint256 indexed withdrawalId, address indexed validator, bytes signature
);
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The ChainId of mainchain network. |
withdrawalId | uint256 | Withdrawal identifier id. |
validator | address | The address of validator who submitted the signature. |
signature | bytes | The submitted signature. |
IERC20Mintable
Functions
mint
function mint(address to, uint256 amount) external;
IMainchainGateway
This is the interface for the crossbell bridge manchain gateway contract. You'll find all the events and external functions.
Functions
initialize
Initializes the MainchainGateway. Note that the thresholds contains:
- thresholds[1]:
function initialize(
address validator,
address admin,
address[] calldata mainchainTokens,
uint256[] calldata dailyWithdrawalMaxQuota,
address[] calldata crossbellTokens,
uint8[] calldata crossbellTokenDecimals
) external;
Parameters
Name | Type | Description |
---|---|---|
validator | address | Address of validator contract. |
admin | address | Address of gateway admin. |
mainchainTokens | address[] | Addresses of mainchain tokens. |
dailyWithdrawalMaxQuota | uint256[] | The daily withdrawal max quotas for mainchain tokens. |
crossbellTokens | address[] | Addresses of crossbell tokens. |
crossbellTokenDecimals | uint8[] | Decimals of crossbell tokens. |
pause
Pauses interaction with the gateway contract. Requirements:
- The caller must have the ADMIN_ROLE.
function pause() external;
unpause
Resumes interaction with the gateway contract. Requirements:
- The caller must have the ADMIN_ROLE.
function unpause() external;
mapTokens
Maps Crossbell tokens to mainchain.
Emits the TokenMapped
event.
Requirements:
- The caller must have the ADMIN_ROLE.
function mapTokens(
address[] calldata mainchainTokens,
address[] calldata crossbellTokens,
uint8[] calldata crossbellTokenDecimals
) external;
Parameters
Name | Type | Description |
---|---|---|
mainchainTokens | address[] | Addresses of mainchain tokens. |
crossbellTokens | address[] | Addresses of crossbell tokens. |
crossbellTokenDecimals | uint8[] | Decimals of crossbell tokens. |
requestDeposit
Requests deposit to crossbell chain.
Emits the RequestDeposit
event.
function requestDeposit(address recipient, address token, uint256 amount) external returns (uint256 depositId);
Parameters
Name | Type | Description |
---|---|---|
recipient | address | Address to receive deposit on crossbell chain. |
token | address | Address of token to deposit from mainchain network. |
amount | uint256 | Amount of token to deposit from mainchain network. |
Returns
Name | Type | Description |
---|---|---|
depositId | uint256 | Deposit id. |
withdraw
Withdraws based on the validator signatures.
Emits the Withdrew
event.
Requirements:
- The signatures should be sorted by signing addresses of validators in ascending order.
function withdraw(
uint256 chainId,
uint256 withdrawalId,
address recipient,
address token,
uint256 amount,
uint256 fee,
DataTypes.Signature[] calldata signatures
) external;
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The chain ID of mainchain network. |
withdrawalId | uint256 | Withdrawal ID from crossbell chain. |
recipient | address | Address to receive withdrawal on mainchain chain. |
token | address | Address of token to withdraw. |
amount | uint256 | Amount of token to withdraw. |
fee | uint256 | The fee amount to pay for the withdrawal tx sender. This is subtracted from the amount . |
signatures | DataTypes.Signature[] | The list of signatures sorted by signing addresses of validators in ascending order. |
setDailyWithdrawalMaxQuotas
Sets daily max quotas for the withdrawals.
Emits the DailyWithdrawalMaxQuotasUpdated
event.
Requirements:
- The caller must have the ADMIN_ROLE.
- The arrays have the same length.
function setDailyWithdrawalMaxQuotas(address[] calldata tokens, uint256[] calldata quotas) external;
Parameters
Name | Type | Description |
---|---|---|
tokens | address[] | Addresses of token to set. |
quotas | uint256[] | quotas corresponding to the tokens to set. |
getDomainSeparator
Returns the domain separator for this contract.
function getDomainSeparator() external view returns (bytes32);
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | bytes32 The domain separator. |
getValidatorContract
Returns the address of the validator contract.
function getValidatorContract() external view returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | The validator contract address. |
getDepositCount
Returns the deposit count of the gateway contract.
function getDepositCount() external view returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The deposit count. |
getWithdrawalHash
Returns the withdrawal hash by withdrawal id.
function getWithdrawalHash(uint256 withdrawalId) external view returns (bytes32);
Parameters
Name | Type | Description |
---|---|---|
withdrawalId | uint256 | WithdrawalId to query. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | The withdrawal hash. |
getDailyWithdrawalMaxQuota
Returns the daily withdrawal max quota.
function getDailyWithdrawalMaxQuota(address token) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
token | address | Token address |
getDailyWithdrawalRemainingQuota
Returns today's withdrawal remaining quota.
function getDailyWithdrawalRemainingQuota(address token) external view returns (uint256 remainingQuota);
Parameters
Name | Type | Description |
---|---|---|
token | address | Token address to query. |
Returns
Name | Type | Description |
---|---|---|
remainingQuota | uint256 | Today's withdrawal remaining quota. |
getCrossbellToken
Returns mapped tokens from crossbell chain.
function getCrossbellToken(address mainchainToken) external view returns (DataTypes.MappedToken memory token);
Parameters
Name | Type | Description |
---|---|---|
mainchainToken | address | Token address on mainchain. |
Returns
Name | Type | Description |
---|---|---|
token | DataTypes.MappedToken | Mapped token from crossbell chain. |
Events
TokenMapped
Emitted when the tokens are mapped
event TokenMapped(address[] mainchainTokens, address[] crossbellTokens, uint8[] crossbellTokenDecimals);
Parameters
Name | Type | Description |
---|---|---|
mainchainTokens | address[] | Addresses of mainchain tokens. |
crossbellTokens | address[] | Addresses of crossbell tokens. |
crossbellTokenDecimals | uint8[] | Decimals of crossbell tokens. |
RequestDeposit
Emitted when the deposit is requested.
event RequestDeposit(
uint256 indexed chainId,
uint256 indexed depositId,
address indexed recipient,
address token,
uint256 amount,
bytes32 depositHash
);
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The chain ID of mainchain network. |
depositId | uint256 | Deposit id. |
recipient | address | Address to receive deposit on crossbell network. |
token | address | Address of token to deposit on crossbell network. |
amount | uint256 | Amount of token to deposit on crossbell network. |
depositHash | bytes32 | Hash of deposit info. |
Withdrew
Emitted when the assets are withdrawn on mainchain.
event Withdrew(
uint256 indexed chainId,
uint256 indexed withdrawalId,
address indexed recipient,
address token,
uint256 amount,
uint256 fee
);
Parameters
Name | Type | Description |
---|---|---|
chainId | uint256 | The chain ID of mainchain network. |
withdrawalId | uint256 | Withdrawal ID from crossbell chain. |
recipient | address | Address to receive withdrawal on mainchain chain. |
token | address | Address of token to withdraw. |
amount | uint256 | Amount of token to withdraw. |
fee | uint256 | The fee amount to pay for the withdrawal tx sender. This is subtracted from the amount . |
DailyWithdrawalMaxQuotasUpdated
Emitted when the daily quota thresholds are updated.
event DailyWithdrawalMaxQuotasUpdated(address[] tokens, uint256[] quotas);
IValidator
This is the interface for the validator contract. You'll find all the events and external functions.
Functions
addValidators
Adds new validators. This function can only be called by the owner of validator contract. Note that this reverts if new validators to add are already validators.
function addValidators(address[] calldata validators) external;
Parameters
Name | Type | Description |
---|---|---|
validators | address[] | New validator addresses to add |
removeValidators
Removes exist validators. This function can only be called by the owner of validator contract. Note that this reverts if validators to remove are not validators.
function removeValidators(address[] calldata validators) external;
Parameters
Name | Type | Description |
---|---|---|
validators | address[] | Validator addresses to remove |
changeRequiredNumber
Change the required number of validators. Requirements::
- the caller is owner of validator contract.
- new required number > validators length.
- new required number is zero.
function changeRequiredNumber(uint256 newRequiredNumber) external;
Parameters
Name | Type | Description |
---|---|---|
newRequiredNumber | uint256 | New required number to set. |
isValidator
Returns whether an address is validator or not.
function isValidator(address addr) external view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
addr | address | Address to query. |
getValidators
Returns all the validators.
function getValidators() external view returns (address[] memory validators);
getRequiredNumber
Returns current required number.
function getRequiredNumber() external view returns (uint256);
checkThreshold
Checks whether the voteCount
passes the threshold.
function checkThreshold(uint256 voteCount) external view returns (bool);
Events
ValidatorAdded
Emitted when a new validator is added.
event ValidatorAdded(address indexed validator);
Parameters
Name | Type | Description |
---|---|---|
validator | address | The validator address to add. |
ValidatorRemoved
Emitted when a validator is removed.
event ValidatorRemoved(address indexed validator);
Parameters
Name | Type | Description |
---|---|---|
validator | address | The validator address to remove. |
RequirementChanged
Emitted when a new required number is set.
event RequirementChanged(uint256 indexed requirement, uint256 indexed previousRequired);
Parameters
Name | Type | Description |
---|---|---|
requirement | uint256 | The new required number to set. |
previousRequired | uint256 | The previous required number. |
Contents
DataTypes
A standard library of data types.
Structs
MappedToken
struct MappedToken {
address token;
uint8 decimals;
}
DepositEntry
A struct containing deposit data.
struct DepositEntry {
uint256 chainId;
address recipient;
address token;
uint256 amount;
}
Properties
Name | Type | Description |
---|---|---|
chainId | uint256 | The ChainId of mainchain network. |
recipient | address | The address of account to receive the deposit. |
token | address | The address of token to deposit. |
amount | uint256 | The amount of token to deposit. |
WithdrawalEntry
A struct containing withdrawal data.
struct WithdrawalEntry {
uint256 chainId;
address recipient;
address token;
uint256 amount;
uint256 fee;
}
Properties
Name | Type | Description |
---|---|---|
chainId | uint256 | The ChainId of mainchain network. |
recipient | address | The address of account to receive the withdrawal. |
token | address | The address of token to withdraw. |
amount | uint256 | The amount of token to be withdrawn on mainchain network. Note that validator should use this `amount' for submitting signature |
fee | uint256 | The fee amount to pay for the withdrawal tx sender on mainchain network. |
Signature
A struct containing a validator signature for the withdrawal.
struct Signature {
uint8 v;
bytes32 r;
bytes32 s;
}
Enums
Status
Acknowledge status, once the acknowledgements reach the threshold the 1st time, it can take effect to the system. Acknowledgments after that should not have any effects.
enum Status {
NotApproved,
FirstApproved,
AlreadyApproved
}
Contents
CrossbellGatewayStorage
Storage of deposit and withdraw information.
State Variables
_deposits
Mapping from chainId => depositId => DepositEntry
mapping(uint256 => mapping(uint256 => DataTypes.DepositEntry)) internal _deposits;
_withdrawalCounter
Mapping from chainId => withdrawCount
mapping(uint256 => uint256) internal _withdrawalCounter;
_withdrawals
Mapping from chainId => withdrawalId => WithdrawalEntry
mapping(uint256 => mapping(uint256 => DataTypes.WithdrawalEntry)) internal _withdrawals;
_withdrawalSig
Mapping from chainId => withdrawalId => signature
mapping(uint256 => mapping(uint256 => mapping(address => bytes))) internal _withdrawalSig;
_withdrawalSigners
Mapping from chainId => withdrawalId => address[]
mapping(uint256 => mapping(uint256 => address[])) internal _withdrawalSigners;
_mainchainTokens
Mapping from token address => chain id => mainchain token address
mapping(address => mapping(uint256 => DataTypes.MappedToken)) internal _mainchainTokens;
_validator
address internal _validator;
_validatorAck
Mapping from chainId => id => validator => data hash
mapping(uint256 => mapping(uint256 => mapping(address => bytes32))) internal _validatorAck;
_ackCount
Mapping from chainId => id => data hash => ack count
mapping(uint256 => mapping(uint256 => mapping(bytes32 => uint256))) internal _ackCount;
_ackStatus
Mapping from chainId => id => data hash => ack status
mapping(uint256 => mapping(uint256 => mapping(bytes32 => DataTypes.Status))) internal _ackStatus;
MainchainGatewayStorage
Storage of deposit and withdraw information.
State Variables
_domainSeparator
Domain separator
bytes32 internal _domainSeparator;
_validator
Validator contract address
address internal _validator;
_depositCounter
Total deposit count
uint256 internal _depositCounter;
_withdrawalHash
Mapping from withdrawal id => withdrawal hash
mapping(uint256 => bytes32) internal _withdrawalHash;
_dailyWithdrawalMaxQuota
for withdrawal restriction
Mapping from mainchain token => daily max amount for withdrawal
mapping(address => uint256) internal _dailyWithdrawalMaxQuota;
_lastSyncedWithdrawal
Mapping from token address => today withdrawal amount
mapping(address => uint256) internal _lastSyncedWithdrawal;
_lastDateSynced
Mapping from token address => last date synced to record the _lastSyncedWithdrawal
mapping(address => uint256) internal _lastDateSynced;
_crossbellTokens
Mapping from mainchain token => token address on crossbell network
mapping(address => DataTypes.MappedToken) internal _crossbellTokens;