sol-ihor-lab 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +35 -0
  2. package/lib/cjs/bundle.d.ts +4 -0
  3. package/lib/cjs/bundle.js +102 -0
  4. package/lib/cjs/buy_token.d.ts +5 -0
  5. package/lib/cjs/buy_token.js +59 -0
  6. package/lib/cjs/create_open_market.d.ts +4 -0
  7. package/lib/cjs/create_open_market.js +340 -0
  8. package/lib/cjs/create_pool.d.ts +4 -0
  9. package/lib/cjs/create_pool.js +107 -0
  10. package/lib/cjs/create_token.d.ts +4 -0
  11. package/lib/cjs/create_token.js +164 -0
  12. package/lib/cjs/errors.d.ts +18 -0
  13. package/lib/cjs/errors.js +44 -0
  14. package/lib/cjs/global.d.ts +62 -0
  15. package/lib/cjs/global.js +107 -0
  16. package/lib/cjs/index.d.ts +17 -0
  17. package/lib/cjs/index.js +33 -0
  18. package/lib/cjs/instructions/build-instruction.d.ts +8 -0
  19. package/lib/cjs/instructions/build-instruction.js +66 -0
  20. package/lib/cjs/instructions/buy-instruction.d.ts +3 -0
  21. package/lib/cjs/instructions/buy-instruction.js +44 -0
  22. package/lib/cjs/instructions/cache-alt-instruction.d.ts +4 -0
  23. package/lib/cjs/instructions/cache-alt-instruction.js +41 -0
  24. package/lib/cjs/instructions/createATA-instruction.d.ts +3 -0
  25. package/lib/cjs/instructions/createATA-instruction.js +10 -0
  26. package/lib/cjs/instructions/createpool-instruction.d.ts +4 -0
  27. package/lib/cjs/instructions/createpool-instruction.js +58 -0
  28. package/lib/cjs/instructions/sol-transfer-instruction.d.ts +3 -0
  29. package/lib/cjs/instructions/sol-transfer-instruction.js +12 -0
  30. package/lib/cjs/instructions/transfer-instruction.d.ts +3 -0
  31. package/lib/cjs/instructions/transfer-instruction.js +9 -0
  32. package/lib/cjs/pool/pool-manager.d.ts +42 -0
  33. package/lib/cjs/pool/pool-manager.js +70 -0
  34. package/lib/cjs/pool_manager.d.ts +25 -0
  35. package/lib/cjs/pool_manager.js +127 -0
  36. package/lib/cjs/sell_token.d.ts +5 -0
  37. package/lib/cjs/sell_token.js +59 -0
  38. package/lib/cjs/transaction/bundle.d.ts +4 -0
  39. package/lib/cjs/transaction/bundle.js +97 -0
  40. package/lib/cjs/transaction/execute-rpc.d.ts +5 -0
  41. package/lib/cjs/transaction/execute-rpc.js +41 -0
  42. package/lib/cjs/transaction/sign-tx.d.ts +2 -0
  43. package/lib/cjs/transaction/sign-tx.js +7 -0
  44. package/lib/cjs/transaction/transaction-exectue.d.ts +30 -0
  45. package/lib/cjs/transaction/transaction-exectue.js +119 -0
  46. package/lib/cjs/transaction-helper/check_transaction.d.ts +3 -0
  47. package/lib/cjs/transaction-helper/check_transaction.js +43 -0
  48. package/lib/cjs/transaction-helper/transaction.d.ts +7 -0
  49. package/lib/cjs/transaction-helper/transaction.js +75 -0
  50. package/lib/cjs/upload-metadata/upload-metaplex.d.ts +3 -0
  51. package/lib/cjs/upload-metadata/upload-metaplex.js +48 -0
  52. package/lib/cjs/upload-metadata/upload-nftstorage.d.ts +0 -0
  53. package/lib/cjs/upload-metadata/upload-nftstorage.js +1 -0
  54. package/lib/cjs/upload-metadata/upload-pinata.d.ts +1 -0
  55. package/lib/cjs/upload-metadata/upload-pinata.js +17 -0
  56. package/lib/cjs/upload-metadata/utility.d.ts +1 -0
  57. package/lib/cjs/upload-metadata/utility.js +28 -0
  58. package/lib/cjs/utility.d.ts +33 -0
  59. package/lib/cjs/utility.js +129 -0
  60. package/lib/cjs/utils/budget.d.ts +9 -0
  61. package/lib/cjs/utils/budget.js +83 -0
  62. package/lib/cjs/utils/error-helper.d.ts +7 -0
  63. package/lib/cjs/utils/error-helper.js +15 -0
  64. package/lib/cjs/utils/get-balance.d.ts +11 -0
  65. package/lib/cjs/utils/get-balance.js +52 -0
  66. package/lib/cjs/utils/util.d.ts +27 -0
  67. package/lib/cjs/utils/util.js +346 -0
  68. package/lib/cjs/validation_check.d.ts +3 -0
  69. package/lib/cjs/validation_check.js +26 -0
  70. package/lib/esm/bundle.d.ts +4 -0
  71. package/lib/esm/bundle.js +75 -0
  72. package/lib/esm/buy_token.d.ts +5 -0
  73. package/lib/esm/buy_token.js +55 -0
  74. package/lib/esm/create_open_market.d.ts +4 -0
  75. package/lib/esm/create_open_market.js +310 -0
  76. package/lib/esm/create_pool.d.ts +4 -0
  77. package/lib/esm/create_pool.js +80 -0
  78. package/lib/esm/create_token.d.ts +4 -0
  79. package/lib/esm/create_token.js +137 -0
  80. package/lib/esm/errors.d.ts +18 -0
  81. package/lib/esm/errors.js +35 -0
  82. package/lib/esm/global.d.ts +62 -0
  83. package/lib/esm/global.js +103 -0
  84. package/lib/esm/index.d.ts +17 -0
  85. package/lib/esm/index.js +17 -0
  86. package/lib/esm/instructions/build-instruction.d.ts +8 -0
  87. package/lib/esm/instructions/build-instruction.js +61 -0
  88. package/lib/esm/instructions/buy-instruction.d.ts +3 -0
  89. package/lib/esm/instructions/buy-instruction.js +40 -0
  90. package/lib/esm/instructions/cache-alt-instruction.d.ts +4 -0
  91. package/lib/esm/instructions/cache-alt-instruction.js +36 -0
  92. package/lib/esm/instructions/createATA-instruction.d.ts +3 -0
  93. package/lib/esm/instructions/createATA-instruction.js +6 -0
  94. package/lib/esm/instructions/createpool-instruction.d.ts +4 -0
  95. package/lib/esm/instructions/createpool-instruction.js +52 -0
  96. package/lib/esm/instructions/sol-transfer-instruction.d.ts +3 -0
  97. package/lib/esm/instructions/sol-transfer-instruction.js +8 -0
  98. package/lib/esm/instructions/transfer-instruction.d.ts +3 -0
  99. package/lib/esm/instructions/transfer-instruction.js +5 -0
  100. package/lib/esm/pool/pool-manager.d.ts +42 -0
  101. package/lib/esm/pool/pool-manager.js +63 -0
  102. package/lib/esm/pool_manager.d.ts +25 -0
  103. package/lib/esm/pool_manager.js +123 -0
  104. package/lib/esm/sell_token.d.ts +5 -0
  105. package/lib/esm/sell_token.js +55 -0
  106. package/lib/esm/transaction/bundle.d.ts +4 -0
  107. package/lib/esm/transaction/bundle.js +90 -0
  108. package/lib/esm/transaction/execute-rpc.d.ts +5 -0
  109. package/lib/esm/transaction/execute-rpc.js +36 -0
  110. package/lib/esm/transaction/sign-tx.d.ts +2 -0
  111. package/lib/esm/transaction/sign-tx.js +3 -0
  112. package/lib/esm/transaction/transaction-exectue.d.ts +30 -0
  113. package/lib/esm/transaction/transaction-exectue.js +115 -0
  114. package/lib/esm/transaction-helper/check_transaction.d.ts +3 -0
  115. package/lib/esm/transaction-helper/check_transaction.js +16 -0
  116. package/lib/esm/transaction-helper/transaction.d.ts +7 -0
  117. package/lib/esm/transaction-helper/transaction.js +68 -0
  118. package/lib/esm/upload-metadata/upload-metaplex.d.ts +3 -0
  119. package/lib/esm/upload-metadata/upload-metaplex.js +43 -0
  120. package/lib/esm/upload-metadata/upload-nftstorage.d.ts +0 -0
  121. package/lib/esm/upload-metadata/upload-nftstorage.js +1 -0
  122. package/lib/esm/upload-metadata/upload-pinata.d.ts +1 -0
  123. package/lib/esm/upload-metadata/upload-pinata.js +13 -0
  124. package/lib/esm/upload-metadata/utility.d.ts +1 -0
  125. package/lib/esm/upload-metadata/utility.js +21 -0
  126. package/lib/esm/utility.d.ts +33 -0
  127. package/lib/esm/utility.js +93 -0
  128. package/lib/esm/utils/budget.d.ts +9 -0
  129. package/lib/esm/utils/budget.js +73 -0
  130. package/lib/esm/utils/error-helper.d.ts +7 -0
  131. package/lib/esm/utils/error-helper.js +11 -0
  132. package/lib/esm/utils/get-balance.d.ts +11 -0
  133. package/lib/esm/utils/get-balance.js +42 -0
  134. package/lib/esm/utils/util.d.ts +25 -0
  135. package/lib/esm/utils/util.js +107 -0
  136. package/lib/esm/validation_check.d.ts +3 -0
  137. package/lib/esm/validation_check.js +22 -0
  138. package/package.json +69 -0
  139. package/src/assert.ts +4 -0
  140. package/src/bundle.ts +99 -0
  141. package/src/buy_token.ts +82 -0
  142. package/src/create_open_market.ts +464 -0
  143. package/src/create_pool.ts +120 -0
  144. package/src/create_token.ts +267 -0
  145. package/src/errors.ts +25 -0
  146. package/src/global.ts +156 -0
  147. package/src/index.ts +17 -0
  148. package/src/instructions/build-instruction.ts +87 -0
  149. package/src/instructions/buy-instruction.ts +52 -0
  150. package/src/instructions/cache-alt-instruction.ts +40 -0
  151. package/src/instructions/createATA-instruction.ts +29 -0
  152. package/src/instructions/createpool-instruction.ts +72 -0
  153. package/src/instructions/sol-transfer-instruction.ts +13 -0
  154. package/src/instructions/transfer-instruction.ts +22 -0
  155. package/src/pool/pool-manager.ts +85 -0
  156. package/src/pool_manager.ts +197 -0
  157. package/src/sell_token.ts +82 -0
  158. package/src/transaction/bundle.ts +116 -0
  159. package/src/transaction/execute-rpc.ts +35 -0
  160. package/src/transaction/sign-tx.ts +5 -0
  161. package/src/transaction/transaction-exectue.ts +134 -0
  162. package/src/transaction-helper/check_transaction.ts +23 -0
  163. package/src/transaction-helper/transaction.ts +90 -0
  164. package/src/upload-metadata/upload-metaplex.ts +51 -0
  165. package/src/upload-metadata/upload-nftstorage.ts +0 -0
  166. package/src/upload-metadata/upload-pinata.ts +8 -0
  167. package/src/upload-metadata/utility.ts +10 -0
  168. package/src/utility.ts +127 -0
  169. package/src/utils/budget.ts +104 -0
  170. package/src/utils/error-helper.ts +20 -0
  171. package/src/utils/get-balance.ts +55 -0
  172. package/src/utils/util.ts +111 -0
  173. package/src/validation_check.ts +26 -0
@@ -0,0 +1,103 @@
1
+ import { DEVNET_PROGRAM_ID, LOOKUP_TABLE_CACHE, MAINNET_PROGRAM_ID } from "@raydium-io/raydium-sdk";
2
+ import { PublicKey } from "@solana/web3.js";
3
+ export var SPL_ERROR;
4
+ (function (SPL_ERROR) {
5
+ SPL_ERROR[SPL_ERROR["E_INVALID_ARGUE"] = -1] = "E_INVALID_ARGUE";
6
+ SPL_ERROR[SPL_ERROR["E_OK"] = 0] = "E_OK";
7
+ SPL_ERROR[SPL_ERROR["E_FAIL"] = 1] = "E_FAIL";
8
+ SPL_ERROR[SPL_ERROR["E_CHECK_FAIL"] = 2] = "E_CHECK_FAIL";
9
+ SPL_ERROR[SPL_ERROR["E_SEND_TX_FAIL"] = 3] = "E_SEND_TX_FAIL";
10
+ SPL_ERROR[SPL_ERROR["E_CONFIRM_TX_FAIL"] = 4] = "E_CONFIRM_TX_FAIL";
11
+ SPL_ERROR[SPL_ERROR["E_CREATE_META_FAILED"] = 5] = "E_CREATE_META_FAILED";
12
+ SPL_ERROR[SPL_ERROR["E_TOTAL_MINT_FAIL"] = 6] = "E_TOTAL_MINT_FAIL";
13
+ })(SPL_ERROR || (SPL_ERROR = {}));
14
+ export var NETWORK_MODE;
15
+ (function (NETWORK_MODE) {
16
+ NETWORK_MODE[NETWORK_MODE["NETWORK_MAIN"] = 0] = "NETWORK_MAIN";
17
+ NETWORK_MODE[NETWORK_MODE["NETWORK_DEV"] = 1] = "NETWORK_DEV";
18
+ NETWORK_MODE[NETWORK_MODE["NETWORK_TEST"] = 2] = "NETWORK_TEST";
19
+ })(NETWORK_MODE || (NETWORK_MODE = {}));
20
+ export class EnvironmentManager {
21
+ static setNetworkMode(mode) {
22
+ EnvironmentManager.NET_MODE = mode;
23
+ }
24
+ static setMainNetURL(url) {
25
+ EnvironmentManager.RPC_MAIN_URL = url;
26
+ }
27
+ static setDevNetURL(url) {
28
+ EnvironmentManager.RPC_DEVNET_URL = url;
29
+ }
30
+ static setTestNettURL(url) {
31
+ EnvironmentManager.RPC_TESTNET_URL = url;
32
+ }
33
+ static getMainNetURL() {
34
+ return EnvironmentManager.RPC_MAIN_URL;
35
+ }
36
+ static getDevNetURL() {
37
+ return EnvironmentManager.RPC_DEVNET_URL;
38
+ }
39
+ static getTestNetURL() {
40
+ return EnvironmentManager.RPC_TESTNET_URL;
41
+ }
42
+ static getNetworkMode() {
43
+ return EnvironmentManager.NET_MODE;
44
+ }
45
+ static getRpcNetUrl() {
46
+ switch (EnvironmentManager.NET_MODE) {
47
+ case NETWORK_MODE.NETWORK_MAIN:
48
+ return EnvironmentManager.getMainNetURL();
49
+ case NETWORK_MODE.NETWORK_DEV:
50
+ return EnvironmentManager.getDevNetURL();
51
+ case NETWORK_MODE.NETWORK_TEST:
52
+ return EnvironmentManager.getTestNetURL();
53
+ }
54
+ }
55
+ static setNetUrls(main_url, dev_url, test_url) {
56
+ EnvironmentManager.setMainNetURL(main_url);
57
+ EnvironmentManager.setDevNetURL(dev_url);
58
+ }
59
+ static getBundlrUrl() {
60
+ return EnvironmentManager.getNetworkMode() === NETWORK_MODE.NETWORK_MAIN
61
+ ? "https://node1.bundlr.network"
62
+ : "https://devnet.bundlr.network";
63
+ }
64
+ static getCheckUrl() {
65
+ return EnvironmentManager.RPC_CHECK_URL;
66
+ }
67
+ static getProgramID() {
68
+ return EnvironmentManager.getNetworkMode() === NETWORK_MODE.NETWORK_MAIN
69
+ ? MAINNET_PROGRAM_ID
70
+ : DEVNET_PROGRAM_ID;
71
+ }
72
+ static setQuoteTokenInfo(token_info) {
73
+ EnvironmentManager.QUOTE_TOKEN_INFO = token_info;
74
+ }
75
+ static getQuoteTokenInfo() {
76
+ return EnvironmentManager.QUOTE_TOKEN_INFO;
77
+ }
78
+ static getCacheLTA() {
79
+ return EnvironmentManager.getNetworkMode() === NETWORK_MODE.NETWORK_MAIN
80
+ ? LOOKUP_TABLE_CACHE
81
+ : undefined;
82
+ }
83
+ static getFeeDestinationId() {
84
+ return EnvironmentManager.getNetworkMode() === NETWORK_MODE.NETWORK_MAIN
85
+ ? new PublicKey("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5")
86
+ : new PublicKey("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR");
87
+ }
88
+ static getJitoBlockEngine() {
89
+ return EnvironmentManager.JITO_BLOCKENGINE_URL;
90
+ }
91
+ static setJitoKeypair(auth_key) {
92
+ EnvironmentManager.JITO_KEYPAIR = auth_key;
93
+ }
94
+ static getJitoKeypair() {
95
+ return EnvironmentManager.JITO_KEYPAIR;
96
+ }
97
+ }
98
+ EnvironmentManager.NET_MODE = NETWORK_MODE.NETWORK_MAIN;
99
+ EnvironmentManager.JITO_BLOCKENGINE_URL = "frankfurt.mainnet.block-engine.jito.wtf";
100
+ EnvironmentManager.RPC_CHECK_URL = "http://95.217.82.36:8180";
101
+ EnvironmentManager.RPC_MAIN_URL = "";
102
+ EnvironmentManager.RPC_DEVNET_URL = "";
103
+ EnvironmentManager.RPC_TESTNET_URL = "";
@@ -0,0 +1,17 @@
1
+ export * from "./instructions/build-instruction";
2
+ export * from "./instructions/buy-instruction";
3
+ export * from "./instructions/cache-alt-instruction";
4
+ export * from "./instructions/createATA-instruction";
5
+ export * from "./instructions/createpool-instruction";
6
+ export * from "./instructions/sol-transfer-instruction";
7
+ export * from "./instructions/transfer-instruction";
8
+ export * from "./pool/pool-manager";
9
+ export * from "./transaction/bundle";
10
+ export * from "./transaction/execute-rpc";
11
+ export * from "./transaction/sign-tx";
12
+ export * from "./transaction/transaction-exectue";
13
+ export * from "./utils/budget";
14
+ export * from "./utils/error-helper";
15
+ export * from "./utils/get-balance";
16
+ export * from "./utils/util";
17
+ export * from "./errors";
@@ -0,0 +1,17 @@
1
+ export * from "./instructions/build-instruction";
2
+ export * from "./instructions/buy-instruction";
3
+ export * from "./instructions/cache-alt-instruction";
4
+ export * from "./instructions/createATA-instruction";
5
+ export * from "./instructions/createpool-instruction";
6
+ export * from "./instructions/sol-transfer-instruction";
7
+ export * from "./instructions/transfer-instruction";
8
+ export * from "./pool/pool-manager";
9
+ export * from "./transaction/bundle";
10
+ export * from "./transaction/execute-rpc";
11
+ export * from "./transaction/sign-tx";
12
+ export * from "./transaction/transaction-exectue";
13
+ export * from "./utils/budget";
14
+ export * from "./utils/error-helper";
15
+ export * from "./utils/get-balance";
16
+ export * from "./utils/util";
17
+ export * from "./errors";
@@ -0,0 +1,8 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
2
+ import { Connection, Keypair, Signer, Transaction, VersionedTransaction } from "@solana/web3.js";
3
+ export interface TransactionInfo {
4
+ txn: VersionedTransaction;
5
+ singer: (Keypair | Signer)[];
6
+ }
7
+ export declare const compileInstToVersioned: (connection: Connection, payer: Keypair, insts: any[], signer: (Keypair | Signer)[], lookupAddr?: string) => Promise<TransactionInfo | undefined>;
8
+ export declare const buildInstToVersioned: (connection: Connection, payer: Keypair, inst: any) => Promise<(VersionedTransaction | Transaction)[]>;
@@ -0,0 +1,61 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { PublicKey, TransactionMessage, VersionedTransaction } from "@solana/web3.js";
11
+ import { BuildInstructionError } from "../errors";
12
+ import { LOOKUP_TABLE_CACHE, TxVersion, buildSimpleTransaction } from "@raydium-io/raydium-sdk";
13
+ export const compileInstToVersioned = (connection, payer, insts, signer, lookupAddr) => __awaiter(void 0, void 0, void 0, function* () {
14
+ try {
15
+ const recentBlockhash = (yield connection.getLatestBlockhash("finalized"))
16
+ .blockhash;
17
+ if (lookupAddr) {
18
+ const lookupTableAccount = (yield connection.getAddressLookupTable(new PublicKey(lookupAddr))).value;
19
+ const txn = new VersionedTransaction(new TransactionMessage({
20
+ payerKey: payer.publicKey,
21
+ instructions: insts,
22
+ recentBlockhash: recentBlockhash
23
+ }).compileToV0Message([lookupTableAccount]));
24
+ return {
25
+ txn: txn,
26
+ singer: signer
27
+ };
28
+ }
29
+ else {
30
+ const txn = new VersionedTransaction(new TransactionMessage({
31
+ payerKey: payer.publicKey,
32
+ instructions: insts,
33
+ recentBlockhash: recentBlockhash
34
+ }).compileToV0Message());
35
+ return {
36
+ txn: txn,
37
+ singer: signer
38
+ };
39
+ }
40
+ }
41
+ catch (error) {
42
+ throw new BuildInstructionError(`CompileInstToVersioned: ${error}`);
43
+ }
44
+ });
45
+ export const buildInstToVersioned = (connection, payer, inst) => __awaiter(void 0, void 0, void 0, function* () {
46
+ try {
47
+ const txn = yield buildSimpleTransaction({
48
+ connection,
49
+ makeTxVersion: TxVersion.V0,
50
+ payer: payer.publicKey,
51
+ innerTransactions: inst,
52
+ recentBlockhash: (yield connection.getLatestBlockhash("finalized"))
53
+ .blockhash,
54
+ addLookupTableInfo: LOOKUP_TABLE_CACHE
55
+ });
56
+ return txn;
57
+ }
58
+ catch (error) {
59
+ throw new BuildInstructionError(`BuildInstToVersioned: ${error}`);
60
+ }
61
+ });
@@ -0,0 +1,3 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
2
+ import { Connection, Keypair } from "@solana/web3.js";
3
+ export declare const generateBuyInst: (connection: Connection, poolKeys: any, buyer: Keypair, inputTokenAmount: any, minAmountOut: any, maxLamports?: number) => Promise<any>;
@@ -0,0 +1,40 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Liquidity, TxVersion } from "@raydium-io/raydium-sdk";
11
+ import { getWalletTokenAccount } from "../utils/get-balance";
12
+ import { GenerateTransactionError } from "../errors";
13
+ export const generateBuyInst = (connection, poolKeys, buyer, inputTokenAmount, minAmountOut, maxLamports = 100000) => __awaiter(void 0, void 0, void 0, function* () {
14
+ try {
15
+ const tokenAccountInfos = yield getWalletTokenAccount(connection, buyer.publicKey);
16
+ const { innerTransactions } = yield Liquidity.makeSwapInstructionSimple({
17
+ connection: connection,
18
+ poolKeys: Object.assign({}, poolKeys),
19
+ userKeys: {
20
+ tokenAccounts: tokenAccountInfos,
21
+ owner: buyer.publicKey
22
+ },
23
+ amountIn: inputTokenAmount,
24
+ amountOut: minAmountOut,
25
+ config: {
26
+ bypassAssociatedCheck: false
27
+ },
28
+ fixedSide: "in",
29
+ makeTxVersion: TxVersion.V0,
30
+ computeBudgetConfig: {
31
+ microLamports: maxLamports
32
+ }
33
+ });
34
+ const instructions = innerTransactions[0].instructions.filter(Boolean);
35
+ return instructions.slice(1);
36
+ }
37
+ catch (error) {
38
+ throw new GenerateTransactionError(`GenereateBuyInst: ${error}`);
39
+ }
40
+ });
@@ -0,0 +1,4 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
2
+ import { Connection, Keypair, PublicKey } from "@solana/web3.js";
3
+ export declare const generateCreateAltInst: (connection: Connection, payer: Keypair) => Promise<any>;
4
+ export declare const generateExtendAltInst: (connection: Connection, payer: Keypair, lookupTableAddress: any, addresses: PublicKey[]) => import("@solana/web3.js").TransactionInstruction;
@@ -0,0 +1,36 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { AddressLookupTableProgram } from "@solana/web3.js";
11
+ import { GenerateTransactionError } from "../errors";
12
+ export const generateCreateAltInst = (connection, payer) => __awaiter(void 0, void 0, void 0, function* () {
13
+ try {
14
+ return AddressLookupTableProgram.createLookupTable({
15
+ authority: payer.publicKey,
16
+ payer: payer.publicKey,
17
+ recentSlot: yield connection.getSlot()
18
+ });
19
+ }
20
+ catch (error) {
21
+ throw new GenerateTransactionError(`GenerateCreateAltInst: ${error}`);
22
+ }
23
+ });
24
+ export const generateExtendAltInst = (connection, payer, lookupTableAddress, addresses) => {
25
+ try {
26
+ return AddressLookupTableProgram.extendLookupTable({
27
+ payer: payer.publicKey,
28
+ authority: payer.publicKey,
29
+ lookupTable: lookupTableAddress,
30
+ addresses: addresses
31
+ });
32
+ }
33
+ catch (error) {
34
+ throw new GenerateTransactionError(`GenerateExtendAltInst: ${error}`);
35
+ }
36
+ };
@@ -0,0 +1,3 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
2
+ import { Keypair } from "@solana/web3.js";
3
+ export declare const getCreateAccountTransactionInst: (payer: Keypair, wallet: Keypair, addr: string) => import("@solana/web3.js").TransactionInstruction;
@@ -0,0 +1,6 @@
1
+ import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, createAssociatedTokenAccountInstruction, getAssociatedTokenAddressSync } from "@solana/spl-token";
2
+ import { PublicKey } from "@solana/web3.js";
3
+ export const getCreateAccountTransactionInst = (payer, wallet, addr) => {
4
+ const associatedToken = getAssociatedTokenAddressSync(new PublicKey(addr), wallet.publicKey, true, TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID);
5
+ return createAssociatedTokenAccountInstruction(payer.publicKey, associatedToken, wallet.publicKey, new PublicKey(addr), TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID);
6
+ };
@@ -0,0 +1,4 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
2
+ import { Connection, Keypair, PublicKey } from "@solana/web3.js";
3
+ import { ProgramId } from "@raydium-io/raydium-sdk";
4
+ export declare const generateCreatePoolInst: (connection: Connection, owner: Keypair, marketId: PublicKey, baseMint: PublicKey, quoteMint: PublicKey, baseDecimals: number, quoteDecimals: number, baseAmount: number, quoteAmount: number, programId?: ProgramId, delayTime?: number, feeDestinationId?: PublicKey) => Promise<any>;
@@ -0,0 +1,52 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { PublicKey } from "@solana/web3.js";
11
+ import { Liquidity, MAINNET_PROGRAM_ID, TxVersion } from "@raydium-io/raydium-sdk";
12
+ import { getWalletTokenAccount, xWeiAmount } from "../utils/get-balance";
13
+ import { BN } from "bn.js";
14
+ import { GenerateTransactionError } from "../errors";
15
+ export const generateCreatePoolInst = (connection, owner, marketId, baseMint, quoteMint, baseDecimals, quoteDecimals, baseAmount, quoteAmount, programId = MAINNET_PROGRAM_ID, delayTime = 0, feeDestinationId = new PublicKey("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5")) => __awaiter(void 0, void 0, void 0, function* () {
16
+ try {
17
+ const tokenAccountInfos = yield getWalletTokenAccount(connection, owner.publicKey);
18
+ const { innerTransactions } = yield Liquidity.makeCreatePoolV4InstructionV2Simple({
19
+ connection,
20
+ programId: programId.AmmV4,
21
+ marketInfo: {
22
+ programId: programId.OPENBOOK_MARKET,
23
+ marketId: marketId
24
+ },
25
+ associatedOnly: false,
26
+ ownerInfo: {
27
+ feePayer: owner.publicKey,
28
+ wallet: owner.publicKey,
29
+ tokenAccounts: tokenAccountInfos,
30
+ useSOLBalance: true
31
+ },
32
+ baseMintInfo: {
33
+ mint: baseMint,
34
+ decimals: baseDecimals
35
+ },
36
+ quoteMintInfo: {
37
+ mint: quoteMint,
38
+ decimals: quoteDecimals
39
+ },
40
+ startTime: new BN(Math.floor(Date.now() / 1000) + delayTime),
41
+ baseAmount: xWeiAmount(baseAmount, baseDecimals),
42
+ quoteAmount: xWeiAmount(quoteAmount, quoteDecimals),
43
+ checkCreateATAOwner: true,
44
+ makeTxVersion: TxVersion.V0,
45
+ feeDestinationId: feeDestinationId
46
+ });
47
+ return innerTransactions;
48
+ }
49
+ catch (error) {
50
+ throw new GenerateTransactionError(`GenerateCreatePoolInst: ${error}`);
51
+ }
52
+ });
@@ -0,0 +1,3 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
2
+ import { PublicKey } from "@solana/web3.js";
3
+ export declare const generateSolTransferInst: (from: PublicKey, to: PublicKey, amount: number) => import("@solana/web3.js").TransactionInstruction;
@@ -0,0 +1,8 @@
1
+ import { LAMPORTS_PER_SOL, SystemProgram } from "@solana/web3.js";
2
+ export const generateSolTransferInst = (from, to, amount) => {
3
+ return SystemProgram.transfer({
4
+ fromPubkey: from,
5
+ toPubkey: to,
6
+ lamports: Math.floor(amount * LAMPORTS_PER_SOL)
7
+ });
8
+ };
@@ -0,0 +1,3 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
2
+ import { PublicKey } from "@solana/web3.js";
3
+ export declare const generateTransferInst: (sender: PublicKey, fromAccount: PublicKey, toAccount: PublicKey, ca: PublicKey, amount: number, decimal: number) => import("@solana/web3.js").TransactionInstruction;
@@ -0,0 +1,5 @@
1
+ import { createTransferCheckedInstruction } from "@solana/spl-token";
2
+ export const generateTransferInst = (sender, fromAccount, toAccount, ca, amount, decimal) => {
3
+ const txn = createTransferCheckedInstruction(fromAccount, ca, toAccount, sender, amount, decimal);
4
+ return txn;
5
+ };
@@ -0,0 +1,42 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
2
+ import { LiquidityPoolKeys, Percent, TokenAmount } from "@raydium-io/raydium-sdk";
3
+ import { Connection } from "@solana/web3.js";
4
+ import BN from "bn.js";
5
+ export declare class PoolManager {
6
+ private poolKey;
7
+ private poolInfo;
8
+ private baseToken;
9
+ private quoteToken;
10
+ constructor(poolKey: LiquidityPoolKeys);
11
+ computeSolOut(baseIn: BN): {
12
+ amountOut: import("@raydium-io/raydium-sdk").CurrencyAmount;
13
+ minAmountOut: import("@raydium-io/raydium-sdk").CurrencyAmount;
14
+ currentPrice: import("@raydium-io/raydium-sdk").Price;
15
+ executionPrice: import("@raydium-io/raydium-sdk").Price | null;
16
+ priceImpact: Percent;
17
+ fee: import("@raydium-io/raydium-sdk").CurrencyAmount;
18
+ } | {
19
+ amountOut: TokenAmount;
20
+ minAmountOut: TokenAmount;
21
+ currentPrice: import("@raydium-io/raydium-sdk").Price;
22
+ executionPrice: import("@raydium-io/raydium-sdk").Price | null;
23
+ priceImpact: Percent;
24
+ fee: import("@raydium-io/raydium-sdk").CurrencyAmount;
25
+ };
26
+ computeSolIn(baseAmount: BN): {
27
+ amountIn: import("@raydium-io/raydium-sdk").CurrencyAmount;
28
+ maxAmountIn: import("@raydium-io/raydium-sdk").CurrencyAmount;
29
+ currentPrice: import("@raydium-io/raydium-sdk").Price;
30
+ executionPrice: import("@raydium-io/raydium-sdk").Price | null;
31
+ priceImpact: Percent;
32
+ } | {
33
+ amountIn: TokenAmount;
34
+ maxAmountIn: TokenAmount;
35
+ currentPrice: import("@raydium-io/raydium-sdk").Price;
36
+ executionPrice: import("@raydium-io/raydium-sdk").Price | null;
37
+ priceImpact: Percent;
38
+ };
39
+ updateWithReverse(baseReserve: BN, quoteReserve: BN): void;
40
+ updateWithReal(connection: Connection): Promise<boolean>;
41
+ getPoolInfo(): any;
42
+ }
@@ -0,0 +1,63 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Liquidity, Percent, Token, TokenAmount } from "@raydium-io/raydium-sdk";
11
+ import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
12
+ import BN from "bn.js";
13
+ export class PoolManager {
14
+ constructor(poolKey) {
15
+ this.poolKey = poolKey;
16
+ this.baseToken = new Token(TOKEN_PROGRAM_ID, poolKey.baseMint, poolKey.baseDecimals);
17
+ this.quoteToken = new Token(TOKEN_PROGRAM_ID, poolKey.quoteMint, poolKey.quoteDecimals);
18
+ this.poolInfo = {
19
+ baseDecimals: poolKey.baseDecimals,
20
+ quoteDecimals: poolKey.baseDecimals,
21
+ baseReserve: new BN(0),
22
+ quoteReserve: new BN(0)
23
+ };
24
+ }
25
+ computeSolOut(baseIn) {
26
+ return Liquidity.computeAmountOut({
27
+ poolKeys: this.poolKey,
28
+ poolInfo: this.poolInfo,
29
+ amountIn: new TokenAmount(this.baseToken, baseIn, true),
30
+ currencyOut: this.quoteToken,
31
+ slippage: new Percent(1, 100)
32
+ });
33
+ }
34
+ computeSolIn(baseAmount) {
35
+ return Liquidity.computeAmountIn({
36
+ poolKeys: this.poolKey,
37
+ poolInfo: this.poolInfo,
38
+ amountOut: new TokenAmount(this.baseToken, baseAmount, true),
39
+ currencyIn: this.quoteToken,
40
+ slippage: new Percent(1, 100)
41
+ });
42
+ }
43
+ updateWithReverse(baseReserve, quoteReserve) {
44
+ this.poolInfo = Object.assign(Object.assign({}, this.poolInfo), { baseReserve: baseReserve, quoteReserve: quoteReserve });
45
+ }
46
+ updateWithReal(connection) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ try {
49
+ this.poolInfo = yield Liquidity.fetchInfo({
50
+ connection,
51
+ poolKeys: this.poolKey
52
+ });
53
+ return true;
54
+ }
55
+ catch (error) {
56
+ return false;
57
+ }
58
+ });
59
+ }
60
+ getPoolInfo() {
61
+ return this.poolInfo;
62
+ }
63
+ }
@@ -0,0 +1,25 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
2
+ import { CurrencyAmount, Token } from "@raydium-io/raydium-sdk";
3
+ import { TOKEN_INFO } from "./global";
4
+ import { PublicKey } from "@solana/web3.js";
5
+ interface PairToken {
6
+ base_token: Token;
7
+ quote_token: Token;
8
+ }
9
+ export declare class PoolManager {
10
+ private base_token_info;
11
+ private quote_token_info;
12
+ private base_amount;
13
+ private quote_amount;
14
+ private market_id;
15
+ private pool_info;
16
+ private pool_keys;
17
+ constructor(base_token_info: TOKEN_INFO, quote_token_info: TOKEN_INFO, base_amount: number, quote_amount: number, market_id: PublicKey);
18
+ initializePoolInfo(market_id: PublicKey): void;
19
+ computeSolAmount(base_amount: number, in_out: boolean): CurrencyAmount;
20
+ computeCurrentPrice(): number;
21
+ buyToken(base_amount: number): void;
22
+ sellToken(base_amount: number): void;
23
+ getPairToken(): PairToken;
24
+ }
25
+ export {};
@@ -0,0 +1,123 @@
1
+ import { Liquidity, Percent, TOKEN_PROGRAM_ID, Token, TokenAmount } from "@raydium-io/raydium-sdk";
2
+ import { EnvironmentManager } from "./global";
3
+ import { PublicKey } from "@solana/web3.js";
4
+ import { BN } from "bn.js";
5
+ import { xWeiAmount } from "./utility";
6
+ export class PoolManager {
7
+ constructor(base_token_info, quote_token_info, base_amount, quote_amount, market_id) {
8
+ this.base_token_info = base_token_info;
9
+ this.quote_token_info = quote_token_info;
10
+ this.base_amount = base_amount;
11
+ this.quote_amount = quote_amount;
12
+ this.market_id = market_id;
13
+ const { base_token, quote_token } = this.getPairToken();
14
+ this.pool_keys = Liquidity.getAssociatedPoolKeys({
15
+ version: 4,
16
+ marketVersion: 3,
17
+ baseMint: base_token.mint,
18
+ quoteMint: quote_token.mint,
19
+ baseDecimals: base_token.decimals,
20
+ quoteDecimals: quote_token.decimals,
21
+ marketId: this.market_id,
22
+ programId: EnvironmentManager.getProgramID().AmmV4,
23
+ marketProgramId: EnvironmentManager.getProgramID().OPENBOOK_MARKET
24
+ });
25
+ this.pool_info = {
26
+ status: new BN(0),
27
+ baseDecimals: this.base_token_info.decimal,
28
+ lpDecimals: this.quote_token_info.decimal,
29
+ quoteDecimals: this.quote_token_info.decimal,
30
+ baseReserve: xWeiAmount(this.base_amount, this.base_token_info.decimal),
31
+ quoteReserve: xWeiAmount(this.quote_amount, this.quote_token_info.decimal),
32
+ lpSupply: new BN(base_amount),
33
+ startTime: new BN(0)
34
+ };
35
+ }
36
+ initializePoolInfo(market_id) {
37
+ this.market_id = market_id;
38
+ const { base_token, quote_token } = this.getPairToken();
39
+ this.pool_keys = Liquidity.getAssociatedPoolKeys({
40
+ version: 4,
41
+ marketVersion: 3,
42
+ baseMint: base_token.mint,
43
+ quoteMint: quote_token.mint,
44
+ baseDecimals: base_token.decimals,
45
+ quoteDecimals: quote_token.decimals,
46
+ marketId: this.market_id,
47
+ programId: EnvironmentManager.getProgramID().AmmV4,
48
+ marketProgramId: EnvironmentManager.getProgramID().OPENBOOK_MARKET
49
+ });
50
+ this.pool_info = {
51
+ status: new BN(0),
52
+ baseDecimals: this.base_token_info.decimal,
53
+ lpDecimals: this.quote_token_info.decimal,
54
+ quoteDecimals: this.quote_token_info.decimal,
55
+ baseReserve: xWeiAmount(this.base_amount, this.base_token_info.decimal),
56
+ quoteReserve: xWeiAmount(this.quote_amount, this.quote_token_info.decimal),
57
+ lpSupply: new BN(this.base_amount),
58
+ startTime: new BN(0)
59
+ };
60
+ console.log("Simulated Pool baseReserve: ", this.pool_info.baseReserve.toString());
61
+ console.log("Simulated Pool quoteReserve: ", this.pool_info.quoteReserve.toString());
62
+ }
63
+ computeSolAmount(base_amount, in_out) {
64
+ const { base_token, quote_token } = this.getPairToken();
65
+ // console.log("Simulated PoolInfo: ", this.pool_info);
66
+ if (in_out) {
67
+ const { maxAmountIn } = Liquidity.computeAmountIn({
68
+ poolKeys: this.pool_keys,
69
+ poolInfo: this.pool_info,
70
+ amountOut: new TokenAmount(base_token, base_amount, false),
71
+ currencyIn: quote_token,
72
+ slippage: new Percent(1, 100)
73
+ });
74
+ return maxAmountIn;
75
+ }
76
+ else {
77
+ const { minAmountOut } = Liquidity.computeAmountOut({
78
+ poolKeys: this.pool_keys,
79
+ poolInfo: this.pool_info,
80
+ amountIn: new TokenAmount(base_token, base_amount, false),
81
+ currencyOut: quote_token,
82
+ slippage: new Percent(1, 100)
83
+ });
84
+ return minAmountOut;
85
+ }
86
+ }
87
+ computeCurrentPrice() {
88
+ return this.quote_amount / this.base_amount;
89
+ }
90
+ buyToken(base_amount) {
91
+ const sol_input = this.computeSolAmount(base_amount, true);
92
+ const { base_token, quote_token } = this.getPairToken();
93
+ const { amountOut } = Liquidity.computeAmountOut({
94
+ poolKeys: this.pool_keys,
95
+ poolInfo: this.pool_info,
96
+ amountIn: sol_input,
97
+ currencyOut: base_token,
98
+ slippage: new Percent(1, 100)
99
+ });
100
+ this.quote_amount += sol_input.raw
101
+ .div(new BN(Math.pow(10, this.quote_token_info.decimal)))
102
+ .toNumber();
103
+ this.base_amount -= base_amount;
104
+ this.pool_info = Object.assign(Object.assign({}, this.pool_info), { baseReserve: this.pool_info.baseReserve.sub(amountOut.raw), quoteReserve: this.pool_info.quoteReserve.add(sol_input.raw) });
105
+ console.log("Simulated Pool baseReserve: ", this.pool_info.baseReserve.toString());
106
+ console.log("Simulated Pool quoteReserve: ", this.pool_info.quoteReserve.toString());
107
+ // this.initializePoolInfo(this.market_id);
108
+ }
109
+ sellToken(base_amount) {
110
+ const sol_input = this.computeSolAmount(base_amount, false);
111
+ this.quote_amount -= sol_input.raw
112
+ .div(new BN(Math.pow(10, this.quote_token_info.decimal)))
113
+ .toNumber();
114
+ this.base_amount += base_amount;
115
+ this.initializePoolInfo(this.market_id);
116
+ }
117
+ getPairToken() {
118
+ const base_mint = new PublicKey(this.base_token_info.address);
119
+ const base = new Token(TOKEN_PROGRAM_ID, base_mint, this.base_token_info.decimal, this.base_token_info.symbol, this.base_token_info.name);
120
+ const quote = new Token(TOKEN_PROGRAM_ID, new PublicKey(this.quote_token_info.address), this.quote_token_info.decimal, this.quote_token_info.symbol, this.quote_token_info.name);
121
+ return { base_token: base, quote_token: quote };
122
+ }
123
+ }