Skip to content

Commit 5713812

Browse files
authored
Merge pull request #208 from Dapp-Learning-DAO/dev
add defispy feature
2 parents 06ddea2 + cd5fd07 commit 5713812

25 files changed

+275
-87
lines changed

deploy/nginx.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ http {
88
listen [::]:80;
99
server_name _;
1010

11+
client_max_body_size 10M;
12+
1113
location / {
1214
proxy_pass http://dl-backend:8080;
1315
proxy_set_header Host $host;

src/main/java/com/dl/officialsite/aave/Constant.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/main/java/com/dl/officialsite/aave/Schedule.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.dl.officialsite.aave;
22

3+
import com.dl.officialsite.aave.service.AaveService;
4+
import com.dl.officialsite.aave.vo.HealthInfoVo;
35
import com.dl.officialsite.mail.EmailService;
46
import com.dl.officialsite.member.Member;
57
import com.dl.officialsite.team.TeamService;
@@ -47,7 +49,7 @@ public void monitorPrice() throws Exception {
4749
for (TeamsWithMembers teamAndMember : teamAndMembers) {
4850
for (Member member : teamAndMember.getMembers()) {
4951
String email = member.getEmail();
50-
HealthInfo healthInfo = aaveService.getHealthInfo(member.getAddress());
52+
HealthInfoVo healthInfo = aaveService.getHealthInfo(member.getAddress());
5153
TokenInfoList tokenInfoList = aaveService.getVar();
5254
emailService.sendMail(email, "Dapp Defi Monitor", tokenInfoList.toString() + "\n" + healthInfo.toString());
5355
}
@@ -70,7 +72,7 @@ public void monitorHealth() {
7072
for (TeamsWithMembers teamAndMember : teamAndMembers) {
7173
for (Member member : teamAndMember.getMembers()) {
7274
String email = member.getEmail();
73-
HealthInfo healthInfo = aaveService.getHealthInfo(member.getAddress());
75+
HealthInfoVo healthInfo = aaveService.getHealthInfo(member.getAddress());
7476
float health = healthInfo.getHealthFactor().divide(e16).floatValue() / 100;
7577
log.info("health is : " + health);
7678
if (health < 1.2) {

src/main/java/com/dl/officialsite/aave/TokenAPYInfo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ public class TokenAPYInfo {
3131

3232
String chainName;
3333

34-
String tokenApy;
34+
String chainId;
35+
36+
Double supply;
37+
38+
Double borrow;
3539

3640
String current;
3741

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.dl.officialsite.aave.constants;
2+
3+
import static org.web3j.tx.gas.DefaultGasProvider.GAS_LIMIT;
4+
import static org.web3j.tx.gas.DefaultGasProvider.GAS_PRICE;
5+
6+
import com.dl.officialsite.common.constants.Constants;
7+
import com.dl.officialsite.config.TokenConfig;
8+
import com.dl.officialsite.contract.ipooladdressesprovider.IPoolAddressesProvider;
9+
import java.util.Arrays;
10+
import java.util.List;
11+
import java.util.concurrent.ConcurrentHashMap;
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.context.annotation.Bean;
14+
import org.springframework.stereotype.Component;
15+
import org.web3j.crypto.Credentials;
16+
import org.web3j.protocol.Web3j;
17+
import org.web3j.tx.gas.ContractGasProvider;
18+
import org.web3j.tx.gas.StaticGasProvider;
19+
20+
/**
21+
* @ClassName Compent
22+
* @Author jackchen
23+
* @Date 2023/11/5 14:30
24+
* @Description Constant
25+
**/
26+
@Component
27+
public class Constant {
28+
29+
public static final TokenConfig POLYGON_DAI =TokenConfig.builder().name("DAI").address("0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063").build();
30+
public static final TokenConfig POLYGON_USDC =TokenConfig.builder().name("USDC").address("0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359").build();
31+
public static final TokenConfig POLYGON_USDT =TokenConfig.builder().name("USDT").address("0xc2132d05d31c914a87c6611c10748aeb04b58e8f").build();
32+
public static final TokenConfig POLYGON_WETH =TokenConfig.builder().name("WETH").address("0x7ceb23fd6bc0add59e62ac25578270cff1b9f619").build();
33+
public static final TokenConfig POLYGON_WBTC =TokenConfig.builder().name("WBTC").address("0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6").build();
34+
35+
public static final TokenConfig POLYGON_USDC_E =TokenConfig.builder().name("USDC.e").address("0x2791bca1f2de4661ed88a30c99a7a9449aa84174").build();
36+
public static final List<TokenConfig> POLYGON_TOKEN_LIST =Arrays.asList(POLYGON_DAI,
37+
POLYGON_USDC,POLYGON_USDT,POLYGON_WETH,POLYGON_WBTC,POLYGON_USDC_E);
38+
39+
public static final TokenConfig OP_DAI =TokenConfig.builder().name("DAI").address("0xda10009cbd5d07dd0cecc66161fc93d7c9000da1").build();
40+
public static final TokenConfig OP_USDC =TokenConfig.builder().name("USDC").address("0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85").build();
41+
public static final TokenConfig OP_USDT =TokenConfig.builder().name("USDT").address("0x94b008aa00579c1307b0ef2c499ad98a8ce58e58").build();
42+
public static final TokenConfig OP_WETH =TokenConfig.builder().name("WETH").address("0x4200000000000000000000000000000000000006").build();
43+
public static final TokenConfig OP_WBTC =TokenConfig.builder().name("WBTC").address("0x68f180fcce6836688e9084f035309e29bf0a2095").build();
44+
45+
public static final TokenConfig OP_USDC_E =TokenConfig.builder().name("USDC.e").address("0x7f5c764cbc14f9669b88837ca1490cca17c31607").build();
46+
public static final List<TokenConfig> OP_TOKEN_LIST =Arrays.asList(OP_DAI,OP_USDC,OP_USDT,
47+
OP_WETH,OP_WBTC,OP_USDC_E);
48+
49+
50+
51+
// public static final TokenConfig SCROLL_DAI =TokenConfig.builder().name("DAI").address("123").build();
52+
public static final TokenConfig SCROLL_USDC =TokenConfig.builder().name("USDC").address("0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4").build();
53+
public static final TokenConfig SCROLL_USDT =TokenConfig.builder().name("USDT").address("0xf55BEC9cafDbE8730f096Aa55dad6D22d44099Df").build();
54+
public static final TokenConfig SCROLL_WETH =TokenConfig.builder().name("WETH").address("0x5300000000000000000000000000000000000004").build();
55+
// public static final TokenConfig SCROLL_WBTC =TokenConfig.builder().name("WBTC").address("123").build();
56+
public static final List<TokenConfig> SCROLL_TOKEN_LIST =Arrays.asList(SCROLL_USDC,SCROLL_USDT,SCROLL_WETH);
57+
58+
59+
public static final TokenConfig ARB_DAI =TokenConfig.builder().name("DAI").address("0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1").build();
60+
public static final TokenConfig ARB_USDC =TokenConfig.builder().name("USDC").address("0xaf88d065e77c8cC2239327C5EDb3A432268e5831").build();
61+
public static final TokenConfig ARB_USDT =TokenConfig.builder().name("USDT").address("0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9").build();
62+
public static final TokenConfig ARB_WETH =TokenConfig.builder().name("WETH").address("0x82af49447d8a07e3bd95bd0d56f35241523fbab1").build();
63+
public static final TokenConfig ARB_WBTC =TokenConfig.builder().name("WBTC").address("0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f").build();
64+
public static final TokenConfig ARB_USDC_E =TokenConfig.builder().name("USDC.e").address("0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8").build();
65+
public static final List<TokenConfig> ARB_TOKEN_LIST =Arrays.asList(ARB_DAI,ARB_USDC,
66+
ARB_USDT,ARB_WETH,ARB_WBTC,ARB_USDC_E);
67+
68+
69+
public static ConcurrentHashMap<String,List<TokenConfig>> tokenConfigListMap = new ConcurrentHashMap<String, List<TokenConfig>>() {{
70+
put( Constants.CHAIN_ID_POLYGON, POLYGON_TOKEN_LIST);
71+
put( Constants.CHAIN_ID_OP, OP_TOKEN_LIST);
72+
put( Constants.CHAIN_ID_SCROLL, SCROLL_TOKEN_LIST);
73+
put( Constants.CHAIN_ID_ARBITRUM, ARB_TOKEN_LIST);
74+
}};
75+
76+
77+
public static ConcurrentHashMap<String,String> aaveLendingPoolProviderV3AddressMap = new ConcurrentHashMap<String, String>() {{
78+
put( Constants.CHAIN_ID_POLYGON, "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb");
79+
put( Constants.CHAIN_ID_OP, "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb");
80+
put( Constants.CHAIN_ID_SCROLL, "0x69850D0B276776781C063771b161bd8894BCdD04");
81+
put( Constants.CHAIN_ID_ARBITRUM, "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb");
82+
}};
83+
84+
85+
86+
public static ContractGasProvider GAS_PROVIDER = new StaticGasProvider(GAS_PRICE, GAS_LIMIT);
87+
88+
// @Autowired
89+
Web3j web3j;
90+
91+
@Autowired
92+
Credentials credentials;
93+
94+
@Bean
95+
IPoolAddressesProvider IPoolAddressesProvider() {
96+
String poolAddressesProviderAddress = "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb";
97+
IPoolAddressesProvider poolAddressesProvider = IPoolAddressesProvider.load(poolAddressesProviderAddress,
98+
web3j, credentials, GAS_PROVIDER);
99+
return poolAddressesProvider;
100+
}
101+
102+
}

src/main/java/com/dl/officialsite/aave/DeFiController.java renamed to src/main/java/com/dl/officialsite/aave/controller/DeFiController.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
package com.dl.officialsite.aave;
1+
package com.dl.officialsite.aave.controller;
22

3+
import com.dl.officialsite.aave.service.AaveTokenAPYService;
4+
import com.dl.officialsite.aave.vo.HealthInfoVo;
35
import com.dl.officialsite.common.base.BaseResponse;
46
import com.dl.officialsite.config.ChainInfo;
57
import lombok.extern.slf4j.Slf4j;
@@ -37,7 +39,7 @@ public BaseResponse chainList() {
3739
}
3840

3941
/**
40-
* 条件查询所有币种年华,按照最大年华排序
42+
* get all token apy
4143
*/
4244
@GetMapping("/tokenApy")
4345
public BaseResponse tokenApy() {
@@ -49,7 +51,7 @@ public BaseResponse tokenApy() {
4951
*/
5052
@PostMapping("/healthInfo")
5153
public BaseResponse detail(@RequestParam String address, @RequestBody ChainInfo chainInfo) {
52-
HealthInfo healthInfo = aaveService.getHealthInfo(chainInfo, address);
54+
HealthInfoVo healthInfo = aaveService.getHealthInfo(chainInfo, address);
5355
return BaseResponse.successWithData(healthInfo);
5456
}
5557
}

src/main/java/com/dl/officialsite/aave/AaveService.java renamed to src/main/java/com/dl/officialsite/aave/service/AaveService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
package com.dl.officialsite.aave;
1+
package com.dl.officialsite.aave.service;
22

33
import static org.web3j.tx.gas.DefaultGasProvider.GAS_LIMIT;
44
import static org.web3j.tx.gas.DefaultGasProvider.GAS_PRICE;
55

6+
import com.dl.officialsite.aave.TokenInfo;
7+
import com.dl.officialsite.aave.TokenInfoList;
8+
import com.dl.officialsite.aave.vo.HealthInfoVo;
69
import com.dl.officialsite.contract.iaaveoracle.IAaveOracle;
710
import com.dl.officialsite.contract.ipool.IPool;
811
import com.dl.officialsite.contract.ipooladdressesprovider.IPoolAddressesProvider;
@@ -36,10 +39,7 @@ public class AaveService {
3639
IPoolAddressesProvider poolAddressesProvider;
3740

3841

39-
40-
41-
42-
public HealthInfo getHealthInfo(String address) {
42+
public HealthInfoVo getHealthInfo(String address) {
4343
try {
4444
String poolAddress = poolAddressesProvider.getPool().send();
4545
log.info("poolAddress is : " + poolAddress);
@@ -50,7 +50,7 @@ public HealthInfo getHealthInfo(String address) {
5050
BigInteger totalDebtBase = info.component2();
5151
BigInteger ltv = info.component5();
5252
BigInteger healthFactor = info.component6();
53-
HealthInfo healthInfo = HealthInfo.builder()
53+
HealthInfoVo healthInfo = HealthInfoVo.builder()
5454
.healthFactor(healthFactor)
5555
.totalBorrows(totalDebtBase.toString())
5656
.totalCollateralETH(totalCollateralBase.toString())

src/main/java/com/dl/officialsite/aave/AaveTokenAPYService.java renamed to src/main/java/com/dl/officialsite/aave/service/AaveTokenAPYService.java

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
package com.dl.officialsite.aave;
1+
package com.dl.officialsite.aave.service;
22

33
import static org.web3j.tx.gas.DefaultGasProvider.GAS_LIMIT;
44
import static org.web3j.tx.gas.DefaultGasProvider.GAS_PRICE;
55

6+
import com.dl.officialsite.aave.TokenAPYInfo;
7+
import com.dl.officialsite.aave.TokenAPYInfoRepository;
8+
import com.dl.officialsite.aave.vo.ChainAndAPYVo;
9+
import com.dl.officialsite.aave.vo.HealthInfoVo;
10+
import com.dl.officialsite.aave.vo.TokenAPYInfoAllVo;
611
import com.dl.officialsite.config.ChainInfo;
712
import com.dl.officialsite.config.Web3jAutoConfiguration;
813
import com.dl.officialsite.contract.ipool.IPool;
@@ -12,8 +17,10 @@
1217
import java.time.format.DateTimeFormatter;
1318
import java.util.ArrayList;
1419
import java.util.List;
20+
import java.util.Map;
1521
import java.util.concurrent.ConcurrentHashMap;
1622
import java.util.concurrent.atomic.AtomicReference;
23+
import java.util.stream.Collectors;
1724
import lombok.extern.slf4j.Slf4j;
1825
import org.springframework.scheduling.annotation.Scheduled;
1926
import org.springframework.stereotype.Service;
@@ -49,14 +56,36 @@ public AaveTokenAPYService(TokenAPYInfoRepository tokenAPYInfoRepository) {
4956
}
5057

5158
@Override
52-
public List<TokenAPYInfo> queryTokenApy() {
53-
return tokenAPYInfoRepository.findAll();
59+
public List<TokenAPYInfoAllVo> queryTokenApy() {
60+
Map<String, List<TokenAPYInfo>> tokenAPYInfoMap = tokenAPYInfoRepository.findAll()
61+
.stream()
62+
.collect(Collectors.groupingBy(TokenAPYInfo::getTokenName));
63+
64+
return tokenAPYInfoMap.entrySet().stream()
65+
.map(entry -> {
66+
TokenAPYInfoAllVo tokenAPYInfoAllVo = new TokenAPYInfoAllVo();
67+
tokenAPYInfoAllVo.setTokenName(entry.getKey());
68+
List<ChainAndAPYVo> chainAndAPYVos = entry.getValue().stream()
69+
.map(tokenAPYInfo -> {
70+
ChainAndAPYVo chainAndAPYVo = new ChainAndAPYVo();
71+
chainAndAPYVo.setChainName(tokenAPYInfo.getChainName());
72+
chainAndAPYVo.setSupply(tokenAPYInfo.getSupply());
73+
chainAndAPYVo.setBorrow(tokenAPYInfo.getBorrow());
74+
chainAndAPYVo.setTokenAddress(tokenAPYInfo.getTokenAddress());
75+
return chainAndAPYVo;
76+
})
77+
.collect(Collectors.toList());
78+
tokenAPYInfoAllVo.setChainAllAPY(chainAndAPYVos);
79+
return tokenAPYInfoAllVo;
80+
})
81+
.collect(Collectors.toList());
5482
}
5583

84+
5685
@Override
57-
public HealthInfo getHealthInfo(ChainInfo chainInfo, String address) {
86+
public HealthInfoVo getHealthInfo(ChainInfo chainInfo, String address) {
5887
try {
59-
AtomicReference<HealthInfo> healthInfo = new AtomicReference<>();
88+
AtomicReference<HealthInfoVo> healthInfo = new AtomicReference<>();
6089
chainWithWeb3j.forEach((chain, web3j) -> {
6190
if (chain.getId().equals(chainInfo.getId())) {
6291
log.info("chain: {}", chain.getName());
@@ -79,7 +108,7 @@ public HealthInfo getHealthInfo(ChainInfo chainInfo, String address) {
79108
BigInteger totalDebtBase = info.component2();
80109
BigInteger ltv = info.component5();
81110
BigInteger healthFactor = info.component6();
82-
healthInfo.set(HealthInfo.builder()
111+
healthInfo.set(HealthInfoVo.builder()
83112
.healthFactor(healthFactor)
84113
.totalBorrows(totalDebtBase.toString())
85114
.totalCollateralETH(totalCollateralBase.toString())
@@ -106,8 +135,8 @@ public void updateTokenAPYInfo() {
106135
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
107136
log.info("update token info task begin --------------------- ");
108137
log.info("now date {}", LocalDateTime.now().format(formatter));
109-
tokenAPYInfoRepository.deleteAll();
110138
List<TokenAPYInfo> tokenAPYInfoList = queryTokenApyOnChain();
139+
tokenAPYInfoRepository.deleteAll();
111140
tokenAPYInfoRepository.saveAll(tokenAPYInfoList);
112141
}
113142

@@ -133,13 +162,18 @@ public List<TokenAPYInfo> queryTokenApyOnChain() {
133162
log.info("tokenName: {} tokenAddress: {}", token.getName(), token.getAddress());
134163
try {
135164
IPool.ReserveData reserveData = pool.getReserveData(token.getAddress()).send();
136-
log.info("{} variable deposit interest: {}", token.getName(), reserveData.currentVariableBorrowRate.divide(E23).floatValue() / 100);
137-
String tokenApy = reserveData.currentLiquidityRate.divide(E23).floatValue() / 100 + "%";
165+
log.info("{} variable deposit interest: {}", token.getName(), reserveData.currentLiquidityRate.divide(E23).floatValue() / 100);
166+
Double deposit = (double) (reserveData.currentLiquidityRate.divide(E23).floatValue() / 100);
167+
log.info( "{} variable borrow interest: {}" ,token.getName(), reserveData.currentVariableBorrowRate.divide(E23).floatValue()/100) ;
168+
Double borrow =
169+
(double) (reserveData.currentVariableBorrowRate.divide(E23).floatValue() / 100);
138170
TokenAPYInfo tokenAPYInfo = new TokenAPYInfo();
139171
tokenAPYInfo.setTokenName(token.getName());
140172
tokenAPYInfo.setTokenAddress(token.getAddress());
141173
tokenAPYInfo.setChainName(chain.getName());
142-
tokenAPYInfo.setTokenApy(tokenApy);
174+
tokenAPYInfo.setSupply(deposit);
175+
tokenAPYInfo.setBorrow(borrow);
176+
tokenAPYInfo.setChainId(chain.getId());
143177
tokenAPYInfo.setProtocol("Aave");
144178
tokenAPYInfoList.add(tokenAPYInfo);
145179
} catch (Exception e) {

src/main/java/com/dl/officialsite/aave/AbstractTokenAPY.java renamed to src/main/java/com/dl/officialsite/aave/service/AbstractTokenAPY.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
package com.dl.officialsite.aave;
1+
package com.dl.officialsite.aave.service;
22

3+
import com.dl.officialsite.aave.vo.HealthInfoVo;
4+
import com.dl.officialsite.aave.vo.TokenAPYInfoAllVo;
35
import com.dl.officialsite.config.ChainInfo;
46
import java.util.List;
57

@@ -14,9 +16,9 @@ public abstract class AbstractTokenAPY {
1416
/**
1517
* get token apy group by defi provider
1618
*/
17-
public abstract List<TokenAPYInfo> queryTokenApy();
19+
public abstract List<TokenAPYInfoAllVo> queryTokenApy();
1820

19-
public abstract HealthInfo getHealthInfo(ChainInfo chainInfo, String address);
21+
public abstract HealthInfoVo getHealthInfo(ChainInfo chainInfo, String address);
2022

2123

2224
}

0 commit comments

Comments
 (0)