Skip to content

Commit

Permalink
Merge pull request #49 from P4-Games/feature/update-deploy-scripts
Browse files Browse the repository at this point in the history
[feat] added new and fixed deploy scripts & tests
  • Loading branch information
tomasfrancizco authored Dec 31, 2024
2 parents ca91b44 + 8a7e79c commit 78e80f5
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 126 deletions.
7 changes: 4 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ast = true
build_info = true
extra_output = ["storageLayout"]
libs = ["lib"]
remappings = ['@openzeppelin/contracts=lib/openzeppelin-contracts/contracts', '@openzeppelin/contracts-upgradeable=lib/openzeppelin-contracts-upgradeable/contracts']

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
remappings = [
'@openzeppelin/contracts=lib/openzeppelin-contracts/contracts',
'@openzeppelin/contracts-upgradeable=lib/openzeppelin-contracts-upgradeable/contracts',
]
98 changes: 98 additions & 0 deletions script/DeployAllContracts.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

import {Script, console} from "forge-std/Script.sol";
import {HelperConfig} from "./HelperConfig.s.sol";
import {ChatterPay} from "../src/L2/ChatterPay.sol";
import {ChatterPayWalletFactory} from "../src/L2/ChatterPayWalletFactory.sol";
import {ChatterPayPaymaster} from "../src/L2/ChatterPayPaymaster.sol";
import {ChatterPayNFT} from "../src/L2/ChatterPayNFT.sol";
import {ChatterPayVault} from "../src/L2/ChatterPayVault.sol";
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";

contract DeployAllContracts is Script {
uint256 ethSepoliaChainId = 11155111;
uint256 scrollSepoliaChainId = 534351;
uint256 scrollDevnetChainId = 2227728;
uint256 arbitrumSepoliaChainId = 421614;

HelperConfig helperConfig;
ChatterPay chatterPay;
ChatterPayWalletFactory factory;
ChatterPayPaymaster paymaster;
ChatterPayNFT chatterPayNFT;
ChatterPayVault vault;
address entryPoint;
address backendEOA;
string NFTBaseUri = "https://back.chatterpay.net/nft/metadata/opensea/";

function run()
public
returns (
HelperConfig,
ChatterPay,
ChatterPayWalletFactory,
ChatterPayNFT,
ChatterPayPaymaster
)
{
helperConfig = new HelperConfig();
HelperConfig.NetworkConfig memory config = helperConfig.getConfig();
entryPoint = config.entryPoint;
backendEOA = config.account;

vm.startBroadcast(config.account);

console.log(
"Deploying ChatterPay contracts in chainId %s with account: %s",
block.chainid,
config.account
);

deployPaymaster();
deployChatterPay();
deployFactory();
deployNFT();
deployVault();

vm.stopBroadcast();

return (helperConfig, chatterPay, factory, chatterPayNFT, paymaster);
}

function deployPaymaster() internal {
paymaster = new ChatterPayPaymaster(entryPoint, backendEOA);
console.log("Paymaster deployed to address %s", address(paymaster));
}

function deployChatterPay() internal {
chatterPay = new ChatterPay();
console.log("ChatterPay Proxy deployed to:", address(chatterPay));
chatterPay = ChatterPay(payable(chatterPay));
}

function deployFactory() internal {
factory = new ChatterPayWalletFactory(
address(chatterPay),
entryPoint,
backendEOA,
address(paymaster)
);
console.log("Factory deployed to:", address(factory));
}

function deployNFT() internal {
address proxy = Upgrades.deployUUPSProxy(
"ChatterPayNFT.sol",
abi.encodeCall(ChatterPayNFT.initialize, (backendEOA, NFTBaseUri))
);
console.log("NFT deployed to:", address(proxy));
chatterPayNFT = ChatterPayNFT(proxy);
}

function deployVault() internal {
vault = new ChatterPayVault();
console.log("Vault deployed to:", address(vault));
}
}
115 changes: 115 additions & 0 deletions script/DeployAllContracts.v2.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

import {Script, console} from "forge-std/Script.sol";
import {HelperConfig} from "./HelperConfig.s.sol";
import {ChatterPay} from "../src/L2/ChatterPay.sol";
import {ChatterPayWalletFactory} from "../src/L2/ChatterPayWalletFactory.sol";
import {ChatterPayPaymaster} from "../src/L2/ChatterPayPaymaster.sol";
import {TokensPriceFeeds} from "../src/Ethereum/TokensPriceFeeds.sol";
import {ChatterPayNFT} from "../src/L2/ChatterPayNFT.sol";
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";
import {DevOpsTools} from "lib/foundry-devops/src/DevOpsTools.sol";

contract DeployChatterPay is Script {
uint256 ethSepoliaChainId = 11155111;
uint256 scrollSepoliaChainId = 534351;
uint256 scrollDevnetChainId = 2227728;
uint256 arbitrumSepoliaChainId = 421614;

HelperConfig helperConfig;
ChatterPay chatterPay;
ChatterPayWalletFactory factory;
ChatterPayPaymaster paymaster;
TokensPriceFeeds tokensPriceFeeds;
ChatterPayNFT chatterPayNFT;

address backendEOA = vm.envAddress("BACKEND_EOA");

function run() public {
deployChatterPayOnL2();
}

function deployChatterPayOnL2()
public
returns (
HelperConfig,
ChatterPay,
ChatterPayWalletFactory,
TokensPriceFeeds,
ChatterPayNFT,
ChatterPayPaymaster
)
{
// Deploy HelperConfig
helperConfig = new HelperConfig();
HelperConfig.NetworkConfig memory config = helperConfig.getConfig();

vm.startBroadcast(config.account);
console.log(
"Deploying ChatterPay contracts in chainId %s with account: %s",
block.chainid,
config.account
);

// Deploy Logic
// CREATE2 for production
// chatterPay = new ChatterPay{
// salt: keccak256(abi.encodePacked(config.account))
// }();
chatterPay = new ChatterPay();
console.log("ChatterPay deployed to address %s", address(chatterPay));

// Deploy Paymaster
// CREATE2 for production
// paymaster = new ChatterPayPaymaster{
// salt: keccak256(abi.encodePacked(config.account))
// }(config.account);
address backendSigner = vm.envAddress("BACKEND_EOA");
paymaster = new ChatterPayPaymaster(config.entryPoint, backendSigner);
console.log("Paymaster deployed to address %s", address(paymaster));

// Deploy Factory (with Wallet Implementation, EntryPoint, Account & Paymaster addresses as parameters)
// CREATE2 for production
// factory = new ChatterPayWalletFactory{
// salt: keccak256(abi.encodePacked(config.account))
// }(address(chatterPay), config.entryPoint, config.account, paymaster);
factory = new ChatterPayWalletFactory(address(chatterPay), config.entryPoint, config.account, address(paymaster));
console.log(
"WalletFactory deployed to address %s",
address(factory)
);

chatterPay.initialize(
config.entryPoint,
config.account,
address(paymaster)
);
console.log("ChatterPay initialized");

// Deploy ChatterPayNFT
// main: "https://chatterpay-back-671609149217.us-central1.run.app/"
// dev: "https://chatterpay-back-staging-671609149217.us-central1.run.app/"
string
memory baseURI = "https://chatterpay-back-staging-671609149217.us-central1.run.app/";
address proxyNFT = Upgrades.deployUUPSProxy(
"ChatterPayNFT.sol",
abi.encodeCall(ChatterPayNFT.initialize, (config.account, baseURI))
);

console.log("proxyNFT deployed to address %s", address(proxyNFT));
chatterPayNFT = ChatterPayNFT(proxyNFT);

vm.stopBroadcast();

return (
helperConfig,
chatterPay,
factory,
tokensPriceFeeds,
chatterPayNFT,
paymaster
);
}
}
107 changes: 14 additions & 93 deletions script/DeployChatterPay.s.sol
Original file line number Diff line number Diff line change
@@ -1,115 +1,36 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;
pragma solidity ^0.8.0;

import {Script, console} from "forge-std/Script.sol";
import {HelperConfig} from "./HelperConfig.s.sol";
import {ChatterPay} from "../src/L2/ChatterPay.sol";
import {ChatterPayWalletFactory} from "../src/L2/ChatterPayWalletFactory.sol";
import {ChatterPayPaymaster} from "../src/L2/ChatterPayPaymaster.sol";
import {TokensPriceFeeds} from "../src/Ethereum/TokensPriceFeeds.sol";
import {ChatterPayNFT} from "../src/L2/ChatterPayNFT.sol";
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";
import {DevOpsTools} from "lib/foundry-devops/src/DevOpsTools.sol";
import {HelperConfig} from "./HelperConfig.s.sol";
import {ChatterPay} from "../src/L2/ChatterPay.sol";

contract DeployChatterPay is Script {
uint256 ethSepoliaChainId = 11155111;
uint256 scrollSepoliaChainId = 534351;
uint256 scrollDevnetChainId = 2227728;
uint256 arbitrumSepoliaChainId = 421614;

HelperConfig helperConfig;
ChatterPay chatterPay;
ChatterPayWalletFactory factory;
ChatterPayPaymaster paymaster;
TokensPriceFeeds tokensPriceFeeds;
ChatterPayNFT chatterPayNFT;

address backendEOA = vm.envAddress("BACKEND_EOA");

function run() public {
deployChatterPayOnL2();
}
function run() external {

function deployChatterPayOnL2()
public
returns (
HelperConfig,
ChatterPay,
ChatterPayWalletFactory,
TokensPriceFeeds,
ChatterPayNFT,
ChatterPayPaymaster
)
{
// Deploy HelperConfig
helperConfig = new HelperConfig();
HelperConfig.NetworkConfig memory config = helperConfig.getConfig();

vm.startBroadcast(config.account);
console.log(
"Deploying ChatterPay contracts in chainId %s with account: %s",
block.chainid,
config.account
// This will get the address of the most recent deployment of the ChatterPayPaymaster contract
// If you want to set the paymaster to a different address, you can do so here
address paymaster = DevOpsTools.get_most_recent_deployment(
"ChatterPayPaymaster",
block.chainid
);

// Deploy Logic
// CREATE2 for production
// chatterPay = new ChatterPay{
// salt: keccak256(abi.encodePacked(config.account))
// }();
chatterPay = new ChatterPay();
console.log("ChatterPay deployed to address %s", address(chatterPay));
vm.startBroadcast();

// Deploy Paymaster
// CREATE2 for production
// paymaster = new ChatterPayPaymaster{
// salt: keccak256(abi.encodePacked(config.account))
// }(config.account);
address backendSigner = vm.envAddress("BACKEND_EOA");
paymaster = new ChatterPayPaymaster(config.entryPoint, backendSigner);
console.log("Paymaster deployed to address %s", address(paymaster));

// Deploy Factory (with Wallet Implementation, EntryPoint, Account & Paymaster addresses as parameters)
// CREATE2 for production
// factory = new ChatterPayWalletFactory{
// salt: keccak256(abi.encodePacked(config.account))
// }(address(chatterPay), config.entryPoint, config.account, paymaster);
factory = new ChatterPayWalletFactory(address(chatterPay), config.entryPoint, config.account, address(paymaster));
console.log(
"WalletFactory deployed to address %s",
address(factory)
);

chatterPay.initialize(
config.entryPoint,
config.account,
address(paymaster)
address proxy = Upgrades.deployUUPSProxy(
"ChatterPay.sol",
abi.encodeCall(ChatterPay.initialize, (config.entryPoint, config.account, paymaster))
);
console.log("ChatterPay initialized");

// Deploy ChatterPayNFT
// main: "https://chatterpay-back-671609149217.us-central1.run.app/"
// dev: "https://chatterpay-back-staging-671609149217.us-central1.run.app/"
string
memory baseURI = "https://chatterpay-back-staging-671609149217.us-central1.run.app/";
address proxyNFT = Upgrades.deployUUPSProxy(
"ChatterPayNFT.sol",
abi.encodeCall(ChatterPayNFT.initialize, (config.account, baseURI))
);

console.log("proxyNFT deployed to address %s", address(proxyNFT));
chatterPayNFT = ChatterPayNFT(proxyNFT);
console.log("ChatterPay Proxy deployed to:", address(proxy));

vm.stopBroadcast();

return (
helperConfig,
chatterPay,
factory,
tokensPriceFeeds,
chatterPayNFT,
paymaster
);
}
}
Loading

0 comments on commit 78e80f5

Please sign in to comment.