Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion rollup/fees/rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TokenRate(state StateDB, tokenID uint16) (*big.Int, *big.Int, error) {
if tokenID == 0 {
return nil, nil, errors.New("token id 0 not support")
}
info, rate, err := GetTokenInfoFromStorage(state, TokenRegistryAddress, tokenID)
info, rate, err := GetTokenInfoFromStorage(state, tokenID)
if err != nil {
log.Error("Failed to get token info from storage", "tokenID", tokenID, "error", err)
return nil, nil, err
Expand Down
12 changes: 6 additions & 6 deletions rollup/fees/token_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ func CalculateStructFieldSlot(baseSlot common.Hash, fieldOffset uint64) common.H
}

// GetUint256MappingValue retrieves a value from a mapping storage slot
func GetUint256MappingValue(state StateDB, contractAddr common.Address, key uint16, mappingSlot common.Hash) (*big.Int, error) {
func GetUint256MappingValue(state StateDB, key uint16, mappingSlot common.Hash) (*big.Int, error) {
// Calculate the storage slot
storageKey := CalculateUint16MappingSlot(key, mappingSlot)

// Get the value from storage
value := state.GetState(contractAddr, storageKey)
value := state.GetState(TokenRegistryAddress, storageKey)

// Convert hash to big.Int
result := new(big.Int).SetBytes(value[:])
Expand Down Expand Up @@ -162,21 +162,21 @@ func IsTokenActive(state StateDB, tokenID uint16) (bool, error) {
}

// GetTokenPriceByIDWithState retrieves token price ratio from priceRatio mapping
func GetTokenPriceByIDWithState(state StateDB, contractAddr common.Address, tokenID uint16) (*big.Int, error) {
return GetUint256MappingValue(state, contractAddr, tokenID, rcfg.PriceRatioSlot)
func GetTokenPriceByIDWithState(state StateDB, tokenID uint16) (*big.Int, error) {
return GetUint256MappingValue(state, tokenID, rcfg.PriceRatioSlot)
}

// GetTokenInfoFromStorage retrieves token address, price, and balance slot from storage
// This is a convenience function that combines multiple storage reads
func GetTokenInfoFromStorage(state StateDB, contractAddr common.Address, tokenID uint16) (*TokenInfo, *big.Int, error) {
func GetTokenInfoFromStorage(state StateDB, tokenID uint16) (*TokenInfo, *big.Int, error) {
// Get token info from TokenInfo struct
info, err := GetTokenInfo(state, tokenID)
if err != nil {
return nil, nil, fmt.Errorf("failed to get token info: %v", err)
}

// Get token price from priceRatio mapping
price, err := GetTokenPriceByIDWithState(state, contractAddr, tokenID)
price, err := GetTokenPriceByIDWithState(state, tokenID)
if err != nil {
return nil, nil, fmt.Errorf("failed to get token price: %v", err)
}
Expand Down