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 / staging to main gateway 1.21.0 #221

Merged
merged 27 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cd8fef9
(fix) prevent multiple init() calls in eth base
OjusWiZard Sep 2, 2023
98b9006
(fix) prevent multiple init() calls in inj base
OjusWiZard Sep 2, 2023
e3c5c89
(fix) prevent multiple init() calls in near base
OjusWiZard Sep 2, 2023
e885379
(fix) prevent multiple init() calls in tezos base
OjusWiZard Sep 2, 2023
494c500
(fix) prevent multiple init() calls in xdc base
OjusWiZard Sep 2, 2023
a93669a
(fix) prevent multiple init() calls in cosmos base
OjusWiZard Sep 2, 2023
1f778ea
(fix) add tests: preventing multiple init() calls
OjusWiZard Sep 3, 2023
1772a60
Merge branch 'development' into fix/#164
nikspz Sep 4, 2023
dfeb2cd
Merge branch 'development' into fix/#164
nikspz Sep 15, 2023
c3ec250
Merge branch 'development' into fix/#164
nikspz Sep 25, 2023
ded0af9
fix/Update version on gateway development
nikspz Oct 2, 2023
66ad22f
Update app.ts
nikspz Oct 2, 2023
0cd3ab8
Merge pull request #210 from hummingbot/fix/Update-version-on-gateway…
nikspz Oct 2, 2023
f4c777f
Merge branch 'development' into fix/#164
rapcmia Oct 6, 2023
0ff07f7
Merge pull request #197 from OjusWiZard/fix/#164
nikspz Oct 16, 2023
82adbc2
(fix) remove defira connector
fengtality Oct 21, 2023
3594360
Bump @babel/traverse from 7.21.3 to 7.23.2
dependabot[bot] Oct 21, 2023
2f867b7
Merge branch 'development' into dependabot/npm_and_yarn/babel/travers…
fengtality Oct 21, 2023
68b0efc
Merge pull request #213 from hummingbot/dependabot/npm_and_yarn/babel…
fengtality Oct 21, 2023
76f7921
fixed yarn.lock conflicts
fengtality Oct 23, 2023
999094a
Merge pull request #216 from hummingbot/development
nikspz Oct 23, 2023
7b009f1
update gateway version to 1.21.0
Oct 24, 2023
8aaf353
Merge pull request #217 from hummingbot/update-staging-v1.21.0
rapcmia Oct 24, 2023
97b17f6
Merge pull request #214 from hummingbot/fix/remove-connectors
rapcmia Oct 26, 2023
3f77898
Merge pull request #220 from hummingbot/development
nikspz Oct 26, 2023
8a0658e
fix/Update package.json
nikspz Oct 30, 2023
1170c85
Merge pull request #224 from hummingbot/update-version
rapcmia Oct 30, 2023
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
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module.exports = {
'src/connectors/uniswap/uniswap.config.ts',
'src/connectors/uniswap/uniswap.ts',
'src/connectors/uniswap/uniswap.lp.helper.ts',
'src/connectors/defira/defira.ts',
'src/connectors/openocean/openocean.ts',
'src/connectors/pangolin/pangolin.ts',
'src/chains/injective/injective.mappers.ts',
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hummingbot-gateway",
"version": "1.20.0",
"version": "1.21.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 Expand Up @@ -59,7 +59,6 @@
"@uniswap/v3-core": "^1.0.0",
"@uniswap/v3-periphery": "^1.1.1",
"@uniswap/v3-sdk": "^3.7.0",
"@zuzu-cat/defira-sdk": "^1.0.0",
"abi-decoder": "^2.4.0",
"ajv": "^8.6.3",
"algosdk": "^2.2.0",
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.20.0"; // gateway version
const gateway_version="1.21.0"; // gateway version
if (!ConfigManagerV2.getInstance().get('server.id')) {
ConfigManagerV2.getInstance().set(
'server.id',
Expand Down
28 changes: 16 additions & 12 deletions src/chains/cosmos/cosmos-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { BigNumber } from 'ethers';
import { AccountData, DirectSignResponse } from '@cosmjs/proto-signing';

import { IndexedTx, setupIbcExtension } from '@cosmjs/stargate';
import { logger } from '../../services/logger';

//Cosmos
const { DirectSecp256k1Wallet } = require('@cosmjs/proto-signing');
Expand Down Expand Up @@ -58,8 +59,7 @@ export class CosmosBase {
private _tokenMap: Record<string, Token> = {};

private _ready: boolean = false;
private _initializing: boolean = false;
private _initPromise: Promise<void> = Promise.resolve();
private _initialized: Promise<boolean> = Promise.resolve(false);

public chainName;
public rpcUrl;
Expand Down Expand Up @@ -93,17 +93,21 @@ export class CosmosBase {
}

async init(): Promise<void> {
if (!this.ready() && !this._initializing) {
this._initializing = true;
this._initPromise = this.loadTokens(
this.tokenListSource,
this.tokenListType
).then(() => {
this._ready = true;
this._initializing = false;
});
await this._initialized; // Wait for any previous init() calls to complete
if (!this.ready()) {
// If we're not ready, this._initialized will be a Promise that resolves after init() completes
this._initialized = (async () => {
try {
await this.loadTokens(this.tokenListSource, this.tokenListType)
return true;
} catch (e) {
logger.error(`Failed to initialize ${this.chainName} chain: ${e}`);
return false;
}
})();
this._ready = await this._initialized; // Wait for the initialization to complete
}
return this._initPromise;
return;
}

async loadTokens(
Expand Down
48 changes: 28 additions & 20 deletions src/chains/ethereum/ethereum-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class EthereumBase {
private _tokenMap: Record<string, TokenInfo> = {};
// there are async values set in the constructor
private _ready: boolean = false;
private _initializing: boolean = false;
private _initialized: Promise<boolean> = Promise.resolve(false);
public chainName;
public chainId;
public rpcUrl;
Expand Down Expand Up @@ -121,14 +121,22 @@ export class EthereumBase {
}

async init(): Promise<void> {
if (!this.ready() && !this._initializing) {
this._initializing = true;
await this._nonceManager.init(
async (address) => await this.provider.getTransactionCount(address)
);
await this.loadTokens(this.tokenListSource, this.tokenListType);
this._ready = true;
this._initializing = false;
await this._initialized; // Wait for any previous init() calls to complete
if (!this.ready()) {
// If we're not ready, this._initialized will be a Promise that resolves after init() completes
this._initialized = (async () => {
try {
await this._nonceManager.init(
async (address) => await this.provider.getTransactionCount(address)
);
await this.loadTokens(this.tokenListSource, this.tokenListType);
return true;
} catch (e) {
logger.error(`Failed to initialize ${this.chainName} chain: ${e}`);
return false;
}
})();
this._ready = await this._initialized; // Wait for the initialization to complete
}
return;
}
Expand Down Expand Up @@ -241,7 +249,7 @@ export class EthereumBase {
const balance: BigNumber = await contract.balanceOf(wallet.address);
logger.info(
`Raw balance of ${contract.address} for ` +
`${wallet.address}: ${balance.toString()}`
`${wallet.address}: ${balance.toString()}`
);
return { value: balance, decimals: decimals };
}
Expand All @@ -255,10 +263,10 @@ export class EthereumBase {
): Promise<TokenValue> {
logger.info(
'Requesting spender ' +
spender +
' allowance for owner ' +
wallet.address +
'.'
spender +
' allowance for owner ' +
wallet.address +
'.'
);
const allowance = await contract.allowance(wallet.address, spender);
logger.info(allowance);
Expand Down Expand Up @@ -311,12 +319,12 @@ export class EthereumBase {
): Promise<Transaction> {
logger.info(
'Calling approve method called for spender ' +
spender +
' requesting allowance ' +
amount.toString() +
' from owner ' +
wallet.address +
'.'
spender +
' requesting allowance ' +
amount.toString() +
' from owner ' +
wallet.address +
'.'
);
return this.nonceManager.provideNonce(
nonce,
Expand Down
1 change: 0 additions & 1 deletion src/chains/ethereum/ethereum.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const validateSpender: Validator = mkValidator(
val === 'viperswap' ||
val === 'openocean' ||
val === 'quickswap' ||
val === 'defira' ||
val === 'mad_meerkat' ||
val === 'vvs' ||
val === 'pancakeswap' ||
Expand Down
4 changes: 1 addition & 3 deletions src/chains/harmony/harmony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ export class Harmony extends EthereumBase implements Ethereumish {

getSpender(reqSpender: string): string {
let spender: string;
if (reqSpender === 'defira') {
spender = '0x3C8BF7e25EbfAaFb863256A4380A8a93490d8065';
} else if (reqSpender === 'openocean') {
if (reqSpender === 'openocean') {
spender = OpenoceanConfig.config.routerAddress('ethereum', this._chain);
} else if (reqSpender === 'sushiswap') {
spender = SushiswapConfig.config.sushiswapRouterAddress(
Expand Down
5 changes: 1 addition & 4 deletions src/chains/harmony/harmony.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ export const validateSpender: Validator = mkValidator(
invalidSpenderError,
(val) =>
typeof val === 'string' &&
(val === 'sushiswap' ||
val === 'defira' ||
val === 'openocean' ||
isValidAddress(val))
(val === 'sushiswap' || val === 'openocean' || isValidAddress(val))
);

export const validateNonce: Validator = mkValidator(
Expand Down
90 changes: 49 additions & 41 deletions src/chains/injective/injective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export interface InjectiveWallet {
export class Injective {
private static _instances: LRUCache<string, Injective>;
private _ready: boolean = false;
private _initializing: boolean = false;
private _initialized: Promise<boolean> = Promise.resolve(false);

private _network: Network;
private _chainId: ChainId;
Expand Down Expand Up @@ -152,48 +152,56 @@ export class Injective {
}

public async init(): Promise<void> {
if (!this.ready() && !this._initializing) {
this._initializing = true;
// initialize nonce manager
await this._nonceManager.init(
async (address: string) => await this.getTransactionCount(address)
);
// start updating block number
this._blockUpdateIntervalID = setInterval(async () => {
await this.updateCurrentBlockNumber();
}, 2000) as unknown as number;

// get tokens
const rawMarkets = await this._spotApi.fetchMarkets();
for (const market of rawMarkets) {
if (market.baseToken) {
const token = {
address: '',
chainId: chainIdToInt(this._chainId),
name: market.baseToken.name,
decimals: market.baseToken.decimals,
symbol: market.baseToken.symbol,
denom: market.baseDenom,
};
this._symbolToToken[market.baseToken.symbol] = token;
this._denomToToken[market.baseDenom] = token;
}
await this._initialized; // Wait for any previous init() calls to complete
if (!this.ready()) {
// If we're not ready, this._initialized will be a Promise that resolves after init() completes
this._initialized = (async () => {
try {
// initialize nonce manager
await this._nonceManager.init(
async (address: string) => await this.getTransactionCount(address)
);
// start updating block number
this._blockUpdateIntervalID = setInterval(async () => {
await this.updateCurrentBlockNumber();
}, 2000) as unknown as number;

// get tokens
const rawMarkets = await this._spotApi.fetchMarkets();
for (const market of rawMarkets) {
if (market.baseToken) {
const token = {
address: '',
chainId: chainIdToInt(this._chainId),
name: market.baseToken.name,
decimals: market.baseToken.decimals,
symbol: market.baseToken.symbol,
denom: market.baseDenom,
};
this._symbolToToken[market.baseToken.symbol] = token;
this._denomToToken[market.baseDenom] = token;
}

if (market.quoteToken) {
const token = {
address: '',
chainId: chainIdToInt(this._chainId),
name: market.quoteToken.name,
decimals: market.quoteToken.decimals,
symbol: market.quoteToken.symbol,
denom: market.quoteDenom,
};
this._symbolToToken[market.quoteToken.symbol] = token;
this._denomToToken[market.quoteDenom] = token;
if (market.quoteToken) {
const token = {
address: '',
chainId: chainIdToInt(this._chainId),
name: market.quoteToken.name,
decimals: market.quoteToken.decimals,
symbol: market.quoteToken.symbol,
denom: market.quoteDenom,
};
this._symbolToToken[market.quoteToken.symbol] = token;
this._denomToToken[market.quoteDenom] = token;
}
}
return true;
} catch (e) {
logger.error(`Failed to initialize ${this.chainName} chain: ${e}`);
return false;
}
this._ready = true;
this._initializing = false;
}
})();
this._ready = await this._initialized; // Wait for the initialization to complete
}
return;
}
Expand Down
34 changes: 20 additions & 14 deletions src/chains/near/near.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export class NearBase {
private _tokenMap: Record<string, TokenInfo> = {};
// there are async values set in the constructor
private _ready: boolean = false;
private _initializing: boolean = false;
private _initPromise: Promise<void> = Promise.resolve();
private _initialized: Promise<boolean> = Promise.resolve(false);
private _keyStore: keyStores.InMemoryKeyStore;
private _connection: Near | undefined;

Expand Down Expand Up @@ -107,18 +106,25 @@ export class NearBase {
}

async init(): Promise<void> {
if (!this.ready() && !this._initializing) {
this._initializing = true;
this._connection = await this.connectProvider();
this._initPromise = this.loadTokens(
this.tokenListSource,
this.tokenListType
).then(() => {
this._ready = true;
this._initializing = false;
});
await this._initialized; // Wait for any previous init() calls to complete
if (!this.ready()) {
// If we're not ready, this._initialized will be a Promise that resolves after init() completes
this._initialized = (async () => {
try {
this._connection = await this.connectProvider();
await this.loadTokens(
this.tokenListSource,
this.tokenListType
)
return true;
} catch (e) {
logger.error(`Failed to initialize ${this.chainName} chain: ${e}`);
return false;
}
})();
this._ready = await this._initialized; // Wait for the initialization to complete
}
return this._initPromise;
return;
}

async connectProvider(): Promise<Near> {
Expand Down Expand Up @@ -260,7 +266,7 @@ export class NearBase {
}
logger.info(
`Raw balance of ${contract.contractId} for ` +
`${contract.account.accountId}: ${balance}`
`${contract.account.accountId}: ${balance}`
);
return balance;
}
Expand Down
Loading
Loading