Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 1 addition & 9 deletions sdk/src/v0.7/FutarchyClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,15 +574,7 @@ export class FutarchyClient {
this.vaultClient.vaultProgram.programId,
)[0],
question,
})
.preInstructions([
createAssociatedTokenAccountIdempotentInstruction(
payer,
getAssociatedTokenAddressSync(outputMint, trader, true),
trader,
outputMint,
),
]);
});
}

squadsProposalCreateTx({
Expand Down
19 changes: 19 additions & 0 deletions tests/futarchy/unit/collectFees.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(
Expand Down
95 changes: 89 additions & 6 deletions tests/futarchy/unit/conditionalSwap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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]);
});
Expand All @@ -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)
Expand All @@ -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({
Expand All @@ -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]);
});
Expand All @@ -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",
Expand All @@ -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]);
});
Expand Down
64 changes: 46 additions & 18 deletions tests/futarchy/unit/executeSpendingLimitChange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
22 changes: 16 additions & 6 deletions tests/futarchy/unit/finalizeProposal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading