0.2.4 • Published 6 months ago
@cks-systems/manifest-sdk v0.2.4
Manifest SDK
Typescript library for interacting with Manifest
Installation
Install via npm:
# add via npm
yarn add @cks-systems/manifest-sdkUsage
import { ManifestClient, OrderType } from '@cks-systems/manifest-sdk';
import { getAssociatedTokenAddressSync } from '@solana/spl-token';
import {
ComputeBudgetProgram,
Connection,
Keypair,
PublicKey,
Transaction,
sendAndConfirmTransaction,
} from '@solana/web3.js';
export const sleep = async (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms));
export const run = async () => {
// FIXME: replace with valid rpcUrl
const conn = new Connection('FIXME');
// FIXME: replace with own `Keypair`
const user = Keypair.generate();
// FIXME: replace with a valid market
const marketPub = new PublicKey('FIXME');
// FIXME: set an appropriate priority fee
const prioFee = 10_000;
const prioIx = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: prioFee,
});
// NOTE: this will automatically attempt to send a tx to claim a seat if needed.
// use `ManifestClient.getClientForMarketNoPrivateKey` if you do not want this behavior
const mfx = await ManifestClient.getClientForMarket(
conn as any,
marketPub,
user as any,
);
const baseMint = mfx.market.baseMint();
const quoteMint = mfx.market.quoteMint();
const baseAta = getAssociatedTokenAddressSync(baseMint, user.publicKey);
const quoteAta = getAssociatedTokenAddressSync(quoteMint, user.publicKey);
const [
{
value: { uiAmount: baseBalTokens },
},
{
value: { uiAmount: quoteBalTokens },
},
] = await Promise.all([
conn.getTokenAccountBalance(baseAta),
conn.getTokenAccountBalance(quoteAta),
]);
console.log('baseBalTokens', baseBalTokens);
console.log('quoteBalTokens', quoteBalTokens);
if ((baseBalTokens || 0) < 1) {
throw new Error(
`base balance is too low. top up and try again. got: ${baseBalTokens} want: 1`,
);
}
const bidParams = {
numBaseTokens: 1,
tokenPrice: 0.9,
isBid: true,
lastValidSlot: 0,
orderType: OrderType.PostOnly,
clientOrderId: 0,
minOutTokens: 0,
};
console.log('submitting bid limit order...');
const bidCuIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 40_000 });
const quoteDepositIx = mfx.depositIx(user.publicKey, quoteMint, 0.9);
const bidIx = mfx.placeOrderIx(bidParams);
const bidTx = new Transaction().add(prioIx, bidCuIx, quoteDepositIx, bidIx);
const bidSig = await sendAndConfirmTransaction(conn, bidTx, [user]);
console.log(`limit bid submitted: txSig: ${bidSig}`);
const askParams = {
numBaseTokens: 1,
tokenPrice: 1.1,
isBid: false,
lastValidSlot: 0,
orderType: OrderType.PostOnly,
clientOrderId: 0,
minOutTokens: 0,
};
console.log('submitting ask limit order...');
const askCuIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 40_000 });
const baseDepositIx = mfx.depositIx(user.publicKey, baseMint, 1);
const askIx = mfx.placeOrderIx(askParams);
const askTx = new Transaction().add(prioIx, askCuIx, baseDepositIx, askIx);
const askSig = await sendAndConfirmTransaction(conn, askTx, [user]);
console.log(`limit ask submitted: txSig: ${askSig}`);
// make sure on-chain state updates
await sleep(5_000);
await mfx.reload();
const openOrders = mfx.wrapper.openOrdersForMarket(marketPub);
const marketInfo = mfx.wrapper.marketInfoForMarket(marketPub);
console.log('market:');
console.log(mfx.market.prettyPrint());
console.log('wrapper:');
console.log(mfx.wrapper.prettyPrint());
console.log('openOrders:');
console.log(openOrders);
console.log('marketInfo:');
console.log(marketInfo);
console.log('bids', mfx.market.bids());
console.log('asks', mfx.market.asks());
console.log('cancelling all orders and withdrawing funds...');
const cancelCuIx = ComputeBudgetProgram.setComputeUnitLimit({
units: 80_000,
});
const cancelAllIx = mfx.cancelAllIx();
const withdrawIxs = mfx.withdrawAllIx();
const cancelAllTx = new Transaction().add(
prioIx,
cancelCuIx,
cancelAllIx,
...withdrawIxs,
);
const cancelSig = await sendAndConfirmTransaction(conn, cancelAllTx, [user]);
console.log(`cancelled/withdrawn: ${cancelSig}`);
};
run().catch(console.error);0.1.74
11 months ago
0.1.75
11 months ago
0.1.76
11 months ago
0.1.77
11 months ago
0.1.78
10 months ago
0.1.79
10 months ago
0.1.70
1 year ago
0.1.71
1 year ago
0.1.72
12 months ago
0.1.73
12 months ago
0.1.65
1 year ago
0.1.66
1 year ago
0.1.67
1 year ago
0.1.68
1 year ago
0.1.69
1 year ago
0.1.80
10 months ago
0.1.81
10 months ago
0.1.82
10 months ago
0.1.83
9 months ago
0.2.1
8 months ago
0.2.0
8 months ago
0.2.3
7 months ago
0.2.2
7 months ago
0.2.4
6 months ago
0.1.63
1 year ago
0.1.64
1 year ago
0.1.61
1 year ago
0.1.62
1 year ago
0.1.60
1 year ago
0.1.59
1 year ago
0.1.58
1 year ago
0.1.57
1 year ago
0.1.56
1 year ago
0.1.55
1 year ago
0.1.54
1 year ago
0.1.53
1 year ago
0.1.52
1 year ago
0.1.51
1 year ago
0.1.41
1 year ago
0.1.5
1 year ago
0.1.4
1 year ago
0.1.3
1 year ago
0.1.2
1 year ago
0.1.1
1 year ago
0.1.0
1 year ago