Skip to content

Commit

Permalink
Changes for token22 support in display in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
brittcyr committed Oct 30, 2024
1 parent edb1ee7 commit 76eeddd
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 21 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cks-systems/manifest-sdk",
"version": "0.1.62",
"version": "0.1.63",
"files": [
"dist/",
"README.md",
Expand Down

0 comments on commit 76eeddd

Please sign in to comment.