Skip to content

Commit

Permalink
Merge pull request #22 from bancorprotocol/extend-source-by-trade-amo…
Browse files Browse the repository at this point in the history
…unt-input-range

Extend the supported input range of trade-by-source-amount
  • Loading branch information
barakman authored Jan 29, 2024
2 parents 1e0c649 + 096266a commit 3227ba8
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 1 deletion.
4 changes: 3 additions & 1 deletion benchmark/core/trade/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def tradeBySourceAmountFunc(x, y, z, A, B):

temp4 = mulDivC(temp1, temp1, factor)
temp5 = mulDivC(temp3, A, factor)
return mulDivF(temp2, temp3 // factor, add(temp4, temp5))
if temp4 + temp5 <= MAX_UINT256:
return mulDivF(temp2, temp3 // factor, temp4 + temp5)
return temp2 // add(A, mulDivC(temp1, temp1, temp3))

#
# x * z ^ 2
Expand Down
92 changes: 92 additions & 0 deletions benchmark/resources/match/SpecialMatch.json
Original file line number Diff line number Diff line change
Expand Up @@ -871,5 +871,97 @@
}
]
}
},
{
"method": "matchBySourceAmount",
"amount": "10000000000000000000000",
"orders": [
{
"liquidity": "9694677352470453892074",
"lowestRate": "33333333333333.01391180980424255864136284799315035343170166015625",
"highestRate": "198019801980197.408654344705869476683801622129976749420166015625",
"marginalRate": "104452559155538.8882958589671163947507815520699425817338168004935"
},
{
"liquidity": "96946773524704538920743",
"lowestRate": "33333333333333.01391180980424255864136284799315035343170166015625",
"highestRate": "198019801980197.408654344705869476683801622129976749420166015625",
"marginalRate": "104452559155538.8882958589671163947507815520699425817338168004935"
},
{
"liquidity": "969467735247045389207437",
"lowestRate": "33333333333333.01391180980424255864136284799315035343170166015625",
"highestRate": "198019801980197.408654344705869476683801622129976749420166015625",
"marginalRate": "104452559155538.8882958589671163947507815520699425817338168004935"
},
{
"liquidity": "9694677352470453892074378",
"lowestRate": "33333333333333.01391180980424255864136284799315035343170166015625",
"highestRate": "198019801980197.408654344705869476683801622129976749420166015625",
"marginalRate": "104452559155538.8882958589671163947507815520699425817338168004935"
},
{
"liquidity": "96946773524704538920743789",
"lowestRate": "33333333333333.01391180980424255864136284799315035343170166015625",
"highestRate": "198019801980197.408654344705869476683801622129976749420166015625",
"marginalRate": "104452559155538.8882958589671163947507815520699425817338168004935"
}
],
"actions": {
"Fast": [
{
"id": "0",
"input": "164298820",
"output": "9694677346078191181485"
},
{
"id": "1",
"input": "1642988201",
"output": "96946773494115245173215"
},
{
"id": "2",
"input": "16429882019",
"output": "969467735241152451806436"
},
{
"id": "3",
"input": "164298820191",
"output": "9694677352444857851397115"
},
{
"id": "4",
"input": "1642988201917",
"output": "96946773524681911847310712"
}
],
"Best": [
{
"id": "0",
"input": "164298820",
"output": "9694677346078191181485"
},
{
"id": "1",
"input": "1642988201",
"output": "96946773494115245173215"
},
{
"id": "2",
"input": "16429882019",
"output": "969467735241152451806436"
},
{
"id": "3",
"input": "164298820191",
"output": "9694677352444857851397115"
},
{
"id": "4",
"input": "1642988201917",
"output": "96946773524681911847310712"
}
]
}
}
]
14 changes: 14 additions & 0 deletions benchmark/resources/trade/ExtremeSrcTrade.json
Original file line number Diff line number Diff line change
Expand Up @@ -7152,5 +7152,19 @@
"impl": "11263526807791440437174508207861",
"spec": "11263526807791494477914130651426"
}
},
{
"method": "tradeBySourceAmount",
"amount": "15120357940",
"order": {
"liquidity": "969467735247045389207437",
"lowestRate": "33333333333333.01391180980424255864136284799315035343170166015625",
"highestRate": "198019801980197.408654344705869476683801622129976749420166015625",
"marginalRate": "104452559155538.8882958589671163947507815520699425817338168004935"
},
"output": {
"impl": "924248818871126217204242",
"spec": "924248818871128843570750.388118986304"
}
}
]

0 comments on commit 3227ba8

Please sign in to comment.