From 6a4095f11d01abd75653523a74418fcbc5854df1 Mon Sep 17 00:00:00 2001 From: MGrgr Date: Thu, 1 Feb 2024 02:34:00 +0300 Subject: [PATCH 01/14] feat: pool stats (store) --- .env.dev | 1 + .env.prod | 1 + .env.stage | 1 + src/components/pools/PoolsList.vue | 5 +- src/config/common.ts | 1 + src/config/tokens.ts | 13 ++- src/stores/index.ts | 1 + src/stores/pools-state.ts | 134 +++++++++++++++++++++++++++++ src/stores/token.ts | 3 + src/utils/index.ts | 1 + src/utils/pools-api.ts | 58 +++++++++++++ types/auto-imports.d.ts | 1 + 12 files changed, 217 insertions(+), 3 deletions(-) create mode 100644 src/stores/pools-state.ts create mode 100644 src/utils/pools-api.ts diff --git a/.env.dev b/.env.dev index 4995813..07235ec 100644 --- a/.env.dev +++ b/.env.dev @@ -1,2 +1,3 @@ VITE_PASSWORD_PROTECT=345719 VITE_ALBUS_APP_URL='https://dev.app.albus.finance' +VITE_POOLS_API_URL='https://dev.app.albus.finance' diff --git a/.env.prod b/.env.prod index 3b506d1..9bf236e 100644 --- a/.env.prod +++ b/.env.prod @@ -2,3 +2,4 @@ VITE_GTAG_ID= VITE_SENTRY_DSN= VITE_ALBUS_APP_URL='https://app.albus.finance' +VITE_POOLS_API_URL='https://app.albus.finance' diff --git a/.env.stage b/.env.stage index b2c0908..b35cb0b 100644 --- a/.env.stage +++ b/.env.stage @@ -1,2 +1,3 @@ VITE_PASSWORD_PROTECT=345719 VITE_ALBUS_APP_URL='https://stage.app.albus.finance' +VITE_POOLS_API_URL='https://stage.app.albus.finance' diff --git a/src/components/pools/PoolsList.vue b/src/components/pools/PoolsList.vue index 368c719..3c27a09 100644 --- a/src/components/pools/PoolsList.vue +++ b/src/components/pools/PoolsList.vue @@ -7,6 +7,9 @@ const onlyMyPools = ref(false) const swapStore = useSwapStore() const tokenSwapsAllFiltered = computed(() => swapStore.tokenSwapsAllFiltered.filter(p => !connected.value || !onlyMyPools.value || swapStore.userPoolsTokens[p.data.poolMint.toBase58()])) const { state } = swapStore + +const poolsStatsStore = usePoolsStatsStore() +const poolDataLoading = computed(() => poolsStatsStore.poolsLoading) diff --git a/src/components/liquidity/WithdrawBothCard.vue b/src/components/liquidity/WithdrawBothCard.vue index 8a737ac..6a6e18d 100644 --- a/src/components/liquidity/WithdrawBothCard.vue +++ b/src/components/liquidity/WithdrawBothCard.vue @@ -8,7 +8,7 @@ const { state: swapState, loadingPoolTokens, loadPoolTokenAccounts } = swapStore const tokenSwap = computed(() => swapStore.tokenSwap) const liquidityWithdrawStore = useLiquidityWithdrawStore() -const { state, depositBothTokens, openSlippage, closeSlippage } = liquidityWithdrawStore +const { state, depositBothTokens, closeSlippage } = liquidityWithdrawStore const balance = computed(() => (tokenSwap.value && swapStore.userPoolsTokens[tokenSwap.value.data.poolMint.toBase58()]) || 0) const poolBalanceA = computed(() => swapState.poolBalance[swapState.from.mint] ? lamportsToSol(swapState.poolBalance[swapState.from.mint], swapState.from.decimals) : 0) @@ -83,7 +83,24 @@ watch([() => state.poolAmount, balance], () => {
Slippage Tolerance
- {{ formatPercent(state.slippage) }} + + {{ formatPercent(state.slippage) }} + + + + + + + +
@@ -138,19 +155,4 @@ watch([() => state.poolAmount, balance], () => { - - - - - - - diff --git a/src/components/pools/PoolsListItem.vue b/src/components/pools/PoolsListItem.vue index bb2dad6..ab3e024 100644 --- a/src/components/pools/PoolsListItem.vue +++ b/src/components/pools/PoolsListItem.vue @@ -60,8 +60,48 @@ const dialog = ref(false)
{{ tokenAData?.symbol }} / {{ tokenBData?.symbol }}
- + i + + +
+ Pool address:  + + {{ shortenAddress(pubkey.toBase58()) }} + + +
+
+ Token A mint:  + + {{ shortenAddress(data.tokenAMint.toBase58()) }} + + +
+
+ Token B mint:  + + {{ shortenAddress(data.tokenBMint.toBase58()) }} + + +
+
+ LP token mint:  + + {{ shortenAddress(data.poolMint.toBase58()) }} + + +
+
+ Swap fee:  + {{ formatPct.format(swapFee) }} +
+
+ Withdraw fee:  + {{ formatPct.format(fees.ownerWithdraw) }} +
+
+
@@ -118,45 +158,5 @@ const dialog = ref(false) - - -
- Pool address:  - - {{ shortenAddress(pubkey.toBase58()) }} - - -
-
- Token A mint:  - - {{ shortenAddress(data.tokenAMint.toBase58()) }} - - -
-
- Token B mint:  - - {{ shortenAddress(data.tokenBMint.toBase58()) }} - - -
-
- LP token mint:  - - {{ shortenAddress(data.poolMint.toBase58()) }} - - -
-
- Swap fee:  - {{ formatPct.format(swapFee) }} -
-
- Withdraw fee:  - {{ formatPct.format(fees.ownerWithdraw) }} -
-
-
diff --git a/src/stores/liquidity-withdraw.ts b/src/stores/liquidity-withdraw.ts index cf2802d..9807cd4 100644 --- a/src/stores/liquidity-withdraw.ts +++ b/src/stores/liquidity-withdraw.ts @@ -192,10 +192,6 @@ export const useLiquidityWithdrawStore = defineStore('liquidity-withdraw', () => } } - function openSlippage() { - state.slippageDialog = true - } - function closeSlippage() { state.slippageDialog = false } @@ -203,7 +199,6 @@ export const useLiquidityWithdrawStore = defineStore('liquidity-withdraw', () => return { state, closeSlippage, - openSlippage, depositBothTokens, } }) diff --git a/src/stores/liquidity.ts b/src/stores/liquidity.ts index 2e2575f..f45142b 100644 --- a/src/stores/liquidity.ts +++ b/src/stores/liquidity.ts @@ -206,10 +206,6 @@ export const useLiquidityStore = defineStore('liquidity', () => { } } - function openSlippage() { - state.slippageDialog = true - } - function closeSlippage() { state.slippageDialog = false } @@ -218,7 +214,6 @@ export const useLiquidityStore = defineStore('liquidity', () => { state, calcRate, closeSlippage, - openSlippage, depositBothTokens, } }) diff --git a/src/stores/swap.ts b/src/stores/swap.ts index 55171ae..55f345c 100644 --- a/src/stores/swap.ts +++ b/src/stores/swap.ts @@ -415,10 +415,6 @@ export const useSwapStore = defineStore('swap', () => { state.direction = state.direction === SwapDirection.ASC ? SwapDirection.DESC : SwapDirection.ASC } - function openSlippage() { - state.slippageDialog = true - } - function closeSlippage() { state.slippageDialog = false } @@ -484,7 +480,6 @@ export const useSwapStore = defineStore('swap', () => { loadPoolTokenAccounts, setTokenSwap, closeSlippage, - openSlippage, changeDirection, swapSubmit, getPoolFee, From 12b3171d7f0d9a72cde377e13d31865413c4fcd7 Mon Sep 17 00:00:00 2001 From: MGrgr Date: Fri, 2 Feb 2024 20:29:39 +0300 Subject: [PATCH 07/14] fix: differet policy for swap and liquidity --- package.json | 2 +- pnpm-lock.yaml | 21 +++++++++--- src/components/CreatePool/CreateSwapCard.vue | 34 ++++++++++++++++++-- src/config/tokens.ts | 1 + src/hooks/create-swap-pool.ts | 28 +++++++++++----- src/stores/swap.ts | 16 ++++++--- src/stores/user.ts | 4 --- 7 files changed, 80 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 8e92f23..679d988 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ }, "dependencies": { "@albus-finance/sdk": "0.2.6", - "@albus-finance/swap-sdk": "0.1.5-next.1", + "@albus-finance/swap-sdk": "0.1.5-next.3", "@albus-finance/transfer-sdk": "0.2.4", "@coral-xyz/anchor": "^0.29.0", "@metaplex-foundation/beet": "^0.7.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7faded5..06c0646 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ dependencies: specifier: 0.2.6 version: 0.2.6 '@albus-finance/swap-sdk': - specifier: 0.1.5-next.1 - version: 0.1.5-next.1 + specifier: 0.1.5-next.3 + version: 0.1.5-next.3 '@albus-finance/transfer-sdk': specifier: 0.2.4 version: 0.2.4 @@ -206,11 +206,11 @@ packages: - utf-8-validate dev: false - /@albus-finance/swap-sdk@0.1.5-next.1: - resolution: {integrity: sha512-OL4/olCOkoVPHB0RjyJHgwzw9IyLUUNvwdBNGWwsyb4QoAypB2TsZrVEY9Rejcqq1D/L4ES1aYKwFm7n/aXVjg==} + /@albus-finance/swap-sdk@0.1.5-next.3: + resolution: {integrity: sha512-HMiFs6GWYMldF2G9ncszuVoiwMFRJZHFH0T48z2L2gjvcYY+voLLtCUSmLcToibcwaNIhK/VCGfOLhwLsUWs8g==} dependencies: '@coral-xyz/anchor': 0.29.0 - '@metaplex-foundation/beet': 0.7.1 + '@metaplex-foundation/beet': 0.7.2 '@solana/spl-token': 0.3.9(@solana/web3.js@1.87.6) '@solana/web3.js': 1.87.6 transitivePeerDependencies: @@ -1305,6 +1305,17 @@ packages: - supports-color dev: false + /@metaplex-foundation/beet@0.7.2: + resolution: {integrity: sha512-K+g3WhyFxKPc0xIvcIjNyV1eaTVJTiuaHZpig7Xx0MuYRMoJLLvhLTnUXhFdR5Tu2l2QSyKwfyXDgZlzhULqFg==} + dependencies: + ansicolors: 0.3.2 + assert: 2.1.0 + bn.js: 5.2.1 + debug: 4.3.4 + transitivePeerDependencies: + - supports-color + dev: false + /@metaplex-foundation/cusper@0.0.2: resolution: {integrity: sha512-S9RulC2fFCFOQraz61bij+5YCHhSO9llJegK8c8Y6731fSi6snUSQJdCUqYS8AIgR0TKbQvdvgSyIIdbDFZbBA==} dev: false diff --git a/src/components/CreatePool/CreateSwapCard.vue b/src/components/CreatePool/CreateSwapCard.vue index eb7ff2e..154f093 100644 --- a/src/components/CreatePool/CreateSwapCard.vue +++ b/src/components/CreatePool/CreateSwapCard.vue @@ -62,14 +62,42 @@ function setPoolMint() {
-
Policy:
+
Swap policy:
+ + +
+ +
+
Liqudity policy:
+ +