adding alpha derivation
This commit is contained in:
parent
2fc25888ea
commit
3a4e78be3c
|
|
@ -0,0 +1,269 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"In this notebook, we are deriving what the alpha value in the @dev formula is based off of 1hive Sol [code](https://github.com/1Hive/conviction-voting-app/blob/bc81f4af266bab6bc4096a31966bd9fe8a89f4a2/contracts/ConvictionVoting.sol)\n",
|
||||
"\n",
|
||||
" /**\n",
|
||||
" * @dev Formula: ρ * supply / (1 - a) / (β - requestedAmount / total)**2\n",
|
||||
" * For the Solidity implementation we amplify ρ and β and simplify the formula:\n",
|
||||
" * weight = ρ * D\n",
|
||||
" * maxRatio = β * D\n",
|
||||
" * decay = a * D\n",
|
||||
" * threshold = weight * supply * D ** 2 * funds ** 2 / (D - decay) / (maxRatio * funds - requestedAmount * D) ** 2\n",
|
||||
" * @param _requestedAmount Requested amount of tokens on certain proposal\n",
|
||||
" * @return Threshold a proposal's conviction should surpass in order to be able to\n",
|
||||
" * executed it.\n",
|
||||
" */\n",
|
||||
" function calculateThreshold(uint256 _requestedAmount) public view returns (uint256 _threshold) {\n",
|
||||
" uint256 funds = vault.balance(requestToken);\n",
|
||||
" require(maxRatio.mul(funds) > _requestedAmount.mul(D), ERROR_AMOUNT_OVER_MAX_RATIO);\n",
|
||||
" uint256 supply = stakeToken.totalSupply();\n",
|
||||
" // denom = maxRatio * 2 ** 64 / D - requestedAmount * 2 ** 64 / funds\n",
|
||||
" uint256 denom = (maxRatio << 64).div(D).sub((_requestedAmount << 64).div(funds));\n",
|
||||
" // _threshold = (weight * 2 ** 128 / D) / (denom ** 2 / 2 ** 64) * supply * D / 2 ** 128\n",
|
||||
" _threshold = ((weight << 128).div(D).div(denom.mul(denom) >> 64)).mul(D).div(D.sub(decay)).mul(supply) >> 64;\n",
|
||||
" }"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0.025"
|
||||
]
|
||||
},
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"# Z original code without alpha\n",
|
||||
"def trigger_threshold_original(requested, funds, supply, beta, rho):\n",
|
||||
" '''\n",
|
||||
" Function that determines threshold for proposals being accepted. \n",
|
||||
" '''\n",
|
||||
" share = requested/funds\n",
|
||||
" if share < beta:\n",
|
||||
" return rho*supply/(beta-share)**2\n",
|
||||
" else: \n",
|
||||
" return np.inf\n",
|
||||
" \n",
|
||||
"#Our new code code\n",
|
||||
"def trigger_threshold(requested, funds, supply, beta, rho, alpha):\n",
|
||||
" '''\n",
|
||||
" Function that determines threshold for proposals being accepted. \n",
|
||||
" '''\n",
|
||||
" share = requested/funds\n",
|
||||
" if share < beta:\n",
|
||||
" threshold = rho*supply/(beta-share)**2 * 1/(1-alpha)\n",
|
||||
" return threshold #* (1-alpha)\n",
|
||||
" else: \n",
|
||||
" return np.inf\n",
|
||||
" \n",
|
||||
"# Assumed values\n",
|
||||
"funds = 4000\n",
|
||||
"requested = 100\n",
|
||||
"supply = 21706\n",
|
||||
"share = requested/funds\n",
|
||||
"share"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Sol values\n",
|
||||
"D = 10000000\n",
|
||||
"decay = 9999599\n",
|
||||
"maxRatio = 2000000\n",
|
||||
"weight = 20000"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Based on the above equations, we can see that $\\rho$ is equal to:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0.002"
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"rho = weight / D\n",
|
||||
"rho"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"We can derive $\\beta$ is equal to be:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0.2"
|
||||
]
|
||||
},
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"beta = maxRatio/D\n",
|
||||
"beta"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"1417.5346938775506"
|
||||
]
|
||||
},
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"originalOutput = trigger_threshold_original(requested,funds,supply,beta,rho)\n",
|
||||
"originalOutput"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"sol code threshold:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"35349992.36602372"
|
||||
]
|
||||
},
|
||||
"execution_count": 31,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"solThreshold = weight * supply * D ** 2 * funds ** 2 / (D - decay) / (maxRatio * funds - requested * D) ** 2\n",
|
||||
"solThreshold"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Our new code threshold to match 1hive dev formulata "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'0.0000401'"
|
||||
]
|
||||
},
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"alpha = 1- 0.9999599\n",
|
||||
"\"{:.7f}\".format(alpha)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 19,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"1417.5915392982765"
|
||||
]
|
||||
},
|
||||
"execution_count": 19,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"newThreshold = trigger_threshold(requested, funds, supply, beta, rho, alpha)\n",
|
||||
"newThreshold"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.7.5"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Loading…
Reference in New Issue