From d59d05eae5677dd48bab6fe6c1a0d15928e043f9 Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Sat, 13 Aug 2022 20:10:49 +0200 Subject: [PATCH] default group is group num 2 on mainnet Signed-off-by: microwavedcola1 --- ts/client/src/scripts/mb-example1-admin.ts | 205 ++++++++++++------ .../src/scripts/mb-example1-close-account.ts | 2 +- ts/client/src/scripts/mb-example1-user.ts | 2 +- 3 files changed, 146 insertions(+), 63 deletions(-) diff --git a/ts/client/src/scripts/mb-example1-admin.ts b/ts/client/src/scripts/mb-example1-admin.ts index c22a6c69c..490d1e66c 100644 --- a/ts/client/src/scripts/mb-example1-admin.ts +++ b/ts/client/src/scripts/mb-example1-admin.ts @@ -4,15 +4,12 @@ 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 -// - const MAINNET_MINTS = new Map([ ['USDC', 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'], ['USDT', 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'], - ['BTC', '9n4nbM75f5Ui33ZbPYXn59EwSgE8CGsHtAeTH5YFeJ9E'], - ['ETH', '2FPyTwcZLUg1MDrwsyoP4D6s1tM7hAkHYRjkNb5w6Pxk'], + ['BTC', '9n4nbM75f5Ui33ZbPYXn59EwSgE8CGsHtAeTH5YFeJ9E'], // Wrapped Bitcoin (Sollet) + ['ETH', '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs'], // Ether (Portal) + ['soETH', '2FPyTwcZLUg1MDrwsyoP4D6s1tM7hAkHYRjkNb5w6Pxk'], // Wrapped Ethereum (Sollet) ['SOL', 'So11111111111111111111111111111111111111112'], ['MSOL', 'mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So'], ['MNGO', 'MangoCzJ36AjZyKwVj3VnYU4GTonjfVEnJmvvWaxLac'], @@ -21,20 +18,22 @@ const MAINNET_ORACLES = new Map([ ['USDT', '3vxLXJqLqF3JG5TCbYycbKWRBbCJQLxQmBGCkyqEEefL'], ['BTC', 'GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU'], ['ETH', 'JBu1AL4obBcCMqKBBxhpWCNUt136ijcuMZLFvTP7iWdB'], + ['soETH', 'JBu1AL4obBcCMqKBBxhpWCNUt136ijcuMZLFvTP7iWdB'], ['SOL', 'H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG'], ['MSOL', 'E4v1BBgoso9s64TQvmyownAVJbhbEPGyzA3qn4n46qj9'], ['MNGO', '79wm3jjcPr6RaNQ4DGvP5KxG1mNd3gEBsg6FsNVFezK4'], ]); -async function main() { - const options = AnchorProvider.defaultOptions(); - const connection = new Connection(process.env.MB_CLUSTER_URL, options); - +async function createGroup() { const admin = Keypair.fromSecretKey( Buffer.from( JSON.parse(fs.readFileSync(process.env.MB_PAYER_KEYPAIR!, 'utf-8')), ), ); + + const options = AnchorProvider.defaultOptions(); + const connection = new Connection(process.env.MB_CLUSTER_URL, options); + const adminWallet = new Wallet(admin); console.log(`Admin ${adminWallet.publicKey.toBase58()}`); const adminProvider = new AnchorProvider(connection, adminWallet, options); @@ -44,14 +43,34 @@ async function main() { MANGO_V4_ID['mainnet-beta'], ); - // group console.log(`Creating Group...`); const insuranceMint = new PublicKey(MAINNET_MINTS.get('USDC')!); - await client.groupCreate(0, true, 0, insuranceMint); - const group = await client.getGroupForCreator(admin.publicKey); + await client.groupCreate(2, true, 0, insuranceMint); + const group = await client.getGroupForCreator(admin.publicKey, 2); console.log(`...registered group ${group.publicKey}`); +} + +async function registerTokens() { + const admin = Keypair.fromSecretKey( + Buffer.from( + JSON.parse(fs.readFileSync(process.env.MB_PAYER_KEYPAIR!, 'utf-8')), + ), + ); + + const options = AnchorProvider.defaultOptions(); + const connection = new Connection(process.env.MB_CLUSTER_URL, options); + + 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'], + ); + + const group = await client.getGroupForCreator(admin.publicKey, 2); - // stub oracle + register token 0 console.log(`Creating USDC stub oracle...`); const usdcMainnetMint = new PublicKey(MAINNET_MINTS.get('USDC')!); await client.stubOracleCreate(group, usdcMainnetMint, 1.0); @@ -69,11 +88,11 @@ async function main() { 0, 'USDC', 0.004, - 0.4, - 0.07, - 0.8, - 0.9, - 1.5, + 0.7, + 0.1, + 0.85, + 0.2, + 2.0, 0.005, 0.0005, 1, @@ -94,18 +113,18 @@ async function main() { 1, 'USDT', 0.004, - 0.4, - 0.07, - 0.8, - 0.9, - 1.5, + 0.7, + 0.1, + 0.85, + 0.2, + 2.0, 0.005, 0.0005, 0.95, 0.9, 1.05, 1.1, - 0.02, + 0.025, ); console.log(`Registering BTC...`); @@ -119,11 +138,11 @@ async function main() { 2, 'BTC', 0.004, - 0.4, - 0.07, - 0.8, - 0.9, - 1.5, + 0.7, + 0.1, + 0.85, + 0.2, + 2.0, 0.005, 0.0005, 0.9, @@ -144,11 +163,36 @@ async function main() { 3, 'ETH', 0.004, - 0.4, - 0.07, - 0.8, + 0.7, + 0.1, + 0.85, + 0.2, + 2.0, + 0.005, + 0.0005, 0.9, - 1.5, + 0.8, + 1.1, + 1.2, + 0.05, + ); + + console.log(`Registering soETH...`); + const soEthMainnetMint = new PublicKey(MAINNET_MINTS.get('soETH')!); + const soEthMainnetOracle = new PublicKey(MAINNET_ORACLES.get('soETH')!); + await client.tokenRegister( + group, + soEthMainnetMint, + soEthMainnetOracle, + 0.1, + 4, + 'soETH', + 0.004, + 0.7, + 0.1, + 0.85, + 0.2, + 2.0, 0.005, 0.0005, 0.9, @@ -166,14 +210,14 @@ async function main() { solMainnetMint, solMainnetOracle, 0.1, - 4, + 5, 'SOL', 0.004, - 0.4, - 0.07, - 0.8, - 0.9, - 1.5, + 0.7, + 0.1, + 0.85, + 0.2, + 2.0, 0.005, 0.0005, 0.9, @@ -191,14 +235,14 @@ async function main() { msolMainnetMint, msolMainnetOracle, 0.1, - 5, + 6, 'MSOL', 0.004, - 0.4, - 0.07, - 0.8, - 0.9, - 1.5, + 0.7, + 0.1, + 0.85, + 0.2, + 2.0, 0.005, 0.0005, 0.9, @@ -208,25 +252,64 @@ async function main() { 0.05, ); - console.log(`Registering MNGO...`); - await client.groupEdit(group, group.admin, group.admin, undefined, undefined); - const mngoMainnetMint = new PublicKey(MAINNET_MINTS.get('MNGO')!); - const mngoMainnetOracle = new PublicKey(MAINNET_ORACLES.get('MNGO')!); - await client.tokenRegisterTrustless( - group, - mngoMainnetMint, - mngoMainnetOracle, - 6, - 'MNGO', - ); - // log tokens/banks await group.reloadAll(client); for (const bank of await group.banksMap.values()) { console.log(`${bank.toString()}`); } - - process.exit(); } -main(); +async function createUser() { + const options = AnchorProvider.defaultOptions(); + const connection = new Connection(process.env.CLUSTER_URL!, options); + + const user = Keypair.fromSecretKey( + Buffer.from( + JSON.parse(fs.readFileSync(process.env.MB_PAYER_KEYPAIR!, 'utf-8')), + ), + ); + const userWallet = new Wallet(user); + const userProvider = new AnchorProvider(connection, userWallet, options); + + const client = await MangoClient.connect( + userProvider, + 'mainnet-beta', + MANGO_V4_ID['mainnet-beta'], + ); + + const admin = Keypair.fromSecretKey( + Buffer.from( + JSON.parse(fs.readFileSync(process.env.MB_PAYER_KEYPAIR!, 'utf-8')), + ), + ); + const group = await client.getGroupForCreator(admin.publicKey, 2); + console.log(`${group.toString()}`); + + console.log(`Creating MangoAccount...`); + const mangoAccount = await client.getOrCreateMangoAccount( + group, + user.publicKey, + ); + console.log(`...created MangoAccount ${mangoAccount.publicKey.toBase58()}`); + console.log(mangoAccount.toString(group)); + + await client.tokenDeposit(group, mangoAccount, 'USDC', 10); + await mangoAccount.reload(client, group); + console.log(`...deposited 10 USDC`); + + await client.tokenDeposit(group, mangoAccount, 'SOL', 1); + await mangoAccount.reload(client, group); + console.log(`...deposited 1 SOL`); +} + +async function main() { + await createGroup(); + await registerTokens(); + // createUser(); +} + +try { + main(); +} catch (error) { + console.log(error); +} diff --git a/ts/client/src/scripts/mb-example1-close-account.ts b/ts/client/src/scripts/mb-example1-close-account.ts index f1f165916..98f557d4f 100644 --- a/ts/client/src/scripts/mb-example1-close-account.ts +++ b/ts/client/src/scripts/mb-example1-close-account.ts @@ -36,7 +36,7 @@ async function main() { console.log(`Admin ${admin.publicKey.toBase58()}`); // fetch group - const group = await client.getGroupForCreator(admin.publicKey, 0); + const group = await client.getGroupForCreator(admin.publicKey, 2); console.log(`Found group ${group.publicKey.toBase58()}`); // account diff --git a/ts/client/src/scripts/mb-example1-user.ts b/ts/client/src/scripts/mb-example1-user.ts index 994c279b3..9aa248a20 100644 --- a/ts/client/src/scripts/mb-example1-user.ts +++ b/ts/client/src/scripts/mb-example1-user.ts @@ -29,7 +29,7 @@ async function main() { ); console.log(`Admin ${admin.publicKey.toBase58()}`); - const group = await client.getGroupForCreator(admin.publicKey, 0); + const group = await client.getGroupForCreator(admin.publicKey, 2); console.log(`${group.toString()}`); // create + fetch account