Skip to content

Commit

Permalink
Merge branch 'master' into runtime-fv
Browse files Browse the repository at this point in the history
  • Loading branch information
aazhou1 authored Nov 21, 2024
2 parents 8cb9e9e + 51e7032 commit 7b62ea2
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 13 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI

on: [push]

jobs:
foundry-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Install forge-std
run: |
forge install foundry-rs/forge-std --no-commit
forge remappings > remappings.txt
- name: Run non-Kontrol tests
run: |
forge test --no-match-path "src/test/kontrol/*" -vvv
- name: Run snapshot without Kontrol tests
run: forge snapshot --no-match-path "src/test/kontrol/*"


50 changes: 50 additions & 0 deletions .github/workflows/deploy-sepolia-governance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "[sepolia-deploy] deploy governance for strategy"
on:
workflow_dispatch:
inputs:
proposer:
description: 'Proposer address'
required: true
default: '0x'
strategy:
description: 'Strategy Address'
required: true
default: '0x'
governorRoleAddress:
description: 'Governor role address'
required: true
default: '0x'
governorVaults:
description: 'Governor vaults as comma separated'
required: false
default: ''

jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: sepolia
url: https://term-finance.github.io/yearn-v3-term-vault/
steps:
- uses: actions/checkout@master
with:
fetch-depth: 0
submodules: recursive
- uses: foundry-rs/foundry-toolchain@v1
- run: forge install
- run: forge build
- run: forge tree
- run: forge script script/DeployGovernance.s.sol:DeployGovernance --rpc-url $RPC_URL --broadcast --gas-price 500000000000 --verify --verbosity 4
env:
RPC_URL: ${{ secrets.RPC_URL }}
PRIVATE_KEY: ${{ secrets.GOVERNANCE_DEPLOYER_KEY }}
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
PROPOSER: ${{ github.event.inputs.proposer }}
STRATEGY: ${{ github.event.inputs.strategy }}
GOVERNOR: ${{ github.event.inputs.governorRoleAddress }}
VAULT_GOVERNORS: ${{ github.event.inputs.governorVaults }}
GOVERNANCE_FACTORY: ${{ vars.GOVERNANCE_FACTORY }}




24 changes: 18 additions & 6 deletions .github/workflows/deploy-sepolia-strategy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ on:
description: 'Yearn strategy name'
required: true
default: '0x'
governorRoleAddress:
description: 'Governor role address'
required: true
default: '0x'
strategyManagementAddress:
description: 'Strategy management address'
required: false
required: true
default: '0x'
discountRateMarkup:
description: 'Discount rate markup'
Expand All @@ -34,6 +30,18 @@ on:
description: 'Required reserve ratio'
required: false
default: '0.01'
profitMaxUnlock:
description: 'Profit max unlock time'
required: false
default: '0'
collateralTokens:
description: 'Collateral tokens comma separated'
required: false
default: '0x'
minCollateralRatios:
description: 'Minimum collateral ratio comma separated'
required: false
default: '0.01'

jobs:
deploy:
Expand All @@ -54,6 +62,7 @@ jobs:
env:
RPC_URL: ${{ secrets.RPC_URL }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
GOVERNOR_DEPLOYER_KEY: ${{ secrets.GOVERNANCE_DEPLOYER_KEY }}
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
ASSET_ADDRESS: ${{ github.event.inputs.asset }}
YEARN_VAULT_ADDRESS: ${{ vars.YEARN_VAULT_ADDRESS }}
Expand All @@ -66,7 +75,10 @@ jobs:
REPOTOKEN_CONCENTRATION_LIMIT: ${{ github.event.inputs.repoTokenConcentrationLimit }}
ADMIN_ADDRESS: ${{ vars.ADMIN_ADDRESS }}
DEVOPS_ADDRESS: ${{ vars.DEVOPS_ADDRESS }}
GOVERNOR_ROLE_ADDRESS: ${{ github.event.inputs.governorRoleAddress }}
GOVERNOR_ROLE_ADDRESS: ${{ vars.GOVERNANCE_FACTORY }}
STRATEGY_MANAGEMENT_ADDRESS: ${{ github.event.inputs.strategyManagementAddress }}
NEW_REQUIRED_RESERVE_RATIO: ${{ github.event.inputs.requiredReserveRatio }}
COLLATERAL_TOKEN_ADDRESSES: ${{ github.event.inputs.collateralTokens }}
MIN_COLLATERAL_RATIOS: ${{ github.event.inputs.minCollateralRatios }}
PROFIT_MAX_UNLOCK_TIME: ${{ github.event.inputs.profitMaxUnlock }}

67 changes: 67 additions & 0 deletions .github/workflows/stylebot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: stylebot
on:
push:
branches:
- master
concurrency:
group: "stylebot"
cancel-in-progress: true
permissions:
id-token: write
contents: write
packages: write
pull-requests: write
jobs:
fix:
runs-on: ubuntu-latest

steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.STYLEBOT_GITHUB_APP_ID }}
private-key: ${{ secrets.STYLEBOT_GITHUB_APP_KEY }}
- uses: actions/checkout@master
- id: nodeversion
run: echo "version=$(grep nodejs .tool-versions | sed -e 's/[^[:space:]]*[[:space:]]*//')" >> $GITHUB_OUTPUT
- uses: actions/setup-node@v4
with:
node-version: ${{ steps.nodeversion.outputs.version }}
cache: yarn
- run: yarn install --immutable
# Run fixes, save stdout.
- run: |
echo 'ESLINT_RESULTS<<EOF' >> ${GITHUB_ENV}
yarn fix:eslint >> ${GITHUB_ENV} || true
echo 'EOF' >> ${GITHUB_ENV}
- run: |
echo 'PRETTIER_RESULTS<<EOF' >> ${GITHUB_ENV}
yarn fix:prettier >> ${GITHUB_ENV}
echo 'EOF' >> ${GITHUB_ENV}
- run: git restore .yarn .yarnrc.yml
# Make PR from local changes.
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
token: ${{ steps.app-token.outputs.token }}
commit-message: "[stylebot] Fixes for code style"
branch: stylebot/patch
title: "[stylebot] Fixes for code style"
body: |
Stylebot detected automatically fix-able code style issues.
<details><summary>`yarn fix:eslint`</summary>
```
${{ env.ESLINT_RESULTS }}
```
</details>
<details><summary>`yarn fix:prettier`</summary>
```
${{ env.PRETTIER_RESULTS }}
```
</details>
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[profile.default]
evm_version = 'shanghai'
src = 'src'
out = 'out'
libs = ['lib']
Expand Down
123 changes: 123 additions & 0 deletions script/DeployGovernance.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import "forge-std/Script.sol";
import "../src/Strategy.sol";

interface TermVaultGovernanceFactory {
function deploySafe(
address proposer,
address strategy,
address governor,
address[] calldata vaultGovernors
) external;
}

contract DeployGovernance is Script {
/**
* @dev Converts a comma-separated string of addresses to an array of addresses.
* @param _input A string containing comma-separated addresses.
* @return addressArray An array of addresses parsed from the input string.
*/
function stringToAddressArray(string memory _input) public pure returns (address[] memory) {
// Check if the input string is empty
if (bytes(_input).length == 0) {
return new address[](0);
}
// Step 1: Split the input string by commas
string[] memory parts = splitString(_input, ",");

// Step 2: Convert each part to an address
address[] memory addressArray = new address[](parts.length);
for (uint256 i = 0; i < parts.length; i++) {
addressArray[i] = parseAddress(parts[i]);
}

return addressArray;
}


/**
* @dev Helper function to split a string by a delimiter
* @param _str The input string
* @param _delimiter The delimiter to split by
* @return An array of substrings
*/
function splitString(string memory _str, string memory _delimiter) internal pure returns (string[] memory) {
bytes memory strBytes = bytes(_str);
bytes memory delimiterBytes = bytes(_delimiter);
uint256 partsCount = 1;

// Count the parts to split the string
for (uint256 i = 0; i < strBytes.length - 1; i++) {
if (strBytes[i] == delimiterBytes[0]) {
partsCount++;
}
}

string[] memory parts = new string[](partsCount);
uint256 partIndex = 0;
bytes memory part;

for (uint256 i = 0; i < strBytes.length; i++) {
if (strBytes[i] == delimiterBytes[0]) {
parts[partIndex] = string(part);
part = "";
partIndex++;
} else {
part = abi.encodePacked(part, strBytes[i]);
}
}

// Add the last part
parts[partIndex] = string(part);

return parts;
}

/**
* @dev Helper function to parse a string and convert it to an address
* @param _str The string representation of an address
* @return The address parsed from the input string
*/
function parseAddress(string memory _str) internal pure returns (address) {
bytes memory tmp = bytes(_str);
require(tmp.length == 42, "Invalid address length"); // Must be 42 characters long (0x + 40 hex chars)

uint160 addr = 0;
for (uint256 i = 2; i < 42; i++) {
uint160 b = uint160(uint8(tmp[i]));

if (b >= 48 && b <= 57) { // 0-9
addr = addr * 16 + (b - 48);
} else if (b >= 65 && b <= 70) { // A-F
addr = addr * 16 + (b - 55);
} else if (b >= 97 && b <= 102) { // a-f
addr = addr * 16 + (b - 87);
} else {
revert("Invalid address character");
}
}

return address(addr);
}

function run() external {
uint256 deployerPK = vm.envUint("PRIVATE_KEY");

// Set up the RPC URL (optional if you're using the default foundry config)
string memory rpcUrl = vm.envString("RPC_URL");

vm.startBroadcast(deployerPK);

TermVaultGovernanceFactory factory = TermVaultGovernanceFactory(vm.envAddress("GOVERNANCE_FACTORY"));
address proposer = vm.envAddress("PROPOSER");
address strategy = vm.envAddress("STRATEGY");
address governor = vm.envAddress("GOVERNOR");
address[] memory vaultGovernors = stringToAddressArray(vm.envString("VAULT_GOVERNORS"));

factory.deploySafe(proposer, strategy, governor, vaultGovernors);

vm.stopBroadcast();
}

}
Loading

0 comments on commit 7b62ea2

Please sign in to comment.