Skip to content

Commit

Permalink
Redeem withdrawal shares not subject to min tx amount (#1546)
Browse files Browse the repository at this point in the history
This fixes a bug with random bots trying to withdraw the minimum
transaction amount when this amount > withdrawal shares in wallet.

Hyperdrive does not restrict redeeming withdrawal shares to the minimum
transaction amount
  • Loading branch information
Sheng Lundquist authored Jun 20, 2024
1 parent ed9fe41 commit f1c75f7
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/agent0/core/base/config/budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np
from fixedpointmath import FixedPoint, clip
from numpy.random._generator import Generator
from numpy.random import Generator


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion src/agent0/core/base/policies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from agent0.core.base.types import Freezable

if TYPE_CHECKING:
from numpy.random._generator import Generator
from numpy.random import Generator

from agent0.core.base.agent import EthWallet
from agent0.core.base.types import Trade
Expand Down
2 changes: 0 additions & 2 deletions src/agent0/core/base/policies/no_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from .base import BasePolicy, MarketInterface, Wallet

if TYPE_CHECKING:
from numpy.random._generator import Generator

from agent0.core.base.types import Trade


Expand Down
2 changes: 1 addition & 1 deletion src/agent0/core/hyperdrive/interactive/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from docker import DockerClient
from docker.errors import NotFound
from docker.models.containers import Container
from numpy.random._generator import Generator
from numpy.random import Generator
from web3.types import BlockData, Timestamp

from agent0.chainsync import PostgresConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from copy import deepcopy

from eth_account.signers.local import LocalAccount
from numpy.random._generator import Generator
from numpy.random import Generator
from web3.types import Nonce

from agent0.core.base import MarketType, Trade
Expand Down
10 changes: 6 additions & 4 deletions src/agent0/core/hyperdrive/policies/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,17 +433,19 @@ def redeem_withdraw_shares_with_random_amount(
A list with a single Trade element for redeeming the LP withdraw shares.
"""
# take a guess at the trade amount, which should be about 10% of the agent’s budget
# TODO we may want to use a different mean/std here, as this is based on the agent's base balance
# but we're trying to redeem withdraw shares here.
initial_trade_amount = FixedPoint(
self.rng.normal(loc=float(wallet.balance.amount) * 0.1, scale=float(wallet.balance.amount) * 0.01)
)
shares_available_to_withdraw = min(
wallet.withdraw_shares,
interface.current_pool_state.pool_info.withdrawal_shares_ready_to_withdraw,
)
# minimum_transaction_amount <= trade_amount <= withdraw_shares
trade_amount = max(
interface.pool_config.minimum_transaction_amount, min(shares_available_to_withdraw, initial_trade_amount)
)

# trade_amount <= withdraw_shares
trade_amount = min(shares_available_to_withdraw, initial_trade_amount)

# return a trade using a specification that is parsable by the rest of the sim framework
return [
redeem_withdraw_shares_trade(
Expand Down
2 changes: 1 addition & 1 deletion src/agent0/hyperfuzz/system_fuzz/run_fuzz_bots.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Callable

from fixedpointmath import FixedPoint
from numpy.random._generator import Generator
from numpy.random import Generator

from agent0 import Chain, Hyperdrive, LocalChain, LocalHyperdrive, PolicyZoo
from agent0.core.base.make_key import make_private_key
Expand Down
2 changes: 1 addition & 1 deletion src/agent0/hyperfuzz/unit_fuzz/helpers/advance_time.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Helpers for advancing time wrt checkpoint boundaries"""

from numpy.random._generator import Generator
from numpy.random import Generator

from agent0.core.hyperdrive.interactive import LocalChain, LocalHyperdrive

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from numpy.random._generator import Generator
from numpy.random import Generator

from agent0.core.hyperdrive.interactive.event_types import OpenLong, OpenShort
from agent0.core.hyperdrive.interactive.local_hyperdrive_agent import LocalHyperdriveAgent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np
from fixedpointmath import FixedPoint
from numpy.random._generator import Generator
from numpy.random import Generator

from agent0.core.hyperdrive import HyperdriveActionType
from agent0.core.hyperdrive.interactive import LocalChain, LocalHyperdrive
Expand Down
2 changes: 1 addition & 1 deletion src/agent0/hyperfuzz/unit_fuzz/helpers/setup_fuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np
from fixedpointmath import FixedPoint
from numpy.random._generator import Generator
from numpy.random import Generator

from agent0.core.hyperdrive.interactive import LocalChain, LocalHyperdrive

Expand Down
2 changes: 1 addition & 1 deletion src/agent0/hyperlogs/json_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import pandas as pd
from fixedpointmath import FixedPoint
from hexbytes import HexBytes
from numpy.random._generator import Generator
from numpy.random import Generator
from web3.datastructures import AttributeDict, MutableAttributeDict


Expand Down

0 comments on commit f1c75f7

Please sign in to comment.