-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a script for merging conditional tokens (#233)
- Loading branch information
1 parent
216c640
commit 7471ea6
Showing
3 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import * as anchor from "@coral-xyz/anchor"; | ||
import { MEMO_PROGRAM_ID } from "@solana/spl-memo"; | ||
import * as token from "@solana/spl-token"; | ||
import { ComputeBudgetProgram, LAMPORTS_PER_SOL } from "@solana/web3.js"; | ||
import { | ||
AmmClient, | ||
AutocratClient, | ||
ConditionalVaultClient, | ||
} from "@metadaoproject/futarchy"; | ||
import { InstructionUtils } from "@metadaoproject/futarchy"; | ||
|
||
const { PublicKey, Keypair, SystemProgram } = anchor.web3; | ||
const { BN, Program } = anchor; | ||
|
||
const provider = anchor.AnchorProvider.env(); | ||
anchor.setProvider(provider); | ||
|
||
let autocratClient: AutocratClient = AutocratClient.createClient({ | ||
provider: anchor.AnchorProvider.env(), | ||
}); | ||
|
||
let ammClient: AmmClient = AmmClient.createClient({ | ||
provider: anchor.AnchorProvider.env(), | ||
}); | ||
|
||
let vaultClient: ConditionalVaultClient = ConditionalVaultClient.createClient({ | ||
provider: anchor.AnchorProvider.env(), | ||
}); | ||
|
||
const payer = provider.wallet["payer"]; | ||
|
||
const PROPOSAL = new PublicKey("MW1dKeDYgewceWuaSmDytdpwNzZDwABf1FuwJix923C"); | ||
|
||
async function main() { | ||
const DAO = new PublicKey("ofvb3CPvEyRfD5az8PAqW6ATpPqVBeiB5zBnpPR5cgm"); | ||
|
||
const storedDao = await autocratClient.getDao(DAO); | ||
console.log(storedDao); | ||
|
||
const { | ||
passAmm, | ||
failAmm, | ||
baseVault, | ||
quoteVault, | ||
passBaseMint, | ||
passQuoteMint, | ||
failBaseMint, | ||
failQuoteMint, | ||
passLp, | ||
failLp, | ||
} = autocratClient.getProposalPdas( | ||
PROPOSAL, | ||
storedDao.tokenMint, | ||
storedDao.usdcMint, | ||
DAO | ||
); | ||
|
||
const basePassBalance = (await token.getOrCreateAssociatedTokenAccount(provider.connection, payer, passBaseMint, payer.publicKey)).amount; | ||
const quotePassBalance = (await token.getOrCreateAssociatedTokenAccount(provider.connection, payer, passQuoteMint, payer.publicKey)).amount; | ||
|
||
await vaultClient.mergeConditionalTokensIx(baseVault, storedDao.tokenMint, new BN(basePassBalance.toString())) | ||
.preInstructions([ | ||
ComputeBudgetProgram.setComputeUnitLimit({ units: 150_000 }), | ||
ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 100 }), | ||
await vaultClient.mergeConditionalTokensIx(quoteVault, storedDao.usdcMint, new BN(quotePassBalance.toString())).instruction(), | ||
]) | ||
.rpc(); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters