Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: merge to Goerli testnet #360

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 39 additions & 22 deletions examples/js/tick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Account } from "fluidex.js";
import { getTestAccount } from "./accounts";
import { strict as assert } from "assert";
import { depositAssets, getPriceOfCoin, putLimitOrder } from "./exchange_helper";
import Decimal from "decimal.js";

const verbose = true;
const botsIds = [1, 2, 3, 4, 5];
Expand All @@ -26,28 +27,43 @@ async function loadAccounts() {
client.addAccount(user_id, acc);
}
}
async function registerAccounts() {
for (const user_id of botsIds) {
// TODO: clean codes here
let acc = Account.fromMnemonic(getTestAccount(user_id).mnemonic);
await client.registerUser({
user_id,
l1_address: acc.ethAddr,
l2_pubkey: acc.bjjPubKey,
});
}
}
async function initAssets() {
for (const user_id of botsIds) {
await depositAssets({ USDT: "500000.0" }, user_id);
for (const [name, info] of client.markets) {
const base = info.base;
const depositReq = {};
depositReq[base] = "10";
await depositAssets(depositReq, user_id);
// async function registerAccounts() {
// for (const user_id of botsIds) {
// // TODO: clean codes here
// let acc = Account.fromMnemonic(getTestAccount(user_id).mnemonic);
// await client.registerUser({
// user_id,
// l1_address: acc.ethAddr,
// l2_pubkey: acc.bjjPubKey,
// });
// }
// }
// async function initAssets() {
// for (const user_id of botsIds) {
// await depositAssets({ USDT: "500000.0" }, user_id);
// for (const [name, info] of client.markets) {
// const base = info.base;
// const depositReq = {};
// depositReq[base] = "10";
// await depositAssets(depositReq, user_id);
// }
// }
// }

async function waitingAssetsReady() {
outer:
while (true) {
await sleep(1000);
for (const user_id of botsIds) {
const balance = await client.balanceQueryByAsset(user_id, "USDT");
if ((new Decimal(balance.available)).lt(new Decimal("500000.0"))) {
continue outer;
}
}
break;
}
}

function randUser() {
return getRandomElem(botsIds);
}
Expand Down Expand Up @@ -145,9 +161,10 @@ async function main() {
await initClient();
//await cancelAll();
if (reset) {
await client.debugReset();
await registerAccounts();
await initAssets();
// await client.debugReset();
// await registerAccounts();
// await initAssets();
await waitingAssetsReady();
await transferTest();
await withdrawTest();
}
Expand Down