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

feat: Support DutchV3 Orders #384

Merged
merged 11 commits into from
Dec 2, 2024
11 changes: 8 additions & 3 deletions bin/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export class APIPipeline extends Stack {
'arn:aws:secretsmanager:us-east-2:644039819003:secret:gouda-parameterization-api-internal-api-key-uw4sIa',
});

const rpcUrls = sm.Secret.fromSecretAttributes(this, 'rpcUrls', {
secretCompleteArn:
'arn:aws:secretsmanager:us-east-2:644039819003:secret:prod/param-api/rpc-urls-HJyniu',
});

// Beta us-east-2

const betaUsEast2Stage = new APIStage(this, 'beta-us-east-2', {
Expand All @@ -123,7 +128,7 @@ export class APIPipeline extends Stack {
envVars: {
RFQ_WEBHOOK_CONFIG: rfqWebhookConfig.secretValue.toString(),
ORDER_SERVICE_URL: urlSecrets.secretValueFromJson('GOUDA_SERVICE_BETA').toString(),
ARBITRUM_RPC_URL: urlSecrets.secretValueFromJson('ARBITRUM_RPC_URL').toString(),
RPC_42161: rpcUrls.secretValueFromJson('RPC_42161').toString(),
alanhwu marked this conversation as resolved.
Show resolved Hide resolved
FILL_LOG_SENDER_ACCOUNT: '321377678687',
ORDER_LOG_SENDER_ACCOUNT: '321377678687',
URA_ACCOUNT: '665191769009',
Expand All @@ -144,7 +149,7 @@ export class APIPipeline extends Stack {
envVars: {
RFQ_WEBHOOK_CONFIG: rfqWebhookConfig.secretValue.toString(),
ORDER_SERVICE_URL: urlSecrets.secretValueFromJson('GOUDA_SERVICE_PROD').toString(),
ARBITRUM_RPC_URL: urlSecrets.secretValueFromJson('ARBITRUM_RPC_URL').toString(),
RPC_42161: rpcUrls.secretValueFromJson('RPC_42161').toString(),
FILL_LOG_SENDER_ACCOUNT: '316116520258',
ORDER_LOG_SENDER_ACCOUNT: '316116520258',
URA_ACCOUNT: '652077092967',
Expand Down Expand Up @@ -246,7 +251,7 @@ envVars['URA_ACCOUNT'] = process.env['URA_ACCOUNT'] || '';
envVars['BOT_ACCOUNT'] = process.env['BOT_ACCOUNT'] || '';
envVars['UNISWAP_API'] = process.env['UNISWAP_API'] || '';
envVars['ORDER_SERVICE_URL'] = process.env['ORDER_SERVICE_URL'] || '';
envVars['ARBITRUM_RPC_URL'] = process.env['ARBITRUM_RPC_URL'] || '';
envVars['RPC_42161'] = process.env['RPC_42161'] || '';

new APIStack(app, `${SERVICE_NAME}Stack`, {
env: {
Expand Down
8 changes: 7 additions & 1 deletion lib/handlers/hard-quote/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,19 @@ export class QuoteHandler extends APIGLambdaHandler<
): Promise<ErrorResponse | Response<HardQuoteResponseData>> {
const {
requestInjected: { log, metric },
containerInjected: { quoters, orderServiceProvider, provider },
containerInjected: { quoters, orderServiceProvider, chainIdRpcMap },
requestBody,
} = params;
const start = Date.now();

metric.putMetric(Metric.QUOTE_REQUESTED, 1, MetricLoggerUnit.Count);

const provider = chainIdRpcMap.get(requestBody.tokenInChainId);
if (!provider)
throw new Error(
`No rpc provider found for chain: ${requestBody.tokenInChainId}`
);

const orderParser = new UniswapXOrderParser();
const orderType: OrderType = orderParser.getOrderTypeFromEncoded(
requestBody.encodedInnerOrder,
Expand Down
18 changes: 13 additions & 5 deletions lib/handlers/hard-quote/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import { STAGE } from '../../util/stage';
import { ApiInjector, ApiRInj } from '../base/api-handler';
import { HardQuoteRequestBody } from './schema';
import { ethers } from 'ethers';
import { ChainId, supportedChains } from '../../util/chains';

export interface ContainerInjected {
quoters: Quoter[];
firehose: FirehoseLogger;
orderServiceProvider: OrderServiceProvider;
provider: ethers.providers.Provider;
chainIdRpcMap: Map<ChainId, ethers.providers.StaticJsonRpcProvider>;
}

export interface RequestInjected extends ApiRInj {
Expand All @@ -42,7 +43,6 @@ export class QuoteInjector extends ApiInjector<ContainerInjected, RequestInjecte
const s3Key = stage === STAGE.BETA ? BETA_S3_KEY : PRODUCTION_S3_KEY;

const orderServiceUrl = checkDefined(process.env.ORDER_SERVICE_URL, 'ORDER_SERVICE_URL is not defined');
const rpcProviderUrl = checkDefined(process.env.ARBITRUM_RPC_URL, 'ARBITRUM_RPC_URL is not defined');

const webhookProvider = new S3WebhookConfigurationProvider(log, `${WEBHOOK_CONFIG_BUCKET}-${stage}-1`, s3Key);
await webhookProvider.fetchEndpoints();
Expand Down Expand Up @@ -78,15 +78,23 @@ export class QuoteInjector extends ApiInjector<ContainerInjected, RequestInjecte
new WebhookQuoter(log, firehose, webhookProvider, circuitBreakerProvider, fillerComplianceProvider, repository),
];

const provider = new ethers.providers.JsonRpcProvider(
rpcProviderUrl,
const chainIdRpcMap = new Map<ChainId, ethers.providers.StaticJsonRpcProvider>();
supportedChains.forEach(
chainId => {
const rpcUrl = checkDefined(
process.env[`RPC_${chainId}`],
`RPC_${chainId} is not defined`
);
const provider = new ethers.providers.StaticJsonRpcProvider(rpcUrl, chainId); // specify chainId to avoid detecctNetwork() call on initialization
alanhwu marked this conversation as resolved.
Show resolved Hide resolved
chainIdRpcMap.set(chainId, provider);
}
);

return {
quoters: quoters,
firehose: firehose,
orderServiceProvider,
provider,
chainIdRpcMap,
};
}

Expand Down
4 changes: 4 additions & 0 deletions lib/util/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export enum ChainId {
ARBITRUM_ONE = 42161,
}

export const supportedChains = [
ChainId.ARBITRUM_ONE,
]

export enum ChainName {
// ChainNames match infura network strings
MAINNET = 'mainnet',
Expand Down
Loading