Skip to content

Commit

Permalink
chore: nit
Browse files Browse the repository at this point in the history
  • Loading branch information
leovct committed Oct 4, 2023
1 parent 7ca3a9f commit ebddf14
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
40 changes: 21 additions & 19 deletions cmd/loadtest/uniswapv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,31 +279,33 @@ func deployUniswapV3(ctx context.Context, c *ethclient.Client, tops *bind.Transa
return config, err
}

// TODO: This is a hack, it should be done differently.
// The NFTPositionDescriptor contract relies on the NFTDescriptor library.
// When compiling NFTPositionDescriptor, we need to deploy the NFTDescriptor
// library to a temporary chain first and link its address in NFTPositionDescriptor
// bytecode. The problem is that we shut down this temporary chain so we redeploy the library
// when running the load tests but the address of the library has changed. This hack enables us
// to modify the bytecode of NFTPositionDescriptor to point to the new address of
// the library.
oldAddressFmt := strings.TrimPrefix(strings.ToLower(oldNFTPositionLibraryAddress.String()), "0x")
newAddressFmt := strings.TrimPrefix(strings.ToLower(config.NFTDescriptorLib.Address.String()), "0x")
newNFTPositionDescriptorBin := strings.ReplaceAll(uniswapv3.NFTPositionDescriptorMetaData.Bin, oldAddressFmt, newAddressFmt)
if uniswapv3.NFTPositionDescriptorMetaData.Bin == newNFTPositionDescriptorBin {
err = fmt.Errorf("the NFTPositionDescriptor bytecode has not been updated")
log.Error().Err(err).Msg("NFTPositionDescriptor bytecode has not been updated")
return config, err
}
log.Debug().Interface("oldAddress", oldNFTPositionLibraryAddress).Interface("newAddress", config.NFTDescriptorLib.Address).Msg("NFTPositionDescriptor bytecode updated with the new NFTDescriptor library address")

// 7. Deploy NFTPositionDescriptor.
config.NFTPositionDescriptor.Address, config.NFTPositionDescriptor.contract, err = deployOrInstantiateContract(
ctx, c, tops, cops, "NFTPositionDescriptor", knownAddresses.NFTPositionDescriptor,
func(*bind.TransactOpts, bind.ContractBackend) (common.Address, *types.Transaction, *uniswapv3.NFTPositionDescriptor, error) {
// Update NFTPositionDescriptor bytecode.
// TODO: This is a hack, it should be done differently.
// The NFTPositionDescriptor contract relies on the NFTDescriptor library.
// When compiling NFTPositionDescriptor, we need to deploy the NFTDescriptor
// library to a temporary chain first and link its address in NFTPositionDescriptor
// bytecode. The problem is that we shut down this temporary chain so we redeploy the library
// when running the load tests but the address of the library has changed. This hack enables us
// to modify the bytecode of NFTPositionDescriptor to point to the new address of
// the library.
oldAddressFmt := strings.TrimPrefix(strings.ToLower(oldNFTPositionLibraryAddress.String()), "0x")
newAddressFmt := strings.TrimPrefix(strings.ToLower(config.NFTDescriptorLib.Address.String()), "0x")
newNFTPositionDescriptorBytecode := strings.ReplaceAll(uniswapv3.NFTPositionDescriptorMetaData.Bin, oldAddressFmt, newAddressFmt)
if uniswapv3.NFTPositionDescriptorMetaData.Bin == newNFTPositionDescriptorBytecode {
err = fmt.Errorf("the NFTPositionDescriptor bytecode has not been updated")
log.Error().Err(err).Msg("NFTPositionDescriptor bytecode has not been updated")
return common.Address{}, nil, nil, err
}
log.Debug().Interface("oldAddress", oldNFTPositionLibraryAddress).Interface("newAddress", config.NFTDescriptorLib.Address).Msg("NFTPositionDescriptor bytecode updated with the new NFTDescriptor library address")

// Deploy contract.
var nativeCurrencyLabelBytes [32]byte
copy(nativeCurrencyLabelBytes[:], "ETH")
return uniswapv3.DeployNFTPositionDescriptor(tops, c, config.WETH9.Address, nativeCurrencyLabelBytes, newNFTPositionDescriptorBin)
return uniswapv3.DeployNFTPositionDescriptor(tops, c, config.WETH9.Address, nativeCurrencyLabelBytes, newNFTPositionDescriptorBytecode)
},
uniswapv3.NewNFTPositionDescriptor,
func(contract *uniswapv3.NFTPositionDescriptor) (err error) {
Expand Down
4 changes: 2 additions & 2 deletions contracts/uniswapv3/NFTPositionDescriptor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions contracts/uniswapv3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ We'd like to be able to specify the new binary so here's the new function.

```go
// contracts/uniswapv3/NFTPositionDescriptor.sol#L47
func DeployNFTPositionDescriptor(auth *bind.TransactOpts, backend bind.ContractBackend, _WETH9 common.Address, _nativeCurrencyLabelBytes [32]byte, nonfungibleTokenPositionDescriptorNewBin string) (common.Address, *types.Transaction, *NFTPositionDescriptor, error) {
func DeployNFTPositionDescriptor(auth *bind.TransactOpts, backend bind.ContractBackend, _WETH9 common.Address, _nativeCurrencyLabelBytes [32]byte, nonfungibleTokenPositionDescriptorNewBytecode string) (common.Address, *types.Transaction, *NFTPositionDescriptor, error) {
parsed, err := NFTPositionDescriptorMetaData.GetAbi()
if err != nil {
return common.Address{}, nil, nil, err
Expand All @@ -87,7 +87,7 @@ func DeployNFTPositionDescriptor(auth *bind.TransactOpts, backend bind.ContractB
return common.Address{}, nil, nil, errors.New("GetABI returned nil")
}

address, tx, contract, err := bind.DeployContract(auth, *parsed, common.FromHex(nonfungibleTokenPositionDescriptorNewBin), backend, _WETH9, _nativeCurrencyLabelBytes)
address, tx, contract, err := bind.DeployContract(auth, *parsed, common.FromHex(nonfungibleTokenPositionDescriptorNewBytecode), backend, _WETH9, _nativeCurrencyLabelBytes)
if err != nil {
return common.Address{}, nil, nil, err
}
Expand Down

0 comments on commit ebddf14

Please sign in to comment.