-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDeployPendlePTAmortizedOracle.s.sol
More file actions
193 lines (163 loc) · 8.44 KB
/
DeployPendlePTAmortizedOracle.s.sol
File metadata and controls
193 lines (163 loc) · 8.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.30;
import { PendlePTAmortizedOracleScriptBase } from "./PendlePTAmortizedOracleScriptBase.s.sol";
import { PendlePTAmortizedOracle } from "../src/oracles/vaults/PendlePTAmortizedOracle.sol";
import { console2 } from "forge-std/console2.sol";
/// @title DeployPendlePTAmortizedOracle
/// @notice Deployment script for PendlePTAmortizedOracle - amortized cost pricing for Pendle PT positions
/// @dev Deploys across multiple chains with deterministic addresses
/// @dev Initially grants all roles to DEPLOYER for operational flexibility, then transfers to SUPER_GOVERNOR later
contract DeployPendlePTAmortizedOracle is PendlePTAmortizedOracleScriptBase {
/*//////////////////////////////////////////////////////////////
MAIN FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Deploy PendlePTAmortizedOracle on a single chain
/// @dev Grants all roles (DEFAULT_ADMIN_ROLE, MANAGER_ROLE) to DEPLOYER
/// @param env Environment (0 = prod, 1 = vnet, 2 = staging)
/// @param chainId Chain ID to deploy on
/// @param branchName Branch name for vnet deployments (required when env == 1, ignored otherwise)
function run(uint256 env, uint64 chainId, string calldata branchName) external broadcast(env) {
_validateEnvAndBranchName(env, branchName);
// Use DEPLOYER as admin - will be transferred to SUPER_GOVERNOR_ADDRESS later
address admin = DEPLOYER;
_deploy(env, chainId, admin, branchName);
}
/// @notice Deploy PendlePTAmortizedOracle on multiple chains
/// @dev Grants all roles (DEFAULT_ADMIN_ROLE, MANAGER_ROLE) to DEPLOYER
/// @param env Environment (0 = prod, 1 = vnet, 2 = staging)
/// @param chainIds Array of chain IDs to deploy on
/// @param branchName Branch name for vnet deployments (required when env == 1, ignored otherwise)
function runMultiChain(uint256 env, uint64[] calldata chainIds, string calldata branchName) external broadcast(env) {
_validateEnvAndBranchName(env, branchName);
// Use DEPLOYER as admin - will be transferred to SUPER_GOVERNOR_ADDRESS later
address admin = DEPLOYER;
console2.log("====== Deploying PendlePTAmortizedOracle (Multi-Chain) ======");
console2.log("Environment:", env);
if (env == 1) {
console2.log("Branch Name:", branchName);
}
console2.log("Admin (DEPLOYER):", admin);
console2.log("Number of chains:", chainIds.length);
console2.log("");
for (uint256 i = 0; i < chainIds.length; i++) {
_deploy(env, chainIds[i], admin, branchName);
console2.log("");
}
console2.log("====== Multi-Chain Deployment Complete ======");
}
/// @notice Check if PendlePTAmortizedOracle is deployed
/// @param env Environment (0 = prod, 1 = vnet, 2 = staging)
/// @param chainId Chain ID to check
/// @param branchName Branch name for vnet deployments (required when env == 1, ignored otherwise)
function runCheck(uint256 env, uint64 chainId, string calldata branchName) external broadcast(env) {
_validateEnvAndBranchName(env, branchName);
_setBaseConfiguration(env, branchName);
// Check with DEPLOYER as admin (initial deployment)
address admin = DEPLOYER;
console2.log("====== PendlePTAmortizedOracle Deployment Check ======");
console2.log("Chain ID:", chainId);
console2.log("Environment:", env);
if (env == 1) {
console2.log("Branch Name:", branchName);
}
console2.log("Admin (DEPLOYER):", admin);
console2.log("SUPER_GOVERNOR_ADDRESS:", SUPER_GOVERNOR_ADDRESS);
console2.log("");
address oracleAddr = _computeOracleAddress(env, admin);
bool isDeployed = oracleAddr.code.length > 0;
console2.log("Computed address:", oracleAddr);
console2.log("Is deployed:", isDeployed);
if (isDeployed) {
PendlePTAmortizedOracle oracle = PendlePTAmortizedOracle(oracleAddr);
console2.log("");
console2.log("=== Oracle Role Status ===");
console2.log("DEPLOYER has DEFAULT_ADMIN_ROLE:", oracle.hasRole(oracle.DEFAULT_ADMIN_ROLE(), admin));
console2.log("DEPLOYER has MANAGER_ROLE:", oracle.hasRole(oracle.MANAGER_ROLE(), admin));
console2.log("");
console2.log("SUPER_GOVERNOR has DEFAULT_ADMIN_ROLE:", oracle.hasRole(oracle.DEFAULT_ADMIN_ROLE(), SUPER_GOVERNOR_ADDRESS));
console2.log("SUPER_GOVERNOR has MANAGER_ROLE:", oracle.hasRole(oracle.MANAGER_ROLE(), SUPER_GOVERNOR_ADDRESS));
}
console2.log("");
console2.log("====== Check Complete ======");
}
/*//////////////////////////////////////////////////////////////
INTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Internal deployment function
/// @dev Grants all roles (DEFAULT_ADMIN_ROLE, MANAGER_ROLE) to admin
/// @param env Environment (0 = prod, 1 = vnet, 2 = staging)
/// @param chainId Chain ID to deploy on
/// @param admin Admin address (DEPLOYER)
/// @param branchName Branch name for vnet deployments
function _deploy(uint256 env, uint64 chainId, address admin, string calldata branchName) internal {
_setBaseConfiguration(env, branchName);
console2.log("====== Deploying PendlePTAmortizedOracle ======");
console2.log("Chain ID:", chainId);
console2.log("Environment:", env);
if (env == 1) {
console2.log("Branch Name:", branchName);
}
console2.log("Admin (DEPLOYER):", admin);
console2.log("");
// Validate inputs
require(admin != address(0), "INVALID_ADMIN");
// Get bytecode from generated artifacts
bytes memory bytecode = __getBytecode(ORACLE_KEY, env);
require(bytecode.length > 0, "BYTECODE_NOT_FOUND");
// Deploy - constructor grants DEFAULT_ADMIN_ROLE and MANAGER_ROLE to admin
address oracleAddr = __deployContract(
ORACLE_KEY,
chainId,
__getSalt(ORACLE_KEY),
abi.encodePacked(bytecode, abi.encode(admin))
);
// Verify deployment
PendlePTAmortizedOracle oracle = PendlePTAmortizedOracle(oracleAddr);
require(oracle.hasRole(oracle.DEFAULT_ADMIN_ROLE(), admin), "ADMIN_ROLE_MISMATCH");
require(oracle.hasRole(oracle.MANAGER_ROLE(), admin), "MANAGER_ROLE_MISMATCH");
console2.log("");
console2.log("=== Deployment Verification ===");
console2.log("PendlePTAmortizedOracle deployed at:", oracleAddr);
console2.log("Admin verified:", admin);
console2.log("Has DEFAULT_ADMIN_ROLE:", true);
console2.log("Has MANAGER_ROLE:", true);
// Write JSON output
_writeOracleJson(env, chainId, oracleAddr, branchName);
console2.log("");
console2.log("====== Deployment Complete ======");
}
/// @notice Merge PendlePTAmortizedOracle address into {ChainName}-latest.json
/// @param env Environment (0 = prod, 1 = vnet, 2 = staging)
/// @param chainId Chain ID
/// @param oracleAddr Deployed oracle address
/// @param branchName Branch name for vnet deployments
function _writeOracleJson(
uint256 env,
uint64 chainId,
address oracleAddr,
string calldata branchName
)
internal
{
string memory root = vm.projectRoot();
string memory envFolder;
if (env == 0) {
envFolder = "prod";
} else if (env == 1) {
envFolder = branchName;
} else {
envFolder = "staging";
}
string memory chainName = chainNames[chainId];
string memory outputFolder =
string(abi.encodePacked(root, "/script/output/", envFolder, "/", vm.toString(uint256(chainId)), "/"));
// Create directory if it doesn't exist
vm.createDir(outputFolder, true);
string memory outputPath = string(abi.encodePacked(outputFolder, chainName, "-latest.json"));
// Merge PendlePTAmortizedOracle address into existing JSON
// vm.writeJson with path selector will create file if it doesn't exist or update existing
vm.writeJson(vm.toString(oracleAddr), outputPath, ".PendlePTAmortizedOracle");
console2.log("");
console2.log("PendlePTAmortizedOracle merged into:", outputPath);
}
}