Skip to content

Commit

Permalink
use the fee tier from the fetched discount key
Browse files Browse the repository at this point in the history
  • Loading branch information
Taylor123 authored and tomjohn1028 committed Jul 9, 2021
1 parent 69f969c commit f8aca90
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/serum/src/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from '@solana/web3.js';
import { decodeEventQueue, decodeRequestQueue } from './queue';
import { Buffer } from 'buffer';
import { getFeeTier, supportsSrmFeeDiscounts } from './fees';
import { getFeeRates, getFeeTier, supportsSrmFeeDiscounts } from './fees';
import {
closeAccount,
initializeAccount,
Expand Down Expand Up @@ -567,21 +567,23 @@ export class Market {
const transaction = new Transaction();
const signers: Account[] = [];

// Fetch an SRM fee discount key if the market supports discounts and it is not supplied
// Fetch an SRM fee discount key and rate if the market supports discounts and it is not supplied
let possibleFeeRate = feeRate;
let useFeeDiscountPubkey: PublicKey | null;
if (feeDiscountPubkey) {
useFeeDiscountPubkey = feeDiscountPubkey;
} else if (
feeDiscountPubkey === undefined &&
this.supportsSrmFeeDiscounts
) {
useFeeDiscountPubkey = (
await this.findBestFeeDiscountKey(
connection,
ownerAddress,
feeDiscountPubkeyCacheDurationMs,
)
).pubkey;
const bestFeeDiscount = await this.findBestFeeDiscountKey(
connection,
ownerAddress,
feeDiscountPubkeyCacheDurationMs,
);
useFeeDiscountPubkey = bestFeeDiscount.pubkey;
const { taker } = getFeeRates(bestFeeDiscount.feeTier);
possibleFeeRate = orderType === 'postOnly' ? 0 : taker;
} else {
useFeeDiscountPubkey = null;
}
Expand Down Expand Up @@ -667,7 +669,7 @@ export class Market {
clientId,
openOrdersAddressKey: openOrdersAddress,
feeDiscountPubkey: useFeeDiscountPubkey,
feeRate,
feeRate: possibleFeeRate,
selfTradeBehavior,
});
transaction.add(placeOrderInstruction);
Expand Down

0 comments on commit f8aca90

Please sign in to comment.