Skip to content

Commit

Permalink
Merge branch 'main' into gstuart/native-token-bridge-ginkgo
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-vball committed Nov 22, 2023
2 parents 25fb790 + ee1fd7d commit 8cfde6b
Show file tree
Hide file tree
Showing 29 changed files with 176 additions and 108 deletions.
32 changes: 20 additions & 12 deletions .github/workflows/abi_bindings_checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,28 @@ on:
branches:
- "*"

env:
GO_VERSION: "1.20.10"

jobs:
abi_binding:
name: abi_binding
runs-on: ubuntu-20.04

steps:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Checkout Teleporter repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Set Go version
run: |
source ./scripts/versions.sh
GO_VERSION=$GO_VERSION >> $GITHUB_ENV
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
Expand All @@ -49,16 +52,21 @@ jobs:
runs-on: ubuntu-20.04

steps:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Checkout repositories and submodules
uses: actions/checkout@v4
with:
submodules: recursive

- name: Set Go version
run: |
source ./scripts/versions.sh
GO_VERSION=$GO_VERSION >> $GITHUB_ENV
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Run ABI Binding Unit Tests
run: |
source scripts/constants.sh
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ on:
branches:
- "*"

env:
GO_VERSION: "1.20.10"

jobs:
e2e_tests:
name: e2e_tests
Expand All @@ -25,6 +22,11 @@ jobs:
with:
submodules: recursive

- name: Set Go version
run: |
source ./scripts/versions.sh
GO_VERSION=$GO_VERSION >> $GITHUB_ENV
- name: Setup Go
uses: actions/setup-go@v4
with:
Expand All @@ -40,9 +42,6 @@ jobs:
cd subnet-evm
./scripts/build.sh /tmp/e2e-test/avalanchego/plugins/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy
- name: Checkout teleporter repository
uses: actions/checkout@v4

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/gomod_checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: go.mod Check

on:
push:
branches:
- main
pull_request:
branches:
- "*"

jobs:
gomod_check:
name: Check go.mod
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- run: |
source ./scripts/versions.sh
GO_VERSION=$GO_VERSION >> $GITHUB_ENV
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- run: go mod tidy
- run: git --no-pager diff -- go.mod go.sum # This prints the diff
- run: git --no-pager diff --quiet -- go.mod go.sum # This errors if there is a diff
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ on:
branches:
- "*"

env:
RELAYER_VERSION: v0.2.4

jobs:
teleporter-integration-test:
runs-on: ubuntu-20.04
Expand All @@ -25,7 +22,8 @@ jobs:

- name: Download awm-relayer image
run: |
docker pull avaplatform/awm-relayer:${RELAYER_VERSION}
source ./scripts/versions.sh
docker pull avaplatform/awm-relayer:${AWM_RELAYER_VERSION}
- name: Teleporter Integration Tests
run: |
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ contract ERC20Bridge is
destinationChainID: destinationChainID,
destinationAddress: destinationBridgeAddress,
feeInfo: TeleporterFeeInfo({
contractAddress: messageFeeAsset,
feeTokenAddress: messageFeeAsset,
amount: adjustedFeeAmount
}),
requiredGasLimit: CREATE_BRIDGE_TOKENS_REQUIRED_GAS,
Expand Down Expand Up @@ -598,7 +598,7 @@ contract ERC20Bridge is
destinationChainID: destinationChainID,
destinationAddress: destinationBridgeAddress,
feeInfo: TeleporterFeeInfo({
contractAddress: nativeContractAddress,
feeTokenAddress: nativeContractAddress,
amount: feeAmount
}),
requiredGasLimit: MINT_BRIDGE_TOKENS_REQUIRED_GAS,
Expand Down Expand Up @@ -692,7 +692,7 @@ contract ERC20Bridge is
destinationChainID: nativeChainID,
destinationAddress: nativeBridgeAddress,
feeInfo: TeleporterFeeInfo({
contractAddress: wrappedTransferInfo.wrappedContractAddress,
feeTokenAddress: wrappedTransferInfo.wrappedContractAddress,
amount: adjustedPrimaryFeeAmount
}),
requiredGasLimit: TRANSFER_BRIDGE_TOKENS_REQUIRED_GAS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ contract ERC20BridgeTest is Test {
destinationChainID: _DEFAULT_OTHER_CHAIN_ID,
destinationAddress: _DEFAULT_OTHER_BRIDGE_ADDRESS,
feeInfo: TeleporterFeeInfo({
contractAddress: address(mockERC20),
feeTokenAddress: address(mockERC20),
amount: 0
}),
requiredGasLimit: erc20Bridge.MINT_BRIDGE_TOKENS_REQUIRED_GAS(),
Expand Down Expand Up @@ -321,7 +321,7 @@ contract ERC20BridgeTest is Test {
destinationChainID: _DEFAULT_OTHER_CHAIN_ID,
destinationAddress: _DEFAULT_OTHER_BRIDGE_ADDRESS,
feeInfo: TeleporterFeeInfo({
contractAddress: address(mockERC20),
feeTokenAddress: address(mockERC20),
amount: feeAmount
}),
requiredGasLimit: erc20Bridge.MINT_BRIDGE_TOKENS_REQUIRED_GAS(),
Expand Down Expand Up @@ -424,7 +424,7 @@ contract ERC20BridgeTest is Test {
destinationChainID: _DEFAULT_OTHER_CHAIN_ID,
destinationAddress: _DEFAULT_OTHER_BRIDGE_ADDRESS,
feeInfo: TeleporterFeeInfo({
contractAddress: address(mockERC20),
feeTokenAddress: address(mockERC20),
amount: bridgeFeeAmount
}),
requiredGasLimit: erc20Bridge.MINT_BRIDGE_TOKENS_REQUIRED_GAS(),
Expand Down Expand Up @@ -705,7 +705,7 @@ contract ERC20BridgeTest is Test {
destinationChainID: destinationChainID,
destinationAddress: destinationBridgeAddress,
feeInfo: TeleporterFeeInfo({
contractAddress: address(0),
feeTokenAddress: address(0),
amount: 0
}),
requiredGasLimit: erc20Bridge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract ExampleCrossChainMessenger is
event SendMessage(
bytes32 indexed destinationChainID,
address indexed destinationAddress,
address feeAsset,
address feeTokenAddress,
uint256 feeAmount,
uint256 requiredGasLimit,
string message
Expand Down Expand Up @@ -79,7 +79,7 @@ contract ExampleCrossChainMessenger is
function sendMessage(
bytes32 destinationChainID,
address destinationAddress,
address feeContractAddress,
address feeTokenAddress,
uint256 feeAmount,
uint256 requiredGasLimit,
string calldata message
Expand All @@ -91,10 +91,10 @@ contract ExampleCrossChainMessenger is
uint256 adjustedFeeAmount = 0;
if (feeAmount > 0) {
adjustedFeeAmount = SafeERC20TransferFrom.safeTransferFrom(
IERC20(feeContractAddress),
IERC20(feeTokenAddress),
feeAmount
);
IERC20(feeContractAddress).safeIncreaseAllowance(
IERC20(feeTokenAddress).safeIncreaseAllowance(
address(teleporterMessenger),
adjustedFeeAmount
);
Expand All @@ -103,7 +103,7 @@ contract ExampleCrossChainMessenger is
emit SendMessage({
destinationChainID: destinationChainID,
destinationAddress: destinationAddress,
feeAsset: feeContractAddress,
feeTokenAddress: feeTokenAddress,
feeAmount: adjustedFeeAmount,
requiredGasLimit: requiredGasLimit,
message: message
Expand All @@ -114,7 +114,7 @@ contract ExampleCrossChainMessenger is
destinationChainID: destinationChainID,
destinationAddress: destinationAddress,
feeInfo: TeleporterFeeInfo({
contractAddress: feeContractAddress,
feeTokenAddress: feeTokenAddress,
amount: adjustedFeeAmount
}),
requiredGasLimit: requiredGasLimit,
Expand Down
12 changes: 6 additions & 6 deletions contracts/src/CrossChainApplications/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ To start, create the function declarations for `sendMessage`, which will send st
function sendMessage(
bytes32 destinationChainID,
address destinationAddress,
address feeContractAddress,
address feeTokenAddress,
uint256 feeAmount,
uint256 requiredGasLimit,
string calldata message
Expand All @@ -86,19 +86,19 @@ function receiveTeleporterMessage(
) external {}
```

Now it's time to implement the methods, starting with `sendMessage`. First, import OpenZeppelin's `IERC20` contract, then in `sendMessage` check whether `feeAmount` is greater than zero. If it is, transfer and approve the amount of IERC20 asset at `feeContractAddress` to the Teleporter Messenger saved as a state variable. Relayer fees are an optional way to incentive relayers to deliver a Teleporter message to its destination. They are not strictly necessary, and may be omitted if a relayer is willing to relay messages with no fee, such as with a self-hosted relayer.
Now it's time to implement the methods, starting with `sendMessage`. First, import OpenZeppelin's `IERC20` contract, then in `sendMessage` check whether `feeAmount` is greater than zero. If it is, transfer and approve the amount of IERC20 asset at `feeTokenAddress` to the Teleporter Messenger saved as a state variable. Relayer fees are an optional way to incentive relayers to deliver a Teleporter message to its destination. They are not strictly necessary, and may be omitted if a relayer is willing to relay messages with no fee, such as with a self-hosted relayer.

```solidity
// For non-zero fee amounts, transfer the fee into the control of this contract first, and then
// allow the Teleporter contract to spend it.
if (feeAmount > 0) {
IERC20 feeAsset = IERC20(feeContractAddress);
IERC20 feeToken = IERC20(feeTokenAddress);
require(
feeAsset.transferFrom(msg.sender, address(this), feeAmount),
feeToken.transferFrom(msg.sender, address(this), feeAmount),
"Failed to transfer fee amount"
);
require(
feeAsset.approve(address(teleporterMessenger), feeAmount),
feeToken.approve(address(teleporterMessenger), feeAmount),
"Failed to approve fee amount"
);
}
Expand All @@ -116,7 +116,7 @@ return
destinationChainID: destinationChainID,
destinationAddress: destinationAddress,
feeInfo: TeleporterFeeInfo({
contractAddress: feeContractAddress,
feeTokenAddress: feeTokenAddress,
amount: feeAmount
}),
requiredGasLimit: requiredGasLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ contract BlockHashPublisher {
destinationChainID: destinationChainID,
destinationAddress: destinationAddress,
feeInfo: TeleporterFeeInfo({
contractAddress: address(0),
feeTokenAddress: address(0),
amount: 0
}),
requiredGasLimit: RECEIVE_BLOCK_HASH_REQUIRED_GAS_LIMIT,
Expand Down
14 changes: 7 additions & 7 deletions contracts/src/Teleporter/ITeleporterMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct TeleporterMessage {
// The contract address is the asset contract the fee will be paid in, and
// the amount is the amount of that specified asset.
struct TeleporterFeeInfo {
address contractAddress;
address feeTokenAddress;
uint256 amount;
}

Expand Down Expand Up @@ -140,14 +140,14 @@ interface ITeleporterMessenger {
* @dev Adds the additional fee amount to the amount to be paid to the relayer that delivers
* the given message ID to the destination chain.
*
* The fee contract address must be the same asset type as the fee asset specified in the original
* The fee token address must be the same asset type as the fee asset specified in the original
* call to sendCrossChainMessage. Reverts if the message doesn't exist or there is already
* receipt of delivery of the message.
*/
function addFeeAmount(
bytes32 destinationChainID,
uint256 messageID,
address feeContractAddress,
address feeTokenAddress,
uint256 additionalFeeAmount
) external;

Expand Down Expand Up @@ -194,7 +194,7 @@ interface ITeleporterMessenger {
/**
* @dev Sends any fee amount rewards for the given fee asset out to the caller.
*/
function redeemRelayerRewards(address feeAsset) external;
function redeemRelayerRewards(address feeTokenAddress) external;

/**
* @dev Gets the hash of a given message stored in the EVM state, if the message exists.
Expand Down Expand Up @@ -230,12 +230,12 @@ interface ITeleporterMessenger {
*/
function checkRelayerRewardAmount(
address relayer,
address feeAsset
address feeTokenAddress
) external view returns (uint256);

/**
* @dev Gets the fee asset and amount for a given message.
* @return The fee asset address and fee amount for a the given message.
* @dev Gets the fee token address and amount for a given message.
* @return The fee token address and fee amount for a the given message.
*/
function getFeeInfo(
bytes32 destinationChainID,
Expand Down
Loading

0 comments on commit 8cfde6b

Please sign in to comment.