Skip to content

Commit

Permalink
Add payer to resolveATA functions (#6)
Browse files Browse the repository at this point in the history
- Allow another wallet to be used to fund the ATA accounts than the caller of the method
  • Loading branch information
odcheung authored Jun 9, 2022
1 parent 888983b commit 1bf36ce
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/common-sdk/src/web3/ata-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@ import { EMPTY_INSTRUCTION } from "./transactions/types";
* @param ownerAddress The user's public key
* @param tokenMint Token mint address
* @param wrappedSolAmountIn Optional. Only use for input/source token that could be SOL
* @param payer Payer that would pay the rent for the creation of the ATAs
* @returns
*/
export async function resolveOrCreateATA(
connection: Connection,
ownerAddress: PublicKey,
tokenMint: PublicKey,
getAccountRentExempt: () => Promise<number>,
wrappedSolAmountIn = new u64(0)
wrappedSolAmountIn = new u64(0),
payer = ownerAddress
): Promise<ResolvedTokenAddressInstruction> {
const instructions = await resolveOrCreateATAs(
connection,
ownerAddress,
[{ tokenMint, wrappedSolAmountIn }],
getAccountRentExempt
getAccountRentExempt,
payer
);
return instructions[0]!;
}
Expand All @@ -54,13 +57,15 @@ type ResolvedTokenAddressRequest = {
* @param ownerAddress The user's public key
* @param tokenMint Token mint address
* @param wrappedSolAmountIn Optional. Only use for input/source token that could be SOL
* @param payer Payer that would pay the rent for the creation of the ATAs
* @returns
*/
export async function resolveOrCreateATAs(
connection: Connection,
ownerAddress: PublicKey,
requests: ResolvedTokenAddressRequest[],
getAccountRentExempt: () => Promise<number>
getAccountRentExempt: () => Promise<number>,
payer = ownerAddress
): Promise<ResolvedTokenAddressInstruction[]> {
const nonNativeMints = requests.filter(({ tokenMint }) => !tokenMint.equals(NATIVE_MINT));
const nativeMints = requests.filter(({ tokenMint }) => tokenMint.equals(NATIVE_MINT));
Expand Down Expand Up @@ -90,7 +95,7 @@ export async function resolveOrCreateATAs(
nonNativeMints[index]!.tokenMint,
ataAddress,
ownerAddress,
ownerAddress
payer
);

resolvedInstruction = {
Expand Down

0 comments on commit 1bf36ce

Please sign in to comment.