Fix math bugs

fx
This commit is contained in:
dapplion 2019-08-10 17:21:57 +02:00
parent 9bc519be2d
commit 1c993642af
2 changed files with 76 additions and 38 deletions

View File

@ -23,7 +23,7 @@ import {
getMinPrice, getMinPrice,
getS, getS,
vest_tokens, vest_tokens,
getMinR, getR,
getSlippage, getSlippage,
getTxDistribution, getTxDistribution,
getDeltaR_priceGrowth, getDeltaR_priceGrowth,
@ -127,6 +127,9 @@ const useStyles = makeStyles((theme: Theme) =>
}, },
descriptionName: { descriptionName: {
fontWeight: theme.typography.fontWeightBold fontWeight: theme.typography.fontWeightBold
},
descriptionPadding: {
padding: theme.spacing(0.5)
} }
}) })
); );
@ -158,6 +161,23 @@ const parameterDescriptions = [
} }
]; ];
const simulationParameterDescriptions = [
{
name: "Price",
text: "Price of the token over time."
},
{
name: "Floor price",
text:
"Lower bound of the price guaranteed by the vesting of hatch tokens. It decreases over time as more hatch tokens are allowed to be traded"
},
{
name: "Total exit tributes",
text:
"Cumulative sum of exit tributes collected from only exit /sell transactions"
}
];
const resultParameterDescriptions = [ const resultParameterDescriptions = [
{ {
name: "Total reserve", name: "Total reserve",
@ -167,12 +187,12 @@ const resultParameterDescriptions = [
{ {
name: "Funds generated from initial hatch", name: "Funds generated from initial hatch",
text: text:
"Fraction of the funds (theta) raised during the hatch that go directly to the cause" "Fraction of the funds (theta) raised during the hatch that go directly to the cause (analytic result)"
}, },
{ {
name: "Funds generated from exit tributes", name: "Funds generated from exit tributes",
text: text:
"Cumulative amount of exit tributes collected from only exit /sell transactions" "Cumulative sum of exit tributes collected from only exit /sell transactions"
}, },
{ {
name: "Average slippage", name: "Average slippage",
@ -286,10 +306,11 @@ export default function App() {
// enforce the effects of the unvested tokens not being burnable // enforce the effects of the unvested tokens not being burnable
let u_lower; let u_lower;
if (H === S) { if (H > S) {
u_lower = 1; u_lower = 1;
} else { } else {
const R_ratio = getMinR({ S, H, V0, k }) / R; // compute the reserve if all that supply is burned
const R_ratio = getR({ S: S - H, V0, k }) / R;
u_lower = Math.max(1 - R_ratio, u_min); u_lower = Math.max(1 - R_ratio, u_min);
} }
const priceGrowth = rv_U(u_lower, u_max); const priceGrowth = rv_U(u_lower, u_max);
@ -328,11 +349,13 @@ export default function App() {
const _avgTxSize = getMedian(txsWithdraw); const _avgTxSize = getMedian(txsWithdraw);
R_t.push(R_next); R_t.push(R_next);
S_t.push(S_next);
H_t.push(H_next);
p_t.push(getPriceR({ R: R_next, V0, k })); p_t.push(getPriceR({ R: R_next, V0, k }));
slippage_t.push(slippage); slippage_t.push(slippage);
avgTxSize_t.push(_avgTxSize); avgTxSize_t.push(_avgTxSize);
wFee_t.push(getLast(wFee_t) + wFees); wFee_t.push(getLast(wFee_t) + wFees);
H_t.push(H_next);
floorprice_t.push(floorprice_next); floorprice_t.push(floorprice_next);
setWithdrawCount(c => c + txsWithdraw.length); setWithdrawCount(c => c + txsWithdraw.length);
@ -454,13 +477,16 @@ export default function App() {
<Typography variant="h6">Preview</Typography> <Typography variant="h6">Preview</Typography>
<HelpText <HelpText
text={ text={
<Typography> <div className={classes.descriptionPadding}>
Visualization of the token bonding curve analytic function <Typography>
on a specific range of reserve [0, 4 * R0]. This result is Visualization of the token bonding curve analytic
deterministic given the current set of parameters and will function on a specific range of reserve [0, 4 * R0].
never change regardes of the campaign performance, it only This result is deterministic given the current set of
shows how the price will react to reserve changes. parameters and will never change regardes of the
</Typography> campaign performance, it only shows how the price will
react to reserve changes.
</Typography>
</div>
} }
/> />
</Box> </Box>
@ -505,14 +531,40 @@ export default function App() {
<Typography variant="h6">Simulation</Typography> <Typography variant="h6">Simulation</Typography>
<HelpText <HelpText
text={ text={
<Typography> <div className={classes.descriptionContainer}>
This chart shows a 52 week simulation of discrete <div className={classes.descriptionPadding}>
transactions interacting with the token bonding curve. <Typography>
Each transaction adds or substract reserve to the This chart shows a 52 week simulation of discrete
system, modifying the price over time. The frequency, transactions interacting with the token bonding
size and direction of each transaction is computed curve. Each transaction adds or substract reserve
from a set of bounded random functions. to the system, modifying the price over time. The
</Typography> frequency, size and direction of each transaction
is computed from a set of bounded random
functions.
</Typography>
</div>
<table>
<tbody>
{simulationParameterDescriptions.map(
({ name, text }) => (
<tr key={name}>
<td>
<Typography
className={classes.descriptionName}
>
{name}
</Typography>
</td>
<td>
<Typography>{text}</Typography>
</td>
</tr>
)
)}
</tbody>
</table>
</div>
} }
/> />
</Box> </Box>

View File

@ -23,7 +23,7 @@ export function getInitialParams({
return { k, R0, S0, V0 }; return { k, R0, S0, V0 };
} }
function getR({ S, V0, k }: { S: number; V0: number; k: number }) { export function getR({ S, V0, k }: { S: number; V0: number; k: number }) {
return S ** k / V0; return S ** k / V0;
} }
@ -31,21 +31,6 @@ export function getS({ R, V0, k }: { R: number; V0: number; k: number }) {
return (V0 * R) ** (1 / k); return (V0 * R) ** (1 / k);
} }
// compute the reserve if all that supply is burned
export function getMinR({
S,
H,
V0,
k
}: {
S: number;
H: number;
V0: number;
k: number;
}) {
return getR({ S: S - H, V0, k });
}
// compute the price if all that supply is burned // compute the price if all that supply is burned
export function getMinPrice({ export function getMinPrice({
S, S,
@ -63,7 +48,8 @@ export function getMinPrice({
const myP = getPriceR({ R: myR, V0, k }); // numerical precision make complex numbers just suppress it const myP = getPriceR({ R: myR, V0, k }); // numerical precision make complex numbers just suppress it
return Math.abs(myP); return Math.abs(myP);
} else { } else {
const minR = getMinR({ S, H, V0, k }); // compute the reserve if all that supply is burned
const minR = getR({ S: S - H, V0, k });
return getPriceR({ R: minR, V0, k }); return getPriceR({ R: minR, V0, k });
} }
} }