diff --git a/src/components/MergeAccountsDialog.js b/src/components/MergeAccountsDialog.js index 7c8cacf..9a52ee3 100644 --- a/src/components/MergeAccountsDialog.js +++ b/src/components/MergeAccountsDialog.js @@ -115,7 +115,6 @@ export default function MergeAccountsDialog({ open, onClose }) { assocTokAddr, mintGroup, mint, - tokenInfo.decimals, wallet, connection, enqueueSnackbar, @@ -243,11 +242,11 @@ async function mergeMint( assocTokAddr, mintAccountSet, mint, - decimals, wallet, connection, enqueueSnackbar, ) { + console.log('mint', mint, mint.toString()); if (mintAccountSet.length === 0) { return; } @@ -293,7 +292,6 @@ async function mergeMint( associatedTokenAccount, tokenAccount.account.amount, mint, - decimals, ); } } diff --git a/src/components/SendDialog.js b/src/components/SendDialog.js index e0bc089..6eff913 100644 --- a/src/components/SendDialog.js +++ b/src/components/SendDialog.js @@ -261,7 +261,6 @@ function SendSplDialog({ onClose, publicKey, balanceInfo, onSubmitRef }) { new PublicKey(destinationAddress), amount, balanceInfo.mint, - decimals, null, overrideDestinationCheck, ); diff --git a/src/utils/tokens/index.js b/src/utils/tokens/index.js index e2b05ea..7d8d9fc 100644 --- a/src/utils/tokens/index.js +++ b/src/utils/tokens/index.js @@ -14,7 +14,7 @@ import { memoInstruction, mintTo, TOKEN_PROGRAM_ID, - transferChecked, + transfer, } from './instructions'; import { ACCOUNT_LAYOUT, @@ -300,7 +300,6 @@ export async function transferTokens({ amount, memo, mint, - decimals, overrideDestinationCheck, }) { const destinationAccountInfo = await connection.getAccountInfo( @@ -313,8 +312,6 @@ export async function transferTokens({ return await transferBetweenSplTokenAccounts({ connection, owner, - mint, - decimals, sourcePublicKey, destinationPublicKey, amount, @@ -342,8 +339,6 @@ export async function transferTokens({ return await transferBetweenSplTokenAccounts({ connection, owner, - mint, - decimals, sourcePublicKey, destinationPublicKey: destinationSplTokenAccount.publicKey, amount, @@ -358,24 +353,44 @@ export async function transferTokens({ amount, memo, mint, - decimals, }); } +// SPL tokens only. +export async function transferAndClose({ + connection, + owner, + sourcePublicKey, + destinationPublicKey, + amount, +}) { + const tx = createTransferBetweenSplTokenAccountsInstruction({ + ownerPublicKey: owner.publicKey, + sourcePublicKey, + destinationPublicKey, + amount, + }); + tx.add( + closeAccount({ + source: sourcePublicKey, + destination: owner.publicKey, + owner: owner.publicKey, + }), + ); + let signers = []; + return await signAndSendTransaction(connection, tx, owner, signers); +} + function createTransferBetweenSplTokenAccountsInstruction({ ownerPublicKey, - mint, - decimals, sourcePublicKey, destinationPublicKey, amount, memo, }) { let transaction = new Transaction().add( - transferChecked({ + transfer({ source: sourcePublicKey, - mint, - decimals, destination: destinationPublicKey, owner: ownerPublicKey, amount, @@ -390,8 +405,6 @@ function createTransferBetweenSplTokenAccountsInstruction({ async function transferBetweenSplTokenAccounts({ connection, owner, - mint, - decimals, sourcePublicKey, destinationPublicKey, amount, @@ -399,8 +412,6 @@ async function transferBetweenSplTokenAccounts({ }) { const transaction = createTransferBetweenSplTokenAccountsInstruction({ ownerPublicKey: owner.publicKey, - mint, - decimals, sourcePublicKey, destinationPublicKey, amount, @@ -418,7 +429,6 @@ async function createAndTransferToAccount({ amount, memo, mint, - decimals, }) { const [ createAccountInstruction, @@ -439,8 +449,6 @@ async function createAndTransferToAccount({ const transferBetweenAccountsTxn = createTransferBetweenSplTokenAccountsInstruction( { ownerPublicKey: owner.publicKey, - mint, - decimals, sourcePublicKey, destinationPublicKey: newAddress, amount, diff --git a/src/utils/tokens/instructions.js b/src/utils/tokens/instructions.js index abc86e8..cde72f0 100644 --- a/src/utils/tokens/instructions.js +++ b/src/utils/tokens/instructions.js @@ -29,6 +29,11 @@ LAYOUT.addVariant( 'initializeMint', ); LAYOUT.addVariant(1, BufferLayout.struct([]), 'initializeAccount'); +LAYOUT.addVariant( + 3, + BufferLayout.struct([BufferLayout.nu64('amount')]), + 'transfer', +); LAYOUT.addVariant( 7, BufferLayout.struct([BufferLayout.nu64('amount')]), @@ -40,11 +45,6 @@ LAYOUT.addVariant( 'burn', ); LAYOUT.addVariant(9, BufferLayout.struct([]), 'closeAccount'); -LAYOUT.addVariant( - 12, - BufferLayout.struct([BufferLayout.nu64('amount'), BufferLayout.u8('decimals')]), - 'transferChecked', -); const instructionMaxSpan = Math.max( ...Object.values(LAYOUT.registry).map((r) => r.span), @@ -96,17 +96,16 @@ export function initializeAccount({ account, mint, owner }) { }); } -export function transferChecked({ source, mint, destination, amount, decimals, owner }) { +export function transfer({ source, destination, amount, owner }) { let keys = [ { pubkey: source, isSigner: false, isWritable: true }, - { pubkey: mint, isSigner: false, isWritable: false }, { pubkey: destination, isSigner: false, isWritable: true }, { pubkey: owner, isSigner: true, isWritable: false }, ]; return new TransactionInstruction({ keys, data: encodeTokenInstructionData({ - transferChecked: { amount, decimals }, + transfer: { amount }, }), programId: TOKEN_PROGRAM_ID, }); diff --git a/src/utils/wallet.js b/src/utils/wallet.js index 47c9af8..18667e4 100644 --- a/src/utils/wallet.js +++ b/src/utils/wallet.js @@ -14,6 +14,7 @@ import { getOwnedTokenAccounts, nativeTransfer, transferTokens, + transferAndClose, } from './tokens'; import { TOKEN_PROGRAM_ID } from './tokens/instructions'; import { @@ -98,7 +99,6 @@ export class Wallet { destination, amount, mint, - decimals, memo = null, overrideDestinationCheck = false, ) => { @@ -116,7 +116,6 @@ export class Wallet { amount, memo, mint, - decimals, overrideDestinationCheck, }); }; @@ -134,6 +133,16 @@ export class Wallet { }); }; + transferAndClose = async (source, destination, amount) => { + return await transferAndClose({ + connection: this.connection, + owner: this, + sourcePublicKey: source, + destinationPublicKey: destination, + amount, + }); + }; + signTransaction = async (transaction) => { return this.provider.signTransaction(transaction); };