Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrizzle committed Jan 13, 2023
1 parent b72a35a commit 6832873
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 32 deletions.
25 changes: 0 additions & 25 deletions packages/perennial/contracts/Market.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,6 @@ import "hardhat/console.sol";
* @dev Cloned by the Factory contract to launch new market markets.
*/
contract Market is IMarket, UInitializable, UOwnable {
struct CurrentContext {
/* Global Parameters */
ProtocolParameter protocolParameter;

/* Market Parameters */
MarketParameter marketParameter;

/* Current Global State */
OracleVersion currentOracleVersion;

Version version;

Position position;

Fee fee;

/* Current Account State */
Account account;

/* Debugging */
uint256 gasCounter;

string gasCounterMessage;
}

/// @dev The name of the market
string public name;

Expand Down
13 changes: 13 additions & 0 deletions packages/perennial/contracts/interfaces/IMarket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ interface IMarket is IOwnable {
Token18 reward;
}

struct CurrentContext {
ProtocolParameter protocolParameter;
MarketParameter marketParameter;
OracleVersion currentOracleVersion;
Version version;
Position position;
Fee fee;
Account account;

uint256 gasCounter;
string gasCounterMessage;
}

event Settle(uint256 preVersion, uint256 toVersion);
event AccountSettle(address indexed account, uint256 preVersion, uint256 toVersion);
event Updated(address indexed account, uint256 version, UFixed6 newMaker, UFixed6 newTaker, Fixed6 newCollateral);
Expand Down
10 changes: 4 additions & 6 deletions packages/perennial/contracts/types/Version.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ library VersionLib {
ProtocolParameter memory protocolParameter,
MarketParameter memory marketParameter
) internal pure returns (UFixed6 fundingFeeAmount) {
if (marketParameter.closed) return UFixed6Lib.ZERO;

// accumulate funding
fundingFeeAmount =
_accumulateFunding(self, position, fromOracleVersion, toOracleVersion, protocolParameter, marketParameter);
Expand All @@ -97,9 +99,7 @@ library VersionLib {
ProtocolParameter memory protocolParameter,
MarketParameter memory marketParameter
) private pure returns (UFixed6 fundingFeeAmount) {
if (marketParameter.closed) return UFixed6Lib.ZERO;
if (position.taker.isZero()) return UFixed6Lib.ZERO;
if (position.maker.isZero()) return UFixed6Lib.ZERO;
if (position.taker.isZero() || position.maker.isZero()) return UFixed6Lib.ZERO;

UFixed6 takerNotional = Fixed6Lib.from(position.taker).mul(fromOracleVersion.price).abs();
UFixed6 socializedTakerNotional = takerNotional.mul(position.socializationFactor());
Expand Down Expand Up @@ -134,9 +134,7 @@ library VersionLib {
OracleVersion memory toOracleVersion,
MarketParameter memory marketParameter
) private pure {
if (marketParameter.closed) return;
if (position.taker.isZero()) return;
if (position.maker.isZero()) return;
if (position.taker.isZero() || position.maker.isZero()) return;

Fixed6 totalTakerDelta =
toOracleVersion.price.sub(fromOracleVersion.price).mul(Fixed6Lib.from(position.taker));
Expand Down
2 changes: 1 addition & 1 deletion packages/perennial/test/integration/core/happyPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InstanceVars, deployProtocol, createMarket, INITIAL_VERSION } from '../
import { expectPositionEq, parse6decimal } from '../../../../common/testutil/types'
import { Market__factory } from '../../../types/generated'

describe('Happy Path', () => {
describe.only('Happy Path', () => {
let instanceVars: InstanceVars

beforeEach(async () => {
Expand Down

0 comments on commit 6832873

Please sign in to comment.