@@ -75,11 +75,28 @@ contract SplitterMockRegistry {
7575contract SplitterMockPool is IMulticurvePool {
7676 address public token0;
7777 address public token1;
78+ uint256 public fees0;
79+ uint256 public fees1;
7880
7981 constructor (address _token0 , address _token1 ) {
8082 token0 = _token0;
8183 token1 = _token1;
8284 }
85+
86+ function setFees (uint256 _fees0 , uint256 _fees1 ) external {
87+ fees0 = _fees0;
88+ fees1 = _fees1;
89+ }
90+
91+ function collectFees () external {
92+ uint256 amount0 = fees0;
93+ uint256 amount1 = fees1;
94+ fees0 = 0 ;
95+ fees1 = 0 ;
96+
97+ if (amount0 != 0 ) require (IERC20 (token0).transfer (msg .sender , amount0), "transfer0 " );
98+ if (amount1 != 0 ) require (IERC20 (token1).transfer (msg .sender , amount1), "transfer1 " );
99+ }
83100}
84101
85102contract RIKRoyaltySplitter_T is Test {
@@ -101,6 +118,13 @@ contract RIKRoyaltySplitter_T is Test {
101118 registry.setOwner (repoId, owner);
102119 }
103120
121+ function test_strangerCannotRegister () public {
122+ address asset = address (0xA55E7 );
123+
124+ vm.expectRevert (RIKRoyaltySplitter.OnlyLauncher.selector );
125+ splitter.registerMarket (asset, 42 );
126+ }
127+
104128 function test_RegisterMarketOnlyLauncher () public {
105129 address asset = address (0xA55E7 );
106130
@@ -165,14 +189,22 @@ contract RIKRoyaltySplitter_T is Test {
165189 }
166190
167191 function test_PullLpAcceptsRegisteredAssetOnEitherSide () public {
168- address asset = address ( 0xA55E7 );
169- address numeraire = address ( 0xBEEF );
192+ SplitterMockERC20 asset = new SplitterMockERC20 ( );
193+ SplitterMockERC20 numeraire = new SplitterMockERC20 ( );
170194
171195 vm.prank (launcher);
172- splitter.registerMarket (asset, repoId);
196+ splitter.registerMarket (address ( asset) , repoId);
173197
174- splitter.pullLp (new SplitterMockPool (asset, numeraire));
175- splitter.pullLp (new SplitterMockPool (numeraire, asset));
198+ splitter.pullLp (new SplitterMockPool (address (asset), address (numeraire)));
199+ splitter.pullLp (new SplitterMockPool (address (numeraire), address (asset)));
200+ }
201+
202+ function test_pullLpForUnknownPoolReverts () public {
203+ SplitterMockPool pool = new SplitterMockPool (address (0x1111 ), address (0x2222 ));
204+
205+ vm.expectRevert (RIKRoyaltySplitter.UnknownPool.selector );
206+
207+ splitter.pullLp (pool);
176208 }
177209
178210 function test_PullLpRejectsUnknownPool () public {
@@ -183,6 +215,53 @@ contract RIKRoyaltySplitter_T is Test {
183215 splitter.pullLp (pool);
184216 }
185217
218+ function test_pullLpDerivesRepoFromPool () public {
219+ uint256 otherRepoId = 22223 ;
220+ SplitterMockERC20 numeraire = new SplitterMockERC20 ();
221+ SplitterMockPool pool = new SplitterMockPool (address (token), address (numeraire));
222+ uint256 amount = 3 ether ;
223+
224+ vm.prank (launcher);
225+ splitter.registerMarket (address (token), repoId);
226+
227+ numeraire.mint (address (pool), amount);
228+ pool.setFees (0 , amount);
229+
230+ splitter.pullLp (pool);
231+
232+ assertEq (splitter.claimable (repoId, address (numeraire)), amount);
233+ assertEq (splitter.claimable (otherRepoId, address (numeraire)), 0 );
234+ }
235+
236+ function test_twoReposIndependent () public {
237+ uint256 repoA = 11112 ;
238+ uint256 repoB = 22223 ;
239+ SplitterMockERC20 assetA = new SplitterMockERC20 ();
240+ SplitterMockERC20 assetB = new SplitterMockERC20 ();
241+ SplitterMockERC20 weth = new SplitterMockERC20 ();
242+ SplitterMockPool poolA = new SplitterMockPool (address (assetA), address (weth));
243+ SplitterMockPool poolB = new SplitterMockPool (address (assetB), address (weth));
244+
245+ vm.startPrank (launcher);
246+ splitter.registerMarket (address (assetA), repoA);
247+ splitter.registerMarket (address (assetB), repoB);
248+ vm.stopPrank ();
249+
250+ weth.mint (address (poolA), 3 ether);
251+ weth.mint (address (poolB), 7 ether);
252+ poolA.setFees (0 , 3 ether);
253+ poolB.setFees (0 , 7 ether);
254+
255+ splitter.pullLp (poolA);
256+ splitter.pullLp (poolB);
257+
258+ uint256 claimableA = splitter.claimable (repoA, address (weth));
259+ uint256 claimableB = splitter.claimable (repoB, address (weth));
260+ assertGt (claimableA, 0 );
261+ assertGt (claimableB, 0 );
262+ assertNotEq (claimableA, claimableB);
263+ }
264+
186265 function _fundFees (uint256 amount ) internal {
187266 token.mint (address (airlock), amount);
188267 airlock.setFees (address (splitter), address (token), amount);
0 commit comments