Skip to content

Commit

Permalink
hedgehog: track parimutuel #11714
Browse files Browse the repository at this point in the history
g1nt0ki committed Sep 25, 2024
1 parent b8373d2 commit 85f10d3
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions projects/hedgehog-markets/index.js
Original file line number Diff line number Diff line change
@@ -7,11 +7,11 @@ async function tvl(api) {
const provider = getProvider()
const connection = getConnection()
const tokenAccounts = []
const owners= []
const owners = []
await getClassicMarketTokenAccounts()
await addP2PBalances()
await addParlay()
// await addParimutuel()
await addParimutuel()

const balances = api.getBalances()
await sumTokens2({ owners, balances, })
@@ -39,7 +39,7 @@ async function tvl(api) {
// - entry count (101..105)
// - entry cost (105..113)
dataSlice: { offset: 69, length: 44 },
filters: [
filters: [
// Market accounts have a discriminator of 3 at offset 0.
{ memcmp: { offset: 0, bytes: "4" } },
// Open markets have a state of 0 at offset 149.
@@ -68,40 +68,44 @@ async function tvl(api) {
dataSlice: { offset: 69, length: 56 },
filters: [
// Market accounts have a discriminator of 3 at offset 0.
{ memcmp: { offset: 0, bytes: "4", } },
{ memcmp: { offset: 0, bytes: "4", } },
// Open markets have a state of 0 at offset 129.
{ memcmp: { offset: 129, bytes: "1"} },
{ memcmp: { offset: 129, bytes: "1" } },
],
});

accounts.forEach(({ account: { data } }) => {
const mint = new PublicKey(data.slice(0, 32)).toString()
const mint = new PublicKey(data.slice(0, 32)).toString()
const yesAmount = Number(data.readUInt8(40));
const noAmount = Number(data.readUInt8(48));
api.add(mint, yesAmount + noAmount)
})
}


async function addParimutuel() {
const programId = new PublicKey('PARrVs6F5egaNuz8g6pKJyU4ze3eX5xGZCFb3GLiVvu')
const poolOwner = "3SAUPiGiATqv8TBgvzSJqpLxLGF6LbJamvimueJQT7WT"
owners.push(poolOwner)

const accounts = await connection.getProgramAccounts(programId, {
dataSlice: { offset: 69, length: 70 },
filters: [
filters: [
// Market accounts have a discriminator of 3 at offset 0.
{ memcmp: { offset: 0, bytes: "4" } },
// Open markets have a state of 0 at offset 149.
{ memcmp: { offset: 149, bytes: "1" } },
],
})

accounts.forEach(({ account }) => {
const data = decodeAccount('hhPari', account)
const token = data.mint.toString()
const amounts = data.amounts.map(Number)
accounts.forEach(({ account: { data } }) => {
const token = new PublicKey(data.slice(69,69+ 32)).toString()
// Amounts is a u64 array with u8 length prefix at offset 131.
const amountsLen = data.readUint8(131);

let amounts = []
for (let i = 0; i < amountsLen; i++) {
amounts.push(data.readBigUint64LE(132 + i * 8).toString())
}

api.add(token, amounts)
})
}

0 comments on commit 85f10d3

Please sign in to comment.