Skip to content

Commit

Permalink
arb gateway contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
aalavandhan committed Oct 25, 2021
1 parent 7910fb3 commit ba184eb
Show file tree
Hide file tree
Showing 27 changed files with 4,388 additions and 2,171 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12
16
2 changes: 2 additions & 0 deletions contracts/_interfaces/IXCAmple.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ interface IXCAmple is IAMPL {

function mint(address who, uint256 xcAmpleAmount) external;

function burn(address who, uint256 xcAmpleAmount) external;

function burnFrom(address who, uint256 xcAmpleAmount) external;
}
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);
}
}
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.

10 changes: 0 additions & 10 deletions contracts/base-bridge-gateways/Layer2RebaseGateway.sol

This file was deleted.

10 changes: 0 additions & 10 deletions contracts/base-bridge-gateways/Layer2TransferGateway.sol

This file was deleted.

Loading

0 comments on commit ba184eb

Please sign in to comment.