forked from Team-Kujira/fin-bot-demo
-
Notifications
You must be signed in to change notification settings - Fork 6
/
start.ts
53 lines (41 loc) · 1.39 KB
/
start.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { GasPrice, SigningStargateClient } from "@cosmjs/stargate";
import { registry } from "kujira.js";
import config from "./config";
import { Connector } from "./src/connector";
console.log("RUN");
async function load(): Promise<Connector> {
const mnemonic = process.env.MNEMONIC;
if (!mnemonic) throw new Error("MNEMONIC not set");
const rpc = process.env.RPC_ENDPOINT;
if (!rpc) throw new Error("RPC_ENDPOINT not set");
const gasPrice = process.env.GAS_PRICE || "0.00125ukuji";
const signer = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
prefix: "kujira",
});
const accounts = await signer.getAccounts();
const account = accounts[0];
const signingClient = await SigningStargateClient.connectWithSigner(
rpc,
signer,
{ registry, gasPrice: GasPrice.fromString(gasPrice) }
);
const cwClient = await CosmWasmClient.connect(rpc);
return new Connector(signer, signingClient, account, cwClient);
}
async function run(connector: Connector) {
Promise.all(
config.markets.map((m) => {
Promise.all(
m.strategies.map((s) => {
const strategy = new s(m.address, connector, m.denoms);
return strategy.run();
})
);
})
);
console.log("RUNNING");
// run();
}
load().then(run);