sol-ihor-lab 1.0.1 → 1.0.2
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/lib/cjs/global.d.ts +0 -1
- package/lib/cjs/global.js +2 -11
- package/lib/cjs/instructions/build-instruction.d.ts +0 -1
- package/lib/cjs/instructions/build-instruction.js +0 -19
- package/lib/cjs/instructions/buy-instruction.js +1 -30
- package/lib/cjs/transaction-helper/transaction.d.ts +0 -1
- package/lib/cjs/transaction-helper/transaction.js +1 -20
- package/lib/cjs/utils/get-balance.d.ts +0 -2
- package/lib/cjs/utils/get-balance.js +1 -19
- package/lib/esm/global.d.ts +0 -2
- package/lib/esm/global.js +1 -4
- package/lib/esm/transaction-helper/transaction.d.ts +0 -1
- package/lib/esm/transaction-helper/transaction.js +1 -17
- package/package.json +1 -1
- package/src/global.ts +0 -5
- package/src/transaction-helper/transaction.ts +2 -24
- package/lib/cjs/bundle.d.ts +0 -4
- package/lib/cjs/bundle.js +0 -102
- package/lib/cjs/buy_token.d.ts +0 -5
- package/lib/cjs/buy_token.js +0 -59
- package/lib/cjs/create_open_market.d.ts +0 -4
- package/lib/cjs/create_open_market.js +0 -340
- package/lib/cjs/create_pool.d.ts +0 -4
- package/lib/cjs/create_pool.js +0 -107
- package/lib/cjs/create_token.d.ts +0 -4
- package/lib/cjs/create_token.js +0 -164
- package/lib/cjs/instructions/createpool-instruction.d.ts +0 -4
- package/lib/cjs/instructions/createpool-instruction.js +0 -58
- package/lib/cjs/pool/pool-manager.d.ts +0 -42
- package/lib/cjs/pool/pool-manager.js +0 -70
- package/lib/cjs/transaction/bundle.d.ts +0 -4
- package/lib/cjs/transaction/bundle.js +0 -97
- package/lib/cjs/transaction/sign-tx.d.ts +0 -2
- package/lib/cjs/transaction/sign-tx.js +0 -7
- package/lib/cjs/transaction-helper/check_transaction.d.ts +0 -3
- package/lib/cjs/transaction-helper/check_transaction.js +0 -43
- package/lib/cjs/upload-metadata/upload-metaplex.d.ts +0 -3
- package/lib/cjs/upload-metadata/upload-metaplex.js +0 -48
- package/lib/cjs/upload-metadata/upload-nftstorage.d.ts +0 -0
- package/lib/cjs/upload-metadata/upload-nftstorage.js +0 -1
- package/lib/cjs/upload-metadata/upload-pinata.d.ts +0 -1
- package/lib/cjs/upload-metadata/upload-pinata.js +0 -17
- package/lib/cjs/upload-metadata/utility.d.ts +0 -1
- package/lib/cjs/upload-metadata/utility.js +0 -28
- package/lib/esm/transaction-helper/check_transaction.d.ts +0 -3
- package/lib/esm/transaction-helper/check_transaction.js +0 -16
- package/src/transaction-helper/check_transaction.ts +0 -23
|
@@ -1,340 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.createOpenBookMarket = void 0;
|
|
39
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
40
|
-
const global_1 = require("./global");
|
|
41
|
-
const raydium_sdk_1 = require("@raydium-io/raydium-sdk");
|
|
42
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
43
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
|
44
|
-
const transactions = __importStar(require("./transaction-helper/transaction"));
|
|
45
|
-
function makeCreateMarketInstruction(_a) {
|
|
46
|
-
return __awaiter(this, arguments, void 0, function* ({ connection, wallet, baseInfo, quoteInfo, lotSize, // 1
|
|
47
|
-
tickSize, // 0.01
|
|
48
|
-
dexProgramId, makeTxVersion, lookupTableCache }) {
|
|
49
|
-
const market = (0, raydium_sdk_1.generatePubKey)({
|
|
50
|
-
fromPublicKey: wallet,
|
|
51
|
-
programId: dexProgramId
|
|
52
|
-
});
|
|
53
|
-
const requestQueue = (0, raydium_sdk_1.generatePubKey)({
|
|
54
|
-
fromPublicKey: wallet,
|
|
55
|
-
programId: dexProgramId
|
|
56
|
-
});
|
|
57
|
-
const eventQueue = (0, raydium_sdk_1.generatePubKey)({
|
|
58
|
-
fromPublicKey: wallet,
|
|
59
|
-
programId: dexProgramId
|
|
60
|
-
});
|
|
61
|
-
const bids = (0, raydium_sdk_1.generatePubKey)({
|
|
62
|
-
fromPublicKey: wallet,
|
|
63
|
-
programId: dexProgramId
|
|
64
|
-
});
|
|
65
|
-
const asks = (0, raydium_sdk_1.generatePubKey)({
|
|
66
|
-
fromPublicKey: wallet,
|
|
67
|
-
programId: dexProgramId
|
|
68
|
-
});
|
|
69
|
-
const baseVault = (0, raydium_sdk_1.generatePubKey)({
|
|
70
|
-
fromPublicKey: wallet,
|
|
71
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID
|
|
72
|
-
});
|
|
73
|
-
const quoteVault = (0, raydium_sdk_1.generatePubKey)({
|
|
74
|
-
fromPublicKey: wallet,
|
|
75
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID
|
|
76
|
-
});
|
|
77
|
-
const feeRateBps = 0;
|
|
78
|
-
const quoteDustThreshold = new bn_js_1.default(100);
|
|
79
|
-
function getVaultOwnerAndNonce() {
|
|
80
|
-
const vaultSignerNonce = new bn_js_1.default(0);
|
|
81
|
-
while (true) {
|
|
82
|
-
try {
|
|
83
|
-
const vaultOwner = web3_js_1.PublicKey.createProgramAddressSync([
|
|
84
|
-
market.publicKey.toBuffer(),
|
|
85
|
-
vaultSignerNonce.toArrayLike(Buffer, "le", 8)
|
|
86
|
-
], dexProgramId);
|
|
87
|
-
return { vaultOwner, vaultSignerNonce };
|
|
88
|
-
}
|
|
89
|
-
catch (e) {
|
|
90
|
-
vaultSignerNonce.iaddn(1);
|
|
91
|
-
if (vaultSignerNonce.gt(new bn_js_1.default(25555)))
|
|
92
|
-
throw Error("find vault owner error");
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
function initializeMarketInstruction({ programId, marketInfo }) {
|
|
97
|
-
const dataLayout = (0, raydium_sdk_1.struct)([
|
|
98
|
-
(0, raydium_sdk_1.u8)("version"),
|
|
99
|
-
(0, raydium_sdk_1.u32)("instruction"),
|
|
100
|
-
(0, raydium_sdk_1.u64)("baseLotSize"),
|
|
101
|
-
(0, raydium_sdk_1.u64)("quoteLotSize"),
|
|
102
|
-
(0, raydium_sdk_1.u16)("feeRateBps"),
|
|
103
|
-
(0, raydium_sdk_1.u64)("vaultSignerNonce"),
|
|
104
|
-
(0, raydium_sdk_1.u64)("quoteDustThreshold")
|
|
105
|
-
]);
|
|
106
|
-
const keys = [
|
|
107
|
-
{ pubkey: marketInfo.id, isSigner: false, isWritable: true },
|
|
108
|
-
{ pubkey: marketInfo.requestQueue, isSigner: false, isWritable: true },
|
|
109
|
-
{ pubkey: marketInfo.eventQueue, isSigner: false, isWritable: true },
|
|
110
|
-
{ pubkey: marketInfo.bids, isSigner: false, isWritable: true },
|
|
111
|
-
{ pubkey: marketInfo.asks, isSigner: false, isWritable: true },
|
|
112
|
-
{ pubkey: marketInfo.baseVault, isSigner: false, isWritable: true },
|
|
113
|
-
{ pubkey: marketInfo.quoteVault, isSigner: false, isWritable: true },
|
|
114
|
-
{ pubkey: marketInfo.baseMint, isSigner: false, isWritable: false },
|
|
115
|
-
{ pubkey: marketInfo.quoteMint, isSigner: false, isWritable: false },
|
|
116
|
-
// Use a dummy address if using the new dex upgrade to save tx space.
|
|
117
|
-
{
|
|
118
|
-
pubkey: marketInfo.authority
|
|
119
|
-
? marketInfo.quoteMint
|
|
120
|
-
: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
121
|
-
isSigner: false,
|
|
122
|
-
isWritable: false
|
|
123
|
-
}
|
|
124
|
-
]
|
|
125
|
-
.concat(marketInfo.authority
|
|
126
|
-
? { pubkey: marketInfo.authority, isSigner: false, isWritable: false }
|
|
127
|
-
: [])
|
|
128
|
-
.concat(marketInfo.authority && marketInfo.pruneAuthority
|
|
129
|
-
? {
|
|
130
|
-
pubkey: marketInfo.pruneAuthority,
|
|
131
|
-
isSigner: false,
|
|
132
|
-
isWritable: false
|
|
133
|
-
}
|
|
134
|
-
: []);
|
|
135
|
-
const data = Buffer.alloc(dataLayout.span);
|
|
136
|
-
dataLayout.encode({
|
|
137
|
-
version: 0,
|
|
138
|
-
instruction: 0,
|
|
139
|
-
baseLotSize: marketInfo.baseLotSize,
|
|
140
|
-
quoteLotSize: marketInfo.quoteLotSize,
|
|
141
|
-
feeRateBps: marketInfo.feeRateBps,
|
|
142
|
-
vaultSignerNonce: marketInfo.vaultSignerNonce,
|
|
143
|
-
quoteDustThreshold: marketInfo.quoteDustThreshold
|
|
144
|
-
}, data);
|
|
145
|
-
return new web3_js_1.TransactionInstruction({
|
|
146
|
-
keys,
|
|
147
|
-
programId,
|
|
148
|
-
data
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
const { vaultOwner, vaultSignerNonce } = getVaultOwnerAndNonce();
|
|
152
|
-
const ZERO = new bn_js_1.default(0);
|
|
153
|
-
const baseLotSize = new bn_js_1.default(Math.round(Math.pow(10, baseInfo.decimals) * lotSize));
|
|
154
|
-
const quoteLotSize = new bn_js_1.default(Math.round(lotSize * Math.pow(10, quoteInfo.decimals) * tickSize));
|
|
155
|
-
if (baseLotSize.eq(ZERO))
|
|
156
|
-
throw Error("lot size is too small");
|
|
157
|
-
if (quoteLotSize.eq(ZERO))
|
|
158
|
-
throw Error("tick size or lot size is too small");
|
|
159
|
-
const ins1 = [];
|
|
160
|
-
const accountLamports = yield connection.getMinimumBalanceForRentExemption(165);
|
|
161
|
-
ins1.push(web3_js_1.SystemProgram.createAccountWithSeed({
|
|
162
|
-
fromPubkey: wallet,
|
|
163
|
-
basePubkey: wallet,
|
|
164
|
-
seed: baseVault.seed,
|
|
165
|
-
newAccountPubkey: baseVault.publicKey,
|
|
166
|
-
lamports: accountLamports,
|
|
167
|
-
space: 165,
|
|
168
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID
|
|
169
|
-
}), web3_js_1.SystemProgram.createAccountWithSeed({
|
|
170
|
-
fromPubkey: wallet,
|
|
171
|
-
basePubkey: wallet,
|
|
172
|
-
seed: quoteVault.seed,
|
|
173
|
-
newAccountPubkey: quoteVault.publicKey,
|
|
174
|
-
lamports: accountLamports,
|
|
175
|
-
space: 165,
|
|
176
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID
|
|
177
|
-
}), (0, spl_token_1.createInitializeAccountInstruction)(baseVault.publicKey, baseInfo.mint, vaultOwner), (0, spl_token_1.createInitializeAccountInstruction)(quoteVault.publicKey, quoteInfo.mint, vaultOwner));
|
|
178
|
-
const EVENT_QUEUE_ITEMS = 128; // Default: 2978
|
|
179
|
-
const REQUEST_QUEUE_ITEMS = 63; // Default: 63
|
|
180
|
-
const ORDERBOOK_ITEMS = 201; // Default: 909
|
|
181
|
-
const eventQueueSpace = EVENT_QUEUE_ITEMS * 88 + 44 + 48;
|
|
182
|
-
const requestQueueSpace = REQUEST_QUEUE_ITEMS * 80 + 44 + 48;
|
|
183
|
-
const orderBookSpace = ORDERBOOK_ITEMS * 80 + 44 + 48;
|
|
184
|
-
const ins2 = [];
|
|
185
|
-
ins2.push(web3_js_1.SystemProgram.createAccountWithSeed({
|
|
186
|
-
fromPubkey: wallet,
|
|
187
|
-
basePubkey: wallet,
|
|
188
|
-
seed: market.seed,
|
|
189
|
-
newAccountPubkey: market.publicKey,
|
|
190
|
-
lamports: yield connection.getMinimumBalanceForRentExemption(raydium_sdk_1.MARKET_STATE_LAYOUT_V2.span),
|
|
191
|
-
space: raydium_sdk_1.MARKET_STATE_LAYOUT_V2.span,
|
|
192
|
-
programId: dexProgramId
|
|
193
|
-
}), web3_js_1.SystemProgram.createAccountWithSeed({
|
|
194
|
-
fromPubkey: wallet,
|
|
195
|
-
basePubkey: wallet,
|
|
196
|
-
seed: requestQueue.seed,
|
|
197
|
-
newAccountPubkey: requestQueue.publicKey,
|
|
198
|
-
lamports: yield connection.getMinimumBalanceForRentExemption(requestQueueSpace),
|
|
199
|
-
space: requestQueueSpace,
|
|
200
|
-
programId: dexProgramId
|
|
201
|
-
}), web3_js_1.SystemProgram.createAccountWithSeed({
|
|
202
|
-
fromPubkey: wallet,
|
|
203
|
-
basePubkey: wallet,
|
|
204
|
-
seed: eventQueue.seed,
|
|
205
|
-
newAccountPubkey: eventQueue.publicKey,
|
|
206
|
-
lamports: yield connection.getMinimumBalanceForRentExemption(eventQueueSpace),
|
|
207
|
-
space: eventQueueSpace,
|
|
208
|
-
programId: dexProgramId
|
|
209
|
-
}), web3_js_1.SystemProgram.createAccountWithSeed({
|
|
210
|
-
fromPubkey: wallet,
|
|
211
|
-
basePubkey: wallet,
|
|
212
|
-
seed: bids.seed,
|
|
213
|
-
newAccountPubkey: bids.publicKey,
|
|
214
|
-
lamports: yield connection.getMinimumBalanceForRentExemption(orderBookSpace),
|
|
215
|
-
space: orderBookSpace,
|
|
216
|
-
programId: dexProgramId
|
|
217
|
-
}), web3_js_1.SystemProgram.createAccountWithSeed({
|
|
218
|
-
fromPubkey: wallet,
|
|
219
|
-
basePubkey: wallet,
|
|
220
|
-
seed: asks.seed,
|
|
221
|
-
newAccountPubkey: asks.publicKey,
|
|
222
|
-
lamports: yield connection.getMinimumBalanceForRentExemption(orderBookSpace),
|
|
223
|
-
space: orderBookSpace,
|
|
224
|
-
programId: dexProgramId
|
|
225
|
-
}), initializeMarketInstruction({
|
|
226
|
-
programId: dexProgramId,
|
|
227
|
-
marketInfo: {
|
|
228
|
-
id: market.publicKey,
|
|
229
|
-
requestQueue: requestQueue.publicKey,
|
|
230
|
-
eventQueue: eventQueue.publicKey,
|
|
231
|
-
bids: bids.publicKey,
|
|
232
|
-
asks: asks.publicKey,
|
|
233
|
-
baseVault: baseVault.publicKey,
|
|
234
|
-
quoteVault: quoteVault.publicKey,
|
|
235
|
-
baseMint: baseInfo.mint,
|
|
236
|
-
quoteMint: quoteInfo.mint,
|
|
237
|
-
baseLotSize: baseLotSize,
|
|
238
|
-
quoteLotSize: quoteLotSize,
|
|
239
|
-
feeRateBps: feeRateBps,
|
|
240
|
-
vaultSignerNonce: vaultSignerNonce,
|
|
241
|
-
quoteDustThreshold: quoteDustThreshold
|
|
242
|
-
}
|
|
243
|
-
}));
|
|
244
|
-
const ins = {
|
|
245
|
-
address: {
|
|
246
|
-
marketId: market.publicKey,
|
|
247
|
-
requestQueue: requestQueue.publicKey,
|
|
248
|
-
eventQueue: eventQueue.publicKey,
|
|
249
|
-
bids: bids.publicKey,
|
|
250
|
-
asks: asks.publicKey,
|
|
251
|
-
baseVault: baseVault.publicKey,
|
|
252
|
-
quoteVault: quoteVault.publicKey,
|
|
253
|
-
baseMint: baseInfo.mint,
|
|
254
|
-
quoteMint: quoteInfo.mint
|
|
255
|
-
},
|
|
256
|
-
innerTransactions: [
|
|
257
|
-
{
|
|
258
|
-
instructions: ins1,
|
|
259
|
-
signers: [],
|
|
260
|
-
instructionTypes: [
|
|
261
|
-
raydium_sdk_1.InstructionType.createAccount,
|
|
262
|
-
raydium_sdk_1.InstructionType.createAccount,
|
|
263
|
-
raydium_sdk_1.InstructionType.initAccount,
|
|
264
|
-
raydium_sdk_1.InstructionType.initAccount
|
|
265
|
-
]
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
instructions: ins2,
|
|
269
|
-
signers: [],
|
|
270
|
-
instructionTypes: [
|
|
271
|
-
raydium_sdk_1.InstructionType.createAccount,
|
|
272
|
-
raydium_sdk_1.InstructionType.createAccount,
|
|
273
|
-
raydium_sdk_1.InstructionType.createAccount,
|
|
274
|
-
raydium_sdk_1.InstructionType.createAccount,
|
|
275
|
-
raydium_sdk_1.InstructionType.createAccount,
|
|
276
|
-
raydium_sdk_1.InstructionType.initMarket
|
|
277
|
-
]
|
|
278
|
-
}
|
|
279
|
-
]
|
|
280
|
-
};
|
|
281
|
-
return {
|
|
282
|
-
address: ins.address,
|
|
283
|
-
innerTransactions: yield (0, raydium_sdk_1.splitTxAndSigners)({
|
|
284
|
-
connection,
|
|
285
|
-
makeTxVersion,
|
|
286
|
-
computeBudgetConfig: undefined,
|
|
287
|
-
payer: wallet,
|
|
288
|
-
innerTransaction: ins.innerTransactions,
|
|
289
|
-
lookupTableCache
|
|
290
|
-
})
|
|
291
|
-
};
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
const createOpenBookMarket = (connection_1, token_owner_1, token_address_1, ...args_1) => __awaiter(void 0, [connection_1, token_owner_1, token_address_1, ...args_1], void 0, function* (connection, token_owner, token_address, min_order_size = 1, tick_size = 0.01) {
|
|
295
|
-
if (token_owner.publicKey.toBase58().length <= 0 ||
|
|
296
|
-
token_address.length <= 0) {
|
|
297
|
-
console.log("Error: [Create Open Book Market] invalid argument for create open book market");
|
|
298
|
-
return global_1.SPL_ERROR.E_INVALID_ARGUE;
|
|
299
|
-
}
|
|
300
|
-
try {
|
|
301
|
-
const token_mint = new web3_js_1.PublicKey(token_address);
|
|
302
|
-
const mint_info = yield (0, spl_token_1.getMint)(connection, token_mint);
|
|
303
|
-
const base_token = new raydium_sdk_1.Token(spl_token_1.TOKEN_PROGRAM_ID, token_address, mint_info.decimals);
|
|
304
|
-
const quote_token_info = global_1.EnvironmentManager.getQuoteTokenInfo();
|
|
305
|
-
const quote_token = new raydium_sdk_1.Token(spl_token_1.TOKEN_PROGRAM_ID, quote_token_info.address, quote_token_info.decimal, quote_token_info.symbol, quote_token_info.name);
|
|
306
|
-
console.log("[Create Open Book Market]<--------------------make marekt instruction");
|
|
307
|
-
const { innerTransactions, address } = yield makeCreateMarketInstruction({
|
|
308
|
-
connection: connection,
|
|
309
|
-
wallet: token_owner.publicKey,
|
|
310
|
-
baseInfo: base_token,
|
|
311
|
-
quoteInfo: quote_token,
|
|
312
|
-
lotSize: min_order_size,
|
|
313
|
-
tickSize: tick_size,
|
|
314
|
-
dexProgramId: global_1.EnvironmentManager.getProgramID().OPENBOOK_MARKET,
|
|
315
|
-
makeTxVersion: raydium_sdk_1.TxVersion.V0,
|
|
316
|
-
lookupTableCache: global_1.EnvironmentManager.getCacheLTA()
|
|
317
|
-
});
|
|
318
|
-
console.log("[Create Open Book Market]<--------------------create simple transaction");
|
|
319
|
-
const txns = yield (0, raydium_sdk_1.buildSimpleTransaction)({
|
|
320
|
-
connection: connection,
|
|
321
|
-
makeTxVersion: raydium_sdk_1.TxVersion.V0,
|
|
322
|
-
payer: token_owner.publicKey,
|
|
323
|
-
innerTransactions: innerTransactions,
|
|
324
|
-
addLookupTableInfo: global_1.EnvironmentManager.getCacheLTA()
|
|
325
|
-
});
|
|
326
|
-
console.log("[Create Open Book Market]<--------------------send and confirm transaction");
|
|
327
|
-
const txn_result = yield transactions.sendAndConfirmTransactionsWithCheck(connection, token_owner, txns);
|
|
328
|
-
if (txn_result !== global_1.SPL_ERROR.E_OK) {
|
|
329
|
-
console.error("Error: [Create Open Book Market] failed to send and confirm transaction");
|
|
330
|
-
return global_1.SPL_ERROR.E_FAIL;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
catch (error) {
|
|
334
|
-
console.error("Error: [Create Open Book Market] error occured: ", error);
|
|
335
|
-
return global_1.SPL_ERROR.E_FAIL;
|
|
336
|
-
}
|
|
337
|
-
console.log("Success: [Create Open Book Market] Success to create open book market id");
|
|
338
|
-
return global_1.SPL_ERROR.E_OK;
|
|
339
|
-
});
|
|
340
|
-
exports.createOpenBookMarket = createOpenBookMarket;
|
package/lib/cjs/create_pool.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
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 createPool: (connection: Connection, token_owner: Keypair, token_address: string, input_token_amount: number, input_quote_amount: number) => Promise<TX_RET>;
|
package/lib/cjs/create_pool.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
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.createPool = 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 raydium_sdk_1 = require("@raydium-io/raydium-sdk");
|
|
40
|
-
const serum_1 = require("@project-serum/serum");
|
|
41
|
-
const utiles = __importStar(require("./utility"));
|
|
42
|
-
const bn_js_1 = require("bn.js");
|
|
43
|
-
const createPool = (connection, token_owner, token_address, input_token_amount, input_quote_amount) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
-
try {
|
|
45
|
-
if (token_address.length <= 0) {
|
|
46
|
-
console.log("Error: [Create Pool] invalid argument for create pool");
|
|
47
|
-
return { result: global_1.SPL_ERROR.E_INVALID_ARGUE, value: undefined };
|
|
48
|
-
}
|
|
49
|
-
console.log("<---------------------[Create Pool]-----------------------");
|
|
50
|
-
const token_mint = new web3_js_1.PublicKey(token_address);
|
|
51
|
-
const mint_info = yield (0, spl_token_1.getMint)(connection, token_mint);
|
|
52
|
-
const base_token = new raydium_sdk_1.Token(spl_token_1.TOKEN_PROGRAM_ID, token_address, mint_info.decimals);
|
|
53
|
-
const quote_token_info = global_1.EnvironmentManager.getQuoteTokenInfo();
|
|
54
|
-
const quote_token = new raydium_sdk_1.Token(spl_token_1.TOKEN_PROGRAM_ID, quote_token_info.address, quote_token_info.decimal, quote_token_info.symbol, quote_token_info.name);
|
|
55
|
-
const accounts = yield serum_1.Market.findAccountsByMints(connection, base_token.mint, quote_token.mint, global_1.EnvironmentManager.getProgramID().OPENBOOK_MARKET);
|
|
56
|
-
if (accounts.length === 0) {
|
|
57
|
-
throw "Get market account failed";
|
|
58
|
-
}
|
|
59
|
-
console.log("Market Found");
|
|
60
|
-
const market_id = accounts[0].publicKey;
|
|
61
|
-
const start_time = Math.floor(Date.now() / 1000);
|
|
62
|
-
const base_amount = utiles.xWeiAmount(input_token_amount, base_token.decimals);
|
|
63
|
-
const quote_amount = utiles.xWeiAmount(input_quote_amount, quote_token.decimals);
|
|
64
|
-
const wallet_token_accounts = yield utiles.getWalletAccounts(connection, token_owner.publicKey);
|
|
65
|
-
if (!wallet_token_accounts || wallet_token_accounts.length <= 0) {
|
|
66
|
-
throw "Get wallet account failed";
|
|
67
|
-
}
|
|
68
|
-
const { innerTransactions, address } = yield raydium_sdk_1.Liquidity.makeCreatePoolV4InstructionV2Simple({
|
|
69
|
-
connection: connection,
|
|
70
|
-
programId: global_1.EnvironmentManager.getProgramID().AmmV4,
|
|
71
|
-
marketInfo: {
|
|
72
|
-
marketId: market_id,
|
|
73
|
-
programId: global_1.EnvironmentManager.getProgramID().OPENBOOK_MARKET
|
|
74
|
-
},
|
|
75
|
-
baseMintInfo: base_token,
|
|
76
|
-
quoteMintInfo: quote_token,
|
|
77
|
-
baseAmount: base_amount,
|
|
78
|
-
quoteAmount: quote_amount,
|
|
79
|
-
startTime: new bn_js_1.BN(start_time),
|
|
80
|
-
ownerInfo: {
|
|
81
|
-
feePayer: token_owner.publicKey,
|
|
82
|
-
wallet: token_owner.publicKey,
|
|
83
|
-
tokenAccounts: wallet_token_accounts,
|
|
84
|
-
useSOLBalance: true
|
|
85
|
-
},
|
|
86
|
-
makeTxVersion: raydium_sdk_1.TxVersion.V0,
|
|
87
|
-
associatedOnly: false,
|
|
88
|
-
checkCreateATAOwner: true,
|
|
89
|
-
feeDestinationId: global_1.EnvironmentManager.getFeeDestinationId()
|
|
90
|
-
});
|
|
91
|
-
const txns = yield (0, raydium_sdk_1.buildSimpleTransaction)({
|
|
92
|
-
connection: connection,
|
|
93
|
-
makeTxVersion: raydium_sdk_1.TxVersion.V0,
|
|
94
|
-
payer: token_owner.publicKey,
|
|
95
|
-
innerTransactions: innerTransactions,
|
|
96
|
-
addLookupTableInfo: global_1.EnvironmentManager.getCacheLTA(),
|
|
97
|
-
recentBlockhash: (yield connection.getLatestBlockhash()).blockhash
|
|
98
|
-
});
|
|
99
|
-
console.log("Success: [Create Pool] made transaction successfully");
|
|
100
|
-
return { result: global_1.SPL_ERROR.E_OK, value: txns };
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
console.error("Error: [Create Pool] err: ", error);
|
|
104
|
-
return { result: global_1.SPL_ERROR.E_FAIL, value: undefined };
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
exports.createPool = createPool;
|
|
@@ -1,4 +0,0 @@
|
|
|
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>;
|
package/lib/cjs/create_token.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
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;
|
|
@@ -1,4 +0,0 @@
|
|
|
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>;
|