Skip to content

Commit

Permalink
Merge branch 'master' into bigz/add-unsettled-to-net-user-pnl
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Apr 20, 2024
2 parents 231fa23 + 1611eda commit 7aa9dcf
Show file tree
Hide file tree
Showing 80 changed files with 6,922 additions and 1,797 deletions.
3 changes: 3 additions & 0 deletions .verified-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH": ["--commit-hash", "8d2cd726afdc800f89c841ff3cf1968980719df0", "--library-name", "drift"]
}
115 changes: 94 additions & 21 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,84 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixes

- program: fix checking isolated tier in add_perp_lp_shares
### Breaking

## [2.79.0] - 2024-04-18

### Features

### Fixes

- program: program: let user with positive pnl be settled if being liquidated ([#1020](https://github.com/drift-labs/protocol-v2/pull/1020))
- program: fix should_expire_order_before_fill ([#1021](https://github.com/drift-labs/protocol-v2/pull/1021))

### Breaking

## [2.78.0] - 2024-04-15

### Features

### Fixes

- program: set default ContractTier to HighlySpeculative ([#1013](https://github.com/drift-labs/protocol-v2/pull/1013))
- program: avoid dust borrows not being transferred

### Breaking

## [2.77.0] - 2024-04-13

### Features
- program: lax funding rate update oracle validity criteria ([#1009](https://github.com/drift-labs/protocol-v2/pull/1009))

### Fixes

- program: fix div by 0 in calculate_liability_transfer_to_cover_margin_shortage

### Breaking

## [2.76.0] - 2024-04-09

### Features

- program: rm admins ability to withdraw from if ([#990](https://github.com/drift-labs/protocol-v2/pull/990))
- program: add add ability to delete initialized spot market ([#998](https://github.com/drift-labs/protocol-v2/pull/998))
- program: more reliable oracle updates ([#1000](https://github.com/drift-labs/protocol-v2/pull/1000))

### Fixes

- program: avoid underflow in update pnl ([#1002](https://github.com/drift-labs/protocol-v2/pull/1002))

### Breaking

## [2.75.0] - 2024-04-01

### Features

- program: add fee adjustment to spot market ([#987](https://github.com/drift-labs/protocol-v2/pull/987))
- program: allow multiple makers to be passed into for spot fills ([#946](https://github.com/drift-labs/protocol-v2/pull/946))
- ts-sdk: add fn to get admin ix ([#980](https://github.com/drift-labs/protocol-v2/pull/980))
- program: add invariant check boolean for attempt settle revenue to insurance ([#937](https://github.com/drift-labs/protocol-v2/pull/937))
- program: improve best bid/ask estimate in mark twap update ([#975](https://github.com/drift-labs/protocol-v2/pull/975))
- program: add optional margin calculations for drift-rs ([#978](https://github.com/drift-labs/protocol-v2/pull/978))

### Fixes

### Breaking

## [2.74.0] - 2024-03-25

### Features

- program: add 'highly speculative' contract tier enum 4 ([#968](https://github.com/drift-labs/protocol-v2/pull/968))
- program: expand initialize market parameters ([#969](https://github.com/drift-labs/protocol-v2/pull/969))

### Fixes

- program: fix checking isolated tier in add_perp_lp_shares ([#965](https://github.com/drift-labs/protocol-v2/pull/965))

### Breaking

## [2.73.0] - 2023-03-15
## [2.73.0] - 2024-03-15

### Features

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

### Breaking

## [2.72.0] - 2023-03-14
## [2.72.0] - 2024-03-14

### Features

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

### Breaking

## [2.71.0] - 2023-03-11
## [2.71.0] - 2024-03-11

### Features

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

- sdk: account for max confidence in isOracleValid ([#949](https://github.com/drift-labs/protocol-v2/pull/949))

## [2.70.0] - 2023-03-07
## [2.70.0] - 2024-03-07

### Features

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

### Breaking

## [2.69.0] - 2023-03-06
## [2.69.0] - 2024-03-06

### Features

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

- program: revert switchboard ([#935](https://github.com/drift-labs/protocol-v2/pull/935))

## [2.68.0] - 2023-03-05
## [2.68.0] - 2024-03-05

### Features

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

### Breaking

## [2.67.0] - 2023-03-05
## [2.67.0] - 2024-03-05

### Features

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

### Breaking

## [2.66.0] - 2023-02-28
## [2.66.0] - 2024-02-28

### Features

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

### Breaking

## [2.65.0] - 2023-02-26
## [2.65.0] - 2024-02-26

### Features

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

### Breaking

## [2.64.0] - 2023-02-20
## [2.64.0] - 2024-02-20

### Features

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

### Breaking

## [2.63.0] - 2023-02-16
## [2.63.0] - 2024-02-16

### Features

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

### Breaking

## [2.62.0] - 2023-02-14
## [2.62.0] - 2024-02-14

### Features

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

### Breaking

## [2.61.0] - 2023-02-09
## [2.61.0] - 2024-02-09

### Features

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

### Breaking

## [2.60.0] - 2023-02-07
## [2.60.0] - 2024-02-07

### Features

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

### Breaking

## [2.59.0] - 2023-01-30
## [2.59.0] - 2024-01-30

### Features

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

### Breaking

## [2.58.0] - 2023-01-27
## [2.58.0] - 2024-01-27

### Features

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

### Breaking

## [2.57.0] - 2023-01-25
## [2.57.0] - 2024-01-25

### Features

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

### Breaking

## [2.56.0] - 2023-01-24
## [2.56.0] - 2024-01-24

### Features

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

### Breaking

## [2.55.0] - 2023-01-18
## [2.55.0] - 2024-01-18

### Features

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

### Breaking

## [2.54.0] - 2023-01-15
## [2.54.0] - 2024-01-15

### Features

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion programs/drift/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "drift"
version = "2.73.0"
version = "2.79.0"
description = "Created with Anchor"
edition = "2018"

Expand All @@ -15,6 +15,7 @@ cpi = ["no-entrypoint"]
mainnet-beta=[]
anchor-test= []
default=["mainnet-beta"]
drift-rs=[]

[dependencies]
anchor-lang = "0.27.0"
Expand Down
44 changes: 31 additions & 13 deletions programs/drift/src/controller/amm/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ fn update_pool_balances_revenue_to_fee_test() {
},
..PerpMarket::default()
};
let now = 33928058;
let mut now = 33928058;

let mut spot_market = SpotMarket {
deposit_balance: 200 * SPOT_BALANCE_PRECISION,
Expand All @@ -822,6 +822,19 @@ fn update_pool_balances_revenue_to_fee_test() {
let prev_tfmd = market.amm.total_fee_minus_distributions;

assert_eq!(market.amm.total_fee_withdrawn, 0);
assert_eq!(spot_market.insurance_fund.revenue_settle_period, 0);

spot_market.insurance_fund.revenue_settle_period = 0;
let res = settle_revenue_to_insurance_fund(0, 0, &mut spot_market, now + 3600, true).unwrap();
assert_eq!(res, 0);
spot_market.insurance_fund.revenue_settle_period = 1;

spot_market.revenue_pool.scaled_balance = 0;
let res =
settle_revenue_to_insurance_fund(200000000, 0, &mut spot_market, now + 1, false).unwrap();
assert_eq!(res, 0);
spot_market.revenue_pool.scaled_balance = 100 * SPOT_BALANCE_PRECISION;
now += 2;

assert_eq!(
get_token_amount(
Expand Down Expand Up @@ -892,7 +905,7 @@ fn update_pool_balances_revenue_to_fee_test() {
market.insurance_claim.revenue_withdraw_since_last_settle,
100000000
);
assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 33928058);
assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, now);

let spot_market_vault_amount = get_token_amount(
spot_market.deposit_balance,
Expand Down Expand Up @@ -953,7 +966,7 @@ fn update_pool_balances_revenue_to_fee_test() {
market.insurance_claim.revenue_withdraw_since_last_settle,
market.insurance_claim.max_revenue_withdraw_per_period as i64
);
assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 33928058);
assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, now);

// calling again only does fee -> pnl pool
update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap();
Expand All @@ -966,7 +979,7 @@ fn update_pool_balances_revenue_to_fee_test() {
market.insurance_claim.revenue_withdraw_since_last_settle,
market.insurance_claim.max_revenue_withdraw_per_period as i64
);
assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 33928058);
assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, now);

// calling again does nothing
update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap();
Expand All @@ -979,17 +992,22 @@ fn update_pool_balances_revenue_to_fee_test() {
market.insurance_claim.revenue_withdraw_since_last_settle,
market.insurance_claim.max_revenue_withdraw_per_period as i64
);
assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 33928058);
assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, now);

// do a revenue settlement to allow up to max again
assert_eq!(spot_market.insurance_fund.last_revenue_settle_ts, 0);
assert_eq!(spot_market.insurance_fund.last_revenue_settle_ts, 33928059);
assert_eq!(spot_market.deposit_balance, 10100000001000);

spot_market.insurance_fund.total_factor = 1;
spot_market.insurance_fund.revenue_settle_period = 1;
let res =
settle_revenue_to_insurance_fund(spot_market_vault_amount, 0, &mut spot_market, now + 3600)
.unwrap();
let res = settle_revenue_to_insurance_fund(
spot_market_vault_amount,
0,
&mut spot_market,
now + 3600,
true,
)
.unwrap();
assert_eq!(res, 9800000001);

let spot_market_vault_amount = get_token_amount(
Expand Down Expand Up @@ -1025,17 +1043,17 @@ fn update_pool_balances_revenue_to_fee_test() {
assert_eq!(market.amm.total_fee_minus_distributions, -9800000000);
assert_eq!(market.amm.total_fee_withdrawn, 0);
assert_eq!(spot_market.revenue_pool.scaled_balance, 9800000001000);
assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 33928058);
assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 33928060);
assert_eq!(
spot_market.insurance_fund.last_revenue_settle_ts,
33928058 + 3600
33928060 + 3600
);

assert!(update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).is_err()); // now timestamp passed is wrong
update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now + 3600).unwrap();

assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 33931658);
assert_eq!(spot_market.insurance_fund.last_revenue_settle_ts, 33931658);
assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 33931660);
assert_eq!(spot_market.insurance_fund.last_revenue_settle_ts, 33931660);
assert_eq!(market.amm.fee_pool.scaled_balance, 205000000000);
assert_eq!(market.pnl_pool.scaled_balance, 295000000000);
assert_eq!(market.amm.total_fee_minus_distributions, -9600000000);
Expand Down
Loading

0 comments on commit 7aa9dcf

Please sign in to comment.