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
90 changes: 65 additions & 25 deletions contracts/SimpleSwapFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,77 @@ import "@openzeppelin/contracts/proxy/Clones.sol";
@notice This contract deploys SimpleSwap contracts
*/
contract SimpleSwapFactory {
/* event fired on every new SimpleSwap deployment */
event SimpleSwapDeployed(address contractAddress);

/* event fired on every new SimpleSwap deployment */
event SimpleSwapDeployed(address contractAddress);
/* mapping to keep track of which contracts were deployed by this factory */
mapping(address => bool) public deployedContracts;

/* mapping to keep track of which contracts were deployed by this factory */
mapping (address => bool) public deployedContracts;
/* mapping to keep track of migrations, pair is issuer => newContractAddress */
mapping(address => address) public migratedContracts;

/* address of the ERC20-token, to be used by the to-be-deployed chequebooks */
address public ERC20Address;
/* address of the code contract from which all chequebooks are cloned */
address public master;
/* address of the ERC20-token, to be used by the to-be-deployed chequebooks */
address public ERC20Address;
/* address of the code contract from which all chequebooks are cloned */
address public master;

constructor(address _ERC20Address) {
ERC20Address = _ERC20Address;
ERC20SimpleSwap _master = new ERC20SimpleSwap();
// set the issuer of the master contract to prevent misuse
_master.init(address(1), address(0), 0);
master = address(_master);
}
/**
constructor(address _ERC20Address) {
ERC20Address = _ERC20Address;
ERC20SimpleSwap _master = new ERC20SimpleSwap();
// set the issuer of the master contract to prevent misuse
_master.init(address(1), address(0), 0);
master = address(_master);
}

/**
@notice creates a clone of the master SimpleSwap contract
@param issuer the issuer of cheques for the new chequebook
@param defaultHardDepositTimeoutDuration duration in seconds which by default will be used to reduce hardDeposit allocations
@param salt salt to include in create2 to enable the same address to deploy multiple chequebooks
*/
function deploySimpleSwap(address issuer, uint defaultHardDepositTimeoutDuration, bytes32 salt)
public returns (address) {
address contractAddress = Clones.cloneDeterministic(master, keccak256(abi.encode(msg.sender, salt)));
ERC20SimpleSwap(contractAddress).init(issuer, ERC20Address, defaultHardDepositTimeoutDuration);
deployedContracts[contractAddress] = true;
emit SimpleSwapDeployed(contractAddress);
return contractAddress;
}
}
function deploySimpleSwap(
address issuer,
uint defaultHardDepositTimeoutDuration,
bytes32 salt
) public returns (address) {
address contractAddress = Clones.cloneDeterministic(
master,
keccak256(abi.encode(msg.sender, salt))
);
ERC20SimpleSwap(contractAddress).init(
issuer,
ERC20Address,
defaultHardDepositTimeoutDuration
);
deployedContracts[contractAddress] = true;
migratedContracts[issuer] = contractAddress;
emit SimpleSwapDeployed(contractAddress);
return contractAddress;
}

/**
@notice migrates a clone of a master SimpleSwap contract
@param issuer the issuer of cheques for the new chequebook
@param defaultHardDepositTimeoutDuration duration in seconds which by default will be used to reduce hardDeposit allocations
@param salt salt to include in create2 to enable the same address to deploy multiple chequebooks
*/
function migrateSimpleSwap(
address issuer,
uint defaultHardDepositTimeoutDuration,
bytes32 salt,
address _master
) public returns (address) {
address newContractAddress = Clones.cloneDeterministic(
_master,
keccak256(abi.encode(issuer, salt))
);
ERC20SimpleSwap(newContractAddress).init(
issuer,
ERC20Address,
defaultHardDepositTimeoutDuration
);
deployedContracts[newContractAddress] = true;
emit SimpleSwapDeployed(newContractAddress);
return newContractAddress;
}
}
70 changes: 57 additions & 13 deletions deployments/testnet/SimpleSwapFactory.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require("solidity-coverage");
require("dotenv/config");
require("hardhat-deploy");
require("@nomicfoundation/hardhat-verify");
require("@nomicfoundation/hardhat-ethers");

const PRIVATE_RPC_MAINNET = !process.env.PRIVATE_RPC_MAINNET
? undefined
Expand Down Expand Up @@ -48,6 +49,11 @@ module.exports = {
accounts,
chainId: 11155111,
},
goerli: {
url: "https://eth-goerli.g.alchemy.com/v2/UbKbbJpAxim12srTJ5vUo3DdQy0WPdHK",
accounts,
chainId: 5,
},
mainnet: {
url: PRIVATE_RPC_MAINNET
? PRIVATE_RPC_MAINNET
Expand All @@ -60,6 +66,7 @@ module.exports = {
apiKey: {
mainnet: mainnetEtherscanKey || "",
testnet: testnetEtherscanKey || "",
goerli: testnetEtherscanKey || "",
},
customChains: [
{
Expand All @@ -70,6 +77,14 @@ module.exports = {
browserURL: "https://sepolia.etherscan.io/address/",
},
},
{
network: "goerli",
chainId: 5,
urls: {
apiURL: "https://api-goerli.etherscan.io/api",
browserURL: "https://goerli.etherscan.io/address/",
},
},
{
network: "mainnet",
chainId: 100,
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
"url": "https://github.com/ethersphere/swap-swear-and-swindle.git"
},
"dependencies": {
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@nomicfoundation/hardhat-verify": "^1.0.0",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@openzeppelin/contracts": "^3.4.1-solc-0.7-2",
"dotenv": "^16.0.3"
"dotenv": "^16.0.3",
"ethers": "^6.9.0"
},
"devDependencies": {
"@nomiclabs/hardhat-truffle5": "^2.0.2",
Expand All @@ -39,4 +41,4 @@
"keywords": [],
"author": "",
"license": "ISC"
}
}
Loading