@@ -4,11 +4,11 @@ pragma solidity ^0.8.22;
44import {IERC20 } from "forge-std/interfaces/IERC20.sol " ;
55import {ConditionalTokens} from "@lay3rlabs/conditional-tokens-contracts/ConditionalTokens.sol " ;
66import {CTHelpers} from "@lay3rlabs/conditional-tokens-contracts/CTHelpers.sol " ;
7- import {Create2CloneFactory} from "./Create2CloneFactory.sol " ;
8- import {FixedProductMarketMaker, FixedProductMarketMakerData} from "./FixedProductMarketMaker.sol " ;
7+ import {FixedProductMarketMaker} from "./FixedProductMarketMaker.sol " ;
98import {IERC1155Receiver } from "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol " ;
9+ import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol " ;
1010
11- contract FPMMDeterministicFactory is Create2CloneFactory , FixedProductMarketMakerData , IERC1155Receiver {
11+ contract FPMMDeterministicFactory is IERC1155Receiver {
1212 event FixedProductMarketMakerCreation (
1313 address indexed creator ,
1414 FixedProductMarketMaker fixedProductMarketMaker ,
@@ -25,100 +25,99 @@ contract FPMMDeterministicFactory is Create2CloneFactory, FixedProductMarketMake
2525 implementationMaster = new FixedProductMarketMaker ();
2626 }
2727
28- function supportsInterface (bytes4 interfaceId ) external pure returns (bool ) {
28+ function supportsInterface (
29+ bytes4 interfaceId
30+ ) external pure returns (bool ) {
2931 return interfaceId == type (IERC1155Receiver ).interfaceId;
3032 }
3133
32- function cloneConstructor (bytes calldata consData ) external override {
33- (ConditionalTokens _conditionalTokens , IERC20 _collateralToken , bytes32 [] memory _conditionIds , uint256 _fee ) =
34- abi.decode (consData, (ConditionalTokens, IERC20 , bytes32 [], uint256 ));
35-
36- _supportedInterfaces[_INTERFACE_ID_ERC165] = true ;
37- _supportedInterfaces[IERC1155Receiver (address (0 )).onERC1155Received.selector
38- ^ IERC1155Receiver (address (0 )).onERC1155BatchReceived.selector ] = true ;
39-
40- conditionalTokens = _conditionalTokens;
41- collateralToken = _collateralToken;
42- conditionIds = _conditionIds;
43- fee = _fee;
44-
45- uint256 atomicOutcomeSlotCount = 1 ;
46- outcomeSlotCounts = new uint256 [](conditionIds.length );
47- for (uint256 i = 0 ; i < conditionIds.length ; i++ ) {
48- uint256 outcomeSlotCount = conditionalTokens.getOutcomeSlotCount (conditionIds[i]);
49- atomicOutcomeSlotCount *= outcomeSlotCount;
50- outcomeSlotCounts[i] = outcomeSlotCount;
51- }
52- require (atomicOutcomeSlotCount > 1 , "conditions must be valid " );
53-
54- collectionIds = new bytes32 [][](conditionIds.length );
55- _recordCollectionIDsForAllConditions (conditionIds.length , bytes32 (0 ));
56- require (positionIds.length == atomicOutcomeSlotCount, "position IDs construction failed!? " );
57- }
58-
59- function _recordCollectionIDsForAllConditions (uint256 conditionsLeft , bytes32 parentCollectionId ) private {
60- if (conditionsLeft == 0 ) {
61- positionIds.push (CTHelpers.getPositionId (collateralToken, parentCollectionId));
62- return ;
63- }
64-
65- conditionsLeft-- ;
66-
67- uint256 outcomeSlotCount = outcomeSlotCounts[conditionsLeft];
68-
69- collectionIds[conditionsLeft].push (parentCollectionId);
70- for (uint256 i = 0 ; i < outcomeSlotCount; i++ ) {
71- _recordCollectionIDsForAllConditions (
72- conditionsLeft, CTHelpers.getCollectionId (parentCollectionId, conditionIds[conditionsLeft], 1 << i)
73- );
74- }
75- }
76-
77- function onERC1155Received (address operator , address from , uint256 id , uint256 value , bytes calldata data )
78- external
79- returns (bytes4 )
80- {
81- ConditionalTokens (msg .sender ).safeTransferFrom (address (this ), currentFunder, id, value, data);
34+ function onERC1155Received (
35+ address ,
36+ address ,
37+ uint256 id ,
38+ uint256 value ,
39+ bytes calldata data
40+ ) external returns (bytes4 ) {
41+ ConditionalTokens (msg .sender ).safeTransferFrom (
42+ address (this ),
43+ currentFunder,
44+ id,
45+ value,
46+ data
47+ );
8248 return this .onERC1155Received.selector ;
8349 }
8450
8551 function onERC1155BatchReceived (
86- address operator ,
87- address from ,
52+ address ,
53+ address ,
8854 uint256 [] calldata ids ,
8955 uint256 [] calldata values ,
9056 bytes calldata data
9157 ) external returns (bytes4 ) {
92- ConditionalTokens (msg .sender ).safeBatchTransferFrom (address (this ), currentFunder, ids, values, data);
58+ ConditionalTokens (msg .sender ).safeBatchTransferFrom (
59+ address (this ),
60+ currentFunder,
61+ ids,
62+ values,
63+ data
64+ );
9365 return this .onERC1155BatchReceived.selector ;
9466 }
9567
9668 function create2FixedProductMarketMaker (
97- uint256 saltNonce ,
69+ bytes32 salt ,
9870 ConditionalTokens conditionalTokens ,
9971 IERC20 collateralToken ,
10072 bytes32 [] calldata conditionIds ,
10173 uint256 fee ,
10274 uint256 initialFunds ,
10375 uint256 [] calldata distributionHint
104- ) external returns (FixedProductMarketMaker) {
105- FixedProductMarketMaker fixedProductMarketMaker = FixedProductMarketMaker (
106- create2Clone (
107- address (implementationMaster),
108- saltNonce,
109- abi.encode (conditionalTokens, collateralToken, conditionIds, fee)
110- )
76+ ) external returns (FixedProductMarketMaker fixedProductMarketMaker ) {
77+ fixedProductMarketMaker = FixedProductMarketMaker (
78+ Clones.cloneDeterministic (address (implementationMaster), salt)
79+ );
80+ fixedProductMarketMaker.initialize (
81+ conditionalTokens,
82+ collateralToken,
83+ conditionIds,
84+ fee
11185 );
86+
11287 emit FixedProductMarketMakerCreation (
113- msg .sender , fixedProductMarketMaker, conditionalTokens, collateralToken, conditionIds, fee
88+ msg .sender ,
89+ fixedProductMarketMaker,
90+ conditionalTokens,
91+ collateralToken,
92+ conditionIds,
93+ fee
11494 );
11595
11696 if (initialFunds > 0 ) {
11797 currentFunder = msg .sender ;
118- collateralToken.transferFrom (msg .sender , address (this ), initialFunds);
119- collateralToken.approve (address (fixedProductMarketMaker), initialFunds);
98+
99+ // Transfer funding to this factory
100+ collateralToken.transferFrom (
101+ msg .sender ,
102+ address (this ),
103+ initialFunds
104+ );
105+
106+ // Approve the market maker to spend the funding from this factory
107+ collateralToken.approve (
108+ address (fixedProductMarketMaker),
109+ initialFunds
110+ );
111+
112+ // Add funding to the market maker, which will spend the funds from this factory
120113 fixedProductMarketMaker.addFunding (initialFunds, distributionHint);
121- fixedProductMarketMaker.transfer (msg .sender , fixedProductMarketMaker.balanceOf (address (this )));
114+
115+ // Transfer the outcome tokens to the creator
116+ fixedProductMarketMaker.transfer (
117+ msg .sender ,
118+ fixedProductMarketMaker.balanceOf (address (this ))
119+ );
120+
122121 currentFunder = address (0 );
123122 }
124123
0 commit comments