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 issue with MarketParameter storage layout #457

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading