In this image, as you see transaction is sent but failed... I don't know even if I've passed correct arguments or not as there is no example I could find in docs neither I could get any support from zksync discord server nor from syncswap discord server...
export async function depositSyncLP(l2signer: zksync.Signer, provider: ethers.providers.Web3Provider) {
await switchNetwork("zksync", provider);
const syncSwapContract = new zksync.Contract(SYNC_SWAP_ROUTER, SYNC_SWAP_ROUTER_ABI, l2signer);
const syncSwapFactory = new zksync.Contract(SYNC_SWAP_FACTORY, SYNC_SWAP_POOL_FACTORY_ABI, l2signer);
const ethBal = await l2signer.getBalance();
const usdcBal = await l2signer.getBalance(TOKENS_L2_LIST.USDC.toLowerCase());
// 5%
const toDepositInLP = usdcBal.mul(5).div(100);
// 25% of the leftover fees
const amountETHDesired = ethBal.mul(25).div(100);
const POOL_ADDRESS = await syncSwapFactory.getPool(
TOKENS_L2_LIST.USDC.toLowerCase(),
TOKENS_L2_LIST.WETH.toLowerCase()
);
console.log(
`ETH balance to Deposit ------- ${amountETHDesired} from Total ${ethBal} ------- USDC balance to deposit ------- ${toDepositInLP} from Total ${usdcBal} ------- In a Pool ${POOL_ADDRESS}`
);
if (POOL_ADDRESS === ZERO_ADDRESS) {
throw Error("Pool not exists");
}
const tokenInputs = [
{
token: TOKENS_L2_LIST.USDC.toLowerCase(),
amount: toDepositInLP,
},
{
token: TOKENS_L2_LIST.WETH.toLowerCase(),
amount: amountETHDesired,
},
];
const token = TOKENS_L2_LIST.USDC.toLowerCase();
console.log("Approval");
const routerApprovalReceipt = await approveERC20(token, SYNC_SWAP_ROUTER.toLowerCase(), l2signer);
console.log(routerApprovalReceipt);
const approvalReceipt = await approveERC20(token, POOL_ADDRESS, l2signer);
console.log(approvalReceipt);
console.log("Adding liquidity");
const data = await ethers.utils.defaultAbiCoder.encode(["address"], [await l2signer.getAddress()]);
const txn = await syncSwapContract.addLiquidity(POOL_ADDRESS, tokenInputs, data, 0, ZERO_ADDRESS, "0x", {
value: amountETHDesired,
gasLimit: 1400000,
});
console.log(txn);
const receipt = await txn.wait();
console.log(receipt);