Skip to content

Commit

Permalink
Initial Cosmwasm
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin committed Sep 20, 2023
1 parent 38a54fb commit fe3367c
Show file tree
Hide file tree
Showing 36 changed files with 8,866 additions and 111 deletions.
84 changes: 5 additions & 79 deletions core/base/src/constants/platforms.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ChainName } from "./chains";
import { Network } from "./networks";
import { RoArray, ToMapping, column, constMap } from "../utils";
import { RoArray, column, constMap } from "../utils";

const platformAndChainsEntries = [
[
Expand All @@ -27,13 +26,14 @@ const platformAndChainsEntries = [
],
],
["Solana", ["Solana", "Pythnet"]],
["Cosmwasm", ["Terra", "Terra2", "Injective", "Xpla", "Sei"]],
[
"Cosmwasm",
["Terra", "Terra2", "Injective", "Xpla", "Sei", "Osmosis", "Wormchain"],
],
["Btc", ["Btc"]],
["Algorand", ["Algorand"]],
["Sui", ["Sui"]],
["Aptos", ["Aptos"]],
["Osmosis", ["Osmosis"]],
["Wormchain", ["Wormchain"]],
["Near", ["Near"]],
] as const satisfies RoArray<readonly [string, RoArray<ChainName>]>;

Expand All @@ -52,77 +52,3 @@ export type PlatformToChains<P extends PlatformName> = ReturnType<
export type ChainToPlatform<C extends ChainName> = ReturnType<
typeof chainToPlatform<C>
>;

const networkChainEvmCIdEntries = [
[
"Mainnet",
[
["Ethereum", 1n],
// TODO: forced to add this to match other list
["Sepolia", 0n],
["Bsc", 56n],
["Polygon", 137n],
["Avalanche", 43114n],
["Oasis", 42262n],
["Aurora", 1313161554n],
["Fantom", 250n],
["Karura", 686n],
["Acala", 787n],
["Klaytn", 8217n],
["Celo", 42220n],
["Moonbeam", 1284n],
["Neon", 245022934n],
["Arbitrum", 42161n],
["Optimism", 10n],
["Gnosis", 100n],
["Base", 8453n],
],
],
[
"Testnet",
[
["Ethereum", 5n], //goerli
["Sepolia", 11155111n], //actually just another ethereum testnet...
["Bsc", 97n],
["Polygon", 80001n], //mumbai
["Avalanche", 43113n], //fuji
["Oasis", 42261n],
["Aurora", 1313161555n],
["Fantom", 4002n],
["Karura", 596n],
["Acala", 597n],
["Klaytn", 1001n], //baobab
["Celo", 44787n], //alfajores
["Moonbeam", 1287n], //moonbase alpha
["Neon", 245022940n],
["Arbitrum", 421613n], //arbitrum goerli
["Optimism", 420n],
["Gnosis", 77n],
["Base", 84531n],
],
],
] as const satisfies RoArray<
readonly [Network, RoArray<readonly [PlatformToChains<"Evm">, bigint]>]
>;

export const evmChainIdToNetworkChainPair = constMap(
networkChainEvmCIdEntries,
[2, [0, 1]]
);
export const evmNetworkChainToEvmChainId = constMap(networkChainEvmCIdEntries);

const networkChainSolanaGenesisHashes = [
["Mainnet", [["Solana", "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d"]]],
["Testnet", [["Solana", "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG"]]], // Note: this is referred to as `devnet` in sol
] as const satisfies RoArray<
readonly [Network, RoArray<readonly [ChainName, string]>]
>;

export const solGenesisHashToNetworkChainPair = constMap(
networkChainSolanaGenesisHashes,
[2, [0, 1]]
);

export const solNetworkChainToGenesisHash = constMap(
networkChainSolanaGenesisHashes
);
15 changes: 13 additions & 2 deletions core/definitions/src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@ export interface EvmRpc {
broadcastTransaction(stxns: string): Promise<any>;
getBalance(address: string): Promise<bigint>;
}
export interface SolRpc {
export interface SolanaRpc {
getBalance(publicKey: any, commitmentOrConfig: any): Promise<number>;
getParsedAccountInfo(publickKey: any): Promise<any>;
}

export interface CosmWasmRpc {
getBalance(address: string, searchDenom: string): Promise<any>;
broadcastTx(
tx: Uint8Array,
timeoutMs?: number,
pollIntervalMs?: number
): Promise<any>;
}

export type RpcConnection<P extends PlatformName> = P extends "Evm"
? EvmRpc
: P extends "Solana"
? SolRpc
? SolanaRpc
: P extends "Cosmwasm"
? CosmWasmRpc
: never;
Loading

0 comments on commit fe3367c

Please sign in to comment.