Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doppler support & Tenderly simulation improvements #223

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion script/50_CoreAndPeriphery.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract CoreAndPeriphery is BatchBuilder {
uint256[1] internal EULER_EARN_HARVEST_COOL_DOWN_CHECK_ON_CHAIN_IDS = [1];

uint256 internal constant HUB_CHAIN_ID = 1;
address internal constant BURN_ADDRESS = 0x000000000000000000000000000000000000dEaD;
address internal constant BURN_ADDRESS = address(0xdead);
uint8 internal constant EUL_DECIMALS = 18;
uint256 internal constant TIMELOCK_MIN_DELAY = 4 days;
address[2] internal EVAULT_FACTORY_GOVERNOR_PAUSERS =
Expand Down
4 changes: 2 additions & 2 deletions script/production/mainnet/clusters/PrimeCluster.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ contract Cluster is ManageCluster {
cluster.externalLTVs = [
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// WETH wstETH cbETH weETH ezETH RETH mETH rsETH ETHx USDC USDT wUSDM wM mTBILL USDS sUSDS tBTC WBTC cbBTC LBTC eBTC solvBTC
/* 0 Escrow WETH */ [uint16(0.00e4), 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.87e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4],
/* 1 Escrow wstETH */ [uint16(0.95e4), 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4],
/* 0 Escrow WETH */ [uint16(0.00e4), 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4],
/* 1 Escrow wstETH */ [uint16(0.95e4), 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.87e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4],
/* 2 Escrow cbETH */ [uint16(0.00e4), 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4],
/* 3 Escrow WEETH */ [uint16(0.00e4), 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4],
/* 4 Escrow USDC */ [uint16(0.00e4), 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4, 0.00e4],
Expand Down
4 changes: 0 additions & 4 deletions script/utils/ScriptExtended.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ abstract contract ScriptExtended is Script {
return _strEq(vm.envOr("use_safe_api", string("")), "--use-safe-api");
}

function isSafeBatchTenderly() internal view returns (bool) {
return _strEq(vm.envOr("safe_batch_tenderly", string("")), "--safe-batch-tenderly");
}

function getAddressesDirPath() internal view returns (string memory) {
string memory path = vm.envOr("ADDRESSES_DIR_PATH", string(""));
path =
Expand Down
23 changes: 0 additions & 23 deletions script/utils/ScriptUtils.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -629,32 +629,9 @@ abstract contract BatchBuilder is ScriptUtils {

transaction.create(true, safe, coreAddresses.evc, getBatchValue(), getBatchCalldata(), safeNonce++);

if (isSafeBatchTenderly()) {
transformBatchForTenderly();
string memory fileName = string.concat(
"SafeTransactionTransformed_", vm.toString(safeNonce - 1), "_", vm.toString(safe), ".json"
);
transaction.initializeAndDump(
true, safe, coreAddresses.evc, getBatchValue(), getBatchCalldata(), safeNonce - 1, fileName
);
}

clearBatchItems();
}

function transformBatchForTenderly() internal {
for (uint256 i = 0; i < batchItems.length; ++i) {
if (bytes4(batchItems[i].data) == IEVault(batchItems[i].targetContract).setLTV.selector) {
bytes memory data = batchItems[i].data;
assembly {
// set the ramp duration to 0 to simulate the immediate effect of the LTV change
mstore(add(data, 132), 0)
}
batchItems[i].data = data;
}
}
}

function dumpBatch(address from) internal {
string memory path = string.concat(vm.projectRoot(), "/script/Batches.json");
string memory json = vm.exists(path) ? vm.readFile(path) : "{}";
Expand Down
66 changes: 66 additions & 0 deletions script/utils/SimulateSafeTxTenderly.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.0;

import {ScriptUtils} from "./ScriptUtils.s.sol";
import {IEVault} from "evk/EVault/IEVault.sol";

contract ClusterDump is ScriptUtils {
function run() public {
string memory json = vm.readFile(vm.envString("CLUSTER_ADDRESSES_PATH"));
address[] memory vaults = getAddressesFromJson(json, ".vaults");

transformCluster(vaults);
}

function transformCluster(address[] memory vaults) public {
// this is to execute the RPC method on Tenderly RPC node
string[] memory setStorageInputs = new string[](7);
setStorageInputs[0] = "cast";
setStorageInputs[1] = "rpc";
setStorageInputs[2] = "--rpc-url";
setStorageInputs[3] = vm.envString("TENDERLY_RPC_URL");
setStorageInputs[4] = "tenderly_setStorageAt";
setStorageInputs[6] = "--raw";

for (uint256 i = 0; i < vaults.length; ++i) {
address[] memory collaterals = IEVault(vaults[i]).LTVList();

for (uint256 j = 0; j < collaterals.length; ++j) {
(
uint16 borrowLTV,
uint16 liquidationLTV,
uint16 initialLiquidationLTV,
uint48 targetTimestamp,
uint32 rampDuration
) = IEVault(vaults[i]).LTVFull(collaterals[j]);

if (targetTimestamp <= block.timestamp) continue;

// we are setting the storage in a way that the LTV ramp down is considered complete
setStorageInputs[5] = string.concat(
'["',
vm.toString(vaults[i]),
'", "',
vm.toString(keccak256(abi.encode(uint256(uint160(collaterals[j])), uint256(14)))),
'", "',
vm.toString(
bytes32(
abi.encodePacked(
uint128(0),
rampDuration,
uint48(block.timestamp),
initialLiquidationLTV,
liquidationLTV,
borrowLTV
)
)
),
'"]'
);

vm.ffi(setStorageInputs);
}
}
}
}
7 changes: 0 additions & 7 deletions script/utils/checkEnvironment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,3 @@ if [[ "$@" == *"--batch-via-safe"* ]]; then
exit 1
fi
fi

if [[ "$@" == *"--safe-batch-tenderly"* ]]; then
if [ -z "$TENDERLY_ACCESS_KEY" ]; then
echo "Error: TENDERLY_ACCESS_KEY environment variable is not set. Please set it and try again."
exit 1
fi
fi
52 changes: 52 additions & 0 deletions script/utils/createTenderlyTestnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

source .env
eval "$(./script/utils/determineArgs.sh "$@")"
eval "set -- $SCRIPT_ARGS"

chainId=$(cast chain-id --rpc-url $DEPLOYMENT_RPC_URL)

response=$(curl -w "\n%{http_code}" --request POST \
--url https://api.tenderly.co/api/v1/account/euler-labs/project/euler/vnets \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header "X-Access-Key: $TENDERLY_ACCESS_KEY" \
--data '{
"slug": "deployment_scripts_'$(date +%s)'",
"fork_config": {
"network_id": '$chainId',
"block_number": "latest"
},
"virtual_network_config": {
"chain_config": {
"chain_id": '$chainId'
}
},
"sync_state_config": {
"enabled": false
},
"explorer_page_config": {
"enabled": false,
"verification_visibility": "abi"
}
}')

http_code=$(echo "$response" | tail -n1)
response_body=$(echo "$response" | sed \$d)

if [ "$http_code" -eq 200 ]; then
TENDERLY_VNET_ID=$(echo "$response_body" | jq -r '.id')
TENDERLY_RPC_URL=$(echo "$response_body" | jq -r '.rpcs[0].url')

if [ -z "$TENDERLY_VNET_ID" ] || [ -z "$TENDERLY_RPC_URL" ]; then
echo "Failed to extract Tenderly ID or RPC URL from response" >&2
exit 1
else
echo "TENDERLY_VNET_ID='$TENDERLY_VNET_ID'"
echo "TENDERLY_RPC_URL='$TENDERLY_RPC_URL'"
fi
else
echo "Tenderly API request failed with status code: $http_code" >&2
echo "Response: $response_body" >&2
exit 1
fi
9 changes: 9 additions & 0 deletions script/utils/dopplerLogin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

doppler login
EXITCODE=$?

if [ "$EXITCODE" -ne "0" ]; then
echo "Doppler CLI is probably not installed. Please go to https://docs.doppler.com/docs/install-cli and follow the instructions for your OS."
exit $EXITCODE
fi
5 changes: 5 additions & 0 deletions script/utils/dopplerSync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

doppler setup -p "evk-periphery" --config "prd"
doppler secrets download --no-file --format env > .env
doppler configure unset config
11 changes: 1 addition & 10 deletions script/utils/executeForgeScript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,11 @@ if [[ "$@" == *"--batch-via-safe"* ]]; then
fi
fi

if [[ "$@" == *"--safe-batch-tenderly"* ]]; then
set -- "${@/--safe-batch-tenderly/}"
safe_batch_tenderly="--safe-batch-tenderly"
fi

if ! env broadcast=$broadcast safe_address=$safe_address safe_nonce=$safe_nonce batch_via_safe=$batch_via_safe use_safe_api=$use_safe_api safe_batch_tenderly=$safe_batch_tenderly \
if ! env broadcast=$broadcast safe_address=$safe_address safe_nonce=$safe_nonce batch_via_safe=$batch_via_safe use_safe_api=$use_safe_api \
forge script script/$scriptPath --rpc-url "$DEPLOYMENT_RPC_URL" $ffi $broadcast --legacy --slow --with-gas-price $gasPrice $@; then
exit 1
fi

if [[ "$broadcast" == "--broadcast" ]] && [[ "$safe_batch_tenderly" == "--safe-batch-tenderly" ]] && compgen -G "script/SafeTransactionTransformed*.json" > /dev/null; then
script/utils/safeBatchTenderly.sh
fi

if [[ "$verify" == "--verify" ]]; then
broadcastFileName=$(basename "${scriptPath%%:*}")

Expand Down
89 changes: 0 additions & 89 deletions script/utils/safeBatchTenderly.sh

This file was deleted.

Loading