Skip to content

Commit

Permalink
Merge pull request #28 from AcalaNetwork/update-prod-config
Browse files Browse the repository at this point in the history
update prod config
  • Loading branch information
shunjizhan committed Jun 14, 2023
2 parents 3de8ed3 + e45474c commit ca286b4
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 42 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"dependencies": {
"@acala-network/api": "~5.1.0-0",
"@acala-network/asset-router": "~1.0.4",
"@acala-network/asset-router": "~1.0.7",
"@acala-network/eth-providers": "~2.6.8",
"@babel/runtime": "^7.21.5",
"@certusone/wormhole-sdk": "^0.9.12",
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const NOT_SUPPORTED_ADDRESS = '';

const RELAYER_URL = 'http://localhost:3111';
// const RELAYER_URL = 'https://relayer.aca-dev.network';
// const RELAYER_URL = 'https://relayer.aca-api.network';
export const RELAYER_URL_TESTNET = 'https://karura-dev.aca-dev.network/eth/relayer';

export const RELAY_URL = `${RELAYER_URL}/relay`;
Expand Down
18 changes: 9 additions & 9 deletions src/__tests__/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
ETH_RPC_BSC,
BSC_TOKEN_BRIDGE_ADDRESS,
} from './consts';
import { ETH_USDC, BASILISK_PARA_ID } from '../consts';
import { GOERLI_USDC, PARA_ID } from '../consts';
import { getSignedVAAFromSequence, transferFromBSCToKarura } from './utils';
import { RelayAndRouteParams, RouteParamsWormhole, RouteParamsXcm } from '../route';

Expand Down Expand Up @@ -92,8 +92,8 @@ describe('/routeXcm', () => {
it('when should route', async () => {
const routeArgs = {
dest,
destParaId: BASILISK_PARA_ID,
originAddr: ETH_USDC,
destParaId: PARA_ID.BASILISK,
originAddr: GOERLI_USDC,
};

const res = await shouldRouteXcm(routeArgs);
Expand Down Expand Up @@ -155,8 +155,8 @@ describe('/relayAndRoute', () => {
it('when should route', async () => {
const routeArgs = {
dest,
destParaId: BASILISK_PARA_ID,
originAddr: ETH_USDC,
destParaId: PARA_ID.BASILISK,
originAddr: GOERLI_USDC,
};

const curBalUser = await getBasiliskUsdcBalance(api, destAddr);
Expand Down Expand Up @@ -204,8 +204,8 @@ describe('/relayAndRoute', () => {
it('when should not route', async () => {
const routeArgs = {
dest,
destParaId: BASILISK_PARA_ID,
originAddr: ETH_USDC,
destParaId: PARA_ID.BASILISK,
originAddr: GOERLI_USDC,
};

try {
Expand Down Expand Up @@ -254,8 +254,8 @@ describe('/routeWormhole', () => {
const routeArgs = {
targetChainId: String(CHAIN_ID_BSC),
destAddr: TEST_USER_ADDR,
fromParaId: BASILISK_PARA_ID,
originAddr: ETH_USDC,
fromParaId: PARA_ID.BASILISK,
originAddr: GOERLI_USDC,
};

const res = await shouldRouteWormhole(routeArgs);
Expand Down
13 changes: 7 additions & 6 deletions src/configureEnv.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ChainId, CHAIN_ID_KARURA, CHAIN_ID_ACALA } from '@certusone/wormhole-sdk';
import dotenv from 'dotenv';
import { ADDRESSES } from './consts';
import { ADDRESSES } from '@acala-network/asset-router/dist/consts';

dotenv.config({ path: '.env' });

export type RelayerEnvironment = {
supportedChains: ChainConfig[];
Expand All @@ -19,7 +21,6 @@ export type ChainConfig = {
const isTestnet = Number(process.env.TESTNET_MODE ?? 1);

export function validateEnvironment(): RelayerEnvironment {
dotenv.config({ path: '.env' });
const supportedChains: ChainConfig[] = [];
supportedChains.push(configKarura());
supportedChains.push(configAcala());
Expand All @@ -41,8 +42,8 @@ function configKarura(): ChainConfig {
}

const addresses = isTestnet
? ADDRESSES.karuraTestnet
: ADDRESSES.karura;
? ADDRESSES.KARURA_TESTNET
: ADDRESSES.KARURA;

return {
chainId: CHAIN_ID_KARURA,
Expand All @@ -66,8 +67,8 @@ function configAcala(): ChainConfig {
}

const addresses = isTestnet
? ADDRESSES.acalaTestnet
: ADDRESSES.acala;
? ADDRESSES.ACALA_TESTNET
: ADDRESSES.ACALA;

return {
chainId: CHAIN_ID_ACALA,
Expand Down
47 changes: 31 additions & 16 deletions src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ROUTER_TOKEN_INFO } from '@acala-network/asset-router/dist/consts';
import {
CHAIN_ID_KARURA,
CHAIN_ID_ACALA,
} from '@certusone/wormhole-sdk';
import dotenv from 'dotenv';
export { ADDRESSES } from '@acala-network/asset-router/dist/consts';

dotenv.config({ path: '.env' });

Expand Down Expand Up @@ -61,36 +61,51 @@ export const RELAYER_SUPPORTED_ADDRESSES_AND_THRESHOLDS = isTestnet
? RELAYER_SUPPORTED_ADDRESSES_AND_THRESHOLDS_DEV
: RELAYER_SUPPORTED_ADDRESSES_AND_THRESHOLDS_PROD;

export const HYDRA_PARA_ID = '';
export const BASILISK_PARA_ID = '2090';
export const enum PARA_ID {
BASILISK = '2090',
CALAMARI = '2084',
SHADOW = '2012',

export interface RouterConfigs {
[destChainName: string]: string[];
HYDRA = '2034'
}

export const ETH_USDC = '0x07865c6e87b9f70255377e024ace6630c1eaa37f';
export const GOERLI_USDC = '0x07865c6e87b9f70255377e024ace6630c1eaa37f';
export const ZERO_ADDR = '0x0000000000000000000000000000000000000000';

const ROUTE_SUPPORTED_CHAINS_AND_ASSETS_DEV: RouterConfigs = {
const ROUTE_SUPPORTED_CHAINS_AND_ASSETS_DEV = {
// [HYDRA_PARA_ID]: [
// ETH_USDC,
// GOERLI_USDC,
// ],
[BASILISK_PARA_ID]: [
ETH_USDC,
[PARA_ID.BASILISK]: [
GOERLI_USDC,
],
};

export const RouterChainIdByDestParaId = {
[BASILISK_PARA_ID]: CHAIN_ID_KARURA,
[HYDRA_PARA_ID]: CHAIN_ID_ACALA,
} as const;

const ROUTE_SUPPORTED_CHAINS_AND_ASSETS_PROD: RouterConfigs = {};
const ROUTE_SUPPORTED_CHAINS_AND_ASSETS_PROD = {
[PARA_ID.BASILISK]: [
ROUTER_TOKEN_INFO.KARURA.usdc.srcAddr,
ROUTER_TOKEN_INFO.KARURA.weth.srcAddr,
ROUTER_TOKEN_INFO.KARURA.wbtc.srcAddr,
],
[PARA_ID.CALAMARI]: [
],
[PARA_ID.SHADOW]: [
ROUTER_TOKEN_INFO.KARURA.csm.srcAddr,
],
} as const;

export const ROUTE_SUPPORTED_CHAINS_AND_ASSETS = isTestnet
? ROUTE_SUPPORTED_CHAINS_AND_ASSETS_DEV
: ROUTE_SUPPORTED_CHAINS_AND_ASSETS_PROD;

export const DEST_PARA_ID_TO_ROUTER_WORMHOLE_CHAIN_ID = {
[PARA_ID.BASILISK]: CHAIN_ID_KARURA,
[PARA_ID.CALAMARI]: CHAIN_ID_KARURA,
[PARA_ID.SHADOW]: CHAIN_ID_KARURA,

[PARA_ID.HYDRA]: CHAIN_ID_ACALA,
} as const;

export const TESTNET_MODE_WARNING = `
----------------------------
🔨 running in testnet mode
Expand Down
14 changes: 9 additions & 5 deletions src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { WormholeInstructionsStruct, XcmInstructionsStruct } from '@acala-networ

import { getChainConfig, ChainConfig } from './configureEnv';
import { checkShouldRelayBeforeRouting, getRouterChainTokenAddr, getSigner, relayEVM } from './utils';
import { RouterChainIdByDestParaId, ROUTE_SUPPORTED_CHAINS_AND_ASSETS, ZERO_ADDR } from './consts';
import {
DEST_PARA_ID_TO_ROUTER_WORMHOLE_CHAIN_ID,
ROUTE_SUPPORTED_CHAINS_AND_ASSETS,
ZERO_ADDR,
} from './consts';
import { logger } from './logger';

interface RouteParamsBase {
Expand Down Expand Up @@ -66,11 +70,11 @@ const prepareRouteXcm = async ({
throw new Error(`unsupported dest parachain: ${destParaId}`);
}

if (!supportedTokens.includes(originAddr.toLowerCase())) {
if (!supportedTokens.map((t: string) => t.toLowerCase()).includes(originAddr.toLowerCase())) {
throw new Error(`unsupported token on dest parachin ${destParaId}. Token origin address: ${originAddr}`);
}

const routerChainId = RouterChainIdByDestParaId[destParaId] as ChainId;
const routerChainId = DEST_PARA_ID_TO_ROUTER_WORMHOLE_CHAIN_ID[destParaId] as ChainId;
const {
chainConfig,
signer,
Expand All @@ -96,7 +100,7 @@ const prepareRouteWormhole = async ({
fromParaId,
targetChainId,
}: RouteParamsWormhole): Promise<RoutePropsWormhole> => {
const routerChainId = RouterChainIdByDestParaId[fromParaId];
const routerChainId = DEST_PARA_ID_TO_ROUTER_WORMHOLE_CHAIN_ID[fromParaId];
if (!routerChainId) {
throw new Error(`unsupported origin parachain: ${fromParaId}`);
}
Expand Down Expand Up @@ -157,7 +161,7 @@ export const routeXcm = async (routeParamsXcm: RouteParamsXcm): Promise<string>
};

export const relayAndRoute = async (params: RelayAndRouteParams): Promise<[string, string]> => {
const routerChainId = RouterChainIdByDestParaId[params.destParaId] as ChainId;
const routerChainId = DEST_PARA_ID_TO_ROUTER_WORMHOLE_CHAIN_ID[params.destParaId] as ChainId;
const { chainConfig, signer } = await _prepareRoute(routerChainId);
await checkShouldRelayBeforeRouting(params, chainConfig, signer);

Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const getRouterChainTokenAddr = async (originAddr: string, chainInfo: Cha
const tokenBridge = Bridge__factory.connect(chainInfo.tokenBridgeAddr, signer);

return tokenBridge.wrappedAsset(
CHAIN_ID_ETH,
CHAIN_ID_ETH, // TODO: from other chains
Buffer.from(tryNativeToHexString(originAddr, CHAIN_ID_ETH), 'hex'),
);
};
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"@acala-network/types" "5.1.0-1"
"@open-web3/orml-api-derive" "^2.0.1"

"@acala-network/asset-router@~1.0.4":
version "1.0.4"
resolved "https://registry.npmjs.org/@acala-network/asset-router/-/asset-router-1.0.4.tgz#14a0bcbe7526e231dad30070eaa61a8d9de8c710"
integrity sha512-avBBbUGK1kdEJEcL9JzegPHoyNvKCArk3An1aidIBYOhS7BjvQLYbK5izS5E2TGfPv8noDn+LB2OxJGol9aGCQ==
"@acala-network/asset-router@~1.0.7":
version "1.0.7"
resolved "https://registry.npmjs.org/@acala-network/asset-router/-/asset-router-1.0.7.tgz#c9bea62abadf1a51aae431c410b3c428b308576a"
integrity sha512-dJWJ0TkMVlOGH1O2LQXYhZuNGTUHV4t2yIuPwVEMfBIoQA+ieZmzarDrUZLgO3YVfRq4Mz0t60+TZnZECUICqg==
dependencies:
"@acala-network/contracts" "^4.3.7"
"@acala-network/eth-providers" "^2.6.2"
Expand Down

0 comments on commit ca286b4

Please sign in to comment.