Skip to content

Commit

Permalink
More tests and minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 5, 2024
1 parent ca49e7c commit be387b2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions convex-core/src/main/cvx/convex/torus/exchange.cvx
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@
(let [tok token-balance
cvm *balance*]
(cond (and (> tok 0) (> cvm 0))
(/ cvm
tok))))
(/ cvm tok))))


(defn sell-cvx
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]}
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions convex-core/src/test/java/convex/actors/TorusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit be387b2

Please sign in to comment.