-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.js
More file actions
92 lines (92 loc) · 4.47 KB
/
Copy pathconfig.js
File metadata and controls
92 lines (92 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.tokens = exports.fetchTokenAccountData = exports.initSdk = exports.txVersion = exports.connection = exports.cluster = exports.mainKp = void 0;
const web3_js_1 = require("@solana/web3.js");
const spl_token_1 = require("@solana/spl-token");
const raydium_sdk_v2_1 = require("@raydium-io/raydium-sdk-v2");
const bs58_1 = __importDefault(require("bs58"));
const constants_1 = require("./constants");
exports.mainKp = web3_js_1.Keypair.fromSecretKey(bs58_1.default.decode(constants_1.PRIVATE_KEY));
exports.cluster = constants_1.CLUSTER == "mainnet" ? "mainnet" : "devnet"; // 'mainnet' | 'devnet'
exports.connection = exports.cluster == "mainnet" ?
new web3_js_1.Connection(constants_1.RPC_ENDPOINT, { wsEndpoint: constants_1.RPC_WEBSOCKET_ENDPOINT, commitment: "confirmed" }) :
new web3_js_1.Connection("https://api.devnet.solana.com");
exports.txVersion = raydium_sdk_v2_1.TxVersion.V0; // or TxVersion.LEGACY
let raydium;
const initSdk = (params) => __awaiter(void 0, void 0, void 0, function* () {
if (raydium)
return raydium;
console.log(`connect to rpc ${exports.connection.rpcEndpoint} in ${exports.cluster}`);
raydium = yield raydium_sdk_v2_1.Raydium.load({
owner: exports.mainKp,
connection: exports.connection,
cluster: exports.cluster,
disableFeatureCheck: true,
disableLoadToken: !(params === null || params === void 0 ? void 0 : params.loadToken),
blockhashCommitment: 'confirmed',
// urlConfigs: {
// BASE_HOST: '<API_HOST>', // api url configs, currently api doesn't support devnet
// },
});
/**
* By default: sdk will automatically fetch token account data when need it or any sol balace changed.
* if you want to handle token account by yourself, set token account data after init sdk
* code below shows how to do it.
* note: after call raydium.account.updateTokenAccount, raydium will not automatically fetch token account
*/
/*
raydium.account.updateTokenAccount(await fetchTokenAccountData())
connection.onAccountChange(mainKp.publicKey, async () => {
raydium!.account.updateTokenAccount(await fetchTokenAccountData())
})
*/
return raydium;
});
exports.initSdk = initSdk;
const fetchTokenAccountData = () => __awaiter(void 0, void 0, void 0, function* () {
const solAccountResp = yield exports.connection.getAccountInfo(exports.mainKp.publicKey);
const tokenAccountResp = yield exports.connection.getTokenAccountsByOwner(exports.mainKp.publicKey, { programId: spl_token_1.TOKEN_PROGRAM_ID });
const token2022Req = yield exports.connection.getTokenAccountsByOwner(exports.mainKp.publicKey, { programId: spl_token_1.TOKEN_2022_PROGRAM_ID });
const tokenAccountData = (0, raydium_sdk_v2_1.parseTokenAccountResp)({
owner: exports.mainKp.publicKey,
solAccountResp,
tokenAccountResp: {
context: tokenAccountResp.context,
value: [...tokenAccountResp.value, ...token2022Req.value],
},
});
return tokenAccountData;
});
exports.fetchTokenAccountData = fetchTokenAccountData;
exports.tokens = {
name: constants_1.NAME,
symbol: constants_1.SYMBOL,
decimals: constants_1.DECIMALS,
description: "it's description",
uiAmount: Math.pow(10, 9),
image: constants_1.IMAGE_PATH,
extensions: {
website: constants_1.WEBSITE,
twitter: constants_1.TWITTER,
telegram: constants_1.TELEGRAM
},
tags: [
"Meme",
"Tokenization"
],
solAmount: 1,
tokenAmountToPutInPool: constants_1.TOKEN_AMOUNT_TO_ADD_LIQUIDITY,
};
//# sourceMappingURL=config.js.map