2022-08-08 02:16:57 -07:00
|
|
|
import { AnchorProvider, Wallet } from '@project-serum/anchor';
|
|
|
|
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
|
|
import fs from 'fs';
|
|
|
|
import { MangoClient } from '../client';
|
|
|
|
import { MANGO_V4_ID } from '../constants';
|
|
|
|
|
|
|
|
//
|
|
|
|
// Script which depoys a new mango group, and registers 3 tokens
|
|
|
|
// with stub oracles
|
|
|
|
//
|
|
|
|
|
|
|
|
// default to group 1, to not conflict with the normal group
|
2022-09-01 02:47:37 -07:00
|
|
|
const GROUP_NUM = Number(process.env.GROUP_NUM || 200);
|
2022-08-08 02:16:57 -07:00
|
|
|
|
|
|
|
const MAINNET_MINTS = new Map([
|
|
|
|
['USDC', 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'],
|
|
|
|
['BTC', '9n4nbM75f5Ui33ZbPYXn59EwSgE8CGsHtAeTH5YFeJ9E'],
|
|
|
|
['SOL', 'So11111111111111111111111111111111111111112'],
|
2022-09-15 00:57:48 -07:00
|
|
|
['MNGO', 'MangoCzJ36AjZyKwVj3VnYU4GTonjfVEnJmvvWaxLac'],
|
2022-08-08 02:16:57 -07:00
|
|
|
]);
|
|
|
|
|
|
|
|
const STUB_PRICES = new Map([
|
|
|
|
['USDC', 1.0],
|
|
|
|
['BTC', 20000.0], // btc and usdc both have 6 decimals
|
|
|
|
['SOL', 0.04], // sol has 9 decimals, equivalent to $40 per SOL
|
2022-09-15 00:57:48 -07:00
|
|
|
['MNGO', 0.04], // same price/decimals as SOL for convenience
|
2022-08-08 02:16:57 -07:00
|
|
|
]);
|
|
|
|
|
2022-09-01 02:47:37 -07:00
|
|
|
// External markets are matched with those in https://github.com/blockworks-foundation/mango-client-v3/blob/main/src/ids.json
|
|
|
|
// and verified to have best liquidity for pair on https://openserum.io/
|
|
|
|
const MAINNET_SERUM3_MARKETS = new Map([
|
|
|
|
['BTC/USDC', 'A8YFbxQYFVqKZaoYJLLUVcQiWP7G2MeEgW5wsAQgMvFw'],
|
|
|
|
['SOL/USDC', '9wFFyRfZBsuAha4YcuxcXLKwMxJR43S7fPfQLusDBzvT'],
|
|
|
|
]);
|
|
|
|
|
2022-08-08 02:16:57 -07:00
|
|
|
async function main() {
|
|
|
|
const options = AnchorProvider.defaultOptions();
|
2022-09-01 02:47:37 -07:00
|
|
|
const connection = new Connection(process.env.CLUSTER_URL!, options);
|
2022-08-08 02:16:57 -07:00
|
|
|
|
|
|
|
const admin = Keypair.fromSecretKey(
|
|
|
|
Buffer.from(
|
|
|
|
JSON.parse(
|
|
|
|
fs.readFileSync(process.env.MANGO_MAINNET_PAYER_KEYPAIR!, 'utf-8'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
const adminWallet = new Wallet(admin);
|
|
|
|
console.log(`Admin ${adminWallet.publicKey.toBase58()}`);
|
|
|
|
const adminProvider = new AnchorProvider(connection, adminWallet, options);
|
|
|
|
const client = await MangoClient.connect(
|
|
|
|
adminProvider,
|
|
|
|
'mainnet-beta',
|
|
|
|
MANGO_V4_ID['mainnet-beta'],
|
2022-09-01 02:47:37 -07:00
|
|
|
{},
|
|
|
|
'get-program-accounts',
|
2022-08-08 02:16:57 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
// group
|
|
|
|
console.log(`Creating Group...`);
|
|
|
|
try {
|
|
|
|
const insuranceMint = new PublicKey(MAINNET_MINTS.get('USDC')!);
|
|
|
|
await client.groupCreate(GROUP_NUM, true, 0, insuranceMint);
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
const group = await client.getGroupForCreator(admin.publicKey, GROUP_NUM);
|
|
|
|
console.log(`...registered group ${group.publicKey}`);
|
|
|
|
|
|
|
|
// stub oracles
|
|
|
|
let oracles = new Map();
|
|
|
|
for (let [name, mint] of MAINNET_MINTS) {
|
|
|
|
console.log(`Creating stub oracle for ${name}...`);
|
|
|
|
const mintPk = new PublicKey(mint);
|
|
|
|
try {
|
2022-09-01 02:47:37 -07:00
|
|
|
const price = STUB_PRICES.get(name)!;
|
2022-08-09 01:57:03 -07:00
|
|
|
await client.stubOracleCreate(group, mintPk, price);
|
2022-08-08 02:16:57 -07:00
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
2022-08-08 07:31:38 -07:00
|
|
|
const oracle = (await client.getStubOracle(group, mintPk))[0];
|
2022-08-08 02:16:57 -07:00
|
|
|
console.log(`...created stub oracle ${oracle.publicKey}`);
|
|
|
|
oracles.set(name, oracle.publicKey);
|
|
|
|
}
|
|
|
|
|
2022-09-01 02:47:37 -07:00
|
|
|
// register token 0
|
|
|
|
console.log(`Registering USDC...`);
|
|
|
|
const usdcMainnetMint = new PublicKey(MAINNET_MINTS.get('USDC')!);
|
|
|
|
const usdcMainnetOracle = oracles.get('USDC');
|
2022-08-08 02:16:57 -07:00
|
|
|
try {
|
|
|
|
await client.tokenRegister(
|
|
|
|
group,
|
2022-09-01 02:47:37 -07:00
|
|
|
usdcMainnetMint,
|
|
|
|
usdcMainnetOracle,
|
2022-08-08 02:16:57 -07:00
|
|
|
0.1,
|
2022-09-01 02:47:37 -07:00
|
|
|
0,
|
|
|
|
'USDC',
|
2022-08-08 02:16:57 -07:00
|
|
|
0.01,
|
|
|
|
0.4,
|
|
|
|
0.07,
|
2022-09-01 02:47:37 -07:00
|
|
|
0.8,
|
|
|
|
0.9,
|
2022-08-08 02:16:57 -07:00
|
|
|
1.5,
|
2022-08-08 08:48:55 -07:00
|
|
|
0.0,
|
2022-08-09 01:57:03 -07:00
|
|
|
0.0001,
|
2022-09-01 02:47:37 -07:00
|
|
|
1,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
0,
|
2022-08-08 02:16:57 -07:00
|
|
|
);
|
|
|
|
await group.reloadAll(client);
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
|
2022-09-01 02:47:37 -07:00
|
|
|
// register token 1
|
|
|
|
console.log(`Registering BTC...`);
|
|
|
|
const btcMainnetMint = new PublicKey(MAINNET_MINTS.get('BTC')!);
|
|
|
|
const btcMainnetOracle = oracles.get('BTC');
|
2022-08-08 02:16:57 -07:00
|
|
|
try {
|
|
|
|
await client.tokenRegister(
|
|
|
|
group,
|
2022-09-01 02:47:37 -07:00
|
|
|
btcMainnetMint,
|
|
|
|
btcMainnetOracle,
|
2022-08-08 02:16:57 -07:00
|
|
|
0.1,
|
2022-09-01 02:47:37 -07:00
|
|
|
1,
|
|
|
|
'BTC',
|
2022-08-08 02:16:57 -07:00
|
|
|
0.01,
|
|
|
|
0.4,
|
|
|
|
0.07,
|
2022-09-01 02:47:37 -07:00
|
|
|
0.7,
|
|
|
|
0.88,
|
2022-08-08 02:16:57 -07:00
|
|
|
1.5,
|
2022-08-08 08:48:55 -07:00
|
|
|
0.0,
|
2022-08-09 01:57:03 -07:00
|
|
|
0.0001,
|
2022-09-01 02:47:37 -07:00
|
|
|
0.9,
|
|
|
|
0.8,
|
|
|
|
1.1,
|
|
|
|
1.2,
|
|
|
|
0.05,
|
2022-08-08 02:16:57 -07:00
|
|
|
);
|
|
|
|
await group.reloadAll(client);
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
// register token 2
|
|
|
|
console.log(`Registering SOL...`);
|
|
|
|
const solMainnetMint = new PublicKey(MAINNET_MINTS.get('SOL')!);
|
|
|
|
const solMainnetOracle = oracles.get('SOL');
|
|
|
|
try {
|
|
|
|
await client.tokenRegister(
|
|
|
|
group,
|
|
|
|
solMainnetMint,
|
|
|
|
solMainnetOracle,
|
|
|
|
0.1,
|
|
|
|
2, // tokenIndex
|
|
|
|
'SOL',
|
|
|
|
0.01,
|
|
|
|
0.4,
|
|
|
|
0.07,
|
|
|
|
0.8,
|
|
|
|
0.9,
|
|
|
|
1.5,
|
2022-08-08 08:48:55 -07:00
|
|
|
0.0,
|
2022-08-09 01:57:03 -07:00
|
|
|
0.0001,
|
2022-08-08 02:16:57 -07:00
|
|
|
0.9,
|
|
|
|
0.8,
|
|
|
|
1.1,
|
|
|
|
1.2,
|
|
|
|
0.05,
|
|
|
|
);
|
|
|
|
await group.reloadAll(client);
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
// log tokens/banks
|
2022-09-01 02:47:37 -07:00
|
|
|
for (const bank of await group.banksMapByMint.values()) {
|
2022-08-08 02:16:57 -07:00
|
|
|
console.log(`${bank.toString()}`);
|
|
|
|
}
|
|
|
|
|
2022-09-01 04:43:17 -07:00
|
|
|
console.log('Registering SOL/USDC serum market...');
|
2022-09-15 00:57:48 -07:00
|
|
|
try {
|
|
|
|
await client.serum3RegisterMarket(
|
|
|
|
group,
|
|
|
|
new PublicKey(MAINNET_SERUM3_MARKETS.get('SOL/USDC')!),
|
|
|
|
group.getFirstBankByMint(new PublicKey(MAINNET_MINTS.get('SOL')!)),
|
|
|
|
group.getFirstBankByMint(new PublicKey(MAINNET_MINTS.get('USDC')!)),
|
|
|
|
1,
|
|
|
|
'SOL/USDC',
|
|
|
|
);
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Registering MNGO-PERP market...');
|
|
|
|
const mngoMainnetOracle = oracles.get('MNGO');
|
|
|
|
try {
|
|
|
|
await client.perpCreateMarket(
|
|
|
|
group,
|
|
|
|
mngoMainnetOracle,
|
|
|
|
0,
|
|
|
|
'MNGO-PERP',
|
|
|
|
0.1,
|
|
|
|
9,
|
|
|
|
0,
|
|
|
|
10,
|
|
|
|
100000, // base lots
|
|
|
|
0.9,
|
|
|
|
0.8,
|
|
|
|
1.1,
|
|
|
|
1.2,
|
|
|
|
0.05,
|
|
|
|
-0.001,
|
|
|
|
0.002,
|
|
|
|
-0.1,
|
|
|
|
0.1,
|
|
|
|
10,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
2022-09-01 04:43:17 -07:00
|
|
|
|
2022-08-08 02:16:57 -07:00
|
|
|
process.exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|