1
1
import { BN , web3 } from "@coral-xyz/anchor" ;
2
2
import {
3
3
ASSOCIATED_TOKEN_PROGRAM_ID ,
4
+ AccountLayout ,
4
5
TOKEN_PROGRAM_ID ,
6
+ createAssociatedTokenAccount ,
5
7
createMint ,
8
+ getAssociatedTokenAddressSync ,
6
9
getOrCreateAssociatedTokenAccount ,
7
10
mintTo ,
11
+ transfer ,
8
12
} from "@solana/spl-token" ;
9
13
import {
10
14
Connection ,
@@ -24,6 +28,7 @@ import {
24
28
} from "../dlmm/helpers" ;
25
29
import { DLMM } from "../dlmm/index" ;
26
30
import { ActivationType } from "../dlmm/types" ;
31
+ import e from "express" ;
27
32
28
33
const keypairBuffer = fs . readFileSync (
29
34
"../keys/localnet/admin-bossj3JvwiNK7pvjr149DqdtJxf2gdygbcmEPTkb2F1.json" ,
@@ -54,6 +59,7 @@ describe("Single Bin Seed Liquidity Test", () => {
54
59
let userUSDC : web3 . PublicKey ;
55
60
let pairKey : web3 . PublicKey ;
56
61
let pair : DLMM ;
62
+ let positionOwnerTokenX : web3 . PublicKey ;
57
63
58
64
const initialPricePerLamport = DLMM . getPricePerLamport ( wenDecimal , usdcDecimal , initialPrice ) ;
59
65
const binId = DLMM . getBinIdFromPrice ( initialPricePerLamport , binStep , false ) ;
@@ -172,9 +178,24 @@ describe("Single Bin Seed Liquidity Test", () => {
172
178
cluster : "localhost" ,
173
179
} ) ;
174
180
181
+ positionOwnerTokenX = getAssociatedTokenAddressSync (
182
+ WEN , positionOwnerKeypair . publicKey , true
183
+ ) ;
175
184
} ) ;
176
185
177
186
it ( "seed liquidity single bin" , async ( ) => {
187
+ const positionOwnerTokenXAccount = await connection . getAccountInfo ( positionOwnerTokenX ) ;
188
+
189
+ if ( positionOwnerTokenXAccount ) {
190
+ const account = AccountLayout . decode ( positionOwnerTokenXAccount . data ) ;
191
+ if ( account . amount == BigInt ( 0 ) ) {
192
+ await transfer ( connection , owner , userWEN , positionOwnerTokenX , owner , 1 ) ;
193
+ }
194
+ } else {
195
+ await createAssociatedTokenAccount ( connection , owner , WEN , positionOwnerKeypair . publicKey ) ;
196
+ await transfer ( connection , owner , userWEN , positionOwnerTokenX , owner , 1 ) ;
197
+ }
198
+
178
199
const ixs = await pair . seedLiquiditySingleBin (
179
200
owner . publicKey ,
180
201
baseKeypair . publicKey ,
@@ -212,7 +233,7 @@ describe("Single Bin Seed Liquidity Test", () => {
212
233
. then ( ( i ) => new BN ( i . value . amount ) ) ;
213
234
214
235
// minus 1 send to positionOwnerTokenX account
215
- const actualDepositedAmount = beforeTokenXBalance . sub ( afterTokenXBalance ) . sub ( new BN ( 1 ) ) ;
236
+ const actualDepositedAmount = beforeTokenXBalance . sub ( afterTokenXBalance ) ;
216
237
expect ( actualDepositedAmount . toString ( ) ) . toEqual ( wenSeedAmount . toString ( ) ) ;
217
238
} )
218
239
0 commit comments