Skip to content

Commit feb0ba5

Browse files
authored
Merge the develop branch to the master branch, preparation to v5.4.1
2 parents e442eb2 + 656fd3b commit feb0ba5

File tree

10 files changed

+134
-15
lines changed

10 files changed

+134
-15
lines changed

.github/workflows/release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: release
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
flats:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- id: get_release
12+
uses: bruceadams/[email protected]
13+
env:
14+
GITHUB_TOKEN: ${{ github.token }}
15+
- uses: actions/setup-node@v1
16+
with:
17+
node-version: 10
18+
- uses: actions/checkout@v2
19+
- uses: actions/cache@v2
20+
id: npm-cache
21+
with:
22+
path: node_modules
23+
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }}
24+
- run: npm install
25+
if: ${{ !steps.npm-cache.outputs.cache-hit }}
26+
- run: npm run flatten
27+
- run: zip flats $(find flats -name '*.sol')
28+
- uses: actions/[email protected]
29+
env:
30+
GITHUB_TOKEN: ${{ github.token }}
31+
with:
32+
upload_url: ${{ steps.get_release.outputs.upload_url }}
33+
asset_path: flats.zip
34+
asset_name: tokenbridge-contracts-flattened-${{ steps.get_release.outputs.tag_name }}.zip
35+
asset_content_type: application/zip

contracts/libraries/SafeERC20.sol

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
pragma solidity 0.4.24;
2+
3+
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
4+
import "../interfaces/ERC677.sol";
5+
6+
/**
7+
* @title SafeERC20
8+
* @dev Helper methods for safe token transfers.
9+
* Functions perform additional checks to be sure that token transfer really happened.
10+
*/
11+
library SafeERC20 {
12+
using SafeMath for uint256;
13+
14+
/**
15+
* @dev Same as ERC20.transfer(address,uint256) but with extra consistency checks.
16+
* @param _token address of the token contract
17+
* @param _to address of the receiver
18+
* @param _value amount of tokens to send
19+
*/
20+
function safeTransfer(address _token, address _to, uint256 _value) internal {
21+
LegacyERC20(_token).transfer(_to, _value);
22+
assembly {
23+
if returndatasize {
24+
returndatacopy(0, 0, 32)
25+
if iszero(mload(0)) {
26+
revert(0, 0)
27+
}
28+
}
29+
}
30+
}
31+
32+
/**
33+
* @dev Same as ERC20.transferFrom(address,address,uint256) but with extra consistency checks.
34+
* @param _token address of the token contract
35+
* @param _from address of the sender
36+
* @param _value amount of tokens to send
37+
*/
38+
function safeTransferFrom(address _token, address _from, uint256 _value) internal {
39+
LegacyERC20(_token).transferFrom(_from, address(this), _value);
40+
assembly {
41+
if returndatasize {
42+
returndatacopy(0, 0, 32)
43+
if iszero(mload(0)) {
44+
revert(0, 0)
45+
}
46+
}
47+
}
48+
}
49+
}

contracts/upgradeable_contracts/amb_erc20_to_native/BasicAMBErc20ToNative.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ contract BasicAMBErc20ToNative is Initializable, Upgradeable, Claimable, Version
5151
* @return patch value of the version
5252
*/
5353
function getBridgeInterfacesVersion() external pure returns (uint64 major, uint64 minor, uint64 patch) {
54-
return (1, 1, 0);
54+
return (1, 1, 1);
5555
}
5656

5757
/**

contracts/upgradeable_contracts/amb_erc20_to_native/ForeignAMBErc20ToNative.sol

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ pragma solidity 0.4.24;
33
import "./BasicAMBErc20ToNative.sol";
44
import "../BaseERC677Bridge.sol";
55
import "../ReentrancyGuard.sol";
6+
import "../../libraries/SafeERC20.sol";
67

78
/**
89
* @title ForeignAMBErc20ToNative
910
* @dev Foreign mediator implementation for erc20-to-native bridge intended to work on top of AMB bridge.
1011
* It is design to be used as implementation contract of EternalStorageProxy contract.
1112
*/
1213
contract ForeignAMBErc20ToNative is BasicAMBErc20ToNative, ReentrancyGuard, BaseERC677Bridge {
14+
using SafeERC20 for ERC677;
15+
1316
bytes32 internal constant MEDIATOR_BALANCE = 0x3db340e280667ee926fa8c51e8f9fcf88a0ff221a66d84d63b4778127d97d139; // keccak256(abi.encodePacked("mediatorBalance"))
1417

1518
/**
@@ -70,13 +73,12 @@ contract ForeignAMBErc20ToNative is BasicAMBErc20ToNative, ReentrancyGuard, Base
7073
// which will call passMessage.
7174
require(!lock());
7275
ERC677 token = _erc677token();
73-
address to = address(this);
7476
require(withinLimit(_value));
7577
addTotalSpentPerDay(getCurrentDay(), _value);
7678
_setMediatorBalance(mediatorBalance().add(_value));
7779

7880
setLock(true);
79-
token.transferFrom(msg.sender, to, _value);
81+
token.safeTransferFrom(msg.sender, _value);
8082
setLock(false);
8183
bridgeSpecificActionsOnTokenTransfer(token, msg.sender, _value, abi.encodePacked(_receiver));
8284
}
@@ -150,7 +152,7 @@ contract ForeignAMBErc20ToNative is BasicAMBErc20ToNative, ReentrancyGuard, Base
150152
bytes32 _messageId = messageId();
151153

152154
_setMediatorBalance(mediatorBalance().sub(valueToTransfer));
153-
_erc677token().transfer(_receiver, valueToTransfer);
155+
_erc677token().safeTransfer(_receiver, valueToTransfer);
154156
emit TokensBridged(_receiver, valueToTransfer, _messageId);
155157
}
156158

@@ -161,7 +163,7 @@ contract ForeignAMBErc20ToNative is BasicAMBErc20ToNative, ReentrancyGuard, Base
161163
*/
162164
function executeActionOnFixedTokens(address _receiver, uint256 _value) internal {
163165
_setMediatorBalance(mediatorBalance().sub(_value));
164-
_erc677token().transfer(_receiver, _value);
166+
_erc677token().safeTransfer(_receiver, _value);
165167
}
166168

167169
/**

contracts/upgradeable_contracts/amb_erc677_to_erc677/BasicAMBErc677ToErc677.sol

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ contract BasicAMBErc677ToErc677 is
6262
return mediatorContractOnOtherSide();
6363
}
6464

65+
/**
66+
* @dev Initiates the bridge operation that will lock the amount of tokens transferred and mint the tokens on
67+
* the other network. The user should first call Approve method of the ERC677 token.
68+
* @param _receiver address that will receive the minted tokens on the other network.
69+
* @param _value amount of tokens to be transferred to the other network.
70+
*/
6571
function relayTokens(address _receiver, uint256 _value) external {
6672
// This lock is to prevent calling passMessage twice if a ERC677 token is used.
6773
// When transferFrom is called, after the transfer, the ERC677 token will call onTokenTransfer from this contract
@@ -90,7 +96,7 @@ contract BasicAMBErc677ToErc677 is
9096
}
9197

9298
function getBridgeInterfacesVersion() external pure returns (uint64 major, uint64 minor, uint64 patch) {
93-
return (1, 2, 0);
99+
return (1, 2, 1);
94100
}
95101

96102
function getBridgeMode() external pure returns (bytes4 _data) {

contracts/upgradeable_contracts/amb_erc677_to_erc677/ForeignAMBErc677ToErc677.sol

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
pragma solidity 0.4.24;
22

33
import "./BasicAMBErc677ToErc677.sol";
4+
import "../../libraries/SafeERC20.sol";
45

56
/**
67
* @title ForeignAMBErc677ToErc677
78
* @dev Foreign side implementation for erc677-to-erc677 mediator intended to work on top of AMB bridge.
89
* It is designed to be used as an implementation contract of EternalStorageProxy contract.
910
*/
1011
contract ForeignAMBErc677ToErc677 is BasicAMBErc677ToErc677 {
12+
using SafeERC20 for ERC677;
13+
1114
/**
1215
* @dev Executes action on the request to withdraw tokens relayed from the other network
1316
* @param _recipient address of tokens receiver
@@ -16,10 +19,31 @@ contract ForeignAMBErc677ToErc677 is BasicAMBErc677ToErc677 {
1619
function executeActionOnBridgedTokens(address _recipient, uint256 _value) internal {
1720
uint256 value = _unshiftValue(_value);
1821
bytes32 _messageId = messageId();
19-
erc677token().transfer(_recipient, value);
22+
erc677token().safeTransfer(_recipient, value);
2023
emit TokensBridged(_recipient, value, _messageId);
2124
}
2225

26+
/**
27+
* @dev Initiates the bridge operation that will lock the amount of tokens transferred and mint the tokens on
28+
* the other network. The user should first call Approve method of the ERC677 token.
29+
* @param _receiver address that will receive the minted tokens on the other network.
30+
* @param _value amount of tokens to be transferred to the other network.
31+
*/
32+
function relayTokens(address _receiver, uint256 _value) external {
33+
// This lock is to prevent calling passMessage twice if a ERC677 token is used.
34+
// When transferFrom is called, after the transfer, the ERC677 token will call onTokenTransfer from this contract
35+
// which will call passMessage.
36+
require(!lock());
37+
ERC677 token = erc677token();
38+
require(withinLimit(_value));
39+
addTotalSpentPerDay(getCurrentDay(), _value);
40+
41+
setLock(true);
42+
token.safeTransferFrom(msg.sender, _value);
43+
setLock(false);
44+
bridgeSpecificActionsOnTokenTransfer(token, msg.sender, _value, abi.encodePacked(_receiver));
45+
}
46+
2347
/**
2448
* @dev Executes action on deposit of bridged tokens
2549
* @param _from address of tokens sender
@@ -38,6 +62,6 @@ contract ForeignAMBErc677ToErc677 is BasicAMBErc677ToErc677 {
3862
}
3963

4064
function executeActionOnFixedTokens(address _recipient, uint256 _value) internal {
41-
erc677token().transfer(_recipient, _value);
65+
erc677token().safeTransfer(_recipient, _value);
4266
}
4367
}

contracts/upgradeable_contracts/multi_amb_erc20_to_erc677/BasicMultiAMBErc20ToErc677.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ contract BasicMultiAMBErc20ToErc677 is
5858
* @return patch value of the version
5959
*/
6060
function getBridgeInterfacesVersion() external pure returns (uint64 major, uint64 minor, uint64 patch) {
61-
return (1, 1, 0);
61+
return (1, 1, 1);
6262
}
6363

6464
/**

contracts/upgradeable_contracts/multi_amb_erc20_to_erc677/ForeignMultiAMBErc20ToErc677.sol

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ import "openzeppelin-solidity/contracts/token/ERC20/DetailedERC20.sol";
44
import "./BasicMultiAMBErc20ToErc677.sol";
55
import "./HomeMultiAMBErc20ToErc677.sol";
66
import "../../libraries/TokenReader.sol";
7+
import "../../libraries/SafeERC20.sol";
78

89
/**
910
* @title ForeignMultiAMBErc20ToErc677
1011
* @dev Foreign side implementation for multi-erc20-to-erc677 mediator intended to work on top of AMB bridge.
1112
* It is designed to be used as an implementation contract of EternalStorageProxy contract.
1213
*/
1314
contract ForeignMultiAMBErc20ToErc677 is BasicMultiAMBErc20ToErc677 {
15+
using SafeERC20 for address;
16+
using SafeERC20 for ERC677;
17+
1418
/**
1519
* @dev Stores the initial parameters of the mediator.
1620
* @param _bridgeContract the address of the AMB bridge contract.
@@ -53,7 +57,7 @@ contract ForeignMultiAMBErc20ToErc677 is BasicMultiAMBErc20ToErc677 {
5357
*/
5458
function executeActionOnBridgedTokens(address _token, address _recipient, uint256 _value) internal {
5559
bytes32 _messageId = messageId();
56-
LegacyERC20(_token).transfer(_recipient, _value);
60+
_token.safeTransfer(_recipient, _value);
5761
_setMediatorBalance(_token, mediatorBalance(_token).sub(_value));
5862
emit TokensBridged(_token, _recipient, _value, _messageId);
5963
}
@@ -97,10 +101,9 @@ contract ForeignMultiAMBErc20ToErc677 is BasicMultiAMBErc20ToErc677 {
97101
// When transferFrom is called, after the transfer, the ERC677 token will call onTokenTransfer from this contract
98102
// which will call passMessage.
99103
require(!lock());
100-
address to = address(this);
101104

102105
setLock(true);
103-
LegacyERC20(token).transferFrom(msg.sender, to, _value);
106+
token.safeTransferFrom(msg.sender, _value);
104107
setLock(false);
105108
bridgeSpecificActionsOnTokenTransfer(token, msg.sender, _value, abi.encodePacked(_receiver));
106109
}
@@ -189,7 +192,7 @@ contract ForeignMultiAMBErc20ToErc677 is BasicMultiAMBErc20ToErc677 {
189192
*/
190193
function executeActionOnFixedTokens(address _token, address _recipient, uint256 _value) internal {
191194
_setMediatorBalance(_token, mediatorBalance(_token).sub(_value));
192-
LegacyERC20(_token).transfer(_recipient, _value);
195+
_token.safeTransfer(_recipient, _value);
193196
}
194197

195198
/**

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tokenbridge-contracts",
3-
"version": "5.4.0",
3+
"version": "5.4.1",
44
"description": "Bridge",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)