From c86c94ce9c9696b7f10d16360569549a3ea0da6d Mon Sep 17 00:00:00 2001 From: caydyan Date: Tue, 23 Jun 2026 01:28:51 +0800 Subject: [PATCH] Reject standard stableswap zero convergence threshold --- contracts/stableswap.clar | 2 +- tests/stableswap_test.ts | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/contracts/stableswap.clar b/contracts/stableswap.clar index 5f65c51..fc464d8 100644 --- a/contracts/stableswap.clar +++ b/contracts/stableswap.clar @@ -1005,6 +1005,7 @@ ) ;; Assert that tx-sender is an admin using is-some & index-of with the admins var (asserts! (is-some (index-of current-admins tx-sender)) (err "err-not-admin")) + (asserts! (> new-convergence-threshold u0) (err "err-invalid-convergence-threshold")) (ok (var-set convergence-threshold new-convergence-threshold)) ) @@ -1032,4 +1033,3 @@ (ok staking-contract) ) ) - diff --git a/tests/stableswap_test.ts b/tests/stableswap_test.ts index 3a7b055..fcfb1d1 100644 --- a/tests/stableswap_test.ts +++ b/tests/stableswap_test.ts @@ -1675,4 +1675,36 @@ Clarinet.test({ block.receipts[0].result.expectErr() console.log(JSON.stringify(block.receipts)); }, -}); \ No newline at end of file +}); + +// Test convergence threshold admin controls +Clarinet.test({ + name: "Ensure admins cannot set convergence threshold to zero", + async fn(chain: Chain, accounts: Map) { + const deployer = accounts.get("deployer")!; + const wallet_1 = accounts.get("wallet_1")!; + + const block = chain.mineBlock([ + Tx.contractCall("stableswap", "change-convergence-threshold", [types.uint(0)], deployer.address) + ]); + + block.receipts[0].result.expectErr() + console.log(JSON.stringify(block.receipts)); + }, +}); + +// Test convergence threshold admin controls +Clarinet.test({ + name: "Ensure admins can set convergence threshold above zero", + async fn(chain: Chain, accounts: Map) { + const deployer = accounts.get("deployer")!; + const wallet_1 = accounts.get("wallet_1")!; + + const block = chain.mineBlock([ + Tx.contractCall("stableswap", "change-convergence-threshold", [types.uint(1)], deployer.address) + ]); + + block.receipts[0].result.expectOk() + console.log(JSON.stringify(block.receipts)); + }, +});