Skip to content
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
22 changes: 13 additions & 9 deletions modules/sdk-coin-sol/src/lib/ataInitializationBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,16 @@ export class AtaInitializationBuilder extends TransactionBuilder {
throw new DuplicateMethodError('Invalid method: single mint already used');
}
validateOwnerAddress(recipient.ownerAddress);
const token = getSolTokenFromTokenName(recipient.tokenName);
let tokenAddress: string;
if (recipient.tokenAddress) {
tokenAddress = recipient.tokenAddress;
} else if (token) {
tokenAddress = token.tokenAddress;
} else {
throw new BuildTransactionError('Invalid transaction: invalid token name, got: ' + recipient.tokenName);
const token = getSolTokenFromTokenName(recipient.tokenName);
if (token) {
tokenAddress = token.tokenAddress;
} else {
throw new BuildTransactionError('Invalid transaction: invalid token name, got: ' + recipient.tokenName);
}
}
validateMintAddress(tokenAddress);

Expand All @@ -147,17 +149,19 @@ export class AtaInitializationBuilder extends TransactionBuilder {
this._instructionsData = [];
await Promise.all(
this._tokenAssociateRecipients.map(async (recipient) => {
const token = getSolTokenFromTokenName(recipient.tokenName);
let tokenAddress: string;
let programId: string;
if (recipient.tokenAddress && recipient.programId) {
tokenAddress = recipient.tokenAddress;
programId = recipient.programId;
} else if (token) {
tokenAddress = token.tokenAddress;
programId = token.programId;
} else {
throw new BuildTransactionError('Invalid transaction: invalid token name, got: ' + recipient.tokenName);
const token = getSolTokenFromTokenName(recipient.tokenName);
if (token) {
tokenAddress = token.tokenAddress;
programId = token.programId;
} else {
throw new BuildTransactionError('Invalid transaction: invalid token name, got: ' + recipient.tokenName);
}
}

// Use the provided ataAddress if it exists, otherwise calculate it
Expand Down
42 changes: 24 additions & 18 deletions modules/sdk-coin-sol/src/lib/tokenTransferBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,16 @@ export class TokenTransferBuilder extends TransactionBuilder {
*/
createAssociatedTokenAccount(recipient: TokenAssociateRecipient): this {
validateOwnerAddress(recipient.ownerAddress);
const token = getSolTokenFromTokenName(recipient.tokenName);
let tokenAddress: string;
if (recipient.tokenAddress) {
tokenAddress = recipient.tokenAddress;
} else if (token) {
tokenAddress = token.tokenAddress;
} else {
throw new BuildTransactionError('Invalid token name, got: ' + recipient.tokenName);
const token = getSolTokenFromTokenName(recipient.tokenName);
if (token) {
tokenAddress = token.tokenAddress;
} else {
throw new BuildTransactionError('Invalid token name, got: ' + recipient.tokenName);
}
}
validateMintAddress(tokenAddress);

Expand All @@ -119,7 +121,6 @@ export class TokenTransferBuilder extends TransactionBuilder {
assert(this._sender, 'Sender must be set before building the transaction');
const sendInstructions = await Promise.all(
this._sendParams.map(async (sendParams: SendParams): Promise<TokenTransfer> => {
const coin = getSolTokenFromTokenName(sendParams.tokenName);
let tokenAddress: string;
let tokenName: string;
let programId: string | undefined;
Expand All @@ -129,13 +130,16 @@ export class TokenTransferBuilder extends TransactionBuilder {
tokenName = sendParams.tokenName;
programId = sendParams.programId;
decimals = sendParams.decimalPlaces;
} else if (coin) {
tokenAddress = coin.tokenAddress;
tokenName = coin.name;
programId = coin.programId;
decimals = coin.decimalPlaces;
} else {
throw new Error(`Could not determine token information for ${sendParams.tokenName}`);
const coin = getSolTokenFromTokenName(sendParams.tokenName);
if (coin) {
tokenAddress = coin.tokenAddress;
tokenName = coin.name;
programId = coin.programId;
decimals = coin.decimalPlaces;
} else {
throw new Error(`Could not determine token information for ${sendParams.tokenName}`);
}
}
const sourceAddress = await getAssociatedTokenAccountAddress(tokenAddress, this._sender, false, programId);
return {
Expand All @@ -158,20 +162,22 @@ export class TokenTransferBuilder extends TransactionBuilder {
});
const createAtaInstructions = await Promise.all(
uniqueCreateAtaParams.map(async (recipient: TokenAssociateRecipient): Promise<AtaInit> => {
const coin = getSolTokenFromTokenName(recipient.tokenName);
let tokenAddress: string;
let tokenName: string;
let programId: string | undefined;
if (coin) {
tokenName = coin.name;
tokenAddress = coin.tokenAddress;
programId = coin.programId;
} else if (recipient.tokenAddress && recipient.programId) {
if (recipient.tokenAddress && recipient.programId) {
tokenName = recipient.tokenName;
tokenAddress = recipient.tokenAddress;
programId = recipient.programId;
} else {
throw new Error(`Could not determine token information for ${recipient.tokenName}`);
const coin = getSolTokenFromTokenName(recipient.tokenName);
if (coin) {
tokenName = coin.name;
tokenAddress = coin.tokenAddress;
programId = coin.programId;
} else {
throw new Error(`Could not determine token information for ${recipient.tokenName}`);
}
}

// Use the provided ataAddress if it exists, otherwise calculate it
Expand Down
Loading