Skip to content

Instantly share code, notes, and snippets.

@BlockmanCodes
Last active May 7, 2022 14:40
Show Gist options
  • Save BlockmanCodes/f7f477b81063442f1b80ec0e18117751 to your computer and use it in GitHub Desktop.
Save BlockmanCodes/f7f477b81063442f1b80ec0e18117751 to your computer and use it in GitHub Desktop.
Decrease Liquidity
INFURA_URL_TESTNET=
WALLET_ADDRESS=
WALLET_SECRET=
const { ethers } = require('ethers')
const { abi: INonfungiblePositionManagerABI } = require('@uniswap/v3-periphery/artifacts/contracts/interfaces/INonfungiblePositionManager.sol/INonfungiblePositionManager.json')
require('dotenv').config()
const INFURA_URL_TESTNET = process.env.INFURA_URL_TESTNET
const WALLET_ADDRESS = process.env.WALLET_ADDRESS
const WALLET_SECRET = process.env.WALLET_SECRET
const positionManagerAddress = "0xC36442b4a4522E871399CD717aBDD847Ab11FE88" // NonfungiblePositionManager
async function main() {
const provider = new ethers.providers.JsonRpcProvider(INFURA_URL_TESTNET)
const nonFungiblePositionManagerContract = new ethers.Contract(
positionManagerAddress,
INonfungiblePositionManagerABI,
provider
)
const wallet = new ethers.Wallet(WALLET_SECRET)
const connectedWallet = wallet.connect(provider)
nonFungiblePositionManagerContract.connect(connectedWallet).positions(
'99999' // your tokenId
).then((res) => {
const totalLiquidity = res.liquidity.toString()
const halfLiquidity = parseInt(totalLiquidity / 2)
params = {
tokenId: 99999, // your tokenId
liquidity: halfLiquidity,
amount0Min: 0,
amount1Min: 0,
deadline: Math.floor(Date.now() / 1000) + (60 * 10),
}
nonFungiblePositionManagerContract.connect(connectedWallet).decreaseLiquidity(
params,
{ gasLimit: ethers.utils.hexlify(1000000)}
).then((res2) => {
console.log(res2)
})
})
}
main()
{
"name": "uniswap-decrease-liquidity",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@uniswap/v3-sdk": "^3.8.2",
"dotenv": "^16.0.0",
"ethers": "^5.6.5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment