Skip to content
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: 18 additions & 0 deletions script/README.md
Original file line number Diff line number Diff line change
@@ -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!
27 changes: 27 additions & 0 deletions script/rebalance-simple.js
Original file line number Diff line number Diff line change
@@ -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);
Loading