Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync gateway / gateway development -> staging 1.25.0 #283

Merged
merged 50 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
0bea44e
Initial commit
tiagofilipenunes Nov 26, 2023
f7dc80b
Update carbon CLOB
tiagofilipenunes Dec 4, 2023
2300b05
Add carbon AMM connector and tests
tiagofilipenunes Dec 6, 2023
7450339
Add carbon-sdk
tiagofilipenunes Dec 6, 2023
81cfb48
Update imports to use @bancor/carbon-sdk
tiagofilipenunes Dec 6, 2023
9256a97
Remove trailling slash
tiagofilipenunes Dec 7, 2023
474eb52
Fix carbon schema
tiagofilipenunes Dec 7, 2023
158719d
Update tests against new SDK version
tiagofilipenunes Dec 7, 2023
6ff1a0a
Improve test coverage and fix bugs
tiagofilipenunes Dec 8, 2023
3135bcc
Rename carbonAMM and fix carbonCLOB balance
tiagofilipenunes Dec 14, 2023
651f201
Update Carbon SDK
tiagofilipenunes Dec 18, 2023
9bf62fc
Update yarn.lock
tiagofilipenunes Dec 18, 2023
91cace4
Merge branch 'main' into tiagofilipenunes-feat/carbondefi
tiagofilipenunes Dec 18, 2023
76d183b
Change name in Carbon AMM test
tiagofilipenunes Dec 19, 2023
d1c5a25
Add carbon-sdk import paths to jest config (jestjs/jest#12270)
tiagofilipenunes Dec 19, 2023
4633fe0
Clean-up Carbon CLOB tests
tiagofilipenunes Dec 19, 2023
083d467
Clean-up Carbon AMM tests
tiagofilipenunes Dec 19, 2023
7ee79ae
Clean-up constructors
tiagofilipenunes Dec 20, 2023
5ae7294
Update balances to remove decimals and count from multiple user strat…
tiagofilipenunes Dec 22, 2023
a2ffd6e
Add test to balances endpoint
tiagofilipenunes Dec 22, 2023
ef04db2
Merge branch 'main' into tiagofilipenunes-feat/carbondefi
tiagofilipenunes Jan 9, 2024
2b96eee
Move tests to test-bronze folder
tiagofilipenunes Jan 9, 2024
c4cc494
Add ETH tests
tiagofilipenunes Jan 9, 2024
b249d5b
Add native token to getTokenByAddress
tiagofilipenunes Jan 9, 2024
143ea6b
Add carbon controllers
tiagofilipenunes Jan 9, 2024
b464c89
Add carbon controllers to amm controllers
tiagofilipenunes Jan 9, 2024
98102fe
Remove CarbonCLOB
tiagofilipenunes Jan 9, 2024
ac7d235
Bump follow-redirects from 1.15.2 to 1.15.4
dependabot[bot] Jan 10, 2024
5486faf
Merge branch 'development' into dependabot/npm_and_yarn/follow-redire…
fengtality Jan 17, 2024
cd7f1f4
update gateway development version to dev-1.25.0
Jan 30, 2024
5d8ea6b
Add market order + fix connector not load markets at init time
mlguys Jan 30, 2024
e451c05
Fix market order + update token and market list
mlguys Jan 31, 2024
be48279
Merge branch 'development' into feat/xrpl-improvement-jan-26
mlguys Jan 31, 2024
695facb
Merge branch 'development' into tiagofilipenunes-feat/carbondefi
tiagofilipenunes Feb 1, 2024
1a963d9
Merge branch 'development' into dependabot/npm_and_yarn/follow-redire…
fengtality Feb 1, 2024
955d665
Merge pull request #275 from hummingbot/update_dev-1.25.0
rapcmia Feb 2, 2024
6431b0e
fix/ Update package.json to dev-1.25.0
nikspz Feb 2, 2024
00a91a6
Merge pull request #279 from hummingbot/Update-package.json-to-dev-1.…
nikspz Feb 2, 2024
bc7310b
Merge pull request #256 from bancorprotocol/tiagofilipenunes-feat/car…
fengtality Feb 2, 2024
2e61f64
Merge pull request #265 from hummingbot/dependabot/npm_and_yarn/follo…
fengtality Feb 2, 2024
fea1707
Merge branch 'development' into feat/xrpl-improvement-jan-26
rapcmia Feb 7, 2024
6590cb9
Add convertStringToHex function and update markets list
mlguys Feb 12, 2024
72ba6e2
Update XRPL network timeouts
mlguys Feb 12, 2024
71efd74
Convert string to uppercase in convertStringToHex function
mlguys Feb 15, 2024
f1b369a
Merge pull request #278 from hummingbot/feat/xrpl-improvement-jan-26
fengtality Feb 16, 2024
1c9a498
add retry and set submittx to submit and wait
mlguys Feb 18, 2024
527d8a5
Increase batch for fetching markets
mlguys Feb 18, 2024
6cda2dd
Merge branch 'staging' into development
nikspz Feb 19, 2024
0930e3c
Merge branch 'development' into fix/xrpl-add-retry-and-wait-for-submit
fengtality Feb 19, 2024
b8d9764
Merge pull request #282 from hummingbot/fix/xrpl-add-retry-and-wait-f…
fengtality Feb 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'],
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hummingbot-gateway",
"version": "1.24.0",
"version": "dev-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 Expand Up @@ -163,4 +164,4 @@
"resolutions": {
"web3-utils": "1.7.3"
}
}
}
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="dev-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
Loading