@@ -7,87 +7,37 @@ import {
77 openFullRangePositionInstructions ,
88 increaseLiquidityInstructions ,
99} from "../src/increaseLiquidity" ;
10- import {
11- TOKEN_MINT_1 ,
12- TOKEN_MINT_2 ,
13- sendTransaction ,
14- rpc ,
15- initPayer ,
16- setAccount ,
17- } from "./mockRpc" ;
18- import { setDefaultFunder , SPLASH_POOL_TICK_SPACING } from "../src/config" ;
10+ import { sendTransaction , rpc } from "./utils/mockRpc" ;
11+ import { SPLASH_POOL_TICK_SPACING } from "../src/config" ;
1912import { swapInstructions } from "../src/swap" ;
20- import type { Address , TransactionSigner } from "@solana/web3.js" ;
13+ import type { Address } from "@solana/web3.js" ;
2114import { harvestPositionInstructions } from "../src/harvest" ;
2215import {
2316 decreaseLiquidityInstructions ,
2417 closePositionInstructions ,
2518} from "../src/decreaseLiquidity" ;
26- import {
27- AccountState ,
28- fetchToken ,
29- findAssociatedTokenPda ,
30- getTokenEncoder ,
31- TOKEN_PROGRAM_ADDRESS ,
32- } from "@solana-program/token" ;
19+ import { fetchToken } from "@solana-program/token" ;
3320import {
3421 fetchPosition ,
3522 fetchWhirlpool ,
3623 getPositionAddress ,
3724} from "@orca-so/whirlpools-client" ;
3825import assert from "assert" ;
26+ import { setupAta , setupMint } from "./utils/token" ;
27+ import { orderMints } from "../src/token" ;
3928
4029describe ( "e2e" , ( ) => {
30+ let mintA : Address ;
31+ let mintB : Address ;
4132 let ataA : Address ;
4233 let ataB : Address ;
43- let payer : TransactionSigner ;
4434
4535 beforeAll ( async ( ) => {
46- payer = await initPayer ( ) ;
47- setDefaultFunder ( payer ) ;
48-
49- [ ataA , ataB ] = await Promise . all ( [
50- findAssociatedTokenPda ( {
51- mint : TOKEN_MINT_1 ,
52- owner : payer . address ,
53- tokenProgram : TOKEN_PROGRAM_ADDRESS ,
54- } ) . then ( ( x ) => x [ 0 ] ) ,
55- findAssociatedTokenPda ( {
56- mint : TOKEN_MINT_2 ,
57- owner : payer . address ,
58- tokenProgram : TOKEN_PROGRAM_ADDRESS ,
59- } ) . then ( ( x ) => x [ 0 ] ) ,
60- ] ) ;
61-
62- setAccount (
63- ataA ,
64- getTokenEncoder ( ) . encode ( {
65- mint : TOKEN_MINT_1 ,
66- owner : payer . address ,
67- amount : 500e9 ,
68- delegate : null ,
69- state : AccountState . Initialized ,
70- isNative : null ,
71- delegatedAmount : 0 ,
72- closeAuthority : null ,
73- } ) ,
74- TOKEN_PROGRAM_ADDRESS ,
75- ) ;
76-
77- setAccount (
78- ataB ,
79- getTokenEncoder ( ) . encode ( {
80- mint : TOKEN_MINT_2 ,
81- owner : payer . address ,
82- amount : 500e9 ,
83- delegate : null ,
84- state : AccountState . Initialized ,
85- isNative : null ,
86- delegatedAmount : 0 ,
87- closeAuthority : null ,
88- } ) ,
89- TOKEN_PROGRAM_ADDRESS ,
90- ) ;
36+ const mint1 = await setupMint ( { decimals : 9 } ) ;
37+ const mint2 = await setupMint ( { decimals : 6 } ) ;
38+ [ mintA , mintB ] = orderMints ( mint1 , mint2 ) ;
39+ ataA = await setupAta ( mintA , { amount : 500e9 } ) ;
40+ ataB = await setupAta ( mintB , { amount : 500e9 } ) ;
9141 } ) ;
9242
9343 const fetchPositionByMint = async ( positionMint : Address ) => {
@@ -97,30 +47,25 @@ describe("e2e", () => {
9747
9848 const testInitSplashPool = async ( ) => {
9949 const { instructions : createPoolInstructions , poolAddress } =
100- await createSplashPoolInstructions ( rpc , TOKEN_MINT_1 , TOKEN_MINT_2 ) ;
101- await sendTransaction ( createPoolInstructions , payer ) ;
50+ await createSplashPoolInstructions ( rpc , mintA , mintB ) ;
51+ await sendTransaction ( createPoolInstructions ) ;
10252
10353 const pool = await fetchWhirlpool ( rpc , poolAddress ) ;
104- assert . strictEqual ( pool . data . tokenMintA , TOKEN_MINT_1 ) ;
105- assert . strictEqual ( pool . data . tokenMintB , TOKEN_MINT_2 ) ;
54+ assert . strictEqual ( pool . data . tokenMintA , mintA ) ;
55+ assert . strictEqual ( pool . data . tokenMintB , mintB ) ;
10656 assert . strictEqual ( pool . data . tickSpacing , SPLASH_POOL_TICK_SPACING ) ;
10757
10858 return poolAddress ;
10959 } ;
11060
11161 const testInitConcentratedLiquidityPool = async ( ) => {
11262 const { instructions : createPoolInstructions , poolAddress } =
113- await createConcentratedLiquidityPoolInstructions (
114- rpc ,
115- TOKEN_MINT_1 ,
116- TOKEN_MINT_2 ,
117- 128 ,
118- ) ;
119- await sendTransaction ( createPoolInstructions , payer ) ;
63+ await createConcentratedLiquidityPoolInstructions ( rpc , mintA , mintB , 128 ) ;
64+ await sendTransaction ( createPoolInstructions ) ;
12065
12166 const pool = await fetchWhirlpool ( rpc , poolAddress ) ;
122- assert . strictEqual ( pool . data . tokenMintA , TOKEN_MINT_1 ) ;
123- assert . strictEqual ( pool . data . tokenMintB , TOKEN_MINT_2 ) ;
67+ assert . strictEqual ( pool . data . tokenMintA , mintA ) ;
68+ assert . strictEqual ( pool . data . tokenMintB , mintB ) ;
12469 assert . strictEqual ( pool . data . tickSpacing , 128 ) ;
12570
12671 return poolAddress ;
@@ -134,7 +79,7 @@ describe("e2e", () => {
13479 await openFullRangePositionInstructions ( rpc , poolAddress , {
13580 liquidity : 1000000000n ,
13681 } ) ;
137- await sendTransaction ( instructions , payer ) ;
82+ await sendTransaction ( instructions ) ;
13883
13984 const positionAfter = await fetchPositionByMint ( positionMint ) ;
14085 const tokenAAfter = await fetchToken ( rpc , ataA ) ;
@@ -162,7 +107,7 @@ describe("e2e", () => {
162107 positionMint ,
163108 { liquidity : 10000n } ,
164109 ) ;
165- await sendTransaction ( instructions , payer ) ;
110+ await sendTransaction ( instructions ) ;
166111
167112 const positionAfter = await fetchPositionByMint ( positionMint ) ;
168113 const tokenAAfter = await fetchToken ( rpc , ataA ) ;
@@ -191,7 +136,7 @@ describe("e2e", () => {
191136 positionMint ,
192137 { liquidity : 10000n } ,
193138 ) ;
194- await sendTransaction ( instructions , payer ) ;
139+ await sendTransaction ( instructions ) ;
195140
196141 const positionAfter = await fetchPositionByMint ( positionMint ) ;
197142 const tokenAAfter = await fetchToken ( rpc , ataA ) ;
@@ -218,7 +163,7 @@ describe("e2e", () => {
218163 rpc ,
219164 positionMint ,
220165 ) ;
221- await sendTransaction ( instructions , payer ) ;
166+ await sendTransaction ( instructions ) ;
222167
223168 const tokenAAfter = await fetchToken ( rpc , ataA ) ;
224169 const tokenBAfter = await fetchToken ( rpc , ataB ) ;
@@ -241,7 +186,7 @@ describe("e2e", () => {
241186 positionMint ,
242187 { liquidity : 1000000000n } ,
243188 ) ;
244- await sendTransaction ( instructions , payer ) ;
189+ await sendTransaction ( instructions ) ;
245190
246191 const positionAfter = await rpc . getMultipleAccounts ( [ positionMint ] ) . send ( ) ;
247192 const tokenAAfter = await fetchToken ( rpc , ataA ) ;
@@ -263,10 +208,10 @@ describe("e2e", () => {
263208
264209 const { instructions, quote } = await swapInstructions (
265210 rpc ,
266- { inputAmount : 100n , mint : TOKEN_MINT_1 } ,
211+ { inputAmount : 100n , mint : mintA } ,
267212 poolAddress ,
268213 ) ;
269- await sendTransaction ( instructions , payer ) ;
214+ await sendTransaction ( instructions ) ;
270215
271216 const tokenAAfter = await fetchToken ( rpc , ataA ) ;
272217 const tokenBAfter = await fetchToken ( rpc , ataB ) ;
@@ -287,10 +232,10 @@ describe("e2e", () => {
287232
288233 const { instructions, quote } = await swapInstructions (
289234 rpc ,
290- { outputAmount : 100n , mint : TOKEN_MINT_1 } ,
235+ { outputAmount : 100n , mint : mintA } ,
291236 poolAddress ,
292237 ) ;
293- await sendTransaction ( instructions , payer ) ;
238+ await sendTransaction ( instructions ) ;
294239
295240 const tokenAAfter = await fetchToken ( rpc , ataA ) ;
296241 const tokenBAfter = await fetchToken ( rpc , ataB ) ;
@@ -311,10 +256,10 @@ describe("e2e", () => {
311256
312257 const { instructions, quote } = await swapInstructions (
313258 rpc ,
314- { inputAmount : 100000n , mint : TOKEN_MINT_2 } ,
259+ { inputAmount : 100000n , mint : mintB } ,
315260 poolAddress ,
316261 ) ;
317- await sendTransaction ( instructions , payer ) ;
262+ await sendTransaction ( instructions ) ;
318263
319264 const tokenAAfter = await fetchToken ( rpc , ataA ) ;
320265 const tokenBAfter = await fetchToken ( rpc , ataB ) ;
@@ -335,10 +280,10 @@ describe("e2e", () => {
335280
336281 const { instructions, quote } = await swapInstructions (
337282 rpc ,
338- { outputAmount : 100000n , mint : TOKEN_MINT_2 } ,
283+ { outputAmount : 100000n , mint : mintB } ,
339284 poolAddress ,
340285 ) ;
341- await sendTransaction ( instructions , payer ) ;
286+ await sendTransaction ( instructions ) ;
342287
343288 const tokenAAfter = await fetchToken ( rpc , ataA ) ;
344289 const tokenBAfter = await fetchToken ( rpc , ataB ) ;
0 commit comments