Skip to content

Commit a0cc26f

Browse files
authored
Merge pull request #28 from MeteoraAg/unwrap-sol-ix-allow-off-curve
Fix/unwrap sol allow off curve
2 parents 635b294 + 43b172b commit a0cc26f

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

Diff for: ts-client/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@meteora-ag/dlmm",
3-
"version": "1.0.10",
3+
"version": "1.0.11",
44
"description": "",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

Diff for: ts-client/src/dlmm/helpers/index.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,15 @@ export const wrapSOLInstruction = (
156156
];
157157
};
158158

159-
export const unwrapSOLInstruction = async (owner: PublicKey) => {
160-
const wSolATAAccount = getAssociatedTokenAddressSync(NATIVE_MINT, owner);
159+
export const unwrapSOLInstruction = async (
160+
owner: PublicKey,
161+
allowOwnerOffCurve = true
162+
) => {
163+
const wSolATAAccount = getAssociatedTokenAddressSync(
164+
NATIVE_MINT,
165+
owner,
166+
allowOwnerOffCurve
167+
);
161168
if (wSolATAAccount) {
162169
const closedWrappedSolInstruction = createCloseAccountInstruction(
163170
wSolATAAccount,

Diff for: ts-client/src/example.ts

+22-19
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export interface ParsedClockState {
3535
space: number;
3636
}
3737

38-
3938
let activeBin;
4039
let userPositions;
4140
let totalXAmount;
@@ -46,7 +45,7 @@ const newPosition = new Keypair();
4645

4746
async function getActiveBin(dlmmPool: DLMM) {
4847
// Get pool state
49-
const activeBin = await dlmmPool.getActiveBin();
48+
activeBin = await dlmmPool.getActiveBin();
5049
console.log("🚀 ~ activeBin:", activeBin);
5150
}
5251

@@ -106,8 +105,8 @@ async function getPositionsState(dlmmPool: DLMM) {
106105
user.publicKey
107106
);
108107

109-
console.log("🚀 ~ userPositions:", userPositions);
110108
userPositions = positionsState.userPositions;
109+
console.log("🚀 ~ userPositions:", userPositions);
111110
}
112111

113112
async function addLiquidityToExistingPosition(dlmmPool: DLMM) {
@@ -179,26 +178,29 @@ async function swap(dlmmPool: DLMM) {
179178
let maxSwappedAmount: BN;
180179
let throttledStats: boolean;
181180
if (!swapYtoX && dlmmPool.lbPair.pairType == 1) {
182-
// get current slot
183-
const parsedClock = await connection.getParsedAccountInfo(SYSVAR_CLOCK_PUBKEY);
184-
const parsedClockAccount = (parsedClock.value!.data as ParsedAccountData).parsed as ParsedClockState;
185-
if (parsedClockAccount.info.slot <= dlmmPool.lbPair.swapCapDeactivateSlot.toNumber()) {
181+
// get current slot
182+
const parsedClock = await connection.getParsedAccountInfo(
183+
SYSVAR_CLOCK_PUBKEY
184+
);
185+
const parsedClockAccount = (parsedClock.value!.data as ParsedAccountData)
186+
.parsed as ParsedClockState;
187+
if (
188+
parsedClockAccount.info.slot <=
189+
dlmmPool.lbPair.swapCapDeactivateSlot.toNumber()
190+
) {
186191
throttledStats = true;
187192
maxSwappedAmount = dlmmPool.lbPair.maxSwappedAmount;
188193
}
189194
}
190-
const swapQuote = throttledStats ? await dlmmPool.swapQuoteWithCap(
191-
swapAmount,
192-
swapYtoX,
193-
new BN(10),
194-
maxSwappedAmount,
195-
binArrays
196-
) : await dlmmPool.swapQuote(
197-
swapAmount,
198-
swapYtoX,
199-
new BN(10),
200-
binArrays
201-
);
195+
const swapQuote = throttledStats
196+
? await dlmmPool.swapQuoteWithCap(
197+
swapAmount,
198+
swapYtoX,
199+
new BN(10),
200+
maxSwappedAmount,
201+
binArrays
202+
)
203+
: await dlmmPool.swapQuote(swapAmount, swapYtoX, new BN(10), binArrays);
202204

203205
console.log("🚀 ~ swapQuote:", swapQuote);
204206

@@ -230,6 +232,7 @@ async function main() {
230232

231233
await getActiveBin(dlmmPool);
232234
await createPosition(dlmmPool);
235+
await getPositionsState(dlmmPool);
233236
await addLiquidityToExistingPosition(dlmmPool);
234237
await removeLiquidity(dlmmPool);
235238
await swap(dlmmPool);

0 commit comments

Comments
 (0)