ts: add back tokenWithdrawNative() (#434)
This commit is contained in:
parent
51a649ac60
commit
d9a253947c
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue