cli and n_users_script
This commit is contained in:
parent
66d7baa807
commit
14a3b51e49
|
@ -0,0 +1,79 @@
|
||||||
|
import { Connection, Keypair } from '@solana/web3.js';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
import * as splToken from "@solana/spl-token";
|
||||||
|
import * as os from 'os';
|
||||||
|
|
||||||
|
// number of users
|
||||||
|
const nbUsers = process.argv[2];
|
||||||
|
// url
|
||||||
|
const url = process.argv.length > 3 ? process.argv[3] : "http://127.0.0.1:8890";
|
||||||
|
// outfile
|
||||||
|
const outFile = process.argv.length > 4 ? process.argv[4] : "out.json";
|
||||||
|
|
||||||
|
console.log("creating " + nbUsers + " Users on " + url + " out file " + outFile);
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const connection = new Connection(url, 'confirmed');
|
||||||
|
|
||||||
|
const authority = Keypair.fromSecretKey(
|
||||||
|
Uint8Array.from(
|
||||||
|
JSON.parse(
|
||||||
|
process.env.KEYPAIR ||
|
||||||
|
fs.readFileSync(os.homedir() + '/.config/solana/id.json', 'utf-8'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// create n key pairs
|
||||||
|
const userKps = [...Array(nbUsers)].map(_x => Keypair.generate())
|
||||||
|
|
||||||
|
// create and initialize new mint
|
||||||
|
const mint = await splToken.createMint(
|
||||||
|
connection,
|
||||||
|
authority,
|
||||||
|
authority.publicKey,
|
||||||
|
null,
|
||||||
|
6,
|
||||||
|
);
|
||||||
|
|
||||||
|
// create accounts for each key pair created earlier
|
||||||
|
const accounts = await Promise.all(userKps.map(x => {
|
||||||
|
return splToken.createAccount(
|
||||||
|
connection,
|
||||||
|
authority,
|
||||||
|
mint,
|
||||||
|
x.publicKey,
|
||||||
|
)
|
||||||
|
}));
|
||||||
|
|
||||||
|
// mint to accounts
|
||||||
|
await Promise.all(accounts.map(to => {
|
||||||
|
return splToken.mintTo(
|
||||||
|
connection,
|
||||||
|
authority,
|
||||||
|
mint,
|
||||||
|
to,
|
||||||
|
authority,
|
||||||
|
1_000_000_000_000,
|
||||||
|
)
|
||||||
|
}));
|
||||||
|
|
||||||
|
const users = userKps.map(user => {
|
||||||
|
return {
|
||||||
|
publicKey: user.publicKey.toBase58(),
|
||||||
|
secretKey: Array.from(user.secretKey)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
'users': users,
|
||||||
|
'tokenAccounts': accounts,
|
||||||
|
'mint': mint,
|
||||||
|
'minted_amount': 1_000_000_000_000
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('created ' + nbUsers + ' Users and minted 10^12 tokens for mint ' + mint);
|
||||||
|
|
||||||
|
fs.writeFileSync(outFile, JSON.stringify(data));
|
||||||
|
|
||||||
|
})()
|
|
@ -4,6 +4,7 @@
|
||||||
"repository": "https://github.com/blockworks-foundation/lite-rpc.git",
|
"repository": "https://github.com/blockworks-foundation/lite-rpc.git",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@solana/spl-token": "^0.3.6",
|
||||||
"@solana/web3.js": "^1.73.0",
|
"@solana/web3.js": "^1.73.0",
|
||||||
"@types/jest": "^29.2.5",
|
"@types/jest": "^29.2.5",
|
||||||
"jest": "^29.3.1",
|
"jest": "^29.3.1",
|
||||||
|
|
|
@ -8,9 +8,9 @@ pub struct Args {
|
||||||
pub rpc_addr: String,
|
pub rpc_addr: String,
|
||||||
#[arg(short, long, default_value_t = String::from(DEFAULT_WS_ADDR))]
|
#[arg(short, long, default_value_t = String::from(DEFAULT_WS_ADDR))]
|
||||||
pub ws_addr: String,
|
pub ws_addr: String,
|
||||||
#[arg(short, long, default_value_t = String::from("127.0.0.1:8890"))]
|
#[arg(long, default_value_t = String::from("127.0.0.1:8890"))]
|
||||||
pub lite_rpc_http_addr: String,
|
pub lite_rpc_http_addr: String,
|
||||||
#[arg(short, long, default_value_t = String::from("127.0.0.1:8891"))]
|
#[arg(short='s', long, default_value_t = String::from("127.0.0.1:8891"))]
|
||||||
pub lite_rpc_ws_addr: String,
|
pub lite_rpc_ws_addr: String,
|
||||||
#[arg(short, long, default_value_t = false)]
|
#[arg(short, long, default_value_t = false)]
|
||||||
pub batch_transactions: bool,
|
pub batch_transactions: bool,
|
||||||
|
|
28
yarn.lock
28
yarn.lock
|
@ -587,6 +587,16 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
"@sinonjs/commons" "^1.7.0"
|
"@sinonjs/commons" "^1.7.0"
|
||||||
|
|
||||||
|
"@solana/buffer-layout-utils@^0.2.0":
|
||||||
|
version "0.2.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@solana/buffer-layout-utils/-/buffer-layout-utils-0.2.0.tgz#b45a6cab3293a2eb7597cceb474f229889d875ca"
|
||||||
|
integrity sha512-szG4sxgJGktbuZYDg2FfNmkMi0DYQoVjN2h7ta1W1hPrwzarcFLBq9UpX1UjNXsNpT9dn+chgprtWGioUAr4/g==
|
||||||
|
dependencies:
|
||||||
|
"@solana/buffer-layout" "^4.0.0"
|
||||||
|
"@solana/web3.js" "^1.32.0"
|
||||||
|
bigint-buffer "^1.1.5"
|
||||||
|
bignumber.js "^9.0.1"
|
||||||
|
|
||||||
"@solana/buffer-layout@^4.0.0":
|
"@solana/buffer-layout@^4.0.0":
|
||||||
version "4.0.1"
|
version "4.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/@solana/buffer-layout/-/buffer-layout-4.0.1.tgz#b996235eaec15b1e0b5092a8ed6028df77fa6c15"
|
resolved "https://registry.yarnpkg.com/@solana/buffer-layout/-/buffer-layout-4.0.1.tgz#b996235eaec15b1e0b5092a8ed6028df77fa6c15"
|
||||||
|
@ -594,7 +604,16 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
buffer "~6.0.3"
|
buffer "~6.0.3"
|
||||||
|
|
||||||
"@solana/web3.js@^1.73.0":
|
"@solana/spl-token@^0.3.6":
|
||||||
|
version "0.3.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.3.6.tgz#35473ad2ed71fe91e5754a2ac72901e1b8b26a42"
|
||||||
|
integrity sha512-P9pTXjDIRvVbjr3J0mCnSamYqLnICeds7IoH1/Ro2R9OBuOHdp5pqKZoscfZ3UYrgnCWUc1bc9M2m/YPHjw+1g==
|
||||||
|
dependencies:
|
||||||
|
"@solana/buffer-layout" "^4.0.0"
|
||||||
|
"@solana/buffer-layout-utils" "^0.2.0"
|
||||||
|
buffer "^6.0.3"
|
||||||
|
|
||||||
|
"@solana/web3.js@^1.32.0", "@solana/web3.js@^1.73.0":
|
||||||
version "1.73.0"
|
version "1.73.0"
|
||||||
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.73.0.tgz#c65f9f954ac80fca6952765c931dd72e57e1b572"
|
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.73.0.tgz#c65f9f954ac80fca6952765c931dd72e57e1b572"
|
||||||
integrity sha512-YrgX3Py7ylh8NYkbanoINUPCj//bWUjYZ5/WPy9nQ9SK3Cl7QWCR+NmbDjmC/fTspZGR+VO9LTQslM++jr5PRw==
|
integrity sha512-YrgX3Py7ylh8NYkbanoINUPCj//bWUjYZ5/WPy9nQ9SK3Cl7QWCR+NmbDjmC/fTspZGR+VO9LTQslM++jr5PRw==
|
||||||
|
@ -876,6 +895,11 @@ bigint-buffer@^1.1.5:
|
||||||
dependencies:
|
dependencies:
|
||||||
bindings "^1.3.0"
|
bindings "^1.3.0"
|
||||||
|
|
||||||
|
bignumber.js@^9.0.1:
|
||||||
|
version "9.1.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.1.1.tgz#c4df7dc496bd849d4c9464344c1aa74228b4dac6"
|
||||||
|
integrity sha512-pHm4LsMJ6lzgNGVfZHjMoO8sdoRhOzOH4MLmY65Jg70bpxCKu5iOHNJyfF6OyvYw7t8Fpf35RuzUyqnQsj8Vig==
|
||||||
|
|
||||||
bindings@^1.3.0:
|
bindings@^1.3.0:
|
||||||
version "1.5.0"
|
version "1.5.0"
|
||||||
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
|
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
|
||||||
|
@ -956,7 +980,7 @@ buffer@6.0.1:
|
||||||
base64-js "^1.3.1"
|
base64-js "^1.3.1"
|
||||||
ieee754 "^1.2.1"
|
ieee754 "^1.2.1"
|
||||||
|
|
||||||
buffer@~6.0.3:
|
buffer@^6.0.3, buffer@~6.0.3:
|
||||||
version "6.0.3"
|
version "6.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6"
|
resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6"
|
||||||
integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==
|
integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==
|
||||||
|
|
Loading…
Reference in New Issue