Skip to content

Commit 01a6fb1

Browse files
committed
Added alphanet support for tokenbridge
1 parent b59d0e2 commit 01a6fb1

35 files changed

+9429
-33
lines changed

bridge/abi/BridgeV4.json

Lines changed: 1356 additions & 0 deletions
Large diffs are not rendered by default.

bridge/contracts/Bridge/BridgeV4.sol

Lines changed: 514 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
interface IBridgeV4 {
6+
7+
struct ClaimData {
8+
address payable to;
9+
uint256 amount;
10+
bytes32 blockHash;
11+
bytes32 transactionHash;
12+
uint32 logIndex;
13+
}
14+
15+
function version() external pure returns (string memory);
16+
17+
function getFeePercentage() external view returns(uint);
18+
19+
/**
20+
* ERC-20 tokens approve and transferFrom pattern
21+
* See https://eips.ethereum.org/EIPS/eip-20#transferfrom
22+
*/
23+
function receiveTokensTo(address tokenToUse, address to, uint256 amount) external;
24+
25+
/**
26+
* Use network currency and cross it.
27+
*/
28+
function depositTo(address to) external payable;
29+
30+
/**
31+
* ERC-777 tokensReceived hook allows to send tokens to a contract and notify it in a single transaction
32+
* See https://eips.ethereum.org/EIPS/eip-777#motivation for details
33+
*/
34+
function tokensReceived (
35+
address operator,
36+
address from,
37+
address to,
38+
uint amount,
39+
bytes calldata userData,
40+
bytes calldata operatorData
41+
) external;
42+
43+
/**
44+
* Accepts the transaction from the other chain that was voted and sent by the Federation contract
45+
*/
46+
function acceptTransfer(
47+
address _originalTokenAddress,
48+
address payable _from,
49+
address payable _to,
50+
uint256 _amount,
51+
bytes32 _blockHash,
52+
bytes32 _transactionHash,
53+
uint32 _logIndex
54+
) external;
55+
56+
/**
57+
* Claims the crossed transaction using the hash, this sends the funds to the address indicated in
58+
*/
59+
function claim(ClaimData calldata _claimData) external returns (uint256 receivedAmount);
60+
61+
function claimFallback(ClaimData calldata _claimData) external returns (uint256 receivedAmount);
62+
63+
function claimGasless(
64+
ClaimData calldata _claimData,
65+
address payable _relayer,
66+
uint256 _fee,
67+
uint256 _deadline,
68+
uint8 _v,
69+
bytes32 _r,
70+
bytes32 _s
71+
) external returns (uint256 receivedAmount);
72+
73+
function getTransactionDataHash(
74+
address _to,
75+
uint256 _amount,
76+
bytes32 _blockHash,
77+
bytes32 _transactionHash,
78+
uint32 _logIndex
79+
) external returns(bytes32);
80+
81+
event Cross(
82+
address indexed _tokenAddress,
83+
address indexed _from,
84+
address indexed _to,
85+
uint256 _amount,
86+
bytes _userData
87+
);
88+
event NewSideToken(
89+
address indexed _newSideTokenAddress,
90+
address indexed _originalTokenAddress,
91+
string _newSymbol,
92+
uint256 _granularity
93+
);
94+
event AcceptedCrossTransfer(
95+
bytes32 indexed _transactionHash,
96+
address indexed _originalTokenAddress,
97+
address indexed _to,
98+
address _from,
99+
uint256 _amount,
100+
bytes32 _blockHash,
101+
uint256 _logIndex
102+
);
103+
event FeePercentageChanged(uint256 _amount);
104+
event Claimed(
105+
bytes32 indexed _transactionHash,
106+
address indexed _originalTokenAddress,
107+
address indexed _to,
108+
address _sender,
109+
uint256 _amount,
110+
bytes32 _blockHash,
111+
uint256 _logIndex,
112+
address _reciever,
113+
address _relayer,
114+
uint256 _fee
115+
);
116+
}

bridge/deploy/04_deploy_bridge.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ module.exports = async function(hre) { // HardhatRuntimeEnvironment
55
const {deployments, network} = hre;
66
const {deployer} = await getNamedAccounts();
77
const {deploy, log} = deployments;
8-
const BRIDGE_LAST_VERSION = 'v3'
8+
const BRIDGE_LAST_VERSION = 'v4'
99

1010
const bridgeProxyAddress = await address.getBridgeProxyAddress(hre);
1111
if (bridgeProxyAddress) {
12-
const Bridge = await deployments.getArtifact('BridgeV3');
12+
const Bridge = await deployments.getArtifact('BridgeV4');
1313
const bridge = new web3.eth.Contract(Bridge.abi, bridgeProxyAddress);
14-
const currentBridgeVersion = bridge.methods.version().call();
14+
const currentBridgeVersion = bridge.methods.version().send();
1515
if (currentBridgeVersion === BRIDGE_LAST_VERSION) {
1616
return;
1717
}
1818
}
1919

20-
const deployResult = await deploy('BridgeV3', {
20+
const deployResult = await deploy('BridgeV4', {
2121
from: deployer,
2222
log: true,
2323
});
@@ -35,4 +35,4 @@ module.exports = async function(hre) { // HardhatRuntimeEnvironment
3535
}
3636
};
3737
module.exports.id = 'deploy_bridge'; // id required to prevent reexecution
38-
module.exports.tags = ['BridgeV3', 'Upgrade', 'DeployFromScratch', 'IntegrationTest'];
38+
module.exports.tags = ['BridgeV4', 'Upgrade', 'DeployFromScratch', 'IntegrationTest'];

bridge/deploy/05_deploy_bridgeProxy.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,25 @@ module.exports = async function (hre) { // HardhatRuntimeEnvironment
1010
return;
1111
}
1212

13-
const Bridge = await deployments.get('BridgeV3');
13+
const Bridge = await deployments.get('BridgeV4');
1414
const multiSigAddress = await address.getMultiSigAddress(hre);
1515
const proxyAdminAddress = await address.getProxyAdminAddress(hre);
1616
const sideTokenFactoryAddress = await address.getSideTokenFactoryAddress(hre);
1717

1818
const bridge = new web3.eth.Contract(Bridge.abi, Bridge.address);
19+
1920
const methodCall = bridge.methods.initialize(
2021
multiSigAddress,
2122
deployer,
2223
deployer,
2324
sideTokenFactoryAddress,
2425
'r'
2526
);
26-
await methodCall.call({ from: deployer })
27+
try {
28+
await methodCall.send({ from: deployer })
29+
} catch (error) {
30+
throw error;
31+
}
2732

2833
const constructorArguments = [
2934
Bridge.address,
@@ -51,4 +56,4 @@ module.exports = async function (hre) { // HardhatRuntimeEnvironment
5156
};
5257
module.exports.id = 'deploy_bridge_proxy'; // id required to prevent reexecution
5358
module.exports.tags = ['BridgeProxy', 'DeployFromScratch', 'IntegrationTest'];
54-
module.exports.dependencies = ['BridgeV3', 'MultiSigWallet', 'ProxyAdmin', 'SideTokenFactory'];
59+
module.exports.dependencies = ['BridgeV4', 'MultiSigWallet', 'ProxyAdmin', 'SideTokenFactory'];

bridge/deploy/06_deploy_federation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = async function(hre) { // HardhatRuntimeEnvironment
1111
if (federationProxyAddress) {
1212
const Federation = await deployments.getArtifact('FederationV2');
1313
const federation = new web3.eth.Contract(Federation.abi, federationProxyAddress);
14-
const currentFederationVersion = federation.methods.version().call();
14+
const currentFederationVersion = federation.methods.version().send();
1515
if (currentFederationVersion === FEDERATION_LAST_VERSION) {
1616
return;
1717
}

bridge/deploy/07_deploy_federationProxy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = async function(hre) { // HardhatRuntimeEnvironment
2424
bridgeProxyAddress,
2525
multiSigAddress,
2626
);
27-
methodCall.call({from: deployer});
27+
methodCall.send({from: deployer});
2828

2929
const constructorArguments = [
3030
Federation.address,
@@ -82,4 +82,4 @@ function getFederationConf(deployer, network) {
8282
members: [deployer],
8383
required: 1,
8484
};
85-
}
85+
}

bridge/deploy/08_deploy_allowToken.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = async function(hre) { // HardhatRuntimeEnvironment
1111
if (allowTokensProxyAddress) {
1212
const AllowTokens = await deployments.getArtifact('AllowTokens');
1313
const allowTokens = new web3.eth.Contract(AllowTokens.abi, allowTokensProxyAddress);
14-
const currentAllowTokensVersion = allowTokens.methods.version().call();
14+
const currentAllowTokensVersion = allowTokens.methods.version().send();
1515
if (currentAllowTokensVersion === ALLOW_TOKEN_LAST_VERSION) {
1616
return;
1717
}

bridge/deploy/09_deploy_allowTokensProxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = async function(hre) { // HardhatRuntimeEnvironment
2929
deployedJson.largeAmountConfirmations ?? '0',
3030
typesInfo
3131
);
32-
methodCall.call({from: deployer});
32+
methodCall.send({from: deployer});
3333

3434
const constructorArguments = [
3535
AllowTokens.address,

bridge/deploy/10_transfer_setTokens_allowTokens.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = async function(hre) { // HardhatRuntimeEnvironment
1919
const allowTokens = new web3.eth.Contract(AllowTokens.abi, AllowTokensProxy.address);
2020
const multiSigAddress = await address.getMultiSigAddress(hre);
2121

22-
const owner = await allowTokens.methods.owner().call({from: deployer});
22+
const owner = await allowTokens.methods.owner().send({from: deployer});
2323
if (owner === multiSigAddress) {
2424
return
2525
}

0 commit comments

Comments
 (0)