1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00
ZoKrates/zokrates_cli/examples/dex/limitLessThanPrice.zok

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