Skip to content

Commit

Permalink
Merge branch 'hummingbot:development' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
chasevoorhees authored Jul 13, 2024
2 parents 622e284 + 22fbbe0 commit c02bb28
Show file tree
Hide file tree
Showing 32 changed files with 2,037 additions and 602 deletions.
3 changes: 2 additions & 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-2.0.1",
"description": "Middleware that helps Hummingbot clients access standardized DEX API endpoints on different blockchain networks",
"main": "index.js",
"license": "Apache-2.0",
Expand All @@ -24,6 +24,7 @@
},
"dependencies": {
"@cosmjs/amino": "^0.32.2",
"@balancer-labs/sdk": "^1.1.5",
"@bancor/carbon-sdk": "^0.0.93-DEV",
"@cosmjs/proto-signing": "^0.31.1",
"@cosmjs/stargate": "^0.31.1",
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-2.0.1"
if (!ConfigManagerV2.getInstance().get('server.id')) {
ConfigManagerV2.getInstance().set(
'server.id',
Expand Down
3 changes: 3 additions & 0 deletions src/chains/avalanche/avalanche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SushiswapConfig } from '../../connectors/sushiswap/sushiswap.config';
import { ConfigManagerV2 } from '../../services/config-manager-v2';
import { EVMController } from '../ethereum/evm.controllers';
import { Curve } from '../../connectors/curve/curve';
import { BalancerConfig } from '../../connectors/balancer/balancer.config';

export class Avalanche extends EthereumBase implements Ethereumish {
private static _instances: { [name: string]: Avalanche };
Expand Down Expand Up @@ -101,6 +102,8 @@ export class Avalanche extends EthereumBase implements Ethereumish {
throw Error('Curve not ready');
}
spender = curve.router;
} else if (reqSpender === 'balancer') {
spender = BalancerConfig.config.routerAddress(this._chain);
} else {
spender = reqSpender;
}
Expand Down
1 change: 1 addition & 0 deletions src/chains/avalanche/avalanche.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const validateSpender: Validator = mkValidator(
val === 'traderjoe' ||
val === 'openocean' ||
val === 'sushiswap' ||
val === 'balancer' ||
isAddress(val))
);

Expand Down
30 changes: 20 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 All @@ -15,6 +16,7 @@ import { SushiswapConfig } from '../../connectors/sushiswap/sushiswap.config';
import { OpenoceanConfig } from '../../connectors/openocean/openocean.config';
import { Curve } from '../../connectors/curve/curve';
import { CarbonConfig } from '../../connectors/carbon/carbon.config';
import { BalancerConfig } from '../../connectors/balancer/balancer.config';

// MKR does not match the ERC20 perfectly so we need to use a separate ABI.
const MKR_ADDRESS = '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2';
Expand Down Expand Up @@ -48,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 @@ -66,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 @@ -95,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 @@ -146,7 +148,7 @@ export class Ethereum extends EthereumBase implements Ethereumish {

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

Expand All @@ -159,15 +161,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 @@ -180,19 +182,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 @@ -210,6 +218,8 @@ export class Ethereum extends EthereumBase implements Ethereumish {
throw Error('Curve not ready');
}
spender = curve.router;
} else if (reqSpender === 'balancer') {
spender = BalancerConfig.config.routerAddress(this._chain);
} else {
spender = reqSpender;
}
Expand All @@ -219,7 +229,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
1 change: 1 addition & 0 deletions src/chains/ethereum/ethereum.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const validateSpender: Validator = mkValidator(
val === 'xsswap' ||
val === 'curve' ||
val === 'carbonamm' ||
val === 'balancer' ||
isAddress(val))
);

Expand Down
3 changes: 3 additions & 0 deletions src/chains/polygon/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ConfigManagerV2 } from '../../services/config-manager-v2';
import { OpenoceanConfig } from '../../connectors/openocean/openocean.config';
import { EVMController } from '../ethereum/evm.controllers';
import { Curve } from '../../connectors/curve/curve';
import { BalancerConfig } from '../../connectors/balancer/balancer.config';

export class Polygon extends EthereumBase implements Ethereumish {
private static _instances: { [name: string]: Polygon };
Expand Down Expand Up @@ -94,6 +95,8 @@ export class Polygon extends EthereumBase implements Ethereumish {
throw Error('Curve not ready');
}
spender = curve.router;
} else if (reqSpender === 'balancer') {
spender = BalancerConfig.config.routerAddress(this._chain);
} else {
spender = reqSpender;
}
Expand Down
1 change: 1 addition & 0 deletions src/chains/polygon/polygon.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const validateSpender: Validator = mkValidator(
val === 'sushi' ||
val === 'quickswap' ||
val === 'openocean' ||
val === 'balancer' ||
isAddress(val))
);

Expand Down
23 changes: 23 additions & 0 deletions src/connectors/balancer/balancer.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { buildConfig, NetworkConfig } from '../../network/network.utils';

export namespace BalancerConfig {
export const config: NetworkConfig = buildConfig(
'balancer',
['AMM'],
[
{
chain: 'avalanche',
networks: ['avalanche'],
},
{
chain: 'ethereum',
networks: ['mainnet', 'arbitrum', 'optimism'],
},
{
chain: 'polygon',
networks: ['mainnet'],
},
],
'EVM'
);
}
Loading

0 comments on commit c02bb28

Please sign in to comment.