diff --git a/contracts/core/accounts/facets/AccountsQueryEndowments.sol b/contracts/core/accounts/facets/AccountsQueryEndowments.sol index ca84b9957..a67495d10 100644 --- a/contracts/core/accounts/facets/AccountsQueryEndowments.sol +++ b/contracts/core/accounts/facets/AccountsQueryEndowments.sol @@ -59,12 +59,11 @@ contract AccountsQueryEndowments is IAccountsQueryEndowments { config = AccountMessages.ConfigResponse({ owner: state.config.owner, version: state.config.version, + networkName: state.config.networkName, registrarContract: state.config.registrarContract, nextAccountId: state.config.nextAccountId, maxGeneralCategoryId: state.config.maxGeneralCategoryId, subDao: state.config.subDao, - gateway: state.config.gateway, - gasReceiver: state.config.gasReceiver, earlyLockedWithdrawFee: state.config.earlyLockedWithdrawFee }); } diff --git a/contracts/core/accounts/message.sol b/contracts/core/accounts/message.sol index e996ea143..211d24b74 100644 --- a/contracts/core/accounts/message.sol +++ b/contracts/core/accounts/message.sol @@ -86,12 +86,11 @@ library AccountMessages { struct ConfigResponse { address owner; string version; + string networkName; address registrarContract; uint256 nextAccountId; uint256 maxGeneralCategoryId; address subDao; - address gateway; - address gasReceiver; LibAccounts.FeeSetting earlyLockedWithdrawFee; } diff --git a/contracts/core/accounts/storage.sol b/contracts/core/accounts/storage.sol index 5019f34ac..084fa52fa 100644 --- a/contracts/core/accounts/storage.sol +++ b/contracts/core/accounts/storage.sol @@ -13,8 +13,6 @@ library AccountStorage { uint32 nextAccountId; uint256 maxGeneralCategoryId; address subDao; - address gateway; - address gasReceiver; bool reentrancyGuardLocked; LibAccounts.FeeSetting earlyLockedWithdrawFee; } diff --git a/contracts/core/registrar/LocalRegistrar.sol b/contracts/core/registrar/LocalRegistrar.sol index 3da234c94..94e222e3f 100644 --- a/contracts/core/registrar/LocalRegistrar.sol +++ b/contracts/core/registrar/LocalRegistrar.sol @@ -8,9 +8,7 @@ import {IVault} from "../vault/interfaces/IVault.sol"; import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import {LibAccounts} from "../accounts/lib/LibAccounts.sol"; - -// Import integrations here -import {APGoldfinchConfigLib} from "../../integrations/goldfinch/APGoldfinchConfig.sol"; +import {IAccountsStrategy} from "../accounts/interfaces/IAccountsStrategy.sol"; contract LocalRegistrar is ILocalRegistrar, Initializable, OwnableUpgradeable { /*//////////////////////////////////////////////// @@ -125,6 +123,18 @@ contract LocalRegistrar is ILocalRegistrar, Initializable, OwnableUpgradeable { return lrs.uniswapRouter; } + /** + * @dev Query the network connection in registrar + * @param networkName The chain name to query + * @return response The network connection + */ + function queryNetworkConnection( + string memory networkName + ) public view returns (IAccountsStrategy.NetworkInfo memory response) { + LocalRegistrarLib.LocalRegistrarStorage storage lrs = LocalRegistrarLib.localRegistrarStorage(); + response = lrs.NetworkConnections[networkName]; + } + /*//////////////////////////////////////////////// RESTRICTED SETTERS */ //////////////////////////////////////////////// @@ -231,24 +241,25 @@ contract LocalRegistrar is ILocalRegistrar, Initializable, OwnableUpgradeable { lrs.uniswapFactory = _uniswapFactory; } - /*//////////////////////////////////////////////// - GOLDFINCH - */ //////////////////////////////////////////////// - function getAPGoldfinchParams() - external - pure - returns (APGoldfinchConfigLib.APGoldfinchConfig memory) - { - APGoldfinchConfigLib.APGoldfinchConfig storage grs = APGoldfinchConfigLib - .goldfinchRegistrarStorage(); - return grs; - } - - function setAPGoldfinchParams( - APGoldfinchConfigLib.APGoldfinchConfig calldata _apGoldfinch - ) public { - APGoldfinchConfigLib.APGoldfinchConfig storage grs = APGoldfinchConfigLib - .goldfinchRegistrarStorage(); - grs.crvParams.allowedSlippage = _apGoldfinch.crvParams.allowedSlippage; + /** + * @dev update network connections in the registrar + * @param networkInfo The network info to update + * @param action The action to perform (POST or DELETE) + */ + function updateNetworkConnections( + string memory networkName, + IAccountsStrategy.NetworkInfo memory networkInfo, + LocalRegistrarLib.NetworkConnectionAction action + ) public onlyOwner { + LocalRegistrarLib.LocalRegistrarStorage storage lrs = LocalRegistrarLib.localRegistrarStorage(); + if (action == LocalRegistrarLib.NetworkConnectionAction.POST) { + lrs.NetworkConnections[networkName] = networkInfo; + emit NetworkConnectionPosted(networkInfo.chainId); + } else if (action == LocalRegistrarLib.NetworkConnectionAction.DELETE) { + delete lrs.NetworkConnections[networkName]; + emit NetworkConnectionRemoved(networkInfo.chainId); + } else { + revert("Invalid inputs"); + } } } diff --git a/contracts/core/registrar/Registrar.sol b/contracts/core/registrar/Registrar.sol index 85de48384..c35e4fa11 100644 --- a/contracts/core/registrar/Registrar.sol +++ b/contracts/core/registrar/Registrar.sol @@ -15,8 +15,6 @@ import {LocalRegistrarLib} from "./lib/LocalRegistrarLib.sol"; */ contract Registrar is LocalRegistrar, Storage, ReentrancyGuard { event ConfigUpdated(); - event NetworkConnectionPosted(uint256 chainId); - event NetworkConnectionRemoved(uint256 chainId); /// @custom:oz-upgrades-unsafe-allow constructor constructor() { @@ -64,7 +62,8 @@ contract Registrar is LocalRegistrar, Storage, ReentrancyGuard { }); emit ConfigUpdated(); - state.NETWORK_CONNECTIONS["Polygon"] = IAccountsStrategy.NetworkInfo({ + LocalRegistrarLib.LocalRegistrarStorage storage lrs = LocalRegistrarLib.localRegistrarStorage(); + lrs.NetworkConnections["Polygon"] = IAccountsStrategy.NetworkInfo({ chainId: block.chainid, router: details.router, axelarGateway: details.axelarGateway, @@ -233,27 +232,6 @@ contract Registrar is LocalRegistrar, Storage, ReentrancyGuard { state.PriceFeeds[token] = priceFeed; } - /** - * @dev update network connections in the registrar - * @param networkInfo The network info to update - * @param action The action to perform (post or delete) - */ - function updateNetworkConnections( - string memory networkName, - IAccountsStrategy.NetworkInfo memory networkInfo, - string memory action - ) public nonReentrant onlyOwner { - if (Validator.compareStrings(action, "post")) { - state.NETWORK_CONNECTIONS[networkName] = networkInfo; - emit NetworkConnectionPosted(networkInfo.chainId); - } else if (Validator.compareStrings(action, "delete")) { - delete state.NETWORK_CONNECTIONS[networkName]; - emit NetworkConnectionRemoved(networkInfo.chainId); - } else { - revert("Invalid inputs"); - } - } - /** * @dev Query the Price Feed contract set for an Accepted Token in the Registrar * @param token The address of token @@ -263,17 +241,6 @@ contract Registrar is LocalRegistrar, Storage, ReentrancyGuard { return state.PriceFeeds[token]; } - /** - * @dev Query the network connection in registrar - * @param networkName The chain name to query - * @return response The network connection - */ - function queryNetworkConnection( - string memory networkName - ) public view returns (IAccountsStrategy.NetworkInfo memory response) { - response = state.NETWORK_CONNECTIONS[networkName]; - } - // Query functions for contract /** diff --git a/contracts/core/registrar/interfaces/ILocalRegistrar.sol b/contracts/core/registrar/interfaces/ILocalRegistrar.sol index 87692a3f1..058b09d0e 100644 --- a/contracts/core/registrar/interfaces/ILocalRegistrar.sol +++ b/contracts/core/registrar/interfaces/ILocalRegistrar.sol @@ -4,6 +4,7 @@ pragma solidity >=0.8.0; import {LocalRegistrarLib} from "../lib/LocalRegistrarLib.sol"; import {LibAccounts} from "../../accounts/lib/LibAccounts.sol"; +import {IAccountsStrategy} from "../../accounts/interfaces/IAccountsStrategy.sol"; interface ILocalRegistrar { /*//////////////////////////////////////////////// @@ -26,6 +27,8 @@ interface ILocalRegistrar { ); event GasFeeUpdated(address _tokenAddr, uint256 _gasFee); event FeeSettingsUpdated(LibAccounts.FeeTypes _feeType, uint256 _bpsRate, address _payoutAddress); + event NetworkConnectionPosted(uint256 chainId); + event NetworkConnectionRemoved(uint256 chainId); /*//////////////////////////////////////////////// EXTERNAL METHODS @@ -61,6 +64,14 @@ interface ILocalRegistrar { function getVaultOperatorApproved(address _operator) external view returns (bool); + function getUniswapFactoryAddress() external view returns (address); + + function getUniswapRouterAddress() external view returns (address); + + function queryNetworkConnection( + string memory networkName + ) external view returns (IAccountsStrategy.NetworkInfo memory response); + // Setter methods for granular changes to specific params function setRebalanceParams(LocalRegistrarLib.RebalanceParams calldata _rebalanceParams) external; @@ -107,4 +118,12 @@ interface ILocalRegistrar { ) external; function setVaultOperatorApproved(address _operator, bool _isApproved) external; + + function setUniswapAddresses(address _uniswapRouter, address _uniswapFactory) external; + + function updateNetworkConnections( + string memory networkName, + IAccountsStrategy.NetworkInfo memory networkInfo, + LocalRegistrarLib.NetworkConnectionAction action + ) external; } diff --git a/contracts/core/registrar/lib/LocalRegistrarLib.sol b/contracts/core/registrar/lib/LocalRegistrarLib.sol index 6884712c1..5985afc83 100644 --- a/contracts/core/registrar/lib/LocalRegistrarLib.sol +++ b/contracts/core/registrar/lib/LocalRegistrarLib.sol @@ -4,6 +4,7 @@ pragma solidity >=0.8.0; import {IVault} from "../../vault/interfaces/IVault.sol"; import {LibAccounts} from "../../accounts/lib/LibAccounts.sol"; +import {IAccountsStrategy} from "../../accounts/interfaces/IAccountsStrategy.sol"; library LocalRegistrarLib { /*//////////////////////////////////////////////// @@ -44,6 +45,12 @@ library LocalRegistrarLib { DEPRECATED } + enum NetworkConnectionAction { + NONE, + POST, + DELETE + } + struct StrategyParams { StrategyApprovalState approvalState; string network; @@ -67,6 +74,7 @@ library LocalRegistrarLib { mapping(address => uint256) GasFeeByToken; mapping(LibAccounts.FeeTypes => LibAccounts.FeeSetting) FeeSettingsByFeeType; mapping(address => bool) ApprovedVaultOperators; + mapping(string => IAccountsStrategy.NetworkInfo) NetworkConnections; } /*//////////////////////////////////////////////// diff --git a/test/core/accounts/AccountsCreateEndowment.ts b/test/core/accounts/AccountsCreateEndowment.ts index afbd3246b..29c9eab9b 100644 --- a/test/core/accounts/AccountsCreateEndowment.ts +++ b/test/core/accounts/AccountsCreateEndowment.ts @@ -191,8 +191,6 @@ describe("AccountsCreateEndowment", function () { nextAccountId: expectedNextAccountId, maxGeneralCategoryId: 1, subDao: ethers.constants.AddressZero, - gateway: ethers.constants.AddressZero, - gasReceiver: ethers.constants.AddressZero, earlyLockedWithdrawFee: {bps: 1000, payoutAddress: ethers.constants.AddressZero}, reentrancyGuardLocked: false, }); diff --git a/test/core/accounts/AccountsQueryEndowments.ts b/test/core/accounts/AccountsQueryEndowments.ts index 8d2f75513..09c7cb7d4 100644 --- a/test/core/accounts/AccountsQueryEndowments.ts +++ b/test/core/accounts/AccountsQueryEndowments.ts @@ -216,8 +216,6 @@ describe("AccountsQueryEndowments", function () { // Assert the expected config expect(configResponse.earlyLockedWithdrawFee).to.equalFee(config.earlyLockedWithdrawFee); - expect(configResponse.gasReceiver).to.equal(config.gasReceiver); - expect(configResponse.gateway).to.equal(config.gateway); expect(configResponse.maxGeneralCategoryId).to.equal(config.maxGeneralCategoryId); expect(configResponse.nextAccountId).to.equal(config.nextAccountId); expect(configResponse.owner).to.equal(config.owner); diff --git a/test/core/accounts/AccountsUpdate.ts b/test/core/accounts/AccountsUpdate.ts index d669a46fb..2fe5167b3 100644 --- a/test/core/accounts/AccountsUpdate.ts +++ b/test/core/accounts/AccountsUpdate.ts @@ -44,8 +44,6 @@ describe("AccountsUpdate", function () { nextAccountId: 1, maxGeneralCategoryId: 1, subDao: ethers.constants.AddressZero, - gateway: ethers.constants.AddressZero, - gasReceiver: ethers.constants.AddressZero, earlyLockedWithdrawFee: {bps: 1000, payoutAddress: ethers.constants.AddressZero}, reentrancyGuardLocked: false, }); diff --git a/test/core/accounts/AccountsUpdateEndowmentSettingsController.ts b/test/core/accounts/AccountsUpdateEndowmentSettingsController.ts index 068110a71..22db3958d 100644 --- a/test/core/accounts/AccountsUpdateEndowmentSettingsController.ts +++ b/test/core/accounts/AccountsUpdateEndowmentSettingsController.ts @@ -65,8 +65,6 @@ describe("AccountsUpdateEndowmentSettingsController", function () { nextAccountId: 1, maxGeneralCategoryId: 1, subDao: ethers.constants.AddressZero, - gateway: ethers.constants.AddressZero, - gasReceiver: ethers.constants.AddressZero, earlyLockedWithdrawFee: {bps: 1000, payoutAddress: ethers.constants.AddressZero}, reentrancyGuardLocked: false, }); diff --git a/test/core/accounts/AccountsUpdateEndowments.ts b/test/core/accounts/AccountsUpdateEndowments.ts index e8af982e5..74be2fc76 100644 --- a/test/core/accounts/AccountsUpdateEndowments.ts +++ b/test/core/accounts/AccountsUpdateEndowments.ts @@ -704,8 +704,6 @@ describe("AccountsUpdateEndowments", function () { nextAccountId: 1, maxGeneralCategoryId: 1, subDao: ethers.constants.AddressZero, - gateway: ethers.constants.AddressZero, - gasReceiver: ethers.constants.AddressZero, earlyLockedWithdrawFee: {bps: 1000, payoutAddress: ethers.constants.AddressZero}, reentrancyGuardLocked: false, }); diff --git a/test/core/accounts/AccountsUpdateStatusEndowments.ts b/test/core/accounts/AccountsUpdateStatusEndowments.ts index 22098bff5..7b01d709c 100644 --- a/test/core/accounts/AccountsUpdateStatusEndowments.ts +++ b/test/core/accounts/AccountsUpdateStatusEndowments.ts @@ -89,8 +89,6 @@ describe("AccountsUpdateStatusEndowments", function () { nextAccountId: accountId + 1, maxGeneralCategoryId: 1, subDao: ethers.constants.AddressZero, - gateway: ethers.constants.AddressZero, - gasReceiver: ethers.constants.AddressZero, earlyLockedWithdrawFee: {bps: 1000, payoutAddress: ethers.constants.AddressZero}, reentrancyGuardLocked: false, }); diff --git a/test/core/registrar/LocalRegistrar.ts b/test/core/registrar/LocalRegistrar.ts index cb190a7be..fe6a910ca 100644 --- a/test/core/registrar/LocalRegistrar.ts +++ b/test/core/registrar/LocalRegistrar.ts @@ -3,8 +3,8 @@ import {expect} from "chai"; import hre from "hardhat"; import {getSigners} from "utils"; -import {LocalRegistrar, LocalRegistrar__factory} from "../../../typechain-types"; -import {StrategyApprovalState} from "test/utils"; +import {LocalRegistrar, LocalRegistrar__factory} from "typechain-types"; +import {DEFAULT_NETWORK_INFO, StrategyApprovalState} from "test/utils"; describe("Local Registrar", function () { const {ethers, upgrades} = hre; @@ -193,6 +193,63 @@ describe("Local Registrar", function () { }); }); + describe("updateNetworkConnections and queryNetworkConnection", async function () { + it("Should be an owner restricted method", async function () { + await expect( + registrar.connect(user).updateNetworkConnections( + "TestNet", + DEFAULT_NETWORK_INFO, + 1 // POST + ) + ).to.be.reverted; + }); + + it("Should revert if an invalid action is taken", async function () { + await expect( + registrar.updateNetworkConnections( + "TestNet", + DEFAULT_NETWORK_INFO, + 0 // POST + ) + ).to.be.reverted; + }); + + it("Should accept and set the new value", async function () { + let networkInfo = { + ...DEFAULT_NETWORK_INFO, + chainId: 42, + }; + await registrar.updateNetworkConnections( + "TestNet", + networkInfo, + 1 // POST + ); + let returnedValue = await registrar.queryNetworkConnection("TestNet"); + expect(returnedValue.chainId).to.equal(42); + }); + + it("Should delete a mapping when requested", async function () { + let networkInfo = { + ...DEFAULT_NETWORK_INFO, + chainId: 42, + }; + await registrar.updateNetworkConnections( + "TestNet", + networkInfo, + 1 // POST + ); + let beforeReturnedValue = await registrar.queryNetworkConnection("TestNet"); + expect(beforeReturnedValue.chainId).to.equal(42); + await registrar.updateNetworkConnections( + "TestNet", + networkInfo, + 2 // DELETE + ); + let afterReturnedValue = await registrar.queryNetworkConnection("TestNet"); + expect(afterReturnedValue.chainId).to.equal(0); + }); + }); + describe("set and get Strategy params", async function () { let strategyId = "0xffffffff"; // random 4-byte hash let strategyParams = { diff --git a/test/utils/helpers/accounts/defaults.ts b/test/utils/helpers/accounts/defaults.ts index 828dcd0ac..99317e00b 100644 --- a/test/utils/helpers/accounts/defaults.ts +++ b/test/utils/helpers/accounts/defaults.ts @@ -93,8 +93,6 @@ export const DEFAULT_ACCOUNTS_CONFIG: AccountStorage.ConfigStruct = { nextAccountId: 0, maxGeneralCategoryId: 0, subDao: ethers.constants.AddressZero, - gateway: ethers.constants.AddressZero, - gasReceiver: ethers.constants.AddressZero, reentrancyGuardLocked: false, earlyLockedWithdrawFee: DEFAULT_FEE_STRUCT, };