Skip to content

Commit 6f6b4c4

Browse files
author
pedro
committed
Change Utils contract to check for the ERC777 interface
We do this before asking for granularity to avoid a warning in etherscan
1 parent 0411198 commit 6f6b4c4

12 files changed

+36
-2790
lines changed

abis/AllowTokens.json

+1-417
Large diffs are not rendered by default.

abis/Bridge.json

+1-1,018
Large diffs are not rendered by default.

abis/Federation.json

+1-611
Large diffs are not rendered by default.

abis/SideToken.json

+1-727
Large diffs are not rendered by default.

bridge/contracts/Utils.sol

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
pragma solidity ^0.5.0;
22

33
import "./zeppelin/math/SafeMath.sol";
4+
import "./zeppelin/introspection/IERC1820Registry.sol";
5+
import "./zeppelin/token/ERC777/IERC777.sol";
46

57
contract Utils {
68
using SafeMath for uint256;
79

10+
IERC1820Registry constant private _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
11+
// keccak256("ERC777Token")
12+
bytes32 constant private TOKENS_ERC777_HASH = 0xac7fbab5f54a3ca8194167523c6753bfeb96a445279294b6125b68cce2177054;
13+
814
function getTokenInfo(address tokenToUse) external view returns (uint8 decimals, uint256 granularity, string memory symbol) {
915
decimals = getDecimals(tokenToUse);
1016
granularity = getGranularity(tokenToUse);
@@ -37,11 +43,11 @@ contract Utils {
3743
}
3844

3945
function getGranularity(address tokenToUse) public view returns (uint256 granularity) {
40-
//support granularity if ERC777
41-
(bool success, bytes memory data) = tokenToUse.staticcall(abi.encodeWithSignature("granularity()"));
4246
granularity = 1;
43-
if(success) {
44-
granularity = abi.decode(data, (uint256));
47+
//support granularity if ERC777
48+
address implementer = _erc1820.getInterfaceImplementer(tokenToUse, TOKENS_ERC777_HASH);
49+
if (implementer != address(0)) {
50+
granularity = IERC777(implementer).granularity();
4551
//Verify granularity is power of 10 to keep it compatible with ERC20 decimals
4652
granularityToDecimals(granularity);
4753
}

bridge/datagen.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const fs = require('fs');
2+
3+
const allowTokensBuild = require('./build/contracts/AllowTokens');
4+
fs.writeFileSync('../abis/AllowTokens.json', JSON.stringify(allowTokensBuild.abi));
5+
6+
const bridgeBuild = require('./build/contracts/Bridge_v1');
7+
fs.writeFileSync('../abis/Bridge.json', JSON.stringify(bridgeBuild.abi));
8+
9+
const federationBuild = require('./build/contracts/Federation_v1');
10+
fs.writeFileSync('../abis/Federation.json', JSON.stringify(federationBuild.abi));
11+
12+
const sideTokenBuild = require('./build/contracts/SideToken_v1');
13+
fs.writeFileSync('../abis/SideToken.json', JSON.stringify(sideTokenBuild.abi));

bridge/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bridge/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bridge",
33
"private": true,
4-
"version": "1.1.0",
4+
"version": "1.0.0",
55
"description": "Decentralized Bridge Contracts",
66
"dependencies": {
77
"@openzeppelin/cli": "^2.8.2",
@@ -20,6 +20,7 @@
2020
"migrate": "rm -rf ./build && rm -f ./.openzeppelin/dev-5777.json && npx truffle migrate --reset",
2121
"test": "npx truffle test",
2222
"coverage": "npx truffle run coverage",
23+
"prepublish": "npx truffle compile && node ./datagen.js",
2324
"deployIntegrationTest": "rm -f ./.openzeppelin/dev-5777.json && rm -f ./.openzeppelin/dev-33.json && rm -rf ./build && npx truffle migrate --reset --network rskregtest && npx truffle migrate --reset --network development"
2425
},
2526
"keywords": [

bridge/test/Utils_test.js

-4
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ contract('Utils Contract', async function (accounts) {
116116
assert.equal(resultGranularity.toString(), granularity);
117117
});
118118

119-
it('Throw if is not a contract', async function () {
120-
await utils.expectThrow(this.utilsLib.getGranularity(owner));
121-
});
122-
123119
it('granularity = 1 if does not have granularity()', async function () {
124120
let result = await this.utilsLib.getGranularity(this.utilsLib.address);
125121
assert.equal(result, '1');

bridge/truffle-config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
const HDWalletProvider = require("@truffle/hdwallet-provider");
1515
const fs = require('fs');
1616

17-
//resulting address 0x170346689cC312D8E19959Bc68c3AD03E72C9850
1817
let MNEMONIC = fs.existsSync('./mnemonic.key') ? fs.readFileSync('./mnemonic.key', { encoding: 'utf8' }) : "";// Your metamask's recovery words
1918
const INFURA_API_KEY = fs.existsSync('./infura.key') ? fs.readFileSync('./infura.key',{ encoding: 'utf8' }) : "";// Your Infura API Key after its registration
2019

@@ -106,8 +105,7 @@ module.exports = {
106105
// Lower values will optimize more for initial deployment cost, higher
107106
// values will optimize more for high-frequency usage.
108107
runs: 200
109-
},
110-
evmVersion: "petersburg"
108+
}
111109
}
112110
}
113111
}

docs/ContractAddresses.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ Between Rsk Mainnet and Ethereum [https://tokenbridge.rsk.co/](https://tokenbrid
4040

4141
### On RSK Testnet
4242
- "bridge": [0x684a8a976635fb7ad74a0134ace990a6a0fcce84](https://explorer.testnet.rsk.co/address/0x684a8a976635fb7ad74a0134ace990a6a0fcce84)
43-
- "federation": [0x36c893a955399cf15a4a2fbef04c0e06d4d9b379](https://explorer.testnet.rsk.co/address/0x36c893a955399cf15a4a2fbef04c0e06d4d9b379)
43+
- "federation": [0x925606edc5863c079b712daed560c31eff8335b9](https://explorer.testnet.rsk.co/address/0x925606edc5863c079b712daed560c31eff8335b9)
4444
- "allowTokens": [0x952b706a9ab5fd2d3b36205648ed7852676afbe7](https://explorer.testnet.rsk.co/address/0x952b706a9ab5fd2d3b36205648ed7852676afbe7)
4545
- "multiSigWallet": [0x88f6b2bc66f4c31a3669b9b1359524abf79cfc4a](https://explorer.testnet.rsk.co/address/0x88f6b2bc66f4c31a3669b9b1359524abf79cfc4a)
4646
- "tRIF": [0x19f64674d8a5b4e652319f5e239efd3bc969a1fe](https://explorer.testnet.rsk.co/address/0x19f64674d8a5b4e652319f5e239efd3bc969a1fe)
4747

4848
### On Kovan
4949
- "bridge": ["0x12ed69359919fc775bc2674860e8fe2d2b6a7b5d"](https://kovan.etherscan.io/address/0x12ed69359919fc775bc2674860e8fe2d2b6a7b5d)
50-
- "federation": ["0x8c1901c031cdf42a846c0c422a3b5a2c943f4944"](https://kovan.etherscan.io/address/0x8c1901c031cdf42a846c0c422a3b5a2c943f4944)
50+
- "federation": ["0xDa2295255633c26EaadBacE5269b6e8bD2648ca0"](https://kovan.etherscan.io/address/0xDa2295255633c26EaadBacE5269b6e8bD2648ca0)
5151
- "allowTokens": [0xe4aa0f414725c9322a1a9d80d469c5e234786653](https://kovan.etherscan.io/address/0xe4aa0f414725c9322a1a9d80d469c5e234786653)
5252
- "multiSigWallet": [0x040007b1804ad78a97f541bebed377dcb60e4138](https://kovan.etherscan.io/address/0x040007b1804ad78a97f541bebed377dcb60e4138)
5353
- "etRIF": [0x69f6d4d4813f8e2e618dae7572e04b6d5329e207](https://kovan.etherscan.io/address/0x69f6d4d4813f8e2e618dae7572e04b6d5329e207)

ui/tokenbridge.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,9 @@ <h5 class="modal-title">log in</h5>
609609
navlink.prop('href', 'https://faucet.rsk.co/');
610610
}
611611

612-
if(!/chrom(e|ium)/.test(navigator.userAgent.toLowerCase())){
613-
alert('This site will only work correctly under chrome or chromium');
612+
if(!/chrom(e|ium)/.test(navigator.userAgent.toLowerCase())
613+
&& navigator.userAgent.indexOf("Firefox") == -1 ) {
614+
alert('This site will only work correctly under chrome, chromium or firefox');
614615
}
615616

616617
disableInputs(true);

0 commit comments

Comments
 (0)