Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a reposition contract function on reposition #427

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
eab0ce0
feat: add a reposition contract function on reposition
jinoosss Jun 24, 2024
af5be07
fix: fix component's argument
jinoosss Jun 24, 2024
0083cb5
Merge remote-tracking branch 'origin/develop' into GSW-1193-add-a-rep…
jinoosss Jun 27, 2024
9ca8753
fix: change message arguments
jinoosss Jun 27, 2024
c59ee3f
Merge remote-tracking branch 'origin/develop' into GSW-1193-add-a-rep…
jinoosss Jun 27, 2024
db151cf
Merge remote-tracking branch 'origin/develop' into GSW-1193-add-a-rep…
jinoosss Jul 15, 2024
0f8ae5b
fix: add button state in reposition
jinoosss Jul 15, 2024
3f98a66
Merge remote-tracking branch 'origin/develop' into GSW-1193-add-a-rep…
jinoosss Jul 16, 2024
d963f3c
feat: change wallet response
jinoosss Jul 16, 2024
746e303
Merge remote-tracking branch 'origin/develop' into GSW-1193-add-a-rep…
jinoosss Jul 16, 2024
0066c0c
feat: add non-selected-range button type
jinoosss Jul 16, 2024
53a79c0
fix: apply reposition amount
jinoosss Jul 16, 2024
b41d12e
Merge remote-tracking branch 'origin/develop' into GSW-1193-add-a-rep…
jinoosss Jul 16, 2024
654f21f
fix: build errors
jinoosss Jul 16, 2024
482a20a
Merge remote-tracking branch 'origin/develop' into GSW-1193-add-a-rep…
jinoosss Jul 16, 2024
c16f402
fix: deposit ratio limit amounts
jinoosss Jul 16, 2024
8ea0b4e
fix: initialize price range
jinoosss Jul 16, 2024
530f565
fix: Exception handling when deposit ratio on end
jinoosss Jul 16, 2024
e432c15
feat: swap amount and slippage
AkydA Jul 16, 2024
cd304d3
refactor: remove console log
jinoosss Jul 16, 2024
be08bd6
fix: slippage
AkydA Jul 16, 2024
9c59470
fix: update gnoscan default chain
AkydA Jul 16, 2024
88c4eae
Merge commit '80ecb6d1359b0153d623fd3dc6e3a9b2f0f77e36' into GSW-1193…
AkydA Jul 16, 2024
0cc07b6
fix: Exception handling when deposit ratio on end
jinoosss Jul 16, 2024
b344b04
fix: reset to default range
jinoosss Jul 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,32 @@ export function makePositionIncreaseLiquidityMessage(
});
}

export function makePositionRepositionLiquidityMessage(
lpTokenId: string,
minTick: number,
maxTick: number,
tokenAAmount: string,
tokenBAmount: string,
caller: string,
sendAmount: string | null,
) {
const send = makeGNOTSendAmount(sendAmount);

return makeTransactionMessage({
send,
func: "Reposition",
packagePath: PACKAGE_POSITION_PATH,
args: [
lpTokenId, // LP Token ID
`${minTick}`, // position's minimal tick
`${maxTick}`, // position's maximal tick
`${tokenAAmount}`, // Maximum amount of tokenB to offer
`${tokenBAmount}`, // Maximum amount of tokenA to offer
],
caller,
});
}

export function makePositionDecreaseLiquidityMessage(
lpTokenId: string,
liquidityRatio: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
this.state = { hasError: false };
}

componentDidCatch() {
componentDidCatch(e: any) {
console.log(e);
this.setState({ hasError: true });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import RepositionInfo from "@components/reposition/reposition-info/RepositionInf
import { RANGE_STATUS_OPTION } from "@constants/option.constant";
import { IPriceRange } from "@hooks/increase/use-increase-handle";
import { TokenModel } from "@models/token/token-model";
import {
AddLiquidityFailedResponse,
AddLiquiditySuccessResponse,
} from "@repositories/pool/response/add-liquidity-response";
import {
SwapRouteFailedResponse,
SwapRouteSuccessResponse,
Expand All @@ -18,6 +14,10 @@ import React, { useCallback, useState } from "react";
import Button, { ButtonHierarchy } from "../button/Button";
import IconClose from "../icons/IconCancel";
import { RepositionModalWrapper } from "./RepositionModal.styles";
import {
RepositionLiquidityFailedResponse,
RepositionLiquiditySuccessResponse,
} from "@repositories/position/response";

interface Props {
close: () => void;
Expand Down Expand Up @@ -45,12 +45,13 @@ interface Props {
swapRemainToken: () => Promise<WalletResponse<
SwapRouteSuccessResponse | SwapRouteFailedResponse
> | null>;
addPosition: (
swapToken: TokenModel,
swapAmount: string,
reposition: (
swapToken: TokenModel | null,
swapAmount: string | null,
) => Promise<WalletResponse<
AddLiquiditySuccessResponse | AddLiquidityFailedResponse
RepositionLiquiditySuccessResponse | RepositionLiquidityFailedResponse
> | null>;
isSkipSwap: boolean;
}

const RepositionModal: React.FC<Props> = ({
Expand All @@ -65,7 +66,8 @@ const RepositionModal: React.FC<Props> = ({
repositionAmounts,
removePosition,
swapRemainToken,
addPosition,
reposition,
isSkipSwap,
}) => {
const [confirm, setConfirm] = useState(false);

Expand Down Expand Up @@ -113,10 +115,12 @@ const RepositionModal: React.FC<Props> = ({
<RepositionBroadcastProgress
removePosition={removePosition}
swapRemainToken={swapRemainToken}
addPosition={addPosition}
reposition={reposition}
closeModal={close}
currentAmounts={currentAmounts}
tokenA={amountInfo.tokenA.info}
tokenB={amountInfo.tokenB.info}
isSkipSwap={isSkipSwap}
/>
</React.Fragment>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface SelectPriceRangeCustomProps {
showDim: boolean;
defaultPrice: number | null;
handleSwapValue: () => void;
resetRange?: () => void;
isEmptyLiquidity: boolean;
isKeepToken: boolean;
}
Expand All @@ -43,6 +44,7 @@ const SelectPriceRangeCustom: React.FC<SelectPriceRangeCustomProps> = ({
priceRangeType,
selectPool,
showDim,
resetRange,
handleSwapValue,
isKeepToken,
}) => {
Expand Down Expand Up @@ -234,7 +236,11 @@ const SelectPriceRangeCustom: React.FC<SelectPriceRangeCustomProps> = ({
}
}

function resetRange(priceRangeType?: PriceRangeType | null) {
function onResetRange(priceRangeType?: PriceRangeType | null) {
if (resetRange) {
resetRange();
return;
}
selectPool.resetRange();
setShiftPosition(0);
initPriceRange(priceRangeType);
Expand All @@ -259,7 +265,7 @@ const SelectPriceRangeCustom: React.FC<SelectPriceRangeCustomProps> = ({
}, [tokenA]);

useEffect(() => {
resetRange(priceRangeType);
onResetRange(priceRangeType);
}, [
selectPool.poolPath,
selectPool.feeTier,
Expand Down Expand Up @@ -430,7 +436,7 @@ const SelectPriceRangeCustom: React.FC<SelectPriceRangeCustomProps> = ({
<div className="extra-wrapper">
<div
className="icon-button reset"
onClick={() => resetRange()}
onClick={() => onResetRange()}
>
<IconRefresh />
<span>Reset Range</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface SelectPriceRangeProps {
showDim: boolean;
defaultPrice: number | null;
handleSwapValue: () => void;
resetRange: () => void;
isEmptyLiquidity: boolean;
isKeepToken: boolean;
}
Expand All @@ -41,6 +42,7 @@ const SelectPriceRangeReposition: React.FC<SelectPriceRangeProps> = ({
showDim,
defaultPrice,
handleSwapValue,
resetRange,
isEmptyLiquidity,
isKeepToken,
}) => {
Expand Down Expand Up @@ -78,6 +80,7 @@ const SelectPriceRangeReposition: React.FC<SelectPriceRangeProps> = ({
priceRangeType={priceRange?.type || null}
showDim={showDim}
defaultPrice={defaultPrice}
resetRange={resetRange}
handleSwapValue={handleSwapValue}
isEmptyLiquidity={isEmptyLiquidity}
isKeepToken={isKeepToken}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,47 @@ import {
SwapRouteFailedResponse,
SwapRouteSuccessResponse,
} from "@repositories/swap/response/swap-route-response";
import {
AddLiquidityFailedResponse,
AddLiquiditySuccessResponse,
} from "@repositories/pool/response/add-liquidity-response";
import { TokenModel } from "@models/token/token-model";
import {
RepositionLiquidityFailedResponse,
RepositionLiquiditySuccessResponse,
} from "@repositories/position/response";

export interface RepositionBroadcastProgressProps {
tokenA: TokenModel;
tokenB: TokenModel;
currentAmounts: { amountA: string; amountB: string } | null;
removePosition: () => Promise<WalletResponse | null>;
swapRemainToken: () => Promise<WalletResponse<
SwapRouteSuccessResponse | SwapRouteFailedResponse
> | null>;
addPosition: (
swapToken: TokenModel,
swapAmount: string,
reposition: (
swapToken: TokenModel | null,
swapAmount: string | null,
) => Promise<WalletResponse<
AddLiquiditySuccessResponse | AddLiquidityFailedResponse
RepositionLiquiditySuccessResponse | RepositionLiquidityFailedResponse
> | null>;
closeModal: () => void;
isSkipSwap: boolean;
}

const RepositionBroadcastProgress: React.FC<
RepositionBroadcastProgressProps
> = ({
removePosition,
addPosition,
reposition,
swapRemainToken,
closeModal,
tokenA,
tokenB,
isSkipSwap,
}) => {
const [removePositionState, setRemovePositionState] =
useState<ProgressStateType>("NONE");
const [swapState, setSwapState] = useState<ProgressStateType>("NONE");
const [swapResult, setSwapResult] = useState<SwapRouteSuccessResponse | null>(null);
const [swapResult, setSwapResult] = useState<SwapRouteSuccessResponse | null>(
null,
);
const [addPositionState, setAddPositionState] =
useState<ProgressStateType>("NONE");

Expand Down Expand Up @@ -136,46 +141,51 @@ const RepositionBroadcastProgress: React.FC<

setAddPositionState("WAIT");

if (!swapResult) {
if (!isSkipSwap && !swapResult) {
wait(async () => true, 500).then(() => {
setAddPositionState("INIT");
});
return;
}

addPosition(swapResult.resultToken, swapResult.resultAmount).then(
response => {
if (!response) {
setAddPositionState("FAIL");
return;
}
reposition(
swapResult?.resultToken || null,
swapResult?.resultAmount || null,
).then(response => {
if (!response) {
setAddPositionState("FAIL");
return;
}

if (response.code === 4000) {
setAddPositionState("REJECTED");
return;
}
if (response.code === 4000) {
setAddPositionState("REJECTED");
return;
}

if (response.code !== 0 || response.data === null) {
setAddPositionState("FAIL");
return;
}
if (response.code !== 0 || response.data === null) {
setAddPositionState("FAIL");
return;
}

setAddPositionState("BROADCAST");
wait(async () => true, 1000).then(() => {
setAddPositionState("SUCCESS");
callback();
});
},
);
setAddPositionState("BROADCAST");
wait(async () => true, 1000).then(() => {
setAddPositionState("SUCCESS");
callback();
});
});
};

useEffect(() => {
if (removePositionState === "INIT") {
processRemovePosition(() => {
setSwapState("INIT");
if (isSkipSwap) {
setAddPositionState("INIT");
} else {
setSwapState("INIT");
}
});
}
}, [removePositionState]);
}, [removePositionState, isSkipSwap]);

useEffect(() => {
if (swapState === "INIT") {
Expand Down Expand Up @@ -218,26 +228,29 @@ const RepositionBroadcastProgress: React.FC<

<div className="divider" />

<div className="row">
<div className="progress-info">
<IconSwapCircle active={isActive(swapState)} />
<span
className={makeActiveClassName(
"progress-title",
isActive(swapState),
)}
>
Swap {tokenA.symbol} for {tokenB.symbol}
</span>
</div>
<RepositionBroadcastProgressState
state={swapState}
retry={() => setSwapState("INIT")}
exit={closeModal}
/>
</div>

<div className="divider" />
{!isSkipSwap && (
<React.Fragment>
<div className="row">
<div className="progress-info">
<IconSwapCircle active={isActive(swapState)} />
<span
className={makeActiveClassName(
"progress-title",
isActive(swapState),
)}
>
Swap {tokenA.symbol} for {tokenB.symbol}
</span>
</div>
<RepositionBroadcastProgressState
state={swapState}
retry={() => setSwapState("INIT")}
exit={closeModal}
/>
</div>
<div className="divider" />
</React.Fragment>
)}

<div className="row">
<div className="progress-info">
Expand Down
Loading
Loading