Skip to content
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

program: add fee adjustment to spot market #987

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### 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))
Expand Down
4 changes: 2 additions & 2 deletions programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4238,7 +4238,7 @@
false,
&None,
&MarketType::Spot,
0,
base_market.fee_adjustment,
)?;

// Update taker state
Expand Down Expand Up @@ -4528,7 +4528,7 @@
external_market_fee,
unsettled_referrer_rebate,
fee_pool_amount.cast()?,
0,
base_market.fee_adjustment,

Check warning on line 4531 in programs/drift/src/controller/orders.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/controller/orders.rs#L4531

Added line #L4531 was not covered by tests
)?;

let quote_spot_position_delta = match quote_update_direction {
Expand Down
25 changes: 24 additions & 1 deletion programs/drift/src/instructions/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@
total_spot_fee: 0,
orders_enabled: spot_market_index != 0,
paused_operations: 0,
padding1: [0; 5],
padding2: 0,
fee_adjustment: 0,
padding1: [0; 2],

Check warning on line 277 in programs/drift/src/instructions/admin.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/instructions/admin.rs#L277

Added line #L277 was not covered by tests
flash_loan_amount: 0,
flash_loan_initial_token_amount: 0,
total_swap_fee: 0,
Expand Down Expand Up @@ -2308,6 +2310,27 @@
Ok(())
}

#[access_control(

Check warning on line 2313 in programs/drift/src/instructions/admin.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/instructions/admin.rs#L2313

Added line #L2313 was not covered by tests
spot_market_valid(&ctx.accounts.spot_market)
)]
pub fn handle_update_spot_market_fee_adjustment(

Check warning on line 2316 in programs/drift/src/instructions/admin.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/instructions/admin.rs#L2316

Added line #L2316 was not covered by tests
ctx: Context<AdminUpdateSpotMarket>,
fee_adjustment: i16,
) -> Result<()> {
let spot = &mut load_mut!(ctx.accounts.spot_market)?;

Check warning on line 2320 in programs/drift/src/instructions/admin.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/instructions/admin.rs#L2320

Added line #L2320 was not covered by tests

validate!(
fee_adjustment.unsigned_abs().cast::<u64>()? <= FEE_ADJUSTMENT_MAX,
ErrorCode::DefaultError,

Check warning on line 2324 in programs/drift/src/instructions/admin.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/instructions/admin.rs#L2322-L2324

Added lines #L2322 - L2324 were not covered by tests
"fee adjustment {} greater than max {}",
fee_adjustment,
FEE_ADJUSTMENT_MAX
)?;

spot.fee_adjustment = fee_adjustment;
Ok(())

Check warning on line 2331 in programs/drift/src/instructions/admin.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/instructions/admin.rs#L2330-L2331

Added lines #L2330 - L2331 were not covered by tests
}

pub fn handle_update_admin(ctx: Context<AdminUpdateState>, admin: Pubkey) -> Result<()> {
ctx.accounts.state.admin = admin;
Ok(())
Expand Down
7 changes: 7 additions & 0 deletions programs/drift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,13 @@
handle_update_perp_market_fee_adjustment(ctx, fee_adjustment)
}

pub fn update_spot_market_fee_adjustment(

Check warning on line 1138 in programs/drift/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/lib.rs#L1138

Added line #L1138 was not covered by tests
ctx: Context<AdminUpdateSpotMarket>,
fee_adjustment: i16,
) -> Result<()> {
handle_update_spot_market_fee_adjustment(ctx, fee_adjustment)

Check warning on line 1142 in programs/drift/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/lib.rs#L1142

Added line #L1142 was not covered by tests
}

pub fn update_admin(ctx: Context<AdminUpdateState>, admin: Pubkey) -> Result<()> {
handle_update_admin(ctx, admin)
}
Expand Down
8 changes: 6 additions & 2 deletions programs/drift/src/state/spot_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ pub struct SpotMarket {
/// The asset tier affects how a deposit can be used as collateral and the priority for a borrow being liquidated
pub asset_tier: AssetTier,
pub paused_operations: u8,
pub padding1: [u8; 5],
pub padding2: u8,
pub fee_adjustment: i16,
pub padding1: [u8; 2],
/// For swaps, the amount of token loaned out in the begin_swap ix
/// precision: token mint precision
pub flash_loan_amount: u64,
Expand Down Expand Up @@ -230,7 +232,9 @@ impl Default for SpotMarket {
status: MarketStatus::default(),
asset_tier: AssetTier::default(),
paused_operations: 0,
padding1: [0; 5],
padding2: 0,
fee_adjustment: 0,
padding1: [0; 2],
flash_loan_amount: 0,
flash_loan_initial_token_amount: 0,
total_swap_fee: 0,
Expand Down
38 changes: 38 additions & 0 deletions sdk/src/adminClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2943,6 +2943,44 @@ export class AdminClient extends DriftClient {
);
}

public async updateSpotMarketFeeAdjustment(
perpMarketIndex: number,
feeAdjustment: number
): Promise<TransactionSignature> {
const updateSpotMarketFeeAdjustmentIx =
await this.getUpdateSpotMarketFeeAdjustmentIx(
perpMarketIndex,
feeAdjustment
);

const tx = await this.buildTransaction(updateSpotMarketFeeAdjustmentIx);

const { txSig } = await this.sendTransaction(tx, [], this.opts);

return txSig;
}

public async getUpdateSpotMarketFeeAdjustmentIx(
spotMarketIndex: number,
feeAdjustment: number
): Promise<TransactionInstruction> {
return await this.program.instruction.updateSpotMarketFeeAdjustment(
feeAdjustment,
{
accounts: {
admin: this.isSubscribed
? this.getStateAccount().admin
: this.wallet.publicKey,
state: await this.getStatePublicKey(),
spotMarket: await getSpotMarketPublicKey(
this.program.programId,
spotMarketIndex
),
},
}
);
}

public async updateSerumVault(
srmVault: PublicKey
): Promise<TransactionSignature> {
Expand Down
36 changes: 35 additions & 1 deletion sdk/src/idl/drift.json
Original file line number Diff line number Diff line change
Expand Up @@ -4784,6 +4784,32 @@
}
]
},
{
"name": "updateSpotMarketFeeAdjustment",
"accounts": [
{
"name": "admin",
"isMut": false,
"isSigner": true
},
{
"name": "state",
"isMut": false,
"isSigner": false
},
{
"name": "spotMarket",
"isMut": true,
"isSigner": false
}
],
"args": [
{
"name": "feeAdjustment",
"type": "i16"
}
]
},
{
"name": "updateAdmin",
"accounts": [
Expand Down Expand Up @@ -6030,12 +6056,20 @@
"name": "pausedOperations",
"type": "u8"
},
{
"name": "padding2",
"type": "u8"
},
{
"name": "feeAdjustment",
"type": "i16"
},
{
"name": "padding1",
"type": {
"array": [
"u8",
5
2
]
}
},
Expand Down
Loading