feat(precompiles): erc20 factory precompile #405
+1,495
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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