@zoralabs/coins 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build$colon$js.log +116 -97
- package/CHANGELOG.md +7 -1
- package/README.md +1 -0
- package/abis/AddressConstants.json +7 -0
- package/abis/BaseTest.json +62 -0
- package/abis/BuySupplyWithV4SwapHook.json +429 -0
- package/abis/IUniswapV4Router04.json +484 -0
- package/abis/MockAirlock.json +39 -0
- package/abis/SimpleERC20.json +326 -0
- package/addresses/8453.json +7 -9
- package/audits/report-cantinacode-zora-1021.pdf +0 -0
- package/dist/index.cjs +140 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +139 -18
- package/dist/index.js.map +1 -1
- package/dist/wagmiGenerated.d.ts +205 -28
- package/dist/wagmiGenerated.d.ts.map +1 -1
- package/package/wagmiGenerated.ts +139 -18
- package/package.json +1 -1
- package/script/DeployPostDeploymentHooks.s.sol +1 -3
- package/src/deployment/CoinsDeployerBase.sol +9 -8
- package/src/hooks/deployment/BuySupplyWithV4SwapHook.sol +310 -0
- package/src/utils/AutoSwapper.sol +1 -1
- package/src/version/ContractVersionBase.sol +1 -1
- package/test/BuySupplyWithV4SwapHook.t.sol +509 -0
- package/test/Coin.t.sol +21 -9
- package/test/CoinUniV4.t.sol +1 -2
- package/test/ContentCoinRewards.t.sol +1 -3
- package/test/CreatorCoin.t.sol +1 -4
- package/test/CreatorCoinRewards.t.sol +1 -3
- package/test/Factory.t.sol +3 -3
- package/test/MultiOwnable.t.sol +4 -4
- package/test/Upgrades.t.sol +26 -17
- package/test/ZoraHookRegistry.t.sol +19 -9
- package/test/mocks/MockAirlock.sol +22 -0
- package/test/mocks/SimpleERC20.sol +8 -0
- package/test/utils/BaseTest.sol +155 -2
- package/test/utils/hookmate/README.md +50 -0
- package/test/utils/hookmate/artifacts/DeployHelper.sol +20 -0
- package/test/utils/hookmate/artifacts/Permit2.sol +16 -0
- package/test/utils/hookmate/artifacts/UniversalRouter.sol +29 -0
- package/test/utils/hookmate/artifacts/V4PoolManager.sol +17 -0
- package/test/utils/hookmate/artifacts/V4PositionManager.sol +23 -0
- package/test/utils/hookmate/artifacts/V4Quoter.sol +17 -0
- package/test/utils/hookmate/artifacts/V4Router.sol +18 -0
- package/test/utils/hookmate/constants/AddressConstants.sol +193 -0
- package/test/utils/hookmate/interfaces/router/IUniswapV4Router04.sol +173 -0
- package/test/utils/hookmate/interfaces/router/PathKey.sol +34 -0
- package/test/utils/hookmate/test/utils/SwapFeeEventAsserter.sol +24 -0
- package/wagmi.config.ts +1 -1
- package/src/utils/uniswap/BytesLib.sol +0 -35
- package/src/utils/uniswap/Path.sol +0 -31
- /package/abis/{VmContractHelper226.json → VmContractHelper239.json} +0 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.26;
|
|
3
|
+
|
|
4
|
+
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
|
|
5
|
+
import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
|
|
6
|
+
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
|
|
7
|
+
|
|
8
|
+
import {PathKey} from "./PathKey.sol";
|
|
9
|
+
|
|
10
|
+
/// @title Uniswap V4 Swap Router
|
|
11
|
+
/// @notice A simple, stateless router for execution of swaps against Uniswap v4 Pools
|
|
12
|
+
/// @dev ABI inspired by UniswapV2Router02; https://github.com/hookmate/v4-router
|
|
13
|
+
interface IUniswapV4Router04 {
|
|
14
|
+
/// ================ MULTI POOL SWAPS ================= ///
|
|
15
|
+
|
|
16
|
+
/// @notice Exact Input Swap; swap the specified amount of input tokens for as many output tokens as possible, along the path
|
|
17
|
+
/// @param amountIn the amount of input tokens to swap
|
|
18
|
+
/// @param amountOutMin the minimum amount of output tokens that must be received for the transaction not to revert. reverts on equals to
|
|
19
|
+
/// @param startCurrency the currency to start the swap from
|
|
20
|
+
/// @param path the path of v4 Pools to swap through
|
|
21
|
+
/// @param receiver the address to send the output tokens to
|
|
22
|
+
/// @param deadline block.timestamp must be before this value, otherwise the transaction will revert
|
|
23
|
+
/// @return Delta the balance changes from the swap
|
|
24
|
+
function swapExactTokensForTokens(
|
|
25
|
+
uint256 amountIn,
|
|
26
|
+
uint256 amountOutMin,
|
|
27
|
+
Currency startCurrency,
|
|
28
|
+
PathKey[] calldata path,
|
|
29
|
+
address receiver,
|
|
30
|
+
uint256 deadline
|
|
31
|
+
) external payable returns (BalanceDelta);
|
|
32
|
+
|
|
33
|
+
/// @notice Exact Output Swap; swap as few input tokens as possible for the specified amount of output tokens, along the path
|
|
34
|
+
/// @param amountOut the amount of output tokens to receive
|
|
35
|
+
/// @param amountInMax the maximum amount of input tokens that can be spent for the transaction not to revert. reverts on equal to
|
|
36
|
+
/// @param startCurrency the currency to start the swap from
|
|
37
|
+
/// @param path the path of v4 Pools to swap through
|
|
38
|
+
/// @param receiver the address to send the output tokens to
|
|
39
|
+
/// @param deadline block.timestamp must be before this value, otherwise the transaction will revert
|
|
40
|
+
/// @return Delta the balance changes from the swap
|
|
41
|
+
function swapTokensForExactTokens(
|
|
42
|
+
uint256 amountOut,
|
|
43
|
+
uint256 amountInMax,
|
|
44
|
+
Currency startCurrency,
|
|
45
|
+
PathKey[] calldata path,
|
|
46
|
+
address receiver,
|
|
47
|
+
uint256 deadline
|
|
48
|
+
) external payable returns (BalanceDelta);
|
|
49
|
+
|
|
50
|
+
/// @notice General-purpose swap interface for Uniswap v4 that handles all types of swaps
|
|
51
|
+
/// @param amountSpecified the amount of tokens to be swapped, negative for exact input swaps and positive for exact output swaps
|
|
52
|
+
/// @param amountLimit the minimum amount of output tokens for exact input swaps, the maximum amount of input tokens for exact output swaps
|
|
53
|
+
/// @param startCurrency the currency to start the swap from
|
|
54
|
+
/// @param path the path of v4 Pools to swap through
|
|
55
|
+
/// @param receiver the address to send the output tokens to
|
|
56
|
+
/// @param deadline block.timestamp must be before this value, otherwise the transaction will revert
|
|
57
|
+
/// @return Delta the balance changes from the swap
|
|
58
|
+
function swap(
|
|
59
|
+
int256 amountSpecified,
|
|
60
|
+
uint256 amountLimit,
|
|
61
|
+
Currency startCurrency,
|
|
62
|
+
PathKey[] calldata path,
|
|
63
|
+
address receiver,
|
|
64
|
+
uint256 deadline
|
|
65
|
+
) external payable returns (BalanceDelta);
|
|
66
|
+
|
|
67
|
+
/// ================ SINGLE POOL SWAPS ================ ///
|
|
68
|
+
|
|
69
|
+
/// @notice Single pool, exact input swap - swap the specified amount of input tokens for as many output tokens as possible, on a single pool
|
|
70
|
+
/// @param amountIn the amount of input tokens to swap
|
|
71
|
+
/// @param amountOutMin the minimum amount of output tokens that must be received for the transaction not to revert
|
|
72
|
+
/// @param zeroForOne the direction of the swap, true if currency0 is being swapped for currency1
|
|
73
|
+
/// @param poolKey the pool to swap through
|
|
74
|
+
/// @param hookData the data to be passed to the hook
|
|
75
|
+
/// @param receiver the address to send the output tokens to
|
|
76
|
+
/// @param deadline block.timestamp must be before this value, otherwise the transaction will revert
|
|
77
|
+
/// @return Delta the balance changes from the swap
|
|
78
|
+
function swapExactTokensForTokens(
|
|
79
|
+
uint256 amountIn,
|
|
80
|
+
uint256 amountOutMin,
|
|
81
|
+
bool zeroForOne,
|
|
82
|
+
PoolKey calldata poolKey,
|
|
83
|
+
bytes calldata hookData,
|
|
84
|
+
address receiver,
|
|
85
|
+
uint256 deadline
|
|
86
|
+
) external payable returns (BalanceDelta);
|
|
87
|
+
|
|
88
|
+
/// @notice Singe pool, exact output swap; swap as few input tokens as possible for the specified amount of output tokens, on a single pool
|
|
89
|
+
/// @param amountOut the amount of output tokens to receive
|
|
90
|
+
/// @param amountInMax the maximum amount of input tokens that can be spent for the transaction not to revert
|
|
91
|
+
/// @param zeroForOne the direction of the swap, true if currency0 is being swapped for currency1
|
|
92
|
+
/// @param poolKey the pool to swap through
|
|
93
|
+
/// @param hookData the data to be passed to the hook
|
|
94
|
+
/// @param receiver the address to send the output tokens to
|
|
95
|
+
/// @param deadline block.timestamp must be before this value, otherwise the transaction will revert
|
|
96
|
+
/// @return Delta the balance changes from the swap
|
|
97
|
+
function swapTokensForExactTokens(
|
|
98
|
+
uint256 amountOut,
|
|
99
|
+
uint256 amountInMax,
|
|
100
|
+
bool zeroForOne,
|
|
101
|
+
PoolKey calldata poolKey,
|
|
102
|
+
bytes calldata hookData,
|
|
103
|
+
address receiver,
|
|
104
|
+
uint256 deadline
|
|
105
|
+
) external payable returns (BalanceDelta);
|
|
106
|
+
|
|
107
|
+
/// @notice General-purpose single-pool swap interface
|
|
108
|
+
/// @param amountSpecified the amount of tokens to be swapped, negative for exact input swaps and positive for exact output swaps
|
|
109
|
+
/// @param amountLimit the minimum amount of output tokens for exact input swaps, the maximum amount of input tokens for exact output swaps
|
|
110
|
+
/// @param zeroForOne the direction of the swap, true if currency0 is being swapped for currency1
|
|
111
|
+
/// @param poolKey the pool to swap through
|
|
112
|
+
/// @param hookData the data to be passed to the hook
|
|
113
|
+
/// @param receiver the address to send the output tokens to
|
|
114
|
+
/// @param deadline block.timestamp must be before this value, otherwise the transaction will revert
|
|
115
|
+
/// @return Delta the balance changes from the swap
|
|
116
|
+
function swap(
|
|
117
|
+
int256 amountSpecified,
|
|
118
|
+
uint256 amountLimit,
|
|
119
|
+
bool zeroForOne,
|
|
120
|
+
PoolKey calldata poolKey,
|
|
121
|
+
bytes calldata hookData,
|
|
122
|
+
address receiver,
|
|
123
|
+
uint256 deadline
|
|
124
|
+
) external payable returns (BalanceDelta);
|
|
125
|
+
|
|
126
|
+
/// ================ OPTIMIZED ================ ///
|
|
127
|
+
|
|
128
|
+
/// @notice Generic multi-pool swap function that accepts pre-encoded calldata
|
|
129
|
+
/// @dev Minor optimization to reduce the number of onchain abi.encode calls
|
|
130
|
+
/// @param data Pre-encoded swap data in one of the following formats:
|
|
131
|
+
/// 1. For single-pool swaps: abi.encode(
|
|
132
|
+
/// BaseData baseData, // struct containing swap parameters
|
|
133
|
+
/// bool zeroForOne, // direction of swap
|
|
134
|
+
/// PoolKey poolKey, // key of the pool to swap through
|
|
135
|
+
/// bytes hookData // data to pass to hooks
|
|
136
|
+
/// )
|
|
137
|
+
/// 2. For multi-pool swaps: abi.encode(
|
|
138
|
+
/// BaseData baseData, // struct containing swap parameters
|
|
139
|
+
/// Currency startCurrency, // initial currency in the swap
|
|
140
|
+
/// PathKey[] path // array of path keys defining the route
|
|
141
|
+
/// )
|
|
142
|
+
///
|
|
143
|
+
/// PERMIT2 EXTENSION:
|
|
144
|
+
/// 1. For single pool swaps: abi.encode(
|
|
145
|
+
/// BaseData baseData, // struct containing swap parameters
|
|
146
|
+
/// bool zeroForOne, // direction of swap
|
|
147
|
+
/// PoolKey poolKey, // key of the pool to swap through
|
|
148
|
+
/// bytes hookData, // data to pass to hooks
|
|
149
|
+
/// PermitPayload permitPayload // permit2 signature payload
|
|
150
|
+
/// )
|
|
151
|
+
/// 2. For multi-pool swaps: abi.encode(
|
|
152
|
+
/// BaseData baseData, // struct containing swap parameters
|
|
153
|
+
/// Currency startCurrency, // initial currency in the swap
|
|
154
|
+
/// PathKey[] path, // array of path keys defining the route
|
|
155
|
+
/// PermitPayload permitPayload // permit2 signature payload
|
|
156
|
+
/// )
|
|
157
|
+
/// Where BaseData.flags contains permit2 flag, and PermitPayload contains:
|
|
158
|
+
/// - permit: ISignatureTransfer.PermitTransferFrom
|
|
159
|
+
/// - signature: bytes
|
|
160
|
+
///
|
|
161
|
+
/// @param deadline block.timestamp must be before this value, otherwise the transaction will revert
|
|
162
|
+
/// @return Delta the balance changes from the swap
|
|
163
|
+
function swap(bytes calldata data, uint256 deadline) external payable returns (BalanceDelta);
|
|
164
|
+
|
|
165
|
+
/// @notice Provides ETH receipts locked to Pool Manager
|
|
166
|
+
receive() external payable;
|
|
167
|
+
|
|
168
|
+
/// ================ GETTERS ================ ///
|
|
169
|
+
|
|
170
|
+
/// @notice Public view function to be used instead of msg.sender, as the contract performs self-reentrancy and at
|
|
171
|
+
/// times msg.sender == address(this). Instead msgSender() returns the initiator of the lock
|
|
172
|
+
function msgSender() external view returns (address);
|
|
173
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.26;
|
|
3
|
+
|
|
4
|
+
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
|
|
5
|
+
import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol";
|
|
6
|
+
import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
|
|
7
|
+
|
|
8
|
+
struct PathKey {
|
|
9
|
+
Currency intermediateCurrency;
|
|
10
|
+
uint24 fee;
|
|
11
|
+
int24 tickSpacing;
|
|
12
|
+
IHooks hooks;
|
|
13
|
+
bytes hookData;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
using PathKeyLibrary for PathKey global;
|
|
17
|
+
|
|
18
|
+
/// @title PathKey Library
|
|
19
|
+
/// @notice Memory-oriented version of v4-periphery/src/libraries/PathKeyLibrary.sol
|
|
20
|
+
/// @dev Handles PathKey operations in memory rather than calldata for router operations
|
|
21
|
+
library PathKeyLibrary {
|
|
22
|
+
/// @notice Get the pool and swap direction for a given PathKey
|
|
23
|
+
/// @param params the given PathKey
|
|
24
|
+
/// @param currencyIn the input currency
|
|
25
|
+
/// @return poolKey the pool key of the swap
|
|
26
|
+
/// @return zeroForOne the direction of the swap, true if currency0 is being swapped for currency1
|
|
27
|
+
function getPoolAndSwapDirection(PathKey memory params, Currency currencyIn) internal pure returns (PoolKey memory poolKey, bool zeroForOne) {
|
|
28
|
+
Currency currencyOut = params.intermediateCurrency;
|
|
29
|
+
(Currency currency0, Currency currency1) = currencyIn < currencyOut ? (currencyIn, currencyOut) : (currencyOut, currencyIn);
|
|
30
|
+
|
|
31
|
+
zeroForOne = currencyIn == currency0;
|
|
32
|
+
poolKey = PoolKey(currency0, currency1, params.fee, params.tickSpacing, params.hooks);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.26;
|
|
3
|
+
|
|
4
|
+
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
|
|
5
|
+
import {Vm} from "forge-std/Vm.sol";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @title Swap Fee Event Asserter
|
|
9
|
+
* @author saucepoint, akshatmittal
|
|
10
|
+
*/
|
|
11
|
+
library SwapFeeEventAsserter {
|
|
12
|
+
function getSwapFeeFromEvent(Vm.Log[] memory recordedLogs) internal pure returns (uint24 fee) {
|
|
13
|
+
for (uint256 i; i < recordedLogs.length; i++) {
|
|
14
|
+
if (recordedLogs[i].topics[0] == IPoolManager.Swap.selector) {
|
|
15
|
+
(, , , , , fee) = abi.decode(recordedLogs[i].data, (int128, int128, uint160, uint128, int24, uint24));
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function assertSwapFee(Vm vm, Vm.Log[] memory recordedLogs, uint24 expectedFee) internal pure {
|
|
22
|
+
vm.assertEq(getSwapFeeFromEvent(recordedLogs), expectedFee);
|
|
23
|
+
}
|
|
24
|
+
}
|
package/wagmi.config.ts
CHANGED
|
@@ -14,11 +14,11 @@ export default defineConfig({
|
|
|
14
14
|
"CreatorCoin",
|
|
15
15
|
"ZoraFactoryImpl",
|
|
16
16
|
"IUniswapV3Pool",
|
|
17
|
-
"BuySupplyWithSwapRouterHook",
|
|
18
17
|
"IPoolConfigEncoding",
|
|
19
18
|
"IUniversalRouter",
|
|
20
19
|
"IPermit2",
|
|
21
20
|
"AutoSwapper",
|
|
21
|
+
"BuySupplyWithV4SwapHook",
|
|
22
22
|
].map((contractName) => `${contractName}.json`),
|
|
23
23
|
}),
|
|
24
24
|
],
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
2
|
-
/*
|
|
3
|
-
* @title Solidity Bytes Arrays Utils
|
|
4
|
-
* @author Gonçalo Sá <goncalo.sa@consensys.net>
|
|
5
|
-
*
|
|
6
|
-
* @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.
|
|
7
|
-
* The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
|
|
8
|
-
*/
|
|
9
|
-
pragma solidity ^0.8.28;
|
|
10
|
-
|
|
11
|
-
library BytesLib {
|
|
12
|
-
function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {
|
|
13
|
-
require(_start + 20 >= _start, "toAddress_overflow");
|
|
14
|
-
require(_bytes.length >= _start + 20, "toAddress_outOfBounds");
|
|
15
|
-
address tempAddress;
|
|
16
|
-
|
|
17
|
-
assembly {
|
|
18
|
-
tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return tempAddress;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function toUint24(bytes memory _bytes, uint256 _start) internal pure returns (uint24) {
|
|
25
|
-
require(_start + 3 >= _start, "toUint24_overflow");
|
|
26
|
-
require(_bytes.length >= _start + 3, "toUint24_outOfBounds");
|
|
27
|
-
uint24 tempUint;
|
|
28
|
-
|
|
29
|
-
assembly {
|
|
30
|
-
tempUint := mload(add(add(_bytes, 0x3), _start))
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return tempUint;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
2
|
-
pragma solidity ^0.8.28;
|
|
3
|
-
|
|
4
|
-
import "./BytesLib.sol";
|
|
5
|
-
|
|
6
|
-
// copied from https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/Path.sol
|
|
7
|
-
// with certain functionality removed
|
|
8
|
-
|
|
9
|
-
/// @title Functions for manipulating path data for multihop swaps
|
|
10
|
-
library Path {
|
|
11
|
-
using BytesLib for bytes;
|
|
12
|
-
|
|
13
|
-
/// @dev The length of the bytes encoded address
|
|
14
|
-
uint256 private constant ADDR_SIZE = 20;
|
|
15
|
-
/// @dev The length of the bytes encoded fee
|
|
16
|
-
uint256 private constant FEE_SIZE = 3;
|
|
17
|
-
|
|
18
|
-
/// @dev The offset of a single token address and pool fee
|
|
19
|
-
uint256 private constant NEXT_OFFSET = ADDR_SIZE + FEE_SIZE;
|
|
20
|
-
|
|
21
|
-
/// @notice Decodes the first pool in path
|
|
22
|
-
/// @param path The bytes encoded swap path
|
|
23
|
-
/// @return tokenA The first token of the given pool
|
|
24
|
-
/// @return tokenB The second token of the given pool
|
|
25
|
-
/// @return fee The fee level of the pool
|
|
26
|
-
function decodeFirstPool(bytes memory path) internal pure returns (address tokenA, address tokenB, uint24 fee) {
|
|
27
|
-
tokenA = path.toAddress(0);
|
|
28
|
-
fee = path.toUint24(ADDR_SIZE);
|
|
29
|
-
tokenB = path.toAddress(NEXT_OFFSET);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
File without changes
|