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

SUPPORT EVM #1

Open
wants to merge 10 commits into
base: feat/add-halotrade
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions NOTE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class UniswapMulticallProvider extends multicall_provider_1.IMulticallProvider {
Added chainID: /home/haitran/Github/AURANetwork/hummingbot-gateway/node_modules/@uniswap/smart-order-router/build/module/util/chains.d.ts
Config addresses: /home/haitran/Github/AURANetwork/hummingbot-gateway/node_modules/@uniswap/smart-order-router/build/module/util/addresses.js
90 changes: 53 additions & 37 deletions src/amm/amm.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,26 @@ import {
PerpBalanceRequest,
PerpBalanceResponse,
} from './amm.requests';
// import {
// price as uniswapPrice,
// trade as uniswapTrade,
// addLiquidity as uniswapV3AddLiquidity,
// removeLiquidity as uniswapV3RemoveLiquidity,
// collectEarnedFees as uniswapV3CollectEarnedFees,
// positionInfo as uniswapV3PositionInfo,
// poolPrice as uniswapV3PoolPrice,
// estimateGas as uniswapEstimateGas,
// } from '../connectors/uniswap/uniswap.controllers';
import {
price as uniswapPrice,
trade as uniswapTrade,
addLiquidity as uniswapV3AddLiquidity,
removeLiquidity as uniswapV3RemoveLiquidity,
collectEarnedFees as uniswapV3CollectEarnedFees,
positionInfo as uniswapV3PositionInfo,
poolPrice as uniswapV3PoolPrice,
estimateGas as uniswapEstimateGas,
} from '../connectors/uniswap/uniswap.controllers';
price as halotradeevmPrice,
trade as halotradeevmTrade,
addLiquidity as halotradeevmV3AddLiquidity,
removeLiquidity as halotradeevmV3RemoveLiquidity,
collectEarnedFees as halotradeevmV3CollectEarnedFees,
positionInfo as halotradeevmV3PositionInfo,
poolPrice as halotradeevmV3PoolPrice,
estimateGas as halotradeevmEstimateGas,
} from '../connectors/halotradeevm/halotradeevm.controllers';
import {
price as refPrice,
trade as refTrade,
Expand Down Expand Up @@ -69,13 +79,16 @@ import {
} from '../services/connection-manager';
import {
Chain as Ethereumish,
Auraevmish,
Nearish,
NetworkSelectionRequest,
Perpish,
RefAMMish,
Tezosish,
Uniswapish,
Halotradeevmish,
UniswapLPish,
// HalotradeevmLPish,
} from '../services/common-interfaces';
import { Algorand } from '../chains/algorand/algorand';
import { Tinyman } from '../connectors/tinyman/tinyman';
Expand All @@ -85,20 +98,24 @@ import { Aura } from '../chains/aura/aura';

export async function price(req: PriceRequest): Promise<PriceResponse> {
const chain = await getInitializedChain<
Algorand | Ethereumish | Nearish | Tezosish
Algorand | Ethereumish | Auraevmish | Nearish | Tezosish
>(req.chain, req.network);
const connector: Uniswapish | RefAMMish | Tinyman | Plenty | Halotrade =
await getConnector<Uniswapish | RefAMMish | Tinyman | Plenty | Halotrade>(
req.chain,
req.network,
req.connector
);
const connector:
| Uniswapish
| Halotradeevmish
| RefAMMish
| Tinyman
| Plenty
| Halotrade = await getConnector<
Uniswapish | Halotradeevmish | RefAMMish | Tinyman | Plenty | Halotrade
>(req.chain, req.network, req.connector);

if (connector instanceof Plenty) {
return plentyPrice(<Tezosish>chain, connector, req);
} else if ('routerAbi' in connector) {
// change to Uniswap when enable it just workaround method for now: TBD
// we currently use the presence of routerAbi to distinguish Uniswapish from RefAMMish
return uniswapPrice(<Ethereumish>chain, connector, req);
return halotradeevmPrice(<Auraevmish>chain, connector, req);
} else if (connector instanceof Tinyman) {
return tinymanPrice(chain as unknown as Algorand, connector, req);
} else if (connector instanceof Halotrade) {
Expand All @@ -110,20 +127,19 @@ export async function price(req: PriceRequest): Promise<PriceResponse> {

export async function trade(req: TradeRequest): Promise<TradeResponse> {
const chain = await getInitializedChain<
Algorand | Ethereumish | Nearish | Tezosish
Algorand | Ethereumish | Auraevmish | Nearish | Tezosish
>(req.chain, req.network);
const connector: Uniswapish | RefAMMish | Tinyman | Plenty =
await getConnector<Uniswapish | RefAMMish | Tinyman | Plenty>(
req.chain,
req.network,
req.connector
);
const connector: Uniswapish | Halotradeevmish | RefAMMish | Tinyman | Plenty =
await getConnector<
Uniswapish | Halotradeevmish | RefAMMish | Tinyman | Plenty
>(req.chain, req.network, req.connector);

if (connector instanceof Plenty) {
return plentyTrade(<Tezosish>chain, connector, req);
} else if ('routerAbi' in connector) {
// change to Uniswap when enable it just workaround method for now: TBD
// we currently use the presence of routerAbi to distinguish Uniswapish from RefAMMish
return uniswapTrade(<Ethereumish>chain, connector, req);
return halotradeevmTrade(<Auraevmish>chain, connector, req);
} else if (connector instanceof Tinyman) {
return tinymanTrade(chain as unknown as Algorand, connector, req);
} else if (connector instanceof Halotrade) {
Expand All @@ -136,70 +152,70 @@ export async function trade(req: TradeRequest): Promise<TradeResponse> {
export async function addLiquidity(
req: AddLiquidityRequest
): Promise<AddLiquidityResponse> {
const chain = await getInitializedChain<Ethereumish>(req.chain, req.network);
const chain = await getInitializedChain<Auraevmish>(req.chain, req.network);
const connector: UniswapLPish = await getConnector<UniswapLPish>(
req.chain,
req.network,
req.connector
);

return uniswapV3AddLiquidity(chain, connector, req);
return halotradeevmV3AddLiquidity(chain, connector, req);
}

export async function reduceLiquidity(
req: RemoveLiquidityRequest
): Promise<RemoveLiquidityResponse> {
const chain = await getInitializedChain<Ethereumish>(req.chain, req.network);
const chain = await getInitializedChain<Auraevmish>(req.chain, req.network);
const connector: UniswapLPish = await getConnector<UniswapLPish>(
req.chain,
req.network,
req.connector
);

return uniswapV3RemoveLiquidity(chain, connector, req);
return halotradeevmV3RemoveLiquidity(chain, connector, req);
}

export async function collectFees(
req: CollectEarnedFeesRequest
): Promise<RemoveLiquidityResponse> {
const chain = await getInitializedChain<Ethereumish>(req.chain, req.network);
const chain = await getInitializedChain<Auraevmish>(req.chain, req.network);
const connector: UniswapLPish = await getConnector<UniswapLPish>(
req.chain,
req.network,
req.connector
);
return uniswapV3CollectEarnedFees(chain, connector, req);
return halotradeevmV3CollectEarnedFees(chain, connector, req);
}

export async function positionInfo(
req: PositionRequest
): Promise<PositionResponse> {
const chain = await getInitializedChain<Ethereumish>(req.chain, req.network);
const chain = await getInitializedChain<Auraevmish>(req.chain, req.network);
const connector: UniswapLPish = await getConnector<UniswapLPish>(
req.chain,
req.network,
req.connector
);
return uniswapV3PositionInfo(chain, connector, req);
return halotradeevmV3PositionInfo(chain, connector, req);
}

export async function poolPrice(
req: PoolPriceRequest
): Promise<PoolPriceResponse> {
const chain = await getInitializedChain<Ethereumish>(req.chain, req.network);
const chain = await getInitializedChain<Auraevmish>(req.chain, req.network);
const connector: UniswapLPish = await getConnector<UniswapLPish>(
req.chain,
req.network,
req.connector
);
return uniswapV3PoolPrice(chain, connector, req);
return halotradeevmV3PoolPrice(chain, connector, req);
}

export async function estimateGas(
req: NetworkSelectionRequest
): Promise<EstimateGasResponse> {
const chain = await getInitializedChain<
Algorand | Ethereumish | Nearish | Tezosish
Algorand | Auraevmish | Nearish | Tezosish
>(req.chain, req.network);
const connector: Uniswapish | RefAMMish | Tinyman | Plenty =
await getConnector<Uniswapish | RefAMMish | Plenty>(
Expand All @@ -212,7 +228,7 @@ export async function estimateGas(
return plentyEstimateGas(<Tezosish>chain, connector);
} else if ('routerAbi' in connector) {
// we currently use the presence of routerAbi to distinguish Uniswapish from RefAMMish
return uniswapEstimateGas(<Ethereumish>chain, connector);
return halotradeevmEstimateGas(<Auraevmish>chain, connector);
} else if (connector instanceof Tinyman) {
return tinymanEstimateGas(chain as unknown as Algorand, connector);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ 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.20.0'; // gateway version
if (!ConfigManagerV2.getInstance().get('server.id')) {
ConfigManagerV2.getInstance().set(
'server.id',
Math.random().toString(16).substr(2, 14)
);
}
logger.info(`Gateway Version: ${gateway_version}`) // display gateway version
logger.info(`Gateway Version: ${gateway_version}`); // display gateway version
logger.info(`⚡️ Starting Gateway API on port ${port}...`);
if (ConfigManagerV2.getInstance().get('server.unsafeDevModeWithHTTP')) {
logger.info('Running in UNSAFE HTTP! This could expose private keys.');
Expand Down
4 changes: 2 additions & 2 deletions src/chains/aura/aura-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
AccountData,
DirectSignResponse,
} from 'cosmjs-proto-signing-0.32';
const { toBase64, fromBase64 } = require('@cosmjs/encoding');
const { toBase64, fromBase64, fromHex } = require('@cosmjs/encoding');
const crypto = require('crypto').webcrypto;
// export interface AuraToken {
// base: string;
Expand Down Expand Up @@ -186,7 +186,7 @@ export class AuraBase {
prefix: string
): Promise<any> {
const wallet = await DirectSecp256k1Wallet.fromKey(
fromBase64(privateKey),
fromHex(privateKey),
prefix
);
// wallet.
Expand Down
Loading