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.
- package/README.md +35 -0
- package/lib/cjs/bundle.d.ts +4 -0
- package/lib/cjs/bundle.js +102 -0
- package/lib/cjs/buy_token.d.ts +5 -0
- package/lib/cjs/buy_token.js +59 -0
- package/lib/cjs/create_open_market.d.ts +4 -0
- package/lib/cjs/create_open_market.js +340 -0
- package/lib/cjs/create_pool.d.ts +4 -0
- package/lib/cjs/create_pool.js +107 -0
- package/lib/cjs/create_token.d.ts +4 -0
- package/lib/cjs/create_token.js +164 -0
- package/lib/cjs/errors.d.ts +18 -0
- package/lib/cjs/errors.js +44 -0
- package/lib/cjs/global.d.ts +62 -0
- package/lib/cjs/global.js +107 -0
- package/lib/cjs/index.d.ts +17 -0
- package/lib/cjs/index.js +33 -0
- package/lib/cjs/instructions/build-instruction.d.ts +8 -0
- package/lib/cjs/instructions/build-instruction.js +66 -0
- package/lib/cjs/instructions/buy-instruction.d.ts +3 -0
- package/lib/cjs/instructions/buy-instruction.js +44 -0
- package/lib/cjs/instructions/cache-alt-instruction.d.ts +4 -0
- package/lib/cjs/instructions/cache-alt-instruction.js +41 -0
- package/lib/cjs/instructions/createATA-instruction.d.ts +3 -0
- package/lib/cjs/instructions/createATA-instruction.js +10 -0
- package/lib/cjs/instructions/createpool-instruction.d.ts +4 -0
- package/lib/cjs/instructions/createpool-instruction.js +58 -0
- package/lib/cjs/instructions/sol-transfer-instruction.d.ts +3 -0
- package/lib/cjs/instructions/sol-transfer-instruction.js +12 -0
- package/lib/cjs/instructions/transfer-instruction.d.ts +3 -0
- package/lib/cjs/instructions/transfer-instruction.js +9 -0
- package/lib/cjs/pool/pool-manager.d.ts +42 -0
- package/lib/cjs/pool/pool-manager.js +70 -0
- package/lib/cjs/pool_manager.d.ts +25 -0
- package/lib/cjs/pool_manager.js +127 -0
- package/lib/cjs/sell_token.d.ts +5 -0
- package/lib/cjs/sell_token.js +59 -0
- package/lib/cjs/transaction/bundle.d.ts +4 -0
- package/lib/cjs/transaction/bundle.js +97 -0
- package/lib/cjs/transaction/execute-rpc.d.ts +5 -0
- package/lib/cjs/transaction/execute-rpc.js +41 -0
- package/lib/cjs/transaction/sign-tx.d.ts +2 -0
- package/lib/cjs/transaction/sign-tx.js +7 -0
- package/lib/cjs/transaction/transaction-exectue.d.ts +30 -0
- package/lib/cjs/transaction/transaction-exectue.js +119 -0
- package/lib/cjs/transaction-helper/check_transaction.d.ts +3 -0
- package/lib/cjs/transaction-helper/check_transaction.js +43 -0
- package/lib/cjs/transaction-helper/transaction.d.ts +7 -0
- package/lib/cjs/transaction-helper/transaction.js +75 -0
- package/lib/cjs/upload-metadata/upload-metaplex.d.ts +3 -0
- package/lib/cjs/upload-metadata/upload-metaplex.js +48 -0
- package/lib/cjs/upload-metadata/upload-nftstorage.d.ts +0 -0
- package/lib/cjs/upload-metadata/upload-nftstorage.js +1 -0
- package/lib/cjs/upload-metadata/upload-pinata.d.ts +1 -0
- package/lib/cjs/upload-metadata/upload-pinata.js +17 -0
- package/lib/cjs/upload-metadata/utility.d.ts +1 -0
- package/lib/cjs/upload-metadata/utility.js +28 -0
- package/lib/cjs/utility.d.ts +33 -0
- package/lib/cjs/utility.js +129 -0
- package/lib/cjs/utils/budget.d.ts +9 -0
- package/lib/cjs/utils/budget.js +83 -0
- package/lib/cjs/utils/error-helper.d.ts +7 -0
- package/lib/cjs/utils/error-helper.js +15 -0
- package/lib/cjs/utils/get-balance.d.ts +11 -0
- package/lib/cjs/utils/get-balance.js +52 -0
- package/lib/cjs/utils/util.d.ts +27 -0
- package/lib/cjs/utils/util.js +346 -0
- package/lib/cjs/validation_check.d.ts +3 -0
- package/lib/cjs/validation_check.js +26 -0
- package/lib/esm/bundle.d.ts +4 -0
- package/lib/esm/bundle.js +75 -0
- package/lib/esm/buy_token.d.ts +5 -0
- package/lib/esm/buy_token.js +55 -0
- package/lib/esm/create_open_market.d.ts +4 -0
- package/lib/esm/create_open_market.js +310 -0
- package/lib/esm/create_pool.d.ts +4 -0
- package/lib/esm/create_pool.js +80 -0
- package/lib/esm/create_token.d.ts +4 -0
- package/lib/esm/create_token.js +137 -0
- package/lib/esm/errors.d.ts +18 -0
- package/lib/esm/errors.js +35 -0
- package/lib/esm/global.d.ts +62 -0
- package/lib/esm/global.js +103 -0
- package/lib/esm/index.d.ts +17 -0
- package/lib/esm/index.js +17 -0
- package/lib/esm/instructions/build-instruction.d.ts +8 -0
- package/lib/esm/instructions/build-instruction.js +61 -0
- package/lib/esm/instructions/buy-instruction.d.ts +3 -0
- package/lib/esm/instructions/buy-instruction.js +40 -0
- package/lib/esm/instructions/cache-alt-instruction.d.ts +4 -0
- package/lib/esm/instructions/cache-alt-instruction.js +36 -0
- package/lib/esm/instructions/createATA-instruction.d.ts +3 -0
- package/lib/esm/instructions/createATA-instruction.js +6 -0
- package/lib/esm/instructions/createpool-instruction.d.ts +4 -0
- package/lib/esm/instructions/createpool-instruction.js +52 -0
- package/lib/esm/instructions/sol-transfer-instruction.d.ts +3 -0
- package/lib/esm/instructions/sol-transfer-instruction.js +8 -0
- package/lib/esm/instructions/transfer-instruction.d.ts +3 -0
- package/lib/esm/instructions/transfer-instruction.js +5 -0
- package/lib/esm/pool/pool-manager.d.ts +42 -0
- package/lib/esm/pool/pool-manager.js +63 -0
- package/lib/esm/pool_manager.d.ts +25 -0
- package/lib/esm/pool_manager.js +123 -0
- package/lib/esm/sell_token.d.ts +5 -0
- package/lib/esm/sell_token.js +55 -0
- package/lib/esm/transaction/bundle.d.ts +4 -0
- package/lib/esm/transaction/bundle.js +90 -0
- package/lib/esm/transaction/execute-rpc.d.ts +5 -0
- package/lib/esm/transaction/execute-rpc.js +36 -0
- package/lib/esm/transaction/sign-tx.d.ts +2 -0
- package/lib/esm/transaction/sign-tx.js +3 -0
- package/lib/esm/transaction/transaction-exectue.d.ts +30 -0
- package/lib/esm/transaction/transaction-exectue.js +115 -0
- package/lib/esm/transaction-helper/check_transaction.d.ts +3 -0
- package/lib/esm/transaction-helper/check_transaction.js +16 -0
- package/lib/esm/transaction-helper/transaction.d.ts +7 -0
- package/lib/esm/transaction-helper/transaction.js +68 -0
- package/lib/esm/upload-metadata/upload-metaplex.d.ts +3 -0
- package/lib/esm/upload-metadata/upload-metaplex.js +43 -0
- package/lib/esm/upload-metadata/upload-nftstorage.d.ts +0 -0
- package/lib/esm/upload-metadata/upload-nftstorage.js +1 -0
- package/lib/esm/upload-metadata/upload-pinata.d.ts +1 -0
- package/lib/esm/upload-metadata/upload-pinata.js +13 -0
- package/lib/esm/upload-metadata/utility.d.ts +1 -0
- package/lib/esm/upload-metadata/utility.js +21 -0
- package/lib/esm/utility.d.ts +33 -0
- package/lib/esm/utility.js +93 -0
- package/lib/esm/utils/budget.d.ts +9 -0
- package/lib/esm/utils/budget.js +73 -0
- package/lib/esm/utils/error-helper.d.ts +7 -0
- package/lib/esm/utils/error-helper.js +11 -0
- package/lib/esm/utils/get-balance.d.ts +11 -0
- package/lib/esm/utils/get-balance.js +42 -0
- package/lib/esm/utils/util.d.ts +25 -0
- package/lib/esm/utils/util.js +107 -0
- package/lib/esm/validation_check.d.ts +3 -0
- package/lib/esm/validation_check.js +22 -0
- package/package.json +69 -0
- package/src/assert.ts +4 -0
- package/src/bundle.ts +99 -0
- package/src/buy_token.ts +82 -0
- package/src/create_open_market.ts +464 -0
- package/src/create_pool.ts +120 -0
- package/src/create_token.ts +267 -0
- package/src/errors.ts +25 -0
- package/src/global.ts +156 -0
- package/src/index.ts +17 -0
- package/src/instructions/build-instruction.ts +87 -0
- package/src/instructions/buy-instruction.ts +52 -0
- package/src/instructions/cache-alt-instruction.ts +40 -0
- package/src/instructions/createATA-instruction.ts +29 -0
- package/src/instructions/createpool-instruction.ts +72 -0
- package/src/instructions/sol-transfer-instruction.ts +13 -0
- package/src/instructions/transfer-instruction.ts +22 -0
- package/src/pool/pool-manager.ts +85 -0
- package/src/pool_manager.ts +197 -0
- package/src/sell_token.ts +82 -0
- package/src/transaction/bundle.ts +116 -0
- package/src/transaction/execute-rpc.ts +35 -0
- package/src/transaction/sign-tx.ts +5 -0
- package/src/transaction/transaction-exectue.ts +134 -0
- package/src/transaction-helper/check_transaction.ts +23 -0
- package/src/transaction-helper/transaction.ts +90 -0
- package/src/upload-metadata/upload-metaplex.ts +51 -0
- package/src/upload-metadata/upload-nftstorage.ts +0 -0
- package/src/upload-metadata/upload-pinata.ts +8 -0
- package/src/upload-metadata/utility.ts +10 -0
- package/src/utility.ts +127 -0
- package/src/utils/budget.ts +104 -0
- package/src/utils/error-helper.ts +20 -0
- package/src/utils/get-balance.ts +55 -0
- package/src/utils/util.ts +111 -0
- package/src/validation_check.ts +26 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="jito-ts/node_modules/@solana/web3.js" />
|
|
2
|
+
import { Connection, Keypair } from "@solana/web3.js";
|
|
3
|
+
import { TX_RET } from "./global";
|
|
4
|
+
export declare const createToken: (connection: Connection, token_owner: Keypair, name: string, symbol: string, decimal: number, total_supply: number, token_logo: string, description?: string) => Promise<TX_RET>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.createToken = void 0;
|
|
36
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
37
|
+
const global_1 = require("./global");
|
|
38
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
39
|
+
const js_1 = require("@metaplex-foundation/js");
|
|
40
|
+
const fs_1 = require("fs");
|
|
41
|
+
const utility_1 = require("./utility");
|
|
42
|
+
const mpl_token_metadata_1 = require("@metaplex-foundation/mpl-token-metadata");
|
|
43
|
+
const transaction = __importStar(require("./transaction-helper/transaction"));
|
|
44
|
+
const totalSupplyMint = (connection, token_owner, token_addr, total_supply) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
const token_mint = new web3_js_1.PublicKey(token_addr);
|
|
46
|
+
const mint_info = yield (0, spl_token_1.getMint)(connection, token_mint);
|
|
47
|
+
try {
|
|
48
|
+
const owner_token_account = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(connection, token_owner, token_mint, token_owner.publicKey);
|
|
49
|
+
if (owner_token_account.address.toBase58().length <= 0) {
|
|
50
|
+
console.log("Error: [Total Supply Mint] failed to create associated token account");
|
|
51
|
+
return global_1.SPL_ERROR.E_TOTAL_MINT_FAIL;
|
|
52
|
+
}
|
|
53
|
+
const token_amount = (0, utility_1.xWeiAmount)(total_supply, mint_info.decimals);
|
|
54
|
+
const mint_result = yield (0, spl_token_1.mintTo)(connection, token_owner, token_mint, owner_token_account.address, token_owner, BigInt(token_amount.toString()));
|
|
55
|
+
if (mint_result.length <= 0) {
|
|
56
|
+
console.log("Error: [Total Supply Mint] failed to mint to owner wallet");
|
|
57
|
+
return global_1.SPL_ERROR.E_TOTAL_MINT_FAIL;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
console.log("Error: [Total Supply Mint] failed to mint to owner wallet");
|
|
62
|
+
return global_1.SPL_ERROR.E_TOTAL_MINT_FAIL;
|
|
63
|
+
}
|
|
64
|
+
return global_1.SPL_ERROR.E_OK;
|
|
65
|
+
});
|
|
66
|
+
const createTokenMetaData = (connection, token_owner, token_addr, name, symbol, token_logo, rpc_url, description) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
try {
|
|
68
|
+
const metaplex = js_1.Metaplex.make(connection)
|
|
69
|
+
.use((0, js_1.keypairIdentity)(token_owner))
|
|
70
|
+
.use((0, js_1.bundlrStorage)({
|
|
71
|
+
address: global_1.EnvironmentManager.getBundlrUrl(),
|
|
72
|
+
providerUrl: rpc_url,
|
|
73
|
+
timeout: 60000
|
|
74
|
+
}));
|
|
75
|
+
const buffer = (0, fs_1.readFileSync)(token_logo);
|
|
76
|
+
const file = (0, js_1.toMetaplexFile)(buffer, "token-logo.png");
|
|
77
|
+
const logo_url = yield metaplex.storage().upload(file);
|
|
78
|
+
if (logo_url.length <= 0) {
|
|
79
|
+
console.log("Error: [Create Token Meta Data] failed to load metapelx data!!!");
|
|
80
|
+
return global_1.SPL_ERROR.E_FAIL;
|
|
81
|
+
}
|
|
82
|
+
const metaplex_data = {
|
|
83
|
+
name: name,
|
|
84
|
+
symbol: symbol,
|
|
85
|
+
image: logo_url,
|
|
86
|
+
description
|
|
87
|
+
};
|
|
88
|
+
const { uri } = yield metaplex.nfts().uploadMetadata(metaplex_data);
|
|
89
|
+
if (uri.length <= 0) {
|
|
90
|
+
console.log("Error: [Create Token Meta Data] failed to upload metaplex data!!!");
|
|
91
|
+
return global_1.SPL_ERROR.E_FAIL;
|
|
92
|
+
}
|
|
93
|
+
const token_mint = new web3_js_1.PublicKey(token_addr);
|
|
94
|
+
const [metadata_PDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), mpl_token_metadata_1.PROGRAM_ID.toBuffer(), token_mint.toBuffer()], mpl_token_metadata_1.PROGRAM_ID);
|
|
95
|
+
const token_meta_data = {
|
|
96
|
+
name: name,
|
|
97
|
+
symbol: symbol,
|
|
98
|
+
uri: uri,
|
|
99
|
+
sellerFeeBasisPoints: 0,
|
|
100
|
+
creators: null,
|
|
101
|
+
collection: null,
|
|
102
|
+
uses: null
|
|
103
|
+
};
|
|
104
|
+
const txn = new web3_js_1.Transaction().add((0, mpl_token_metadata_1.createCreateMetadataAccountV3Instruction)({
|
|
105
|
+
metadata: metadata_PDA,
|
|
106
|
+
mint: token_mint,
|
|
107
|
+
mintAuthority: token_owner.publicKey,
|
|
108
|
+
payer: token_owner.publicKey,
|
|
109
|
+
updateAuthority: token_owner.publicKey
|
|
110
|
+
}, {
|
|
111
|
+
createMetadataAccountArgsV3: {
|
|
112
|
+
data: token_meta_data,
|
|
113
|
+
isMutable: true,
|
|
114
|
+
collectionDetails: null
|
|
115
|
+
}
|
|
116
|
+
}));
|
|
117
|
+
if ((yield transaction.sendAndConfirmTransactionWithCheck(connection, token_owner, txn)) !== global_1.SPL_ERROR.E_OK) {
|
|
118
|
+
return global_1.SPL_ERROR.E_FAIL;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.log("Error: [Create Token Meta Data] failed to create meta data -", error);
|
|
123
|
+
return global_1.SPL_ERROR.E_FAIL;
|
|
124
|
+
}
|
|
125
|
+
return global_1.SPL_ERROR.E_OK;
|
|
126
|
+
});
|
|
127
|
+
const createToken = (connection, token_owner, name, symbol, decimal, total_supply, token_logo, description) => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
|
+
if (name.length <= 0 ||
|
|
129
|
+
symbol.length <= 0 ||
|
|
130
|
+
token_logo.length <= 0 ||
|
|
131
|
+
token_owner.publicKey.toBase58().length <= 0 ||
|
|
132
|
+
global_1.EnvironmentManager.getRpcNetUrl().length <= 0 ||
|
|
133
|
+
decimal <= 0 ||
|
|
134
|
+
total_supply <= 0) {
|
|
135
|
+
console.log("Error: [Create Token] invalid argument to create token!!!");
|
|
136
|
+
return { result: global_1.SPL_ERROR.E_INVALID_ARGUE, value: undefined };
|
|
137
|
+
}
|
|
138
|
+
if ((yield (0, utility_1.checkFileExists)(token_logo)) === false) {
|
|
139
|
+
console.log("Error: [Create Token] invalid argument to create token - token logo path invalid!!!");
|
|
140
|
+
return { result: global_1.SPL_ERROR.E_INVALID_ARGUE, value: undefined };
|
|
141
|
+
}
|
|
142
|
+
console.log("<-----------------[Create Token]---------------------");
|
|
143
|
+
console.log("Name: ", name, "Symbol: ", symbol, "Decimal: ", decimal, "Total Supply: ", total_supply, "Token Logo: ", token_logo, "Token Description: ", description);
|
|
144
|
+
console.log("<-----------------[Create Token]---------------------");
|
|
145
|
+
const token_mint = yield (0, spl_token_1.createMint)(connection, token_owner, token_owner.publicKey, token_owner.publicKey, decimal);
|
|
146
|
+
if (token_mint.toBase58().length <= 0) {
|
|
147
|
+
console.log("Error: [Create Token] failed to create mint!!!");
|
|
148
|
+
return { result: global_1.SPL_ERROR.E_FAIL, value: undefined };
|
|
149
|
+
}
|
|
150
|
+
console.log("<-----------------[Create Token Meta Data]---------------------");
|
|
151
|
+
const meta_result = yield createTokenMetaData(connection, token_owner, token_mint.toBase58(), name, symbol, token_logo, global_1.EnvironmentManager.getRpcNetUrl(), description);
|
|
152
|
+
if (meta_result !== global_1.SPL_ERROR.E_OK) {
|
|
153
|
+
console.log("Error: [Create Token] failed to create meta data!!!");
|
|
154
|
+
return { result: global_1.SPL_ERROR.E_CREATE_META_FAILED, value: undefined };
|
|
155
|
+
}
|
|
156
|
+
console.log("<-----------------[Token mint]---------------------");
|
|
157
|
+
if ((yield totalSupplyMint(connection, token_owner, token_mint.toBase58(), total_supply)) !== global_1.SPL_ERROR.E_OK) {
|
|
158
|
+
console.log("Error: [Create Token] failed to mint total supply!!!");
|
|
159
|
+
return { result: global_1.SPL_ERROR.E_TOTAL_MINT_FAIL, value: undefined };
|
|
160
|
+
}
|
|
161
|
+
console.log("Success: [Create Token] Mint Address: ", token_mint.toBase58());
|
|
162
|
+
return { result: global_1.SPL_ERROR.E_OK, value: token_mint.toBase58() };
|
|
163
|
+
});
|
|
164
|
+
exports.createToken = createToken;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare abstract class BaseError extends Error {
|
|
2
|
+
constructor(message?: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class UploadMetadataError extends BaseError {
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class GenerateTransactionError extends BaseError {
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class BuildInstructionError extends BaseError {
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
export declare class SetTxPriorityError extends BaseError {
|
|
14
|
+
name: string;
|
|
15
|
+
}
|
|
16
|
+
export declare class TransactionExecuteError extends BaseError {
|
|
17
|
+
name: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionExecuteError = exports.SetTxPriorityError = exports.BuildInstructionError = exports.GenerateTransactionError = exports.UploadMetadataError = exports.BaseError = void 0;
|
|
4
|
+
class BaseError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.BaseError = BaseError;
|
|
10
|
+
class UploadMetadataError extends BaseError {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.name = "UploadMetadataError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.UploadMetadataError = UploadMetadataError;
|
|
17
|
+
class GenerateTransactionError extends BaseError {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.name = "GenerateTransactionError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.GenerateTransactionError = GenerateTransactionError;
|
|
24
|
+
class BuildInstructionError extends BaseError {
|
|
25
|
+
constructor() {
|
|
26
|
+
super(...arguments);
|
|
27
|
+
this.name = "BuildInstructionError";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.BuildInstructionError = BuildInstructionError;
|
|
31
|
+
class SetTxPriorityError extends BaseError {
|
|
32
|
+
constructor() {
|
|
33
|
+
super(...arguments);
|
|
34
|
+
this.name = "SetTxPriorityError";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.SetTxPriorityError = SetTxPriorityError;
|
|
38
|
+
class TransactionExecuteError extends BaseError {
|
|
39
|
+
constructor() {
|
|
40
|
+
super(...arguments);
|
|
41
|
+
this.name = "TransactionExecuteError";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.TransactionExecuteError = TransactionExecuteError;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/// <reference types="jito-ts/node_modules/@solana/web3.js" />
|
|
2
|
+
import { CacheLTA, ProgramId } from "@raydium-io/raydium-sdk";
|
|
3
|
+
import { Keypair, PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
4
|
+
export declare enum SPL_ERROR {
|
|
5
|
+
E_INVALID_ARGUE = -1,
|
|
6
|
+
E_OK = 0,
|
|
7
|
+
E_FAIL = 1,
|
|
8
|
+
E_CHECK_FAIL = 2,
|
|
9
|
+
E_SEND_TX_FAIL = 3,
|
|
10
|
+
E_CONFIRM_TX_FAIL = 4,
|
|
11
|
+
E_CREATE_META_FAILED = 5,
|
|
12
|
+
E_TOTAL_MINT_FAIL = 6
|
|
13
|
+
}
|
|
14
|
+
export declare enum NETWORK_MODE {
|
|
15
|
+
NETWORK_MAIN = 0,
|
|
16
|
+
NETWORK_DEV = 1,
|
|
17
|
+
NETWORK_TEST = 2
|
|
18
|
+
}
|
|
19
|
+
export interface TX_RET {
|
|
20
|
+
result: SPL_ERROR;
|
|
21
|
+
value: string | (VersionedTransaction | Transaction)[] | undefined;
|
|
22
|
+
}
|
|
23
|
+
export interface TOKEN_INFO {
|
|
24
|
+
address: string;
|
|
25
|
+
name: string;
|
|
26
|
+
symbol: string;
|
|
27
|
+
decimal: number;
|
|
28
|
+
}
|
|
29
|
+
export interface BUNDLE_TRANSACTION {
|
|
30
|
+
txn: VersionedTransaction;
|
|
31
|
+
signer: Keypair;
|
|
32
|
+
}
|
|
33
|
+
export declare class EnvironmentManager {
|
|
34
|
+
private static NET_MODE;
|
|
35
|
+
private static JITO_BLOCKENGINE_URL;
|
|
36
|
+
private static RPC_CHECK_URL;
|
|
37
|
+
private static RPC_MAIN_URL;
|
|
38
|
+
private static RPC_DEVNET_URL;
|
|
39
|
+
private static RPC_TESTNET_URL;
|
|
40
|
+
private static JITO_KEYPAIR;
|
|
41
|
+
private static QUOTE_TOKEN_INFO;
|
|
42
|
+
static setNetworkMode(mode: NETWORK_MODE): void;
|
|
43
|
+
static setMainNetURL(url: string): void;
|
|
44
|
+
static setDevNetURL(url: string): void;
|
|
45
|
+
static setTestNettURL(url: string): void;
|
|
46
|
+
static getMainNetURL(): string;
|
|
47
|
+
static getDevNetURL(): string;
|
|
48
|
+
static getTestNetURL(): string;
|
|
49
|
+
static getNetworkMode(): NETWORK_MODE;
|
|
50
|
+
static getRpcNetUrl(): string;
|
|
51
|
+
static setNetUrls(main_url: string, dev_url: string, test_url?: string): void;
|
|
52
|
+
static getBundlrUrl(): string;
|
|
53
|
+
static getCheckUrl(): string;
|
|
54
|
+
static getProgramID(): ProgramId;
|
|
55
|
+
static setQuoteTokenInfo(token_info: TOKEN_INFO): void;
|
|
56
|
+
static getQuoteTokenInfo(): TOKEN_INFO;
|
|
57
|
+
static getCacheLTA(): CacheLTA | undefined;
|
|
58
|
+
static getFeeDestinationId(): PublicKey;
|
|
59
|
+
static getJitoBlockEngine(): string;
|
|
60
|
+
static setJitoKeypair(auth_key: Keypair): void;
|
|
61
|
+
static getJitoKeypair(): Keypair;
|
|
62
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnvironmentManager = exports.NETWORK_MODE = exports.SPL_ERROR = void 0;
|
|
4
|
+
const raydium_sdk_1 = require("@raydium-io/raydium-sdk");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
var SPL_ERROR;
|
|
7
|
+
(function (SPL_ERROR) {
|
|
8
|
+
SPL_ERROR[SPL_ERROR["E_INVALID_ARGUE"] = -1] = "E_INVALID_ARGUE";
|
|
9
|
+
SPL_ERROR[SPL_ERROR["E_OK"] = 0] = "E_OK";
|
|
10
|
+
SPL_ERROR[SPL_ERROR["E_FAIL"] = 1] = "E_FAIL";
|
|
11
|
+
SPL_ERROR[SPL_ERROR["E_CHECK_FAIL"] = 2] = "E_CHECK_FAIL";
|
|
12
|
+
SPL_ERROR[SPL_ERROR["E_SEND_TX_FAIL"] = 3] = "E_SEND_TX_FAIL";
|
|
13
|
+
SPL_ERROR[SPL_ERROR["E_CONFIRM_TX_FAIL"] = 4] = "E_CONFIRM_TX_FAIL";
|
|
14
|
+
SPL_ERROR[SPL_ERROR["E_CREATE_META_FAILED"] = 5] = "E_CREATE_META_FAILED";
|
|
15
|
+
SPL_ERROR[SPL_ERROR["E_TOTAL_MINT_FAIL"] = 6] = "E_TOTAL_MINT_FAIL";
|
|
16
|
+
})(SPL_ERROR || (exports.SPL_ERROR = SPL_ERROR = {}));
|
|
17
|
+
var NETWORK_MODE;
|
|
18
|
+
(function (NETWORK_MODE) {
|
|
19
|
+
NETWORK_MODE[NETWORK_MODE["NETWORK_MAIN"] = 0] = "NETWORK_MAIN";
|
|
20
|
+
NETWORK_MODE[NETWORK_MODE["NETWORK_DEV"] = 1] = "NETWORK_DEV";
|
|
21
|
+
NETWORK_MODE[NETWORK_MODE["NETWORK_TEST"] = 2] = "NETWORK_TEST";
|
|
22
|
+
})(NETWORK_MODE || (exports.NETWORK_MODE = NETWORK_MODE = {}));
|
|
23
|
+
class EnvironmentManager {
|
|
24
|
+
static setNetworkMode(mode) {
|
|
25
|
+
EnvironmentManager.NET_MODE = mode;
|
|
26
|
+
}
|
|
27
|
+
static setMainNetURL(url) {
|
|
28
|
+
EnvironmentManager.RPC_MAIN_URL = url;
|
|
29
|
+
}
|
|
30
|
+
static setDevNetURL(url) {
|
|
31
|
+
EnvironmentManager.RPC_DEVNET_URL = url;
|
|
32
|
+
}
|
|
33
|
+
static setTestNettURL(url) {
|
|
34
|
+
EnvironmentManager.RPC_TESTNET_URL = url;
|
|
35
|
+
}
|
|
36
|
+
static getMainNetURL() {
|
|
37
|
+
return EnvironmentManager.RPC_MAIN_URL;
|
|
38
|
+
}
|
|
39
|
+
static getDevNetURL() {
|
|
40
|
+
return EnvironmentManager.RPC_DEVNET_URL;
|
|
41
|
+
}
|
|
42
|
+
static getTestNetURL() {
|
|
43
|
+
return EnvironmentManager.RPC_TESTNET_URL;
|
|
44
|
+
}
|
|
45
|
+
static getNetworkMode() {
|
|
46
|
+
return EnvironmentManager.NET_MODE;
|
|
47
|
+
}
|
|
48
|
+
static getRpcNetUrl() {
|
|
49
|
+
switch (EnvironmentManager.NET_MODE) {
|
|
50
|
+
case NETWORK_MODE.NETWORK_MAIN:
|
|
51
|
+
return EnvironmentManager.getMainNetURL();
|
|
52
|
+
case NETWORK_MODE.NETWORK_DEV:
|
|
53
|
+
return EnvironmentManager.getDevNetURL();
|
|
54
|
+
case NETWORK_MODE.NETWORK_TEST:
|
|
55
|
+
return EnvironmentManager.getTestNetURL();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
static setNetUrls(main_url, dev_url, test_url) {
|
|
59
|
+
EnvironmentManager.setMainNetURL(main_url);
|
|
60
|
+
EnvironmentManager.setDevNetURL(dev_url);
|
|
61
|
+
}
|
|
62
|
+
static getBundlrUrl() {
|
|
63
|
+
return EnvironmentManager.getNetworkMode() === NETWORK_MODE.NETWORK_MAIN
|
|
64
|
+
? "https://node1.bundlr.network"
|
|
65
|
+
: "https://devnet.bundlr.network";
|
|
66
|
+
}
|
|
67
|
+
static getCheckUrl() {
|
|
68
|
+
return EnvironmentManager.RPC_CHECK_URL;
|
|
69
|
+
}
|
|
70
|
+
static getProgramID() {
|
|
71
|
+
return EnvironmentManager.getNetworkMode() === NETWORK_MODE.NETWORK_MAIN
|
|
72
|
+
? raydium_sdk_1.MAINNET_PROGRAM_ID
|
|
73
|
+
: raydium_sdk_1.DEVNET_PROGRAM_ID;
|
|
74
|
+
}
|
|
75
|
+
static setQuoteTokenInfo(token_info) {
|
|
76
|
+
EnvironmentManager.QUOTE_TOKEN_INFO = token_info;
|
|
77
|
+
}
|
|
78
|
+
static getQuoteTokenInfo() {
|
|
79
|
+
return EnvironmentManager.QUOTE_TOKEN_INFO;
|
|
80
|
+
}
|
|
81
|
+
static getCacheLTA() {
|
|
82
|
+
return EnvironmentManager.getNetworkMode() === NETWORK_MODE.NETWORK_MAIN
|
|
83
|
+
? raydium_sdk_1.LOOKUP_TABLE_CACHE
|
|
84
|
+
: undefined;
|
|
85
|
+
}
|
|
86
|
+
static getFeeDestinationId() {
|
|
87
|
+
return EnvironmentManager.getNetworkMode() === NETWORK_MODE.NETWORK_MAIN
|
|
88
|
+
? new web3_js_1.PublicKey("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5")
|
|
89
|
+
: new web3_js_1.PublicKey("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR");
|
|
90
|
+
}
|
|
91
|
+
static getJitoBlockEngine() {
|
|
92
|
+
return EnvironmentManager.JITO_BLOCKENGINE_URL;
|
|
93
|
+
}
|
|
94
|
+
static setJitoKeypair(auth_key) {
|
|
95
|
+
EnvironmentManager.JITO_KEYPAIR = auth_key;
|
|
96
|
+
}
|
|
97
|
+
static getJitoKeypair() {
|
|
98
|
+
return EnvironmentManager.JITO_KEYPAIR;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.EnvironmentManager = EnvironmentManager;
|
|
102
|
+
EnvironmentManager.NET_MODE = NETWORK_MODE.NETWORK_MAIN;
|
|
103
|
+
EnvironmentManager.JITO_BLOCKENGINE_URL = "frankfurt.mainnet.block-engine.jito.wtf";
|
|
104
|
+
EnvironmentManager.RPC_CHECK_URL = "http://95.217.82.36:8180";
|
|
105
|
+
EnvironmentManager.RPC_MAIN_URL = "";
|
|
106
|
+
EnvironmentManager.RPC_DEVNET_URL = "";
|
|
107
|
+
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";
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./instructions/build-instruction"), exports);
|
|
18
|
+
__exportStar(require("./instructions/buy-instruction"), exports);
|
|
19
|
+
__exportStar(require("./instructions/cache-alt-instruction"), exports);
|
|
20
|
+
__exportStar(require("./instructions/createATA-instruction"), exports);
|
|
21
|
+
__exportStar(require("./instructions/createpool-instruction"), exports);
|
|
22
|
+
__exportStar(require("./instructions/sol-transfer-instruction"), exports);
|
|
23
|
+
__exportStar(require("./instructions/transfer-instruction"), exports);
|
|
24
|
+
__exportStar(require("./pool/pool-manager"), exports);
|
|
25
|
+
__exportStar(require("./transaction/bundle"), exports);
|
|
26
|
+
__exportStar(require("./transaction/execute-rpc"), exports);
|
|
27
|
+
__exportStar(require("./transaction/sign-tx"), exports);
|
|
28
|
+
__exportStar(require("./transaction/transaction-exectue"), exports);
|
|
29
|
+
__exportStar(require("./utils/budget"), exports);
|
|
30
|
+
__exportStar(require("./utils/error-helper"), exports);
|
|
31
|
+
__exportStar(require("./utils/get-balance"), exports);
|
|
32
|
+
__exportStar(require("./utils/util"), exports);
|
|
33
|
+
__exportStar(require("./errors"), exports);
|
|
@@ -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,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.buildInstToVersioned = exports.compileInstToVersioned = void 0;
|
|
13
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
14
|
+
const errors_1 = require("../errors");
|
|
15
|
+
const raydium_sdk_1 = require("@raydium-io/raydium-sdk");
|
|
16
|
+
const compileInstToVersioned = (connection, payer, insts, signer, lookupAddr) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
try {
|
|
18
|
+
const recentBlockhash = (yield connection.getLatestBlockhash("finalized"))
|
|
19
|
+
.blockhash;
|
|
20
|
+
if (lookupAddr) {
|
|
21
|
+
const lookupTableAccount = (yield connection.getAddressLookupTable(new web3_js_1.PublicKey(lookupAddr))).value;
|
|
22
|
+
const txn = new web3_js_1.VersionedTransaction(new web3_js_1.TransactionMessage({
|
|
23
|
+
payerKey: payer.publicKey,
|
|
24
|
+
instructions: insts,
|
|
25
|
+
recentBlockhash: recentBlockhash
|
|
26
|
+
}).compileToV0Message([lookupTableAccount]));
|
|
27
|
+
return {
|
|
28
|
+
txn: txn,
|
|
29
|
+
singer: signer
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const txn = new web3_js_1.VersionedTransaction(new web3_js_1.TransactionMessage({
|
|
34
|
+
payerKey: payer.publicKey,
|
|
35
|
+
instructions: insts,
|
|
36
|
+
recentBlockhash: recentBlockhash
|
|
37
|
+
}).compileToV0Message());
|
|
38
|
+
return {
|
|
39
|
+
txn: txn,
|
|
40
|
+
singer: signer
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
throw new errors_1.BuildInstructionError(`CompileInstToVersioned: ${error}`);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
exports.compileInstToVersioned = compileInstToVersioned;
|
|
49
|
+
const buildInstToVersioned = (connection, payer, inst) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
try {
|
|
51
|
+
const txn = yield (0, raydium_sdk_1.buildSimpleTransaction)({
|
|
52
|
+
connection,
|
|
53
|
+
makeTxVersion: raydium_sdk_1.TxVersion.V0,
|
|
54
|
+
payer: payer.publicKey,
|
|
55
|
+
innerTransactions: inst,
|
|
56
|
+
recentBlockhash: (yield connection.getLatestBlockhash("finalized"))
|
|
57
|
+
.blockhash,
|
|
58
|
+
addLookupTableInfo: raydium_sdk_1.LOOKUP_TABLE_CACHE
|
|
59
|
+
});
|
|
60
|
+
return txn;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw new errors_1.BuildInstructionError(`BuildInstToVersioned: ${error}`);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
exports.buildInstToVersioned = buildInstToVersioned;
|
|
@@ -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,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.generateBuyInst = void 0;
|
|
13
|
+
const raydium_sdk_1 = require("@raydium-io/raydium-sdk");
|
|
14
|
+
const get_balance_1 = require("../utils/get-balance");
|
|
15
|
+
const errors_1 = require("../errors");
|
|
16
|
+
const generateBuyInst = (connection, poolKeys, buyer, inputTokenAmount, minAmountOut, maxLamports = 100000) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
try {
|
|
18
|
+
const tokenAccountInfos = yield (0, get_balance_1.getWalletTokenAccount)(connection, buyer.publicKey);
|
|
19
|
+
const { innerTransactions } = yield raydium_sdk_1.Liquidity.makeSwapInstructionSimple({
|
|
20
|
+
connection: connection,
|
|
21
|
+
poolKeys: Object.assign({}, poolKeys),
|
|
22
|
+
userKeys: {
|
|
23
|
+
tokenAccounts: tokenAccountInfos,
|
|
24
|
+
owner: buyer.publicKey
|
|
25
|
+
},
|
|
26
|
+
amountIn: inputTokenAmount,
|
|
27
|
+
amountOut: minAmountOut,
|
|
28
|
+
config: {
|
|
29
|
+
bypassAssociatedCheck: false
|
|
30
|
+
},
|
|
31
|
+
fixedSide: "in",
|
|
32
|
+
makeTxVersion: raydium_sdk_1.TxVersion.V0,
|
|
33
|
+
computeBudgetConfig: {
|
|
34
|
+
microLamports: maxLamports
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const instructions = innerTransactions[0].instructions.filter(Boolean);
|
|
38
|
+
return instructions.slice(1);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw new errors_1.GenerateTransactionError(`GenereateBuyInst: ${error}`);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
exports.generateBuyInst = generateBuyInst;
|
|
@@ -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,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.generateExtendAltInst = exports.generateCreateAltInst = void 0;
|
|
13
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
14
|
+
const errors_1 = require("../errors");
|
|
15
|
+
const generateCreateAltInst = (connection, payer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
return web3_js_1.AddressLookupTableProgram.createLookupTable({
|
|
18
|
+
authority: payer.publicKey,
|
|
19
|
+
payer: payer.publicKey,
|
|
20
|
+
recentSlot: yield connection.getSlot()
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw new errors_1.GenerateTransactionError(`GenerateCreateAltInst: ${error}`);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
exports.generateCreateAltInst = generateCreateAltInst;
|
|
28
|
+
const generateExtendAltInst = (connection, payer, lookupTableAddress, addresses) => {
|
|
29
|
+
try {
|
|
30
|
+
return web3_js_1.AddressLookupTableProgram.extendLookupTable({
|
|
31
|
+
payer: payer.publicKey,
|
|
32
|
+
authority: payer.publicKey,
|
|
33
|
+
lookupTable: lookupTableAddress,
|
|
34
|
+
addresses: addresses
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
throw new errors_1.GenerateTransactionError(`GenerateExtendAltInst: ${error}`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.generateExtendAltInst = generateExtendAltInst;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCreateAccountTransactionInst = void 0;
|
|
4
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
const getCreateAccountTransactionInst = (payer, wallet, addr) => {
|
|
7
|
+
const associatedToken = (0, spl_token_1.getAssociatedTokenAddressSync)(new web3_js_1.PublicKey(addr), wallet.publicKey, true, spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
8
|
+
return (0, spl_token_1.createAssociatedTokenAccountInstruction)(payer.publicKey, associatedToken, wallet.publicKey, new web3_js_1.PublicKey(addr), spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
9
|
+
};
|
|
10
|
+
exports.getCreateAccountTransactionInst = getCreateAccountTransactionInst;
|
|
@@ -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>;
|