plugins-network.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.FetchUrlFeeDataNetworkPlugin = exports.FeeDataNetworkPlugin = exports.EnsPlugin = exports.GasCostPlugin = exports.NetworkPlugin = void 0;
  4. const properties_js_1 = require("../utils/properties.js");
  5. const index_js_1 = require("../utils/index.js");
  6. const EnsAddress = "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e";
  7. /**
  8. * A **NetworkPlugin** provides additional functionality on a [[Network]].
  9. */
  10. class NetworkPlugin {
  11. /**
  12. * The name of the plugin.
  13. *
  14. * It is recommended to use reverse-domain-notation, which permits
  15. * unique names with a known authority as well as hierarchal entries.
  16. */
  17. name;
  18. /**
  19. * Creates a new **NetworkPlugin**.
  20. */
  21. constructor(name) {
  22. (0, properties_js_1.defineProperties)(this, { name });
  23. }
  24. /**
  25. * Creates a copy of this plugin.
  26. */
  27. clone() {
  28. return new NetworkPlugin(this.name);
  29. }
  30. }
  31. exports.NetworkPlugin = NetworkPlugin;
  32. /**
  33. * A **GasCostPlugin** allows a network to provide alternative values when
  34. * computing the intrinsic gas required for a transaction.
  35. */
  36. class GasCostPlugin extends NetworkPlugin {
  37. /**
  38. * The block number to treat these values as valid from.
  39. *
  40. * This allows a hardfork to have updated values included as well as
  41. * mulutiple hardforks to be supported.
  42. */
  43. effectiveBlock;
  44. /**
  45. * The transactions base fee.
  46. */
  47. txBase;
  48. /**
  49. * The fee for creating a new account.
  50. */
  51. txCreate;
  52. /**
  53. * The fee per zero-byte in the data.
  54. */
  55. txDataZero;
  56. /**
  57. * The fee per non-zero-byte in the data.
  58. */
  59. txDataNonzero;
  60. /**
  61. * The fee per storage key in the [[link-eip-2930]] access list.
  62. */
  63. txAccessListStorageKey;
  64. /**
  65. * The fee per address in the [[link-eip-2930]] access list.
  66. */
  67. txAccessListAddress;
  68. /**
  69. * Creates a new GasCostPlugin from %%effectiveBlock%% until the
  70. * latest block or another GasCostPlugin supercedes that block number,
  71. * with the associated %%costs%%.
  72. */
  73. constructor(effectiveBlock, costs) {
  74. if (effectiveBlock == null) {
  75. effectiveBlock = 0;
  76. }
  77. super(`org.ethers.network.plugins.GasCost#${(effectiveBlock || 0)}`);
  78. const props = { effectiveBlock };
  79. function set(name, nullish) {
  80. let value = (costs || {})[name];
  81. if (value == null) {
  82. value = nullish;
  83. }
  84. (0, index_js_1.assertArgument)(typeof (value) === "number", `invalud value for ${name}`, "costs", costs);
  85. props[name] = value;
  86. }
  87. set("txBase", 21000);
  88. set("txCreate", 32000);
  89. set("txDataZero", 4);
  90. set("txDataNonzero", 16);
  91. set("txAccessListStorageKey", 1900);
  92. set("txAccessListAddress", 2400);
  93. (0, properties_js_1.defineProperties)(this, props);
  94. }
  95. clone() {
  96. return new GasCostPlugin(this.effectiveBlock, this);
  97. }
  98. }
  99. exports.GasCostPlugin = GasCostPlugin;
  100. /**
  101. * An **EnsPlugin** allows a [[Network]] to specify the ENS Registry
  102. * Contract address and the target network to use when using that
  103. * contract.
  104. *
  105. * Various testnets have their own instance of the contract to use, but
  106. * in general, the mainnet instance supports multi-chain addresses and
  107. * should be used.
  108. */
  109. class EnsPlugin extends NetworkPlugin {
  110. /**
  111. * The ENS Registrty Contract address.
  112. */
  113. address;
  114. /**
  115. * The chain ID that the ENS contract lives on.
  116. */
  117. targetNetwork;
  118. /**
  119. * Creates a new **EnsPlugin** connected to %%address%% on the
  120. * %%targetNetwork%%. The default ENS address and mainnet is used
  121. * if unspecified.
  122. */
  123. constructor(address, targetNetwork) {
  124. super("org.ethers.plugins.network.Ens");
  125. (0, properties_js_1.defineProperties)(this, {
  126. address: (address || EnsAddress),
  127. targetNetwork: ((targetNetwork == null) ? 1 : targetNetwork)
  128. });
  129. }
  130. clone() {
  131. return new EnsPlugin(this.address, this.targetNetwork);
  132. }
  133. }
  134. exports.EnsPlugin = EnsPlugin;
  135. /**
  136. * A **FeeDataNetworkPlugin** allows a network to provide and alternate
  137. * means to specify its fee data.
  138. *
  139. * For example, a network which does not support [[link-eip-1559]] may
  140. * choose to use a Gas Station site to approximate the gas price.
  141. */
  142. class FeeDataNetworkPlugin extends NetworkPlugin {
  143. #feeDataFunc;
  144. /**
  145. * The fee data function provided to the constructor.
  146. */
  147. get feeDataFunc() {
  148. return this.#feeDataFunc;
  149. }
  150. /**
  151. * Creates a new **FeeDataNetworkPlugin**.
  152. */
  153. constructor(feeDataFunc) {
  154. super("org.ethers.plugins.network.FeeData");
  155. this.#feeDataFunc = feeDataFunc;
  156. }
  157. /**
  158. * Resolves to the fee data.
  159. */
  160. async getFeeData(provider) {
  161. return await this.#feeDataFunc(provider);
  162. }
  163. clone() {
  164. return new FeeDataNetworkPlugin(this.#feeDataFunc);
  165. }
  166. }
  167. exports.FeeDataNetworkPlugin = FeeDataNetworkPlugin;
  168. class FetchUrlFeeDataNetworkPlugin extends NetworkPlugin {
  169. #url;
  170. #processFunc;
  171. /**
  172. * The URL to initialize the FetchRequest with in %%processFunc%%.
  173. */
  174. get url() { return this.#url; }
  175. /**
  176. * The callback to use when computing the FeeData.
  177. */
  178. get processFunc() { return this.#processFunc; }
  179. /**
  180. * Creates a new **FetchUrlFeeDataNetworkPlugin** which will
  181. * be used when computing the fee data for the network.
  182. */
  183. constructor(url, processFunc) {
  184. super("org.ethers.plugins.network.FetchUrlFeeDataPlugin");
  185. this.#url = url;
  186. this.#processFunc = processFunc;
  187. }
  188. // We are immutable, so we can serve as our own clone
  189. clone() { return this; }
  190. }
  191. exports.FetchUrlFeeDataNetworkPlugin = FetchUrlFeeDataNetworkPlugin;
  192. /*
  193. export class CustomBlockNetworkPlugin extends NetworkPlugin {
  194. readonly #blockFunc: (provider: Provider, block: BlockParams<string>) => Block<string>;
  195. readonly #blockWithTxsFunc: (provider: Provider, block: BlockParams<TransactionResponseParams>) => Block<TransactionResponse>;
  196. constructor(blockFunc: (provider: Provider, block: BlockParams<string>) => Block<string>, blockWithTxsFunc: (provider: Provider, block: BlockParams<TransactionResponseParams>) => Block<TransactionResponse>) {
  197. super("org.ethers.network-plugins.custom-block");
  198. this.#blockFunc = blockFunc;
  199. this.#blockWithTxsFunc = blockWithTxsFunc;
  200. }
  201. async getBlock(provider: Provider, block: BlockParams<string>): Promise<Block<string>> {
  202. return await this.#blockFunc(provider, block);
  203. }
  204. async getBlockions(provider: Provider, block: BlockParams<TransactionResponseParams>): Promise<Block<TransactionResponse>> {
  205. return await this.#blockWithTxsFunc(provider, block);
  206. }
  207. clone(): CustomBlockNetworkPlugin {
  208. return new CustomBlockNetworkPlugin(this.#blockFunc, this.#blockWithTxsFunc);
  209. }
  210. }
  211. */
  212. //# sourceMappingURL=plugins-network.js.map