simplify dex further, adjust display function
This commit is contained in:
parent
16f03e34b1
commit
328fa7b2bf
3 changed files with 45 additions and 45 deletions
|
@ -35,60 +35,46 @@ def verifyCompletelyFulfilledIfLimitLowerHighestTouchedOrder(field[9] highestTou
|
||||||
field valid = if limit < highest then 1 - (sourceAmount - volume) else 1 fi
|
field valid = if limit < highest then 1 - (sourceAmount - volume) else 1 fi
|
||||||
return valid
|
return valid
|
||||||
|
|
||||||
def checkConstraints(field amount1, field sourceToken1, field targetToken1, field limit1, field amount2, field sourceToken2, field targetToken2, field limit2, field amount3, field sourceToken3, field targetToken3, field limit3, field[3] volume, field[3] priceToken) -> (field):
|
def checkConstraints(field[3] amount, field[3] sourceToken, field[3] targetToken, field[3] limit, field[3] volume, field[3] priceToken) -> (field):
|
||||||
// volumes are not larger than in original offer
|
// volumes are not larger than in original offer
|
||||||
field validVolumesLowerAmount1 = if amount1 < volume[0] then 0 else 1 fi
|
for field i in 0..3 do
|
||||||
validVolumesLowerAmount1 == 1
|
1 == if amount[i] < volume[i] then 0 else 1 fi
|
||||||
field validVolumesLowerAmount2 = if amount2 < volume[1] then 0 else 1 fi
|
endfor
|
||||||
validVolumesLowerAmount2 == 1
|
|
||||||
field validVolumesLowerAmount3 = if amount3 < volume[2] then 0 else 1 fi
|
|
||||||
validVolumesLowerAmount3 == 1
|
|
||||||
|
|
||||||
field sourceTokenPriceOrder1 = priceToken[sourceToken1]
|
field[3] sourceTokenPriceOrder = [0, 0, 0]
|
||||||
field targetTokenPriceOrder1 = priceToken[targetToken1]
|
field[3] targetTokenPriceOrder = [0, 0, 0]
|
||||||
field sourceTokenPriceOrder2 = priceToken[sourceToken2]
|
|
||||||
field targetTokenPriceOrder2 = priceToken[targetToken2]
|
for field i in 0..3 do
|
||||||
field sourceTokenPriceOrder3 = priceToken[sourceToken3]
|
sourceTokenPriceOrder[i] = priceToken[sourceToken[i]]
|
||||||
field targetTokenPriceOrder3 = priceToken[targetToken3]
|
targetTokenPriceOrder[i] = priceToken[targetToken[i]]
|
||||||
|
endfor
|
||||||
|
|
||||||
// orders are only touched, if the limit price is below the calculated price:
|
// orders are only touched, if the limit price is below the calculated price:
|
||||||
field validLimitLessThanPrice1 = if volume[0] == 0 then 1 else limitLessThanPrice(sourceTokenPriceOrder1, targetTokenPriceOrder1, limit1) fi
|
for field i in 0..3 do
|
||||||
validLimitLessThanPrice1 == 1
|
1 == if volume[i] == 0 then 1 else limitLessThanPrice(sourceTokenPriceOrder[i], targetTokenPriceOrder[i], limit[i]) fi
|
||||||
field validLimitLessThanPrice2 = if volume[1] == 0 then 1 else limitLessThanPrice(sourceTokenPriceOrder2, targetTokenPriceOrder2, limit2) fi
|
endfor
|
||||||
validLimitLessThanPrice2 == 1
|
|
||||||
field validLimitLessThanPrice3 = if volume[2] == 0 then 1 else limitLessThanPrice(sourceTokenPriceOrder3, targetTokenPriceOrder3, limit3) fi
|
|
||||||
validLimitLessThanPrice3 == 1
|
|
||||||
|
|
||||||
// the amount of sell volume for a token equals its buy volume:
|
// the amount of sell volume for a token equals its buy volume:
|
||||||
buyVolumeToken = tupleForTokensWithValue(0)
|
buyVolumeToken = tupleForTokensWithValue(0)
|
||||||
sellVolumeToken = tupleForTokensWithValue(0)
|
sellVolumeToken = tupleForTokensWithValue(0)
|
||||||
|
|
||||||
buyVolumeToken = addVolumesForOrder(buyVolumeToken, targetToken1, volume[0] * sourceTokenPriceOrder1)
|
for field i in 0..3 do
|
||||||
sellVolumeToken = addVolumesForOrder(sellVolumeToken, sourceToken1, volume[0] * sourceTokenPriceOrder1)
|
buyVolumeToken = addVolumesForOrder(buyVolumeToken, targetToken[i], volume[i] * sourceTokenPriceOrder[i])
|
||||||
|
sellVolumeToken = addVolumesForOrder(sellVolumeToken, sourceToken[i], volume[i] * sourceTokenPriceOrder[i])
|
||||||
buyVolumeToken = addVolumesForOrder(buyVolumeToken, targetToken2, volume[1] * sourceTokenPriceOrder2)
|
endfor
|
||||||
sellVolumeToken = addVolumesForOrder(sellVolumeToken, sourceToken2, volume[1] * sourceTokenPriceOrder2)
|
|
||||||
|
|
||||||
buyVolumeToken = addVolumesForOrder(buyVolumeToken, targetToken3, volume[2] * sourceTokenPriceOrder3)
|
|
||||||
sellVolumeToken = addVolumesForOrder(sellVolumeToken, sourceToken3, volume[2] * sourceTokenPriceOrder3)
|
|
||||||
|
|
||||||
buyVolumeToken == sellVolumeToken
|
buyVolumeToken == sellVolumeToken
|
||||||
|
|
||||||
// If an order σ ∈ Oi→j with a limit price p has a positive trading volume, then every order in Oi→j with a lower limit price should be completely fulfilled.
|
// If an order σ ∈ Oi→j with a limit price p has a positive trading volume, then every order in Oi→j with a lower limit price should be completely fulfilled.
|
||||||
highestTouchedOrder = tupleForTokenPairsWithValue(0)
|
highestTouchedOrder = tupleForTokenPairsWithValue(0)
|
||||||
|
|
||||||
highestTouchedOrder = updateHighestTouchedOrder(highestTouchedOrder, sourceToken1, targetToken1, limit1, volume[0])
|
for field i in 0..3 do
|
||||||
|
highestTouchedOrder = updateHighestTouchedOrder(highestTouchedOrder, sourceToken[i], targetToken[i], limit[i], volume[i])
|
||||||
|
endfor
|
||||||
|
|
||||||
highestTouchedOrder = updateHighestTouchedOrder(highestTouchedOrder, sourceToken2, targetToken2, limit2, volume[1])
|
for field i in 0..3 do
|
||||||
|
1 == verifyCompletelyFulfilledIfLimitLowerHighestTouchedOrder(highestTouchedOrder, amount[i], sourceToken[i], targetToken[i], limit[i], volume[i])
|
||||||
highestTouchedOrder = updateHighestTouchedOrder(highestTouchedOrder, sourceToken3, targetToken3, limit3, volume[2])
|
endfor
|
||||||
|
|
||||||
valid = verifyCompletelyFulfilledIfLimitLowerHighestTouchedOrder(highestTouchedOrder, amount1, sourceToken1, targetToken1, limit1, volume[0])
|
|
||||||
valid == 1
|
|
||||||
valid = verifyCompletelyFulfilledIfLimitLowerHighestTouchedOrder(highestTouchedOrder, amount2, sourceToken2, targetToken2, limit2, volume[1])
|
|
||||||
valid == 1
|
|
||||||
valid = verifyCompletelyFulfilledIfLimitLowerHighestTouchedOrder(highestTouchedOrder, amount3, sourceToken3, targetToken3, limit3, volume[2])
|
|
||||||
valid == 1
|
|
||||||
|
|
||||||
return 1 // Could return total volume to maximize for
|
return 1 // Could return total volume to maximize for
|
||||||
|
|
||||||
|
@ -96,9 +82,18 @@ def main(private field[3] encodedOrder, private field[3] bitmapOrder, private fi
|
||||||
// Remove orders that are not double signed
|
// Remove orders that are not double signed
|
||||||
encodedOrder = [if bitmapOrder[0] == 1 then encodedOrder[0] else 0 fi, if bitmapOrder[1] == 1 then encodedOrder[1] else 0 fi, if bitmapOrder[2] == 1 then encodedOrder[2] else 0 fi]
|
encodedOrder = [if bitmapOrder[0] == 1 then encodedOrder[0] else 0 fi, if bitmapOrder[1] == 1 then encodedOrder[1] else 0 fi, if bitmapOrder[2] == 1 then encodedOrder[2] else 0 fi]
|
||||||
|
|
||||||
// Decode orders
|
field[3] amount = [0, 0, 0]
|
||||||
amount1, sourceToken1, targetToken1, limit1 = decodeOrder(encodedOrder[0])
|
field[3] sourceToken = [0, 0, 0]
|
||||||
amount2, sourceToken2, targetToken2, limit2 = decodeOrder(encodedOrder[1])
|
field[3] targetToken = [0, 0, 0]
|
||||||
amount3, sourceToken3, targetToken3, limit3 = decodeOrder(encodedOrder[2])
|
field[3] limit = [0, 0, 0]
|
||||||
|
|
||||||
return checkConstraints(amount1, sourceToken1, targetToken1, limit1, amount2, sourceToken2, targetToken2, limit2, amount3, sourceToken3, targetToken3, limit3, volume, priceToken)
|
// Decode orders
|
||||||
|
for field i in 0..3 do
|
||||||
|
a, s, t, l = decodeOrder(encodedOrder[i])
|
||||||
|
amount[i] = a
|
||||||
|
sourceToken[i] = s
|
||||||
|
targetToken[i] = t
|
||||||
|
limit[i] = l
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return checkConstraints(amount, sourceToken, targetToken, limit, volume, priceToken)
|
|
@ -3,4 +3,9 @@
|
||||||
import "./../../binary/and.code" as AND
|
import "./../../binary/and.code" as AND
|
||||||
|
|
||||||
def main(field[32] b, field[32] c) -> (field[32]):
|
def main(field[32] b, field[32] c) -> (field[32]):
|
||||||
return [AND(b[0], c[0]), AND(b[1], c[1]), AND(b[2], c[2]), AND(b[3], c[3]), AND(b[4], c[4]), AND(b[5], c[5]), AND(b[6], c[6]), AND(b[7], c[7]), AND(b[8], c[8]), AND(b[9], c[9]), AND(b[10], c[10]), AND(b[11], c[11]), AND(b[12], c[12]), AND(b[13], c[13]), AND(b[14], c[14]), AND(b[15], c[15]), AND(b[16], c[16]), AND(b[17], c[17]), AND(b[18], c[18]), AND(b[19], c[19]), AND(b[20], c[20]), AND(b[21], c[21]), AND(b[22], c[22]), AND(b[23], c[23]), AND(b[24], c[24]), AND(b[25], c[25]), AND(b[26], c[26]), AND(b[27], c[27]), AND(b[28], c[28]), AND(b[29], c[29]), AND(b[30], c[30]), AND(b[31], c[31])]
|
field[32] result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
for field i in 0..32 do
|
||||||
|
r = AND(b[i], c[i])
|
||||||
|
result[i] = r
|
||||||
|
endfor
|
||||||
|
return result
|
|
@ -142,7 +142,7 @@ impl<T: Field> Typed for TypedAssignee<T> {
|
||||||
impl<T: Field> fmt::Debug for TypedAssignee<T> {
|
impl<T: Field> fmt::Debug for TypedAssignee<T> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
TypedAssignee::Identifier(ref s) => write!(f, "{}", s),
|
TypedAssignee::Identifier(ref s) => write!(f, "{}", s.id),
|
||||||
TypedAssignee::ArrayElement(ref a, ref e) => write!(f, "{}[{}]", a, e),
|
TypedAssignee::ArrayElement(ref a, ref e) => write!(f, "{}[{}]", a, e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue