Skip to content

Commit

Permalink
Merge branch 'community' into fun-development
Browse files Browse the repository at this point in the history
  • Loading branch information
alvaro-mota-funttastic committed Feb 6, 2024
2 parents af4c542 + a1149ce commit 8942384
Show file tree
Hide file tree
Showing 16 changed files with 2,364 additions and 1,683 deletions.
407 changes: 407 additions & 0 deletions integration-test/withdraw_fee_sum.test.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"test:scripts": "jest -i --verbose ./test-scripts/*.test.ts"
},
"dependencies": {
"@cosmjs/proto-signing": "^0.30.1",
"@cosmjs/stargate": "^0.30.1",
"@cosmjs/proto-signing": "^0.31.1",
"@cosmjs/stargate": "^0.31.1",
"@crocswap/sdk": "^2.4.5",
"@ethersproject/abstract-provider": "5.7.0",
"@ethersproject/address": "5.7.0",
Expand Down Expand Up @@ -79,7 +79,7 @@
"http-status-codes": "2.2.0",
"immutable": "^4.2.4",
"js-yaml": "^4.1.0",
"kujira.js": "https://github.com/Team-Kujira/kujira.js",
"kujira.js": "0.9.6",
"level": "^8.0.0",
"libsodium-wrappers": "^0.7.11",
"libsodium-wrappers-sumo": "^0.7.11",
Expand Down
5 changes: 4 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ export const startSwagger = async () => {
};

export const startGateway = async () => {
const port = ConfigManagerV2.getInstance().get('server.port');
const port = parseInt(
process.env['GATEWAY_PORT']
|| ConfigManagerV2.getInstance().get('server.port')
);
const gateway_version="dev-1.19.0"; // gateway version
if (!ConfigManagerV2.getInstance().get('server.id')) {
ConfigManagerV2.getInstance().set(
Expand Down
132 changes: 132 additions & 0 deletions src/chains/kujira/kujira.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ import {
Address,
GetCurrentBlockRequest,
GetCurrentBlockResponse,
Token,
TransferRequest,
TransferResponse,
} from '../../connectors/kujira/kujira.types';
import { TokenInfo } from '../ethereum/ethereum-base';
import { MAINNET, NETWORKS, TESTNET } from 'kujira.js';
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 {BigNumber} from "bignumber.js";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const caches = {
Expand All @@ -20,6 +27,7 @@ const caches = {
export class KujiraChain {
chain: string = 'kujira';
network: string;
controller: KujiraChain = this;

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down Expand Up @@ -101,4 +109,128 @@ export class KujiraChain {
): 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),
});
}
}
2 changes: 1 addition & 1 deletion src/clob/clob.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const validateOrderId: Validator = mkValidator(
export const validateOrderType: Validator = mkValidator(
'orderType',
invalidOrderTypeError,
(val) => typeof val === 'string' && (val === 'LIMIT' || val === 'LIMIT_MAKER')
(val) => typeof val === 'string' && (val === 'LIMIT' || val === 'LIMIT_MAKER' || val === 'MARKET')
);

const NETWORK_VALIDATIONS = [validateConnector, validateChain, validateNetwork];
Expand Down
25 changes: 13 additions & 12 deletions src/connectors/kujira/kujira.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BigNumber } from 'bignumber.js';
import { ConfigManagerV2 } from '../../services/config-manager-v2';
import { getNotNullOrThrowError } from './kujira.helpers';

const configManager = ConfigManagerV2.getInstance();

Expand Down Expand Up @@ -28,7 +27,7 @@ export namespace KujiraConfig {
prefix: configManager.get('kujira.prefix') || 'kujira',
accountNumber: configManager.get('kujira.accountNumber') || 0,
nativeToken: 'KUJI',
gasPrice: BigNumber(configManager.get('kujira.gasPrice') || 0.00125),
gasPrice: configManager.get('kujira.gasPrice') ? BigNumber(configManager.get('kujira.gasPrice')) : null,
gasPriceSuffix: 'ukuji',
gasLimitEstimate: BigNumber(
configManager.get('kujira.gasLimitEstimate') || 0.009147
Expand Down Expand Up @@ -67,12 +66,12 @@ export namespace KujiraConfig {
),
},
open: {
limit: configManager.get(`kujira.orders.open.limit`) | 255,
limit: configManager.get(`kujira.orders.open.limit`) | (5 * 31),
paginationLimit:
configManager.get(`kujira.orders.open.paginationLimit`) | 31,
},
filled: {
limit: configManager.get(`kujira.orders.filled.limit`) | 255,
limit: configManager.get(`kujira.orders.filled.limit`) | (5 * 31),
},
cancel: {
maxPerTransaction: configManager.get(
Expand Down Expand Up @@ -118,14 +117,16 @@ export namespace KujiraConfig {
marketsData: configManager.get('kujira.cache.marketsData') || 3600, // in seconds
markets: configManager.get('kujira.cache.markets') || 3600, // in seconds
tokens: configManager.get('kujira.cache.markets') || 3600, // in seconds
coinGeckoCoins: configManager.get('kujira.cache.coinGeckoCoins') || 3600, // in seconds
},
coinGecko: {
coinsUrl:
configManager.get('kujira.coinGecko.coinsUrl') ||
'https://api.coingecko.com/api/v3/coins/list',
priceUrl:
configManager.get('kujira.coinGecko.priceUrl') ||
'https://api.coingecko.com/api/v3/simple/price?ids={targets}&vs_currencies=usd',
apiKeys: configManager.get('kujira.coinGecko.apiKeys') || [''],
},
};
}

if (KujiraConfig.config.tickers.sources.has('nomics')) {
getNotNullOrThrowError<any>(
KujiraConfig.config.tickers.sources.get('nomics')
).url =
KujiraConfig.config.tickers.sources.get('nomics')?.url ||
'https://nomics.com/data/exchange-markets-ticker?convert=USD&exchange=kujira_dex&interval=1m&market=${marketAddress}';
}
Loading

0 comments on commit 8942384

Please sign in to comment.