{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using Plots\n",
"# time (the simulation runs for 2T blocks)\n",
"T = 1000;\n",
"# adjSpeed/2\n",
"S = 0.125;\n",
"# number of good users\n",
"user = 10000;\n",
"# number of bad agents\n",
"agent = 10;\n",
"# network capacity\n",
"M = 100_000;\n",
"# 10% of transactions are from bad agents\n",
"userTX = 1.8*M/user;\n",
"agentTX = 0.2*M/agent;\n",
"# the initial fee\n",
"fee = 100;\n",
"# the equilibrium payments\n",
"payU = userTX*user*fee/2;\n",
"payA = agentTX*agent*fee/2;\n",
"\n",
"transA = 0;\n",
"for t in 1:2*T\n",
" volU = sum([rand(0:userTX) for i in 1:user]);\n",
" if t > T\n",
" transA = transA + sum([rand(0:agentTX) for i in 1:agent]);\n",
" if t % 10 == 0\n",
" volA = copy(transA);\n",
" transA = 0;\n",
" else\n",
" volA = 0;\n",
" end\n",
" else\n",
" volA = sum([rand(0:agentTX) for i in 1:agent]);\n",
" end\n",
" payU = [payU; volU*fee[end]];\n",
" payA = [payA; volA*fee[end]];\n",
" fee = [fee; fee[end]*(1+S*((volU + volA)/M - 1))];\n",
"end\n",
"\n",
"plot(fee, label = \"Transaction Fee Pricing\");\n",
"xlabel!(\"Block\");\n",
"ylabel!(\"Gas Price\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total Payment of Bad Agents: 1.6414604097649074e9\n",
"Total Payment of Good Users: 1.5119574350551254e10\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"println(\"Total Payment of Bad Agents: \", sum(payA));\n",
"println(\"Total Payment of Good Users: \", sum(payU));\n",
"\n",
"plot(payA, label = \"Bad Agents\");\n",
"plot!(payU, label = \"Good Users\");\n",
"xlabel!(\"Block\");\n",
"ylabel!(\"Total Payment\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.1.0",
"language": "julia",
"name": "julia-1.1"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.1.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}