Skip to content
Open
Show file tree
Hide file tree
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
Binary file removed .DS_Store
Binary file not shown.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,34 @@ just delegates all calls to the master contract address.

`npm install @optionality.io/clone-factory`

```javascript
```solidity
import "./Thing.sol";
import "@optionality.io/clone-factory/contracts/CloneFactory.sol";
import "zeppelin-solidity/contracts/ownership/Ownable.sol";


contract ThingFactory is Ownable, CloneFactory {

address public libraryAddress;
address public target;

event ThingCreated(address newThingAddress);

function ThingFactory(address _libraryAddress) public {
libraryAddress = _libraryAddress;
function ThingFactory(address _target) public {
target = _target;
}

function setLibraryAddress(address _libraryAddress) public onlyOwner {
libraryAddress = _libraryAddress;
function setTarget(address _target) public onlyOwner {
target = _target;
}

function createThing(string _name, uint _value) public onlyOwner {
address clone = createClone(libraryAddress);
address clone = createClone(target);
Thing(clone).init(_name, _value);
ThingCreated(clone);
}
}
```

This will inexpensively create a mimimalist forwarding shim contract that will delegate all calls to the contract libraryAddress
This will inexpensively create a mimimalist forwarding shim contract that will delegate all calls to the `target` contract.

## WARNINGS
- Be sure that the master contract is pre-initialized. You can usually accomplish this in your constructor as the only time the master contract constructor is called is during the master contract's creation. Clone contracts do not call the constructor, but are initialized with an inline initialization method (as demonstrated above).
Expand Down
16 changes: 8 additions & 8 deletions test/ShortThingFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ import "../contracts/CloneFactory17.sol";

contract ShortThingFactory is CloneFactory17 {

address public libraryAddress;
address public target;

event ThingCreated(address newThingAddress, address libraryAddress);
event ThingCreated(address newThingAddress, address target);

constructor(address _libraryAddress) public {
libraryAddress = _libraryAddress;
constructor(address _target) public {
target = _target;
}

function onlyCreate() public {
createClone(libraryAddress);
createClone(target);
}

function createThing(string _name, uint _value) public {
address clone = createClone(libraryAddress);
address clone = createClone(target);
Thing(clone).init(_name, _value);
emit ThingCreated(clone, libraryAddress);
emit ThingCreated(clone, target);
}


function isThing(address thing) public view returns (bool) {
return isClone(libraryAddress, thing);
return isClone(target, thing);
}

}
16 changes: 8 additions & 8 deletions test/ThingFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ import "../contracts/CloneFactory.sol";

contract ThingFactory is CloneFactory {

address public libraryAddress;
address public target;

event ThingCreated(address newThingAddress, address libraryAddress);
event ThingCreated(address newThingAddress, address target);

constructor (address _libraryAddress) public {
libraryAddress = _libraryAddress;
constructor (address _target) public {
target = _target;
}

function onlyCreate() public {
createClone(libraryAddress);
createClone(target);
}

function createThing(string _name, uint _value) public {
address clone = createClone(libraryAddress);
address clone = createClone(target);
Thing(clone).init(_name, _value);
emit ThingCreated(clone, libraryAddress);
emit ThingCreated(clone, target);
}

function isThing(address thing) public view returns (bool) {
return isClone(libraryAddress, thing);
return isClone(target, thing);
}

function incrementThings(address[] things) public returns (bool) {
Expand Down