-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implemt event heap iterators * fee math for events * simplify * fmt * add event watcher
- Loading branch information
1 parent
4e02fa8
commit 9fc3e83
Showing
8 changed files
with
212 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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,42 @@ | ||
import { PublicKey } from '@solana/web3.js'; | ||
import { AnyEvent, EventHeapAccount, FillEvent, Market, OutEvent } from '..'; | ||
|
||
export enum EventType { | ||
Fill = 0, | ||
Out = 1, | ||
} | ||
|
||
export class EventHeap { | ||
constructor( | ||
public pubkey: PublicKey, | ||
public account: EventHeapAccount, | ||
public market: Market, | ||
) {} | ||
|
||
public *rawEvents(): Generator<AnyEvent> { | ||
let currentIndex = this.account.header.usedHead; | ||
for (let i = 0; i < this.account.header.count; ++i) { | ||
const { event, next } = this.account.nodes[currentIndex]; | ||
yield event; | ||
currentIndex = next; | ||
} | ||
} | ||
|
||
public *parsedEvents(): Generator<FillEvent | OutEvent> { | ||
const { decode } = this.market.client.program.coder.types; | ||
for (const event of this.rawEvents()) { | ||
// TODO find out how not to re-allocate | ||
const buffer = Buffer.from([event.eventType].concat(event.padding)); | ||
switch (event.eventType) { | ||
case EventType.Fill: { | ||
yield decode('FillEvent', buffer); | ||
continue; | ||
} | ||
case EventType.Out: { | ||
yield decode('OutEvent', buffer); | ||
continue; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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