Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
Update teleporter
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-vball committed Aug 30, 2024
1 parent 4955f22 commit 3466c22
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 38 deletions.
2 changes: 1 addition & 1 deletion contracts/lib/teleporter
9 changes: 8 additions & 1 deletion contracts/src/TokenHome/ERC20TokenHome.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@ contract ERC20TokenHome is ERC20TokenHomeUpgradeable {
constructor(
address teleporterRegistryAddress,
address teleporterManager,
uint256 minTeleporterVersion,
address tokenAddress,
uint8 tokenDecimals
) ERC20TokenHomeUpgradeable(ICTTInitializable.Allowed) {
initialize(teleporterRegistryAddress, teleporterManager, tokenAddress, tokenDecimals);
initialize(
teleporterRegistryAddress,
teleporterManager,
minTeleporterVersion,
tokenAddress,
tokenDecimals
);
}
}
17 changes: 15 additions & 2 deletions contracts/src/TokenHome/ERC20TokenHomeUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,41 @@ contract ERC20TokenHomeUpgradeable is IERC20TokenHome, TokenHome {
* address. See here for details: https://github.com/ava-labs/teleporter/tree/main/contracts/teleporter/registry
* @param teleporterManager Address that manages this contract's integration with the
* Teleporter registry and Teleporter versions.
* @param minTeleporterVersion Minimum Teleporter version supported by this contract.
* @param tokenAddress The ERC20 token contract address to be transferred by the home.
* @param tokenDecimals The number of decimals for the ERC20 token
*/
function initialize(
address teleporterRegistryAddress,
address teleporterManager,
uint256 minTeleporterVersion,
address tokenAddress,
uint8 tokenDecimals
) public initializer {
__ERC20TokenHome_init(
teleporterRegistryAddress, teleporterManager, tokenAddress, tokenDecimals
teleporterRegistryAddress,
teleporterManager,
minTeleporterVersion,
tokenAddress,
tokenDecimals
);
}

// solhint-disable-next-line func-name-mixedcase
function __ERC20TokenHome_init(
address teleporterRegistryAddress,
address teleporterManager,
uint256 minTeleporterVersion,
address tokenAddress,
uint8 tokenDecimals
) internal onlyInitializing {
__TokenHome_init(teleporterRegistryAddress, teleporterManager, tokenAddress, tokenDecimals);
__TokenHome_init(
teleporterRegistryAddress,
teleporterManager,
minTeleporterVersion,
tokenAddress,
tokenDecimals
);
__ERC20TokenHome_init_unchained(tokenAddress);
}

Expand Down
5 changes: 4 additions & 1 deletion contracts/src/TokenHome/NativeTokenHome.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ contract NativeTokenHome is NativeTokenHomeUpgradeable {
constructor(
address teleporterRegistryAddress,
address teleporterManager,
uint256 minTeleporterVersion,
address wrappedTokenAddress
) NativeTokenHomeUpgradeable(ICTTInitializable.Allowed) {
initialize(teleporterRegistryAddress, teleporterManager, wrappedTokenAddress);
initialize(
teleporterRegistryAddress, teleporterManager, minTeleporterVersion, wrappedTokenAddress
);
}
}
15 changes: 13 additions & 2 deletions contracts/src/TokenHome/NativeTokenHomeUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,35 @@ contract NativeTokenHomeUpgradeable is INativeTokenHome, TokenHome {
* address. See here for details: https://github.com/ava-labs/teleporter/tree/main/contracts/teleporter/registry
* @param teleporterManager Address that manages this contract's integration with the
* Teleporter registry and Teleporter versions.
* @param minTeleporterVersion Minimum Teleporter version supported by this contract.
* @param wrappedTokenAddress The wrapped native token contract address of the native asset
* to be transferred to TokenRemote instances.
*/
function initialize(
address teleporterRegistryAddress,
address teleporterManager,
uint256 minTeleporterVersion,
address wrappedTokenAddress
) public initializer {
__NativeTokenHome_init(teleporterRegistryAddress, teleporterManager, wrappedTokenAddress);
__NativeTokenHome_init(
teleporterRegistryAddress, teleporterManager, minTeleporterVersion, wrappedTokenAddress
);
}

// solhint-disable-next-line func-name-mixedcase
function __NativeTokenHome_init(
address teleporterRegistryAddress,
address teleporterManager,
uint256 minTeleporterVersion,
address wrappedTokenAddress
) internal onlyInitializing {
__TokenHome_init(teleporterRegistryAddress, teleporterManager, wrappedTokenAddress, 18);
__TokenHome_init(
teleporterRegistryAddress,
teleporterManager,
minTeleporterVersion,
wrappedTokenAddress,
18
);
__NativeTokenHome_init_unchained(wrappedTokenAddress);
}

Expand Down
6 changes: 5 additions & 1 deletion contracts/src/TokenHome/TokenHome.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,21 @@ abstract contract TokenHome is
* @param teleporterRegistryAddress The address of the TeleporterRegistry contract.
* @param teleporterManager Address that manages this contract's integration with the
* Teleporter registry and Teleporter versions.
* @param minTeleporterVersion Minimum Teleporter version supported by this contract.
* @param tokenAddress The token contract address to be transferredd by the home instance.
* @param tokenDecimals The number of decimals for the token being transferred.
*/
// solhint-disable-next-line func-name-mixedcase
function __TokenHome_init(
address teleporterRegistryAddress,
address teleporterManager,
uint256 minTeleporterVersion,
address tokenAddress,
uint8 tokenDecimals
) internal virtual onlyInitializing {
__TeleporterRegistryOwnableApp_init(teleporterRegistryAddress, teleporterManager);
__TeleporterRegistryOwnableApp_init(
teleporterRegistryAddress, teleporterManager, minTeleporterVersion
);
__SendReentrancyGuard_init();
__TokenHome_init_unchained(tokenAddress, tokenDecimals);
}
Expand Down
4 changes: 3 additions & 1 deletion contracts/src/TokenRemote/TokenRemote.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ abstract contract TokenRemote is
uint8 tokenDecimals
) internal onlyInitializing {
__TeleporterRegistryOwnableApp_init(
settings.teleporterRegistryAddress, settings.teleporterManager
settings.teleporterRegistryAddress,
settings.teleporterManager,
settings.minTeleporterVersion
);
__SendReentrancyGuard_init();
__TokenRemote_init_unchained(settings, initialReserveImbalance_, tokenDecimals);
Expand Down
2 changes: 2 additions & 0 deletions contracts/src/TokenRemote/interfaces/ITokenRemote.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import {TeleporterFeeInfo} from "@teleporter/ITeleporterMessenger.sol";
* address. See here for details: https://github.com/ava-labs/teleporter/tree/main/contracts/teleporter/registry.
* @param teleporterManager Address that manages this contract's integration with the
* Teleporter registry and Teleporter versions.
* @param minTeleporterVersion Minimum Teleporter version supported by this contract.
* @param tokenHomeBlockchainID The blockchain ID of the associated TokenHome instance.
* @param tokenHomeAddress The address of the associated token home contract.
* @param tokenHomeDecimals The number of decimal places used by the token home's token.
*/
struct TokenRemoteSettings {
address teleporterRegistryAddress;
address teleporterManager;
uint256 minTeleporterVersion;
bytes32 tokenHomeBlockchainID;
address tokenHomeAddress;
uint8 tokenHomeDecimals;
Expand Down
7 changes: 4 additions & 3 deletions contracts/test/ERC20TokenHomeTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ contract ERC20TokenHomeTest is ERC20TokenTransferrerTest, TokenHomeTest {
app.initialize(
MOCK_TELEPORTER_REGISTRY_ADDRESS,
MOCK_TELEPORTER_MESSENGER_ADDRESS,
1,
address(mockERC20),
tokenHomeDecimals
);
Expand All @@ -51,7 +52,7 @@ contract ERC20TokenHomeTest is ERC20TokenTransferrerTest, TokenHomeTest {
*/
function testNonUpgradeableInitialization() public {
app = new ERC20TokenHome(
MOCK_TELEPORTER_REGISTRY_ADDRESS, address(this), address(mockERC20), tokenHomeDecimals
MOCK_TELEPORTER_REGISTRY_ADDRESS, address(this), 1, address(mockERC20), tokenHomeDecimals
);
assertEq(app.getBlockchainID(), DEFAULT_TOKEN_HOME_BLOCKCHAIN_ID);
}
Expand All @@ -60,7 +61,7 @@ contract ERC20TokenHomeTest is ERC20TokenTransferrerTest, TokenHomeTest {
app = new ERC20TokenHomeUpgradeable(ICTTInitializable.Disallowed);
vm.expectRevert(abi.encodeWithSelector(Initializable.InvalidInitialization.selector));
app.initialize(
MOCK_TELEPORTER_REGISTRY_ADDRESS, address(this), address(mockERC20), tokenHomeDecimals
MOCK_TELEPORTER_REGISTRY_ADDRESS, address(this), 1, address(mockERC20), tokenHomeDecimals
);
}

Expand Down Expand Up @@ -303,7 +304,7 @@ contract ERC20TokenHomeTest is ERC20TokenTransferrerTest, TokenHomeTest {
app = new ERC20TokenHomeUpgradeable(ICTTInitializable.Allowed);
vm.expectRevert(expectedErrorMessage);
app.initialize(
teleporterRegistryAddress, teleporterManagerAddress, feeTokenAddress, tokenDecimals
teleporterRegistryAddress, teleporterManagerAddress, 1, feeTokenAddress, tokenDecimals
);
}
}
18 changes: 13 additions & 5 deletions contracts/test/ERC20TokenRemoteTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ contract ERC20TokenRemoteTest is ERC20TokenTransferrerTest, TokenRemoteTest {
TokenRemoteSettings({
teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,
teleporterManager: address(this),
minTeleporterVersion: 1,
tokenHomeBlockchainID: DEFAULT_TOKEN_HOME_BLOCKCHAIN_ID,
tokenHomeAddress: DEFAULT_TOKEN_HOME_ADDRESS,
tokenHomeDecimals: tokenHomeDecimals
Expand All @@ -76,6 +77,7 @@ contract ERC20TokenRemoteTest is ERC20TokenTransferrerTest, TokenRemoteTest {
TokenRemoteSettings({
teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,
teleporterManager: address(this),
minTeleporterVersion: 1,
tokenHomeBlockchainID: DEFAULT_TOKEN_HOME_BLOCKCHAIN_ID,
tokenHomeAddress: DEFAULT_TOKEN_HOME_ADDRESS,
tokenHomeDecimals: tokenHomeDecimals
Expand All @@ -91,6 +93,7 @@ contract ERC20TokenRemoteTest is ERC20TokenTransferrerTest, TokenRemoteTest {
TokenRemoteSettings({
teleporterRegistryAddress: address(0),
teleporterManager: address(this),
minTeleporterVersion: 1,
tokenHomeBlockchainID: DEFAULT_TOKEN_HOME_BLOCKCHAIN_ID,
tokenHomeAddress: DEFAULT_TOKEN_HOME_ADDRESS,
tokenHomeDecimals: tokenHomeDecimals
Expand All @@ -107,6 +110,7 @@ contract ERC20TokenRemoteTest is ERC20TokenTransferrerTest, TokenRemoteTest {
TokenRemoteSettings({
teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,
teleporterManager: address(0),
minTeleporterVersion: 1,
tokenHomeBlockchainID: DEFAULT_TOKEN_HOME_BLOCKCHAIN_ID,
tokenHomeAddress: DEFAULT_TOKEN_HOME_ADDRESS,
tokenHomeDecimals: tokenHomeDecimals
Expand All @@ -123,6 +127,7 @@ contract ERC20TokenRemoteTest is ERC20TokenTransferrerTest, TokenRemoteTest {
TokenRemoteSettings({
teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,
teleporterManager: address(this),
minTeleporterVersion: 1,
tokenHomeBlockchainID: bytes32(0),
tokenHomeAddress: DEFAULT_TOKEN_HOME_ADDRESS,
tokenHomeDecimals: tokenHomeDecimals
Expand All @@ -139,6 +144,7 @@ contract ERC20TokenRemoteTest is ERC20TokenTransferrerTest, TokenRemoteTest {
TokenRemoteSettings({
teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,
teleporterManager: address(this),
minTeleporterVersion: 1,
tokenHomeBlockchainID: DEFAULT_TOKEN_REMOTE_BLOCKCHAIN_ID,
tokenHomeAddress: DEFAULT_TOKEN_HOME_ADDRESS,
tokenHomeDecimals: tokenHomeDecimals
Expand All @@ -155,6 +161,7 @@ contract ERC20TokenRemoteTest is ERC20TokenTransferrerTest, TokenRemoteTest {
TokenRemoteSettings({
teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,
teleporterManager: address(this),
minTeleporterVersion: 1,
tokenHomeBlockchainID: DEFAULT_TOKEN_HOME_BLOCKCHAIN_ID,
tokenHomeAddress: address(0),
tokenHomeDecimals: 18
Expand All @@ -166,11 +173,6 @@ contract ERC20TokenRemoteTest is ERC20TokenTransferrerTest, TokenRemoteTest {
);
}

function testDecimals() public {
uint8 res = app.decimals();
assertEq(tokenDecimals, res);
}

function testSendWithSeparateFeeAsset() public {
uint256 amount = 200_000;
uint256 feeAmount = 100;
Expand All @@ -197,13 +199,19 @@ contract ERC20TokenRemoteTest is ERC20TokenTransferrerTest, TokenRemoteTest {
_send(input, amount);
}

function testDecimals() public view {
uint8 res = app.decimals();
assertEq(tokenDecimals, res);
}

function _createNewRemoteInstance() internal override returns (TokenRemote) {
ERC20TokenRemoteUpgradeable instance =
new ERC20TokenRemoteUpgradeable(ICTTInitializable.Allowed);
instance.initialize(
TokenRemoteSettings({
teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,
teleporterManager: address(this),
minTeleporterVersion: 1,
tokenHomeBlockchainID: DEFAULT_TOKEN_HOME_BLOCKCHAIN_ID,
tokenHomeAddress: DEFAULT_TOKEN_HOME_ADDRESS,
tokenHomeDecimals: tokenHomeDecimals
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/ExampleERC20DecimalsTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract ExampleERC20DecimalsTest is Test {
exampleERC20 = new ExampleERC20Decimals(MOCK_DECIMALS);
}

function testDecimals() public {
function testDecimals() public view {
assertEq(exampleERC20.decimals(), MOCK_DECIMALS);
}
}
8 changes: 4 additions & 4 deletions contracts/test/NativeTokenHomeTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract NativeTokenHomeTest is NativeTokenTransferrerTest, TokenHomeTest {
wavax = new WrappedNativeToken("AVAX");
app = new NativeTokenHomeUpgradeable(ICTTInitializable.Allowed);
app.initialize(
MOCK_TELEPORTER_REGISTRY_ADDRESS, MOCK_TELEPORTER_MESSENGER_ADDRESS, address(wavax)
MOCK_TELEPORTER_REGISTRY_ADDRESS, MOCK_TELEPORTER_MESSENGER_ADDRESS, 1, address(wavax)
);
tokenHome = app;
nativeTokenTransferrer = app;
Expand All @@ -47,14 +47,14 @@ contract NativeTokenHomeTest is NativeTokenTransferrerTest, TokenHomeTest {
* Initialization unit tests
*/
function testNonUpgradeableInitialization() public {
app = new NativeTokenHome(MOCK_TELEPORTER_REGISTRY_ADDRESS, address(this), address(wavax));
app = new NativeTokenHome(MOCK_TELEPORTER_REGISTRY_ADDRESS, address(this), 1, address(wavax));
assertEq(app.getBlockchainID(), DEFAULT_TOKEN_HOME_BLOCKCHAIN_ID);
}

function testDisableInitialization() public {
app = new NativeTokenHomeUpgradeable(ICTTInitializable.Disallowed);
vm.expectRevert(abi.encodeWithSelector(Initializable.InvalidInitialization.selector));
app.initialize(MOCK_TELEPORTER_REGISTRY_ADDRESS, address(this), address(wavax));
app.initialize(MOCK_TELEPORTER_REGISTRY_ADDRESS, address(this), 1, address(wavax));
}

function testZeroTeleporterRegistryAddress() public {
Expand Down Expand Up @@ -173,6 +173,6 @@ contract NativeTokenHomeTest is NativeTokenTransferrerTest, TokenHomeTest {
) private {
app = new NativeTokenHomeUpgradeable(ICTTInitializable.Allowed);
vm.expectRevert(expectedErrorMessage);
app.initialize(teleporterRegistryAddress, teleporterManagerAddress, wrappedTokenAddress);
app.initialize(teleporterRegistryAddress, teleporterManagerAddress, 1, wrappedTokenAddress);
}
}
8 changes: 8 additions & 0 deletions contracts/test/NativeTokenRemoteTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ contract NativeTokenRemoteTest is NativeTokenTransferrerTest, TokenRemoteTest {
settings: TokenRemoteSettings({
teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,
teleporterManager: address(this),
minTeleporterVersion: 1,
tokenHomeBlockchainID: DEFAULT_TOKEN_HOME_BLOCKCHAIN_ID,
tokenHomeAddress: DEFAULT_TOKEN_HOME_ADDRESS,
tokenHomeDecimals: tokenHomeDecimals
Expand All @@ -73,6 +74,7 @@ contract NativeTokenRemoteTest is NativeTokenTransferrerTest, TokenRemoteTest {
settings: TokenRemoteSettings({
teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,
teleporterManager: address(this),
minTeleporterVersion: 1,
tokenHomeBlockchainID: DEFAULT_TOKEN_HOME_BLOCKCHAIN_ID,
tokenHomeAddress: DEFAULT_TOKEN_HOME_ADDRESS,
tokenHomeDecimals: tokenHomeDecimals
Expand All @@ -88,6 +90,7 @@ contract NativeTokenRemoteTest is NativeTokenTransferrerTest, TokenRemoteTest {
settings: TokenRemoteSettings({
teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,
teleporterManager: address(this),
minTeleporterVersion: 1,
tokenHomeBlockchainID: DEFAULT_TOKEN_HOME_BLOCKCHAIN_ID,
tokenHomeAddress: DEFAULT_TOKEN_HOME_ADDRESS,
tokenHomeDecimals: tokenHomeDecimals
Expand All @@ -104,6 +107,7 @@ contract NativeTokenRemoteTest is NativeTokenTransferrerTest, TokenRemoteTest {
settings: TokenRemoteSettings({
teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,
teleporterManager: address(this),
minTeleporterVersion: 1,
tokenHomeBlockchainID: DEFAULT_TOKEN_HOME_BLOCKCHAIN_ID,
tokenHomeAddress: DEFAULT_TOKEN_HOME_ADDRESS,
tokenHomeDecimals: tokenHomeDecimals
Expand All @@ -120,6 +124,7 @@ contract NativeTokenRemoteTest is NativeTokenTransferrerTest, TokenRemoteTest {
settings: TokenRemoteSettings({
teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,
teleporterManager: address(this),
minTeleporterVersion: 1,
tokenHomeBlockchainID: bytes32(0),
tokenHomeAddress: DEFAULT_TOKEN_HOME_ADDRESS,
tokenHomeDecimals: tokenHomeDecimals
Expand All @@ -136,6 +141,7 @@ contract NativeTokenRemoteTest is NativeTokenTransferrerTest, TokenRemoteTest {
settings: TokenRemoteSettings({
teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,
teleporterManager: address(this),
minTeleporterVersion: 1,
tokenHomeBlockchainID: DEFAULT_TOKEN_REMOTE_BLOCKCHAIN_ID,
tokenHomeAddress: DEFAULT_TOKEN_HOME_ADDRESS,
tokenHomeDecimals: tokenHomeDecimals
Expand Down Expand Up @@ -343,6 +349,7 @@ contract NativeTokenRemoteTest is NativeTokenTransferrerTest, TokenRemoteTest {
settings: TokenRemoteSettings({
teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,
teleporterManager: address(this),
minTeleporterVersion: 1,
tokenHomeBlockchainID: DEFAULT_TOKEN_HOME_BLOCKCHAIN_ID,
tokenHomeAddress: DEFAULT_TOKEN_HOME_ADDRESS,
tokenHomeDecimals: tokenHomeDecimals
Expand Down Expand Up @@ -399,6 +406,7 @@ contract NativeTokenRemoteTest is NativeTokenTransferrerTest, TokenRemoteTest {
settings: TokenRemoteSettings({
teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,
teleporterManager: address(this),
minTeleporterVersion: 1,
tokenHomeBlockchainID: DEFAULT_TOKEN_HOME_BLOCKCHAIN_ID,
tokenHomeAddress: DEFAULT_TOKEN_HOME_ADDRESS,
tokenHomeDecimals: tokenHomeDecimals
Expand Down
Loading

0 comments on commit 3466c22

Please sign in to comment.