@sodax/dapp-kit 1.5.5-beta → 1.5.7-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +26 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/hooks/dex/useLiquidityAmounts.ts +14 -2
- package/src/utils/dex-utils.ts +17 -11
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sodax/dapp-kit",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.7-beta",
|
|
5
5
|
"description": "dapp-kit of New World",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"viem": "2.29.2",
|
|
19
|
-
"@sodax/sdk": "1.5.
|
|
20
|
-
"@sodax/types": "1.5.
|
|
19
|
+
"@sodax/sdk": "1.5.7-beta",
|
|
20
|
+
"@sodax/types": "1.5.7-beta"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/react": "19.0.8",
|
|
@@ -109,7 +109,13 @@ export function useLiquidityAmounts(
|
|
|
109
109
|
try {
|
|
110
110
|
const amount0BigInt = BigInt(Math.floor(amount0 * 10 ** poolData.token0.decimals));
|
|
111
111
|
|
|
112
|
-
const amount1BigInt = ClService.calculateAmount1FromAmount0(
|
|
112
|
+
const amount1BigInt = ClService.calculateAmount1FromAmount0(
|
|
113
|
+
amount0BigInt,
|
|
114
|
+
tickLower,
|
|
115
|
+
tickUpper,
|
|
116
|
+
currentTick,
|
|
117
|
+
poolData.sqrtPriceX96,
|
|
118
|
+
);
|
|
113
119
|
|
|
114
120
|
const amount1 = Number(amount1BigInt) / 10 ** poolData.token1.decimals;
|
|
115
121
|
setLiquidityToken1Amount(amount1.toFixed(6));
|
|
@@ -140,7 +146,13 @@ export function useLiquidityAmounts(
|
|
|
140
146
|
try {
|
|
141
147
|
const amount1BigInt = BigInt(Math.floor(amount1 * 10 ** poolData.token1.decimals));
|
|
142
148
|
|
|
143
|
-
const amount0BigInt = ClService.calculateAmount0FromAmount1(
|
|
149
|
+
const amount0BigInt = ClService.calculateAmount0FromAmount1(
|
|
150
|
+
amount1BigInt,
|
|
151
|
+
tickLower,
|
|
152
|
+
tickUpper,
|
|
153
|
+
currentTick,
|
|
154
|
+
poolData.sqrtPriceX96,
|
|
155
|
+
);
|
|
144
156
|
|
|
145
157
|
const amount0 = Number(amount0BigInt) / 10 ** poolData.token0.decimals;
|
|
146
158
|
setLiquidityToken0Amount(amount0.toFixed(6));
|
package/src/utils/dex-utils.ts
CHANGED
|
@@ -124,20 +124,26 @@ export function createSupplyLiquidityParamsProps({
|
|
|
124
124
|
const tickLower = ClService.priceToTick(minPriceNum, token0, token1, tickSpacing);
|
|
125
125
|
const tickUpper = ClService.priceToTick(maxPriceNum, token0, token1, tickSpacing);
|
|
126
126
|
|
|
127
|
-
//
|
|
128
|
-
const slippageMultiplier = BigInt(Math.floor((100 - slippage) * 100)); // e.g., 0.5% => 9950
|
|
129
|
-
|
|
130
|
-
const amount0ForLiquidity = (amount0BigInt * slippageMultiplier) / 10000n;
|
|
131
|
-
const amount1ForLiquidity = (amount1BigInt * slippageMultiplier) / 10000n;
|
|
132
|
-
|
|
133
|
-
// Calculate liquidity based on reduced amounts (accounting for slippage)
|
|
127
|
+
// Calculate liquidity from full amounts (the desired deposit)
|
|
134
128
|
const liquidity = ClService.calculateLiquidityFromAmounts(
|
|
135
|
-
|
|
136
|
-
|
|
129
|
+
amount0BigInt,
|
|
130
|
+
amount1BigInt,
|
|
137
131
|
tickLower,
|
|
138
132
|
tickUpper,
|
|
139
133
|
BigInt(poolData.currentTick),
|
|
140
134
|
);
|
|
135
|
+
|
|
136
|
+
// Apply slippage to get max amounts — the ceiling the contract is allowed to pull.
|
|
137
|
+
// If price moves unfavorably, the contract may need slightly more tokens than expected.
|
|
138
|
+
const { amount0Max, amount1Max } = ClService.calculateMaxAmountsForSlippage(
|
|
139
|
+
liquidity,
|
|
140
|
+
tickLower,
|
|
141
|
+
tickUpper,
|
|
142
|
+
BigInt(poolData.currentTick),
|
|
143
|
+
poolData.sqrtPriceX96,
|
|
144
|
+
slippage,
|
|
145
|
+
);
|
|
146
|
+
|
|
141
147
|
const tokenId = positionId ? BigInt(positionId) : undefined;
|
|
142
148
|
|
|
143
149
|
return {
|
|
@@ -145,8 +151,8 @@ export function createSupplyLiquidityParamsProps({
|
|
|
145
151
|
tickLower,
|
|
146
152
|
tickUpper,
|
|
147
153
|
liquidity,
|
|
148
|
-
amount0Max
|
|
149
|
-
amount1Max
|
|
154
|
+
amount0Max,
|
|
155
|
+
amount1Max,
|
|
150
156
|
sqrtPriceX96: poolData.sqrtPriceX96,
|
|
151
157
|
positionId,
|
|
152
158
|
isValidPosition,
|