Skip to content

Commit

Permalink
Merge branch 'master' into crispheaney/derive-perp-auction-params-whe…
Browse files Browse the repository at this point in the history
…n-missing
  • Loading branch information
crispheaney committed Feb 8, 2024
2 parents 488beec + adb90df commit b6141cb
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 16 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Features

- program: better derivation of perp auction params when missing and for triggers ([#869](https://github.com/drift-labs/protocol-v2/pull/869))
- program: calculate whether oracle's num quoters sufficient ([#860](https://github.com/drift-labs/protocol-v2/pull/860))

### Fixes

Expand All @@ -20,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Features

- program: sanitize perp auction params ([#859](https://github.com/drift-labs/protocol-v2/pull/859))
- program: add repay borrow explanation ([#862](https://github.com/drift-labs/protocol-v2/pull/862))
- program: add repay borrow explanation ([#862](https://github.com/drift-labs/protocol-v2/pull/862))
- program: derisk lp more granularly ([#849](https://github.com/drift-labs/protocol-v2/pull/849))

### Fixes
Expand Down Expand Up @@ -81,6 +82,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.54.0] - 2023-01-15

### Features

- sdk: move bracket orders into single instruction
- sdk: add ability to do placeAndTake order with bracket orders attached
- sdk: add option to cancel existing orders in market for place and take order
Expand All @@ -98,7 +100,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Breaking


## [2.53.0] - 2023-12-31

### Features
Expand All @@ -116,7 +117,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- program: add ability to reclaim rent without deleting account ([#763](https://github.com/drift-labs/protocol-v2/pull/763))
- program: add ability to reclaim rent without deleting account ([#763](https://github.com/drift-labs/protocol-v2/pull/763))
- program: add borrow explanation to DepositRecords ([#772](https://github.com/drift-labs/protocol-v2/pull/772))
- sdk: OrderSubscriber has resync option ([#780](https://github.com/drift-labs/protocol-v2/pull/780))
- program: only consider recent last_active_slot in qualifies_for_withdraw_feen ([#756](https://github.com/drift-labs/protocol-v2/pull/756))
Expand All @@ -125,7 +126,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixes

- program: handle underflow in calculate_liability_transfer_to_cover_margin_shortage ([#774](https://github.com/drift-labs/protocol-v2/pull/774))
- program: flip auction flag when trigger order adds auction ([#775](https://github.com/drift-labs/protocol-v2/pull/775))
- program: flip auction flag when trigger order adds auction ([#775](https://github.com/drift-labs/protocol-v2/pull/775))
- program: don't perform funding rate updates when slots_since_amm_update is stale ([#757](https://github.com/drift-labs/protocol-v2/pull/757))
- program: add update last slot for filler in pay_keeper_flat_reward_for_spot

Expand Down
5 changes: 4 additions & 1 deletion programs/drift/src/state/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ pub fn get_pyth_price(
let oracle_price = price_data.agg.price;
let oracle_conf = price_data.agg.conf;

let min_publishers = price_data.num.min(3);
let publisher_count = price_data.num_qt;

let oracle_precision = 10_u128.pow(price_data.expo.unsigned_abs());

if oracle_precision <= multiple {
Expand Down Expand Up @@ -207,7 +210,7 @@ pub fn get_pyth_price(
price: oracle_price_scaled,
confidence: oracle_conf_scaled,
delay: oracle_delay,
has_sufficient_number_of_data_points: true,
has_sufficient_number_of_data_points: publisher_count >= min_publishers,
})
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.61.0-beta.1
2.61.0-beta.2
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@drift-labs/sdk",
"version": "2.61.0-beta.1",
"version": "2.61.0-beta.2",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"author": "crispheaney",
Expand Down
30 changes: 22 additions & 8 deletions sdk/src/math/exchangeStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,36 @@ export function fillPaused(
state: StateAccount,
market: PerpMarketAccount | SpotMarketAccount
): boolean {
return (
if (
(state.exchangeStatus & ExchangeStatus.FILL_PAUSED) ===
ExchangeStatus.FILL_PAUSED ||
isOneOfVariant(market.status, ['paused', 'fillPaused'])
);
ExchangeStatus.FILL_PAUSED
) {
return true;
}

if (market.hasOwnProperty('amm')) {
return isOperationPaused(market.pausedOperations, PerpOperation.FILL);
} else {
return isOperationPaused(market.pausedOperations, SpotOperation.FILL);
}
}

export function ammPaused(
state: StateAccount,
market: PerpMarketAccount | SpotMarketAccount
): boolean {
return (
if (
(state.exchangeStatus & ExchangeStatus.AMM_PAUSED) ===
ExchangeStatus.AMM_PAUSED ||
isOneOfVariant(market.status, ['paused', 'ammPaused'])
);
ExchangeStatus.AMM_PAUSED
) {
return true;
}

if (market.hasOwnProperty('amm')) {
return isOperationPaused(market.pausedOperations, PerpOperation.AMM_FILL);
} else {
return false;
}
}

export function isOperationPaused(
Expand Down
3 changes: 2 additions & 1 deletion sdk/src/oracles/pythClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class PythClient implements OracleClient {
priceData.exponent,
this.multiple
);
const minPublishers = Math.min(priceData.numComponentPrices, 3);
let price = convertPythPrice(
priceData.aggregate.price,
priceData.exponent,
Expand All @@ -61,7 +62,7 @@ export class PythClient implements OracleClient {
priceData.exponent,
this.multiple
),
hasSufficientNumberOfDataPoints: true,
hasSufficientNumberOfDataPoints: priceData.numQuoters >= minPublishers,
};
}
}
Expand Down
3 changes: 3 additions & 0 deletions sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ export type PerpMarketAccount = {
};
quoteSpotMarketIndex: number;
feeAdjustment: number;
pausedOperations: number;
};

export type HistoricalOracleData = {
Expand Down Expand Up @@ -700,6 +701,8 @@ export type SpotMarketAccount = {
flashLoanInitialTokenAmount: BN;

ordersEnabled: boolean;

pausedOperations: number;
};

export type PoolBalance = {
Expand Down

0 comments on commit b6141cb

Please sign in to comment.