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

chore: update contracts #151

Closed
wants to merge 21 commits into from
Closed
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
16 changes: 16 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[submodule "contracts/lib/forge-std"]
path = contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std

# openzeppelin
[submodule "contracts/lib/openzeppelin-contracts"]
path = contracts/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "contracts/lib/openzeppelin-contracts-v3.4.1-solc-0.7-2"]
path = contracts/lib/openzeppelin-contracts-v3.4.1-solc-0.7-2
url = https://github.com/OpenZeppelin/openzeppelin-contracts

# weth9
[submodule "contracts/lib/canonical-weth"]
path = contracts/lib/canonical-weth
url = https://github.com/gnosis/canonical-weth
60 changes: 20 additions & 40 deletions cmd/loadtest/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import (
"time"

uniswapv3loadtest "github.com/maticnetwork/polygon-cli/cmd/loadtest/uniswapv3"
"github.com/maticnetwork/polygon-cli/contracts"
"github.com/maticnetwork/polygon-cli/contracts/tokens"
"github.com/maticnetwork/polygon-cli/contracts/src/loadtester"
"github.com/maticnetwork/polygon-cli/contracts/src/tokens"

"github.com/maticnetwork/polygon-cli/metrics"
"github.com/maticnetwork/polygon-cli/rpctypes"
"github.com/maticnetwork/polygon-cli/util"

Expand Down Expand Up @@ -472,7 +471,7 @@ func mainLoop(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client) erro

// deploy and instantiate the load tester contract
var ltAddr ethcommon.Address
var ltContract *contracts.LoadTester
var ltContract *loadtester.LoadTester
if anyModeRequiresLoadTestContract(ltp.ParsedModes) || *inputLoadTestParams.ForceContractDeploy {
ltAddr, ltContract, err = getLoadTestContract(ctx, c, tops, cops)
if err != nil {
Expand Down Expand Up @@ -659,19 +658,19 @@ func mainLoop(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client) erro
return nil
}

func getLoadTestContract(ctx context.Context, c *ethclient.Client, tops *bind.TransactOpts, cops *bind.CallOpts) (ltAddr ethcommon.Address, ltContract *contracts.LoadTester, err error) {
func getLoadTestContract(ctx context.Context, c *ethclient.Client, tops *bind.TransactOpts, cops *bind.CallOpts) (ltAddr ethcommon.Address, ltContract *loadtester.LoadTester, err error) {
ltAddr = ethcommon.HexToAddress(*inputLoadTestParams.LtAddress)

if *inputLoadTestParams.LtAddress == "" {
ltAddr, _, _, err = contracts.DeployLoadTester(tops, c)
ltAddr, _, _, err = loadtester.DeployLoadTester(tops, c)
if err != nil {
log.Error().Err(err).Msg("Failed to create the load testing contract. Do you have the right chain id? Do you have enough funds?")
return
}
}
log.Trace().Interface("contractaddress", ltAddr).Msg("Load test contract address")

ltContract, err = contracts.NewLoadTester(ltAddr, c)
ltContract, err = loadtester.NewLoadTester(ltAddr, c)
if err != nil {
log.Error().Err(err).Msg("Unable to instantiate new contract")
return
Expand All @@ -685,15 +684,13 @@ func getLoadTestContract(ctx context.Context, c *ethclient.Client, tops *bind.Tr
}
func getERC20Contract(ctx context.Context, c *ethclient.Client, tops *bind.TransactOpts, cops *bind.CallOpts) (erc20Addr ethcommon.Address, erc20Contract *tokens.ERC20, err error) {
erc20Addr = ethcommon.HexToAddress(*inputLoadTestParams.ERC20Address)
shouldMint := false
if *inputLoadTestParams.ERC20Address == "" {
erc20Addr, _, _, err = tokens.DeployERC20(tops, c, "ERC20TestToken", "T20")
erc20Addr, _, _, err = tokens.DeployERC20(tops, c)
if err != nil {
log.Error().Err(err).Msg("Unable to deploy ERC20 contract")
return
}
// if we're deploying a new ERC 20 we should mint tokens
shouldMint = true
// Tokens are minted and sent to the deployer's address by default.
}
log.Trace().Interface("contractaddress", erc20Addr).Msg("ERC20 contract address")

Expand All @@ -703,23 +700,6 @@ func getERC20Contract(ctx context.Context, c *ethclient.Client, tops *bind.Trans
return
}

err = blockUntilSuccessful(ctx, c, func() error {
_, err = erc20Contract.BalanceOf(cops, *inputLoadTestParams.FromETHAddress)
return err
})
if err != nil {
return
}

if !shouldMint {
return
}
_, err = erc20Contract.Mint(tops, metrics.UnitMegaether)
if err != nil {
log.Error().Err(err).Msg("There was an error minting ERC20")
return
}

err = blockUntilSuccessful(ctx, c, func() error {
var balance *big.Int
balance, err = erc20Contract.BalanceOf(cops, *inputLoadTestParams.FromETHAddress)
Expand Down Expand Up @@ -923,10 +903,10 @@ func loadTestDeploy(ctx context.Context, c *ethclient.Client, nonce uint64) (t1
defer func() { t2 = time.Now() }()
if *ltp.CallOnly {
msg := transactOptsToCallMsg(tops)
msg.Data = ethcommon.FromHex(contracts.LoadTesterMetaData.Bin)
msg.Data = ethcommon.FromHex(loadtester.LoadTesterMetaData.Bin)
_, err = c.CallContract(ctx, msg, nil)
} else {
_, _, _, err = contracts.DeployLoadTester(tops, c)
_, _, _, err = loadtester.DeployLoadTester(tops, c)
}
return
}
Expand All @@ -939,9 +919,9 @@ func getCurrentLoadTestFunction() uint64 {
if loadTestModeFunction == inputLoadTestParams.Mode {
return *inputLoadTestParams.Function
}
return contracts.GetRandomOPCode()
return loadtester.GetRandomOPCode()
}
func loadTestFunction(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *contracts.LoadTester) (t1 time.Time, t2 time.Time, err error) {
func loadTestFunction(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *loadtester.LoadTester) (t1 time.Time, t2 time.Time, err error) {
ltp := inputLoadTestParams

chainID := new(big.Int).SetUint64(*ltp.ChainID)
Expand All @@ -962,19 +942,19 @@ func loadTestFunction(ctx context.Context, c *ethclient.Client, nonce uint64, lt
if *ltp.CallOnly {
tops.NoSend = true
var tx *ethtypes.Transaction
tx, err = contracts.CallLoadTestFunctionByOpCode(f, ltContract, tops, *iterations)
tx, err = loadtester.CallLoadTestFunctionByOpCode(f, ltContract, tops, *iterations)
if err != nil {
return
}
msg := txToCallMsg(tx)
_, err = c.CallContract(ctx, msg, nil)
} else {
_, err = contracts.CallLoadTestFunctionByOpCode(f, ltContract, tops, *iterations)
_, err = loadtester.CallLoadTestFunctionByOpCode(f, ltContract, tops, *iterations)
}
return
}

func loadTestCallPrecompiledContracts(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *contracts.LoadTester, useSelectedAddress bool) (t1 time.Time, t2 time.Time, err error) {
func loadTestCallPrecompiledContracts(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *loadtester.LoadTester, useSelectedAddress bool) (t1 time.Time, t2 time.Time, err error) {
var f int
ltp := inputLoadTestParams

Expand All @@ -984,7 +964,7 @@ func loadTestCallPrecompiledContracts(ctx context.Context, c *ethclient.Client,
if useSelectedAddress {
f = int(*ltp.Function)
} else {
f = contracts.GetRandomPrecompiledContractAddress()
f = loadtester.GetRandomPrecompiledContractAddress()
}

tops, err := bind.NewKeyedTransactorWithChainID(privateKey, chainID)
Expand All @@ -1000,19 +980,19 @@ func loadTestCallPrecompiledContracts(ctx context.Context, c *ethclient.Client,
if *ltp.CallOnly {
tops.NoSend = true
var tx *ethtypes.Transaction
tx, err = contracts.CallPrecompiledContracts(f, ltContract, tops, *iterations, privateKey)
tx, err = loadtester.CallPrecompiledContracts(f, ltContract, tops, *iterations, privateKey)
if err != nil {
return
}
msg := txToCallMsg(tx)
_, err = c.CallContract(ctx, msg, nil)
} else {
_, err = contracts.CallPrecompiledContracts(f, ltContract, tops, *iterations, privateKey)
_, err = loadtester.CallPrecompiledContracts(f, ltContract, tops, *iterations, privateKey)
}
return
}

func loadTestInc(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *contracts.LoadTester) (t1 time.Time, t2 time.Time, err error) {
func loadTestInc(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *loadtester.LoadTester) (t1 time.Time, t2 time.Time, err error) {
ltp := inputLoadTestParams

chainID := new(big.Int).SetUint64(*ltp.ChainID)
Expand Down Expand Up @@ -1043,7 +1023,7 @@ func loadTestInc(ctx context.Context, c *ethclient.Client, nonce uint64, ltContr
return
}

func loadTestStore(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *contracts.LoadTester) (t1 time.Time, t2 time.Time, err error) {
func loadTestStore(ctx context.Context, c *ethclient.Client, nonce uint64, ltContract *loadtester.LoadTester) (t1 time.Time, t2 time.Time, err error) {
ltp := inputLoadTestParams

chainID := new(big.Int).SetUint64(*ltp.ChainID)
Expand Down
6 changes: 3 additions & 3 deletions cmd/loadtest/uniswapv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
uniswapv3loadtest "github.com/maticnetwork/polygon-cli/cmd/loadtest/uniswapv3"
"github.com/maticnetwork/polygon-cli/contracts/uniswapv3"
tokens "github.com/maticnetwork/polygon-cli/contracts/src/tokens"
"github.com/rs/zerolog/log"
)

Expand Down Expand Up @@ -106,14 +106,14 @@ func initUniswapV3Loadtest(ctx context.Context, c *ethclient.Client, tops *bind.
log.Debug().Interface("addresses", uniswapV3Config.GetAddresses()).Msg("UniswapV3 deployed")

log.Debug().Msg("🪙 Deploying ERC20 tokens...")
var token0 uniswapv3loadtest.ContractConfig[uniswapv3.Swapper]
var token0 uniswapv3loadtest.ContractConfig[tokens.Swapper]
token0, err = uniswapv3loadtest.DeployERC20(
ctx, c, tops, cops, uniswapV3Config, "SwapperA", "SA", uniswapv3loadtest.MintAmount, recipient, common.HexToAddress(*uniswapv3LoadTestParams.UniswapPoolToken0), blockUntilSuccessful)
if err != nil {
return
}

var token1 uniswapv3loadtest.ContractConfig[uniswapv3.Swapper]
var token1 uniswapv3loadtest.ContractConfig[tokens.Swapper]
token1, err = uniswapv3loadtest.DeployERC20(
ctx, c, tops, cops, uniswapV3Config, "SwapperB", "SB", uniswapv3loadtest.MintAmount, recipient, common.HexToAddress(*uniswapv3LoadTestParams.UniswapPoolToken1), blockUntilSuccessful)
if err != nil {
Expand Down
Loading
Loading