Skip to content

Commit

Permalink
Merge branch 'development' into fix/uniswap-lp-error-225
Browse files Browse the repository at this point in the history
  • Loading branch information
nikspz authored May 16, 2024
2 parents a4dfcf3 + 2160d18 commit e5ab28c
Show file tree
Hide file tree
Showing 18 changed files with 768 additions and 585 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hummingbot-gateway",
"version": "dev-1.26.0",
"version": "dev-1.28.0",
"description": "Middleware that helps Hummingbot clients access standardized DEX API endpoints on different blockchain networks",
"main": "index.js",
"license": "Apache-2.0",
Expand Down
4 changes: 4 additions & 0 deletions src/amm/amm.requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface PriceRequest extends NetworkSelectionRequest {
amount: string;
side: Side;
allowedSlippage?: string;
poolId?: string;
}

export interface PriceResponse {
Expand All @@ -41,6 +42,7 @@ export interface PoolPriceRequest extends NetworkSelectionRequest {
fee?: string;
period?: number;
interval?: number;
poolId?: string;
}

export interface PoolPriceResponse {
Expand All @@ -67,6 +69,7 @@ export interface TradeRequest extends NetworkSelectionRequest {
maxFeePerGas?: string;
maxPriorityFeePerGas?: string;
allowedSlippage?: string;
poolId?: string;
}

export interface TradeResponse {
Expand Down Expand Up @@ -106,6 +109,7 @@ export interface AddLiquidityRequest extends NetworkSelectionRequest { // now al
maxFeePerGas?: string;
maxPriorityFeePerGas?: string;
allowedSlippage?: string; // COSMOS: used to calc TokenMinAmount
poolId?: string;
}

export interface AddLiquidityResponse {
Expand Down
14 changes: 14 additions & 0 deletions src/amm/amm.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export const invalidDecreasePercentError: string =
export const invalidAllowedSlippageError: string =
'The allowedSlippage param may be null or a string of a fraction.';

export const invalidPoolIdError: string =
'PoolId(if supplied) must be a string.';

export const validateConnector: Validator = mkValidator(
'connector',
invalidConnectorError,
Expand Down Expand Up @@ -194,6 +197,13 @@ export const validateAllowedSlippage: Validator = mkValidator(
true
);

export const validatePoolId: Validator = mkValidator(
'poolId',
invalidPoolIdError,
(val) => typeof val === 'string' && val.length !== 0,
true
);

export const validatePriceRequest: RequestValidator = mkRequestValidator([
validateConnector,
validateChain,
Expand All @@ -203,6 +213,7 @@ export const validatePriceRequest: RequestValidator = mkRequestValidator([
validateAmount,
validateSide,
validateAllowedSlippage,
validatePoolId,
]);

export const validateTradeRequest: RequestValidator = mkRequestValidator([
Expand All @@ -218,6 +229,7 @@ export const validateTradeRequest: RequestValidator = mkRequestValidator([
validateMaxFeePerGas,
validateMaxPriorityFeePerGas,
validateAllowedSlippage,
validatePoolId,
]);

export const validatePerpPositionRequest: RequestValidator = mkRequestValidator(
Expand Down Expand Up @@ -302,6 +314,7 @@ export const validateAddLiquidityRequest: RequestValidator = mkRequestValidator(
validateNonce,
validateMaxFeePerGas,
validateMaxPriorityFeePerGas,
validatePoolId,
]
);

Expand Down Expand Up @@ -345,4 +358,5 @@ export const validatePoolPriceRequest: RequestValidator = mkRequestValidator([
validateFee,
validateInterval,
validatePeriod,
validatePoolId,
]);
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const startSwagger = async () => {

export const startGateway = async () => {
const port = ConfigManagerV2.getInstance().get('server.port');
const gateway_version="dev-1.26.0"; // gateway version
const gateway_version="dev-1.28.0"
if (!ConfigManagerV2.getInstance().get('server.id')) {
ConfigManagerV2.getInstance().set(
'server.id',
Expand Down
27 changes: 17 additions & 10 deletions src/chains/ethereum/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { logger } from '../../services/logger';
import { BigNumber, Contract, Transaction, Wallet } from 'ethers';
import { EthereumBase } from './ethereum-base';
import { getEthereumConfig } from './ethereum.config';
import { PancakeSwapConfig } from '../../connectors/pancakeswap/pancakeswap.config';
import { Provider } from '@ethersproject/abstract-provider';
import { ConfigManagerV2 } from '../../services/config-manager-v2';
// import { throttleRetryWrapper } from '../../services/retry';
Expand Down Expand Up @@ -49,7 +50,7 @@ export class Ethereum extends EthereumBase implements Ethereumish {
config.manualGasPrice,
config.gasLimitTransaction,
ConfigManagerV2.getInstance().get('server.nonceDbPath'),
ConfigManagerV2.getInstance().get('server.transactionDbPath')
ConfigManagerV2.getInstance().get('server.transactionDbPath'),
);
this._chain = network;
this._nativeTokenSymbol = config.nativeCurrencySymbol;
Expand All @@ -67,7 +68,7 @@ export class Ethereum extends EthereumBase implements Ethereumish {
this.onDebugMessage(this.requestCounter.bind(this));
this._metricTimer = setInterval(
this.metricLogger.bind(this),
this.metricsLogInterval
this.metricsLogInterval,
);
this.controller = EVMController;
}
Expand Down Expand Up @@ -96,7 +97,7 @@ export class Ethereum extends EthereumBase implements Ethereumish {
this.requestCount +
' request(s) sent in last ' +
this.metricsLogInterval / 1000 +
' seconds.'
' seconds.',
);
this._requestCount = 0; // reset
}
Expand Down Expand Up @@ -151,7 +152,7 @@ export class Ethereum extends EthereumBase implements Ethereumish {

setTimeout(
this.updateGasPrice.bind(this),
this._gasPriceRefreshInterval * 1000
this._gasPriceRefreshInterval * 1000,
);
}

Expand All @@ -164,15 +165,15 @@ export class Ethereum extends EthereumBase implements Ethereumish {
let priorityFee: BigNumber = BigNumber.from('0');
if (this._chain === 'mainnet') {
priorityFee = BigNumber.from(
await this.provider.send('eth_maxPriorityFeePerGas', [])
await this.provider.send('eth_maxPriorityFeePerGas', []),
);
}
return baseFee.add(priorityFee).toNumber() * 1e-9;
}

getContract(
tokenAddress: string,
signerOrProvider?: Wallet | Provider
signerOrProvider?: Wallet | Provider,
): Contract {
return tokenAddress === MKR_ADDRESS
? new Contract(tokenAddress, abi.MKRAbi, signerOrProvider)
Expand All @@ -185,19 +186,25 @@ export class Ethereum extends EthereumBase implements Ethereumish {
let spender: string;
if (reqSpender === 'uniswap') {
spender = UniswapConfig.config.uniswapV3SmartOrderRouterAddress(
this._chain
this._chain,
);
} else if (reqSpender === 'pancakeswap') {
spender = PancakeSwapConfig.config.routerAddress(this._chain);
} else if (reqSpender === 'pancakeswapLP') {
spender = PancakeSwapConfig.config.pancakeswapV3NftManagerAddress(
this._chain,
);
} else if (reqSpender === 'sushiswap') {
spender = SushiswapConfig.config.sushiswapRouterAddress(
this.chainName,
this._chain
this._chain,
);
} else if (reqSpender === 'uniswapLP') {
spender = UniswapConfig.config.uniswapV3NftManagerAddress(this._chain);
} else if (reqSpender === 'carbonamm') {
spender = CarbonConfig.config.carbonContractsConfig(
'ethereum',
this._chain
this._chain,
).carbonControllerAddress;
} else if (reqSpender === 'perp') {
const perp = Perp.getInstance(this._chain, 'optimism');
Expand All @@ -224,7 +231,7 @@ export class Ethereum extends EthereumBase implements Ethereumish {
// cancel transaction
async cancelTx(wallet: Wallet, nonce: number): Promise<Transaction> {
logger.info(
'Canceling any existing transaction(s) with nonce number ' + nonce + '.'
'Canceling any existing transaction(s) with nonce number ' + nonce + '.',
);
return this.cancelTxWithGasPrice(wallet, nonce, this._gasPrice * 2);
}
Expand Down
11 changes: 7 additions & 4 deletions src/connectors/pancakeswap/pancakeswap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export namespace PancakeSwapConfig {
export const v2Config: V2NetworkConfig = buildConfig(
'pancakeswap',
['AMM'],
[{ chain: 'binance-smart-chain', networks: ['mainnet', 'testnet'] }],
'EVM'
[
{ chain: 'binance-smart-chain', networks: ['mainnet', 'testnet'] },
{ chain: 'ethereum', networks: ['mainnet', 'arbitrum', 'zksync'] },
],
'EVM',
);

export const config: NetworkConfig = {
Expand All @@ -27,11 +30,11 @@ export namespace PancakeSwapConfig {
maximumHops: ConfigManagerV2.getInstance().get(`pancakeswap.maximumHops`),
pancakeswapV3SmartOrderRouterAddress: (network: string) =>
ConfigManagerV2.getInstance().get(
`pancakeswap.contractAddresses.${network}.pancakeswapV3SmartOrderRouterAddress`
`pancakeswap.contractAddresses.${network}.pancakeswapV3SmartOrderRouterAddress`,
),
pancakeswapV3NftManagerAddress: (network: string) =>
ConfigManagerV2.getInstance().get(
`pancakeswap.contractAddresses.${network}.pancakeswapV3NftManagerAddress`
`pancakeswap.contractAddresses.${network}.pancakeswapV3NftManagerAddress`,
),
tradingTypes: (type: string) => {
return type === 'swap' ? ['AMM'] : ['AMM_LP'];
Expand Down
Loading

0 comments on commit e5ab28c

Please sign in to comment.