Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private void eth2token(String tokenSymbol, String tokenQuantity) {
Kyber3j kyber3j = Kyber3j.build(new KyberService(KyberService.KYBER_ROPSTEN));
log.info("Connected to Kyber Network: "+KyberService.KYBER_ROPSTEN);
// ETH2<Token> Swap
try {
// Check if token is supported
Currencies currencies = kyber3j.currencies().send();
log.info("Exists Currency"+tokenSymbol+": " + currencies.existsCurreny(tokenSymbol));
if (!checkForError(currencies) && currencies.existsCurreny(tokenSymbol)) {
// Get buy rates
BuyRate buyRate = kyber3j.buyRate(currencies.getCurrency(tokenSymbol).getId(),tokenQuantity,
false).send();
if (!checkForError(buyRate)) {
Rates rates = buyRate.getData().get(0);
SingleRate singleRate = rates.getSingleRate(0);
log.info("Conversion Rate: " + singleRate.getSrc_qty());
// Get tradeData
// Adjust conversion rates to 97%
singleRate.approximateReceivableToken(0.97);
TradeData tradeData = kyber3j.tradeData(credentials.getAddress(), singleRate, GasPriceRange.medium,nonce).send();
if (!checkForError(tradeData)) {
executeEthereumTransaction(tradeData.getData().get(0));
}
}
}
} catch (Exception e) { e.printStackTrace(); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.