Skip to content

Commit

Permalink
Merge pull request #258 from mrgnlabs/j/lut-support
Browse files Browse the repository at this point in the history
Lookup table support
  • Loading branch information
jkbpvsc authored Oct 4, 2023
2 parents 84031b5 + efe342a commit 81fbb89
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/marginfi-client-v2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mrgnlabs/marginfi-client-v2",
"version": "2.1.0",
"version": "2.1.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
Expand Down
20 changes: 16 additions & 4 deletions packages/marginfi-client-v2/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Address, AnchorProvider, BorshAccountsCoder, Program, translateAddress } from "@coral-xyz/anchor";
import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";
import {
AddressLookupTableAccount,
Commitment,
ConfirmOptions,
Connection,
Expand All @@ -27,7 +28,7 @@ import {
Wallet,
} from "@mrgnlabs/mrgn-common";
import { MarginfiGroup } from "./models/group";
import { BankRaw, parseOracleSetup, parsePriceInfo, Bank, OraclePrice } from ".";
import { BankRaw, parseOracleSetup, parsePriceInfo, Bank, OraclePrice, ADDRESS_LOOKUP_TABLE_FOR_GROUP } from ".";
import { MarginfiAccountWrapper } from "./models/account/wrapper";

export type BankMap = Map<string, Bank>;
Expand All @@ -40,6 +41,7 @@ class MarginfiClient {
public group: MarginfiGroup;
public banks: BankMap;
public oraclePrices: OraclePriceMap;
private addressLookupTables: AddressLookupTableAccount[];

// --------------------------------------------------------------------------
// Factories
Expand All @@ -55,11 +57,13 @@ class MarginfiClient {
readonly isReadOnly: boolean,
group: MarginfiGroup,
banks: BankMap,
priceInfos: OraclePriceMap
priceInfos: OraclePriceMap,
addressLookupTables?: AddressLookupTableAccount[]
) {
this.group = group;
this.banks = banks;
this.oraclePrices = priceInfos;
this.addressLookupTables = addressLookupTables ?? [];
}

/**
Expand Down Expand Up @@ -97,7 +101,15 @@ class MarginfiClient {

const { marginfiGroup, banks, priceInfos } = await this.fetchGroupData(program, config.groupPk, opts?.commitment);

return new MarginfiClient(config, program, wallet, readOnly, marginfiGroup, banks, priceInfos);
const addressLookupTableAddresses = ADDRESS_LOOKUP_TABLE_FOR_GROUP[config.groupPk.toString()] ?? [];
debug("Fetching address lookup tables for %s", addressLookupTableAddresses);
const addressLookupTables = (
await Promise.all(addressLookupTableAddresses.map((address) => connection.getAddressLookupTable(address)))
)
.map((response) => response!.value)
.filter((table) => table !== null) as AddressLookupTableAccount[];

return new MarginfiClient(config, program, wallet, readOnly, marginfiGroup, banks, priceInfos, addressLookupTables);
}

static async fromEnv(
Expand Down Expand Up @@ -415,7 +427,7 @@ class MarginfiClient {
recentBlockhash: blockhash,
});

versionedTransaction = new VersionedTransaction(versionedMessage.compileToV0Message([]));
versionedTransaction = new VersionedTransaction(versionedMessage.compileToV0Message(this.addressLookupTables));
} else {
versionedTransaction = transaction;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/marginfi-client-v2/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PublicKey } from "@solana/web3.js";
import BigNumber from "bignumber.js";

export const PDA_BANK_LIQUIDITY_VAULT_AUTH_SEED = Buffer.from("liquidity_vault_auth");
Expand All @@ -11,3 +12,7 @@ export const PDA_BANK_FEE_VAULT_SEED = Buffer.from("fee_vault");
export const PYTH_PRICE_CONF_INTERVALS = new BigNumber(2.12);
export const SWB_PRICE_CONF_INTERVALS = new BigNumber(2.12);
export const USDC_DECIMALS = 6;

export const ADDRESS_LOOKUP_TABLE_FOR_GROUP: { [key: string]: [PublicKey] } = {
"4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8": [new PublicKey("Ed6FZFDbVPFjjfqFZmVnyLNxicnsRuzkYp6tqxRZzbwe")],
};

0 comments on commit 81fbb89

Please sign in to comment.