Skip to content

Commit

Permalink
sdk: PriorityFeeSubscriber init (#585)
Browse files Browse the repository at this point in the history
* sdk: PriorityFeeSubscriber init

* sdk: priority fee subscriber (fork) (#590)

* sdk: release v2.37.1-beta.7

* program: fix place_and_make/take_spot

* amm_spread.rs: add conf_component logic (#577)

* amm_spread.rs: add conf_component logic

* update CHANGELOG.md

* order subscriber event emitter

* renaming new to update

* checking for length > 0 before emitting

* fixing new orders bug

* sdk: release v2.37.1-beta.8

* program: add lp shares rebase (#568)

* start test

* improve lp_delta_quote

* improve per_lp_delta_quote

* init per_lp_base

* add rebase functions (wip)

* rm err msg

* add controller rebase to proper locations

* add rebase cargo test

* (wip) k out of wack

* fix rebase test and add more asserts

* format fix

* incorp basic example to typescript tests

* fix rebase math in position.rs (wip)

* wip continue

* working baseAssetAmountWithUnsettledLp

* mvp encapsulation of update_lp_market_position

* src/user.ts: add perLpBase to empty position

* remove logs

* simplify base unit logic more

* add get_per_lp_base_unit

* simplify per_lp_fee and add numbers to test

* properly set per_lp_base for lp_share=0 in mint_lp_shares (and add sdk/test)

* incorp feedback / format

* tests/liquidityProvider.ts: work with sdk change

* admin.rs: add constraint on per_lp_base range

* add apply_lp_rebase_to_perp_position to simulate_settled_lp_position

* use get_per_lp_base_unit consistently (wip sdk test for negative lp base)

* cut excess return values in calculate_lp_delta

* fix getPerpPositionWithLPSettle with negative perLpBase delta

---------

Co-authored-by: Chris Heaney <[email protected]>

* sdk: release v2.37.1-beta.9

* bigz/oracle-auction-oracle-validity-test (#584)

* sdk: fixes for getHealthComponents

* sdk: release v2.37.1-beta.10

* sdk: add option for marginCategory to getFreeCollateral (#573)

* sdk: release v2.37.1-beta.11

* wip save work

* sdk: updates to priorityfeesubscriber

* 25 default batch size

* tests: fix liquidateSpot health checks

* sdk: add debug for bulk account loader handleAccountCallbacks (#592)

* sdk: add debug for bulk account loader handleAccountCallbacks

* log callbacks individually

* sdk: release v2.37.1-beta.12

* configurable in polling config

* sdk: release v2.37.1-beta.13

* tests/driftClient.ts: add sleep

* bigz/fix-liquidatePerpAndLp-test (#593)

* bigz/fix-liquidatePerpAndLp-test

* uncomment out assert

* perpLpJit.ts: longer sleep for rc ts test

* perpLpJit.ts: longer sleep for rc ts test

* perpLpJit.ts: rm redundant check

* prepegMarketOrderBaseAssetAmount.ts: add sleep

* merge master

* v2.38.0

* sdk: release v2.38.1-beta.0

* feedback updates

* sdk: catch decoding error in polling drift client account subscriber

* sdk: release v2.38.1-beta.1

* Revert "sdk: catch decoding error in polling drift client account subscriber"

This reverts commit 36e0f0f.

* sdk: use decodeUnchecked in bulk account loader

* sdk: release v2.38.1-beta.2

* sdk: use decodeUnchecked in more places

* sdk: release v2.38.1-beta.3

* Revert "sdk: use decodeUnchecked in more places"

This reverts commit f11a3b0.

* sdk: use decodeUnchecked in PollingUserStatsAccountSubscriber

* sdk: fetchUserStatsAccount use decodeUnchecked

* sdk: update anchor to 0.28.1-beta.2 (#595)

* try 0.28.0

* try updating top dir anchor

* anchor 0.28.1-beta.2

* fix prettify

* CHANGELOG

* sdk: release v2.38.1-beta.4

---------

Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Chris Heaney <[email protected]>
Co-authored-by: bigzPubkey <[email protected]>
Co-authored-by: Nour Alharithi <[email protected]>
Co-authored-by: Evan Pipta <[email protected]>

---------

Co-authored-by: lowkeynicc <[email protected]>
Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: bigzPubkey <[email protected]>
Co-authored-by: Nour Alharithi <[email protected]>
Co-authored-by: Evan Pipta <[email protected]>
Co-authored-by: lowkeynicc <[email protected]>
  • Loading branch information
7 people committed Aug 28, 2023
1 parent 2678a6f commit 3ff6dfd
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Features

- sdk: updated anchor to 0.28.1-beta.2
- sdk: add priorityFeeSubscriber

### Fixes

Expand Down
1 change: 1 addition & 0 deletions sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export * from './constants/numericConstants';
export * from './serum/serumSubscriber';
export * from './serum/serumFulfillmentConfigMap';
export * from './phoenix/phoenixSubscriber';
export * from './priorityFee/priorityFeeSubscriber';
export * from './phoenix/phoenixFulfillmentConfigMap';
export * from './tx/fastSingleTxSender';
export * from './tx/retryTxSender';
Expand Down
75 changes: 75 additions & 0 deletions sdk/src/priorityFee/priorityFeeSubscriber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Connection, PublicKey } from '@solana/web3.js';

export class PriorityFeeSubscriber {
connection: Connection;
frequencyMs: number;
addresses: PublicKey[];
slotsToCheck: number;

intervalId?: NodeJS.Timer;

latestPriorityFee = 0;
// avg of last {slotsToCheck} slots
avgPriorityFee = 0;
// max of last {slotsToCheck} slots
maxPriorityFee = 0;
lastSlotSeen = 0;

public constructor({
connection,
frequencyMs,
addresses,
slotsToCheck = 10,
}: {
connection: Connection;
frequencyMs: number;
addresses: PublicKey[];
slotsToCheck?: number;
}) {
this.connection = connection;
this.frequencyMs = frequencyMs;
this.addresses = addresses;
this.slotsToCheck = slotsToCheck;
}

public async subscribe(): Promise<void> {
if (this.intervalId) {
return;
}

this.intervalId = setInterval(this.load.bind(this), this.frequencyMs);
}

public async load(): Promise<void> {
// @ts-ignore
const rpcJSONResponse: any = await this.connection._rpcRequest(
'getRecentPrioritizationFees',
[this.addresses]
);

const descResults: { slot: number; prioritizationFee: number }[] =
rpcJSONResponse?.result
?.sort((a, b) => b.slot - a.slot)
?.slice(0, this.slotsToCheck) ?? [];

if (!descResults?.length) return;

const mostRecentResult = descResults[0];
this.latestPriorityFee = mostRecentResult.prioritizationFee;
this.lastSlotSeen = mostRecentResult.slot;
this.avgPriorityFee =
descResults.reduce((a, b) => {
return a + b.prioritizationFee;
}, 0) / descResults.length;
this.maxPriorityFee = Math.max(
...descResults.map((result) => result.prioritizationFee)
);
}

public async unsubscribe(): Promise<void> {
if (this.intervalId) {
clearInterval(this.intervalId);
this.intervalId = undefined;
}
}
}

0 comments on commit 3ff6dfd

Please sign in to comment.