ts: fix withdraw wrapped sol -> sol

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2022-09-01 12:11:31 +02:00
parent 3a1f6f08ee
commit c420d71943
1 changed files with 6 additions and 31 deletions

View File

@ -857,8 +857,8 @@ export class MangoClient {
mangoAccount.owner,
);
// ensure withdraws don't fail with missing ATAs
const preInstructions: TransactionInstruction[] = [
// ensure withdraws don't fail with missing ATAs
await createAssociatedTokenAccountIdempotentInstruction(
mangoAccount.owner,
mangoAccount.owner,
@ -866,34 +866,15 @@ export class MangoClient {
),
];
let wrappedSolAccount: Keypair | undefined;
const postInstructions: TransactionInstruction[] = [];
const additionalSigners: Signer[] = [];
if (mintPk.equals(WRAPPED_SOL_MINT)) {
wrappedSolAccount = new Keypair();
const lamports = nativeAmount + 1e7;
preInstructions.push(
SystemProgram.createAccount({
fromPubkey: mangoAccount.owner,
newAccountPubkey: wrappedSolAccount.publicKey,
lamports,
space: 165,
programId: TOKEN_PROGRAM_ID,
}),
initializeAccount({
account: wrappedSolAccount.publicKey,
mint: WRAPPED_SOL_MINT,
owner: mangoAccount.owner,
}),
);
postInstructions.push(
closeAccount({
source: wrappedSolAccount.publicKey,
source: tokenAccountPk,
destination: mangoAccount.owner,
owner: mangoAccount.owner,
}),
);
additionalSigners.push(wrappedSolAccount);
}
const healthRemainingAccounts: PublicKey[] =
@ -905,7 +886,7 @@ export class MangoClient {
[],
);
const transaction = await this.program.methods
const tx = await this.program.methods
.tokenWithdraw(new BN(nativeAmount), allowBorrow)
.accounts({
group: group.publicKey,
@ -924,17 +905,11 @@ export class MangoClient {
)
.preInstructions(preInstructions)
.postInstructions(postInstructions)
.signers(additionalSigners)
.transaction();
// .rpc({ skipPreflight: true });
return await sendTransaction(
this.program.provider as AnchorProvider,
transaction,
{
postSendTxCallback: this.postSendTxCallback,
},
);
return await sendTransaction(this.program.provider as AnchorProvider, tx, {
postSendTxCallback: this.postSendTxCallback,
});
}
// Serum