Skip to content

Commit 7b7a7ca

Browse files
committed
intermediate
1 parent 7794c0e commit 7b7a7ca

File tree

65 files changed

+5397
-3310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+5397
-3310
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12
1+
16

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ dist: trusty
22
sudo: required
33
language: node_js
44
node_js:
5-
- '12'
5+
- '16'
66
cache:
77
directories:
88
- node_modules

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ token: 0xDB021b1B247fe2F1fa57e0A87C748Cc1E321F07F
3737
controller: 0x17F084dFF8a71e38521BCBD3Da871753Dc67aa81
3838
rebaseRelayer: 0x0c0144D04594AB99F4C02691B6684e3d871B589e
3939

40-
# AVAX (controlled by Ampleforth Bridge DAO on AVAX)
41-
owner: 0x744ab0D47Ce9650E4d0eD45112d04BaA19dF4260
42-
token: 0x027dbcA046ca156De9622cD1e2D907d375e53aa7
43-
controller: 0x24232ccAf8bB87908C419aD7dDCca8cc9e74746d
44-
rebaseRelayer: 0xE3a0B70676ed6e1947140Ff0b332cAe7d7f0364B
45-
4640
# Matic / Polygon (controlled by Ampleforth Bridge DAO on Matic)
4741
owner: 0x5d96A65E51A78C511C545a0247eb2d006912b636
4842
token: 0xc67238827da94B15F6bA10F3d35f690809919F75

contracts/_interfaces/IXCAmple.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ interface IXCAmple is IAMPL {
66

77
function mint(address who, uint256 xcAmpleAmount) external;
88

9+
function burn(address who, uint256 xcAmpleAmount) external;
10+
911
function burnFrom(address who, uint256 xcAmpleAmount) external;
1012
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
import {IBCRebaseGatewayEvents, ISCRebaseGatewayEvents, ITransferGatewayEvents} from "./IGateway.sol";
3+
import {ITokenGateway} from "arb-bridge-peripherals/contracts/tokenbridge/libraries/gateway/ITokenGateway.sol";
4+
5+
// Arbitrum chains expect the cross chain transaction to "pre-pay" in eth
6+
// for execution on the other chain
7+
// https://developer.offchainlabs.com/docs/l1_l2_messages
8+
9+
interface IArbitrumBCRebaseGateway is IBCRebaseGatewayEvents {
10+
event RebaseReportInitiated(uint256 indexed _sequenceNumber);
11+
12+
function reportRebaseInit(
13+
uint256 _maxSubmissionCost,
14+
uint256 _maxGas,
15+
uint256 _gasPriceBid
16+
) external payable returns (bytes memory);
17+
}
18+
19+
interface IArbitrumSCRebaseGateway is ISCRebaseGatewayEvents {
20+
event RebaseReportFinalized(uint256 indexed _exitNum);
21+
22+
function reportRebaseCommit(uint256 globalAmpleforthEpoch, uint256 globalAMPLSupply) external;
23+
}
24+
25+
interface IArbitrumTransferGateway is ITransferGatewayEvents, ITokenGateway {
26+
function getOutboundCalldata(
27+
address _l1Token,
28+
address _from,
29+
address _to,
30+
uint256 _amount,
31+
bytes memory _data
32+
) external view returns (bytes memory);
33+
}
34+
35+
interface IArbitrumBCTransferGateway is IArbitrumTransferGateway {
36+
event DepositInitiated(
37+
address l1Token,
38+
address indexed _from,
39+
address indexed _to,
40+
uint256 indexed _sequenceNumber,
41+
uint256 _amount
42+
);
43+
44+
event WithdrawalFinalized(
45+
address l1Token,
46+
address indexed _from,
47+
address indexed _to,
48+
uint256 indexed _exitNum,
49+
uint256 _amount
50+
);
51+
}
52+
53+
interface IArbitrumSCTransferGateway is IArbitrumTransferGateway {
54+
event DepositFinalized(
55+
address indexed l1Token,
56+
address indexed _from,
57+
address indexed _to,
58+
uint256 _amount
59+
);
60+
61+
event WithdrawalInitiated(
62+
address l1Token,
63+
address indexed _from,
64+
address indexed _to,
65+
uint256 indexed _l2ToL1Id,
66+
uint256 _exitNum,
67+
uint256 _amount
68+
);
69+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
import {IBCRebaseGatewayEvents, ISCRebaseGatewayEvents, ITransferGatewayEvents} from "./IGateway.sol";
4+
5+
interface IChainBridgeBCRebaseGateway is IBCRebaseGatewayEvents {
6+
function validateRebaseReport(uint256 globalAmpleforthEpoch, uint256 globalAMPLSupply) external;
7+
}
8+
9+
interface IChainBridgeSCRebaseGateway is ISCRebaseGatewayEvents {
10+
function reportRebase(uint256 globalAmpleforthEpoch, uint256 globalAMPLSupply) external;
11+
}
12+
13+
interface IChainBridgeBCTransferGateway is ITransferGatewayEvents {
14+
function validateAndLock(
15+
address sender,
16+
address recipientInTargetChain,
17+
uint256 amount,
18+
uint256 globalAMPLSupply
19+
) external;
20+
21+
function unlock(
22+
address senderInSourceChain,
23+
address recipient,
24+
uint256 amount,
25+
uint256 globalAMPLSupply
26+
) external;
27+
}
28+
29+
interface IChainBridgeSCTransferGateway is ITransferGatewayEvents {
30+
function mint(
31+
address senderInSourceChain,
32+
address recipient,
33+
uint256 amount,
34+
uint256 globalAMPLSupply
35+
) external;
36+
37+
function validateAndBurn(
38+
address sender,
39+
address recipientInTargetChain,
40+
uint256 amount,
41+
uint256 globalAMPLSupply
42+
) external;
43+
}

contracts/_interfaces/bridge-gateways/ITransferGatewayEvents.sol renamed to contracts/_interfaces/bridge-gateways/IGateway.sol

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22

3+
interface IBCRebaseGatewayEvents {
4+
// Logged on the base chain gateway (ethereum) when rebase report is propagated out
5+
event XCRebaseReportOut(
6+
// epoch from the Ampleforth Monetary Policy on the base chain
7+
uint256 globalAmpleforthEpoch,
8+
// totalSupply of AMPL ERC-20 contract on the base chain
9+
uint256 globalAMPLSupply
10+
);
11+
}
12+
13+
interface ISCRebaseGatewayEvents {
14+
// Logged on the satellite chain gateway when bridge reports most recent rebase
15+
event XCRebaseReportIn(
16+
// new value coming in from the base chain
17+
uint256 globalAmpleforthEpoch,
18+
// new value coming in from the base chain
19+
uint256 globalAMPLSupply,
20+
// existing value on the satellite chain
21+
uint256 recordedGlobalAmpleforthEpoch,
22+
// existing value on the satellite chain
23+
uint256 recordedGlobalAMPLSupply
24+
);
25+
}
26+
327
interface ITransferGatewayEvents {
428
// Logged on source chain when cross-chain transfer is initiated
529
event XCTransferOut(
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
import {IBCRebaseGatewayEvents, ISCRebaseGatewayEvents, ITransferGatewayEvents} from "./IGateway.sol";
4+
5+
interface IMaticBCRebaseGateway is IBCRebaseGatewayEvents {
6+
function reportRebase() external;
7+
}
8+
9+
interface IMaticSCRebaseGateway is ISCRebaseGatewayEvents {}
10+
11+
interface IMaticTransferGateway is ITransferGatewayEvents {
12+
function transfer(address recipientInTargetChain, uint256 amount) external;
13+
}

contracts/_interfaces/bridge-gateways/IRebaseGatewayEvents.sol

Lines changed: 0 additions & 23 deletions
This file was deleted.

contracts/_mocks/MockArbitrum.sol

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
pragma solidity 0.6.11;
3+
pragma experimental ABIEncoderV2;
4+
5+
import {InboxMock} from "arb-bridge-peripherals/contracts/tokenbridge/test/InboxMock.sol";
6+
import {L1ArbitrumMessenger} from "arb-bridge-peripherals/contracts/tokenbridge/ethereum/L1ArbitrumMessenger.sol";
7+
import {L2ArbitrumMessenger} from "arb-bridge-peripherals/contracts/tokenbridge/arbitrum/L2ArbitrumMessenger.sol";
8+
import {L1ArbitrumTestMessenger} from "arb-bridge-peripherals/contracts/tokenbridge/test/GatewayTest.sol";
9+
import {L2ArbitrumTestMessenger} from "arb-bridge-peripherals/contracts/tokenbridge/test/GatewayTest.sol";
10+
import {IBridge} from "arb-bridge-peripherals/contracts/tokenbridge/test/GatewayTest.sol";
11+
import {AMPLArbitrumGateway} from "../base-chain/bridge-gateways/AMPLArbitrumGateway.sol";
12+
import {ArbitrumXCAmpleGateway} from "../satellite-chain/bridge-gateways/ArbitrumXCAmpleGateway.sol";
13+
14+
contract MockArbitrumInbox is InboxMock {}
15+
16+
// Mocking sendTxToL2
17+
// https://shorturl.at/dgABO
18+
contract MockAMPLArbitrumGateway is L1ArbitrumTestMessenger, AMPLArbitrumGateway {
19+
constructor(
20+
address ampl_,
21+
address policy_,
22+
address vault_
23+
) public AMPLArbitrumGateway(ampl_, policy_, vault_) {}
24+
25+
function sendTxToL2(
26+
address _inbox,
27+
address _to,
28+
address _user,
29+
uint256 _l1CallValue,
30+
uint256 _l2CallValue,
31+
uint256 _maxSubmissionCost,
32+
uint256 _maxGas,
33+
uint256 _gasPriceBid,
34+
bytes memory _data
35+
) internal virtual override(L1ArbitrumMessenger, L1ArbitrumTestMessenger) returns (uint256) {
36+
return
37+
L1ArbitrumTestMessenger.sendTxToL2(
38+
_inbox,
39+
_to,
40+
_user,
41+
_l1CallValue,
42+
_l2CallValue,
43+
_maxSubmissionCost,
44+
_maxGas,
45+
_gasPriceBid,
46+
_data
47+
);
48+
}
49+
50+
function getL2ToL1Sender(address _inbox)
51+
internal
52+
view
53+
virtual
54+
override(L1ArbitrumMessenger, L1ArbitrumTestMessenger)
55+
returns (address)
56+
{
57+
return L1ArbitrumTestMessenger.getL2ToL1Sender(_inbox);
58+
}
59+
60+
function getBridge(address _inbox)
61+
internal
62+
view
63+
virtual
64+
override(L1ArbitrumMessenger, L1ArbitrumTestMessenger)
65+
returns (IBridge)
66+
{
67+
return L1ArbitrumTestMessenger.getBridge(_inbox);
68+
}
69+
}
70+
71+
contract MockArbitrumXCAmpleGateway is L2ArbitrumTestMessenger, ArbitrumXCAmpleGateway {
72+
constructor(address xcAmple_, address xcController_)
73+
public
74+
ArbitrumXCAmpleGateway(xcAmple_, xcController_)
75+
{}
76+
77+
function sendTxToL1(
78+
uint256 _l1CallValue,
79+
address _from,
80+
address _to,
81+
bytes memory _data
82+
) internal virtual override(L2ArbitrumMessenger, L2ArbitrumTestMessenger) returns (uint256) {
83+
return L2ArbitrumTestMessenger.sendTxToL1(_l1CallValue, _from, _to, _data);
84+
}
85+
}

0 commit comments

Comments
 (0)