From 92ce5161efdfcf212dc969813faa8dbf4e3b37ab Mon Sep 17 00:00:00 2001 From: luc <58892938+llllllluc@users.noreply.github.com> Date: Sun, 7 May 2023 12:08:36 -0700 Subject: [PATCH] Update swapping.mdx fix calculating belief price using simulate endpoint --- docs/develop/tutorials/trading/swapping.mdx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/develop/tutorials/trading/swapping.mdx b/docs/develop/tutorials/trading/swapping.mdx index 16021b2..9d0dd1a 100644 --- a/docs/develop/tutorials/trading/swapping.mdx +++ b/docs/develop/tutorials/trading/swapping.mdx @@ -200,6 +200,7 @@ Performs a native swap in a given pool. ```js const astrolunaAddress = "terra1udsua9w6jljwxwgwsegvt6v657rg3ayfvemupnes7lrggd28s0wq7g8azm"; + const offeredlunaAmount = "100000" let beliefPrice; const simulation = await lcd.wasm.contractQuery( @@ -212,13 +213,13 @@ Performs a native swap in a given pool. "denom": "uluna" } }, - "amount": "100000" + "amount": offeredlunaAmount } } } ).then(result => { beliefPrice = result.return_amount }); - beliefPrice = String(beliefPrice * 1000000); + beliefPrice = (beliefPrice / offeredlunaAmount).toFixed(18); ``` ---