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

ci: update set allocation #251

Merged
merged 4 commits into from
Nov 26, 2024
Merged
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
18 changes: 7 additions & 11 deletions .github/workflows/set-allocation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,21 @@ jobs:
setAllocation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- uses: actions/setup-node@v4
with:
node-version: 16
- run: |
echo MNEMONIC="test test test test test test test test test test test junk" > .env
echo INFURA_API_KEY="test" >> .env
echo ETHERSCAN_API_KEY="test" >> .env
echo AURORA_API_KEY="test" >> .env
node-version: 18
cache: yarn
- run: cp .env.example .env
- run: yarn
- name: Propose pool allocation
env:
SAFE_SIGNER_MNEMONIC: ${{ secrets.SAFE_SIGNER_MNEMONIC }}
SAFE_PROPOSER_PRIVATE_KEY: ${{ secrets.SAFE_OPS_PROPOSER }}
AURORA_API_KEY: ${{ secrets.AURORA_API_KEY }}
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
run: |
yarn
yarn hardhat run scripts/ops/safeAllocation.ts --network aurora
run: yarn hardhat run scripts/ops/proposerSetAllocation.ts --network aurora
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Removed allocationConfig.json due to transaction proposed on gnosis safe
89 changes: 89 additions & 0 deletions scripts/ops/proposerSetAllocation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import fs from "fs-extra";
import { ethers } from "hardhat";
import Safe from "@gnosis.pm/safe-core-sdk";
import EthersAdapter from "@gnosis.pm/safe-ethers-lib";
import { SafeEthersSigner, SafeService } from "@gnosis.pm/safe-ethers-adapters";
import { Wallet } from "ethers";
import { JsonRpcProvider } from "@ethersproject/providers";
import { chefV2Address, ops, SAFE_SERVICE_URL } from "../constants";

type AllocationConfig = {
PoolId: number;
Allocation: number;
Rewarder: string;
LpToken: string;
};

const { AURORA_API_KEY, SAFE_PROPOSER_PRIVATE_KEY } = process.env;
if (!AURORA_API_KEY) {
throw new Error("*** AURORA_API_KEY NOT FOUND IN ENV");
}
if (!SAFE_PROPOSER_PRIVATE_KEY) {
throw new Error("*** SAFE_PROPOSER_PRIVATE_KEY NOT FOUND IN ENV");
}

const AURORA_URL = "https://mainnet.aurora.dev/" + AURORA_API_KEY;
const provider = new JsonRpcProvider(AURORA_URL);

const signer = new Wallet(SAFE_PROPOSER_PRIVATE_KEY, provider);
const service = new SafeService(SAFE_SERVICE_URL);
console.info("Setup SafeEthersSigner");
const ethAdapter = new EthersAdapter({ ethers, signer });

console.info("*** Using signer address: ", signer.address);
console.info("*** Using SAFE_SERVICE_URL: ", SAFE_SERVICE_URL);

async function main() {
const safe = await Safe.create({ ethAdapter, safeAddress: ops });
const safeSigner = new SafeEthersSigner(safe, service, provider);

console.info("*** Proposing updating pool allocation ***");

let allocationConfig: AllocationConfig | undefined;
try {
allocationConfig = await fs.readJSON("./allocationConfig.json");
console.info("*** allocationConfig.json found ***");
console.info(JSON.stringify(allocationConfig));
} catch (err) {
console.info("*** No allocationConfig.json found");
}

if (allocationConfig && typeof allocationConfig?.Rewarder === "string") {
const masterChefV2 = await ethers.getContractFactory("MasterChefV2");

const chefv2 = masterChefV2.attach(chefV2Address);

const { LpToken: lpTokenAddress, PoolId: poolId, Rewarder: rewarder, Allocation: allocPoint } = allocationConfig;

const [poolInfo, poolLpToken] = await Promise.all([chefv2.poolInfo(poolId), chefv2.lpToken(poolId)]);

console.info(`Chef v2 address: ${chefv2.address}`);
console.info("poolId: " + poolId);
console.info("lpTokenAddress: " + lpTokenAddress);
console.info("rewarder: " + rewarder);
console.info("poolInfo: " + poolInfo);
console.info("poolLpToken: " + poolLpToken);

if (poolLpToken === lpTokenAddress) {
await chefv2.connect(safeSigner).set(poolId, allocPoint, rewarder, false);

console.info("*** USER ACTION REQUIRED ***");
console.info("Go to the Gnosis Safe Web App to confirm the transaction");
console.info(`https://gnosis-safe.io/app/aurora:${ops}/transactions/queue`);
console.info(`*** Please verify the proposed adding pool to MCV2`);

// NOTE - Used because fs.promises.rm is not a function error on github actions, weird
await fs.remove("./allocationConfig.json");
console.info("*** Removed allocationConfig.json file, no longer needed");
}
}
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error: Error) => {
console.error(error);
process.exit(1);
});
Loading