Skip to content

Commit 92aab9a

Browse files
committed
feat: merge main into release/npm BREAKING CHANGE: Updated API interface and response format
2 parents 52547bf + c460063 commit 92aab9a

16 files changed

Lines changed: 337 additions & 245 deletions

examples/create_partner.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const RPC_URL = process.env.RPC_URL!;
1010
const SEND_RPC_URL = process.env.SEND_RPC_URL ?? RPC_URL;
1111
const KEYPAIR_PATH = process.env.KEYPAIR_PATH!;
1212
const POOL_STATE = process.env.POOL_STATE!;
13-
const PARTNER_NAME = process.env.PARTNER_NAME ?? "test_partner"
13+
const PARTNER_NAME = process.env.PARTNER_NAME ?? "test_partner";
1414
const MICRO_LAMPORTS = parseInt(process.env.DEFAULT_CU_LAMPORTS ?? "1200000");
1515

1616
async function mainFn(): Promise<void> {
@@ -27,8 +27,8 @@ async function mainFn(): Promise<void> {
2727
});
2828

2929
const info = await client.cpmm.getPoolInfoFromRpc(POOL_STATE);
30-
const partner = Keypair.generate()
31-
console.log(`Initializing partner with pubkey: ${partner.publicKey.toBase58()}`)
30+
const partner = Keypair.generate();
31+
console.log(`Initializing partner with pubkey: ${partner.publicKey.toBase58()}`);
3232

3333
let { transaction } = await client.cpmm.initializePartner({
3434
pool: POOL_STATE,
@@ -63,7 +63,7 @@ async function mainFn(): Promise<void> {
6363
"confirmed",
6464
);
6565
console.log(`createPartner txn confirmed. View at https://solscan.io/tx/${signature}`);
66-
console.log(`Partner account: https://solscan.io/account/${partner.publicKey.toBase58()}`)
66+
console.log(`Partner account: https://solscan.io/account/${partner.publicKey.toBase58()}`);
6767
}
6868

6969
export function createKeypairFromFile(filePath: string): Keypair {

examples/liquidity.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const AMOUNT = process.env.AMOUNT!;
1616
const POOL_STATE = new PublicKey(process.env.POOL!);
1717
const MICRO_LAMPORTS = parseInt(process.env.DEFAULT_CU_LAMPORTS ?? "1200000");
1818
const SLIPPAGE_BPS = parseInt(process.env.SLIPPAGE_BPS ?? "1000");
19-
const BASE_IN = process.env.BASE_IN === undefined ? true : process.env.BASE_IN === "true";
19+
const BASE_SPECIFIED = process.env.BASE_SPECIFIED === undefined ? true : process.env.BASE_SPECIFIED === "true";
2020

2121
async function mainFn(): Promise<void> {
2222
const keypair = createKeypairFromFile(KEYPAIR_PATH);
@@ -37,54 +37,54 @@ async function mainFn(): Promise<void> {
3737
baseReserve: info.rpcData.baseReserve,
3838
quoteReserve: info.rpcData.quoteReserve,
3939
slippage,
40-
baseIn: BASE_IN,
40+
baseSpecified: BASE_SPECIFIED,
4141
amount: new Decimal(AMOUNT.toString())
42-
.div(10 ** (BASE_IN ? info.poolInfo.mintA.decimals : info.poolInfo.mintB.decimals))
42+
.div(10 ** (BASE_SPECIFIED ? info.poolInfo.mintA.decimals : info.poolInfo.mintB.decimals))
4343
.toString(),
4444
epochInfo: await client.connection.getEpochInfo(),
4545
});
4646

47-
// let { transaction: addTxn } = await client.cpmm.addLiquidity({
48-
// poolInfo: info.poolInfo,
49-
// poolKeys: info.poolKeys,
50-
// payer: keypair.publicKey,
51-
// inputAmount: new BN(AMOUNT),
52-
// baseIn: BASE_IN,
53-
// slippage,
54-
// computeResult: compute,
55-
// computeBudgetConfig: {
56-
// microLamports: MICRO_LAMPORTS,
57-
// },
58-
// txVersion: TxVersion.V0,
59-
// });
47+
let { transaction: addTxn } = await client.cpmm.addLiquidity({
48+
poolInfo: info.poolInfo,
49+
poolKeys: info.poolKeys,
50+
payer: keypair.publicKey,
51+
inputAmount: new BN(AMOUNT),
52+
baseSpecified: BASE_SPECIFIED,
53+
slippage,
54+
computeResult: compute,
55+
computeBudgetConfig: {
56+
microLamports: MICRO_LAMPORTS,
57+
},
58+
txVersion: TxVersion.V0,
59+
});
6060

6161
let latestBlockhash = await client.connection.getLatestBlockhash();
62-
// addTxn.message.recentBlockhash = latestBlockhash.blockhash;
63-
// addTxn.sign([
64-
// {
65-
// publicKey: keypair.publicKey,
66-
// secretKey: keypair.secretKey,
67-
// },
68-
// ]);
62+
addTxn.message.recentBlockhash = latestBlockhash.blockhash;
63+
addTxn.sign([
64+
{
65+
publicKey: keypair.publicKey,
66+
secretKey: keypair.secretKey,
67+
},
68+
]);
6969

7070
const sendConnection = new Connection(SEND_RPC_URL);
71-
// console.log("Sending addLiquidity transaction");
72-
// let signature = await sendConnection.sendTransaction(addTxn as unknown as VersionedTransaction, {
73-
// skipPreflight: true,
74-
// preflightCommitment: "confirmed",
75-
// maxRetries: 0,
76-
// });
77-
// console.log(`Waiting to confirm transaction ${signature}`);
71+
console.log("Sending addLiquidity transaction");
72+
let signature = await sendConnection.sendTransaction(addTxn as unknown as VersionedTransaction, {
73+
skipPreflight: true,
74+
preflightCommitment: "confirmed",
75+
maxRetries: 0,
76+
});
77+
console.log(`Waiting to confirm transaction ${signature}`);
7878

79-
// await client.connection.confirmTransaction(
80-
// {
81-
// signature,
82-
// blockhash: latestBlockhash.blockhash,
83-
// lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
84-
// },
85-
// "confirmed",
86-
// );
87-
// console.log(`addLiquidity txn confirmed. View at https://solscan.io/tx/${signature}`);
79+
await client.connection.confirmTransaction(
80+
{
81+
signature,
82+
blockhash: latestBlockhash.blockhash,
83+
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
84+
},
85+
"confirmed",
86+
);
87+
console.log(`addLiquidity txn confirmed. View at https://solscan.io/tx/${signature}`);
8888

8989
latestBlockhash = await client.connection.getLatestBlockhash();
9090
let { transaction: withdrawTxn } = await client.cpmm.withdrawLiquidity({
@@ -107,7 +107,7 @@ async function mainFn(): Promise<void> {
107107
]);
108108

109109
console.log("Sending removeLiquidity transaction");
110-
let signature = await sendConnection.sendTransaction(withdrawTxn as unknown as VersionedTransaction, {
110+
signature = await sendConnection.sendTransaction(withdrawTxn as unknown as VersionedTransaction, {
111111
skipPreflight: false,
112112
preflightCommitment: "confirmed",
113113
maxRetries: 0,

examples/oracle_swap.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { OracleBasedCurveCalculator } from "@/gfx/cpmm/curve/oracleCalculator";
1111
const RPC_URL = process.env.RPC_URL!;
1212
const SEND_RPC_URL = process.env.SEND_RPC_URL ?? RPC_URL;
1313
const KEYPAIR_PATH = process.env.KEYPAIR_PATH!;
14-
const AMOUNT = new BN(process.env.AMOUNT ?? '1_000_000');
14+
const AMOUNT = new BN(process.env.AMOUNT ?? "1_000_000");
1515
const POOL_STATE = new PublicKey(process.env.POOL!);
1616
const MICRO_LAMPORTS = parseInt(process.env.DEFAULT_CU_LAMPORTS ?? "500000");
1717
const SLIPPAGE_BPS = parseInt(process.env.SLIPPAGE_BPS ?? "1000");
@@ -41,14 +41,12 @@ async function mainFn(): Promise<void> {
4141
observationState!,
4242
info.rpcData,
4343
);
44-
console.log("swapResult", swapResult);
45-
44+
console.log(`swapResult: `, swapResult);
4645

4746
const { transaction } = await client.cpmm.swapWithOracle({
4847
poolInfo: info.poolInfo,
4948
poolKeys: info.poolKeys,
5049
zeroForOne: ZERO_FOR_ONE,
51-
inputAmount: AMOUNT,
5250
swapResult,
5351
slippage: SLIPPAGE_BPS / 10_000,
5452
computeBudgetConfig: {

examples/swap.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,21 @@ async function mainFn(): Promise<void> {
3232
const info = await client.cpmm.getPoolInfoFromRpc(POOL_STATE.toBase58());
3333
const observationState = await client.cpmm.getObservationStates([info.rpcData.observationKey]).then((res) => res[0]);
3434

35-
const swapResult = CurveCalculator.swap(
35+
const swapResult = CurveCalculator.swapBaseIn(
3636
AMOUNT,
3737
ZERO_FOR_ONE ? info.rpcData.baseReserve : info.rpcData.quoteReserve,
3838
ZERO_FOR_ONE ? info.rpcData.quoteReserve : info.rpcData.baseReserve,
3939
info.rpcData.configInfo!.tradeFeeRate,
4040
observationState!,
4141
info.rpcData.volatilityFactor,
4242
);
43-
console.log(`swapResult: `, swapResult)
43+
console.log(`swapResult: `, swapResult);
4444

4545
const { transaction } = await client.cpmm.swap({
4646
poolInfo: info.poolInfo,
4747
poolKeys: info.poolKeys,
4848
zeroForOne: ZERO_FOR_ONE,
4949
baseIn: BASE_IN,
50-
inputAmount: AMOUNT,
5150
swapResult,
5251
slippage: SLIPPAGE_BPS / 10_000,
5352
computeBudgetConfig: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
},
4646
"dependencies": {
4747
"@coral-xyz/anchor": "^0.31.1",
48-
"@project-serum/serum": "^0.13.65",
48+
"@project-serum/anchor": "^0.26.0",
4949
"@solana/spl-token": "^0.4.6",
5050
"@solana/web3.js": "^1.91.8",
5151
"axios": "^1.1.3",

src/gfx/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export interface ClientLoadParams extends TokenAccountDataProp, Omit<ClientApiBa
4040
kamino?: {
4141
market?: PublicKey;
4242
programId?: PublicKey;
43-
}
43+
};
4444
}
4545

4646
export interface ClientApiBatchRequestParams {
@@ -72,7 +72,7 @@ export class GfxCpmmClient {
7272
public kamino?: {
7373
market?: PublicKey;
7474
programId?: PublicKey;
75-
}
75+
};
7676

7777
private _connection: Connection;
7878
private _owner: Owner | undefined;

0 commit comments

Comments
 (0)