@orca-so/common-sdk
Advanced tools
Comparing version 0.3.5 to 0.3.6-beta.0
@@ -44,3 +44,3 @@ "use strict"; | ||
*/ | ||
async function resolveOrCreateATAs(connection, ownerAddress, requests, getAccountRentExempt, payer = ownerAddress, modeIdempotent = false, allowPDAOwnerAddress = false, wrappedSolAccountCreateMethod = "keypair") { | ||
async function resolveOrCreateATAs(connection, ownerAddress, requests, getAccountRentExempt, payer = ownerAddress, modeIdempotent = false, allowPDAOwnerAddress = false, wrappedSolAccountCreateMethod = "ata") { | ||
const nonNativeMints = requests.filter(({ tokenMint }) => !tokenMint.equals(spl_token_1.NATIVE_MINT)); | ||
@@ -47,0 +47,0 @@ const nativeMints = requests.filter(({ tokenMint }) => tokenMint.equals(spl_token_1.NATIVE_MINT)); |
@@ -13,3 +13,3 @@ import { Connection, PublicKey } from "@solana/web3.js"; | ||
*/ | ||
export type WrappedSolAccountCreateMethod = "keypair" | "withSeed"; | ||
export type WrappedSolAccountCreateMethod = "keypair" | "withSeed" | "ata"; | ||
/** | ||
@@ -16,0 +16,0 @@ * @category Util |
@@ -30,8 +30,15 @@ "use strict"; | ||
*/ | ||
static createWrappedNativeAccountInstruction(owner, amountIn, rentExemptLamports, payer, unwrapDestination, createAccountMethod = "keypair") { | ||
static createWrappedNativeAccountInstruction(owner, amountIn, rentExemptLamports, payer, unwrapDestination, createAccountMethod = "ata") { | ||
const payerKey = payer ?? owner; | ||
const unwrapDestinationKey = unwrapDestination ?? payer ?? owner; | ||
return createAccountMethod === "keypair" | ||
? createWrappedNativeAccountInstructionWithKeypair(owner, amountIn, rentExemptLamports, payerKey, unwrapDestinationKey) | ||
: createWrappedNativeAccountInstructionWithSeed(owner, amountIn, rentExemptLamports, payerKey, unwrapDestinationKey); | ||
switch (createAccountMethod) { | ||
case "ata": | ||
return createWrappedNativeAccountInstructionWithATA(owner, amountIn, rentExemptLamports, payerKey, unwrapDestinationKey); | ||
case "keypair": | ||
return createWrappedNativeAccountInstructionWithKeypair(owner, amountIn, rentExemptLamports, payerKey, unwrapDestinationKey); | ||
case "withSeed": | ||
return createWrappedNativeAccountInstructionWithSeed(owner, amountIn, rentExemptLamports, payerKey, unwrapDestinationKey); | ||
default: | ||
throw new Error(`Invalid createAccountMethod: ${createAccountMethod}`); | ||
} | ||
} | ||
@@ -80,2 +87,25 @@ /** | ||
exports.TokenUtil = TokenUtil; | ||
function createWrappedNativeAccountInstructionWithATA(owner, amountIn, _rentExemptLamports, payerKey, unwrapDestinationKey) { | ||
const tempAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, owner); | ||
const instructions = []; | ||
const createAccountInstruction = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(payerKey, tempAccount, owner, spl_token_1.NATIVE_MINT); | ||
instructions.push(createAccountInstruction); | ||
if (amountIn.gt(math_1.ZERO)) { | ||
const transferInstruction = web3_js_1.SystemProgram.transfer({ | ||
fromPubkey: payerKey, | ||
toPubkey: tempAccount, | ||
lamports: amountIn.toNumber(), | ||
}); | ||
instructions.push(transferInstruction); | ||
const syncNativeInstruction = (0, spl_token_1.createSyncNativeInstruction)(tempAccount); | ||
instructions.push(syncNativeInstruction); | ||
} | ||
const closeWSOLAccountInstruction = (0, spl_token_1.createCloseAccountInstruction)(tempAccount, unwrapDestinationKey, owner); | ||
return { | ||
address: tempAccount, | ||
instructions, | ||
cleanupInstructions: [closeWSOLAccountInstruction], | ||
signers: [], | ||
}; | ||
} | ||
function createWrappedNativeAccountInstructionWithKeypair(owner, amountIn, rentExemptLamports, payerKey, unwrapDestinationKey) { | ||
@@ -82,0 +112,0 @@ const tempAccount = new web3_js_1.Keypair(); |
{ | ||
"name": "@orca-so/common-sdk", | ||
"version": "0.3.5", | ||
"version": "0.3.6-beta.0", | ||
"description": "Common Typescript components across Orca", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/orca-so/orca-sdks", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1803
124018
1