diff --git a/sdk/package.json b/sdk/package.json index 96ecb688..1ba36331 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@metadaoproject/futarchy", - "version": "0.7.3-alpha.1", + "version": "0.7.3-alpha.2", "type": "module", "main": "dist/index.js", "module": "dist/index.js", diff --git a/sdk/src/v0.7/FutarchyClient.ts b/sdk/src/v0.7/FutarchyClient.ts index 55a2d550..13ee4e42 100644 --- a/sdk/src/v0.7/FutarchyClient.ts +++ b/sdk/src/v0.7/FutarchyClient.ts @@ -574,15 +574,7 @@ export class FutarchyClient { this.vaultClient.vaultProgram.programId, )[0], question, - }) - .preInstructions([ - createAssociatedTokenAccountIdempotentInstruction( - payer, - getAssociatedTokenAddressSync(outputMint, trader, true), - trader, - outputMint, - ), - ]); + }); } squadsProposalCreateTx({ diff --git a/tests/futarchy/unit/collectFees.test.ts b/tests/futarchy/unit/collectFees.test.ts index d0054974..0b61ef8e 100644 --- a/tests/futarchy/unit/collectFees.test.ts +++ b/tests/futarchy/unit/collectFees.test.ts @@ -185,6 +185,13 @@ export default function suite() { ], }); + const { failQuoteMint } = this.futarchy.getProposalPdas( + proposal, + META, + USDC, + dao, + ); + await this.conditionalVault .splitTokensIx(question, baseVault, META, new BN(5 * 10 ** 6), 2) .rpc(); @@ -204,6 +211,18 @@ export default function suite() { inputAmount: new BN(1), minOutputAmount: new BN(0), }) + .preInstructions([ + createAssociatedTokenAccountIdempotentInstruction( + this.payer.publicKey, + getAssociatedTokenAddressSync( + failQuoteMint, + this.payer.publicKey, + true, + ), + this.payer.publicKey, + failQuoteMint, + ), + ]) .rpc(); const callbacks = expectError( diff --git a/tests/futarchy/unit/conditionalSwap.test.ts b/tests/futarchy/unit/conditionalSwap.test.ts index 05c6eb8d..350f3a78 100644 --- a/tests/futarchy/unit/conditionalSwap.test.ts +++ b/tests/futarchy/unit/conditionalSwap.test.ts @@ -4,6 +4,10 @@ import { PublicKey, TransactionMessage, } from "@solana/web3.js"; +import { + createAssociatedTokenAccountIdempotentInstruction, + getAssociatedTokenAddressSync, +} from "@solana/spl-token"; import { expectError, setupBasicDao } from "../../utils.js"; import { BN } from "bn.js"; import { assert } from "chai"; @@ -59,7 +63,20 @@ export default function suite() { market: "pass", swapType: "buy", inputAmount: new BN(10 * 10 ** 6), // 1 USDC + minOutputAmount: new BN(0), }) + .preInstructions([ + createAssociatedTokenAccountIdempotentInstruction( + this.payer.publicKey, + getAssociatedTokenAddressSync( + passBaseMint, + this.payer.publicKey, + true, + ), + this.payer.publicKey, + passBaseMint, + ), + ]) .rpc(); const postAmmState = (await this.futarchy.getDao(dao)).amm; @@ -115,7 +132,20 @@ export default function suite() { market: "fail", swapType: "buy", inputAmount: new BN(10 * 10 ** 6), // 1 META + minOutputAmount: new BN(0), }) + .preInstructions([ + createAssociatedTokenAccountIdempotentInstruction( + this.payer.publicKey, + getAssociatedTokenAddressSync( + failBaseMint, + this.payer.publicKey, + true, + ), + this.payer.publicKey, + failBaseMint, + ), + ]) .rpc(); const postFailQuoteBalance = await this.getTokenBalance( @@ -144,6 +174,13 @@ export default function suite() { ], }); + const { passBaseMint } = this.futarchy.getProposalPdas( + proposal, + META, + USDC, + dao, + ); + // Split some tokens to have conditional tokens to trade await this.conditionalVault .splitTokensIx(question, quoteVault, USDC, new BN(5 * 10 ** 6), 2) @@ -164,7 +201,20 @@ export default function suite() { market: "pass", swapType: "buy", inputAmount: new BN(1000 * 10 ** 6), // 1000 USDC (more than we have) + minOutputAmount: new BN(0), }) + .preInstructions([ + createAssociatedTokenAccountIdempotentInstruction( + this.payer.publicKey, + getAssociatedTokenAddressSync( + passBaseMint, + this.payer.publicKey, + true, + ), + this.payer.publicKey, + passBaseMint, + ), + ]) .rpc() .then(callbacks[0], callbacks[1]); }); @@ -182,6 +232,13 @@ export default function suite() { ], }); + const { passQuoteMint } = this.futarchy.getProposalPdas( + proposal, + META, + USDC, + dao, + ); + // Split some tokens to have conditional tokens to trade await this.conditionalVault .splitTokensIx(question, baseVault, META, new BN(5 * 10 ** 6), 2) @@ -199,9 +256,6 @@ export default function suite() { }) .rpc(); - // Ensure user has USDC token account for input (already created in beforeEach) - // await this.createTokenAccount(USDC, this.payer.publicKey); - // Finalize the proposal first await this.futarchy .finalizeProposalIxV2({ @@ -227,7 +281,20 @@ export default function suite() { market: "pass", swapType: "sell", inputAmount: new BN(1 * 10 ** 6), + minOutputAmount: new BN(0), }) + .preInstructions([ + createAssociatedTokenAccountIdempotentInstruction( + this.payer.publicKey, + getAssociatedTokenAddressSync( + passQuoteMint, + this.payer.publicKey, + true, + ), + this.payer.publicKey, + passQuoteMint, + ), + ]) .rpc() .then(callbacks[0], callbacks[1]); }); @@ -245,14 +312,18 @@ export default function suite() { ], }); + const { passQuoteMint } = this.futarchy.getProposalPdas( + proposal, + META, + USDC, + dao, + ); + // Split some tokens to have conditional tokens to trade await this.conditionalVault .splitTokensIx(question, baseVault, META, new BN(5 * 10 ** 6), 2) .rpc(); - // Ensure user has USDC token account for input (already created in beforeEach) - // await this.createTokenAccount(USDC, this.payer.publicKey); - const callbacks = expectError( "SwapSlippageExceeded", "conditional swap should fail when slippage is too high", @@ -270,6 +341,18 @@ export default function suite() { inputAmount: new BN(1 * 10 ** 6), // 1 META minOutputAmount: new BN(1000 * 10 ** 6), // Expect 1000 USDC (unrealistic) }) + .preInstructions([ + createAssociatedTokenAccountIdempotentInstruction( + this.payer.publicKey, + getAssociatedTokenAddressSync( + passQuoteMint, + this.payer.publicKey, + true, + ), + this.payer.publicKey, + passQuoteMint, + ), + ]) .rpc() .then(callbacks[0], callbacks[1]); }); diff --git a/tests/futarchy/unit/executeSpendingLimitChange.test.ts b/tests/futarchy/unit/executeSpendingLimitChange.test.ts index 18566129..fb1cb6e0 100644 --- a/tests/futarchy/unit/executeSpendingLimitChange.test.ts +++ b/tests/futarchy/unit/executeSpendingLimitChange.test.ts @@ -8,6 +8,10 @@ import { Transaction, TransactionMessage, } from "@solana/web3.js"; +import { + createAssociatedTokenAccountIdempotentInstruction, + getAssociatedTokenAddressSync, +} from "@solana/spl-token"; import BN from "bn.js"; import { expectError, setupBasicDao } from "../../utils.js"; import { assert } from "chai"; @@ -77,12 +81,8 @@ export default function suite() { proposal = proposalResult.proposal; squadsProposal = proposalResult.squadsProposal; - const { question, quoteVault } = this.futarchy.getProposalPdas( - proposal, - META, - USDC, - dao, - ); + const { question, quoteVault, passBaseMint } = + this.futarchy.getProposalPdas(proposal, META, USDC, dao); await this.conditionalVault .splitTokensIx(question, quoteVault, USDC, new BN(11_000 * 1_000_000), 2) @@ -100,6 +100,18 @@ export default function suite() { inputAmount: new BN(10_000 * 1_000_000), minOutputAmount: new BN(0), }) + .preInstructions([ + createAssociatedTokenAccountIdempotentInstruction( + this.payer.publicKey, + getAssociatedTokenAddressSync( + passBaseMint, + this.payer.publicKey, + true, + ), + this.payer.publicKey, + passBaseMint, + ), + ]) .rpc(); // Crank TWAP to build up price history @@ -190,12 +202,8 @@ export default function suite() { proposal = proposalResult.proposal; squadsProposal = proposalResult.squadsProposal; - const { question, quoteVault } = this.futarchy.getProposalPdas( - proposal, - META, - USDC, - dao, - ); + const { question, quoteVault, passBaseMint } = + this.futarchy.getProposalPdas(proposal, META, USDC, dao); await this.conditionalVault .splitTokensIx(question, quoteVault, USDC, new BN(11_000 * 1_000_000), 2) @@ -213,6 +221,18 @@ export default function suite() { inputAmount: new BN(10_000 * 1_000_000), minOutputAmount: new BN(0), }) + .preInstructions([ + createAssociatedTokenAccountIdempotentInstruction( + this.payer.publicKey, + getAssociatedTokenAddressSync( + passBaseMint, + this.payer.publicKey, + true, + ), + this.payer.publicKey, + passBaseMint, + ), + ]) .rpc(); // Crank TWAP to build up price history @@ -309,12 +329,8 @@ export default function suite() { proposal = proposalResult.proposal; squadsProposal = proposalResult.squadsProposal; - const { question, quoteVault } = this.futarchy.getProposalPdas( - proposal, - META, - USDC, - dao, - ); + const { question, quoteVault, passBaseMint } = + this.futarchy.getProposalPdas(proposal, META, USDC, dao); await this.conditionalVault .splitTokensIx(question, quoteVault, USDC, new BN(11_000 * 1_000_000), 2) @@ -332,6 +348,18 @@ export default function suite() { inputAmount: new BN(10_000 * 1_000_000), minOutputAmount: new BN(0), }) + .preInstructions([ + createAssociatedTokenAccountIdempotentInstruction( + this.payer.publicKey, + getAssociatedTokenAddressSync( + passBaseMint, + this.payer.publicKey, + true, + ), + this.payer.publicKey, + passBaseMint, + ), + ]) .rpc(); // Crank TWAP to build up price history diff --git a/tests/futarchy/unit/finalizeProposal.test.ts b/tests/futarchy/unit/finalizeProposal.test.ts index a93fec1c..46a57e13 100644 --- a/tests/futarchy/unit/finalizeProposal.test.ts +++ b/tests/futarchy/unit/finalizeProposal.test.ts @@ -8,6 +8,10 @@ import { Transaction, TransactionMessage, } from "@solana/web3.js"; +import { + createAssociatedTokenAccountIdempotentInstruction, + getAssociatedTokenAddressSync, +} from "@solana/spl-token"; import BN from "bn.js"; import { expectError, setupBasicDao } from "../../utils.js"; import { assert } from "chai"; @@ -246,12 +250,8 @@ export default function suite() { }); it("fails proposals when Pass TWAP < Fail TWAP", async function () { - const { quoteVault, question } = this.futarchy.getProposalPdas( - proposal, - META, - USDC, - dao, - ); + const { quoteVault, question, passBaseMint } = + this.futarchy.getProposalPdas(proposal, META, USDC, dao); await this.conditionalVault .splitTokensIx(question, quoteVault, USDC, new BN(11_000 * 1_000_000), 2) @@ -271,6 +271,16 @@ export default function suite() { }) .preInstructions([ ComputeBudgetProgram.setComputeUnitPrice({ microLamports: i }), + createAssociatedTokenAccountIdempotentInstruction( + this.payer.publicKey, + getAssociatedTokenAddressSync( + passBaseMint, + this.payer.publicKey, + true, + ), + this.payer.publicKey, + passBaseMint, + ), ]) .rpc(); diff --git a/yarn.lock b/yarn.lock index 784a21db..ea4bdca0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -975,7 +975,7 @@ "@jridgewell/sourcemap-codec" "^1.4.10" "@metadaoproject/futarchy@./sdk": - version "0.7.3-alpha.1" + version "0.7.3-alpha.2" dependencies: "@coral-xyz/anchor" "^0.29.0" "@metaplex-foundation/umi" "^0.9.2"