-
Notifications
You must be signed in to change notification settings - Fork 1
/
ts-test.nodemon.ts
72 lines (65 loc) · 1.87 KB
/
ts-test.nodemon.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
import { createReachAPI, initHumbleSDK } from "./src";
import { poolBackend } from "./src/build/backend";
import { getHumbleAddr } from "./src/constants";
import { parseCurrency, /* trimByteString */ } from "./src/reach-helpers";
import { Balances, PoolProtocolInfo } from "./src/types";
type PoolData = {
tokADecimals: number | undefined;
tokBDecimals: number | undefined;
tokABalance: any;
tokBBalance: any;
};
initHumbleSDK();
/* loadReach(loadStdlib); */
const reach = createReachAPI();
/**
* Compute expected Swap output
* @returns Tuple, first object is `swap result`, and second object is
* `protocol fees` from swap
*/
type ComputeSwapFn = {
(
aForB: boolean,
normalIn: Balances,
poolBalances: Balances,
protocolInfo: PoolProtocolInfo
): Balances[];
};
const poolIsOverloaded = (data?: PoolData) => {
if (!data) return true;
const { tokADecimals, tokBDecimals, tokABalance, tokBBalance } = data;
let aToB: any;
let bToA: any;
try {
const computeSwap: ComputeSwapFn =
poolBackend.getExports(reach).computeSwap_;
const minAmt = reach.bigNumberify(1);
const poolBals = {
A: parseCurrency(tokABalance, tokADecimals),
B: parseCurrency(tokBBalance, tokBDecimals),
};
// const FEE_INFO = getFeeInfo();
// aToB = getAmtOutView(minAmt, balA, balB, FEE_INFO);
// bToA = getAmtOutView(minAmt, balB, balA, FEE_INFO);
const pi: PoolProtocolInfo = {
lpFee: 25,
protoAddr: getHumbleAddr(),
protoFee: 5,
totFee: 30,
};
aToB = computeSwap(true, { A: minAmt, B: 0 }, poolBals, pi);
console.log({ aToB });
bToA = computeSwap(false, { B: minAmt, A: 0 }, poolBals, pi);
console.log({ bToA });
return false;
} catch (e: any) {
console.log({ e });
return true;
}
};
poolIsOverloaded({
tokABalance: 1_000_000,
tokADecimals: 6,
tokBBalance: 1000,
tokBDecimals: 6,
});