Skip to content

Commit 7889425

Browse files
authored
Merge pull request #20 from ampleforth/minor-fixes
Minor fixes
2 parents b982e72 + d90fc0a commit 7889425

File tree

10 files changed

+95
-61
lines changed

10 files changed

+95
-61
lines changed

.solcover.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
skipFiles: ['_external', '_mocks'],
33
mocha: {
4-
timeout: 100000
4+
timeout: 100000,
55
},
66
};

contracts/_utilities/BatchTxExecutor.sol

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

4-
import "@openzeppelin/contracts/math/SafeMath.sol";
5-
import "@openzeppelin/contracts/access/Ownable.sol";
4+
import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol";
5+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
66

77
/**
88
* @title BatchTxExecutor

contracts/base-chain/TokenVault.sol

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

4-
import "@openzeppelin/contracts/access/Ownable.sol";
5-
import "@openzeppelin/contracts/math/SafeMath.sol";
6-
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
4+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
5+
import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol";
6+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
77

88
/**
99
* @title TokenVault
@@ -26,14 +26,14 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
2626
contract TokenVault is Ownable {
2727
using SafeMath for uint256;
2828

29-
event Locked(
29+
event GatewayLocked(
3030
address indexed bridgeGateway,
3131
address indexed token,
3232
address indexed depositor,
3333
uint256 amount
3434
);
3535

36-
event Unlocked(
36+
event GatewayUnlocked(
3737
address indexed bridgeGateway,
3838
address indexed token,
3939
address indexed recipient,
@@ -83,32 +83,39 @@ contract TokenVault is Ownable {
8383

8484
/**
8585
* @notice Transfers specified amount from the depositor's wallet and locks it in the gateway contract.
86+
* @param token address of the token to lock.
87+
* @param depositor address of wallet to transfer specified token from
88+
* @param amount amount of tokens to transfer
8689
*/
8790
function lock(
8891
address token,
8992
address depositor,
9093
uint256 amount
9194
) external onlyBridgeGateway {
9295
require(IERC20(token).transferFrom(depositor, address(this), amount));
93-
emit Locked(msg.sender, token, depositor, amount);
96+
emit GatewayLocked(msg.sender, token, depositor, amount);
9497
}
9598

9699
/**
97100
* @notice Unlocks the specified amount from the gateway contract and transfers it to the recipient.
101+
* @param token address of the token to unlock.
102+
* @param recipient address of wallet to transfer specified token to
103+
* @param amount amount of tokens to transfer
98104
*/
99105
function unlock(
100106
address token,
101107
address recipient,
102108
uint256 amount
103109
) external onlyBridgeGateway {
104110
require(IERC20(token).transfer(recipient, amount));
105-
emit Unlocked(msg.sender, token, recipient, amount);
111+
emit GatewayUnlocked(msg.sender, token, recipient, amount);
106112
}
107113

108114
/**
109-
* @notice Total token balance secured by the gateway contract.
115+
* @notice Total balance of the specified token, held by this vault.
116+
* @param token address of the token to check.
110117
*/
111-
function totalLocked(address token) public view returns (uint256) {
118+
function totalLocked(address token) external view returns (uint256) {
112119
return IERC20(token).balanceOf(address(this));
113120
}
114121
}

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

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

4-
import "@openzeppelin/contracts/access/Ownable.sol";
5-
import "@openzeppelin/contracts/math/SafeMath.sol";
6-
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
7-
import "../../_interfaces/IAmpleforthPolicy.sol";
8-
import "../../_interfaces/ITokenVault.sol";
9-
import "../../_interfaces/IBridgeGateway.sol";
4+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
5+
import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol";
6+
7+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
8+
import {IAmpleforthPolicy} from "../../_interfaces/IAmpleforthPolicy.sol";
9+
import {ITokenVault} from "../../_interfaces/ITokenVault.sol";
10+
import {IBridgeGateway} from "../../_interfaces/IBridgeGateway.sol";
1011

1112
/**
1213
* @title AMPLChainBridgeGateway: AMPL-ChainBridge Gateway Contract
@@ -48,7 +49,7 @@ contract AMPLChainBridgeGateway is IBridgeGateway, Ownable {
4849
* @param globalAMPLSupply AMPL ERC-20 total supply.
4950
*/
5051
function validateRebaseReport(uint256 globalAmpleforthEpoch, uint256 globalAMPLSupply)
51-
public
52+
external
5253
onlyOwner
5354
returns (bool)
5455
{
@@ -82,7 +83,7 @@ contract AMPLChainBridgeGateway is IBridgeGateway, Ownable {
8283
address recipientAddressInTargetChain,
8384
uint256 amount,
8485
uint256 globalAMPLSupply
85-
) public onlyOwner returns (bool) {
86+
) external onlyOwner returns (bool) {
8687
uint256 recordedGlobalAMPLSupply = IERC20(ampl).totalSupply();
8788

8889
require(
@@ -110,7 +111,7 @@ contract AMPLChainBridgeGateway is IBridgeGateway, Ownable {
110111
address recipient,
111112
uint256 amount,
112113
uint256 globalAMPLSupply
113-
) public onlyOwner returns (bool) {
114+
) external onlyOwner returns (bool) {
114115
uint256 recordedGlobalAMPLSupply = IERC20(ampl).totalSupply();
115116
uint256 unlockAmount = amount.mul(recordedGlobalAMPLSupply).div(globalAMPLSupply);
116117

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

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

4-
import "@openzeppelin/contracts/access/Ownable.sol";
5-
import "@openzeppelin/contracts/math/SafeMath.sol";
6-
import "../../_interfaces/IBridgeGateway.sol";
7-
import "../../_interfaces/IXCAmpleController.sol";
8-
import "../../_interfaces/IXCAmple.sol";
4+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
5+
import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol";
6+
7+
import {IBridgeGateway} from "../../_interfaces/IBridgeGateway.sol";
8+
import {IXCAmpleController} from "../../_interfaces/IXCAmpleController.sol";
9+
import {IXCAmple} from "../../_interfaces/IXCAmple.sol";
910

1011
/**
1112
* @title ChainBridgeXCAmpleGateway

contracts/satellite-chain/xc-ampleforth/XCAmple.sol

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

4-
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
5-
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol";
6-
import "@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol";
4+
import {
5+
SafeMathUpgradeable
6+
} from "@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol";
7+
import {
8+
IERC20Upgradeable
9+
} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
10+
import {
11+
OwnableUpgradeable
12+
} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
713

814
/**
915
* @title XC(cross-chain)Ample ERC20 token
@@ -15,9 +21,9 @@ import "@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol";
1521
* Additionally, the XCAmple contract lets the XCAmpleController
1622
* `mint` or `burn` tokens.
1723
*/
18-
contract XCAmple is IERC20, OwnableUpgradeSafe {
24+
contract XCAmple is IERC20Upgradeable, OwnableUpgradeable {
1925
// PLEASE EXERCISE CAUTION BEFORE CHANGING ANY ACCOUNTING OR MATH
20-
using SafeMath for uint256;
26+
using SafeMathUpgradeable for uint256;
2127

2228
event LogRebase(uint256 indexed epoch, uint256 globalAMPLSupply);
2329
event ControllerUpdated(address controller);
@@ -80,6 +86,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
8086

8187
/**
8288
* @dev XCAmpleController notifies this contract about a new rebase cycle.
89+
* @param epoch The rebase epoch number.
8390
* @param newGlobalAMPLSupply The new total supply of AMPL from the base chain.
8491
* @return The new total AMPL supply.
8592
*/
@@ -128,15 +135,15 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
128135
/**
129136
* @dev Returns the name of the token.
130137
*/
131-
function name() public view returns (string memory) {
138+
function name() external view returns (string memory) {
132139
return _name;
133140
}
134141

135142
/**
136143
* @dev Returns the symbol of the token, usually a shorter version of the
137144
* name.
138145
*/
139-
function symbol() public view returns (string memory) {
146+
function symbol() external view returns (string memory) {
140147
return _symbol;
141148
}
142149

@@ -149,22 +156,22 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
149156
* no way affects any of the arithmetic of the contract, including
150157
* {IERC20-balanceOf} and {IERC20-transfer}.
151158
*/
152-
function decimals() public view returns (uint8) {
159+
function decimals() external view returns (uint8) {
153160
return _decimals;
154161
}
155162

156163
/**
157164
* @return The total supply of xcAmples.
158165
*/
159-
function totalSupply() public view override returns (uint256) {
166+
function totalSupply() external view override returns (uint256) {
160167
return _totalSupply;
161168
}
162169

163170
/**
164171
* @param who The address to query.
165172
* @return The balance of the specified address.
166173
*/
167-
function balanceOf(address who) public view override returns (uint256) {
174+
function balanceOf(address who) external view override returns (uint256) {
168175
return _gonBalances[who].div(_gonsPerAMPL);
169176
}
170177

@@ -174,7 +181,12 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
174181
* @param value The amount to be transferred.
175182
* @return True on success, false otherwise.
176183
*/
177-
function transfer(address to, uint256 value) public override validRecipient(to) returns (bool) {
184+
function transfer(address to, uint256 value)
185+
external
186+
override
187+
validRecipient(to)
188+
returns (bool)
189+
{
178190
uint256 gonValue = value.mul(_gonsPerAMPL);
179191
_gonBalances[msg.sender] = _gonBalances[msg.sender].sub(gonValue);
180192
_gonBalances[to] = _gonBalances[to].add(gonValue);
@@ -188,7 +200,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
188200
* @param spender The address which will spend the funds.
189201
* @return The number of tokens still available for the spender.
190202
*/
191-
function allowance(address owner_, address spender) public view override returns (uint256) {
203+
function allowance(address owner_, address spender) external view override returns (uint256) {
192204
return _allowedXCAmples[owner_][spender];
193205
}
194206

@@ -202,7 +214,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
202214
address from,
203215
address to,
204216
uint256 value
205-
) public override validRecipient(to) returns (bool) {
217+
) external override validRecipient(to) returns (bool) {
206218
_allowedXCAmples[from][msg.sender] = _allowedXCAmples[from][msg.sender].sub(value);
207219

208220
uint256 gonValue = value.mul(_gonsPerAMPL);
@@ -224,7 +236,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
224236
* @param spender The address which will spend the funds.
225237
* @param value The amount of tokens to be spent.
226238
*/
227-
function approve(address spender, uint256 value) public override returns (bool) {
239+
function approve(address spender, uint256 value) external override returns (bool) {
228240
_allowedXCAmples[msg.sender][spender] = value;
229241
emit Approval(msg.sender, spender, value);
230242
return true;
@@ -237,7 +249,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
237249
* @param spender The address which will spend the funds.
238250
* @param addedValue The amount of tokens to increase the allowance by.
239251
*/
240-
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
252+
function increaseAllowance(address spender, uint256 addedValue) external returns (bool) {
241253
_allowedXCAmples[msg.sender][spender] = _allowedXCAmples[msg.sender][spender].add(
242254
addedValue
243255
);
@@ -251,7 +263,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
251263
* @param spender The address which will spend the funds.
252264
* @param subtractedValue The amount of tokens to decrease the allowance by.
253265
*/
254-
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
266+
function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool) {
255267
uint256 oldValue = _allowedXCAmples[msg.sender][spender];
256268
if (subtractedValue >= oldValue) {
257269
_allowedXCAmples[msg.sender][spender] = 0;
@@ -268,7 +280,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
268280
* @param who The address of the beneficiary.
269281
* @param xcAmpleAmount The amount of xcAmple tokens to be minted.
270282
*/
271-
function mint(address who, uint256 xcAmpleAmount) public onlyController validRecipient(who) {
283+
function mint(address who, uint256 xcAmpleAmount) external onlyController validRecipient(who) {
272284
uint256 gonValue = xcAmpleAmount.mul(_gonsPerAMPL);
273285
_gonBalances[who] = _gonBalances[who].add(gonValue);
274286
_totalSupply = _totalSupply.add(xcAmpleAmount);
@@ -285,7 +297,7 @@ contract XCAmple is IERC20, OwnableUpgradeSafe {
285297
* @param who The address of the beneficiary.
286298
* @param xcAmpleAmount The amount of xcAmple tokens to be burned.
287299
*/
288-
function burn(address who, uint256 xcAmpleAmount) public onlyController {
300+
function burn(address who, uint256 xcAmpleAmount) external onlyController {
289301
require(who != address(0), "XCAmple: burn address zero address");
290302

291303
uint256 gonValue = xcAmpleAmount.mul(_gonsPerAMPL);

contracts/satellite-chain/xc-ampleforth/XCAmpleController.sol

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22
pragma solidity 0.6.12;
33

4-
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
5-
import "@openzeppelin/contracts-ethereum-package/contracts/math/SignedSafeMath.sol";
6-
import "@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol";
7-
8-
import "./UInt256Lib.sol";
9-
import "../../_interfaces/IXCAmple.sol";
10-
import "../../_interfaces/IBatchTxExecutor.sol";
4+
import {
5+
SafeMathUpgradeable
6+
} from "@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol";
7+
import {
8+
SignedSafeMathUpgradeable
9+
} from "@openzeppelin/contracts-upgradeable/math/SignedSafeMathUpgradeable.sol";
10+
import {
11+
OwnableUpgradeable
12+
} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
13+
14+
import {UInt256Lib} from "./UInt256Lib.sol";
15+
import {IXCAmple} from "../../_interfaces/IXCAmple.sol";
16+
import {IBatchTxExecutor} from "../../_interfaces/IBatchTxExecutor.sol";
1117

1218
/**
1319
* @title XC(Cross-Chain)Ample Controller
@@ -17,9 +23,9 @@ import "../../_interfaces/IBatchTxExecutor.sol";
1723
* rebase on XCAmple, based on updated AMPL supply reported through
1824
* the bridge gateway.
1925
*/
20-
contract XCAmpleController is OwnableUpgradeSafe {
21-
using SafeMath for uint256;
22-
using SignedSafeMath for int256;
26+
contract XCAmpleController is OwnableUpgradeable {
27+
using SafeMathUpgradeable for uint256;
28+
using SignedSafeMathUpgradeable for int256;
2329
using UInt256Lib for uint256;
2430

2531
event GatewayMint(
@@ -151,7 +157,7 @@ contract XCAmpleController is OwnableUpgradeSafe {
151157
* After rebase, it notifies down-stream platforms by executing post-rebase callbacks
152158
* on the rebase relayer.
153159
*/
154-
function rebase() public {
160+
function rebase() external {
155161
// recently reported epoch needs to be more than current globalEpoch in storage
156162
require(
157163
nextGlobalAmpleforthEpoch > globalAmpleforthEpoch,
@@ -184,8 +190,10 @@ contract XCAmpleController is OwnableUpgradeSafe {
184190
* @dev ZOS upgradable contract initialization method.
185191
* It is called at the time of contract creation to invoke parent class initializers and
186192
* initialize the contract's state variables.
193+
* @param xcAmple_ reference to the cross-chain ample token erc-20 contract
194+
* @param globalAmpleforthEpoch_ the epoch number from monetary policy on the base chain
187195
*/
188-
function initialize(address xcAmple_, uint256 globalAmpleforthEpoch_) public initializer {
196+
function initialize(address xcAmple_, uint256 globalAmpleforthEpoch_) external initializer {
189197
__Ownable_init();
190198

191199
xcAmple = xcAmple_;

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
],
2020
"dependencies": {
2121
"@openzeppelin/contracts": "^3.2.0",
22-
"@openzeppelin/contracts-ethereum-package": "^3.0.0",
22+
"@openzeppelin/contracts-upgradeable": "^3.3.0",
2323
"chainbridge-solidity": "https://github.com/ChainSafe/chainbridge-solidity#master",
24-
"uFragments": "https://github.com/ampleforth/uFragments#master",
25-
"market-oracle": "https://github.com/ampleforth/market-oracle#master"
24+
"market-oracle": "https://github.com/ampleforth/market-oracle#master",
25+
"uFragments": "https://github.com/ampleforth/uFragments#master"
2626
},
2727
"devDependencies": {
2828
"@nomiclabs/hardhat-ethers": "^2.0.1",

0 commit comments

Comments
 (0)