ts: add back tokenWithdrawNative() (#434)

This commit is contained in:
Christian Kamm 2023-02-02 15:08:57 +01:00 committed by GitHub
parent 51a649ac60
commit d9a253947c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 20 deletions

View File

@ -1180,6 +1180,28 @@ export class MangoClient {
return [...preInstructions, ix, ...postInstructions];
}
public async tokenWithdrawNative(
group: Group,
mangoAccount: MangoAccount,
mintPk: PublicKey,
nativeAmount: BN,
allowBorrow: boolean,
healthAccountsToExclude: PublicKey[] = [],
): Promise<TransactionSignature> {
const ixs = await this.tokenWithdrawNativeIx(
group,
mangoAccount,
mintPk,
nativeAmount,
allowBorrow,
healthAccountsToExclude,
);
return await this.sendAndConfirmTransaction(
ixs,
group.addressLookupTablesList,
);
}
// Serum
public async serum3RegisterMarket(

View File

@ -114,7 +114,7 @@ async function main() {
} native amount ${nativeFlooredNumber} `,
);
const withdrawIx = await client.tokenWithdrawNativeIx(
await client.tokenWithdrawNative(
group,
mangoAccount,
group.getFirstBankByTokenIndex(token.tokenIndex).mint,
@ -123,10 +123,6 @@ async function main() {
) /* see comment in token_withdraw in program */,
false,
);
await this.sendAndConfirmTransaction(
[...withdrawIx],
group.addressLookupTablesList,
);
}
// reload and print current positions

View File

@ -99,7 +99,7 @@ async function closeUserAccount(userKeypairFile: string) {
continue;
}
const withdrawIx = await client.tokenWithdrawNativeIx(
await client.tokenWithdrawNative(
group,
mangoAccount,
group.getFirstBankByTokenIndex(token.tokenIndex)!.mint,
@ -110,10 +110,6 @@ async function closeUserAccount(userKeypairFile: string) {
),
false,
);
await this.sendAndConfirmTransaction(
[...withdrawIx],
group.addressLookupTablesList,
);
}
} catch (error) {
console.log(error);

View File

@ -153,17 +153,13 @@ async function main() {
try {
await setBankPrice(bank, PRICES[liabName] / 2);
const withdrawIx = await client.tokenWithdrawNativeIx(
await client.tokenWithdrawNative(
group,
mangoAccount,
liabMint,
new BN(liabAmount),
true,
);
await this.sendAndConfirmTransaction(
[...withdrawIx],
group.addressLookupTablesList,
);
} finally {
// restore the oracle
await setBankPrice(bank, PRICES[liabName]);
@ -378,17 +374,13 @@ async function main() {
await setBankPrice(collateralBank, PRICES['SOL'] * 10);
// Spot-borrow more than the collateral is worth
const withdrawIx = await client.tokenWithdrawNativeIx(
await client.tokenWithdrawNative(
group,
mangoAccount,
liabMint,
new BN(-5000),
true,
);
await this.sendAndConfirmTransaction(
[...withdrawIx],
group.addressLookupTablesList,
);
await mangoAccount.reload(client);
// Execute two trades that leave the account with +$0.011 positive pnl