-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add burn token action * refactor: fix lint issues * feat: add burn token to public api * feat: add close instruction to remove empty account * test: update timeout for the failing test * test: increase timeouts for particular tests
- Loading branch information
Showing
4 changed files
with
62 additions
and
5 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,58 @@ | ||
import { PublicKey } from '@solana/web3.js'; | ||
import { Wallet } from '../wallet'; | ||
import { Connection } from '../Connection'; | ||
import { sendTransaction } from './transactions'; | ||
import { Transaction } from '../Transaction'; | ||
import { Token, TOKEN_PROGRAM_ID, u64 } from '@solana/spl-token'; | ||
|
||
interface IBurnTokenParams { | ||
connection: Connection; | ||
wallet: Wallet; | ||
token: PublicKey; | ||
mint: PublicKey; | ||
amount: number | u64; | ||
owner?: PublicKey; | ||
// close token account after | ||
close?: boolean; | ||
} | ||
|
||
interface IBurnTokenResponse { | ||
txId: string; | ||
} | ||
|
||
export const burnToken = async ({ | ||
connection, | ||
wallet, | ||
token, | ||
mint, | ||
amount, | ||
owner, | ||
close = true, | ||
}: IBurnTokenParams): Promise<IBurnTokenResponse> => { | ||
const tx = new Transaction({ feePayer: wallet.publicKey }).add( | ||
Token.createBurnInstruction( | ||
TOKEN_PROGRAM_ID, | ||
mint, | ||
token, | ||
owner ?? wallet.publicKey, | ||
[], | ||
amount, | ||
), | ||
); | ||
|
||
if (close) { | ||
tx.add( | ||
Token.createCloseAccountInstruction( | ||
TOKEN_PROGRAM_ID, | ||
token, | ||
wallet.publicKey, | ||
owner ?? wallet.publicKey, | ||
[], | ||
), | ||
); | ||
} | ||
|
||
const txId = await sendTransaction({ connection, wallet, txs: [tx] }); | ||
|
||
return { txId }; | ||
}; |
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
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
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