web3-wizzard-lib 1.7.1__py3-none-any.whl → 1.9.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.
- web3_wizzard_lib/core/contract/cog_erc20.py +47 -0
- web3_wizzard_lib/core/contract/compound_v3.py +13 -0
- web3_wizzard_lib/core/modules/bank/bank.py +3 -0
- web3_wizzard_lib/core/modules/bank/cog_bank.py +23 -0
- web3_wizzard_lib/core/modules/bank/compound_v3.py +16 -4
- web3_wizzard_lib/core/modules/bank_module.py +12 -5
- web3_wizzard_lib/resources/abi/cog_erc20.json +1263 -0
- web3_wizzard_lib/resources/main/contracts.json +2 -1
- {web3_wizzard_lib-1.7.1.dist-info → web3_wizzard_lib-1.9.0.dist-info}/METADATA +1 -1
- {web3_wizzard_lib-1.7.1.dist-info → web3_wizzard_lib-1.9.0.dist-info}/RECORD +12 -9
- {web3_wizzard_lib-1.7.1.dist-info → web3_wizzard_lib-1.9.0.dist-info}/WHEEL +0 -0
- {web3_wizzard_lib-1.7.1.dist-info → web3_wizzard_lib-1.9.0.dist-info}/top_level.txt +0 -0
@@ -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()
|
@@ -1,4 +1,5 @@
|
|
1
1
|
from sybil_engine.contract.contract import Contract
|
2
|
+
from sybil_engine.contract.transaction_executor import evm_transaction
|
2
3
|
from sybil_engine.utils.file_loader import load_abi
|
3
4
|
|
4
5
|
abi = load_abi("resources/abi/compound_v3.json")
|
@@ -8,6 +9,18 @@ class CompoundV3Contract(Contract):
|
|
8
9
|
def __init__(self, contract_address, web3):
|
9
10
|
super().__init__(contract_address, web3, abi)
|
10
11
|
|
12
|
+
def borrow_balance_of(self, account):
|
13
|
+
return self.contract.functions.borrowBalanceOf(account.address).call()
|
14
|
+
|
15
|
+
@evm_transaction
|
16
|
+
def supply(self, account, amount, token_address):
|
17
|
+
txn_params = self.build_generic_data(account.address, set_contract_address=False)
|
18
|
+
|
19
|
+
return self.contract.functions.supply(
|
20
|
+
token_address,
|
21
|
+
amount
|
22
|
+
).build_transaction(txn_params)
|
23
|
+
|
11
24
|
def user_collateral(self, account, token_address):
|
12
25
|
return self.contract.functions.userCollateral(
|
13
26
|
account.address,
|
@@ -0,0 +1,23 @@
|
|
1
|
+
from sybil_engine.data.contracts import get_contracts_for_chain
|
2
|
+
from sybil_engine.utils.utils import ConfigurationException
|
3
|
+
|
4
|
+
from web3_wizzard_lib.core.contract.cog_erc20 import CogErc20Contract
|
5
|
+
from web3_wizzard_lib.core.modules.bank.bank import Bank
|
6
|
+
|
7
|
+
|
8
|
+
class Cog(Bank):
|
9
|
+
app_name = 'COG_USDC'
|
10
|
+
supported_chains = ['SCROLL']
|
11
|
+
|
12
|
+
def __init__(self, chain, web3):
|
13
|
+
self.contract_address = get_contracts_for_chain(chain)[self.app_name]
|
14
|
+
self.contract = CogErc20Contract(self.contract_address, web3)
|
15
|
+
|
16
|
+
def supply(self, account, amount):
|
17
|
+
raise ConfigurationException("Only redeem supported for Compound V3")
|
18
|
+
|
19
|
+
def redeem(self, account, amount, token):
|
20
|
+
self.contract.redeem(account, amount)
|
21
|
+
|
22
|
+
def get_deposit_amount(self, account, token):
|
23
|
+
return self.contract.balance_of(account)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
from sybil_engine.data.contracts import get_contracts_for_chain
|
2
2
|
from sybil_engine.data.networks import get_ids_chain
|
3
3
|
from sybil_engine.data.tokens import get_tokens_for_chain
|
4
|
+
from sybil_engine.domain.balance.tokens import Erc20Token
|
4
5
|
from sybil_engine.utils.utils import ConfigurationException
|
5
6
|
|
6
7
|
from web3_wizzard_lib.core.contract.compound_v3 import CompoundV3Contract
|
@@ -21,15 +22,26 @@ class CompoundV3(Bank):
|
|
21
22
|
def supply(self, account, amount):
|
22
23
|
raise ConfigurationException("Only redeem supported for Compound V3")
|
23
24
|
|
25
|
+
def get_repay_borrow_amount(self, account):
|
26
|
+
return self.contract.borrow_balance_of(account)
|
27
|
+
|
28
|
+
def repay_borrow(self, account, amount):
|
29
|
+
erc20_token = Erc20Token(self.contract.chain_instance['chain'], "USDC", self.contract.web3)
|
30
|
+
|
31
|
+
if erc20_token.allowance(account, self.contract.contract_address) < 100:
|
32
|
+
erc20_token.approve(account, self.contract.contract_address)
|
33
|
+
|
34
|
+
return self.contract.supply(account, amount, erc20_token.erc20_contract.contract_address)
|
35
|
+
|
24
36
|
def redeem(self, account, amount, token):
|
25
|
-
|
26
|
-
self.contract_bulker.invoke(account, amount,
|
37
|
+
actions = '0x414354494f4e5f57495448445241575f41535345540000000000000000000000'
|
38
|
+
self.contract_bulker.invoke(account, amount, actions)
|
27
39
|
|
28
40
|
def get_deposit_amount(self, account, token):
|
29
41
|
token_address = get_tokens_for_chain(get_ids_chain()[self.contract.web3.eth.chain_id])[token]
|
30
|
-
|
42
|
+
compound_v3_address = get_contracts_for_chain(get_ids_chain()[self.contract.web3.eth.chain_id])[self.app_name]
|
31
43
|
|
32
|
-
return CompoundV3Contract(
|
44
|
+
return CompoundV3Contract(compound_v3_address, self.contract.web3).user_collateral(
|
33
45
|
account,
|
34
46
|
token_address
|
35
47
|
)
|
@@ -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,18 +39,23 @@ 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':
|
50
50
|
bank_app.borrow(account, amount)
|
51
51
|
elif action == 'REPAY':
|
52
|
-
bank_app.
|
52
|
+
amount = bank_app.get_repay_borrow_amount(account)
|
53
|
+
|
54
|
+
if amount > 0:
|
55
|
+
logger.info(f"Repay {amount} {token} in {bank_app.app_name}")
|
56
|
+
bank_app.repay_borrow(account, amount)
|
57
|
+
else:
|
58
|
+
logger.info(f"{token} borrow balance is 0")
|
53
59
|
elif action == 'REDEEM':
|
54
60
|
amount = bank_app.get_deposit_amount(account, token)
|
55
61
|
|
@@ -57,7 +63,7 @@ class Banking(Module):
|
|
57
63
|
logger.info(f"Redeem {amount} of {token} from {bank_app.app_name}")
|
58
64
|
bank_app.redeem(account, amount, token)
|
59
65
|
else:
|
60
|
-
logger.info(f"{
|
66
|
+
logger.info(f"{token} balance is 0")
|
61
67
|
else:
|
62
68
|
raise ConfigurationException("Unsupported action")
|
63
69
|
|
@@ -85,7 +91,8 @@ class Banking(Module):
|
|
85
91
|
LayerBank,
|
86
92
|
Aave,
|
87
93
|
ZeroLend,
|
88
|
-
CompoundV3
|
94
|
+
CompoundV3,
|
95
|
+
Cog
|
89
96
|
}
|
90
97
|
|
91
98
|
def log(self):
|