@@ -4,6 +4,10 @@ import {
44 PublicKey ,
55 TransactionMessage ,
66} from "@solana/web3.js" ;
7+ import {
8+ createAssociatedTokenAccountIdempotentInstruction ,
9+ getAssociatedTokenAddressSync ,
10+ } from "@solana/spl-token" ;
711import { expectError , setupBasicDao } from "../../utils.js" ;
812import { BN } from "bn.js" ;
913import { assert } from "chai" ;
@@ -59,7 +63,20 @@ export default function suite() {
5963 market : "pass" ,
6064 swapType : "buy" ,
6165 inputAmount : new BN ( 10 * 10 ** 6 ) , // 1 USDC
66+ minOutputAmount : new BN ( 0 ) ,
6267 } )
68+ . preInstructions ( [
69+ createAssociatedTokenAccountIdempotentInstruction (
70+ this . payer . publicKey ,
71+ getAssociatedTokenAddressSync (
72+ passBaseMint ,
73+ this . payer . publicKey ,
74+ true ,
75+ ) ,
76+ this . payer . publicKey ,
77+ passBaseMint ,
78+ ) ,
79+ ] )
6380 . rpc ( ) ;
6481
6582 const postAmmState = ( await this . futarchy . getDao ( dao ) ) . amm ;
@@ -115,7 +132,20 @@ export default function suite() {
115132 market : "fail" ,
116133 swapType : "buy" ,
117134 inputAmount : new BN ( 10 * 10 ** 6 ) , // 1 META
135+ minOutputAmount : new BN ( 0 ) ,
118136 } )
137+ . preInstructions ( [
138+ createAssociatedTokenAccountIdempotentInstruction (
139+ this . payer . publicKey ,
140+ getAssociatedTokenAddressSync (
141+ failBaseMint ,
142+ this . payer . publicKey ,
143+ true ,
144+ ) ,
145+ this . payer . publicKey ,
146+ failBaseMint ,
147+ ) ,
148+ ] )
119149 . rpc ( ) ;
120150
121151 const postFailQuoteBalance = await this . getTokenBalance (
@@ -144,6 +174,13 @@ export default function suite() {
144174 ] ,
145175 } ) ;
146176
177+ const { passBaseMint } = this . futarchy . getProposalPdas (
178+ proposal ,
179+ META ,
180+ USDC ,
181+ dao ,
182+ ) ;
183+
147184 // Split some tokens to have conditional tokens to trade
148185 await this . conditionalVault
149186 . splitTokensIx ( question , quoteVault , USDC , new BN ( 5 * 10 ** 6 ) , 2 )
@@ -164,7 +201,20 @@ export default function suite() {
164201 market : "pass" ,
165202 swapType : "buy" ,
166203 inputAmount : new BN ( 1000 * 10 ** 6 ) , // 1000 USDC (more than we have)
204+ minOutputAmount : new BN ( 0 ) ,
167205 } )
206+ . preInstructions ( [
207+ createAssociatedTokenAccountIdempotentInstruction (
208+ this . payer . publicKey ,
209+ getAssociatedTokenAddressSync (
210+ passBaseMint ,
211+ this . payer . publicKey ,
212+ true ,
213+ ) ,
214+ this . payer . publicKey ,
215+ passBaseMint ,
216+ ) ,
217+ ] )
168218 . rpc ( )
169219 . then ( callbacks [ 0 ] , callbacks [ 1 ] ) ;
170220 } ) ;
@@ -182,6 +232,13 @@ export default function suite() {
182232 ] ,
183233 } ) ;
184234
235+ const { passQuoteMint } = this . futarchy . getProposalPdas (
236+ proposal ,
237+ META ,
238+ USDC ,
239+ dao ,
240+ ) ;
241+
185242 // Split some tokens to have conditional tokens to trade
186243 await this . conditionalVault
187244 . splitTokensIx ( question , baseVault , META , new BN ( 5 * 10 ** 6 ) , 2 )
@@ -199,9 +256,6 @@ export default function suite() {
199256 } )
200257 . rpc ( ) ;
201258
202- // Ensure user has USDC token account for input (already created in beforeEach)
203- // await this.createTokenAccount(USDC, this.payer.publicKey);
204-
205259 // Finalize the proposal first
206260 await this . futarchy
207261 . finalizeProposalIxV2 ( {
@@ -227,7 +281,20 @@ export default function suite() {
227281 market : "pass" ,
228282 swapType : "sell" ,
229283 inputAmount : new BN ( 1 * 10 ** 6 ) ,
284+ minOutputAmount : new BN ( 0 ) ,
230285 } )
286+ . preInstructions ( [
287+ createAssociatedTokenAccountIdempotentInstruction (
288+ this . payer . publicKey ,
289+ getAssociatedTokenAddressSync (
290+ passQuoteMint ,
291+ this . payer . publicKey ,
292+ true ,
293+ ) ,
294+ this . payer . publicKey ,
295+ passQuoteMint ,
296+ ) ,
297+ ] )
231298 . rpc ( )
232299 . then ( callbacks [ 0 ] , callbacks [ 1 ] ) ;
233300 } ) ;
@@ -245,14 +312,18 @@ export default function suite() {
245312 ] ,
246313 } ) ;
247314
315+ const { passQuoteMint } = this . futarchy . getProposalPdas (
316+ proposal ,
317+ META ,
318+ USDC ,
319+ dao ,
320+ ) ;
321+
248322 // Split some tokens to have conditional tokens to trade
249323 await this . conditionalVault
250324 . splitTokensIx ( question , baseVault , META , new BN ( 5 * 10 ** 6 ) , 2 )
251325 . rpc ( ) ;
252326
253- // Ensure user has USDC token account for input (already created in beforeEach)
254- // await this.createTokenAccount(USDC, this.payer.publicKey);
255-
256327 const callbacks = expectError (
257328 "SwapSlippageExceeded" ,
258329 "conditional swap should fail when slippage is too high" ,
@@ -270,6 +341,18 @@ export default function suite() {
270341 inputAmount : new BN ( 1 * 10 ** 6 ) , // 1 META
271342 minOutputAmount : new BN ( 1000 * 10 ** 6 ) , // Expect 1000 USDC (unrealistic)
272343 } )
344+ . preInstructions ( [
345+ createAssociatedTokenAccountIdempotentInstruction (
346+ this . payer . publicKey ,
347+ getAssociatedTokenAddressSync (
348+ passQuoteMint ,
349+ this . payer . publicKey ,
350+ true ,
351+ ) ,
352+ this . payer . publicKey ,
353+ passQuoteMint ,
354+ ) ,
355+ ] )
273356 . rpc ( )
274357 . then ( callbacks [ 0 ] , callbacks [ 1 ] ) ;
275358 } ) ;
0 commit comments