From 206aa0684af6ca33be94964f3066eb703537419d Mon Sep 17 00:00:00 2001 From: cavalier-eth <91091124+cavalier-eth@users.noreply.github.com> Date: Sun, 3 Aug 2025 15:39:51 +1000 Subject: [PATCH] simplest rebalance --- script/README.md | 18 ++++++++++++++++++ script/rebalance-simple.js | 27 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 script/README.md create mode 100644 script/rebalance-simple.js diff --git a/script/README.md b/script/README.md new file mode 100644 index 0000000..110a573 --- /dev/null +++ b/script/README.md @@ -0,0 +1,18 @@ +# Simple Rebalance Script + +Rebalances all leverage tokens that need it. + +## Usage + +```bash +export PRIVATE_KEY="your_private_key" +export RPC_URL="your_rpc_url" +node script/rebalance-simple.js +``` + +## Requirements + +- Your address must be authorized as a rebalancer +- Node.js with ethers.js installed + +That's it! \ No newline at end of file diff --git a/script/rebalance-simple.js b/script/rebalance-simple.js new file mode 100644 index 0000000..a884d7a --- /dev/null +++ b/script/rebalance-simple.js @@ -0,0 +1,27 @@ +const { ethers } = require('ethers'); + +// Setup +const provider = new ethers.JsonRpcProvider(process.env.RPC_URL); +const signer = new ethers.Wallet(process.env.PRIVATE_KEY, provider); + +// Contract addresses +const FACTORY = "0x5Dd85f51e9fD6aDE8ecc216C07919ecD443eB14d"; + +// ABIs +const factoryAbi = ["function allTokens() external view returns (address[] memory)"]; +const tokenAbi = ["function canRebalance() external view returns (bool)", "function rebalance() external"]; + +async function rebalance() { + const factory = new ethers.Contract(FACTORY, factoryAbi, signer); + const tokens = await factory.allTokens(); + + for (const tokenAddr of tokens) { + const token = new ethers.Contract(tokenAddr, tokenAbi, signer); + if (await token.canRebalance()) { + await token.rebalance(); + console.log(`Rebalanced ${tokenAddr}`); + } + } +} + +rebalance().catch(console.error); \ No newline at end of file