Skip to content

Commit 3d358a4

Browse files
committed
add predeployed ERC20 token for benchmarking
- Add BenchmarkToken contract (BENCH) predeployed at 0xB0B5... - Include compiled bytecode and storage in genesis.json - Fix ToWei function decimal conversion bug - EWOQ address holds 100M token supply
1 parent 509a20d commit 3d358a4

4 files changed

Lines changed: 80 additions & 23 deletions

File tree

contracts/BenchmarkToken.sol

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
/**
5+
* @title BenchmarkToken
6+
* @dev Minimal ERC20 implementation for benchmarking. No constructor needed as state is set in genesis.
7+
* Storage layout:
8+
* - Slot 0: _balances mapping
9+
* - Slot 1: _allowances mapping
10+
* - Slot 2: _totalSupply
11+
*/
12+
contract BenchmarkToken {
13+
mapping(address => uint256) private _balances;
14+
mapping(address => mapping(address => uint256)) private _allowances;
15+
uint256 private _totalSupply;
16+
17+
event Transfer(address indexed from, address indexed to, uint256 value);
18+
event Approval(address indexed owner, address indexed spender, uint256 value);
19+
20+
function name() public pure returns (string memory) {
21+
return "Benchmark Token";
22+
}
23+
24+
function symbol() public pure returns (string memory) {
25+
return "BENCH";
26+
}
27+
28+
function decimals() public pure returns (uint8) {
29+
return 18;
30+
}
31+
32+
function totalSupply() public view returns (uint256) {
33+
return _totalSupply;
34+
}
35+
36+
function balanceOf(address account) public view returns (uint256) {
37+
return _balances[account];
38+
}
39+
40+
function transfer(address to, uint256 amount) public returns (bool) {
41+
address owner = msg.sender;
42+
_balances[owner] -= amount;
43+
_balances[to] += amount;
44+
emit Transfer(owner, to, amount);
45+
return true;
46+
}
47+
48+
function allowance(address owner, address spender) public view returns (uint256) {
49+
return _allowances[owner][spender];
50+
}
51+
52+
function approve(address spender, uint256 amount) public returns (bool) {
53+
_allowances[msg.sender][spender] = amount;
54+
emit Approval(msg.sender, spender, amount);
55+
return true;
56+
}
57+
58+
function transferFrom(address from, address to, uint256 amount) public returns (bool) {
59+
_allowances[from][msg.sender] -= amount;
60+
_balances[from] -= amount;
61+
_balances[to] += amount;
62+
emit Transfer(from, to, amount);
63+
return true;
64+
}
65+
}

genesis.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
"alloc": {
1616
"8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC": {
1717
"balance": "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
18+
},
19+
"B0B5B0B5B0B5B0B5B0B5B0B5B0B5B0B5B0B5B0B5": {
20+
"balance": "0x0",
21+
"code": "0x608060405234801561000f575f5ffd5b5060043610610090575f3560e01c8063313ce56711610063578063313ce5671461011957806370a082311461012857806395d89b4114610150578063a9059cbb14610171578063dd62ed3e14610184575f5ffd5b806306fdde0314610094578063095ea7b3146100d157806318160ddd146100f457806323b872dd14610106575b5f5ffd5b60408051808201909152600f81526e2132b731b436b0b935902a37b5b2b760891b60208201525b6040516100c891906103ad565b60405180910390f35b6100e46100df3660046103fd565b6101bc565b60405190151581526020016100c8565b6002545b6040519081526020016100c8565b6100e4610114366004610425565b610228565b604051601281526020016100c8565b6100f861013636600461045f565b6001600160a01b03165f9081526020819052604090205490565b6040805180820190915260058152640848a9c86960db1b60208201526100bb565b6100e461017f3660046103fd565b610312565b6100f861019236600461047f565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b335f8181526001602090815260408083206001600160a01b038716808552925280832085905551919290917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925906102169086815260200190565b60405180910390a35060015b92915050565b6001600160a01b0383165f90815260016020908152604080832033845290915281208054839190839061025c9084906104c4565b90915550506001600160a01b0384165f90815260208190526040812080548492906102889084906104c4565b90915550506001600160a01b0383165f90815260208190526040812080548492906102b49084906104d7565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161030091815260200190565b60405180910390a35060019392505050565b335f818152602081905260408120805491929184919084906103359084906104c4565b90915550506001600160a01b0384165f90815260208190526040812080548592906103619084906104d7565b92505081905550836001600160a01b0316816001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8560405161030091815260200190565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b80356001600160a01b03811681146103f8575f5ffd5b919050565b5f5f6040838503121561040e575f5ffd5b610417836103e2565b946020939093013593505050565b5f5f5f60608486031215610437575f5ffd5b610440846103e2565b925061044e602085016103e2565b929592945050506040919091013590565b5f6020828403121561046f575f5ffd5b610478826103e2565b9392505050565b5f5f60408385031215610490575f5ffd5b610499836103e2565b91506104a7602084016103e2565b90509250929050565b634e487b7160e01b5f52601160045260245ffd5b81810381811115610222576102226104b0565b80820180821115610222576102226104b056fea264697066735822122071ad18298e7f4d2994c942653d84907923eb80ff2123ac979e21fed08757929264736f6c634300081d0033",
22+
"storage": {
23+
"0x8752f2ce489c60adfebb82af1ee397b7cda0e7af19fe4d57af54dd0cbf417866": "0x00000000000000000000000000000000000000000052b7d2dcc80cd2e4000000",
24+
"0x0000000000000000000000000000000000000000000000000000000000000002": "0x00000000000000000000000000000000000000000052b7d2dcc80cd2e4000000"
25+
}
1826
}
1927
},
2028
"nonce": "0x0",

internal/bombard/fund.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const EwoqAddress = "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC"
2020

2121
// PredeployedTokenAddress is the address of the predeployed ERC20 "Benchmark Token" (BENCH)
2222
// in the default subnet-evm genesis. The ewoq address holds the entire 100M token supply.
23-
const PredeployedTokenAddress = "0x0200000000000000000000000000000000000001"
23+
const PredeployedTokenAddress = "0xB0B5B0B5B0B5B0B5B0B5B0B5B0B5B0B5B0B5B0B5"
2424

2525
func fundAccounts(client *ethclient.Client, listener *TxListener, keys []*Key) error {
2626
ewoqKey, err := crypto.HexToECDSA(ewoqPrivateKey)

internal/bombard/utils.go

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,18 @@
11
package bombard
22

33
import (
4-
"fmt"
54
"math/big"
6-
"strings"
75

86
"github.com/ava-labs/libevm/common"
97
)
108

11-
// ToWei converts a float amount to wei (18 decimals).
9+
// ToWei converts a whole token amount to wei (18 decimals).
10+
// E.g., ToWei(100) returns 100 * 10^18.
1211
func ToWei(amount float64) *big.Int {
13-
const decimals = 18
14-
15-
wei := new(big.Int)
16-
17-
// Convert float to string with maximum precision
18-
amountStr := fmt.Sprintf("%.18f", amount)
19-
20-
// Remove decimal point and trailing zeros
21-
amountStr = strings.Replace(amountStr, ".", "", 1)
22-
amountStr = strings.TrimRight(amountStr, "0")
23-
24-
// Parse string to big.Int
25-
wei.SetString(amountStr, 10)
26-
27-
// Adjust for decimals
28-
multiplier := new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(decimals)), nil)
29-
wei.Mul(wei, multiplier)
30-
31-
return wei
12+
// For whole numbers, simply multiply by 10^18
13+
multiplier := new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)
14+
result := new(big.Int).SetInt64(int64(amount))
15+
return result.Mul(result, multiplier)
3216
}
3317

3418
// ERC20TransferSelector is the function selector for transfer(address,uint256)

0 commit comments

Comments
 (0)