|
| 1 | +# ClipperRouter |
| 2 | + |
| 3 | + |
| 4 | +Clipper router that allows to use `ClipperExchangeInterface` for swaps |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +## Derives |
| 9 | +- [EthReceiver](helpers/EthReceiver.md) |
| 10 | + |
| 11 | +## Functions |
| 12 | +### constructor |
| 13 | +```solidity |
| 14 | +function constructor(contract IWETH weth) |
| 15 | +``` |
| 16 | + |
| 17 | + |
| 18 | +#### Parameters: |
| 19 | +| Name | Type | Description | |
| 20 | +| :--- | :--- | :------------------------------------------------------------------- | |
| 21 | +|`weth` | contract IWETH | |
| 22 | + |
| 23 | + |
| 24 | +### clipperSwapToWithPermit |
| 25 | +```solidity |
| 26 | +function clipperSwapToWithPermit( |
| 27 | + contract IClipperExchangeInterface clipperExchange, |
| 28 | + address payable recipient, |
| 29 | + contract IERC20 srcToken, |
| 30 | + contract IERC20 dstToken, |
| 31 | + uint256 inputAmount, |
| 32 | + uint256 outputAmount, |
| 33 | + uint256 expiryWithFlags, |
| 34 | + bytes32 r, |
| 35 | + bytes32 vs, |
| 36 | + bytes calldata permit |
| 37 | +) external returns(uint256 returnAmount) |
| 38 | +``` |
| 39 | +Same as `clipperSwapTo` but calls permit first, allowing to approve token spending and make a swap in one transaction. |
| 40 | + |
| 41 | + |
| 42 | +#### Parameters: |
| 43 | +| Name | Type | Description | |
| 44 | +| :--- | :--- | :------------------------------------------------------------------- | |
| 45 | +|`clipperExchange` | contract IClipperExchangeInterface | Clipper pool address |
| 46 | +|`recipient` | address payable | Address that will receive swap funds |
| 47 | +|`srcToken` | contract IERC20 | Source token |
| 48 | +|`dstToken` | contract IERC20 | Destination token |
| 49 | +|`inputAmount` | uint256 | Amount of source tokens to swap |
| 50 | +|`outputAmount` | uint256 | Amount of destination tokens to receive |
| 51 | +|`expiryWithFlags` | uint256 | Timestamp until the swap will be valid with permit2 flag |
| 52 | +|`r` | bytes32 | Clipper order signature (r part) |
| 53 | +|`vs` | bytes32 | Clipper order signature (vs part) |
| 54 | +|`permit` | bytes | Should contain valid permit that can be used in `IERC20Permit.permit` calls. See tests for examples |
| 55 | + |
| 56 | + |
| 57 | +#### Return values |
| 58 | +| Name | Type | Description | |
| 59 | +| :--- | :--- | :------------------------------------------------------------------- | |
| 60 | +|`returnAmount` | uint256 | Amount of destination tokens received |
| 61 | + |
| 62 | + |
| 63 | +### clipperSwap |
| 64 | +```solidity |
| 65 | +function clipperSwap( |
| 66 | + contract IClipperExchangeInterface clipperExchange, |
| 67 | + contract IERC20 srcToken, |
| 68 | + contract IERC20 dstToken, |
| 69 | + uint256 inputAmount, |
| 70 | + uint256 outputAmount, |
| 71 | + uint256 expiryWithFlags, |
| 72 | + bytes32 r, |
| 73 | + bytes32 vs |
| 74 | +) external payable returns(uint256 returnAmount) |
| 75 | +``` |
| 76 | +Same as `clipperSwapTo` but uses `msg.sender` as recipient |
| 77 | + |
| 78 | + |
| 79 | +#### Parameters: |
| 80 | +| Name | Type | Description | |
| 81 | +| :--- | :--- | :------------------------------------------------------------------- | |
| 82 | +|`clipperExchange` | contract IClipperExchangeInterface | Clipper pool address |
| 83 | +|`srcToken` | contract IERC20 | Source token |
| 84 | +|`dstToken` | contract IERC20 | Destination token |
| 85 | +|`inputAmount` | uint256 | Amount of source tokens to swap |
| 86 | +|`outputAmount` | uint256 | Amount of destination tokens to receive |
| 87 | +|`expiryWithFlags` | uint256 | Timestamp until the swap will be valid with permit2 flag |
| 88 | +|`r` | bytes32 | Clipper order signature (r part) |
| 89 | +|`vs` | bytes32 | Clipper order signature (vs part) |
| 90 | + |
| 91 | + |
| 92 | +#### Return values |
| 93 | +| Name | Type | Description | |
| 94 | +| :--- | :--- | :------------------------------------------------------------------- | |
| 95 | +|`returnAmount` | uint256 | Amount of destination tokens received |
| 96 | + |
| 97 | + |
| 98 | +### clipperSwapTo |
| 99 | +```solidity |
| 100 | +function clipperSwapTo( |
| 101 | + contract IClipperExchangeInterface clipperExchange, |
| 102 | + address payable recipient, |
| 103 | + contract IERC20 srcToken, |
| 104 | + contract IERC20 dstToken, |
| 105 | + uint256 inputAmount, |
| 106 | + uint256 outputAmount, |
| 107 | + uint256 expiryWithFlags, |
| 108 | + bytes32 r, |
| 109 | + bytes32 vs |
| 110 | +) public payable returns(uint256 returnAmount) |
| 111 | +``` |
| 112 | +Performs swap using Clipper exchange. Wraps and unwraps ETH if required. |
| 113 | +Sending non-zero `msg.value` for anything but ETH swaps is prohibited |
| 114 | + |
| 115 | + |
| 116 | +#### Parameters: |
| 117 | +| Name | Type | Description | |
| 118 | +| :--- | :--- | :------------------------------------------------------------------- | |
| 119 | +|`clipperExchange` | contract IClipperExchangeInterface | Clipper pool address |
| 120 | +|`recipient` | address payable | Address that will receive swap funds |
| 121 | +|`srcToken` | contract IERC20 | Source token |
| 122 | +|`dstToken` | contract IERC20 | Destination token |
| 123 | +|`inputAmount` | uint256 | Amount of source tokens to swap |
| 124 | +|`outputAmount` | uint256 | Amount of destination tokens to receive |
| 125 | +|`expiryWithFlags` | uint256 | Timestamp until the swap will be valid with permit2 flag |
| 126 | +|`r` | bytes32 | Clipper order signature (r part) |
| 127 | +|`vs` | bytes32 | Clipper order signature (vs part) |
| 128 | + |
| 129 | + |
| 130 | +#### Return values |
| 131 | +| Name | Type | Description | |
| 132 | +| :--- | :--- | :------------------------------------------------------------------- | |
| 133 | +|`returnAmount` | uint256 | Amount of destination tokens received |
| 134 | + |
0 commit comments