Skip to content

Instantly share code, notes, and snippets.

@SuperCipher
Created November 18, 2021 14:56
Show Gist options
  • Save SuperCipher/2ee45fdd5e3058e12a9e4080ae3cb0bb to your computer and use it in GitHub Desktop.
Save SuperCipher/2ee45fdd5e3058e12a9e4080ae3cb0bb to your computer and use it in GitHub Desktop.
mango rate decode
import {
blob,
Blob,
greedy,
Layout,
nu64,
seq,
struct,
Structure,
u16,
u32,
u8,
UInt,
union,
} from 'buffer-layout';
import BN from 'bn.js';
// import * as fs from 'fs';
import {
Account,
AccountInfo,
Commitment,
Connection,
PublicKey,
RpcResponseAndContext,
SimulatedTransactionResponse,
SystemProgram,
Transaction,
TransactionConfirmationStatus,
TransactionInstruction,
TransactionSignature,
} from '@solana/web3.js';
// import { OpenOrders, TokenInstructions } from '@project-serum/serum';
import { I80F48, ONE_I80F48 } from './fixednum';
import MangoGroup from './MangoGroup';
import { HealthType } from './MangoAccount';
import {
TokenAccountLayout, NodeBank, NodeBankLayout, PerpEventQueueLayout, RootBankLayout, MangoCacheLayout, MangoGroupLayout, MangoAccountLayout, PublicKeyLayout,
MetaDataLayout,
RootBankCache,
RootBankCacheLayoutInit,
priceCacheLayout
} from './layout';
class BNLayout extends Blob {
signed: boolean;
constructor(number: number, property, signed = false) {
super(number, property);
this.signed = signed;
// restore prototype chain
Object.setPrototypeOf(this, new.target.prototype);
}
decode(b, offset) {
let result = new BN(super.decode(b, offset), 10, 'le');
if (this.signed) result = result.fromTwos(8 * this['length']);
return result;
}
encode(src, b, offset) {
if (this.signed) src = src.toTwos(8 * this['length']);
return super.encode(src.toArrayLike(Buffer, 'le', this['span']), b, offset);
}
}
export function u64(property = '') {
return new BNLayout(8, property);
}
async function getMultipleAccounts(
)
{
const hopefully_rate = Buffer.from('BwABAAAAAAAawFsgQVUAAAAAAAAAAAAAhlmWYQAAAAAi2/l+avwP6AAAAAAAAAAAhlmWYQAAAACAJsKGpxdaEAAAAAAAAAAAhlmWYQAAAABZNLY6rTQAAAAAAAAAAAAAhl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(hopefully_rate))
const cacheLayout = MangoCacheLayout.decode(hopefully_rate)
console.log('CACHELAYOUT.PRICECACHE >>> :', cacheLayout.priceCache)
const cacheLayout0 = cacheLayout.priceCache[0]
console.log('CACHELAYOUT0 >>> :', cacheLayout0)
}
const new_obj = getMultipleAccounts();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment