Skip to content

Commit

Permalink
Snowbridge API updates (#1192)
Browse files Browse the repository at this point in the history
* update packages

* remove ui

* updated version numbers

* added configuration for enviroments

* token metadata

* export types

* added more metadata

* update sources

* add destination fee

* add fee functions

* refactor error bools to list of errors

* fixes

* use list of errors with codes

* fixes

* downgrade ethers

* downgrade ethers

* update back to 6.12.1 ethers

* more fix
  • Loading branch information
alistair-singh authored May 8, 2024
1 parent b666f13 commit e579711
Show file tree
Hide file tree
Showing 36 changed files with 4,422 additions and 14,329 deletions.
29 changes: 29 additions & 0 deletions contracts/src/interfaces/extensions/IERC20Metadata.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2024 Snowfork <[email protected]>
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.23;

import "../IERC20.sol";

/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);

/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);

/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
8 changes: 4 additions & 4 deletions web/packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snowbridge/api",
"version": "0.1.2",
"version": "0.1.3",
"description": "Snowbridge API client",
"license": "Apache-2.0",
"repository": {
Expand All @@ -26,14 +26,14 @@
"typescript": "^5.4.5"
},
"dependencies": {
"@polkadot/api": "^10.12.6",
"@polkadot/api": "^11.0.2",
"@polkadot/keyring": "^12.6.2",
"@polkadot/types": "^10.12.6",
"@polkadot/types": "^11.0.2",
"@polkadot/util": "^12.6.2",
"@polkadot/util-crypto": "^12.6.2",
"@snowbridge/contract-types": "workspace:*",
"@typechain/ethers-v6": "^0.5.1",
"ethers": "^6.11.1",
"ethers": "^6.12.1",
"rxjs": "^7.8.1"
}
}
174 changes: 174 additions & 0 deletions web/packages/api/src/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@

export type Config = {
BEACON_HTTP_API: string
ETHEREUM_WS_API: (secret: string) => string
RELAY_CHAIN_WS_URL: string
ASSET_HUB_WS_URL: string
BRIDGE_HUB_WS_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[]
}

export type SourceType = 'substrate' | 'ethereum'
export type Relayer = { name: string, account: string, type: SourceType }
export type ParachainInfo = { paraId: number, destinationFeeDOT: bigint, has20ByteAccounts: boolean, decimals: number }
export type TransferLocation = {
id: string
name: string
type: SourceType
destinationIds: string[]
paraInfo?: ParachainInfo
erc20tokensReceivable: { [name: string]: string }
}

export type SnowbridgeEnvironment = {
config: Config
name: string
locations: TransferLocation[]
}

export const SNOWBRIDGE_ENV: { [id: string]: SnowbridgeEnvironment } = {
'local_e2e': {
name: 'local_e2e',
locations: [{
id: 'ethereum',
name: 'Ethereum',
type: 'ethereum',
destinationIds: ['assethub', 'penpal'],
erc20tokensReceivable: {
"WETH": '0x87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d',
},
},
{
id: 'assethub',
name: 'Asset Hub',
type: 'substrate',
destinationIds: ['ethereum'],
paraInfo: {
paraId: 1000,
destinationFeeDOT: 0n,
has20ByteAccounts: false,
decimals: 12,
},
erc20tokensReceivable: {
"WETH": '0x87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d',
},
},
{
id: 'penpal',
name: 'Penpal',
type: 'substrate',
destinationIds: ["ethereum"],
paraInfo: {
paraId: 2000,
destinationFeeDOT: 4_000_000_000n,
has20ByteAccounts: false,
decimals: 12,
},
erc20tokensReceivable: {
"WETH": '0x87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d',
},
}],
config: {
BEACON_HTTP_API: 'http://127.0.0.1:9596',
ETHEREUM_WS_API: (_) => 'ws://127.0.0.1:8546',
RELAY_CHAIN_WS_URL: 'ws://127.0.0.1:9944',
ASSET_HUB_WS_URL: 'ws://127.0.0.1:12144',
BRIDGE_HUB_WS_URL: 'ws://127.0.0.1:11144',
PARACHAINS: ['ws://127.0.0.1:13144'],
GATEWAY_CONTRACT: '0xEDa338E4dC46038493b885327842fD3E301CaB39',
BEEFY_CONTRACT: '0x992B9df075935E522EC7950F37eC8557e86f6fdb',
ASSET_HUB_PARAID: 1000,
BRIDGE_HUB_PARAID: 1013,
PRIMARY_GOVERNANCE_CHANNEL_ID: '0x0000000000000000000000000000000000000000000000000000000000000001',
SECONDARY_GOVERNANCE_CHANNEL_ID: '0x0000000000000000000000000000000000000000000000000000000000000002',
RELAYERS: [
{ name: 'beacon', account: '5GWFwdZb6JyU46e6ZiLxjGxogAHe8SenX76btfq8vGNAaq8c', type: 'substrate' },
{ name: 'beefy', account: '0x87D987206180B8f3807Dd90455606eEa85cdB87a', type: 'ethereum' },
{ name: 'parachain-primary-gov', account: '0xeEBFA6B9242A19f91a0463291A937a20e3355681', type: 'ethereum' },
{ name: 'parachain-secondary-gov', account: '0x13e16C4e5787f878f98a610EB321170512b134D4', type: 'ethereum' },
{ name: 'execution-assethub', account: '5DF6KbMTBPGQN6ScjqXzdB2ngk5wi3wXvubpQVUZezNfM6aV', type: 'substrate' },
{ name: 'parachain-assethub', account: '0x8b66D5499F52D6F1857084A61743dFCB9a712859', type: 'ethereum' },
{ name: 'execution-penpal', account: '5HgmfVcc8xBUcReNJsUaJMhFWGkdYpEw4RiCX4SeZPdKXR6H', type: 'substrate' },
{ name: 'parachain-penpal', account: '0x01F6749035e02205768f97e6f1d394Fb6769EC20', type: 'ethereum' },
],
},
},
'rococo_sepolia': {
name: 'rococo_sepolia',
locations: [{
id: 'ethereum',
name: 'Ethereum',
type: 'ethereum',
destinationIds: ['assethub', 'muse'],
erc20tokensReceivable: {
"WETH": '0xfff9976782d46cc05630d1f6ebab18b2324d6b14',
"vETH": '0xc3d088842dcf02c13699f936bb83dfbbc6f721ab',
"MUSE1": '0xb34a6924a02100ba6ef12af1c798285e8f7a16ee',
"MUSE2": '0xc9f05326311bc2a55426761bec20057685fb80f7',
},
},
{
id: 'assethub',
name: 'Asset Hub',
type: 'substrate',
destinationIds: ['ethereum'],
paraInfo: {
paraId: 1000,
destinationFeeDOT: 0n,
has20ByteAccounts: false,
decimals: 12,
},
erc20tokensReceivable: {
"WETH": '0xfff9976782d46cc05630d1f6ebab18b2324d6b14',
"vETH": '0xc3d088842dcf02c13699f936bb83dfbbc6f721ab',
"MUSE1": '0xb34a6924a02100ba6ef12af1c798285e8f7a16ee',
"MUSE2": '0xc9f05326311bc2a55426761bec20057685fb80f7',
},
},
{
id: 'muse',
name: 'Muse',
type: 'substrate',
destinationIds: [],
paraInfo: {
paraId: 3369,
destinationFeeDOT: 4_000_000_000n,
has20ByteAccounts: true,
decimals: 12,
},
erc20tokensReceivable: {
"MUSE1": '0xb34a6924a02100ba6ef12af1c798285e8f7a16ee',
"MUSE2": '0xc9f05326311bc2a55426761bec20057685fb80f7',
},
}],
config: {
BEACON_HTTP_API: 'https://lodestar-sepolia.chainsafe.io',
ETHEREUM_WS_API: (key) => `https://eth-sepolia.g.alchemy.com/v2/${key}`,
RELAY_CHAIN_WS_URL: 'wss://rococo-rpc.polkadot.io',
ASSET_HUB_WS_URL: 'wss://rococo-asset-hub-rpc.polkadot.io',
BRIDGE_HUB_WS_URL: 'wss://rococo-bridge-hub-rpc.polkadot.io',
PARACHAINS: ['wss://rococo-muse-rpc.polkadot.io'],
GATEWAY_CONTRACT: '0x5b4909ce6ca82d2ce23bd46738953c7959e710cd',
BEEFY_CONTRACT: '0x27e5e17ac995d3d720c311e1e9560e28f5855fb1',
ASSET_HUB_PARAID: 1000,
BRIDGE_HUB_PARAID: 1013,
PRIMARY_GOVERNANCE_CHANNEL_ID: '0x0000000000000000000000000000000000000000000000000000000000000001',
SECONDARY_GOVERNANCE_CHANNEL_ID: '0x0000000000000000000000000000000000000000000000000000000000000002',
RELAYERS: [
{ name: 'beacon', account: '5FyC9GkHhiAYjMtddwVNc2gx8wBjH9gpMKWbQ1QVXmmJtr8M', type: 'substrate' },
{ name: 'beefy', account: '0xF061685F2B729b89a7A5966B3ab9aee15269e8FE', type: 'ethereum' },
{ name: 'parachain-primary-gov', account: '0xE3f4e40E0dB2F828e248dB2790958035BaB1a4B5', type: 'ethereum' },
{ name: 'parachain-secondary-gov', account: '0x71429d3B9d68557C2F49e42e12B9cf7edAADCe3D', type: 'ethereum' },
{ name: 'execution-assethub', account: '5GeLu5rPcaoZ2RVDbhX8DKJt8NxnKn6DvvjfuhnwTZyYRY59', type: 'substrate' },
{ name: 'parachain-assethub', account: '0x0b65d43d159f1C40Bad7768fd59667E3104a2ECE', type: 'ethereum' },
],
},
}
};
1 change: 1 addition & 0 deletions web/packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,4 @@ export * as toPolkadot from './toPolkadot'
export * as toEthereum from './toEthereum'
export * as utils from './utils'
export * as status from './status'
export * as environment from './environment'
18 changes: 14 additions & 4 deletions web/packages/api/src/status.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IERC20__factory } from '@snowbridge/contract-types'
import { IERC20Metadata__factory, IERC20__factory } from '@snowbridge/contract-types'
import { Context } from './index'
import { fetchBeaconSlot } from './utils'

Expand Down Expand Up @@ -132,7 +132,7 @@ export const assetStatusInfo = async (context: Context, tokenAddress: string, ow
const tokenContract = IERC20__factory.connect(tokenAddress, context.ethereum.api)
let ownerBalance = BigInt(0)
let tokenGatewayAllowance = BigInt(0)
let tokenIsValidERC20 = true
let isValidERC20 = true
try {
const owner = ownerAddress || "0x0000000000000000000000000000000000000000"
const [tokenBalance_, tokenGatewayAllowance_] = await Promise.all([
Expand All @@ -142,13 +142,13 @@ export const assetStatusInfo = async (context: Context, tokenAddress: string, ow
ownerBalance = tokenBalance_
tokenGatewayAllowance = tokenGatewayAllowance_
} catch {
tokenIsValidERC20 = false
isValidERC20 = false
}

return {
ethereumChainId,
multiLocation,
tokenIsValidERC20,
isValidERC20,
tokenContract,
isTokenRegistered,
tokenGatewayAllowance,
Expand All @@ -157,3 +157,13 @@ export const assetStatusInfo = async (context: Context, tokenAddress: string, ow
foreignAsset,
}
}

export const assetMetadata = async (context: Context, tokenAddress: string) => {
const tokenMetadata = IERC20Metadata__factory.connect(tokenAddress, context.ethereum.api)
const [name, symbol, decimal] = await Promise.all([
tokenMetadata.name(),
tokenMetadata.symbol(),
tokenMetadata.decimals(),
])
return { name, symbol, decimal }
}
Loading

0 comments on commit e579711

Please sign in to comment.