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

ET factories for stablecoins #58

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ poetry run brownie networks import network-config.yaml True
poetry shell
```

This is a workaround related brownie deps pyyaml issue eth-brownie/brownie#1701:

```bash
poetry run pip install "cython<3.0" pyyaml==5.4.1 --no-build-isolation
``````

Compile the Smart Contracts:

```bash
Expand Down
192 changes: 76 additions & 116 deletions contracts/AllowedRecipientsBuilder.sol
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there some memory[] external func args left still

Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,9 @@

pragma solidity ^0.8.4;

interface IEasyTrack {
function evmScriptExecutor() external view returns (address);
}

interface IAllowedRecipientsRegistry {
function addRecipient(address _recipient, string memory _title) external;

function renounceRole(bytes32 role, address account) external;

function isRecipientAllowed(address _recipient) external view returns (bool);

function setLimitParameters(uint256 _limit, uint256 _periodDurationMonths) external;

function getLimitParameters() external view returns (uint256, uint256);

function updateSpentAmount(uint256 _payoutAmount) external;

function spendableBalance() external view returns (uint256);

function hasRole(bytes32 role, address account) external view returns (bool);

function getAllowedRecipients() external view returns (address[] memory);

function bokkyPooBahsDateTimeContract() external view returns (address);
}
import "./interfaces/IAllowedRecipientsRegistry.sol";
import "./interfaces/IAllowedTokensRegistry.sol";
import "./interfaces/IEasyTrack.sol";

interface ITopUpAllowedRecipients {
function token() external view returns (address);
Expand All @@ -39,6 +17,8 @@ interface ITopUpAllowedRecipients {
function trustedCaller() external view returns (address);

function allowedRecipientsRegistry() external view returns (address);

function allowedTokensRegistry() external view returns (address);
}

interface IAddAllowedRecipient {
Expand All @@ -63,22 +43,27 @@ interface IAllowedRecipientsFactory {
address bokkyPooBahsDateTimeContract
) external returns (IAllowedRecipientsRegistry);

function deployAllowedTokensRegistry(
address _defaultAdmin,
address[] memory _addTokensToAllowedListRoleHolders,
address[] memory _removeTokensFromAllowedListRoleHolders
) external returns (IAllowedTokensRegistry registry);

function deployTopUpAllowedRecipients(
address _trustedCaller,
address _allowedRecipientsRegistry,
address _token,
address _allowedTokensRegistry,
address _finance,
IEasyTrack _easyTrack
) external returns (ITopUpAllowedRecipients);
address _easyTrack
) external returns (ITopUpAllowedRecipients topUpAllowedRecipients);

function deployAddAllowedRecipient(address _trustedCaller, address _allowedRecipientsRegistry)
external
returns (IAddAllowedRecipient);

function deployRemoveAllowedRecipient(
address _trustedCaller,
address _allowedRecipientsRegistry
) external returns (IRemoveAllowedRecipient);
function deployRemoveAllowedRecipient(address _trustedCaller, address _allowedRecipientsRegistry)
external
returns (IRemoveAllowedRecipient);
}

contract AllowedRecipientsBuilder {
Expand All @@ -89,10 +74,11 @@ contract AllowedRecipientsBuilder {
address public immutable bokkyPooBahsDateTimeContract;
IAllowedRecipientsFactory public immutable factory;

bytes32 public constant ADD_RECIPIENT_TO_ALLOWED_LIST_ROLE =
keccak256("ADD_RECIPIENT_TO_ALLOWED_LIST_ROLE");
bytes32 public constant ADD_RECIPIENT_TO_ALLOWED_LIST_ROLE = keccak256("ADD_RECIPIENT_TO_ALLOWED_LIST_ROLE");
bytes32 public constant REMOVE_RECIPIENT_FROM_ALLOWED_LIST_ROLE =
keccak256("REMOVE_RECIPIENT_FROM_ALLOWED_LIST_ROLE");
bytes32 public constant ADD_TOKEN_TO_ALLOWED_LIST_ROLE = keccak256("ADD_TOKEN_TO_ALLOWED_LIST_ROLE");
bytes32 public constant REMOVE_TOKEN_FROM_ALLOWED_LIST_ROLE = keccak256("REMOVE_TOKEN_FROM_ALLOWED_LIST_ROLE");
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
bytes32 public constant SET_PARAMETERS_ROLE = keccak256("SET_PARAMETERS_ROLE");
bytes32 public constant UPDATE_SPENT_AMOUNT_ROLE = keccak256("UPDATE_SPENT_AMOUNT_ROLE");
Expand Down Expand Up @@ -204,136 +190,110 @@ contract AllowedRecipientsBuilder {
assert(!registry.hasRole(DEFAULT_ADMIN_ROLE, address(this)));
}

function deployAllowedTokensRegistry(address[] memory _tokens) public returns (IAllowedTokensRegistry registry) {
address[] memory addTokenRoleHolders = new address[](2);
address[] memory removeTokenRoleHolders = new address[](1);

addTokenRoleHolders[0] = admin;
addTokenRoleHolders[1] = address(this);

removeTokenRoleHolders[0] = admin;

registry = factory.deployAllowedTokensRegistry(admin, addTokenRoleHolders, removeTokenRoleHolders);

for (uint256 i = 0; i < _tokens.length; i++) {
registry.addToken(_tokens[i]);
}

registry.renounceRole(ADD_TOKEN_TO_ALLOWED_LIST_ROLE, address(this));

for (uint256 i = 0; i < _tokens.length; i++) {
assert(registry.isTokenAllowed(_tokens[i]));
}

assert(registry.hasRole(ADD_TOKEN_TO_ALLOWED_LIST_ROLE, admin));
assert(registry.hasRole(REMOVE_TOKEN_FROM_ALLOWED_LIST_ROLE, admin));
assert(registry.hasRole(DEFAULT_ADMIN_ROLE, admin));

assert(!registry.hasRole(ADD_TOKEN_TO_ALLOWED_LIST_ROLE, address(this)));
assert(!registry.hasRole(REMOVE_TOKEN_FROM_ALLOWED_LIST_ROLE, address(this)));
assert(!registry.hasRole(DEFAULT_ADMIN_ROLE, address(this)));
}

function deployTopUpAllowedRecipients(
address _trustedCaller,
address _allowedRecipientsRegistry,
address _token
address _allowedTokensRegistry
) public returns (ITopUpAllowedRecipients topUpAllowedRecipients) {
topUpAllowedRecipients = factory.deployTopUpAllowedRecipients(
_trustedCaller,
_allowedRecipientsRegistry,
_token,
finance,
easyTrack
_trustedCaller, _allowedRecipientsRegistry, _allowedTokensRegistry, finance, address(easyTrack)
);

assert(topUpAllowedRecipients.token() == _token);
assert(topUpAllowedRecipients.finance() == finance);
assert(topUpAllowedRecipients.easyTrack() == easyTrack);
assert(topUpAllowedRecipients.trustedCaller() == _trustedCaller);
assert(
address(topUpAllowedRecipients.allowedRecipientsRegistry()) ==
_allowedRecipientsRegistry
);
assert(address(topUpAllowedRecipients.allowedRecipientsRegistry()) == _allowedRecipientsRegistry);
rkolpakov marked this conversation as resolved.
Show resolved Hide resolved
assert(address(topUpAllowedRecipients.allowedTokensRegistry()) == _allowedTokensRegistry);
}

function deployAddAllowedRecipient(address _trustedCaller, address _allowedRecipientsRegistry)
public
returns (IAddAllowedRecipient addAllowedRecipient)
{
addAllowedRecipient = factory.deployAddAllowedRecipient(
_trustedCaller,
_allowedRecipientsRegistry
);
addAllowedRecipient = factory.deployAddAllowedRecipient(_trustedCaller, _allowedRecipientsRegistry);

assert(addAllowedRecipient.trustedCaller() == _trustedCaller);
assert(
address(addAllowedRecipient.allowedRecipientsRegistry()) == _allowedRecipientsRegistry
);
assert(address(addAllowedRecipient.allowedRecipientsRegistry()) == _allowedRecipientsRegistry);
}

function deployRemoveAllowedRecipient(
address _trustedCaller,
address _allowedRecipientsRegistry
) public returns (IRemoveAllowedRecipient removeAllowedRecipient) {
removeAllowedRecipient = factory.deployRemoveAllowedRecipient(
_trustedCaller,
_allowedRecipientsRegistry
);
function deployRemoveAllowedRecipient(address _trustedCaller, address _allowedRecipientsRegistry)
public
returns (IRemoveAllowedRecipient removeAllowedRecipient)
{
removeAllowedRecipient = factory.deployRemoveAllowedRecipient(_trustedCaller, _allowedRecipientsRegistry);

assert(removeAllowedRecipient.trustedCaller() == _trustedCaller);
assert(
address(removeAllowedRecipient.allowedRecipientsRegistry()) ==
_allowedRecipientsRegistry
);
assert(address(removeAllowedRecipient.allowedRecipientsRegistry()) == _allowedRecipientsRegistry);
}

function deployFullSetup(
address _trustedCaller,
address _token,
uint256 _limit,
uint256 _periodDurationMonths,
address[] memory _tokens,
address[] memory _recipients,
string[] memory _titles,
uint256 _spentAmount
)
public
returns (
IAllowedRecipientsRegistry allowedRecipientsRegistry,
ITopUpAllowedRecipients topUpAllowedRecipients,
IAddAllowedRecipient addAllowedRecipient,
IRemoveAllowedRecipient removeAllowedRecipient
)
{
allowedRecipientsRegistry = deployAllowedRecipientsRegistry(
_limit,
_periodDurationMonths,
_recipients,
_titles,
_spentAmount,
true
);
) public {
IAllowedRecipientsRegistry allowedRecipientsRegistry =
deployAllowedRecipientsRegistry(_limit, _periodDurationMonths, _recipients, _titles, _spentAmount, true);
IAllowedTokensRegistry allowedTokensRegistry = deployAllowedTokensRegistry(_tokens);

topUpAllowedRecipients = deployTopUpAllowedRecipients(
_trustedCaller,
address(allowedRecipientsRegistry),
_token
);
deployTopUpAllowedRecipients(_trustedCaller, address(allowedRecipientsRegistry), address(allowedTokensRegistry));

addAllowedRecipient = deployAddAllowedRecipient(
_trustedCaller,
address(allowedRecipientsRegistry)
);
deployAddAllowedRecipient(_trustedCaller, address(allowedRecipientsRegistry));

removeAllowedRecipient = deployRemoveAllowedRecipient(
_trustedCaller,
address(allowedRecipientsRegistry)
);
deployRemoveAllowedRecipient(_trustedCaller, address(allowedRecipientsRegistry));
}

function deploySingleRecipientTopUpOnlySetup(
address _recipient,
string memory _title,
address _token,
address[] memory _tokens,
uint256 _limit,
uint256 _periodDurationMonths,
uint256 _spentAmount
)
public
returns (
IAllowedRecipientsRegistry allowedRecipientsRegistry,
ITopUpAllowedRecipients topUpAllowedRecipients
)
{
) public {
address[] memory recipients = new address[](1);
recipients[0] = _recipient;

string[] memory titles = new string[](1);
titles[0] = _title;

allowedRecipientsRegistry = deployAllowedRecipientsRegistry(
_limit,
_periodDurationMonths,
recipients,
titles,
_spentAmount,
false
);
IAllowedRecipientsRegistry allowedRecipientsRegistry =
deployAllowedRecipientsRegistry(_limit, _periodDurationMonths, recipients, titles, _spentAmount, false);
IAllowedTokensRegistry allowedTokensRegistry = deployAllowedTokensRegistry(_tokens);

topUpAllowedRecipients = deployTopUpAllowedRecipients(
_recipient,
address(allowedRecipientsRegistry),
_token
);
deployTopUpAllowedRecipients(_recipient, address(allowedRecipientsRegistry), address(allowedTokensRegistry));
}
}
37 changes: 33 additions & 4 deletions contracts/AllowedRecipientsFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import "./EVMScriptFactories/RemoveAllowedRecipient.sol";
import "./EVMScriptFactories/TopUpAllowedRecipients.sol";
import "./AllowedRecipientsRegistry.sol";
import "./AllowedTokensRegistry.sol";

/// @author bulbozaur
/// @notice Factory for Allowed Recipient Easy Track contracts
Expand All @@ -22,13 +23,21 @@
IBokkyPooBahsDateTimeContract bokkyPooBahsDateTimeContract
);

event AllowedTokensRegistryDeployed(
address indexed creator,
address indexed allowedTokensRegistry,
address _defaultAdmin,
address[] addTokenToAllowedListRoleHolders,
address[] removeTokenFromAllowedListRoleHolders
);

event TopUpAllowedRecipientsDeployed(
address indexed creator,
address indexed topUpAllowedRecipients,
address trustedCaller,
address allowedRecipientsRegistry,
address allowedTokenssRegistry,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo tokenss

address finance,
address token,
address easyTrack
);

Expand Down Expand Up @@ -75,18 +84,38 @@
);
}

function deployAllowedTokensRegistry(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a strong point: maybe semantically, it could have been a dedicated factory for the tokens registry (since doesn't affect allowed recipients)

image

address _defaultAdmin,
address[] memory _addTokensToAllowedListRoleHolders,
address[] memory _removeTokensFromAllowedListRoleHolders
) public returns (AllowedTokensRegistry registry) {
registry = new AllowedTokensRegistry(
_defaultAdmin,
_addTokensToAllowedListRoleHolders,
_removeTokensFromAllowedListRoleHolders
);

emit AllowedTokensRegistryDeployed(
msg.sender,
address(registry),
_defaultAdmin,
_addTokensToAllowedListRoleHolders,
_removeTokensFromAllowedListRoleHolders
);
}
Fixed Show fixed Hide fixed

function deployTopUpAllowedRecipients(
address _trustedCaller,
address _allowedRecipientsRegistry,
address _token,
address _allowedTokensRegistry,
address _finance,
address _easyTrack
) public returns (TopUpAllowedRecipients topUpAllowedRecipients) {
topUpAllowedRecipients = new TopUpAllowedRecipients(
_trustedCaller,
_allowedRecipientsRegistry,
_allowedTokensRegistry,
_finance,
_token,
_easyTrack
);

Expand All @@ -95,8 +124,8 @@
address(topUpAllowedRecipients),
_trustedCaller,
_allowedRecipientsRegistry,
_allowedTokensRegistry,
_finance,
_token,
_easyTrack
);

Expand Down
Loading
Loading