From 8b31746e57bcb1541f663576899a8b1f90c7afab Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Mon, 24 Jan 2022 16:19:47 +0000 Subject: [PATCH] make remove output calculation work --- .../Asset/AssetActions/Pool/Remove.tsx | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/components/Asset/AssetActions/Pool/Remove.tsx b/src/components/Asset/AssetActions/Pool/Remove.tsx index 27429b15d..58050e207 100644 --- a/src/components/Asset/AssetActions/Pool/Remove.tsx +++ b/src/components/Asset/AssetActions/Pool/Remove.tsx @@ -43,6 +43,7 @@ export default function Remove({ }): ReactElement { const { accountId, web3 } = useWeb3() const { isAssetNetwork } = useAsset() + const [amountPercent, setAmountPercent] = useState('0') const [amountMaxPercent, setAmountMaxPercent] = useState('100') const [amountPoolShares, setAmountPoolShares] = useState('0') @@ -52,6 +53,7 @@ export default function Remove({ const [slippage, setSlippage] = useState('5') const [minOceanAmount, setMinOceanAmount] = useState('0') + // TODO: precision needs to be set based on baseToken decimals Decimal.set({ toExpNeg: -18, precision: 18, rounding: 1 }) const poolInstance = new Pool(web3, LoggerInstance) @@ -89,21 +91,15 @@ export default function Remove({ const getValues = useRef( debounce(async (newAmountPoolShares) => { - // TODO: check based on pool tokens sent in, what I get out in baseToken. - // Seems to be not possible with getAmountInExactOut(). - // const tokenIn = newAmountPoolShares // TODO: this needs to pool shares? - // const swapMarketFee = '' // TODO: which is it? Swap fee or market fee? - // const baseTokenAmount = '' // TODO: this is what I want to know, why do I need to pass as param then? - // const newAmountOcean = await poolInstance.getAmountInExactOut( - // poolAddress, - // tokenIn, - // baseTokenAddress, - // baseTokenAmount, - // swapMarketFee - // ) - // setAmountOcean(newAmountOcean) + const newAmountOcean = await poolInstance.calcSingleOutGivenPoolIn( + poolAddress, + baseTokenAddress, + newAmountPoolShares + ) + setAmountOcean(newAmountOcean) }, 150) ) + // Check and set outputs when amountPoolShares changes useEffect(() => { if (!accountId || !poolTokens) return