Skip to content

Commit

Permalink
Merge pull request #4 from robotter-ai/feat/mango-markets-3
Browse files Browse the repository at this point in the history
Feat/mango markets 3
  • Loading branch information
MHHukiewitz authored Oct 7, 2024
2 parents 6439cd2 + 6d8dfe4 commit e36c004
Show file tree
Hide file tree
Showing 38 changed files with 162,677 additions and 220 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"dependencies": {
"@balancer-labs/sdk": "^1.1.5",
"@bancor/carbon-sdk": "^0.0.93-DEV",
"@blockworks-foundation/mango-v4": "^0.33.5",
"@coral-xyz/anchor": "^0.30.1",
"@cosmjs/amino": "^0.32.2",
"@cosmjs/cosmwasm-stargate": "^0.31.1",
"@cosmjs/proto-signing": "^0.31.1",
Expand All @@ -50,6 +52,8 @@
"@pancakeswap/v3-periphery": "^1.0.2",
"@pancakeswap/v3-sdk": "^3.7.0",
"@pangolindex/sdk": "^1.1.0",
"@solana/spl-token": "^0.4.8",
"@solana/spl-token-registry": "^0.2.4574",
"@sushiswap/sdk": "^5.0.0-canary.116",
"@taquito/rpc": "^17.0.0",
"@taquito/signer": "^17.0.0",
Expand Down
7 changes: 6 additions & 1 deletion src/amm/amm.requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import {
PositionInfo as LPPositionInfo,
} from '../services/common-interfaces';

export type OrderType = 'LIMIT' | 'LIMIT_MAKER';
export type OrderType =
| 'LIMIT'
| 'LIMIT_MAKER'
| 'IOC'
| 'MARKET'
| 'POST_ONLY';
export type Side = 'BUY' | 'SELL';

export interface PriceRequest extends NetworkSelectionRequest {
Expand Down
25 changes: 16 additions & 9 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { ConfigManagerV2 } from './services/config-manager-v2';
import { SwaggerManager } from './services/swagger-manager';
import { ConnectorsRoutes } from './connectors/connectors.routes';
import { AmmRoutes, AmmLiquidityRoutes } from './amm/amm.routes';
import { CLOBRoutes, PerpClobRoutes } from './clob/clob.routes';
import { MangoRoutes } from './mango/mango.routes';

import morgan from 'morgan';
import swaggerUi from 'swagger-ui-express';
Expand All @@ -37,7 +39,7 @@ gatewayApp.use(
req.originalUrl === '/' || req.originalUrl.includes('/network/status')
);
},
})
}),
);

// mount sub routers
Expand All @@ -49,6 +51,11 @@ gatewayApp.use('/amm', AmmRoutes.router);
gatewayApp.use('/amm/liquidity', AmmLiquidityRoutes.router);
gatewayApp.use('/wallet', WalletRoutes.router);

gatewayApp.use('/clob', CLOBRoutes.router);
gatewayApp.use('/clob/perp', PerpClobRoutes.router);

gatewayApp.use('/mango', MangoRoutes.router);

// a simple route to test that the server is running
gatewayApp.get('/', (_req: Request, res: Response) => {
res.status(200).json({ status: 'ok' });
Expand All @@ -61,7 +68,7 @@ gatewayApp.post(
process.exit(1);
// this is only to satisfy the compiler, it will never be called.
res.status(200).json();
})
}),
);

// handle any error thrown in the gateway api route
Expand All @@ -70,12 +77,12 @@ gatewayApp.use(
err: Error | NodeError | HttpException,
_req: Request,
res: Response,
_next: NextFunction
_next: NextFunction,
) => {
const response = gatewayErrorMiddleware(err);
logger.error(err);
return res.status(response.httpErrorCode).json(response);
}
},
);

export const swaggerDocument = SwaggerManager.generateSwaggerJson(
Expand All @@ -88,15 +95,15 @@ export const swaggerDocument = SwaggerManager.generateSwaggerJson(
'./docs/swagger/amm-routes.yml',
'./docs/swagger/amm-liquidity-routes.yml',
'./docs/swagger/chain-routes.yml',
]
],
);

export const startSwagger = async () => {
const swaggerApp = express();
const swaggerPort = 8080;

logger.info(
`⚡️ Swagger listening on port ${swaggerPort}. Read the Gateway API documentation at 127.0.0.1:${swaggerPort}`
`⚡️ Swagger listening on port ${swaggerPort}. Read the Gateway API documentation at 127.0.0.1:${swaggerPort}`,
);

swaggerApp.use('/', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
Expand All @@ -106,11 +113,11 @@ export const startSwagger = async () => {

export const startGateway = async () => {
const port = ConfigManagerV2.getInstance().get('server.port');
const gateway_version="dev-2.0.2"
const gateway_version = 'dev-2.0.2';
if (!ConfigManagerV2.getInstance().get('server.id')) {
ConfigManagerV2.getInstance().set(
'server.id',
Math.random().toString(16).substr(2, 14)
Math.random().toString(16).substr(2, 14),
);
}
logger.info(`Gateway Version: ${gateway_version}`); // display gateway version
Expand All @@ -124,7 +131,7 @@ export const startGateway = async () => {
logger.info('The gateway server is secured behind HTTPS.');
} catch (e) {
logger.error(
`Failed to start the server with https. Confirm that the SSL certificate files exist and are correct. Error: ${e}`
`Failed to start the server with https. Confirm that the SSL certificate files exist and are correct. Error: ${e}`,
);
process.exit();
}
Expand Down
20 changes: 20 additions & 0 deletions src/chains/solana/solana-middlewares.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { HttpException } from '../../services/error-handler';
import { Solana } from './solana';
import { NextFunction, Request, Response } from 'express';

export const verifySolanaIsAvailable = async (
req: Request,
_res: Response,
next: NextFunction
) => {
if (!req || !req.body || !req.body.network) {
throw new HttpException(404, 'No Solana network informed.');
}

const solana = await Solana.getInstance(req.body.network);
if (!solana.ready) {
await solana.init();
}

return next();
};
54 changes: 54 additions & 0 deletions src/chains/solana/solana.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { TokenListType } from '../../services/base';
import { ConfigManagerV2 } from '../../services/config-manager-v2';
interface NetworkConfig {
name: string;
nodeURL: string;
tokenListType: TokenListType;
tokenListSource: string;
nativeCurrencySymbol: string;
maxLRUCacheInstances: number;
}

export interface Config {
network: NetworkConfig;
tokenProgram: string;
transactionLamports: number;
lamportsToSol: number;
timeToLive: number;
}

export function getSolanaConfig(
chainName: string,
networkName: string
): Config {
return {
network: {
name: networkName,
nodeURL: ConfigManagerV2.getInstance().get(
chainName + '.networks.' + networkName + '.nodeURL'
),
tokenListType: ConfigManagerV2.getInstance().get(
chainName + '.networks.' + networkName + '.tokenListType'
),
tokenListSource: ConfigManagerV2.getInstance().get(
chainName + '.networks.' + networkName + '.tokenListSource'
),
nativeCurrencySymbol: ConfigManagerV2.getInstance().get(
chainName + '.networks.' + networkName + '.nativeCurrencySymbol'
),
maxLRUCacheInstances: ConfigManagerV2.getInstance().get(
chainName + '.networks.' + networkName + '.maxLRUCacheInstances'
),
},
tokenProgram: ConfigManagerV2.getInstance().get(
chainName + '.tokenProgram'
),
transactionLamports: ConfigManagerV2.getInstance().get(
chainName + '.transactionLamports'
),
lamportsToSol: ConfigManagerV2.getInstance().get(
chainName + '.lamportsToSol'
),
timeToLive: ConfigManagerV2.getInstance().get(chainName + '.timeToLive'),
};
}
19 changes: 19 additions & 0 deletions src/chains/solana/solana.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const constants = {
retry: {
all: {
maxNumberOfRetries: 0, // 0 means no retries
delayBetweenRetries: 0, // 0 means no delay (milliseconds)
},
},
timeout: {
all: 0, // 0 means no timeout (milliseconds)
},
parallel: {
all: {
batchSize: 0, // 0 means no batching (group all)
delayBetweenBatches: 0, // 0 means no delay (milliseconds)
},
},
};

export default constants;
Loading

0 comments on commit e36c004

Please sign in to comment.