From cc9867c51f2fa70aef13712c07a61764a9187aa7 Mon Sep 17 00:00:00 2001 From: ArjunQBTech Date: Tue, 18 Feb 2025 03:13:34 +0000 Subject: [PATCH 01/10] Refactor calculateEquivalentAmounts function to improve logic and integrate rest token input handling --- .../poolPageComponent/AddLiquidity.jsx | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/valueswap_frontend/src/components/poolPageComponent/AddLiquidity.jsx b/src/valueswap_frontend/src/components/poolPageComponent/AddLiquidity.jsx index 5e0d296..3f2b9a4 100644 --- a/src/valueswap_frontend/src/components/poolPageComponent/AddLiquidity.jsx +++ b/src/valueswap_frontend/src/components/poolPageComponent/AddLiquidity.jsx @@ -263,26 +263,22 @@ const AddLiquidity = () => { const poolName = "ExamplePool"; // Static value // Function to calculate equivalent rest token amounts - const calculateEquivalentAmounts = useCallback(async (canisterID1) => { - if (!token1 || !restTokens.length > 0) return; - - const equivalentAmounts = await Promise.all( - restTokens.map(async (token) => { - const precomputedSwap = await backendActor.pre_compute_swap({ - token1_name: token1?.ShortForm?.toLowerCase(), - token_amount: initialTokenAmount * Math.pow(10, token1?.decimals), - token2_name: token.ShortForm?.toLowerCase(), - ledger_canister_id1: Principal.fromText(canisterID1), - ledger_canister_id2: token.CanisterId, - }); - console.log(precomputedSwap) - return parseFloat(precomputedSwap[1]).toLocaleString() // TODO : Use fetched decimals + const calculateEquivalentAmounts = useCallback(() => { + if (!token1.currencyAmount || !restTokens.length > 0) return; + let onePercentPrice = token1?.currencyAmount / token1?.weight; + const equivalentAmounts = restTokens.map((token, index) => { + let totalPrice = token.weights * initialTokenAmount; + console.log("token.currencyAmount", totalPrice, token.currencyAmount ) + // console.log(totalPrice / token.marketPrice) + let newValue = totalPrice / token.currencyAmount + let newIndex = 1 + index + console.log("idex", newIndex, newValue) + return parseFloat(newValue) // TODO : Use fetched decimals }) - ); - equivalentAmounts.forEach((amount, index) => { - amount = (parseInt(amount) / Math.pow(10, 8)); // TODO : Use fetched decimals - }); + // equivalentAmounts.forEach((amount, index) => { + // amount = (parseInt(amount) / Math.pow(10, 8)); // TODO : Use fetched decimals + // }); console.log("Equivalent Amounts : ", equivalentAmounts); setRestTokenAmount(equivalentAmounts); @@ -291,12 +287,18 @@ const AddLiquidity = () => { // Call the function after fetching the pool data useEffect(() => { if (tokens.length > 0) { - const canisterID1 = tokens[0].token_name === "cketh" ? process.env.CANISTER_ID_CKETH : process.env.CANISTER_ID_CKBTC; - calculateEquivalentAmounts(canisterID1); + calculateEquivalentAmounts(); } }, [restTokens, calculateEquivalentAmounts,token1?.currencyAmount,initialTokenAmount]); - + const handleRestTokenInput = (e, index) => { + const value = parseFloat(e.target.value) || 0; + const newAmounts = restTokensAmount.map((amount, i) => { + if (i === index) return value; + return amount; + }); + setRestTokenAmount(newAmounts); + } return (
@@ -354,11 +356,11 @@ const AddLiquidity = () => { className="font-normal leading-5 text-xl sm:text-3xl py-1 inline-block outline-none bg-transparent" type="number" min="0" - value={isNaN(parseInt(restTokensAmount[index])) ? "" : parseInt(restTokensAmount[index])} + value={restTokensAmount[index]} placeholder="0" ref={(el) => (restTokensRefs.current[index] = el)} - // onChange={(e) => handleInput(e, index + 1)} - disabled={true} + onChange={(e) => handleRestTokenInput(e, index)} + disabled={optimizeEnable} />
From 645d6ae12cc26823708dd3e9f713da4b258c030c Mon Sep 17 00:00:00 2001 From: ArjunQBTech Date: Tue, 18 Feb 2025 07:48:20 +0000 Subject: [PATCH 02/10] Refactor AddLiquidity component to enhance calculation logic for total pool value and equivalent token amounts --- .../poolPageComponent/AddLiquidity.jsx | 109 +++++++++++++++--- 1 file changed, 94 insertions(+), 15 deletions(-) diff --git a/src/valueswap_frontend/src/components/poolPageComponent/AddLiquidity.jsx b/src/valueswap_frontend/src/components/poolPageComponent/AddLiquidity.jsx index 3f2b9a4..055a8de 100644 --- a/src/valueswap_frontend/src/components/poolPageComponent/AddLiquidity.jsx +++ b/src/valueswap_frontend/src/components/poolPageComponent/AddLiquidity.jsx @@ -197,24 +197,61 @@ const AddLiquidity = () => { const [restTokensAmount,setRestTokenAmount] = useState([]); const restTokensRefs = React.useRef([]); + const calculateTotal = useCallback(()=>{ + const total = restTokensAmount.reduce((acc,amount)=>{ + return acc + parseFloat(amount) + },initialTokenAmount) + console.log("Total : ", total) + },[initialTokenAmount,restTokensAmount]) + + + const calculatePoolShare = useCallback(()=>{ + return 0.001 + },[]) + + const calculatePoolLocked = useCallback(()=>{ + return 0 + },[]) + + const calculateResult = useCallback((type)=>{ + let ans; + switch(type){ + case "total": + ans = calculateTotal() + break; + case "pool_share": + ans = calculatePoolShare() + break; + case "gas_fee": + ans = swapFee.toLocaleString() + break; + case "total_pool_value_locked": + ans = calculatePoolLocked() + break; + default: + break; + } + return ans + }) + const Result = useMemo(()=>({ heading : 'Total', - headingData : '$0.00', + headingData : calculateResult("total"), data : [ { title : 'Total Pool value locked', - value : '$125,165' + value : calculateResult("total_pool_value_locked") }, { title : 'Your pool share', - value : '0.0001%', + value : calculateResult("pool_share"), }, { title : 'Gas fee', - value : swapFee.toLocaleString() + value : calculateResult("gas_fee") } ] - }), []) + }), [tokens,initialTokenAmount,restTokensAmount,swapFee]) console.log("Init : \n",token1,"\nRest :",restTokens) @@ -264,16 +301,58 @@ const AddLiquidity = () => { // Function to calculate equivalent rest token amounts const calculateEquivalentAmounts = useCallback(() => { - if (!token1.currencyAmount || !restTokens.length > 0) return; - let onePercentPrice = token1?.currencyAmount / token1?.weight; + // const handleOptimize = useCallback(() => { + // if (!Tokens[0].Amount || !Tokens[0].marketPrice || !Tokens[0].weights) { + // console.error("Missing required data for first token"); + // return; + // } + // // Calculate total pool value based on first token + // const firstTokenUSDValue = Tokens[0].Amount * Tokens[0].marketPrice; + // if (firstTokenUSDValue <= 0) { + // console.error("Invalid first token value"); + // return; + // } + // // Calculate total pool value based on first token's weight + // const totalPoolValue = firstTokenUSDValue / (Tokens[0].weights / 100); + // console.log("Total pool value:", totalPoolValue); + // // Calculate and update amounts for other tokens + // Tokens.slice(1).forEach((token, index) => { + // if (!token.marketPrice || !token.weights) { + // console.error(`Missing required data for token ${index + 1}`); + // return; + // } + // const tokenTargetUSDValue = totalPoolValue * (token.weights / 100); + // const requiredTokenAmount = tokenTargetUSDValue / token.marketPrice; + // // Round to 8 decimal places to avoid floating point issues + // const roundedAmount = Number(requiredTokenAmount.toFixed(8)); + // console.log(`Token ${index + 1} calculation:`, { + // weight: token.weights, + // targetUSD: tokenTargetUSDValue, + // marketPrice: token.marketPrice, + // requiredAmount: roundedAmount + // }); + // dispatch(UpdateAmount({ + // index: index + 1, + // Amount: roundedAmount + // })); + // }); + // }, [Tokens, dispatch]); + if (!token1?.currencyAmount || !token1?.weights){ + console.error("Missing required data for first token", token1); + return + }; + const token1USD = token1.currencyAmount * initialTokenAmount; + console.log(token1USD,"Token1USD") + if(token1USD <= 0) return; + const totalPoolValue = token1USD / (parseInt(token1.weights) / 100); + console.log("Total pool value:", totalPoolValue); const equivalentAmounts = restTokens.map((token, index) => { - let totalPrice = token.weights * initialTokenAmount; - console.log("token.currencyAmount", totalPrice, token.currencyAmount ) - // console.log(totalPrice / token.marketPrice) - let newValue = totalPrice / token.currencyAmount - let newIndex = 1 + index - console.log("idex", newIndex, newValue) - return parseFloat(newValue) // TODO : Use fetched decimals + const tokenTargetUSDValue = totalPoolValue * (parseInt(token.weights) / 100); + console.log("Token Target", tokenTargetUSDValue) + const requiredTokenAmount = tokenTargetUSDValue / token.currencyAmount; + console.log("Required Token Amount", requiredTokenAmount) + const roundedAmount = Number(requiredTokenAmount.toFixed(8)); + return roundedAmount; }) // equivalentAmounts.forEach((amount, index) => { @@ -289,7 +368,7 @@ const AddLiquidity = () => { if (tokens.length > 0) { calculateEquivalentAmounts(); } - }, [restTokens, calculateEquivalentAmounts,token1?.currencyAmount,initialTokenAmount]); + }, [restTokens, calculateEquivalentAmounts,token1?.currencyAmount,initialTokenAmount,optimizeEnable]); const handleRestTokenInput = (e, index) => { const value = parseFloat(e.target.value) || 0; From a9f3caa2e07c9632985a59a6a5975e5ab245d7ec Mon Sep 17 00:00:00 2001 From: Harshit Chauhan Date: Wed, 19 Feb 2025 11:43:35 +0530 Subject: [PATCH 03/10] updated code --- Cargo.lock | 2148 +++++++++++++++++++++++--- scripts/local_deploy/deploy_ckbtc.sh | 1 + 2 files changed, 1973 insertions(+), 176 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ee784a..5e4c6d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,30 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "anyhow" version = "1.0.95" @@ -14,12 +38,45 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "binread" version = "2.2.0" @@ -43,6 +100,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "bitflags" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" + [[package]] name = "block-buffer" version = "0.10.4" @@ -52,12 +115,24 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bumpalo" +version = "3.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" + [[package]] name = "byteorder" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "bytes" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f61dac84819c6588b558454b194026eb1f09c293b9036ae9b159e74e73ab6cf9" + [[package]] name = "candid" version = "0.10.11" @@ -78,7 +153,7 @@ dependencies = [ "serde", "serde_bytes", "stacker", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -108,6 +183,28 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "core-foundation" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "cpufeatures" version = "0.2.16" @@ -126,6 +223,21 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ba6d68e24814cb8de6bb986db8222d3a027d15872cabc0d18817bc3c0e4471" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + [[package]] name = "crypto-common" version = "0.1.6" @@ -142,6 +254,15 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + [[package]] name = "digest" version = "0.10.7" @@ -152,12 +273,59 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.94", +] + +[[package]] +name = "dyn-clone" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "feeef44e73baff3a26d371801df019877a9866a8c493d315ab00177843314f35" + [[package]] name = "either" version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "erased-serde" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c138974f9d5e7fe373eb04df7cae98833802ae4b11c24ac7039a21d5af4b26c" +dependencies = [ + "serde", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + [[package]] name = "futures" version = "0.3.31" @@ -257,11 +425,168 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + +[[package]] +name = "h2" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccae279728d634d083c00f6099cb58f01cc99c145b84b8be2f6c74618d79922e" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "half" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403" + +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +dependencies = [ + "serde", +] + +[[package]] +name = "http" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2d708df4e7140240a16cd6ab0ab65c972d7433ab77819ea693fde9c43811e2a" + +[[package]] +name = "hyper" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d191583f3da1305256f22463b9bb0471acad48a4e534a5218b9963e9c1f59b2" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-native-certs", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] [[package]] name = "ic-cdk" @@ -331,6 +656,18 @@ dependencies = [ "slotmap", ] +[[package]] +name = "ic-certification" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e64ee3d8b6e81b51f245716d3e0badb63c283c00f3c9fb5d5219afc30b5bf821" +dependencies = [ + "hex", + "serde", + "serde_bytes", + "sha2", +] + [[package]] name = "ic-stable-structures" version = "0.6.7" @@ -340,6 +677,23 @@ dependencies = [ "ic_principal", ] +[[package]] +name = "ic-transport-types" +version = "0.37.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "875dc4704780383112e8e8b5063a1b98de114321d0c7d3e7f635dcf360a57fba" +dependencies = [ + "candid", + "hex", + "ic-certification", + "leb128", + "serde", + "serde_bytes", + "serde_repr", + "sha2", + "thiserror 1.0.69", +] + [[package]] name = "ic-xrc-types" version = "1.2.0" @@ -372,82 +726,380 @@ dependencies = [ "data-encoding", "serde", "sha2", - "thiserror", + "thiserror 1.0.69", ] [[package]] -name = "lazy_static" +name = "icu_collections" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] [[package]] -name = "leb128" -version = "0.2.5" +name = "icu_locid" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] [[package]] -name = "libc" -version = "0.2.169" +name = "icu_locid_transform" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] [[package]] -name = "log" -version = "0.4.22" +name = "icu_locid_transform_data" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" [[package]] -name = "memchr" -version = "2.7.4" +name = "icu_normalizer" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] [[package]] -name = "num-bigint" -version = "0.4.6" +name = "icu_normalizer_data" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" dependencies = [ - "num-integer", - "num-traits", - "serde", + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", ] [[package]] -name = "num-integer" -version = "0.1.46" +name = "icu_properties_data" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" dependencies = [ - "num-traits", + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", ] [[package]] -name = "num-traits" -version = "0.2.19" +name = "icu_provider_macros" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ - "autocfg", + "proc-macro2", + "quote", + "syn 2.0.94", ] [[package]] -name = "once_cell" -version = "1.20.2" +name = "idna" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] [[package]] -name = "paste" -version = "1.0.15" +name = "idna_adapter" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", +] [[package]] -name = "pin-project-lite" +name = "indexmap" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" + +[[package]] +name = "itoa" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" + +[[package]] +name = "js-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "libc" +version = "0.2.169" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" + +[[package]] +name = "litemap" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "miniz_oxide" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3b1c9bd4fe1f0f8b387f6eb9eb3b4a1aa26185e5750efb9140301703f62cd1b" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.52.0", +] + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "object" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openssl-probe" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pin-project-lite" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" @@ -459,251 +1111,1283 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] -name = "pretty" -version = "0.12.3" +name = "pocket-ic" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "124a2380ca6f557adf8b02517cbfd2f564113230e14cda6f6aadd3dfe156293c" +dependencies = [ + "base64 0.13.1", + "candid", + "hex", + "ic-certification", + "ic-transport-types", + "reqwest", + "schemars", + "serde", + "serde_bytes", + "serde_cbor", + "serde_json", + "sha2", + "slog", + "strum", + "strum_macros", + "thiserror 1.0.69", + "tokio", + "tracing", + "tracing-appender", + "tracing-subscriber", + "wslpath", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "pretty" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55c4d17d994b637e2f4daf6e5dc5d660d209d5642377d675d7a1c3ab69fa579" +dependencies = [ + "arrayvec", + "typed-arena", + "unicode-width", +] + +[[package]] +name = "proc-macro2" +version = "1.0.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "200b9ff220857e53e184257720a14553b2f4aa02577d2ed9842d45d4b9654810" +dependencies = [ + "cc", +] + +[[package]] +name = "quinn" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62e96808277ec6f97351a2380e6c25114bc9e67037775464979f3037c92d05ef" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror 2.0.11", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2fe5ef3495d7d2e377ff17b1a8ce2ee2ec2a18cde8b6ad6619d65d0701c135d" +dependencies = [ + "bytes", + "getrandom", + "rand", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror 2.0.11", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e46f3055866785f6b92bc6164b76be02ca8f2eb4b002c0354b28cf4c119e5944" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.59.0", +] + +[[package]] +name = "quote" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.9", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "reqwest" +version = "0.12.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43e734407157c3c2034e0258f5e4473ddb361b1e85f95a66690d67264d7cd1da" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "mime_guess", + "once_cell", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-native-certs", + "rustls-pemfile", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tokio-socks", + "tokio-util", + "tower", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", + "webpki-roots", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e75ec5e92c4d8aede845126adc388046234541629e76029599ed35a003c7ed24" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustls" +version = "0.23.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47796c98c480fce5406ef69d1c76378375492c3b0a0de587be0c1d9feb12f395" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcff2dd52b58a8d98a70243663a0d234c4e2b79235637849d15913394a247d3" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" +dependencies = [ + "web-time", +] + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" + +[[package]] +name = "ryu" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd" + +[[package]] +name = "schannel" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "schemars" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 2.0.94", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "security-framework" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271720403f46ca04f7ba6f55d438f8bd878d6b8ca0a1046e8228c4145bcbb316" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "serde" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_bytes" +version = "0.11.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_cbor" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" +dependencies = [ + "half", + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.94", +] + +[[package]] +name = "serde_derive_internals" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.94", +] + +[[package]] +name = "serde_json" +version = "1.0.138" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_repr" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.94", +] + +[[package]] +name = "serde_tokenstream" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "797ba1d80299b264f3aac68ab5d12e5825a561749db4df7cd7c8083900c5d4e9" +dependencies = [ + "proc-macro2", + "serde", + "syn 1.0.109", +] + +[[package]] +name = "serde_tokenstream" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64060d864397305347a78851c51588fd283767e7e7589829e8121d65512340f1" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "syn 2.0.94", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "slog" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8347046d4ebd943127157b94d63abb990fcf729dc4e9978927fdf4ac3c998d06" +dependencies = [ + "erased-serde", +] + +[[package]] +name = "slotmap" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbff4acf519f630b3a3ddcfaea6c06b42174d9a44bc70c620e9ed1649d58b82a" +dependencies = [ + "version_check", +] + +[[package]] +name = "smallvec" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" + +[[package]] +name = "socket2" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c970269d99b64e60ec3bd6ad27270092a5394c4e309314b18ae3fe575695fbe8" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "stacker" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "799c883d55abdb5e98af1a7b3f23b9b6de8ecada0ecac058672d7635eb48ca7b" +dependencies = [ + "cc", + "cfg-if", + "libc", + "psm", + "windows-sys 0.59.0", +] + +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.94", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "swap" +version = "0.1.0" +dependencies = [ + "candid", + "ic-cdk 0.17.1", + "ic-cdk-macros 0.17.1", + "ic-cdk-timers", + "num-traits", + "serde", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "987bc0be1cdea8b10216bd06e2ca407d40b9543468fafd3ddfb02f36e77f71f3" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.94", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" +dependencies = [ + "thiserror-impl 2.0.11", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.94", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.94", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "time" +version = "0.3.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "022db8904dfa342efe721985167e9fcd16c29b226db4397ed752a761cfce81e8" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.43.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-macros" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.94", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6d0975eaace0cf0fcadee4e4aaa5da15b5c079146f2cffb67c113be122bf37" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-socks" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d4770b8024672c1101b3f6733eab95b18007dbe0847a8afe341fcf79e06043f" +dependencies = [ + "either", + "futures-util", + "thiserror 1.0.69", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7fcaa8d55a2bdd6b83ace262b016eca0d79ee02818c5c1bcdf0305114081078" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-appender" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3566e8ce28cc0a3fe42519fc80e6b4c943cc4c8cef275620eb8dac2d3d4e06cf" +dependencies = [ + "crossbeam-channel", + "thiserror 1.0.69", + "time", + "tracing-subscriber", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.94", +] + +[[package]] +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-serde" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "704b1aeb7be0d0a84fc9828cae51dab5970fee5088f83d1dd7ee6f6246fc6ff1" +dependencies = [ + "serde", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "serde", + "serde_json", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", + "tracing-serde", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "typed-arena" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicase" +version = "2.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" + +[[package]] +name = "unicode-ident" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" + +[[package]] +name = "unicode-width" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b55c4d17d994b637e2f4daf6e5dc5d660d209d5642377d675d7a1c3ab69fa579" -dependencies = [ - "arrayvec", - "typed-arena", - "unicode-width", -] +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] -name = "proc-macro2" -version = "1.0.92" +name = "untrusted" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" -dependencies = [ - "unicode-ident", -] +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] -name = "psm" -version = "0.1.24" +name = "url" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "200b9ff220857e53e184257720a14553b2f4aa02577d2ed9842d45d4b9654810" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" dependencies = [ - "cc", + "form_urlencoded", + "idna", + "percent-encoding", ] [[package]] -name = "quote" -version = "1.0.38" +name = "utf16_iter" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" -dependencies = [ - "proc-macro2", -] +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" [[package]] -name = "rustversion" -version = "1.0.19" +name = "utf8_iter" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] -name = "serde" -version = "1.0.217" +name = "valuable" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" -dependencies = [ - "serde_derive", -] +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" [[package]] -name = "serde_bytes" -version = "0.11.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a" +name = "valueswap_backend" +version = "0.1.0" dependencies = [ + "candid", + "futures", + "ic-cdk 0.17.1", + "ic-cdk-macros 0.17.1", + "ic-cdk-timers", + "ic-stable-structures", + "ic-xrc-types", + "lazy_static", + "log", + "num-bigint", + "num-traits", + "once_cell", + "pocket-ic", + "regex", "serde", ] [[package]] -name = "serde_derive" -version = "1.0.217" +name = "version_check" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.94", + "try-lock", ] [[package]] -name = "serde_tokenstream" -version = "0.1.7" +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "797ba1d80299b264f3aac68ab5d12e5825a561749db4df7cd7c8083900c5d4e9" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ - "proc-macro2", - "serde", - "syn 1.0.109", + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", ] [[package]] -name = "serde_tokenstream" -version = "0.2.2" +name = "wasm-bindgen-backend" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64060d864397305347a78851c51588fd283767e7e7589829e8121d65512340f1" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ + "bumpalo", + "log", "proc-macro2", "quote", - "serde", "syn 2.0.94", + "wasm-bindgen-shared", ] [[package]] -name = "sha2" -version = "0.10.8" +name = "wasm-bindgen-futures" +version = "0.4.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" dependencies = [ "cfg-if", - "cpufeatures", - "digest", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", ] [[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "slab" -version = "0.4.9" +name = "wasm-bindgen-macro" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" dependencies = [ - "autocfg", + "quote", + "wasm-bindgen-macro-support", ] [[package]] -name = "slotmap" -version = "1.0.7" +name = "wasm-bindgen-macro-support" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbff4acf519f630b3a3ddcfaea6c06b42174d9a44bc70c620e9ed1649d58b82a" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ - "version_check", + "proc-macro2", + "quote", + "syn 2.0.94", + "wasm-bindgen-backend", + "wasm-bindgen-shared", ] [[package]] -name = "stacker" -version = "0.1.17" +name = "wasm-bindgen-shared" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "799c883d55abdb5e98af1a7b3f23b9b6de8ecada0ecac058672d7635eb48ca7b" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" dependencies = [ - "cc", - "cfg-if", - "libc", - "psm", - "windows-sys", + "unicode-ident", ] [[package]] -name = "swap" -version = "0.1.0" +name = "wasm-streams" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65" dependencies = [ - "candid", - "ic-cdk 0.17.1", - "ic-cdk-macros 0.17.1", - "ic-cdk-timers", - "num-traits", - "serde", + "futures-util", + "js-sys", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", ] [[package]] -name = "syn" -version = "1.0.109" +name = "web-sys" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "js-sys", + "wasm-bindgen", ] [[package]] -name = "syn" -version = "2.0.94" +name = "web-time" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "987bc0be1cdea8b10216bd06e2ca407d40b9543468fafd3ddfb02f36e77f71f3" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "js-sys", + "wasm-bindgen", ] [[package]] -name = "thiserror" -version = "1.0.69" +name = "webpki-roots" +version = "0.26.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +checksum = "2210b291f7ea53617fbafcc4939f10914214ec15aace5ba62293a668f322c5c9" dependencies = [ - "thiserror-impl", + "rustls-pki-types", ] [[package]] -name = "thiserror-impl" -version = "1.0.69" +name = "winapi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.94", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] -name = "typed-arena" -version = "2.0.2" +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] -name = "typenum" -version = "1.17.0" +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "unicode-ident" -version = "1.0.14" +name = "windows-registry" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets", +] [[package]] -name = "unicode-width" -version = "0.1.14" +name = "windows-result" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] [[package]] -name = "valueswap_backend" +name = "windows-strings" version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" dependencies = [ - "candid", - "futures", - "ic-cdk 0.17.1", - "ic-cdk-macros 0.17.1", - "ic-cdk-timers", - "ic-stable-structures", - "ic-xrc-types", - "lazy_static", - "log", - "num-bigint", - "num-traits", - "once_cell", - "serde", + "windows-result", + "windows-targets", ] [[package]] -name = "version_check" -version = "0.9.5" +name = "windows-sys" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] [[package]] name = "windows-sys" @@ -777,3 +2461,115 @@ name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + +[[package]] +name = "wslpath" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04a2ecdf2cc4d33a6a93d71bcfbc00bb1f635cdb8029a2cc0709204a045ec7a3" + +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.94", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.94", +] + +[[package]] +name = "zerofrom" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.94", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.94", +] diff --git a/scripts/local_deploy/deploy_ckbtc.sh b/scripts/local_deploy/deploy_ckbtc.sh index c4c9678..65c828e 100755 --- a/scripts/local_deploy/deploy_ckbtc.sh +++ b/scripts/local_deploy/deploy_ckbtc.sh @@ -11,6 +11,7 @@ set -e # dfx build --all # Get the principal ID for the minter account +# minter=$(dfx ) export MINTER="b77ix-eeaaa-aaaaa-qaada-cai" echo "MINTER principal: $MINTER" From 2a9151135b25b7ec9310cd26c8e1427ce3103951 Mon Sep 17 00:00:00 2001 From: Harshit Chauhan Date: Wed, 19 Feb 2025 15:09:58 +0530 Subject: [PATCH 04/10] changed the result arguments of the swap canister for transfer --- scripts/local_deploy/LP.sh | 3 ++- scripts/local_deploy/deploy_ckbtc.sh | 5 +++-- scripts/local_deploy/deploy_cketh.sh | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/local_deploy/LP.sh b/scripts/local_deploy/LP.sh index ccd0b05..4bf5985 100755 --- a/scripts/local_deploy/LP.sh +++ b/scripts/local_deploy/LP.sh @@ -3,7 +3,8 @@ set -e # Get the principal ID for the minter account -export MINTER="b77ix-eeaaa-aaaaa-qaada-cai" +minter=$(dfx canister id valueswap_backend) +export MINTER="$minter" echo "MINTER principal: $MINTER" # Set token details diff --git a/scripts/local_deploy/deploy_ckbtc.sh b/scripts/local_deploy/deploy_ckbtc.sh index 65c828e..3e67cd5 100755 --- a/scripts/local_deploy/deploy_ckbtc.sh +++ b/scripts/local_deploy/deploy_ckbtc.sh @@ -1,5 +1,6 @@ #!/bin/bash dfx deploy swap +dfx deploy valueswap_backend ./LP.sh set -e @@ -11,8 +12,8 @@ set -e # dfx build --all # Get the principal ID for the minter account -# minter=$(dfx ) -export MINTER="b77ix-eeaaa-aaaaa-qaada-cai" +minter=$(dfx canister id valueswap_backend) +export MINTER="$minter" echo "MINTER principal: $MINTER" # Set token details diff --git a/scripts/local_deploy/deploy_cketh.sh b/scripts/local_deploy/deploy_cketh.sh index 6627b74..158f0fb 100755 --- a/scripts/local_deploy/deploy_cketh.sh +++ b/scripts/local_deploy/deploy_cketh.sh @@ -8,7 +8,8 @@ set -e # dfx build --all # Get the principal ID for the minter account -export MINTER="b77ix-eeaaa-aaaaa-qaada-cai" +minter=$(dfx canister id valueswap_backend) +export MINTER="$minter" echo "MINTER principal: $MINTER" # Set token details From d87051ee2104067028e984d6c481617ac2fab881 Mon Sep 17 00:00:00 2001 From: SarayuProdduturu04 Date: Wed, 19 Feb 2025 15:19:48 +0530 Subject: [PATCH 05/10] f64 and parse usage change to nat in lp_tokens.rs --- scripts/pool_creation_scripts/valid.sh | 24 ++- src/swap/src/lib.rs | 114 ++------------ src/swap/swap.did | 4 +- src/valueswap_backend/src/vault/lp_tokens.rs | 151 +++++++------------ src/valueswap_backend/valueswap_backend.did | 2 +- 5 files changed, 87 insertions(+), 208 deletions(-) diff --git a/scripts/pool_creation_scripts/valid.sh b/scripts/pool_creation_scripts/valid.sh index d6c5a7b..329bfc3 100755 --- a/scripts/pool_creation_scripts/valid.sh +++ b/scripts/pool_creation_scripts/valid.sh @@ -1,19 +1,27 @@ #!/bin/bash +# Load environment variables from the correct path +if [ -f "/home/ray/valueswap/.env" ]; then + export $(grep -v '^#' /home/ray/valueswap/.env | xargs) +else + echo "Error: .env file not found!" + exit 1 +fi + # Define base command for dfx canister call base_command="dfx canister call valueswap_backend create_pools" -# Ledger IDs for cketh and ckbtc -cketh_ledger_id="b77ix-eeaaa-aaaaa-qaada-cai" -ckbtc_ledger_id="bw4dl-smaaa-aaaaa-qaacq-cai" +# Fetch ledger IDs from environment variables +cketh_ledger_id=$CANISTER_ID_CKETH +ckbtc_ledger_id=$CANISTER_ID_CKBTC # Correct and valid pool data token_name="ValidToken" -balance="100 : nat" # Valid balance -weight="10 : nat" # Valid weight -value="100 : nat" # Valid value -image_url="https://example.com/valid-image.png" -swap_fee="5 : nat" # Valid swap fee +balance="100000 : nat" # Valid balance +weight="10 : nat" # Valid weight +value="100 : nat" # Valid value +image_url="img" +swap_fee="5 : nat" # Valid swap fee # Create pools using valid ledger IDs alternately for diversity echo "Creating pool with ledger ID for cketh..." diff --git a/src/swap/src/lib.rs b/src/swap/src/lib.rs index bcac574..c5ef037 100644 --- a/src/swap/src/lib.rs +++ b/src/swap/src/lib.rs @@ -2,6 +2,7 @@ use candid::{ Nat, Principal}; use ic_cdk_macros::*; use std::cell::RefCell; use std::collections::BTreeMap; +use num_traits::cast::ToPrimitive; mod api; mod utils; @@ -249,12 +250,11 @@ pub async fn lp_rollback(user: Principal, pool_data: Pool_Data) -> Result<(), St // TODO : make ledger calls with state checks for balance to prevent TOCTOU vulnerablities - #[update] async fn burn_tokens( params: Pool_Data, user: Principal, - tokens_to_transfer: f64, + tokens_to_transfer: Nat, ) -> Result<(), String> { // Validate user principal if user == Principal::anonymous() { @@ -262,57 +262,23 @@ async fn burn_tokens( return Err("Invalid user principal: Cannot be anonymous.".to_string()); } - // Validate pool data using the `validate` method + // Validate pool data if let Err(err) = params.validate() { ic_cdk::println!("Error: Invalid pool data - {:?}", err); return Err(format!("Invalid pool data: {:?}", err)); } - let tokens_to_transfer_u64 = tokens_to_transfer as u64; - let tokens_to_transfer_nat = Nat::from(tokens_to_transfer_u64); + let base_scaling = Nat::from(10u64.pow(18)); - // Debug: Log the burn operation start ic_cdk::println!( - "Debug: Starting burn_tokens for user principal {} with share ratio {}.", + "Debug: Starting burn_tokens for user principal {} with tokens to transfer {:?}.", user, tokens_to_transfer ); - - // TODO Add check for balance if its greater than canister balance - - // Get total token balance for the user - // let total_token_balance = match get_pool_balance(user.clone()) { - // Some(balance) => balance, - // None => { - // ic_cdk::println!( - // "Debug: No pool balance found for user principal {}. Defaulting to zero.", - // user - // ); - // Nat::from(0u128) - // } - // }; - - // Debug: Log total token balance - // ic_cdk::println!( - // "Debug: Total token balance for user principal {} is {}.", - // user, - // total_token_balance - // ); - - // Iterate over pool data to calculate and burn tokens for token in params.pool_data.iter() { - // Calculate token amount to burn - let mut token_amount = token.weight.clone() * tokens_to_transfer_nat.clone(); - // user_share_ratio = user_share_ratio * 10; - // let user_share_ratio_u64 = user_share_ratio as u64; - // let ratio = Nat::from(user_share_ratio_u64); - // let mut transfer_amount = token_amount.clone() * ratio; - // transfer_amount = transfer_amount / Nat::from(10u128); - - token_amount = token_amount * Nat::from(10u128); + let token_amount = (token.weight.clone() * tokens_to_transfer.clone()) / base_scaling.clone(); - // Debug: Log transfer details ic_cdk::println!( "Debug: Burning {} of token {} for user principal {}.", token_amount, @@ -320,7 +286,6 @@ async fn burn_tokens( user ); - // Perform the token transfer let transfer_result = icrc1_transfer(token.ledger_canister_id, user, token_amount).await; if let Err(e) = transfer_result { @@ -333,93 +298,41 @@ async fn burn_tokens( } } - // Debug: Log successful burn operation ic_cdk::println!("Debug: burn_tokens completed successfully for user principal {}.", user); Ok(()) } - - #[query] async fn get_burned_tokens( params: Pool_Data, user: Principal, - tokens_to_transfer: f64, + tokens_to_transfer: Nat, ) -> Result, String> { - // Validate user principal if user == Principal::anonymous() { ic_cdk::println!("Error: Invalid user principal: Cannot be anonymous."); return Err("Invalid user principal: Cannot be anonymous.".to_string()); } - // Validate pool data using the `validate` method if let Err(err) = params.validate() { ic_cdk::println!("Error: Invalid pool data - {:?}", err); return Err(format!("Invalid pool data: {:?}", err)); } - // Validate user_share_ratio - // if user_share_ratio <= 0.0 { - // ic_cdk::println!("Error: Invalid user share ratio. Must be greater than zero."); - // return Err("User share ratio must be greater than zero.".to_string()); - // } - - let tokens_transfer_u64 = tokens_to_transfer as u64; - let tokens_to_transfer_nat = Nat::from(tokens_transfer_u64); - - - // Debug: Log the start of the function - ic_cdk::println!( - "Debug: Calculating burned tokens for user {} with share ratio {}.", - user, - tokens_to_transfer_nat - ); - - - - // Get the total token balance for the user - // let total_token_balance = match get_pool_balance(user.clone()) { - // Some(balance) => { - // ic_cdk::println!( - // "Debug: Total token balance for user {} is {}.", - // user, - // balance - // ); - // balance - // } - // None => { - // ic_cdk::println!( - // "Debug: No pool balance found for user {}. Defaulting to zero.", - // user - // ); - // Nat::from(0u128) - // } - // }; + ic_cdk::println!("tokens_to_transfer (Nat): {:?}", tokens_to_transfer); let mut result: Vec = vec![]; - // Iterate over each token in pool data for token in params.pool_data.iter() { - // Calculate token amount and transfer amount - let token_amount = token.weight.clone() * tokens_to_transfer_nat.clone(); - // let transfer_amount = token_amount - // .to_string() - // .parse::() - // .unwrap_or_default() - // / tokens_to_transfer_nat; - - // Debug: Log the calculated transfer amount + let token_amount = token.weight.clone() * tokens_to_transfer.clone(); ic_cdk::println!( - "Debug: Calculated transfer amount for token {}: {}.", + "Debug: Calculated transfer amount for token {}: {:?}.", token.token_name, - tokens_to_transfer_nat + token_amount ); - - result.push(token_amount.clone()); + result.push(token_amount); } - // Debug: Log the result ic_cdk::println!( "Debug: Burned token calculation completed for user {}. Result: {:?}", user, @@ -431,6 +344,9 @@ async fn get_burned_tokens( + + + #[update] async fn swap(user_principal: Principal, params: SwapParams, amount: Nat) -> Result<(), String> { // Validate user principal diff --git a/src/swap/swap.did b/src/swap/swap.did index 468d5f7..5dd1e78 100644 --- a/src/swap/swap.did +++ b/src/swap/swap.did @@ -19,8 +19,8 @@ type SwapParams = record { }; service : { add_liquidity_to_pool : (principal, Pool_Data) -> (Result); - burn_tokens : (Pool_Data, principal, float64) -> (Result); - get_burned_tokens : (Pool_Data, principal, float64) -> (Result_1) query; + burn_tokens : (Pool_Data, principal, nat) -> (Result); + get_burned_tokens : (Pool_Data, principal, nat) -> (Result_1) query; get_decimals : (principal) -> (Result_2); get_pool_balance : (principal) -> (opt nat) query; icrc1_transfer : (principal, principal, nat) -> (Result_2); diff --git a/src/valueswap_backend/src/vault/lp_tokens.rs b/src/valueswap_backend/src/vault/lp_tokens.rs index 0f300ea..3b0ba38 100644 --- a/src/valueswap_backend/src/vault/lp_tokens.rs +++ b/src/valueswap_backend/src/vault/lp_tokens.rs @@ -8,8 +8,8 @@ use crate::api::deposit::deposit_tokens; use crate::api::transfer::icrc1_transfer; use crate::constants::asset_address::LP_LEDGER_ADDRESS; use crate::utils::types::*; -use crate::with_state; use crate::vault::apy::*; +use crate::with_state; thread_local! { static TOTAL_LP_SUPPLY : RefCell = RefCell::new(Nat::from(0u128)); @@ -38,7 +38,7 @@ pub fn increase_pool_lp_tokens(params: Pool_Data) -> Result<(), CustomError> { return Err(CustomError::InvalidInput( "Pool value and balance must be greater than zero.".to_string(), )); - } + } Ok(acc + (value * balance)) }) .unwrap_or_else(|err| { @@ -62,11 +62,7 @@ pub fn increase_pool_lp_tokens(params: Pool_Data) -> Result<(), CustomError> { .entry(key.clone()) .and_modify(|existing_supply| { *existing_supply += pool_supply.clone() / Nat::from(1000u128); - ic_cdk::println!( - "Updated LP share for pool {}: {}", - key, - *existing_supply - ); + ic_cdk::println!("Updated LP share for pool {}: {}", key, *existing_supply); }) .or_insert_with(|| { let new_supply = pool_supply.clone() / Nat::from(1000u128); @@ -117,7 +113,6 @@ pub fn increase_pool_lp_tokens(params: Pool_Data) -> Result<(), CustomError> { Ok(()) } - #[update] pub fn users_pool(params: Pool_Data) -> Result<(), CustomError> { // Validate input params @@ -151,11 +146,12 @@ pub fn users_pool(params: Pool_Data) -> Result<(), CustomError> { Ok(()) } - #[query] fn get_users_pool(user: Principal) -> Result>, CustomError> { if user == Principal::anonymous() { - return Err(CustomError::InvalidInput("Anonymous principal is not allowed.".to_string())); + return Err(CustomError::InvalidInput( + "Anonymous principal is not allowed.".to_string(), + )); } USERS_POOL.with(|pool| { @@ -204,7 +200,6 @@ fn total_lp_tokens() { }); } - #[query] fn get_total_lp() -> Nat { TOTAL_LP_SUPPLY.with(|total_lp| { @@ -218,7 +213,6 @@ fn get_total_lp() -> Nat { }) } - // Query to get LP tokens for a specific pool #[query] pub fn get_pool_lp_tokens(pool_name: String) -> Nat { @@ -240,7 +234,6 @@ pub fn get_pool_lp_tokens(pool_name: String) -> Nat { }) } - #[query] pub fn get_user_pools_with_lp(user: Principal) -> Option> { if user == Principal::anonymous() { @@ -263,12 +256,13 @@ pub fn get_user_pools_with_lp(user: Principal) -> Option> }) } - #[update] pub async fn users_lp_share(params: Pool_Data) -> Result<(), String> { let user = ic_cdk::caller(); - params.validate().map_err(|e| format!("Invalid pool data: {:?}", e))?; + params + .validate() + .map_err(|e| format!("Invalid pool data: {:?}", e))?; let mut users_contribution: Nat = Nat::from(1u128); @@ -321,7 +315,11 @@ pub async fn users_lp_share(params: Pool_Data) -> Result<(), String> { ); if attempts == max_retries { - log::error!("Transfer failed after {} attempts for user: {}", attempts, user); + log::error!( + "Transfer failed after {} attempts for user: {}", + attempts, + user + ); } } } @@ -333,9 +331,6 @@ pub async fn users_lp_share(params: Pool_Data) -> Result<(), String> { Ok(()) } - - - #[query] fn get_users_lp(user_id: Principal) -> Option { if user_id == Principal::anonymous() { @@ -361,7 +356,9 @@ fn get_users_lp(user_id: Principal) -> Option { // TODO Send token amount to pool canister instead of user_share ratio #[update] async fn burn_lp_tokens(params: Pool_Data, pool_name: String, amount: Nat) -> Result<(), String> { - params.validate().map_err(|e| format!("Invalid pool data: {:?}", e))?; + params + .validate() + .map_err(|e| format!("Invalid pool data: {:?}", e))?; let user = ic_cdk::caller(); @@ -384,57 +381,40 @@ async fn burn_lp_tokens(params: Pool_Data, pool_name: String, amount: Nat) -> Re let canister_id = with_state(|pool| { let pool_borrowed = &mut pool.token_pools; - pool_borrowed.get(&pool_name).map(|user_principal| user_principal.principal) - }); - - let canister_id = match canister_id { - Some(id) => id, - None => { - ic_cdk::println!("No canister ID found for pool: {}", pool_name); - return Err("No canister ID found for the pool.".to_string()); - } - }; + pool_borrowed + .get(&pool_name) + .map(|user_principal| user_principal.principal) + }) + .ok_or_else(|| format!("No canister ID found for the pool: {}", pool_name))?; let pool_total_lp = POOL_LP_SHARE.with(|share| { let borrowed_share = share.borrow(); - borrowed_share.get(&pool_name).cloned().unwrap_or(Nat::from(0u128)) + borrowed_share + .get(&pool_name) + .cloned() + .unwrap_or(Nat::from(0u128)) }); if pool_total_lp <= Nat::from(0u128) { return Err(format!("No LP tokens in the pool: {}", pool_name)); } - let user_share_ratio = match amount.clone().to_string().parse::() { - Ok(amount_f64) => match pool_total_lp.to_string().parse::() { - Ok(total_f64) => amount_f64 / total_f64, - Err(_) => return Err("Failed to parse pool_total_lp to f64.".to_string()), - }, - Err(_) => return Err("Failed to parse amount to f64.".to_string()), - }; + let base_scaling = Nat::from(10u128.pow(18)); + let user_share_ratio = (amount.clone() * base_scaling.clone()) / pool_total_lp.clone(); let pool_value: Nat = POOL_LP_SHARE.with(|pool_lp| { let borrowed_pool_lp = pool_lp.borrow(); - if let Some(lp_value) = borrowed_pool_lp.get(&pool_name) { - lp_value.clone() * Nat::from(1000u128) - } else { - Nat::from(0u128) - } + borrowed_pool_lp + .get(&pool_name) + .map(|lp_value| lp_value.clone() * Nat::from(1000u128)) + .unwrap_or(Nat::from(0u128)) }); if pool_value <= Nat::from(0u128) { return Err(format!("No tokens in the pool: {}", pool_name)); } - let pool_value_f64 = match pool_value.to_string().parse::() { - Ok(value) => value, - Err(_) => return Err("Failed to parse pool_value to f64.".to_string()), - }; - - let mut tokens_to_transfer = pool_value_f64 * user_share_ratio; - - let apy_earned = get_users_pool_apy(pool_name.clone() , user.clone()); - - tokens_to_transfer += apy_earned.to_string().parse::().unwrap_or_default(); + let tokens_to_transfer = (pool_value * user_share_ratio.clone()) / base_scaling; let result: Result<(), String> = call( canister_id, @@ -448,97 +428,75 @@ async fn burn_lp_tokens(params: Pool_Data, pool_name: String, amount: Nat) -> Re return Err(e); } - decrease_users_apy(user.clone() , pool_name.clone()); decrease_pool_lp(pool_name.clone(), amount.clone()); decrease_user_pool_lp(user, pool_name, amount.clone()); decrease_total_lp(amount); ic_cdk::println!("Successfully burned LP tokens for user: {}", user); - Ok(()) } - - -// TODO Send token amount to pool canister instead of user_share ratio #[update] async fn get_user_share_ratio( params: Pool_Data, pool_name: String, amount: Nat, -) -> Result, String> { +) -> Result, String> { let user = ic_cdk::caller(); + ic_cdk::println!("Input Params: {:?}, Pool Name: {}, Amount: {}", params, pool_name, amount); - // Validate input: pool_name if pool_name.trim().is_empty() { return Err("Pool name cannot be empty.".to_string()); } - // Validate input: amount if amount <= Nat::from(0u128) { return Err("Amount must be greater than zero.".to_string()); } - // Validate params params.validate().map_err(|e| format!("Invalid pool data: {:?}", e))?; - // Retrieve the total LP share for the pool let pool_total_lp = POOL_LP_SHARE.with(|share| { let borrowed_share = share.borrow(); - borrowed_share - .get(&pool_name) - .cloned() - .unwrap_or(Nat::from(0u128)) + let val = borrowed_share.get(&pool_name).cloned(); + ic_cdk::println!("pool_total_lp: {:?}", val); + val.unwrap_or(Nat::from(0u128)) }); if pool_total_lp <= Nat::from(0u128) { return Err(format!("No LP tokens found for the pool: {}", pool_name)); } - // Retrieve the canister ID for the pool let canister_id = with_state(|pool| { let pool_borrowed = &mut pool.token_pools; - pool_borrowed - .get(&pool_name) - .map(|user_principal| user_principal.principal) + let val = pool_borrowed.get(&pool_name).map(|user_principal| user_principal.principal); + ic_cdk::println!("canister_id: {:?}", val); + val }); let canister_id = match canister_id { Some(id) => id, None => return Err(format!("No canister ID found for the pool: {}", pool_name)), }; + //nat usage + let base_scaling = Nat::from(10u64.pow(18)); + let user_share_ratio = (amount.clone() * base_scaling.clone()) / pool_total_lp.clone(); + ic_cdk::println!("user_share_ratio: {:?}", user_share_ratio); - // Retrieve the pool value - let pool_value: Nat = POOL_LP_SHARE.with(|pool_lp| { + let pool_value = POOL_LP_SHARE.with(|pool_lp| { let borrowed_pool_lp = pool_lp.borrow(); - borrowed_pool_lp - .get(&pool_name) - .map(|lp_value| lp_value.clone() * Nat::from(1000u128)) - .unwrap_or(Nat::from(0u128)) + let val = borrowed_pool_lp.get(&pool_name).map(|lp_value| lp_value.clone() * base_scaling.clone()); + ic_cdk::println!("pool_value: {:?}", val); + val.unwrap_or(Nat::from(0u128)) }); if pool_value <= Nat::from(0u128) { return Err(format!("No tokens in the pool: {}", pool_name)); } - // Calculate the user share ratio - let user_share_ratio = match amount.clone().to_string().parse::() { - Ok(amount_f64) => match pool_total_lp.to_string().parse::() { - Ok(total_f64) => amount_f64 / total_f64, - Err(_) => return Err("Failed to parse pool_total_lp to f64.".to_string()), - }, - Err(_) => return Err("Failed to parse amount to f64.".to_string()), - }; - - let pool_value_f64 = match pool_value.to_string().parse::() { - Ok(value) => value, - Err(_) => return Err("Failed to parse pool_value to f64.".to_string()), - }; - - let tokens_to_transfer = pool_value_f64 * user_share_ratio; + let tokens_to_transfer = (pool_value * user_share_ratio.clone()) / base_scaling; + ic_cdk::println!("tokens_to_transfer: {:?}", tokens_to_transfer); - // Call the `get_burned_tokens` function on the canister - let result: Result<(Vec,), String> = call( + let result: Result<(Vec,), String> = call( canister_id, "get_burned_tokens", (params, user, tokens_to_transfer), @@ -546,7 +504,7 @@ async fn get_user_share_ratio( .await .map_err(|e| format!("Failed to get token data: {:?}", e)); - // Return the result from the call + ic_cdk::println!("get_burned_tokens result: {:?}", result); result.map(|(burned_tokens_vec,)| burned_tokens_vec) } @@ -586,7 +544,6 @@ fn decrease_pool_lp(pool_name: String, amount: Nat) { }); } - #[update] fn decrease_user_pool_lp(user: Principal, pool_name: String, amount: Nat) { if pool_name.trim().is_empty() { @@ -632,7 +589,6 @@ fn decrease_user_pool_lp(user: Principal, pool_name: String, amount: Nat) { }); } - #[update] fn decrease_total_lp(lp: Nat) { // Validation: LP amount must be greater than zero @@ -650,4 +606,3 @@ fn decrease_total_lp(lp: Nat) { } }); } - diff --git a/src/valueswap_backend/valueswap_backend.did b/src/valueswap_backend/valueswap_backend.did index 7df45ef..b219005 100644 --- a/src/valueswap_backend/valueswap_backend.did +++ b/src/valueswap_backend/valueswap_backend.did @@ -51,7 +51,7 @@ type RejectionCode = variant { }; type Result = variant { Ok; Err : text }; type Result_1 = variant { Ok; Err : CustomError }; -type Result_10 = variant { Ok : vec float64; Err : text }; +type Result_10 = variant { Ok : vec nat; Err : text }; type Result_11 = variant { Ok : opt vec text; Err : CustomError }; type Result_12 = variant { Ok; Err : InstallError }; type Result_13 = variant { Ok : vec text; Err : text }; From 2cd4d8c95edf5202ec9bd51f40d01bfa03b243aa Mon Sep 17 00:00:00 2001 From: Rudransh Singh Tomar Date: Thu, 20 Feb 2025 11:41:58 +0530 Subject: [PATCH 06/10] Add get_user_share_ratio function to swap canister - Implemented new function to calculate user's share ratio in a liquidity pool - Handles cross-canister call to get burned tokens - Includes detailed logging for debugging and calculation steps - Uses Nat-based calculations for precise token share computation --- src/swap/src/lib.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/swap/src/lib.rs b/src/swap/src/lib.rs index c5ef037..73a4fd8 100644 --- a/src/swap/src/lib.rs +++ b/src/swap/src/lib.rs @@ -462,6 +462,48 @@ async fn swap(user_principal: Principal, params: SwapParams, amount: Nat) -> Res Ok(()) } +#[update] +async fn get_user_share_ratio( + params: Pool_Data, + pool_name: String, + amount: Nat, +) -> Result, String> { + let user = ic_cdk::caller(); + ic_cdk::println!("Input Params: {:?}, Pool Name: {}, Amount: {}", params, pool_name, amount); + + // ... existing validation code ... + + let base_scaling = Nat::from(10u64.pow(18)); + let user_share_ratio = (amount.clone() * base_scaling.clone()) / pool_total_lp.clone(); + ic_cdk::println!("user_share_ratio: {:?}", user_share_ratio); + + let pool_value = POOL_LP_SHARE.with(|pool_lp| { + let borrowed_pool_lp = pool_lp.borrow(); + let val = borrowed_pool_lp.get(&pool_name).map(|lp_value| lp_value.clone() * base_scaling.clone()); + ic_cdk::println!("pool_value: {:?}", val); + val.unwrap_or(Nat::from(0u128)) + }); + let tokens_to_transfer = (pool_value * user_share_ratio.clone()) / base_scaling; + ic_cdk::println!("tokens_to_transfer: {:?}", tokens_to_transfer); + + // Fix: Properly handle the Result type from the cross-canister call + let result: Result, String>, String> = call( + canister_id, + "get_burned_tokens", + (params, user, tokens_to_transfer), + ) + .await + .map_err(|e| format!("Failed to make canister call: {:?}", e)); + + // Properly handle nested Results + match result { + Ok(inner_result) => { + ic_cdk::println!("get_burned_tokens result: {:?}", inner_result); + inner_result // This is already a Result, String> + } + Err(e) => Err(e) + } +} export_candid!(); From 119e65ddd869d328e74fef6d21557dc07e98c355 Mon Sep 17 00:00:00 2001 From: SarayuProdduturu04 Date: Mon, 24 Feb 2025 17:30:06 +0530 Subject: [PATCH 07/10] Updated Functions logic for transition to nat from f64 --- src/swap/src/lib.rs | 45 +++--- src/valueswap_backend/src/vault/lp_tokens.rs | 153 ++++++++++--------- 2 files changed, 103 insertions(+), 95 deletions(-) diff --git a/src/swap/src/lib.rs b/src/swap/src/lib.rs index c5ef037..2f2e168 100644 --- a/src/swap/src/lib.rs +++ b/src/swap/src/lib.rs @@ -256,50 +256,47 @@ async fn burn_tokens( user: Principal, tokens_to_transfer: Nat, ) -> Result<(), String> { - // Validate user principal if user == Principal::anonymous() { - ic_cdk::println!("Error: Invalid user principal: Cannot be anonymous."); return Err("Invalid user principal: Cannot be anonymous.".to_string()); } - // Validate pool data if let Err(err) = params.validate() { - ic_cdk::println!("Error: Invalid pool data - {:?}", err); return Err(format!("Invalid pool data: {:?}", err)); } - let base_scaling = Nat::from(10u64.pow(18)); + // Define scaling factors + let base_scaling = Nat::from(10u128.pow(18)); // 10^18 for base calculations + let weight_scaling = Nat::from(100u128); // Scale for percentages ic_cdk::println!( - "Debug: Starting burn_tokens for user principal {} with tokens to transfer {:?}.", - user, + "Debug: Starting burn_tokens with tokens_to_transfer: {:?}", tokens_to_transfer ); for token in params.pool_data.iter() { - let token_amount = (token.weight.clone() * tokens_to_transfer.clone()) / base_scaling.clone(); + // Calculate token amount with proper scaling + // (weight * tokens_to_transfer * weight_scaling) / (base_scaling * 100) + let token_amount = (token.weight.clone() * tokens_to_transfer.clone() * weight_scaling.clone()) + / (base_scaling.clone() * Nat::from(100u128)); ic_cdk::println!( - "Debug: Burning {} of token {} for user principal {}.", - token_amount, + "Debug: Calculated token_amount for {}: {:?}", token.token_name, - user + token_amount ); let transfer_result = icrc1_transfer(token.ledger_canister_id, user, token_amount).await; if let Err(e) = transfer_result { let error_message = format!( - "Error: Token transfer failed for token {} for user {}: {}", + "Token transfer failed for {} for user {}: {}", token.token_name, user, e ); - ic_cdk::println!("{}", error_message); + ic_cdk::println!("Error: {}", error_message); return Err(error_message); } } - ic_cdk::println!("Debug: burn_tokens completed successfully for user principal {}.", user); - Ok(()) } @@ -319,17 +316,25 @@ async fn get_burned_tokens( return Err(format!("Invalid pool data: {:?}", err)); } + let base_scaling = Nat::from(10u128.pow(18)); // 10^18 for base calculations + let weight_scaling = Nat::from(100u128); // Scale for percentages + ic_cdk::println!("tokens_to_transfer (Nat): {:?}", tokens_to_transfer); - let mut result: Vec = vec![]; + let mut result: Vec = Vec::new(); for token in params.pool_data.iter() { - let token_amount = token.weight.clone() * tokens_to_transfer.clone(); + // Calculate token amount with proper scaling + // (weight * tokens_to_transfer * weight_scaling) / (base_scaling * 100) + let token_amount = (token.weight.clone() * tokens_to_transfer.clone() * weight_scaling.clone()) + / (base_scaling.clone() * Nat::from(100u128)); + ic_cdk::println!( - "Debug: Calculated transfer amount for token {}: {:?}.", + "Debug: Calculated amount for token {}: {:?}", token.token_name, token_amount ); + result.push(token_amount); } @@ -343,10 +348,6 @@ async fn get_burned_tokens( } - - - - #[update] async fn swap(user_principal: Principal, params: SwapParams, amount: Nat) -> Result<(), String> { // Validate user principal diff --git a/src/valueswap_backend/src/vault/lp_tokens.rs b/src/valueswap_backend/src/vault/lp_tokens.rs index 3b0ba38..c7bc26f 100644 --- a/src/valueswap_backend/src/vault/lp_tokens.rs +++ b/src/valueswap_backend/src/vault/lp_tokens.rs @@ -360,81 +360,88 @@ async fn burn_lp_tokens(params: Pool_Data, pool_name: String, amount: Nat) -> Re .validate() .map_err(|e| format!("Invalid pool data: {:?}", e))?; - let user = ic_cdk::caller(); - - if pool_name.trim().is_empty() { - return Err("Pool name cannot be empty.".to_string()); - } - - if amount <= Nat::from(0u128) { - return Err("Amount to burn must be greater than zero.".to_string()); - } - - let ledger_canister_id = - Principal::from_text(LP_LEDGER_ADDRESS).expect("Invalid ledger canister ID"); - let target_canister_id = ic_cdk::id(); - - let result = deposit_tokens(amount.clone(), ledger_canister_id, target_canister_id).await; - if let Err(e) = result { - return Err(format!("Transfer failed: {}", e)); - } - - let canister_id = with_state(|pool| { - let pool_borrowed = &mut pool.token_pools; - pool_borrowed - .get(&pool_name) - .map(|user_principal| user_principal.principal) - }) - .ok_or_else(|| format!("No canister ID found for the pool: {}", pool_name))?; - - let pool_total_lp = POOL_LP_SHARE.with(|share| { - let borrowed_share = share.borrow(); - borrowed_share - .get(&pool_name) - .cloned() - .unwrap_or(Nat::from(0u128)) - }); - - if pool_total_lp <= Nat::from(0u128) { - return Err(format!("No LP tokens in the pool: {}", pool_name)); - } - - let base_scaling = Nat::from(10u128.pow(18)); - let user_share_ratio = (amount.clone() * base_scaling.clone()) / pool_total_lp.clone(); - - let pool_value: Nat = POOL_LP_SHARE.with(|pool_lp| { - let borrowed_pool_lp = pool_lp.borrow(); - borrowed_pool_lp - .get(&pool_name) - .map(|lp_value| lp_value.clone() * Nat::from(1000u128)) - .unwrap_or(Nat::from(0u128)) - }); - - if pool_value <= Nat::from(0u128) { - return Err(format!("No tokens in the pool: {}", pool_name)); - } - - let tokens_to_transfer = (pool_value * user_share_ratio.clone()) / base_scaling; - - let result: Result<(), String> = call( - canister_id, - "burn_tokens", - (params, user, tokens_to_transfer), - ) - .await - .map_err(|e| format!("Failed to perform swap: {:?}", e)); - - if let Err(e) = result { - return Err(e); + let base_scaling = Nat::from(10u128.pow(18)); // 10^18 for base calculations + let weight_scaling = Nat::from(100u128); // Scale for percentages + + let user = ic_cdk::caller(); + + if pool_name.trim().is_empty() { + return Err("Pool name cannot be empty.".to_string()); + } + + if amount <= Nat::from(0u128) { + return Err("Amount to burn must be greater than zero.".to_string()); + } + + let ledger_canister_id = Principal::from_text(LP_LEDGER_ADDRESS) + .map_err(|_| "Invalid ledger canister ID".to_string())?; + let target_canister_id = ic_cdk::id(); + + // Transfer tokens to the canister + let result = deposit_tokens(amount.clone(), ledger_canister_id, target_canister_id).await; + if let Err(e) = result { + return Err(format!("Transfer failed: {}", e)); + } + + let canister_id = with_state(|pool| { + let pool_borrowed = &mut pool.token_pools; + pool_borrowed + .get(&pool_name) + .map(|user_principal| user_principal.principal) + }) + .ok_or_else(|| format!("No canister ID found for the pool: {}", pool_name))?; + + let pool_total_lp = POOL_LP_SHARE.with(|share| { + let borrowed_share = share.borrow(); + borrowed_share + .get(&pool_name) + .cloned() + .unwrap_or(Nat::from(0u128)) + }); + + if pool_total_lp <= Nat::from(0u128) { + return Err(format!("No LP tokens in the pool: {}", pool_name)); + } + + // Calculate user share ratio with proper scaling + let user_share_ratio = (amount.clone() * base_scaling.clone()) / pool_total_lp.clone(); + + let pool_value: Nat = POOL_LP_SHARE.with(|pool_lp| { + let borrowed_pool_lp = pool_lp.borrow(); + borrowed_pool_lp + .get(&pool_name) + .map(|lp_value| lp_value.clone() * weight_scaling.clone()) + .unwrap_or(Nat::from(0u128)) + }); + + if pool_value <= Nat::from(0u128) { + return Err(format!("No tokens in the pool: {}", pool_name)); + } + + // Calculate tokens to transfer with proper scaling + let tokens_to_transfer = (pool_value * user_share_ratio) / base_scaling.clone(); + + let result: Result<(), String> = call( + canister_id, + "burn_tokens", + (params, user, tokens_to_transfer), + ) + .await + .map_err(|e| format!("Failed to perform swap: {:?}", e)); + + if let Err(e) = result { + return Err(e); + } + + // Update pool state + decrease_pool_lp(pool_name.clone(), amount.clone()); + decrease_user_pool_lp(user, pool_name, amount.clone()); + decrease_total_lp(amount); + + ic_cdk::println!("Successfully burned LP tokens for user: {}", user); + Ok(()) } - decrease_pool_lp(pool_name.clone(), amount.clone()); - decrease_user_pool_lp(user, pool_name, amount.clone()); - decrease_total_lp(amount); - - ic_cdk::println!("Successfully burned LP tokens for user: {}", user); - Ok(()) -} #[update] async fn get_user_share_ratio( From 8d5b9ddafc13d161a7bb32893d60380c448fe92c Mon Sep 17 00:00:00 2001 From: Harshit Chauhan Date: Thu, 20 Feb 2025 11:30:54 +0530 Subject: [PATCH 08/10] latest code --- canister_ids.json | 9 ++ scripts/helper_scripts/approval.sh | 30 ++-- scripts/helper_scripts/sendBalance.sh | 5 +- scripts/helper_scripts/swap_test.sh | 80 +++++----- scripts/helper_scripts/swap_test2.sh | 6 +- src/swap/src/api/transfer.rs | 141 +++++++++++++++--- .../src/vault/pool_factory.rs | 2 +- src/valueswap_frontend/src/Modals/Swap.jsx | 2 +- 8 files changed, 190 insertions(+), 85 deletions(-) diff --git a/canister_ids.json b/canister_ids.json index 203983d..9da1f1a 100644 --- a/canister_ids.json +++ b/canister_ids.json @@ -2,6 +2,12 @@ "LP_ledger_canister": { "ic": "yyins-zqaaa-aaaac-ak2ia-cai" }, + "ckbtc": { + "ic": "wpwuj-jyaaa-aaaac-albla-cai" + }, + "cketh": { + "ic": "wixs5-eaaaa-aaaac-alblq-cai" + }, "swap": { "ic": "i5hhh-rqaaa-aaaac-aadba-cai" }, @@ -10,5 +16,8 @@ }, "valueswap_frontend": { "ic": "ibd5w-gqaaa-aaaac-aadda-cai" + }, + "xrc": { + "ic": "xfzwt-liaaa-aaaac-albma-cai" } } \ No newline at end of file diff --git a/scripts/helper_scripts/approval.sh b/scripts/helper_scripts/approval.sh index b899703..9ed75a9 100755 --- a/scripts/helper_scripts/approval.sh +++ b/scripts/helper_scripts/approval.sh @@ -1,19 +1,19 @@ dfx identity use Harshit -dfx canister call cketh icrc2_approve '( - record { - fee = null; - memo = null; - from_subaccount = null; - created_at_time = null; - amount = 5_000_000_000 : nat; - expected_allowance = null; - expires_at = null; - spender = record { - owner = principal "be2us-64aaa-aaaaa-qaabq-cai"; - subaccount = null; - }; - }, -)' +# dfx canister call cketh icrc2_approve '( +# record { +# fee = null; +# memo = null; +# from_subaccount = null; +# created_at_time = null; +# amount = 5_000_000_000 : nat; +# expected_allowance = null; +# expires_at = null; +# spender = record { +# owner = principal "be2us-64aaa-aaaaa-qaabq-cai"; +# subaccount = null; +# }; +# }, +# )' dfx canister call ckbtc icrc2_approve '( record { fee = null; diff --git a/scripts/helper_scripts/sendBalance.sh b/scripts/helper_scripts/sendBalance.sh index cfed869..81a529b 100755 --- a/scripts/helper_scripts/sendBalance.sh +++ b/scripts/helper_scripts/sendBalance.sh @@ -4,4 +4,7 @@ dfx canister call cketh icrc1_transfer ' (record {to=record {owner = principal " dfx canister call ckbtc icrc1_transfer ' (record {to=record {owner = principal "um2uc-3w7jg-5lycg-pmjio-is7ms-jjzwo-kvwfa-xdeus-ur2tx-4sbzd-cae"; subaccount=null}; fee=null; memo=null; from_subaccount=null; created_at_time=null; amount=5000000000})' -./approval.sh +# ./approval.sh + +# minter=$(dfx canister id swap) +# echo "$minter" \ No newline at end of file diff --git a/scripts/helper_scripts/swap_test.sh b/scripts/helper_scripts/swap_test.sh index 3d004e8..fbb8590 100755 --- a/scripts/helper_scripts/swap_test.sh +++ b/scripts/helper_scripts/swap_test.sh @@ -1,57 +1,51 @@ -# dfx canister call valueswap_backend out_given_in '( -# 500000000 : nat, -# 30 : nat, -# 141000000000000000000 : nat, -# 70 : nat, -# 100000000 : nat -# )' - -# INPUT_TOKEN=100000000; -# IDENTITY=$(dfx identity get-principal) -# VALUESWAP_BACKEND=$(dfx canister id valueswap_backend) - -dfx canister call valueswap_backend pre_compute_swap '( - record { - token1_name = "ckbtc"; - token_amount = 100000000 : nat; - token2_name = "cketh"; - ledger_canister_id1 = principal "br5f7-7uaaa-aaaaa-qaaca-cai"; - ledger_canister_id2 = principal "bw4dl-smaaa-aaaaa-qaacq-cai"; - fee = 30 - } -)' - -# echo "Approving valueswap_backend to transfer 1000000000 tokens on behalf of DevJourney" - -# APPROVE=$( -# dfx --identity Harshit canister call ckbtc icrc2_approve "(record{ amount = 1000000000 ; spender = record { owner = principal \"$VALUESWAP_BACKEND\"}})" -# ) -# echo "Approve result: $APPROVE" - -# echo "Checking allowance" -# ALLOWANCE=$( -# dfx --identity Harshit canister call ckbtc icrc2_allowance "(record { account = record {owner = principal \"$IDENTITY\"}; spender = record { owner = principal \"$VALUESWAP_BACKEND\"}})" -# ) -# echo "Allowance result : $ALLOWANCE" - -# # dfx canister call ckbtc icrc1_balance_of "(record {owner=principal\"hyhkx-53cuq-lmkqq-yhjmt-eve7b-j5pyf-3evrj-tncch-ilmtl-nrcee-sqe\"; subaccount=null; memo=null; from_subaccount=null; created_at_time=null;})" +# dfx identity use DevJourney -# dfx canister call ckbtc icrc1_transfer ' (record {to=record {owner = principal "um2uc-3w7jg-5lycg-pmjio-is7ms-jjzwo-kvwfa-xdeus-ur2tx-4sbzd-cae"; subaccount=null}; fee=null; memo=null; from_subaccount=null; created_at_time=null; amount=100000000})' +# dfx canister call ckbtc icrc1_transfer ' (record {to=record {owner = principal "um2uc-3w7jg-5lycg-pmjio-is7ms-jjzwo-kvwfa-xdeus-ur2tx-4sbzd-cae"; subaccount=null}; fee=null; memo=null; from_subaccount=null; created_at_time=null; amount=5000000000})' # dfx identity use Harshit -# dfx canister call valueswap_backend compute_swap '( +IDENTITY=$(dfx identity get-principal) +VALUESWAP_BACKEND=$(dfx canister id valueswap_backend) + +# dfx canister call valueswap_backend pre_compute_swap '( # record { # token1_name = "ckbtc"; # token_amount = 100000000 : nat; # token2_name = "cketh"; -# ledger_canister_id1 = principal "br5f7-7uaaa-aaaaa-qaaca-cai"; -# ledger_canister_id2 = principal "bw4dl-smaaa-aaaaa-qaacq-cai"; +# ledger_canister_id1 = principal "b77ix-eeaaa-aaaaa-qaada-cai"; +# ledger_canister_id2 = principal "by6od-j4aaa-aaaaa-qaadq-cai"; +# fee = 30; # } # )' -# dfx canister call ckbtc icrc1_balance_of "(record {owner=principal\"um2uc-3w7jg-5lycg-pmjio-is7ms-jjzwo-kvwfa-xdeus-ur2tx-4sbzd-cae\"; subaccount=null; memo=null; from_subaccount=null; created_at_time=null;})" -# dfx canister call cketh icrc1_balance_of "(record {owner=principal\"um2uc-3w7jg-5lycg-pmjio-is7ms-jjzwo-kvwfa-xdeus-ur2tx-4sbzd-cae\"; subaccount=null; memo=null; from_subaccount=null; created_at_time=null;})" +# echo "Approving valueswap_backend to transfer 1000000000 tokens on behalf of DevJourney" +dfx identity use Harshit + +APPROVE=$( + dfx --identity Harshit canister call ckbtc icrc2_approve "(record{ amount = 1000000000 ; spender = record { owner = principal \"$VALUESWAP_BACKEND\"}})" +) +echo "Approve result: $APPROVE" + +echo "Checking allowance" +ALLOWANCE=$( + dfx --identity Harshit canister call ckbtc icrc2_allowance "(record { account = record {owner = principal \"$IDENTITY\"}; spender = record { owner = principal \"$VALUESWAP_BACKEND\"}})" +) +echo "Allowance result : $ALLOWANCE" + + +dfx canister call valueswap_backend compute_swap '( + record { + token1_name = "ckbtc"; + token_amount = 100000000 : nat; + token2_name = "cketh"; + ledger_canister_id1 = principal "b77ix-eeaaa-aaaaa-qaada-cai"; + ledger_canister_id2 = principal "by6od-j4aaa-aaaaa-qaadq-cai"; + fee = 30; + } +)' + +dfx canister call ckbtc icrc1_balance_of "(record {owner=principal\"um2uc-3w7jg-5lycg-pmjio-is7ms-jjzwo-kvwfa-xdeus-ur2tx-4sbzd-cae\"; subaccount=null; memo=null; from_subaccount=null; created_at_time=null;})" +dfx canister call cketh icrc1_balance_of "(record {owner=principal\"um2uc-3w7jg-5lycg-pmjio-is7ms-jjzwo-kvwfa-xdeus-ur2tx-4sbzd-cae\"; subaccount=null; memo=null; from_subaccount=null; created_at_time=null;})" diff --git a/scripts/helper_scripts/swap_test2.sh b/scripts/helper_scripts/swap_test2.sh index f3f47eb..27afdd3 100755 --- a/scripts/helper_scripts/swap_test2.sh +++ b/scripts/helper_scripts/swap_test2.sh @@ -6,9 +6,9 @@ # 100000000 : nat # )' -INPUT_TOKEN=100000000; -IDENTITY=$(dfx identity get-principal) -VALUESWAP_BACKEND=$(dfx canister id valueswap_backend) +# INPUT_TOKEN=100000000; +# IDENTITY=$(dfx identity get-principal) +# VALUESWAP_BACKEND=$(dfx canister id valueswap_backend) # dfx canister call valueswap_backend pre_compute_swap '( # record { diff --git a/src/swap/src/api/transfer.rs b/src/swap/src/api/transfer.rs index 6add5db..e3c90b7 100644 --- a/src/swap/src/api/transfer.rs +++ b/src/swap/src/api/transfer.rs @@ -9,26 +9,125 @@ struct Account { pub subaccount: Option>, } -#[derive(CandidType, Deserialize,Debug)] +// #[derive(CandidType, Deserialize,Debug)] +// struct TransferArg { +// from_subaccount: Option>, +// to: Account, +// amount: Nat, +// fee: Option, +// memo: Option>, +// created_at_time: Option, +// } +pub type BlockIndex = Nat; + +#[derive(CandidType, Deserialize, Debug)] struct TransferArg { from_subaccount: Option>, to: Account, amount: Nat, - fee: Option, + fee: Option, memo: Option>, created_at_time: Option, } +#[derive(CandidType, Deserialize, Debug)] +enum TransferError { + BadFee { expected_fee: Nat }, + BadBurn { min_burn_amount: Nat }, + InsufficientFunds { balance: Nat }, + TooOld, + CreatedInFuture { ledger_time: u64 }, + TemporarilyUnavailable, + Duplicate { duplicate_of: Nat }, + GenericError { error_code: Nat, message: String }, +} + #[derive(CandidType, Deserialize)] enum TransferResult { - Ok(Nat), - Err(String), + Ok(BlockIndex), + Err(TransferError), } +// #[derive(CandidType, Deserialize)] +// enum TransferResult { +// Ok(Nat), +// Err(String), +// } + + +// #[update] +// pub async fn icrc1_transfer( +// canister_id: Principal, +// user_principal: Principal, +// amount: Nat, +// ) -> Result { +// // Validate input amount +// if amount == Nat::from(0u32) { +// return Err("Transfer amount must be greater than zero.".to_string()); +// } + +// // Validate user principal +// if user_principal == Principal::anonymous() { +// return Err("Invalid user principal: Cannot be anonymous.".to_string()); +// } + +// // Validate canister ID +// if canister_id == Principal::anonymous() { +// return Err("Invalid canister ID: Cannot be anonymous.".to_string()); +// } + +// // Debug: Log input arguments +// ic_cdk::println!( +// "Debug: Initiating transfer to {} with amount {} via canister {}", +// user_principal, amount, canister_id +// ); + +// // Define the parameters for the ICRC2 transfer call +// let args = TransferArg { +// from_subaccount: None, // Optionally specify a subaccount if needed +// to: Account { +// owner: user_principal, // The recipient of the transfer +// subaccount: None, +// }, +// amount: amount.clone(), // The amount of tokens to transfer +// fee: None, // Specify a fee if required +// memo: None, // Optional memo for the transfer +// created_at_time: None, // Optional timestamp +// }; + +// // Debug: Log constructed transfer arguments +// ic_cdk::println!("Debug: TransferArg constructed: {:?}", args); + +// // Make the call to the ICRC2 token canister with the transfer arguments +// let (result,): (TransferResult,) = call( +// canister_id, // The canister ID of the token ledger (ICRC2) +// "icrc1_transfer", // The method to call +// (args,), // Transfer arguments +// ) +// .await +// .map_err(|e| format!("Transfer failed: {:?}", e))?; + +// // Check if the call was successful +// match result { +// TransferResult::Ok(balance) => { +// // Debug: Log successful transfer +// ic_cdk::println!( +// "Debug: Transfer successful. New balance: {}", +// balance +// ); +// Ok(balance) +// } +// TransferResult::Err(err) => { +// // Debug: Log transfer error +// ic_cdk::println!("Error: Transfer failed: {:?}", err); +// Err(format!("Transfer failed: {:?}", err)) +// } +// } +// } #[update] pub async fn icrc1_transfer( - canister_id: Principal, + ledger_canister: Principal, user_principal: Principal, amount: Nat, ) -> Result { @@ -42,15 +141,15 @@ pub async fn icrc1_transfer( return Err("Invalid user principal: Cannot be anonymous.".to_string()); } - // Validate canister ID - if canister_id == Principal::anonymous() { - return Err("Invalid canister ID: Cannot be anonymous.".to_string()); + // Validate ledger canister principal + if ledger_canister == Principal::anonymous() { + return Err("Invalid ledger canister ID: Cannot be anonymous.".to_string()); } // Debug: Log input arguments ic_cdk::println!( - "Debug: Initiating transfer to {} with amount {} via canister {}", - user_principal, amount, canister_id + "Debug: Initiating faucet transfer to {} with amount {} via ledger {}", + user_principal, amount, ledger_canister ); // Define the parameters for the ICRC2 transfer call @@ -60,7 +159,7 @@ pub async fn icrc1_transfer( owner: user_principal, // The recipient of the transfer subaccount: None, }, - amount: amount.clone(), // The amount of tokens to transfer + amount, // The amount of tokens to transfer fee: None, // Specify a fee if required memo: None, // Optional memo for the transfer created_at_time: None, // Optional timestamp @@ -70,28 +169,28 @@ pub async fn icrc1_transfer( ic_cdk::println!("Debug: TransferArg constructed: {:?}", args); // Make the call to the ICRC2 token canister with the transfer arguments - let (result,): (TransferResult,) = call( - canister_id, // The canister ID of the token ledger (ICRC2) - "icrc1_transfer", // The method to call - (args,), // Transfer arguments - ) - .await - .map_err(|e| format!("Transfer failed: {:?}", e))?; + let (result,): (TransferResult,) = call(ledger_canister, "icrc1_transfer", (args,)) + .await + .map_err(|e| format!("Transfer failed: {:?}", e))?; // Check if the call was successful match result { TransferResult::Ok(balance) => { // Debug: Log successful transfer ic_cdk::println!( - "Debug: Transfer successful. New balance: {}", + "Debug: Faucet transfer successful. New balance: {}", balance ); Ok(balance) } TransferResult::Err(err) => { // Debug: Log transfer error - ic_cdk::println!("Error: Transfer failed: {:?}", err); - Err(format!("Transfer failed: {:?}", err)) + ic_cdk::println!("Error: Faucet transfer failed: {:?}", err); + Err(format!("Faucet transfer failed: {:?}", err)) } } } + + + + diff --git a/src/valueswap_backend/src/vault/pool_factory.rs b/src/valueswap_backend/src/vault/pool_factory.rs index f5f0529..40c2a28 100644 --- a/src/valueswap_backend/src/vault/pool_factory.rs +++ b/src/valueswap_backend/src/vault/pool_factory.rs @@ -945,7 +945,7 @@ async fn compute_swap(params: SwapParams) -> Result<(), CustomError> { // let user_principal_id = api::caller(); let pool_lp_token = get_pool_lp_tokens(pool_name.clone()); - let pool_lp_token_limit = (Nat::from(30u128) * (pool_lp_token)) / Nat::from(100u128); + let pool_lp_token_limit = (Nat::from(30u128) * (pool_lp_token)) / Nat::from(1000u128); let token_amount = params.token_amount.clone(); diff --git a/src/valueswap_frontend/src/Modals/Swap.jsx b/src/valueswap_frontend/src/Modals/Swap.jsx index 69ec94e..3d99605 100644 --- a/src/valueswap_frontend/src/Modals/Swap.jsx +++ b/src/valueswap_frontend/src/Modals/Swap.jsx @@ -281,7 +281,7 @@ const Swap = () => { }) const res = await backendActor.compute_swap({ token1_name: payCoin.ShortForm, - token_amount: amount, + token_amount: amount * 100000000, token2_name: receiveCoin.ShortForm, ledger_canister_id1: Principal.fromText(payCoin.CanisterId), ledger_canister_id2: Principal.fromText(receiveCoin.CanisterId), From a89ceb8c4a89c163df994ff893cad7f92b027cca Mon Sep 17 00:00:00 2001 From: Harshit Chauhan Date: Tue, 25 Feb 2025 16:57:34 +0530 Subject: [PATCH 09/10] latest changes --- .../poolPageComponent/AddLiquidity.jsx | 216 +----------------- 1 file changed, 2 insertions(+), 214 deletions(-) diff --git a/src/valueswap_frontend/src/components/poolPageComponent/AddLiquidity.jsx b/src/valueswap_frontend/src/components/poolPageComponent/AddLiquidity.jsx index 055a8de..8749997 100644 --- a/src/valueswap_frontend/src/components/poolPageComponent/AddLiquidity.jsx +++ b/src/valueswap_frontend/src/components/poolPageComponent/AddLiquidity.jsx @@ -1,21 +1,14 @@ import React, { useState, useEffect, useCallback, useMemo } from 'react' import { useParams } from 'react-router-dom'; -import { portfolioSampleData } from '../../TextData'; -import PoolInfoBox from '../../displayBoxes/PoolInfoBox'; import GradientButton from '../../buttons/GradientButton' -import { PoolCompositions, Swapping, LiquidityOverview } from '../../tables' -import Echarts from '../portfolioComponents/Echarts'; import { IOSSwitch } from '../../buttons/SwitchButton'; import { convertTokenEquivalentUSD } from '../../utils'; import { useAuth } from '../utils/useAuthClient'; -import { Principal } from '@dfinity/principal'; const AddLiquidity = () => { const { id } = useParams() - const [currIndex, setCurrIndex] = useState(0) - const [currentRang, setCurrentRange] = useState(0) const [tokens, setTokens] = useState([]) const [restTokens, setRestTokens] = useState([]) const [token1, setToken1] = useState(null); @@ -24,32 +17,6 @@ const AddLiquidity = () => { const Heading = ['Pool Compositions', 'Swapping', 'Liquidiity Overview'] const {backendActor,principal, createTokenActor, getBalance} = useAuth() - - - - const fetchMetadata = async (CanisterId) => { - try { - const ledgerActor = await createTokenActor(CanisterId); - const result = await ledgerActor?.icrc1_metadata(); - console.log("Fetched metadata:", result); - - // Extract decimals and symbol from the metadata - const decimalsEntry = result.find(([key]) => key === "icrc1:decimals"); - const symbolEntry = result.find(([key]) => key === "icrc1:symbol"); - - const decimals = decimalsEntry ? Number(decimalsEntry[1]?.Nat) : null; // Convert BigInt to Number - const symbol = symbolEntry ? symbolEntry[1]?.Text : null; - console.log("meta", decimals, symbol) - return { - decimals, - symbol, - }; - } catch (error) { - console.error("Error fetching metadata:", error); - return null; // Return null in case of an error - } - }; - const initToken = useCallback(async()=>{ const initialToken = tokens[0] let data = {} @@ -301,42 +268,7 @@ const AddLiquidity = () => { // Function to calculate equivalent rest token amounts const calculateEquivalentAmounts = useCallback(() => { - // const handleOptimize = useCallback(() => { - // if (!Tokens[0].Amount || !Tokens[0].marketPrice || !Tokens[0].weights) { - // console.error("Missing required data for first token"); - // return; - // } - // // Calculate total pool value based on first token - // const firstTokenUSDValue = Tokens[0].Amount * Tokens[0].marketPrice; - // if (firstTokenUSDValue <= 0) { - // console.error("Invalid first token value"); - // return; - // } - // // Calculate total pool value based on first token's weight - // const totalPoolValue = firstTokenUSDValue / (Tokens[0].weights / 100); - // console.log("Total pool value:", totalPoolValue); - // // Calculate and update amounts for other tokens - // Tokens.slice(1).forEach((token, index) => { - // if (!token.marketPrice || !token.weights) { - // console.error(`Missing required data for token ${index + 1}`); - // return; - // } - // const tokenTargetUSDValue = totalPoolValue * (token.weights / 100); - // const requiredTokenAmount = tokenTargetUSDValue / token.marketPrice; - // // Round to 8 decimal places to avoid floating point issues - // const roundedAmount = Number(requiredTokenAmount.toFixed(8)); - // console.log(`Token ${index + 1} calculation:`, { - // weight: token.weights, - // targetUSD: tokenTargetUSDValue, - // marketPrice: token.marketPrice, - // requiredAmount: roundedAmount - // }); - // dispatch(UpdateAmount({ - // index: index + 1, - // Amount: roundedAmount - // })); - // }); - // }, [Tokens, dispatch]); + if (!token1?.currencyAmount || !token1?.weights){ console.error("Missing required data for first token", token1); return @@ -514,151 +446,7 @@ const AddLiquidity = () => { ); - // return ( - //
- - //
- - //
- //
- //
- //
- // { - // TokenData?.PoolData.map((token, index) => ( - //
- //
- // - //
- //
- // )) - // } - //
- //
- // {TokenData?.PoolData[0].ShortForm} - // { - // TokenData?.PoolData.slice(1).map((token, index) => ( - //
- // / - // {token.ShortForm} - //
- // )) - // } - // : : - - // {TokenData?.PoolData[0].weights} - // { - // TokenData?.PoolData.slice(1).map((token, index) => ( - //
- // / - // {token.weights} - //
- // )) - // } - //
- //
- //
- //
- //
- // {/* pool info chart here in this div */} - //
- //
- //

$125,625,175

- //
- //
- //
- //

Volumes in Past-

- //
- //
- // - //
- //
- // { - // selectRang.map((rang, index) => - //
{ - // setCurrentRange(index) - // }}> - //

{rang}

- // - //
- // ) - // } - - //
- //
- //
- // - //
- //
- - //
- //
- - //
- //
- // - // - //
- //
- // - // - //
- //
- //
- - //
- // My Pool Balance: - // ${TokenData?.PoolMetaData.PersonalPoolBalance.toLocaleString('en-US')} - //
- - - // {/*
- //
- // - // Swap Tokens - // - //
- //
- // - // Add Liquidity - // - //
- //
- // - // Withdraw - // - //
- //
*/} - - // {/*
- // {Heading.map((heading, index) => ( - //
{ - // setCurrIndex(index) - // }}> - //

{heading}

- // - //
- // ))} - //
*/} - - - // {/*
- // {currIndex === 0 && } - // {currIndex === 1 && } - // {currIndex === 2 && } - //
*/} - - - - //
- - //
- //
- // ) - + } export default AddLiquidity From af7ce244e923ab760cd2c74d02520de8d63f982d Mon Sep 17 00:00:00 2001 From: ArjunQBTech Date: Fri, 28 Feb 2025 10:09:46 +0000 Subject: [PATCH 10/10] Add market impact calculation and warning display in Swap component --- src/valueswap_frontend/src/Modals/Swap.jsx | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/valueswap_frontend/src/Modals/Swap.jsx b/src/valueswap_frontend/src/Modals/Swap.jsx index 3d99605..f2366d2 100644 --- a/src/valueswap_frontend/src/Modals/Swap.jsx +++ b/src/valueswap_frontend/src/Modals/Swap.jsx @@ -4,7 +4,8 @@ import { useAuth } from '../components/utils/useAuthClient' import { Principal } from '@dfinity/principal' import { Settings as SettingsIcon, - Cached as CachedIcon + Cached as CachedIcon, + Warning } from '@mui/icons-material' import BorderGradientButton from '../buttons/BorderGradientButton' import GradientButton from '../buttons/GradientButton' @@ -18,8 +19,7 @@ import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp'; import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline'; const Swap = () => { - const { backendActor, getBalance, createTokenActor, isAuthenticated } = - useAuth() + const { backendActor, getBalance, createTokenActor, isAuthenticated } = useAuth() // States const [payCoin, setPayCoin] = useState(null) @@ -40,6 +40,7 @@ const Swap = () => { const [subModel, setSubModel] = useState(1) const [initialSlipageAmount, setInitialSlipageAmount] = useState(0) const [afterSlipageAmnt, setAfterSlipageAmnt] = useState(0) + const [marketImpact, setMarketImpact] = useState(0) // Fetch balances whenever payCoin or receiveCoin changes useEffect(() => { if (payCoin) { @@ -312,6 +313,17 @@ const Swap = () => { } } + const updateMarketImpact = async()=>{ + const payMarketPrice = (coinAmount * payCoin?.marketPrice).toFixed(2); + const receiveMarketPrice = ((Number(receiveValue) / (Math.pow(10,Math.max(payCoin.metaData.decimals,receiveCoin.metaData.decimals)))) * receiveCoin?.marketPrice).toFixed(2) + const impactPercent = ((payMarketPrice - receiveMarketPrice) / payMarketPrice) * 100 + setMarketImpact(impactPercent.toFixed(2)) + } + + useEffect(()=>{ + updateMarketImpact() + },[receiveValue, coinAmount]) + const handleSettings = () => { setSettings((prev) => !prev) } @@ -423,7 +435,7 @@ const Swap = () => {
-
${coinAmount > 0 ? coinAmount * payCoin?.marketPrice : 0}
+
${coinAmount > 0 ? (Number(receiveValue) / (Math.pow(10,Math.max(payCoin.metaData.decimals,receiveCoin.metaData.decimals)))).toFixed(2) * receiveCoin?.marketPrice : 0}
+
0 ? `flex w-full justify-center items-center gap-x-2 ${marketImpact > 10 ? 'text-red-600' : 'text-yellow-500'}` : `hidden`}> + +

Market Impact Higher : ({marketImpact}%)

+
+ {/* Action Buttons */}
{isAuthenticated ? (