Skip to content

Commit

Permalink
Changes for token22 support in display in UI (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
brittcyr authored Oct 31, 2024
1 parent 1b15ffa commit a05fe73
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 20 deletions.
88 changes: 71 additions & 17 deletions client/ts/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
TOKEN_2022_PROGRAM_ID,
TOKEN_PROGRAM_ID,
getAssociatedTokenAddressSync,
getMint,
unpackMint,
} from '@solana/spl-token';
import {
createCreateMarketInstruction,
Expand Down Expand Up @@ -64,8 +64,8 @@ const marketDiscriminator: Buffer = genAccDiscriminator(
);

export class ManifestClient {
private isBase22: boolean;
private isQuote22: boolean;
public isBase22: boolean;
public isQuote22: boolean;

private constructor(
public connection: Connection,
Expand Down Expand Up @@ -184,8 +184,20 @@ export class ManifestClient {
});
const baseMintPk: PublicKey = marketObject.baseMint();
const quoteMintPk: PublicKey = marketObject.quoteMint();
const baseMint: Mint = await getMint(connection, baseMintPk);
const quoteMint: Mint = await getMint(connection, quoteMintPk);
const baseMintAccountInfo: AccountInfo<Buffer> =
(await connection.getAccountInfo(baseMintPk))!;
const baseMint: Mint = unpackMint(
baseMintPk,
baseMintAccountInfo,
baseMintAccountInfo.owner,
);
const quoteMintAccountInfo: AccountInfo<Buffer> =
(await connection.getAccountInfo(quoteMintPk))!;
const quoteMint: Mint = unpackMint(
quoteMintPk,
quoteMintAccountInfo,
quoteMintAccountInfo.owner,
);
const baseGlobal: Global | null = await Global.loadFromAddress({
connection,
address: getGlobalAddress(baseMint.address),
Expand Down Expand Up @@ -412,8 +424,20 @@ export class ManifestClient {
});
const baseMintPk: PublicKey = marketObject.baseMint();
const quoteMintPk: PublicKey = marketObject.quoteMint();
const baseMint: Mint = await getMint(connection, baseMintPk);
const quoteMint: Mint = await getMint(connection, quoteMintPk);
const baseMintAccountInfo: AccountInfo<Buffer> =
(await connection.getAccountInfo(baseMintPk))!;
const baseMint: Mint = unpackMint(
baseMintPk,
baseMintAccountInfo,
baseMintAccountInfo.owner,
);
const quoteMintAccountInfo: AccountInfo<Buffer> =
(await connection.getAccountInfo(quoteMintPk))!;
const quoteMint: Mint = unpackMint(
quoteMintPk,
quoteMintAccountInfo,
quoteMintAccountInfo.owner,
);

const userWrapper = await ManifestClient.fetchFirstUserWrapper(
connection,
Expand Down Expand Up @@ -471,8 +495,20 @@ export class ManifestClient {
});
const baseMintPk: PublicKey = marketObject.baseMint();
const quoteMintPk: PublicKey = marketObject.quoteMint();
const baseMint: Mint = await getMint(connection, baseMintPk);
const quoteMint: Mint = await getMint(connection, quoteMintPk);
const baseMintAccountInfo: AccountInfo<Buffer> =
(await connection.getAccountInfo(baseMintPk))!;
const baseMint: Mint = unpackMint(
baseMintPk,
baseMintAccountInfo,
baseMintAccountInfo.owner,
);
const quoteMintAccountInfo: AccountInfo<Buffer> =
(await connection.getAccountInfo(quoteMintPk))!;
const quoteMint: Mint = unpackMint(
quoteMintPk,
quoteMintAccountInfo,
quoteMintAccountInfo.owner,
);
const baseGlobal: Global | null = await Global.loadFromAddress({
connection,
address: getGlobalAddress(baseMint.address),
Expand Down Expand Up @@ -1222,8 +1258,14 @@ export class ManifestClient {
): Promise<TransactionInstruction> {
const global: PublicKey = getGlobalAddress(globalMint);
const globalVault: PublicKey = getGlobalVaultAddress(globalMint);
const mintInfo: Mint = await getMint(connection, globalMint);
const is22: boolean = mintInfo.tlvData.length > 0;
const globalMintAccountInfo: AccountInfo<Buffer> =
(await connection.getAccountInfo(globalMint))!;
const mint: Mint = unpackMint(
globalMint,
globalMintAccountInfo,
globalMintAccountInfo.owner,
);
const is22: boolean = mint.tlvData.length > 0;
return createGlobalCreateInstruction({
payer,
global,
Expand Down Expand Up @@ -1275,9 +1317,15 @@ export class ManifestClient {
globalMint,
payer,
);
const mintInfo: Mint = await getMint(connection, globalMint);
const is22: boolean = mintInfo.tlvData.length > 0;
const mintDecimals = mintInfo.decimals;
const globalMintAccountInfo: AccountInfo<Buffer> =
(await connection.getAccountInfo(globalMint))!;
const mint: Mint = unpackMint(
globalMint,
globalMintAccountInfo,
globalMintAccountInfo.owner,
);
const is22: boolean = mint.tlvData.length > 0;
const mintDecimals = mint.decimals;
const amountAtoms = Math.ceil(amountTokens * 10 ** mintDecimals);

return createGlobalDepositInstruction(
Expand Down Expand Up @@ -1319,9 +1367,15 @@ export class ManifestClient {
globalMint,
payer,
);
const mintInfo: Mint = await getMint(connection, globalMint);
const is22: boolean = mintInfo.tlvData.length > 0;
const mintDecimals = mintInfo.decimals;
const globalMintAccountInfo: AccountInfo<Buffer> =
(await connection.getAccountInfo(globalMint))!;
const mint: Mint = unpackMint(
globalMint,
globalMintAccountInfo,
globalMintAccountInfo.owner,
);
const is22: boolean = mint.tlvData.length > 0;
const mintDecimals = mint.decimals;
const amountAtoms = Math.ceil(amountTokens * 10 ** mintDecimals);

return createGlobalWithdrawInstruction(
Expand Down
20 changes: 17 additions & 3 deletions debug-ui/app/components/MyStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
} from '@cks-systems/manifest-sdk';
import { WrapperCancelOrderParams } from '@cks-systems/manifest-sdk/wrapper';
import { WrapperOpenOrder } from '@cks-systems/manifest-sdk/wrapperObj';
import { getAssociatedTokenAddressSync } from '@solana/spl-token';
import {
getAssociatedTokenAddressSync,
TOKEN_2022_PROGRAM_ID,
TOKEN_PROGRAM_ID,
} from '@solana/spl-token';
import { useConnection, useWallet } from '@solana/wallet-adapter-react';
import {
PublicKey,
Expand Down Expand Up @@ -213,7 +217,12 @@ const MyStatus = ({

try {
const baseBalance = await conn.getTokenAccountBalance(
getAssociatedTokenAddressSync(market.baseMint(), signerPub),
getAssociatedTokenAddressSync(
market.baseMint(),
signerPub,
true,
mClient.isBase22 ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID,
),
);
setBaseWalletBalance(baseBalance.value.uiAmount!);
} catch (err) {
Expand All @@ -222,7 +231,12 @@ const MyStatus = ({
}
try {
const quoteBalance = await conn.getTokenAccountBalance(
getAssociatedTokenAddressSync(market.quoteMint(), signerPub),
getAssociatedTokenAddressSync(
market.quoteMint(),
signerPub,
true,
mClient.isQuote22 ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID,
),
);
setQuoteWalletBalance(quoteBalance.value.uiAmount!);
} catch (err) {
Expand Down

0 comments on commit a05fe73

Please sign in to comment.