-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1004 from madfish-solutions/QUIPU-322-logic-remov…
…e-liq-form QUIPU-322 logic for remove liq form
- Loading branch information
Showing
45 changed files
with
593 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './get-new-liquidity-list.api'; | ||
export * from './get-new-liquidity-stats.api'; | ||
export * from './add-dex-two-liquidity.api'; | ||
export * from './remove-dex-two-liquidity.api'; | ||
export * from './create-new-liquidity-pool.api'; |
31 changes: 31 additions & 0 deletions
31
src/modules/new-liquidity/api/remove-dex-two-liquidity.api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { TezosToolkit } from '@taquito/taquito'; | ||
import { BigNumber } from 'bignumber.js'; | ||
|
||
import { sendBatch } from '@blockchain'; | ||
import { ZERO_BAKER_ADDRESS } from '@config/constants'; | ||
import { DEX_TWO_CONTRACT_ADDRESS } from '@config/environment'; | ||
import { AmountToken } from '@shared/types'; | ||
|
||
export const removeDexTwoLiquidityApi = async ( | ||
tezos: TezosToolkit, | ||
shares: BigNumber, | ||
tokensAndAmounts: Array<AmountToken>, | ||
deadline: string, | ||
accountPkh: string, | ||
candidate: string, | ||
itemId: BigNumber | ||
) => { | ||
if (!candidate) { | ||
candidate = ZERO_BAKER_ADDRESS; | ||
} | ||
|
||
const dexTwoContract = await tezos.wallet.at(DEX_TWO_CONTRACT_ADDRESS); | ||
|
||
const [tokenA, tokenB] = tokensAndAmounts; | ||
|
||
const dexTwoLiquidityParams = dexTwoContract.methods | ||
.divest_liquidity(itemId, tokenA.amount, tokenB.amount, shares, accountPkh, candidate, deadline) | ||
.toTransferParams(); | ||
|
||
return await sendBatch(tezos, [dexTwoLiquidityParams]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import BigNumber from 'bignumber.js'; | ||
|
||
import { isTezosToken } from '@shared/helpers'; | ||
import { AmountToken } from '@shared/types'; | ||
|
||
const ZERO_BN = new BigNumber('0'); | ||
|
||
export const getTezValue = (tokensAndAmounts: Array<AmountToken>) => { | ||
return tokensAndAmounts.find(item => isTezosToken(item.token))?.amount ?? ZERO_BN; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import BigNumber from 'bignumber.js'; | ||
|
||
import { PERCENTAGE_100 } from '@config/constants'; | ||
|
||
export const getValueWithFee = (value: BigNumber, fee: BigNumber.Value) => { | ||
const percentFee = new BigNumber(fee).multipliedBy(PERCENTAGE_100); | ||
|
||
return value.multipliedBy(PERCENTAGE_100.minus(percentFee)).dividedBy(PERCENTAGE_100); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from './is-hot-pool.helper'; | ||
export * from './is-hot-pool'; | ||
export * from './get-value-with-fee'; | ||
export * from './get-tez-value'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './use-add-liquidity'; | ||
export * from './use-remove-liquidity'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/modules/new-liquidity/hooks/blockchain/use-remove-liquidity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import BigNumber from 'bignumber.js'; | ||
import { FormikValues } from 'formik'; | ||
|
||
import { FISRT_INDEX } from '@config/constants'; | ||
import { LP_TOKEN } from '@modules/new-liquidity/pages/item/components/forms/helpers/mock-lp-token'; | ||
import { useRootStore } from '@providers/root-store-provider'; | ||
import { useAccountPkh } from '@providers/use-dapp'; | ||
import { | ||
decreaseBySlippage, | ||
extractTokens, | ||
getTransactionDeadline, | ||
isExist, | ||
isNull, | ||
isTezosToken, | ||
sortTokens, | ||
toAtomic | ||
} from '@shared/helpers'; | ||
import { useSettingsStore } from '@shared/hooks/use-settings-store'; | ||
import { tokensAndAmountsMapper } from '@shared/mapping'; | ||
import { useConfirmOperation, useToasts } from '@shared/utils'; | ||
import { useTranslation } from '@translation'; | ||
|
||
import { removeDexTwoLiquidityApi } from '../../api'; | ||
import { useNewLiquidityItemStore } from '../store'; | ||
|
||
export const useRemoveLiquidity = () => { | ||
const { tezos } = useRootStore(); | ||
const { showErrorToast } = useToasts(); | ||
const confirmOperation = useConfirmOperation(); | ||
const { t } = useTranslation(); | ||
const { | ||
settings: { transactionDeadline, liquiditySlippage } | ||
} = useSettingsStore(); | ||
const accountPkh = useAccountPkh(); | ||
const { item } = useNewLiquidityItemStore(); | ||
|
||
const removeLiquidity = async (inputAmounts: FormikValues, shares: BigNumber) => { | ||
if (isNull(tezos) || !isExist(item) || isNull(accountPkh) || !inputAmounts.every(isExist)) { | ||
return; | ||
} | ||
const itemId = item.id; | ||
const tokens = extractTokens(item.tokensInfo); | ||
|
||
const atomicAndDecresedInputAmounts = inputAmounts.map((amount: BigNumber, index: number) => | ||
decreaseBySlippage(toAtomic(amount, tokens[index]), liquiditySlippage).minus(1).integerValue(BigNumber.ROUND_DOWN) | ||
); | ||
|
||
const tokensAndAmounts = tokensAndAmountsMapper(tokens, atomicAndDecresedInputAmounts).sort((a, b) => | ||
sortTokens(a.token, b.token) | ||
); | ||
|
||
if (isTezosToken(tokensAndAmounts[FISRT_INDEX].token)) { | ||
tokensAndAmounts.reverse(); | ||
} | ||
|
||
const atomicLpTokenBalance = toAtomic(shares, LP_TOKEN).integerValue(BigNumber.ROUND_DOWN); | ||
|
||
const deadline = await getTransactionDeadline(tezos, transactionDeadline); | ||
|
||
try { | ||
const operation = await removeDexTwoLiquidityApi( | ||
tezos, | ||
atomicLpTokenBalance, | ||
tokensAndAmounts, | ||
deadline, | ||
accountPkh, | ||
item.currentDelegate, | ||
itemId | ||
); | ||
await confirmOperation(operation.opHash, { message: t('newLiquidity|successfullyRemoved') }); | ||
} catch (error) { | ||
showErrorToast(error as Error); | ||
} | ||
}; | ||
|
||
return { removeLiquidity }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
...-liquidity/pages/item/components/forms/add-liq-form/use-dex-two-add-liq-form.interface.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.