Skip to content

Commit

Permalink
add verify code and utils to script
Browse files Browse the repository at this point in the history
  • Loading branch information
radar bear committed Aug 26, 2024
1 parent bb5d04f commit b1b01ed
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 70 deletions.
129 changes: 65 additions & 64 deletions script/deployChainlinkDSPortal.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,95 +4,96 @@ pragma solidity ^0.8.19;

import "forge-std/Script.sol";
import "../src/oracle/ChainlinkDS.sol";
import "./Utils.s.sol";

contract ChainlinkDSPortalScript is Script {
// add this to be excluded from coverage report
function test() public { }
function test() public {}

function run() external {
uint256 deployerPrivateKey = vm.envUint("JOJO_DEPLOYER_PK");
vm.startBroadcast(deployerPrivateKey);
address _dsVerifyProxy = 0xDE1A28D87Afd0f546505B28AB50410A5c3a7387a;
uint256 _usdcHeartbeat = 86400;
address _usdcSource = 0x7e860098F58bBFC8648a4311b374B1D669a2bc6B;
address _reportSubmitter = 0x58D6e7ACcC617758F890Ba796d34777d2c46210C;

ChainlinkDSPortal chainlinkDSPortal = new ChainlinkDSPortal(
// address _dsVerifyProxy
0xDE1A28D87Afd0f546505B28AB50410A5c3a7387a,
// uint256 _usdcHeartbeat (in second)
86400,
// address _usdcSource
0x7e860098F58bBFC8648a4311b374B1D669a2bc6B
_dsVerifyProxy,
_reportSubmitter,
_usdcHeartbeat,
_usdcSource
);

vm.stopBroadcast();

// 自动执行验证
string memory etherscanApiKey = vm.envString("ETHERSCAN_API_KEY");
string[] memory inputs = new string[](6);
string memory chainId = vm.envString("CHAIN_ID");
bytes memory arguments = abi.encode(_dsVerifyProxy,_reportSubmitter,_usdcHeartbeat,_usdcSource);
string[] memory inputs = new string[](8);
inputs[0] = "forge";
inputs[1] = "verify-contract";
inputs[2] = addressToString(address(chainlinkDSPortal));
inputs[2] = Utils.addressToString(address(chainlinkDSPortal));
inputs[3] = "src/oracle/ChainlinkDS.sol:ChainlinkDSPortal";
inputs[4] = "--etherscan-api-key";
inputs[5] = etherscanApiKey;

bytes memory res = vm.ffi(inputs);
console.log(string(res));
}

function addressToString(address _addr) internal pure returns (string memory) {
bytes32 value = bytes32(uint256(uint160(_addr)));
bytes memory alphabet = "0123456789abcdef";

bytes memory str = new bytes(42);
str[0] = '0';
str[1] = 'x';
for (uint256 i = 0; i < 20; i++) {
str[2 + i * 2] = alphabet[uint8(value[i + 12] >> 4)];
str[3 + i * 2] = alphabet[uint8(value[i + 12] & 0x0f)];
}
return string(str);
inputs[4] = "--chain-id";
inputs[5] = chainId;
inputs[6] = "--constructor-args";
inputs[7] = Utils.bytesToStringWithout0x(arguments);
Utils.logInputs(inputs);
}
}

contract ChainlinkDSPortalScriptTestnet is Script {
contract ChainlinkDSPortalScriptBaseTestnet is Script {
// add this to be excluded from coverage report
function test() public { }
function test() public {}

function run() external {
uint256 deployerPrivateKey = vm.envUint("JOJO_DEPLOYER_PK");
vm.startBroadcast(deployerPrivateKey);
new ChainlinkDSPortal(
// address _dsVerifyProxy
0x8Ac491b7c118a0cdcF048e0f707247fD8C9575f9,
// uint256 _usdcHeartbeat (in second)
86400,
// address _usdcSource
0xd30e2101a97dcbAeBCBC04F14C3f624E67A35165
address _dsVerifyProxy = 0x8Ac491b7c118a0cdcF048e0f707247fD8C9575f9;
uint256 _usdcHeartbeat = 86400;
address _usdcSource = 0xd30e2101a97dcbAeBCBC04F14C3f624E67A35165;
address _reportSubmitter = 0x1cA8dd11fF12Fc22cd2ab83317cFd90df6a73694;
// address _owner = 0x1cA8dd11fF12Fc22cd2ab83317cFd90df6a73694;

ChainlinkDSPortal chainlinkDSPortal = new ChainlinkDSPortal(
_dsVerifyProxy,
_reportSubmitter,
_usdcHeartbeat,
_usdcSource
);

chainlinkDSPortal.newPriceSources(
"BTCUSDC",
0x0FB99723Aee6f420beAD13e6bBB79b7E6F034298,
0x00037da06d56d083fe599397a4769a042d63aa73dc4ef57709d31e9971a5b439,
20,
30,
86400
);
chainlinkDSPortal.newPriceSources(
"ETHUSDC",
0x4aDC67696bA383F43DD60A9e78F2C97Fbbfc7cb1,
0x000359843a543ee2fe414dc14c7e7920ef10f4372990b79d6361cdc0dd1ba782,
20,
30,
86400
);
// chainlinkDSPortal.transferOwnership(_owner);
vm.stopBroadcast();

// 自动执行验证
// string memory etherscanApiKey = vm.envString("ETHERSCAN_API_KEY");
// string[] memory inputs = new string[](6);
// inputs[0] = "forge";
// inputs[1] = "verify-contract";
// inputs[2] = addressToString(address(chainlinkDSPortal));
// inputs[3] = "src/oracle/ChainlinkDS.sol:ChainlinkDSPortal";
// inputs[4] = "--etherscan-api-key";
// inputs[5] = etherscanApiKey;

// bytes memory res = vm.ffi(inputs);
// console.log(string(res));
}

function addressToString(address _addr) internal pure returns (string memory) {
bytes32 value = bytes32(uint256(uint160(_addr)));
bytes memory alphabet = "0123456789abcdef";

bytes memory str = new bytes(42);
str[0] = '0';
str[1] = 'x';
for (uint256 i = 0; i < 20; i++) {
str[2 + i * 2] = alphabet[uint8(value[i + 12] >> 4)];
str[3 + i * 2] = alphabet[uint8(value[i + 12] & 0x0f)];
}
return string(str);
string memory chainId = vm.envString("CHAIN_ID");
bytes memory arguments = abi.encode(_dsVerifyProxy,_reportSubmitter,_usdcHeartbeat,_usdcSource);
string[] memory inputs = new string[](8);
inputs[0] = "forge";
inputs[1] = "verify-contract";
inputs[2] = Utils.addressToString(address(chainlinkDSPortal));
inputs[3] = "src/oracle/ChainlinkDS.sol:ChainlinkDSPortal";
inputs[4] = "--chain-id";
inputs[5] = chainId;
inputs[6] = "--constructor-args";
inputs[7] = Utils.bytesToStringWithout0x(arguments);
Utils.logInputs(inputs);
}
}
}
2 changes: 1 addition & 1 deletion script/deployEmergencyOracle.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract EmergencyOracleScript is Script {
function run() public {
uint256 deployerPrivateKey = vm.envUint("JOJO_DEPLOYER_PK");
vm.startBroadcast(deployerPrivateKey);
new EmergencyOracle("WSTETH/USDC");
new EmergencyOracle("WUSDM/USDC");
vm.stopBroadcast();
}
}
10 changes: 5 additions & 5 deletions script/deployFlashLiquidate.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ contract FlashLiquidateScript is Script {
vm.startBroadcast(deployerPrivateKey);
new FlashLoanLiquidate(
// jusdBank
0xb0D9Ce393f3483449be357EF715a3492858f8a5E,
0x8Eb3E014e1D6aB354dFBd44880eb7E6b403EE3fE,
// jusdExchange
0x33a317a875Bc23af2E083555E5E46e3ac559C40A,
0x78307eaa9A30a27639f656Ead99298C065C07b66,
// _USDC
0x834D14F87700e5fFc084e732c7381673133cdbcC,
0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913,
// _JUSD
0xDd29a69462a08006Fda068D090b44B045958C5B7,
0x0013BbB9F5d913F700B10E316768e7935D1A13d4,
// _insurance
0x81c438F53Aeb554db3310104535Ab60967d78059
0x9C9DD45db8045954309078dC5f235024bC75Cb81
);
vm.stopBroadcast();
}
Expand Down
54 changes: 54 additions & 0 deletions script/utils.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.19;

import "forge-std/Script.sol";

library Utils {
/**
* @dev Logs the inputs of a function call.
* @param inputs The inputs to log.
*/
function logInputs(string[] memory inputs) public view {
string memory concatenatedInputs = "";
for (uint256 i = 0; i < inputs.length; i++) {
concatenatedInputs = string(abi.encodePacked(concatenatedInputs, inputs[i], " "));
}
console.log(concatenatedInputs);
}

/**
* @dev Converts an address to its string representation.
* @param addr The address to convert.
* @return The string representation of the address.
*/
function addressToString(address addr) internal pure returns (string memory) {
bytes32 value = bytes32(uint256(uint160(addr)));
bytes memory alphabet = "0123456789abcdef";

bytes memory str = new bytes(42);
str[0] = '0';
str[1] = 'x';
for (uint256 i = 0; i < 20; i++) {
str[2 + i * 2] = alphabet[uint8(value[i + 12] >> 4)];
str[3 + i * 2] = alphabet[uint8(value[i + 12] & 0x0f)];
}
return string(str);
}

/**
* @dev Converts bytes to a string without the '0x' prefix.
* @param data The bytes to convert.
* @return The string representation of the bytes.
*/
function bytesToStringWithout0x(bytes memory data) internal pure returns (string memory) {
bytes memory alphabet = "0123456789abcdef";

bytes memory str = new bytes(data.length * 2);
for (uint256 i = 0; i < data.length; i++) {
str[i * 2] = alphabet[uint8(data[i] >> 4)];
str[i * 2 + 1] = alphabet[uint8(data[i] & 0x0f)];
}
return string(str);
}
}

0 comments on commit b1b01ed

Please sign in to comment.