Skip to content

Commit

Permalink
add typescript test, fix order param market_type
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbigz committed Jan 11, 2024
1 parent 98ef362 commit 3156829
Show file tree
Hide file tree
Showing 6 changed files with 504 additions and 2 deletions.
1 change: 1 addition & 0 deletions programs/drift/src/state/order_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl OrderParams {
};

let params = OrderParams {
market_type: MarketType::Perp,
direction: direction_to_close,
order_type: OrderType::Oracle,
market_index: market.market_index,
Expand Down
8 changes: 8 additions & 0 deletions programs/drift/src/state/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,14 @@ impl PerpPosition {
.map(|delta| delta.max(0))?
.safe_add(pnl_pool_excess.max(0))?;

if max_positive_pnl < unrealized_pnl {
msg!(
"Claimable pnl below position upnl: {} < {}",
max_positive_pnl,
unrealized_pnl

Check warning on line 926 in programs/drift/src/state/user.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/state/user.rs#L925-L926

Added lines #L925 - L926 were not covered by tests
);
}

Ok(unrealized_pnl.min(max_positive_pnl))
} else {
Ok(unrealized_pnl)
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/math/funding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ONE,
FUNDING_RATE_OFFSET_DENOMINATOR,
} from '../constants/numericConstants';
import { ContractTier, PerpMarketAccount, isVariant } from '../types';
import { PerpMarketAccount, isVariant } from '../types';
import { OraclePriceData } from '../oracles/types';
import { calculateBidAskPrice } from './amm';
import { calculateLiveOracleTwap } from './oracles';
Expand Down
1 change: 1 addition & 0 deletions test-scripts/run-anchor-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ test_files=(
stopLimits.ts
oracleFillPriceGuardrails.ts
perpLpJit.ts
perpLpRiskMitigation.ts
spotSwap.ts
maxLeverageOrderParams.ts
multipleMakerOrders.ts
Expand Down
2 changes: 1 addition & 1 deletion test-scripts/single-anchor-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if [ "$1" != "--skip-build" ]
cp target/idl/drift.json sdk/src/idl/
fi

test_files=(perpLpJit.ts)
test_files=(perpLpRiskMitigation.ts)

for test_file in ${test_files[@]}; do
ANCHOR_TEST_FILE=${test_file} anchor test --skip-build || exit 1;
Expand Down
Loading

0 comments on commit 3156829

Please sign in to comment.