Skip to content

Commit 96251a8

Browse files
committed
"insufficient collateral" error bugfix
1 parent 27a2fd5 commit 96251a8

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

alpha_homora_v2/position.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def sign_and_send(self, function_call: ContractFunction):
172172

173173
return tx_hash.hex(), receipt
174174

175-
def decode_transaction_data(self, w3_provider: Web3, transaction_address: Optional) -> tuple:
175+
def decode_transaction_data(self, transaction_address: Optional) -> tuple:
176176
"""
177177
Returns the transaction data used to invoke the smart contract function for the underlying contract
178178
@@ -186,7 +186,7 @@ def decode_transaction_data(self, w3_provider: Web3, transaction_address: Option
186186
decoded spell function (ContractFunction, dict)
187187
)
188188
"""
189-
transaction = w3_provider.eth.get_transaction(transaction_address)
189+
transaction = self.w3_provider.eth.get_transaction(transaction_address)
190190

191191
decoded_bank_transaction = self.homora_bank.decode_function_input(transaction.input)
192192

alpha_homora_v2/spell.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,26 @@ def prepare_close_position(self, underlying_tokens: list[tuple], position_size:
6060
amtLPTake = position_size # int(MAX_INT, 16)
6161
amtLPWithdraw = 0 # int(MAX_INT, 16)
6262
amtARepay = underlying_tokens[0][1]
63+
if amtARepay > 0:
64+
amtARepay = int(MAX_INT, 16)
65+
6366
amtBRepay = underlying_tokens[1][1]
67+
if amtBRepay > 0:
68+
amtBRepay = int(MAX_INT, 16)
6469

6570
# Slippage controls (Minimum amount allowed after final transaction) 0 = No slippage controls
6671
amtAMin = 0
6772
amtBMin = 0
73+
74+
print("Attempting to close position with following parameters:\n"
75+
"removeLiquidityWMasterChef\n"
76+
f"Underlying Tokens: {underlying_tokens}\n"
77+
f"amtLPTake: {amtLPTake}\n"
78+
f"amtLPWithdraw: {amtLPWithdraw}\n"
79+
f"amtARepay: {amtARepay}\n"
80+
f"amtBRepay: {amtBRepay}\n"
81+
f"amtAMin: {amtAMin}\n"
82+
f"amtBMin: {amtBMin}")
6883

6984
return self.contract.encodeABI(fn_name='removeLiquidityWMasterChef',
7085
args=[underlying_tokens[0][0], underlying_tokens[1][0],
@@ -85,12 +100,27 @@ def prepare_close_position(self, underlying_tokens: list[tuple], position_size:
85100
amtLPTake = position_size # int(MAX_INT, 16)
86101
amtLPWithdraw = 0 # int(MAX_INT, 16)
87102
amtARepay = underlying_tokens[0][1]
103+
if amtARepay > 0:
104+
amtARepay = int(MAX_INT, 16)
105+
88106
amtBRepay = underlying_tokens[1][1]
107+
if amtBRepay > 0:
108+
amtBRepay = int(MAX_INT, 16)
89109

90110
# Slippage controls (Minimum amount allowed after final transaction) 0 = No slippage controls
91111
amtAMin = 0
92112
amtBMin = 0
93113

114+
print("Attempting to close position with following parameters:\n"
115+
"removeLiquidityWMiniChef\n"
116+
f"Underlying Tokens: {underlying_tokens}\n"
117+
f"amtLPTake: {amtLPTake}\n"
118+
f"amtLPWithdraw: {amtLPWithdraw}\n"
119+
f"amtARepay: {amtARepay}\n"
120+
f"amtBRepay: {amtBRepay}\n"
121+
f"amtAMin: {amtAMin}\n"
122+
f"amtBMin: {amtBMin}")
123+
94124
return self.contract.encodeABI(fn_name='removeLiquidityWMiniChef',
95125
args=[underlying_tokens[0][0], underlying_tokens[1][0],
96126
(amtLPTake, amtLPWithdraw, amtARepay, amtBRepay, amtLPRepay, amtAMin, amtBMin)])

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name='alpha_homora_v2',
6-
version='0.0.2',
6+
version='0.0.3',
77
author='Harrison Schick',
88
author_email='hschickdevs@gmail.com',
99
description='Python package that allows for interacting with Alpha Homora v2 position smart contracts',

0 commit comments

Comments
 (0)