Skip to content

Commit

Permalink
intermediate
Browse files Browse the repository at this point in the history
  • Loading branch information
aalavandhan committed Oct 21, 2021
1 parent 7794c0e commit 7b7a7ca
Show file tree
Hide file tree
Showing 65 changed files with 5,397 additions and 3,310 deletions.
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 .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dist: trusty
sudo: required
language: node_js
node_js:
- '12'
- '16'
cache:
directories:
- node_modules
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ token: 0xDB021b1B247fe2F1fa57e0A87C748Cc1E321F07F
controller: 0x17F084dFF8a71e38521BCBD3Da871753Dc67aa81
rebaseRelayer: 0x0c0144D04594AB99F4C02691B6684e3d871B589e

# AVAX (controlled by Ampleforth Bridge DAO on AVAX)
owner: 0x744ab0D47Ce9650E4d0eD45112d04BaA19dF4260
token: 0x027dbcA046ca156De9622cD1e2D907d375e53aa7
controller: 0x24232ccAf8bB87908C419aD7dDCca8cc9e74746d
rebaseRelayer: 0xE3a0B70676ed6e1947140Ff0b332cAe7d7f0364B

# Matic / Polygon (controlled by Ampleforth Bridge DAO on Matic)
owner: 0x5d96A65E51A78C511C545a0247eb2d006912b636
token: 0xc67238827da94B15F6bA10F3d35f690809919F75
Expand Down
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);
}
}
6 changes: 5 additions & 1 deletion contracts/_mocks/MockRebaseRelayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
pragma solidity 0.7.3;

contract MockRebaseRelayer {
enum State {Failure, Revert, Success}
enum State {
Failure,
Revert,
Success
}
State private state;

function executeAll() external view returns (bool) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/_mocks/MockXCAmple.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract MockXCAmple {
emit Mint(who, value);
}

function burnFrom(address who, uint256 value) external {
function burn(address who, uint256 value) external {
emit Burn(who, value);
}
}
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

0 comments on commit 7b7a7ca

Please sign in to comment.