mirror of
https://github.com/tymur999/sol-incinerator-oss.git
synced 2025-08-03 15:20:36 +00:00
initial
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
.env
|
75
burn.ts
Normal file
75
burn.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import {Config} from "./config";
|
||||
import {ComputeBudgetProgram, TransactionMessage, VersionedTransaction} from "@solana/web3.js";
|
||||
import {createCloseAccountInstruction, TOKEN_PROGRAM_ID} from "@solana/spl-token";
|
||||
import bs58 from "bs58";
|
||||
|
||||
const blacklist = [
|
||||
"EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",
|
||||
"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
|
||||
];
|
||||
|
||||
(async function close_atas() {
|
||||
const atas = await Config.connection.getParsedTokenAccountsByOwner(Config.solWallet.publicKey, {
|
||||
programId: TOKEN_PROGRAM_ID
|
||||
});
|
||||
|
||||
const inst = [
|
||||
ComputeBudgetProgram.setComputeUnitPrice({microLamports: 1000}),
|
||||
ComputeBudgetProgram.setComputeUnitLimit({units: 45000})
|
||||
];
|
||||
|
||||
const block = await Config.connection.getLatestBlockhash({commitment: "processed"});
|
||||
for(const ata of atas.value.slice(0, 15)) {
|
||||
const data = (<TokenAccountData> ata.account.data.parsed).info;
|
||||
if(blacklist.includes(data.mint)) continue;
|
||||
if(data.tokenAmount.amount != "0") {
|
||||
console.log("Skipping", data.mint);
|
||||
continue;
|
||||
}
|
||||
console.log("mint:", data.mint)
|
||||
|
||||
inst.push(
|
||||
createCloseAccountInstruction(
|
||||
ata.pubkey,
|
||||
Config.solWallet.publicKey,
|
||||
Config.solWallet.publicKey
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const txn = new VersionedTransaction(new TransactionMessage({
|
||||
instructions: inst,
|
||||
payerKey: Config.solWallet.publicKey,
|
||||
recentBlockhash: block.blockhash
|
||||
}).compileToV0Message());
|
||||
txn.sign([Config.solWallet.payer]);
|
||||
let sig = bs58.encode(txn.signatures[0]);
|
||||
|
||||
await Config.connection.sendTransaction(txn, {
|
||||
preflightCommitment: "processed",
|
||||
skipPreflight: false,
|
||||
maxRetries: 10
|
||||
});
|
||||
|
||||
let res = await Config.connection.confirmTransaction({
|
||||
...block,
|
||||
signature: sig
|
||||
}, "processed");
|
||||
if(!res.value.err)
|
||||
console.log("14 token accounts successfully closed");
|
||||
})();
|
||||
|
||||
interface TokenAccountData {
|
||||
info: {
|
||||
isNative: boolean,
|
||||
mint: string,
|
||||
owner: string,
|
||||
state: string,
|
||||
tokenAmount: {
|
||||
amount: string,
|
||||
decimals: number,
|
||||
uiAmount: number,
|
||||
uiAmountString: string
|
||||
}
|
||||
}
|
||||
}
|
17
config.ts
Normal file
17
config.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import web3, {Connection, PublicKey} from "@solana/web3.js";
|
||||
import {Wallet} from "@project-serum/anchor";
|
||||
|
||||
export class Config {
|
||||
public static RPC_URL: string = process.env.RPC_URL!;
|
||||
public static solWallet = new Wallet(
|
||||
web3.Keypair.fromSeed(
|
||||
Uint8Array.from(
|
||||
JSON.parse(process.env.WALLET!)
|
||||
).slice(0, 32)
|
||||
)
|
||||
);
|
||||
|
||||
public static connection = new Connection(Config.RPC_URL, {
|
||||
commitment: "processed"
|
||||
});
|
||||
}
|
1038
package-lock.json
generated
Normal file
1038
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
16
package.json
Normal file
16
package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "close-token-accounts",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"burn": "tsc && node --env-file .env src/burn.js"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@project-serum/anchor": "^0.26.0",
|
||||
"@solana/spl-token": "^0.4.8",
|
||||
"@solana/web3.js": "^1.95.0",
|
||||
"bs58": "^6.0.0"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user