From 0951eede43ad60123db9b2ae68718ffabba63052 Mon Sep 17 00:00:00 2001 From: bartosz-lipinski <264380+bartosz-lipinski@users.noreply.github.com> Date: Fri, 8 Jan 2021 18:14:20 -0600 Subject: [PATCH] feat: account layout --- src/contexts/connection.tsx | 6 +++++- src/models/lending/market.ts | 11 ++++++++--- src/models/lending/obligation.ts | 9 +++++++-- src/models/lending/reserve.ts | 9 +++++++-- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/contexts/connection.tsx b/src/contexts/connection.tsx index 3de821b..9102d45 100644 --- a/src/contexts/connection.tsx +++ b/src/contexts/connection.tsx @@ -13,9 +13,13 @@ export const ENDPOINTS = [ name: 'mainnet-beta' as ENV, endpoint: 'https://solana-api.projectserum.com/', }, + { + name: 'Oyster Dev' as ENV, + endpoint: 'http://oyster-dev.solana.com/', + }, { name: 'Lending' as ENV, - endpoint: 'https://tln.solana.com/', + endpoint: 'http://tln.solana.com/', }, { name: 'testnet' as ENV, endpoint: clusterApiUrl('testnet') }, { name: 'devnet' as ENV, endpoint: clusterApiUrl('devnet') }, diff --git a/src/models/lending/market.ts b/src/models/lending/market.ts index 1dff8ba..ecde757 100644 --- a/src/models/lending/market.ts +++ b/src/models/lending/market.ts @@ -4,20 +4,25 @@ import * as Layout from "./../../utils/layout"; export const LendingMarketLayout: typeof BufferLayout.Structure = BufferLayout.struct( [ - BufferLayout.u8("version"), + BufferLayout.u8('version'), Layout.publicKey("quoteMint"), - Layout.publicKey("tokenProgramId") + Layout.publicKey("tokenProgramId"), + + // extra space for future contract changes + BufferLayout.blob(63, "padding"), ], ); export interface LendingMarket { + version: number; + isInitialized: boolean; quoteMint: PublicKey; tokenProgramId: PublicKey, } export const isLendingMarket = (info: AccountInfo) => { - return info.data.length === LendingMarketLayout.span + 63; + return info.data.length === LendingMarketLayout.span; }; export const LendingMarketParser = ( diff --git a/src/models/lending/obligation.ts b/src/models/lending/obligation.ts index aaa6064..bb24ee0 100644 --- a/src/models/lending/obligation.ts +++ b/src/models/lending/obligation.ts @@ -5,7 +5,7 @@ import * as Layout from "./../../utils/layout"; export const LendingObligationLayout: typeof BufferLayout.Structure = BufferLayout.struct( [ - BufferLayout.u8("version"), + BufferLayout.u8('version'), /// Slot when obligation was updated. Used for calculating interest. Layout.uint64("lastUpdateSlot"), /// Amount of collateral tokens deposited for this obligation @@ -20,14 +20,19 @@ export const LendingObligationLayout: typeof BufferLayout.Structure = BufferLayo Layout.publicKey("borrowReserve"), /// Mint address of the tokens for this obligation Layout.publicKey("tokenMint"), + + // extra space for future contract changes + BufferLayout.blob(128, "padding"), ] ); export const isLendingObligation = (info: AccountInfo) => { - return info.data.length === LendingObligationLayout.span + 300; + return info.data.length === LendingObligationLayout.span; }; export interface LendingObligation { + version: number; + lastUpdateSlot: BN; depositedCollateral: BN; collateralReserve: PublicKey; diff --git a/src/models/lending/reserve.ts b/src/models/lending/reserve.ts index be711bd..6356f70 100644 --- a/src/models/lending/reserve.ts +++ b/src/models/lending/reserve.ts @@ -66,7 +66,7 @@ export const LendingReserveLayout: typeof BufferLayout.Structure = BufferLayout. ), BufferLayout.struct( - [ + [ Layout.uint128('cumulativeBorrowRateWad'), Layout.uint128('borrowedLiquidityWad'), Layout.uint64('availableLiquidity'), @@ -74,13 +74,18 @@ export const LendingReserveLayout: typeof BufferLayout.Structure = BufferLayout. ], 'state' ), + + // extra space for future contract changes + BufferLayout.blob(300, "padding"), ]); export const isLendingReserve = (info: AccountInfo) => { - return info.data.length === LendingReserveLayout.span + 300; + return info.data.length === LendingReserveLayout.span; }; export interface LendingReserve { + version: number; + lastUpdateSlot: BN; lendingMarket: PublicKey;