Skip to content

Commit

Permalink
add usdt and usdc permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
kovalgek committed Oct 25, 2023
1 parent a24f584 commit a68403d
Show file tree
Hide file tree
Showing 4 changed files with 397 additions and 46 deletions.
2 changes: 2 additions & 0 deletions configs/config_mainnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
]
# General network addresses
DAI_TOKEN = "0x6b175474e89094c44da98b954eedeac495271d0f"
USDT_TOKEN = "0xdac17f958d2ee523a2206206994597c13d831ec7"
USDC_TOKEN = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
WETH_TOKEN = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"

#
Expand Down
39 changes: 22 additions & 17 deletions interfaces/TopUpAllowedRecipients.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
},
{
"internalType": "address",
"name": "_finance",
"name": "_allowedTokensRegistry",
"type": "address"
},
{
"internalType": "address",
"name": "_token",
"name": "_finance",
"type": "address"
},
{
Expand All @@ -35,7 +35,20 @@
"name": "allowedRecipientsRegistry",
"outputs": [
{
"internalType": "contract AllowedRecipientsRegistry",
"internalType": "contract IAllowedRecipientsRegistry",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "allowedTokensRegistry",
"outputs": [
{
"internalType": "contract IAllowedTokensRegistry",
"name": "",
"type": "address"
}
Expand Down Expand Up @@ -77,6 +90,11 @@
],
"name": "decodeEVMScriptCallData",
"outputs": [
{
"internalType": "address",
"name": "token",
"type": "address"
},
{
"internalType": "address[]",
"name": "recipients",
Expand All @@ -96,7 +114,7 @@
"name": "easyTrack",
"outputs": [
{
"internalType": "contract EasyTrack",
"internalType": "contract IEasyTrack",
"name": "",
"type": "address"
}
Expand All @@ -117,19 +135,6 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "token",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "trustedCaller",
Expand Down
155 changes: 135 additions & 20 deletions scripts/vote_2023_10_31.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@

import time

from typing import Dict
from typing import Dict, List
from brownie.network.transaction import TransactionReceipt
from brownie import interface
from brownie import interface, ZERO_ADDRESS
from utils.voting import bake_vote_items, confirm_vote_script, create_vote
from utils.agent import agent_forward
from utils.ipfs import upload_vote_ipfs_description, calculate_vote_ipfs_description
from utils.easy_track import add_evmscript_factory, create_permissions, remove_evmscript_factory
from utils.permission_parameters import Param, SpecialArgumentID, Op, ArgumentValue, encode_argument_value_if
from utils.permissions import encode_permission_revoke, encode_permission_grant_p

from utils.config import (
get_deployer_account,
contracts,
get_is_live,
get_priority_fee
get_priority_fee,
EASYTRACK_EVMSCRIPT_EXECUTOR,
LIDO,
LDO_TOKEN,
DAI_TOKEN,
USDC_TOKEN,
USDT_TOKEN
)

# todo: change description
Expand All @@ -30,6 +38,99 @@
"""

eth = {
"limit": 1_000 * (10**18),
"address": ZERO_ADDRESS,
}

steth = {
"limit": 1_000 * (10**18),
"address": LIDO,
}

ldo = {
"limit": 5_000_000 * (10**18),
"address": LDO_TOKEN,
}

dai = {
"limit": 2_000_000 * (10**18),
"address": DAI_TOKEN,
}

usdc = {
"limit": 2_000_000 * (10**18),
"address": USDC_TOKEN,
}

usdt = {
"limit": 2_000_000 * (10**18),
"address": USDT_TOKEN,
}

def amount_limits() -> List[Param]:
token_arg_index = 0
amount_arg_index = 2

return [
# 0: if (1) then (2) else (3)
Param(
SpecialArgumentID.LOGIC_OP_PARAM_ID, Op.IF_ELSE, encode_argument_value_if(condition=1, success=2, failure=3)
),
# 1: (_token == LDO)
Param(token_arg_index, Op.EQ, ArgumentValue(ldo["address"])),
# 2: { return _amount <= 5_000_000 }
Param(amount_arg_index, Op.LTE, ArgumentValue(ldo["limit"])),
# 3: else if (4) then (5) else (6)
Param(
SpecialArgumentID.LOGIC_OP_PARAM_ID, Op.IF_ELSE, encode_argument_value_if(condition=4, success=5, failure=6)
),
# 4: (_token == ETH)
Param(token_arg_index, Op.EQ, ArgumentValue(eth["address"])),
# 5: { return _amount <= 1000 }
Param(amount_arg_index, Op.LTE, ArgumentValue(eth["limit"])),
# 6: else if (7) then (8) else (9)
Param(
SpecialArgumentID.LOGIC_OP_PARAM_ID, Op.IF_ELSE, encode_argument_value_if(condition=7, success=8, failure=9)
),
# 7: (_token == DAI)
Param(token_arg_index, Op.EQ, ArgumentValue(dai["address"])),
# 8: { return _amount <= 2_000_000 }
Param(amount_arg_index, Op.LTE, ArgumentValue(dai["limit"])),
# 9: else if (10) then (11) else (12)
Param(
SpecialArgumentID.LOGIC_OP_PARAM_ID,
Op.IF_ELSE,
encode_argument_value_if(condition=10, success=11, failure=12),
),
# 10: (_token == USDT)
Param(token_arg_index, Op.EQ, ArgumentValue(usdt["address"])),
# 11: { return _amount <= 2_000_000 }
Param(amount_arg_index, Op.LTE, ArgumentValue(usdt["limit"])),
# 12: else if (13) then (14) else (15)
Param(
SpecialArgumentID.LOGIC_OP_PARAM_ID,
Op.IF_ELSE,
encode_argument_value_if(condition=13, success=14, failure=15),
),
# 13: (_token == USDC)
Param(token_arg_index, Op.EQ, ArgumentValue(usdc["address"])),
# 14: { return _amount <= 2_000_000 }
Param(amount_arg_index, Op.LTE, ArgumentValue(usdc["limit"])),
# 15: else if (16) then (17) else (18)
Param(
SpecialArgumentID.LOGIC_OP_PARAM_ID,
Op.IF_ELSE,
encode_argument_value_if(condition=16, success=17, failure=18),
),
# 16: (_token == stETH)
Param(token_arg_index, Op.EQ, ArgumentValue(steth["address"])),
# 17: { return _amount <= 1000 }
Param(amount_arg_index, Op.LTE, ArgumentValue(steth["limit"])),
# 18: else { return false }
Param(SpecialArgumentID.PARAM_VALUE_PARAM_ID, Op.RET, ArgumentValue(0)),
]

def start_vote(tx_params: Dict[str, str], silent: bool) -> bool | list[int | TransactionReceipt | None]:
"""Prepare and run voting."""

Expand All @@ -42,52 +143,66 @@ def start_vote(tx_params: Dict[str, str], silent: bool) -> bool | list[int | Tra
pml_stable_topup_factory = interface.TopUpAllowedRecipients("0x4E6D3A5023A38cE2C4c5456d3760357fD93A22cD")
atc_stable_topup_factory = interface.TopUpAllowedRecipients("0x67Fb97ABB9035E2e93A7e3761a0d0571c5d7CD07")

# todo: change addresses
# addresses stay same
rcc_stable_registry = interface.AllowedRecipientRegistry("0xDc1A0C7849150f466F07d48b38eAA6cE99079f80")
pml_stable_registry = interface.AllowedRecipientRegistry("0xDFfCD3BF14796a62a804c1B16F877Cf7120379dB")
atc_stable_registry = interface.AllowedRecipientRegistry("0xe07305F43B11F230EaA951002F6a55a16419B707")

call_script_items = [
# 1. Switch off TopUp ETs for RCC PML ACT

## 1. Remove RCC DAI top up EVM script factory (old ver) 0x84f74733ede9bFD53c1B3Ea96338867C94EC313e from Easy Track
# 1. Revoke role CREATE_PAYMENTS_ROLE from EVM script executor
encode_permission_revoke(
target_app=contracts.finance,
permission_name="CREATE_PAYMENTS_ROLE",
revoke_from=EASYTRACK_EVMSCRIPT_EXECUTOR,
),
# 2. Grant role CREATE_PAYMENTS_ROLE to EasyTrack EVMScriptExecutor 0xFE5986E06210aC1eCC1aDCafc0cc7f8D63B3F977
# with limits: 1000 ETH, 1000 stETH, 5M LDO, 2M DAI, 2M USTD, 2M USDC
encode_permission_grant_p(
target_app=contracts.finance,
permission_name="CREATE_PAYMENTS_ROLE",
grant_to=EASYTRACK_EVMSCRIPT_EXECUTOR,
params=amount_limits(),
),

## 3. Remove RCC DAI top up EVM script factory (old ver) 0x84f74733ede9bFD53c1B3Ea96338867C94EC313e from Easy Track
remove_evmscript_factory(factory=rcc_dai_topup_factory_old),
## 2. Remove PML DAI top up EVM script factory (old ver) 0x4E6D3A5023A38cE2C4c5456d3760357fD93A22cD from Easy Track
## 4. Remove PML DAI top up EVM script factory (old ver) 0x4E6D3A5023A38cE2C4c5456d3760357fD93A22cD from Easy Track
remove_evmscript_factory(factory=pml_dai_topup_factory_old),
## 3. Remove ATC DAI top up EVM script factory (old ver) 0x67Fb97ABB9035E2e93A7e3761a0d0571c5d7CD07 from Easy Track
## 5. Remove ATC DAI top up EVM script factory (old ver) 0x67Fb97ABB9035E2e93A7e3761a0d0571c5d7CD07 from Easy Track
remove_evmscript_factory(factory=atc_dai_topup_factory_old),

# 2. Switch on TopUpStable ETs for RCC PML ACT

# todo: change addresses
## 4. Add RCC stable top up EVM script factory 0x84f74733ede9bFD53c1B3Ea96338867C94EC313e to Easy Track
## 6. Add RCC stable top up EVM script factory 0x84f74733ede9bFD53c1B3Ea96338867C94EC313e to Easy Track
add_evmscript_factory(
factory=rcc_stable_topup_factory,
permissions=create_permissions(contracts.finance, "newImmediatePayment")
+ create_permissions(rcc_stable_registry, "updateSpentAmount")[2:],
),
## 5. Add PML stable top up EVM script factory 0x4E6D3A5023A38cE2C4c5456d3760357fD93A22cD to Easy Track
## 7. Add PML stable top up EVM script factory 0x4E6D3A5023A38cE2C4c5456d3760357fD93A22cD to Easy Track
add_evmscript_factory(
factory=pml_stable_topup_factory,
permissions=create_permissions(contracts.finance, "newImmediatePayment")
+ create_permissions(pml_stable_registry, "updateSpentAmount")[2:],
),
## 6. Add ATC stable top up EVM script factory 0x67Fb97ABB9035E2e93A7e3761a0d0571c5d7CD07 to Easy Track
## 8. Add ATC stable top up EVM script factory 0x67Fb97ABB9035E2e93A7e3761a0d0571c5d7CD07 to Easy Track
add_evmscript_factory(
factory=atc_stable_topup_factory,
permissions=create_permissions(contracts.finance, "newImmediatePayment")
+ create_permissions(atc_stable_registry, "updateSpentAmount")[2:],
)
]

# todo: change addresses in 4,5,6 strings
# todo: change addresses in 6,7,8 strings
vote_desc_items = [
f"1) Remove RCC DAI top up EVM script factory (old ver) 0x84f74733ede9bFD53c1B3Ea96338867C94EC313e from Easy Track",
f"2) Remove PML DAI top up EVM script factory (old ver) 0x4E6D3A5023A38cE2C4c5456d3760357fD93A22cD from Easy Track",
f"3) Remove ATC DAI top up EVM script factory (old ver) 0x67Fb97ABB9035E2e93A7e3761a0d0571c5d7CD07 from Easy Track",
f"4) Add RCC stable top up EVM script factory 0x84f74733ede9bFD53c1B3Ea96338867C94EC313e to Easy Track",
f"5) Add PML stable top up EVM script factory 0x4E6D3A5023A38cE2C4c5456d3760357fD93A22cD to Easy Track",
f"6) Add ATC stable top up EVM script factory 0x67Fb97ABB9035E2e93A7e3761a0d0571c5d7CD07 to Easy Track",
f"1) Revoke role CREATE_PAYMENTS_ROLE from EVM script executor",
f"2) Grant role CREATE_PAYMENTS_ROLE to EasyTrack EVMScriptExecutor 0xFE5986E06210aC1eCC1aDCafc0cc7f8D63B3F977",
f"3) Remove RCC DAI top up EVM script factory (old ver) 0x84f74733ede9bFD53c1B3Ea96338867C94EC313e from Easy Track",
f"4) Remove PML DAI top up EVM script factory (old ver) 0x4E6D3A5023A38cE2C4c5456d3760357fD93A22cD from Easy Track",
f"5) Remove ATC DAI top up EVM script factory (old ver) 0x67Fb97ABB9035E2e93A7e3761a0d0571c5d7CD07 from Easy Track",
f"6) Add RCC stable top up EVM script factory 0x84f74733ede9bFD53c1B3Ea96338867C94EC313e to Easy Track",
f"7) Add PML stable top up EVM script factory 0x4E6D3A5023A38cE2C4c5456d3760357fD93A22cD to Easy Track",
f"8) Add ATC stable top up EVM script factory 0x67Fb97ABB9035E2e93A7e3761a0d0571c5d7CD07 to Easy Track",
]

vote_items = bake_vote_items(vote_desc_items, call_script_items)
Expand Down
Loading

0 comments on commit a68403d

Please sign in to comment.