Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
Cleanup axelar config storage (#203)
Browse files Browse the repository at this point in the history
* Removed axelar from accounts config

* Fix tests

* Moved the NetworkInfo storage down into LocalRegistrar

* New test cases in LocalRegistrar

* Fix test

* Lint

* Fix tsc errors
  • Loading branch information
stevieraykatz authored Jul 18, 2023
1 parent 4ecaa5e commit f9b5c65
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 79 deletions.
3 changes: 1 addition & 2 deletions contracts/core/accounts/facets/AccountsQueryEndowments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
Expand Down
3 changes: 1 addition & 2 deletions contracts/core/accounts/message.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 0 additions & 2 deletions contracts/core/accounts/storage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ library AccountStorage {
uint32 nextAccountId;
uint256 maxGeneralCategoryId;
address subDao;
address gateway;
address gasReceiver;
bool reentrancyGuardLocked;
LibAccounts.FeeSetting earlyLockedWithdrawFee;
}
Expand Down
55 changes: 33 additions & 22 deletions contracts/core/registrar/LocalRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/*////////////////////////////////////////////////
Expand Down Expand Up @@ -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
*/ ////////////////////////////////////////////////
Expand Down Expand Up @@ -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");
}
}
}
37 changes: 2 additions & 35 deletions contracts/core/registrar/Registrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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

/**
Expand Down
19 changes: 19 additions & 0 deletions contracts/core/registrar/interfaces/ILocalRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/*////////////////////////////////////////////////
Expand All @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
8 changes: 8 additions & 0 deletions contracts/core/registrar/lib/LocalRegistrarLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/*////////////////////////////////////////////////
Expand Down Expand Up @@ -44,6 +45,12 @@ library LocalRegistrarLib {
DEPRECATED
}

enum NetworkConnectionAction {
NONE,
POST,
DELETE
}

struct StrategyParams {
StrategyApprovalState approvalState;
string network;
Expand All @@ -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;
}

/*////////////////////////////////////////////////
Expand Down
2 changes: 0 additions & 2 deletions test/core/accounts/AccountsCreateEndowment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
2 changes: 0 additions & 2 deletions test/core/accounts/AccountsQueryEndowments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions test/core/accounts/AccountsUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
2 changes: 0 additions & 2 deletions test/core/accounts/AccountsUpdateEndowments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
2 changes: 0 additions & 2 deletions test/core/accounts/AccountsUpdateStatusEndowments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
61 changes: 59 additions & 2 deletions test/core/registrar/LocalRegistrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 0 additions & 2 deletions test/utils/helpers/accounts/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down

0 comments on commit f9b5c65

Please sign in to comment.