-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbonding-curve-simulation.ts
98 lines (79 loc) · 2.9 KB
/
bonding-curve-simulation.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
91
92
93
94
95
96
97
98
const totalSupply = 100000000000;
const ethPrice = 2350;
const usdToRaise = 1000000;
const ethToRaise = 1500;
const reserveToSell = totalSupply * 0.2;
const reserveInLP = totalSupply * 0.1;
const valuationUsdFromRaise = (
reserveInLP: number,
usdInLp: number,
totalSupply: number
) => totalSupply * (usdInLp / reserveInLP);
const valuationEthFromRaise = (
reserveInLP: number,
ethInLp: number,
totalSupply: number
) => totalSupply * ((ethInLp * ethPrice) / reserveInLP);
console.log("tokens to sell", reserveToSell);
console.log("usd to raise", usdToRaise);
console.log("eth to raise", ethToRaise);
console.log("tokens in LP", reserveInLP);
console.log("valuation", valuationUsdFromRaise(reserveInLP, 100, totalSupply));
const bondingCurveETH = (x: number) =>
reserveToSell * (1 - (1 - x / ethToRaise) ** 2);
const bondingCurveUSD = (x: number) =>
reserveToSell * (1 - (1 - x / usdToRaise) ** 2);
const bondingCurveETHv2 = (x: number) => reserveToSell * (x / ethToRaise) ** 2;
const bondingCurveUSDv2 = (x: number) => reserveToSell * (x / usdToRaise) ** 2;
const tokensReceivedETH = (
prevTokensSold: number,
prevEthGiven: number,
ethGiven: number
) => bondingCurveETH(prevEthGiven + ethGiven) - prevTokensSold;
const tokensReceivedETHv2 = (
prevTokensSold: number,
prevEthGiven: number,
ethGiven: number
) => bondingCurveETHv2(prevEthGiven + ethGiven) - prevTokensSold;
const tokensReceivedUSD = (
prevTokensSold: number,
prevUsdGiven: number,
usdGiven: number
) => bondingCurveUSD(prevUsdGiven + usdGiven) - prevTokensSold;
console.log("bonding USD - 10%", bondingCurveUSD(usdToRaise * 0.1));
console.log("sale 1 for 900k$", tokensReceivedUSD(0, 0, 900000));
console.log("sale 1 for 100k$", tokensReceivedUSD(0, 0, 100000));
console.log(
"sale 2 for 200k$",
tokensReceivedUSD(tokensReceivedUSD(0, 0, 100000), 100000, 200000)
);
console.log("\n\nETH raise:");
const check = (n: number) => {
const tokensRecvd = tokensReceivedETH(0, 0, n);
const percentage = n / 1500;
const tokensInLp = percentage * reserveInLP;
const valuation = valuationEthFromRaise(tokensInLp, n * 0.6, totalSupply);
console.log(`\nvaluation at ${n} eth raised`, valuation);
console.log(`eth bought price`, n * ethPrice);
console.log(`tokens sold`, tokensRecvd);
console.log(`tokens sold price`, tokensRecvd * (valuation / totalSupply));
console.log(`price`, valuation / totalSupply);
console.log(
"percentage of sale completed",
Math.round((100 * tokensReceivedETH(0, 0, n)) / (totalSupply * 0.2))
);
};
// check(1);
check(0.052);
// check(25);
// check(50);
// check(100);
// check(250);
// check(500);
// console.log("bonding USD - 10%", bondingCurveETH(ethToRaise * 0.1));
// console.log("sale 1 for 900k$", tokensReceivedETH(0, 0, 428));
// console.log("sale 1 for 100k$", tokensReceivedETH(0, 0, 47));
// console.log(
// "sale 2 for 200k$",
// tokensReceivedETH(tokensReceivedETH(0, 0, 47), 47, 94)
// );