Merge branch 'main' into dev
This commit is contained in:
commit
85206c46a3
|
@ -1,5 +1,10 @@
|
||||||
import { AnchorProvider, Wallet } from '@project-serum/anchor';
|
import { AnchorProvider, Wallet } from '@project-serum/anchor';
|
||||||
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
import {
|
||||||
|
AddressLookupTableProgram,
|
||||||
|
Connection,
|
||||||
|
Keypair,
|
||||||
|
PublicKey,
|
||||||
|
} from '@solana/web3.js';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { TokenIndex } from '../accounts/bank';
|
import { TokenIndex } from '../accounts/bank';
|
||||||
import { Group } from '../accounts/group';
|
import { Group } from '../accounts/group';
|
||||||
|
@ -10,6 +15,7 @@ import {
|
||||||
} from '../accounts/serum3';
|
} from '../accounts/serum3';
|
||||||
import { MangoClient } from '../client';
|
import { MangoClient } from '../client';
|
||||||
import { MANGO_V4_ID } from '../constants';
|
import { MANGO_V4_ID } from '../constants';
|
||||||
|
import { buildVersionedTx } from '../utils';
|
||||||
|
|
||||||
const MAINNET_MINTS = new Map([
|
const MAINNET_MINTS = new Map([
|
||||||
['USDC', 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'],
|
['USDC', 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'],
|
||||||
|
@ -556,6 +562,126 @@ async function placeSerum3TradeAndCancelIt(userKeypair: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function createAndPopulateAlt() {
|
||||||
|
const result = await buildAdminClient();
|
||||||
|
const client = result[0];
|
||||||
|
const admin = result[1];
|
||||||
|
|
||||||
|
const group = await client.getGroupForCreator(admin.publicKey, 2);
|
||||||
|
|
||||||
|
const connection = client.program.provider.connection;
|
||||||
|
|
||||||
|
// Create ALT, and set to group at index 0
|
||||||
|
if (group.addressLookupTables[0].equals(PublicKey.default)) {
|
||||||
|
try {
|
||||||
|
console.log(`ALT: Creating`);
|
||||||
|
const createIx = AddressLookupTableProgram.createLookupTable({
|
||||||
|
authority: admin.publicKey,
|
||||||
|
payer: admin.publicKey,
|
||||||
|
recentSlot: await connection.getSlot('finalized'),
|
||||||
|
});
|
||||||
|
const createTx = await buildVersionedTx(
|
||||||
|
client.program.provider as AnchorProvider,
|
||||||
|
[createIx[0]],
|
||||||
|
);
|
||||||
|
let sig = await connection.sendTransaction(createTx);
|
||||||
|
console.log(
|
||||||
|
`...created ALT ${createIx[1]} https://explorer.solana.com/tx/${sig}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(`ALT: set at index 0 for group...`);
|
||||||
|
sig = await client.altSet(group, createIx[1], 0);
|
||||||
|
console.log(`...https://explorer.solana.com/tx/${sig}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extend using mango v4 relevant pub keys
|
||||||
|
try {
|
||||||
|
let bankAddresses = Array.from(group.banksMapByMint.values())
|
||||||
|
.flat()
|
||||||
|
.map((bank) => [bank.publicKey, bank.oracle, bank.vault])
|
||||||
|
.flat()
|
||||||
|
.concat(
|
||||||
|
Array.from(group.banksMapByMint.values())
|
||||||
|
.flat()
|
||||||
|
.map((mintInfo) => mintInfo.publicKey),
|
||||||
|
);
|
||||||
|
|
||||||
|
let serum3MarketAddresses = Array.from(
|
||||||
|
group.serum3MarketsMapByExternal.values(),
|
||||||
|
)
|
||||||
|
.flat()
|
||||||
|
.map((serum3Market) => serum3Market.publicKey);
|
||||||
|
|
||||||
|
let serum3ExternalMarketAddresses = Array.from(
|
||||||
|
group.serum3ExternalMarketsMap.values(),
|
||||||
|
)
|
||||||
|
.flat()
|
||||||
|
.map((serum3ExternalMarket) => [
|
||||||
|
serum3ExternalMarket.publicKey,
|
||||||
|
serum3ExternalMarket.bidsAddress,
|
||||||
|
serum3ExternalMarket.asksAddress,
|
||||||
|
])
|
||||||
|
.flat();
|
||||||
|
|
||||||
|
let perpMarketAddresses = Array.from(
|
||||||
|
group.perpMarketsMapByMarketIndex.values(),
|
||||||
|
)
|
||||||
|
.flat()
|
||||||
|
.map((perpMarket) => [
|
||||||
|
perpMarket.publicKey,
|
||||||
|
perpMarket.oracle,
|
||||||
|
perpMarket.bids,
|
||||||
|
perpMarket.asks,
|
||||||
|
perpMarket.eventQueue,
|
||||||
|
])
|
||||||
|
.flat();
|
||||||
|
|
||||||
|
async function extendTable(addresses: PublicKey[]) {
|
||||||
|
await group.reloadAll(client);
|
||||||
|
const alt =
|
||||||
|
await client.program.provider.connection.getAddressLookupTable(
|
||||||
|
group.addressLookupTables[0],
|
||||||
|
);
|
||||||
|
|
||||||
|
addresses = addresses.filter(
|
||||||
|
(newAddress) =>
|
||||||
|
alt.value?.state.addresses &&
|
||||||
|
alt.value?.state.addresses.findIndex((addressInALt) =>
|
||||||
|
addressInALt.equals(newAddress),
|
||||||
|
) === -1,
|
||||||
|
);
|
||||||
|
if (addresses.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const extendIx = AddressLookupTableProgram.extendLookupTable({
|
||||||
|
lookupTable: group.addressLookupTables[0],
|
||||||
|
payer: admin.publicKey,
|
||||||
|
authority: admin.publicKey,
|
||||||
|
addresses,
|
||||||
|
});
|
||||||
|
const extendTx = await buildVersionedTx(
|
||||||
|
client.program.provider as AnchorProvider,
|
||||||
|
[extendIx],
|
||||||
|
);
|
||||||
|
let sig = await client.program.provider.connection.sendTransaction(
|
||||||
|
extendTx,
|
||||||
|
);
|
||||||
|
console.log(`https://explorer.solana.com/tx/${sig}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`ALT: extending using mango v4 relevant public keys`);
|
||||||
|
await extendTable(bankAddresses);
|
||||||
|
await extendTable(serum3MarketAddresses);
|
||||||
|
await extendTable(serum3ExternalMarketAddresses);
|
||||||
|
await extendTable(perpMarketAddresses);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
// await createGroup();
|
// await createGroup();
|
||||||
|
@ -582,6 +708,10 @@ async function main() {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// await createAndPopulateAlt();
|
||||||
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue