Skip to content

Commit 9878668

Browse files
committed
merge with develop, update SDK
2 parents 804ad58 + 33c1461 commit 9878668

7 files changed

Lines changed: 173 additions & 41 deletions

File tree

sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metadaoproject/futarchy",
3-
"version": "0.7.4-alpha.0",
3+
"version": "0.7.4-alpha.1",
44
"type": "module",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

sdk/src/v0.7/FutarchyClient.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -574,15 +574,7 @@ export class FutarchyClient {
574574
this.vaultClient.vaultProgram.programId,
575575
)[0],
576576
question,
577-
})
578-
.preInstructions([
579-
createAssociatedTokenAccountIdempotentInstruction(
580-
payer,
581-
getAssociatedTokenAddressSync(outputMint, trader, true),
582-
trader,
583-
outputMint,
584-
),
585-
]);
577+
});
586578
}
587579

588580
squadsProposalCreateTx({

tests/futarchy/unit/collectFees.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ export default function suite() {
185185
],
186186
});
187187

188+
const { failQuoteMint } = this.futarchy.getProposalPdas(
189+
proposal,
190+
META,
191+
USDC,
192+
dao,
193+
);
194+
188195
await this.conditionalVault
189196
.splitTokensIx(question, baseVault, META, new BN(5 * 10 ** 6), 2)
190197
.rpc();
@@ -204,6 +211,18 @@ export default function suite() {
204211
inputAmount: new BN(1),
205212
minOutputAmount: new BN(0),
206213
})
214+
.preInstructions([
215+
createAssociatedTokenAccountIdempotentInstruction(
216+
this.payer.publicKey,
217+
getAssociatedTokenAddressSync(
218+
failQuoteMint,
219+
this.payer.publicKey,
220+
true,
221+
),
222+
this.payer.publicKey,
223+
failQuoteMint,
224+
),
225+
])
207226
.rpc();
208227

209228
const callbacks = expectError(

tests/futarchy/unit/conditionalSwap.test.ts

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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";
711
import { expectError, setupBasicDao } from "../../utils.js";
812
import { BN } from "bn.js";
913
import { 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
});

tests/futarchy/unit/executeSpendingLimitChange.test.ts

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import {
88
Transaction,
99
TransactionMessage,
1010
} from "@solana/web3.js";
11+
import {
12+
createAssociatedTokenAccountIdempotentInstruction,
13+
getAssociatedTokenAddressSync,
14+
} from "@solana/spl-token";
1115
import BN from "bn.js";
1216
import { expectError, setupBasicDao } from "../../utils.js";
1317
import { assert } from "chai";
@@ -77,12 +81,8 @@ export default function suite() {
7781
proposal = proposalResult.proposal;
7882
squadsProposal = proposalResult.squadsProposal;
7983

80-
const { question, quoteVault } = this.futarchy.getProposalPdas(
81-
proposal,
82-
META,
83-
USDC,
84-
dao,
85-
);
84+
const { question, quoteVault, passBaseMint } =
85+
this.futarchy.getProposalPdas(proposal, META, USDC, dao);
8686

8787
await this.conditionalVault
8888
.splitTokensIx(question, quoteVault, USDC, new BN(11_000 * 1_000_000), 2)
@@ -100,6 +100,18 @@ export default function suite() {
100100
inputAmount: new BN(10_000 * 1_000_000),
101101
minOutputAmount: new BN(0),
102102
})
103+
.preInstructions([
104+
createAssociatedTokenAccountIdempotentInstruction(
105+
this.payer.publicKey,
106+
getAssociatedTokenAddressSync(
107+
passBaseMint,
108+
this.payer.publicKey,
109+
true,
110+
),
111+
this.payer.publicKey,
112+
passBaseMint,
113+
),
114+
])
103115
.rpc();
104116

105117
// Crank TWAP to build up price history
@@ -190,12 +202,8 @@ export default function suite() {
190202
proposal = proposalResult.proposal;
191203
squadsProposal = proposalResult.squadsProposal;
192204

193-
const { question, quoteVault } = this.futarchy.getProposalPdas(
194-
proposal,
195-
META,
196-
USDC,
197-
dao,
198-
);
205+
const { question, quoteVault, passBaseMint } =
206+
this.futarchy.getProposalPdas(proposal, META, USDC, dao);
199207

200208
await this.conditionalVault
201209
.splitTokensIx(question, quoteVault, USDC, new BN(11_000 * 1_000_000), 2)
@@ -213,6 +221,18 @@ export default function suite() {
213221
inputAmount: new BN(10_000 * 1_000_000),
214222
minOutputAmount: new BN(0),
215223
})
224+
.preInstructions([
225+
createAssociatedTokenAccountIdempotentInstruction(
226+
this.payer.publicKey,
227+
getAssociatedTokenAddressSync(
228+
passBaseMint,
229+
this.payer.publicKey,
230+
true,
231+
),
232+
this.payer.publicKey,
233+
passBaseMint,
234+
),
235+
])
216236
.rpc();
217237

218238
// Crank TWAP to build up price history
@@ -309,12 +329,8 @@ export default function suite() {
309329
proposal = proposalResult.proposal;
310330
squadsProposal = proposalResult.squadsProposal;
311331

312-
const { question, quoteVault } = this.futarchy.getProposalPdas(
313-
proposal,
314-
META,
315-
USDC,
316-
dao,
317-
);
332+
const { question, quoteVault, passBaseMint } =
333+
this.futarchy.getProposalPdas(proposal, META, USDC, dao);
318334

319335
await this.conditionalVault
320336
.splitTokensIx(question, quoteVault, USDC, new BN(11_000 * 1_000_000), 2)
@@ -332,6 +348,18 @@ export default function suite() {
332348
inputAmount: new BN(10_000 * 1_000_000),
333349
minOutputAmount: new BN(0),
334350
})
351+
.preInstructions([
352+
createAssociatedTokenAccountIdempotentInstruction(
353+
this.payer.publicKey,
354+
getAssociatedTokenAddressSync(
355+
passBaseMint,
356+
this.payer.publicKey,
357+
true,
358+
),
359+
this.payer.publicKey,
360+
passBaseMint,
361+
),
362+
])
335363
.rpc();
336364

337365
// Crank TWAP to build up price history

tests/futarchy/unit/finalizeProposal.test.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import {
88
Transaction,
99
TransactionMessage,
1010
} from "@solana/web3.js";
11+
import {
12+
createAssociatedTokenAccountIdempotentInstruction,
13+
getAssociatedTokenAddressSync,
14+
} from "@solana/spl-token";
1115
import BN from "bn.js";
1216
import { expectError, setupBasicDao } from "../../utils.js";
1317
import { assert } from "chai";
@@ -246,12 +250,8 @@ export default function suite() {
246250
});
247251

248252
it("fails proposals when Pass TWAP < Fail TWAP", async function () {
249-
const { quoteVault, question } = this.futarchy.getProposalPdas(
250-
proposal,
251-
META,
252-
USDC,
253-
dao,
254-
);
253+
const { quoteVault, question, passBaseMint } =
254+
this.futarchy.getProposalPdas(proposal, META, USDC, dao);
255255

256256
await this.conditionalVault
257257
.splitTokensIx(question, quoteVault, USDC, new BN(11_000 * 1_000_000), 2)
@@ -271,6 +271,16 @@ export default function suite() {
271271
})
272272
.preInstructions([
273273
ComputeBudgetProgram.setComputeUnitPrice({ microLamports: i }),
274+
createAssociatedTokenAccountIdempotentInstruction(
275+
this.payer.publicKey,
276+
getAssociatedTokenAddressSync(
277+
passBaseMint,
278+
this.payer.publicKey,
279+
true,
280+
),
281+
this.payer.publicKey,
282+
passBaseMint,
283+
),
274284
])
275285
.rpc();
276286

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@
975975
"@jridgewell/sourcemap-codec" "^1.4.10"
976976

977977
"@metadaoproject/futarchy@./sdk":
978-
version "0.7.4-alpha.0"
978+
version "0.7.4-alpha.1"
979979
dependencies:
980980
"@coral-xyz/anchor" "^0.29.0"
981981
"@metaplex-foundation/umi" "^0.9.2"

0 commit comments

Comments
 (0)