From 96d6196dab7e2b51b88520a7f8c7bf448579c588 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 28 Sep 2023 10:29:04 +0200 Subject: [PATCH 1/3] v2.1.1 --- packages/marginfi-client-v2/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/marginfi-client-v2/package.json b/packages/marginfi-client-v2/package.json index ac4a8a02e2..b0e60fbcfa 100644 --- a/packages/marginfi-client-v2/package.json +++ b/packages/marginfi-client-v2/package.json @@ -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", From efe342a3fcd8d632025f5d5df25e3d00efececc1 Mon Sep 17 00:00:00 2001 From: j Date: Wed, 4 Oct 2023 12:51:41 +0200 Subject: [PATCH 2/3] fix: add lut support for marginfi client --- packages/marginfi-client-v2/src/client.ts | 20 ++++++++++++++++---- packages/marginfi-client-v2/src/constants.ts | 5 +++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/marginfi-client-v2/src/client.ts b/packages/marginfi-client-v2/src/client.ts index df6a5feda3..8db2d08f98 100644 --- a/packages/marginfi-client-v2/src/client.ts +++ b/packages/marginfi-client-v2/src/client.ts @@ -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, @@ -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; @@ -40,6 +41,7 @@ class MarginfiClient { public group: MarginfiGroup; public banks: BankMap; public oraclePrices: OraclePriceMap; + private addressLookupTables: AddressLookupTableAccount[]; // -------------------------------------------------------------------------- // Factories @@ -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 ?? []; } /** @@ -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( @@ -415,7 +427,7 @@ class MarginfiClient { recentBlockhash: blockhash, }); - versionedTransaction = new VersionedTransaction(versionedMessage.compileToV0Message([])); + versionedTransaction = new VersionedTransaction(versionedMessage.compileToV0Message(this.addressLookupTables)); } else { versionedTransaction = transaction; } diff --git a/packages/marginfi-client-v2/src/constants.ts b/packages/marginfi-client-v2/src/constants.ts index 75118f963e..b2599d07b5 100644 --- a/packages/marginfi-client-v2/src/constants.ts +++ b/packages/marginfi-client-v2/src/constants.ts @@ -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"); @@ -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")], +}; From 4b5a63ec16c6269efe767a9b7bf0306aa5f65f8b Mon Sep 17 00:00:00 2001 From: j Date: Wed, 4 Oct 2023 14:49:07 +0200 Subject: [PATCH 3/3] fix: close button disabled bug --- .../src/components/AssetsList/AssetRow/AssetRow.tsx | 6 ++++-- .../UserPositions/UserPositionRow/UserPositionRow.tsx | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/marginfi-v2-ui/src/components/AssetsList/AssetRow/AssetRow.tsx b/apps/marginfi-v2-ui/src/components/AssetsList/AssetRow/AssetRow.tsx index 04b9446add..8f5ac0d5b6 100644 --- a/apps/marginfi-v2-ui/src/components/AssetsList/AssetRow/AssetRow.tsx +++ b/apps/marginfi-v2-ui/src/components/AssetsList/AssetRow/AssetRow.tsx @@ -675,8 +675,10 @@ const AssetRow: FC<{ onClick={currentAction === "Connect" ? openWalletSelector : isDust ? closeBalance : borrowOrLend} disabled={ currentAction !== "Connect" && - ((isDust && uiToNative(bank.userInfo.tokenAccount.balance, bank.info.state.mintDecimals).isZero()) || - maxAmount === 0) + ((isDust && + uiToNative(bank.userInfo.tokenAccount.balance, bank.info.state.mintDecimals).isZero() && + currentAction == ActionType.Borrow) || + (!isDust && maxAmount === 0)) } > {isDust ? "Close" : currentAction} diff --git a/apps/marginfi-v2-ui/src/components/UserPositions/UserPositionRow/UserPositionRow.tsx b/apps/marginfi-v2-ui/src/components/UserPositions/UserPositionRow/UserPositionRow.tsx index 2561f23a6d..9758c083ab 100644 --- a/apps/marginfi-v2-ui/src/components/UserPositions/UserPositionRow/UserPositionRow.tsx +++ b/apps/marginfi-v2-ui/src/components/UserPositions/UserPositionRow/UserPositionRow.tsx @@ -189,8 +189,9 @@ const UserPositionRow: FC = ({ activeBankInfo, marginfiAcc uiToNative( activeBankInfo.userInfo.tokenAccount.balance, activeBankInfo.info.state.mintDecimals - ).isZero()) || - maxAmount === 0 + ).isZero() && + !activeBankInfo.position.isLending) || + (!isDust && maxAmount === 0) } > {isDust ? "Close" : activeBankInfo.position.isLending ? "Withdraw" : "Repay"}