@zoralabs/coins 1.0.0 → 1.0.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.log +123 -75
- package/CHANGELOG.md +6 -0
- package/abis/BuySupplyWithSwapRouterHook.json +40 -0
- package/abis/CoinUniV4Test.json +42 -4
- package/abis/FeeEstimatorHook.json +0 -13
- package/abis/HooksTest.json +13 -0
- package/abis/IZoraFactory.json +19 -0
- package/abis/UpgradesTest.json +14 -0
- package/abis/ZoraV4CoinHook.json +0 -13
- package/addresses/8453.json +7 -8
- package/addresses/84532.json +8 -9
- package/addresses/dev/8453.json +10 -0
- package/dist/index.cjs +15 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/wagmiGenerated.d.ts +30 -0
- package/dist/wagmiGenerated.d.ts.map +1 -1
- package/foundry.toml +1 -0
- package/package/wagmiGenerated.ts +14 -0
- package/package.json +1 -1
- package/script/Deploy.s.sol +1 -1
- package/script/DeployDevFactory.s.sol +2 -2
- package/script/DeployHooks.s.sol +1 -1
- package/script/PrintUpgradeCommand.s.sol +1 -1
- package/script/TestBackingCoinSwap.s.sol +25 -24
- package/script/TestV4Swap.s.sol +6 -6
- package/script/UpgradeCoinImpl.sol +2 -2
- package/script/UpgradeFactoryImpl.s.sol +1 -1
- package/src/BaseCoin.sol +14 -0
- package/{script → src/deployment}/CoinsDeployerBase.sol +59 -28
- package/src/hooks/ZoraV4CoinHook.sol +32 -15
- package/src/hooks/deployment/BuySupplyWithSwapRouterHook.sol +64 -4
- package/src/interfaces/IZoraFactory.sol +2 -1
- package/src/libs/CoinRewardsV4.sol +0 -1
- package/src/libs/HooksDeployment.sol +51 -7
- package/src/libs/UniV4SwapToCurrency.sol +3 -3
- package/src/libs/V4Liquidity.sol +2 -9
- package/src/version/ContractVersionBase.sol +1 -1
- package/test/CoinUniV4.t.sol +85 -60
- package/test/DeploymentHooks.t.sol +51 -10
- package/test/Upgrades.t.sol +92 -1
- package/test/utils/BaseTest.sol +56 -1
package/test/Upgrades.t.sol
CHANGED
|
@@ -4,6 +4,17 @@ import {Test} from "forge-std/Test.sol";
|
|
|
4
4
|
import {IZoraFactory} from "../src/interfaces/IZoraFactory.sol";
|
|
5
5
|
import {ZoraFactoryImpl} from "../src/ZoraFactoryImpl.sol";
|
|
6
6
|
import {BaseTest} from "./utils/BaseTest.sol";
|
|
7
|
+
import {CoinsDeployerBase} from "../src/deployment/CoinsDeployerBase.sol";
|
|
8
|
+
import {CoinConfigurationVersions} from "../src/libs/CoinConfigurationVersions.sol";
|
|
9
|
+
import {ICoinV4} from "../src/interfaces/ICoinV4.sol";
|
|
10
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
11
|
+
import {ISwapRouter} from "../src/interfaces/ISwapRouter.sol";
|
|
12
|
+
import {IWETH} from "../src/interfaces/IWETH.sol";
|
|
13
|
+
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
|
|
14
|
+
import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
|
|
15
|
+
import {BuySupplyWithSwapRouterHook} from "../src/hooks/deployment/BuySupplyWithSwapRouterHook.sol";
|
|
16
|
+
|
|
17
|
+
import {console} from "forge-std/console.sol";
|
|
7
18
|
|
|
8
19
|
contract BadImpl {
|
|
9
20
|
function contractName() public pure returns (string memory) {
|
|
@@ -11,7 +22,7 @@ contract BadImpl {
|
|
|
11
22
|
}
|
|
12
23
|
}
|
|
13
24
|
|
|
14
|
-
contract UpgradesTest is BaseTest {
|
|
25
|
+
contract UpgradesTest is BaseTest, CoinsDeployerBase {
|
|
15
26
|
ZoraFactoryImpl public factoryProxy;
|
|
16
27
|
|
|
17
28
|
function test_canUpgradeFromVersionWithoutContractName() public {
|
|
@@ -65,4 +76,84 @@ contract UpgradesTest is BaseTest {
|
|
|
65
76
|
|
|
66
77
|
assertEq(factoryProxy.implementation(), address(newImpl2));
|
|
67
78
|
}
|
|
79
|
+
|
|
80
|
+
function test_canUpgradeAndSwap() public {
|
|
81
|
+
vm.createSelectFork("base");
|
|
82
|
+
|
|
83
|
+
factoryProxy = ZoraFactoryImpl(0x777777751622c0d3258f214F9DF38E35BF45baF3);
|
|
84
|
+
|
|
85
|
+
CoinsDeployment memory deployment = readDeployment();
|
|
86
|
+
|
|
87
|
+
vm.prank(factoryProxy.owner());
|
|
88
|
+
factoryProxy.upgradeToAndCall(deployment.zoraFactoryImpl, "");
|
|
89
|
+
|
|
90
|
+
// deploy a v4 coin
|
|
91
|
+
|
|
92
|
+
bytes memory poolConfig = CoinConfigurationVersions.defaultDopplerMultiCurveUniV4(ZORA);
|
|
93
|
+
|
|
94
|
+
uint128 amountIn = 1 ether;
|
|
95
|
+
|
|
96
|
+
address buySupplyWithSwapRouterHook = deployment.buySupplyWithSwapRouterHook;
|
|
97
|
+
|
|
98
|
+
// build weth to usdc swap
|
|
99
|
+
bytes memory call = abi.encodeWithSelector(
|
|
100
|
+
ISwapRouter.exactInputSingle.selector,
|
|
101
|
+
ISwapRouter.ExactInputSingleParams({
|
|
102
|
+
tokenIn: WETH_ADDRESS,
|
|
103
|
+
tokenOut: ZORA,
|
|
104
|
+
fee: 3000,
|
|
105
|
+
recipient: buySupplyWithSwapRouterHook,
|
|
106
|
+
amountIn: amountIn,
|
|
107
|
+
amountOutMinimum: 0,
|
|
108
|
+
sqrtPriceLimitX96: 0
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
address buyRecipient = makeAddr("buyRecipient");
|
|
113
|
+
|
|
114
|
+
address trader = 0xC077e4cC02fa01A5b7fAca1acE9BBe9f5ac5Af9F;
|
|
115
|
+
|
|
116
|
+
vm.startPrank(trader);
|
|
117
|
+
vm.deal(trader, amountIn);
|
|
118
|
+
|
|
119
|
+
(address coinAddress, ) = factoryProxy.deploy{value: amountIn}(
|
|
120
|
+
users.creator,
|
|
121
|
+
_getDefaultOwners(),
|
|
122
|
+
"https://test.com",
|
|
123
|
+
"Testcoin",
|
|
124
|
+
"TEST",
|
|
125
|
+
poolConfig,
|
|
126
|
+
users.platformReferrer,
|
|
127
|
+
buySupplyWithSwapRouterHook,
|
|
128
|
+
abi.encode(buyRecipient, call),
|
|
129
|
+
keccak256("test")
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
// do some swaps to test out
|
|
133
|
+
_swapSomeCurrencyForCoin(ICoinV4(coinAddress), ZORA, uint128(IERC20(ZORA).balanceOf(trader)), trader);
|
|
134
|
+
|
|
135
|
+
// do some swaps to test out
|
|
136
|
+
_swapSomeCoinForCurrency(ICoinV4(coinAddress), ZORA, uint128(IERC20(coinAddress).balanceOf(trader)), trader);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function test_realSwapUsingCurrentCode() external {
|
|
140
|
+
bytes[] memory inputs = new bytes[](5);
|
|
141
|
+
|
|
142
|
+
vm.createSelectFork("base", 31138268);
|
|
143
|
+
|
|
144
|
+
address trader = vm.parseAddress("0xa3c881f39972925d865b300bcd65e72a6222c10a");
|
|
145
|
+
|
|
146
|
+
ICoinV4 coin = ICoinV4(vm.parseAddress("0xca1de5b8e8336326d5749fde43e245285cd1daf1"));
|
|
147
|
+
|
|
148
|
+
PoolKey memory key = coin.getPoolKey();
|
|
149
|
+
|
|
150
|
+
address[] memory trustedMessageSenders = new address[](0);
|
|
151
|
+
deployCodeTo(
|
|
152
|
+
"ZoraV4CoinHook.sol:ZoraV4CoinHook",
|
|
153
|
+
abi.encode(V4_POOL_MANAGER, 0x3d7A3f3351855e135CF89AB412A7C2AA449f9296, trustedMessageSenders),
|
|
154
|
+
address(coin.hooks())
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
_swapSomeCurrencyForCoin(coin, ZORA, uint128(IERC20(ZORA).balanceOf(trader)), trader);
|
|
158
|
+
}
|
|
68
159
|
}
|
package/test/utils/BaseTest.sol
CHANGED
|
@@ -32,11 +32,18 @@ import {ZoraV4CoinHook} from "../../src/hooks/ZoraV4CoinHook.sol";
|
|
|
32
32
|
import {HooksDeployment} from "../../src/libs/HooksDeployment.sol";
|
|
33
33
|
import {CoinConstants} from "../../src/libs/CoinConstants.sol";
|
|
34
34
|
import {ProxyShim} from "./ProxyShim.sol";
|
|
35
|
+
import {ICoinV4} from "../../src/interfaces/ICoinV4.sol";
|
|
36
|
+
import {UniV4SwapHelper} from "../../src/libs/UniV4SwapHelper.sol";
|
|
37
|
+
import {IPermit2} from "permit2/src/interfaces/IPermit2.sol";
|
|
38
|
+
import {IUniversalRouter} from "@uniswap/universal-router/contracts/interfaces/IUniversalRouter.sol";
|
|
39
|
+
import {Commands} from "@uniswap/universal-router/contracts/libraries/Commands.sol";
|
|
40
|
+
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
|
|
41
|
+
import {Actions} from "@uniswap/v4-periphery/src/libraries/Actions.sol";
|
|
42
|
+
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
|
35
43
|
|
|
36
44
|
contract BaseTest is Test {
|
|
37
45
|
using stdStorage for StdStorage;
|
|
38
46
|
|
|
39
|
-
address internal constant PROTOCOL_REWARDS = 0x7777777F279eba3d3Ad8F4E708545291A6fDBA8B;
|
|
40
47
|
address internal constant WETH_ADDRESS = 0x4200000000000000000000000000000000000006;
|
|
41
48
|
address internal constant V3_FACTORY = 0x33128a8fC17869897dcE68Ed026d694621f6FDfD;
|
|
42
49
|
address internal constant NONFUNGIBLE_POSITION_MANAGER = 0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1;
|
|
@@ -67,6 +74,8 @@ contract BaseTest is Test {
|
|
|
67
74
|
ProtocolRewards internal protocolRewards;
|
|
68
75
|
IUniswapV3Factory internal v3Factory;
|
|
69
76
|
INonfungiblePositionManager internal nonfungiblePositionManager;
|
|
77
|
+
IPermit2 internal permit2;
|
|
78
|
+
IUniversalRouter internal router;
|
|
70
79
|
|
|
71
80
|
ISwapRouter internal swapRouter;
|
|
72
81
|
IAirlock internal airlock;
|
|
@@ -141,6 +150,50 @@ contract BaseTest is Test {
|
|
|
141
150
|
vm.label(address(pool), "POOL");
|
|
142
151
|
}
|
|
143
152
|
|
|
153
|
+
function _swapSomeCurrencyForCoin(ICoinV4 _coin, address currency, uint128 amountIn, address trader) internal {
|
|
154
|
+
uint128 minAmountOut = uint128(0);
|
|
155
|
+
|
|
156
|
+
(bytes memory commands, bytes[] memory inputs) = UniV4SwapHelper.buildExactInputSingleSwapCommand(
|
|
157
|
+
currency,
|
|
158
|
+
amountIn,
|
|
159
|
+
address(_coin),
|
|
160
|
+
minAmountOut,
|
|
161
|
+
_coin.getPoolKey(),
|
|
162
|
+
bytes("")
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
vm.startPrank(trader);
|
|
166
|
+
UniV4SwapHelper.approveTokenWithPermit2(permit2, address(router), currency, amountIn, uint48(block.timestamp + 1 days));
|
|
167
|
+
|
|
168
|
+
// Execute the swap
|
|
169
|
+
uint256 deadline = block.timestamp + 20;
|
|
170
|
+
router.execute(commands, inputs, deadline);
|
|
171
|
+
|
|
172
|
+
vm.stopPrank();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function _swapSomeCoinForCurrency(ICoinV4 _coin, address currency, uint128 amountIn, address trader) internal {
|
|
176
|
+
uint128 minAmountOut = uint128(0);
|
|
177
|
+
|
|
178
|
+
(bytes memory commands, bytes[] memory inputs) = UniV4SwapHelper.buildExactInputSingleSwapCommand(
|
|
179
|
+
address(_coin),
|
|
180
|
+
amountIn,
|
|
181
|
+
currency,
|
|
182
|
+
minAmountOut,
|
|
183
|
+
_coin.getPoolKey(),
|
|
184
|
+
bytes("")
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
vm.startPrank(trader);
|
|
188
|
+
UniV4SwapHelper.approveTokenWithPermit2(permit2, address(router), address(_coin), amountIn, uint48(block.timestamp + 1 days));
|
|
189
|
+
|
|
190
|
+
// Execute the swap
|
|
191
|
+
uint256 deadline = block.timestamp + 20;
|
|
192
|
+
router.execute(commands, inputs, deadline);
|
|
193
|
+
|
|
194
|
+
vm.stopPrank();
|
|
195
|
+
}
|
|
196
|
+
|
|
144
197
|
function setUp() public virtual {
|
|
145
198
|
setUpWithBlockNumber(28415528);
|
|
146
199
|
}
|
|
@@ -155,6 +208,8 @@ contract BaseTest is Test {
|
|
|
155
208
|
swapRouter = ISwapRouter(SWAP_ROUTER);
|
|
156
209
|
airlock = IAirlock(DOPPLER_AIRLOCK);
|
|
157
210
|
protocolRewards = new ProtocolRewards();
|
|
211
|
+
permit2 = IPermit2(V4_PERMIT2);
|
|
212
|
+
router = IUniversalRouter(UNIVERSAL_ROUTER);
|
|
158
213
|
users = Users({
|
|
159
214
|
factoryOwner: makeAddr("factoryOwner"),
|
|
160
215
|
feeRecipient: makeAddr("feeRecipient"),
|