From 3667e79fc0ab4091c8bae39a86a03d9a8c2fa902 Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Tue, 7 Nov 2023 11:45:21 -0800 Subject: [PATCH 01/15] Fixing hyperdrive state methods to match update 0.1.0 --- .../src/hyperdrive_state_methods.rs | 110 +++++++++++------- 1 file changed, 68 insertions(+), 42 deletions(-) diff --git a/crates/pyperdrive/src/hyperdrive_state_methods.rs b/crates/pyperdrive/src/hyperdrive_state_methods.rs index bb8a3eb..85ef378 100644 --- a/crates/pyperdrive/src/hyperdrive_state_methods.rs +++ b/crates/pyperdrive/src/hyperdrive_state_methods.rs @@ -1,6 +1,5 @@ use ethers::core::types::{I256, U256}; use fixed_point::FixedPoint; -use hyperdrive_math::Asset; use pyo3::exceptions::PyValueError; use pyo3::prelude::*; @@ -23,20 +22,23 @@ impl HyperdriveState { Ok(HyperdriveState::new(state)) } - pub fn get_solvency(&self) -> PyResult { - let result_fp = self.state.get_solvency(); + pub fn get_max_spot_price(&self) -> PyResult { + let result_fp = self.state.get_max_spot_price(); let result = U256::from(result_fp).to_string(); return Ok(result); } - pub fn get_spot_price(&self) -> PyResult { - let result_fp = self.state.get_spot_price(); + pub fn get_spot_price_after_long(&self, long_amount: &str) -> PyResult { + let long_amount_fp = FixedPoint::from(U256::from_dec_str(long_amount).map_err(|_| { + PyErr::new::("Failed to convert long_amount string to U256") + })?); + let result_fp = self.state.get_spot_price_after_long(long_amount_fp); let result = U256::from(result_fp).to_string(); return Ok(result); } - pub fn get_spot_rate(&self) -> PyResult { - let result_fp = self.state.get_spot_rate(); + pub fn get_solvency(&self) -> PyResult { + let result_fp = self.state.get_solvency(); let result = U256::from(result_fp).to_string(); return Ok(result); } @@ -50,6 +52,18 @@ impl HyperdriveState { return Ok(result); } + pub fn get_spot_price(&self) -> PyResult { + let result_fp = self.state.get_spot_price(); + let result = U256::from(result_fp).to_string(); + return Ok(result); + } + + pub fn get_spot_rate(&self) -> PyResult { + let result_fp = self.state.get_spot_rate(); + let result = U256::from(result_fp).to_string(); + return Ok(result); + } + pub fn get_short_deposit( &self, short_amount: &str, @@ -66,58 +80,70 @@ impl HyperdriveState { FixedPoint::from(U256::from_dec_str(open_share_price).map_err(|_| { PyErr::new::("Failed to convert open_share_price string to U256") })?); - let result_fp = - self.state - .get_short_deposit(short_amount_fp, spot_price_fp, open_share_price_fp); - let result = match result_fp { - Some(result) => U256::from(result).to_string(), - None => { - return Err(PyErr::new::( - "Failed to estimate the short deposit; short_principal is None ", - )); - } - }; + let result_fp = + self.state.get_short_deposit(short_amount_fp, spot_price_fp, open_share_price_fp).unwrap(); + let result = U256::from(result_fp).to_string(); return Ok(result); } - pub fn get_out_for_in(&self, amount_in: &str, shares_in: bool) -> PyResult { + pub fn calculate_bonds_out_given_shares_in_down(&self, amount_in: &str) -> PyResult { let amount_in_fp = FixedPoint::from(U256::from_dec_str(amount_in).map_err(|_| { PyErr::new::("Failed to convert budget string to U256") })?); - let asset = match shares_in { - true => Asset::Shares(amount_in_fp), - false => Asset::Bonds(amount_in_fp), - }; - let result_fp = self.state.get_out_for_in(asset); + let result_fp = self.state.calculate_bonds_out_given_shares_in_down(amount_in_fp); let result = U256::from(result_fp).to_string(); return Ok(result); } - pub fn get_out_for_in_safe(&self, amount_in: &str, shares_in: bool) -> PyResult { + pub fn calculate_shares_in_given_bonds_out_up(&self, amount_in: &str) -> PyResult { let amount_in_fp = FixedPoint::from(U256::from_dec_str(amount_in).map_err(|_| { PyErr::new::("Failed to convert budget string to U256") })?); - let asset = match shares_in { - true => Asset::Shares(amount_in_fp), - false => Asset::Bonds(amount_in_fp), - }; - match self.state.get_out_for_in_safe(asset) { - Some(result_fp) => Ok(U256::from(result_fp).to_string()), - None => Err(PyErr::new::( - "get_out_for_in_safe returned None", - )), - } + let result_fp = self.state.calculate_shares_in_given_bonds_out_up(amount_in_fp); + let result = U256::from(result_fp).to_string(); + return Ok(result); } - pub fn get_in_for_out(&self, amount_out: &str, shares_out: bool) -> PyResult { - let amount_out_fp = FixedPoint::from(U256::from_dec_str(amount_out).map_err(|_| { + pub fn calculate_shares_in_given_bonds_out_down(&self, amount_in: &str) -> PyResult { + let amount_in_fp = FixedPoint::from(U256::from_dec_str(amount_in).map_err(|_| { PyErr::new::("Failed to convert budget string to U256") })?); - let asset = match shares_out { - true => Asset::Shares(amount_out_fp), - false => Asset::Bonds(amount_out_fp), - }; - let result_fp = self.state.get_out_for_in(asset); + let result_fp = self.state.calculate_shares_in_given_bonds_out_down(amount_in_fp); + let result = U256::from(result_fp).to_string(); + return Ok(result); + } + + pub fn calculate_shares_out_given_bonds_in_down(&self, amount_in: &str) -> PyResult { + let amount_in_fp = FixedPoint::from(U256::from_dec_str(amount_in).map_err(|_| { + PyErr::new::("Failed to convert budget string to U256") + })?); + let result_fp = self.state.calculate_shares_out_given_bonds_in_down(amount_in_fp); + let result = U256::from(result_fp).to_string(); + return Ok(result); + } + + pub fn calculate_shares_out_given_bonds_in_down_safe(&self, amount_in: &str) -> PyResult { + let amount_in_fp = FixedPoint::from(U256::from_dec_str(amount_in).map_err(|_| { + PyErr::new::("Failed to convert budget string to U256") + })?); + let result_fp = + self.state.calculate_shares_out_given_bonds_in_down_safe(amount_in_fp).unwrap(); + let result = U256::from(result_fp).to_string(); + return Ok(result); + } + + pub fn calculate_max_buy(&self) -> PyResult { + let result_fp = self.state.calculate_max_buy(); + let result = U256::from(result_fp).to_string(); + return Ok(result); + } + + pub fn calculate_max_sell(&self, minimum_share_reserves: &str) -> PyResult { + let minimum_share_reserves_fp = + FixedPoint::from(U256::from_dec_str(minimum_share_reserves).map_err(|_| { + PyErr::new::("Failed to convert budget string to U256") + })?); + let result_fp = self.state.calculate_max_sell(minimum_share_reserves_fp); let result = U256::from(result_fp).to_string(); return Ok(result); } From e659a310dadea690a018f5cd5f5dc24fc4265272 Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Tue, 7 Nov 2023 11:45:30 -0800 Subject: [PATCH 02/15] Fixing readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 897198a..d08c245 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ pypechain. From the pyperdrive project root, run: ```shell pip install --upgrade -r requirements-dev.txt -pypechain hyperdrive/out/IHyperdrive.sol/IHyperdrive.json --output_dir crates/pyperdrive/python/pypechain_types +pypechain hyperdrive/out/IHyperdrive.sol/IHyperdrive.json --output_dir crates/pyperdrive/python/pypechain/pypechain_types ``` ## Disclaimer From e4dba4214bbd84fc74ca6573b2231cb5a37ffe34 Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Tue, 7 Nov 2023 11:49:52 -0800 Subject: [PATCH 03/15] Updating pypechain types --- .../pypechain_types/IHyperdriveContract.py | 140 ++++++++++-------- .../pypechain_types/IHyperdriveTypes.py | 51 ++++++- 2 files changed, 126 insertions(+), 65 deletions(-) diff --git a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py index 0180532..13c95af 100644 --- a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py +++ b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py @@ -9,12 +9,11 @@ # pylint: disable=no-else-return from __future__ import annotations -from typing import cast +from typing import Any, cast from eth_typing import ChecksumAddress from web3.contract.contract import Contract, ContractFunction, ContractFunctions from web3.exceptions import FallbackNotFound -from web3.types import ABI class IHyperdriveDOMAIN_SEPARATORContractFunction(ContractFunction): @@ -38,14 +37,9 @@ class IHyperdriveAddLiquidityContractFunction(ContractFunction): # pylint: disable=arguments-differ def __call__( - self, - _contribution: int, - _minApr: int, - _maxApr: int, - _destination: str, - _asUnderlying: bool, + self, _contribution: int, _minApr: int, _maxApr: int, _options: tuple ) -> "IHyperdriveAddLiquidityContractFunction": - super().__call__(_contribution, _minApr, _maxApr, _destination, _asUnderlying) + super().__call__(_contribution, _minApr, _maxApr, _options) return self # TODO: add call def so we can get return types for the calls @@ -58,7 +52,9 @@ class IHyperdriveBalanceOfContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, tokenId: int, owner: str) -> "IHyperdriveBalanceOfContractFunction": + def __call__( + self, tokenId: int, owner: str + ) -> "IHyperdriveBalanceOfContractFunction": super().__call__(tokenId, owner) return self @@ -102,7 +98,9 @@ class IHyperdriveCheckpointContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, _checkpointTime: int) -> "IHyperdriveCheckpointContractFunction": + def __call__( + self, _checkpointTime: int + ) -> "IHyperdriveCheckpointContractFunction": super().__call__(_checkpointTime) return self @@ -121,10 +119,9 @@ def __call__( _maturityTime: int, _bondAmount: int, _minOutput: int, - _destination: str, - _asUnderlying: bool, + _options: tuple, ) -> "IHyperdriveCloseLongContractFunction": - super().__call__(_maturityTime, _bondAmount, _minOutput, _destination, _asUnderlying) + super().__call__(_maturityTime, _bondAmount, _minOutput, _options) return self # TODO: add call def so we can get return types for the calls @@ -142,10 +139,9 @@ def __call__( _maturityTime: int, _bondAmount: int, _minOutput: int, - _destination: str, - _asUnderlying: bool, + _options: tuple, ) -> "IHyperdriveCloseShortContractFunction": - super().__call__(_maturityTime, _bondAmount, _minOutput, _destination, _asUnderlying) + super().__call__(_maturityTime, _bondAmount, _minOutput, _options) return self # TODO: add call def so we can get return types for the calls @@ -158,8 +154,24 @@ class IHyperdriveCollectGovernanceFeeContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, asUnderlying: bool) -> "IHyperdriveCollectGovernanceFeeContractFunction": - super().__call__(asUnderlying) + def __call__( + self, _options: tuple + ) -> "IHyperdriveCollectGovernanceFeeContractFunction": + super().__call__(_options) + return self + + # TODO: add call def so we can get return types for the calls + # def call() + + +class IHyperdriveDataProviderContractFunction(ContractFunction): + """ContractFunction for the dataProvider method.""" + + # super() call methods are generic, while our version adds values & types + # pylint: disable=arguments-differ + + def __call__(self) -> "IHyperdriveDataProviderContractFunction": + super().__call__() return self # TODO: add call def so we can get return types for the calls @@ -186,7 +198,9 @@ class IHyperdriveGetCheckpointContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, _checkpointId: int) -> "IHyperdriveGetCheckpointContractFunction": + def __call__( + self, _checkpointId: int + ) -> "IHyperdriveGetCheckpointContractFunction": super().__call__(_checkpointId) return self @@ -273,13 +287,9 @@ class IHyperdriveInitializeContractFunction(ContractFunction): # pylint: disable=arguments-differ def __call__( - self, - _contribution: int, - _apr: int, - _destination: str, - _asUnderlying: bool, + self, _contribution: int, _apr: int, _options: tuple ) -> "IHyperdriveInitializeContractFunction": - super().__call__(_contribution, _apr, _destination, _asUnderlying) + super().__call__(_contribution, _apr, _options) return self # TODO: add call def so we can get return types for the calls @@ -292,7 +302,9 @@ class IHyperdriveIsApprovedForAllContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, owner: str, spender: str) -> "IHyperdriveIsApprovedForAllContractFunction": + def __call__( + self, owner: str, spender: str + ) -> "IHyperdriveIsApprovedForAllContractFunction": super().__call__(owner, spender) return self @@ -367,10 +379,9 @@ def __call__( _baseAmount: int, _minOutput: int, _minSharePrice: int, - _destination: str, - _asUnderlying: bool, + _options: tuple, ) -> "IHyperdriveOpenLongContractFunction": - super().__call__(_baseAmount, _minOutput, _minSharePrice, _destination, _asUnderlying) + super().__call__(_baseAmount, _minOutput, _minSharePrice, _options) return self # TODO: add call def so we can get return types for the calls @@ -388,16 +399,9 @@ def __call__( _bondAmount: int, _maxDeposit: int, _minSharePrice: int, - _destination: str, - _asUnderlying: bool, + _options: tuple, ) -> "IHyperdriveOpenShortContractFunction": - super().__call__( - _bondAmount, - _maxDeposit, - _minSharePrice, - _destination, - _asUnderlying, - ) + super().__call__(_bondAmount, _maxDeposit, _minSharePrice, _options) return self # TODO: add call def so we can get return types for the calls @@ -410,8 +414,8 @@ class IHyperdrivePauseContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, status: bool) -> "IHyperdrivePauseContractFunction": - super().__call__(status) + def __call__(self, _status: bool) -> "IHyperdrivePauseContractFunction": + super().__call__(_status) return self # TODO: add call def so we can get return types for the calls @@ -424,7 +428,9 @@ class IHyperdrivePerTokenApprovalsContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, tokenId: int, owner: str, spender: str) -> "IHyperdrivePerTokenApprovalsContractFunction": + def __call__( + self, tokenId: int, owner: str, spender: str + ) -> "IHyperdrivePerTokenApprovalsContractFunction": super().__call__(tokenId, owner, spender) return self @@ -462,13 +468,9 @@ class IHyperdriveRedeemWithdrawalSharesContractFunction(ContractFunction): # pylint: disable=arguments-differ def __call__( - self, - _shares: int, - _minOutput: int, - _destination: str, - _asUnderlying: bool, + self, _shares: int, _minOutput: int, _options: tuple ) -> "IHyperdriveRedeemWithdrawalSharesContractFunction": - super().__call__(_shares, _minOutput, _destination, _asUnderlying) + super().__call__(_shares, _minOutput, _options) return self # TODO: add call def so we can get return types for the calls @@ -482,13 +484,9 @@ class IHyperdriveRemoveLiquidityContractFunction(ContractFunction): # pylint: disable=arguments-differ def __call__( - self, - _shares: int, - _minOutput: int, - _destination: str, - _asUnderlying: bool, + self, _shares: int, _minOutput: int, _options: tuple ) -> "IHyperdriveRemoveLiquidityContractFunction": - super().__call__(_shares, _minOutput, _destination, _asUnderlying) + super().__call__(_shares, _minOutput, _options) return self # TODO: add call def so we can get return types for the calls @@ -501,7 +499,9 @@ class IHyperdriveSetApprovalContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, tokenID: int, operator: str, amount: int) -> "IHyperdriveSetApprovalContractFunction": + def __call__( + self, tokenID: int, operator: str, amount: int + ) -> "IHyperdriveSetApprovalContractFunction": super().__call__(tokenID, operator, amount) return self @@ -531,7 +531,9 @@ class IHyperdriveSetApprovalForAllContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, operator: str, approved: bool) -> "IHyperdriveSetApprovalForAllContractFunction": + def __call__( + self, operator: str, approved: bool + ) -> "IHyperdriveSetApprovalForAllContractFunction": super().__call__(operator, approved) return self @@ -545,8 +547,8 @@ class IHyperdriveSetGovernanceContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, who: str) -> "IHyperdriveSetGovernanceContractFunction": - super().__call__(who) + def __call__(self, _who: str) -> "IHyperdriveSetGovernanceContractFunction": + super().__call__(_who) return self # TODO: add call def so we can get return types for the calls @@ -559,8 +561,10 @@ class IHyperdriveSetPauserContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, who: str, status: bool) -> "IHyperdriveSetPauserContractFunction": - super().__call__(who, status) + def __call__( + self, _who: str, _status: bool + ) -> "IHyperdriveSetPauserContractFunction": + super().__call__(_who, _status) return self # TODO: add call def so we can get return types for the calls @@ -601,7 +605,9 @@ class IHyperdriveTransferFromContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, tokenID: int, _from: str, to: str, amount: int) -> "IHyperdriveTransferFromContractFunction": + def __call__( + self, tokenID: int, _from: str, to: str, amount: int + ) -> "IHyperdriveTransferFromContractFunction": super().__call__(tokenID, _from, to, amount) return self @@ -646,6 +652,8 @@ class IHyperdriveContractFunctions(ContractFunctions): collectGovernanceFee: IHyperdriveCollectGovernanceFeeContractFunction + dataProvider: IHyperdriveDataProviderContractFunction + factory: IHyperdriveFactoryContractFunction getCheckpoint: IHyperdriveGetCheckpointContractFunction @@ -708,11 +716,17 @@ class IHyperdriveContractFunctions(ContractFunctions): class IHyperdriveContract(Contract): """A web3.py Contract class for the IHyperdrive contract.""" - def __init__(self, abi: ABI, address: ChecksumAddress | None = None) -> None: + def __init__(self, address: ChecksumAddress | None = None, abi=Any) -> None: self.abi = abi # TODO: make this better, shouldn't initialize to the zero address, but the Contract's init # function requires an address. - self.address = address if address else cast(ChecksumAddress, "0x0000000000000000000000000000000000000000") + self.address = ( + address + if address + else cast( + ChecksumAddress, "0x0000000000000000000000000000000000000000" + ) + ) try: # Initialize parent Contract class diff --git a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveTypes.py b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveTypes.py index 4a6be15..776e951 100644 --- a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveTypes.py +++ b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveTypes.py @@ -21,6 +21,15 @@ from web3.types import ABIEventParams +@dataclass +class Options: + """Options struct.""" + + destination: str + asBase: bool + extraData: bytes + + @dataclass class Checkpoint: """Checkpoint struct.""" @@ -105,6 +114,8 @@ class WithdrawPool: ABIEventParams(indexed=True, name="provider", type="address"), ABIEventParams(indexed=False, name="lpAmount", type="uint256"), ABIEventParams(indexed=False, name="baseAmount", type="uint256"), + ABIEventParams(indexed=False, name="sharePrice", type="uint256"), + ABIEventParams(indexed=False, name="lpSharePrice", type="uint256"), ], name="AddLiquidity", type="event", @@ -139,6 +150,7 @@ class WithdrawPool: ABIEventParams(indexed=True, name="assetId", type="uint256"), ABIEventParams(indexed=False, name="maturityTime", type="uint256"), ABIEventParams(indexed=False, name="baseAmount", type="uint256"), + ABIEventParams(indexed=False, name="sharePrice", type="uint256"), ABIEventParams(indexed=False, name="bondAmount", type="uint256"), ], name="CloseLong", @@ -152,18 +164,44 @@ class WithdrawPool: ABIEventParams(indexed=True, name="assetId", type="uint256"), ABIEventParams(indexed=False, name="maturityTime", type="uint256"), ABIEventParams(indexed=False, name="baseAmount", type="uint256"), + ABIEventParams(indexed=False, name="sharePrice", type="uint256"), ABIEventParams(indexed=False, name="bondAmount", type="uint256"), ], name="CloseShort", type="event", ) +CollectGovernanceFee = ABIEvent( + anonymous=False, + inputs=[ + ABIEventParams(indexed=True, name="collector", type="address"), + ABIEventParams(indexed=False, name="baseFees", type="uint256"), + ABIEventParams(indexed=False, name="sharePrice", type="uint256"), + ], + name="CollectGovernanceFee", + type="event", +) + +CreateCheckpoint = ABIEvent( + anonymous=False, + inputs=[ + ABIEventParams(indexed=True, name="checkpointTime", type="uint256"), + ABIEventParams(indexed=False, name="sharePrice", type="uint256"), + ABIEventParams(indexed=False, name="maturedShorts", type="uint256"), + ABIEventParams(indexed=False, name="maturedLongs", type="uint256"), + ABIEventParams(indexed=False, name="lpSharePrice", type="uint256"), + ], + name="CreateCheckpoint", + type="event", +) + Initialize = ABIEvent( anonymous=False, inputs=[ ABIEventParams(indexed=True, name="provider", type="address"), ABIEventParams(indexed=False, name="lpAmount", type="uint256"), ABIEventParams(indexed=False, name="baseAmount", type="uint256"), + ABIEventParams(indexed=False, name="sharePrice", type="uint256"), ABIEventParams(indexed=False, name="apr", type="uint256"), ], name="Initialize", @@ -177,6 +215,7 @@ class WithdrawPool: ABIEventParams(indexed=True, name="assetId", type="uint256"), ABIEventParams(indexed=False, name="maturityTime", type="uint256"), ABIEventParams(indexed=False, name="baseAmount", type="uint256"), + ABIEventParams(indexed=False, name="sharePrice", type="uint256"), ABIEventParams(indexed=False, name="bondAmount", type="uint256"), ], name="OpenLong", @@ -190,6 +229,7 @@ class WithdrawPool: ABIEventParams(indexed=True, name="assetId", type="uint256"), ABIEventParams(indexed=False, name="maturityTime", type="uint256"), ABIEventParams(indexed=False, name="baseAmount", type="uint256"), + ABIEventParams(indexed=False, name="sharePrice", type="uint256"), ABIEventParams(indexed=False, name="bondAmount", type="uint256"), ], name="OpenShort", @@ -200,8 +240,11 @@ class WithdrawPool: anonymous=False, inputs=[ ABIEventParams(indexed=True, name="provider", type="address"), - ABIEventParams(indexed=False, name="withdrawalShareAmount", type="uint256"), + ABIEventParams( + indexed=False, name="withdrawalShareAmount", type="uint256" + ), ABIEventParams(indexed=False, name="baseAmount", type="uint256"), + ABIEventParams(indexed=False, name="sharePrice", type="uint256"), ], name="RedeemWithdrawalShares", type="event", @@ -213,7 +256,11 @@ class WithdrawPool: ABIEventParams(indexed=True, name="provider", type="address"), ABIEventParams(indexed=False, name="lpAmount", type="uint256"), ABIEventParams(indexed=False, name="baseAmount", type="uint256"), - ABIEventParams(indexed=False, name="withdrawalShareAmount", type="uint256"), + ABIEventParams(indexed=False, name="sharePrice", type="uint256"), + ABIEventParams( + indexed=False, name="withdrawalShareAmount", type="uint256" + ), + ABIEventParams(indexed=False, name="lpSharePrice", type="uint256"), ], name="RemoveLiquidity", type="event", From ba2c7dc436911f028c41c53f58fc8fb2f0cc2cb1 Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Tue, 7 Nov 2023 11:49:57 -0800 Subject: [PATCH 04/15] Updating cargo lock --- Cargo.lock | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index da23e75..a805d66 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -634,6 +634,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + [[package]] name = "dunce" version = "1.0.4" @@ -1545,6 +1551,7 @@ dependencies = [ "fixed-point", "heck", "rand", + "serde", "tokio", ] @@ -3346,6 +3353,7 @@ name = "test-utils" version = "0.1.0" dependencies = [ "async-trait", + "dotenvy", "ethers", "eyre", "fixed-point", @@ -3357,6 +3365,8 @@ dependencies = [ "rand", "rand_chacha", "reqwest", + "serde", + "serde_json", "tokio", "tracing", ] From 562180b0256b7a7000b600577704279ddfe6c94f Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Tue, 7 Nov 2023 12:59:21 -0800 Subject: [PATCH 05/15] Updating python interface --- .../python/pyperdrive/hyperdrive_state.py | 200 +++++++++++++++--- .../src/hyperdrive_state_methods.rs | 10 - 2 files changed, 169 insertions(+), 41 deletions(-) diff --git a/crates/pyperdrive/python/pyperdrive/hyperdrive_state.py b/crates/pyperdrive/python/pyperdrive/hyperdrive_state.py index efe2df2..fb11a5e 100644 --- a/crates/pyperdrive/python/pyperdrive/hyperdrive_state.py +++ b/crates/pyperdrive/python/pyperdrive/hyperdrive_state.py @@ -8,6 +8,56 @@ # pylint: disable=too-many-arguments +def get_max_spot_price( + pool_config: types.PoolConfigType, + pool_info: types.PoolInfoType, +) -> str: + """Get the pool's max spot price. + + Arguments + --------- + pool_config : PoolConfig + Static configuration for the hyperdrive contract. + Set at deploy time. + pool_info : PoolInfo + Current state information of the hyperdrive contract. + Includes things like reserve levels and share prices. + + Returns + ------- + str (FixedPoint) + max_spot_price = 1/1 + curve_fee * (1 / (spot_price - 1)) + """ + return _get_interface(pool_config, pool_info).get_max_spot_price() + + +def get_spot_price_after_long( + pool_config: types.PoolConfigType, + pool_info: types.PoolInfoType, + long_amount: str, +) -> str: + """Get the spot price after opening the long on YieldSpace + and before calculating the fees. + + Arguments + --------- + pool_config : PoolConfig + Static configuration for the hyperdrive contract. + Set at deploy time. + pool_info : PoolInfo + Current state information of the hyperdrive contract. + Includes things like reserve levels and share prices. + long_amount : str (FixedPoint) + The long amount. + + Returns + ------- + str (FixedPoint) + The spot price after opening the long. + """ + return _get_interface(pool_config, pool_info).get_spot_price_after_long() + + def get_solvency( pool_config: types.PoolConfigType, pool_info: types.PoolInfoType, @@ -137,7 +187,9 @@ def get_short_deposit( # the underlying rust code uses current market share price if this is 0 # zero value is used because the smart contract will return 0 if the checkpoint hasn't been minted open_share_price = "0" - return _get_interface(pool_config, pool_info).get_short_deposit(short_amount, spot_price, open_share_price) + return _get_interface(pool_config, pool_info).get_short_deposit( + short_amount, spot_price, open_share_price + ) def to_checkpoint( @@ -195,7 +247,9 @@ def get_max_long( str (FixedPoint) The maximum long the pool and user's wallet can support. """ - return _get_interface(pool_config, pool_info).get_max_long(budget, checkpoint_exposure, maybe_max_iterations) + return _get_interface(pool_config, pool_info).get_max_long( + budget, checkpoint_exposure, maybe_max_iterations + ) def get_max_short( @@ -242,13 +296,72 @@ def get_max_short( ) -def get_out_for_in( +def calculate_bonds_out_given_shares_in_down( + pool_config: types.PoolConfigType, + pool_info: types.PoolInfoType, + amount_in: str, +) -> str: + """Calculates the amount of bonds a user will receive from the pool by + providing a specified amount of shares. We underestimate the amount of + bonds. + + Arguments + --------- + pool_config : PoolConfig + Static configuration for the hyperdrive contract. + Set at deploy time. + pool_info : PoolInfo + Current state information of the hyperdrive contract. + Includes things like reserve levels and share prices. + amount_in : str (FixedPoint) + The amount of shares going into the pool. + + Returns + ------- + str (FixedPoint) + The amount of bonds out. + """ + return _get_interface( + pool_config, pool_info + ).calculate_bonds_out_given_shares_in_down(amount_in) + + +def calculate_shares_in_given_bonds_out_up( + pool_config: types.PoolConfigType, + pool_info: types.PoolInfoType, + amount_in: str, +) -> str: + """Calculates the amount of shares a user must provide the pool to receive + a specified amount of bonds. We overestimate the amount of shares in. + + Arguments + --------- + pool_config : PoolConfig + Static configuration for the hyperdrive contract. + Set at deploy time. + pool_info : PoolInfo + Current state information of the hyperdrive contract. + Includes things like reserve levels and share prices. + amount_in : str (FixedPoint) + The amount of bonds to target. + + Returns + ------- + str (FixedPoint) + The amount of shares in to reach the target. + """ + return _get_interface( + pool_config, pool_info + ).calculate_shares_in_given_bonds_out_up(amount_in) + + +def calculate_shares_in_given_bonds_out_down( pool_config: types.PoolConfigType, pool_info: types.PoolInfoType, amount_in: str, - shares_in: bool, ) -> str: - """Gets the amount of an asset for a given amount in of the other. + """Calculates the amount of shares a user must provide the pool to receive + a specified amount of bonds. We underestimate the amount of shares in. Arguments --------- @@ -259,26 +372,26 @@ def get_out_for_in( Current state information of the hyperdrive contract. Includes things like reserve levels and share prices. amount_in : str (FixedPoint) - The amount of asset going into the pool. - shares_in : bool - True if the asset in is shares, False if it is bonds. - The amount out will be the opposite type. + The amount of bonds to target. Returns ------- str (FixedPoint) - The amount out. + The amount of shares in to reach the target. """ - return _get_interface(pool_config, pool_info).get_out_for_in(amount_in, shares_in) + return _get_interface( + pool_config, pool_info + ).calculate_shares_in_given_bonds_out_down(amount_in) -def get_out_for_in_safe( +def calculate_shares_out_given_bonds_in_down( pool_config: types.PoolConfigType, pool_info: types.PoolInfoType, amount_in: str, - shares_in: bool, ) -> str: - """Gets the amount of an asset for a given amount in of the other. + """Calculates the amount of shares a user will receive from the pool by + providing a specified amount of bonds. We underestimate the amount of + shares out. Arguments --------- @@ -289,26 +402,52 @@ def get_out_for_in_safe( Current state information of the hyperdrive contract. Includes things like reserve levels and share prices. amount_in : str (FixedPoint) - The amount of asset going into the pool. - shares_in : bool - True if the asset in is shares, False if it is bonds. - The amount out will be the opposite type. + The amount of bonds in. + + Returns + ------- + str (FixedPoint) + The amount of shares out. + """ + return _get_interface( + pool_config, pool_info + ).calculate_shares_out_given_bonds_in_down(amount_in) + + +def calculate_max_buy( + pool_config: types.PoolConfigType, + pool_info: types.PoolInfoType, +) -> str: + """ + Calculates the maximum amount of bonds that can be purchased with the + specified reserves. We round so that the max buy amount is + underestimated. + + Arguments + --------- + pool_config : PoolConfig + Static configuration for the hyperdrive contract. + Set at deploy time. + pool_info : PoolInfo + Current state information of the hyperdrive contract. + Includes things like reserve levels and share prices. Returns ------- str (FixedPoint) - The amount out. + The maximum buy amount. """ - return _get_interface(pool_config, pool_info).get_out_for_in_safe(amount_in, shares_in) + return _get_interface(pool_config, pool_info).calculate_max_buy() -def get_in_for_out( +def calculate_max_sell( pool_config: types.PoolConfigType, pool_info: types.PoolInfoType, - amount_out: str, - shares_out: bool, + minimum_share_reserves: str, ) -> str: - """Gets the amount of an asset for a given amount out of the other. + """Calculates the maximum amount of bonds that can be sold with the + specified reserves. We round so that the max sell amount is + underestimated. Arguments --------- @@ -318,15 +457,14 @@ def get_in_for_out( pool_info : PoolInfo Current state information of the hyperdrive contract. Includes things like reserve levels and share prices. - amount_out : str (FixedPoint) - The amount of asset the user expects to receive from the pool. - shares_out : bool - True if the asset out is shares, False if it is bonds. - The amount in will be the opposite type. + minimum_share_reserves: str (FixedPoint) + The minimum share reserves to target Returns ------- str (FixedPoint) - The amount in as a string representation of a Solidity uint256 value. + The maximum buy amount. """ - return _get_interface(pool_config, pool_info).get_in_for_out(amount_out, shares_out) + return _get_interface(pool_config, pool_info).calculate_max_sell( + minimum_share_reserves + ) diff --git a/crates/pyperdrive/src/hyperdrive_state_methods.rs b/crates/pyperdrive/src/hyperdrive_state_methods.rs index 85ef378..da78cc5 100644 --- a/crates/pyperdrive/src/hyperdrive_state_methods.rs +++ b/crates/pyperdrive/src/hyperdrive_state_methods.rs @@ -122,16 +122,6 @@ impl HyperdriveState { return Ok(result); } - pub fn calculate_shares_out_given_bonds_in_down_safe(&self, amount_in: &str) -> PyResult { - let amount_in_fp = FixedPoint::from(U256::from_dec_str(amount_in).map_err(|_| { - PyErr::new::("Failed to convert budget string to U256") - })?); - let result_fp = - self.state.calculate_shares_out_given_bonds_in_down_safe(amount_in_fp).unwrap(); - let result = U256::from(result_fp).to_string(); - return Ok(result); - } - pub fn calculate_max_buy(&self) -> PyResult { let result_fp = self.state.calculate_max_buy(); let result = U256::from(result_fp).to_string(); From e6586ac913b3f3139c414ac184fb5044c6fdaad6 Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Tue, 7 Nov 2023 13:16:32 -0800 Subject: [PATCH 06/15] Bumping version --- Cargo.lock | 2 +- crates/pyperdrive/Cargo.toml | 2 +- crates/pyperdrive/pyproject.toml | 2 +- crates/pyperdrive/setup.py | 2 +- pyproject.toml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a805d66..f0f57d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2491,7 +2491,7 @@ dependencies = [ [[package]] name = "pyperdrive" -version = "0.1.0" +version = "0.2.0" dependencies = [ "ethers", "eyre", diff --git a/crates/pyperdrive/Cargo.toml b/crates/pyperdrive/Cargo.toml index eb6fcc1..5fde2af 100644 --- a/crates/pyperdrive/Cargo.toml +++ b/crates/pyperdrive/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pyperdrive" edition = "2021" -version = "0.1.0" +version = "0.2.0" authors = [ "Dylan Paiton", "Matt Brown", diff --git a/crates/pyperdrive/pyproject.toml b/crates/pyperdrive/pyproject.toml index 182fa57..51d1912 100644 --- a/crates/pyperdrive/pyproject.toml +++ b/crates/pyperdrive/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pyperdrive" -version = "0.1.0" +version = "0.2.0" requires-python = ">=3.7" classifiers = [ "Programming Language :: Rust", diff --git a/crates/pyperdrive/setup.py b/crates/pyperdrive/setup.py index a08d1aa..caf47c2 100644 --- a/crates/pyperdrive/setup.py +++ b/crates/pyperdrive/setup.py @@ -4,7 +4,7 @@ setup( name="pyperdrive", - version="0.1.0", + version="0.2.0", packages=["pyperdrive"], package_dir={"": "python"}, rust_extensions=[ diff --git a/pyproject.toml b/pyproject.toml index 634c280..d324ac4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pyperdrive" -version = "0.1.0" +version = "0.2.0" authors = [ { name = "Dylan Paiton", email = "dylan@delv.tech" }, { name = "Matthew Brown", email = "matt@delv.tech" }, From 4b2bae95ac057456d00fc2920845ae3610fd55ef Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Tue, 7 Nov 2023 14:08:25 -0800 Subject: [PATCH 07/15] Updating tests and fixing typo --- .../python/pyperdrive/hyperdrive_state.py | 2 +- system_tests/wrapper_tests.py | 84 ++++++++++++++----- 2 files changed, 63 insertions(+), 23 deletions(-) diff --git a/crates/pyperdrive/python/pyperdrive/hyperdrive_state.py b/crates/pyperdrive/python/pyperdrive/hyperdrive_state.py index fb11a5e..3c683d0 100644 --- a/crates/pyperdrive/python/pyperdrive/hyperdrive_state.py +++ b/crates/pyperdrive/python/pyperdrive/hyperdrive_state.py @@ -55,7 +55,7 @@ def get_spot_price_after_long( str (FixedPoint) The spot price after opening the long. """ - return _get_interface(pool_config, pool_info).get_spot_price_after_long() + return _get_interface(pool_config, pool_info).get_spot_price_after_long(long_amount) def get_solvency( diff --git a/system_tests/wrapper_tests.py b/system_tests/wrapper_tests.py index 2b07213..c38f14f 100644 --- a/system_tests/wrapper_tests.py +++ b/system_tests/wrapper_tests.py @@ -37,6 +37,30 @@ ) +def test_get_max_spot_price(): + """test get_max_spot_rate.""" + max_spot_price = pyperdrive.get_max_spot_price(POOL_CONFIG, POOL_INFO) + assert max_spot_price is not None, "Failed to get max spot price." + assert isinstance(max_spot_price, str), "Expected spot rate to be a string." + assert int(max_spot_price) > 0, "Expected max_spot_price to > 0." + + +def test_get_spot_price_after_long(): + """test get_spot_price_after_long.""" + spot_price = pyperdrive.get_spot_price_after_long(POOL_CONFIG, POOL_INFO, long_amount=str(1_000 * 10**18)) + assert spot_price is not None, "Failed to get spot price after long." + assert isinstance(spot_price, str), "Expected spot rate to be a string." + assert int(spot_price) > 0, "Expected max_spot_price to > 0." + + +def test_get_solvency(): + """test get_max_spot_rate.""" + solvency = pyperdrive.get_solvency(POOL_CONFIG, POOL_INFO) + assert solvency is not None, "Failed to get spot price after long." + assert isinstance(solvency, str), "Expected spot rate to be a string." + assert int(solvency) > 0, "Expected max_spot_price to > 0." + + def test_get_spot_rate(): """test get_spot_rate.""" spot_rate = pyperdrive.get_spot_rate(POOL_CONFIG, POOL_INFO) @@ -99,29 +123,45 @@ def test_calculate_bonds_given_shares_and_rate(): assert int(bonds) > 0, "Expected bonds to be > 0." -def get_out_for_in(): - """Test get_out_for_in.""" +def test_calculate_bonds_out_given_shares_in_down(): + """Test calculate_bonds_out_given_shares_in_down.""" amount_in = str(1_000 * 10**18) - is_shares_in = True - is_bonds_in = not is_shares_in - # test bonds - bonds_out = pyperdrive.get_out_for_in(POOL_CONFIG, POOL_INFO, amount_in, is_shares_in) - assert int(bonds_out) > 0 - # test shares - shares_out = pyperdrive.get_out_for_in(POOL_CONFIG, POOL_INFO, amount_in, is_bonds_in) - assert int(shares_out) > 0 - - -def get_in_for_out(): - """Test get_in_for_out.""" - # test using the state directly - amount_out = str(1_000 * 10**18) - is_shares_out = True - is_bonds_out = not is_shares_out - bonds_in = pyperdrive.get_in_for_out(POOL_CONFIG, POOL_INFO, amount_out, is_shares_out) - assert int(bonds_in) > 0 - shares_in = pyperdrive.get_in_for_out(POOL_CONFIG, POOL_INFO, amount_out, is_bonds_out) - assert int(shares_in) > 0 + out = pyperdrive.calculate_bonds_out_given_shares_in_down(POOL_CONFIG, POOL_INFO, amount_in) + assert int(out) > 0 + + +def test_calculate_shares_in_given_bonds_out_up(): + """Test calculate_shares_in_given_bonds_out_up.""" + amount_in = str(1_000 * 10**18) + out = pyperdrive.calculate_shares_in_given_bonds_out_up(POOL_CONFIG, POOL_INFO, amount_in) + assert int(out) > 0 + + +def test_calculate_shares_in_given_bonds_out_down(): + """Test calculate_shares_in_given_bonds_out_down.""" + amount_in = str(1_000 * 10**18) + out = pyperdrive.calculate_shares_in_given_bonds_out_down(POOL_CONFIG, POOL_INFO, amount_in) + assert int(out) > 0 + + +def test_calculate_shares_out_given_bonds_in_down(): + """Test calculate_shares_out_given_bonds_in_down.""" + amount_in = str(1_000 * 10**18) + out = pyperdrive.calculate_shares_out_given_bonds_in_down(POOL_CONFIG, POOL_INFO, amount_in) + assert int(out) > 0 + + +def test_calculate_max_buy(): + """Test calculate_max_buy.""" + out = pyperdrive.calculate_max_buy(POOL_CONFIG, POOL_INFO) + assert int(out) > 0 + + +def test_calculate_max_sell(): + """Test calculate_max_buy.""" + minimum_share_reserves = str(10 * 10**18) + out = pyperdrive.calculate_max_sell(POOL_CONFIG, POOL_INFO, minimum_share_reserves) + assert int(out) > 0 def test_get_long_amount(): From cdfe144ce3dfea8c61e02b3121a4967bcba7c03f Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Tue, 7 Nov 2023 14:10:42 -0800 Subject: [PATCH 08/15] Updating workflow hyperdrive versions --- .github/workflows/build_linux_wheel.yml | 2 +- .github/workflows/build_wasm.yml | 2 +- .github/workflows/build_wheels.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/test.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build_linux_wheel.yml b/.github/workflows/build_linux_wheel.yml index 5ff3569..cb1ae87 100644 --- a/.github/workflows/build_linux_wheel.yml +++ b/.github/workflows/build_linux_wheel.yml @@ -41,7 +41,7 @@ jobs: uses: actions/checkout@master with: repository: delvtech/hyperdrive - ref: "v0.0.16" + ref: "v0.2.0" path: "./hyperdrive" ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }} diff --git a/.github/workflows/build_wasm.yml b/.github/workflows/build_wasm.yml index be151f4..967fb94 100644 --- a/.github/workflows/build_wasm.yml +++ b/.github/workflows/build_wasm.yml @@ -39,7 +39,7 @@ jobs: uses: actions/checkout@master with: repository: delvtech/hyperdrive - ref: "v0.0.16" + ref: "v0.2.0" path: "./hyperdrive" ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }} diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 19d7168..f04a1a7 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -32,7 +32,7 @@ jobs: uses: actions/checkout@master with: repository: delvtech/hyperdrive - ref: "v0.0.16" + ref: "v0.2.0" path: "./hyperdrive" ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8e54df1..2909b67 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -22,7 +22,7 @@ jobs: uses: actions/checkout@master with: repository: delvtech/hyperdrive - ref: "v0.0.16" + ref: "v0.2.0" path: "./hyperdrive" ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2d63f27..6c77153 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: uses: actions/checkout@master with: repository: delvtech/hyperdrive - ref: "v0.0.16" + ref: "v0.2.0" path: "./hyperdrive" ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }} From 4f22d1dd60f9cd5774e8c16d7f0974ceebada242 Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Tue, 7 Nov 2023 16:40:22 -0800 Subject: [PATCH 09/15] Black for codegen code --- .../pypechain_types/IHyperdriveContract.py | 8 ++------ .../pyperdrive/pypechain_types/IHyperdriveTypes.py | 13 +++---------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py index 13c95af..2823b5b 100644 --- a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py +++ b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py @@ -98,9 +98,7 @@ class IHyperdriveCheckpointContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, _checkpointTime: int - ) -> "IHyperdriveCheckpointContractFunction": + def __call__(self, _checkpointTime: int) -> "IHyperdriveCheckpointContractFunction": super().__call__(_checkpointTime) return self @@ -723,9 +721,7 @@ def __init__(self, address: ChecksumAddress | None = None, abi=Any) -> None: self.address = ( address if address - else cast( - ChecksumAddress, "0x0000000000000000000000000000000000000000" - ) + else cast(ChecksumAddress, "0x0000000000000000000000000000000000000000") ) try: diff --git a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveTypes.py b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveTypes.py index 776e951..5a412f9 100644 --- a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveTypes.py +++ b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveTypes.py @@ -13,12 +13,9 @@ # pylint: disable=no-else-return from __future__ import annotations - from dataclasses import dataclass -from web3.types import ABIEvent - -from web3.types import ABIEventParams +from web3.types import ABIEvent, ABIEventParams @dataclass @@ -240,9 +237,7 @@ class WithdrawPool: anonymous=False, inputs=[ ABIEventParams(indexed=True, name="provider", type="address"), - ABIEventParams( - indexed=False, name="withdrawalShareAmount", type="uint256" - ), + ABIEventParams(indexed=False, name="withdrawalShareAmount", type="uint256"), ABIEventParams(indexed=False, name="baseAmount", type="uint256"), ABIEventParams(indexed=False, name="sharePrice", type="uint256"), ], @@ -257,9 +252,7 @@ class WithdrawPool: ABIEventParams(indexed=False, name="lpAmount", type="uint256"), ABIEventParams(indexed=False, name="baseAmount", type="uint256"), ABIEventParams(indexed=False, name="sharePrice", type="uint256"), - ABIEventParams( - indexed=False, name="withdrawalShareAmount", type="uint256" - ), + ABIEventParams(indexed=False, name="withdrawalShareAmount", type="uint256"), ABIEventParams(indexed=False, name="lpSharePrice", type="uint256"), ], name="RemoveLiquidity", From fa1a77dcf760e3826b6dbdeb4cdee046a75ba8c4 Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Wed, 8 Nov 2023 11:23:53 -0800 Subject: [PATCH 10/15] formatting change --- .../python/pyperdrive/hyperdrive_state.py | 28 +++-------- .../pypechain_types/IHyperdriveContract.py | 50 +++++-------------- 2 files changed, 19 insertions(+), 59 deletions(-) diff --git a/crates/pyperdrive/python/pyperdrive/hyperdrive_state.py b/crates/pyperdrive/python/pyperdrive/hyperdrive_state.py index 3c683d0..e541e5d 100644 --- a/crates/pyperdrive/python/pyperdrive/hyperdrive_state.py +++ b/crates/pyperdrive/python/pyperdrive/hyperdrive_state.py @@ -187,9 +187,7 @@ def get_short_deposit( # the underlying rust code uses current market share price if this is 0 # zero value is used because the smart contract will return 0 if the checkpoint hasn't been minted open_share_price = "0" - return _get_interface(pool_config, pool_info).get_short_deposit( - short_amount, spot_price, open_share_price - ) + return _get_interface(pool_config, pool_info).get_short_deposit(short_amount, spot_price, open_share_price) def to_checkpoint( @@ -247,9 +245,7 @@ def get_max_long( str (FixedPoint) The maximum long the pool and user's wallet can support. """ - return _get_interface(pool_config, pool_info).get_max_long( - budget, checkpoint_exposure, maybe_max_iterations - ) + return _get_interface(pool_config, pool_info).get_max_long(budget, checkpoint_exposure, maybe_max_iterations) def get_max_short( @@ -321,9 +317,7 @@ def calculate_bonds_out_given_shares_in_down( str (FixedPoint) The amount of bonds out. """ - return _get_interface( - pool_config, pool_info - ).calculate_bonds_out_given_shares_in_down(amount_in) + return _get_interface(pool_config, pool_info).calculate_bonds_out_given_shares_in_down(amount_in) def calculate_shares_in_given_bonds_out_up( @@ -350,9 +344,7 @@ def calculate_shares_in_given_bonds_out_up( str (FixedPoint) The amount of shares in to reach the target. """ - return _get_interface( - pool_config, pool_info - ).calculate_shares_in_given_bonds_out_up(amount_in) + return _get_interface(pool_config, pool_info).calculate_shares_in_given_bonds_out_up(amount_in) def calculate_shares_in_given_bonds_out_down( @@ -379,9 +371,7 @@ def calculate_shares_in_given_bonds_out_down( str (FixedPoint) The amount of shares in to reach the target. """ - return _get_interface( - pool_config, pool_info - ).calculate_shares_in_given_bonds_out_down(amount_in) + return _get_interface(pool_config, pool_info).calculate_shares_in_given_bonds_out_down(amount_in) def calculate_shares_out_given_bonds_in_down( @@ -409,9 +399,7 @@ def calculate_shares_out_given_bonds_in_down( str (FixedPoint) The amount of shares out. """ - return _get_interface( - pool_config, pool_info - ).calculate_shares_out_given_bonds_in_down(amount_in) + return _get_interface(pool_config, pool_info).calculate_shares_out_given_bonds_in_down(amount_in) def calculate_max_buy( @@ -465,6 +453,4 @@ def calculate_max_sell( str (FixedPoint) The maximum buy amount. """ - return _get_interface(pool_config, pool_info).calculate_max_sell( - minimum_share_reserves - ) + return _get_interface(pool_config, pool_info).calculate_max_sell(minimum_share_reserves) diff --git a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py index 2823b5b..40f679a 100644 --- a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py +++ b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py @@ -52,9 +52,7 @@ class IHyperdriveBalanceOfContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, tokenId: int, owner: str - ) -> "IHyperdriveBalanceOfContractFunction": + def __call__(self, tokenId: int, owner: str) -> "IHyperdriveBalanceOfContractFunction": super().__call__(tokenId, owner) return self @@ -152,9 +150,7 @@ class IHyperdriveCollectGovernanceFeeContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, _options: tuple - ) -> "IHyperdriveCollectGovernanceFeeContractFunction": + def __call__(self, _options: tuple) -> "IHyperdriveCollectGovernanceFeeContractFunction": super().__call__(_options) return self @@ -196,9 +192,7 @@ class IHyperdriveGetCheckpointContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, _checkpointId: int - ) -> "IHyperdriveGetCheckpointContractFunction": + def __call__(self, _checkpointId: int) -> "IHyperdriveGetCheckpointContractFunction": super().__call__(_checkpointId) return self @@ -284,9 +278,7 @@ class IHyperdriveInitializeContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, _contribution: int, _apr: int, _options: tuple - ) -> "IHyperdriveInitializeContractFunction": + def __call__(self, _contribution: int, _apr: int, _options: tuple) -> "IHyperdriveInitializeContractFunction": super().__call__(_contribution, _apr, _options) return self @@ -300,9 +292,7 @@ class IHyperdriveIsApprovedForAllContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, owner: str, spender: str - ) -> "IHyperdriveIsApprovedForAllContractFunction": + def __call__(self, owner: str, spender: str) -> "IHyperdriveIsApprovedForAllContractFunction": super().__call__(owner, spender) return self @@ -426,9 +416,7 @@ class IHyperdrivePerTokenApprovalsContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, tokenId: int, owner: str, spender: str - ) -> "IHyperdrivePerTokenApprovalsContractFunction": + def __call__(self, tokenId: int, owner: str, spender: str) -> "IHyperdrivePerTokenApprovalsContractFunction": super().__call__(tokenId, owner, spender) return self @@ -481,9 +469,7 @@ class IHyperdriveRemoveLiquidityContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, _shares: int, _minOutput: int, _options: tuple - ) -> "IHyperdriveRemoveLiquidityContractFunction": + def __call__(self, _shares: int, _minOutput: int, _options: tuple) -> "IHyperdriveRemoveLiquidityContractFunction": super().__call__(_shares, _minOutput, _options) return self @@ -497,9 +483,7 @@ class IHyperdriveSetApprovalContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, tokenID: int, operator: str, amount: int - ) -> "IHyperdriveSetApprovalContractFunction": + def __call__(self, tokenID: int, operator: str, amount: int) -> "IHyperdriveSetApprovalContractFunction": super().__call__(tokenID, operator, amount) return self @@ -529,9 +513,7 @@ class IHyperdriveSetApprovalForAllContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, operator: str, approved: bool - ) -> "IHyperdriveSetApprovalForAllContractFunction": + def __call__(self, operator: str, approved: bool) -> "IHyperdriveSetApprovalForAllContractFunction": super().__call__(operator, approved) return self @@ -559,9 +541,7 @@ class IHyperdriveSetPauserContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, _who: str, _status: bool - ) -> "IHyperdriveSetPauserContractFunction": + def __call__(self, _who: str, _status: bool) -> "IHyperdriveSetPauserContractFunction": super().__call__(_who, _status) return self @@ -603,9 +583,7 @@ class IHyperdriveTransferFromContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, tokenID: int, _from: str, to: str, amount: int - ) -> "IHyperdriveTransferFromContractFunction": + def __call__(self, tokenID: int, _from: str, to: str, amount: int) -> "IHyperdriveTransferFromContractFunction": super().__call__(tokenID, _from, to, amount) return self @@ -718,11 +696,7 @@ def __init__(self, address: ChecksumAddress | None = None, abi=Any) -> None: self.abi = abi # TODO: make this better, shouldn't initialize to the zero address, but the Contract's init # function requires an address. - self.address = ( - address - if address - else cast(ChecksumAddress, "0x0000000000000000000000000000000000000000") - ) + self.address = address if address else cast(ChecksumAddress, "0x0000000000000000000000000000000000000000") try: # Initialize parent Contract class From 6cd52152996a2d0777507457c4a80cd5cc1bb95b Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Wed, 8 Nov 2023 11:46:56 -0800 Subject: [PATCH 11/15] Reverting wasm hyperdrive version to 0.0.16 --- .github/workflows/build_wasm.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wasm.yml b/.github/workflows/build_wasm.yml index 967fb94..be151f4 100644 --- a/.github/workflows/build_wasm.yml +++ b/.github/workflows/build_wasm.yml @@ -39,7 +39,7 @@ jobs: uses: actions/checkout@master with: repository: delvtech/hyperdrive - ref: "v0.2.0" + ref: "v0.0.16" path: "./hyperdrive" ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }} From 68c927af4b708c37e832c8591e7ccfa528e9846c Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Wed, 8 Nov 2023 12:08:23 -0800 Subject: [PATCH 12/15] Pypechain update --- .../pypechain_types/IHyperdriveContract.py | 1620 ++++++++++++++++- 1 file changed, 1615 insertions(+), 5 deletions(-) diff --git a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py index 40f679a..6323cd3 100644 --- a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py +++ b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py @@ -14,6 +14,7 @@ from eth_typing import ChecksumAddress from web3.contract.contract import Contract, ContractFunction, ContractFunctions from web3.exceptions import FallbackNotFound +from web3.types import ABI class IHyperdriveDOMAIN_SEPARATORContractFunction(ContractFunction): @@ -689,15 +690,1624 @@ class IHyperdriveContractFunctions(ContractFunctions): transferFromBridge: IHyperdriveTransferFromBridgeContractFunction +ihyperdrive_abi: ABI = cast( + ABI, + [ + {"inputs": [], "name": "AlreadyClosed", "type": "error"}, + {"inputs": [], "name": "ApprovalFailed", "type": "error"}, + { + "inputs": [], + "name": "BaseBufferExceedsShareReserves", + "type": "error", + }, + {"inputs": [], "name": "BatchInputLengthMismatch", "type": "error"}, + {"inputs": [], "name": "BelowMinimumContribution", "type": "error"}, + {"inputs": [], "name": "BelowMinimumShareReserves", "type": "error"}, + {"inputs": [], "name": "BondMatured", "type": "error"}, + {"inputs": [], "name": "BondNotMatured", "type": "error"}, + { + "inputs": [ + { + "internalType": "bytes4", + "name": "underlyingError", + "type": "bytes4", + } + ], + "name": "CallFailed", + "type": "error", + }, + {"inputs": [], "name": "ExpiredDeadline", "type": "error"}, + {"inputs": [], "name": "FeeTooHigh", "type": "error"}, + { + "inputs": [], + "name": "FixedPointMath_InvalidExponent", + "type": "error", + }, + {"inputs": [], "name": "FixedPointMath_InvalidInput", "type": "error"}, + {"inputs": [], "name": "FixedPointMath_NegativeInput", "type": "error"}, + { + "inputs": [], + "name": "FixedPointMath_NegativeOrZeroInput", + "type": "error", + }, + {"inputs": [], "name": "InputLengthMismatch", "type": "error"}, + {"inputs": [], "name": "InsufficientPrice", "type": "error"}, + {"inputs": [], "name": "InvalidApr", "type": "error"}, + {"inputs": [], "name": "InvalidBaseToken", "type": "error"}, + {"inputs": [], "name": "InvalidCheckpointDuration", "type": "error"}, + {"inputs": [], "name": "InvalidCheckpointTime", "type": "error"}, + {"inputs": [], "name": "InvalidContribution", "type": "error"}, + {"inputs": [], "name": "InvalidERC20Bridge", "type": "error"}, + {"inputs": [], "name": "InvalidFeeAmounts", "type": "error"}, + {"inputs": [], "name": "InvalidFeeDestination", "type": "error"}, + {"inputs": [], "name": "InvalidForwarderAddress", "type": "error"}, + {"inputs": [], "name": "InvalidInitialSharePrice", "type": "error"}, + {"inputs": [], "name": "InvalidMaturityTime", "type": "error"}, + {"inputs": [], "name": "InvalidMinimumShareReserves", "type": "error"}, + {"inputs": [], "name": "InvalidPositionDuration", "type": "error"}, + {"inputs": [], "name": "InvalidShareReserves", "type": "error"}, + {"inputs": [], "name": "InvalidSignature", "type": "error"}, + {"inputs": [], "name": "InvalidTimestamp", "type": "error"}, + {"inputs": [], "name": "InvalidToken", "type": "error"}, + {"inputs": [], "name": "InvalidTradeSize", "type": "error"}, + {"inputs": [], "name": "MaxFeeTooHigh", "type": "error"}, + {"inputs": [], "name": "MinimumSharePrice", "type": "error"}, + {"inputs": [], "name": "MinimumTransactionAmount", "type": "error"}, + {"inputs": [], "name": "MintPercentTooHigh", "type": "error"}, + {"inputs": [], "name": "NegativeInterest", "type": "error"}, + {"inputs": [], "name": "NegativePresentValue", "type": "error"}, + {"inputs": [], "name": "NoAssetsToWithdraw", "type": "error"}, + {"inputs": [], "name": "NonPayableInitialization", "type": "error"}, + {"inputs": [], "name": "NotPayable", "type": "error"}, + {"inputs": [], "name": "OutputLimit", "type": "error"}, + {"inputs": [], "name": "Paused", "type": "error"}, + {"inputs": [], "name": "PoolAlreadyInitialized", "type": "error"}, + {"inputs": [], "name": "QueryOutOfRange", "type": "error"}, + {"inputs": [], "name": "RestrictedZeroAddress", "type": "error"}, + { + "inputs": [{"internalType": "bytes", "name": "data", "type": "bytes"}], + "name": "ReturnData", + "type": "error", + }, + { + "inputs": [], + "name": "ShareReservesDeltaExceedsBondReservesDelta", + "type": "error", + }, + {"inputs": [], "name": "TransferFailed", "type": "error"}, + {"inputs": [], "name": "Unauthorized", "type": "error"}, + {"inputs": [], "name": "UnexpectedAssetId", "type": "error"}, + {"inputs": [], "name": "UnexpectedSender", "type": "error"}, + {"inputs": [], "name": "UnexpectedSuccess", "type": "error"}, + {"inputs": [], "name": "UnsafeCastToInt128", "type": "error"}, + {"inputs": [], "name": "UnsafeCastToUint128", "type": "error"}, + {"inputs": [], "name": "UnsupportedToken", "type": "error"}, + {"inputs": [], "name": "ZeroLpTotalSupply", "type": "error"}, + { + "anonymous": False, + "inputs": [ + { + "indexed": True, + "internalType": "address", + "name": "provider", + "type": "address", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "lpAmount", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "baseAmount", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "sharePrice", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "lpSharePrice", + "type": "uint256", + }, + ], + "name": "AddLiquidity", + "type": "event", + }, + { + "anonymous": False, + "inputs": [ + { + "indexed": True, + "internalType": "address", + "name": "owner", + "type": "address", + }, + { + "indexed": True, + "internalType": "address", + "name": "spender", + "type": "address", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "value", + "type": "uint256", + }, + ], + "name": "Approval", + "type": "event", + }, + { + "anonymous": False, + "inputs": [ + { + "indexed": True, + "internalType": "address", + "name": "account", + "type": "address", + }, + { + "indexed": True, + "internalType": "address", + "name": "operator", + "type": "address", + }, + { + "indexed": False, + "internalType": "bool", + "name": "approved", + "type": "bool", + }, + ], + "name": "ApprovalForAll", + "type": "event", + }, + { + "anonymous": False, + "inputs": [ + { + "indexed": True, + "internalType": "address", + "name": "trader", + "type": "address", + }, + { + "indexed": True, + "internalType": "uint256", + "name": "assetId", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "maturityTime", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "baseAmount", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "sharePrice", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "bondAmount", + "type": "uint256", + }, + ], + "name": "CloseLong", + "type": "event", + }, + { + "anonymous": False, + "inputs": [ + { + "indexed": True, + "internalType": "address", + "name": "trader", + "type": "address", + }, + { + "indexed": True, + "internalType": "uint256", + "name": "assetId", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "maturityTime", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "baseAmount", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "sharePrice", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "bondAmount", + "type": "uint256", + }, + ], + "name": "CloseShort", + "type": "event", + }, + { + "anonymous": False, + "inputs": [ + { + "indexed": True, + "internalType": "address", + "name": "collector", + "type": "address", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "baseFees", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "sharePrice", + "type": "uint256", + }, + ], + "name": "CollectGovernanceFee", + "type": "event", + }, + { + "anonymous": False, + "inputs": [ + { + "indexed": True, + "internalType": "uint256", + "name": "checkpointTime", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "sharePrice", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "maturedShorts", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "maturedLongs", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "lpSharePrice", + "type": "uint256", + }, + ], + "name": "CreateCheckpoint", + "type": "event", + }, + { + "anonymous": False, + "inputs": [ + { + "indexed": True, + "internalType": "address", + "name": "provider", + "type": "address", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "lpAmount", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "baseAmount", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "sharePrice", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "apr", + "type": "uint256", + }, + ], + "name": "Initialize", + "type": "event", + }, + { + "anonymous": False, + "inputs": [ + { + "indexed": True, + "internalType": "address", + "name": "trader", + "type": "address", + }, + { + "indexed": True, + "internalType": "uint256", + "name": "assetId", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "maturityTime", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "baseAmount", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "sharePrice", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "bondAmount", + "type": "uint256", + }, + ], + "name": "OpenLong", + "type": "event", + }, + { + "anonymous": False, + "inputs": [ + { + "indexed": True, + "internalType": "address", + "name": "trader", + "type": "address", + }, + { + "indexed": True, + "internalType": "uint256", + "name": "assetId", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "maturityTime", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "baseAmount", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "sharePrice", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "bondAmount", + "type": "uint256", + }, + ], + "name": "OpenShort", + "type": "event", + }, + { + "anonymous": False, + "inputs": [ + { + "indexed": True, + "internalType": "address", + "name": "provider", + "type": "address", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "withdrawalShareAmount", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "baseAmount", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "sharePrice", + "type": "uint256", + }, + ], + "name": "RedeemWithdrawalShares", + "type": "event", + }, + { + "anonymous": False, + "inputs": [ + { + "indexed": True, + "internalType": "address", + "name": "provider", + "type": "address", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "lpAmount", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "baseAmount", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "sharePrice", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "withdrawalShareAmount", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "lpSharePrice", + "type": "uint256", + }, + ], + "name": "RemoveLiquidity", + "type": "event", + }, + { + "anonymous": False, + "inputs": [ + { + "indexed": True, + "internalType": "address", + "name": "operator", + "type": "address", + }, + { + "indexed": True, + "internalType": "address", + "name": "from", + "type": "address", + }, + { + "indexed": True, + "internalType": "address", + "name": "to", + "type": "address", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "id", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "value", + "type": "uint256", + }, + ], + "name": "TransferSingle", + "type": "event", + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{"internalType": "bytes32", "name": "", "type": "bytes32"}], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_contribution", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "_minApr", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "_maxApr", + "type": "uint256", + }, + { + "components": [ + { + "internalType": "address", + "name": "destination", + "type": "address", + }, + { + "internalType": "bool", + "name": "asBase", + "type": "bool", + }, + { + "internalType": "bytes", + "name": "extraData", + "type": "bytes", + }, + ], + "internalType": "struct IHyperdrive.Options", + "name": "_options", + "type": "tuple", + }, + ], + "name": "addLiquidity", + "outputs": [ + { + "internalType": "uint256", + "name": "lpShares", + "type": "uint256", + } + ], + "stateMutability": "payable", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256", + }, + {"internalType": "address", "name": "owner", "type": "address"}, + ], + "name": "balanceOf", + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [], + "name": "baseToken", + "outputs": [{"internalType": "address", "name": "", "type": "address"}], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [ + {"internalType": "address", "name": "from", "type": "address"}, + {"internalType": "address", "name": "to", "type": "address"}, + { + "internalType": "uint256[]", + "name": "ids", + "type": "uint256[]", + }, + { + "internalType": "uint256[]", + "name": "values", + "type": "uint256[]", + }, + ], + "name": "batchTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_checkpointTime", + "type": "uint256", + } + ], + "name": "checkpoint", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_maturityTime", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "_bondAmount", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "_minOutput", + "type": "uint256", + }, + { + "components": [ + { + "internalType": "address", + "name": "destination", + "type": "address", + }, + { + "internalType": "bool", + "name": "asBase", + "type": "bool", + }, + { + "internalType": "bytes", + "name": "extraData", + "type": "bytes", + }, + ], + "internalType": "struct IHyperdrive.Options", + "name": "_options", + "type": "tuple", + }, + ], + "name": "closeLong", + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "stateMutability": "nonpayable", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_maturityTime", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "_bondAmount", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "_minOutput", + "type": "uint256", + }, + { + "components": [ + { + "internalType": "address", + "name": "destination", + "type": "address", + }, + { + "internalType": "bool", + "name": "asBase", + "type": "bool", + }, + { + "internalType": "bytes", + "name": "extraData", + "type": "bytes", + }, + ], + "internalType": "struct IHyperdrive.Options", + "name": "_options", + "type": "tuple", + }, + ], + "name": "closeShort", + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "stateMutability": "nonpayable", + "type": "function", + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "address", + "name": "destination", + "type": "address", + }, + { + "internalType": "bool", + "name": "asBase", + "type": "bool", + }, + { + "internalType": "bytes", + "name": "extraData", + "type": "bytes", + }, + ], + "internalType": "struct IHyperdrive.Options", + "name": "_options", + "type": "tuple", + } + ], + "name": "collectGovernanceFee", + "outputs": [ + { + "internalType": "uint256", + "name": "proceeds", + "type": "uint256", + } + ], + "stateMutability": "nonpayable", + "type": "function", + }, + { + "inputs": [], + "name": "dataProvider", + "outputs": [{"internalType": "address", "name": "", "type": "address"}], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [], + "name": "factory", + "outputs": [{"internalType": "address", "name": "", "type": "address"}], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_checkpointId", + "type": "uint256", + } + ], + "name": "getCheckpoint", + "outputs": [ + { + "components": [ + { + "internalType": "uint128", + "name": "sharePrice", + "type": "uint128", + }, + { + "internalType": "int128", + "name": "longExposure", + "type": "int128", + }, + ], + "internalType": "struct IHyperdrive.Checkpoint", + "name": "", + "type": "tuple", + } + ], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [], + "name": "getMarketState", + "outputs": [ + { + "components": [ + { + "internalType": "uint128", + "name": "shareReserves", + "type": "uint128", + }, + { + "internalType": "uint128", + "name": "bondReserves", + "type": "uint128", + }, + { + "internalType": "int128", + "name": "shareAdjustment", + "type": "int128", + }, + { + "internalType": "uint128", + "name": "longExposure", + "type": "uint128", + }, + { + "internalType": "uint128", + "name": "longsOutstanding", + "type": "uint128", + }, + { + "internalType": "uint128", + "name": "shortsOutstanding", + "type": "uint128", + }, + { + "internalType": "uint128", + "name": "longAverageMaturityTime", + "type": "uint128", + }, + { + "internalType": "uint128", + "name": "shortAverageMaturityTime", + "type": "uint128", + }, + { + "internalType": "bool", + "name": "isInitialized", + "type": "bool", + }, + { + "internalType": "bool", + "name": "isPaused", + "type": "bool", + }, + ], + "internalType": "struct IHyperdrive.MarketState", + "name": "", + "type": "tuple", + } + ], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [], + "name": "getPoolConfig", + "outputs": [ + { + "components": [ + { + "internalType": "contract IERC20", + "name": "baseToken", + "type": "address", + }, + { + "internalType": "uint256", + "name": "initialSharePrice", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "minimumShareReserves", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "minimumTransactionAmount", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "positionDuration", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "checkpointDuration", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "timeStretch", + "type": "uint256", + }, + { + "internalType": "address", + "name": "governance", + "type": "address", + }, + { + "internalType": "address", + "name": "feeCollector", + "type": "address", + }, + { + "components": [ + { + "internalType": "uint256", + "name": "curve", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "flat", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "governance", + "type": "uint256", + }, + ], + "internalType": "struct IHyperdrive.Fees", + "name": "fees", + "type": "tuple", + }, + { + "internalType": "uint256", + "name": "oracleSize", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "updateGap", + "type": "uint256", + }, + ], + "internalType": "struct IHyperdrive.PoolConfig", + "name": "", + "type": "tuple", + } + ], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [], + "name": "getPoolInfo", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "shareReserves", + "type": "uint256", + }, + { + "internalType": "int256", + "name": "shareAdjustment", + "type": "int256", + }, + { + "internalType": "uint256", + "name": "bondReserves", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "lpTotalSupply", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "sharePrice", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "longsOutstanding", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "longAverageMaturityTime", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "shortsOutstanding", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "shortAverageMaturityTime", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "withdrawalSharesReadyToWithdraw", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "withdrawalSharesProceeds", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "lpSharePrice", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "longExposure", + "type": "uint256", + }, + ], + "internalType": "struct IHyperdrive.PoolInfo", + "name": "", + "type": "tuple", + } + ], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [], + "name": "getUncollectedGovernanceFees", + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [], + "name": "getWithdrawPool", + "outputs": [ + { + "components": [ + { + "internalType": "uint128", + "name": "readyToWithdraw", + "type": "uint128", + }, + { + "internalType": "uint128", + "name": "proceeds", + "type": "uint128", + }, + ], + "internalType": "struct IHyperdrive.WithdrawPool", + "name": "", + "type": "tuple", + } + ], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_contribution", + "type": "uint256", + }, + {"internalType": "uint256", "name": "_apr", "type": "uint256"}, + { + "components": [ + { + "internalType": "address", + "name": "destination", + "type": "address", + }, + { + "internalType": "bool", + "name": "asBase", + "type": "bool", + }, + { + "internalType": "bytes", + "name": "extraData", + "type": "bytes", + }, + ], + "internalType": "struct IHyperdrive.Options", + "name": "_options", + "type": "tuple", + }, + ], + "name": "initialize", + "outputs": [ + { + "internalType": "uint256", + "name": "lpShares", + "type": "uint256", + } + ], + "stateMutability": "payable", + "type": "function", + }, + { + "inputs": [ + {"internalType": "address", "name": "owner", "type": "address"}, + { + "internalType": "address", + "name": "spender", + "type": "address", + }, + ], + "name": "isApprovedForAll", + "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [], + "name": "linkerCodeHash", + "outputs": [{"internalType": "bytes32", "name": "", "type": "bytes32"}], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256[]", + "name": "_slots", + "type": "uint256[]", + } + ], + "name": "load", + "outputs": [{"internalType": "bytes32[]", "name": "", "type": "bytes32[]"}], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [{"internalType": "uint256", "name": "id", "type": "uint256"}], + "name": "name", + "outputs": [{"internalType": "string", "name": "", "type": "string"}], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [{"internalType": "address", "name": "owner", "type": "address"}], + "name": "nonces", + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_baseAmount", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "_minOutput", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "_minSharePrice", + "type": "uint256", + }, + { + "components": [ + { + "internalType": "address", + "name": "destination", + "type": "address", + }, + { + "internalType": "bool", + "name": "asBase", + "type": "bool", + }, + { + "internalType": "bytes", + "name": "extraData", + "type": "bytes", + }, + ], + "internalType": "struct IHyperdrive.Options", + "name": "_options", + "type": "tuple", + }, + ], + "name": "openLong", + "outputs": [ + { + "internalType": "uint256", + "name": "maturityTime", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "bondProceeds", + "type": "uint256", + }, + ], + "stateMutability": "payable", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_bondAmount", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "_maxDeposit", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "_minSharePrice", + "type": "uint256", + }, + { + "components": [ + { + "internalType": "address", + "name": "destination", + "type": "address", + }, + { + "internalType": "bool", + "name": "asBase", + "type": "bool", + }, + { + "internalType": "bytes", + "name": "extraData", + "type": "bytes", + }, + ], + "internalType": "struct IHyperdrive.Options", + "name": "_options", + "type": "tuple", + }, + ], + "name": "openShort", + "outputs": [ + { + "internalType": "uint256", + "name": "maturityTime", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "traderDeposit", + "type": "uint256", + }, + ], + "stateMutability": "payable", + "type": "function", + }, + { + "inputs": [{"internalType": "bool", "name": "_status", "type": "bool"}], + "name": "pause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256", + }, + {"internalType": "address", "name": "owner", "type": "address"}, + { + "internalType": "address", + "name": "spender", + "type": "address", + }, + ], + "name": "perTokenApprovals", + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [ + {"internalType": "address", "name": "owner", "type": "address"}, + { + "internalType": "address", + "name": "spender", + "type": "address", + }, + {"internalType": "bool", "name": "_approved", "type": "bool"}, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256", + }, + {"internalType": "uint8", "name": "v", "type": "uint8"}, + {"internalType": "bytes32", "name": "r", "type": "bytes32"}, + {"internalType": "bytes32", "name": "s", "type": "bytes32"}, + ], + "name": "permitForAll", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_shares", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "_minOutput", + "type": "uint256", + }, + { + "components": [ + { + "internalType": "address", + "name": "destination", + "type": "address", + }, + { + "internalType": "bool", + "name": "asBase", + "type": "bool", + }, + { + "internalType": "bytes", + "name": "extraData", + "type": "bytes", + }, + ], + "internalType": "struct IHyperdrive.Options", + "name": "_options", + "type": "tuple", + }, + ], + "name": "redeemWithdrawalShares", + "outputs": [ + { + "internalType": "uint256", + "name": "proceeds", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "sharesRedeemed", + "type": "uint256", + }, + ], + "stateMutability": "nonpayable", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_shares", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "_minOutput", + "type": "uint256", + }, + { + "components": [ + { + "internalType": "address", + "name": "destination", + "type": "address", + }, + { + "internalType": "bool", + "name": "asBase", + "type": "bool", + }, + { + "internalType": "bytes", + "name": "extraData", + "type": "bytes", + }, + ], + "internalType": "struct IHyperdrive.Options", + "name": "_options", + "type": "tuple", + }, + ], + "name": "removeLiquidity", + "outputs": [ + { + "internalType": "uint256", + "name": "baseProceeds", + "type": "uint256", + }, + { + "internalType": "uint256", + "name": "withdrawalShares", + "type": "uint256", + }, + ], + "stateMutability": "nonpayable", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenID", + "type": "uint256", + }, + { + "internalType": "address", + "name": "operator", + "type": "address", + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256", + }, + ], + "name": "setApproval", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenID", + "type": "uint256", + }, + { + "internalType": "address", + "name": "operator", + "type": "address", + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256", + }, + { + "internalType": "address", + "name": "caller", + "type": "address", + }, + ], + "name": "setApprovalBridge", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "address", + "name": "operator", + "type": "address", + }, + {"internalType": "bool", "name": "approved", "type": "bool"}, + ], + "name": "setApprovalForAll", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function", + }, + { + "inputs": [{"internalType": "address", "name": "_who", "type": "address"}], + "name": "setGovernance", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function", + }, + { + "inputs": [ + {"internalType": "address", "name": "_who", "type": "address"}, + {"internalType": "bool", "name": "_status", "type": "bool"}, + ], + "name": "setPauser", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function", + }, + { + "inputs": [{"internalType": "uint256", "name": "id", "type": "uint256"}], + "name": "symbol", + "outputs": [{"internalType": "string", "name": "", "type": "string"}], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [{"internalType": "uint256", "name": "id", "type": "uint256"}], + "name": "totalSupply", + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "stateMutability": "view", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenID", + "type": "uint256", + }, + {"internalType": "address", "name": "from", "type": "address"}, + {"internalType": "address", "name": "to", "type": "address"}, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256", + }, + ], + "name": "transferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function", + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenID", + "type": "uint256", + }, + {"internalType": "address", "name": "from", "type": "address"}, + {"internalType": "address", "name": "to", "type": "address"}, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256", + }, + { + "internalType": "address", + "name": "caller", + "type": "address", + }, + ], + "name": "transferFromBridge", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function", + }, + ], +) + + class IHyperdriveContract(Contract): """A web3.py Contract class for the IHyperdrive contract.""" - def __init__(self, address: ChecksumAddress | None = None, abi=Any) -> None: - self.abi = abi - # TODO: make this better, shouldn't initialize to the zero address, but the Contract's init - # function requires an address. - self.address = address if address else cast(ChecksumAddress, "0x0000000000000000000000000000000000000000") + abi: ABI = ihyperdrive_abi + def __init__(self, address: ChecksumAddress | None = None) -> None: try: # Initialize parent Contract class super().__init__(address=address) From 0c616b4ddb261b346a0c10c05d97a24b9c4beec6 Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Wed, 8 Nov 2023 12:54:17 -0800 Subject: [PATCH 13/15] Updating with new pyperdrive --- .../pypechain_types/IHyperdriveContract.py | 148 +++++++++++++----- 1 file changed, 112 insertions(+), 36 deletions(-) diff --git a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py index 6323cd3..1311949 100644 --- a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py +++ b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py @@ -1,18 +1,26 @@ """A web3.py Contract class for the IHyperdrive contract.""" + # contracts have PascalCase names # pylint: disable=invalid-name + # contracts control how many attributes and arguments we have in generated code # pylint: disable=too-many-instance-attributes # pylint: disable=too-many-arguments + # we don't need else statement if the other conditionals all have return, # but it's easier to generate # pylint: disable=no-else-return + +# This file is bound to get very long depending on contract sizes. +# pylint: disable=too-many-lines + from __future__ import annotations -from typing import Any, cast +from typing import cast from eth_typing import ChecksumAddress -from web3.contract.contract import Contract, ContractFunction, ContractFunctions +from web3.contract.contract import (Contract, ContractFunction, + ContractFunctions) from web3.exceptions import FallbackNotFound from web3.types import ABI @@ -53,7 +61,9 @@ class IHyperdriveBalanceOfContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, tokenId: int, owner: str) -> "IHyperdriveBalanceOfContractFunction": + def __call__( + self, tokenId: int, owner: str + ) -> "IHyperdriveBalanceOfContractFunction": super().__call__(tokenId, owner) return self @@ -97,7 +107,9 @@ class IHyperdriveCheckpointContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, _checkpointTime: int) -> "IHyperdriveCheckpointContractFunction": + def __call__( + self, _checkpointTime: int + ) -> "IHyperdriveCheckpointContractFunction": super().__call__(_checkpointTime) return self @@ -151,7 +163,9 @@ class IHyperdriveCollectGovernanceFeeContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, _options: tuple) -> "IHyperdriveCollectGovernanceFeeContractFunction": + def __call__( + self, _options: tuple + ) -> "IHyperdriveCollectGovernanceFeeContractFunction": super().__call__(_options) return self @@ -193,7 +207,9 @@ class IHyperdriveGetCheckpointContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, _checkpointId: int) -> "IHyperdriveGetCheckpointContractFunction": + def __call__( + self, _checkpointId: int + ) -> "IHyperdriveGetCheckpointContractFunction": super().__call__(_checkpointId) return self @@ -279,7 +295,9 @@ class IHyperdriveInitializeContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, _contribution: int, _apr: int, _options: tuple) -> "IHyperdriveInitializeContractFunction": + def __call__( + self, _contribution: int, _apr: int, _options: tuple + ) -> "IHyperdriveInitializeContractFunction": super().__call__(_contribution, _apr, _options) return self @@ -293,7 +311,9 @@ class IHyperdriveIsApprovedForAllContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, owner: str, spender: str) -> "IHyperdriveIsApprovedForAllContractFunction": + def __call__( + self, owner: str, spender: str + ) -> "IHyperdriveIsApprovedForAllContractFunction": super().__call__(owner, spender) return self @@ -417,7 +437,9 @@ class IHyperdrivePerTokenApprovalsContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, tokenId: int, owner: str, spender: str) -> "IHyperdrivePerTokenApprovalsContractFunction": + def __call__( + self, tokenId: int, owner: str, spender: str + ) -> "IHyperdrivePerTokenApprovalsContractFunction": super().__call__(tokenId, owner, spender) return self @@ -470,7 +492,9 @@ class IHyperdriveRemoveLiquidityContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, _shares: int, _minOutput: int, _options: tuple) -> "IHyperdriveRemoveLiquidityContractFunction": + def __call__( + self, _shares: int, _minOutput: int, _options: tuple + ) -> "IHyperdriveRemoveLiquidityContractFunction": super().__call__(_shares, _minOutput, _options) return self @@ -484,7 +508,9 @@ class IHyperdriveSetApprovalContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, tokenID: int, operator: str, amount: int) -> "IHyperdriveSetApprovalContractFunction": + def __call__( + self, tokenID: int, operator: str, amount: int + ) -> "IHyperdriveSetApprovalContractFunction": super().__call__(tokenID, operator, amount) return self @@ -514,7 +540,9 @@ class IHyperdriveSetApprovalForAllContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, operator: str, approved: bool) -> "IHyperdriveSetApprovalForAllContractFunction": + def __call__( + self, operator: str, approved: bool + ) -> "IHyperdriveSetApprovalForAllContractFunction": super().__call__(operator, approved) return self @@ -542,7 +570,9 @@ class IHyperdriveSetPauserContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, _who: str, _status: bool) -> "IHyperdriveSetPauserContractFunction": + def __call__( + self, _who: str, _status: bool + ) -> "IHyperdriveSetPauserContractFunction": super().__call__(_who, _status) return self @@ -584,7 +614,9 @@ class IHyperdriveTransferFromContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__(self, tokenID: int, _from: str, to: str, amount: int) -> "IHyperdriveTransferFromContractFunction": + def __call__( + self, tokenID: int, _from: str, to: str, amount: int + ) -> "IHyperdriveTransferFromContractFunction": super().__call__(tokenID, _from, to, amount) return self @@ -765,7 +797,9 @@ class IHyperdriveContractFunctions(ContractFunctions): {"inputs": [], "name": "QueryOutOfRange", "type": "error"}, {"inputs": [], "name": "RestrictedZeroAddress", "type": "error"}, { - "inputs": [{"internalType": "bytes", "name": "data", "type": "bytes"}], + "inputs": [ + {"internalType": "bytes", "name": "data", "type": "bytes"} + ], "name": "ReturnData", "type": "error", }, @@ -1255,7 +1289,9 @@ class IHyperdriveContractFunctions(ContractFunctions): { "inputs": [], "name": "DOMAIN_SEPARATOR", - "outputs": [{"internalType": "bytes32", "name": "", "type": "bytes32"}], + "outputs": [ + {"internalType": "bytes32", "name": "", "type": "bytes32"} + ], "stateMutability": "view", "type": "function", }, @@ -1320,14 +1356,18 @@ class IHyperdriveContractFunctions(ContractFunctions): {"internalType": "address", "name": "owner", "type": "address"}, ], "name": "balanceOf", - "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "outputs": [ + {"internalType": "uint256", "name": "", "type": "uint256"} + ], "stateMutability": "view", "type": "function", }, { "inputs": [], "name": "baseToken", - "outputs": [{"internalType": "address", "name": "", "type": "address"}], + "outputs": [ + {"internalType": "address", "name": "", "type": "address"} + ], "stateMutability": "view", "type": "function", }, @@ -1405,7 +1445,9 @@ class IHyperdriveContractFunctions(ContractFunctions): }, ], "name": "closeLong", - "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "outputs": [ + {"internalType": "uint256", "name": "", "type": "uint256"} + ], "stateMutability": "nonpayable", "type": "function", }, @@ -1450,7 +1492,9 @@ class IHyperdriveContractFunctions(ContractFunctions): }, ], "name": "closeShort", - "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "outputs": [ + {"internalType": "uint256", "name": "", "type": "uint256"} + ], "stateMutability": "nonpayable", "type": "function", }, @@ -1493,14 +1537,18 @@ class IHyperdriveContractFunctions(ContractFunctions): { "inputs": [], "name": "dataProvider", - "outputs": [{"internalType": "address", "name": "", "type": "address"}], + "outputs": [ + {"internalType": "address", "name": "", "type": "address"} + ], "stateMutability": "view", "type": "function", }, { "inputs": [], "name": "factory", - "outputs": [{"internalType": "address", "name": "", "type": "address"}], + "outputs": [ + {"internalType": "address", "name": "", "type": "address"} + ], "stateMutability": "view", "type": "function", }, @@ -1775,7 +1823,9 @@ class IHyperdriveContractFunctions(ContractFunctions): { "inputs": [], "name": "getUncollectedGovernanceFees", - "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "outputs": [ + {"internalType": "uint256", "name": "", "type": "uint256"} + ], "stateMutability": "view", "type": "function", }, @@ -1863,7 +1913,9 @@ class IHyperdriveContractFunctions(ContractFunctions): { "inputs": [], "name": "linkerCodeHash", - "outputs": [{"internalType": "bytes32", "name": "", "type": "bytes32"}], + "outputs": [ + {"internalType": "bytes32", "name": "", "type": "bytes32"} + ], "stateMutability": "view", "type": "function", }, @@ -1876,21 +1928,31 @@ class IHyperdriveContractFunctions(ContractFunctions): } ], "name": "load", - "outputs": [{"internalType": "bytes32[]", "name": "", "type": "bytes32[]"}], + "outputs": [ + {"internalType": "bytes32[]", "name": "", "type": "bytes32[]"} + ], "stateMutability": "view", "type": "function", }, { - "inputs": [{"internalType": "uint256", "name": "id", "type": "uint256"}], + "inputs": [ + {"internalType": "uint256", "name": "id", "type": "uint256"} + ], "name": "name", - "outputs": [{"internalType": "string", "name": "", "type": "string"}], + "outputs": [ + {"internalType": "string", "name": "", "type": "string"} + ], "stateMutability": "view", "type": "function", }, { - "inputs": [{"internalType": "address", "name": "owner", "type": "address"}], + "inputs": [ + {"internalType": "address", "name": "owner", "type": "address"} + ], "name": "nonces", - "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "outputs": [ + {"internalType": "uint256", "name": "", "type": "uint256"} + ], "stateMutability": "view", "type": "function", }, @@ -2007,7 +2069,9 @@ class IHyperdriveContractFunctions(ContractFunctions): "type": "function", }, { - "inputs": [{"internalType": "bool", "name": "_status", "type": "bool"}], + "inputs": [ + {"internalType": "bool", "name": "_status", "type": "bool"} + ], "name": "pause", "outputs": [], "stateMutability": "nonpayable", @@ -2028,7 +2092,9 @@ class IHyperdriveContractFunctions(ContractFunctions): }, ], "name": "perTokenApprovals", - "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "outputs": [ + {"internalType": "uint256", "name": "", "type": "uint256"} + ], "stateMutability": "view", "type": "function", }, @@ -2223,7 +2289,9 @@ class IHyperdriveContractFunctions(ContractFunctions): "type": "function", }, { - "inputs": [{"internalType": "address", "name": "_who", "type": "address"}], + "inputs": [ + {"internalType": "address", "name": "_who", "type": "address"} + ], "name": "setGovernance", "outputs": [], "stateMutability": "nonpayable", @@ -2240,16 +2308,24 @@ class IHyperdriveContractFunctions(ContractFunctions): "type": "function", }, { - "inputs": [{"internalType": "uint256", "name": "id", "type": "uint256"}], + "inputs": [ + {"internalType": "uint256", "name": "id", "type": "uint256"} + ], "name": "symbol", - "outputs": [{"internalType": "string", "name": "", "type": "string"}], + "outputs": [ + {"internalType": "string", "name": "", "type": "string"} + ], "stateMutability": "view", "type": "function", }, { - "inputs": [{"internalType": "uint256", "name": "id", "type": "uint256"}], + "inputs": [ + {"internalType": "uint256", "name": "id", "type": "uint256"} + ], "name": "totalSupply", - "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "outputs": [ + {"internalType": "uint256", "name": "", "type": "uint256"} + ], "stateMutability": "view", "type": "function", }, From 678af438522bedc717817f468093684006ed743e Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Wed, 8 Nov 2023 13:16:19 -0800 Subject: [PATCH 14/15] reformat --- .../pypechain_types/IHyperdriveContract.py | 136 +++++------------- 1 file changed, 34 insertions(+), 102 deletions(-) diff --git a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py index 1311949..67a1183 100644 --- a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py +++ b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py @@ -61,9 +61,7 @@ class IHyperdriveBalanceOfContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, tokenId: int, owner: str - ) -> "IHyperdriveBalanceOfContractFunction": + def __call__(self, tokenId: int, owner: str) -> "IHyperdriveBalanceOfContractFunction": super().__call__(tokenId, owner) return self @@ -107,9 +105,7 @@ class IHyperdriveCheckpointContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, _checkpointTime: int - ) -> "IHyperdriveCheckpointContractFunction": + def __call__(self, _checkpointTime: int) -> "IHyperdriveCheckpointContractFunction": super().__call__(_checkpointTime) return self @@ -163,9 +159,7 @@ class IHyperdriveCollectGovernanceFeeContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, _options: tuple - ) -> "IHyperdriveCollectGovernanceFeeContractFunction": + def __call__(self, _options: tuple) -> "IHyperdriveCollectGovernanceFeeContractFunction": super().__call__(_options) return self @@ -207,9 +201,7 @@ class IHyperdriveGetCheckpointContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, _checkpointId: int - ) -> "IHyperdriveGetCheckpointContractFunction": + def __call__(self, _checkpointId: int) -> "IHyperdriveGetCheckpointContractFunction": super().__call__(_checkpointId) return self @@ -295,9 +287,7 @@ class IHyperdriveInitializeContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, _contribution: int, _apr: int, _options: tuple - ) -> "IHyperdriveInitializeContractFunction": + def __call__(self, _contribution: int, _apr: int, _options: tuple) -> "IHyperdriveInitializeContractFunction": super().__call__(_contribution, _apr, _options) return self @@ -311,9 +301,7 @@ class IHyperdriveIsApprovedForAllContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, owner: str, spender: str - ) -> "IHyperdriveIsApprovedForAllContractFunction": + def __call__(self, owner: str, spender: str) -> "IHyperdriveIsApprovedForAllContractFunction": super().__call__(owner, spender) return self @@ -437,9 +425,7 @@ class IHyperdrivePerTokenApprovalsContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, tokenId: int, owner: str, spender: str - ) -> "IHyperdrivePerTokenApprovalsContractFunction": + def __call__(self, tokenId: int, owner: str, spender: str) -> "IHyperdrivePerTokenApprovalsContractFunction": super().__call__(tokenId, owner, spender) return self @@ -492,9 +478,7 @@ class IHyperdriveRemoveLiquidityContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, _shares: int, _minOutput: int, _options: tuple - ) -> "IHyperdriveRemoveLiquidityContractFunction": + def __call__(self, _shares: int, _minOutput: int, _options: tuple) -> "IHyperdriveRemoveLiquidityContractFunction": super().__call__(_shares, _minOutput, _options) return self @@ -508,9 +492,7 @@ class IHyperdriveSetApprovalContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, tokenID: int, operator: str, amount: int - ) -> "IHyperdriveSetApprovalContractFunction": + def __call__(self, tokenID: int, operator: str, amount: int) -> "IHyperdriveSetApprovalContractFunction": super().__call__(tokenID, operator, amount) return self @@ -540,9 +522,7 @@ class IHyperdriveSetApprovalForAllContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, operator: str, approved: bool - ) -> "IHyperdriveSetApprovalForAllContractFunction": + def __call__(self, operator: str, approved: bool) -> "IHyperdriveSetApprovalForAllContractFunction": super().__call__(operator, approved) return self @@ -570,9 +550,7 @@ class IHyperdriveSetPauserContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, _who: str, _status: bool - ) -> "IHyperdriveSetPauserContractFunction": + def __call__(self, _who: str, _status: bool) -> "IHyperdriveSetPauserContractFunction": super().__call__(_who, _status) return self @@ -614,9 +592,7 @@ class IHyperdriveTransferFromContractFunction(ContractFunction): # super() call methods are generic, while our version adds values & types # pylint: disable=arguments-differ - def __call__( - self, tokenID: int, _from: str, to: str, amount: int - ) -> "IHyperdriveTransferFromContractFunction": + def __call__(self, tokenID: int, _from: str, to: str, amount: int) -> "IHyperdriveTransferFromContractFunction": super().__call__(tokenID, _from, to, amount) return self @@ -797,9 +773,7 @@ class IHyperdriveContractFunctions(ContractFunctions): {"inputs": [], "name": "QueryOutOfRange", "type": "error"}, {"inputs": [], "name": "RestrictedZeroAddress", "type": "error"}, { - "inputs": [ - {"internalType": "bytes", "name": "data", "type": "bytes"} - ], + "inputs": [{"internalType": "bytes", "name": "data", "type": "bytes"}], "name": "ReturnData", "type": "error", }, @@ -1289,9 +1263,7 @@ class IHyperdriveContractFunctions(ContractFunctions): { "inputs": [], "name": "DOMAIN_SEPARATOR", - "outputs": [ - {"internalType": "bytes32", "name": "", "type": "bytes32"} - ], + "outputs": [{"internalType": "bytes32", "name": "", "type": "bytes32"}], "stateMutability": "view", "type": "function", }, @@ -1356,18 +1328,14 @@ class IHyperdriveContractFunctions(ContractFunctions): {"internalType": "address", "name": "owner", "type": "address"}, ], "name": "balanceOf", - "outputs": [ - {"internalType": "uint256", "name": "", "type": "uint256"} - ], + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "stateMutability": "view", "type": "function", }, { "inputs": [], "name": "baseToken", - "outputs": [ - {"internalType": "address", "name": "", "type": "address"} - ], + "outputs": [{"internalType": "address", "name": "", "type": "address"}], "stateMutability": "view", "type": "function", }, @@ -1445,9 +1413,7 @@ class IHyperdriveContractFunctions(ContractFunctions): }, ], "name": "closeLong", - "outputs": [ - {"internalType": "uint256", "name": "", "type": "uint256"} - ], + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "stateMutability": "nonpayable", "type": "function", }, @@ -1492,9 +1458,7 @@ class IHyperdriveContractFunctions(ContractFunctions): }, ], "name": "closeShort", - "outputs": [ - {"internalType": "uint256", "name": "", "type": "uint256"} - ], + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "stateMutability": "nonpayable", "type": "function", }, @@ -1537,18 +1501,14 @@ class IHyperdriveContractFunctions(ContractFunctions): { "inputs": [], "name": "dataProvider", - "outputs": [ - {"internalType": "address", "name": "", "type": "address"} - ], + "outputs": [{"internalType": "address", "name": "", "type": "address"}], "stateMutability": "view", "type": "function", }, { "inputs": [], "name": "factory", - "outputs": [ - {"internalType": "address", "name": "", "type": "address"} - ], + "outputs": [{"internalType": "address", "name": "", "type": "address"}], "stateMutability": "view", "type": "function", }, @@ -1823,9 +1783,7 @@ class IHyperdriveContractFunctions(ContractFunctions): { "inputs": [], "name": "getUncollectedGovernanceFees", - "outputs": [ - {"internalType": "uint256", "name": "", "type": "uint256"} - ], + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "stateMutability": "view", "type": "function", }, @@ -1913,9 +1871,7 @@ class IHyperdriveContractFunctions(ContractFunctions): { "inputs": [], "name": "linkerCodeHash", - "outputs": [ - {"internalType": "bytes32", "name": "", "type": "bytes32"} - ], + "outputs": [{"internalType": "bytes32", "name": "", "type": "bytes32"}], "stateMutability": "view", "type": "function", }, @@ -1928,31 +1884,21 @@ class IHyperdriveContractFunctions(ContractFunctions): } ], "name": "load", - "outputs": [ - {"internalType": "bytes32[]", "name": "", "type": "bytes32[]"} - ], + "outputs": [{"internalType": "bytes32[]", "name": "", "type": "bytes32[]"}], "stateMutability": "view", "type": "function", }, { - "inputs": [ - {"internalType": "uint256", "name": "id", "type": "uint256"} - ], + "inputs": [{"internalType": "uint256", "name": "id", "type": "uint256"}], "name": "name", - "outputs": [ - {"internalType": "string", "name": "", "type": "string"} - ], + "outputs": [{"internalType": "string", "name": "", "type": "string"}], "stateMutability": "view", "type": "function", }, { - "inputs": [ - {"internalType": "address", "name": "owner", "type": "address"} - ], + "inputs": [{"internalType": "address", "name": "owner", "type": "address"}], "name": "nonces", - "outputs": [ - {"internalType": "uint256", "name": "", "type": "uint256"} - ], + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "stateMutability": "view", "type": "function", }, @@ -2069,9 +2015,7 @@ class IHyperdriveContractFunctions(ContractFunctions): "type": "function", }, { - "inputs": [ - {"internalType": "bool", "name": "_status", "type": "bool"} - ], + "inputs": [{"internalType": "bool", "name": "_status", "type": "bool"}], "name": "pause", "outputs": [], "stateMutability": "nonpayable", @@ -2092,9 +2036,7 @@ class IHyperdriveContractFunctions(ContractFunctions): }, ], "name": "perTokenApprovals", - "outputs": [ - {"internalType": "uint256", "name": "", "type": "uint256"} - ], + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "stateMutability": "view", "type": "function", }, @@ -2289,9 +2231,7 @@ class IHyperdriveContractFunctions(ContractFunctions): "type": "function", }, { - "inputs": [ - {"internalType": "address", "name": "_who", "type": "address"} - ], + "inputs": [{"internalType": "address", "name": "_who", "type": "address"}], "name": "setGovernance", "outputs": [], "stateMutability": "nonpayable", @@ -2308,24 +2248,16 @@ class IHyperdriveContractFunctions(ContractFunctions): "type": "function", }, { - "inputs": [ - {"internalType": "uint256", "name": "id", "type": "uint256"} - ], + "inputs": [{"internalType": "uint256", "name": "id", "type": "uint256"}], "name": "symbol", - "outputs": [ - {"internalType": "string", "name": "", "type": "string"} - ], + "outputs": [{"internalType": "string", "name": "", "type": "string"}], "stateMutability": "view", "type": "function", }, { - "inputs": [ - {"internalType": "uint256", "name": "id", "type": "uint256"} - ], + "inputs": [{"internalType": "uint256", "name": "id", "type": "uint256"}], "name": "totalSupply", - "outputs": [ - {"internalType": "uint256", "name": "", "type": "uint256"} - ], + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "stateMutability": "view", "type": "function", }, From 01caea82682f6ae2fa753bb827fde71a36e1338a Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Wed, 8 Nov 2023 13:28:16 -0800 Subject: [PATCH 15/15] Black --- .../python/pyperdrive/pypechain_types/IHyperdriveContract.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py index 67a1183..deea5c8 100644 --- a/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py +++ b/crates/pyperdrive/python/pyperdrive/pypechain_types/IHyperdriveContract.py @@ -19,8 +19,7 @@ from typing import cast from eth_typing import ChecksumAddress -from web3.contract.contract import (Contract, ContractFunction, - ContractFunctions) +from web3.contract.contract import Contract, ContractFunction, ContractFunctions from web3.exceptions import FallbackNotFound from web3.types import ABI