Skip to content

Commit

Permalink
Merge pull request #287 from hummingbot/staging
Browse files Browse the repository at this point in the history
sync gateway / staging -> master for gateway Hummingbot version 1.25.0
  • Loading branch information
nikspz authored Feb 26, 2024
2 parents be368ed + 8a6a7f4 commit 77c682f
Show file tree
Hide file tree
Showing 27 changed files with 4,264 additions and 278 deletions.
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ module.exports = {
globalTeardown: '<rootDir>/test/teardown.ts',
moduleNameMapper: {
eccrypto: '<rootDir>/test/mock/eccrypto-mock.js',
// Add carbon sdk subpath imports that are unsupported until jest v29.4.0
'@bancor/carbon-sdk/strategy-management':
'<rootDir>/node_modules/@bancor/carbon-sdk/dist/strategy-management/index.cjs',
'@bancor/carbon-sdk/utils':
'<rootDir>/node_modules/@bancor/carbon-sdk/dist/utils/index.cjs',
'@bancor/carbon-sdk/contracts-api':
'<rootDir>/node_modules/@bancor/carbon-sdk/dist/contracts-api/index.cjs',
'@bancor/carbon-sdk/chain-cache':
'<rootDir>/node_modules/@bancor/carbon-sdk/dist/chain-cache/index.cjs',
},
testPathIgnorePatterns: ['/node_modules/', 'test-helpers'],
};
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": "1.24.0",
"version": "1.25.0",
"description": "Middleware that helps Hummingbot clients access standardized DEX API endpoints on different blockchain networks",
"main": "index.js",
"license": "Apache-2.0",
Expand All @@ -23,6 +23,7 @@
"test:scripts": "jest -i --verbose ./test-scripts/*.test.ts"
},
"dependencies": {
"@bancor/carbon-sdk": "^0.0.93-DEV",
"@cosmjs/proto-signing": "^0.31.1",
"@cosmjs/stargate": "^0.31.1",
"@crocswap/sdk": "^2.4.5",
Expand Down
12 changes: 12 additions & 0 deletions src/amm/amm.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ import {
poolPrice as uniswapV3PoolPrice,
estimateGas as uniswapEstimateGas,
} from '../connectors/uniswap/uniswap.controllers';
import {
price as carbonPrice,
trade as carbonTrade,
estimateGas as carbonEstimateGas,
} from '../connectors/carbon/carbon.controllers';
import {
price as refPrice,
trade as refTrade,
Expand Down Expand Up @@ -81,6 +86,7 @@ import { Algorand } from '../chains/algorand/algorand';
import { Tinyman } from '../connectors/tinyman/tinyman';
import { Plenty } from '../connectors/plenty/plenty';
import { QuipuSwap } from '../connectors/quipuswap/quipuswap';
import { Carbonamm } from '../connectors/carbon/carbonAMM';

export async function price(req: PriceRequest): Promise<PriceResponse> {
const chain = await getInitializedChain<
Expand All @@ -97,6 +103,8 @@ export async function price(req: PriceRequest): Promise<PriceResponse> {
return plentyPrice(<Tezosish>chain, connector, req);
} else if (connector instanceof QuipuSwap) {
return quipuPrice(<Tezosish>chain, connector, req);
} else if (connector instanceof Carbonamm) {
return carbonPrice(<Ethereumish>chain, connector, req);
} else if ('routerAbi' in connector) {
// we currently use the presence of routerAbi to distinguish Uniswapish from RefAMMish
return uniswapPrice(<Ethereumish>chain, connector, req);
Expand All @@ -122,6 +130,8 @@ export async function trade(req: TradeRequest): Promise<TradeResponse> {
return plentyTrade(<Tezosish>chain, connector, req);
} else if (connector instanceof QuipuSwap) {
return quipuTrade(<Tezosish>chain, connector, req);
} else if (connector instanceof Carbonamm) {
return carbonTrade(<Ethereumish>chain, connector, req);
} else if ('routerAbi' in connector) {
// we currently use the presence of routerAbi to distinguish Uniswapish from RefAMMish
return uniswapTrade(<Ethereumish>chain, connector, req);
Expand Down Expand Up @@ -211,6 +221,8 @@ export async function estimateGas(
return plentyEstimateGas(<Tezosish>chain, connector);
} else if (connector instanceof QuipuSwap) {
return quipuEstimateGas(<Tezosish>chain, connector);
} else if (connector instanceof Carbonamm) {
return carbonEstimateGas(<Ethereumish>chain, connector);
} else if ('routerAbi' in connector) {
// we currently use the presence of routerAbi to distinguish Uniswapish from RefAMMish
return uniswapEstimateGas(<Ethereumish>chain, connector);
Expand Down
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="1.24.0"; // gateway version
const gateway_version="1.25.0"; // gateway version
if (!ConfigManagerV2.getInstance().get('server.id')) {
ConfigManagerV2.getInstance().set(
'server.id',
Expand Down
6 changes: 6 additions & 0 deletions src/chains/ethereum/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Perp } from '../../connectors/perp/perp';
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';

// MKR does not match the ERC20 perfectly so we need to use a separate ABI.
const MKR_ADDRESS = '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2';
Expand Down Expand Up @@ -188,6 +189,11 @@ export class Ethereum extends EthereumBase implements Ethereumish {
);
} else if (reqSpender === 'uniswapLP') {
spender = UniswapConfig.config.uniswapV3NftManagerAddress(this._chain);
} else if (reqSpender === 'carbonamm') {
spender = CarbonConfig.config.carbonContractsConfig(
'ethereum',
this._chain
).carbonControllerAddress;
} else if (reqSpender === 'perp') {
const perp = Perp.getInstance(this._chain, 'optimism');
if (!perp.ready()) {
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 @@ -63,6 +63,7 @@ export const validateSpender: Validator = mkValidator(
val === 'pancakeswapLP' ||
val === 'xsswap' ||
val === 'curve' ||
val === 'carbonamm' ||
isAddress(val))
);

Expand Down
43 changes: 27 additions & 16 deletions src/chains/xrpl/xrpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { rootPath } from '../../paths';
import { TokenListType, walletPath, MarketListType } from '../../services/base';
import { ConfigManagerCertPassphrase } from '../../services/config-manager-cert-passphrase';
import { getXRPLConfig } from './xrpl.config';
// import { logger } from '../../services/logger';
import { logger } from '../../services/logger';
import { TransactionResponseStatusCode, TokenBalance } from './xrpl.requests';
import { XRPLOrderStorage } from './xrpl.order-storage';
import { OrderTracker } from './xrpl.order-tracker';
Expand All @@ -45,8 +45,6 @@ export type MarketInfo = {
baseCode: string;
quoteIssuer: string;
quoteCode: string;
baseTokenID: number;
quoteTokenID: number;
};

export type Fee = {
Expand All @@ -56,6 +54,9 @@ export type Fee = {
openLedger: string;
};

const MAX_POLL_RETRY = 5;
const POLL_RETRY_INTERVAL = 300;

export class XRPL implements XRPLish {
private static _instances: { [name: string]: XRPL };
public rpcUrl;
Expand Down Expand Up @@ -219,6 +220,8 @@ export class XRPL implements XRPLish {
this.tokenList = await this.getTokenList(tokenListSource, tokenListType);
if (this.tokenList) {
this.tokenList.forEach((token: XRPTokenInfo) => {
//TODO: There are duplicate codes with different issuer,
// find way to resolve this.
if (!this._tokenMap[token.code]) {
this._tokenMap[token.code] = [];
}
Expand Down Expand Up @@ -284,12 +287,7 @@ export class XRPL implements XRPLish {
}

public getTokenForSymbol(code: string): XRPTokenInfo[] | undefined {
let query = code;

// Special case for SOLO on mainnet
if (code === 'SOLO') {
query = '534F4C4F00000000000000000000000000000000';
}
let query = convertHexToString(code);

return this._tokenMap[query] ? this._tokenMap[query] : undefined;
}
Expand Down Expand Up @@ -510,15 +508,28 @@ export class XRPL implements XRPLish {

async getTransaction(txHash: string): Promise<TxResponse> {
await this.ensureConnection();
const tx_resp = await this._client.request({
command: 'tx',
transaction: txHash,
binary: false,
});
let retryCount = 0;
let result: any = undefined;
while (retryCount < MAX_POLL_RETRY && result === undefined) {
try {
const tx_resp = await this._client.request({
command: 'tx',
transaction: txHash,
binary: false,
});

const result = tx_resp;
result = tx_resp;
} catch (error) {
retryCount++;
if (retryCount >= 5) {
throw new Error(`Transaction ${txHash} not found, error: ` + String(error));
}
logger.info(`Transaction ${txHash} not found, retrying ${retryCount}/${MAX_POLL_RETRY}...`);
await new Promise(resolve => setTimeout(resolve, POLL_RETRY_INTERVAL)); // Add delay
}
}

return result;
return result as TxResponse;
}

async close() {
Expand Down
4 changes: 3 additions & 1 deletion src/clob/clob.requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import {
PerpetualMarket,
Position,
} from '@injectivelabs/sdk-ts';
import { OrderType, Side } from '../amm/amm.requests';
import { NetworkSelectionRequest } from '../services/common-interfaces';

export type OrderType = 'LIMIT' | 'LIMIT_MAKER' | 'MARKET';
export type Side = 'BUY' | 'SELL';

export interface ClobMarketsRequest extends NetworkSelectionRequest {
market?: string;
}
Expand Down
58 changes: 58 additions & 0 deletions src/connectors/carbon/carbon.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { ContractsConfig } from '@bancor/carbon-sdk/contracts-api';
import { MatchType } from '@bancor/carbon-sdk';
import { AvailableNetworks } from '../../services/config-manager-types';
import { ConfigManagerV2 } from '../../services/config-manager-v2';

export namespace CarbonConfig {
export interface NetworkConfig {
allowedSlippage: string;
gasLimitEstimate: number;
ttl: number;
tradingTypes: Array<string>;
chainType: string;
matchType: MatchType;
availableNetworks: Array<AvailableNetworks>;
carbonContractsConfig: (
chain: string,
network: string
) => Required<ContractsConfig>;
}

export const config: NetworkConfig = {
allowedSlippage: ConfigManagerV2.getInstance().get(
`carbon.allowedSlippage`
),
gasLimitEstimate: ConfigManagerV2.getInstance().get(
`carbon.gasLimitEstimate`
),
ttl: ConfigManagerV2.getInstance().get(`carbon.ttl`),
tradingTypes: ['AMM'],
chainType: 'EVM',
matchType: MatchType.Fast,
availableNetworks: [
{
chain: 'ethereum',
networks: Object.keys(
ConfigManagerV2.getInstance().get('carbon.contractAddresses.ethereum')
).filter((network) =>
Object.keys(
ConfigManagerV2.getInstance().get('ethereum.networks')
).includes(network)
),
},
],
carbonContractsConfig: (chain: string, network: string) => {
return {
carbonControllerAddress: ConfigManagerV2.getInstance().get(
`carbon.contractAddresses.${chain}.${network}.carbonControllerAddress`
),
multiCallAddress: ConfigManagerV2.getInstance().get(
`carbon.contractAddresses.${chain}.${network}.multiCallAddress`
),
voucherAddress: ConfigManagerV2.getInstance().get(
`carbon.contractAddresses.${chain}.${network}.voucherAddress`
),
};
},
};
}
Loading

0 comments on commit 77c682f

Please sign in to comment.