--wip-- [skip ci]

This commit is contained in:
microwavedcola1 2022-03-31 11:28:47 +02:00
parent c9ca8d5563
commit c40aa30e03
1 changed files with 42 additions and 19 deletions

View File

@ -37,6 +37,9 @@ async function main() {
const provider = new Provider(connection, wallet, options);
const client = await MangoClient.connect(provider, true);
//
// check if group exists, iff not, then create
//
let group;
let gpa = await client.program.account.group.all([
{
@ -73,6 +76,9 @@ async function main() {
}
console.log(`Group address: ${group.publicKey.toBase58()}`);
//
// check if token is already registered, iff not, then register
//
// mngo devnet mint
const mint = new web3.PublicKey(
'Bb9bsTQa1bGEtQ5KagGkvSHyuLqDWumFUcRqFusFNJWC',
@ -81,7 +87,24 @@ async function main() {
const mngoOracle = new web3.PublicKey(
'8k7F9Xb36oFJsjpCKpsXvg4cgBRoZtwNTc3EzG5Ttd2o',
);
let bank;
gpa = await client.program.account.bank.all([
{
memcmp: {
bytes: bs58.encode(group.publicKey.toBuffer()),
offset: 8,
},
},
{
memcmp: {
bytes: bs58.encode(mint.toBuffer()),
offset: 40,
},
},
]);
if (gpa.length > 0) {
bank = gpa[0];
} else {
await client.program.methods
.registerToken(0, 0.8, 0.6, 1.2, 1.4, 0.02)
.accounts({
@ -111,9 +134,9 @@ async function main() {
},
},
]);
console.log(gpa);
// const bank = gpa[0];
// console.log(bank.publicKey.toBase58());
bank = gpa[0];
}
console.log(`Bank address: ${bank.publicKey.toBase58()}`);
}
main();