-
-
Save BlockmanCodes/f7f477b81063442f1b80ec0e18117751 to your computer and use it in GitHub Desktop.
Decrease Liquidity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INFURA_URL_TESTNET= | |
WALLET_ADDRESS= | |
WALLET_SECRET= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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