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

chore: update axelar rpc #257

Merged
merged 4 commits into from
Mar 6, 2024
Merged
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
6 changes: 6 additions & 0 deletions .changeset/modern-dots-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@axelarjs/deposit-address": patch
"@axelarjs/core": patch
---

update core rpc config and add optional rpc parameter for deposit addr module
4 changes: 2 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export const DEPOSIT_SERVICE_API_URLS = {
export type DepositServiceAPIUrl = keyof typeof DEPOSIT_SERVICE_API_URLS;

export const AXELAR_RPC_URLS = {
testnet: "https://axelartest-rpc.quickapi.com",
mainnet: "https://axelar-rpc.quickapi.com",
testnet: "https://rpc-axelar-testnet.imperator.co",
mainnet: "https://rpc-axelar.imperator.co",
} as const;

export type AxelarRPCUrl = keyof typeof AXELAR_RPC_URLS;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { AXELAR_RPC_URLS, Environment } from "@axelarjs/core";
import { createAxelarQueryClient } from "@axelarjs/cosmos";
import { ChainStatus } from "@axelarjs/proto/axelar/nexus/v1beta1/query";

import { DepositAddressRequestConfig } from "../types";

export function unwrappable(
destinationChain: string,
asset: string,
Expand All @@ -20,9 +22,12 @@ export function unwrappable(
return destAsset?.module === "evm" && destAsset.isERC20WrappedNativeGasToken;
}

export async function getActiveChains(environment: Environment) {
export async function getActiveChains(
environment: Environment,
requestConfig?: DepositAddressRequestConfig
) {
const axelarQueryClient = await createAxelarQueryClient(
AXELAR_RPC_URLS[environment]
requestConfig?.axelarRpcUrl ?? AXELAR_RPC_URLS[environment]
);

return axelarQueryClient.nexus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ import { Environment } from "@axelarjs/core";
import { bech32 } from "bech32";
import { isAddress } from "viem";

import { DepositAddressRequestConfig } from "../types";
import { getActiveChains } from "./depositService";

export async function validateAddressAndChains(
sourceChain: string,
destinationChain: string,
destinationAddress: string,
chainConfigs: ChainConfigsResponse,
environment: Environment
environment: Environment,
requestConfig?: DepositAddressRequestConfig
) {
validateAddress(
destinationAddress,
chainConfigs.chains[destinationChain.toLowerCase()] as ChainConfig
);
validateChainIds([sourceChain, destinationChain], chainConfigs);

const activeChains = await getActiveChains(environment);
const activeChains = await getActiveChains(environment, requestConfig);
validateActiveChains([sourceChain, destinationChain], activeChains);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ENVIRONMENTS } from "@axelarjs/core";

import * as mod from "../get-deposit-address/helpers/depositService";
import {
getDepositAddress,
getLinkedDepositAddress,
Expand Down Expand Up @@ -186,3 +187,25 @@ describe("Deposit Address", () => {
});
});
});

describe("requestConfigs", () => {
test("should allow users to customize an RPC endpoint", async () => {
vi.spyOn(mod, "getActiveChains");
const axelarRpcUrl = "https://axelar-testnet-rpc.qubelabs.io:443";
const params: SendOptions = {
sourceChain: "osmosis-7",
destinationChain: "ethereum-2",
asset: "uaxl",
destinationAddress: "0xB8Cd93C83A974649D76B1c19f311f639e62272BC",
environment: ENVIRONMENTS.testnet,
requestConfig: { axelarRpcUrl },
};

const res = await getLinkedDepositAddress(params);

expect(res?.depositAddress).toBeTruthy();
expect(mod.getActiveChains).toHaveBeenCalledWith("testnet", {
axelarRpcUrl,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export async function getDepositAddress(
destinationChain,
environment,
destinationAddress,
requestConfig,
} = params;

const chainConfigs = await dependencies.configClient.getChainConfigs(
Expand Down Expand Up @@ -74,6 +75,7 @@ export async function getDepositAddress(
destinationChain,
environment,
asset,
requestConfig,
},
dependencies
).then((res) => res?.depositAddress);
Expand Down Expand Up @@ -123,7 +125,8 @@ export async function getLinkedDepositAddress(
params.destinationChain,
params.destinationAddress,
chainConfigs,
params.environment
params.environment,
params.requestConfig
);

return getDepositAddressFromAxelarNetwork(params, chainConfigs, dependencies);
Expand Down
8 changes: 8 additions & 0 deletions packages/deposit-address/src/get-deposit-address/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type SendOptions = {
destinationAddress: string;
asset: string;
environment: Environment;
requestConfig?: DepositAddressRequestConfig;
};

export type DepositAddressOptions = {
Expand All @@ -26,6 +27,7 @@ export type DepositAddressOptions = {
refundAddress?: string;
skipUnwrap?: boolean;
};
requestConfig?: DepositAddressRequestConfig;
};

export type DepositNativeWrapOptions = {
Expand Down Expand Up @@ -56,3 +58,9 @@ export type GetDepositServiceDependencies = {
configClient: AxelarConfigClient;
depositServiceClient: DepositServiceClient;
};
export type DepositAddressRequestConfig =
| {
axelarRpcUrl?: string;
axelarLcdUrl?: string;
}
| undefined;
Loading