Skip to content

Commit

Permalink
Add MockLBTCTokenPool contract and generate gethwrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
rstout committed Dec 6, 2024
1 parent 85fa021 commit e80957c
Show file tree
Hide file tree
Showing 8 changed files with 3,212 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/scripts/native_solc_compile_all_ccip
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ compileContract ccip/test/helpers/receivers/MaybeRevertMessageReceiver.sol
compileContract ccip/test/helpers/MultiOCR3Helper.sol
compileContract ccip/test/mocks/MockE2EUSDCTokenMessenger.sol
compileContract ccip/test/mocks/MockE2EUSDCTransmitter.sol
compileContract ccip/test/mocks/MockLBTCTokenPool.sol
compileContract ccip/test/WETH9.sol


Expand Down
62 changes: 62 additions & 0 deletions contracts/src/v0.8/ccip/test/mocks/MockLBTCTokenPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.24;

import {ITypeAndVersion} from "../../../shared/interfaces/ITypeAndVersion.sol";

import {Pool} from "../../libraries/Pool.sol";
import {TokenPool} from "../../pools/TokenPool.sol";

import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/utils/SafeERC20.sol";


contract MockLBTCTokenPool is TokenPool, ITypeAndVersion {
using SafeERC20 for IERC20;

string public constant override typeAndVersion = "LBTCTokenPool 1.5.1";

constructor(
IERC20 token,
address[] memory allowlist,
address rmnProxy,
address router
) TokenPool(token, 6, allowlist, rmnProxy, router) {
}

/// @notice Burn the token in the pool
/// @dev The _validateLockOrBurn check is an essential security check
function lockOrBurn(
Pool.LockOrBurnInV1 calldata lockOrBurnIn
) external virtual override returns (Pool.LockOrBurnOutV1 memory) {
bytes memory payload;
bytes memory destPoolData;
payload = abi.encodePacked(hex"1234abcd");
destPoolData = abi.encode(sha256(payload));

return
Pool.LockOrBurnOutV1({
destTokenAddress: getRemoteToken(
lockOrBurnIn.remoteChainSelector
),
destPoolData: destPoolData
});
}

function releaseOrMint(
Pool.ReleaseOrMintInV1 calldata releaseOrMintIn
) external virtual override returns (Pool.ReleaseOrMintOutV1 memory) {

// TODO: validate releaseOrMintIn.offchainTokenData?

emit Minted(
msg.sender,
releaseOrMintIn.receiver,
releaseOrMintIn.amount
);

return
Pool.ReleaseOrMintOutV1({
destinationAmount: releaseOrMintIn.amount
});
}
}
3,018 changes: 3,018 additions & 0 deletions core/gethwrappers/ccip/generated/mock_lbtc_token_pool/mock_lbtc_token_pool.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ lock_release_token_pool: ../../../contracts/solc/v0.8.24/LockReleaseTokenPool/Lo
lock_release_token_pool_and_proxy: ../../../contracts/solc/v0.8.24/LockReleaseTokenPoolAndProxy/LockReleaseTokenPoolAndProxy.abi ../../../contracts/solc/v0.8.24/LockReleaseTokenPoolAndProxy/LockReleaseTokenPoolAndProxy.bin e632b08be0fbd1d013e8b3a9d75293d0d532b83071c531ff2be1deec1fa48ec1
maybe_revert_message_receiver: ../../../contracts/solc/v0.8.24/MaybeRevertMessageReceiver/MaybeRevertMessageReceiver.abi ../../../contracts/solc/v0.8.24/MaybeRevertMessageReceiver/MaybeRevertMessageReceiver.bin d73956c26232ebcc4a5444429fa99cbefed960e323be9b5a24925885c2e477d5
message_hasher: ../../../contracts/solc/v0.8.24/MessageHasher/MessageHasher.abi ../../../contracts/solc/v0.8.24/MessageHasher/MessageHasher.bin 0a2661da24147160383ad61d56a258515d1cc07f5e0f471ec5cbb4bccaf82389
mock_lbtc_token_pool: ../../../contracts/solc/v0.8.24/MockLBTCTokenPool/MockLBTCTokenPool.abi ../../../contracts/solc/v0.8.24/MockLBTCTokenPool/MockLBTCTokenPool.bin e7d57c256ca3040a190415eeb89afa5850007635d0c0a9be600a9fbee4fb3fa6
mock_usdc_token_messenger: ../../../contracts/solc/v0.8.24/MockE2EUSDCTokenMessenger/MockE2EUSDCTokenMessenger.abi ../../../contracts/solc/v0.8.24/MockE2EUSDCTokenMessenger/MockE2EUSDCTokenMessenger.bin d976651d36b33ac2196b32b9d2f4fa6690c6a18d41b621365659fce1c1d1e737
mock_usdc_token_transmitter: ../../../contracts/solc/v0.8.24/MockE2EUSDCTransmitter/MockE2EUSDCTransmitter.abi ../../../contracts/solc/v0.8.24/MockE2EUSDCTransmitter/MockE2EUSDCTransmitter.bin be0dbc3e475741ea0b7a54ec2b935a321b428baa9f4ce18180a87fb38bb87de2
mock_v3_aggregator_contract: ../../../contracts/solc/v0.8.24/MockV3Aggregator/MockV3Aggregator.abi ../../../contracts/solc/v0.8.24/MockV3Aggregator/MockV3Aggregator.bin 518e19efa2ff52b0fefd8e597b05765317ee7638189bfe34ca43de2f6599faf4
Expand Down
1 change: 1 addition & 0 deletions core/gethwrappers/ccip/go_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ package ccip
//go:generate go run ../generation/generate/wrap.go ../../../contracts/solc/v0.8.24/WETH9/WETH9.abi ../../../contracts/solc/v0.8.24/WETH9/WETH9.bin WETH9 weth9
//go:generate go run ../generation/generate/wrap.go ../../../contracts/solc/v0.8.24/MockE2EUSDCTokenMessenger/MockE2EUSDCTokenMessenger.abi ../../../contracts/solc/v0.8.24/MockE2EUSDCTokenMessenger/MockE2EUSDCTokenMessenger.bin MockE2EUSDCTokenMessenger mock_usdc_token_messenger
//go:generate go run ../generation/generate/wrap.go ../../../contracts/solc/v0.8.24/MockE2EUSDCTransmitter/MockE2EUSDCTransmitter.abi ../../../contracts/solc/v0.8.24/MockE2EUSDCTransmitter/MockE2EUSDCTransmitter.bin MockE2EUSDCTransmitter mock_usdc_token_transmitter
//go:generate go run ../generation/generate/wrap.go ../../../contracts/solc/v0.8.24/MockLBTCTokenPool/MockLBTCTokenPool.abi ../../../contracts/solc/v0.8.24/MockLBTCTokenPool/MockLBTCTokenPool.bin MockLBTCTokenPool mock_lbtc_token_pool

// EncodingUtils
//go:generate go run ../generation/generate/wrap.go ../../../contracts/solc/v0.8.24/ICCIPEncodingUtils/ICCIPEncodingUtils.abi ../../../contracts/solc/v0.8.24/ICCIPEncodingUtils/ICCIPEncodingUtils.bin EncodingUtils ccip_encoding_utils
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.7.0 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/fjl/memsize v0.0.2 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gagliardetto/binary v0.7.7 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c=
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA=
github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
Expand Down
126 changes: 126 additions & 0 deletions integration-tests/ccip-tests/contracts/contract_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,132 @@ func (e *CCIPContractsDeployer) DeployUSDCTokenPoolContract(tokenAddr string, to
}
}

// TODO: finish converting from USDC to LBTC
func (e *CCIPContractsDeployer) NewLBTCTokenPoolContract(addr common.Address) (
*TokenPool,
error,
) {
version := VersionMap[TokenPoolContract]
e.logger.Info().Str("Version", version.String()).Msg("New LBTC Token Pool")
switch version {
case Latest:
pool, err := usdc_token_pool.NewUSDCTokenPool(addr, wrappers.MustNewWrappedContractBackend(e.evmClient, nil))

if err != nil {
return nil, err
}
e.logger.Info().
Str("Contract Address", addr.Hex()).
Str("Contract Name", "LBTC Token Pool").
Str("From", e.evmClient.GetDefaultWallet().Address()).
Str("Network Name", e.evmClient.GetNetworkConfig().Name).
Msg("New contract")
poolInterface, err := token_pool.NewTokenPool(addr, wrappers.MustNewWrappedContractBackend(e.evmClient, nil))
if err != nil {
return nil, err
}
return &TokenPool{
client: e.evmClient,
logger: e.logger,
Instance: &TokenPoolWrapper{
Latest: &LatestPool{
PoolInterface: poolInterface,
USDCPool: pool,
},
},
EthAddress: addr,
OwnerAddress: common.HexToAddress(e.evmClient.GetDefaultWallet().Address()),
OwnerWallet: e.evmClient.GetDefaultWallet(),
}, err
case V1_4_0:
pool, err := usdc_token_pool_1_4_0.NewUSDCTokenPool(addr, wrappers.MustNewWrappedContractBackend(e.evmClient, nil))

if err != nil {
return nil, err
}
e.logger.Info().
Str("Contract Address", addr.Hex()).
Str("Contract Name", "USDC Token Pool").
Str("From", e.evmClient.GetDefaultWallet().Address()).
Str("Network Name", e.evmClient.GetNetworkConfig().Name).
Msg("New contract")
poolInterface, err := token_pool_1_4_0.NewTokenPool(addr, wrappers.MustNewWrappedContractBackend(e.evmClient, nil))
if err != nil {
return nil, err
}
return &TokenPool{
client: e.evmClient,
logger: e.logger,
Instance: &TokenPoolWrapper{
V1_4_0: &V1_4_0Pool{
PoolInterface: poolInterface,
USDCPool: pool,
},
},
EthAddress: addr,
OwnerAddress: common.HexToAddress(e.evmClient.GetDefaultWallet().Address()),
OwnerWallet: e.evmClient.GetDefaultWallet(),
}, err
default:
return nil, fmt.Errorf("version not supported: %s", version)
}

}

// TODO: finish converting from USDC to LBTC
func (e *CCIPContractsDeployer) DeployLBTCTokenPoolContract(tokenAddr string, tokenMessenger, rmnProxy common.Address, router common.Address) (
*TokenPool,
error,
) {
version := VersionMap[TokenPoolContract]
e.logger.Debug().Str("Token", tokenAddr).Msg("Deploying LBTC token pool")
token := common.HexToAddress(tokenAddr)
switch version {
case Latest:
address, _, _, err := e.evmClient.DeployContract("LBTC Token Pool", func(
auth *bind.TransactOpts,
_ bind.ContractBackend,
) (common.Address, *types.Transaction, interface{}, error) {
return usdc_token_pool.DeployUSDCTokenPool(
auth,
wrappers.MustNewWrappedContractBackend(e.evmClient, nil),
tokenMessenger,
token,
[]common.Address{},
rmnProxy,
router,
)
})

if err != nil {
return nil, err
}
return e.NewUSDCTokenPoolContract(*address)
case V1_4_0:
address, _, _, err := e.evmClient.DeployContract("USDC Token Pool", func(
auth *bind.TransactOpts,
_ bind.ContractBackend,
) (common.Address, *types.Transaction, interface{}, error) {
return usdc_token_pool_1_4_0.DeployUSDCTokenPool(
auth,
wrappers.MustNewWrappedContractBackend(e.evmClient, nil),
tokenMessenger,
token,
[]common.Address{},
rmnProxy,
router,
)
})

if err != nil {
return nil, err
}
return e.NewUSDCTokenPoolContract(*address)
default:
return nil, fmt.Errorf("version not supported: %s", version)
}
}

func (e *CCIPContractsDeployer) DeployBurnAndMintTokenPoolContract(tokenAddr string, rmnProxy common.Address, router common.Address) (
*TokenPool,
error,
Expand Down

0 comments on commit e80957c

Please sign in to comment.