Skip to content

Commit

Permalink
Specify destination token account (#3607)
Browse files Browse the repository at this point in the history
  • Loading branch information
febo authored Apr 5, 2023
1 parent e50f2d9 commit 0cd876a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export function SendSolanaConfirmationCard({
mint: new PublicKey(token.mint!),
amount: amount.toNumber(),
decimals: token.decimals,
source: new PublicKey(token.address),
});
}
// Use an else here to avoid an extra request if we are transferring sol native mints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export function SendSolanaConfirmationCard({
mint: new PublicKey(token.mint!),
amount: amount.toNumber(),
decimals: token.decimals,
source: new PublicKey(token.address),
});
} else {
txSig = await Solana.transferToken(solanaCtx, {
Expand Down
9 changes: 6 additions & 3 deletions packages/common/src/solana/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,10 @@ export class Solana {
const { walletPublicKey, tokenClient, commitment } = solanaCtx;
const { amount, mint, destination: destinationOwner } = req;

const sourceAta = associatedTokenAddress(mint, walletPublicKey);
const source = req.source ?? associatedTokenAddress(mint, walletPublicKey);
const destinationAta = associatedTokenAddress(mint, destinationOwner);

const ownerTokenRecord = await tokenRecordAddress(mint, sourceAta);
const ownerTokenRecord = await tokenRecordAddress(mint, source);

// we need to check whether the token is lock or listed

Expand Down Expand Up @@ -441,7 +441,7 @@ export class Solana {
const transferAcccounts: TransferInstructionAccounts = {
authority: walletPublicKey,
tokenOwner: walletPublicKey,
token: sourceAta,
token: source,
metadata: await metadataAddress(mint),
mint,
edition: await masterEditionAddress(mint),
Expand Down Expand Up @@ -726,6 +726,9 @@ export type TransferTokenRequest = {
mint: PublicKey;
amount: number;
decimals?: number;
// Source token addess. If not provided, an ATA will
// be derived from the wallet.
source?: PublicKey;
};

export type TransferSolRequest = {
Expand Down

1 comment on commit 0cd876a

@vercel
Copy link

@vercel vercel bot commented on 0cd876a Apr 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.