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

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-vball committed Aug 20, 2024
1 parent ee1fabd commit 9e1f0c9
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ Note that the value returned by `totalNativeAssetSupply` is an upper bound on th

## Teleporter Message Fees

Fees can be optionally added to Teleporter messages in order to incentivize relayers to deliver them, as documented [here](https://github.com/ava-labs/teleporter/tree/main/contracts/src/Teleporter#fees). The token transfer contracts in this repository allow for specifying any ERC20 token and amount to be used as the Teleporter message fee for single-hop transfers in either direction between `TokenHome` and `TokenRemote` instances. Fee amounts must be pre-approved to be spent by the token transfer contract before initiating a transfer.
Fees can be optionally added to Teleporter messages in order to incentivize relayers to deliver them, as documented [here](https://github.com/ava-labs/teleporter/tree/main/contracts/teleporter#fees). The token transfer contracts in this repository allow for specifying any ERC20 token and amount to be used as the Teleporter message fee for single-hop transfers in either direction between `TokenHome` and `TokenRemote` instances. Fee amounts must be pre-approved to be spent by the token transfer contract before initiating a transfer.

Multi-hop transfers between two `TokenRemote` instances involve two Teleporter messages: the first from the initiating `TokenRemote` instance to its home, and the second from its home to the destination `TokenRemote` instance. In the multi-hop case, the first message fee can be paid in any ERC20 token and amount (similar to the single-hop case), but the second message fee must be paid in-kind of the asset being transferred and is deducted from the amount being transferred. This restriction on the secondary message fee is necessary because the transaction on the intermediate chain routing the funds to the destination `TokenRemote` instance is not sent by the wallet performing the transfer. Because of this, it can not directly spend an arbitrary ERC20 token from that wallet. Using the asset being transferred for the optional secondary fee allows users to perform an incentivized multi-hop transfer without needing to make any interaction with the home themselves. If there is a need for the second message from the home to the destination `TokenRemote` instance to pay a fee in another asset, it is recommended to perform two single-hop transfers, which allows for specifying an arbitrary ERC20 token to be used for the fee of each.
6 changes: 3 additions & 3 deletions contracts/remappings.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@openzeppelin/[email protected]/=lib/openzeppelin-contracts/contracts/
@openzeppelin/[email protected]/=lib/openzeppelin-contracts-upgradeable/contracts/
@avalabs/[email protected]/=lib/teleporter/contracts/lib/subnet-evm/contracts/
@teleporter/=lib/teleporter/contracts/src/teleporter/
@teleporter-mocks/=lib/teleporter/contracts/src/mocks
@avalabs/[email protected]/=lib/teleporter/lib/subnet-evm/contracts/
@teleporter/=lib/teleporter/contracts/teleporter/
@teleporter-mocks/=lib/teleporter/contracts/mocks
2 changes: 1 addition & 1 deletion contracts/src/TokenHome/ERC20TokenHomeUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ contract ERC20TokenHomeUpgradeable is IERC20TokenHome, TokenHome {
/**
* @notice Initializes the token TokenHome instance to send ERC20 tokens to TokenRemote instances on other chains.
* @param teleporterRegistryAddress The current blockchain ID's Teleporter registry
* address. See here for details: https://github.com/ava-labs/teleporter/tree/main/contracts/src/Teleporter/upgrades
* address. See here for details: https://github.com/ava-labs/teleporter/tree/main/contracts/teleporter/upgrades
* @param teleporterManager Address that manages this contract's integration with the
* Teleporter registry and Teleporter versions.
* @param tokenAddress The ERC20 token contract address to be transferred by the home.
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/TokenHome/NativeTokenHomeUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ contract NativeTokenHomeUpgradeable is INativeTokenHome, TokenHome {
* @notice Initializes this token TokenHome instance to send native tokens to TokenRemote instances on other chains.
* Always uses a {tokenDecimals} value of 18 since it is the denomination of the native token of EVM instances.
* @param teleporterRegistryAddress The current blockchain ID's Teleporter registry
* address. See here for details: https://github.com/ava-labs/teleporter/tree/main/contracts/src/Teleporter/upgrades
* address. See here for details: https://github.com/ava-labs/teleporter/tree/main/contracts/teleporter/upgrades
* @param teleporterManager Address that manages this contract's integration with the
* Teleporter registry and Teleporter versions.
* @param wrappedTokenAddress The wrapped native token contract address of the native asset
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/TokenRemote/interfaces/ITokenRemote.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {TeleporterFeeInfo} from "@teleporter/ITeleporterMessenger.sol";
/**
* @notice Settings for constructing a {ITokenRemote} contract.
* @param teleporterRegistryAddress The current blockchain ID's Teleporter registry
* address. See here for details: https://github.com/ava-labs/teleporter/tree/main/contracts/src/Teleporter/upgrades.
* address. See here for details: https://github.com/ava-labs/teleporter/tree/main/contracts/teleporter/upgrades.
* @param teleporterManager Address that manages this contract's integration with the
* Teleporter registry and Teleporter versions.
* @param tokenHomeBlockchainID The blockchain ID of the associated TokenHome instance.
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/utils/SafeERC20TransferFrom.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {SafeERC20} from "@openzeppelin/[email protected]/token/ERC20/utils/SafeERC
/**
* @dev Provides a wrapper used for calling an ERC20 transferFrom method to receive tokens to a contract
* from a specified sender. Differs from the "SafeERC20TransferFrom" implementation found here
* https://github.com/ava-labs/teleporter/blob/main/contracts/src/Teleporter/SafeERC20TransferFrom.sol in that
* https://github.com/ava-labs/teleporter/blob/main/contracts/teleporter/SafeERC20TransferFrom.sol in that
* it supports passing arbitrary sender address values, allowing its use in ERC-2771 compliant meta-transactions.
*
* Checks the balance of the contract using the library before and after the call to safeTransferFrom, and
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/ERC20TokenHomeTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {SendTokensInput} from "../src/interfaces/ITokenTransferrer.sol";
import {ERC20TokenHomeUpgradeable} from "../src/TokenHome/ERC20TokenHomeUpgradeable.sol";
import {ERC20TokenHome} from "../src/TokenHome/ERC20TokenHome.sol";
import {IERC20} from "@openzeppelin/[email protected]/token/ERC20/IERC20.sol";
import {ExampleERC20} from "../lib/teleporter/contracts/src/mocks/ExampleERC20.sol";
import {ExampleERC20} from "../lib/teleporter/contracts/mocks/ExampleERC20.sol";
import {SafeERC20} from "@openzeppelin/[email protected]/token/ERC20/utils/SafeERC20.sol";
import {TeleporterMessageInput, TeleporterFeeInfo} from "@teleporter/ITeleporterMessenger.sol";
import {TokenScalingUtils} from "../src/utils/TokenScalingUtils.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/ERC20TokenRemoteTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {ERC20TokenRemoteUpgradeable} from "../src/TokenRemote/ERC20TokenRemoteUp
import {ERC20TokenRemote} from "../src/TokenRemote/ERC20TokenRemote.sol";
import {SafeERC20} from "@openzeppelin/[email protected]/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/[email protected]/token/ERC20/IERC20.sol";
import {ExampleERC20} from "../lib/teleporter/contracts/src/mocks/ExampleERC20.sol";
import {ExampleERC20} from "../lib/teleporter/contracts/mocks/ExampleERC20.sol";
import {SendTokensInput} from "../src/interfaces/ITokenTransferrer.sol";
import {Ownable} from "@openzeppelin/[email protected]/access/Ownable.sol";
import {ICTTInitializable} from "../src/utils/ICTTInitializable.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/MockSendAndCallReceiverTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {Test} from "forge-std/Test.sol";
import {MockERC20SendAndCallReceiver} from "../src/mocks/MockERC20SendAndCallReceiver.sol";
import {MockNativeSendAndCallReceiver} from "../src/mocks/MockNativeSendAndCallReceiver.sol";
import {IERC20} from "@openzeppelin/[email protected]/token/ERC20/IERC20.sol";
import {ExampleERC20} from "../lib/teleporter/contracts/src/mocks/ExampleERC20.sol";
import {ExampleERC20} from "../lib/teleporter/contracts/mocks/ExampleERC20.sol";

contract MockERC20SendAndCallReceiverTest is Test {
IERC20 public erc20;
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/NativeTokenRemoteTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import {SendTokensInput} from "../src/interfaces/ITokenTransferrer.sol";
import {IERC20} from "@openzeppelin/[email protected]/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/[email protected]/token/ERC20/utils/SafeERC20.sol";
import {ExampleERC20} from "../lib/teleporter/contracts/src/mocks/ExampleERC20.sol";
import {ExampleERC20} from "../lib/teleporter/contracts/mocks/ExampleERC20.sol";
import {ICTTInitializable} from "../src/utils/ICTTInitializable.sol";
import {Initializable} from "@openzeppelin/[email protected]/proxy/utils/Initializable.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/test/TokenRemoteTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
RegisterRemoteMessage
} from "../src/interfaces/ITokenTransferrer.sol";
import {IERC20} from "@openzeppelin/[email protected]/token/ERC20/IERC20.sol";
import {ExampleERC20} from "../lib/teleporter/contracts/src/mocks/ExampleERC20.sol";
import {ExampleERC20} from "../lib/teleporter/contracts/mocks/ExampleERC20.sol";
import {SafeERC20} from "@openzeppelin/[email protected]/token/ERC20/utils/SafeERC20.sol";

abstract contract TokenRemoteTest is TokenTransferrerTest {
Expand Down
4 changes: 2 additions & 2 deletions scripts/abi_bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ generate_bindings "${contract_names[@]}"

contract_names=($PROXY_LIST)
cd $AVALANCHE_INTERCHAIN_TOKEN_TRANSFER_PATH/contracts
forge build --skip test --force --extra-output-files abi bin --contracts lib/teleporter/contracts/lib/openzeppelin-contracts/contracts/proxy/transparent
forge build --skip test --force --extra-output-files abi bin --contracts lib/openzeppelin-contracts/contracts/proxy/transparent

cd $AVALANCHE_INTERCHAIN_TOKEN_TRANSFER_PATH/contracts/lib/teleporter/contracts/lib/openzeppelin-contracts/contracts/proxy/transparent
cd $AVALANCHE_INTERCHAIN_TOKEN_TRANSFER_PATH/contracts/lib/openzeppelin-contracts/contracts/proxy/transparent
generate_bindings "${contract_names[@]}"

exit 0
5 changes: 2 additions & 3 deletions tests/local/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var _ = ginkgo.BeforeSuite(func() {
)

// Generate the Teleporter deployment values
teleporterDeployerTransaction, teleporterDeployerAddress,
teleporterDeployerTransaction, _, teleporterDeployerAddress,
teleporterContractAddress, err := deploymentUtils.ConstructKeylessTransaction(
teleporterByteCodeFile,
false,
Expand All @@ -73,12 +73,11 @@ var _ = ginkgo.BeforeSuite(func() {
Expect(err).Should(BeNil())

_, fundedKey := LocalNetworkInstance.GetFundedAccountInfo()
LocalNetworkInstance.DeployTeleporterContracts(
LocalNetworkInstance.DeployTeleporterContractToCChain(
teleporterDeployerTransaction,
teleporterDeployerAddress,
teleporterContractAddress,
fundedKey,
true,
)

LocalNetworkInstance.DeployTeleporterRegistryContracts(teleporterContractAddress, fundedKey)
Expand Down

0 comments on commit 9e1f0c9

Please sign in to comment.