Last active
March 2, 2025 14:03
-
-
Save 5aurabh/00ba282a5559cdb3e191b60c6e13e4b9 to your computer and use it in GitHub Desktop.
clsoePosition example for whirlpool-sdk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { web3, splToken, orca, orcaCommon, Decimal, SOL, USDC } = require('./commonImports'); | |
const utils = require('./utils'); | |
const { | |
connection, | |
ctx, | |
client, | |
whirlpoolPublicKey, | |
walletPublicKey | |
} = require('./setup') | |
async function example(){ | |
const positionAddress = "BaVSMffw3zhrGDbiYvPCQ46vSjVKTHrHgQLXCJuEyY9X"; | |
await closePosition(ctx, positionAddress); | |
} | |
async function closePosition(ctx, positionAddress){ | |
const whirlpool = await client.getPool(whirlpoolPublicKey); | |
const slippage = orcaCommon.Percentage.fromFraction(5, 1000); // 0.5% | |
const position = await client.getPosition(positionAddress); | |
const positionData = position.getData(); | |
console.log(positionData) | |
const liquidity = positionData.liquidity; | |
const positionPublicKey = new web3.PublicKey(positionAddress); | |
console.log(positionPublicKey) | |
console.log("Position Public Key:", positionPublicKey.toBase58()); | |
// this gets the details about tokenVaultA - EUuUbDcafPrmVTD5M6qoJAoyyNbihBhugADAxRMn5he9 | |
try { | |
const poolInfo = await whirlpool.getTokenVaultAInfo(whirlpool.tokenVaultA); | |
console.log("Vault A Info:", poolInfo); | |
} catch (e) { | |
console.error("Error fetching Vault A:", e); | |
} | |
// try { | |
// const poolInfo = await whirlpool.getTokenVaultBInfo(whirlpool.tokenVaultB); | |
// console.log("Vault B Info:", poolInfo); | |
// } catch (e) { | |
// console.error("Error fetching Vault B:", e); | |
// } | |
const tx = await whirlpool.closePosition(positionPublicKey, slippage); // sometimes this throws error Error: Unable to fetch TokenAccountInfo for vault - EUuUbDcafPrmVTD5M6qoJAoyyNbihBhugADAxRMn5he9 and sometimes this logs the transaction | |
console.log(tx) | |
return | |
// pending code for sending transaction. | |
} | |
example(); | |
module.exports = closePosition |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment