Skip to content

Commit

Permalink
uni - new pool native-token
Browse files Browse the repository at this point in the history
  • Loading branch information
shendel committed Sep 26, 2024
1 parent c768961 commit 3bd5a3e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ function AddLiquidity(props) {
}

const toWei = (token_type:TOKEN, amount:any): BigNumber => {
return new BigNumber(amount)
.multipliedBy(10 ** ((token_type == TOKEN._0) ? token0.decimals : token1.decimals))
return new BigNumber(
new BigNumber(amount)
.multipliedBy(10 ** ((token_type == TOKEN._0) ? token0.decimals : token1.decimals))
.toFixed(0)
)
}

const token0BalanceOk = token0BalanceWei.isGreaterThanOrEqualTo(toWei(TOKEN._0, amount0))
Expand Down
25 changes: 14 additions & 11 deletions src/front/shared/pages/Exchange/QuickSwap/univ3/MintPosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,11 @@ function MintPosition(props) {
}

const toWei = (token_type:TOKEN, amount:any): BigNumber => {
return new BigNumber(amount)
.multipliedBy(10 ** ((token_type == TOKEN._0) ? token0.decimals : token1.decimals))
return new BigNumber(
new BigNumber(amount)
.multipliedBy(10 ** ((token_type == TOKEN._0) ? token0.decimals : token1.decimals))
.toFixed(0)
)
}


Expand Down Expand Up @@ -324,19 +327,19 @@ function MintPosition(props) {
priceHigh: token0HighPrice,
priceLow: token0LowerPrice,
}).toNumber()
const _amount1 = new BigNumber(amount).dividedBy(perTokenPrice).toNumber()
const _amount1 = new BigNumber(amount).dividedBy(perTokenPrice).toFixed(token1.decimals)
setAmount0(amount)
setAmount1(_amount1)
setAmount1(Number(_amount1))
}
if (token == TOKEN._1) {
const _amount0 = actions.uniswap.addLiquidityV3CalcAmount({
amountIn: amount,
price: startPrice,
priceHigh: token0HighPrice,
priceLow: token0LowerPrice,
}).toNumber()
}).toFixed(token0.decimals)
console.log('>>> _amount0', _amount0)
setAmount0(_amount0)
setAmount0(Number(_amount0))
setAmount1(amount)
}
} else {
Expand All @@ -347,8 +350,8 @@ function MintPosition(props) {
priceHigh: token1HighPrice,
priceLow: token1LowerPrice,
}).toNumber()
const _amount0 = new BigNumber(amount).dividedBy(perTokenPrice).toNumber()
setAmount0(_amount0)
const _amount0 = new BigNumber(amount).dividedBy(perTokenPrice).toFixed(token0.decimals)
setAmount0(Number(_amount0))
setAmount1(amount)
}
if (token == TOKEN._0) {
Expand All @@ -357,8 +360,8 @@ function MintPosition(props) {
price: startPrice,
priceHigh: token1HighPrice,
priceLow: token1LowerPrice,
}).toNumber()
setAmount1(_amount1)
}).toFixed(token1.decimals)
setAmount1(Number(_amount1))
setAmount0(amount)
}
}
Expand All @@ -381,7 +384,7 @@ function MintPosition(props) {

const handleCreatePosition = () => {
const amount0Wei = toWei(TOKEN._0, amount0).toString()
const amount1Wei = toWei(TOKEN._0, amount1).toString()
const amount1Wei = toWei(TOKEN._1, amount1).toString()

const {
tick: tickCurrent,
Expand Down
51 changes: 31 additions & 20 deletions src/front/shared/redux/actions/uniswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,25 +574,33 @@ const mintPositionV3 = async (params) => {
const deadline = await getDeadline(provider, deadlinePeriod * 60)

const callsDataSource = [
...((!poolExists) ? [[ 'createAndInitializePoolIfNecessary', [
token0Address,
token1Address,
fee,
sqrtPriceX96,
]]] : []),
[ 'mint', [[
token0Address,
token1Address,
fee,
tickLower,
tickUpper,
amount0Wei,
amount1Wei,
amount0Min.toString(),
amount1Min.toString(),
owner,
deadline,
]]],
...((!poolExists) ? [
[ 'createAndInitializePoolIfNecessary', [
token0Address,
token1Address,
fee,
sqrtPriceX96
]
]
] : []),
[ 'mint', [
[
token0Address,
token1Address,
fee,
tickLower,
tickUpper,
amount0Wei,
amount1Wei,
amount0Min.toString(),
amount1Min.toString(),
owner,
deadline
]
]],
...((isWrappedToken0 || isWrappedToken1) ? [
[ 'refundETH', []]
] : []),
]

console.log('>>> callsDataSource', callsDataSource)
Expand All @@ -601,7 +609,8 @@ const mintPositionV3 = async (params) => {
return positionsInterface.encodeFunctionData(func, args)
})
console.log('>>> callsData', callsData)

console.log('>>> nativeWei', nativeWei.toFixed(0))

const txData = positionsContract.methods.multicall(callsData).encodeABI()
const sendParams = {
to: positionsContractAddress,
Expand All @@ -610,8 +619,10 @@ const mintPositionV3 = async (params) => {
amount: `0x`+new BigNumber(nativeWei.toFixed(0)).toString(16),
amountInWei: true,
}


return actions[baseCurrency.toLowerCase()].send(sendParams)

}

const getUserPoolLiquidityV3 = async (params) => {
Expand Down

0 comments on commit 3bd5a3e

Please sign in to comment.