Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store denom trace mapping #32

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion contracts/apps/20-transfer/ICS20TransferERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol"
contract ICS20TransferERC20 is ICS20Transfer {
// Map sink denom to ERC20.
mapping(string => ERC20PresetMinterPauser) public denomTokenContract;
// Map denom hash to denom full path
mapping(bytes32 => string) public denomTraces;

constructor(IBCHandler ibcHandler_) ICS20Transfer(ibcHandler_) {
}
Expand All @@ -33,8 +35,14 @@ contract ICS20TransferERC20 is ICS20Transfer {
function _mint(address account, string memory denom, uint256 amount) internal virtual override returns (bool) {
// Deploy an ERC20 contract for each (sink zone) denom seen.
if (address(denomTokenContract[denom]) == address(0)) {
string memory name = string.concat("IBC/", hexEncode(abi.encodePacked(sha256(bytes(denom)))));
bytes32 dh = sha256(bytes(denom));
string memory name = string.concat("IBC/", hexEncode(abi.encodePacked(dh)));
denomTokenContract[denom] = new ERC20PresetMinterPauser(name, "");
// store denomTrace(hash -> denom)
bytes memory denomTrace = bytes(denomTraces[dh]); // Uses memory
if (denomTrace.length == 0) {
denomTraces[dh] = denom;
}
}
denomTokenContract[denom].mint(account, amount);
return true;
Expand Down