Skip to content

Commit

Permalink
Implement protocol deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
ashhanai committed Oct 25, 2022
1 parent 21bddb8 commit bf3a839
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
cache
out
broadcast
.idea
.vscode
.env
161 changes: 161 additions & 0 deletions script/PWN.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.16;

import "forge-std/Script.sol";

import "openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

import "@pwn/config/PWNConfig.sol";
import "@pwn/deployer/PWNContractDeployerSalt.sol";
import "@pwn/deployer/PWNDeployer.sol";
import "@pwn/hub/PWNHub.sol";
import "@pwn/hub/PWNHubTags.sol";
import "@pwn/loan/type/PWNSimpleLoan.sol";
import "@pwn/loan/PWNLOAN.sol";
import "@pwn/loan-factory/simple-loan/offer/PWNSimpleLoanListOffer.sol";
import "@pwn/loan-factory/simple-loan/offer/PWNSimpleLoanSimpleOffer.sol";
import "@pwn/loan-factory/simple-loan/request/PWNSimpleLoanSimpleRequest.sol";
import "@pwn/loan-factory/PWNRevokedNonce.sol";


/*
// Deployer
forge script script/PWN.s.sol:Deploy \
--sig "deployDeployer(address)" $ADMIN_ADDRESS \
--rpc-url $GOERLI_URL \
--private-key $PRIVATE_KEY_TESTNET \
--broadcast
// Protocol
forge script script/PWN.s.sol:Deploy \
--sig "deployProtocol(address,address,address,address)" $PWN_DEPLOYER $ADMIN_ADDRESS $OWNER_ADDRESS $FEE_COLLECTOR_ADDRESS \
--rpc-url $GOERLI_URL \
--private-key $PRIVATE_KEY_TESTNET \
--broadcast
*/

contract Deploy is Script {

function deployDeployer(address owner) external {
vm.startBroadcast();
new PWNDeployer(owner);
vm.stopBroadcast();
}

function deployProtocol(
address deployer_,
address admin,
address owner,
address feeCollector
) external {
vm.startBroadcast();

PWNDeployer deployer = PWNDeployer(deployer_);

// Deploy realm

// - Config
PWNConfig configSingleton = new PWNConfig();
PWNConfig config = PWNConfig(deployer.deploy({
salt: PWNContractDeployerSalt.CONFIG,
bytecode: abi.encodePacked(
type(TransparentUpgradeableProxy).creationCode,
abi.encode(
address(configSingleton),
admin,
abi.encodeWithSignature("initialize(address,uint16,address)", owner, 0, feeCollector)
)
)
}));

// - Hub
PWNHub hub = PWNHub(deployer.deploy({
salt: PWNContractDeployerSalt.HUB,
bytecode: abi.encodePacked(
type(PWNHub).creationCode,
abi.encode(admin)
)
}));

// - LOAN token
PWNLOAN loanToken = PWNLOAN(deployer.deploy({
salt: PWNContractDeployerSalt.LOAN,
bytecode: abi.encodePacked(
type(PWNLOAN).creationCode,
abi.encode(address(hub))
)
}));

// - Revoked nonces
PWNRevokedNonce revokedOfferNonce = PWNRevokedNonce(deployer.deploy({
salt: PWNContractDeployerSalt.REVOKED_OFFER_NONCE,
bytecode: abi.encodePacked(
type(PWNRevokedNonce).creationCode,
abi.encode(address(hub), PWNHubTags.LOAN_OFFER)
)
}));
PWNRevokedNonce revokedRequestNonce = PWNRevokedNonce(deployer.deploy({
salt: PWNContractDeployerSalt.REVOKED_REQUEST_NONCE,
bytecode: abi.encodePacked(
type(PWNRevokedNonce).creationCode,
abi.encode(address(hub), PWNHubTags.LOAN_REQUEST)
)
}));

// - Loan types
PWNSimpleLoan simpleLoan = PWNSimpleLoan(deployer.deploy({
salt: PWNContractDeployerSalt.SIMPLE_LOAN_V1,
bytecode: abi.encodePacked(
type(PWNSimpleLoan).creationCode,
abi.encode(address(hub), address(loanToken), address(config))
)
}));

// - Offers
PWNSimpleLoanSimpleOffer simpleOffer = PWNSimpleLoanSimpleOffer(deployer.deploy({
salt: PWNContractDeployerSalt.SIMPLE_LOAN_SIMPLE_OFFER_V1,
bytecode: abi.encodePacked(
type(PWNSimpleLoanSimpleOffer).creationCode,
abi.encode(address(hub), address(revokedOfferNonce))
)
}));
PWNSimpleLoanListOffer listOffer = PWNSimpleLoanListOffer(deployer.deploy({
salt: PWNContractDeployerSalt.SIMPLE_LOAN_LIST_OFFER_V1,
bytecode: abi.encodePacked(
type(PWNSimpleLoanListOffer).creationCode,
abi.encode(address(hub), address(revokedOfferNonce))
)
}));

// - Requests
PWNSimpleLoanSimpleRequest simpleRequest = PWNSimpleLoanSimpleRequest(deployer.deploy({
salt: PWNContractDeployerSalt.SIMPLE_LOAN_SIMPLE_REQUEST_V1,
bytecode: abi.encodePacked(
type(PWNSimpleLoanSimpleRequest).creationCode,
abi.encode(address(hub), address(revokedRequestNonce))
)
}));

// Set hub tags
hub.setTag(address(simpleLoan), PWNHubTags.ACTIVE_LOAN, true);

hub.setTag(address(simpleOffer), PWNHubTags.SIMPLE_LOAN_TERMS_FACTORY, true);
hub.setTag(address(simpleOffer), PWNHubTags.LOAN_OFFER, true);

hub.setTag(address(listOffer), PWNHubTags.SIMPLE_LOAN_TERMS_FACTORY, true);
hub.setTag(address(listOffer), PWNHubTags.LOAN_OFFER, true);

hub.setTag(address(simpleRequest), PWNHubTags.SIMPLE_LOAN_TERMS_FACTORY, true);
hub.setTag(address(simpleRequest), PWNHubTags.LOAN_REQUEST, true);


vm.stopBroadcast();
}

}

contract Scripts {

}
16 changes: 8 additions & 8 deletions src/deployer/PWNContractDeployerSalt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ library PWNContractDeployerSalt {
string internal constant VERSION = "0.1.0";

// Singletons
bytes32 constant internal config = keccak256("PWNConfig");
bytes32 constant internal hub = keccak256("PWNHub");
bytes32 constant internal CONFIG = keccak256("PWNConfig");
bytes32 constant internal HUB = keccak256("PWNHub");
bytes32 constant internal LOAN = keccak256("PWNLOAN");
bytes32 constant internal revokedOfferNonce = keccak256("PWNRevokedOfferNonce");
bytes32 constant internal revokedRequestNonce = keccak256("PWNRevokedRequestNonce");
bytes32 constant internal REVOKED_OFFER_NONCE = keccak256("PWNRevokedOfferNonce");
bytes32 constant internal REVOKED_REQUEST_NONCE = keccak256("PWNRevokedRequestNonce");

// Loan types
bytes32 constant internal simpleLoanV1 = keccak256("PWNSimpleLoanV1");
bytes32 constant internal SIMPLE_LOAN_V1 = keccak256("PWNSimpleLoanV1");

// Offer types
bytes32 constant internal simpleLoanSimpleOfferV1 = keccak256("PWNSimpleLoanSimpleOfferV1");
bytes32 constant internal simpleLoanListOfferV1 = keccak256("PWNSimpleLoanListOfferV1");
bytes32 constant internal SIMPLE_LOAN_SIMPLE_OFFER_V1 = keccak256("PWNSimpleLoanSimpleOfferV1");
bytes32 constant internal SIMPLE_LOAN_LIST_OFFER_V1 = keccak256("PWNSimpleLoanListOfferV1");

// Request types
bytes32 constant internal simpleLoanSimpleRequestV1 = keccak256("PWNSimpleLoanSimpleRequestV1");
bytes32 constant internal SIMPLE_LOAN_SIMPLE_REQUEST_V1 = keccak256("PWNSimpleLoanSimpleRequestV1");

}

0 comments on commit bf3a839

Please sign in to comment.