-
Notifications
You must be signed in to change notification settings - Fork 8
/
calculator.ts
90 lines (73 loc) · 2.55 KB
/
calculator.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { CalculatorModel, CUModel, GridClient, SUModel } from "../src";
import { getClient } from "./client_loader";
import { log } from "./utils";
async function calculateCU(client: GridClient, CUModel: CUModel) {
const res = await client.calculator.calCU(CUModel);
log("================= Calculating CU =================");
log(res);
log("================= Calculating CU =================");
}
async function calculateSU(client: GridClient, SUModel: SUModel) {
const res = await client.calculator.calSU(SUModel);
log("================= Calculating SU =================");
log(res);
log("================= Calculating SU =================");
}
async function getTFTPrice(client: GridClient) {
const res = await client.calculator.tftPrice();
log("================= TFT Price =================");
log(res);
log("================= TFT Price =================");
}
async function getPricingPolicy(client: GridClient) {
const res = await client.calculator.getPrices();
log("================= Pricing Policy =================");
log(res);
log("================= Pricing Policy =================");
}
async function calculateDeployment(client: GridClient, CalculatorModel: CalculatorModel) {
const res = await client.calculator.calculate(CalculatorModel);
log("================= Deployment Cost =================");
log(res);
log("================= Deployment Cost =================");
}
async function calculateDeploymentWithCurrentBalance(client: GridClient, CalculatorModel: CalculatorModel) {
const res = await client.calculator.calculateWithMyBalance(CalculatorModel);
log("================= Deployment Cost with current balance =================");
log(res);
log("================= Deployment Cost with current balance =================");
}
async function main() {
const grid3: GridClient = await getClient();
const CalculatorModel: CalculatorModel = {
cru: 16,
mru: 8, // GB
sru: 25,
hru: 0,
ipv4u: false,
certified: true,
balance: 0,
};
const CUModel: CUModel = {
cru: 1,
mru: 1, // GB
};
const SUModel: SUModel = {
hru: 1,
sru: 1, // GB
};
//Calculate CU
await calculateCU(grid3, CUModel);
//Calculate SU
await calculateSU(grid3, SUModel);
//Get TFT price
await getTFTPrice(grid3);
//Get Pricing Policy
await getPricingPolicy(grid3);
//Get deployment cost
await calculateDeployment(grid3, CalculatorModel);
//Get deployment cost with current balance
await calculateDeploymentWithCurrentBalance(grid3, CalculatorModel);
await grid3.disconnect();
}
main();