Skip to content

Commit

Permalink
PP-566: migrate script deploy collector (#95)
Browse files Browse the repository at this point in the history
* feat: dummy commit, create empty deployCollector.ts file

* refactor: add script and task to deploy a Collector using Hardhat and Ethers.js

* style: apply format rules

* test: add the tests, remove the positional arguments and simplify the output file

* fix: apply PR suggestions

Remove some scripts from the package.json
Use console.table to print the collector output
Rename the input config file parameter

Co-authored-by: Antonio Morrone <antonio@iovlabs.org>
  • Loading branch information
AndresQuijano and antomor committed Nov 24, 2022
1 parent 36e0648 commit e0ff1a6
Show file tree
Hide file tree
Showing 18 changed files with 1,097 additions and 701 deletions.
21 changes: 13 additions & 8 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,18 @@ Parameters:

#### Collector Deployment

To deploy a collector, we need to run the script `deploy-collector.js`; it receives two parameters:
- `collectorConfig`: used to specify the collector owner and the partners configuration (addresses and shares). If not specified, the file `deploy-collector.input.json` will be used. Please have a look at `deploy-collector.input.sample.json` for a sample file.
- `outputFile`: used to log the main information of the collector deployment. If not specified, the file `revenue-sharing-addresses.json` will be used.
To deploy a collector, we need to the script `deploy:collector`. It receives the following parameters:
- `config-file-name`: optional, used to specify the collector owner and the partners configuration (addresses and shares). If not specified, the file `deploy-collector.input.json` will be used. Please have a look at `deploy-collector.input.sample.json` for a sample file.
- `outputFile`: optional, used to log the main information of the collector deployment. If not specified, the file `revenue-sharing-addresses.json` will be used.

E.g.:
Usage:
```bash
npx hardhat deploy:collector --network "<network>" --config-file-name "<input_config_file.json>" --output-file-name "output_config_file.json"
```

Example:
```bash
npx truffle --network <network_name> exec tasks/deploy-collector.js --collectorConfig="<collector_configuration.json>" --outputFile="output.json"
npx hardhat deploy:collector --network regtest --config-file-name "deploy-collector.input.json" --output-file-name "collector-output.json"
```

#### Change partner shares
Expand Down Expand Up @@ -108,11 +113,11 @@ This file also is being exported on the distributable version to provide the con

Once the smart contracts are deployed, tokens must be individually allowed to be able to work with the RIF Relay system. In the same way, tokens can be removed from the list of previously allowed tokens. There are some helpful commands for this:

1. To allow a specific token, run `npm run allow-tokens <NETWORK_NAME> <TOKEN_ADDRESSES>` where:
1. To allow a specific token, run `npx hardhat allow-tokens --network <NETWORK_NAME> <TOKEN_ADDRESSES>` where:
- `<TOKEN_ADDRESSES>` is a comma-separated list of the token addresses to be allowed on the available verifiers
- `<NETWORK_NAME>` is an optional parameter for the network name, taken from the `hardhat.config.ts` file (default value is `hardhat`) **important! This should be the same network name as the one used to deploy the contracts**
2. To query allowed tokens run `npm run allowed-tokens <NETWORK_NAME>`. This will display them on the console.
3. To remove a sepecific token, run `npm run remove-tokens <NETWORK_NAME> <TOKEN_ADDRESSES>` where:
2. To query allowed tokens run `npx hardhat allowed-tokens --network <NETWORK_NAME>`. This will display them on the console.
3. To remove a sepecific token, run `npx hardhat remove-tokens --network <NETWORK_NAME> <TOKEN_ADDRESSES>` where:
- `<TOKEN_ADDRESSES>` is a comma-separated list of the token addresses to be removed on the available verifiers.
- `<NETWORK_NAME>` is an optional parameter for the network name, taken from the `hardhat.config.ts` file (default value is `hardhat`) **important! This should be the same network name as the one used to deploy the contracts**.

Expand Down
17 changes: 6 additions & 11 deletions contracts/Collector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,9 @@ contract Collector is ICollector {
return _partners;
}

function updateShares(RevenuePartner[] memory partners)
external
validShares(partners)
onlyOwner
noBalanceToShare
{
function updateShares(
RevenuePartner[] memory partners
) external validShares(partners) onlyOwner noBalanceToShare {
delete _partners;

for (uint256 i = 0; i < partners.length; i++)
Expand All @@ -68,11 +65,9 @@ contract Collector is ICollector {

//@notice Withdraw the actual remainder and then update the remainder's address
//for a new one. This function is the only way to withdraw the remainder.
function updateRemainderAddress(address remainderAddress)
external
onlyOwner
noBalanceToShare
{
function updateRemainderAddress(
address remainderAddress
) external onlyOwner noBalanceToShare {
uint256 balance = token.balanceOf(address(this));

if (balance != 0) {
Expand Down
8 changes: 3 additions & 5 deletions contracts/Penalizer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ contract Penalizer is IPenalizer {

using ECDSA for bytes32;

function _decodeTransaction(bytes memory rawTransaction)
private
pure
returns (Transaction memory transaction)
{
function _decodeTransaction(
bytes memory rawTransaction
) private pure returns (Transaction memory transaction) {
(
transaction.nonce,
transaction.gasPrice,
Expand Down
54 changes: 23 additions & 31 deletions contracts/RelayHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ contract RelayHub is IRelayHub {
emit RelayServerRegistered(msg.sender, url);
}

function disableRelayWorkers(address[] calldata relayWorkers)
external
override
{
function disableRelayWorkers(
address[] calldata relayWorkers
) external override {
//relay manager is msg.sender
uint256 actualWorkerCount = workerCount[msg.sender];
require(
Expand Down Expand Up @@ -107,10 +106,9 @@ contract RelayHub is IRelayHub {
/**
New relay worker addresses can be added (as enabled workers) as long as they don't have a relay manager aldeady assigned.
*/
function addRelayWorkers(address[] calldata newRelayWorkers)
external
override
{
function addRelayWorkers(
address[] calldata newRelayWorkers
) external override {
address relayManager = msg.sender;
workerCount[relayManager] =
workerCount[relayManager] +
Expand Down Expand Up @@ -245,11 +243,10 @@ contract RelayHub is IRelayHub {
/// Slash the stake of the relay relayManager. In order to prevent stake kidnapping, burns half of stake on the way.
/// @param relayWorker - worker whose manager will be penalized
/// @param beneficiary - address that receives half of the penalty amount
function penalize(address relayWorker, address payable beneficiary)
external
override
penalizerOnly
{
function penalize(
address relayWorker,
address payable beneficiary
) external override penalizerOnly {
//Relay worker might be enabled or disabled
address relayManager = address(
uint160(uint256(workerToManager[relayWorker] >> 4))
Expand Down Expand Up @@ -277,7 +274,9 @@ contract RelayHub is IRelayHub {
emit StakePenalized(relayManager, beneficiary, reward);
}

function getRelayInfo(address relayManager)
function getRelayInfo(
address relayManager
)
external
view
override
Expand All @@ -286,12 +285,9 @@ contract RelayHub is IRelayHub {
return relayData[relayManager];
}

function getStakeInfo(address relayManager)
external
view
override
returns (StakeInfo memory stakeInfo)
{
function getStakeInfo(
address relayManager
) external view override returns (StakeInfo memory stakeInfo) {
return stakes[relayManager];
}

Expand All @@ -300,11 +296,10 @@ contract RelayHub is IRelayHub {
// If the entry already exists, only the owner can call this function.
// @param relayManager - address that represents a stake entry and controls relay registrations on relay hubs
// @param unstakeDelay - number of blocks to elapse before the owner can retrieve the stake after calling 'unlock'
function stakeForAddress(address relayManager, uint256 unstakeDelay)
external
payable
override
{
function stakeForAddress(
address relayManager,
uint256 unstakeDelay
) external payable override {
StakeInfo storage stakeInfo = stakes[relayManager];

require(
Expand Down Expand Up @@ -385,12 +380,9 @@ contract RelayHub is IRelayHub {
);
}

function isRelayManagerStaked(address relayManager)
external
view
override
returns (bool)
{
function isRelayManagerStaked(
address relayManager
) external view override returns (bool) {
StakeInfo storage info = stakes[relayManager];
return
info.stake >= minimumStake && //isAmountSufficient
Expand Down
8 changes: 4 additions & 4 deletions contracts/interfaces/IForwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ interface IForwarder {
bytes calldata signature
) external payable returns (bool success, bytes memory ret);

function directExecute(address to, bytes calldata data)
external
payable
returns (bool success, bytes memory ret);
function directExecute(
address to,
bytes calldata data
) external payable returns (bool success, bytes memory ret);
}
34 changes: 17 additions & 17 deletions contracts/interfaces/IRelayHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ interface IRelayHub {
bytes calldata signature
) external;

function penalize(address relayWorker, address payable beneficiary)
external;
function penalize(
address relayWorker,
address payable beneficiary
) external;

/* getters */
function penalizer() external view returns (address);
Expand All @@ -103,16 +105,14 @@ interface IRelayHub {

function workerCount(address manager) external view returns (uint256);

function isRelayManagerStaked(address relayManager)
external
view
returns (bool);
function isRelayManagerStaked(
address relayManager
) external view returns (bool);

// get the relay info from the manager address
function getRelayInfo(address relayManager)
external
view
returns (RelayManagerData memory relayManagerData);
function getRelayInfo(
address relayManager
) external view returns (RelayManagerData memory relayManagerData);

// Represents the relay data for a particular relay manager
struct RelayManagerData {
Expand Down Expand Up @@ -169,18 +169,18 @@ interface IRelayHub {
// If the entry already exists, only the owner can call this function.
// @param relayManager - address that represents a stake entry and controls relay registrations on relay hubs
// @param unstakeDelay - number of blocks to elapse before the owner can retrieve the stake after calling 'unlock'
function stakeForAddress(address relayManager, uint256 unstakeDelay)
external
payable;
function stakeForAddress(
address relayManager,
uint256 unstakeDelay
) external payable;

function unlockStake(address relayManager) external;

function withdrawStake(address relayManager) external;

function getStakeInfo(address relayManager)
external
view
returns (StakeInfo memory stakeInfo);
function getStakeInfo(
address relayManager
) external view returns (StakeInfo memory stakeInfo);

//For initial stakes, this is the minimum stake value allowed for taking ownership of this address' stake
function minimumEntryDepositValue() external view returns (uint256);
Expand Down
8 changes: 4 additions & 4 deletions contracts/interfaces/IWalletCustomLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ interface IWalletCustomLogic {
* @param to Target contract address
* @param data Destination function
*/
function directExecute(address to, bytes calldata data)
external
payable
returns (bytes memory ret);
function directExecute(
address to,
bytes calldata data
) external payable returns (bytes memory ret);
}
19 changes: 8 additions & 11 deletions contracts/smartwallet/CustomSmartWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,10 @@ contract CustomSmartWallet is IForwarder {
}
}

function directExecute(address to, bytes calldata data)
external
payable
override
returns (bool success, bytes memory ret)
{
function directExecute(
address to,
bytes calldata data
) external payable override returns (bool success, bytes memory ret) {
//Verify Owner
require(
_getOwner() == keccak256(abi.encodePacked(msg.sender)),
Expand Down Expand Up @@ -254,11 +252,10 @@ contract CustomSmartWallet is IForwarder {
);
}

function _getEncoded(bytes32 suffixData, ForwardRequest memory req)
private
pure
returns (bytes memory)
{
function _getEncoded(
bytes32 suffixData,
ForwardRequest memory req
) private pure returns (bytes memory) {
return
abi.encodePacked(
keccak256(
Expand Down
19 changes: 8 additions & 11 deletions contracts/smartwallet/SmartWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,10 @@ contract SmartWallet is IForwarder {
}
}

function directExecute(address to, bytes calldata data)
external
payable
override
returns (bool success, bytes memory ret)
{
function directExecute(
address to,
bytes calldata data
) external payable override returns (bool success, bytes memory ret) {
//Verify Owner
require(
_getOwner() == keccak256(abi.encodePacked(msg.sender)),
Expand Down Expand Up @@ -215,11 +213,10 @@ contract SmartWallet is IForwarder {
);
}

function _getEncoded(bytes32 suffixData, ForwardRequest memory req)
private
pure
returns (bytes memory)
{
function _getEncoded(
bytes32 suffixData,
ForwardRequest memory req
) private pure returns (bytes memory) {
return
abi.encodePacked(
keccak256(
Expand Down
14 changes: 4 additions & 10 deletions contracts/utils/Eip712Library.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ library Eip712Library {
bytes calldata signature
)
internal
returns (
bool forwarderSuccess,
bool relaySuccess,
bytes memory ret
)
returns (bool forwarderSuccess, bool relaySuccess, bytes memory ret)
{
/* solhint-disable-next-line avoid-low-level-calls */
(forwarderSuccess, ret) = relayRequest.relayData.callForwarder.call(
Expand All @@ -64,11 +60,9 @@ library Eip712Library {
MinLibBytes.truncateInPlace(ret, 1024); // maximum length of return value/revert reason for 'execute' method. Will truncate result if exceeded.
}

function hashRelayData(EnvelopingTypes.RelayData calldata req)
internal
pure
returns (bytes32)
{
function hashRelayData(
EnvelopingTypes.RelayData calldata req
) internal pure returns (bytes32) {
return
keccak256(
abi.encode(
Expand Down
Loading

0 comments on commit e0ff1a6

Please sign in to comment.