def doubleHopTestFloat(supply, balance1, weight1, balance2, weight2, amount):
    try:
        amount = FormulaNativePython.calculatePurchaseReturn(
            supply, balance1, weight1, amount)
        return FormulaNativePython.calculateSaleReturn(supply + amount,
                                                       balance2, weight2,
                                                       amount)
    except:
        return -1
def formulaTest(x):
    resultSolidityPort = FormulaSolidityPort.lambertNeg1(x)
    resultNativePython = FormulaNativePython.lambertNeg(
        x, FormulaSolidityPort.MAX_PRECISION)
    if resultSolidityPort > resultNativePython:
        error = ['Implementation Error:']
        error.append('x                  = {}'.format(x))
        error.append('resultSolidityPort = {}'.format(resultSolidityPort))
        error.append('resultNativePython = {}'.format(resultNativePython))
        raise BaseException('\n'.join(error))
    return resultSolidityPort / resultNativePython
def formulaTest(staked1, balance1, balance2, rate1, rate2):
    if isSolvable(staked1, balance1, balance2, rate1, rate2):
        weights = FormulaSolidityPort.balancedWeights(staked1, balance1,
                                                      balance2, rate1, rate2)
        weight1 = weights[0]
        weight2 = weights[1]
        amount1 = staked1 - balance1
        amount2 = FormulaNativePython.crossReserveTargetAmount(
            balance1, weight1, balance2, weight2, amount1)
        return Decimal((balance1 + amount1) * weight2 * rate2) / Decimal(
            (balance2 - amount2) * weight1 * rate1)
    return Decimal(1)
Ejemplo n.º 4
0
def powerTest(baseN, baseD, expN, expD):
    resultSolidityPort, precision = FormulaSolidityPort.power(baseN, baseD, expN, expD)
    resultNativePython = FormulaNativePython.power(baseN, baseD, expN, expD, precision)
    if resultSolidityPort > resultNativePython:
        error = ['Implementation Error:']
        error.append('baseN              = {}'.format(baseN             ))
        error.append('baseD              = {}'.format(baseD             ))
        error.append('expN               = {}'.format(expN              ))
        error.append('expD               = {}'.format(expD              ))
        error.append('resultSolidityPort = {}'.format(resultSolidityPort))
        error.append('resultNativePython = {}'.format(resultNativePython))
        raise BaseException('\n'.join(error))
    return resultSolidityPort/resultNativePython
Ejemplo n.º 5
0
def formulaTest(supply,balance,ratio,amount):
    resultSolidityPort = FormulaSolidityPort.calculatePurchaseReturn(supply,balance,ratio,amount)
    resultNativePython = FormulaNativePython.calculatePurchaseReturn(supply,balance,ratio,amount)
    if resultSolidityPort > resultNativePython:
        error = ['Implementation Error:']
        error.append('supply             = {}'.format(supply            ))
        error.append('balance            = {}'.format(balance           ))
        error.append('ratio              = {}'.format(ratio             ))
        error.append('amount             = {}'.format(amount            ))
        error.append('resultSolidityPort = {}'.format(resultSolidityPort))
        error.append('resultNativePython = {}'.format(resultNativePython))
        raise BaseException('\n'.join(error))
    return resultSolidityPort/resultNativePython
def formulaTest(supply, balance, weight, amount):
    resultSolidityPort = FormulaSolidityPort.saleRate(supply, balance, weight, amount)
    resultNativePython = FormulaNativePython.saleRate(supply, balance, weight, amount)
    if resultSolidityPort > resultNativePython:
        error = ['Implementation Error:']
        error.append('supply             = {}'.format(supply))
        error.append('balance            = {}'.format(balance))
        error.append('weight             = {}'.format(weight))
        error.append('amount             = {}'.format(amount))
        error.append('resultSolidityPort = {}'.format(resultSolidityPort))
        error.append('resultNativePython = {}'.format(resultNativePython))
        raise BaseException('\n'.join(error))
    return resultSolidityPort / resultNativePython
def formulaTest(balance1, weight1, balance2, weight2, amount):
    resultSolidityPort = FormulaSolidityPort.crossReserveTargetAmount(balance1, weight1, balance2, weight2, amount)
    resultNativePython = FormulaNativePython.crossReserveTargetAmount(balance1, weight1, balance2, weight2, amount)
    if resultSolidityPort > resultNativePython:
        error = ['Implementation Error:']
        error.append('balance1           = {}'.format(balance1))
        error.append('weight1            = {}'.format(weight1))
        error.append('balance2           = {}'.format(balance2))
        error.append('weight2            = {}'.format(weight2))
        error.append('amount             = {}'.format(amount))
        error.append('resultSolidityPort = {}'.format(resultSolidityPort))
        error.append('resultNativePython = {}'.format(resultNativePython))
        raise BaseException('\n'.join(error))
    return resultSolidityPort / resultNativePython
Ejemplo n.º 8
0
 def closeArbitrage(self, user):
     self._updateWeights()
     mainBranch = self.branches[self.mainSymbol]
     sideBranch = self.branches[self.sideSymbol]
     amount = mainBranch.reserveStaked - mainBranch.reserveToken.balanceOf[
         self.id]
     if amount > 0:
         self.convert(False, self.mainSymbol, self.sideSymbol, user, amount)
     if amount < 0:
         self.convert(
             False, self.sideSymbol, self.mainSymbol, user,
             int(-FormulaNativePython.crossReserveTargetAmount(
                 mainBranch.virtualBalance(self.amp, self.id), mainBranch.
                 reserveWeight, sideBranch.virtualBalance(
                     self.amp, self.id), sideBranch.reserveWeight, amount)))
Ejemplo n.º 9
0
def formulaTest(balance1, ratio1, balance2, ratio2, amount):
    resultSolidityPort = FormulaSolidityPort.calculateCrossReserveReturn(
        balance1, ratio1, balance2, ratio2, amount)
    resultNativePython = FormulaNativePython.calculateCrossReserveReturn(
        balance1, ratio1, balance2, ratio2, amount)
    if resultSolidityPort > resultNativePython:
        error = ['Implementation Error:']
        error.append('balance1           = {}'.format(balance1))
        error.append('ratio1             = {}'.format(ratio1))
        error.append('balance2           = {}'.format(balance2))
        error.append('ratio2             = {}'.format(ratio2))
        error.append('amount             = {}'.format(amount))
        error.append('resultSolidityPort = {}'.format(resultSolidityPort))
        error.append('resultNativePython = {}'.format(resultNativePython))
        raise BaseException('\n'.join(error))
    return resultSolidityPort / resultNativePython
def formulaTest(x):
    resultSolidityPort = FormulaSolidityPort.lambertPos3(x)
    resultNativePython = FormulaNativePython.lambertPos(x, FormulaSolidityPort.MAX_PRECISION)
    return resultSolidityPort / resultNativePython