@@ -35,7 +35,6 @@ export interface ParsedClockState {
35
35
space : number ;
36
36
}
37
37
38
-
39
38
let activeBin ;
40
39
let userPositions ;
41
40
let totalXAmount ;
@@ -46,7 +45,7 @@ const newPosition = new Keypair();
46
45
47
46
async function getActiveBin ( dlmmPool : DLMM ) {
48
47
// Get pool state
49
- const activeBin = await dlmmPool . getActiveBin ( ) ;
48
+ activeBin = await dlmmPool . getActiveBin ( ) ;
50
49
console . log ( "🚀 ~ activeBin:" , activeBin ) ;
51
50
}
52
51
@@ -106,8 +105,8 @@ async function getPositionsState(dlmmPool: DLMM) {
106
105
user . publicKey
107
106
) ;
108
107
109
- console . log ( "🚀 ~ userPositions:" , userPositions ) ;
110
108
userPositions = positionsState . userPositions ;
109
+ console . log ( "🚀 ~ userPositions:" , userPositions ) ;
111
110
}
112
111
113
112
async function addLiquidityToExistingPosition ( dlmmPool : DLMM ) {
@@ -179,26 +178,29 @@ async function swap(dlmmPool: DLMM) {
179
178
let maxSwappedAmount : BN ;
180
179
let throttledStats : boolean ;
181
180
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
+ ) {
186
191
throttledStats = true ;
187
192
maxSwappedAmount = dlmmPool . lbPair . maxSwappedAmount ;
188
193
}
189
194
}
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 ) ;
202
204
203
205
console . log ( "🚀 ~ swapQuote:" , swapQuote ) ;
204
206
@@ -230,6 +232,7 @@ async function main() {
230
232
231
233
await getActiveBin ( dlmmPool ) ;
232
234
await createPosition ( dlmmPool ) ;
235
+ await getPositionsState ( dlmmPool ) ;
233
236
await addLiquidityToExistingPosition ( dlmmPool ) ;
234
237
await removeLiquidity ( dlmmPool ) ;
235
238
await swap ( dlmmPool ) ;
0 commit comments