diff --git a/.changeset/fluffy-meals-act.md b/.changeset/fluffy-meals-act.md new file mode 100644 index 0000000..03d0d93 --- /dev/null +++ b/.changeset/fluffy-meals-act.md @@ -0,0 +1,5 @@ +--- +'@traderjoe-xyz/sdk-v2': patch +--- + +add v22 diff --git a/packages/v2/src/abis/json/LBQuoterV22.json b/packages/v2/src/abis/json/LBQuoterV22.json new file mode 100644 index 0000000..9ba92fa --- /dev/null +++ b/packages/v2/src/abis/json/LBQuoterV22.json @@ -0,0 +1,197 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "factoryV1", "type": "address" }, + { + "internalType": "address", + "name": "legacyFactoryV2", + "type": "address" + }, + { "internalType": "address", "name": "factoryV2_1", "type": "address" }, + { "internalType": "address", "name": "factoryV2_2", "type": "address" }, + { + "internalType": "address", + "name": "legacyRouterV2", + "type": "address" + }, + { "internalType": "address", "name": "routerV2_1", "type": "address" }, + { "internalType": "address", "name": "routerV2_2", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { "inputs": [], "name": "JoeLibrary__AddressZero", "type": "error" }, + { "inputs": [], "name": "JoeLibrary__IdenticalAddresses", "type": "error" }, + { "inputs": [], "name": "JoeLibrary__InsufficientAmount", "type": "error" }, + { + "inputs": [], + "name": "JoeLibrary__InsufficientLiquidity", + "type": "error" + }, + { "inputs": [], "name": "LBQuoter_InvalidLength", "type": "error" }, + { "inputs": [], "name": "SafeCast__Exceeds128Bits", "type": "error" }, + { "inputs": [], "name": "SafeCast__Exceeds24Bits", "type": "error" }, + { + "inputs": [ + { "internalType": "uint256", "name": "x", "type": "uint256" }, + { "internalType": "int256", "name": "y", "type": "int256" } + ], + "name": "Uint128x128Math__PowUnderflow", + "type": "error" + }, + { "inputs": [], "name": "Uint256x256Math__MulDivOverflow", "type": "error" }, + { + "inputs": [], + "name": "Uint256x256Math__MulShiftOverflow", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address[]", "name": "route", "type": "address[]" }, + { "internalType": "uint128", "name": "amountIn", "type": "uint128" } + ], + "name": "findBestPathFromAmountIn", + "outputs": [ + { + "components": [ + { "internalType": "address[]", "name": "route", "type": "address[]" }, + { "internalType": "address[]", "name": "pairs", "type": "address[]" }, + { + "internalType": "uint256[]", + "name": "binSteps", + "type": "uint256[]" + }, + { + "internalType": "enum ILBRouter.Version[]", + "name": "versions", + "type": "uint8[]" + }, + { + "internalType": "uint128[]", + "name": "amounts", + "type": "uint128[]" + }, + { + "internalType": "uint128[]", + "name": "virtualAmountsWithoutSlippage", + "type": "uint128[]" + }, + { "internalType": "uint128[]", "name": "fees", "type": "uint128[]" } + ], + "internalType": "struct LBQuoter.Quote", + "name": "quote", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address[]", "name": "route", "type": "address[]" }, + { "internalType": "uint128", "name": "amountOut", "type": "uint128" } + ], + "name": "findBestPathFromAmountOut", + "outputs": [ + { + "components": [ + { "internalType": "address[]", "name": "route", "type": "address[]" }, + { "internalType": "address[]", "name": "pairs", "type": "address[]" }, + { + "internalType": "uint256[]", + "name": "binSteps", + "type": "uint256[]" + }, + { + "internalType": "enum ILBRouter.Version[]", + "name": "versions", + "type": "uint8[]" + }, + { + "internalType": "uint128[]", + "name": "amounts", + "type": "uint128[]" + }, + { + "internalType": "uint128[]", + "name": "virtualAmountsWithoutSlippage", + "type": "uint128[]" + }, + { "internalType": "uint128[]", "name": "fees", "type": "uint128[]" } + ], + "internalType": "struct LBQuoter.Quote", + "name": "quote", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getFactoryV1", + "outputs": [ + { "internalType": "address", "name": "factoryV1", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getFactoryV2_1", + "outputs": [ + { "internalType": "address", "name": "factoryV2_1", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getFactoryV2_2", + "outputs": [ + { "internalType": "address", "name": "factoryV2_2", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getLegacyFactoryV2", + "outputs": [ + { + "internalType": "address", + "name": "legacyFactoryV2", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getLegacyRouterV2", + "outputs": [ + { "internalType": "address", "name": "legacyRouterV2", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getRouterV2_1", + "outputs": [ + { "internalType": "address", "name": "routerV2_1", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getRouterV2_2", + "outputs": [ + { "internalType": "address", "name": "routerV2_2", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/packages/v2/src/abis/json/LBRouterV22.json b/packages/v2/src/abis/json/LBRouterV22.json new file mode 100644 index 0000000..ab1eef8 --- /dev/null +++ b/packages/v2/src/abis/json/LBRouterV22.json @@ -0,0 +1,917 @@ +[ + { + "inputs": [ + { + "internalType": "contract ILBFactory", + "name": "factory2_2", + "type": "address" + }, + { + "internalType": "contract IJoeFactory", + "name": "factoryV1", + "type": "address" + }, + { + "internalType": "contract ILBLegacyFactory", + "name": "legacyFactory", + "type": "address" + }, + { + "internalType": "contract ILBLegacyRouter", + "name": "legacyRouter", + "type": "address" + }, + { + "internalType": "contract ILBFactory", + "name": "factory2_1", + "type": "address" + }, + { + "internalType": "contract IWNATIVE", + "name": "wnative", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { "inputs": [], "name": "JoeLibrary__InsufficientAmount", "type": "error" }, + { + "inputs": [], + "name": "JoeLibrary__InsufficientLiquidity", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amountSlippage", "type": "uint256" } + ], + "name": "LBRouter__AmountSlippageBPTooBig", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amountXMin", "type": "uint256" }, + { "internalType": "uint256", "name": "amountX", "type": "uint256" }, + { "internalType": "uint256", "name": "amountYMin", "type": "uint256" }, + { "internalType": "uint256", "name": "amountY", "type": "uint256" } + ], + "name": "LBRouter__AmountSlippageCaught", + "type": "error" + }, + { + "inputs": [{ "internalType": "uint256", "name": "id", "type": "uint256" }], + "name": "LBRouter__BinReserveOverflows", + "type": "error" + }, + { "inputs": [], "name": "LBRouter__BrokenSwapSafetyCheck", "type": "error" }, + { + "inputs": [ + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { + "internalType": "uint256", + "name": "currentTimestamp", + "type": "uint256" + } + ], + "name": "LBRouter__DeadlineExceeded", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "LBRouter__FailedToSendNATIVE", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "idDesired", "type": "uint256" }, + { "internalType": "uint256", "name": "idSlippage", "type": "uint256" } + ], + "name": "LBRouter__IdDesiredOverflows", + "type": "error" + }, + { + "inputs": [{ "internalType": "int256", "name": "id", "type": "int256" }], + "name": "LBRouter__IdOverflows", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "activeIdDesired", + "type": "uint256" + }, + { "internalType": "uint256", "name": "idSlippage", "type": "uint256" }, + { "internalType": "uint256", "name": "activeId", "type": "uint256" } + ], + "name": "LBRouter__IdSlippageCaught", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amountOutMin", "type": "uint256" }, + { "internalType": "uint256", "name": "amountOut", "type": "uint256" } + ], + "name": "LBRouter__InsufficientAmountOut", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "wrongToken", "type": "address" } + ], + "name": "LBRouter__InvalidTokenPath", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "version", "type": "uint256" } + ], + "name": "LBRouter__InvalidVersion", + "type": "error" + }, + { "inputs": [], "name": "LBRouter__LengthsMismatch", "type": "error" }, + { + "inputs": [ + { "internalType": "uint256", "name": "amountInMax", "type": "uint256" }, + { "internalType": "uint256", "name": "amountIn", "type": "uint256" } + ], + "name": "LBRouter__MaxAmountInExceeded", + "type": "error" + }, + { "inputs": [], "name": "LBRouter__NotFactoryOwner", "type": "error" }, + { + "inputs": [ + { "internalType": "address", "name": "tokenX", "type": "address" }, + { "internalType": "address", "name": "tokenY", "type": "address" }, + { "internalType": "uint256", "name": "binStep", "type": "uint256" } + ], + "name": "LBRouter__PairNotCreated", + "type": "error" + }, + { "inputs": [], "name": "LBRouter__SenderIsNotWNATIVE", "type": "error" }, + { + "inputs": [{ "internalType": "uint256", "name": "id", "type": "uint256" }], + "name": "LBRouter__SwapOverflows", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "excess", "type": "uint256" } + ], + "name": "LBRouter__TooMuchTokensIn", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "uint256", "name": "reserve", "type": "uint256" } + ], + "name": "LBRouter__WrongAmounts", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "tokenX", "type": "address" }, + { "internalType": "address", "name": "tokenY", "type": "address" }, + { "internalType": "uint256", "name": "amountX", "type": "uint256" }, + { "internalType": "uint256", "name": "amountY", "type": "uint256" }, + { "internalType": "uint256", "name": "msgValue", "type": "uint256" } + ], + "name": "LBRouter__WrongNativeLiquidityParameters", + "type": "error" + }, + { "inputs": [], "name": "LBRouter__WrongTokenOrder", "type": "error" }, + { "inputs": [], "name": "PackedUint128Math__SubUnderflow", "type": "error" }, + { "inputs": [], "name": "TokenHelper__TransferFailed", "type": "error" }, + { + "inputs": [ + { + "components": [ + { + "internalType": "contract IERC20", + "name": "tokenX", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "tokenY", + "type": "address" + }, + { "internalType": "uint256", "name": "binStep", "type": "uint256" }, + { "internalType": "uint256", "name": "amountX", "type": "uint256" }, + { "internalType": "uint256", "name": "amountY", "type": "uint256" }, + { + "internalType": "uint256", + "name": "amountXMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountYMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "activeIdDesired", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "idSlippage", + "type": "uint256" + }, + { + "internalType": "int256[]", + "name": "deltaIds", + "type": "int256[]" + }, + { + "internalType": "uint256[]", + "name": "distributionX", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "distributionY", + "type": "uint256[]" + }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "address", "name": "refundTo", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "internalType": "struct ILBRouter.LiquidityParameters", + "name": "liquidityParameters", + "type": "tuple" + } + ], + "name": "addLiquidity", + "outputs": [ + { "internalType": "uint256", "name": "amountXAdded", "type": "uint256" }, + { "internalType": "uint256", "name": "amountYAdded", "type": "uint256" }, + { "internalType": "uint256", "name": "amountXLeft", "type": "uint256" }, + { "internalType": "uint256", "name": "amountYLeft", "type": "uint256" }, + { + "internalType": "uint256[]", + "name": "depositIds", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "liquidityMinted", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "contract IERC20", + "name": "tokenX", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "tokenY", + "type": "address" + }, + { "internalType": "uint256", "name": "binStep", "type": "uint256" }, + { "internalType": "uint256", "name": "amountX", "type": "uint256" }, + { "internalType": "uint256", "name": "amountY", "type": "uint256" }, + { + "internalType": "uint256", + "name": "amountXMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountYMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "activeIdDesired", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "idSlippage", + "type": "uint256" + }, + { + "internalType": "int256[]", + "name": "deltaIds", + "type": "int256[]" + }, + { + "internalType": "uint256[]", + "name": "distributionX", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "distributionY", + "type": "uint256[]" + }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "address", "name": "refundTo", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "internalType": "struct ILBRouter.LiquidityParameters", + "name": "liquidityParameters", + "type": "tuple" + } + ], + "name": "addLiquidityNATIVE", + "outputs": [ + { "internalType": "uint256", "name": "amountXAdded", "type": "uint256" }, + { "internalType": "uint256", "name": "amountYAdded", "type": "uint256" }, + { "internalType": "uint256", "name": "amountXLeft", "type": "uint256" }, + { "internalType": "uint256", "name": "amountYLeft", "type": "uint256" }, + { + "internalType": "uint256[]", + "name": "depositIds", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "liquidityMinted", + "type": "uint256[]" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "tokenX", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "tokenY", + "type": "address" + }, + { "internalType": "uint24", "name": "activeId", "type": "uint24" }, + { "internalType": "uint16", "name": "binStep", "type": "uint16" } + ], + "name": "createLBPair", + "outputs": [ + { "internalType": "contract ILBPair", "name": "pair", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "getFactory", + "outputs": [ + { + "internalType": "contract ILBFactory", + "name": "lbFactory", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getFactoryV2_1", + "outputs": [ + { + "internalType": "contract ILBFactory", + "name": "lbFactory", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract ILBPair", "name": "pair", "type": "address" }, + { "internalType": "uint256", "name": "price", "type": "uint256" } + ], + "name": "getIdFromPrice", + "outputs": [{ "internalType": "uint24", "name": "", "type": "uint24" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getLegacyFactory", + "outputs": [ + { + "internalType": "contract ILBLegacyFactory", + "name": "legacyLBfactory", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getLegacyRouter", + "outputs": [ + { + "internalType": "contract ILBLegacyRouter", + "name": "legacyRouter", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract ILBPair", "name": "pair", "type": "address" }, + { "internalType": "uint24", "name": "id", "type": "uint24" } + ], + "name": "getPriceFromId", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract ILBPair", "name": "pair", "type": "address" }, + { "internalType": "uint128", "name": "amountOut", "type": "uint128" }, + { "internalType": "bool", "name": "swapForY", "type": "bool" } + ], + "name": "getSwapIn", + "outputs": [ + { "internalType": "uint128", "name": "amountIn", "type": "uint128" }, + { "internalType": "uint128", "name": "amountOutLeft", "type": "uint128" }, + { "internalType": "uint128", "name": "fee", "type": "uint128" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract ILBPair", "name": "pair", "type": "address" }, + { "internalType": "uint128", "name": "amountIn", "type": "uint128" }, + { "internalType": "bool", "name": "swapForY", "type": "bool" } + ], + "name": "getSwapOut", + "outputs": [ + { "internalType": "uint128", "name": "amountInLeft", "type": "uint128" }, + { "internalType": "uint128", "name": "amountOut", "type": "uint128" }, + { "internalType": "uint128", "name": "fee", "type": "uint128" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getV1Factory", + "outputs": [ + { + "internalType": "contract IJoeFactory", + "name": "factoryV1", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getWNATIVE", + "outputs": [ + { + "internalType": "contract IWNATIVE", + "name": "wnative", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "tokenX", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "tokenY", + "type": "address" + }, + { "internalType": "uint16", "name": "binStep", "type": "uint16" }, + { "internalType": "uint256", "name": "amountXMin", "type": "uint256" }, + { "internalType": "uint256", "name": "amountYMin", "type": "uint256" }, + { "internalType": "uint256[]", "name": "ids", "type": "uint256[]" }, + { "internalType": "uint256[]", "name": "amounts", "type": "uint256[]" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "name": "removeLiquidity", + "outputs": [ + { "internalType": "uint256", "name": "amountX", "type": "uint256" }, + { "internalType": "uint256", "name": "amountY", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "internalType": "uint16", "name": "binStep", "type": "uint16" }, + { + "internalType": "uint256", + "name": "amountTokenMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountNATIVEMin", + "type": "uint256" + }, + { "internalType": "uint256[]", "name": "ids", "type": "uint256[]" }, + { "internalType": "uint256[]", "name": "amounts", "type": "uint256[]" }, + { "internalType": "address payable", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "name": "removeLiquidityNATIVE", + "outputs": [ + { "internalType": "uint256", "name": "amountToken", "type": "uint256" }, + { "internalType": "uint256", "name": "amountNATIVE", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amountOutMin", "type": "uint256" }, + { + "components": [ + { + "internalType": "uint256[]", + "name": "pairBinSteps", + "type": "uint256[]" + }, + { + "internalType": "enum ILBRouter.Version[]", + "name": "versions", + "type": "uint8[]" + }, + { + "internalType": "contract IERC20[]", + "name": "tokenPath", + "type": "address[]" + } + ], + "internalType": "struct ILBRouter.Path", + "name": "path", + "type": "tuple" + }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "name": "swapExactNATIVEForTokens", + "outputs": [ + { "internalType": "uint256", "name": "amountOut", "type": "uint256" } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amountOutMin", "type": "uint256" }, + { + "components": [ + { + "internalType": "uint256[]", + "name": "pairBinSteps", + "type": "uint256[]" + }, + { + "internalType": "enum ILBRouter.Version[]", + "name": "versions", + "type": "uint8[]" + }, + { + "internalType": "contract IERC20[]", + "name": "tokenPath", + "type": "address[]" + } + ], + "internalType": "struct ILBRouter.Path", + "name": "path", + "type": "tuple" + }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "name": "swapExactNATIVEForTokensSupportingFeeOnTransferTokens", + "outputs": [ + { "internalType": "uint256", "name": "amountOut", "type": "uint256" } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amountIn", "type": "uint256" }, + { + "internalType": "uint256", + "name": "amountOutMinNATIVE", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint256[]", + "name": "pairBinSteps", + "type": "uint256[]" + }, + { + "internalType": "enum ILBRouter.Version[]", + "name": "versions", + "type": "uint8[]" + }, + { + "internalType": "contract IERC20[]", + "name": "tokenPath", + "type": "address[]" + } + ], + "internalType": "struct ILBRouter.Path", + "name": "path", + "type": "tuple" + }, + { "internalType": "address payable", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "name": "swapExactTokensForNATIVE", + "outputs": [ + { "internalType": "uint256", "name": "amountOut", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amountIn", "type": "uint256" }, + { + "internalType": "uint256", + "name": "amountOutMinNATIVE", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint256[]", + "name": "pairBinSteps", + "type": "uint256[]" + }, + { + "internalType": "enum ILBRouter.Version[]", + "name": "versions", + "type": "uint8[]" + }, + { + "internalType": "contract IERC20[]", + "name": "tokenPath", + "type": "address[]" + } + ], + "internalType": "struct ILBRouter.Path", + "name": "path", + "type": "tuple" + }, + { "internalType": "address payable", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "name": "swapExactTokensForNATIVESupportingFeeOnTransferTokens", + "outputs": [ + { "internalType": "uint256", "name": "amountOut", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amountIn", "type": "uint256" }, + { "internalType": "uint256", "name": "amountOutMin", "type": "uint256" }, + { + "components": [ + { + "internalType": "uint256[]", + "name": "pairBinSteps", + "type": "uint256[]" + }, + { + "internalType": "enum ILBRouter.Version[]", + "name": "versions", + "type": "uint8[]" + }, + { + "internalType": "contract IERC20[]", + "name": "tokenPath", + "type": "address[]" + } + ], + "internalType": "struct ILBRouter.Path", + "name": "path", + "type": "tuple" + }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "name": "swapExactTokensForTokens", + "outputs": [ + { "internalType": "uint256", "name": "amountOut", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amountIn", "type": "uint256" }, + { "internalType": "uint256", "name": "amountOutMin", "type": "uint256" }, + { + "components": [ + { + "internalType": "uint256[]", + "name": "pairBinSteps", + "type": "uint256[]" + }, + { + "internalType": "enum ILBRouter.Version[]", + "name": "versions", + "type": "uint8[]" + }, + { + "internalType": "contract IERC20[]", + "name": "tokenPath", + "type": "address[]" + } + ], + "internalType": "struct ILBRouter.Path", + "name": "path", + "type": "tuple" + }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "name": "swapExactTokensForTokensSupportingFeeOnTransferTokens", + "outputs": [ + { "internalType": "uint256", "name": "amountOut", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amountOut", "type": "uint256" }, + { + "components": [ + { + "internalType": "uint256[]", + "name": "pairBinSteps", + "type": "uint256[]" + }, + { + "internalType": "enum ILBRouter.Version[]", + "name": "versions", + "type": "uint8[]" + }, + { + "internalType": "contract IERC20[]", + "name": "tokenPath", + "type": "address[]" + } + ], + "internalType": "struct ILBRouter.Path", + "name": "path", + "type": "tuple" + }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "name": "swapNATIVEForExactTokens", + "outputs": [ + { "internalType": "uint256[]", "name": "amountsIn", "type": "uint256[]" } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountNATIVEOut", + "type": "uint256" + }, + { "internalType": "uint256", "name": "amountInMax", "type": "uint256" }, + { + "components": [ + { + "internalType": "uint256[]", + "name": "pairBinSteps", + "type": "uint256[]" + }, + { + "internalType": "enum ILBRouter.Version[]", + "name": "versions", + "type": "uint8[]" + }, + { + "internalType": "contract IERC20[]", + "name": "tokenPath", + "type": "address[]" + } + ], + "internalType": "struct ILBRouter.Path", + "name": "path", + "type": "tuple" + }, + { "internalType": "address payable", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "name": "swapTokensForExactNATIVE", + "outputs": [ + { "internalType": "uint256[]", "name": "amountsIn", "type": "uint256[]" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amountOut", "type": "uint256" }, + { "internalType": "uint256", "name": "amountInMax", "type": "uint256" }, + { + "components": [ + { + "internalType": "uint256[]", + "name": "pairBinSteps", + "type": "uint256[]" + }, + { + "internalType": "enum ILBRouter.Version[]", + "name": "versions", + "type": "uint8[]" + }, + { + "internalType": "contract IERC20[]", + "name": "tokenPath", + "type": "address[]" + } + ], + "internalType": "struct ILBRouter.Path", + "name": "path", + "type": "tuple" + }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "name": "swapTokensForExactTokens", + "outputs": [ + { "internalType": "uint256[]", "name": "amountsIn", "type": "uint256[]" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "sweep", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract ILBToken", + "name": "lbToken", + "type": "address" + }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256[]", "name": "ids", "type": "uint256[]" }, + { "internalType": "uint256[]", "name": "amounts", "type": "uint256[]" } + ], + "name": "sweepLBToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { "stateMutability": "payable", "type": "receive" } +] diff --git a/packages/v2/src/abis/json/index.ts b/packages/v2/src/abis/json/index.ts index eb9a037..6c883f6 100644 --- a/packages/v2/src/abis/json/index.ts +++ b/packages/v2/src/abis/json/index.ts @@ -2,9 +2,11 @@ export { default as LBPairABI } from './LBPair.json' export { default as LBFactoryABI } from './LBFactory.json' export { default as LBRouterABI } from './LBRouter.json' export { default as LBRouterV21ABI } from './LBRouterV21.json' +export { default as LBRouterV22ABI } from './LBRouterV22.json' export { default as DexLensABI } from './DexLens.json' export { default as LBQuoterABI } from './LBQuoter.json' export { default as LBQuoterV21ABI } from './LBQuoterV21.json' +export { default as LBQuoterV22ABI } from './LBQuoterV22.json' export { default as LBRewarderABI } from './LBRewarder.json' export { default as VaultABI } from './Vault.json' export { default as VaultFactoryABI } from './VaultFactory.json' diff --git a/packages/v2/src/abis/ts/LBQuoterV22.ts b/packages/v2/src/abis/ts/LBQuoterV22.ts new file mode 100644 index 0000000..57492af --- /dev/null +++ b/packages/v2/src/abis/ts/LBQuoterV22.ts @@ -0,0 +1,155 @@ +export const LBQuoterV22ABI = [ + { + inputs: [ + { internalType: 'address', name: 'factoryV1', type: 'address' }, + { internalType: 'address', name: 'legacyFactoryV2', type: 'address' }, + { internalType: 'address', name: 'factoryV2_1', type: 'address' }, + { internalType: 'address', name: 'factoryV2_2', type: 'address' }, + { internalType: 'address', name: 'legacyRouterV2', type: 'address' }, + { internalType: 'address', name: 'routerV2_1', type: 'address' }, + { internalType: 'address', name: 'routerV2_2', type: 'address' } + ], + stateMutability: 'nonpayable', + type: 'constructor' + }, + { inputs: [], name: 'JoeLibrary__AddressZero', type: 'error' }, + { inputs: [], name: 'JoeLibrary__IdenticalAddresses', type: 'error' }, + { inputs: [], name: 'JoeLibrary__InsufficientAmount', type: 'error' }, + { inputs: [], name: 'JoeLibrary__InsufficientLiquidity', type: 'error' }, + { inputs: [], name: 'LBQuoter_InvalidLength', type: 'error' }, + { inputs: [], name: 'SafeCast__Exceeds128Bits', type: 'error' }, + { inputs: [], name: 'SafeCast__Exceeds24Bits', type: 'error' }, + { + inputs: [ + { internalType: 'uint256', name: 'x', type: 'uint256' }, + { internalType: 'int256', name: 'y', type: 'int256' } + ], + name: 'Uint128x128Math__PowUnderflow', + type: 'error' + }, + { inputs: [], name: 'Uint256x256Math__MulDivOverflow', type: 'error' }, + { inputs: [], name: 'Uint256x256Math__MulShiftOverflow', type: 'error' }, + { + inputs: [ + { internalType: 'address[]', name: 'route', type: 'address[]' }, + { internalType: 'uint128', name: 'amountIn', type: 'uint128' } + ], + name: 'findBestPathFromAmountIn', + outputs: [ + { + components: [ + { internalType: 'address[]', name: 'route', type: 'address[]' }, + { internalType: 'address[]', name: 'pairs', type: 'address[]' }, + { internalType: 'uint256[]', name: 'binSteps', type: 'uint256[]' }, + { + internalType: 'enum ILBRouter.Version[]', + name: 'versions', + type: 'uint8[]' + }, + { internalType: 'uint128[]', name: 'amounts', type: 'uint128[]' }, + { + internalType: 'uint128[]', + name: 'virtualAmountsWithoutSlippage', + type: 'uint128[]' + }, + { internalType: 'uint128[]', name: 'fees', type: 'uint128[]' } + ], + internalType: 'struct LBQuoter.Quote', + name: 'quote', + type: 'tuple' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { internalType: 'address[]', name: 'route', type: 'address[]' }, + { internalType: 'uint128', name: 'amountOut', type: 'uint128' } + ], + name: 'findBestPathFromAmountOut', + outputs: [ + { + components: [ + { internalType: 'address[]', name: 'route', type: 'address[]' }, + { internalType: 'address[]', name: 'pairs', type: 'address[]' }, + { internalType: 'uint256[]', name: 'binSteps', type: 'uint256[]' }, + { + internalType: 'enum ILBRouter.Version[]', + name: 'versions', + type: 'uint8[]' + }, + { internalType: 'uint128[]', name: 'amounts', type: 'uint128[]' }, + { + internalType: 'uint128[]', + name: 'virtualAmountsWithoutSlippage', + type: 'uint128[]' + }, + { internalType: 'uint128[]', name: 'fees', type: 'uint128[]' } + ], + internalType: 'struct LBQuoter.Quote', + name: 'quote', + type: 'tuple' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'getFactoryV1', + outputs: [{ internalType: 'address', name: 'factoryV1', type: 'address' }], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'getFactoryV2_1', + outputs: [ + { internalType: 'address', name: 'factoryV2_1', type: 'address' } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'getFactoryV2_2', + outputs: [ + { internalType: 'address', name: 'factoryV2_2', type: 'address' } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'getLegacyFactoryV2', + outputs: [ + { internalType: 'address', name: 'legacyFactoryV2', type: 'address' } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'getLegacyRouterV2', + outputs: [ + { internalType: 'address', name: 'legacyRouterV2', type: 'address' } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'getRouterV2_1', + outputs: [{ internalType: 'address', name: 'routerV2_1', type: 'address' }], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'getRouterV2_2', + outputs: [{ internalType: 'address', name: 'routerV2_2', type: 'address' }], + stateMutability: 'view', + type: 'function' + } +] as const diff --git a/packages/v2/src/abis/ts/LBRouterV22.ts b/packages/v2/src/abis/ts/LBRouterV22.ts new file mode 100644 index 0000000..59b9bca --- /dev/null +++ b/packages/v2/src/abis/ts/LBRouterV22.ts @@ -0,0 +1,767 @@ +export const LBRouterV22ABI = [ + { + inputs: [ + { + internalType: 'contract ILBFactory', + name: 'factory2_2', + type: 'address' + }, + { + internalType: 'contract IJoeFactory', + name: 'factoryV1', + type: 'address' + }, + { + internalType: 'contract ILBLegacyFactory', + name: 'legacyFactory', + type: 'address' + }, + { + internalType: 'contract ILBLegacyRouter', + name: 'legacyRouter', + type: 'address' + }, + { + internalType: 'contract ILBFactory', + name: 'factory2_1', + type: 'address' + }, + { internalType: 'contract IWNATIVE', name: 'wnative', type: 'address' } + ], + stateMutability: 'nonpayable', + type: 'constructor' + }, + { inputs: [], name: 'JoeLibrary__InsufficientAmount', type: 'error' }, + { inputs: [], name: 'JoeLibrary__InsufficientLiquidity', type: 'error' }, + { + inputs: [ + { internalType: 'uint256', name: 'amountSlippage', type: 'uint256' } + ], + name: 'LBRouter__AmountSlippageBPTooBig', + type: 'error' + }, + { + inputs: [ + { internalType: 'uint256', name: 'amountXMin', type: 'uint256' }, + { internalType: 'uint256', name: 'amountX', type: 'uint256' }, + { internalType: 'uint256', name: 'amountYMin', type: 'uint256' }, + { internalType: 'uint256', name: 'amountY', type: 'uint256' } + ], + name: 'LBRouter__AmountSlippageCaught', + type: 'error' + }, + { + inputs: [{ internalType: 'uint256', name: 'id', type: 'uint256' }], + name: 'LBRouter__BinReserveOverflows', + type: 'error' + }, + { inputs: [], name: 'LBRouter__BrokenSwapSafetyCheck', type: 'error' }, + { + inputs: [ + { internalType: 'uint256', name: 'deadline', type: 'uint256' }, + { internalType: 'uint256', name: 'currentTimestamp', type: 'uint256' } + ], + name: 'LBRouter__DeadlineExceeded', + type: 'error' + }, + { + inputs: [ + { internalType: 'address', name: 'recipient', type: 'address' }, + { internalType: 'uint256', name: 'amount', type: 'uint256' } + ], + name: 'LBRouter__FailedToSendNATIVE', + type: 'error' + }, + { + inputs: [ + { internalType: 'uint256', name: 'idDesired', type: 'uint256' }, + { internalType: 'uint256', name: 'idSlippage', type: 'uint256' } + ], + name: 'LBRouter__IdDesiredOverflows', + type: 'error' + }, + { + inputs: [{ internalType: 'int256', name: 'id', type: 'int256' }], + name: 'LBRouter__IdOverflows', + type: 'error' + }, + { + inputs: [ + { internalType: 'uint256', name: 'activeIdDesired', type: 'uint256' }, + { internalType: 'uint256', name: 'idSlippage', type: 'uint256' }, + { internalType: 'uint256', name: 'activeId', type: 'uint256' } + ], + name: 'LBRouter__IdSlippageCaught', + type: 'error' + }, + { + inputs: [ + { internalType: 'uint256', name: 'amountOutMin', type: 'uint256' }, + { internalType: 'uint256', name: 'amountOut', type: 'uint256' } + ], + name: 'LBRouter__InsufficientAmountOut', + type: 'error' + }, + { + inputs: [{ internalType: 'address', name: 'wrongToken', type: 'address' }], + name: 'LBRouter__InvalidTokenPath', + type: 'error' + }, + { + inputs: [{ internalType: 'uint256', name: 'version', type: 'uint256' }], + name: 'LBRouter__InvalidVersion', + type: 'error' + }, + { inputs: [], name: 'LBRouter__LengthsMismatch', type: 'error' }, + { + inputs: [ + { internalType: 'uint256', name: 'amountInMax', type: 'uint256' }, + { internalType: 'uint256', name: 'amountIn', type: 'uint256' } + ], + name: 'LBRouter__MaxAmountInExceeded', + type: 'error' + }, + { inputs: [], name: 'LBRouter__NotFactoryOwner', type: 'error' }, + { + inputs: [ + { internalType: 'address', name: 'tokenX', type: 'address' }, + { internalType: 'address', name: 'tokenY', type: 'address' }, + { internalType: 'uint256', name: 'binStep', type: 'uint256' } + ], + name: 'LBRouter__PairNotCreated', + type: 'error' + }, + { inputs: [], name: 'LBRouter__SenderIsNotWNATIVE', type: 'error' }, + { + inputs: [{ internalType: 'uint256', name: 'id', type: 'uint256' }], + name: 'LBRouter__SwapOverflows', + type: 'error' + }, + { + inputs: [{ internalType: 'uint256', name: 'excess', type: 'uint256' }], + name: 'LBRouter__TooMuchTokensIn', + type: 'error' + }, + { + inputs: [ + { internalType: 'uint256', name: 'amount', type: 'uint256' }, + { internalType: 'uint256', name: 'reserve', type: 'uint256' } + ], + name: 'LBRouter__WrongAmounts', + type: 'error' + }, + { + inputs: [ + { internalType: 'address', name: 'tokenX', type: 'address' }, + { internalType: 'address', name: 'tokenY', type: 'address' }, + { internalType: 'uint256', name: 'amountX', type: 'uint256' }, + { internalType: 'uint256', name: 'amountY', type: 'uint256' }, + { internalType: 'uint256', name: 'msgValue', type: 'uint256' } + ], + name: 'LBRouter__WrongNativeLiquidityParameters', + type: 'error' + }, + { inputs: [], name: 'LBRouter__WrongTokenOrder', type: 'error' }, + { inputs: [], name: 'PackedUint128Math__SubUnderflow', type: 'error' }, + { inputs: [], name: 'TokenHelper__TransferFailed', type: 'error' }, + { + inputs: [ + { + components: [ + { internalType: 'contract IERC20', name: 'tokenX', type: 'address' }, + { internalType: 'contract IERC20', name: 'tokenY', type: 'address' }, + { internalType: 'uint256', name: 'binStep', type: 'uint256' }, + { internalType: 'uint256', name: 'amountX', type: 'uint256' }, + { internalType: 'uint256', name: 'amountY', type: 'uint256' }, + { internalType: 'uint256', name: 'amountXMin', type: 'uint256' }, + { internalType: 'uint256', name: 'amountYMin', type: 'uint256' }, + { internalType: 'uint256', name: 'activeIdDesired', type: 'uint256' }, + { internalType: 'uint256', name: 'idSlippage', type: 'uint256' }, + { internalType: 'int256[]', name: 'deltaIds', type: 'int256[]' }, + { + internalType: 'uint256[]', + name: 'distributionX', + type: 'uint256[]' + }, + { + internalType: 'uint256[]', + name: 'distributionY', + type: 'uint256[]' + }, + { internalType: 'address', name: 'to', type: 'address' }, + { internalType: 'address', name: 'refundTo', type: 'address' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' } + ], + internalType: 'struct ILBRouter.LiquidityParameters', + name: 'liquidityParameters', + type: 'tuple' + } + ], + name: 'addLiquidity', + outputs: [ + { internalType: 'uint256', name: 'amountXAdded', type: 'uint256' }, + { internalType: 'uint256', name: 'amountYAdded', type: 'uint256' }, + { internalType: 'uint256', name: 'amountXLeft', type: 'uint256' }, + { internalType: 'uint256', name: 'amountYLeft', type: 'uint256' }, + { internalType: 'uint256[]', name: 'depositIds', type: 'uint256[]' }, + { internalType: 'uint256[]', name: 'liquidityMinted', type: 'uint256[]' } + ], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { + components: [ + { internalType: 'contract IERC20', name: 'tokenX', type: 'address' }, + { internalType: 'contract IERC20', name: 'tokenY', type: 'address' }, + { internalType: 'uint256', name: 'binStep', type: 'uint256' }, + { internalType: 'uint256', name: 'amountX', type: 'uint256' }, + { internalType: 'uint256', name: 'amountY', type: 'uint256' }, + { internalType: 'uint256', name: 'amountXMin', type: 'uint256' }, + { internalType: 'uint256', name: 'amountYMin', type: 'uint256' }, + { internalType: 'uint256', name: 'activeIdDesired', type: 'uint256' }, + { internalType: 'uint256', name: 'idSlippage', type: 'uint256' }, + { internalType: 'int256[]', name: 'deltaIds', type: 'int256[]' }, + { + internalType: 'uint256[]', + name: 'distributionX', + type: 'uint256[]' + }, + { + internalType: 'uint256[]', + name: 'distributionY', + type: 'uint256[]' + }, + { internalType: 'address', name: 'to', type: 'address' }, + { internalType: 'address', name: 'refundTo', type: 'address' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' } + ], + internalType: 'struct ILBRouter.LiquidityParameters', + name: 'liquidityParameters', + type: 'tuple' + } + ], + name: 'addLiquidityNATIVE', + outputs: [ + { internalType: 'uint256', name: 'amountXAdded', type: 'uint256' }, + { internalType: 'uint256', name: 'amountYAdded', type: 'uint256' }, + { internalType: 'uint256', name: 'amountXLeft', type: 'uint256' }, + { internalType: 'uint256', name: 'amountYLeft', type: 'uint256' }, + { internalType: 'uint256[]', name: 'depositIds', type: 'uint256[]' }, + { internalType: 'uint256[]', name: 'liquidityMinted', type: 'uint256[]' } + ], + stateMutability: 'payable', + type: 'function' + }, + { + inputs: [ + { internalType: 'contract IERC20', name: 'tokenX', type: 'address' }, + { internalType: 'contract IERC20', name: 'tokenY', type: 'address' }, + { internalType: 'uint24', name: 'activeId', type: 'uint24' }, + { internalType: 'uint16', name: 'binStep', type: 'uint16' } + ], + name: 'createLBPair', + outputs: [ + { internalType: 'contract ILBPair', name: 'pair', type: 'address' } + ], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [], + name: 'getFactory', + outputs: [ + { + internalType: 'contract ILBFactory', + name: 'lbFactory', + type: 'address' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'getFactoryV2_1', + outputs: [ + { + internalType: 'contract ILBFactory', + name: 'lbFactory', + type: 'address' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { internalType: 'contract ILBPair', name: 'pair', type: 'address' }, + { internalType: 'uint256', name: 'price', type: 'uint256' } + ], + name: 'getIdFromPrice', + outputs: [{ internalType: 'uint24', name: '', type: 'uint24' }], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'getLegacyFactory', + outputs: [ + { + internalType: 'contract ILBLegacyFactory', + name: 'legacyLBfactory', + type: 'address' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'getLegacyRouter', + outputs: [ + { + internalType: 'contract ILBLegacyRouter', + name: 'legacyRouter', + type: 'address' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { internalType: 'contract ILBPair', name: 'pair', type: 'address' }, + { internalType: 'uint24', name: 'id', type: 'uint24' } + ], + name: 'getPriceFromId', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { internalType: 'contract ILBPair', name: 'pair', type: 'address' }, + { internalType: 'uint128', name: 'amountOut', type: 'uint128' }, + { internalType: 'bool', name: 'swapForY', type: 'bool' } + ], + name: 'getSwapIn', + outputs: [ + { internalType: 'uint128', name: 'amountIn', type: 'uint128' }, + { internalType: 'uint128', name: 'amountOutLeft', type: 'uint128' }, + { internalType: 'uint128', name: 'fee', type: 'uint128' } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { internalType: 'contract ILBPair', name: 'pair', type: 'address' }, + { internalType: 'uint128', name: 'amountIn', type: 'uint128' }, + { internalType: 'bool', name: 'swapForY', type: 'bool' } + ], + name: 'getSwapOut', + outputs: [ + { internalType: 'uint128', name: 'amountInLeft', type: 'uint128' }, + { internalType: 'uint128', name: 'amountOut', type: 'uint128' }, + { internalType: 'uint128', name: 'fee', type: 'uint128' } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'getV1Factory', + outputs: [ + { + internalType: 'contract IJoeFactory', + name: 'factoryV1', + type: 'address' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'getWNATIVE', + outputs: [ + { internalType: 'contract IWNATIVE', name: 'wnative', type: 'address' } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { internalType: 'contract IERC20', name: 'tokenX', type: 'address' }, + { internalType: 'contract IERC20', name: 'tokenY', type: 'address' }, + { internalType: 'uint16', name: 'binStep', type: 'uint16' }, + { internalType: 'uint256', name: 'amountXMin', type: 'uint256' }, + { internalType: 'uint256', name: 'amountYMin', type: 'uint256' }, + { internalType: 'uint256[]', name: 'ids', type: 'uint256[]' }, + { internalType: 'uint256[]', name: 'amounts', type: 'uint256[]' }, + { internalType: 'address', name: 'to', type: 'address' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' } + ], + name: 'removeLiquidity', + outputs: [ + { internalType: 'uint256', name: 'amountX', type: 'uint256' }, + { internalType: 'uint256', name: 'amountY', type: 'uint256' } + ], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { internalType: 'contract IERC20', name: 'token', type: 'address' }, + { internalType: 'uint16', name: 'binStep', type: 'uint16' }, + { internalType: 'uint256', name: 'amountTokenMin', type: 'uint256' }, + { internalType: 'uint256', name: 'amountNATIVEMin', type: 'uint256' }, + { internalType: 'uint256[]', name: 'ids', type: 'uint256[]' }, + { internalType: 'uint256[]', name: 'amounts', type: 'uint256[]' }, + { internalType: 'address payable', name: 'to', type: 'address' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' } + ], + name: 'removeLiquidityNATIVE', + outputs: [ + { internalType: 'uint256', name: 'amountToken', type: 'uint256' }, + { internalType: 'uint256', name: 'amountNATIVE', type: 'uint256' } + ], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { internalType: 'uint256', name: 'amountOutMin', type: 'uint256' }, + { + components: [ + { + internalType: 'uint256[]', + name: 'pairBinSteps', + type: 'uint256[]' + }, + { + internalType: 'enum ILBRouter.Version[]', + name: 'versions', + type: 'uint8[]' + }, + { + internalType: 'contract IERC20[]', + name: 'tokenPath', + type: 'address[]' + } + ], + internalType: 'struct ILBRouter.Path', + name: 'path', + type: 'tuple' + }, + { internalType: 'address', name: 'to', type: 'address' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' } + ], + name: 'swapExactNATIVEForTokens', + outputs: [{ internalType: 'uint256', name: 'amountOut', type: 'uint256' }], + stateMutability: 'payable', + type: 'function' + }, + { + inputs: [ + { internalType: 'uint256', name: 'amountOutMin', type: 'uint256' }, + { + components: [ + { + internalType: 'uint256[]', + name: 'pairBinSteps', + type: 'uint256[]' + }, + { + internalType: 'enum ILBRouter.Version[]', + name: 'versions', + type: 'uint8[]' + }, + { + internalType: 'contract IERC20[]', + name: 'tokenPath', + type: 'address[]' + } + ], + internalType: 'struct ILBRouter.Path', + name: 'path', + type: 'tuple' + }, + { internalType: 'address', name: 'to', type: 'address' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' } + ], + name: 'swapExactNATIVEForTokensSupportingFeeOnTransferTokens', + outputs: [{ internalType: 'uint256', name: 'amountOut', type: 'uint256' }], + stateMutability: 'payable', + type: 'function' + }, + { + inputs: [ + { internalType: 'uint256', name: 'amountIn', type: 'uint256' }, + { internalType: 'uint256', name: 'amountOutMinNATIVE', type: 'uint256' }, + { + components: [ + { + internalType: 'uint256[]', + name: 'pairBinSteps', + type: 'uint256[]' + }, + { + internalType: 'enum ILBRouter.Version[]', + name: 'versions', + type: 'uint8[]' + }, + { + internalType: 'contract IERC20[]', + name: 'tokenPath', + type: 'address[]' + } + ], + internalType: 'struct ILBRouter.Path', + name: 'path', + type: 'tuple' + }, + { internalType: 'address payable', name: 'to', type: 'address' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' } + ], + name: 'swapExactTokensForNATIVE', + outputs: [{ internalType: 'uint256', name: 'amountOut', type: 'uint256' }], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { internalType: 'uint256', name: 'amountIn', type: 'uint256' }, + { internalType: 'uint256', name: 'amountOutMinNATIVE', type: 'uint256' }, + { + components: [ + { + internalType: 'uint256[]', + name: 'pairBinSteps', + type: 'uint256[]' + }, + { + internalType: 'enum ILBRouter.Version[]', + name: 'versions', + type: 'uint8[]' + }, + { + internalType: 'contract IERC20[]', + name: 'tokenPath', + type: 'address[]' + } + ], + internalType: 'struct ILBRouter.Path', + name: 'path', + type: 'tuple' + }, + { internalType: 'address payable', name: 'to', type: 'address' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' } + ], + name: 'swapExactTokensForNATIVESupportingFeeOnTransferTokens', + outputs: [{ internalType: 'uint256', name: 'amountOut', type: 'uint256' }], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { internalType: 'uint256', name: 'amountIn', type: 'uint256' }, + { internalType: 'uint256', name: 'amountOutMin', type: 'uint256' }, + { + components: [ + { + internalType: 'uint256[]', + name: 'pairBinSteps', + type: 'uint256[]' + }, + { + internalType: 'enum ILBRouter.Version[]', + name: 'versions', + type: 'uint8[]' + }, + { + internalType: 'contract IERC20[]', + name: 'tokenPath', + type: 'address[]' + } + ], + internalType: 'struct ILBRouter.Path', + name: 'path', + type: 'tuple' + }, + { internalType: 'address', name: 'to', type: 'address' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' } + ], + name: 'swapExactTokensForTokens', + outputs: [{ internalType: 'uint256', name: 'amountOut', type: 'uint256' }], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { internalType: 'uint256', name: 'amountIn', type: 'uint256' }, + { internalType: 'uint256', name: 'amountOutMin', type: 'uint256' }, + { + components: [ + { + internalType: 'uint256[]', + name: 'pairBinSteps', + type: 'uint256[]' + }, + { + internalType: 'enum ILBRouter.Version[]', + name: 'versions', + type: 'uint8[]' + }, + { + internalType: 'contract IERC20[]', + name: 'tokenPath', + type: 'address[]' + } + ], + internalType: 'struct ILBRouter.Path', + name: 'path', + type: 'tuple' + }, + { internalType: 'address', name: 'to', type: 'address' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' } + ], + name: 'swapExactTokensForTokensSupportingFeeOnTransferTokens', + outputs: [{ internalType: 'uint256', name: 'amountOut', type: 'uint256' }], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { internalType: 'uint256', name: 'amountOut', type: 'uint256' }, + { + components: [ + { + internalType: 'uint256[]', + name: 'pairBinSteps', + type: 'uint256[]' + }, + { + internalType: 'enum ILBRouter.Version[]', + name: 'versions', + type: 'uint8[]' + }, + { + internalType: 'contract IERC20[]', + name: 'tokenPath', + type: 'address[]' + } + ], + internalType: 'struct ILBRouter.Path', + name: 'path', + type: 'tuple' + }, + { internalType: 'address', name: 'to', type: 'address' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' } + ], + name: 'swapNATIVEForExactTokens', + outputs: [ + { internalType: 'uint256[]', name: 'amountsIn', type: 'uint256[]' } + ], + stateMutability: 'payable', + type: 'function' + }, + { + inputs: [ + { internalType: 'uint256', name: 'amountNATIVEOut', type: 'uint256' }, + { internalType: 'uint256', name: 'amountInMax', type: 'uint256' }, + { + components: [ + { + internalType: 'uint256[]', + name: 'pairBinSteps', + type: 'uint256[]' + }, + { + internalType: 'enum ILBRouter.Version[]', + name: 'versions', + type: 'uint8[]' + }, + { + internalType: 'contract IERC20[]', + name: 'tokenPath', + type: 'address[]' + } + ], + internalType: 'struct ILBRouter.Path', + name: 'path', + type: 'tuple' + }, + { internalType: 'address payable', name: 'to', type: 'address' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' } + ], + name: 'swapTokensForExactNATIVE', + outputs: [ + { internalType: 'uint256[]', name: 'amountsIn', type: 'uint256[]' } + ], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { internalType: 'uint256', name: 'amountOut', type: 'uint256' }, + { internalType: 'uint256', name: 'amountInMax', type: 'uint256' }, + { + components: [ + { + internalType: 'uint256[]', + name: 'pairBinSteps', + type: 'uint256[]' + }, + { + internalType: 'enum ILBRouter.Version[]', + name: 'versions', + type: 'uint8[]' + }, + { + internalType: 'contract IERC20[]', + name: 'tokenPath', + type: 'address[]' + } + ], + internalType: 'struct ILBRouter.Path', + name: 'path', + type: 'tuple' + }, + { internalType: 'address', name: 'to', type: 'address' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' } + ], + name: 'swapTokensForExactTokens', + outputs: [ + { internalType: 'uint256[]', name: 'amountsIn', type: 'uint256[]' } + ], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { internalType: 'contract IERC20', name: 'token', type: 'address' }, + { internalType: 'address', name: 'to', type: 'address' }, + { internalType: 'uint256', name: 'amount', type: 'uint256' } + ], + name: 'sweep', + outputs: [], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { internalType: 'contract ILBToken', name: 'lbToken', type: 'address' }, + { internalType: 'address', name: 'to', type: 'address' }, + { internalType: 'uint256[]', name: 'ids', type: 'uint256[]' }, + { internalType: 'uint256[]', name: 'amounts', type: 'uint256[]' } + ], + name: 'sweepLBToken', + outputs: [], + stateMutability: 'nonpayable', + type: 'function' + }, + { stateMutability: 'payable', type: 'receive' } +] as const diff --git a/packages/v2/src/abis/ts/index.ts b/packages/v2/src/abis/ts/index.ts index 9e9592a..575ee35 100644 --- a/packages/v2/src/abis/ts/index.ts +++ b/packages/v2/src/abis/ts/index.ts @@ -3,8 +3,10 @@ export * from './LBFactory' export * from './LBPair' export * from './LBQuoter' export * from './LBQuoterV21' +export * from './LBQuoterV22' export * from './LBRouter' export * from './LBRouterV21' +export * from './LBRouterV22' export * from './LBRewarder' export * from './Vault' export * from './VaultFactory' diff --git a/packages/v2/src/constants/v2Addrs.ts b/packages/v2/src/constants/v2Addrs.ts index 2cbb59e..849753c 100644 --- a/packages/v2/src/constants/v2Addrs.ts +++ b/packages/v2/src/constants/v2Addrs.ts @@ -34,6 +34,17 @@ export const LB_QUOTER_V21_ADDRESS: { [chainId in ChainId]: Hex } = { [ChainId.BNB_CHAIN]: '0xd76019A16606FDa4651f636D9751f500Ed776250', [ChainId.BNB_TESTNET]: '0xd76019A16606FDa4651f636D9751f500Ed776250', [ChainId.ETHEREUM]: '0x4d6Dbd1b52807C71b9a148E222b167247a7cA789', + [ChainId.MANTLE]: '0x0000000000000000000000000000000000000000' +} + +export const LB_QUOTER_V22_ADDRESS: { [chainId in ChainId]: Hex } = { + [ChainId.FUJI]: '0x9A550a522BBaDFB69019b0432800Ed17855A51C3', + [ChainId.AVALANCHE]: '0x9A550a522BBaDFB69019b0432800Ed17855A51C3', + [ChainId.ARBITRUM_ONE]: '0x9A550a522BBaDFB69019b0432800Ed17855A51C3', + [ChainId.ARB_GOERLI]: '0x0000000000000000000000000000000000000000', + [ChainId.BNB_CHAIN]: '0x0000000000000000000000000000000000000000', + [ChainId.BNB_TESTNET]: '0x0000000000000000000000000000000000000000', + [ChainId.ETHEREUM]: '0x0000000000000000000000000000000000000000', [ChainId.MANTLE]: '0xE25Dc29b856D5A6dF45B5D854ccF9223D716f46d' } @@ -56,6 +67,17 @@ export const LB_ROUTER_V21_ADDRESS: { [chainId in ChainId]: Hex } = { [ChainId.BNB_CHAIN]: '0xb4315e873dBcf96Ffd0acd8EA43f689D8c20fB30', [ChainId.BNB_TESTNET]: '0x8FABE13D95F28f7478Dc655d8D4BA99935D50e02', [ChainId.ETHEREUM]: '0x9A93a421b74F1c5755b83dD2C211614dC419C44b', + [ChainId.MANTLE]: '0x0000000000000000000000000000000000000000' +} + +export const LB_ROUTER_V22_ADDRESS: { [chainId in ChainId]: Hex } = { + [ChainId.FUJI]: '0x18556DA13313f3532c54711497A8FedAC273220E', + [ChainId.AVALANCHE]: '0x18556DA13313f3532c54711497A8FedAC273220E', + [ChainId.ARBITRUM_ONE]: '0x18556DA13313f3532c54711497A8FedAC273220E', + [ChainId.ARB_GOERLI]: '0x0000000000000000000000000000000000000000', + [ChainId.BNB_CHAIN]: '0x0000000000000000000000000000000000000000', + [ChainId.BNB_TESTNET]: '0x0000000000000000000000000000000000000000', + [ChainId.ETHEREUM]: '0x0000000000000000000000000000000000000000', [ChainId.MANTLE]: '0xAFb85a12Babfafabfe1a518594492d5a830e782a' } @@ -78,6 +100,17 @@ export const LB_FACTORY_V21_ADDRESS: { [chainId in ChainId]: Hex } = { [ChainId.BNB_CHAIN]: '0x8e42f2F4101563bF679975178e880FD87d3eFd4e', [ChainId.BNB_TESTNET]: '0x8e42f2F4101563bF679975178e880FD87d3eFd4e', [ChainId.ETHEREUM]: '0xDC8d77b69155c7E68A95a4fb0f06a71FF90B943a', + [ChainId.MANTLE]: '0x0000000000000000000000000000000000000000' +} + +export const LB_FACTORY_V22_ADDRESS: { [chainId in ChainId]: Hex } = { + [ChainId.FUJI]: '0xb43120c4745967fa9b93E79C149E66B0f2D6Fe0c', + [ChainId.AVALANCHE]: '0xb43120c4745967fa9b93E79C149E66B0f2D6Fe0c', + [ChainId.ARBITRUM_ONE]: '0xb43120c4745967fa9b93E79C149E66B0f2D6Fe0c', + [ChainId.ARB_GOERLI]: '0x0000000000000000000000000000000000000000', + [ChainId.BNB_CHAIN]: '0x0000000000000000000000000000000000000000', + [ChainId.BNB_TESTNET]: '0x0000000000000000000000000000000000000000', + [ChainId.ETHEREUM]: '0x0000000000000000000000000000000000000000', [ChainId.MANTLE]: '0xa6630671775c4EA2743840F9A5016dCf2A104054' } @@ -150,3 +183,14 @@ export const APT_FARM_LENS: { [chainId in ChainId]: Hex } = { [ChainId.ETHEREUM]: '0x0000000000000000000000000000000000000000', [ChainId.MANTLE]: '0x0000000000000000000000000000000000000000' } + +export const LB_HOOKS_LENS_ADDRESS: { [chainId in ChainId]: Hex } = { + [ChainId.FUJI]: '0xFe439C9b95c659d4B8a0aF580Ae992Ae63E0aDE5', + [ChainId.AVALANCHE]: '0xFe439C9b95c659d4B8a0aF580Ae992Ae63E0aDE5', + [ChainId.ARBITRUM_ONE]: '0xFe439C9b95c659d4B8a0aF580Ae992Ae63E0aDE5', + [ChainId.ARB_GOERLI]: '0x0000000000000000000000000000000000000000', + [ChainId.BNB_CHAIN]: '0x0000000000000000000000000000000000000000', + [ChainId.BNB_TESTNET]: '0x0000000000000000000000000000000000000000', + [ChainId.ETHEREUM]: '0x0000000000000000000000000000000000000000', + [ChainId.MANTLE]: '0x93185784e04D8B5a0aDe98d80C48AA06B9689Ee8' +} diff --git a/packages/v2/src/index.ts b/packages/v2/src/index.ts index 8c6b8af..6420ba8 100644 --- a/packages/v2/src/index.ts +++ b/packages/v2/src/index.ts @@ -6,10 +6,13 @@ export { JSBI } export { LB_QUOTER_ADDRESS, LB_QUOTER_V21_ADDRESS, + LB_QUOTER_V22_ADDRESS, LB_ROUTER_ADDRESS, LB_ROUTER_V21_ADDRESS, + LB_ROUTER_V22_ADDRESS, LB_FACTORY_ADDRESS, LB_FACTORY_V21_ADDRESS, + LB_FACTORY_V22_ADDRESS, DEX_V2_SUBGRAPH, DEXCANDLES_SUBGRAPH_V2, DEXLENS_ADDRESS, @@ -17,7 +20,8 @@ export { VAULT_FACTORY_ADDRESS, LIQUIDITY_AMOUNTS_HELPER_ADDRESS, LIMIT_ORDER_MANAGER_ADDRESS, - APT_FARM_LENS + APT_FARM_LENS, + LB_HOOKS_LENS_ADDRESS } from './constants' export * from './abis/ts' diff --git a/packages/v2/src/types/trade.ts b/packages/v2/src/types/trade.ts index 471d9c9..0ec128c 100644 --- a/packages/v2/src/types/trade.ts +++ b/packages/v2/src/types/trade.ts @@ -4,7 +4,8 @@ import { Hex } from 'viem' export enum PoolVersion { V1 = 0, V2 = 1, - V2_1 = 2 + V2_1 = 2, + V2_2 = 3 } /** Interface representing a quote */ diff --git a/packages/v2/src/v2entities/pair.test.ts b/packages/v2/src/v2entities/pair.test.ts index e6fd755..eebce33 100644 --- a/packages/v2/src/v2entities/pair.test.ts +++ b/packages/v2/src/v2entities/pair.test.ts @@ -38,26 +38,26 @@ describe('PairV2 entity', () => { }) it('can fetch all available v2 LBPairs', async () => { - const LBPairs = await pair1.fetchAvailableLBPairs(false, CLIENT, CHAIN_ID) + const LBPairs = await pair1.fetchAvailableLBPairs('v2', CLIENT, CHAIN_ID) expect(LBPairs.length).toBeGreaterThan(0) }) it('can fetch single v2 LBPair given the bin step', async () => { const binStep = 10 - const LBPair = await pair1.fetchLBPair(binStep, false, CLIENT, CHAIN_ID) + const LBPair = await pair1.fetchLBPair(binStep, 'v2', CLIENT, CHAIN_ID) expect(LBPair.binStep).toEqual(binStep) expect(LBPair.LBPair).not.toBeUndefined() }) it('can fetch all available v2.1 LBPairs', async () => { - const LBPairs = await pair1.fetchAvailableLBPairs(true, CLIENT, CHAIN_ID) + const LBPairs = await pair1.fetchAvailableLBPairs('v21', CLIENT, CHAIN_ID) expect(LBPairs.length).toBeGreaterThan(0) }) it('can fetch single v2.1 LBPair given the bin step', async () => { - const binStep = 10 - const LBPair = await pair1.fetchLBPair(binStep, false, CLIENT, CHAIN_ID) - expect(LBPair.binStep).toEqual(binStep) + const binStep = 20 + const LBPair = await pair1.fetchLBPair(binStep, 'v21', CLIENT, CHAIN_ID) + expect(LBPair.binStep).toEqual(20) expect(LBPair.LBPair).not.toBeUndefined() }) @@ -99,12 +99,11 @@ describe('PairV2 entity', () => { describe('PairV2.getLBPairReservesAndId()', () => { it('can fetch LBPair v2 reserves and activeId', async () => { const binStep = 10 - const isV21 = false - const LBPair = await pair1.fetchLBPair(binStep, isV21, CLIENT, CHAIN_ID) + const LBPair = await pair1.fetchLBPair(binStep, 'v2', CLIENT, CHAIN_ID) const lbPairData = await PairV2.getLBPairReservesAndId( LBPair.LBPair, - isV21, + 'v2', CLIENT ) @@ -115,12 +114,11 @@ describe('PairV2 entity', () => { it('can fetch LBPair v2.1 reserves and activeId', async () => { const binStep = 20 - const isV21 = true - const LBPair = await pair1.fetchLBPair(binStep, isV21, CLIENT, CHAIN_ID) + const LBPair = await pair1.fetchLBPair(binStep, 'v21', CLIENT, CHAIN_ID) const lbPairData = await PairV2.getLBPairReservesAndId( LBPair.LBPair, - isV21, + 'v21', CLIENT ) @@ -133,7 +131,7 @@ describe('PairV2 entity', () => { describe('PairV2.getFeeParameters()', () => { it('can fetch LBPair fee parameters', async () => { const binStep = 10 - const LBPair = await pair1.fetchLBPair(binStep, false, CLIENT, CHAIN_ID) + const LBPair = await pair1.fetchLBPair(binStep, 'v2', CLIENT, CHAIN_ID) const lbPairFeeParams = await PairV2.getFeeParameters( LBPair.LBPair, diff --git a/packages/v2/src/v2entities/pair.ts b/packages/v2/src/v2entities/pair.ts index f544e56..9a350f0 100644 --- a/packages/v2/src/v2entities/pair.ts +++ b/packages/v2/src/v2entities/pair.ts @@ -16,7 +16,11 @@ import { LiquidityDistribution, BinReserves } from '../types' -import { LB_FACTORY_ADDRESS, LB_FACTORY_V21_ADDRESS } from '../constants' +import { + LB_FACTORY_ADDRESS, + LB_FACTORY_V21_ADDRESS, + LB_FACTORY_V22_ADDRESS +} from '../constants' import { Bin } from './bin' import { getLiquidityConfig } from '../utils' @@ -46,13 +50,13 @@ export class PairV2 { /** * Returns all available LBPairs for this pair * - * @param {boolean} isV21 + * @param {'v2' | 'v21' | 'v22'} version * @param {PublicClient} publicClient * @param {ChainId} chainId * @returns {Promise} */ public async fetchAvailableLBPairs( - isV21: boolean, + version: 'v2' | 'v21' | 'v22', publicClient: PublicClient, chainId: ChainId ): Promise { @@ -61,33 +65,43 @@ export class PairV2 { getAddress(this.token1.address) ] as const - return isV21 - ? await publicClient.readContract({ + switch (version) { + case 'v2': + return await publicClient.readContract({ + abi: LBFactoryABI, + address: LB_FACTORY_ADDRESS[chainId], + functionName: 'getAllLBPairs', + args + }) + case 'v21': + return await publicClient.readContract({ abi: LBFactoryV21ABI, address: LB_FACTORY_V21_ADDRESS[chainId], functionName: 'getAllLBPairs', args }) - : await publicClient.readContract({ - abi: LBFactoryABI, - address: LB_FACTORY_ADDRESS[chainId], + case 'v22': + return await publicClient.readContract({ + abi: LBFactoryV21ABI, + address: LB_FACTORY_V22_ADDRESS[chainId], functionName: 'getAllLBPairs', args }) + } } /** * Fetches LBPair for token0, token1, and given binStep * * @param {number} binStep - * @param {boolean} isV21 + * @param {'v2' | 'v21' | 'v22'} version * @param {PublicClient} publicClient * @param {ChainId} chainId * @returns {Promise} */ public async fetchLBPair( binStep: number, - isV21: boolean, + version: 'v2' | 'v21' | 'v22', publicClient: PublicClient, chainId: ChainId ): Promise { @@ -97,24 +111,29 @@ export class PairV2 { BigInt(binStep) ] as const - let lbPair: LBPair - if (isV21) { - lbPair = await publicClient.readContract({ - abi: LBFactoryV21ABI, - address: LB_FACTORY_V21_ADDRESS[chainId], - functionName: 'getLBPairInformation', - args - }) - } else { - lbPair = await publicClient.readContract({ - abi: LBFactoryABI, - address: LB_FACTORY_ADDRESS[chainId], - functionName: 'getLBPairInformation', - args - }) + switch (version) { + case 'v2': + return await publicClient.readContract({ + abi: LBFactoryABI, + address: LB_FACTORY_ADDRESS[chainId], + functionName: 'getLBPairInformation', + args + }) + case 'v21': + return await publicClient.readContract({ + abi: LBFactoryV21ABI, + address: LB_FACTORY_V21_ADDRESS[chainId], + functionName: 'getLBPairInformation', + args + }) + case 'v22': + return await publicClient.readContract({ + abi: LBFactoryV21ABI, + address: LB_FACTORY_V22_ADDRESS[chainId], + functionName: 'getLBPairInformation', + args + }) } - - return lbPair } /** @@ -195,44 +214,49 @@ export class PairV2 { * Fetches the reserves active bin id for the LBPair * * @param {Hex} LBPairAddr - * @param {boolean} isV21 + * @param {'v2' | 'v21' | 'v22'} version * @param {PublicClient} publicClient * @returns {Promise} */ public static async getLBPairReservesAndId( LBPairAddr: Hex, - isV21: boolean, + version: 'v2' | 'v21' | 'v22', publicClient: PublicClient ): Promise { - if (isV21) { - const [reserveX, reserveY] = await publicClient.readContract({ - abi: LBPairV21ABI, - address: LBPairAddr, - functionName: 'getReserves' - }) - const activeId = await publicClient.readContract({ - abi: LBPairV21ABI, - address: LBPairAddr, - functionName: 'getActiveId' - }) - - return { - reserveX, - reserveY, - activeId - } - } - - const [reserveX, reserveY, activeId] = await publicClient.readContract({ - abi: LBPairABI, - address: LBPairAddr, - functionName: 'getReservesAndId' - }) + switch (version) { + case 'v2': { + const [reserveX, reserveY, activeId] = await publicClient.readContract({ + abi: LBPairABI, + address: LBPairAddr, + functionName: 'getReservesAndId' + }) - return { - reserveX, - reserveY, - activeId: Number(activeId) + return { + reserveX, + reserveY, + activeId: Number(activeId) + } + } + case 'v21': + case 'v22': + const [[reserveX, reserveY], activeId] = await Promise.all([ + publicClient.readContract({ + abi: LBPairV21ABI, + address: LBPairAddr, + functionName: 'getReserves' + }), + publicClient.readContract({ + abi: LBPairV21ABI, + address: LBPairAddr, + functionName: 'getActiveId' + }) + ]) + + return { + reserveX, + reserveY, + activeId + } } } diff --git a/packages/v2/src/v2entities/trade.ts b/packages/v2/src/v2entities/trade.ts index 5f90d57..36e910a 100644 --- a/packages/v2/src/v2entities/trade.ts +++ b/packages/v2/src/v2entities/trade.ts @@ -18,6 +18,8 @@ import { RouteV2 } from './route' import { LB_QUOTER_V21_ADDRESS, LB_ROUTER_V21_ADDRESS, + LB_QUOTER_V22_ADDRESS, + LB_ROUTER_V22_ADDRESS, ZERO_HEX } from '../constants' import { toHex, validateAndParseAddress, isZero } from '../utils' @@ -30,8 +32,13 @@ import { RouterPathParameters } from '../types' -import { LBQuoterV21ABI, LBRouterV21ABI } from '../abis/ts' -import { Hex, PublicClient, encodeFunctionData } from 'viem' +import { + LBQuoterV21ABI, + LBRouterV21ABI, + LBQuoterV22ABI, + LBRouterV22ABI +} from '../abis/ts' +import { Hex, PublicClient, encodeFunctionData, zeroAddress } from 'viem' /** Class representing a trade */ export class TradeV2 { @@ -309,12 +316,18 @@ export class TradeV2 { const { methodName, args, value }: SwapParameters = this.swapCallParameters(options) + const useV22 = LB_ROUTER_V22_ADDRESS[chainId] !== zeroAddress + const routerAddress = useV22 + ? LB_ROUTER_V22_ADDRESS[chainId] + : LB_ROUTER_V21_ADDRESS[chainId] + const abi = useV22 ? LBRouterV22ABI : LBRouterV21ABI + const gasEstimate = await publicClient.estimateGas({ blockTag: 'latest', account, - to: LB_ROUTER_V21_ADDRESS[chainId], + to: routerAddress, data: encodeFunctionData({ - abi: LBRouterV21ABI, + abi, functionName: methodName as any, args: args as any }), @@ -360,10 +373,17 @@ export class TradeV2 { const amountIn = BigInt(tokenAmountIn.raw.toString()) try { + const useV22 = LB_QUOTER_V22_ADDRESS[chainId] !== zeroAddress + const quoterAddress = useV22 + ? LB_QUOTER_V22_ADDRESS[chainId] + : LB_QUOTER_V21_ADDRESS[chainId] + + const abi = useV22 ? LBQuoterV22ABI : LBQuoterV21ABI + const calls = routes.map((route) => { return { - abi: LBQuoterV21ABI, - address: LB_QUOTER_V21_ADDRESS[chainId], + abi, + address: quoterAddress, functionName: 'findBestPathFromAmountIn', args: [route.pathToStrArr(), amountIn] } as const @@ -434,10 +454,17 @@ export class TradeV2 { const amountOut = BigInt(tokenAmountOut.raw.toString()) try { + const useV22 = LB_QUOTER_V22_ADDRESS[chainId] !== zeroAddress + const quoterAddress = useV22 + ? LB_QUOTER_V22_ADDRESS[chainId] + : LB_QUOTER_V21_ADDRESS[chainId] + + const abi = useV22 ? LBQuoterV22ABI : LBQuoterV21ABI + const calls = routes.map((route) => { return { - abi: LBQuoterV21ABI, - address: LB_QUOTER_V21_ADDRESS[chainId], + abi, + address: quoterAddress, functionName: 'findBestPathFromAmountOut', args: [route.pathToStrArr(), amountOut] } as const