chains.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import { ChainExecutor } from "./chain-executor";
  2. import { CosmwasmExecutor } from "./cosmwasm";
  3. import { InjectiveExecutor } from "./injective";
  4. import { Network } from "@injectivelabs/networks";
  5. export enum ChainType {
  6. INJECTIVE = "injective",
  7. COSMWASM = "cosmwasm",
  8. }
  9. // GUIDELINES: to add new chains
  10. // ENUM Key should be of the form:
  11. // CHAINNAME{_OPTIONAL-IDENTIFIER}
  12. // ENUM Value should be of the form:
  13. // chainname{_optional-identifier}
  14. export enum ChainId {
  15. INJECTIVE_TESTNET = "injective_testnet",
  16. OSMOSIS_TESTNET_5 = "osmosis_testnet_5",
  17. SEI_TESTNET_ATLANTIC_2 = "sei_testnet_atlantic_2",
  18. NEUTRON_TESTNET_PION_1 = "neutron_testnet_pion_1",
  19. JUNO_TESTNET = "juno_testnet",
  20. // Below are mainnet chain ids
  21. INJECTIVE = "injective",
  22. OSMOSIS = "osmosis",
  23. SEI_PACIFIC_1 = "sei_pacific_1",
  24. NEUTRON = "neutron",
  25. }
  26. export const ChainIds = Object.values(ChainId);
  27. export type ChainNetworkConfig =
  28. | {
  29. // usually the chain name
  30. // osmosis, injective
  31. chainId: ChainId;
  32. chainType: ChainType.INJECTIVE;
  33. // endpoints to create executor and querier for a particular chain
  34. querierEndpoint: string;
  35. executorEndpoint: string;
  36. }
  37. | {
  38. // usually the chain name
  39. // osmosis, injective
  40. chainId: ChainId;
  41. chainType: ChainType.COSMWASM;
  42. // endpoints to create executor and querier for a particular chain
  43. querierEndpoint: string;
  44. executorEndpoint: string;
  45. // some extra fields
  46. // prefix of the particular cosmwasm chain
  47. // eg "osmo"
  48. prefix: string;
  49. // gas price for that chain
  50. // eg "0.025 uosmo"
  51. gasPrice: string;
  52. };
  53. export const CHAINS_NETWORK_CONFIG: Record<ChainId, ChainNetworkConfig> = {
  54. [ChainId.INJECTIVE_TESTNET]: {
  55. chainId: ChainId.INJECTIVE_TESTNET,
  56. chainType: ChainType.INJECTIVE,
  57. querierEndpoint: "https://k8s.testnet.tm.injective.network:443",
  58. executorEndpoint: "https://k8s.testnet.chain.grpc-web.injective.network",
  59. },
  60. [ChainId.OSMOSIS_TESTNET_5]: {
  61. chainId: ChainId.OSMOSIS_TESTNET_5,
  62. chainType: ChainType.COSMWASM,
  63. executorEndpoint: "https://rpc.osmotest5.osmosis.zone/",
  64. querierEndpoint: "https://rpc.osmotest5.osmosis.zone/",
  65. prefix: "osmo",
  66. gasPrice: "0.025uosmo",
  67. },
  68. [ChainId.SEI_TESTNET_ATLANTIC_2]: {
  69. chainId: ChainId.SEI_TESTNET_ATLANTIC_2,
  70. chainType: ChainType.COSMWASM,
  71. executorEndpoint: "https://rpc.atlantic-2.seinetwork.io/",
  72. querierEndpoint: "https://rpc.atlantic-2.seinetwork.io/",
  73. prefix: "sei",
  74. gasPrice: "0.01usei",
  75. },
  76. [ChainId.NEUTRON_TESTNET_PION_1]: {
  77. chainId: ChainId.NEUTRON_TESTNET_PION_1,
  78. chainType: ChainType.COSMWASM,
  79. executorEndpoint: "https://rpc-palvus.pion-1.ntrn.tech/",
  80. querierEndpoint: "https://rpc-palvus.pion-1.ntrn.tech/",
  81. prefix: "neutron",
  82. gasPrice: "0.025untrn",
  83. },
  84. [ChainId.JUNO_TESTNET]: {
  85. chainId: ChainId.JUNO_TESTNET,
  86. chainType: ChainType.COSMWASM,
  87. executorEndpoint: "https://rpc.uni.junonetwork.io/",
  88. querierEndpoint: "https://rpc.uni.junonetwork.io/",
  89. prefix: "juno",
  90. gasPrice: "0.025ujunox",
  91. },
  92. // Mainnet chains
  93. [ChainId.INJECTIVE]: {
  94. chainId: ChainId.INJECTIVE,
  95. chainType: ChainType.INJECTIVE,
  96. querierEndpoint: "https://k8s.testnet.tm.injective.network:443",
  97. executorEndpoint: "https://k8s.testnet.chain.grpc-web.injective.network",
  98. },
  99. [ChainId.OSMOSIS]: {
  100. chainId: ChainId.OSMOSIS,
  101. chainType: ChainType.COSMWASM,
  102. executorEndpoint: "https://rpc.osmosis.zone:443",
  103. querierEndpoint: "https://rpc.osmosis.zone:443",
  104. prefix: "osmo",
  105. gasPrice: "0.025uosmo",
  106. },
  107. [ChainId.SEI_PACIFIC_1]: {
  108. chainId: ChainId.SEI_PACIFIC_1,
  109. chainType: ChainType.COSMWASM,
  110. executorEndpoint: "https://sei-rpc.polkachu.com",
  111. querierEndpoint: "https://sei-rpc.polkachu.com",
  112. prefix: "sei",
  113. gasPrice: "0.025usei",
  114. },
  115. [ChainId.NEUTRON]: {
  116. chainId: ChainId.NEUTRON,
  117. chainType: ChainType.COSMWASM,
  118. executorEndpoint: "https://rpc-kralum.neutron-1.neutron.org",
  119. querierEndpoint: "https://rpc-kralum.neutron-1.neutron.org",
  120. prefix: "neutron",
  121. gasPrice: "0.025untrn",
  122. },
  123. };
  124. /**
  125. * This method will return an executor for given chainConfig.
  126. */
  127. export async function createExecutorForChain(
  128. chainConfig: ChainNetworkConfig,
  129. mnemonic: string
  130. ): Promise<ChainExecutor> {
  131. const chainType = chainConfig.chainType;
  132. if (chainType === ChainType.INJECTIVE) {
  133. return InjectiveExecutor.fromMnemonic(
  134. chainConfig.chainId === ChainId.INJECTIVE_TESTNET
  135. ? Network.Testnet
  136. : Network.Mainnet,
  137. mnemonic
  138. );
  139. } else
  140. return new CosmwasmExecutor(
  141. chainConfig.executorEndpoint,
  142. await CosmwasmExecutor.getSignerFromMnemonic(
  143. mnemonic,
  144. chainConfig.prefix
  145. ),
  146. chainConfig.gasPrice
  147. );
  148. }