* ts: use gpa path if rest services has not caught up yet

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* ts: convert wrapped sol to sol when withdrawing

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2022-09-01 11:25:58 +02:00 committed by GitHub
parent 149e0eb0c7
commit 0222ca8954
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 15 deletions

View File

@ -114,7 +114,7 @@ export class Group {
public async reloadBanks(client: MangoClient, ids?: Id) {
let banks: Bank[];
if (ids) {
if (ids && ids.getBanks().length) {
banks = (
await client.program.account.bank.fetchMultiple(ids.getBanks())
).map((account, index) =>
@ -143,7 +143,7 @@ export class Group {
public async reloadMintInfos(client: MangoClient, ids?: Id) {
let mintInfos: MintInfo[];
if (ids) {
if (ids && ids.getMintInfos().length) {
mintInfos = (
await client.program.account.mintInfo.fetchMultiple(ids.getMintInfos())
).map((account, index) =>
@ -212,7 +212,7 @@ export class Group {
public async reloadPerpMarkets(client: MangoClient, ids?: Id) {
let perpMarkets: PerpMarket[];
if (ids) {
if (ids && ids.getPerpMarkets().length) {
perpMarkets = (
await client.program.account.perpMarket.fetchMultiple(
ids.getPerpMarkets(),

View File

@ -857,6 +857,45 @@ export class MangoClient {
mangoAccount.owner,
);
const preInstructions: TransactionInstruction[] = [
// ensure withdraws don't fail with missing ATAs
await createAssociatedTokenAccountIdempotentInstruction(
mangoAccount.owner,
mangoAccount.owner,
bank.mint,
),
];
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,
destination: mangoAccount.owner,
owner: mangoAccount.owner,
}),
);
additionalSigners.push(wrappedSolAccount);
}
const healthRemainingAccounts: PublicKey[] =
this.buildHealthRemainingAccounts(
AccountRetriever.Fixed,
@ -883,14 +922,9 @@ export class MangoClient {
({ pubkey: pk, isWritable: false, isSigner: false } as AccountMeta),
),
)
.preInstructions([
// ensure withdraws don't fail with missing ATAs
await createAssociatedTokenAccountIdempotentInstruction(
mangoAccount.owner,
mangoAccount.owner,
bank.mint,
),
])
.preInstructions(preInstructions)
.postInstructions(postInstructions)
.signers(additionalSigners)
.transaction();
// .rpc({ skipPreflight: true });

View File

@ -177,9 +177,9 @@ async function main() {
for (const mangoAccount of mangoAccounts) {
console.log(`MangoAccount ${mangoAccount.publicKey}`);
if (mangoAccount.name === '2nd Account') {
await debugUser(client, group, mangoAccount);
}
// if (mangoAccount.name === '2nd Account') {
await debugUser(client, group, mangoAccount);
// }
}
}

View File

@ -16,7 +16,7 @@ const MAINNET_MINTS = new Map([
['BTC', '9n4nbM75f5Ui33ZbPYXn59EwSgE8CGsHtAeTH5YFeJ9E'], // Wrapped Bitcoin (Sollet)
['ETH', '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs'], // Ether (Portal)
['soETH', '2FPyTwcZLUg1MDrwsyoP4D6s1tM7hAkHYRjkNb5w6Pxk'], // Wrapped Ethereum (Sollet)
['SOL', 'So11111111111111111111111111111111111111112'],
['SOL', 'So11111111111111111111111111111111111111112'], // Wrapped SOL
['MSOL', 'mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So'],
['MNGO', 'MangoCzJ36AjZyKwVj3VnYU4GTonjfVEnJmvvWaxLac'],
]);