@zoralabs/coins 1.1.2 → 2.1.0

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.
Files changed (78) hide show
  1. package/.turbo/turbo-build.log +107 -110
  2. package/CHANGELOG.md +50 -0
  3. package/README.md +48 -1
  4. package/abis/BaseCoin.json +442 -0
  5. package/abis/BaseZoraV4CoinHook.json +6 -2
  6. package/abis/CoinTest.json +3 -246
  7. package/abis/CoinUniV4Test.json +20 -0
  8. package/abis/ContentCoinHook.json +6 -2
  9. package/abis/CreatorCoinHook.json +6 -2
  10. package/abis/FactoryTest.json +8 -133
  11. package/abis/FeeEstimatorHook.json +6 -2
  12. package/abis/HooksTest.json +0 -26
  13. package/abis/ICoin.json +378 -0
  14. package/abis/ICoinV3.json +378 -0
  15. package/abis/IZoraFactory.json +0 -18
  16. package/abis/IZoraV4CoinHook.json +2 -2
  17. package/abis/LiquidityMigrationTest.json +101 -0
  18. package/abis/MockBadFactory.json +15 -0
  19. package/abis/Ownable2StepUpgradeable.json +138 -0
  20. package/abis/ZoraFactoryImpl.json +38 -65
  21. package/addresses/8453.json +5 -5
  22. package/dist/index.cjs +272 -268
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.js +270 -266
  25. package/dist/index.js.map +1 -1
  26. package/dist/wagmiGenerated.d.ts +397 -470
  27. package/dist/wagmiGenerated.d.ts.map +1 -1
  28. package/package/wagmiGenerated.ts +275 -271
  29. package/package.json +3 -3
  30. package/script/DeployPostDeploymentHooks.s.sol +2 -2
  31. package/script/TestBackingCoinSwap.s.sol +9 -9
  32. package/script/TestV4Swap.s.sol +9 -9
  33. package/script/UpgradeFactoryImpl.s.sol +0 -1
  34. package/src/BaseCoin.sol +109 -6
  35. package/src/ContentCoin.sol +45 -0
  36. package/src/CreatorCoin.sol +7 -5
  37. package/src/ZoraFactoryImpl.sol +12 -95
  38. package/src/deployment/CoinsDeployerBase.sol +13 -30
  39. package/src/hooks/BaseZoraV4CoinHook.sol +8 -6
  40. package/src/hooks/deployment/BuySupplyWithSwapRouterHook.sol +4 -5
  41. package/src/interfaces/ICoin.sol +67 -1
  42. package/src/interfaces/ICreatorCoin.sol +2 -2
  43. package/src/interfaces/IZoraFactory.sol +0 -5
  44. package/src/interfaces/IZoraV4CoinHook.sol +1 -1
  45. package/src/libs/CoinConfigurationVersions.sol +1 -39
  46. package/src/libs/CoinRewardsV4.sol +2 -2
  47. package/src/libs/CoinSetup.sol +1 -4
  48. package/src/libs/UniV4SwapHelper.sol +1 -1
  49. package/src/libs/UniV4SwapToCurrency.sol +2 -2
  50. package/src/libs/V4Liquidity.sol +1 -1
  51. package/src/version/ContractVersionBase.sol +1 -1
  52. package/test/Coin.t.sol +112 -535
  53. package/test/CoinUniV4.t.sol +66 -10
  54. package/test/DeploymentHooks.t.sol +5 -102
  55. package/test/Factory.t.sol +49 -291
  56. package/test/LiquidityMigration.t.sol +160 -2
  57. package/test/MultiOwnable.t.sol +36 -36
  58. package/test/Upgrades.t.sol +23 -42
  59. package/test/utils/BaseTest.sol +39 -84
  60. package/test/utils/FeeEstimatorHook.sol +3 -3
  61. package/wagmi.config.ts +2 -2
  62. package/abis/Coin.json +0 -1912
  63. package/abis/DopplerUniswapV3Test.json +0 -800
  64. package/abis/ICoinV4.json +0 -1048
  65. package/abis/Simulate.json +0 -29
  66. package/abis/UniV3BuySell.json +0 -12
  67. package/abis/UniV3Errors.json +0 -32
  68. package/script/Simulate.s.sol +0 -59
  69. package/src/Coin.sol +0 -236
  70. package/src/CoinV4.sol +0 -151
  71. package/src/interfaces/ICoinV4.sol +0 -74
  72. package/src/libs/CoinDopplerUniV3.sol +0 -50
  73. package/src/libs/CoinRewards.sol +0 -201
  74. package/src/libs/CoinSetupV3.sol +0 -50
  75. package/src/libs/UniV3BuySell.sol +0 -231
  76. package/src/libs/UniV3Errors.sol +0 -11
  77. package/test/CoinDopplerUniV3.t.sol +0 -310
  78. /package/abis/{CoinV4.json → ContentCoin.json} +0 -0
@@ -12,8 +12,7 @@ import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/U
12
12
  import {IZoraFactory} from "../../src/interfaces/IZoraFactory.sol";
13
13
  import {ZoraFactoryImpl} from "../../src/ZoraFactoryImpl.sol";
14
14
  import {ZoraFactory} from "../../src/proxy/ZoraFactory.sol";
15
- import {Coin} from "../../src/Coin.sol";
16
- import {CoinV4} from "../../src/CoinV4.sol";
15
+ import {ContentCoin} from "../../src/ContentCoin.sol";
17
16
  import {MultiOwnable} from "../../src/utils/MultiOwnable.sol";
18
17
  import {ICoin} from "../../src/interfaces/ICoin.sol";
19
18
  import {IERC7572} from "../../src/interfaces/IERC7572.sol";
@@ -32,7 +31,7 @@ import {ContentCoinHook} from "../../src/hooks/ContentCoinHook.sol";
32
31
  import {HooksDeployment} from "../../src/libs/HooksDeployment.sol";
33
32
  import {CoinConstants} from "../../src/libs/CoinConstants.sol";
34
33
  import {ProxyShim} from "./ProxyShim.sol";
35
- import {ICoinV4} from "../../src/interfaces/ICoinV4.sol";
34
+ import {ICoin} from "../../src/interfaces/ICoin.sol";
36
35
  import {UniV4SwapHelper} from "../../src/libs/UniV4SwapHelper.sol";
37
36
  import {IPermit2} from "permit2/src/interfaces/IPermit2.sol";
38
37
  import {IUniversalRouter} from "@uniswap/universal-router/contracts/interfaces/IUniversalRouter.sol";
@@ -75,61 +74,30 @@ contract BaseTest is Test, ContractAddresses {
75
74
  IUniversalRouter internal router;
76
75
  IPoolManager internal poolManager;
77
76
  IV4Quoter internal quoter;
78
- CoinV4 internal coinV4;
77
+ ContentCoin internal coinV4;
79
78
 
80
79
  ISwapRouter internal swapRouter;
81
80
  IAirlock internal airlock;
82
81
  Users internal users;
83
82
 
84
- Coin internal coinV3Impl;
85
- CoinV4 internal coinV4Impl;
83
+ // Coin internal coinV3Impl;
84
+ ContentCoin internal coinV4Impl;
86
85
  CreatorCoin internal creatorCoinImpl;
87
86
  ZoraFactoryImpl internal factoryImpl;
88
87
  IZoraFactory internal factory;
89
88
  ContentCoinHook internal contentCoinHook;
90
89
  CreatorCoinHook internal creatorCoinHook;
91
90
  HookUpgradeGate internal hookUpgradeGate;
92
- Coin internal coin;
93
-
94
- IUniswapV3Pool internal pool;
95
91
  int24 internal constant DEFAULT_DISCOVERY_TICK_LOWER = CoinConstants.DEFAULT_DISCOVERY_TICK_LOWER;
96
92
  int24 internal constant DEFAULT_DISCOVERY_TICK_UPPER = CoinConstants.DEFAULT_DISCOVERY_TICK_UPPER;
97
93
  uint16 internal constant DEFAULT_NUM_DISCOVERY_POSITIONS = CoinConstants.DEFAULT_NUM_DISCOVERY_POSITIONS;
98
94
  uint256 internal constant DEFAULT_DISCOVERY_SUPPLY_SHARE = CoinConstants.DEFAULT_DISCOVERY_SUPPLY_SHARE;
99
95
 
100
- function _deployCoin() internal {
101
- bytes memory poolConfig_ = _generatePoolConfig(
102
- CoinConfigurationVersions.DOPPLER_UNI_V3_POOL_VERSION,
103
- address(weth),
104
- DEFAULT_DISCOVERY_TICK_LOWER,
105
- DEFAULT_DISCOVERY_TICK_UPPER,
106
- DEFAULT_NUM_DISCOVERY_POSITIONS,
107
- DEFAULT_DISCOVERY_SUPPLY_SHARE
108
- );
109
- vm.prank(users.creator);
110
- (address coinAddress, ) = factory.deploy(
111
- users.creator,
112
- _getDefaultOwners(),
113
- "https://test.com",
114
- "Testcoin",
115
- "TEST",
116
- poolConfig_,
117
- users.platformReferrer,
118
- 0
119
- );
120
-
121
- coin = Coin(payable(coinAddress));
122
- pool = IUniswapV3Pool(coin.poolAddress());
123
-
124
- vm.label(address(coin), "COIN");
125
- vm.label(address(pool), "POOL");
126
- }
127
-
128
96
  function _defaultPoolConfig(address currency) internal pure returns (bytes memory) {
129
97
  return CoinConfigurationVersions.defaultDopplerMultiCurveUniV4(currency);
130
98
  }
131
99
 
132
- function _deployV4Coin(address currency) internal returns (ICoinV4) {
100
+ function _deployV4Coin(address currency) internal returns (ICoin) {
133
101
  bytes32 salt = keccak256(abi.encode(bytes("randomSalt")));
134
102
  return _deployV4Coin(currency, address(0), salt);
135
103
  }
@@ -137,7 +105,7 @@ contract BaseTest is Test, ContractAddresses {
137
105
  string constant DEFAULT_NAME = "Testcoin";
138
106
  string constant DEFAULT_SYMBOL = "TEST";
139
107
 
140
- function _deployV4Coin(address currency, address createReferral, bytes32 salt) internal returns (ICoinV4) {
108
+ function _deployV4Coin(address currency, address createReferral, bytes32 salt) internal returns (ICoin) {
141
109
  address[] memory owners = new address[](1);
142
110
  owners[0] = users.creator;
143
111
 
@@ -157,19 +125,17 @@ contract BaseTest is Test, ContractAddresses {
157
125
  salt
158
126
  );
159
127
 
160
- coinV4 = CoinV4(payable(coinAddress));
128
+ coinV4 = ContentCoin(payable(coinAddress));
161
129
  return coinV4;
162
130
  }
163
131
 
132
+ function _deployV4Coin() internal returns (ICoin) {
133
+ // deploy with eth and no referral
134
+ return _deployV4Coin(address(0), address(0), bytes32(0));
135
+ }
136
+
164
137
  function _deployCoinUSDCPair() internal {
165
- bytes memory poolConfig_ = _generatePoolConfig(
166
- CoinConfigurationVersions.DOPPLER_UNI_V3_POOL_VERSION,
167
- USDC_ADDRESS,
168
- DEFAULT_DISCOVERY_TICK_LOWER,
169
- DEFAULT_DISCOVERY_TICK_UPPER,
170
- DEFAULT_NUM_DISCOVERY_POSITIONS,
171
- DEFAULT_DISCOVERY_SUPPLY_SHARE
172
- );
138
+ bytes memory poolConfig_ = _defaultPoolConfig(USDC_ADDRESS);
173
139
  vm.prank(users.creator);
174
140
  (address coinAddress, ) = factory.deploy(
175
141
  users.creator,
@@ -182,18 +148,14 @@ contract BaseTest is Test, ContractAddresses {
182
148
  0
183
149
  );
184
150
 
185
- coin = Coin(payable(coinAddress));
186
- pool = IUniswapV3Pool(coin.poolAddress());
187
-
188
- vm.label(address(coin), "COIN");
189
- vm.label(address(pool), "POOL");
151
+ vm.label(coinAddress, "COIN");
190
152
  }
191
153
 
192
- function _swapSomeCurrencyForCoin(ICoinV4 _coin, address currency, uint128 amountIn, address trader) internal {
154
+ function _swapSomeCurrencyForCoin(ICoin _coin, address currency, uint128 amountIn, address trader) internal {
193
155
  _swapSomeCurrencyForCoin(_coin.getPoolKey(), _coin, currency, amountIn, trader);
194
156
  }
195
157
 
196
- function _swapSomeCurrencyForCoin(PoolKey memory poolKey, ICoinV4 _coin, address currency, uint128 amountIn, address trader) internal {
158
+ function _swapSomeCurrencyForCoin(PoolKey memory poolKey, ICoin _coin, address currency, uint128 amountIn, address trader) internal {
197
159
  uint128 minAmountOut = uint128(0);
198
160
 
199
161
  (bytes memory commands, bytes[] memory inputs) = UniV4SwapHelper.buildExactInputSingleSwapCommand(
@@ -206,16 +168,20 @@ contract BaseTest is Test, ContractAddresses {
206
168
  );
207
169
 
208
170
  vm.startPrank(trader);
209
- UniV4SwapHelper.approveTokenWithPermit2(permit2, address(router), currency, amountIn, uint48(block.timestamp + 1 days));
171
+ if (currency != address(0)) {
172
+ UniV4SwapHelper.approveTokenWithPermit2(permit2, address(router), currency, amountIn, uint48(block.timestamp + 1 days));
173
+ }
174
+
175
+ uint256 value = currency == address(0) ? amountIn : 0;
210
176
 
211
177
  // Execute the swap
212
178
  uint256 deadline = block.timestamp + 20;
213
- router.execute(commands, inputs, deadline);
179
+ router.execute{value: value}(commands, inputs, deadline);
214
180
 
215
181
  vm.stopPrank();
216
182
  }
217
183
 
218
- function _swapSomeCoinForCurrency(ICoinV4 _coin, address currency, uint128 amountIn, address trader) internal {
184
+ function _swapSomeCoinForCurrency(ICoin _coin, address currency, uint128 amountIn, address trader) internal {
219
185
  uint128 minAmountOut = uint128(0);
220
186
 
221
187
  (bytes memory commands, bytes[] memory inputs) = UniV4SwapHelper.buildExactInputSingleSwapCommand(
@@ -269,18 +235,22 @@ contract BaseTest is Test, ContractAddresses {
269
235
  (bytes32 contentCoinSalt, bytes32 creatorCoinSalt) = getSalts(trustedMessageSenders);
270
236
 
271
237
  contentCoinHook = ContentCoinHook(
272
- address(
273
- HooksDeployment.deployHookWithSalt(
274
- HooksDeployment.contentCoinCreationCode(V4_POOL_MANAGER, address(factory), trustedMessageSenders, address(hookUpgradeGate)),
275
- contentCoinSalt
238
+ payable(
239
+ address(
240
+ HooksDeployment.deployHookWithSalt(
241
+ HooksDeployment.contentCoinCreationCode(V4_POOL_MANAGER, address(factory), trustedMessageSenders, address(hookUpgradeGate)),
242
+ contentCoinSalt
243
+ )
276
244
  )
277
245
  )
278
246
  );
279
247
  creatorCoinHook = CreatorCoinHook(
280
- address(
281
- HooksDeployment.deployHookWithSalt(
282
- HooksDeployment.creatorCoinHookCreationCode(V4_POOL_MANAGER, address(factory), trustedMessageSenders, address(hookUpgradeGate)),
283
- creatorCoinSalt
248
+ payable(
249
+ address(
250
+ HooksDeployment.deployHookWithSalt(
251
+ HooksDeployment.creatorCoinHookCreationCode(V4_POOL_MANAGER, address(factory), trustedMessageSenders, address(hookUpgradeGate)),
252
+ creatorCoinSalt
253
+ )
284
254
  )
285
255
  )
286
256
  );
@@ -318,23 +288,16 @@ contract BaseTest is Test, ContractAddresses {
318
288
 
319
289
  ProxyShim mockUpgradeableImpl = new ProxyShim();
320
290
  factory = IZoraFactory(address(new ZoraFactory(address(mockUpgradeableImpl))));
321
- coinV3Impl = new Coin(users.feeRecipient, address(protocolRewards), WETH_ADDRESS, V3_FACTORY, SWAP_ROUTER, DOPPLER_AIRLOCK);
322
291
 
323
292
  hookUpgradeGate = new HookUpgradeGate(users.factoryOwner);
324
293
 
325
294
  _deployHooks();
326
295
 
327
- coinV4Impl = new CoinV4(users.feeRecipient, address(protocolRewards), IPoolManager(V4_POOL_MANAGER), DOPPLER_AIRLOCK);
296
+ coinV4Impl = new ContentCoin(users.feeRecipient, address(protocolRewards), IPoolManager(V4_POOL_MANAGER), DOPPLER_AIRLOCK);
328
297
 
329
298
  creatorCoinImpl = new CreatorCoin(users.feeRecipient, address(protocolRewards), IPoolManager(V4_POOL_MANAGER), DOPPLER_AIRLOCK);
330
299
 
331
- factoryImpl = new ZoraFactoryImpl(
332
- address(coinV3Impl),
333
- address(coinV4Impl),
334
- address(creatorCoinImpl),
335
- address(contentCoinHook),
336
- address(creatorCoinHook)
337
- );
300
+ factoryImpl = new ZoraFactoryImpl(address(coinV4Impl), address(creatorCoinImpl), address(contentCoinHook), address(creatorCoinHook));
338
301
  UUPSUpgradeable(address(factory)).upgradeToAndCall(address(factoryImpl), "");
339
302
  factory = IZoraFactory(address(factory));
340
303
 
@@ -411,15 +374,7 @@ contract BaseTest is Test, ContractAddresses {
411
374
  }
412
375
 
413
376
  function _generatePoolConfig(address currency_) internal pure returns (bytes memory) {
414
- return
415
- _generatePoolConfig(
416
- CoinConfigurationVersions.DOPPLER_UNI_V3_POOL_VERSION,
417
- currency_,
418
- DEFAULT_DISCOVERY_TICK_LOWER,
419
- DEFAULT_DISCOVERY_TICK_UPPER,
420
- DEFAULT_NUM_DISCOVERY_POSITIONS,
421
- DEFAULT_DISCOVERY_SUPPLY_SHARE
422
- );
377
+ return CoinConfigurationVersions.defaultDopplerMultiCurveUniV4(currency_);
423
378
  }
424
379
 
425
380
  function _generatePoolConfig(
@@ -11,7 +11,7 @@ import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
11
11
  import {CoinCommon} from "../../src/libs/CoinCommon.sol";
12
12
  import {V4Liquidity} from "../../src/libs/V4Liquidity.sol";
13
13
  import {BaseHook} from "@uniswap/v4-periphery/src/utils/BaseHook.sol";
14
- import {ICoinV4, IHasSwapPath} from "../../src/interfaces/ICoinV4.sol";
14
+ import {ICoin, IHasSwapPath} from "../../src/interfaces/ICoin.sol";
15
15
  import {UniV4SwapToCurrency} from "../../src/libs/UniV4SwapToCurrency.sol";
16
16
  import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
17
17
  import {CoinRewardsV4} from "../../src/libs/CoinRewardsV4.sol";
@@ -59,7 +59,7 @@ contract FeeEstimatorHook is BaseZoraV4CoinHook {
59
59
 
60
60
  {
61
61
  uint256 coinBalanceBefore = IERC20(coin).balanceOf(address(this));
62
- uint256 currencyBalanceBefore = IERC20(ICoinV4(coin).currency()).balanceOf(address(this));
62
+ uint256 currencyBalanceBefore = IERC20(ICoin(coin).currency()).balanceOf(address(this));
63
63
 
64
64
  IHasSwapPath.PayoutSwapPath memory payoutSwapPath = IHasSwapPath(coin).getPayoutSwapPath(coinVersionLookup);
65
65
 
@@ -81,7 +81,7 @@ contract FeeEstimatorHook is BaseZoraV4CoinHook {
81
81
  feeState.fees1 += uint128(fee1);
82
82
 
83
83
  uint256 coinBalanceAfter = IERC20(coin).balanceOf(address(this));
84
- uint256 currencyBalanceAfter = IERC20(ICoinV4(coin).currency()).balanceOf(address(this));
84
+ uint256 currencyBalanceAfter = IERC20(ICoin(coin).currency()).balanceOf(address(this));
85
85
 
86
86
  feeState.coinBalanceChange = coinBalanceAfter - coinBalanceBefore;
87
87
  feeState.currencyBalanceChange = currencyBalanceAfter - currencyBalanceBefore;
package/wagmi.config.ts CHANGED
@@ -9,8 +9,8 @@ export default defineConfig({
9
9
  build: false,
10
10
  },
11
11
  include: [
12
- "Coin",
13
- "CoinV4",
12
+ "BaseCoin",
13
+ "ContentCoin",
14
14
  "CreatorCoin",
15
15
  "ZoraFactoryImpl",
16
16
  "IUniswapV3Pool",