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: Migrate position burn to decrease liquidity #325

Merged
merged 2 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -45,12 +45,48 @@ export function makePositionMintMessage(
});
}

export function makePositionBurnMessage(lpTokenId: string, caller: string) {
export function makePositionIncreaseLiquidityMessage(
lpTokenId: string,
amount0Desired: number,
amount1Desired: number,
amount0Min: number,
amount1Min: number,
caller: string,
) {
return makeTransactionMessage({
send: "",
func: "Burn",
func: "IncreaseLiquidity",
packagePath: PACKAGE_POSITION_PATH,
args: [lpTokenId],
args: [
lpTokenId, // LP Token ID
`${amount0Desired}`, // Maximum amount of tokenA to offer
`${amount1Desired}`, // Maximum amount of tokenB to offer
`${amount0Min}`, // Minimum amount of tokenA to provide
`${amount1Min}`, // Minimum amount of tokenB to provide
"9999999999", // Deadline UTC time
],
caller,
});
}

export function makePositionDecreaseLiquidityMessage(
lpTokenId: string,
liquidityRatio: number,
existWrappedToken: boolean,
caller: string,
) {
return makeTransactionMessage({
send: "",
func: "DecreaseLiquidity",
packagePath: PACKAGE_POSITION_PATH,
args: [
lpTokenId, // LP Token ID
`${liquidityRatio}`, // Percentage of liquidity to reduce (0 ~ 100)
"0", // Minimum quantity of tokenA to decrease liquidity
"0", // Minimum quantity of tokenB to decrease liquidity
"9999999999", // Deadline UTC time
`${existWrappedToken}`, // Whether to receive wrapped tokens as native tokens
],
caller,
});
}
Expand Down
14 changes: 11 additions & 3 deletions packages/web/src/repositories/position/position-repository-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
makeUnstakeMessage,
} from "@common/clients/wallet-client/transaction-messages/staker";
import {
makePositionBurnMessage,
makePositionDecreaseLiquidityMessage,
makePositionCollectFeeMessage,
} from "@common/clients/wallet-client/transaction-messages/position";

Expand All @@ -42,7 +42,9 @@ export class PositionRepositoryImpl implements PositionRepository {
}

getPositionsByAddress = async (address: string): Promise<PositionModel[]> => {
const response = await this.networkClient.get<{ data: PositionListResponse }>({
const response = await this.networkClient.get<{
data: PositionListResponse;
}>({
url: "/users/" + address + "/position",
});
return PositionMapper.fromList(response.data.data);
Expand Down Expand Up @@ -127,8 +129,14 @@ export class PositionRepositoryImpl implements PositionRepository {
throw new CommonError("FAILED_INITIALIZE_WALLET");
}
const { lpTokenIds, caller } = request;
const decreaseLiquidityRatio = 100;
const messages = lpTokenIds.map(lpTokenId =>
makePositionBurnMessage(lpTokenId, caller),
makePositionDecreaseLiquidityMessage(
lpTokenId,
decreaseLiquidityRatio,
true,
caller,
),
);
const result = await this.walletClient.sendTransaction({
messages,
Expand Down
Loading