Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arbitrum gateways #57

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ module.exports = {
'matic',
'dev1',
'dev2',
'dev3',
'avax',
'arbitrum',

// names
'nithin',
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12
16
2 changes: 1 addition & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
skipFiles: ['_external', '_mocks'],
skipFiles: ['_external', '_interfaces', '_mocks', '_test'],
mocha: {
timeout: 100000,
},
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ dist: trusty
sudo: required
language: node_js
node_js:
- '12'
- '16'
cache:
directories:
- node_modules
script:
- yarn format
- yarn lint
- yarn test
- yarn coverage
after_success:
- yarn coverage
- cat coverage/lcov.info | npx coveralls
notifications:
email:
Expand Down
69 changes: 69 additions & 0 deletions contracts/_interfaces/bridge-gateways/IArbitrumGateway.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: GPL-3.0-or-later
import {IBCRebaseGatewayEvents, ISCRebaseGatewayEvents, ITransferGatewayEvents} from "./IGateway.sol";
import {ITokenGateway} from "arb-bridge-peripherals/contracts/tokenbridge/libraries/gateway/ITokenGateway.sol";

// Arbitrum chains expect the cross chain transaction to "pre-pay" in eth
// for execution on the other chain
// https://developer.offchainlabs.com/docs/l1_l2_messages

interface IArbitrumBCRebaseGateway is IBCRebaseGatewayEvents {
event RebaseReportInitiated(uint256 indexed _sequenceNumber);

function reportRebaseInit(
uint256 _maxSubmissionCost,
uint256 _maxGas,
uint256 _gasPriceBid
) external payable returns (bytes memory);
}

interface IArbitrumSCRebaseGateway is ISCRebaseGatewayEvents {
event RebaseReportFinalized(uint256 indexed _exitNum);

function reportRebaseCommit(uint256 globalAmpleforthEpoch, uint256 globalAMPLSupply) external;
}

interface IArbitrumTransferGateway is ITransferGatewayEvents, ITokenGateway {
function getOutboundCalldata(
address _l1Token,
address _from,
address _to,
uint256 _amount,
bytes memory _data
) external view returns (bytes memory);
}

interface IArbitrumBCTransferGateway is IArbitrumTransferGateway {
event DepositInitiated(
address l1Token,
address indexed _from,
address indexed _to,
uint256 indexed _sequenceNumber,
uint256 _amount
);

event WithdrawalFinalized(
address l1Token,
address indexed _from,
address indexed _to,
uint256 indexed _exitNum,
uint256 _amount
);
}

interface IArbitrumSCTransferGateway is IArbitrumTransferGateway {
event DepositFinalized(
address indexed l1Token,
address indexed _from,
address indexed _to,
uint256 _amount
);

event WithdrawalInitiated(
address l1Token,
address indexed _from,
address indexed _to,
uint256 indexed _l2ToL1Id,
uint256 _exitNum,
uint256 _amount
);
}
43 changes: 43 additions & 0 deletions contracts/_interfaces/bridge-gateways/IChainBridgeGateway.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: GPL-3.0-or-later

import {IBCRebaseGatewayEvents, ISCRebaseGatewayEvents, ITransferGatewayEvents} from "./IGateway.sol";

interface IChainBridgeBCRebaseGateway is IBCRebaseGatewayEvents {
function validateRebaseReport(uint256 globalAmpleforthEpoch, uint256 globalAMPLSupply) external;
}

interface IChainBridgeSCRebaseGateway is ISCRebaseGatewayEvents {
function reportRebase(uint256 globalAmpleforthEpoch, uint256 globalAMPLSupply) external;
}

interface IChainBridgeBCTransferGateway is ITransferGatewayEvents {
function validateAndLock(
address sender,
address recipientInTargetChain,
uint256 amount,
uint256 globalAMPLSupply
) external;

function unlock(
address senderInSourceChain,
address recipient,
uint256 amount,
uint256 globalAMPLSupply
) external;
}

interface IChainBridgeSCTransferGateway is ITransferGatewayEvents {
function mint(
address senderInSourceChain,
address recipient,
uint256 amount,
uint256 globalAMPLSupply
) external;

function validateAndBurn(
address sender,
address recipientInTargetChain,
uint256 amount,
uint256 globalAMPLSupply
) external;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
// SPDX-License-Identifier: GPL-3.0-or-later

interface IBCRebaseGatewayEvents {
// Logged on the base chain gateway (ethereum) when rebase report is propagated out
event XCRebaseReportOut(
// epoch from the Ampleforth Monetary Policy on the base chain
uint256 globalAmpleforthEpoch,
// totalSupply of AMPL ERC-20 contract on the base chain
uint256 globalAMPLSupply
);
}

interface ISCRebaseGatewayEvents {
// Logged on the satellite chain gateway when bridge reports most recent rebase
event XCRebaseReportIn(
// new value coming in from the base chain
uint256 globalAmpleforthEpoch,
// new value coming in from the base chain
uint256 globalAMPLSupply,
// existing value on the satellite chain
uint256 recordedGlobalAmpleforthEpoch,
// existing value on the satellite chain
uint256 recordedGlobalAMPLSupply
);
}

interface ITransferGatewayEvents {
// Logged on source chain when cross-chain transfer is initiated
event XCTransferOut(
Expand Down
13 changes: 13 additions & 0 deletions contracts/_interfaces/bridge-gateways/IMaticGateway.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-3.0-or-later

import {IBCRebaseGatewayEvents, ISCRebaseGatewayEvents, ITransferGatewayEvents} from "./IGateway.sol";

interface IMaticBCRebaseGateway is IBCRebaseGatewayEvents {
function reportRebase() external;
}

interface IMaticSCRebaseGateway is ISCRebaseGatewayEvents {}

interface IMaticTransferGateway is ITransferGatewayEvents {
function transfer(address recipientInTargetChain, uint256 amount) external;
}
23 changes: 0 additions & 23 deletions contracts/_interfaces/bridge-gateways/IRebaseGatewayEvents.sol

This file was deleted.

85 changes: 85 additions & 0 deletions contracts/_mocks/MockArbitrum.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.6.11;
pragma experimental ABIEncoderV2;

import {InboxMock} from "arb-bridge-peripherals/contracts/tokenbridge/test/InboxMock.sol";
import {L1ArbitrumMessenger} from "arb-bridge-peripherals/contracts/tokenbridge/ethereum/L1ArbitrumMessenger.sol";
import {L2ArbitrumMessenger} from "arb-bridge-peripherals/contracts/tokenbridge/arbitrum/L2ArbitrumMessenger.sol";
import {L1ArbitrumTestMessenger} from "arb-bridge-peripherals/contracts/tokenbridge/test/GatewayTest.sol";
import {L2ArbitrumTestMessenger} from "arb-bridge-peripherals/contracts/tokenbridge/test/GatewayTest.sol";
import {IBridge} from "arb-bridge-peripherals/contracts/tokenbridge/test/GatewayTest.sol";
import {AMPLArbitrumGateway} from "../base-chain/bridge-gateways/AMPLArbitrumGateway.sol";
import {ArbitrumXCAmpleGateway} from "../satellite-chain/bridge-gateways/ArbitrumXCAmpleGateway.sol";

contract MockArbitrumInbox is InboxMock {}

// Mocking sendTxToL2
// https://shorturl.at/dgABO
contract MockAMPLArbitrumGateway is L1ArbitrumTestMessenger, AMPLArbitrumGateway {
constructor(
address ampl_,
address policy_,
address vault_
) public AMPLArbitrumGateway(ampl_, policy_, vault_) {}

function sendTxToL2(
address _inbox,
address _to,
address _user,
uint256 _l1CallValue,
uint256 _l2CallValue,
uint256 _maxSubmissionCost,
uint256 _maxGas,
uint256 _gasPriceBid,
bytes memory _data
) internal virtual override(L1ArbitrumMessenger, L1ArbitrumTestMessenger) returns (uint256) {
return
L1ArbitrumTestMessenger.sendTxToL2(
_inbox,
_to,
_user,
_l1CallValue,
_l2CallValue,
_maxSubmissionCost,
_maxGas,
_gasPriceBid,
_data
);
}

function getL2ToL1Sender(address _inbox)
internal
view
virtual
override(L1ArbitrumMessenger, L1ArbitrumTestMessenger)
returns (address)
{
return L1ArbitrumTestMessenger.getL2ToL1Sender(_inbox);
}

function getBridge(address _inbox)
internal
view
virtual
override(L1ArbitrumMessenger, L1ArbitrumTestMessenger)
returns (IBridge)
{
return L1ArbitrumTestMessenger.getBridge(_inbox);
}
}

contract MockArbitrumXCAmpleGateway is L2ArbitrumTestMessenger, ArbitrumXCAmpleGateway {
constructor(address xcAmple_, address xcController_)
public
ArbitrumXCAmpleGateway(xcAmple_, xcController_)
{}

function sendTxToL1(
uint256 _l1CallValue,
address _from,
address _to,
bytes memory _data
) internal virtual override(L2ArbitrumMessenger, L2ArbitrumTestMessenger) returns (uint256) {
return L2ArbitrumTestMessenger.sendTxToL1(_l1CallValue, _from, _to, _data);
}
}
24 changes: 24 additions & 0 deletions contracts/_test/UFragmentsTestnet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Importing uFragments contract dependencies to be compiled for integration tests
pragma solidity 0.7.6;

import {UFragments} from "uFragments/contracts/UFragments.sol";

contract UFragmentsTestnet is UFragments {
event Result(bool result, bytes reason);

function isArbitrumEnabled() external view returns (uint8) {
return uint8(0xa4b1);
}

// NOTE: this allows the token contarct to register itself with the bridge on testnet
// The AMPL contract on mainnet is immutable and this can't be used!
function externalCall(
address destination,
bytes calldata data,
uint256 value
) external payable {
(bool result, bytes memory reason) = destination.call{value: value}(data);
emit Result(result, reason);
}
}
21 changes: 0 additions & 21 deletions contracts/base-bridge-gateways/ChainBridgeRebaseGateway.sol

This file was deleted.

45 changes: 0 additions & 45 deletions contracts/base-bridge-gateways/ChainBridgeTransferGateway.sol

This file was deleted.

Loading