From e0a1cd77fc3acd61637459b113bf64f4ae8f328e Mon Sep 17 00:00:00 2001 From: dcpp Date: Thu, 17 Oct 2024 11:19:18 +0300 Subject: [PATCH] Add min-order-size CLI command --- Cargo.lock | 18 +-- spark-cli/Cargo.toml | 6 +- spark-cli/README.md | 110 +++++++++++------- spark-cli/src/commands/batch/deploy_all.rs | 6 +- spark-cli/src/commands/core/cli.rs | 7 +- spark-cli/src/commands/core/mod.rs | 1 + .../src/commands/core/set_min_order_size.rs | 51 ++++++++ spark-cli/src/commands/info/cli.rs | 9 +- spark-cli/src/commands/info/min_order_size.rs | 32 +++++ spark-cli/src/commands/info/mod.rs | 1 + spark-cli/src/main.rs | 2 + 11 files changed, 183 insertions(+), 60 deletions(-) create mode 100644 spark-cli/src/commands/core/set_min_order_size.rs create mode 100644 spark-cli/src/commands/info/min_order_size.rs diff --git a/Cargo.lock b/Cargo.lock index 8703760..e86e8c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5553,14 +5553,14 @@ dependencies = [ [[package]] name = "spark-cli" -version = "0.6.1" +version = "0.6.2" dependencies = [ "anyhow", "clap", "dotenv", "fuels", - "spark-market-sdk 0.6.1", - "spark-registry-sdk 0.6.1", + "spark-market-sdk 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "spark-registry-sdk 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio", ] @@ -5578,9 +5578,7 @@ dependencies = [ [[package]] name = "spark-market-sdk" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb68a9d4aeb968d7b7a165aca487cce1741da6fbc69bda885cdecfc0f92e10c4" +version = "0.6.2" dependencies = [ "anyhow", "fuels", @@ -5591,6 +5589,8 @@ dependencies = [ [[package]] name = "spark-market-sdk" version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab19c341f67f2b2aa04d6687c739b9a9330a27d26e8272a56f9353073ab118a7" dependencies = [ "anyhow", "fuels", @@ -5631,9 +5631,7 @@ dependencies = [ [[package]] name = "spark-registry-sdk" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f03eabeef7b9cc93991a51e4b21c42e62be211b150460e7acab0b5c109a33afb" +version = "0.6.2" dependencies = [ "anyhow", "fuels", @@ -5644,6 +5642,8 @@ dependencies = [ [[package]] name = "spark-registry-sdk" version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "382a74d5e5aa01a317816a50e572e5b30ccbac28c60eae15c764c99c43a0897a" dependencies = [ "anyhow", "fuels", diff --git a/spark-cli/Cargo.toml b/spark-cli/Cargo.toml index 768350d..a2b5b59 100644 --- a/spark-cli/Cargo.toml +++ b/spark-cli/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "spark-cli" description = "Spark Rust CLI for Market & Orderbook contract interactions" -version = "0.6.1" +version = "0.6.2" authors = { workspace = true } edition = { workspace = true } license = { workspace = true } @@ -15,8 +15,8 @@ anyhow = { workspace = true } clap = { version = "4.5.20", features = ["derive"] } dotenv = "0.15.0" fuels = { workspace = true } -spark-market-sdk = { version = "0.6.1" } -spark-registry-sdk = { version = "0.6.1" } +spark-market-sdk = { version = "0.6.2" } +spark-registry-sdk = { version = "0.6.2" } tokio = { workspace = true } [[bin]] diff --git a/spark-cli/README.md b/spark-cli/README.md index f25f1aa..e2a93de 100644 --- a/spark-cli/README.md +++ b/spark-cli/README.md @@ -32,16 +32,16 @@ spark-cli batch deploy-all \ ``` Sample output: -Spark CLI v0.6.1 +Spark CLI v0.6.2 -BTC/USDC Market version 0.6.1 (1537) deployed to: 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e -Deployment cost: 6089 +BTC/USDC Market version 0.6.2 (1538) deployed to: 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 +Deployment cost: 6324 -ETH/USDC Market version 0.6.1 (1537) deployed to: 0xcb021899e5a3178069b7caeb6e0b2391b9acf631f77733ee52500a55dc00736d -Deployment cost: 6089 +ETH/USDC Market version 0.6.2 (1538) deployed to: 0x3830aa30ddd4843dd13b6af7ae4fb59d8c5933b1a98cba9a80897c8ba5557307 +Deployment cost: 6324 -MarketRegistry version 0.6.1 (1537) deployed to: 0xd6474c9d90a4a4bcdb762f48d38afc8283799799d7e48e1055fb373ff87fb9d7 -Deployment cost: 7487 +MarketRegistry version 0.6.2 (1538) deployed to: 0xd76662328e464549b6f619401992127bed9b5cff3b46a3516e6b509d810b7035 +Deployment cost: 7723 ### Deploy BTC-USDC market @@ -56,7 +56,7 @@ spark-cli core deploy \ ``` Sample output: -Market deployed to: 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e +Market deployed to: 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 Deployment cost: 0 Owner address: fuel173lqaa6y4jxfjd2suq730uwys3zfg4f6zt9vzx4cc45v3xvlmwlszdvdpz 0xf47e0ef744ac8c993550e03d17f1c4844494553a12cac11ab8c568c8999fdbbf @@ -74,7 +74,7 @@ spark-cli core deploy \ ``` Sample output: -SparkMarket deployed to: 0xcb021899e5a3178069b7caeb6e0b2391b9acf631f77733ee52500a55dc00736d +SparkMarket deployed to: 0x3830aa30ddd4843dd13b6af7ae4fb59d8c5933b1a98cba9a80897c8ba5557307 Deployment cost: 0 Owner address: fuel173lqaa6y4jxfjd2suq730uwys3zfg4f6zt9vzx4cc45v3xvlmwlszdvdpz 0xf47e0ef744ac8c993550e03d17f1c4844494553a12cac11ab8c568c8999fdbbf @@ -86,7 +86,7 @@ spark-cli core deposit \ --asset-type base \ --amount 10 \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ``` @@ -94,7 +94,7 @@ spark-cli core deposit \ --asset-type quote \ --amount 10000 \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Deposit For @@ -106,7 +106,7 @@ spark-cli core deposit-for \ --account-type address \ --account-id 0xf47e0ef744ac8c993550e03d17f1c4844494553a12cac11ab8c568c8999fdbbf \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Withdraw @@ -116,7 +116,7 @@ spark-cli core withdraw \ --asset-type base \ --amount 10 \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ``` @@ -124,7 +124,7 @@ spark-cli core withdraw \ --asset-type quote \ --amount 7000 \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Withdraw To Market @@ -133,9 +133,9 @@ spark-cli core withdraw \ spark-cli core withdraw-to-market \ --asset-type quote \ --amount 7000 \ - --market-id 0xcb021899e5a3178069b7caeb6e0b2391b9acf631f77733ee52500a55dc00736d \ + --market-id 0x3830aa30ddd4843dd13b6af7ae4fb59d8c5933b1a98cba9a80897c8ba5557307 \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Open Order @@ -146,7 +146,7 @@ spark-cli core open \ --order-type buy \ --price 70000000000000 \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ``` @@ -155,7 +155,7 @@ spark-cli core open \ --order-type sell \ --price 70000000000000 \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Cancel Order @@ -164,7 +164,7 @@ spark-cli core open \ spark-cli core cancel \ --order-id e950192bd177292dd7b98c69e6f85a46f5d59d93a0ba2f84af1f9d06d1fdf821 \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Match Order Pair @@ -174,7 +174,7 @@ spark-cli core match-pair \ --orders f8051a6f690347e7446eb9a777e883b68a1f825b7a55d021a91412abacfca48a \ --orders 3d66b9caf0628903e037eaa65318d926fb63bf34e7277d7413e349edddd5b0f0 \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Match Order Many @@ -184,7 +184,7 @@ spark-cli core match-many \ --orders 0a96241df0a2606ead475af4cf66f89097bcbec27fdb59ff5cdb30a7525393e2 \ --orders 2a6273b795e682f9fc4723097e682e0097c29c16f0419d7dc6132f77151e27ca \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Fulfill Order Many @@ -199,7 +199,7 @@ spark-cli core fulfill-many \ --orders 0d0d7540d7350222b39a453452067cb3e1d1a29773a1678293771c9a0a12fe6f \ --orders 12e7c70e34d437960fe455ce41ee9f839a93f5b317d19a9708c3ef51dffb89d0 \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Set Protocol Fee @@ -215,7 +215,7 @@ spark-cli core set-protocol-fee \ --fee "2,7,500000000000" \ --fee "1,5,1000000000000" \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Set Matcher Fee @@ -226,7 +226,7 @@ Sets a matcher fee for the market spark-cli core set-matcher-fee \ --amount 1000 \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Set Epoch @@ -238,7 +238,7 @@ spark-cli core set-epoch \ --epoch 4611686020155120000 \ --epoch-duration 2332800 \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Set Store Order Change Info @@ -249,9 +249,21 @@ Sets a store order change info for the market spark-cli core set-store-order-change-info \ --store \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` +## Set Minimum Order Size + +Sets a minimum order size for the market + +``` +spark-cli core set-min-order-size \ + --size 1500 \ + --rpc "testnet.fuel.network" \ + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 +``` + + # Info @@ -265,7 +277,7 @@ spark-cli info account \ --account-type address \ --account-id 0xf47e0ef744ac8c993550e03d17f1c4844494553a12cac11ab8c568c8999fdbbf \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Config @@ -273,7 +285,7 @@ spark-cli info account \ ``` spark-cli info config \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Epoch @@ -281,7 +293,7 @@ spark-cli info config \ ``` spark-cli info epoch \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Protocol Fee @@ -291,7 +303,7 @@ Protocol fee ``` spark-cli info protocol-fee \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Protocol Fee User @@ -303,7 +315,7 @@ spark-cli info protocol-fee-user \ --account-type address \ --account-id 0xf47e0ef744ac8c993550e03d17f1c4844494553a12cac11ab8c568c8999fdbbf \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Protocol Fee User Amount @@ -316,7 +328,7 @@ spark-cli info protocol-fee-user-amount \ --account-type address \ --account-id 0xf47e0ef744ac8c993550e03d17f1c4844494553a12cac11ab8c568c8999fdbbf \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Matcher Fee @@ -326,7 +338,17 @@ Matcher Fee for the market ``` spark-cli info matcher-fee \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 +``` + +## Minimum Order Size + +Minimum Order Size for the market + +``` +spark-cli info min-order-size \ + --rpc "testnet.fuel.network" \ + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Order ID @@ -339,7 +361,7 @@ spark-cli info order-id \ --price 70000000000000 \ --block-height 10000 \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Order @@ -348,7 +370,7 @@ spark-cli info order-id \ spark-cli info order \ --order-id 769663aef01812de5e5b4a4cd96f31a1641d4924cd26bdf7665fc00708487007 \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Store Order Change Info @@ -358,7 +380,7 @@ Store Order Change Info for the market ``` spark-cli info store-order-change-info \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## User Orders @@ -368,7 +390,7 @@ spark-cli info user-orders \ --account-type address \ --account-id 0xf47e0ef744ac8c993550e03d17f1c4844494553a12cac11ab8c568c8999fdbbf \ --rpc "testnet.fuel.network" \ - --contract-id 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e + --contract-id 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 ``` ## Deploy Market Registry @@ -379,7 +401,7 @@ spark-cli registry deploy \ ``` Output: -SparkRegistry deployed to: 0xd6474c9d90a4a4bcdb762f48d38afc8283799799d7e48e1055fb373ff87fb9d7 +SparkRegistry deployed to: 0xd76662328e464549b6f619401992127bed9b5cff3b46a3516e6b509d810b7035 Deployment cost: 0 Owner address: fuel173lqaa6y4jxfjd2suq730uwys3zfg4f6zt9vzx4cc45v3xvlmwlszdvdpz 0xf47e0ef744ac8c993550e03d17f1c4844494553a12cac11ab8c568c8999fdbbf @@ -388,18 +410,18 @@ Owner address: fuel173lqaa6y4jxfjd2suq730uwys3zfg4f6zt9vzx4cc45v3xvlmwlszdvdpz ``` spark-cli registry register \ - --market 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e \ + --market 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 \ --rpc "testnet.fuel.network" \ - --contract-id 0xd6474c9d90a4a4bcdb762f48d38afc8283799799d7e48e1055fb373ff87fb9d7 + --contract-id 0xd76662328e464549b6f619401992127bed9b5cff3b46a3516e6b509d810b7035 ``` ## Unregister a market ``` spark-cli registry unregister \ - --market 0x9492dfe08f7da2ff6366304bed64ab64b5208593657852d5b22f2c12f256785e \ + --market 0x81acb82a64ff799836c19f4e7f9871cf6d13a1e5d286e815f91c26a1b92a8195 \ --rpc "testnet.fuel.network" \ - --contract-id 0xd6474c9d90a4a4bcdb762f48d38afc8283799799d7e48e1055fb373ff87fb9d7 + --contract-id 0xd76662328e464549b6f619401992127bed9b5cff3b46a3516e6b509d810b7035 ``` ## Get registered markets by assets @@ -409,7 +431,7 @@ spark-cli registry markets \ --base 0x38e4ca985b22625fff93205e997bfc5cc8453a953da638ad297ca60a9f2600bc \ --quote 0x336b7c06352a4b736ff6f688ba6885788b3df16e136e95310ade51aa32dc6f05 \ --rpc "testnet.fuel.network" \ - --contract-id 0xd6474c9d90a4a4bcdb762f48d38afc8283799799d7e48e1055fb373ff87fb9d7 + --contract-id 0xd76662328e464549b6f619401992127bed9b5cff3b46a3516e6b509d810b7035 ``` ## Config @@ -417,5 +439,5 @@ spark-cli registry markets \ ``` spark-cli registry config \ --rpc "testnet.fuel.network" \ - --contract-id 0xd6474c9d90a4a4bcdb762f48d38afc8283799799d7e48e1055fb373ff87fb9d7 + --contract-id 0xd76662328e464549b6f619401992127bed9b5cff3b46a3516e6b509d810b7035 ``` diff --git a/spark-cli/src/commands/batch/deploy_all.rs b/spark-cli/src/commands/batch/deploy_all.rs index dc2d902..7b111a5 100644 --- a/spark-cli/src/commands/batch/deploy_all.rs +++ b/spark-cli/src/commands/batch/deploy_all.rs @@ -28,7 +28,7 @@ impl DeployAllCommand { let quote_decimals = 6; let price_decimals = 9; let version = SparkMarketContract::sdk_version(); - let matcher_fee = 1_000; + let matcher_fee = 1_000; // 0.001 USDC // multi tier protocol fee structure let protocol_fee = vec![ @@ -91,6 +91,7 @@ impl DeployAllCommand { // 1. Deploy BTC/USDC market contract let base_asset = AssetId::from_str(&btc).unwrap(); let base_decimals = 8; + let min_size = 1_500; // 0.000015 BTC // Initial balance prior to contract call let balance = wallet @@ -111,6 +112,7 @@ impl DeployAllCommand { let _ = contract.set_matcher_fee(matcher_fee).await?; let _ = contract.set_protocol_fee(protocol_fee.clone()).await?; let _ = contract.set_epoch(epoch, epoch_duration).await?; + let _ = contract.set_min_order_size(min_size).await?; // Balance post-deployment let new_balance = wallet @@ -129,6 +131,7 @@ impl DeployAllCommand { // 2. Deploy ETH/USDC market contract let base_asset = AssetId::from_str(ð).unwrap(); let base_decimals = 9; + let min_size = 400_000; // 0.0004 ETH // Initial balance prior to contract call let balance = wallet @@ -149,6 +152,7 @@ impl DeployAllCommand { let _ = contract.set_matcher_fee(matcher_fee).await?; let _ = contract.set_protocol_fee(protocol_fee.clone()).await?; let _ = contract.set_epoch(epoch, epoch_duration).await?; + let _ = contract.set_min_order_size(min_size).await?; // Balance post-deployment let new_balance = wallet diff --git a/spark-cli/src/commands/core/cli.rs b/spark-cli/src/commands/core/cli.rs index b2b283f..8b80010 100644 --- a/spark-cli/src/commands/core/cli.rs +++ b/spark-cli/src/commands/core/cli.rs @@ -2,7 +2,8 @@ use crate::commands::core::{ cancel_order::CancelCommand, deploy::DeployCommand, deposit::DepositCommand, deposit_for::DepositForCommand, fulfill_many::FulfillManyCommand, match_many::MatchManyCommand, match_pair::MatchPairCommand, open_order::OpenCommand, set_epoch::SetEpochCommand, - set_matcher_fee::SetMatcherFeeCommand, set_protocol_fee::SetProtocolFeeCommand, + set_matcher_fee::SetMatcherFeeCommand, set_min_order_size::SetMinOrderSizeCommand, + set_protocol_fee::SetProtocolFeeCommand, set_store_order_change_info::SetStoreOrderChangeInfoCommand, withdraw::WithdrawCommand, withdraw_to_market::WithdrawToMarketCommand, }; @@ -58,6 +59,10 @@ pub(crate) enum CoreCommands { #[clap(short_flag = 'U')] SetStoreOrderChangeInfo(SetStoreOrderChangeInfoCommand), + /// Set a minimum order size for the market + #[clap(short_flag = 'V')] + SetMinOrderSize(SetMinOrderSizeCommand), + /// Withdraw from the market contract #[clap(short_flag = 'W')] Withdraw(WithdrawCommand), diff --git a/spark-cli/src/commands/core/mod.rs b/spark-cli/src/commands/core/mod.rs index 7818250..c8df476 100644 --- a/spark-cli/src/commands/core/mod.rs +++ b/spark-cli/src/commands/core/mod.rs @@ -9,6 +9,7 @@ pub(crate) mod match_pair; pub(crate) mod open_order; pub(crate) mod set_epoch; pub(crate) mod set_matcher_fee; +pub(crate) mod set_min_order_size; pub(crate) mod set_protocol_fee; pub(crate) mod set_store_order_change_info; pub(crate) mod withdraw; diff --git a/spark-cli/src/commands/core/set_min_order_size.rs b/spark-cli/src/commands/core/set_min_order_size.rs new file mode 100644 index 0000000..be7b2e0 --- /dev/null +++ b/spark-cli/src/commands/core/set_min_order_size.rs @@ -0,0 +1,51 @@ +use crate::utils::{setup, validate_contract_id}; +use clap::Args; +use fuels::accounts::ViewOnlyAccount; +use spark_market_sdk::SparkMarketContract; + +#[derive(Args, Clone)] +#[command(about = "Change the min order size for the market")] +pub(crate) struct SetMinOrderSizeCommand { + /// The fee to set + #[clap(long)] + pub(crate) size: u64, + + /// The contract id of the market + #[clap(long)] + pub(crate) contract_id: String, + + /// The URL to query + /// Ex. testnet.fuel.network + #[clap(long)] + pub(crate) rpc: String, +} + +impl SetMinOrderSizeCommand { + pub(crate) async fn run(&self) -> anyhow::Result<()> { + let wallet = setup(&self.rpc).await?; + let contract_id = validate_contract_id(&self.contract_id)?; + + // Initial balance prior to contract call - used to calculate contract interaction cost + let balance = wallet + .get_asset_balance(&wallet.provider().unwrap().base_asset_id()) + .await?; + + // Connect to the deployed contract via the rpc + let contract = SparkMarketContract::new(contract_id, wallet.clone()).await; + + let _ = contract.set_min_order_size(self.size).await?; + + // Balance post-deployment + let new_balance = wallet + .get_asset_balance(&wallet.provider().unwrap().base_asset_id()) + .await?; + + println!( + "\nThe min order size has been set to: {}", + contract.min_order_size().await?.value + ); + println!("Contract call cost: {}", balance - new_balance); + + Ok(()) + } +} diff --git a/spark-cli/src/commands/info/cli.rs b/spark-cli/src/commands/info/cli.rs index e9140b4..ed070d1 100644 --- a/spark-cli/src/commands/info/cli.rs +++ b/spark-cli/src/commands/info/cli.rs @@ -1,7 +1,8 @@ use crate::commands::info::{ account::AccountCommand, config::ConfigCommand, epoch::EpochCommand, - matcher_fee::MatcherFeeCommand, order::OrderCommand, order_id::OrderIdCommand, - protocol_fee::ProtocolFeeCommand, protocol_fee_user::ProtocolFeeUserCommand, + matcher_fee::MatcherFeeCommand, min_order_size::MinOrderSizeCommand, order::OrderCommand, + order_id::OrderIdCommand, protocol_fee::ProtocolFeeCommand, + protocol_fee_user::ProtocolFeeUserCommand, protocol_fee_user_amount::ProtocolFeeUserAmountCommand, store_order_change_info::StoreOrderChangeInfoCommand, user_orders::UserOrdersCommand, }; @@ -37,6 +38,10 @@ pub(crate) enum InfoCommands { #[clap(short_flag = 'M')] MatcherFee(MatcherFeeCommand), + /// Query minimum order size of the market contract + #[clap(short_flag = 'N')] + MinOrderSize(MinOrderSizeCommand), + /// Calculate the order id given the provided arguments #[clap(short_flag = 'I')] OrderId(OrderIdCommand), diff --git a/spark-cli/src/commands/info/min_order_size.rs b/spark-cli/src/commands/info/min_order_size.rs new file mode 100644 index 0000000..839b868 --- /dev/null +++ b/spark-cli/src/commands/info/min_order_size.rs @@ -0,0 +1,32 @@ +use crate::utils::{setup, validate_contract_id}; +use clap::Args; +use spark_market_sdk::SparkMarketContract; + +#[derive(Args, Clone)] +#[command(about = "Query the minimum order size")] +pub(crate) struct MinOrderSizeCommand { + /// The contract id of the market + #[clap(long)] + pub(crate) contract_id: String, + + /// The URL to query + /// Ex. testnet.fuel.network + #[clap(long)] + pub(crate) rpc: String, +} + +impl MinOrderSizeCommand { + pub(crate) async fn run(&self) -> anyhow::Result<()> { + let wallet = setup(&self.rpc).await?; + let contract_id = validate_contract_id(&self.contract_id)?; + + // Connect to the deployed contract via the rpc + let contract = SparkMarketContract::new(contract_id, wallet).await; + + let min_order_size = contract.min_order_size().await?.value; + + println!("\nMinimum Order Size: {}", min_order_size); + + Ok(()) + } +} diff --git a/spark-cli/src/commands/info/mod.rs b/spark-cli/src/commands/info/mod.rs index e0e2886..8747715 100644 --- a/spark-cli/src/commands/info/mod.rs +++ b/spark-cli/src/commands/info/mod.rs @@ -3,6 +3,7 @@ pub(crate) mod cli; pub(crate) mod config; pub(crate) mod epoch; pub(crate) mod matcher_fee; +pub(crate) mod min_order_size; pub(crate) mod order; pub(crate) mod order_id; pub(crate) mod protocol_fee; diff --git a/spark-cli/src/main.rs b/spark-cli/src/main.rs index 391d6ca..1d87f98 100644 --- a/spark-cli/src/main.rs +++ b/spark-cli/src/main.rs @@ -36,6 +36,7 @@ async fn main() -> anyhow::Result<()> { CoreCommands::SetEpoch(args) => args.run().await, CoreCommands::SetProtocolFee(args) => args.run().await, CoreCommands::SetMatcherFee(args) => args.run().await, + CoreCommands::SetMinOrderSize(args) => args.run().await, CoreCommands::SetStoreOrderChangeInfo(args) => args.run().await, CoreCommands::Withdraw(args) => args.run().await, CoreCommands::WithdrawToMarket(args) => args.run().await, @@ -48,6 +49,7 @@ async fn main() -> anyhow::Result<()> { InfoCommands::ProtocolFeeUser(args) => args.run().await, InfoCommands::ProtocolFeeUserAmount(args) => args.run().await, InfoCommands::MatcherFee(args) => args.run().await, + InfoCommands::MinOrderSize(args) => args.run().await, InfoCommands::OrderId(args) => args.run().await, InfoCommands::Order(args) => args.run().await, InfoCommands::StoreOrderChangeInfo(args) => args.run().await,