Skip to content

Instantly share code, notes, and snippets.

@kuznetsov-m
Last active May 26, 2021 08:16
Show Gist options
  • Save kuznetsov-m/a46257e85092be6736eaa09fd702843e to your computer and use it in GitHub Desktop.
Save kuznetsov-m/a46257e85092be6736eaa09fd702843e to your computer and use it in GitHub Desktop.
import base64
data64 = 'AQAAAAAAAAAA9gS5bBWmAYqIWY0MWjEP4rYzOqSLqRblAr4CV4ylA4RUb5AegR/zDQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJXH2dBhmCO+Qx2UVe6Jt+82VluOtYSKxdN49XuVOGTxQMfjEzKi8XVUfL4wQoTtWZmE7hxytvWvNfNpOPmRXJQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=='
data_bytes = base64.b64decode(data64)
print(data_bytes)
print(len(data_bytes)) # 265
from construct import Int8ub, Int64ub, Struct, Array, Byte, Bytes
# Mainnet obligation format:
#
# /// Borrow obligation state
# [derive(Clone, Debug, Default, PartialEq)]
# pub struct Obligation {
# /// Version of the obligation
# pub version: u8,
# /// Amount of collateral tokens deposited for this obligation
# pub deposited_collateral_tokens: u64,
# /// Reserve which collateral tokens were deposited into
# pub collateral_reserve: Pubkey,
# /// Borrow rate used for calculating interest.
# pub cumulative_borrow_rate_wads: Decimal,
# /// Amount of tokens borrowed for this obligation plus interest
# pub borrowed_liquidity_wads: Decimal,
# /// Reserve which tokens were borrowed from
# pub borrow_reserve: Pubkey,
# /// Mint address of the tokens for this obligation
# pub token_mint: Pubkey,
# }
#
# const OBLIGATION_LEN: usize = 265;
PUBLIC_KEY_LAYOUT = Bytes(32)
format = Struct(
"version" / Int8ub,
"deposited_collateral_tokens" / Int64ub,
"collateral_reserve" / PUBLIC_KEY_LAYOUT,
"cumulative_borrow_rate_wads" / Array(3, Int64ub),
"borrowed_liquidity_wads" / Array(3, Int64ub),
"borrow_reserve" / PUBLIC_KEY_LAYOUT,
"token_mint" / PUBLIC_KEY_LAYOUT
)
obligation_container = format.parse(data_bytes)
print(obligation_container)
# Container:
# version = 1
# deposited_collateral_tokens = 0
# collateral_reserve = b'\xf6\x04\xb9l\x15\xa6\x01\x8a\x88Y\x8d\x0cZ1\x0f\xe2'... (truncated, total 32)
# cumulative_borrow_rate_wads = ListContainer:
# 6084240082290602765
# 0
# 0
# borrowed_liquidity_wads = ListContainer:
# 0
# 10792834521030468542
# 4836184671660914671
# borrow_reserve = b'6V[\x8e\xb5\x84\x8a\xc5\xd3x\xf5{\x958d\xf1'... (truncated, total 32)
# token_mint = b'\x99\x84\xee\x1cr\xb6\xf5\xaf5\xf3i8\xf9\x91\\\x94'... (truncated, total 32)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment