Skip to content

Commit

Permalink
Add deployment script
Browse files Browse the repository at this point in the history
  • Loading branch information
vivinvinh212 committed Jan 23, 2025
1 parent 4777a81 commit 3a52a1c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@ contract DeploySwan is Script {
(proxy, impl) = config.deploySwan();
}
}

contract DeploySwanLottery is Script {
HelperConfig public config;

function run() external returns (address addr) {
config = new HelperConfig();
addr = config.deploySwanLottery();
}
}
26 changes: 26 additions & 0 deletions script/HelperConfig.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {LLMOracleRegistry} from "@firstbatch/dria-oracle-contracts/LLMOracleRegi
import {SwanAgentFactory} from "../src/SwanAgent.sol";
import {SwanArtifactFactory} from "../src/SwanArtifact.sol";
import {Swan} from "../src/Swan.sol";
import {SwanLottery} from "../src/SwanLottery.sol";
import {WETH9} from "../test/contracts/WETH9.sol";

struct Stakes {
Expand Down Expand Up @@ -197,6 +198,31 @@ contract HelperConfig is Script {
return (swanProxy, swanImplementation);
}

function deploySwanLottery() external returns (address) {
// read Swan proxy address from deployments file
string memory dir = "deployments/";
string memory fileName = Strings.toString(block.chainid);
string memory path = string.concat(dir, fileName, ".json");

string memory contractAddresses = vm.readFile(path);
bool isSwanExist = vm.keyExistsJson(contractAddresses, "$.Swan");
require(isSwanExist, "Please deploy Swan first");

address swanProxy = vm.parseJsonAddress(contractAddresses, "$.Swan.proxyAddr");
require(swanProxy != address(0), "Swan proxy address is invalid");

// Default claim window
uint256 defaultClaimWindow = 2;

vm.startBroadcast();
SwanLottery lottery = new SwanLottery(swanProxy, defaultClaimWindow);
vm.stopBroadcast();

writeContractAddress("SwanLottery", address(lottery));

return address(lottery);
}

function writeContractAddress(string memory name, address addr) internal {
// create a deployment file if not exist
string memory dir = "deployments/";
Expand Down

0 comments on commit 3a52a1c

Please sign in to comment.