Skip to content

Commit a627590

Browse files
authored
Merge pull request #24 from GooseFX1/main
Merge pull request #24 from GooseFX1/kamino-profit-stats
2 parents 31a690b + 7c65780 commit a627590

28 files changed

Lines changed: 712 additions & 554 deletions

.prettierrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"arrowParens": "always",
33
"bracketSpacing": true,
4-
"eslintIntegration": true,
54
"overrides": [
65
{
76
"files": ".prettierrc",

examples/api.ts

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,76 @@
1-
import { GfxCpmmClient } from '../src/gfx/index'
2-
import { Connection } from '@solana/web3.js'
1+
import { GfxCpmmClient } from "../src/gfx/index";
2+
import { Connection } from "@solana/web3.js";
33

4-
const GAMMA_CONFIG = '68yDnv1sDzU3L2cek5kNEszKFPaK9yUJaC4ghV5LAXW6'
5-
const POOL_STATE = 'Hjm1F98vgVdN7Y9L46KLqcZZWyTKS9tj9ybYKJcXnSng'
6-
const MINT1 = 'So11111111111111111111111111111111111111112'
7-
const MINT2 = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
4+
const GAMMA_CONFIG = "68yDnv1sDzU3L2cek5kNEszKFPaK9yUJaC4ghV5LAXW6";
5+
const POOL_STATE = "Hjm1F98vgVdN7Y9L46KLqcZZWyTKS9tj9ybYKJcXnSng";
6+
const MINT1 = "So11111111111111111111111111111111111111112";
7+
const MINT2 = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
88

99
async function mainFn(): Promise<void> {
10-
const gfxClient = await GfxCpmmClient.load(
11-
{
12-
connection: new Connection(process.env.RPC_URL ?? 'https://api.mainnet-beta.solana.com'),
13-
disableFeatureCheck: true,
14-
disableLoadToken: true,
15-
urlConfigs: {}
16-
}
17-
)
10+
const gfxClient = await GfxCpmmClient.load({
11+
connection: new Connection(process.env.RPC_URL ?? "https://api.mainnet-beta.solana.com"),
12+
disableFeatureCheck: true,
13+
disableLoadToken: true,
14+
urlConfigs: {},
15+
});
1816

1917
try {
20-
const poolsById = await gfxClient.api.fetchPoolById({ idList: [POOL_STATE] })
21-
console.log(`poolsById: `, poolsById)
22-
} catch(err) {
23-
console.log(`pools-by-id req failed: ${err}`)
18+
const poolsById = await gfxClient.api.fetchPoolById({ idList: [POOL_STATE] });
19+
console.log(`poolsById: `, poolsById);
20+
} catch (err) {
21+
console.log(`pools-by-id req failed: ${err}`);
2422
}
2523

2624
try {
27-
const mint1Pools = await gfxClient.api.fetchPoolByMints({ mint1: MINT1 })
28-
console.log(`mint1Pools: `, mint1Pools)
29-
} catch(err) {
30-
console.log(`pool-by-mints req failed: ${err}`)
25+
const mint1Pools = await gfxClient.api.fetchPoolByMints({ mint1: MINT1 });
26+
console.log(`mint1Pools: `, mint1Pools);
27+
} catch (err) {
28+
console.log(`pool-by-mints req failed: ${err}`);
3129
}
3230

3331
try {
34-
const mint1mint2Pools = await gfxClient.api.fetchPoolByMints({ mint1: MINT1, mint2: MINT2})
35-
console.log(`mint1mint2Pools: `, mint1mint2Pools)
36-
} catch(err) {
37-
console.log(`pool-by-mints2 req failed: ${err}`)
32+
const mint1mint2Pools = await gfxClient.api.fetchPoolByMints({ mint1: MINT1, mint2: MINT2 });
33+
console.log(`mint1mint2Pools: `, mint1mint2Pools);
34+
} catch (err) {
35+
console.log(`pool-by-mints2 req failed: ${err}`);
3836
}
3937

4038
try {
41-
const poolKeys = await gfxClient.api.fetchPoolKeysById({ idList: [POOL_STATE] })
42-
console.log(`poolKeysById: `, poolKeys)
43-
} catch(err) {
44-
console.log(`pool-keys-by-id req failed: ${err}`)
39+
const poolKeys = await gfxClient.api.fetchPoolKeysById({ idList: [POOL_STATE] });
40+
console.log(`poolKeysById: `, poolKeys);
41+
} catch (err) {
42+
console.log(`pool-keys-by-id req failed: ${err}`);
4543
}
4644

4745
try {
48-
const config = await gfxClient.api.getConfig(GAMMA_CONFIG)
49-
console.log(`config: `, config)
50-
} catch(err) {
51-
console.log(`get-config req failed: ${err}`)
46+
const config = await gfxClient.api.getConfig(GAMMA_CONFIG);
47+
console.log(`config: `, config);
48+
} catch (err) {
49+
console.log(`get-config req failed: ${err}`);
5250
}
5351

5452
try {
55-
const poolList = await gfxClient.api.getPoolList()
56-
console.log(`Got ${poolList.pools.length} pools from API`,)
57-
} catch(err) {
58-
console.log(`get-pool-list req failed: ${err}`)
53+
const poolList = await gfxClient.api.getPoolList();
54+
console.log(`Got ${poolList.pools.length} pools from API`);
55+
} catch (err) {
56+
console.log(`get-pool-list req failed: ${err}`);
5957
}
6058

6159
try {
62-
const tokenInfos = await gfxClient.api.getTokenInfo([MINT1, MINT2])
63-
console.log(`tokenInfos: `, tokenInfos)
64-
} catch(err) {
65-
console.log(`get-token-info req failed: ${err}`)
60+
const tokenInfos = await gfxClient.api.getTokenInfo([MINT1, MINT2]);
61+
console.log(`tokenInfos: `, tokenInfos);
62+
} catch (err) {
63+
console.log(`get-token-info req failed: ${err}`);
6664
}
6765

6866
try {
69-
const jupTokenList = await gfxClient.api.getJupTokenList()
70-
console.log(`Got ${jupTokenList.length} tokens from jup token list `)
71-
} catch(err) {
72-
console.log(`get-jup-token-list req failed: ${err}`)
67+
const jupTokenList = await gfxClient.api.getJupTokenList();
68+
console.log(`Got ${jupTokenList.length} tokens from jup token list `);
69+
} catch (err) {
70+
console.log(`get-jup-token-list req failed: ${err}`);
7371
}
7472
}
7573

7674
if (require.main === module) {
77-
mainFn().catch(console.error)
75+
mainFn().catch(console.error);
7876
}

examples/create.ts

Lines changed: 68 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,60 @@
1-
import dotenv from 'dotenv'
2-
dotenv.config()
3-
import { GfxCpmmClient } from '../src/gfx/index'
4-
import fs from 'fs'
5-
import BN from "bn.js"
1+
import dotenv from "dotenv";
2+
dotenv.config();
3+
import { GfxCpmmClient } from "../src/gfx/index";
4+
import fs from "fs";
5+
import BN from "bn.js";
66

7-
import { Connection, Keypair, PublicKey, VersionedTransaction } from '@solana/web3.js'
8-
import { fetchMultipleMintInfos, TxVersion } from "@/common"
7+
import { Connection, Keypair, PublicKey, VersionedTransaction } from "@solana/web3.js";
8+
import { fetchMultipleMintInfos, TxVersion } from "@/common";
99

10-
const RPC_URL = process.env.RPC_URL!
11-
const SEND_RPC_URL = process.env.SEND_RPC_URL ?? RPC_URL
12-
const KEYPAIR_PATH = process.env.KEYPAIR_PATH!
13-
const MINT1 = process.env.MINT1!
14-
const MINT2 = process.env.MINT2!
15-
const MINT1_AMOUNT = parseInt(process.env.MINT1_AMOUNT!)
16-
const MINT2_AMOUNT = parseInt(process.env.MINT2_AMOUNT!)
17-
const GAMMA_CONFIG = new PublicKey(process.env.GAMMA_CONFIG!)
18-
const GAMMA_PROGRAM = new PublicKey(process.env.GAMMA_PROGRAM!)
19-
const GAMMA_POOL_FEE_ACCOUNT = new PublicKey(process.env.GAMMA_POOL_FEE_ACCOUNT!)
20-
const MICRO_LAMPORTS = parseInt(process.env.DEFAULT_CU_LAMPORTS ?? '1200000')
10+
const RPC_URL = process.env.RPC_URL!;
11+
const SEND_RPC_URL = process.env.SEND_RPC_URL ?? RPC_URL;
12+
const KEYPAIR_PATH = process.env.KEYPAIR_PATH!;
13+
const MINT1 = process.env.MINT1!;
14+
const MINT2 = process.env.MINT2!;
15+
const MINT1_AMOUNT = parseInt(process.env.MINT1_AMOUNT!);
16+
const MINT2_AMOUNT = parseInt(process.env.MINT2_AMOUNT!);
17+
const GAMMA_CONFIG = new PublicKey(process.env.GAMMA_CONFIG!);
18+
const GAMMA_PROGRAM = new PublicKey(process.env.GAMMA_PROGRAM!);
19+
const GAMMA_POOL_FEE_ACCOUNT = new PublicKey(process.env.GAMMA_POOL_FEE_ACCOUNT!);
20+
const MICRO_LAMPORTS = parseInt(process.env.DEFAULT_CU_LAMPORTS ?? "1200000");
2121

2222
async function mainFn(): Promise<void> {
23-
const keypair = createKeypairFromFile(KEYPAIR_PATH)
24-
console.log("Pubkey: ", keypair.publicKey.toBase58())
25-
const client = await GfxCpmmClient.load(
26-
{
27-
connection: new Connection(RPC_URL),
28-
disableFeatureCheck: true,
29-
disableLoadToken: true,
30-
urlConfigs: {
31-
BASE_HOST: '',
32-
},
33-
owner: keypair
34-
}
35-
)
23+
const keypair = createKeypairFromFile(KEYPAIR_PATH);
24+
console.log("Pubkey: ", keypair.publicKey.toBase58());
25+
const client = await GfxCpmmClient.load({
26+
connection: new Connection(RPC_URL),
27+
disableFeatureCheck: true,
28+
disableLoadToken: true,
29+
urlConfigs: {
30+
BASE_HOST: "",
31+
},
32+
owner: keypair,
33+
});
3634

3735
const mints = await fetchMultipleMintInfos({
3836
connection: client.connection,
3937
mints: [MINT1, MINT2].map((mint) => new PublicKey(mint)),
4038
config: {
41-
batchRequest: true
42-
}
43-
})
44-
const mint1 = mints[MINT1]
45-
const mint2 = mints[MINT2]
46-
const feeConfig = await client.api.getConfig(GAMMA_CONFIG.toBase58())
39+
batchRequest: true,
40+
},
41+
});
42+
const mint1 = mints[MINT1];
43+
const mint2 = mints[MINT2];
44+
const feeConfig = await client.api.getConfig(GAMMA_CONFIG.toBase58());
4745

4846
let { transaction } = await client.cpmm.createPool({
4947
programId: GAMMA_PROGRAM,
5048
poolFeeAccount: GAMMA_POOL_FEE_ACCOUNT,
5149
mintA: {
5250
...mint1,
5351
address: mint1.address.toBase58(),
54-
programId: mint1.programId.toBase58()
52+
programId: mint1.programId.toBase58(),
5553
},
5654
mintB: {
5755
...mint2,
5856
address: mint2.address.toBase58(),
59-
programId: mint2.programId.toBase58()
57+
programId: mint2.programId.toBase58(),
6058
},
6159
mintAAmount: new BN(MINT1_AMOUNT),
6260
mintBAmount: new BN(MINT2_AMOUNT),
@@ -67,49 +65,49 @@ async function mainFn(): Promise<void> {
6765
associatedOnly: true,
6866
checkCreateATAOwner: false,
6967
ownerInfo: {
70-
useSOLBalance: true
68+
useSOLBalance: true,
7169
},
7270
computeBudgetConfig: {
7371
units: 200000,
74-
microLamports: MICRO_LAMPORTS
72+
microLamports: MICRO_LAMPORTS,
7573
},
76-
txVersion: TxVersion.V0
77-
})
78-
79-
const latestBlockhash = await client.connection.getLatestBlockhash()
80-
transaction.message.recentBlockhash = latestBlockhash.blockhash
81-
transaction.sign([{
82-
publicKey: keypair.publicKey,
83-
secretKey: keypair.secretKey
84-
}])
74+
txVersion: TxVersion.V0,
75+
});
8576

86-
console.log("Sending createPool transaction")
87-
const signature = await new Connection(SEND_RPC_URL).sendTransaction(
88-
transaction as unknown as VersionedTransaction,
77+
const latestBlockhash = await client.connection.getLatestBlockhash();
78+
transaction.message.recentBlockhash = latestBlockhash.blockhash;
79+
transaction.sign([
8980
{
90-
skipPreflight: true,
91-
preflightCommitment: 'confirmed',
92-
maxRetries: 0,
93-
}
94-
)
95-
console.log(`Waiting to confirm transaction ${signature}`)
81+
publicKey: keypair.publicKey,
82+
secretKey: keypair.secretKey,
83+
},
84+
]);
85+
86+
console.log("Sending createPool transaction");
87+
const signature = await new Connection(SEND_RPC_URL).sendTransaction(transaction as unknown as VersionedTransaction, {
88+
skipPreflight: true,
89+
preflightCommitment: "confirmed",
90+
maxRetries: 0,
91+
});
92+
console.log(`Waiting to confirm transaction ${signature}`);
9693

97-
await client.connection.confirmTransaction({
98-
signature,
99-
blockhash: latestBlockhash.blockhash,
100-
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight
101-
}, 'confirmed')
102-
console.log(`createPool txn confirmed. View at https://solscan.io/tx/${signature}`)
94+
await client.connection.confirmTransaction(
95+
{
96+
signature,
97+
blockhash: latestBlockhash.blockhash,
98+
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
99+
},
100+
"confirmed",
101+
);
102+
console.log(`createPool txn confirmed. View at https://solscan.io/tx/${signature}`);
103103
}
104104

105-
export function createKeypairFromFile(
106-
filePath: string
107-
): Keypair {
108-
const secretKeyString = fs.readFileSync(filePath, {encoding: 'utf8'});
105+
export function createKeypairFromFile(filePath: string): Keypair {
106+
const secretKeyString = fs.readFileSync(filePath, { encoding: "utf8" });
109107
const secretKey = Uint8Array.from(JSON.parse(secretKeyString));
110108
return Keypair.fromSecretKey(secretKey);
111109
}
112110

113111
if (require.main === module) {
114-
mainFn().catch(console.error)
112+
mainFn().catch(console.error);
115113
}

0 commit comments

Comments
 (0)