Skip to content

Commit

Permalink
Merge pull request #227 from Dapp-Learning-DAO/dev
Browse files Browse the repository at this point in the history
release v1.0.9
  • Loading branch information
cheng521521 authored Apr 7, 2024
2 parents 969863c + 1131d13 commit cc78cf7
Show file tree
Hide file tree
Showing 35 changed files with 772 additions and 96 deletions.

This file was deleted.

34 changes: 34 additions & 0 deletions src/main/java/com/dl/officialsite/admin/HookController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.dl.officialsite.admin;

import com.dl.officialsite.common.base.BaseResponse;
import com.dl.officialsite.defi.service.AaveTokenAPYService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @ClassName TiggerController
* @Author jackchen
* @Date 2024/4/5 19:04
* @Description HookController
**/
@RestController
@RequestMapping("/hook")
@Slf4j
@ConditionalOnProperty(name = "hook.open", havingValue = "true", matchIfMissing = false)
public class HookController {

private final AaveTokenAPYService aaveService;

public HookController(AaveTokenAPYService aaveService) {
this.aaveService = aaveService;
}

@GetMapping("/token/apy")
public BaseResponse HookTokenApy() {
aaveService.updateTokenAPYInfo();
return BaseResponse.success();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public class Constants {
public static final String CHAIN_ID_ARBITRUM = "42161";
public static final String CHAIN_ID_ZKSYNC = "324";
public static final String CHAIN_ID_POLYGON = "137";
public static final String CHAIN_ID_POLYGON_ZKEVM = "1101";
public static final String CHAIN_ID_LINEA = "59144";
public static final String CHAIN_ID_BASE = "8453";
public static final String CHAIN_ID_GNOSIS = "100";


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;

import com.dl.officialsite.aave.constants.Constant;
import com.dl.officialsite.defi.constants.Constant;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import org.apache.commons.logging.Log;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dl.officialsite.aave;
package com.dl.officialsite.defi;

import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.dl.officialsite.aave;
package com.dl.officialsite.defi;

import com.dl.officialsite.aave.service.AaveService;
import com.dl.officialsite.aave.vo.HealthInfoVo;
import com.dl.officialsite.defi.service.AaveService;
import com.dl.officialsite.defi.vo.HealthInfoVo;
import com.dl.officialsite.mail.EmailService;
import com.dl.officialsite.member.Member;
import com.dl.officialsite.team.TeamService;
import com.dl.officialsite.team.vo.TeamQueryVo;
import com.dl.officialsite.team.vo.TeamsWithMembers;
import java.math.BigInteger;
import java.math.BigDecimal;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -33,7 +33,7 @@ public class Schedule {
@Autowired
private TeamService teamService;

BigInteger e16 = new BigInteger("10000000000000000");
BigDecimal e16 = new BigDecimal("10000000000000000");

/**
* 监控价格一天发送一次
Expand Down Expand Up @@ -73,7 +73,8 @@ public void monitorHealth() {
for (Member member : teamAndMember.getMembers()) {
String email = member.getEmail();
HealthInfoVo healthInfo = aaveService.getHealthInfo(member.getAddress());
float health = healthInfo.getHealthFactor().divide(e16).floatValue() / 100;
BigDecimal healthFactor = new BigDecimal(healthInfo.getHealthFactor());
float health =healthFactor.divide(e16).floatValue() / 100;
log.info("health is : " + health);
if (health < 1.2) {
emailService.sendMail(email, "Dapp Defi Monitor", healthInfo.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dl.officialsite.aave;
package com.dl.officialsite.defi;

import javax.persistence.Entity;
import javax.persistence.EntityListeners;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dl.officialsite.aave;
package com.dl.officialsite.defi;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dl.officialsite.aave;
package com.dl.officialsite.defi;

import lombok.Builder;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dl.officialsite.aave;
package com.dl.officialsite.defi;

import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dl.officialsite.aave.constants;
package com.dl.officialsite.defi.constants;

import static org.web3j.tx.gas.DefaultGasProvider.GAS_LIMIT;
import static org.web3j.tx.gas.DefaultGasProvider.GAS_PRICE;
Expand Down Expand Up @@ -71,11 +71,34 @@ public class Constant {
ARB_USDT,ARB_WETH,ARB_WBTC,ARB_USDC_E,ARB_USDC_LUSD);





// public static final TokenConfig BASE_DAI =TokenConfig.builder().name("DAI").address("").build();
public static final TokenConfig BASE_USDC =TokenConfig.builder().name("USDC").address("0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913").build();
// public static final TokenConfig BASE_USDT =TokenConfig.builder().name("USDT").address("").build();
public static final TokenConfig BASE_WETH =TokenConfig.builder().name("WETH").address("0x4200000000000000000000000000000000000006").build();
// public static final TokenConfig BASE_WBTC =TokenConfig.builder().name("WBTC").address("").build();
public static final List<TokenConfig> BASE_TOKEN_LIST =Arrays.asList(BASE_USDC,BASE_WETH);




/*public static final TokenConfig GNOSIS_DAI =TokenConfig.builder().name("DAI").address("0x44fA8E6f47987339850636F88629646662444217").build();*/
public static final TokenConfig GNOSIS_USDC =TokenConfig.builder().name("USDC").address("0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83").build();
/*public static final TokenConfig GNOSIS_USDT =TokenConfig.builder().name("USDT").address("0x4ECaBa5870353805a9F068101A40E0f32ed605C6").build();*/
public static final TokenConfig GNOSIS_WETH =TokenConfig.builder().name("WETH").address("0x6a023ccd1ff6f2045c3309768ead9e68f978f6e1").build();
// public static final TokenConfig GNOSIS_WBTC =TokenConfig.builder().name("WBTC").address("").build();
public static final List<TokenConfig> GNOSIS_TOKEN_LIST =Arrays.asList(GNOSIS_USDC,GNOSIS_WETH);


public static ConcurrentHashMap<String,List<TokenConfig>> tokenConfigListMap = new ConcurrentHashMap<String, List<TokenConfig>>() {{
put( Constants.CHAIN_ID_POLYGON, POLYGON_TOKEN_LIST);
put( Constants.CHAIN_ID_OP, OP_TOKEN_LIST);
put( Constants.CHAIN_ID_SCROLL, SCROLL_TOKEN_LIST);
put( Constants.CHAIN_ID_ARBITRUM, ARB_TOKEN_LIST);
put( Constants.CHAIN_ID_BASE, BASE_TOKEN_LIST);
put( Constants.CHAIN_ID_GNOSIS, GNOSIS_TOKEN_LIST);
}};


Expand All @@ -84,6 +107,8 @@ public class Constant {
put( Constants.CHAIN_ID_OP, "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb");
put( Constants.CHAIN_ID_SCROLL, "0x69850D0B276776781C063771b161bd8894BCdD04");
put( Constants.CHAIN_ID_ARBITRUM, "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb");
put( Constants.CHAIN_ID_BASE, "0xe20fCBdBfFC4Dd138cE8b2E6FBb6CB49777ad64D");
put( Constants.CHAIN_ID_GNOSIS, "0x36616cf17557639614c1cdDb356b1B83fc0B2132");
}};


Expand Down
106 changes: 106 additions & 0 deletions src/main/java/com/dl/officialsite/defi/controller/DeFiController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.dl.officialsite.defi.controller;

import com.dl.officialsite.common.base.BaseResponse;
import com.dl.officialsite.config.ChainInfo;
import com.dl.officialsite.defi.entity.WhaleTxRow;
import com.dl.officialsite.defi.service.AaveTokenAPYService;
import com.dl.officialsite.defi.service.WhaleService;
import com.dl.officialsite.defi.vo.HealthInfoVo;
import com.dl.officialsite.defi.vo.params.QueryWhaleParams;
import com.dl.officialsite.member.MemberService;
import com.dl.officialsite.team.TeamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
* @ClassName DeFiController
* @Author jackchen
* @Date 2024/3/6 19:45
* @Description defi
**/
@RestController
@RequestMapping("/defi")
@Slf4j
public class DeFiController {

private final AaveTokenAPYService aaveService;

private final WhaleService whaleService;

private final MemberService memberService;

private final TeamService teamService;

public DeFiController(AaveTokenAPYService aaveService, WhaleService whaleService,
MemberService memberService, TeamService teamService) {
this.aaveService = aaveService;
this.whaleService = whaleService;
this.memberService = memberService;
this.teamService = teamService;
}


/**
* get all chainName
*/
@GetMapping("/chainList")
public BaseResponse chainList() {
return BaseResponse.successWithData(aaveService.queryChainList());
}

/**
* get all token apy
*/
@GetMapping("/tokenApy")
public BaseResponse tokenApy() {
return BaseResponse.successWithData(aaveService.queryTokenApy());
}

/**
* get healthInfo by wallet address
*/
@PostMapping("/healthInfo")
public BaseResponse detail(@RequestParam String address, @RequestBody ChainInfo chainInfo) {
HealthInfoVo healthInfo = aaveService.getHealthInfo(chainInfo, address);
return BaseResponse.successWithData(healthInfo);
}

@GetMapping("/init")
public BaseResponse init(@RequestParam String address) {
teamService.checkMemberIsSuperAdmin(address);
whaleService.init();
return BaseResponse.success();
}

@GetMapping("/Listener")
public BaseResponse Listener() {
whaleService.aaveListener();
return BaseResponse.success();
}

@PostMapping("/query/whale")
public BaseResponse queryWhale(
@RequestParam(defaultValue = "1") Integer pageNumber,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestBody QueryWhaleParams query) {
Pageable pageable = null;
if (query.getOrder() == 1) {
pageable = PageRequest.of(pageNumber - 1, pageSize, Sort.by(Sort.Direction.DESC, "createTime"));
} else {
pageable = PageRequest.of(pageNumber - 1, pageSize, Sort.by(Sort.Direction.ASC, "createTime"));
}
Page<WhaleTxRow> whaleDataVos = whaleService.queryWhale(pageable, query);
return BaseResponse.successWithData(whaleDataVos);
}


}
Loading

0 comments on commit cc78cf7

Please sign in to comment.