Skip to content

Add swap fee #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ The RouterLogic contract implements the logic for swapping tokens using a route.

The RouterAdapter contract provides helper functions for interacting with different types of pairs, including Uniswap V2, LFJ Legacy Liquidity Book, LFJ Liquidity Book, Uniswap V3 pairs, and LFJ Token Mill pairs.

### ForwarderLogic.sol

The ForwarderLogic contract serves as a utility for forwarding calls to a third-party router contract. It simplifies user interactions by eliminating the need for repeated token approvals. Additionally, it enhances security by ensuring that users do not overpay or receive less than the expected amount of tokens during transactions. This contract acts as a safeguard, providing a seamless and secure experience when interacting with external router contracts.

## Libraries

### TokenLib.sol
Expand Down
1 change: 1 addition & 0 deletions abis/FeeLogic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"type": "function", "name": "getProtocolFeeRecipient", "inputs": [], "outputs": [{"name": "", "type": "address", "internalType": "address"}], "stateMutability": "view"}, {"type": "function", "name": "getProtocolFeeShare", "inputs": [], "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}], "stateMutability": "view"}, {"type": "function", "name": "setProtocolFeeParameters", "inputs": [{"name": "feeReceiver", "type": "address", "internalType": "address"}, {"name": "feeShare", "type": "uint96", "internalType": "uint96"}], "outputs": [], "stateMutability": "nonpayable"}, {"type": "event", "name": "FeeSent", "inputs": [{"name": "token", "type": "address", "indexed": true, "internalType": "address"}, {"name": "feeRecipient", "type": "address", "indexed": true, "internalType": "address"}, {"name": "feeAmount", "type": "uint256", "indexed": false, "internalType": "uint256"}, {"name": "protocolFeeAmount", "type": "uint256", "indexed": false, "internalType": "uint256"}], "anonymous": false}, {"type": "event", "name": "ProtocolFeeParametersSet", "inputs": [{"name": "sender", "type": "address", "indexed": true, "internalType": "address"}, {"name": "protocolFeeReceiver", "type": "address", "indexed": true, "internalType": "address"}, {"name": "protocolFeeShare", "type": "uint96", "indexed": false, "internalType": "uint96"}], "anonymous": false}, {"type": "error", "name": "FeeLogic__InvalidFeeReceiver", "inputs": []}, {"type": "error", "name": "FeeLogic__InvalidFrom", "inputs": []}, {"type": "error", "name": "FeeLogic__InvalidProtocolFeeReceiver", "inputs": []}, {"type": "error", "name": "FeeLogic__InvalidProtocolFeeShare", "inputs": []}]
2 changes: 1 addition & 1 deletion abis/ForwarderLogic.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"type": "constructor", "inputs": [{"name": "router", "type": "address", "internalType": "address"}], "stateMutability": "nonpayable"}, {"type": "function", "name": "getTrustedRouterAt", "inputs": [{"name": "index", "type": "uint256", "internalType": "uint256"}], "outputs": [{"name": "", "type": "address", "internalType": "address"}], "stateMutability": "view"}, {"type": "function", "name": "getTrustedRouterLength", "inputs": [], "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}], "stateMutability": "view"}, {"type": "function", "name": "swapExactIn", "inputs": [{"name": "tokenIn", "type": "address", "internalType": "address"}, {"name": "tokenOut", "type": "address", "internalType": "address"}, {"name": "amountIn", "type": "uint256", "internalType": "uint256"}, {"name": "", "type": "uint256", "internalType": "uint256"}, {"name": "from", "type": "address", "internalType": "address"}, {"name": "to", "type": "address", "internalType": "address"}, {"name": "data", "type": "bytes", "internalType": "bytes"}], "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}, {"name": "", "type": "uint256", "internalType": "uint256"}], "stateMutability": "nonpayable"}, {"type": "function", "name": "swapExactOut", "inputs": [{"name": "", "type": "address", "internalType": "address"}, {"name": "", "type": "address", "internalType": "address"}, {"name": "", "type": "uint256", "internalType": "uint256"}, {"name": "", "type": "uint256", "internalType": "uint256"}, {"name": "", "type": "address", "internalType": "address"}, {"name": "", "type": "address", "internalType": "address"}, {"name": "", "type": "bytes", "internalType": "bytes"}], "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}, {"name": "", "type": "uint256", "internalType": "uint256"}], "stateMutability": "pure"}, {"type": "function", "name": "sweep", "inputs": [{"name": "token", "type": "address", "internalType": "address"}, {"name": "to", "type": "address", "internalType": "address"}, {"name": "amount", "type": "uint256", "internalType": "uint256"}], "outputs": [], "stateMutability": "nonpayable"}, {"type": "function", "name": "updateTrustedRouter", "inputs": [{"name": "router", "type": "address", "internalType": "address"}, {"name": "add", "type": "bool", "internalType": "bool"}], "outputs": [], "stateMutability": "nonpayable"}, {"type": "event", "name": "TrustedRouterUpdated", "inputs": [{"name": "router", "type": "address", "indexed": true, "internalType": "address"}, {"name": "trusted", "type": "bool", "indexed": false, "internalType": "bool"}], "anonymous": false}, {"type": "error", "name": "AddressEmptyCode", "inputs": [{"name": "target", "type": "address", "internalType": "address"}]}, {"type": "error", "name": "AddressInsufficientBalance", "inputs": [{"name": "account", "type": "address", "internalType": "address"}]}, {"type": "error", "name": "FailedInnerCall", "inputs": []}, {"type": "error", "name": "ForwarderLogic__InvalidRouter", "inputs": []}, {"type": "error", "name": "ForwarderLogic__NoCode", "inputs": []}, {"type": "error", "name": "ForwarderLogic__NotImplemented", "inputs": []}, {"type": "error", "name": "ForwarderLogic__OnlyRouter", "inputs": []}, {"type": "error", "name": "ForwarderLogic__OnlyRouterOwner", "inputs": []}, {"type": "error", "name": "ForwarderLogic__RouterUpdateFailed", "inputs": []}, {"type": "error", "name": "ForwarderLogic__UntrustedRouter", "inputs": []}, {"type": "error", "name": "SafeERC20FailedOperation", "inputs": [{"name": "token", "type": "address", "internalType": "address"}]}, {"type": "error", "name": "TokenLib__BalanceOfFailed", "inputs": []}, {"type": "error", "name": "TokenLib__NativeTransferFailed", "inputs": []}, {"type": "error", "name": "TokenLib__TransferFailed", "inputs": []}]
[{"type": "constructor", "inputs": [{"name": "router", "type": "address", "internalType": "address"}, {"name": "protocolFeeReceiver", "type": "address", "internalType": "address"}, {"name": "protocolFeeShare", "type": "uint96", "internalType": "uint96"}], "stateMutability": "nonpayable"}, {"type": "function", "name": "getProtocolFeeRecipient", "inputs": [], "outputs": [{"name": "", "type": "address", "internalType": "address"}], "stateMutability": "view"}, {"type": "function", "name": "getProtocolFeeShare", "inputs": [], "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}], "stateMutability": "view"}, {"type": "function", "name": "getTrustedRouterAt", "inputs": [{"name": "index", "type": "uint256", "internalType": "uint256"}], "outputs": [{"name": "", "type": "address", "internalType": "address"}], "stateMutability": "view"}, {"type": "function", "name": "getTrustedRouterLength", "inputs": [], "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}], "stateMutability": "view"}, {"type": "function", "name": "isBlacklisted", "inputs": [{"name": "account", "type": "address", "internalType": "address"}], "outputs": [{"name": "", "type": "bool", "internalType": "bool"}], "stateMutability": "view"}, {"type": "function", "name": "setProtocolFeeParameters", "inputs": [{"name": "feeReceiver", "type": "address", "internalType": "address"}, {"name": "feeShare", "type": "uint96", "internalType": "uint96"}], "outputs": [], "stateMutability": "nonpayable"}, {"type": "function", "name": "swapExactIn", "inputs": [{"name": "tokenIn", "type": "address", "internalType": "address"}, {"name": "tokenOut", "type": "address", "internalType": "address"}, {"name": "amountIn", "type": "uint256", "internalType": "uint256"}, {"name": "", "type": "uint256", "internalType": "uint256"}, {"name": "from", "type": "address", "internalType": "address"}, {"name": "to", "type": "address", "internalType": "address"}, {"name": "data", "type": "bytes", "internalType": "bytes"}], "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}, {"name": "", "type": "uint256", "internalType": "uint256"}], "stateMutability": "nonpayable"}, {"type": "function", "name": "swapExactOut", "inputs": [{"name": "", "type": "address", "internalType": "address"}, {"name": "", "type": "address", "internalType": "address"}, {"name": "", "type": "uint256", "internalType": "uint256"}, {"name": "", "type": "uint256", "internalType": "uint256"}, {"name": "", "type": "address", "internalType": "address"}, {"name": "", "type": "address", "internalType": "address"}, {"name": "", "type": "bytes", "internalType": "bytes"}], "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}, {"name": "", "type": "uint256", "internalType": "uint256"}], "stateMutability": "pure"}, {"type": "function", "name": "sweep", "inputs": [{"name": "token", "type": "address", "internalType": "address"}, {"name": "to", "type": "address", "internalType": "address"}, {"name": "amount", "type": "uint256", "internalType": "uint256"}], "outputs": [], "stateMutability": "nonpayable"}, {"type": "function", "name": "updateBlacklist", "inputs": [{"name": "account", "type": "address", "internalType": "address"}, {"name": "blacklisted", "type": "bool", "internalType": "bool"}], "outputs": [], "stateMutability": "nonpayable"}, {"type": "function", "name": "updateTrustedRouter", "inputs": [{"name": "router", "type": "address", "internalType": "address"}, {"name": "add", "type": "bool", "internalType": "bool"}], "outputs": [], "stateMutability": "nonpayable"}, {"type": "event", "name": "BlacklistUpdated", "inputs": [{"name": "account", "type": "address", "indexed": true, "internalType": "address"}, {"name": "blacklisted", "type": "bool", "indexed": false, "internalType": "bool"}], "anonymous": false}, {"type": "event", "name": "FeeSent", "inputs": [{"name": "token", "type": "address", "indexed": true, "internalType": "address"}, {"name": "feeRecipient", "type": "address", "indexed": true, "internalType": "address"}, {"name": "feeAmount", "type": "uint256", "indexed": false, "internalType": "uint256"}, {"name": "protocolFeeAmount", "type": "uint256", "indexed": false, "internalType": "uint256"}], "anonymous": false}, {"type": "event", "name": "ProtocolFeeParametersSet", "inputs": [{"name": "sender", "type": "address", "indexed": true, "internalType": "address"}, {"name": "protocolFeeReceiver", "type": "address", "indexed": true, "internalType": "address"}, {"name": "protocolFeeShare", "type": "uint96", "indexed": false, "internalType": "uint96"}], "anonymous": false}, {"type": "event", "name": "TrustedRouterUpdated", "inputs": [{"name": "router", "type": "address", "indexed": true, "internalType": "address"}, {"name": "trusted", "type": "bool", "indexed": false, "internalType": "bool"}], "anonymous": false}, {"type": "error", "name": "AddressEmptyCode", "inputs": [{"name": "target", "type": "address", "internalType": "address"}]}, {"type": "error", "name": "AddressInsufficientBalance", "inputs": [{"name": "account", "type": "address", "internalType": "address"}]}, {"type": "error", "name": "FailedInnerCall", "inputs": []}, {"type": "error", "name": "FeeLogic__InvalidFeeReceiver", "inputs": []}, {"type": "error", "name": "FeeLogic__InvalidFrom", "inputs": []}, {"type": "error", "name": "FeeLogic__InvalidProtocolFeeReceiver", "inputs": []}, {"type": "error", "name": "FeeLogic__InvalidProtocolFeeShare", "inputs": []}, {"type": "error", "name": "ForwarderLogic__Blacklisted", "inputs": []}, {"type": "error", "name": "ForwarderLogic__InvalidRouter", "inputs": []}, {"type": "error", "name": "ForwarderLogic__NoCode", "inputs": []}, {"type": "error", "name": "ForwarderLogic__NotImplemented", "inputs": []}, {"type": "error", "name": "ForwarderLogic__OnlyRouter", "inputs": []}, {"type": "error", "name": "ForwarderLogic__OnlyRouterOwner", "inputs": []}, {"type": "error", "name": "ForwarderLogic__RouterUpdateFailed", "inputs": []}, {"type": "error", "name": "ForwarderLogic__UntrustedRouter", "inputs": []}, {"type": "error", "name": "SafeERC20FailedOperation", "inputs": [{"name": "token", "type": "address", "internalType": "address"}]}, {"type": "error", "name": "TokenLib__BalanceOfFailed", "inputs": []}, {"type": "error", "name": "TokenLib__NativeTransferFailed", "inputs": []}, {"type": "error", "name": "TokenLib__TransferFailed", "inputs": []}]
2 changes: 1 addition & 1 deletion abis/RouterAdapter.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"type": "function", "name": "uniswapV3SwapCallback", "inputs": [{"name": "amount0Delta", "type": "int256", "internalType": "int256"}, {"name": "amount1Delta", "type": "int256", "internalType": "int256"}, {"name": "data", "type": "bytes", "internalType": "bytes"}], "outputs": [], "stateMutability": "nonpayable"}, {"type": "error", "name": "RouterAdapter__InsufficientLBLiquidity", "inputs": []}, {"type": "error", "name": "RouterAdapter__InsufficientTMLiquidity", "inputs": []}, {"type": "error", "name": "RouterAdapter__InvalidId", "inputs": []}, {"type": "error", "name": "RouterAdapter__UnexpectedAmountIn", "inputs": []}, {"type": "error", "name": "RouterAdapter__UnexpectedCallback", "inputs": []}, {"type": "error", "name": "RouterAdapter__UniswapV3SwapCallbackOnly", "inputs": [{"name": "amount0Delta", "type": "int256", "internalType": "int256"}, {"name": "amount1Delta", "type": "int256", "internalType": "int256"}]}, {"type": "error", "name": "TokenLib__TransferFailed", "inputs": []}]
[{"type": "fallback", "stateMutability": "nonpayable"}, {"type": "error", "name": "PairInteraction__InvalidReturnData", "inputs": []}, {"type": "error", "name": "RouterAdapter__InsufficientLBLiquidity", "inputs": []}, {"type": "error", "name": "RouterAdapter__InsufficientTMLiquidity", "inputs": []}, {"type": "error", "name": "RouterAdapter__InsufficientTMV2Liquidity", "inputs": []}, {"type": "error", "name": "RouterAdapter__InvalidId", "inputs": []}, {"type": "error", "name": "RouterAdapter__UnexpectedAmountIn", "inputs": []}, {"type": "error", "name": "RouterAdapter__UnexpectedCallback", "inputs": []}, {"type": "error", "name": "TokenLib__TransferFailed", "inputs": []}]
Loading