15
15
16
16
@ Data
17
17
public class LendingPool {
18
+ private final ILendingPool lendingPool ;
18
19
private AaveConnect connection ;
19
20
20
21
private String lendingPoolAddressProvider ;
@@ -23,70 +24,53 @@ public class LendingPool {
23
24
24
25
private ContractGasProvider provider ;
25
26
26
- private ILendingPoolAddressesProvider lendingPoolAddress ;
27
-
28
- public LendingPool (AaveConnect connection , String lendingPoolAddressProvider , String gasFee , String gasLimit ) {
27
+ public LendingPool (AaveConnect connection , String lendingPoolAddressProvider , String gasFee , String gasLimit ) throws Exception {
29
28
this .connection = connection ;
30
29
this .lendingPoolAddressProvider = lendingPoolAddressProvider ;
31
30
this .provider = new StaticGasProvider (new BigInteger (gasFee ),new BigInteger (gasLimit ));
32
- this .lendingPoolAddress = new ILendingPoolAddressesProvider (lendingPoolAddressProvider ,connection .getWeb3j (),connection .getCredentials (),provider );
31
+ ILendingPoolAddressesProvider lendingPoolAddress = new ILendingPoolAddressesProvider (lendingPoolAddressProvider ,connection .getWeb3j (),connection .getCredentials (),provider );
32
+ String poolAddress = lendingPoolAddress .getLendingPool ().send ();
33
+ this .lendingPool = ILendingPool .load (poolAddress ,connection .getWeb3j (),connection .getCredentials (),provider );
33
34
}
34
35
35
36
TransactionReceipt deposit (String amount , String assetAddress , String onBehalfOf ) throws Exception {
36
- String poolAddress = lendingPoolAddress .getLendingPool ().send ();
37
- ILendingPool lendingPool = ILendingPool .load (poolAddress ,connection .getWeb3j (),connection .getCredentials (),provider );
37
+
38
38
BigInteger value = new BigInteger (amount );
39
39
40
40
return lendingPool .deposit (assetAddress , value , onBehalfOf , BigInteger .valueOf (0 )).send ();
41
41
}
42
42
43
43
List <ILendingPool .DepositEventResponse > depositEvents (Web3j web3j , TransactionReceipt transactionReceipt ) throws Exception {
44
- ContractGasProvider provider = new StaticGasProvider (new BigInteger ("2000000" ),new BigInteger ("2000000" ));
45
- ILendingPoolAddressesProvider lendingPoolAddressesProvider = new ILendingPoolAddressesProvider ("0x5E52dEc931FFb32f609681B8438A51c675cc232d" ,connection .getWeb3j (),connection .getCredentials (),provider );
46
- RemoteFunctionCall <String > address = lendingPoolAddressesProvider .getLendingPool ();
47
- String poolAddress = address .send ();
48
- ILendingPool lendingPool = ILendingPool .load (poolAddress ,connection .getWeb3j (),connection .getCredentials (),provider );
44
+
49
45
return lendingPool .getDepositEvents (transactionReceipt );
50
46
}
51
47
52
48
ReserveData loadReservedData (String assetAddress ) throws Exception {
53
- String poolAddress = lendingPoolAddress .getLendingPool ().send ();
54
-
55
- ILendingPool lendingPool = ILendingPool .load (poolAddress ,connection .getWeb3j (),connection .getCredentials (),provider );
56
49
57
50
return mapper .map (lendingPool .getReserveData (assetAddress ).send (), ReserveData .class );
58
51
}
59
52
60
53
TransactionReceipt withdraw (String amount , String assetAddress , String toAddress ) throws Exception {
61
- String poolAddress = lendingPoolAddress .getLendingPool ().send ();
62
- BigInteger value = new BigInteger (amount );
54
+ BigInteger value = new BigInteger (amount );
63
55
64
- ILendingPool lendingPool = ILendingPool .load (poolAddress ,connection .getWeb3j (),connection .getCredentials (),provider );
65
56
return lendingPool .withdraw (assetAddress ,value ,toAddress ).send ();
66
57
}
67
58
68
59
TransactionReceipt borrow (String amount , String assetAddress , String onBehalfOf ) throws Exception {
69
- String poolAddress = lendingPoolAddress .getLendingPool ().send ();
70
60
BigInteger value = new BigInteger (amount );
71
61
72
- ILendingPool lendingPool = ILendingPool .load (poolAddress ,connection .getWeb3j (),connection .getCredentials (),provider );
73
62
return lendingPool .borrow (assetAddress ,value , BigInteger .ONE ,BigInteger .ZERO , onBehalfOf ).send ();
74
63
}
75
64
76
65
TransactionReceipt repay (String amount , String assetAddress , String onBehalfOf ) throws Exception {
77
- String poolAddress = lendingPoolAddress .getLendingPool ().send ();
78
- BigInteger value = new BigInteger (amount );
66
+ BigInteger value = new BigInteger (amount );
79
67
80
- ILendingPool lendingPool = ILendingPool .load (poolAddress ,connection .getWeb3j (),connection .getCredentials (),provider );
81
-
82
- return lendingPool .repay (assetAddress ,value ,BigInteger .ONE ,onBehalfOf ).send ();
68
+ return lendingPool .repay (assetAddress ,value ,BigInteger .ONE ,onBehalfOf ).send ();
83
69
}
84
70
85
71
TransactionReceipt swapBorrowRate (String assetAddress , String mode ) throws Exception {
86
- String poolAddress = lendingPoolAddress .getLendingPool ().send ();
87
72
BigInteger value = new BigInteger (mode );
88
73
89
- ILendingPool lendingPool = ILendingPool .load (poolAddress ,connection .getWeb3j (),connection .getCredentials (),provider );
90
74
return lendingPool .swapBorrowRateMode (assetAddress ,value ).send ();
91
75
}
92
76
0 commit comments