Skip to content
This repository was archived by the owner on Feb 25, 2023. It is now read-only.

Commit b9c758a

Browse files
authored
Merge pull request #110 from CoinAlpha/revert-109-uniswap-v3-changes
Revert "Uniswap V3 fixes"
2 parents e4957ba + 56defc6 commit b9c758a

File tree

8 files changed

+36
-42
lines changed

8 files changed

+36
-42
lines changed

conf/global_conf.yml.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ GMT_OFFSET: +0800
7676
# EthGasStation
7777
# API key for defipulse.com gas station API
7878
# Gas level you want to use for Ethereum transactions (fast, fastest, safeLow, average)
79-
ETH_GAS_STATION_ENABLE: true
79+
ENABLE_ETH_GAS_STATION: true
8080
ETH_GAS_STATION_API_KEY:
8181
ETH_GAS_STATION_GAS_LEVEL: fast
8282
ETH_GAS_STATION_REFRESH_TIME: 60
83-
ETH_MANUAL_GAS_PRICE: 100
83+
MANUAL_GAS_PRICE: 100
8484

8585
# Balancer Config
8686
BALANCER_MAX_SWAPS: 4

src/assets/erc20_tokens_kovan.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
{
1515
"symbol": "DAI",
16-
"address": "0x4f96fe3b7a6cf9725f59d353f723c1bdb64ca6aa",
16+
"address": "0x1528F3FCc26d13F7079325Fb78D9442607781c8C",
1717
"decimals": 18
1818
},
1919
{

src/routes/ethereum.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import {
44
TokenERC20Info,
55
} from '../services/ethereum';
66
import { EthereumConfigService } from '../services/ethereum_config';
7-
// import { EthereumGasService } from '../services/ethereum_gas';
8-
import Fees from '../services/fees';
9-
7+
import { EthereumGasService } from '../services/ethereum_gas';
108
import { logger } from '../services/logger';
119
import { Router, Request, Response } from 'express';
1210
import { ethers } from 'ethers';
@@ -19,8 +17,7 @@ const latency = (startTime: number, endTime: number): number => {
1917

2018
const config = new EthereumConfigService();
2119
const ethereumService = new EthereumService(config);
22-
// const ethereumGasService = new EthereumGasService(config);
23-
const fees = new Fees();
20+
const ethereumGasService = new EthereumGasService(config);
2421

2522
router.post('/', async (_req: Request, res: Response) => {
2623
/*
@@ -161,8 +158,8 @@ router.post('/approve', async (req: Request, res: Response) => {
161158
res.status(500).send(`Token "${req.body.token}" is not supported`);
162159
} else {
163160
const tokenAddress = tokenContractInfo.address;
164-
// const gasPrice = req.body.gasPrice || ethereumGasService.getGasPrice();
165-
const gasPrice = req.body.gasPrice || fees.ethGasPrice;
161+
162+
const gasPrice = req.body.gasPrice || ethereumGasService.getGasPrice();
166163

167164
let amount = ethers.constants.MaxUint256;
168165
if (req.body.amount) {

src/routes/uniswap_v3.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ router.post('/trade', async (req: Request, res: Response) => {
250250
);
251251

252252
if (side === 'BUY') {
253-
const price = trade.executionPrice.invert().toSignificant(8);
253+
const price = trade.executionPrice.invert().toFixed();
254254
logger.info(`uniswap.route - Price: ${price.toString()}`);
255255
if (!limitPrice || price <= limitPrice) {
256256
// pass swaps to exchange-proxy to complete trade
@@ -268,7 +268,7 @@ router.post('/trade', async (req: Request, res: Response) => {
268268
base: baseTokenAddress,
269269
quote: quoteTokenAddress,
270270
amount: amount,
271-
expectedIn: expectedAmount.toSignificant(8),
271+
expectedIn: expectedAmount.toFixed(),
272272
price: price,
273273
gasPrice: gasPrice,
274274
gasLimit,
@@ -286,7 +286,7 @@ router.post('/trade', async (req: Request, res: Response) => {
286286
}
287287
} else {
288288
// sell
289-
const price = trade.executionPrice.toSignificant(8);
289+
const price = trade.executionPrice.toFixed();
290290
logger.info(`Price: ${price.toString()}`);
291291
if (!limitPrice || price >= limitPrice) {
292292
// pass swaps to exchange-proxy to complete trade
@@ -304,7 +304,7 @@ router.post('/trade', async (req: Request, res: Response) => {
304304
base: baseTokenAddress,
305305
quote: quoteTokenAddress,
306306
amount: parseFloat(req.body.amount),
307-
expectedOut: expectedAmount.toSignificant(8),
307+
expectedOut: expectedAmount.toFixed(),
308308
price: parseFloat(price),
309309
gasPrice: gasPrice,
310310
gasLimit,
@@ -389,13 +389,13 @@ router.post('/price', async (req: Request, res: Response) => {
389389
if (trade !== null && expectedAmount !== null) {
390390
price =
391391
side === 'BUY'
392-
? trade.executionPrice.invert().toSignificant(8)
393-
: trade.executionPrice.toSignificant(8);
392+
? trade.executionPrice.invert().toFixed()
393+
: trade.executionPrice.toFixed();
394394

395395
priceResult = {
396396
price: parseFloat(price),
397397
amount: parseFloat(amount),
398-
expectedAmount: parseFloat(expectedAmount.toSignificant(8)),
398+
expectedAmount: parseFloat(expectedAmount.toFixed()),
399399
};
400400
}
401401
} else {

src/services/ethereum.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class EthereumService {
178178
return await contract.approve(spender, amount, {
179179
gasPrice: gasPrice * 1e9,
180180
// fixate gas limit to prevent overwriting
181-
gasLimit: 60000,
181+
gasLimit: this.config.approvalGasLimit,
182182
});
183183
} catch (err) {
184184
throw new Error(err.reason || 'error approval');
@@ -235,15 +235,15 @@ export class EthereumService {
235235
* @param {string} tokenAddress
236236
* @return {TokenERC20Info} | null
237237
*/
238-
getERC20TokenByAddress(tokenAddress: string): TokenERC20Info | undefined {
238+
getERC20TokenByAddress(tokenAddress: string): TokenERC20Info | undefined {
239239
if (this.erc20TokenList) {
240240
const tokenContract = this.erc20TokenList.tokens.filter((obj) => {
241-
return obj.address.toUpperCase() === tokenAddress.toUpperCase();
242-
});
243-
return tokenContract[0];
244-
}
245-
return;
241+
return obj.address.toUpperCase() === tokenAddress.toUpperCase();
242+
});
243+
return tokenContract[0];
246244
}
245+
return;
246+
}
247247

248248
/**
249249
* Return wallet of a private string
@@ -262,19 +262,12 @@ export class EthereumService {
262262
async getTransactionReceipt(txHash: string): Promise<EthTransactionReceipt> {
263263
const transaction = await this.provider.getTransactionReceipt(txHash);
264264

265-
let gasUsed;
266-
if (transaction.gasUsed) {
267-
gasUsed = transaction.gasUsed.toNumber();
268-
} else {
269-
gasUsed = 0;
270-
}
271-
272265
return {
273-
gasUsed: gasUsed,
266+
gasUsed: transaction.gasUsed.toNumber(),
274267
blockNumber: transaction.blockNumber,
275268
confirmations: transaction.confirmations,
276269
status: transaction.status || 0,
277-
logs: transaction.logs,
270+
logs: transaction.logs
278271
};
279272
}
280273
}

src/services/ethereum_config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export class EthereumConfigService {
1717
return this.config.getConfig('ETHEREUM_TOKEN_LIST_URL');
1818
}
1919

20+
get approvalGasLimit(): string {
21+
return this.config.getConfig('APPROVAL_GAS_LIMIT');
22+
}
23+
2024
get networkName(): string {
2125
return this.config.getConfig('ETHEREUM_CHAIN');
2226
}
@@ -27,7 +31,7 @@ export class EthereumConfigService {
2731

2832
get gasServiceUrl(): string {
2933
return (
30-
'https://ethgasstation.info/api/ethgasAPI.json?api-key=' +
34+
this.config.getConfig('ETH_GAS_STATION_URL') +
3135
this.config.getConfig('ETH_GAS_STATION_API_KEY')
3236
);
3337
}

src/services/fees.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ const ethGasStationHost = 'https://ethgasstation.info';
77
const globalConfig =
88
require('../services/configuration_manager').configManagerInstance;
99
const ethGasStationEnabled =
10-
globalConfig.getConfig('ETH_GAS_STATION_ENABLE') || false;
10+
globalConfig.getConfig('ENABLE_ETH_GAS_STATION') || false;
1111
const ethGasStationApiKey = globalConfig.getConfig('ETH_GAS_STATION_API_KEY');
12-
const ethManualGasPrice = parseInt(globalConfig.getConfig('ETH_MANUAL_GAS_PRICE'));
12+
const ethManualGasPrice = parseInt(globalConfig.getConfig('MANUAL_GAS_PRICE'));
1313
const ethGasStationURL =
1414
ethGasStationHost + '/api/ethgasAPI.json?api-key=' + ethGasStationApiKey;
1515
const defaultRefreshInterval = 120;

src/services/uniswap_v3.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const abiDecoder = require('abi-decoder');
1717

1818
// constants
1919
const FeeAmount = uniV3.FeeAmount;
20-
const GAS_LIMIT = globalConfig.getConfig('UNISWAP_GAS_LIMIT') || 550688;
20+
const GAS_LIMIT = globalConfig.getConfig('UNISWAP_GAS_LIMIT') || 5506880;
2121
const UPDATE_PERIOD = globalConfig.getConfig('UNISWAP_UPDATE_PERIOD') || 300000; // stop updating pair after 5 minutes from last request
2222
const MaxUint128 = ethers.BigNumber.from(2).pow(128).sub(1);
2323

@@ -178,7 +178,7 @@ export default class UniswapV3 {
178178
request[twap].value.tickCumulatives[0].toNumber()
179179
)
180180
)
181-
.toSignificant(8)
181+
.toFixed()
182182
);
183183
}
184184
}
@@ -418,10 +418,10 @@ Note that extending the uniswap v2 code may be possible in the future if uniswap
418418
fee: Object.keys(FeeAmount).find(
419419
(key) => FeeAmount[key] === position.fee
420420
),
421-
lowerPrice: positionInst.token0PriceLower.toSignificant(8),
422-
upperPrice: positionInst.token0PriceUpper.toSignificant(8),
423-
amount0: positionInst.amount0.toSignificant(8),
424-
amount1: positionInst.amount1.toSignificant(8),
421+
lowerPrice: positionInst.token0PriceLower.toFixed(8),
422+
upperPrice: positionInst.token0PriceUpper.toFixed(8),
423+
amount0: positionInst.amount0.toFixed(),
424+
amount1: positionInst.amount1.toFixed(),
425425
unclaimedToken0: ethers.utils.formatUnits(
426426
feeInfo.amount0.toString(),
427427
token0.decimals

0 commit comments

Comments
 (0)