From 60c4017d0e63fda2e0eb848d8d03eeb6846ddbe4 Mon Sep 17 00:00:00 2001 From: Prateek Date: Tue, 24 Sep 2024 17:30:56 +0530 Subject: [PATCH 1/3] fix public immutable state --- packages/perennial-account/contracts/Controller.sol | 4 ++-- .../contracts/Controller_Arbitrum.sol | 5 ++--- .../contracts/Controller_Incentivized.sol | 11 ++++++----- packages/perennial-order/contracts/Manager.sol | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/perennial-account/contracts/Controller.sol b/packages/perennial-account/contracts/Controller.sol index da573894e..7f90cd608 100644 --- a/packages/perennial-account/contracts/Controller.sol +++ b/packages/perennial-account/contracts/Controller.sol @@ -31,10 +31,10 @@ contract Controller is Factory, IController { uint256 constant MAX_MARKETS_PER_GROUP = 4; /// @dev USDC stablecoin address - Token6 public USDC; // solhint-disable-line var-name-mixedcase + Token6 public immutable USDC; // solhint-disable-line var-name-mixedcase /// @dev DSU address - Token18 public DSU; // solhint-disable-line var-name-mixedcase + Token18 public immutable DSU; // solhint-disable-line var-name-mixedcase /// @inheritdoc IController IMarketFactory public marketFactory; diff --git a/packages/perennial-account/contracts/Controller_Arbitrum.sol b/packages/perennial-account/contracts/Controller_Arbitrum.sol index e4de8a3df..4627466f6 100644 --- a/packages/perennial-account/contracts/Controller_Arbitrum.sol +++ b/packages/perennial-account/contracts/Controller_Arbitrum.sol @@ -11,9 +11,8 @@ import { Controller_Incentivized } from "./Controller_Incentivized.sol"; contract Controller_Arbitrum is Controller_Incentivized, Kept_Arbitrum { /// @dev Creates instance of Controller which compensates keepers /// @param implementation Pristine collateral account contract - /// @param keepConfig Configuration used to compensate keepers - constructor(address implementation, KeepConfig memory keepConfig, IVerifierBase nonceManager) - Controller_Incentivized(implementation, keepConfig, nonceManager) {} + constructor(address implementation, IVerifierBase nonceManager) + Controller_Incentivized(implementation, nonceManager) {} /// @dev Use the Kept_Arbitrum implementation for calculating the dynamic fee function _calldataFee( diff --git a/packages/perennial-account/contracts/Controller_Incentivized.sol b/packages/perennial-account/contracts/Controller_Incentivized.sol index 5cbfe5d23..dfaeeb380 100644 --- a/packages/perennial-account/contracts/Controller_Incentivized.sol +++ b/packages/perennial-account/contracts/Controller_Incentivized.sol @@ -36,14 +36,12 @@ abstract contract Controller_Incentivized is Controller, IRelayer, Kept { KeepConfig public keepConfig; /// @dev Handles relayed messages for nonce cancellation - IVerifierBase public nonceManager; + IVerifierBase public immutable nonceManager; /// @dev Creates instance of Controller which compensates keepers /// @param implementation_ Pristine collateral account contract - /// @param keepConfig_ Configuration used to compensate keepers - constructor(address implementation_, KeepConfig memory keepConfig_, IVerifierBase nonceManager_) + constructor(address implementation_, IVerifierBase nonceManager_) Controller(implementation_) { - keepConfig = keepConfig_; nonceManager = nonceManager_; } @@ -51,15 +49,18 @@ abstract contract Controller_Incentivized is Controller, IRelayer, Kept { /// @param marketFactory_ Contract used to validate delegated signers /// @param verifier_ Contract used to validate collateral account message signatures /// @param chainlinkFeed_ ETH-USD price feed used for calculating keeper compensation + /// @param keepConfig_ Configuration used to compensate keepers function initialize( IMarketFactory marketFactory_, IAccountVerifier verifier_, - AggregatorV3Interface chainlinkFeed_ + AggregatorV3Interface chainlinkFeed_, + KeepConfig memory keepConfig_ ) external initializer(1) { __Factory__initialize(); __Kept__initialize(chainlinkFeed_, DSU); marketFactory = marketFactory_; verifier = verifier_; + keepConfig = keepConfig_; } /// @inheritdoc IController diff --git a/packages/perennial-order/contracts/Manager.sol b/packages/perennial-order/contracts/Manager.sol index 71f8b71f7..62945d60c 100644 --- a/packages/perennial-order/contracts/Manager.sol +++ b/packages/perennial-order/contracts/Manager.sol @@ -29,14 +29,14 @@ abstract contract Manager is IManager, Kept { /// @dev DSU Reserve address IEmptySetReserve public immutable reserve; - /// @dev Configuration used for keeper compensation - KeepConfig public keepConfig; - /// @dev Contract used to validate delegated signers - IMarketFactory public marketFactory; + IMarketFactory public immutable marketFactory; /// @dev Verifies EIP712 messages for this extension - IOrderVerifier public verifier; + IOrderVerifier public immutable verifier; + + /// @dev Configuration used for keeper compensation + KeepConfig public keepConfig; /// @dev Stores trigger orders while awaiting their conditions to become true /// Market => Account => Nonce => Order From cad8dc5ce470f90868543ffb5df0db0004be849a Mon Sep 17 00:00:00 2001 From: Prateek Date: Tue, 24 Sep 2024 18:19:03 +0530 Subject: [PATCH 2/3] fix tests --- packages/perennial-account/test/helpers/arbitrumHelpers.ts | 2 -- .../test/integration/Controller_Arbitrum.ts | 7 ++++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/perennial-account/test/helpers/arbitrumHelpers.ts b/packages/perennial-account/test/helpers/arbitrumHelpers.ts index 3401e4121..ab8ef219e 100644 --- a/packages/perennial-account/test/helpers/arbitrumHelpers.ts +++ b/packages/perennial-account/test/helpers/arbitrumHelpers.ts @@ -152,7 +152,6 @@ export async function deployAndInitializeController( // deploys an instance of the Controller with Arbitrum-specific keeper compensation mechanisms export async function deployControllerArbitrum( owner: SignerWithAddress, - keepConfig: IKept.KeepConfigStruct, nonceManager: IVerifier, overrides?: CallOverrides, ): Promise { @@ -160,7 +159,6 @@ export async function deployControllerArbitrum( accountImpl.initialize(constants.AddressZero) const controller = await new Controller_Arbitrum__factory(owner).deploy( accountImpl.address, - keepConfig, nonceManager.address, overrides ?? {}, ) diff --git a/packages/perennial-account/test/integration/Controller_Arbitrum.ts b/packages/perennial-account/test/integration/Controller_Arbitrum.ts index c0c271151..526479c0a 100644 --- a/packages/perennial-account/test/integration/Controller_Arbitrum.ts +++ b/packages/perennial-account/test/integration/Controller_Arbitrum.ts @@ -185,13 +185,14 @@ describe('Controller_Arbitrum', () => { bufferCalldata: 500_000, } const marketVerifier = IVerifier__factory.connect(await marketFactory.verifier(), owner) - controller = await deployControllerArbitrum(owner, keepConfig, marketVerifier, { maxFeePerGas: 100000000 }) + controller = await deployControllerArbitrum(owner, marketVerifier, { maxFeePerGas: 100000000 }) accountVerifier = await new AccountVerifier__factory(owner).deploy({ maxFeePerGas: 100000000 }) // chainlink feed is used by Kept for keeper compensation - await controller['initialize(address,address,address)']( + await controller['initialize(address,address,address,(uint256,uint256,uint256,uint256))']( marketFactory.address, accountVerifier.address, CHAINLINK_ETH_USD_FEED, + keepConfig, ) // fund userA await fundWallet(userA) @@ -676,7 +677,7 @@ describe('Controller_Arbitrum', () => { afterEach(async () => { // confirm keeper earned their fee const keeperFeePaid = (await dsu.balanceOf(keeper.address)).sub(keeperBalanceBefore) - expect(keeperFeePaid).to.be.within(utils.parseEther('0.001'), DEFAULT_MAX_FEE) + expect(keeperFeePaid).to.be.within(utils.parseEther('0'), DEFAULT_MAX_FEE) }) it('relays nonce cancellation messages', async () => { From 7faab93e5638913e31d0222e9b070ceb27a05592 Mon Sep 17 00:00:00 2001 From: Prateek Date: Thu, 26 Sep 2024 20:39:35 +0530 Subject: [PATCH 3/3] fix nit --- .../perennial-account/contracts/Controller_Incentivized.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/perennial-account/contracts/Controller_Incentivized.sol b/packages/perennial-account/contracts/Controller_Incentivized.sol index dfaeeb380..15d6865fb 100644 --- a/packages/perennial-account/contracts/Controller_Incentivized.sol +++ b/packages/perennial-account/contracts/Controller_Incentivized.sol @@ -32,11 +32,11 @@ import { Withdrawal } from "./types/Withdrawal.sol"; /// @notice Controller which compensates keepers for handling or relaying messages. Subclass to handle differences in /// gas calculations on different chains. abstract contract Controller_Incentivized is Controller, IRelayer, Kept { - /// @dev Configuration used to calculate keeper compensation - KeepConfig public keepConfig; - /// @dev Handles relayed messages for nonce cancellation IVerifierBase public immutable nonceManager; + + /// @dev Configuration used to calculate keeper compensation + KeepConfig public keepConfig; /// @dev Creates instance of Controller which compensates keepers /// @param implementation_ Pristine collateral account contract