ERC20 Bank Berachain β
The ERC20 Bank precompile serves as an interface to Berachainβs ERC20 Bank module. It is designed to facilitate the conversion between ERC20 tokens and Cosmos coins within the Cosmos ecosystem. It allows users to transfer tokens between the two formats and provides a seamless way to interact with both types of assets.
The IERC20BankModule interface defines several events, such as TransferCoinToErc20and TransferErc20ToCoin, which are emitted when specific actions occur within the module. These events help track the movement of tokens and provide transparency for users and developers.
The interface also includes read methods, such as coinDenomForERC20Address and erc20AddressForCoinDenom, which allow users to query the corresponding Cosmos coin denomination for a given ERC20 token address and vice versa.
Additionally, the interface provides write methods for transferring tokens between ERC20 and Cosmos coins. These methods enable users to transfer tokens between their own accounts or between different accounts, depending on the specific method used.
Lastly, the performBankTransfer method allows BERC20 contracts to perform bank transfers between two addresses, enabling seamless integration with the Cosmos bank module.
In summary, the IERC20BankModule Interface enables developers and users to interact with both ERC20 tokens and Cosmos coins within the Cosmos ecosystem. It provides a set of methods for transferring tokens between the two formats, querying the corresponding assets, and performing bank transfers, making it a valuable tool for managing and interacting with digital assets in the Cosmos ecosystem.
Note: Link to existing contract ABI's can be found on Github here.
Interface of berachain's erc20 bank module's precompiled contract
Functions β
coinDenomForERC20Address β
coinDenomForERC20Address returns the SDK coin denomination for the given ERC20 address.
function coinDenomForERC20Address(IERC20 token) external view returns (string memory);
function coinDenomForERC20Address(IERC20 token) external view returns (string memory);
Parameters
Name | Type | Description |
---|---|---|
token | IERC20 | the ERC20 token being queried for |
erc20AddressForCoinDenom β
erc20AddressForCoinDenom returns the ERC20 address for the given SDK coin denomination.
function erc20AddressForCoinDenom(string calldata denom) external view returns (IERC20);
function erc20AddressForCoinDenom(string calldata denom) external view returns (IERC20);
Parameters
Name | Type | Description |
---|---|---|
denom | string | the denomination of the SDK coin being queried for |
transferCoinToERC20 β
transferCoinToERC20 transfers amount
SDK coins to ERC20 tokens for msg.sender
function transferCoinToERC20(string calldata denom, uint256 amount) external returns (bool);
function transferCoinToERC20(string calldata denom, uint256 amount) external returns (bool);
Parameters
Name | Type | Description |
---|---|---|
denom | string | the denomination of the SDK coin being transferred from |
amount | uint256 | the amount of coins to transfer |
transferCoinToERC20From β
transferCoinToERC20From transfers amount
SDK coins to ERC20 tokens from owner
to recipient
function transferCoinToERC20From(string calldata denom, address owner, address recipient, uint256 amount)
external
returns (bool);
function transferCoinToERC20From(string calldata denom, address owner, address recipient, uint256 amount)
external
returns (bool);
Parameters
Name | Type | Description |
---|---|---|
denom | string | the denomination of the SDK coin being transferred from |
owner | address | the address of the owner of the coins |
recipient | address | the address of the recipient of the tokens |
amount | uint256 | the amount of coins to transfer |
transferCoinToERC20To β
transferCoinToERC20To transfers amount
SDK coins to ERC20 tokens from msg.sender
to recipient
function transferCoinToERC20To(string calldata denom, address recipient, uint256 amount) external returns (bool);
function transferCoinToERC20To(string calldata denom, address recipient, uint256 amount) external returns (bool);
Parameters
Name | Type | Description |
---|---|---|
denom | string | the denomination of the SDK coin being transferred from |
recipient | address | the address of the recipient of the tokens |
amount | uint256 | the amount of coins to transfer |
transferERC20ToCoin β
transferERC20ToCoin transfers amount
ERC20 tokens to SDK coins for msg.sender
function transferERC20ToCoin(IERC20 token, uint256 amount) external returns (bool);
function transferERC20ToCoin(IERC20 token, uint256 amount) external returns (bool);
Parameters
Name | Type | Description |
---|---|---|
token | IERC20 | the ERC20 token being transferred from |
amount | uint256 | the amount of tokens to transfer |
transferERC20ToCoinFrom β
transferERC20ToCoinFrom transfers amount
ERC20 tokens to SDK coins from owner
to recipient
function transferERC20ToCoinFrom(IERC20 token, address owner, address recipient, uint256 amount)
external
returns (bool);
function transferERC20ToCoinFrom(IERC20 token, address owner, address recipient, uint256 amount)
external
returns (bool);
Parameters
Name | Type | Description |
---|---|---|
token | IERC20 | the ERC20 token being transferred from |
owner | address | the address of the owner of the coins |
recipient | address | the address of the recipient of the tokens |
amount | uint256 | the amount of tokens to transfer |
transferERC20ToCoinTo β
transferERC20ToCoinTo transfers amount
ERC20 tokens to SDK coins from msg.sender
to recipient
function transferERC20ToCoinTo(IERC20 token, address recipient, uint256 amount) external returns (bool);
function transferERC20ToCoinTo(IERC20 token, address recipient, uint256 amount) external returns (bool);
Parameters
Name | Type | Description |
---|---|---|
token | IERC20 | the ERC20 token being transferred from |
recipient | address | the address of the recipient of the tokens |
amount | uint256 | the amount of tokens to transfer |
performBankTransfer β
it is assumed msg.sender
is a BeraERC20 contract.
performBankTransfer performs a bank module transfer.
function performBankTransfer(address owner, address recipient, uint256 amount) external returns (bool);
function performBankTransfer(address owner, address recipient, uint256 amount) external returns (bool);
Parameters
Name | Type | Description |
---|---|---|
owner | address | the user who is getting their balance decreased. |
recipient | address | the user who is gettting their balance increased. |
amount | uint256 | the amount of coins to transfer. |
Events β
TransferCoinToErc20 β
Emitted by the erc20 bank module when coins (coinSent
) are transferred from SDK coin to an ERC20 token
from owner
to recipient
.
event TransferCoinToErc20(
address indexed token, address indexed owner, address indexed recipient, Cosmos.Coin coinSent
);
event TransferCoinToErc20(
address indexed token, address indexed owner, address indexed recipient, Cosmos.Coin coinSent
);
Parameters
Name | Type | Description |
---|---|---|
token | address | the ERC20 token being transferred to |
owner | address | the address of the owner of the coins |
recipient | address | the address of the recipient of the tokens |
coinSent | Cosmos.Coin | the amount of coins sent (in the sent SDK Coin denomination) |
TransferErc20ToCoin β
Emitted by the erc20 bank module when ERC20 token
is transferred to an SDK coin (coinReceived
) from owner
to recipient
.
event TransferErc20ToCoin(
address indexed token, address indexed owner, address indexed recipient, Cosmos.Coin coinReceived
);
event TransferErc20ToCoin(
address indexed token, address indexed owner, address indexed recipient, Cosmos.Coin coinReceived
);
Parameters
Name | Type | Description |
---|---|---|
token | address | the ERC20 token being transferred from |
owner | address | the address of the owner of the tokens |
recipient | address | the address of the recipient of the coins |
coinReceived | Cosmos.Coin | the amount of coins received (in the received SDK Coin denomination) |
Erc20CreatedFromCoin β
Emitted by the erc20 bank module when a coin is first transferred to ERC20, a new ERC20 token is deployed, and the ERC20 mapping is instantiated.
event Erc20CreatedFromCoin(address indexed token, string denom);
event Erc20CreatedFromCoin(address indexed token, string denom);
Parameters
Name | Type | Description |
---|---|---|
token | address | the address of the newly deployed ERC20 token |
denom | string | the denomination of the SDK coin being transferred from |
CoinCreatedFromErc20 β
Emitted by the erc20 bank module when an ERC20 token is first transferred to coin, and the coin mapping is instantiated.
event CoinCreatedFromErc20(address indexed token, string denom);
event CoinCreatedFromErc20(address indexed token, string denom);
Parameters
Name | Type | Description |
---|---|---|
token | address | the address of the ERC20 token being transferred from |
denom | string | the denomination of the newly created SDK coin |