--wip-- [skip ci]
This commit is contained in:
parent
f0d32f07da
commit
6a50b7ccd7
|
@ -0,0 +1,94 @@
|
|||
import { AnchorProvider, Wallet } from '@coral-xyz/anchor';
|
||||
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
||||
import fs from 'fs';
|
||||
import { MangoClient } from '../../src/client';
|
||||
import { DefaultTokenRegisterParams } from '../../src/clientIxParamBuilder';
|
||||
import { MANGO_V4_ID } from '../../src/constants';
|
||||
import { MangoSignatureStatus } from '../../src/utils/rpc';
|
||||
|
||||
const TESTNET_MINTS = new Map([
|
||||
['USDC', 'AkdEhBMvaDD1UbGMD3Hxnr3h5PEL2R8PaCDAssCN28WV'],
|
||||
]);
|
||||
|
||||
// TODO: should these constants be baked right into client.ts or even program?
|
||||
const NET_BORROWS_LIMIT_NATIVE = 1 * Math.pow(10, 7) * Math.pow(10, 6);
|
||||
|
||||
const GROUP_NUM = Number(process.env.GROUP_NUM || 0);
|
||||
|
||||
async function main(): Promise<void> {
|
||||
let sig: MangoSignatureStatus;
|
||||
|
||||
const options = AnchorProvider.defaultOptions();
|
||||
const connection = new Connection(
|
||||
'https://testnet.dev2.eclipsenetwork.xyz',
|
||||
options,
|
||||
);
|
||||
|
||||
const admin = Keypair.fromSecretKey(
|
||||
Buffer.from(
|
||||
JSON.parse(fs.readFileSync(process.env.ADMIN_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,
|
||||
'testnet',
|
||||
MANGO_V4_ID['testnet'],
|
||||
{
|
||||
idsSource: 'get-program-accounts',
|
||||
},
|
||||
);
|
||||
|
||||
// group
|
||||
console.log(`Creating Group...`);
|
||||
const insuranceMint = new PublicKey(TESTNET_MINTS.get('USDC')!);
|
||||
try {
|
||||
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 usdc oracle + register token 0
|
||||
console.log(`Registering USDC...`);
|
||||
const usdcDevnetMint = new PublicKey(TESTNET_MINTS.get('USDC')!);
|
||||
|
||||
sig = await client.stubOracleCreate(group, usdcDevnetMint, 1.0);
|
||||
const usdcDevnetOracle = (
|
||||
await client.getStubOracle(group, usdcDevnetMint)
|
||||
)[0];
|
||||
console.log(
|
||||
`...registered stub oracle ${usdcDevnetOracle}, https://explorer.dev.eclipsenetwork.xyz/tx/${sig.signature}?cluster=testnet`,
|
||||
);
|
||||
|
||||
sig = await client.tokenRegister(
|
||||
group,
|
||||
usdcDevnetMint,
|
||||
usdcDevnetOracle.publicKey,
|
||||
PublicKey.default,
|
||||
0, // tokenIndex
|
||||
'USDC',
|
||||
{
|
||||
...DefaultTokenRegisterParams,
|
||||
initAssetWeight: 1,
|
||||
maintAssetWeight: 1,
|
||||
initLiabWeight: 1,
|
||||
maintLiabWeight: 1,
|
||||
liquidationFee: 0,
|
||||
netBorrowLimitPerWindowQuote: NET_BORROWS_LIMIT_NATIVE,
|
||||
},
|
||||
);
|
||||
await group.reloadAll(client);
|
||||
const bank = group.getFirstBankByMint(usdcDevnetMint);
|
||||
console.log(
|
||||
`...registered token bank ${bank.publicKey}, https://explorer.dev.eclipsenetwork.xyz/tx/${sig.signature}?cluster=testnet`,
|
||||
);
|
||||
await group.reloadAll(client);
|
||||
|
||||
process.exit();
|
||||
}
|
||||
|
||||
main();
|
|
@ -0,0 +1,78 @@
|
|||
import { AnchorProvider, Wallet } from '@coral-xyz/anchor';
|
||||
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
||||
import fs from 'fs';
|
||||
import { MangoAccount } from '../../src/accounts/mangoAccount';
|
||||
import { MangoClient } from '../../src/client';
|
||||
import { MANGO_V4_ID } from '../../src/constants';
|
||||
|
||||
const TESTNET_MINTS = new Map([
|
||||
['USDC', 'AkdEhBMvaDD1UbGMD3Hxnr3h5PEL2R8PaCDAssCN28WV'],
|
||||
]);
|
||||
|
||||
const GROUP_NUM = Number(process.env.GROUP_NUM || 0);
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const options = AnchorProvider.defaultOptions();
|
||||
const connection = new Connection(
|
||||
'https://testnet.dev2.eclipsenetwork.xyz',
|
||||
options,
|
||||
);
|
||||
|
||||
const user = Keypair.fromSecretKey(
|
||||
Buffer.from(
|
||||
JSON.parse(fs.readFileSync(process.env.USER_KEYPAIR!, 'utf-8')),
|
||||
),
|
||||
);
|
||||
const userWallet = new Wallet(user);
|
||||
const userProvider = new AnchorProvider(connection, userWallet, options);
|
||||
const client = await MangoClient.connect(
|
||||
userProvider,
|
||||
'testnet',
|
||||
MANGO_V4_ID['testnet'],
|
||||
{
|
||||
idsSource: 'get-program-accounts',
|
||||
},
|
||||
);
|
||||
console.log(`User ${userWallet.publicKey.toBase58()}`);
|
||||
|
||||
// fetch group
|
||||
const admin = Keypair.fromSecretKey(
|
||||
Buffer.from(
|
||||
JSON.parse(fs.readFileSync(process.env.ADMIN_KEYPAIR!, 'utf-8')),
|
||||
),
|
||||
);
|
||||
const group = await client.getGroupForCreator(admin.publicKey, GROUP_NUM);
|
||||
console.log(`Group ${group.publicKey}`);
|
||||
|
||||
// create + fetch account
|
||||
console.log(`Creating mangoaccount...`);
|
||||
let mangoAccount = (await client.getMangoAccountForOwner(
|
||||
group,
|
||||
user.publicKey,
|
||||
0,
|
||||
)) as MangoAccount;
|
||||
if (!mangoAccount) {
|
||||
await client.createMangoAccount(group, 0);
|
||||
mangoAccount = (await client.getMangoAccountForOwner(
|
||||
group,
|
||||
user.publicKey,
|
||||
0,
|
||||
)) as MangoAccount;
|
||||
}
|
||||
console.log(`...created/found mangoAccount ${mangoAccount.publicKey}`);
|
||||
|
||||
// deposit USDC
|
||||
const sig = await client.tokenDeposit(
|
||||
group,
|
||||
mangoAccount,
|
||||
new PublicKey(TESTNET_MINTS.get('USDC')!),
|
||||
50,
|
||||
);
|
||||
console.log(
|
||||
`deposited token, https://explorer.dev.eclipsenetwork.xyz/tx/${sig.signature}?cluster=testnet`,
|
||||
);
|
||||
|
||||
process.exit();
|
||||
}
|
||||
|
||||
main();
|
Loading…
Reference in New Issue