diff --git a/sdk/bun.lockb b/sdk/bun.lockb index 05307cc68..ee9965d3c 100755 Binary files a/sdk/bun.lockb and b/sdk/bun.lockb differ diff --git a/sdk/src/dlob/DLOB.ts b/sdk/src/dlob/DLOB.ts index 6333a99b4..79df87b91 100644 --- a/sdk/src/dlob/DLOB.ts +++ b/sdk/src/dlob/DLOB.ts @@ -157,9 +157,10 @@ export class DLOB { for (const user of userMap.values()) { const userAccount = user.getUserAccount(); const userAccountPubkey = user.getUserAccountPublicKey(); + const userAccountPubkeyString = userAccountPubkey.toString(); for (const order of userAccount.orders) { - this.insertOrder(order, userAccountPubkey, slot); + this.insertOrder(order, userAccountPubkeyString, slot); } } @@ -173,7 +174,7 @@ export class DLOB { } for (const { user, order } of dlobOrders) { - this.insertOrder(order, user, slot); + this.insertOrder(order, user.toString(), slot); } this.initialized = true; @@ -181,7 +182,7 @@ export class DLOB { } public handleOrderRecord(record: OrderRecord, slot: number): void { - this.insertOrder(record.order, record.user, slot); + this.insertOrder(record.order, record.user.toString(), slot); } public handleOrderActionRecord( @@ -249,7 +250,7 @@ export class DLOB { public insertOrder( order: Order, - userAccount: PublicKey, + userAccount: string, slot: number, onInsert?: OrderBookCallback ): void { @@ -327,7 +328,7 @@ export class DLOB { }; newOrder.baseAssetAmountFilled = cumulativeBaseAssetAmountFilled; - this.getListForOrder(order, slot)?.update(newOrder, userAccount); + this.getListForOrder(order, slot)?.update(newOrder, userAccount.toString()); if (onUpdate) { onUpdate(); @@ -354,9 +355,13 @@ export class DLOB { const triggerList = this.orderLists.get(marketType).get(order.marketIndex) .trigger[isVariant(order.triggerCondition, 'above') ? 'above' : 'below']; - triggerList.remove(order, userAccount); + triggerList.remove(order, userAccount.toString()); - this.getListForOrder(order, slot)?.insert(order, marketType, userAccount); + this.getListForOrder(order, slot)?.insert( + order, + marketType, + userAccount.toString() + ); if (onTrigger) { onTrigger(); } @@ -374,7 +379,7 @@ export class DLOB { this.updateRestingLimitOrders(slot); - this.getListForOrder(order, slot)?.remove(order, userAccount); + this.getListForOrder(order, slot)?.remove(order, userAccount.toString()); if (onDelete) { onDelete(); } @@ -472,7 +477,7 @@ export class DLOB { } public getOrder(orderId: number, userAccount: PublicKey): Order | undefined { - const orderSignature = getOrderSignature(orderId, userAccount); + const orderSignature = getOrderSignature(orderId, userAccount.toString()); for (const nodeList of this.getNodeLists()) { const node = nodeList.get(orderSignature); if (node) { @@ -852,7 +857,7 @@ export class DLOB { for (const makerNode of makerNodeGenerator) { // Can't match orders from the same user - const sameUser = takerNode.userAccount.equals(makerNode.userAccount); + const sameUser = takerNode.userAccount === makerNode.userAccount; if (sameUser) { continue; } @@ -1377,7 +1382,7 @@ export class DLOB { const askOrder = askNode.order; // Can't match orders from the same user - const sameUser = bidNode.userAccount.equals(askNode.userAccount); + const sameUser = bidNode.userAccount === askNode.userAccount; if (sameUser) { continue; } @@ -1760,7 +1765,7 @@ export class DLOB { for (const nodeList of this.getNodeLists()) { for (const node of nodeList.getGenerator()) { dlobOrders.push({ - user: node.userAccount, + user: new PublicKey(node.userAccount), order: node.order, }); } @@ -1902,7 +1907,7 @@ export class DLOB { asks.push({ price: ask.getPrice(oraclePriceData, slot), size: ask.order.baseAssetAmount.sub(ask.order.baseAssetAmountFilled), - maker: ask.userAccount, + maker: new PublicKey(ask.userAccount), orderId: ask.order.orderId, }); } @@ -1918,7 +1923,7 @@ export class DLOB { bids.push({ price: bid.getPrice(oraclePriceData, slot), size: bid.order.baseAssetAmount.sub(bid.order.baseAssetAmountFilled), - maker: bid.userAccount, + maker: new PublicKey(bid.userAccount), orderId: bid.order.orderId, }); } @@ -2028,7 +2033,10 @@ export class DLOB { for (const node of generator) { if (!makers.has(node.userAccount.toString())) { - makers.set(node.userAccount.toString(), node.userAccount); + makers.set( + node.userAccount.toString(), + new PublicKey(node.userAccount) + ); } if (makers.size === numMakers) { diff --git a/sdk/src/dlob/DLOBNode.ts b/sdk/src/dlob/DLOBNode.ts index b6dcf245d..bab644acb 100644 --- a/sdk/src/dlob/DLOBNode.ts +++ b/sdk/src/dlob/DLOBNode.ts @@ -9,7 +9,7 @@ import { Order, ZERO, } from '..'; -import { PublicKey } from '@solana/web3.js'; +// import { PublicKey } from '@solana/web3.js'; import { getOrderSignature } from './NodeList'; export interface DLOBNode { @@ -18,17 +18,17 @@ export interface DLOBNode { order: Order | undefined; isBaseFilled(): boolean; haveFilled: boolean; - userAccount: PublicKey | undefined; + userAccount: string | undefined; } export abstract class OrderNode implements DLOBNode { order: Order; - userAccount: PublicKey; + userAccount: string; sortValue: BN; haveFilled = false; haveTrigger = false; - constructor(order: Order, userAccount: PublicKey) { + constructor(order: Order, userAccount: string) { // Copy the order over to the node this.order = { ...order }; this.userAccount = userAccount; @@ -140,7 +140,7 @@ export type DLOBNodeType = export function createNode( nodeType: T, order: Order, - userAccount: PublicKey + userAccount: string ): DLOBNodeMap[T] { switch (nodeType) { case 'floatingLimit': diff --git a/sdk/src/dlob/NodeList.ts b/sdk/src/dlob/NodeList.ts index a113bd42f..7add26756 100644 --- a/sdk/src/dlob/NodeList.ts +++ b/sdk/src/dlob/NodeList.ts @@ -1,12 +1,12 @@ import { BN, isVariant, MarketTypeStr, Order } from '..'; -import { PublicKey } from '@solana/web3.js'; +// import { PublicKey } from '@solana/web3.js'; import { createNode, DLOBNode, DLOBNodeMap } from './DLOBNode'; export type SortDirection = 'asc' | 'desc'; export function getOrderSignature( orderId: number, - userAccount: PublicKey + userAccount: string ): string { return `${userAccount.toString()}-${orderId.toString()}`; } @@ -36,7 +36,7 @@ export class NodeList public insert( order: Order, marketType: MarketTypeStr, - userAccount: PublicKey + userAccount: string ): void { if (isVariant(order.status, 'init')) { return; @@ -101,7 +101,7 @@ export class NodeList } } - public update(order: Order, userAccount: PublicKey): void { + public update(order: Order, userAccount: string): void { const orderId = getOrderSignature(order.orderId, userAccount); if (this.nodeMap.has(orderId)) { const node = this.nodeMap.get(orderId); @@ -110,7 +110,7 @@ export class NodeList } } - public remove(order: Order, userAccount: PublicKey): void { + public remove(order: Order, userAccount: string): void { const orderId = getOrderSignature(order.orderId, userAccount); if (this.nodeMap.has(orderId)) { const node = this.nodeMap.get(orderId); @@ -142,7 +142,7 @@ export class NodeList } } - public has(order: Order, userAccount: PublicKey): boolean { + public has(order: Order, userAccount: string): boolean { return this.nodeMap.has(getOrderSignature(order.orderId, userAccount)); } diff --git a/sdk/src/orderSubscriber/OrderSubscriber.ts b/sdk/src/orderSubscriber/OrderSubscriber.ts index 982346fcf..e8ad166c3 100644 --- a/sdk/src/orderSubscriber/OrderSubscriber.ts +++ b/sdk/src/orderSubscriber/OrderSubscriber.ts @@ -200,9 +200,8 @@ export class OrderSubscriber { public async getDLOB(slot: number): Promise { const dlob = new DLOB(); for (const [key, { userAccount }] of this.usersAccounts.entries()) { - const userAccountPubkey = new PublicKey(key); for (const order of userAccount.orders) { - dlob.insertOrder(order, userAccountPubkey, slot); + dlob.insertOrder(order, key, slot); } } return dlob; diff --git a/sdk/src/phoenix/phoenixFulfillmentConfigMap.ts b/sdk/src/phoenix/phoenixFulfillmentConfigMap.ts index 0708cc196..34b8540f9 100644 --- a/sdk/src/phoenix/phoenixFulfillmentConfigMap.ts +++ b/sdk/src/phoenix/phoenixFulfillmentConfigMap.ts @@ -14,9 +14,10 @@ export class PhoenixFulfillmentConfigMap { marketIndex: number, phoenixMarketAddress: PublicKey ): Promise { - const account = await this.driftClient.getPhoenixV1FulfillmentConfig( - phoenixMarketAddress - ); + const account = + await this.driftClient.getPhoenixV1FulfillmentConfig( + phoenixMarketAddress + ); this.map.set(marketIndex, account); } diff --git a/sdk/src/serum/serumFulfillmentConfigMap.ts b/sdk/src/serum/serumFulfillmentConfigMap.ts index 4d57f40a2..23b3562a1 100644 --- a/sdk/src/serum/serumFulfillmentConfigMap.ts +++ b/sdk/src/serum/serumFulfillmentConfigMap.ts @@ -14,9 +14,8 @@ export class SerumFulfillmentConfigMap { marketIndex: number, serumMarketAddress: PublicKey ): Promise { - const account = await this.driftClient.getSerumV3FulfillmentConfig( - serumMarketAddress - ); + const account = + await this.driftClient.getSerumV3FulfillmentConfig(serumMarketAddress); this.map.set(marketIndex, account); } diff --git a/sdk/tests/dlob/test.ts b/sdk/tests/dlob/test.ts index 9a7271518..541d3fdcc 100644 --- a/sdk/tests/dlob/test.ts +++ b/sdk/tests/dlob/test.ts @@ -6073,41 +6073,40 @@ describe('DLOB Spot Tests', () => { }); describe('Uncross L2', () => { - it('Bid crosses ask above oracle (no premium)', () => { const bids = [ { price: new BN(104).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(103).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(102).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"dlob": new BN(1).mul(BASE_PRECISION)} + sources: { dlob: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(100).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} - } + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, + }, ]; const asks = [ { price: new BN(101).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)}, + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(102).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)}, + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, ]; @@ -6117,24 +6116,59 @@ describe('Uncross L2', () => { const groupingSize = QUOTE_PRECISION.divn(10); - const { bids: newBids, asks: newAsks } = uncrossL2(bids, asks, oraclePrice, oraclePrice5Min, markPrice5Min, groupingSize, new Set(), new Set()); + const { bids: newBids, asks: newAsks } = uncrossL2( + bids, + asks, + oraclePrice, + oraclePrice5Min, + markPrice5Min, + groupingSize, + new Set(), + new Set() + ); - expect(newBids[0].price.toString()).to.equal(new BN(101).mul(QUOTE_PRECISION).sub(groupingSize).toString()); - expect(newBids[0].size.toString()).to.equal(new BN(3).mul(BASE_PRECISION).toString()); - expect(newBids[0].sources["vamm"].toString()).to.equal(new BN(2).mul(BASE_PRECISION).toString()); - expect(newBids[0].sources["dlob"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newBids[0].price.toString()).to.equal( + new BN(101).mul(QUOTE_PRECISION).sub(groupingSize).toString() + ); + expect(newBids[0].size.toString()).to.equal( + new BN(3).mul(BASE_PRECISION).toString() + ); + expect(newBids[0].sources['vamm'].toString()).to.equal( + new BN(2).mul(BASE_PRECISION).toString() + ); + expect(newBids[0].sources['dlob'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newBids[1].price.toString()).to.equal(new BN(100).mul(QUOTE_PRECISION).toString()); - expect(newBids[1].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newBids[1].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newBids[1].price.toString()).to.equal( + new BN(100).mul(QUOTE_PRECISION).toString() + ); + expect(newBids[1].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newBids[1].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newAsks[0].price.toString()).to.equal(new BN(101).mul(QUOTE_PRECISION).toString()); - expect(newAsks[0].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newAsks[0].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newAsks[0].price.toString()).to.equal( + new BN(101).mul(QUOTE_PRECISION).toString() + ); + expect(newAsks[0].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newAsks[0].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newAsks[1].price.toString()).to.equal(new BN(102).mul(QUOTE_PRECISION).toString()); - expect(newAsks[1].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newAsks[1].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newAsks[1].price.toString()).to.equal( + new BN(102).mul(QUOTE_PRECISION).toString() + ); + expect(newAsks[1].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newAsks[1].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); }); it('Ask crosses ask below oracle, (new premium)', () => { @@ -6142,12 +6176,12 @@ describe('Uncross L2', () => { { price: new BN(99).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(98).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, ]; @@ -6155,23 +6189,23 @@ describe('Uncross L2', () => { { price: new BN(96).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(97).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(98).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"dlob": new BN(1).mul(BASE_PRECISION)} + sources: { dlob: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(100).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} - } + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, + }, ]; const oraclePrice = new BN(100).mul(QUOTE_PRECISION); @@ -6180,24 +6214,59 @@ describe('Uncross L2', () => { const groupingSize = QUOTE_PRECISION.divn(10); - const { bids: newBids, asks: newAsks } = uncrossL2(bids, asks, oraclePrice, oraclePrice5Min, markPrice5Min, groupingSize, new Set(), new Set()); + const { bids: newBids, asks: newAsks } = uncrossL2( + bids, + asks, + oraclePrice, + oraclePrice5Min, + markPrice5Min, + groupingSize, + new Set(), + new Set() + ); - expect(newBids[0].price.toString()).to.equal(new BN(99).mul(QUOTE_PRECISION).toString()); - expect(newBids[0].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newBids[0].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newBids[0].price.toString()).to.equal( + new BN(99).mul(QUOTE_PRECISION).toString() + ); + expect(newBids[0].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newBids[0].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newBids[1].price.toString()).to.equal(new BN(98).mul(QUOTE_PRECISION).toString()); - expect(newBids[1].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newBids[1].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newBids[1].price.toString()).to.equal( + new BN(98).mul(QUOTE_PRECISION).toString() + ); + expect(newBids[1].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newBids[1].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newAsks[0].price.toString()).to.equal(new BN(99).mul(QUOTE_PRECISION).add(groupingSize).toString()); - expect(newAsks[0].size.toString()).to.equal(new BN(3).mul(BASE_PRECISION).toString()); - expect(newAsks[0].sources["vamm"].toString()).to.equal(new BN(2).mul(BASE_PRECISION).toString()); - expect(newAsks[0].sources["dlob"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newAsks[0].price.toString()).to.equal( + new BN(99).mul(QUOTE_PRECISION).add(groupingSize).toString() + ); + expect(newAsks[0].size.toString()).to.equal( + new BN(3).mul(BASE_PRECISION).toString() + ); + expect(newAsks[0].sources['vamm'].toString()).to.equal( + new BN(2).mul(BASE_PRECISION).toString() + ); + expect(newAsks[0].sources['dlob'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newAsks[1].price.toString()).to.equal(new BN(100).mul(QUOTE_PRECISION).toString()); - expect(newAsks[1].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newAsks[1].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newAsks[1].price.toString()).to.equal( + new BN(100).mul(QUOTE_PRECISION).toString() + ); + expect(newAsks[1].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newAsks[1].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); }); it('No cross (no premium)', () => { @@ -6205,17 +6274,17 @@ describe('Uncross L2', () => { { price: new BN(99).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(98).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(97).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, ]; @@ -6223,12 +6292,12 @@ describe('Uncross L2', () => { { price: new BN(101).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(102).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, ]; @@ -6238,27 +6307,66 @@ describe('Uncross L2', () => { const groupingSize = QUOTE_PRECISION.divn(10); - const { bids: newBids, asks: newAsks } = uncrossL2(bids, asks, oraclePrice, oraclePrice5Min, markPrice5Min, groupingSize, new Set(), new Set()); + const { bids: newBids, asks: newAsks } = uncrossL2( + bids, + asks, + oraclePrice, + oraclePrice5Min, + markPrice5Min, + groupingSize, + new Set(), + new Set() + ); - expect(newBids[0].price.toString()).to.equal(new BN(99).mul(QUOTE_PRECISION).toString()); - expect(newBids[0].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newBids[0].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newBids[0].price.toString()).to.equal( + new BN(99).mul(QUOTE_PRECISION).toString() + ); + expect(newBids[0].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newBids[0].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newBids[1].price.toString()).to.equal(new BN(98).mul(QUOTE_PRECISION).toString()); - expect(newBids[1].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newBids[1].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newBids[1].price.toString()).to.equal( + new BN(98).mul(QUOTE_PRECISION).toString() + ); + expect(newBids[1].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newBids[1].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newBids[2].price.toString()).to.equal(new BN(97).mul(QUOTE_PRECISION).toString()); - expect(newBids[2].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newBids[2].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newBids[2].price.toString()).to.equal( + new BN(97).mul(QUOTE_PRECISION).toString() + ); + expect(newBids[2].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newBids[2].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newAsks[0].price.toString()).to.equal(new BN(101).mul(QUOTE_PRECISION).toString()); - expect(newAsks[0].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newAsks[0].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newAsks[0].price.toString()).to.equal( + new BN(101).mul(QUOTE_PRECISION).toString() + ); + expect(newAsks[0].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newAsks[0].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newAsks[1].price.toString()).to.equal(new BN(102).mul(QUOTE_PRECISION).toString()); - expect(newAsks[1].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newAsks[1].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newAsks[1].price.toString()).to.equal( + new BN(102).mul(QUOTE_PRECISION).toString() + ); + expect(newAsks[1].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newAsks[1].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); }); it('Crossed on opposite sides of reference price', () => { @@ -6266,7 +6374,7 @@ describe('Uncross L2', () => { { price: new BN(32).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"dlob": new BN(1).mul(BASE_PRECISION)} + sources: { dlob: new BN(1).mul(BASE_PRECISION) }, }, ]; @@ -6274,27 +6382,48 @@ describe('Uncross L2', () => { { price: new BN(29).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, ]; - const oraclePrice = new BN("29250100"); - const oraclePrice5Min = new BN("29696597"); - const markPrice5Min = new BN("31747865"); + const oraclePrice = new BN('29250100'); + const oraclePrice5Min = new BN('29696597'); + const markPrice5Min = new BN('31747865'); const groupingSize = QUOTE_PRECISION.divn(10); - const { bids: newBids, asks: newAsks } = uncrossL2(bids, asks, oraclePrice, oraclePrice5Min, markPrice5Min, groupingSize, new Set(), new Set()); + const { bids: newBids, asks: newAsks } = uncrossL2( + bids, + asks, + oraclePrice, + oraclePrice5Min, + markPrice5Min, + groupingSize, + new Set(), + new Set() + ); const referencePrice = oraclePrice.add(markPrice5Min.sub(oraclePrice5Min)); - expect(newBids[0].price.toString()).to.equal(referencePrice.sub(groupingSize).toString()); - expect(newBids[0].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newBids[0].sources["dlob"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newBids[0].price.toString()).to.equal( + referencePrice.sub(groupingSize).toString() + ); + expect(newBids[0].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newBids[0].sources['dlob'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newAsks[0].price.toString()).to.equal(referencePrice.add(groupingSize).toString()); - expect(newAsks[0].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newAsks[0].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newAsks[0].price.toString()).to.equal( + referencePrice.add(groupingSize).toString() + ); + expect(newAsks[0].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newAsks[0].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); }); it('Skip user with bid', () => { @@ -6302,35 +6431,35 @@ describe('Uncross L2', () => { { price: new BN(104).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"dlob": new BN(1).mul(BASE_PRECISION)} + sources: { dlob: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(103).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(102).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"dlob": new BN(1).mul(BASE_PRECISION)} + sources: { dlob: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(100).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} - } + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, + }, ]; const asks = [ { price: new BN(101).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)}, + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(102).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)}, + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, ]; @@ -6340,29 +6469,72 @@ describe('Uncross L2', () => { const groupingSize = QUOTE_PRECISION.divn(10); - const userBids = new Set([new BN(104).mul(QUOTE_PRECISION).toString()]); - const { bids: newBids, asks: newAsks } = uncrossL2(bids, asks, oraclePrice, oraclePrice5Min, markPrice5Min, groupingSize, userBids, new Set()); + const userBids = new Set([ + new BN(104).mul(QUOTE_PRECISION).toString(), + ]); + const { bids: newBids, asks: newAsks } = uncrossL2( + bids, + asks, + oraclePrice, + oraclePrice5Min, + markPrice5Min, + groupingSize, + userBids, + new Set() + ); - expect(newBids[0].price.toString()).to.equal(new BN(104).mul(QUOTE_PRECISION).toString()); - expect(newBids[0].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newBids[0].sources["dlob"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newBids[0].price.toString()).to.equal( + new BN(104).mul(QUOTE_PRECISION).toString() + ); + expect(newBids[0].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newBids[0].sources['dlob'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newBids[1].price.toString()).to.equal(new BN(101).mul(QUOTE_PRECISION).sub(groupingSize).toString()); - expect(newBids[1].size.toString()).to.equal(new BN(2).mul(BASE_PRECISION).toString()); - expect(newBids[1].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newBids[1].sources["dlob"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newBids[1].price.toString()).to.equal( + new BN(101).mul(QUOTE_PRECISION).sub(groupingSize).toString() + ); + expect(newBids[1].size.toString()).to.equal( + new BN(2).mul(BASE_PRECISION).toString() + ); + expect(newBids[1].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newBids[1].sources['dlob'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newBids[2].price.toString()).to.equal(new BN(100).mul(QUOTE_PRECISION).toString()); - expect(newBids[2].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newBids[2].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newBids[2].price.toString()).to.equal( + new BN(100).mul(QUOTE_PRECISION).toString() + ); + expect(newBids[2].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newBids[2].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newAsks[0].price.toString()).to.equal(new BN(101).mul(QUOTE_PRECISION).toString()); - expect(newAsks[0].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newAsks[0].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newAsks[0].price.toString()).to.equal( + new BN(101).mul(QUOTE_PRECISION).toString() + ); + expect(newAsks[0].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newAsks[0].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newAsks[1].price.toString()).to.equal(new BN(102).mul(QUOTE_PRECISION).toString()); - expect(newAsks[1].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newAsks[1].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newAsks[1].price.toString()).to.equal( + new BN(102).mul(QUOTE_PRECISION).toString() + ); + expect(newAsks[1].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newAsks[1].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); }); it('Skip user with ask', () => { @@ -6370,12 +6542,12 @@ describe('Uncross L2', () => { { price: new BN(99).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(98).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, ]; @@ -6383,23 +6555,23 @@ describe('Uncross L2', () => { { price: new BN(96).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"dlob": new BN(1).mul(BASE_PRECISION)} + sources: { dlob: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(97).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(98).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"dlob": new BN(1).mul(BASE_PRECISION)} + sources: { dlob: new BN(1).mul(BASE_PRECISION) }, }, { price: new BN(100).mul(QUOTE_PRECISION), size: new BN(1).mul(BASE_PRECISION), - sources: {"vamm": new BN(1).mul(BASE_PRECISION)} - } + sources: { vamm: new BN(1).mul(BASE_PRECISION) }, + }, ]; const oraclePrice = new BN(100).mul(QUOTE_PRECISION); @@ -6408,28 +6580,71 @@ describe('Uncross L2', () => { const groupingSize = QUOTE_PRECISION.divn(10); - const userAsks = new Set([new BN(96).mul(QUOTE_PRECISION).toString()]); - const { bids: newBids, asks: newAsks } = uncrossL2(bids, asks, oraclePrice, oraclePrice5Min, markPrice5Min, groupingSize, new Set(), userAsks); + const userAsks = new Set([ + new BN(96).mul(QUOTE_PRECISION).toString(), + ]); + const { bids: newBids, asks: newAsks } = uncrossL2( + bids, + asks, + oraclePrice, + oraclePrice5Min, + markPrice5Min, + groupingSize, + new Set(), + userAsks + ); - expect(newBids[0].price.toString()).to.equal(new BN(99).mul(QUOTE_PRECISION).toString()); - expect(newBids[0].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newBids[0].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newBids[0].price.toString()).to.equal( + new BN(99).mul(QUOTE_PRECISION).toString() + ); + expect(newBids[0].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newBids[0].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newBids[1].price.toString()).to.equal(new BN(98).mul(QUOTE_PRECISION).toString()); - expect(newBids[1].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newBids[1].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newBids[1].price.toString()).to.equal( + new BN(98).mul(QUOTE_PRECISION).toString() + ); + expect(newBids[1].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newBids[1].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newAsks[0].price.toString()).to.equal(new BN(96).mul(QUOTE_PRECISION).toString()); - expect(newAsks[0].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newAsks[0].sources["dlob"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newAsks[0].price.toString()).to.equal( + new BN(96).mul(QUOTE_PRECISION).toString() + ); + expect(newAsks[0].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newAsks[0].sources['dlob'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newAsks[1].price.toString()).to.equal(new BN(99).mul(QUOTE_PRECISION).add(groupingSize).toString()); - expect(newAsks[1].size.toString()).to.equal(new BN(2).mul(BASE_PRECISION).toString()); - expect(newAsks[1].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newAsks[1].sources["dlob"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newAsks[1].price.toString()).to.equal( + new BN(99).mul(QUOTE_PRECISION).add(groupingSize).toString() + ); + expect(newAsks[1].size.toString()).to.equal( + new BN(2).mul(BASE_PRECISION).toString() + ); + expect(newAsks[1].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newAsks[1].sources['dlob'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); - expect(newAsks[2].price.toString()).to.equal(new BN(100).mul(QUOTE_PRECISION).toString()); - expect(newAsks[2].size.toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); - expect(newAsks[2].sources["vamm"].toString()).to.equal(new BN(1).mul(BASE_PRECISION).toString()); + expect(newAsks[2].price.toString()).to.equal( + new BN(100).mul(QUOTE_PRECISION).toString() + ); + expect(newAsks[2].size.toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); + expect(newAsks[2].sources['vamm'].toString()).to.equal( + new BN(1).mul(BASE_PRECISION).toString() + ); }); }); diff --git a/sdk/tests/tx/priorityFeeStrategy.ts b/sdk/tests/tx/priorityFeeStrategy.ts index 087b0d41b..f4b21d554 100644 --- a/sdk/tests/tx/priorityFeeStrategy.ts +++ b/sdk/tests/tx/priorityFeeStrategy.ts @@ -6,92 +6,90 @@ import { MaxOverSlotsStrategy } from '../../src/priorityFee/maxOverSlotsStrategy import { AverageOverSlotsStrategy } from '../../src/priorityFee/averageOverSlotsStrategy'; describe('PriorityFeeStrategy', () => { - it('AverageStrategy should calculate the average prioritization fee', () => { - const averageStrategy = new AverageStrategy(); - const samples = [ - { slot: 3, prioritizationFee: 300 }, - { slot: 2, prioritizationFee: 200 }, - { slot: 1, prioritizationFee: 100 }, - ]; - const average = averageStrategy.calculate(samples); - expect(average).to.equal(200); - }); + it('AverageStrategy should calculate the average prioritization fee', () => { + const averageStrategy = new AverageStrategy(); + const samples = [ + { slot: 3, prioritizationFee: 300 }, + { slot: 2, prioritizationFee: 200 }, + { slot: 1, prioritizationFee: 100 }, + ]; + const average = averageStrategy.calculate(samples); + expect(average).to.equal(200); + }); - it('MaxStrategy should calculate the maximum prioritization fee', () => { - const maxStrategy = new MaxStrategy(); - const samples = [ - { slot: 3, prioritizationFee: 300 }, - { slot: 2, prioritizationFee: 200 }, - { slot: 1, prioritizationFee: 100 }, - ]; - const max = maxStrategy.calculate(samples); - expect(max).to.equal(300); - }); + it('MaxStrategy should calculate the maximum prioritization fee', () => { + const maxStrategy = new MaxStrategy(); + const samples = [ + { slot: 3, prioritizationFee: 300 }, + { slot: 2, prioritizationFee: 200 }, + { slot: 1, prioritizationFee: 100 }, + ]; + const max = maxStrategy.calculate(samples); + expect(max).to.equal(300); + }); - it('EwmaStrategy should calculate the ewma prioritization fee', () => { - // halflife of 5 alots - const ewmaStrategy = new EwmaStrategy(5); - const samples = [ - { slot: 6, prioritizationFee: 0 }, - { slot: 2, prioritizationFee: 0 }, - { slot: 2, prioritizationFee: 0 }, - { slot: 2, prioritizationFee: 0 }, - { slot: 2, prioritizationFee: 0 }, - { slot: 1, prioritizationFee: 1000 }, - ]; - const ewma = ewmaStrategy.calculate(samples); - expect(ewma).to.be.approximately(500, 0.00001); - }); + it('EwmaStrategy should calculate the ewma prioritization fee', () => { + // halflife of 5 alots + const ewmaStrategy = new EwmaStrategy(5); + const samples = [ + { slot: 6, prioritizationFee: 0 }, + { slot: 2, prioritizationFee: 0 }, + { slot: 2, prioritizationFee: 0 }, + { slot: 2, prioritizationFee: 0 }, + { slot: 2, prioritizationFee: 0 }, + { slot: 1, prioritizationFee: 1000 }, + ]; + const ewma = ewmaStrategy.calculate(samples); + expect(ewma).to.be.approximately(500, 0.00001); + }); - it('EwmaStrategy should calculate the ewma prioritization fee, length 1', () => { - // halflife of 5 alots - const ewmaStrategy = new EwmaStrategy(5); - const samples = [ - { slot: 6, prioritizationFee: 1000 }, - ]; - const ewma = ewmaStrategy.calculate(samples); - expect(ewma).to.be.approximately(1000, 0.00001); - }); + it('EwmaStrategy should calculate the ewma prioritization fee, length 1', () => { + // halflife of 5 alots + const ewmaStrategy = new EwmaStrategy(5); + const samples = [{ slot: 6, prioritizationFee: 1000 }]; + const ewma = ewmaStrategy.calculate(samples); + expect(ewma).to.be.approximately(1000, 0.00001); + }); - it('EwmaStrategy should calculate the ewma prioritization fee, length 6', () => { - const ewmaStrategy = new EwmaStrategy(5); - const samples = [ - { slot: 6, prioritizationFee: 1000 }, - { slot: 5, prioritizationFee: 570 }, - { slot: 4, prioritizationFee: 860 }, - { slot: 3, prioritizationFee: 530 }, - { slot: 2, prioritizationFee: 701 }, - { slot: 1, prioritizationFee: 230 }, - ]; - const ewma = ewmaStrategy.calculate(samples); - expect(ewma).to.be.approximately(490.43706, 0.00001); - }); + it('EwmaStrategy should calculate the ewma prioritization fee, length 6', () => { + const ewmaStrategy = new EwmaStrategy(5); + const samples = [ + { slot: 6, prioritizationFee: 1000 }, + { slot: 5, prioritizationFee: 570 }, + { slot: 4, prioritizationFee: 860 }, + { slot: 3, prioritizationFee: 530 }, + { slot: 2, prioritizationFee: 701 }, + { slot: 1, prioritizationFee: 230 }, + ]; + const ewma = ewmaStrategy.calculate(samples); + expect(ewma).to.be.approximately(490.43706, 0.00001); + }); - it('MaxOverSlotsStrategy should calculate the max prioritization fee over slots', () => { - const maxOverSlotsStrategy = new MaxOverSlotsStrategy(5); - const samples = [ - { slot: 6, prioritizationFee: 432 }, - { slot: 3, prioritizationFee: 543 }, - { slot: 3, prioritizationFee: 342 }, - { slot: 3, prioritizationFee: 832 }, - { slot: 2, prioritizationFee: 123 }, - { slot: 1, prioritizationFee: 1000 }, - ]; - const maxOverSlots = maxOverSlotsStrategy.calculate(samples); - expect(maxOverSlots).to.equal(832); - }); + it('MaxOverSlotsStrategy should calculate the max prioritization fee over slots', () => { + const maxOverSlotsStrategy = new MaxOverSlotsStrategy(5); + const samples = [ + { slot: 6, prioritizationFee: 432 }, + { slot: 3, prioritizationFee: 543 }, + { slot: 3, prioritizationFee: 342 }, + { slot: 3, prioritizationFee: 832 }, + { slot: 2, prioritizationFee: 123 }, + { slot: 1, prioritizationFee: 1000 }, + ]; + const maxOverSlots = maxOverSlotsStrategy.calculate(samples); + expect(maxOverSlots).to.equal(832); + }); - it('AverageOverSlotsStrategy should calculate the average prioritization fee over slots', () => { - const averageOverSlotsStrategy = new AverageOverSlotsStrategy(5); - const samples = [ - { slot: 6, prioritizationFee: 432 }, - { slot: 3, prioritizationFee: 543 }, - { slot: 3, prioritizationFee: 342 }, - { slot: 3, prioritizationFee: 832 }, - { slot: 2, prioritizationFee: 123 }, - { slot: 1, prioritizationFee: 1000 }, - ]; - const averageOverSlots = averageOverSlotsStrategy.calculate(samples); - expect(averageOverSlots).to.equal(454.4); - }); + it('AverageOverSlotsStrategy should calculate the average prioritization fee over slots', () => { + const averageOverSlotsStrategy = new AverageOverSlotsStrategy(5); + const samples = [ + { slot: 6, prioritizationFee: 432 }, + { slot: 3, prioritizationFee: 543 }, + { slot: 3, prioritizationFee: 342 }, + { slot: 3, prioritizationFee: 832 }, + { slot: 2, prioritizationFee: 123 }, + { slot: 1, prioritizationFee: 1000 }, + ]; + const averageOverSlots = averageOverSlotsStrategy.calculate(samples); + expect(averageOverSlots).to.equal(454.4); + }); });