-
Notifications
You must be signed in to change notification settings - Fork 91
feat(precompiles): erc20 factory precompile #405
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
base: main
Are you sure you want to change the base?
feat(precompiles): erc20 factory precompile #405
Conversation
Hey @GuillemGarciaDev looks like we have some solidity tests failing from these changes |
# Conflicts: # local_node.sh # precompiles/common/interfaces.go
Fixes applied! They should pass now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, looks great! I do have a couple nits and comments, though. After you look at those, we should be good to finally merge :)
*/ | ||
event Create( | ||
address indexed tokenAddress, | ||
uint8 tokenPairType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain what this is and why it's needed? If I understand correctly, this is the ownership type, but we seem to always set this to externally owned. If it's something different, can you link this in the docs?
return nil, err | ||
} | ||
|
||
address := crypto.CreateAddress2(caller, salt, calculateCodeHash(tokenType)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a sanity check, could we also make sure that there's no contract storage/hash at the address? Probably fine here regardless, but would be good to verify
errContains: "invalid premintedSupply", | ||
}, | ||
{ | ||
name: "fail - invalid number of arguments", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a test here that checks that blocked addresses (like module addresses) cannot receive the tokens?
} | ||
|
||
symbol, ok = args[3].(string) | ||
if !ok || len(symbol) < 3 || len(symbol) > 16 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should allow the symbol to be 1 character. There are cases like this in production already, like Sonic's $S.
uint8(0), | ||
[32]uint8{}, | ||
name, | ||
"is", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be a valid symbol, nothing in the bank metadata validation prevents symbols of under 3 characters to be added.
Description
This PR implements event emission functionality for the ERC20 Factory precompile and fixes critical issues with event topic handling.
ERC20 Factory Precompile Overview
The ERC20 Factory precompile is a precompile deployed at address
0x0000000000000000000000000000000000000900
that enables deterministic creation of ERC20 token pairs. It provides a factory pattern for deploying ERC20 tokens with predictable addresses.Core Functionality
The precompile bridges Ethereum-style ERC20 tokens with Cosmos SDK's bank module, automatically:
Available Methods
1.
create(uint8 tokenPairType, bytes32 salt, string name, string symbol, uint8 decimals) → address
Transaction Method | Gas Cost: 3,000,000
Creates a new ERC20 token pair and returns the deployed contract address.
Parameters:
tokenPairType
: Type identifier for the token pair (uint8)salt
: 32-byte salt for deterministic address generationname
: Token name (3-128 characters)symbol
: Token symbol (3-16 characters)decimals
: Number of decimal places (uint8)Process:
Create
event2.
calculateAddress(uint8 tokenPairType, bytes32 salt) → address
View Method | Gas Cost: 3,000
Calculates the deterministic address where a token would be deployed without actually creating it.
Parameters:
tokenPairType
: Type identifier for the token pairsalt
: 32-byte salt for address calculationReturns: The calculated contract address using CREATE2 formula
Events Emitted
Create(address indexed tokenAddress, uint8 tokenPairType, bytes32 salt, string name, string symbol, uint8 decimals)
Emitted when a new ERC20 token pair is successfully created.
Indexed Parameters:
tokenAddress
: Address of the deployed token contractNon-Indexed Parameters:
tokenPairType
: Type identifier used during creationsalt
: Salt value used for deterministic deploymentname
: Token namesymbol
: Token symboldecimals
: Decimal precisionIntegration with Cosmos SDK
The precompile seamlessly integrates with multiple Cosmos SDK modules:
Critical Files to Review
precompiles/erc20factory/events.go
- Core event emission logicprecompiles/erc20factory/types.go
- Event struct definitionsprecompiles/erc20factory/tx.go
- Integration with Create methodtests/integration/precompiles/erc20factory/test_events.go
- Go test coveragetests/solidity/suites/precompiles/test/erc20factory.js
- JavaScript test coverageCloses: #XXXX
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
main
branchReviewers Checklist
All items are required.
Please add a note if the item is not applicable
and please add your handle next to the items reviewed
if you only reviewed selected items.
I have...
Unreleased
section inCHANGELOG.md