Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix public immutable state #449

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 6 additions & 5 deletions packages/perennial-account/contracts/Controller_Incentivized.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,31 @@ 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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this above the mutable keepConfig just to make the storage layout clearer?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7faab93


/// @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 @@ -25,7 +25,7 @@
IOracleProvider,
GasOracle__factory,
} from '../../types/generated'
import { IKept } from '../../types/generated/contracts/Controller_Arbitrum'

Check warning on line 28 in packages/perennial-account/test/helpers/arbitrumHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint

'IKept' is defined but never used
import { impersonate } from '../../../common/testutil'
import { IVerifier } from '@equilibria/perennial-v2/types/generated'

Expand Down Expand Up @@ -152,15 +152,13 @@
// 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
Loading