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 27 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a3e9ac3
feat: modify top up factories to work with different stablecoins
rkolpakov Oct 6, 2023
a7eafa7
feat: modify top up factories to work with different stablecoins
rkolpakov Oct 9, 2023
0b1e3b3
chore: bump poetry lock brownie version to 1.19.3
rkolpakov Oct 9, 2023
425f4a2
chore: update readme
rkolpakov Oct 9, 2023
7e467c2
fix: make normalizeAmount safe for external callers
rkolpakov Oct 9, 2023
733ef7c
feat: pre deploy preparations
rkolpakov Oct 19, 2023
feb440d
fix: missing comment parameter
rkolpakov Oct 24, 2023
480c3f1
fix: pull fix from develop
rkolpakov Oct 24, 2023
9e4f813
fix: make allowed recipients factory functions external
rkolpakov Oct 24, 2023
f4efe8e
fix: add zero validation top up evm factory
rkolpakov Oct 24, 2023
3b718ad
fix: partially change memory params to calldata
rkolpakov Oct 24, 2023
52b1b1d
fix: remove redundant asserts in builder
rkolpakov Oct 24, 2023
35b01d1
fix: review fixes
rkolpakov Oct 26, 2023
19e760e
fix: test fix
rkolpakov Oct 26, 2023
bf6c9c5
fix: deploy fixes
rkolpakov Oct 26, 2023
1c8f7c1
test: bytecode verification
rkolpakov Oct 30, 2023
f6bf883
fix start fork
bulbozaur Oct 30, 2023
f081888
settings for holesky added
kate-aleksseeva Sep 27, 2024
d8fcc33
ugrade eth-brownie and dependencies
zuzueeka Sep 27, 2024
00305fe
change tokens input format
zuzueeka Sep 27, 2024
afbd0df
Merge pull request #77 from lidofinance/fix/feature/top-up-allowed-to…
zuzueeka Oct 23, 2024
e385d5d
added functionality for contracts deployment using an existing tokens…
kate-aleksseeva Oct 30, 2024
b4c77ca
deployAllowedRecipientsRegistry usage fixed
kate-aleksseeva Oct 30, 2024
c176cb1
deployAllowedRecipientsRegistry usage fixed
kate-aleksseeva Oct 30, 2024
e1f84d6
comments corrected
kate-aleksseeva Oct 30, 2024
363e6d6
Merge branch 'feature/top-up-allowed-tokens' into feature/top-up-allo…
kate-aleksseeva Nov 4, 2024
cb09953
Merge pull request #79 from lidofinance/feature/top-up-allowed-tokens…
kate-aleksseeva Nov 4, 2024
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
204 changes: 81 additions & 123 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 @@ -56,29 +36,34 @@ interface IRemoveAllowedRecipient {
interface IAllowedRecipientsFactory {
function deployAllowedRecipientsRegistry(
address _admin,
address[] memory _addRecipientToAllowedListRoleHolders,
address[] memory _removeRecipientFromAllowedListRoleHolders,
address[] memory _setLimitParametersRoleHolders,
address[] memory _updateSpentAmountRoleHolders,
address[] calldata _addRecipientToAllowedListRoleHolders,
address[] calldata _removeRecipientFromAllowedListRoleHolders,
address[] calldata _setLimitParametersRoleHolders,
address[] calldata _updateSpentAmountRoleHolders,
address bokkyPooBahsDateTimeContract
) external returns (IAllowedRecipientsRegistry);

function deployAllowedTokensRegistry(
address _defaultAdmin,
address[] calldata _addTokensToAllowedListRoleHolders,
address[] calldata _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,108 @@ contract AllowedRecipientsBuilder {
assert(!registry.hasRole(DEFAULT_ADMIN_ROLE, address(this)));
}

function deployAllowedTokensRegistry(address[] calldata _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)));
}

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 _recipients,
string[] memory _titles,
address[] calldata _tokens,
address[] calldata _recipients,
string[] calldata _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,
string calldata _title,
address[] calldata _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));
}
}
Loading
Loading