Skip to main content
Version: testnet (v0.75)

ERC20 Bridge Logic (ERC20_Bridge_Logic.sol)

View Source: contracts/ERC20_Bridge_Logic.sol

↗ Extends: IERC20_Bridge_Logic

ERC20_Bridge_Logic_Restricted

This contract is used by Vega network users to deposit and withdraw ERC20 tokens to/from Vega.

Contract Members

Constants & Variables

address payable internal erc20_asset_pool_address;

mapping(address => bool) internal listed_tokens;

mapping(bytes32 => address) internal vega_asset_ids_to_source;

mapping(address => bytes32) internal asset_source_to_vega_asset_id;

mapping(address => mapping(address => uint256)) internal user_lifetime_deposits;

mapping(address => uint256) internal asset_deposit_lifetime_limit;

mapping(address => uint256) internal withdraw_thresholds;

mapping(address => bool) internal exempt_depositors;

uint256 public default_withdraw_delay;

bool public is_stopped;

Functions

function (address payable erc20_asset_pool) public nonpayable

Arguments

NameTypeDescription
erc20_asset_pooladdress payableInitial Asset Pool contract address

multisig_control_address

function multisig_control_address() internal view
returns(address)

Arguments

NameTypeDescription

list_asset

This function lists the given ERC20 token contract as valid for deposit to this bridgeEmits Asset_Listed if successful

function list_asset(address asset_source, bytes32 vega_asset_id, uint256 lifetime_limit, uint256 withdraw_threshold, uint256 nonce, bytes signatures) public nonpayable

Arguments

NameTypeDescription
asset_sourceaddressContract address for given ERC20 token
vega_asset_idbytes32Vega-generated asset ID for internal use in Vega Core
lifetime_limituint256Initial lifetime deposit limit RESTRICTION FEATURE
withdraw_thresholduint256Amount at which the withdraw delay goes into effect RESTRICTION FEATURE
nonceuint256Vega-assigned single-use number that provides replay attack protection
signaturesbytesVega-supplied signature bundle of a validator-signed order

remove_asset

This function removes from listing the given ERC20 token contract. This marks the token as invalid for deposit to this bridgeEmits Asset_Removed if successful

function remove_asset(address asset_source, uint256 nonce, bytes signatures) public nonpayable

Arguments

NameTypeDescription
asset_sourceaddressContract address for given ERC20 token
nonceuint256Vega-assigned single-use number that provides replay attack protection
signaturesbytesVega-supplied signature bundle of a validator-signed order

set_asset_limits

This function sets the lifetime maximum deposit for a given assetasset must first be listed

function set_asset_limits(address asset_source, uint256 lifetime_limit, uint256 threshold, uint256 nonce, bytes signatures) public nonpayable

Arguments

NameTypeDescription
asset_sourceaddressContract address for given ERC20 token
lifetime_limituint256Deposit limit for a given ethereum address
thresholduint256Withdraw size above which the withdraw delay goes into effect
nonceuint256Vega-assigned single-use number that provides replay attack protection
signaturesbytesVega-supplied signature bundle of a validator-signed order

get_asset_deposit_lifetime_limit

This view returns the lifetime deposit limit for the given asset

function get_asset_deposit_lifetime_limit(address asset_source) public view
returns(uint256)

Returns

Lifetime limit for the given asset

Arguments

NameTypeDescription
asset_sourceaddressContract address for given ERC20 token

get_withdraw_threshold

This view returns the given token's withdraw threshold above which the withdraw delay goes into effect

function get_withdraw_threshold(address asset_source) public view
returns(uint256)

Returns

Withdraw threshold

Arguments

NameTypeDescription
asset_sourceaddressContract address for given ERC20 token

set_withdraw_delay

This function sets the withdraw delay for withdrawals over the per-asset set thresholds

function set_withdraw_delay(uint256 delay, uint256 nonce, bytes signatures) public nonpayable

Arguments

NameTypeDescription
delayuint256Amount of time to delay a withdrawal
nonceuint256Vega-assigned single-use number that provides replay attack protection
signaturesbytesVega-supplied signature bundle of a validator-signed order

global_stop

This function triggers the global bridge stop that halts all withdrawals and deposits until it is resumedbridge must not be stopped already

function global_stop(uint256 nonce, bytes signatures) public nonpayable

Arguments

NameTypeDescription
nonceuint256Vega-assigned single-use number that provides replay attack protection
signaturesbytesVega-supplied signature bundle of a validator-signed order

global_resume

This function resumes bridge operations from the stopped statebridge must be stopped

function global_resume(uint256 nonce, bytes signatures) public nonpayable

Arguments

NameTypeDescription
nonceuint256Vega-assigned single-use number that provides replay attack protection
signaturesbytesVega-supplied signature bundle of a validator-signed order

exempt_depositor

this function allows the sender to exempt themselves from the deposit limitsemits Depositor_Exempted if successful

function exempt_depositor() public nonpayable

Arguments

NameTypeDescription

revoke_exempt_depositor

this function allows the exemption_lister to revoke a depositor's exemption from deposit limitsemits Depositor_Exemption_Revoked if successful

function revoke_exempt_depositor() public nonpayable

Arguments

NameTypeDescription

is_exempt_depositor

this view returns true if the given despoitor address has been exempted from deposit limits

function is_exempt_depositor(address depositor) public view
returns(bool)

Returns

true if depositor is exempt

Arguments

NameTypeDescription
depositoraddressThe depositor to check

withdraw_asset

This function withdraws assets to the target Ethereum addressEmits Asset_Withdrawn if successful

function withdraw_asset(address asset_source, uint256 amount, address target, uint256 creation, uint256 nonce, bytes signatures) public nonpayable

Arguments

NameTypeDescription
asset_sourceaddressContract address for given ERC20 token
amountuint256Amount of ERC20 tokens to withdraw
targetaddressTarget Ethereum address to receive withdrawn ERC20 tokens
creationuint256Timestamp of when requestion was created RESTRICTION FEATURE
nonceuint256Vega-assigned single-use number that provides replay attack protection
signaturesbytesVega-supplied signature bundle of a validator-signed order

deposit_asset

This function allows a user to deposit given ERC20 tokens into Vegaemits Asset_Deposited if successful

function deposit_asset(address asset_source, uint256 amount, bytes32 vega_public_key) public nonpayable

Arguments

NameTypeDescription
asset_sourceaddressContract address for given ERC20 token
amountuint256Amount of tokens to be deposited into Vega
vega_public_keybytes32Target Vega public key to be credited with this deposit

is_asset_listed

This view returns true if the given ERC20 token contract has been listed valid for deposit

function is_asset_listed(address asset_source) public view
returns(bool)

Returns

True if asset is listed

Arguments

NameTypeDescription
asset_sourceaddressContract address for given ERC20 token

get_multisig_control_address

function get_multisig_control_address() public view
returns(address)

Returns

current multisig_control_address

Arguments

NameTypeDescription

get_vega_asset_id

function get_vega_asset_id(address asset_source) public view
returns(bytes32)

Returns

The assigned Vega Asset Id for given ERC20 token

Arguments

NameTypeDescription
asset_sourceaddressContract address for given ERC20 token

get_asset_source

function get_asset_source(bytes32 vega_asset_id) public view
returns(address)

Returns

The ERC20 token contract address for a given Vega Asset Id

Arguments

NameTypeDescription
vega_asset_idbytes32Vega-assigned asset ID for which you want the ERC20 token address