I'm trying to mint a new position with this function:
export const newMint = async (
token0: string,
token1: string,
fee: number,
tickLower: number,
tickUpper: number,
amount0Desired: string,
amount1Desired: string,
amount0Min: number,
amount1Min: number,
recipient: string,
deadline: number
) => {
try {
const signer = new ethers.providers.Web3Provider(window.ethereum).getSigner()
const nonfungible = new ethers.Contract(
nftAddress,
positionManagerABI,
signer
)
const data = ethers.utils.defaultAbiCoder.encode(
[
"address",
"address",
'uint24',
'int24',
'int24',
'uint256',
'uint256',
'uint256',
'uint256',
'address',
'uint256'
],
[
token0,
token1,
fee,
tickLower,
tickUpper,
amount0Desired,
amount1Desired,
amount0Min,
amount1Min,
recipient,
deadline
]
)
nonfungible.mint(data)
} catch (error) {
console.log(error, "this is the error for newMinting")
console.log(
token0,
token1,
fee,
tickLower,
tickUpper,
amount0Desired,
amount1Desired,
amount0Min,
amount1Min,
recipient,
deadline
)
}
}
I'm calling it correctly through this call:
const addLiquidity = () => {
newMint(
token0,
token1,
3000,
-887220,
887220,
String(Number(ethers.utils.parseEther(formattedAmounts[Field.INPUT])) * ether),
String(Number(ethers.utils.parseEther(formattedAmounts[Field.OUTPUT])) * ether),
0,
0,
userAddress,
tS + 3000
)
}
Getting the timestamp through this function:
export const timestamp = async () => {
try {
const block = await provider.getBlock('latest')
return block
} catch (error) {
console.log(error, 'error for timestamp')
}
}
I think that everything is ok with the params, the problem is to encode the struct:
struct MintParams {
address token0;
address token1;
uint24 fee;
int24 tickLower;
int24 tickUpper;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
address recipient;
uint256 deadline;
}
My idea is that ethers.utils.defaultAbiCoder.encode
does not fit as the best approach. Can someone give me a hint over this?
The error:
Error: unexpected character at position 46 (argument="param", value="struct INonfungiblePositionManager.MintParams params", code=INVALID_ARGUMENT, version=abi/5.6.1)