From ee0605a0b586f600018764237076ac5db0ef82c0 Mon Sep 17 00:00:00 2001 From: bguillaumat Date: Wed, 19 Jun 2024 18:13:00 +0200 Subject: [PATCH] Permit Native ATA to be offcurve --- packages/common-sdk/package.json | 2 +- packages/common-sdk/src/web3/ata-util.ts | 3 ++- packages/common-sdk/src/web3/token-util.ts | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/common-sdk/package.json b/packages/common-sdk/package.json index 383ff9d..185f8d4 100644 --- a/packages/common-sdk/package.json +++ b/packages/common-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@orca-so/common-sdk", - "version": "0.6.0", + "version": "0.6.1", "description": "Common Typescript components across Orca", "repository": "https://github.com/orca-so/orca-sdks", "author": "Orca Foundation", diff --git a/packages/common-sdk/src/web3/ata-util.ts b/packages/common-sdk/src/web3/ata-util.ts index 2f06fb7..9f249a0 100644 --- a/packages/common-sdk/src/web3/ata-util.ts +++ b/packages/common-sdk/src/web3/ata-util.ts @@ -161,7 +161,8 @@ export async function resolveOrCreateATAs( accountRentExempt, payer, undefined, // use default - wrappedSolAccountCreateMethod + wrappedSolAccountCreateMethod, + allowPDAOwnerAddress ); } diff --git a/packages/common-sdk/src/web3/token-util.ts b/packages/common-sdk/src/web3/token-util.ts index 4003dc8..6603631 100644 --- a/packages/common-sdk/src/web3/token-util.ts +++ b/packages/common-sdk/src/web3/token-util.ts @@ -54,6 +54,7 @@ export class TokenUtil { payer?: PublicKey, unwrapDestination?: PublicKey, createAccountMethod: WrappedSolAccountCreateMethod = "keypair", + allowPDAOwnerAddress: boolean = false, ): ResolvedTokenAddressInstruction { const payerKey = payer ?? owner; const unwrapDestinationKey = unwrapDestination ?? owner; @@ -65,7 +66,8 @@ export class TokenUtil { amountIn, rentExemptLamports, payerKey, - unwrapDestinationKey + unwrapDestinationKey, + allowPDAOwnerAddress ); case "keypair": return createWrappedNativeAccountInstructionWithKeypair( @@ -175,8 +177,9 @@ function createWrappedNativeAccountInstructionWithATA( _rentExemptLamports: number, payerKey: PublicKey, unwrapDestinationKey: PublicKey, + allowPDAOwnerAddress: boolean = false, ): ResolvedTokenAddressInstruction { - const tempAccount = getAssociatedTokenAddressSync(NATIVE_MINT, owner); + const tempAccount = getAssociatedTokenAddressSync(NATIVE_MINT, owner, allowPDAOwnerAddress); const instructions: TransactionInstruction[] = [ createAssociatedTokenAccountIdempotentInstruction(