Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify source token account on transfer #3607

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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