web3-wizzard-lib 1.7.0__py3-none-any.whl → 1.8.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,47 @@
1
+ from loguru import logger
2
+ from web3 import Web3
3
+
4
+ from sybil_engine.contract.contract import Contract
5
+ from sybil_engine.contract.transaction_executor import evm_transaction
6
+ from sybil_engine.utils.file_loader import load_abi
7
+
8
+ abi = load_abi("resources/abi/cog_erc20.json")
9
+
10
+ MAX_ALLOWANCE = 115792089237316195423570985008687907853269984665640564039457584007913129639935
11
+
12
+
13
+ class CogErc20Contract(Contract):
14
+ def __init__(self, contract_address, web3):
15
+ super().__init__(contract_address, web3, abi)
16
+
17
+ @evm_transaction
18
+ def approve(self, account, contract_on_approve):
19
+ logger.info(f"Approving token")
20
+
21
+ txn_params = self.build_generic_data(account.address, set_contract_address=False)
22
+
23
+ return self.contract.functions.approve(
24
+ Web3.to_checksum_address(contract_on_approve),
25
+ MAX_ALLOWANCE
26
+ ).build_transaction(txn_params)
27
+
28
+ @evm_transaction
29
+ def redeem(self, account, amount):
30
+ txn_params = self.build_generic_data(account.address, set_contract_address=False)
31
+
32
+ return self.contract.functions.redeem(amount).build_transaction(txn_params)
33
+
34
+ def balance_of(self, account):
35
+ return self.contract.functions.balanceOf(account.address).call()
36
+
37
+ def max_redeem(self, account):
38
+ return self.contract.functions.maxRedeem(account.address).call()
39
+
40
+ def allowance(self, account, allowance_contract):
41
+ return self.contract.functions.allowance(account.address, Web3.to_checksum_address(allowance_contract)).call()
42
+
43
+ def decimals(self):
44
+ return self.contract.functions.decimals().call()
45
+
46
+ def symbol(self):
47
+ return self.contract.functions.symbol().call()
@@ -0,0 +1,26 @@
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.utils.utils import ConfigurationException
4
+
5
+ from web3_wizzard_lib.core.contract.cog_erc20 import CogErc20Contract
6
+ from web3_wizzard_lib.core.modules.bank.bank import Bank
7
+
8
+
9
+ class Cog(Bank):
10
+ app_name = 'COG_USDC'
11
+ supported_chains = ['SCROLL']
12
+
13
+ def __init__(self, chain, web3):
14
+ contract_address = get_contracts_for_chain(chain)[self.app_name]
15
+ self.contract = CogErc20Contract(contract_address, web3)
16
+
17
+ def supply(self, account, amount):
18
+ raise ConfigurationException("Only redeem supported for Compound V3")
19
+
20
+ def redeem(self, account, amount, token):
21
+ self.contract.redeem(account, amount)
22
+
23
+ def get_deposit_amount(self, account, token):
24
+ cog_usdc_token = get_contracts_for_chain(get_ids_chain()[self.contract.web3.eth.chain_id])['COG_USDC']
25
+
26
+ return CogErc20Contract(cog_usdc_token, self.contract.web3).balance_of(account)
@@ -22,14 +22,13 @@ class CompoundV3(Bank):
22
22
  raise ConfigurationException("Only redeem supported for Compound V3")
23
23
 
24
24
  def redeem(self, account, amount, token):
25
- redeem_action = '0x414354494f4e5f57495448445241575f4e41544956455f544f4b454e00000000'
26
- self.contract_bulker.invoke(account, amount, redeem_action)
25
+ self.contract_bulker.invoke(account, amount)
27
26
 
28
27
  def get_deposit_amount(self, account, token):
29
28
  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]
29
+ compound_v3_address = get_contracts_for_chain(get_ids_chain()[self.contract.web3.eth.chain_id])[self.app_name]
31
30
 
32
- return CompoundV3Contract(compound_v3, self.contract.web3).user_collateral(
31
+ return CompoundV3Contract(compound_v3_address, self.contract.web3).user_collateral(
33
32
  account,
34
33
  token_address
35
34
  )
@@ -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.cog_bank import Cog
12
13
  from web3_wizzard_lib.core.modules.bank.compound_v3 import CompoundV3
13
14
  from web3_wizzard_lib.core.modules.bank.eralend import Eralend
14
15
  from web3_wizzard_lib.core.modules.bank.layerbank import LayerBank
@@ -38,12 +39,11 @@ class Banking(Module):
38
39
 
39
40
  bank_app = self.get_bank_app(bank_app_name, chain, web3)
40
41
 
41
- logger.info(f"{bank_app.app_name}")
42
+ logger.info(f"{bank_app.app_name} | {action}")
42
43
 
43
44
  self.perform_action(bank_app, action, amount, token, account)
44
45
 
45
46
  def perform_action(self, bank_app, action, amount, token, account):
46
- logger.info(action)
47
47
  if action == 'SUPPLY':
48
48
  bank_app.supply(account, amount)
49
49
  elif action == 'BORROW':
@@ -52,9 +52,12 @@ class Banking(Module):
52
52
  bank_app.repay_borrow(account, amount)
53
53
  elif action == 'REDEEM':
54
54
  amount = bank_app.get_deposit_amount(account, token)
55
- logger.info(f"Redeem {amount} of {token} from {bank_app.app_name}")
56
55
 
57
- bank_app.redeem(account, amount, token)
56
+ if amount > 0:
57
+ logger.info(f"Redeem {amount} of {token} from {bank_app.app_name}")
58
+ bank_app.redeem(account, amount, token)
59
+ else:
60
+ logger.info(f"{account.address} does not have {token}")
58
61
  else:
59
62
  raise ConfigurationException("Unsupported action")
60
63
 
@@ -82,7 +85,8 @@ class Banking(Module):
82
85
  LayerBank,
83
86
  Aave,
84
87
  ZeroLend,
85
- CompoundV3
88
+ CompoundV3,
89
+ Cog
86
90
  }
87
91
 
88
92
  def log(self):