Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewards for bridge validators and Ethereum Classic support #143

Merged
merged 170 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
94947eb
Update BridgeValidator to support linked-list
fernandomg Dec 26, 2018
9f8b18c
Add/Update tests for BridgeValidator
fernandomg Dec 26, 2018
eb9e9bf
Fix tests that initialize `BridgeValidator`
fernandomg Dec 26, 2018
058335f
Add `_reward` param to `addValidator` method
fernandomg Dec 27, 2018
9d21972
Fix/Add `require`s for `validator` and `reward` addresses
fernandomg Dec 27, 2018
e25f0ff
Extend BridgeValidators interface and make F_ADDR public
fernandomg Dec 27, 2018
c43f117
Add/Extend BridgeValidators tests
fernandomg Dec 27, 2018
76d45e2
Add validatorList method
patitonar Jan 3, 2019
349bbbb
Update BridgeValidators version
patitonar Jan 7, 2019
363a304
Add removed nextValidator test
patitonar Jan 7, 2019
4e9db7b
Refactor BridgeValidators
patitonar Jan 7, 2019
5c553e0
Update ValidatorAdded event on RewardableValidators
patitonar Jan 7, 2019
1d7456c
Add end of list check on removeValidator
patitonar Jan 8, 2019
b743602
Refactor addValidator and RemoveValidator methods
patitonar Jan 8, 2019
6912fdc
Rename setValidator to setNextValidator
patitonar Jan 8, 2019
212d796
Add zero address check on getNextValidator usage
patitonar Jan 8, 2019
fa36918
Move validatorList method to RewardableValidators
patitonar Jan 8, 2019
a3b947a
Remove onlyOwner modifier on BaseBridgeValidators methods
patitonar Jan 9, 2019
5bf5440
Add zero address check for getNextValidator
patitonar Jan 9, 2019
f8bffb4
Merge pull request #130 from poanetwork/123-update-contracts-to-prope…
akolotov Jan 9, 2019
e008b24
Create FeeManager related contracts
fernandomg Dec 27, 2018
ceb8478
Implement Fee Distribution for ERC20 to Native mode
fernandomg Dec 27, 2018
5991ef3
Update fee contract implementation
patitonar Jan 4, 2019
9a34973
Fix onExecuteAffirmation
patitonar Jan 8, 2019
515f23a
Update delegateCall usage on calculateFee method
patitonar Jan 8, 2019
9bbaf56
Fix rewardableValidatorContract method on BaseFeeManager
patitonar Jan 9, 2019
97d3759
Remove unused files
patitonar Jan 9, 2019
8eb4809
Remove unused import
patitonar Jan 9, 2019
fbf81a8
Fixes on Fee related methods
patitonar Jan 10, 2019
16b3959
Add ERC-to-Native feeManager basic tests
patitonar Jan 10, 2019
c48b650
Merge branch 'develop' into 119-Epic-rewards-for-bridge-validators
patitonar Jan 10, 2019
6deecda
Merge branch '119-Epic-rewards-for-bridge-validators' into 122-create…
patitonar Jan 10, 2019
9ee9ce4
Fixes after merge
patitonar Jan 10, 2019
e752e94
Fix fee related methods
patitonar Jan 10, 2019
c7d62b4
Add fallback and submitSignature fee basic tests
patitonar Jan 10, 2019
8876e15
Refactor getFee
patitonar Jan 11, 2019
1993efc
Add onSignaturesCollected
patitonar Jan 11, 2019
faf9712
move reward logic to RewardableBridge
patitonar Jan 11, 2019
5170863
Update send usage on onSignatureFeeDistribution
patitonar Jan 11, 2019
98dfc8b
Replace delegatecall with callcode on calculateFee
patitonar Jan 11, 2019
d5b9bb5
Add fee tests for 5 validators
patitonar Jan 11, 2019
6b9ce95
Update getFee to use callcode
patitonar Jan 14, 2019
ee666a1
Update setFee modifier to onlyOwner
patitonar Jan 14, 2019
4b8f53a
Refactor BaseFeeManager fee direction
patitonar Jan 14, 2019
71870e0
Add random fee distribution on remaining fee difference
patitonar Jan 14, 2019
40e5b1d
Merge pull request #132 from poanetwork/122-create-feemanager-basic-c…
akolotov Jan 14, 2019
182a483
Add rewardableInitialize on HomeBridgeErcToNative
patitonar Jan 15, 2019
38ebcf1
Add rewardable bridge options on deploy script for erc-to-native mode
patitonar Jan 15, 2019
c1c0880
Update gas consumption on ERC-TO-NATIVE
patitonar Jan 17, 2019
7191c75
Refactor gas consumptions docs
patitonar Jan 17, 2019
7aee850
Fix ERC-TO-NATIVE foreign gas consumption doc
patitonar Jan 17, 2019
0576f18
Add internal setFee method on RewardableBridge
patitonar Jan 22, 2019
51a31be
Rename variable on erc-to-native home deploy script
patitonar Jan 22, 2019
228aaf1
Add HOME_REWARDABLE and FOREIGN_REWARDABLE env vars
patitonar Jan 22, 2019
bdc24f9
Add HOME_TRANSACTIONS_FEE and FOREIGN_TRANSACTIONS_FEE env vars
patitonar Jan 22, 2019
e0bf489
Improve validators and reward address log on deploy script
patitonar Jan 22, 2019
e56b51d
Update home bridge initialization log on erc-to-native deploy script
patitonar Jan 22, 2019
74743cb
Update HomeBridgeErcToNative gas usage docs
patitonar Jan 22, 2019
49fc67d
Merge pull request #134 from poanetwork/124-update-deploy-scripts
akolotov Jan 22, 2019
ef6c47d
Merge pull request #135 from poanetwork/update-gas-consumption-erc-to…
akolotov Jan 22, 2019
6d6b549
Add REWARD_MANAGEMENT.md
patitonar Jan 23, 2019
164c8e6
Add Native-to-Erc fee manager
patitonar Jan 21, 2019
112632a
Add tests for FeeManagerNativeToErc on Foreign bridge
patitonar Jan 22, 2019
348b168
Add tests for FeeManagerNativeToErc on Home bridge
patitonar Jan 22, 2019
8d995fb
Fix rewardableInitialize on NativeToErc contracts
patitonar Jan 23, 2019
41216b5
Add rewardable bridge options on deploy script for native-to-erc mode
patitonar Jan 23, 2019
f7d319d
Merge pull request #141 from poanetwork/add-fee-manager-docs
akolotov Jan 24, 2019
e8d414a
Merge pull request #142 from poanetwork/#127-implement-fee-manager-na…
akolotov Jan 28, 2019
ae7cad2
Update gas consumption NATIVE-TO-ERC
patitonar Jan 29, 2019
b070322
Merge pull request #144 from poanetwork/update-gas-consumption-native…
akolotov Jan 29, 2019
a90babf
Add getFeeManagerMode method
patitonar Feb 1, 2019
1931586
Merge pull request #150 from poanetwork/#148-fee-manager-mode-interface
akolotov Feb 1, 2019
e1787e6
Refactor fee into homeFee and foreignFee
patitonar Feb 1, 2019
34a4960
Update deploy script to use home and foreign fee on rewardableInitialize
patitonar Feb 1, 2019
b209667
Update gas consumption
patitonar Feb 4, 2019
b54cd53
Update fee parameter docs
patitonar Feb 4, 2019
78d6c3b
Refactor RewardableBridge
patitonar Feb 4, 2019
5a69e97
Fix rewardableInitialize methods
patitonar Feb 4, 2019
f9e3193
Update gas consumption docs
patitonar Feb 4, 2019
0f15d7f
Merge pull request #151 from poanetwork/#149-separate-fee-home-foreig…
akolotov Feb 5, 2019
e245268
Add both-directions fee manager for native-to-erc
patitonar Feb 19, 2019
bbbf609
Update tests for native-to-erc
patitonar Feb 19, 2019
f1b8a30
Refactor rewardable env variables
patitonar Feb 20, 2019
94f5d39
Update deploy script
patitonar Feb 20, 2019
289e09f
Fix native-to-erc deploy script
patitonar Feb 20, 2019
3997423
Update Reward Management doc
patitonar Feb 20, 2019
e414d66
Remove onRequestForSignature and onSignaturesCollected from FeeManager
patitonar Feb 25, 2019
67de488
Update gas consumption docs
patitonar Feb 25, 2019
70cc735
update home native-to-erc deploy script
patitonar Feb 27, 2019
f016a25
update foreign native-to-erc deploy script
patitonar Feb 27, 2019
b0d2e36
add .idea to .gitignore
patitonar Feb 27, 2019
afe5407
Update erc-to-erc deploy script
patitonar Feb 27, 2019
4cc175c
Update erc-to-native deploy script
patitonar Feb 27, 2019
b419821
Add promise-retry for state asserts on deploy scripts
patitonar Feb 28, 2019
d2bdf62
Add fee manager for erc-to-native in posdao chain
patitonar Mar 15, 2019
9a1ce93
Add FeeManagerErcToNativePOSDAO on deploy script
patitonar Mar 21, 2019
b117b21
Merge branch 'develop' into 119-Epic-rewards-for-bridge-validators
patitonar Mar 22, 2019
04ab82f
Add fee manager erc-to-erc
patitonar Mar 26, 2019
4cfb617
Add erc-to-erc fee manager unit tests
patitonar Mar 26, 2019
96d75f2
Add rewardable erc-to-erc executeAffirmation tests
patitonar Mar 29, 2019
0092b10
Fix truffle version
patitonar Mar 29, 2019
bf2222d
Add fee manager on erc-to-erc deploy script
patitonar Mar 29, 2019
88a503b
Use ERC677BridgeTokenRewardable if rewards distributed on erc-to-erc
patitonar Apr 1, 2019
5400cd9
Add erc-to-erc reward management schema
patitonar Apr 1, 2019
4def1fd
Merge branch '119-Epic-rewards-for-bridge-validators' into 160-fee-er…
patitonar Apr 3, 2019
0ae69e6
Fix package-lock.json
patitonar Apr 3, 2019
05d5a2b
Fix merge conflicts
patitonar Apr 3, 2019
745eeb0
Add validatorList on BaseBridgeValidators
patitonar Apr 11, 2019
d2f6b0a
Update addValidator method and ValidatorAdded event
patitonar Apr 12, 2019
7581f12
Increase validator interface version
patitonar Apr 15, 2019
3971866
Merge pull request #167 from poanetwork/add-validator-list-method-bri…
akolotov Apr 15, 2019
4c8e664
Emit event on fee distribution from transfer
patitonar Apr 15, 2019
8f551d1
Merge pull request #171 from poanetwork/add-transfer-fee-events
akolotov Apr 16, 2019
9be3f38
Move validator events to BaseBridgeValidators
patitonar Apr 16, 2019
2bc4bd7
Merge branch '119-Epic-rewards-for-bridge-validators' into 160-fee-er…
patitonar Apr 16, 2019
16be3f8
Add event on fee distribution
patitonar Apr 16, 2019
cf81b76
Refactor BaseFeeManager
patitonar Apr 16, 2019
95f2362
Fix _initialize on HomeBridgeErcToErc
patitonar Apr 16, 2019
63fbd12
Move ValidatorsFeeManager constants
patitonar Apr 16, 2019
ffdd595
Merge pull request #169 from poanetwork/update-rewardable-validator
akolotov Apr 16, 2019
8ab76b9
Add POSDAOHomeBridgeErcToErc
patitonar Apr 17, 2019
851c0b9
Fix erc_to_erc home deploy script
patitonar Apr 17, 2019
fd5086b
Fee distribution events moved to the RewardableBridge contract
akolotov Apr 18, 2019
1ca930a
Update erc-to-erc rewards schemas
patitonar Apr 18, 2019
e605559
Add getAmountToBurn on erc-to-native fee manager
patitonar Apr 18, 2019
4326644
tests cover emmiting fee dsitribution event for submitSignature call …
akolotov Apr 19, 2019
b6df9b3
syncronize node.js version in TravisCI with the requirements
akolotov Apr 19, 2019
c9b8a68
Merge pull request #176 from akolotov/119-Epic-rewards-for-bridge-val…
akolotov Apr 22, 2019
d5c7c5a
Fix erc-to-erc reward schema text
patitonar Apr 22, 2019
3592024
Merge branch '119-Epic-rewards-for-bridge-validators' into 160-fee-er…
patitonar Apr 22, 2019
6b25ffb
Update fee events logic on HomeBridgeErcToErc
patitonar Apr 22, 2019
f7cb8d2
Update getAmountToBurn method signature
patitonar Apr 22, 2019
7ee814e
Merge pull request #166 from poanetwork/160-fee-erc-erc-posdao-chain
akolotov Apr 22, 2019
1f57b24
Merge branch '119-Epic-rewards-for-bridge-validators' into #159-fee-e…
patitonar Apr 22, 2019
04069bb
Update FeeManagerErcToNativePOSDAO to extend BlockRewardFeeManager
patitonar Apr 22, 2019
39c7d39
Fix FeeManagerErcToNativePOSDAO unit tests
patitonar Apr 22, 2019
a448e3d
Add HOME_FEE_MANAGER_TYPE env var
patitonar Apr 22, 2019
3ba8ea1
Merge branch '119-Epic-rewards-for-bridge-validators' into #138-fee-m…
patitonar Apr 22, 2019
e3d7fb9
Merge fix
patitonar Apr 22, 2019
3f3457c
Update FeeManagerNativeToErcBothDirections to extend ValidatorsFeeMan…
patitonar Apr 22, 2019
19fa684
Merge pull request #155 from poanetwork/#138-fee-manager-POA-bridge
akolotov Apr 23, 2019
cad1cc5
Update .env.example
patitonar Apr 23, 2019
91eeb64
Merge branch '119-Epic-rewards-for-bridge-validators' into #159-fee-e…
patitonar Apr 23, 2019
c7c84cf
Merge pull request #164 from poanetwork/#159-fee-erc-native-posdao-chain
akolotov Apr 23, 2019
082d47b
Merge branch '119-Epic-rewards-for-bridge-validators' into support-nu…
patitonar Apr 23, 2019
bb33eec
Merge fix
patitonar Apr 23, 2019
d92dd65
Fix initializeValidators logs
patitonar May 2, 2019
f022bed
Fix sendTx method used on deploy script utils
patitonar May 2, 2019
9aed1f1
Merge pull request #156 from poanetwork/support-null-status-deploy-sc…
akolotov May 2, 2019
786529a
Merge branch 'develop' into 119-Epic-rewards-for-bridge-validators
patitonar May 3, 2019
fb6b0d7
Fix merge
patitonar May 3, 2019
f30a1da
flattening sources of the new set of contracts
akolotov May 3, 2019
92be48b
Fix merge deploy script
patitonar May 3, 2019
9a049e8
Merge remote-tracking branch 'upstream/119-Epic-rewards-for-bridge-va…
akolotov May 3, 2019
d69f8f4
flattening of the new contract related to erc677-to-erc677 bridge mode
akolotov May 3, 2019
492f6d0
Merge pull request #179 from akolotov/119-Epic-rewards-for-bridge-val…
akolotov May 3, 2019
964d104
Apply contract changes from `develop-for-classic`
patitonar May 8, 2019
d5139e1
Upgrade truffle version
patitonar May 8, 2019
a682bd6
compile contracts for byzantium and spuriousDragon
patitonar May 8, 2019
de536a3
Remove unused migrations files
patitonar May 8, 2019
b736613
Update deploy script to use correct evm build
patitonar May 8, 2019
20e7cef
Add specific script for gas report on tests
patitonar May 8, 2019
f937e50
Update test dependencies
patitonar May 8, 2019
9538a78
remove web3-utils
patitonar May 9, 2019
6bad8be
Fix unit tests
patitonar May 14, 2019
34d48ef
Add linter for unit tests
patitonar May 14, 2019
2cdff96
Fix used HomeBridgeNativeToErc contract on deploy script
patitonar May 14, 2019
28aac26
Merge pull request #181 from poanetwork/180-support-multiple-evm-vers…
akolotov May 21, 2019
a7c0752
new contracts should be flatten after #181
akolotov May 21, 2019
f5b5538
Merge pull request #184 from akolotov/119-Epic-rewards-for-bridge-val…
akolotov May 22, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
deploy
27 changes: 27 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"extends": [
"plugin:node/recommended",
"airbnb-base",
"plugin:prettier/recommended"
],
"plugins": ["node"],
"env": {
"node" : true,
"mocha" : true
},
"globals" : {
"artifacts": false,
"contract": false,
"assert": false,
"web3": false
},
"rules": {
"no-plusplus": "off",
"no-await-in-loop": "off",
"no-shadow": "off",
"prefer-destructuring": "off",
"no-use-before-define": ["error", { "functions": false }],
"no-restricted-syntax": "off",
"node/no-unpublished-require": "off"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
build
flats
.node*
.idea
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"printWidth": 120
}
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: required
group: beta
language: node_js
node_js:
- "9"
- "10"
cache:
yarn: true
env:
Expand All @@ -14,4 +14,5 @@ matrix:
allow_failures:
- env: SOLIDITY_COVERAGE=true
script:
- yarn lint:js
- yarn test
179 changes: 6 additions & 173 deletions GAS_CONSUMPTION.md
Original file line number Diff line number Diff line change
@@ -1,174 +1,7 @@
## Gas Consumption
## Gas Consumption by Bridge Mode

### `NATIVE-TO-ERC` Bridge Mode

#### Deployment
##### Home
Contract | Method | Min | Max | Avg
---- | ---- | ---- | ---- | ----
EternalStorageProxy|deployment|378510|378510|378510
BridgeValidators|deployment|1144207|1144207|1144207
EternalStorageProxy|upgradeTo|35871|30924|30913
BridgeValidators|initialize|187738|280847|253949
EternalStorageProxy|transferProxyOwnership|30653|30653|30653
EternalStorageProxy|deployment|378510|378510|378510
HomeBridgeNativeToErc|deployment|3327263|3327263|3327263
EternalStorageProxy|upgradeTo|35871|30924|30913
HomeBridgeNativeToErc|initialize|190051|190947|190755
EternalStorageProxy|transferProxyOwnership|30653|30653|30653
Total| |5739327|5823438|5796326

##### Foreign
Contract | Method | Min | Max | Avg
---- | ---- | ---- | ---- | ----
ERC677BridgeToken|deployment|1498202|1499226|1498829
EternalStorageProxy|deployment|378510|378510|378510
BridgeValidators|deployment|1144207|1144207|1144207
EternalStorageProxy|upgradeTo|35871|30924|30913
BridgeValidators|initialize|187738|280847|253949
EternalStorageProxy|transferProxyOwnership|30653|30653|30653
EternalStorageProxy|deployment|378510|378510|378510
ForeignBridgeNativeToErc|deployment|2768705|2768705|2768705
EternalStorageProxy|upgradeTo|35871|30924|30913
ForeignBridgeNativeToErc|initialize|213493|213557|213549
ERC677BridgeToken|setBridgeContract|29432|44432|39432
ERC677BridgeToken|transferOwnership|30860|30924|30913
EternalStorageProxy|transferProxyOwnership|30653|30653|30653
Total| |6762705|6862072|6829736

#### Usage

##### Validators

Contract | Method | Min | Max | Avg
---- | ---- | ---- | ---- | ----
To sign at the Home (each validator)|
HomeBridgeNativeToErc|submitSignature|159362|275135|220127
To relay signatures from the Home to the Foreign (one validator)|
ForeignBridgeNativeToErc|executeSignatures|89201|146127|120917
To sign and relay from the Foreign to the Home (each validator)|
HomeBridgeNativeToErc|executeAffirmation|64314|107669|83596

##### Users

Contract | Method | Min | Max | Avg
---- | ---- | ---- | ---- | ----
To request transfer from the Home to the Foreign|
HomeBridgeNativeToErc|fallback|46982|46982|46982
To request transfer from the Foreign to the Home|
ERC677BridgeToken|transferAndCall|58370|166206|92399


### `ERC-TO-ERC` Bridge Mode

#### Deployment
##### Home
Contract | Method | Min | Max | Avg
---- | ---- | ---- | ---- | ----
EternalStorageProxy|deployment|378510|378510|378510
BridgeValidators|deployment|1144207|1144207|1144207
EternalStorageProxy|upgradeTo|35871|30924|30913
BridgeValidators|initialize|187738|280847|253949
EternalStorageProxy|transferProxyOwnership|30653|30653|30653
EternalStorageProxy|deployment|378510|378510|378510
HomeBridgeErcToErc|deployment|3528509|3528509|3528509
EternalStorageProxy|upgradeTo|35871|30924|30913
ERC677BridgeToken|deployment|1498202|1499226|1498829
ERC677BridgeToken|setBridgeContract|29432|44432|39432
ERC677BridgeToken|transferOwnership|30860|30924|30913
HomeBridgeErcToErc|initialize|212299|213195|213003
EternalStorageProxy|transferProxyOwnership|30653|30653|30653
Total| |7521315|7621514|7588994

##### Foreign
Contract | Method | Min | Max | Avg
---- | ---- | ---- | ---- | ----
EternalStorageProxy|deployment|378510|378510|378510
BridgeValidators|deployment|1144207|1144207|1144207
EternalStorageProxy|upgradeTo|35871|30924|30913
BridgeValidators|initialize|187738|280847|253949
EternalStorageProxy|transferProxyOwnership|30653|30653|30653
EternalStorageProxy|deployment|378510|378510|378510
ForeignBridgeErcToErc|deployment|2449436|2449436|2449436
EternalStorageProxy|upgradeTo|35871|30924|30913
ForeignBridgeErcToErc|initialize|150614|150614|150614
EternalStorageProxy|transferProxyOwnership|30653|30653|30653
Total| |4822063|4905278|4878358

#### Usage

##### Validators

Contract | Method | Min | Max | Avg
---- | ---- | ---- | ---- | ----
To sign at the Home (each validator)|
HomeBridgeErcToErc|submitSignature|159386|275159|220171
To relay signatures from the Home to the Foreign (one validator)|
ForeignBridgeErcToErc|executeSignatures|73779|115769|93027
To sign and relay from the Foreign to the Home (each validator)|
HomeBridgeErcToErc|executeAffirmation|79336|134607|108215

##### Users

Contract | Method | Min | Max | Avg
---- | ---- | ---- | ---- | ----
To request transfer from the Home to the Foreign|
ERC677BridgeToken|transferAndCall|58370|166206|92399
To request transfer from the Foreign to the Home|
ERC677BridgeToken|transfer|37691|86589|55000


### `ERC-TO-NATIVE` Bridge Mode

#### Deployment
##### Home
Contract | Method | Min | Max | Avg
---- | ---- | ---- | ---- | ----
EternalStorageProxy|deployment|378510|378510|378510
BridgeValidators|deployment|1144207|1144207|1144207
EternalStorageProxy|upgradeTo|35871|30924|30913
BridgeValidators|initialize|187738|280847|253949
EternalStorageProxy|transferProxyOwnership|30653|30653|30653
EternalStorageProxy|deployment|378510|378510|378510
HomeBridgeErcToNative|deployment|3757420|3757420|3757420
EternalStorageProxy|upgradeTo|35871|30924|30913
HomeBridgeErcToNative|initialize|196910|213930|210795
EternalStorageProxy|transferProxyOwnership|30653|30653|30653
Total| |6176343|6276578|6246523

##### Foreign
Contract | Method | Min | Max | Avg
---- | ---- | ---- | ---- | ----
EternalStorageProxy|deployment|378510|378510|378510
BridgeValidators|deployment|1144207|1144207|1144207
EternalStorageProxy|upgradeTo|35871|30924|30913
BridgeValidators|initialize|187738|280847|253949
EternalStorageProxy|transferProxyOwnership|30653|30653|30653
EternalStorageProxy|deployment|378510|378510|378510
ForeignBridgeErcToNative|deployment|2449564|2449564|2449564
EternalStorageProxy|upgradeTo|35871|30924|30913
ForeignBridgeErcToNative|initialize|150614|150614|150614
EternalStorageProxy|transferProxyOwnership|30653|30653|30653
Total| |

#### Usage

##### Validators

Contract | Method | Min | Max | Avg
---- | ---- | ---- | ---- | ----
To sign at the Home (each validator)|
HomeBridgeErcToNative|submitSignature|159428|275201|220206
To relay signatures from the Home to the Foreign (one validator)|
ForeignBridgeErcToNative|executeSignatures|73779|115769|92985
To sign and relay from the Foreign to the Home (each validator)|
HomeBridgeErcToNative|executeAffirmation|64380|140744|97562

##### Users

Contract | Method | Min | Max | Avg
---- | ---- | ---- | ---- | ----
To request transfer from the Home to the Foreign|
HomeBridgeErcToNative|fallback|80174|80174|80174
To request transfer from the Foreign to the Home|
ERC677BridgeToken|transfer|37691|86589|55000
- [NATIVE-TO-ERC](docs/NATIVE-TO-ERC.md)
- [NATIVE-TO-ERC-WITH-REWARD](docs/NATIVE-TO-ERC-WITH-REWARD.md)
- [ERC-TO-ERC](docs/ERC-TO-ERC.md)
- [ERC-TO-NATIVE](docs/ERC-TO-NATIVE.md)
- [ERC-TO-NATIVE-WITH-REWARD](docs/ERC-TO-NATIVE-WITH-REWARD.md)
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ docker-compose down
### Gas Consumption
The [GAS_CONSUMPTION](GAS_CONSUMPTION.md) file includes Min, Max, and Avg gas consumption figures for contracts associated with each bridge mode.

### Reward Management
The [REWARD_MANAGEMENT](REWARD_MANAGEMENT.md) file includes information on how rewards are distributed among the validators on each bridge mode.

### Testing environment
To test the bridge scripts in ERC20-to-ERC20 mode on a testnet like Sokol or Kovan, you must deploy an ERC20 token to the foreign network.
This can be done by running the following command:
Expand Down
53 changes: 53 additions & 0 deletions REWARD_MANAGEMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Reward Management

## NATIVE-TO-ERC
Configuration:
```
HOME_REWARDABLE=ONE_DIRECTION
FOREIGN_REWARDABLE=ONE_DIRECTION
```
### Home to Foreign transfer
Fees are calculated and distributed on Foreign network. Validators will receive ERC20 tokens.
![native-erc-hometoforeign](https://user-images.githubusercontent.com/4614574/51607402-4bda6180-1ef3-11e9-91e3-50fe5d35d296.png)

### Foreign to Home transfer
Fees are calculated and distributed on Home network. Validators will receive native coins.
![native-erc-foreigntohome](https://user-images.githubusercontent.com/4614574/51607428-5d236e00-1ef3-11e9-8083-3669899c7252.png)

## NATIVE-TO-ERC - Fees collected on Home network only
Configuration:
```
HOME_REWARDABLE=BOTH_DIRECTIONS
FOREIGN_REWARDABLE=false
```
### Home to Foreign transfer
Fees are calculated and distributed on Home network. Validators will receive native coins.
![native-erc-homefee-hometoforeign](https://user-images.githubusercontent.com/4614574/53118155-43456d00-352b-11e9-80db-53e31494e09b.png)

### Foreign to Home transfer
Fees are calculated and distributed on Home network. Validators will receive native coins.
![native-erc-homefee-foreigntohome](https://user-images.githubusercontent.com/4614574/53118176-4b9da800-352b-11e9-8118-123f30e37d61.png)

## ERC-TO-NATIVE
Configuration:
```
HOME_REWARDABLE=BOTH_DIRECTIONS
FOREIGN_REWARDABLE=false
```
### Foreign to Home transfer
Fees are calculated and distributed on Home network. Validators will receive native coins.
![erc-native-foreigntohome](https://user-images.githubusercontent.com/4614574/51607498-9065fd00-1ef3-11e9-8212-fc1ba16ae91a.png)

### Home to Foreign transfer
Fees are calculated and distributed on Home network. Validators will receive native coins.
![erc-native-hometoforeign](https://user-images.githubusercontent.com/4614574/51607508-96f47480-1ef3-11e9-93a1-0f1111793f2a.png)

## ERC-TO-ERC

### Foreign to Home transfer
Fees are calculated and distributed on Home network. Validators will receive ERC20 tokens.
![ERC-ERC-ForeignToHome (1)](https://user-images.githubusercontent.com/4614574/56502412-98c8d680-64e8-11e9-8eea-5bcd545d74d9.png)

### Home to Foreign transfer
Fees are calculated and distributed on Home network. Validators will receive ERC20 tokens.
![ERC-ERC-HomeToForeign (1)](https://user-images.githubusercontent.com/4614574/56502454-b8f89580-64e8-11e9-84ae-d9a1c229e0c4.png)
2 changes: 2 additions & 0 deletions contracts/IBlockReward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ interface IBlockReward {
function mintedTotally() public view returns (uint256);
function mintedTotallyByBridge(address _bridge) public view returns(uint256);
function bridgesAllowedLength() external view returns(uint256);
function addBridgeTokenFeeReceivers(uint256 _amount) external;
function addBridgeNativeFeeReceivers(uint256 _amount) external;
}
12 changes: 12 additions & 0 deletions contracts/IRewardableValidators.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pragma solidity 0.4.24;


interface IRewardableValidators {
function isValidator(address _validator) public view returns(bool);
function requiredSignatures() public view returns(uint256);
function owner() public view returns(address);
function validatorList() public view returns (address[]);
function getValidatorRewardAddress(address _validator) public view returns(address);
function validatorCount() public view returns (uint256);
function getNextValidator(address _address) public view returns (address);
}
58 changes: 58 additions & 0 deletions contracts/test/BlockReward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import "../libraries/SafeMath.sol";
contract BlockReward is IBlockReward {
using SafeMath for uint256;

address[] public validatorList;
uint256 public mintedCoins = 0;
uint256 public feeAmount = 0;
mapping(bytes32 => uint256) internal uintStorage;
bytes32 internal constant MINTED_TOTALLY_BY_BRIDGE = "mintedTotallyByBridge";
address public token;

function () external payable {
}
Expand Down Expand Up @@ -40,4 +43,59 @@ contract BlockReward is IBlockReward {
bytes32 hash = keccak256(abi.encode(MINTED_TOTALLY_BY_BRIDGE, _bridge));
uintStorage[hash] = uintStorage[hash].add(_amount);
}

function setValidatorsRewards(address[] _initialValidators) external {
validatorList = _initialValidators;
}

function setToken(address _token) external {
token = _token;
}

function addBridgeNativeFeeReceivers(uint256 _amount) external {
feeAmount = _amount;
uint256 feePerValidator = _amount.div(validatorList.length);

uint256 randomValidatorIndex;
uint256 diff = _amount.sub(feePerValidator.mul(validatorList.length));
if (diff > 0) {
randomValidatorIndex = random(validatorList.length);
}

for (uint256 i = 0; i < validatorList.length; i++) {
uint256 feeToDistribute = feePerValidator;
if (diff > 0 && randomValidatorIndex == i) {
feeToDistribute = feeToDistribute.add(diff);
}
this.addExtraReceiver(feeToDistribute, validatorList[i]);
}
}

function addBridgeTokenFeeReceivers(uint256 _amount) external {
address[] memory receivers = new address[](validatorList.length);
uint256[] memory rewards = new uint256[](validatorList.length);
feeAmount = _amount;
uint256 feePerValidator = _amount.div(validatorList.length);

uint256 randomValidatorIndex;
uint256 diff = _amount.sub(feePerValidator.mul(validatorList.length));
if (diff > 0) {
randomValidatorIndex = random(validatorList.length);
}

for (uint256 i = 0; i < validatorList.length; i++) {
uint256 feeToDistribute = feePerValidator;
if (diff > 0 && randomValidatorIndex == i) {
feeToDistribute = feeToDistribute.add(diff);
}
receivers[i] = validatorList[i];
rewards[i] = feeToDistribute;
}

require(token.call(abi.encodeWithSignature("mintReward(address[],uint256[])", receivers, rewards)));
}

function random(uint256 _count) public view returns(uint256) {
return uint256(blockhash(block.number.sub(1))) % _count;
}
}
Loading