Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/factory/BrokerFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract BrokerFactory {
address public vaultImplementation;
address[] public deployedBrokers;

event BrokerCreated(address vaultAddress);

constructor(address _vaultImplementation) {
vaultImplementation = _vaultImplementation;
}

function setBrokerImplementation(address _vaultImplementation) public {
vaultImplementation = _vaultImplementation;
}

function createBroker() public {
address vault = deployClone(vaultImplementation);
deployedBrokers.push(vault);
emit BrokerCreated(vault);
}

function getDeployedBrokers() public view returns (address[] memory) {
return deployedBrokers;
}

function deployClone(address implementation) internal returns (address instance) {
bytes20 targetBytes = bytes20(implementation);
assembly {
let clone := mload(0x40)
mstore(clone, 0x3d602d80600a3d3981f3)
mstore(add(clone, 0x14), targetBytes)
mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf3)
instance := create(0, clone, 0x37)
}
}
}