diff --git a/convex-core/src/main/cvx/convex/torus/exchange.cvx b/convex-core/src/main/cvx/convex/torus/exchange.cvx index 4071ee623..5729ee1c3 100644 --- a/convex-core/src/main/cvx/convex/torus/exchange.cvx +++ b/convex-core/src/main/cvx/convex/torus/exchange.cvx @@ -194,8 +194,7 @@ (let [tok token-balance cvm *balance*] (cond (and (> tok 0) (> cvm 0)) - (/ cvm - tok)))) + (/ cvm tok)))) (defn sell-cvx @@ -299,7 +298,9 @@ own-holding (or (get-holding *caller*) 0) ;; Check withrawal amount is valid - _ (or (<= 0 shares own-holding) (fail :FUNDS "Insufficient shares")) + _ (cond + (> shares own-holding) (fail :FUNDS "Insufficient shares") + (< shares 0) (fail :ARGUMENT "Negative withdrawal")) proportion (if (> supply 0) @@ -449,7 +450,7 @@ (defn price - ^{:doc {:description "Gets the current price for a token, in CVX or an optional given currency. Returns nil if a market with liquidity does not exist." + ^{:doc {:description "Gets the current price for a token, in CVM or an optional given currency. Returns nil if a market with liquidity does not exist." :examples [{:code "(price USD)"} {:code "(price GBP USD)"}] :signature [{:params [token]} @@ -507,7 +508,7 @@ (sell-cvx-quote cvx-amount)))))) (defn sell-tokens - ^{:doc {:description "Sell tokens at current CVX price" + ^{:doc {:description "Sell tokens at current CVM price" :signature [{:params [token amount]}]}} [token amount] (let [market (or (get-market token) diff --git a/convex-core/src/test/java/convex/actors/TorusTest.java b/convex-core/src/test/java/convex/actors/TorusTest.java index 5bd9785d9..853c17f62 100644 --- a/convex-core/src/test/java/convex/actors/TorusTest.java +++ b/convex-core/src/test/java/convex/actors/TorusTest.java @@ -228,6 +228,7 @@ public class TorusTest extends ACVMTest { assertEquals(RT.cvm(4.0),eval(ctx,"(torus/price TOK)")); assertFundsError(step(ctx,"(torus/withdraw-liquidity TOK 10001)")); + assertArgumentError(step(ctx,"(torus/withdraw-liquidity TOK -100)")); } @Test public void testLiquidityZeroCVM() { diff --git a/convex-core/src/test/java/convex/core/data/FuzzTestFormat.java b/convex-core/src/test/java/convex/core/data/FuzzTestFormat.java index cb01c085b..871fbb069 100644 --- a/convex-core/src/test/java/convex/core/data/FuzzTestFormat.java +++ b/convex-core/src/test/java/convex/core/data/FuzzTestFormat.java @@ -68,7 +68,7 @@ public static void doCellFuzzTests(ACell c) { private static void doFuzzTest(Blob b) throws BadFormatException { ACell v; try { - v = Format.read(b); + v = Format.read(b,0); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Badd fuzzed read: "+b); throw e;