Skip to content

Commit

Permalink
Merge pull request #206 from hummingbot/staging
Browse files Browse the repository at this point in the history
sync gateway / gateway staging -> master for Hummingbot version 1.20.0
  • Loading branch information
nikspz committed Oct 2, 2023
2 parents 37d7c04 + 318c5f9 commit 8f4b983
Show file tree
Hide file tree
Showing 29 changed files with 35,359 additions and 410 deletions.
17 changes: 13 additions & 4 deletions gateway-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,28 @@ copy_certs () {
read -p "Enter path to the Hummingbot certs folder >>> " CERTS_FROM_PATH
if [ ! -d "$CERTS_FROM_PATH" ]; then
echo "Error: $CERTS_FROM_PATH does not exist or is not a directory"
exit
exit 1
fi

# Check if there are any .pem files in the source directory
PEM_COUNT=$(find "$CERTS_FROM_PATH" -maxdepth 1 -name "*.pem" | wc -l)
if [ "$PEM_COUNT" -eq 0 ]; then
echo "Error: No .pem files found in $CERTS_FROM_PATH"
exit 1
fi

# Make destination folder if needed
mkdir $CERTS_TO_PATH
mkdir -p $CERTS_TO_PATH

# Copy all files in the source folder to the destination folder
cp -r $CERTS_FROM_PATH/* $CERTS_TO_PATH/

# Confirm that the files were copied
if [ $? -eq 0 ]; then
echo "Files successfully copied from $CERTS_FROM_PATH to $CERTS_TO_PATH"
else
echo "Error copying files from $CERTS_FROM_PATH to $CERTS_TO_PATH"
exit
exit 1
fi
}

Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hummingbot-gateway",
"version": "1.19.0",
"version": "1.20.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,8 +23,8 @@
"test:scripts": "jest -i --verbose ./test-scripts/*.test.ts"
},
"dependencies": {
"@cosmjs/proto-signing": "^0.28.10",
"@cosmjs/stargate": "^0.28.13",
"@cosmjs/proto-signing": "^0.30.1",
"@cosmjs/stargate": "^0.30.1",
"@crocswap/sdk": "^2.4.5",
"@ethersproject/abstract-provider": "5.7.0",
"@ethersproject/address": "5.7.0",
Expand Down Expand Up @@ -77,7 +77,10 @@
"express": "^4.17.1",
"express-winston": "^4.1.0",
"fs-extra": "^10.0.0",
"http-status-codes": "2.2.0",
"immutable": "^4.2.4",
"js-yaml": "^4.1.0",
"kujira.js": "^0.8.145",
"level": "^8.0.0",
"lodash": "^4.17.21",
"lru-cache": "^7.14.1",
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.19.0"; // gateway version
const gateway_version="1.20.0"; // gateway version
if (!ConfigManagerV2.getInstance().get('server.id')) {
ConfigManagerV2.getInstance().set(
'server.id',
Expand Down
231 changes: 231 additions & 0 deletions src/chains/kujira/kujira.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
import { KujiraModel } from '../../connectors/kujira/kujira.model';
import { convertToGetTokensResponse } from '../../connectors/kujira/kujira.convertors';
import { KujiraConfig } from '../../connectors/kujira/kujira.config';
import {
Address,
GetCurrentBlockRequest,
GetCurrentBlockResponse,
Token,
} from '../../connectors/kujira/kujira.types';
import { TokenInfo } from '../ethereum/ethereum-base';
import {
BalanceRequest,
PollRequest,
TokensRequest,
TokensResponse,
} from '../../network/network.requests';
import { Chain, CustomTransaction } from '../../services/common-interfaces';
import {
AllowancesRequest,
ApproveRequest,
CancelRequest,
NonceRequest,
NonceResponse,
} from '../chain.requests';
import {
TransferRequest,
TransferResponse,
} from '../injective/injective.requests';
import { BigNumber } from 'bignumber.js';

export class Kujira {
chain: string = 'kujira';
network: string;
controller: Kujira = this;

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
private kujira: KujiraModel;
storedTokenList: any;

private static _instances: { [name: string]: Kujira };

private constructor(network: string) {
this.network = network;
}

public static getInstance(chain: string): Kujira {
if (Kujira._instances === undefined) {
Kujira._instances = {};
}

const key = `${chain}`;

if (!(key in Kujira._instances)) {
Kujira._instances[key] = new Kujira(chain);
}

return Kujira._instances[key];
}

public static getConnectedInstances(): { [key: string]: Kujira } {
return Kujira._instances;
}

async init() {
this.kujira = KujiraModel.getInstance(this.chain, this.network);
await this.kujira.init();
}

ready(): boolean {
return this.kujira ? this.kujira.isReady : false;
}

async getWalletPublicKey(
mnemonic: string,
accountNumber: number | undefined
): Promise<Address> {
return await this.kujira.getWalletPublicKey({
mnemonic: mnemonic,
accountNumber: accountNumber || KujiraConfig.config.accountNumber,
});
}

async encrypt(
mnemonic: string,
accountNumber: number,
publicKey: string
): Promise<string> {
return await this.kujira.encryptWallet({
wallet: {
mnemonic,
accountNumber,
publicKey,
},
});
}

async getTokenForSymbol(symbol: string): Promise<TokenInfo> {
return convertToGetTokensResponse(await this.kujira.getToken({ symbol }));
}

async getCurrentBlockNumber(
_options: GetCurrentBlockRequest
): Promise<GetCurrentBlockResponse> {
return await this.kujira.getCurrentBlock(_options);
}

async balances(
_chain: any,
req: BalanceRequest
): Promise<{ balances: Record<string, string> }> {
let balances;
if (req.tokenSymbols && req.tokenSymbols.length) {
balances = await this.kujira.getBalances({
ownerAddress: req.address,
tokenSymbols: req.tokenSymbols,
});
} else {
balances = await this.kujira.getAllBalances({
ownerAddress: req.address,
});
}

const output: Record<string, string> = {};

for (const balance of balances.tokens.values()) {
output[(balance.token as Token).symbol] = balance.free.toString();
}

return { balances: output };
}

async poll(_chain: Chain, req: PollRequest): Promise<any> {
const currentBlock = await this.kujira.getCurrentBlock({});

const transaction = await this.kujira.getTransaction({
hash: req.txHash,
});

// noinspection UnnecessaryLocalVariableJS
const output = {
currentBlock: currentBlock,
txHash: transaction.hash,
txStatus: transaction.code,
txBlock: transaction.blockNumber,
txData: transaction.data,
txReceipt: undefined,
};

return output;
}

async getTokens(_chain: Chain, _req: TokensRequest): Promise<TokensResponse> {
const tokens = await this.kujira.getAllTokens({});

const output: {
tokens: any[];
} = {
tokens: [],
};

for (const token of tokens.values()) {
output.tokens.push({
chainId: this.kujira.chain,
address: token.id,
name: token.name,
symbol: token.symbol,
decimals: token.decimals,
});
}

return output;
}

async nextNonce(_chain: Chain, _req: NonceRequest): Promise<NonceResponse> {
// Not applicable.

return {
nonce: undefined as unknown as number,
};
}

async nonce(_chain: Chain, _req: NonceRequest): Promise<NonceResponse> {
// Not applicable.

return {
nonce: undefined as unknown as number,
};
}

async allowances(_chain: Chain, _req: AllowancesRequest): Promise<any> {
// Not applicable.

return {
spender: undefined as unknown as string,
approvals: {} as Record<string, string>,
};
}

async approve(_chain: Chain, _req: ApproveRequest): Promise<any> {
// Not applicable.

return {
tokenAddress: undefined as unknown as string,
spender: undefined as unknown as string,
amount: undefined as unknown as string,
nonce: undefined as unknown as number,
approval: undefined as unknown as CustomTransaction,
};
}

async cancel(_chain: Chain, _req: CancelRequest): Promise<any> {
// Not applicable.

return {
txHash: undefined as unknown as string,
};
}

async transfer(
_chain: Chain,
req: TransferRequest
): Promise<TransferResponse> {
return this.kujira.transferFromTo({
from: req.from,
to: req.to,
tokenSymbol: req.token,
amount: BigNumber(req.amount),
});
}
}
6 changes: 5 additions & 1 deletion src/clob/clob.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
validateAmount,
validateSide,
} from '../amm/amm.validators';
import { isValidKujiraPublicKey } from '../connectors/kujira/kujira.helpers';

export const invalidMarketError: string =
'The market param is not a valid market. Market should be in {base}-{quote} format.';
Expand Down Expand Up @@ -95,7 +96,10 @@ export const validateWallet: Validator = mkValidator(
'address',
invalidWalletError,
(val) => {
return typeof val === 'string' && isAddress(val.slice(0, 42));
return (
typeof val === 'string' &&
(isAddress(val.slice(0, 42)) || isValidKujiraPublicKey(val))
);
}
);

Expand Down
13 changes: 12 additions & 1 deletion src/connectors/connectors.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ConnectorsResponse } from './connectors.request';
import { DexalotCLOBConfig } from './dexalot/dexalot.clob.config';
import { TinymanConfig } from './tinyman/tinyman.config';
import { PlentyConfig } from './plenty/plenty.config';
import { KujiraConfig } from './kujira/kujira.config';

export namespace ConnectorsRoutes {
export const router = Router();
Expand Down Expand Up @@ -157,7 +158,17 @@ export namespace ConnectorsRoutes {
trading_type: PlentyConfig.config.tradingTypes,
chain_type: PlentyConfig.config.chainType,
available_networks: PlentyConfig.config.availableNetworks,
}
},
{
name: 'kujira',
trading_type: KujiraConfig.config.tradingTypes,
chain_type: KujiraConfig.config.chainType,
available_networks: KujiraConfig.config.availableNetworks,
additional_add_wallet_prompts: {
accountId:
'Enter your kujira account number (input 0 if unsure) >>> ',
},
},
],
});
})
Expand Down
Loading

0 comments on commit 8f4b983

Please sign in to comment.