-
Notifications
You must be signed in to change notification settings - Fork 209
Wphan/builder codes #1805
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
Merged
Merged
Wphan/builder codes #1805
Changes from 24 commits
Commits
Show all changes
230 commits
Select commit
Hold shift + click to select a range
f251378
program: init lp pool
0xbigz be58c57
cargo fmt --
0xbigz 2cf149d
add total fee fields
0xbigz b2cf992
add update_target_weights math
0xbigz a405a56
program: use sparse matrix for constituent map and update tests
0xbigz 34b044c
zero copy accounts, init ix (#1578)
wphan 5d3fd5e
update accounts (#1580)
wphan 9826453
zero copy + permissionless crank ixs (#1581)
moosecat2 b7e0cab
program: support negative target weights for borrow-lend
0xbigz 57b4ec2
fix tests to work with zero copy
moosecat2 81dd06e
few comment changes
moosecat2 73b32d5
remove discriminator from impl macro
moosecat2 afdfe7b
add get_swap_amount, get_swap_fees, get_weight (#1579)
wphan 9383688
fix swap fee calc (#1582)
wphan 007bace
add init amm mapping to lp context (#1583)
moosecat2 10d070e
init constituent
moosecat2 6cd4254
Merge pull request #1584 from drift-labs/nour/init-constituent
moosecat2 1d7fd00
add initializeLpPool test (#1585)
wphan be22c24
add add datum ix
moosecat2 ffd6a51
Merge branch 'bigz/init-lp-pool' into nour/add-mapping-datum
moosecat2 188ab4e
add init tests and invariant checks
moosecat2 6353b62
Merge pull request #1587 from drift-labs/nour/add-mapping-datum
moosecat2 f450cb2
rename data to more useful names
moosecat2 c803c16
dlp use spl token program (#1588)
wphan f7fac79
add crank ix
moosecat2 6bbe40d
update total_weight for validation_flags check
0xbigz 55014a0
push test so far
moosecat2 4b13618
overriding perp position works
moosecat2 39726c5
remove message
moosecat2 222a335
Merge pull request #1589 from drift-labs/nour/crank-constituent-targe…
moosecat2 bddb41f
fix dup total_weight add
0xbigz 495977f
constituent map remaining accounts
moosecat2 014b4a3
compiles
moosecat2 228b94b
bankrun tests pass
moosecat2 0b7049c
compiles but casting failure in overflow protection test
moosecat2 9372702
address comment and change token arguments from u64 to u128
moosecat2 9addd8c
bankrun tests pass
moosecat2 33dbe08
Merge branch 'nour/crank-aum' into nour/remove-amm-mappings
moosecat2 5d6f15f
Merge pull request #1595 from drift-labs/nour/remove-amm-mappings
moosecat2 e950e5d
init constituent token account (#1596)
wphan f145aa1
update aum calc
moosecat2 4c8a721
add update /remove mapping ixs
moosecat2 16ab911
Merge branch 'bigz/init-lp-pool' into nour/crank-aum
moosecat2 b6ec47c
Merge pull request #1593 from drift-labs/nour/crank-aum
moosecat2 3923458
fix test - init constituent spot market
wphan 11fed5f
add crank improvements
moosecat2 8721f9b
crank improvements
moosecat2 a059f00
passes tests
moosecat2 cbf3395
precision fix crank aum
moosecat2 a7830f4
precision fixes and constituent map check for account owner
moosecat2 420b85f
Merge pull request #1598 from drift-labs/nour/crank-aum-improvements
moosecat2 1c24027
add passthrough account logic (#1602)
moosecat2 cb34da4
Wphan/dlp-swap-ixs (#1592)
wphan 4974540
Merge branch 'master' into bigz/init-lp-pool
wphan 2589040
post-merge fixes
wphan 961d6ed
store bumps on accounts (#1604)
moosecat2 9bfbab1
address comments
moosecat2 b363288
Merge pull request #1611 from drift-labs/nour/address-comments
moosecat2 dce2442
Wphan/add liquidity (#1607)
wphan 8f19f61
program: lp-pool-to-use-target-base-vector (#1615)
0xbigz acab7f5
add beta and cost to trade in bps to target datum
moosecat2 9f99b1d
add more tests
moosecat2 ec2e2f0
Merge pull request #1617 from drift-labs/nour/beta-cost-to-trade
moosecat2 db3ad52
add fields to LP events, fix tests (#1620)
wphan b9efc52
dlp jup swap (#1636)
moosecat2 ee50a60
cleanup
moosecat2 1f70026
transfer oracle data ix to constituent (#1643)
moosecat2 83e22ec
big cargo test (#1644)
moosecat2 e980aa7
derivative constituents + better testing + bug fixes (#1657)
moosecat2 2ae54d1
deposit/borrow working and changing positions (#1652)
moosecat2 b1fb7a8
sdk: allow custom coder
wphan 81e442a
program: dlp add upnl for settles to amm cache (#1659)
0xbigz d374e55
remove unused accounts coder
wphan a4a2f02
move customCoder into sdk, lint
wphan 0871d9d
testing: ix: settle perp to dlp, insufficient balance edge case and i…
moosecat2 34e9f99
added more settle test coverage and squash bugs (#1689)
moosecat2 feda828
dlp: add constituentMap (#1699)
wphan 71db8bf
Nour/gauntlet fee impl (#1698)
moosecat2 7a94a4a
update aum considers amm cache (#1701)
moosecat2 f5d5a4f
prettify (#1702)
moosecat2 30fe08f
Wphan/merge master dlp (#1703)
wphan bd615ea
slot staleness checks (#1705)
moosecat2 b41cd6e
Nour/derivative constituent testing (#1708)
moosecat2 7efab3e
merge
crispheaney c00ebb6
Merge branch 'master' into bigz/init-lp-pool
wphan 4fe3146
Merge branch 'master' into bigz/init-lp-pool
wphan d5643a1
remove incorrect usage of nav
wphan 6cfa245
Merge remote-tracking branch 'origin/bigz/init-lp-pool' into bigz/ini…
wphan 8be6977
fix adminClient and tests
wphan 99b52ac
Nour/fee grid search testing (#1714)
moosecat2 6e6813a
Nour/address comments (#1715)
moosecat2 84569d6
add swap fee unit tests (#1713)
wphan 9ebb39a
Nour/settle accounting (#1723)
moosecat2 bac790e
dont update lp quote owed unless collateralized
moosecat2 0e9a454
Nour/settle testing (#1725)
moosecat2 c5ccdea
prettify
moosecat2 464e1d3
Nour/address more comments (#1726)
moosecat2 19c88f8
refactor update_aum, add unit tests (#1727)
wphan b8a8030
Nour/parameterize dlp (#1731)
moosecat2 a3e2ee0
Merge branch 'master' into bigz/init-lp-pool
moosecat2 0bafd5a
fixes
moosecat2 016dda3
update idl
moosecat2 5f8f4f0
bug fixes
moosecat2 839c17d
mostly sdk fixes
moosecat2 0dffd52
bug fixes
moosecat2 ee408ae
merge in master and fix conflicts
moosecat2 edb3039
bug fix and deploy script
moosecat2 ce30260
merge in master
moosecat2 e6eef9d
program: new amm oracle (#1738)
moosecat2 f493187
fix tests (#1764)
moosecat2 fa47f31
Nour/move ixs around (#1766)
moosecat2 2bb3ab4
add devnet oracle crank wallet
moosecat2 35a5939
refactored mm oracle
moosecat2 bd9c1ac
Merge branch 'master' into nour/mm-oracle-2
moosecat2 13264f1
sdk changes + cargo fmt
moosecat2 7015234
fix tests
moosecat2 10d9178
validate price bands with fill fix
moosecat2 d6708e2
normalize fill within price bands
moosecat2 254990e
add sdk warning
moosecat2 d812fd2
updated type
moosecat2 7377f16
undefined guard so anchor tests pass
moosecat2 742ac6c
accept vec for update amm and view amm
moosecat2 ee40ac8
adjust test to work with new price bands
moosecat2 ddf3067
Revert "adjust test to work with new price bands"
moosecat2 607a687
remove price bands logic
moosecat2 c66099e
add zero ix for mm oracle for reset
moosecat2 4b5aa72
merge mm oracle refactor
moosecat2 a886a49
add new drift client ix grouping
moosecat2 4c36b9f
v1 safety improvements
moosecat2 406dc91
isolate funding from MM oracle
moosecat2 4a83337
add cargo tests for amm availability
moosecat2 9ba8217
change oracle validity log bool to enum
moosecat2 5588574
address comment
moosecat2 396cd47
make validate fill direction agnostic
moosecat2 de784dd
merge master
moosecat2 6158c74
fix liquidate borrow for perp pnl test
moosecat2 213d0f2
merge master
moosecat2 4105ecc
fix tests and address comments
moosecat2 ce3b2ef
Merge branch 'nour/safety-improvements' into bigz/init-lp-pool
moosecat2 04c1a3e
Merge branch 'nour/validate-fill-change' into bigz/init-lp-pool
moosecat2 8451b2d
merge in master
moosecat2 010e8a3
add RevenueShare and RevenueShareEscrow accounts an init ixs
wphan dfe4330
fix multiple array zc account, and handling different message types i…
wphan aa88106
decoding error
wphan 9af0257
merge master
moosecat2 cd716ea
commit constituent map to barrel file
moosecat2 df1f5d8
add lp fields to perp market account
moosecat2 6afc60c
recording orders in RevenueShareEscrow workin
wphan 9da4114
rearrange perp market struct for lp fields
moosecat2 e93bc21
cancel and fill orders
wphan 2e247b5
Merge remote-tracking branch 'origin/master' into wphan/builder_codes
wphan 35486e9
idl
wphan 35350ba
fix sdk build
wphan f0e06af
fix math
wphan a2ffde0
bug fix for notional position tracking
moosecat2 2ef60ce
update RevenueShareOrder bitflags, store builder_idx instead of pubkey
wphan fcd1c65
view function
moosecat2 57e335d
merge RevenueShareOrders on add
wphan 9070282
fee view functions
moosecat2 5ddfdf1
max aum + whitelist check and removing get_mint_redeem_fee for now
moosecat2 f2c9f22
add wsol support for add liquidity
moosecat2 6add765
fix sdk and typing bugs
moosecat2 101fd6e
update lp pool params ix
moosecat2 0a2171a
merge master
moosecat2 300e343
admin override cache and disable settle functions
moosecat2 b2fe670
remove builder accounts from cancel ixs, wip settle impl
wphan 7b688ad
dont fail settlpnl if no builder users provided
wphan abc450e
devnet swap working
moosecat2 d11de9e
finish settle, rename RevenueShare->Builder, RevenueShareEscrow->Buil…
wphan 464ff9b
add more bankrun tests, clean up
wphan 97ef7f7
Merge branch 'master' into wphan/builder_codes
wphan 8ffb821
clean up, fix tests
wphan 7971ab5
why test fail
wphan 6b5142a
dlp taker discovered bug fixes and sdk changes
moosecat2 28860b1
add subaccountid to BuilderOrder
wphan e4aafb0
reduce diff
wphan dca7093
refactor last settle ts to last settle slot
moosecat2 fabe2ff
add referrals
wphan 84e7c46
add test can fill settle user with no builderescrow
wphan 29fb679
add referral builder feature flag and referral migration method
wphan 8870bad
fix cargo tests, try fix bankrun test timing issue
wphan 3bf665d
Nour/settle pnl fix (#1817)
moosecat2 2540d55
add log msgs for withdraw and fix casting bug
moosecat2 9c37f89
Merge remote-tracking branch 'origin/master' into wphan/builder_codes
wphan 6069dd5
add SignedMsgOrderParamsMessageV2
wphan 55d866d
check in for z (#1823)
moosecat2 bcea62b
zero pad swift messages to make backwards compatible
wphan e44f43d
PR feedback
wphan 08b7432
add price for lp validates (#1833)
moosecat2 d6fa03f
update tests/placeAndMakeSignedMsgBankrun.ts to handle client side er…
wphan 15ef9e2
add missing token account reloads and syncs
moosecat2 86ba8dc
add disabled lp pool swaps by default
moosecat2 d9382a3
Merge pull request #1836 from drift-labs/nour/admin-can-disable-swap
moosecat2 f557fb4
refactor account logic for borrows
wphan 3932d27
remove double fee count, update tests to check filled position and qu…
wphan a2a16c2
more extensive aum logging
moosecat2 267c5e8
rename Builder -> RevenueShare
wphan 75b9654
Merge remote-tracking branch 'origin/master' into wphan/builder_codes
wphan 06c3909
add test check accumulated builder/ref fees
wphan 00dae75
fix settle multiple pnl accounts, test ref rewards in multiple markets
wphan 404dbbc
express builder fees in tenth of bps
wphan cd29a8c
update referral migration params
wphan 90cd0bb
PR feedback
wphan 254b9eb
add builder code feature gate
wphan 20d1a47
Merge remote-tracking branch 'origin/master' into wphan/builder_codes
wphan 1f17720
fix tests
wphan 142b10f
add referral fields
wphan 5365402
Merge branch 'wphan/builder_codes' into wphan/merge-builder-codes
wphan 57b0147
run all tests
wphan d3a7aad
kickoff build
wphan a4fe692
disable extra instructions, fix builder code feature flag selection
wphan 5db315b
update driftclient
wphan 415f247
Revert recent builder codes chain and merge (#1848)
wphan eb90de5
Merge branch 'master' into wphan/builder_codes
wphan e3db97b
clean up account inclusion rules in settle pnl for builder codes
wphan 76e2f2f
Merge branch 'master' into wphan/builder_codes
wphan cf07e05
Merge remote-tracking branch 'origin/master' into wphan/builder_codes
wphan 3dc10eb
cargo fmt
wphan cb96b3b
Merge remote-tracking branch 'origin/master' into wphan/builder_codes
wphan 0e9b82f
PR comments, featureflag clean up
wphan 413c87d
move authority check into get_revenue_share_escrow_account
wphan dd0a964
clean up referrer eligibility check, support placeAndTake/Make referr…
wphan b5746e4
skip builder fee accrual on full escrow account, dont throw
wphan 47887d2
Merge remote-tracking branch 'origin/master' into wphan/builder_codes
wphan 61f8f4f
add feature flag sdk fn
wphan e1dc1b0
program: builder codes dont throw tx on missing acc
wphan 7e1b469
placeAndMake respect builder codes
wphan f161577
ensure update userstats referrerstatus on migration
wphan 86ea2a3
hold back OrderActionRecord idl changes
wphan fa64671
update CHANGELOG.md
wphan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| use anchor_lang::prelude::*; | ||
|
|
||
| use crate::controller::spot_balance; | ||
| use crate::math::safe_math::SafeMath; | ||
| use crate::math::spot_balance::get_token_amount; | ||
| use crate::state::builder::{BuilderEscrowZeroCopyMut, BuilderOrder, BuilderOrderBitFlag}; | ||
| use crate::state::builder_map::BuilderMap; | ||
| use crate::state::events::BuilderSettleRecord; | ||
| use crate::state::perp_market_map::PerpMarketMap; | ||
| use crate::state::spot_market::SpotBalance; | ||
| use crate::state::spot_market_map::SpotMarketMap; | ||
| use crate::state::user::MarketType; | ||
|
|
||
| /// Runs through the user's BuilderEscrow account and sweeps any accrued fees to the corresponding | ||
| /// builders and referrer. | ||
| pub fn sweep_completed_builder_fees_for_market<'a>( | ||
| market_index: u16, | ||
| builder_escrow: &mut BuilderEscrowZeroCopyMut, | ||
| perp_market_map: &PerpMarketMap<'a>, | ||
| spot_market_map: &SpotMarketMap<'a>, | ||
| builder_map: BuilderMap<'a>, | ||
| now_ts: i64, | ||
| ) -> crate::error::DriftResult<()> { | ||
| let perp_market = &mut perp_market_map.get_ref_mut(&market_index)?; | ||
| let quote_spot_market = &mut spot_market_map.get_quote_spot_market_mut()?; | ||
|
|
||
| spot_balance::update_spot_market_cumulative_interest(quote_spot_market, None, now_ts)?; | ||
|
|
||
| let orders_len = builder_escrow.orders_len(); | ||
| for i in 0..orders_len { | ||
| let ( | ||
| is_completed, | ||
| is_referral_order, | ||
| order_market_type, | ||
| order_market_index, | ||
| fees_accrued, | ||
| builder_idx, | ||
| ) = { | ||
| let ord_ro = match builder_escrow.get_order(i) { | ||
| Ok(o) => o, | ||
| Err(_) => { | ||
| continue; | ||
| } | ||
| }; | ||
| ( | ||
| ord_ro.is_completed(), | ||
| ord_ro.is_referral_order(), | ||
| ord_ro.market_type, | ||
| ord_ro.market_index, | ||
| ord_ro.fees_accrued, | ||
| ord_ro.builder_idx, | ||
| ) | ||
| }; | ||
|
|
||
| if is_referral_order { | ||
| if fees_accrued == 0 { | ||
| continue; | ||
| } | ||
| } else if !(is_completed | ||
| && order_market_type == MarketType::Perp | ||
| && order_market_index == market_index | ||
| && fees_accrued > 0) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| let pnl_pool_token_amount = get_token_amount( | ||
| perp_market.pnl_pool.scaled_balance, | ||
| quote_spot_market, | ||
| perp_market.pnl_pool.balance_type(), | ||
| )?; | ||
|
|
||
| // TODO: should we add buffer on pnl pool? | ||
| if pnl_pool_token_amount < fees_accrued as u128 { | ||
| msg!( | ||
| "market {} PNL pool has insufficient balance to sweep fees for builder", | ||
| market_index | ||
| ); | ||
| break; | ||
| } | ||
|
|
||
| if is_referral_order { | ||
| let referrer_authority = if let Some(referrer_authority) = builder_escrow.get_referrer() | ||
| { | ||
| referrer_authority | ||
| } else { | ||
| continue; | ||
| }; | ||
|
|
||
| let referrer_user = builder_map.get_user_ref_mut(&referrer_authority); | ||
| let referrer_builder = builder_map.get_builder_account_mut(&referrer_authority); | ||
|
|
||
| if referrer_user.is_ok() && referrer_builder.is_ok() { | ||
| let mut referrer_user = referrer_user.unwrap(); | ||
| let mut referrer_builder = referrer_builder.unwrap(); | ||
|
|
||
| spot_balance::transfer_spot_balances( | ||
| fees_accrued as i128, | ||
| quote_spot_market, | ||
| &mut perp_market.pnl_pool, | ||
| referrer_user.get_quote_spot_position_mut(), | ||
| )?; | ||
|
|
||
| referrer_builder.total_referrer_rewards = referrer_builder | ||
| .total_referrer_rewards | ||
| .safe_add(fees_accrued as u64)?; | ||
|
|
||
| emit!(BuilderSettleRecord { | ||
wphan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ts: now_ts, | ||
| builder: None, | ||
| referrer: Some(referrer_authority), | ||
| fee_settled: fees_accrued as u64, | ||
| market_index: order_market_index, | ||
| market_type: order_market_type, | ||
| builder_total_referrer_rewards: referrer_builder.total_referrer_rewards, | ||
| builder_total_builder_rewards: referrer_builder.total_builder_rewards, | ||
| builder_sub_account_id: referrer_user.sub_account_id, | ||
| }); | ||
|
|
||
| // zero out the order | ||
| if let Ok(builder_order) = builder_escrow.get_order_mut(i) { | ||
| builder_order.fees_accrued = 0; | ||
| } | ||
| } | ||
| } else { | ||
| let builder_authority = match builder_escrow | ||
| .get_approved_builder_mut(builder_idx) | ||
| .map(|builder| builder.authority) | ||
| { | ||
| Ok(auth) => auth, | ||
| Err(_) => { | ||
| continue; | ||
| } | ||
| }; | ||
|
|
||
| let builder_user = builder_map.get_user_ref_mut(&builder_authority); | ||
| let builder = builder_map.get_builder_account_mut(&builder_authority); | ||
|
|
||
| if builder_user.is_ok() && builder.is_ok() { | ||
wphan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let mut builder_user = builder_user.unwrap(); | ||
| let mut builder_revenue_share = builder.unwrap(); | ||
|
|
||
| spot_balance::transfer_spot_balances( | ||
| fees_accrued as i128, | ||
| quote_spot_market, | ||
| &mut perp_market.pnl_pool, | ||
| builder_user.get_quote_spot_position_mut(), | ||
| )?; | ||
|
|
||
| builder_revenue_share.total_builder_rewards = builder_revenue_share | ||
| .total_builder_rewards | ||
| .safe_add(fees_accrued as u64)?; | ||
|
|
||
| emit!(BuilderSettleRecord { | ||
| ts: now_ts, | ||
| builder: Some(builder_authority), | ||
| referrer: None, | ||
| fee_settled: fees_accrued as u64, | ||
| market_index: order_market_index, | ||
| market_type: order_market_type, | ||
| builder_total_referrer_rewards: builder_revenue_share.total_referrer_rewards, | ||
| builder_total_builder_rewards: builder_revenue_share.total_builder_rewards, | ||
| builder_sub_account_id: builder_user.sub_account_id, | ||
| }); | ||
|
|
||
| // remove order | ||
| if let Ok(builder_order) = builder_escrow.get_order_mut(i) { | ||
| *builder_order = BuilderOrder::default(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| pub mod amm; | ||
| pub mod builder; | ||
| pub mod funding; | ||
| pub mod insurance; | ||
| pub mod liquidation; | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good q for @0xbigz