1212from web3 import Web3
1313from web3 .contract import Contract
1414from web3 .types import TxParams
15+ from flare_ai_defai .storage .fake_storage import WalletStore
1516
1617from flare_ai_defai .models import UserInfo
1718
@@ -106,7 +107,7 @@ class KineticMarket:
106107 "type" : "function"
107108 },]
108109
109- def __init__ (self , web3_provider_url : str , flare_explorer : FlareExplorer , flare_provider : FlareProvider ) -> None :
110+ def __init__ (self , web3_provider_url : str , flare_explorer : FlareExplorer , flare_provider : FlareProvider , wallet_store : WalletStore ) -> None :
110111 """
111112 Args:
112113 web3_provider_url (str): URL of the Web3 provider endpoint
@@ -118,6 +119,7 @@ def __init__(self, web3_provider_url: str, flare_explorer: FlareExplorer, flare_
118119 self .web3_provider_url = web3_provider_url
119120 self .flare_explorer = flare_explorer
120121 self .flare_provider = flare_provider
122+ self .wallet_store = wallet_store
121123
122124 #self.supplySFLRwithFLR(user, 1)
123125
@@ -199,7 +201,7 @@ def supplySFLRwithFLR(self,user:UserInfo, amount: float):
199201
200202 return tx_hashes
201203
202- def swapFLRtoSFLR (self , amount : float , spender : str = None ):
204+ def swapFLRtoSFLR (self , user : UserInfo , amount : float ):
203205 if not self .w3 .is_connected ():
204206 raise Exception ("Not connected to Flare blockchain" )
205207
@@ -214,24 +216,19 @@ def swapFLRtoSFLR(self, amount: float, spender: str = None):
214216 self .logger .debug ("Converted amount to wei" , amount = amount , amount_wei = amount_wei )
215217
216218 # Check balance
217- balance = self .w3 .eth .get_balance (self .flare_provider . address )
219+ balance = self .w3 .eth .get_balance (self .wallet_store . get_address ( user ) )
218220 if balance < amount_wei :
219221 raise ValueError (f"Insufficient balance: { self .w3 .from_wei (balance , 'ether' )} FLR, required: { amount } FLR" )
220222
221223 # Fetch current nonce
222- current_nonce = self .w3 .eth .get_transaction_count (self .flare_provider . address )
224+ current_nonce = self .w3 .eth .get_transaction_count (self .wallet_store . get_address ( user ) )
223225
224226 # Create submit transaction with value
225- tx1 = self .flare_provider .create_contract_function_tx (
227+ tx1 = self .flare_provider .create_contract_function_tx (user ,
226228 contract , "submit" , 0 , value = amount_wei
227229 )
228- tx2 = self .flare_provider .create_contract_function_tx (
229- contract , "approve" , 1 , spender , amount_wei
230- )
231-
232-
233230
234- return [tx1 , tx2 ]
231+ return [tx1 ]
235232
236233
237234 def borrowUSDC (self ,user_order : dict ):
0 commit comments