private BigInteger getRawValue(BigDecimal amount, int decimals) { return toWei(amount, decimals).toBigInteger(); } }
@PostConstruct @Scheduled(fixedDelay = 20000) private void init() { currentProvider = updateCurrentProvider(); }
private HumanStandardToken getERC20(final String token) { return HumanStandardToken.load(token, web3jGateway.web3j()); } }
private boolean hasFailed(PendingFund fund) { return azraelClient.getTransactionStatus(prettify(fund.getTransactionHash())).equals(TransactionStatus.FAILED); } }
@Test public void statisticsReturnsTotalAvailableFunding() { TokenAmountDto tokenAmount = new TokenAmountDto(fnd.getAddress(), EthUtil.toWei(BigDecimal.TEN, fnd.getDecimals())); TokenAmountDto tokenAmount2 = new TokenAmountDto(zrx.getAddress(), EthUtil.toWei(BigDecimal.ONE, zrx.getDecimals())); when(fundRepository.getAmountPerTokenWhereRequestHasStatusFunded()).thenReturn(Arrays.asList(tokenAmount, tokenAmount2)); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(fnd.getSymbol()) .tokenAddress(fnd.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount.getTotalAmount(), fnd.getDecimals())) .build())).thenReturn(10.0); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(zrx.getSymbol()) .tokenAddress(zrx.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount2.getTotalAmount(), zrx.getDecimals())) .build())).thenReturn(20.0); StatisticsDto result = statisticsService.getStatistics(); assertThat(result.getTotalAvailableFunding()).isEqualTo(30.0); }
public TokenValueDto map(final String tokenAddress, final BigDecimal rawBalance) { final TokenInfoDto tokenInfo = tokenInfoService.getTokenInfo(tokenAddress); return tokenInfo == null ? null : TokenValueDto.builder() .tokenAddress(tokenInfo.getAddress()) .tokenSymbol(tokenInfo.getSymbol()) .totalAmount(fromWei(rawBalance, tokenInfo.getDecimals())) .build(); } }
public Optional<String> getTokenByIndex(final String platform, final String platformId, final long index) { final Function function = new Function("getTokenByIndex", Arrays.asList( new Bytes32(Arrays.copyOfRange(platform.getBytes(), 0, 32)), new Utf8String(platformId), new Uint(BigInteger.valueOf(index))), singletonList(new TypeReference<Address>() { })); try { return Optional.of(prettify(executeCallSingleValueReturn(function, String.class))); } catch (final Exception ex) { return empty(); } }
@Test public void statisticsReturnsMostFundedTechnology() { TokenAmountDto tokenAmount = new TokenAmountDto(fnd.getAddress(), EthUtil.toWei(BigDecimal.TEN, fnd.getDecimals())); TokenAmountDto tokenAmount2 = new TokenAmountDto(zrx.getAddress(), EthUtil.toWei(BigDecimal.ONE, zrx.getDecimals())); List<Object[]> requests = Arrays.asList( createObject("Java", fnd.getAddress(), tokenAmount.getTotalAmount()), createObject("Python", zrx.getAddress(), tokenAmount2.getTotalAmount()) ); when(fundRepository.getAmountPerTokenPerTechnologyWhereRequestHasStatusFunded()).thenReturn(requests); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(fnd.getSymbol()) .tokenAddress(fnd.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount.getTotalAmount(), fnd.getDecimals())) .build())).thenReturn(10.0); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(zrx.getSymbol()) .tokenAddress(zrx.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount2.getTotalAmount(), zrx.getDecimals())) .build())).thenReturn(20.0); StatisticsDto result = statisticsService.getStatistics(); assertThat(result.getMostFundedTechnology()).isEqualTo("Python"); }
@Override public TokenValueDto map(final TokenValue tokenValue) { final TokenInfoDto tokenInfo = tokenInfoService.getTokenInfo(tokenValue.getTokenAddress()); return TokenValueDto.builder() .tokenAddress(tokenValue.getTokenAddress()) .tokenSymbol(tokenInfo.getSymbol()) .totalAmount(fromWei(tokenValue.getAmountInWei(), tokenInfo.getDecimals())) .build(); } }
private BigInteger toWei(PendingFundCommand command) { final TokenInfoDto tokenInfo = tokenInfoService.getTokenInfo(command.getTokenAddress()); return EthUtil.toWei(new BigDecimal(command.getAmount()), tokenInfo.getDecimals()).toBigInteger(); }
@Test public void shouldntRemoveWhenThrownExceptionFromAzrael() { final PendingFund pendingFund = PendingFundMother.aPendingFund(); when(pendingFundService.findAll()) .thenReturn(of(pendingFund)); when(azraelClient.getTransactionStatus(prettify(pendingFund.getTransactionHash()))).thenThrow(new IllegalArgumentException("problemos")); pendingFundCleaner.cleanupPendingFunds(); verify(pendingFundService, times(0)).removePendingFund(any(PendingFund.class)); } }
@Test public void statisticsReturnsMostFundedProject() { TokenAmountDto tokenAmount = new TokenAmountDto(fnd.getAddress(), EthUtil.toWei(BigDecimal.TEN, fnd.getDecimals())); TokenAmountDto tokenAmount2 = new TokenAmountDto(zrx.getAddress(), EthUtil.toWei(BigDecimal.ONE, zrx.getDecimals())); List<Object[]> requests = Arrays.asList( createObject("FundRequest", fnd.getAddress(), tokenAmount.getTotalAmount()), createObject("Dock", zrx.getAddress(), tokenAmount2.getTotalAmount()) ); when(fundRepository.getAmountPerTokenPerProjectWhereRequestHasStatusFunded()).thenReturn(requests); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(fnd.getSymbol()) .tokenAddress(fnd.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount.getTotalAmount(), fnd.getDecimals())) .build())).thenReturn(10.0); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(zrx.getSymbol()) .tokenAddress(zrx.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount2.getTotalAmount(), zrx.getDecimals())) .build())).thenReturn(20.0); StatisticsDto result = statisticsService.getStatistics(); assertThat(result.getMostFundedProject()).isEqualTo("Dock"); }
private double mapToUsd(TokenAmountDto f) { TokenInfoDto tokenInfo = tokenInfoService.getTokenInfo(f.getTokenAddress()); TokenValueDto dto = TokenValueDto.builder() .totalAmount(fromWei(f.getTotalAmount(), tokenInfo.getDecimals())) .tokenAddress(f.getTokenAddress()) .tokenSymbol(tokenInfo.getSymbol()) .build(); return fiatService.getUsdPrice(dto); } }
@Transactional @Override public void approve(Long requestClaimId) { RequestClaim requestClaim = requestClaimRepository.findOne(requestClaimId).orElseThrow(() -> new RuntimeException("Request claim not found")); Request request = requestRepository.findOne(requestClaim.getRequestId()).orElseThrow(ResourceNotFoundException::new); ClaimSignature sig = azraelClient.getSignature(createSignClaimCommand(requestClaim, request)); try { final ClaimTransaction claimTransaction = azraelClient.submitClaim(sig); request.setStatus(RequestStatus.CLAIM_APPROVED); requestClaim.setStatus(ClaimRequestStatus.APPROVED); requestClaim.setTransactionHash(prettify(claimTransaction.getTransactionHash())); requestClaim.setTransactionSubmitTime(LocalDateTime.now()); requestRepository.save(request); requestClaimRepository.save(requestClaim); } catch (final Exception ex) { throw new IllegalArgumentException("Unable to submit claim transaction: " + ex.getMessage()); } }
@Test void map() { final String tokenAddress = "dafsd"; final String symbol = "ZRX"; final BigDecimal rawBalance = new BigDecimal("1000000000000000000"); final int decimals = 18; final TokenInfoDto tokenInfoDto = TokenInfoDto.builder().address(tokenAddress).symbol(symbol).decimals(decimals).build(); when(tokenInfoService.getTokenInfo(tokenAddress)).thenReturn(tokenInfoDto); final TokenValueDto result = mapper.map(tokenAddress, rawBalance); assertThat(result.getTokenAddress()).isEqualTo(tokenAddress); assertThat(result.getTokenSymbol()).isEqualTo(symbol); assertThat(result.getTotalAmount()).isEqualTo(fromWei(rawBalance, decimals)); }
@Test public void shouldRemoveFailedPendingFunds() { final PendingFund pendingFund = PendingFundMother.aPendingFund(); when(pendingFundService.findAll()) .thenReturn(of(pendingFund)); when(azraelClient.getTransactionStatus(prettify(pendingFund.getTransactionHash()))).thenReturn(TransactionStatus.FAILED); pendingFundCleaner.cleanupPendingFunds(); verify(pendingFundService).removePendingFund(pendingFund); }
@Test public void shouldRemoveAgedPendingFunds() { final PendingFund pendingFund = PendingFundMother.aPendingFund(); when(pendingFundService.findAll()) .thenReturn(of(pendingFund)); when(azraelClient.getTransactionStatus(prettify(pendingFund.getTransactionHash()))).thenReturn(TransactionStatus.SUCCEEDED); ReflectionUtils.set(pendingFund, "creationDate", LocalDateTime.now().minusDays(2)); pendingFundCleaner.cleanupPendingFunds(); verify(pendingFundService).removePendingFund(pendingFund); }