From c5ef1cc4f920620d245363e1b784b21b396d27d5 Mon Sep 17 00:00:00 2001 From: Ed Noepel Date: Tue, 1 Oct 2024 10:18:13 -0400 Subject: [PATCH] adjusted storage layout --- .../contracts/types/MarketParameter.sol | 17 ++++++++--------- .../test/integration/core/happyPath.test.ts | 8 -------- .../test/integration/helpers/setupHelpers.ts | 2 -- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/packages/perennial/contracts/types/MarketParameter.sol b/packages/perennial/contracts/types/MarketParameter.sol index 54bb6ad63..e78e2ba1d 100644 --- a/packages/perennial/contracts/types/MarketParameter.sol +++ b/packages/perennial/contracts/types/MarketParameter.sol @@ -46,7 +46,6 @@ using MarketParameterStorageLib for MarketParameterStorage global; /// uint24 interestFee; // <= 1677% /// uint24 makerFee; // <= 1677% /// uint24 takerFee; // <= 1677% -/// uint24 __unallocated__; // <= 1677% /// uint24 riskFee; // <= 1677% /// uint16 maxPendingGlobal; // <= 65k /// uint16 maxPendingLocal; // <= 65k @@ -61,7 +60,7 @@ library MarketParameterStorageLib { function read(MarketParameterStorage storage self) internal view returns (MarketParameter memory) { uint256 slot0 = self.slot0; - uint256 flags = uint256(slot0 << (256 - 24 - 24 - 24 - 24 - 24 - 24 - 16 - 16 - 48 - 8)) >> (256 - 8); + uint256 flags = uint256(slot0 << (256 - 24 - 24 - 24 - 24 - 24 - 16 - 16 - 48 - 8)) >> (256 - 8); (bool closed, bool settle) = (flags & 0x04 == 0x04, flags & 0x08 == 0x08); @@ -70,9 +69,9 @@ library MarketParameterStorageLib { UFixed6.wrap(uint256(slot0 << (256 - 24 - 24)) >> (256 - 24)), UFixed6.wrap(uint256(slot0 << (256 - 24 - 24 - 24)) >> (256 - 24)), UFixed6.wrap(uint256(slot0 << (256 - 24 - 24 - 24 - 24)) >> (256 - 24)), - UFixed6.wrap(uint256(slot0 << (256 - 24 - 24 - 24 - 24 - 24 - 24)) >> (256 - 24)), - uint256(slot0 << (256 - 24 - 24 - 24 - 24 - 24 - 24 - 16)) >> (256 - 16), - uint256(slot0 << (256 - 24 - 24 - 24 - 24 - 24 - 24 - 16 - 16)) >> (256 - 16), + UFixed6.wrap(uint256(slot0 << (256 - 24 - 24 - 24 - 24 - 24)) >> (256 - 24)), + uint256(slot0 << (256 - 24 - 24 - 24 - 24 - 24 - 16)) >> (256 - 16), + uint256(slot0 << (256 - 24 - 24 - 24 - 24 - 24 - 16 - 16)) >> (256 - 16), closed, settle ); @@ -108,10 +107,10 @@ library MarketParameterStorageLib { uint256(UFixed6.unwrap(newValue.interestFee) << (256 - 24)) >> (256 - 24 - 24) | uint256(UFixed6.unwrap(newValue.makerFee) << (256 - 24)) >> (256 - 24 - 24 - 24) | uint256(UFixed6.unwrap(newValue.takerFee) << (256 - 24)) >> (256 - 24 - 24 - 24 - 24) | - uint256(UFixed6.unwrap(newValue.riskFee) << (256 - 24)) >> (256 - 24 - 24 - 24 - 24 - 24 - 24) | - uint256(newValue.maxPendingGlobal << (256 - 16)) >> (256 - 24 - 24 - 24 - 24 - 24 - 24 - 16) | - uint256(newValue.maxPendingLocal << (256 - 16)) >> (256 - 24 - 24 - 24 - 24 - 24 - 24 - 16 - 16) | - uint256(flags << (256 - 8)) >> (256 - 24 - 24 - 24 - 24 - 24 - 24 - 16 - 16 - 48 - 8); + uint256(UFixed6.unwrap(newValue.riskFee) << (256 - 24)) >> (256 - 24 - 24 - 24 - 24 - 24) | + uint256(newValue.maxPendingGlobal << (256 - 16)) >> (256 - 24 - 24 - 24 - 24 - 24 - 16) | + uint256(newValue.maxPendingLocal << (256 - 16)) >> (256 - 24 - 24 - 24 - 24 - 24 - 16 - 16) | + uint256(flags << (256 - 8)) >> (256 - 24 - 24 - 24 - 24 - 24 - 16 - 16 - 48 - 8); assembly { sstore(self.slot, encoded0) diff --git a/packages/perennial/test/integration/core/happyPath.test.ts b/packages/perennial/test/integration/core/happyPath.test.ts index 133ba6ff1..31fbe090c 100644 --- a/packages/perennial/test/integration/core/happyPath.test.ts +++ b/packages/perennial/test/integration/core/happyPath.test.ts @@ -110,13 +110,11 @@ describe('Happy Path', () => { const parameter = { fundingFee: parse6decimal('0.1'), interestFee: parse6decimal('0.1'), - oracleFee: 0, riskFee: 0, makerFee: 0, takerFee: 0, maxPendingGlobal: 8, maxPendingLocal: 8, - settlementFee: 0, closed: false, settle: false, } @@ -1287,9 +1285,7 @@ describe('Happy Path', () => { const parameter = { fundingFee: parse6decimal('0.1'), interestFee: parse6decimal('0.1'), - oracleFee: 0, riskFee: 0, - settlementFee: 0, maxPendingGlobal: 8, maxPendingLocal: 8, makerFee: positionFeesOn ? parse6decimal('0.2') : 0, @@ -1452,9 +1448,7 @@ describe('Happy Path', () => { const parameter = { fundingFee: parse6decimal('0.1'), interestFee: parse6decimal('0.1'), - oracleFee: 0, riskFee: 0, - settlementFee: 0, maxPendingGlobal: 8, maxPendingLocal: 8, makerFee: parse6decimal('0.2'), @@ -2530,9 +2524,7 @@ describe('Happy Path', () => { const parameter = { fundingFee: parse6decimal('0.1'), interestFee: parse6decimal('0.1'), - oracleFee: 0, riskFee: 0, - settlementFee: 0, maxPendingGlobal: 8, maxPendingLocal: 8, makerFee: positionFeesOn ? parse6decimal('0.2') : 0, diff --git a/packages/perennial/test/integration/helpers/setupHelpers.ts b/packages/perennial/test/integration/helpers/setupHelpers.ts index e800410c5..4cc673b71 100644 --- a/packages/perennial/test/integration/helpers/setupHelpers.ts +++ b/packages/perennial/test/integration/helpers/setupHelpers.ts @@ -261,13 +261,11 @@ export async function createMarket( const marketParameter = { fundingFee: parse6decimal('0.1'), interestFee: parse6decimal('0.1'), - oracleFee: 0, riskFee: 0, makerFee: 0, takerFee: 0, maxPendingGlobal: 8, maxPendingLocal: 8, - settlementFee: 0, closed: false, settle: false, ...marketParamOverrides,