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

Hydradx and Moonbeam support in API #1326

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
28 changes: 20 additions & 8 deletions web/packages/api/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ import { Codec, Registry } from "@polkadot/types/types"
import { IERC20Metadata__factory, IERC20__factory } from "@snowbridge/contract-types"
import { Context } from "./index"

/**
* @deprecated use Parachain.properties()
*/
export interface NativeAsset {
tokenSymbol: string
tokenDecimal: number
ss58Format: number
}

/**
* @deprecated use Parachain.properties()
*/
export const parachainNativeAsset = async (api: ApiPromise): Promise<NativeAsset> => {
const properties = await api.rpc.system.properties()
const tokenSymbols = properties.tokenSymbol.unwrapOrDefault()
Expand Down Expand Up @@ -42,22 +48,26 @@ export const assetStatusInfo = async (
tokenAddress: string,
ownerAddress?: string
) => {
const assetHub = (await context.assetHub()).api
const ethereum = context.ethereum()
const gateway = context.gateway()

let [ethereumNetwork, isTokenRegistered] = await Promise.all([
context.ethereum.api.getNetwork(),
context.ethereum.contracts.gateway.isTokenRegistered(tokenAddress),
ethereum.getNetwork(),
gateway.isTokenRegistered(tokenAddress),
])

const ethereumChainId = ethereumNetwork.chainId
const multiLocation = erc20TokenToAssetLocation(
context.polkadot.api.assetHub.registry,
assetHub.registry,
ethereumChainId,
tokenAddress
)
const foreignAsset = (
await context.polkadot.api.assetHub.query.foreignAssets.asset(multiLocation)
await assetHub.query.foreignAssets.asset(multiLocation)
).toPrimitive() as { status: "Live" }

const tokenContract = IERC20__factory.connect(tokenAddress, context.ethereum.api)
const tokenContract = IERC20__factory.connect(tokenAddress, ethereum)
let ownerBalance = BigInt(0)
let tokenGatewayAllowance = BigInt(0)
let isValidERC20 = true
Expand Down Expand Up @@ -94,8 +104,9 @@ export const assetErc20Balance = async (
balance: bigint
gatewayAllowance: bigint
}> => {
const tokenContract = IERC20__factory.connect(token, context.ethereum.api)
const gateway = await context.ethereum.contracts.gateway.getAddress()
const ethereum = context.ethereum()
const tokenContract = IERC20__factory.connect(token, ethereum)
const gateway = await context.gateway().getAddress()
const [balance, gatewayAllowance] = await Promise.all([
tokenContract.balanceOf(owner),
tokenContract.allowance(owner, gateway),
Expand All @@ -116,7 +127,8 @@ export const assetErc20Metadata = async (
context: Context,
tokenAddress: string
): Promise<ERC20Metadata> => {
const tokenMetadata = IERC20Metadata__factory.connect(tokenAddress, context.ethereum.api)
const ethereum = context.ethereum()
const tokenMetadata = IERC20Metadata__factory.connect(tokenAddress, ethereum)
const [name, symbol, decimals] = await Promise.all([
tokenMetadata.name(),
tokenMetadata.symbol(),
Expand Down
166 changes: 149 additions & 17 deletions web/packages/api/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ export type Config = {
BEACON_HTTP_API: string
ETHEREUM_API: (secret: string) => string
RELAY_CHAIN_URL: string
ASSET_HUB_URL: string
BRIDGE_HUB_URL: string
GATEWAY_CONTRACT: string
BEEFY_CONTRACT: string
ASSET_HUB_PARAID: number
BRIDGE_HUB_PARAID: number
PRIMARY_GOVERNANCE_CHANNEL_ID: string
SECONDARY_GOVERNANCE_CHANNEL_ID: string
RELAYERS: Relayer[]
PARACHAINS: string[]
PARACHAINS: { [paraId: number]: string }
SUBSCAN_API?: {
RELAY_CHAIN_URL: string
ASSET_HUB_URL: string
Expand Down Expand Up @@ -117,9 +115,11 @@ export const SNOWBRIDGE_ENV: { [id: string]: SnowbridgeEnvironment } = {
BEACON_HTTP_API: "http://127.0.0.1:9596",
ETHEREUM_API: () => "ws://127.0.0.1:8546",
RELAY_CHAIN_URL: "ws://127.0.0.1:9944",
ASSET_HUB_URL: "ws://127.0.0.1:12144",
BRIDGE_HUB_URL: "ws://127.0.0.1:11144",
PARACHAINS: ["ws://127.0.0.1:13144"],
PARACHAINS: {
1000: "ws://127.0.0.1:12144",
1002: "ws://127.0.0.1:11144",
2000: "ws://127.0.0.1:13144",
},
GATEWAY_CONTRACT: "0xEDa338E4dC46038493b885327842fD3E301CaB39",
BEEFY_CONTRACT: "0x992B9df075935E522EC7950F37eC8557e86f6fdb",
ASSET_HUB_PARAID: 1000,
Expand Down Expand Up @@ -180,7 +180,7 @@ export const SNOWBRIDGE_ENV: { [id: string]: SnowbridgeEnvironment } = {
id: "ethereum",
name: "Ethereum",
type: "ethereum",
destinationIds: ["assethub"],
destinationIds: ["assethub", "hydradx"],
erc20tokensReceivable: [
{
id: "WETH",
Expand Down Expand Up @@ -220,14 +220,86 @@ export const SNOWBRIDGE_ENV: { [id: string]: SnowbridgeEnvironment } = {
},
],
},
{
id: "muse",
name: "Muse",
type: "substrate",
destinationIds: [],
paraInfo: {
paraId: 3369,
destinationFeeDOT: 500_000_000n,
skipExistentialDepositCheck: true,
addressType: "20byte",
decimals: 18,
maxConsumers: 16,
},
erc20tokensReceivable: [
// TODO: Register
{
id: "MYTH",
address: "0xb34a6924a02100ba6ef12af1c798285e8f7a16ee",
minimumTransferAmount: 10_000_000_000_000_000n,
},
],
},
{
id: "bifrost",
name: "Bifrost",
type: "substrate",
destinationIds: [],
paraInfo: {
paraId: 2030,
destinationFeeDOT: 20_000_000n,
skipExistentialDepositCheck: false,
addressType: "32byte",
decimals: 12,
maxConsumers: 16,
},
erc20tokensReceivable: [
// TODO: Register
{
id: "WETH",
address: "0xfff9976782d46cc05630d1f6ebab18b2324d6b14",
minimumTransferAmount: 15_000_000_000_000n,
},
],
},
{
id: "hydradx",
name: "Hydration",
type: "substrate",
destinationIds: [],
paraInfo: {
paraId: 2034,
destinationFeeDOT: 100_000_000n,
skipExistentialDepositCheck: true,
addressType: "32byte",
decimals: 12,
maxConsumers: 16,
},
erc20tokensReceivable: [
{
id: "WETH",
address: "0xfff9976782d46cc05630d1f6ebab18b2324d6b14",
minimumTransferAmount: 15_000_000_000_000n,
},
// Todo fix token metadata
//{
// id: "WBTC",
// address: "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
// minimumTransferAmount: 1n,
//},
],
},
],
config: {
BEACON_HTTP_API: "https://lodestar-sepolia.chainsafe.io",
ETHEREUM_API: (key) => `https://eth-sepolia.g.alchemy.com/v2/${key}`,
RELAY_CHAIN_URL: "wss://paseo-rpc.dwellir.com",
ASSET_HUB_URL: "wss://asset-hub-paseo-rpc.dwellir.com",
BRIDGE_HUB_URL: "wss://bridge-hub-paseo.dotters.network",
PARACHAINS: [],
PARACHAINS: {
1000: "wss://asset-hub-paseo-rpc.dwellir.com",
1002: "wss://bridge-hub-paseo.dotters.network",
},
GATEWAY_CONTRACT: "0x5a84b15B618beEE6F6285F6bd2bA20a08673e473",
BEEFY_CONTRACT: "0xE7388f953f50d377D131350490156dB649E5DC10",
ASSET_HUB_PARAID: 1000,
Expand Down Expand Up @@ -283,7 +355,7 @@ export const SNOWBRIDGE_ENV: { [id: string]: SnowbridgeEnvironment } = {
id: "ethereum",
name: "Ethereum",
type: "ethereum",
destinationIds: ["assethub", "mythos", "bifrost"],
destinationIds: ["assethub", "mythos", "bifrost", "hydradx", "moonbeam"],
erc20tokensReceivable: [
{
id: "WETH",
Expand Down Expand Up @@ -455,14 +527,73 @@ export const SNOWBRIDGE_ENV: { [id: string]: SnowbridgeEnvironment } = {
},
],
},
{
id: "hydradx",
name: "Hydration",
type: "substrate",
destinationIds: [],
paraInfo: {
paraId: 2034,
destinationFeeDOT: 100_000_000n,
skipExistentialDepositCheck: true,
addressType: "32byte",
decimals: 12,
maxConsumers: 16,
},
erc20tokensReceivable: [
{
id: "WETH",
address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
minimumTransferAmount: 15_000_000_000_000n,
},
{
id: "WBTC",
address: "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
minimumTransferAmount: 1n,
},
],
},
{
id: "moonbeam",
name: "Moonbeam",
type: "substrate",
destinationIds: [],
paraInfo: {
paraId: 2004,
destinationFeeDOT: 100_000_000n,
skipExistentialDepositCheck: false,
addressType: "20byte",
decimals: 18,
maxConsumers: 16,
},
erc20tokensReceivable: [
{
id: "WETH",
address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
minimumTransferAmount: 15_000_000_000_000n,
},
{
id: "WBTC",
address: "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
minimumTransferAmount: 1n,
},
{
id: "wstETH",
address: "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0",
minimumTransferAmount: 1n,
},
],
},
],
config: {
BEACON_HTTP_API: "https://lodestar-mainnet.chainsafe.io",
ETHEREUM_API: (key) => `https://eth-mainnet.g.alchemy.com/v2/${key}`,
RELAY_CHAIN_URL: "https://polkadot-rpc.dwellir.com",
ASSET_HUB_URL: "wss://asset-hub-polkadot-rpc.dwellir.com",
BRIDGE_HUB_URL: "https://bridge-hub-polkadot-rpc.dwellir.com",
PARACHAINS: ["https://polkadot-mythos-rpc.polkadot.io"],
PARACHAINS: {
1000: "wss://asset-hub-polkadot-rpc.dwellir.com",
1002: "https://bridge-hub-polkadot-rpc.dwellir.com",
3369: "https://polkadot-mythos-rpc.polkadot.io",
},
GATEWAY_CONTRACT: "0x27ca963c279c93801941e1eb8799c23f407d68e7",
BEEFY_CONTRACT: "0x6eD05bAa904df3DE117EcFa638d4CB84e1B8A00C",
ASSET_HUB_PARAID: 1000,
Expand Down Expand Up @@ -554,9 +685,10 @@ export const SNOWBRIDGE_ENV: { [id: string]: SnowbridgeEnvironment } = {
BEACON_HTTP_API: "https://lodestar-sepolia.chainsafe.io",
ETHEREUM_API: (key) => `https://eth-sepolia.g.alchemy.com/v2/${key}`,
RELAY_CHAIN_URL: "https://westend-rpc.polkadot.io",
ASSET_HUB_URL: "wss://westend-asset-hub-rpc.polkadot.io",
BRIDGE_HUB_URL: "https://westend-bridge-hub-rpc.polkadot.io",
PARACHAINS: [],
PARACHAINS: {
1000: "wss://westend-asset-hub-rpc.polkadot.io",
1002: "https://westend-bridge-hub-rpc.polkadot.io",
},
GATEWAY_CONTRACT: "0x9ed8b47bc3417e3bd0507adc06e56e2fa360a4e9",
BEEFY_CONTRACT: "0x6DFaD3D73A28c48E4F4c616ECda80885b415283a",
ASSET_HUB_PARAID: 1000,
Expand Down
Loading
Loading