web3-wizzard-lib 1.6.14__py3-none-any.whl → 1.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ from sybil_engine.contract.contract import Contract
2
+ from sybil_engine.utils.file_loader import load_abi
3
+
4
+ abi = load_abi("resources/abi/compound_v3.json")
5
+
6
+
7
+ class CompoundV3Contract(Contract):
8
+ def __init__(self, contract_address, web3):
9
+ super().__init__(contract_address, web3, abi)
10
+
11
+ def user_collateral(self, account, token_address):
12
+ return self.contract.functions.userCollateral(
13
+ account.address,
14
+ token_address
15
+ ).call()[0]
@@ -0,0 +1,39 @@
1
+ from sybil_engine.contract.contract import Contract
2
+ from sybil_engine.contract.transaction_executor import evm_transaction
3
+ from sybil_engine.utils.file_loader import load_abi
4
+ from web3_wizzard_lib.core.contract.horizondex_router import decimal_to_padded_hexadecimal
5
+
6
+ abi = load_abi("resources/abi/compound_v3_bulker.json")
7
+
8
+
9
+ class CompoundV3BulkerContract(Contract):
10
+ def __init__(self, contract_address, web3):
11
+ super().__init__(contract_address, web3, abi)
12
+
13
+ @evm_transaction
14
+ def invoke(self, account, amount, actions):
15
+ hex_amount = decimal_to_padded_hexadecimal(amount, 32)
16
+ data = f'0x000000000000000000000000b2f97c1bd3bf02f5e74d13f02e3e26f93d77ce44000000000000000000000000ef0f48dadd0abe4f99b4c14862df303ba956bd1300000000000000000000000000000000{hex_amount}'
17
+
18
+ return self.contract.functions.invoke(
19
+ [hex_to_bytes(actions)],
20
+ [hex_to_bytes(data)]
21
+ ).build_transaction(self.build_generic_data(account.address, False))
22
+
23
+
24
+ def hex_to_bytes(hex_string):
25
+ """
26
+ Convert a hexadecimal string to bytes.
27
+
28
+ Args:
29
+ hex_string (str): The hexadecimal string, with or without '0x' prefix
30
+
31
+ Returns:
32
+ bytes: The converted bytes object
33
+ """
34
+ # Remove '0x' prefix if it exists
35
+ if hex_string.startswith('0x'):
36
+ hex_string = hex_string[2:]
37
+
38
+ # Convert hex string to bytes
39
+ return bytes.fromhex(hex_string)
@@ -0,0 +1,35 @@
1
+ from sybil_engine.data.contracts import get_contracts_for_chain
2
+ from sybil_engine.data.networks import get_ids_chain
3
+ from sybil_engine.data.tokens import get_tokens_for_chain
4
+ from sybil_engine.utils.utils import ConfigurationException
5
+
6
+ from web3_wizzard_lib.core.contract.compound_v3 import CompoundV3Contract
7
+ from web3_wizzard_lib.core.contract.compund_v3_bulker import CompoundV3BulkerContract
8
+ from web3_wizzard_lib.core.modules.bank.bank import Bank
9
+
10
+
11
+ class CompoundV3(Bank):
12
+ app_name = 'COMPOUND_V3'
13
+ supported_chains = ['SCROLL']
14
+
15
+ def __init__(self, chain, web3):
16
+ compound_v3_address = get_contracts_for_chain(chain)[self.app_name]
17
+ self.contract = CompoundV3Contract(compound_v3_address, web3)
18
+ compound_v3_bulker_address = get_contracts_for_chain(chain)['COMPOUND_V3_BULKER']
19
+ self.contract_bulker = CompoundV3BulkerContract(compound_v3_bulker_address, web3)
20
+
21
+ def supply(self, account, amount):
22
+ raise ConfigurationException("Only redeem supported for Compound V3")
23
+
24
+ def redeem(self, account, amount, token):
25
+ redeem_action = '0x414354494f4e5f57495448445241575f4e41544956455f544f4b454e00000000'
26
+ self.contract_bulker.invoke(account, amount, redeem_action)
27
+
28
+ def get_deposit_amount(self, account, token):
29
+ token_address = get_tokens_for_chain(get_ids_chain()[self.contract.web3.eth.chain_id])[token]
30
+ compound_v3 = get_contracts_for_chain(get_ids_chain()[self.contract.web3.eth.chain_id])[self.app_name]
31
+
32
+ return CompoundV3Contract(compound_v3, self.contract.web3).user_collateral(
33
+ account,
34
+ token_address
35
+ )
@@ -9,6 +9,7 @@ from sybil_engine.utils.utils import ConfigurationException
9
9
  from sybil_engine.utils.web3_utils import init_web3
10
10
 
11
11
  from web3_wizzard_lib.core.modules.bank.basilisk import Basilisk
12
+ from web3_wizzard_lib.core.modules.bank.compound_v3 import CompoundV3
12
13
  from web3_wizzard_lib.core.modules.bank.eralend import Eralend
13
14
  from web3_wizzard_lib.core.modules.bank.layerbank import LayerBank
14
15
  from web3_wizzard_lib.core.modules.bank.mendi_finance import MendiFinance
@@ -80,7 +81,8 @@ class Banking(Module):
80
81
  MendiFinance,
81
82
  LayerBank,
82
83
  Aave,
83
- ZeroLend
84
+ ZeroLend,
85
+ CompoundV3
84
86
  }
85
87
 
86
88
  def log(self):