Skip to content

Commit

Permalink
Added a pause script to test-utils (#644)
Browse files Browse the repository at this point in the history
* Added a pause script to `test-utils`

* Improved the output

* Added some documentation about running the scripts
  • Loading branch information
jalextowle authored Nov 1, 2023
1 parent 1148b95 commit 3c9bcea
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 14 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/hyperdrive-math/src/long.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,8 @@ mod tests {
// considering fees.
// 2. The pool's solvency is close to zero.
// 3. Bob's budget is consumed.
let is_max_price = max_spot_price - spot_price_after_long < fixed!(1e15);
let is_max_price =
max_spot_price - spot_price_after_long.min(max_spot_price) < fixed!(1e15);
let is_solvency_consumed = {
let state = bob.get_state().await?;
let error_tolerance = fixed!(1_000e18).mul_div_down(fixed_rate, fixed!(0.1e18));
Expand Down
29 changes: 17 additions & 12 deletions crates/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@ name = "test-utils"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "pause"
path = "src/bin/pause.rs"

[[example]]
name = "dev_chain"

[[example]]
name = "max_short"

[[example]]
name = "test_chain_new"

[[example]]
name = "test_chain_load_crash"

[dependencies]

# External dependencies.
async-trait = "0.1.73"
dotenvy = "0.15"
ethers = "2.0.8"
eyre = "0.6.8"
lazy_static = "1.4.0"
Expand All @@ -24,15 +41,3 @@ fixed-point-macros = { path = "../fixed-point-macros" }
hyperdrive-addresses = { path = "../hyperdrive-addresses" }
hyperdrive-math = { path = "../hyperdrive-math" }
hyperdrive-wrappers = { path = "../hyperdrive-wrappers" }

[[example]]
name = "dev_chain"

[[example]]
name = "max_short"

[[example]]
name = "test_chain_new"

[[example]]
name = "test_chain_load_crash"
31 changes: 31 additions & 0 deletions crates/test-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,34 @@ example with the command:
```bash
cargo run --example max_short
```

# Scripts

Along with the test utilities, this crate also contains scripts for interacting
with live versions of the protocol. In order to make use of these scripts, add
the following fields to your root level `.env` file:

```bash
HYPERDRIVE_ETHEREUM_URL=
HYPERDRIVE_ARTIFACTS_URL=
HYPERDRIVE_PRIVATE_KEY=
```

These variables will be overwritten by variables already present in the
environment which makes it easy to use alternate variables as follows:

```bash
ENVVAR=ENVVAR_VALUE cargo run --bin SCRIPT
```

## Pause

The `pause` script pauses the Hyperdrive pool, which puts the pool into a state
where `openLong`, `openShort`, and `addLiquidity` are disabled. For competition
pools, only the admin can call `pause`, so make sure that you are using the
correct private key in your environment. You can run the `pause` script with the
command:

```bash
cargo run --bin pause
```
2 changes: 1 addition & 1 deletion crates/test-utils/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ impl Agent<ChainClient, ChaCha8Rng> {
) -> Result<()> {
let tx = ContractCall_(self.hyperdrive.checkpoint(checkpoint))
.apply(self.pre_process_options(maybe_tx_options));
tx.0.send().await?;
tx.0.send().await?.await?;
Ok(())
}

Expand Down
38 changes: 38 additions & 0 deletions crates/test-utils/src/bin/pause.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use std::env;

use dotenvy::dotenv;
use ethers::signers::LocalWallet;
use eyre::Result;
use hyperdrive_wrappers::wrappers::ierc4626_hyperdrive::IERC4626Hyperdrive;
use test_utils::chain::{Chain, DevChain, MNEMONIC};

#[tokio::main]
async fn main() -> Result<()> {
// Connect to the chain and set up an agent with the provided envvars.
dotenv().expect("Failed to load .env file");
let chain = DevChain::new(
&env::var("HYPERDRIVE_ETHEREUM_URL")?,
&env::var("HYPERDRIVE_ARTIFACTS_URL")?,
MNEMONIC,
0,
)
.await?;
let client = chain
.client(env::var("HYPERDRIVE_PRIVATE_KEY")?.parse::<LocalWallet>()?)
.await?;

// Pause the pool.
println!("Pausing the pool...");
let hyperdrive = IERC4626Hyperdrive::new(chain.addresses().hyperdrive, client);
hyperdrive.pause(true).send().await?.await?;

// Check that the pool is paused.
let market_state = hyperdrive.get_market_state().call().await?;
if market_state.is_paused {
println!("The pool was successfully paused!");
} else {
panic!("The pool was not paused!");
}

Ok(())
}

0 comments on commit 3c9bcea

Please sign in to comment.