Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formula for optimal in incorrect, doesn't pass simple test. #15

Open
tomekozlowski opened this issue Jul 25, 2022 · 1 comment
Open

Comments

@tomekozlowski
Copy link

tomekozlowski commented Jul 25, 2022

Formulas extracted from functions getEaEb() and getOptimalAmount().
[btw, python should have snake case naming, pls contain the pokemon syntax disease inside JS ecosystem]

r01_0 = 10*10**9
r01_1 = 10*10**9
r10_0 =  5*10**9
r10_1 = 15*10**9

Ea_1= (1000 * r01_0 * r10_1) / (1000 * r10_1) + (997 * r01_1); 
Eb_1= (997  * r01_1 * r10_0) / (1000 * r10_1) + (997 * r01_1);

import math as m

optimal_in = m.sqrt(Ea_1 * Eb_1 * 997 * 1000)
optimal_in = abs((optimal_in - (Ea_1 * 1000)) / 997)


print( f'opt_in: {optimal_in:.2f}')


def getAmountOut(
    amountIn,
    reserveIn,
    reserveOut
):
    amountInWithFee = amountIn * 997
    numerator = amountInWithFee * reserveOut
    denominator = (reserveIn * 1000) + amountInWithFee
    amountOut = numerator / denominator
    return amountOut


amountz1 = getAmountOut(optimal_in, r01_0, r01_1)
amountz2 = getAmountOut(amountz1, r10_0, r10_1)

print("amnz out: ", amountz1)
print("amnz out: ", amountz2)

pr = amountz2 - optimal_in
print("profitz: ", pr)


print("[!!] verifying +")
print("if amounts were higher by 1000, the profits should be less!")
print("profits are...")

amountz1 = getAmountOut(optimal_in+1000, r01_0, r01_1)
amountz2 = getAmountOut(amountz1, r10_0, r10_1)
pr = amountz2 - (optimal_in+1000)

print(f"...{pr}")

print("[!!] verifying -")
print("if amounts were lower by 1000, the profits should be less!")
print("profits are...")

amountz1 = getAmountOut(optimal_in-1000, r01_0, r01_1)
amountz2 = getAmountOut(amountz1, r10_0, r10_1)
pr = amountz2 - (optimal_in-1000)

print(f"...{pr}")

Output:

opt_in: 18370234838.05
amnz out:  6468318502.5644455
amnz out:  8449160071.675033
profitz:  -9921074766.375118
[!!] verifying +
if amounts were higher by 1000, the profits should be less!
profits are...
...-9921075695.435955
[!!] verifying -
if amounts were lower by 1000, the profits should be less!
profits are...
...-9921073837.31429


@jeanbmar
Copy link

jeanbmar commented May 5, 2023

Your transcriptions of Ea_1 and Eb_1 are wrong, check parenthesis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants