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

feat(loadtest): uniswapv3 loadtest #137

Merged
merged 189 commits into from
Oct 20, 2023
Merged
Changes from 1 commit
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
62fa6b0
doc: document how to generate new loadtest mode string
leovct Sep 19, 2023
399cc6c
chore: build uniswap v3 contracts
leovct Sep 19, 2023
56d0a5c
chore: remove avail cmds
leovct Sep 19, 2023
62d916e
chore: generate go bindings for uniswap contracts
leovct Sep 19, 2023
46681dd
doc: document how to build uniswap contracts and how to generate go b…
leovct Sep 19, 2023
d1abfca
feat: add uniswap v3 loadtest mode
leovct Sep 19, 2023
69c6ea7
doc: update doc
leovct Sep 19, 2023
ec4f016
chore: define deployment config for uniswap
leovct Sep 19, 2023
752822e
chore: lint
leovct Sep 19, 2023
1dbb6b2
feat: enable 1 bp fee tier
leovct Sep 19, 2023
596adf9
chore: remove unused contracts and deploy multicall
leovct Sep 19, 2023
e079493
feat: deploy ProxyAdmin
leovct Sep 19, 2023
4845b25
chore: clean up
leovct Sep 19, 2023
1fab4dc
chore: make lint
leovct Sep 19, 2023
ffd9f04
feat: deploy TickLens
leovct Sep 19, 2023
f2393a7
chore: minor change
leovct Sep 19, 2023
7b375f2
chore: refactor to use generics
leovct Sep 20, 2023
7539cc5
chore: clean up
leovct Sep 20, 2023
380cb1a
chore: rename lib contract
leovct Sep 20, 2023
04ea6fd
feat: deploy NFTDescriptor and WETH9
leovct Sep 20, 2023
f39503c
feat: deploy TransparentUpgradeableProxy
leovct Sep 20, 2023
8e7e46e
chore: generate NonfungiblePositionManager go binding
leovct Sep 20, 2023
e0b26fe
feat: deploy NonfungiblePositionManager contract
leovct Sep 20, 2023
b15d753
chore: generate go binding for V3Migrator
leovct Sep 20, 2023
da6a379
feat: deploy V3Migrator
leovct Sep 20, 2023
f198cf9
chore: raise geth gas limit and send more funds to the loadtest account
leovct Sep 20, 2023
74f96a8
chore: update build process
leovct Sep 20, 2023
576cd1f
chore: update contract bytecode
leovct Sep 20, 2023
4ab1fde
feat: transfer factory ownership
leovct Sep 20, 2023
3b922ce
chore: generate go binding for UniswapV3Staker
leovct Sep 20, 2023
f90231e
chore: update build process
leovct Sep 20, 2023
71e05d4
fix: build process
leovct Sep 20, 2023
dd8ba18
feat: deploy staker
leovct Sep 20, 2023
b60b661
chore: generate go bindings for QuoterV2
leovct Sep 20, 2023
33245b1
feat: deploy QuoterV2
leovct Sep 20, 2023
dc2cba2
chore: generate go bindings for SwapRouter02
leovct Sep 20, 2023
2ea1130
chore: clean up build process
leovct Sep 20, 2023
d2dc571
chore: update bindings
leovct Sep 20, 2023
15b6176
chore: clean up
leovct Sep 20, 2023
016c709
fix: build issues
leovct Sep 20, 2023
d49b37c
chore: new bytecodes
leovct Sep 20, 2023
5e87cb6
doc: update doc
leovct Sep 20, 2023
8418c09
feat: deploy SwapRouter02
leovct Sep 20, 2023
176ffc7
feat: transfer ProxyAdmin ownership
leovct Sep 20, 2023
8f72995
chore: update debug msgs
leovct Sep 20, 2023
acb0f75
fix: update owner address
leovct Sep 20, 2023
26dfdc0
chore: clean up
leovct Sep 20, 2023
74189d2
chore: forge init
leovct Sep 20, 2023
c8a5802
forge install: forge-std
leovct Sep 20, 2023
573ad78
chore: forge init
leovct Sep 20, 2023
de3d208
forge install: forge-std
leovct Sep 20, 2023
de9267f
chore: add ERC20 contracts
leovct Sep 20, 2023
3591976
fix: remove quotes from ERC20 bytecode
leovct Sep 20, 2023
96b2985
feat: generate go bindings for ERC20
leovct Sep 20, 2023
fd7d5b7
feat: deploy the two ERC20 contracts
leovct Sep 20, 2023
e22c472
feat: approve erc20 spendings
leovct Sep 20, 2023
2a58173
feat: create pool between the erc20 contracts
leovct Sep 20, 2023
6f7fea8
chore: make sure pool is deployed before moving on
leovct Sep 20, 2023
f687992
chore: generate go binding for UniswapV3Pool
leovct Sep 20, 2023
2ef0f6c
feat: initialize, provied liquidity and swap tokens
leovct Sep 20, 2023
b9de3d9
chore: clean up
leovct Sep 20, 2023
c522675
chore: lint
leovct Sep 20, 2023
d3ac524
doc: update `polycli loadtest` doc
leovct Sep 20, 2023
34332cd
fix: build process
leovct Sep 20, 2023
e03575e
chore: update sqrtX96price computation
leovct Sep 20, 2023
9f33d98
chore: refactor
leovct Sep 20, 2023
61e0397
chore: new bytecode
leovct Sep 20, 2023
f09d5b3
chore: remove unused code
leovct Sep 20, 2023
817db0f
chore: minor update to build process
leovct Sep 20, 2023
8249d23
chore: document script
leovct Sep 20, 2023
f57ef32
fix: shadowed vars
leovct Sep 20, 2023
059e47b
chore: test remove artefacts
leovct Sep 20, 2023
3e748d6
chore: nit
leovct Sep 20, 2023
77cc519
chore: only upload relevant v3-core contracts
leovct Sep 20, 2023
f696882
chore: remove all v3-periphery contracts
leovct Sep 20, 2023
7705aea
chore: upload only relevant v3-periphery contracts
leovct Sep 20, 2023
31b3eec
chore: remove the rest of the contracts
leovct Sep 20, 2023
7c64c02
chore: only upload relevant contracts
leovct Sep 20, 2023
b51c1a3
chore: update bytecode
leovct Sep 20, 2023
a59ac4f
chore: build script name option change
leovct Sep 20, 2023
3984b4a
chore: bindings script nit
leovct Sep 20, 2023
ead8fbd
chore: new bytecode
leovct Sep 20, 2023
8cdd208
chore: refactor
leovct Sep 20, 2023
ca13026
chore: small nits
leovct Sep 20, 2023
0d9dba9
chore: remove unused field
leovct Sep 20, 2023
f52cd77
feat: enable pre-deployed contract mode for uniswap
leovct Sep 21, 2023
59b8299
fix: retrieve pool instead of creating a new one
leovct Sep 21, 2023
4bad8b9
fix: issue with initializing a pool twice
leovct Sep 21, 2023
1424ba6
feat: add loadtest fn
leovct Sep 21, 2023
d45186a
doc: gen
leovct Sep 21, 2023
8841536
chore: make lint
leovct Sep 21, 2023
1945b0c
Merge branch 'main' into feat/uniswap-loadtest
leovct Oct 2, 2023
b8eef8b
chore: `go mod tidy`
leovct Oct 2, 2023
8f2cac5
chore: update ERC20 contract
leovct Oct 3, 2023
aa8641e
chore: generate new bindings for ERC20
leovct Oct 3, 2023
6eb456d
chore: fix some issues with Swapper and ERC20
leovct Oct 3, 2023
783a871
chore: rename ERC20 contract to Swapper
leovct Oct 3, 2023
18cc742
chore: fix the pool initialization issue
leovct Oct 3, 2023
7d70acd
chore: specify the amount of tokens to mint
leovct Oct 3, 2023
10a5ce1
chore: rename contract
leovct Oct 3, 2023
e21b489
chore: update build process
leovct Oct 4, 2023
c81ffca
chore: update `Swapper` contract
leovct Oct 4, 2023
55bb5d9
chore: don't commit tmp/
leovct Oct 4, 2023
531c255
chore: hack to update the NonfungibleTokenPositionDescriptorMetaData …
leovct Oct 4, 2023
ba3039e
chore: document how to update the deploy fn of NFTPositionDescriptor
leovct Oct 4, 2023
7d5ccdd
chore: add a warning in the script
leovct Oct 4, 2023
6a247b1
chore: more debug
leovct Oct 4, 2023
80a69c1
chore: rename TokenA and TokenB into Token0 and Token1
leovct Oct 4, 2023
1c31daf
chore: add debug
leovct Oct 4, 2023
b945031
chore: update debug msgs
leovct Oct 4, 2023
695dc26
feat: move uniswapv3 loadtest to subcommand
leovct Oct 4, 2023
6216001
chore: nits
leovct Oct 4, 2023
50a11b6
chore: remove `fmt.Sprintf()`
leovct Oct 4, 2023
756a9ba
chore: clean up
leovct Oct 4, 2023
be715ee
chore: rename contracts
leovct Oct 4, 2023
df5cd97
chore: update steps
leovct Oct 4, 2023
7ca3a9f
fix: proxy data
leovct Oct 4, 2023
ebddf14
chore: nit
leovct Oct 4, 2023
60f8a5d
chore: clean up
leovct Oct 4, 2023
05cb287
chore: update `uniswapv3` cmd usage
leovct Oct 4, 2023
0b6de0f
Merge branch 'main' into feat/uniswap-loadtest
leovct Oct 5, 2023
78c9a18
chore: update build process
leovct Oct 5, 2023
0f4cec8
chore: update binding process
leovct Oct 5, 2023
94b646d
chore: save nft descriptor lib address to file
leovct Oct 5, 2023
fa1b434
chore: update nftdescriptor lib address
leovct Oct 5, 2023
5d2614d
chore: hack
leovct Oct 5, 2023
835c4b7
fix: issues
leovct Oct 5, 2023
a0958f5
chore: clean up
leovct Oct 6, 2023
70b54b1
chore: diplay tx hashes in trace mode
leovct Oct 10, 2023
30f89db
chore: use swap-router v1.1.0 instead of v1.3.0
leovct Oct 10, 2023
3c4a4a7
Merge branch 'main' into feat/uniswap-loadtest
leovct Oct 12, 2023
ab3dda4
fix: `blockUntilSuccessful` default case return a nil error
leovct Oct 12, 2023
7e3362a
fix: `TransparentUpgradeableProxy` deployment
leovct Oct 12, 2023
4a0decb
chore: nit
leovct Oct 12, 2023
b8a8dc4
chore: solve lint issue
leovct Oct 12, 2023
5ab9ec0
feat: adding more logging
praetoriansentry Oct 16, 2023
e74c21e
refactor: minor changes to the setup
praetoriansentry Oct 17, 2023
b2a3834
chore: nit
leovct Oct 17, 2023
10e0dbe
chore: go mod tidy
leovct Oct 17, 2023
e9985c2
fix: swap issue
leovct Oct 17, 2023
75bbddb
chore: clean up
leovct Oct 18, 2023
77f7755
chore: nit
leovct Oct 18, 2023
3678bed
chore: update help msg
leovct Oct 18, 2023
09a213f
chore: update help msg once again
leovct Oct 18, 2023
8483f50
chore: add fn to validate url
leovct Oct 18, 2023
0d7612a
doc: document swap method
leovct Oct 18, 2023
a411f58
doc: nit
leovct Oct 18, 2023
b166f3a
chore: rename swap method
leovct Oct 18, 2023
ffdb3f1
chore: nit
leovct Oct 18, 2023
2c8f74b
doc: document `createPool`
leovct Oct 18, 2023
68948eb
chore: refactor pool logic
leovct Oct 18, 2023
520361b
chore: swap file
leovct Oct 18, 2023
4013a70
chore: same thing with deloy logic
leovct Oct 18, 2023
ea01a82
chore: same thing with swapper logic
leovct Oct 18, 2023
180e39f
chore: go mod tidy
leovct Oct 18, 2023
adb52a6
chore: clean up loadtest
leovct Oct 18, 2023
c7f184e
chore: nit
leovct Oct 18, 2023
8da3ca1
Merge branch 'main' into jhilliard/feat/uniswap-loadtest
leovct Oct 18, 2023
69c0f66
chore: gen doc
leovct Oct 18, 2023
7dbc5d7
fix: lint issues
leovct Oct 18, 2023
f5b0099
chore: nit
leovct Oct 18, 2023
a8a0b42
chore: more nit
leovct Oct 18, 2023
27dd235
chore: differentiat between local and persistent flags
leovct Oct 18, 2023
4e847e1
chore: gen doc
leovct Oct 18, 2023
702ec59
chore: document `deploy.go`
leovct Oct 19, 2023
4b837fc
chore: nit
leovct Oct 19, 2023
04f3f82
chore: document `pool.go`
leovct Oct 19, 2023
c6c8e74
lint: transform `fmt.Errorf` into `errors.New`
leovct Oct 19, 2023
25ab60d
chore: document `swap.go`
leovct Oct 19, 2023
ba30e53
chore: nit
leovct Oct 19, 2023
6416f62
chore: document `swapper.go`
leovct Oct 19, 2023
560f4ff
chore: nit
leovct Oct 19, 2023
e81e592
doc: document `types.go`
leovct Oct 19, 2023
0985075
chore: remove tx hash logs
leovct Oct 19, 2023
1362e72
chore: nit
leovct Oct 19, 2023
0a44edc
chore: display name of spenders
leovct Oct 19, 2023
4465b22
chore: nit
leovct Oct 19, 2023
d9dc28d
chore: add ERC20 contract name
leovct Oct 19, 2023
3e77e4c
chore: more nit
leovct Oct 19, 2023
250b1dc
chore: update `setUniswapV3Allowances` method
leovct Oct 19, 2023
0e79568
feat: add flag to set the pool fee and the swap amount
leovct Oct 19, 2023
985e848
chore: check pool fees flag
leovct Oct 19, 2023
c3e98f0
chore: nit
leovct Oct 19, 2023
2cd6c51
chore: use fees as percentage as it's easier to type for users
leovct Oct 19, 2023
9583a10
fix: conversion issue
leovct Oct 19, 2023
a29a122
chore: gen-doc
leovct Oct 19, 2023
35986cc
chore: update `Swapper.sol` and specify the amount of token to mint i…
leovct Oct 19, 2023
bc0ec38
chore: lint
leovct Oct 19, 2023
f401890
Merge branch 'main' into jhilliard/feat/uniswap-loadtest
leovct Oct 20, 2023
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
Prev Previous commit
Next Next commit
chore: update setUniswapV3Allowances method
leovct committed Oct 19, 2023

Verified

This commit was signed with the committer’s verified signature.
leovct Léo Vincent
commit 250b1dc7c9468e5f36f093b73fffaa2299cb9275
45 changes: 32 additions & 13 deletions cmd/loadtest/uniswapv3/swapper.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package uniswapv3loadtest
import (
"context"
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -15,7 +16,7 @@ import (

// The amount of token to approve a spender to use on behalf of the token owner.
// We use a very high amount to avoid frequent approval transactions. Don't use in production.
var approvalAmount = big.NewInt(999_999_999_999_999_999)
var allowanceAmount = big.NewInt(999_999_999_999_999_999)

// Deploy an ERC20 token.
func DeployERC20(ctx context.Context, c *ethclient.Client, tops *bind.TransactOpts, cops *bind.CallOpts, uniswapV3Config UniswapV3Config, tokenName string, recipient common.Address, tokenKnownAddress common.Address, blockUntilSuccessful blockUntilSuccessfulFn) (tokenConfig ContractConfig[uniswapv3.Swapper], err error) {
@@ -29,11 +30,11 @@ func DeployERC20(ctx context.Context, c *ethclient.Client, tops *bind.TransactOp
func(contract *uniswapv3.Swapper) error {
// After the contract has been deployed, we autorize a few UniswapV3 addresses to spend those ERC20 tokens.
// This is required to be able to perform swaps later.
addressesToApprove := map[string]common.Address{
uniswapV3Addresses := map[string]common.Address{
"NFTPositionManager": uniswapV3Config.NonfungiblePositionManager.Address,
"SwapRouter02": uniswapV3Config.SwapRouter02.Address,
}
return approveSwapperSpendingsByUniswap(ctx, c, contract, tops, cops, tokenName, addressesToApprove, recipient, blockUntilSuccessful)
return setUniswapV3Allowances(ctx, c, contract, tops, cops, tokenName, uniswapV3Addresses, recipient, blockUntilSuccessful)
},
blockUntilSuccessful,
)
@@ -43,35 +44,53 @@ func DeployERC20(ctx context.Context, c *ethclient.Client, tops *bind.TransactOp
return
}

// Approve a slice of addresses to spend tokens on behalf of the token owner.
func approveSwapperSpendingsByUniswap(ctx context.Context, c *ethclient.Client, contract *uniswapv3.Swapper, tops *bind.TransactOpts, cops *bind.CallOpts, tokenName string, addresses map[string]common.Address, owner common.Address, blockUntilSuccessful blockUntilSuccessfulFn) error {
var err error
for spenderName, address := range addresses {
// Approve some UniswapV3 addresses to spend tokens on behalf of the token owner.
func setUniswapV3Allowances(ctx context.Context, c *ethclient.Client, contract *uniswapv3.Swapper, tops *bind.TransactOpts, cops *bind.CallOpts, tokenName string, addresses map[string]common.Address, owner common.Address, blockUntilSuccessful blockUntilSuccessfulFn) error {
// Get the ERC20 contract name.
erc20Name, err := contract.Name(cops)
if err != nil {
return err

}

for spenderName, spenderAddress := range addresses {
// Approve the spender to spend the tokens on behalf of the owner.
if _, err = contract.Approve(tops, address, approvalAmount); err != nil {
log.Error().Err(err).Interface("address", address).Msg("Unable to set the allowance")
if _, err = contract.Approve(tops, spenderAddress, allowanceAmount); err != nil {
log.Error().Err(err).
Str("tokenName", fmt.Sprintf("%s_%s", erc20Name, tokenName)).
Interface("spenderAddress", spenderAddress).Str("spenderName", spenderName).
Interface("amount", allowanceAmount).
Msg("Unable to set the allowance")
return err
}

// Check that the allowance is set.
err = blockUntilSuccessful(ctx, c, func() (err error) {
allowance, err := contract.Allowance(cops, owner, address)
allowance, err := contract.Allowance(cops, owner, spenderAddress)
if err != nil {
return err
}
if allowance.Cmp(big.NewInt(0)) == 0 { // allowance == 0
return errors.New("allowance is set to zero")
}
if allowance.Cmp(approvalAmount) == -1 { // allowance < approvalAmount
if allowance.Cmp(allowanceAmount) == -1 { // allowance < allowanceAmount
return errors.New("allowance has not been set properly")
}
return nil
})
if err != nil {
log.Error().Err(err).Msg("Unable to verify that the allowance has been set")
log.Error().Err(err).
Str("tokenName", fmt.Sprintf("%s_%s", erc20Name, tokenName)).
Interface("spenderAddress", spenderAddress).Str("spenderName", spenderName).
Interface("amount", allowanceAmount).
Msg("Unable to verify that the allowance has been set")
return err
} else {
log.Debug().Str("tokenName", tokenName).Interface("spenderAddress", address).Str("spenderName", spenderName).Interface("amount", approvalAmount).Msg("Allowance set")
log.Debug().
Str("tokenName", fmt.Sprintf("%s_%s", erc20Name, tokenName)).
Interface("spenderAddress", spenderAddress).Str("spenderName", spenderName).
Interface("amount", allowanceAmount).
Msg("Allowance set")
}
}
return nil