Geode Finance
Search…
⌃K

Case Study: ERC20Interface

Your Favorite ERC1155 token acting like it is ERC20!

Important changes to the ERC20 implementation

ERC20Interface will be using the balance info coming from gAVAX, so there is no _balances

/**
* @dev gAVAX ERC20 interface doesn't use balance info, catches it from ERC1155.
* mapping(address => uint256) private _balances;
**/
function _transfer(...) internal virtual {
...
unchecked {
_ERC1155.safeTransferFrom(sender,recipient,_id,amount,"0x00");
}
...
}

There is also a function for pricePerShare, so it is easy for any code to keep track of underlying AVAX balances.

function pricePerShare() public view returns(uint){
return _ERC1155.pricePerShare(_id);
}

Balance info of used ID's ERC20interface will show the gAVAX balance info.

function balanceOf(address account) public view virtual override returns (uint256) {
return _ERC1155.balanceOf(account,_id);
}

TotalSupply info of used ID's ERC20interface will show the gAVAX totalSupply info.

/**
* @dev gAVAX ERC20 interface doesn't use totalSupply info, catches it from ERC1155.
* uint256 private _totalSupply;
**/
function totalSupply() public view virtual override returns (uint256) {
return _ERC1155.totalSupply(_id);
}
Note, these codes should NOT be used in production.

​See it on Github.​