Skip to content

Commit

Permalink
Merge pull request #457 from equilibria-xyz/ed/90-marketparameter-sto…
Browse files Browse the repository at this point in the history
…rage

Fix issue with MarketParameter storage layout
  • Loading branch information
EdNoepel authored Oct 3, 2024
2 parents 41ec629 + c5ef1cc commit 75cccea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
17 changes: 8 additions & 9 deletions packages/perennial/contracts/types/MarketParameter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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
);
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 0 additions & 8 deletions packages/perennial/test/integration/core/happyPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions packages/perennial/test/integration/helpers/setupHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 75cccea

Please sign in to comment.