Skip to content

Commit

Permalink
Merge pull request #449 from equilibria-xyz/prateek/fix-immutable-state
Browse files Browse the repository at this point in the history
Fix public immutable state
  • Loading branch information
prateekdefi authored Sep 30, 2024
2 parents 01e6c3b + 7faab93 commit 354a930
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
4 changes: 2 additions & 2 deletions packages/perennial-account/contracts/Controller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions packages/perennial-account/contracts/Controller_Arbitrum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 8 additions & 7 deletions packages/perennial-account/contracts/Controller_Incentivized.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,35 @@ 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 Handles relayed messages for nonce cancellation
IVerifierBase public immutable nonceManager;

/// @dev Configuration used to calculate keeper compensation
KeepConfig public keepConfig;

/// @dev Handles relayed messages for nonce cancellation
IVerifierBase public 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_;
}

/// @notice Configures message verification and keeper compensation
/// @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
Expand Down
2 changes: 0 additions & 2 deletions packages/perennial-account/test/helpers/arbitrumHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,13 @@ 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<Controller_Arbitrum> {
const accountImpl = await new Account__factory(owner).deploy(USDC_ADDRESS, DSU_ADDRESS, DSU_RESERVE)
accountImpl.initialize(constants.AddressZero)
const controller = await new Controller_Arbitrum__factory(owner).deploy(
accountImpl.address,
keepConfig,
nonceManager.address,
overrides ?? {},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/perennial-order/contracts/Manager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 354a930

Please sign in to comment.