Skip to content

Commit f4f79e0

Browse files
authored
Merge pull request #23 from ampleforth/elastic-interface
Porting recent changes from base-chain codebase
2 parents 7889425 + 515554b commit f4f79e0

File tree

21 files changed

+833
-101
lines changed

21 files changed

+833
-101
lines changed

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ module.exports = {
101101
'Utf8Bytes',
102102
'keccak256',
103103
'Sighash',
104+
'hre',
105+
'ecsign',
104106

105107
// shorthand
106108
'eth',
@@ -175,6 +177,7 @@ module.exports = {
175177
'rebasing',
176178
'depositer',
177179
'coinmarketcap',
180+
'nonces',
178181

179182
// names
180183
'nithin',

contracts/_interfaces/IAmpleforthPolicy.sol

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

contracts/_interfaces/IXCAmple.sol

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22
pragma solidity 0.6.12;
33

4-
interface IXCAmple {
5-
function globalAMPLSupply() external returns (uint256);
4+
import "uFragments/contracts/interfaces/IAMPL.sol";
65

7-
function mint(address who, uint256 value) external;
8-
9-
function burn(address who, uint256 value) external;
10-
11-
function rebase(uint256 globalAmpleforthEpoch_, uint256 globalAMPLSupply_)
12-
external
13-
returns (uint256);
6+
interface IXCAmple is IAMPL {
7+
function globalAMPLSupply() external view returns (uint256);
148
}

contracts/_interfaces/IXCAmpleController.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
pragma solidity 0.6.12;
33

44
interface IXCAmpleController {
5-
function globalAmpleforthEpoch() external returns (uint256);
5+
function rebase() external;
66

7-
function mint(address recipient, uint256 xcAmplAmount) external;
7+
function lastRebaseTimestampSec() external view returns (uint256);
88

9-
function burn(address depositor, uint256 xcAmplAmount) external;
9+
function globalAmpleforthEpoch() external view returns (uint256);
1010

11-
function reportRebase(uint256 nextGlobalAmpleforthEpoch, uint256 nextGlobalAMPLSupply) external;
11+
function globalAmpleforthEpochAndAMPLSupply() external view returns (uint256, uint256);
1212
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
pragma solidity 0.6.12;
3+
4+
interface IXCAmpleControllerGateway {
5+
function nextGlobalAmpleforthEpoch() external view returns (uint256);
6+
7+
function nextGlobalAMPLSupply() external view returns (uint256);
8+
9+
function mint(address recipient, uint256 xcAmplAmount) external;
10+
11+
function burn(address depositor, uint256 xcAmplAmount) external;
12+
13+
function reportRebase(uint256 nextGlobalAmpleforthEpoch_, uint256 nextGlobalAMPLSupply_)
14+
external;
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
pragma solidity 0.6.12;
3+
4+
interface IXCAmpleSupplyPolicy {
5+
function rebase(uint256 globalAmpleforthEpoch_, uint256 globalAMPLSupply_)
6+
external
7+
returns (uint256);
8+
9+
function mint(address who, uint256 value) external;
10+
11+
function burn(address who, uint256 value) external;
12+
}

contracts/_mocks/MockAmplPolicy.sol renamed to contracts/_mocks/MockAmpleforth.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22
pragma solidity 0.6.12;
33

4-
contract MockAmplPolicy {
4+
contract MockAmpleforth {
55
uint256 public epoch;
66

77
function updateEpoch(uint256 epoch_) external {

contracts/_mocks/MockXCAmple.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ contract MockXCAmple {
1818
}
1919

2020
function rebase(uint256 globalEpoch, uint256 globalAMPLSupply_) external returns (uint256) {
21+
globalAMPLSupply = globalAMPLSupply_;
2122
emit Rebase(globalEpoch, globalAMPLSupply_);
2223
}
2324

contracts/base-chain/bridge-gateways/AMPLChainBridgeGateway.sol

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
55
import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol";
66

77
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
8-
import {IAmpleforthPolicy} from "../../_interfaces/IAmpleforthPolicy.sol";
8+
import {IAmpleforth} from "uFragments/contracts/interfaces/IAmpleforth.sol";
99
import {ITokenVault} from "../../_interfaces/ITokenVault.sol";
1010
import {IBridgeGateway} from "../../_interfaces/IBridgeGateway.sol";
1111

@@ -51,9 +51,8 @@ contract AMPLChainBridgeGateway is IBridgeGateway, Ownable {
5151
function validateRebaseReport(uint256 globalAmpleforthEpoch, uint256 globalAMPLSupply)
5252
external
5353
onlyOwner
54-
returns (bool)
5554
{
56-
uint256 recordedGlobalAmpleforthEpoch = IAmpleforthPolicy(policy).epoch();
55+
uint256 recordedGlobalAmpleforthEpoch = IAmpleforth(policy).epoch();
5756
uint256 recordedGlobalAMPLSupply = IERC20(ampl).totalSupply();
5857

5958
require(
@@ -66,8 +65,6 @@ contract AMPLChainBridgeGateway is IBridgeGateway, Ownable {
6665
);
6766

6867
emit XCRebaseReportOut(globalAmpleforthEpoch, globalAMPLSupply);
69-
70-
return true;
7168
}
7269

7370
/**
@@ -83,7 +80,7 @@ contract AMPLChainBridgeGateway is IBridgeGateway, Ownable {
8380
address recipientAddressInTargetChain,
8481
uint256 amount,
8582
uint256 globalAMPLSupply
86-
) external onlyOwner returns (bool) {
83+
) external onlyOwner {
8784
uint256 recordedGlobalAMPLSupply = IERC20(ampl).totalSupply();
8885

8986
require(
@@ -94,8 +91,6 @@ contract AMPLChainBridgeGateway is IBridgeGateway, Ownable {
9491
ITokenVault(vault).lock(ampl, sender, amount);
9592

9693
emit XCTransferOut(sender, amount, recordedGlobalAMPLSupply);
97-
98-
return true;
9994
}
10095

10196
/**
@@ -111,15 +106,13 @@ contract AMPLChainBridgeGateway is IBridgeGateway, Ownable {
111106
address recipient,
112107
uint256 amount,
113108
uint256 globalAMPLSupply
114-
) external onlyOwner returns (bool) {
109+
) external onlyOwner {
115110
uint256 recordedGlobalAMPLSupply = IERC20(ampl).totalSupply();
116111
uint256 unlockAmount = amount.mul(recordedGlobalAMPLSupply).div(globalAMPLSupply);
117112

118113
emit XCTransferIn(recipient, globalAMPLSupply, unlockAmount, recordedGlobalAMPLSupply);
119114

120115
ITokenVault(vault).unlock(ampl, recipient, unlockAmount);
121-
122-
return true;
123116
}
124117

125118
constructor(

contracts/satellite-chain/bridge-gateways/ChainBridgeXCAmpleGateway.sol

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol";
66

77
import {IBridgeGateway} from "../../_interfaces/IBridgeGateway.sol";
88
import {IXCAmpleController} from "../../_interfaces/IXCAmpleController.sol";
9+
import {IXCAmpleControllerGateway} from "../../_interfaces/IXCAmpleControllerGateway.sol";
910
import {IXCAmple} from "../../_interfaces/IXCAmple.sol";
1011

1112
/**
@@ -45,7 +46,6 @@ contract ChainBridgeXCAmpleGateway is IBridgeGateway, Ownable {
4546
function reportRebase(uint256 globalAmpleforthEpoch, uint256 globalAMPLSupply)
4647
external
4748
onlyOwner
48-
returns (bool)
4949
{
5050
uint256 recordedGlobalAmpleforthEpoch = IXCAmpleController(xcController)
5151
.globalAmpleforthEpoch();
@@ -59,9 +59,10 @@ contract ChainBridgeXCAmpleGateway is IBridgeGateway, Ownable {
5959
recordedGlobalAMPLSupply
6060
);
6161

62-
IXCAmpleController(xcController).reportRebase(globalAmpleforthEpoch, globalAMPLSupply);
63-
64-
return true;
62+
IXCAmpleControllerGateway(xcController).reportRebase(
63+
globalAmpleforthEpoch,
64+
globalAMPLSupply
65+
);
6566
}
6667

6768
/**
@@ -78,15 +79,13 @@ contract ChainBridgeXCAmpleGateway is IBridgeGateway, Ownable {
7879
address recipient,
7980
uint256 amount,
8081
uint256 globalAMPLSupply
81-
) external onlyOwner returns (bool) {
82+
) external onlyOwner {
8283
uint256 recordedGlobalAMPLSupply = IXCAmple(xcAmple).globalAMPLSupply();
8384
uint256 mintAmount = amount.mul(recordedGlobalAMPLSupply).div(globalAMPLSupply);
8485

8586
emit XCTransferIn(recipient, globalAMPLSupply, mintAmount, recordedGlobalAMPLSupply);
8687

87-
IXCAmpleController(xcController).mint(recipient, mintAmount);
88-
89-
return true;
88+
IXCAmpleControllerGateway(xcController).mint(recipient, mintAmount);
9089
}
9190

9291
/**
@@ -101,18 +100,16 @@ contract ChainBridgeXCAmpleGateway is IBridgeGateway, Ownable {
101100
address recipientAddressInTargetChain,
102101
uint256 amount,
103102
uint256 globalAMPLSupply
104-
) external onlyOwner returns (bool) {
103+
) external onlyOwner {
105104
uint256 recordedGlobalAMPLSupply = IXCAmple(xcAmple).globalAMPLSupply();
106105
require(
107106
globalAMPLSupply == recordedGlobalAMPLSupply,
108107
"ChainBridgeXCAmpleGateway: total supply not consistent"
109108
);
110109

111-
IXCAmpleController(xcController).burn(sender, amount);
110+
IXCAmpleControllerGateway(xcController).burn(sender, amount);
112111

113112
emit XCTransferOut(sender, amount, recordedGlobalAMPLSupply);
114-
115-
return true;
116113
}
117114

118115
constructor(

0 commit comments

Comments
 (0)