-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Giannis Chatziveroglou
committed
Sep 13, 2023
1 parent
3c2f332
commit 4cfb036
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as anchor from "@project-serum/anchor"; | ||
import { Keypair, PublicKey, Transaction } from "@solana/web3.js"; | ||
import dotenv from "dotenv"; | ||
|
||
import { createCloseMintManagerInstruction, MintManager } from "../sdk"; | ||
import { findMintEditionId, findMintManagerId } from "../sdk/pda"; | ||
import { connectionFor, executeTransaction } from "../utils"; | ||
|
||
dotenv.config(); | ||
|
||
export type Params = { | ||
mintManagerId: PublicKey; | ||
}; | ||
|
||
const wallet = Keypair.fromSecretKey( | ||
anchor.utils.bytes.bs58.decode(process.env.WALLET || "") | ||
); // your wallet's secret key | ||
|
||
const main = async (params: Params, cluster = "devnet") => { | ||
const connection = connectionFor(cluster); | ||
const transaction = new Transaction(); | ||
|
||
const mintManager = await MintManager.fromAccountAddress( | ||
connection, | ||
params.mintManagerId | ||
); | ||
const tkas = await connection.getTokenLargestAccounts(mintManager.mint); | ||
const tokenAccount = tkas.value.find((tk) => Number(tk.amount) === 1); | ||
|
||
if (!tokenAccount) { | ||
throw "None"; | ||
} | ||
|
||
transaction.add( | ||
createCloseMintManagerInstruction({ | ||
mintManager: findMintManagerId(mintManager.mint), | ||
mint: mintManager.mint, | ||
holderTokenAccount: tokenAccount.address, | ||
newTokenAuthority: findMintEditionId(mintManager.mint), | ||
authority: wallet.publicKey, | ||
payer: wallet.publicKey, | ||
}) | ||
); | ||
|
||
try { | ||
const txid = await executeTransaction( | ||
connection, | ||
transaction, | ||
new anchor.Wallet(wallet) | ||
); | ||
console.log(`https://explorer.solana.com/address/${txid}`); | ||
} catch (e) { | ||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
console.log(`Transactionn failed: ${e}`); | ||
} | ||
}; | ||
|
||
main( | ||
{ | ||
mintManagerId: new PublicKey("address-here"), | ||
}, | ||
"mainnet-beta" | ||
).catch((e) => console.log(e)); |