-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy2022.ts
103 lines (93 loc) · 2.6 KB
/
deploy2022.ts
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
93
94
95
96
97
98
99
100
101
102
103
import {
clusterApiUrl,
sendAndConfirmTransaction,
Connection,
Keypair,
SystemProgram,
Transaction,
LAMPORTS_PER_SOL,
} from '@solana/web3.js';
import {
ExtensionType,
createInitializeMintInstruction,
mintTo,
createAccount,
getMintLen,
TOKEN_2022_PROGRAM_ID,
unpackAccount,
getTransferFeeAmount,
} from '@solana/spl-token';
import {
createInitializeTransferFeeConfigInstruction,
harvestWithheldTokensToMint,
transferCheckedWithFee,
withdrawWithheldTokensFromAccounts,
withdrawWithheldTokensFromMint,
} from '@solana/spl-token';
import * as dotenv from 'dotenv';
dotenv.config();
import { loadSecretKey, saveSecretKey } from './utils';
const decimals = 9;
const feeBasisPoints = 300; // 3%
const maxSupply = BigInt(1_000_000_000_000_000_000); // 1B token
const maxFee = maxSupply;
(async () => {
const signer = await loadSecretKey('signer.key');
if (!signer) {
process.exit(1);
}
const mintAuthority = signer;
const mintKeypair = Keypair.generate();
const mint = mintKeypair.publicKey;
const transferFeeConfigAuthority = signer;
const withdrawWithheldAuthority = signer;
saveSecretKey(mintKeypair, 'mint.key');
const connection = new Connection(clusterApiUrl(process.env.NODE_ENV == 'production' ? 'mainnet-beta' : 'devnet'), 'confirmed');
// deploy token
const extensions = [ExtensionType.TransferFeeConfig];
const mintLen = getMintLen(extensions);
const mintLamports = await connection.getMinimumBalanceForRentExemption(mintLen);
const mintTransaction = new Transaction().add(
SystemProgram.createAccount({
fromPubkey: signer.publicKey,
newAccountPubkey: mint,
space: mintLen,
lamports: mintLamports,
programId: TOKEN_2022_PROGRAM_ID,
}),
createInitializeTransferFeeConfigInstruction(
mint,
transferFeeConfigAuthority.publicKey,
withdrawWithheldAuthority.publicKey,
feeBasisPoints,
maxFee,
TOKEN_2022_PROGRAM_ID
),
createInitializeMintInstruction(mint, decimals, mintAuthority.publicKey, null, TOKEN_2022_PROGRAM_ID)
);
await sendAndConfirmTransaction(connection, mintTransaction, [signer, mintKeypair], undefined);
// mint
const mintAmount = maxSupply;
const tokenAccount = await createAccount(
connection,
signer,
mint,
signer.publicKey,
undefined,
undefined,
TOKEN_2022_PROGRAM_ID
);
await mintTo(
connection,
signer,
mint,
tokenAccount,
mintAuthority,
mintAmount,
[],
undefined,
TOKEN_2022_PROGRAM_ID
);
console.log('Token deployed & minted');
console.log('Token address :>> ', mint.toString());
})();