10 lines
No EOL
707 B
Text
10 lines
No EOL
707 B
Text
def main(field sourceTokenPrice, field targetTokenPrice, field limit) -> (field):
|
|
// Assuming limit is in sourceToken->targetToken and price_i in token_i->refToken
|
|
// Because of arbitrage freeness the following statement should hold:
|
|
// sourceToken->targetToken = sourceToken->refToken * refToken->targetToken = refToken->targetToken / refToken->sourceToken
|
|
// Therefore we have to check that:
|
|
// `limit <= sourceToken->refToken / targetToken->refToken`
|
|
// which is equivalent to checking
|
|
// `limit * targetToken->refToken <= sourceToken->refToken`
|
|
field limitIsLessOrEqual = if sourceTokenPrice * 1000000000000000000 < (limit * targetTokenPrice) then 0 else 1 fi
|
|
return limitIsLessOrEqual |