Skip to content

Commit

Permalink
feat: deploy user safe latest contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam-ef committed Oct 29, 2024
1 parent 29a1f0d commit b6a1b10
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 120 deletions.
24 changes: 12 additions & 12 deletions deployments/534352/deployments.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"addresses": {
"cashDataProviderImpl": "0x3c73ac2A698F7b264A8a8b78a8022710aBB787cA",
"cashDataProviderProxy": "0x04238598eFFE31AB66F1fdeCbfBd59aa4117D69A",
"cashDataProviderImpl": "0xCeBbe0A1A9F880ABD5C51939980283E61719EB58",
"cashDataProviderProxy": "0x1c802B34691419a57212e68303783eaDbD8031bb",
"debtManagerAdminImpl": "0x0000000000000000000000000000000000000000",
"debtManagerCore": "0x0000000000000000000000000000000000000000",
"debtManagerInitializer": "0x0000000000000000000000000000000000000000",
"debtManagerProxy": "0x0000000000000000000000000000000000000000",
"etherFiWallet": "0x7D829d50aAF400B8B29B3b311F4aD70aD819DC6E",
"owner": "0x7D829d50aAF400B8B29B3b311F4aD70aD819DC6E",
"priceProvider": "0x38ea1a441Ab0328b164BD1CED4e9635AbF44b890",
"priceProvider": "0xE49d39598d0689a62929E15E94551932cC6ef6fc",
"recoverySigner1": "0x7fEd99d0aA90423de55e238Eb5F9416FF7Cc58eF",
"recoverySigner2": "0x24e311DA50784Cf9DB1abE59725e4A1A110220FA",
"settlementDispatcherImpl": "0xa276232f6A87bFc9C657ec0A679d9218E0D552b6",
"settlementDispatcherProxy": "0x395a6F029D018F1A52E42220a293215b73914dF9",
"swapper": "0x00B09BcE1eb66f414F4C5caAffA9cc61b4f95dA4",
"settlementDispatcherImpl": "0xB2012d7d1ddCe38F5482551f1879D83C18EA6398",
"settlementDispatcherProxy": "0xbb22B1fa06c33F5fd493a6990D57c10717D9EEC4",
"swapper": "0x60C81f0eF6FDc11D702D178c9b03c9D383Eb0AEA",
"usdc": "0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4",
"userSafeCoreImpl": "0x07aCE651BA09318C6DfEeFc56066585780f62F18",
"userSafeEventEmitterImpl": "0xB48F11E55dC6EFF03f1e2DB5796fe118C527E67A",
"userSafeEventEmitterProxy": "0x0848D817157Bfe0e4d5625EB5E2cA0D3b83053FE",
"userSafeFactoryImpl": "0x8B4922B20bB259c3fB9273796622aa5DAfd641f6",
"userSafeFactoryProxy": "0x0c0B2Dfe0790790Af395dE23712e45e4C13fec57",
"userSafeSettersImpl": "0x83D75Ca3740Fd2d0f0Cdc9B97Ba1075aA45Adf38",
"userSafeCoreImpl": "0xA2c049d81Fc6a048D6EF005A947994A1fB9E1c7A",
"userSafeEventEmitterImpl": "0x7c8dCAA8C5733C373883458b6a1059943F8A2002",
"userSafeEventEmitterProxy": "0x1a329FaE0ab264328B3c07Eb7218775923E6fFAa",
"userSafeFactoryImpl": "0x9Cb88EfE476d3133B7ad48C4e5f625aCD812764b",
"userSafeFactoryProxy": "0x9ec8CaCc5f08AbDab75a430732dBCFD9b1b0a029",
"userSafeSettersImpl": "0x74c18bDe147074565853426D47BB410a39E0B3a8",
"weETH": "0x01f0a31698C4d065659b9bdC21B3610292a1c506",
"wrappedERC20Impl": "0x0000000000000000000000000000000000000000",
"wrapperTokenFactory": "0x0000000000000000000000000000000000000000"
Expand Down
5 changes: 0 additions & 5 deletions script/user-safe/DeployUserSafe.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ contract DeployUserSafe is Utils {
uint256 collateralLimit = 10000e6;
int256 timezoneOffset = 4 * 3600; // Dubai Timezone
address ownerEoa;
address recoverySigner1 = 0x7fEd99d0aA90423de55e238Eb5F9416FF7Cc58eF;
address recoverySigner2 = 0x24e311DA50784Cf9DB1abE59725e4A1A110220FA;


function run() public {
// Pulling deployer info from the environment
Expand Down Expand Up @@ -51,8 +48,6 @@ contract DeployUserSafe is Utils {
abi.encodeWithSelector(
UserSafeCore.initialize.selector,
cashDataProvider,
recoverySigner1,
recoverySigner2,
abi.encode(ownerEoa),
defaultDailySpendingLimit,
defaultMonthlySpendingLimit,
Expand Down
8 changes: 5 additions & 3 deletions script/user-safe/MockSetup.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ contract DeployMockUserSafeSetup is Utils {
)
));

CashDataProvider(address(cashDataProvider)).initialize(
CashDataProvider(address(cashDataProvider)).initialize(abi.encode(
owner,
uint64(delay),
etherFiWallet,
Expand All @@ -138,8 +138,10 @@ contract DeployMockUserSafeSetup is Utils {
address(swapper),
address(aaveAdapter),
address(userSafeFactory),
address(userSafeEventEmitter)
);
address(userSafeEventEmitter),
recoverySigner1,
recoverySigner2
));

DebtManagerInitializer(address(debtManager)).initialize(
owner,
Expand Down
8 changes: 5 additions & 3 deletions script/user-safe/Setup.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ contract DeployUserSafeSetup is Utils {
}

function initializeCashDataProvider() internal {
CashDataProvider(address(cashDataProvider)).initialize(
CashDataProvider(address(cashDataProvider)).initialize(abi.encode(
owner,
uint64(delay),
etherFiWallet,
Expand All @@ -230,8 +230,10 @@ contract DeployUserSafeSetup is Utils {
address(swapper),
address(aaveV3Adapter),
address(userSafeFactory),
address(userSafeEventEmitter)
);
address(userSafeEventEmitter),
recoverySigner1,
recoverySigner2
));
}

function initializeDebtManager(
Expand Down
29 changes: 28 additions & 1 deletion src/interfaces/ICashDataProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ interface ICashDataProvider {
address newPriceProvider
);
event SwapperUpdated(address oldSwapper, address newSwapper);
event EtherFiRecoverySafeUpdated(address oldSafe, address newSafe);
event AaveAdapterUpdated(address oldAdapter, address newAdapter);
event UserSafeFactoryUpdated(address oldFactory, address newFactory);
event UserSafeEventEmitterUpdated(address oldEventEmitter, address newEventEmitter);
event EtherFiRecoverySignerUpdated(address oldSigner, address newSigner);
event ThirdPartyRecoverySignerUpdated(address oldSigner, address newSigner);
event UserSafeWhitelisted(address userSafe);
event EtherFiWalletAdded(address wallet);
event EtherFiWalletRemoved(address wallet);
Expand All @@ -25,6 +26,7 @@ interface ICashDataProvider {
error OnlyUserSafeFactory();
error AlreadyAWhitelistedEtherFiWallet();
error NotAWhitelistedEtherFiWallet();
error RecoverySignersCannotBeSame();

/**
* @notice Function to fetch the timelock delay for tokens from User Safe
Expand Down Expand Up @@ -81,6 +83,18 @@ interface ICashDataProvider {
*/
function userSafeEventEmitter() external view returns (address);

/**
* @notice Function to fetch the address of the EtherFi recovery signerr
* @return Address of the EtherFi recovery signer
*/
function etherFiRecoverySigner() external view returns (address);

/**
* @notice Function to fetch the address of the third party recovery signerr
* @return Address of the third party recovery signer
*/
function thirdPartyRecoverySigner() external view returns (address);

/**
* @notice Function to check if an account is a user safe
* @param account Address of the account
Expand Down Expand Up @@ -157,6 +171,19 @@ interface ICashDataProvider {
*/
function setUserSafeEventEmitter(address eventEmitter) external;


/**
* @notice Function to set the addrss of the EtherFi recovery signer.
* @param recoverySigner Address of the EtherFi recovery signer
*/
function setEtherFiRecoverySigner(address recoverySigner) external;

/**
* @notice Function to set the addrss of the third party recovery signer.
* @param recoverySigner Address of the third party recovery signer
*/
function setThirdPartyRecoverySigner(address recoverySigner) external;

/**
* @notice Function to whitelist user safes
* @notice Can only be called by the user safe factory
Expand Down
11 changes: 3 additions & 8 deletions src/user-safe/UserSafeCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,14 @@ contract UserSafeCore is UserSafeStorage {

function initialize(
address __cashDataProvider,
address __etherFiRecoverySigner,
address __thirdPartyRecoverySigner,
bytes calldata __owner,
uint256 __dailySpendingLimit,
uint256 __monthlySpendingLimit,
uint256 __collateralLimit,
int256 __timezoneOffset
) external initializer {
_cashDataProvider = ICashDataProvider(__cashDataProvider);
if (__etherFiRecoverySigner == __thirdPartyRecoverySigner) revert RecoverySignersCannotBeSame();
_etherFiRecoverySigner = __etherFiRecoverySigner;
_thirdPartyRecoverySigner = __thirdPartyRecoverySigner;


__ReentrancyGuardTransient_init();
_isRecoveryActive = true;
_ownerBytes = __owner;
Expand Down Expand Up @@ -97,8 +92,8 @@ contract UserSafeCore is UserSafeStorage {
returns (OwnerLib.OwnerObject[3] memory signers)
{
signers[0] = _userRecoverySigner.getOwnerObject();
signers[1] = _etherFiRecoverySigner.getOwnerObject();
signers[2] = _thirdPartyRecoverySigner.getOwnerObject();
signers[1] = _cashDataProvider.etherFiRecoverySigner().getOwnerObject();
signers[2] = _cashDataProvider.thirdPartyRecoverySigner().getOwnerObject();
}

function isRecoveryActive() external view returns (bool) {
Expand Down
8 changes: 3 additions & 5 deletions src/user-safe/UserSafeSetters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,10 @@ contract UserSafeSetters is UserSafeStorage {
uint8 index
) internal view returns (OwnerLib.OwnerObject memory) {
if (index == 0) {
if (_userRecoverySigner == address(0))
revert UserRecoverySignerIsUnsetCannotUseIndexZero();

if (_userRecoverySigner == address(0)) revert UserRecoverySignerIsUnsetCannotUseIndexZero();
return _userRecoverySigner.getOwnerObject();
} else if (index == 1) return _etherFiRecoverySigner.getOwnerObject();
else if (index == 2) return _thirdPartyRecoverySigner.getOwnerObject();
} else if (index == 1) return _cashDataProvider.etherFiRecoverySigner().getOwnerObject();
else if (index == 2) return _cashDataProvider.thirdPartyRecoverySigner().getOwnerObject();
else revert InvalidSignatureIndex();
}

Expand Down
4 changes: 0 additions & 4 deletions src/user-safe/UserSafeStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ contract UserSafeStorage is Initializable, ReentrancyGuardTransientUpgradeable {

// Address of the Cash Data Provider
ICashDataProvider internal _cashDataProvider;
// Address of the EtherFi Recovery Signer
address internal _etherFiRecoverySigner;
// Address of the Third Party Recovery Signer
address internal _thirdPartyRecoverySigner;
// Address of the recovery signer set by the user
address internal _userRecoverySigner;

Expand Down
120 changes: 78 additions & 42 deletions src/utils/CashDataProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import {UUPSUpgradeable, Initializable} from "openzeppelin-contracts-upgradeable
* @author ether.fi [[email protected]]
* @notice Contract which stores necessary data required for Cash contracts
*/
contract CashDataProvider is
ICashDataProvider,
UUPSUpgradeable,
AccessControlDefaultAdminRulesUpgradeable
{
contract CashDataProvider is ICashDataProvider, UUPSUpgradeable, AccessControlDefaultAdminRulesUpgradeable {
bytes32 public constant ETHER_FI_WALLET_ROLE = keccak256("ETHER_FI_WALLET_ROLE");
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");

Expand All @@ -35,47 +31,53 @@ contract CashDataProvider is
address private _userSafeFactory;
// Address of user safe event emitter
address private _userSafeEventEmitter;
// Address of the EtherFi Recovery Signer
address internal _etherFiRecoverySigner;
// Address of the Third Party Recovery Signer
address internal _thirdPartyRecoverySigner;

// Mapping of user safes
mapping (address account => bool isUserSafe) private _isUserSafe;

function initialize(
address __owner,
uint64 __delay,
address __etherFiWallet,
address __settlementDispatcher,
address __etherFiCashDebtManager,
address __priceProvider,
address __swapper,
address __aaveAdapter,
address __userSafeFactory,
address __userSafeEventEmitter
) external initializer {
_setInitialValues(__owner, __delay, __etherFiWallet, __settlementDispatcher, __etherFiCashDebtManager, __priceProvider, __swapper, __aaveAdapter, __userSafeFactory, __userSafeEventEmitter);
}
function initialize(bytes memory data) external initializer {
{
(
address __owner,
uint64 __delay,
address __etherFiWallet,
address __settlementDispatcher,
address __etherFiCashDebtManager,
address __priceProvider
) = abi.decode(data, (address, uint64, address, address, address, address));
__AccessControlDefaultAdminRules_init_unchained(uint48(__delay), __owner);
_grantRole(ADMIN_ROLE, __owner);
_grantRole(ETHER_FI_WALLET_ROLE, __etherFiWallet);

function _setInitialValues(
address __owner,
uint64 __delay,
address __etherFiWallet,
address __settlementDispatcher,
address __etherFiCashDebtManager,
address __priceProvider,
address __swapper,
address __aaveAdapter,
address __userSafeFactory,
address __userSafeEventEmitter
) internal {
__AccessControlDefaultAdminRules_init(uint48(__delay), __owner);
_grantRole(ADMIN_ROLE, __owner);
_grantRole(ETHER_FI_WALLET_ROLE, __etherFiWallet);
_delay = __delay;
_settlementDispatcher = __settlementDispatcher;
_etherFiCashDebtManager = __etherFiCashDebtManager;
_priceProvider = __priceProvider;
_swapper = __swapper;
_aaveAdapter = __aaveAdapter;
_userSafeFactory = __userSafeFactory;
_userSafeEventEmitter = __userSafeEventEmitter;
_delay = __delay;
_settlementDispatcher = __settlementDispatcher;
_etherFiCashDebtManager = __etherFiCashDebtManager;
_priceProvider = __priceProvider;
}

{
(
, , , , , ,
address __swapper,
address __aaveAdapter,
address __userSafeFactory,
address __userSafeEventEmitter,
address __etherFiRecoverySigner,
address __thirdPartyRecoverySigner
) = abi.decode(data, (address, uint64, address, address, address, address, address, address, address, address, address, address));

if (__etherFiRecoverySigner == address(0) || __thirdPartyRecoverySigner == address(0)) revert InvalidValue();
_swapper = __swapper;
_aaveAdapter = __aaveAdapter;
_userSafeFactory = __userSafeFactory;
_userSafeEventEmitter = __userSafeEventEmitter;
_etherFiRecoverySigner = __etherFiRecoverySigner;
_thirdPartyRecoverySigner = __thirdPartyRecoverySigner;
}
}

function _authorizeUpgrade(
Expand Down Expand Up @@ -144,6 +146,20 @@ contract CashDataProvider is
function userSafeEventEmitter() external view returns (address) {
return _userSafeEventEmitter;
}

/**
* @inheritdoc ICashDataProvider
*/
function etherFiRecoverySigner() external view returns (address) {
return _etherFiRecoverySigner;
}

/**
* @inheritdoc ICashDataProvider
*/
function thirdPartyRecoverySigner() external view returns (address) {
return _thirdPartyRecoverySigner;
}

/**
* @inheritdoc ICashDataProvider
Expand Down Expand Up @@ -247,6 +263,26 @@ contract CashDataProvider is
emit UserSafeEventEmitterUpdated(_userSafeEventEmitter, eventEmitter);
_userSafeEventEmitter = eventEmitter;
}

/**
* @inheritdoc ICashDataProvider
*/
function setEtherFiRecoverySigner(address recoverySigner) external onlyRole(ADMIN_ROLE) {
if (recoverySigner == address(0)) revert InvalidValue();
if (_thirdPartyRecoverySigner == recoverySigner) revert RecoverySignersCannotBeSame();
emit EtherFiRecoverySignerUpdated(_etherFiRecoverySigner, recoverySigner);
_etherFiRecoverySigner = recoverySigner;
}

/**
* @inheritdoc ICashDataProvider
*/
function setThirdPartyRecoverySigner(address recoverySigner) external onlyRole(ADMIN_ROLE) {
if (recoverySigner == address(0)) revert InvalidValue();
if (_etherFiRecoverySigner == recoverySigner) revert RecoverySignersCannotBeSame();
emit ThirdPartyRecoverySignerUpdated(_thirdPartyRecoverySigner, recoverySigner);
_thirdPartyRecoverySigner = recoverySigner;
}

/**
* @inheritdoc ICashDataProvider
Expand Down
Loading

0 comments on commit b6a1b10

Please sign in to comment.