From e61741f3269bd286f8da38687e044ff5c43e6e22 Mon Sep 17 00:00:00 2001 From: Georges KABBOUCHI Date: Thu, 30 Sep 2021 21:47:14 +0300 Subject: [PATCH] Liquity Stability Pool --- components/common/input/ButtonOutlined.vue | 31 +++ components/common/input/ButtonRadio.vue | 28 +++ .../liquity/CardLiquityStabilityPool.vue | 164 +++++++++++++++ .../liquity/SidebarLiquityPoolSupply.vue | 186 +++++++++++++++++ .../liquity/SidebarLiquityPoolWithdraw.vue | 187 ++++++++++++++++++ composables/protocols/useLiquityClaim.ts | 139 +++++++++++++ composables/protocols/useLiquityPosition.ts | 8 + composables/useSidebar.ts | 4 + package.json | 2 +- pages/mainnet/liquity.vue | 146 ++++++++++---- yarn.lock | 8 +- 11 files changed, 862 insertions(+), 41 deletions(-) create mode 100644 components/common/input/ButtonOutlined.vue create mode 100644 components/common/input/ButtonRadio.vue create mode 100644 components/protocols/liquity/CardLiquityStabilityPool.vue create mode 100644 components/sidebar/context/liquity/SidebarLiquityPoolSupply.vue create mode 100644 components/sidebar/context/liquity/SidebarLiquityPoolWithdraw.vue create mode 100644 composables/protocols/useLiquityClaim.ts diff --git a/components/common/input/ButtonOutlined.vue b/components/common/input/ButtonOutlined.vue new file mode 100644 index 0000000..e9a8b6a --- /dev/null +++ b/components/common/input/ButtonOutlined.vue @@ -0,0 +1,31 @@ + + + diff --git a/components/common/input/ButtonRadio.vue b/components/common/input/ButtonRadio.vue new file mode 100644 index 0000000..63707f0 --- /dev/null +++ b/components/common/input/ButtonRadio.vue @@ -0,0 +1,28 @@ + + + diff --git a/components/protocols/liquity/CardLiquityStabilityPool.vue b/components/protocols/liquity/CardLiquityStabilityPool.vue new file mode 100644 index 0000000..9a2f17e --- /dev/null +++ b/components/protocols/liquity/CardLiquityStabilityPool.vue @@ -0,0 +1,164 @@ + + + diff --git a/components/sidebar/context/liquity/SidebarLiquityPoolSupply.vue b/components/sidebar/context/liquity/SidebarLiquityPoolSupply.vue new file mode 100644 index 0000000..be9b27e --- /dev/null +++ b/components/sidebar/context/liquity/SidebarLiquityPoolSupply.vue @@ -0,0 +1,186 @@ + + + diff --git a/components/sidebar/context/liquity/SidebarLiquityPoolWithdraw.vue b/components/sidebar/context/liquity/SidebarLiquityPoolWithdraw.vue new file mode 100644 index 0000000..1acf20c --- /dev/null +++ b/components/sidebar/context/liquity/SidebarLiquityPoolWithdraw.vue @@ -0,0 +1,187 @@ + + + + diff --git a/composables/protocols/useLiquityClaim.ts b/composables/protocols/useLiquityClaim.ts new file mode 100644 index 0000000..23d0a1c --- /dev/null +++ b/composables/protocols/useLiquityClaim.ts @@ -0,0 +1,139 @@ +import { useWeb3 } from "@instadapp/vue-web3"; +import { ref, computed } from "@nuxtjs/composition-api"; +import { useBalances } from "../useBalances"; +import { useBigNumber } from "../useBigNumber"; +import { useDSA } from "../useDSA"; +import { useNotification } from "../useNotification"; +import { useToken } from "../useToken"; +import { useLiquityPosition } from "./useLiquityPosition"; + +export function useLiquityClaim() { + const { account } = useWeb3(); + const { getTokenByKey, valInt } = useToken(); + const { dsa } = useDSA(); + const { plus } = useBigNumber(); + const { + stabilityEthGain, + getTrovePositionHints, + debtInWei, + collateralInWei, + fetchPosition + } = useLiquityPosition(); + + const { + showConfirmedTransaction, + showPendingTransaction, + showWarning, + } = useNotification(); + const { fetchBalances } = useBalances(); + + const ethToken = computed(() => getTokenByKey("eth")); + + const pendingStabilityClaimAndMove = ref(false); + + async function stabilityClaimAndMove() { + pendingStabilityClaimAndMove.value = true; + + try { + const amountInWei = valInt( + stabilityEthGain.value, + ethToken.value.decimals + ); + const totalDepositAmountInWei = plus( + collateralInWei.value, + amountInWei + ).toFixed(); + + const { upperHint, lowerHint } = await getTrovePositionHints( + totalDepositAmountInWei, + debtInWei.value + ); + + console.log({ + connector: "LIQUITY-A", + method: "stabilityMoveEthGainToTrove", + args: [upperHint, lowerHint] + }); + + const spells = dsa.value.Spell(); + spells.add({ + connector: "LIQUITY-A", + method: "stabilityMoveEthGainToTrove", + args: [upperHint, lowerHint] + }); + + const tx = await dsa.value.cast({ + spells, + from: account.value, + onReceipt: async receipt => { + showConfirmedTransaction(receipt.transactionHash); + + await fetchBalances(true); + await fetchPosition(); + } + }); + + showPendingTransaction(tx); + } catch (error) { + console.log(error); + showWarning(error.message); + } + + pendingStabilityClaimAndMove.value = false; + } + + const pendingStabilityClaimOnly = ref(false); + + async function stabilityClaimOnly() { + pendingStabilityClaimOnly.value = true; + + try { + const supplyAmountInWei = 0; + + const getDepositId = 0; + const setDepositId = 0; + const setEthGainId = 0; + const setLqtyGainId = 0; + + const spells = dsa.value.Spell(); + spells.add({ + connector: "LIQUITY-A", + method: "stabilityWithdraw", + args: [ + supplyAmountInWei, + getDepositId, + setDepositId, + setEthGainId, + setLqtyGainId + ] + }); + + + + const tx = await dsa.value.cast({ + spells, + from: account.value, + onReceipt: async receipt => { + showConfirmedTransaction(receipt.transactionHash); + + await fetchBalances(true); + await fetchPosition(); + } + }); + + showPendingTransaction(tx); + } catch (error) { + console.log(error); + showWarning(error.message); + } + + pendingStabilityClaimOnly.value = false; + } + + return { + stabilityClaimAndMove, + pendingStabilityClaimAndMove, + pendingStabilityClaimOnly, + stabilityClaimOnly + }; +} diff --git a/composables/protocols/useLiquityPosition.ts b/composables/protocols/useLiquityPosition.ts index 03eb632..cba4830 100644 --- a/composables/protocols/useLiquityPosition.ts +++ b/composables/protocols/useLiquityPosition.ts @@ -60,6 +60,7 @@ export function useLiquityPosition( const collateralToken = computed(() => getTokenByKey("eth")); const debtToken = computed(() => getTokenByKey("lusd")); + const poolToken = computed(() => getTokenByKey('lusd')) const stakingToken = computed(() => getTokenByKey("lqty")); const collateral = computed(() => trove.value.collateral); @@ -74,6 +75,9 @@ export function useLiquityPosition( times(collateral.value, priceInUsd.value).toFixed() ); const stabilityAmount = computed(() => trove.value.stabilityAmount); + const stabilityEthGain = computed(() => trove.value.stabilityEthGain) + const stabilityLqtyGain = computed(() => trove.value.stabilityLqtyGain) + const debtUsd = computed(() => times(debt.value, "1").toFixed()); const stabilityAmountUsd = computed(() => times(stabilityAmount.value, "1").toFixed() @@ -224,6 +228,10 @@ export function useLiquityPosition( priceInUsd, debt, debtInWei, + poolToken, + stabilityAmount, + stabilityEthGain, + stabilityLqtyGain, }; } diff --git a/composables/useSidebar.ts b/composables/useSidebar.ts index d5ec48e..eeb2231 100644 --- a/composables/useSidebar.ts +++ b/composables/useSidebar.ts @@ -34,6 +34,8 @@ import SidebarLiquityTroveSupply from '~/components/sidebar/context/liquity/Side import SidebarLiquityTroveWithdraw from '~/components/sidebar/context/liquity/SidebarLiquityTroveWithdraw.vue' import SidebarLiquityTroveBorrow from '~/components/sidebar/context/liquity/SidebarLiquityTroveBorrow.vue' import SidebarLiquityTrovePayback from '~/components/sidebar/context/liquity/SidebarLiquityTrovePayback.vue' +import SidebarLiquityPoolSupply from '~/components/sidebar/context/liquity/SidebarLiquityPoolSupply.vue' +import SidebarLiquityPoolWithdraw from '~/components/sidebar/context/liquity/SidebarLiquityPoolWithdraw.vue' import SidebarReflexerCollateral from '~/components/sidebar/context/reflexer/SidebarReflexerCollateral.vue' import SidebarReflexerSupply from '~/components/sidebar/context/reflexer/SidebarReflexerSupply.vue' @@ -75,6 +77,8 @@ const sidebars = { '/mainnet/liquity#trove-withdraw': { component: SidebarLiquityTroveWithdraw }, '/mainnet/liquity#trove-borrow': { component: SidebarLiquityTroveBorrow }, '/mainnet/liquity#trove-payback': { component: SidebarLiquityTrovePayback }, + '/mainnet/liquity#pool-supply': { component: SidebarLiquityPoolSupply }, + '/mainnet/liquity#pool-withdraw': { component: SidebarLiquityPoolWithdraw }, "/mainnet/reflexer": { component: null }, '/mainnet/reflexer#collateral': { component: SidebarReflexerCollateral }, diff --git a/package.json b/package.json index 5709b8d..d3f6966 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "bignumber.js": "^9.0.1", "core-js": "^3.15.1", "css-color-function": "^1.3.3", - "dsa-connect": "^0.4.4", + "dsa-connect": "^0.4.9", "nuxt": "^2.15.7", "qrcode": "^1.4.4", "slugify": "^1.6.0", diff --git a/pages/mainnet/liquity.vue b/pages/mainnet/liquity.vue index b945dc6..83797cf 100644 --- a/pages/mainnet/liquity.vue +++ b/pages/mainnet/liquity.vue @@ -10,7 +10,7 @@ -
+

Your Positions

-
- - - - +
+
+ + Trove + + + Stability Pool + +
+
+
- - Open Trove - + + + + + + + Open Trove + +
+ +
+ +