@hybrd/utils 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -19,12 +19,63 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/index.ts
20
20
  var src_exports = {};
21
21
  __export(src_exports, {
22
+ bipsToDecimal: () => bipsToDecimal,
23
+ bipsToPercent: () => bipsToPercent,
24
+ chainName: () => chainName,
25
+ ethToWei: () => ethToWei,
22
26
  etherscanAddressURL: () => etherscanAddressURL,
23
27
  etherscanHost: () => etherscanHost,
24
- etherscanTxURL: () => etherscanTxURL
28
+ etherscanTxURL: () => etherscanTxURL,
29
+ percentToBips: () => percentToBips,
30
+ truncateEthAddress: () => truncateEthAddress,
31
+ weiToEth: () => weiToEth
25
32
  });
26
33
  module.exports = __toCommonJS(src_exports);
27
34
 
35
+ // src/basisPoints.ts
36
+ function bipsToPercent(bp) {
37
+ if (typeof bp !== "number")
38
+ return null;
39
+ return parseInt(bp.toString()) / 100;
40
+ }
41
+ function percentToBips(percent) {
42
+ return percent * 100;
43
+ }
44
+ function bipsToDecimal(bp) {
45
+ if (typeof bp !== "number")
46
+ return 0;
47
+ return parseInt(bp.toString()) / 1e4;
48
+ }
49
+
50
+ // src/chains.ts
51
+ function chainName(chainId) {
52
+ switch (parseInt(chainId.toString())) {
53
+ case 1:
54
+ return `Ethereum`;
55
+ case 3:
56
+ return `Ropsten`;
57
+ case 4:
58
+ return `Rinkeby`;
59
+ case 5:
60
+ return `Goerli`;
61
+ case 137:
62
+ return `Polygon`;
63
+ case 80001:
64
+ return `Mumbai`;
65
+ }
66
+ }
67
+
68
+ // src/conversion.ts
69
+ var import_ethers = require("ethers");
70
+ function weiToEth(wei) {
71
+ return parseFloat(import_ethers.utils.formatEther(wei.toString()));
72
+ }
73
+ function ethToWei(eth) {
74
+ if (typeof eth === "undefined")
75
+ return null;
76
+ return import_ethers.ethers.utils.parseUnits(eth.toString(), "ether");
77
+ }
78
+
28
79
  // src/etherscan.ts
29
80
  function etherscanAddressURL(address, chainId = 1) {
30
81
  return etherscanHost(chainId) + "/address/" + address;
@@ -50,10 +101,24 @@ function etherscanHost(chainId = 1) {
50
101
  throw new Error("Etherscan: Unknown chain id " + chainId);
51
102
  }
52
103
  }
104
+
105
+ // src/formatting.ts
106
+ function truncateEthAddress(address) {
107
+ if (!address)
108
+ return null;
109
+ return address.slice(0, 6) + "\u2026" + address.slice(38, 42);
110
+ }
53
111
  // Annotate the CommonJS export names for ESM import in node:
54
112
  0 && (module.exports = {
113
+ bipsToDecimal,
114
+ bipsToPercent,
115
+ chainName,
116
+ ethToWei,
55
117
  etherscanAddressURL,
56
118
  etherscanHost,
57
- etherscanTxURL
119
+ etherscanTxURL,
120
+ percentToBips,
121
+ truncateEthAddress,
122
+ weiToEth
58
123
  });
59
124
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/etherscan.ts"],"sourcesContent":["export * from \"./etherscan\"\n","export function etherscanAddressURL(address: string, chainId = 1) {\n return etherscanHost(chainId) + \"/address/\" + address\n}\n\nexport function etherscanTxURL(hash: string, chainId = 1) {\n return etherscanHost(chainId) + \"/tx/\" + hash\n}\n\nexport function etherscanHost(chainId = 1) {\n switch (chainId) {\n case 1:\n return `https://etherscan.io`\n case 3:\n return `https://ropsten.etherscan.io`\n case 4:\n return `https://rinkeby.etherscan.io`\n case 5:\n return `https://goerli.etherscan.io`\n case 137:\n return `https://polygonscan.com`\n case 80001:\n return `https://mumbai.polygonscan.com`\n default:\n throw new Error(\"Etherscan: Unknown chain id \" + chainId)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,SAAS,oBAAoB,SAAiB,UAAU,GAAG;AAChE,SAAO,cAAc,OAAO,IAAI,cAAc;AAChD;AAEO,SAAS,eAAe,MAAc,UAAU,GAAG;AACxD,SAAO,cAAc,OAAO,IAAI,SAAS;AAC3C;AAEO,SAAS,cAAc,UAAU,GAAG;AACzC,UAAQ,SAAS;AAAA,IACf,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,YAAM,IAAI,MAAM,iCAAiC,OAAO;AAAA,EAC5D;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/basisPoints.ts","../src/chains.ts","../src/conversion.ts","../src/etherscan.ts","../src/formatting.ts"],"sourcesContent":["export * from \"./basisPoints\"\nexport * from \"./chains\"\nexport * from \"./conversion\"\nexport * from \"./etherscan\"\nexport * from \"./formatting\"\n","export function bipsToPercent(bp: number | string) {\n if (typeof bp !== \"number\") return null\n return parseInt(bp.toString()) / 100\n}\n\nexport function percentToBips(percent: number) {\n return percent * 100\n}\n\nexport function bipsToDecimal(bp: number | string) {\n if (typeof bp !== \"number\") return 0\n return parseInt(bp.toString()) / 10000\n}\n","export function chainName(chainId: number | string) {\n switch (parseInt(chainId.toString())) {\n case 1:\n return `Ethereum`\n case 3:\n return `Ropsten`\n case 4:\n return `Rinkeby`\n case 5:\n return `Goerli`\n case 137:\n return `Polygon`\n case 80001:\n return `Mumbai`\n }\n}\n","import { BigNumber, BigNumberish, ethers, utils } from \"ethers\"\n\nexport function weiToEth(wei: BigNumberish): number {\n return parseFloat(utils.formatEther(wei.toString()))\n}\n\nexport function ethToWei(eth: number): BigNumber | null {\n if (typeof eth === \"undefined\") return null\n return ethers.utils.parseUnits(eth.toString(), \"ether\")\n}\n","export function etherscanAddressURL(address: string, chainId = 1) {\n return etherscanHost(chainId) + \"/address/\" + address\n}\n\nexport function etherscanTxURL(hash: string, chainId = 1) {\n return etherscanHost(chainId) + \"/tx/\" + hash\n}\n\nexport function etherscanHost(chainId = 1) {\n switch (chainId) {\n case 1:\n return `https://etherscan.io`\n case 3:\n return `https://ropsten.etherscan.io`\n case 4:\n return `https://rinkeby.etherscan.io`\n case 5:\n return `https://goerli.etherscan.io`\n case 137:\n return `https://polygonscan.com`\n case 80001:\n return `https://mumbai.polygonscan.com`\n default:\n throw new Error(\"Etherscan: Unknown chain id \" + chainId)\n }\n}\n","export function truncateEthAddress(address: string | undefined) {\n if (!address) return null\n return address.slice(0, 6) + \"…\" + address.slice(38, 42)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,SAAS,cAAc,IAAqB;AACjD,MAAI,OAAO,OAAO;AAAU,WAAO;AACnC,SAAO,SAAS,GAAG,SAAS,CAAC,IAAI;AACnC;AAEO,SAAS,cAAc,SAAiB;AAC7C,SAAO,UAAU;AACnB;AAEO,SAAS,cAAc,IAAqB;AACjD,MAAI,OAAO,OAAO;AAAU,WAAO;AACnC,SAAO,SAAS,GAAG,SAAS,CAAC,IAAI;AACnC;;;ACZO,SAAS,UAAU,SAA0B;AAClD,UAAQ,SAAS,QAAQ,SAAS,CAAC,GAAG;AAAA,IACpC,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACX;AACF;;;ACfA,oBAAuD;AAEhD,SAAS,SAAS,KAA2B;AAClD,SAAO,WAAW,oBAAM,YAAY,IAAI,SAAS,CAAC,CAAC;AACrD;AAEO,SAAS,SAAS,KAA+B;AACtD,MAAI,OAAO,QAAQ;AAAa,WAAO;AACvC,SAAO,qBAAO,MAAM,WAAW,IAAI,SAAS,GAAG,OAAO;AACxD;;;ACTO,SAAS,oBAAoB,SAAiB,UAAU,GAAG;AAChE,SAAO,cAAc,OAAO,IAAI,cAAc;AAChD;AAEO,SAAS,eAAe,MAAc,UAAU,GAAG;AACxD,SAAO,cAAc,OAAO,IAAI,SAAS;AAC3C;AAEO,SAAS,cAAc,UAAU,GAAG;AACzC,UAAQ,SAAS;AAAA,IACf,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,YAAM,IAAI,MAAM,iCAAiC,OAAO;AAAA,EAC5D;AACF;;;ACzBO,SAAS,mBAAmB,SAA6B;AAC9D,MAAI,CAAC;AAAS,WAAO;AACrB,SAAO,QAAQ,MAAM,GAAG,CAAC,IAAI,WAAM,QAAQ,MAAM,IAAI,EAAE;AACzD;","names":[]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,18 @@
1
+ import { BigNumberish, BigNumber } from 'ethers';
2
+
3
+ declare function bipsToPercent(bp: number | string): number;
4
+ declare function percentToBips(percent: number): number;
5
+ declare function bipsToDecimal(bp: number | string): number;
6
+
7
+ declare function chainName(chainId: number | string): "Ethereum" | "Ropsten" | "Rinkeby" | "Goerli" | "Polygon" | "Mumbai";
8
+
9
+ declare function weiToEth(wei: BigNumberish): number;
10
+ declare function ethToWei(eth: number): BigNumber | null;
11
+
1
12
  declare function etherscanAddressURL(address: string, chainId?: number): string;
2
13
  declare function etherscanTxURL(hash: string, chainId?: number): string;
3
14
  declare function etherscanHost(chainId?: number): "https://etherscan.io" | "https://ropsten.etherscan.io" | "https://rinkeby.etherscan.io" | "https://goerli.etherscan.io" | "https://polygonscan.com" | "https://mumbai.polygonscan.com";
4
15
 
5
- export { etherscanAddressURL, etherscanHost, etherscanTxURL };
16
+ declare function truncateEthAddress(address: string | undefined): string;
17
+
18
+ export { bipsToDecimal, bipsToPercent, chainName, ethToWei, etherscanAddressURL, etherscanHost, etherscanTxURL, percentToBips, truncateEthAddress, weiToEth };
package/dist/index.js CHANGED
@@ -1,3 +1,47 @@
1
+ // src/basisPoints.ts
2
+ function bipsToPercent(bp) {
3
+ if (typeof bp !== "number")
4
+ return null;
5
+ return parseInt(bp.toString()) / 100;
6
+ }
7
+ function percentToBips(percent) {
8
+ return percent * 100;
9
+ }
10
+ function bipsToDecimal(bp) {
11
+ if (typeof bp !== "number")
12
+ return 0;
13
+ return parseInt(bp.toString()) / 1e4;
14
+ }
15
+
16
+ // src/chains.ts
17
+ function chainName(chainId) {
18
+ switch (parseInt(chainId.toString())) {
19
+ case 1:
20
+ return `Ethereum`;
21
+ case 3:
22
+ return `Ropsten`;
23
+ case 4:
24
+ return `Rinkeby`;
25
+ case 5:
26
+ return `Goerli`;
27
+ case 137:
28
+ return `Polygon`;
29
+ case 80001:
30
+ return `Mumbai`;
31
+ }
32
+ }
33
+
34
+ // src/conversion.ts
35
+ import { ethers, utils } from "ethers";
36
+ function weiToEth(wei) {
37
+ return parseFloat(utils.formatEther(wei.toString()));
38
+ }
39
+ function ethToWei(eth) {
40
+ if (typeof eth === "undefined")
41
+ return null;
42
+ return ethers.utils.parseUnits(eth.toString(), "ether");
43
+ }
44
+
1
45
  // src/etherscan.ts
2
46
  function etherscanAddressURL(address, chainId = 1) {
3
47
  return etherscanHost(chainId) + "/address/" + address;
@@ -23,9 +67,23 @@ function etherscanHost(chainId = 1) {
23
67
  throw new Error("Etherscan: Unknown chain id " + chainId);
24
68
  }
25
69
  }
70
+
71
+ // src/formatting.ts
72
+ function truncateEthAddress(address) {
73
+ if (!address)
74
+ return null;
75
+ return address.slice(0, 6) + "\u2026" + address.slice(38, 42);
76
+ }
26
77
  export {
78
+ bipsToDecimal,
79
+ bipsToPercent,
80
+ chainName,
81
+ ethToWei,
27
82
  etherscanAddressURL,
28
83
  etherscanHost,
29
- etherscanTxURL
84
+ etherscanTxURL,
85
+ percentToBips,
86
+ truncateEthAddress,
87
+ weiToEth
30
88
  };
31
89
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/etherscan.ts"],"sourcesContent":["export function etherscanAddressURL(address: string, chainId = 1) {\n return etherscanHost(chainId) + \"/address/\" + address\n}\n\nexport function etherscanTxURL(hash: string, chainId = 1) {\n return etherscanHost(chainId) + \"/tx/\" + hash\n}\n\nexport function etherscanHost(chainId = 1) {\n switch (chainId) {\n case 1:\n return `https://etherscan.io`\n case 3:\n return `https://ropsten.etherscan.io`\n case 4:\n return `https://rinkeby.etherscan.io`\n case 5:\n return `https://goerli.etherscan.io`\n case 137:\n return `https://polygonscan.com`\n case 80001:\n return `https://mumbai.polygonscan.com`\n default:\n throw new Error(\"Etherscan: Unknown chain id \" + chainId)\n }\n}\n"],"mappings":";AAAO,SAAS,oBAAoB,SAAiB,UAAU,GAAG;AAChE,SAAO,cAAc,OAAO,IAAI,cAAc;AAChD;AAEO,SAAS,eAAe,MAAc,UAAU,GAAG;AACxD,SAAO,cAAc,OAAO,IAAI,SAAS;AAC3C;AAEO,SAAS,cAAc,UAAU,GAAG;AACzC,UAAQ,SAAS;AAAA,IACf,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,YAAM,IAAI,MAAM,iCAAiC,OAAO;AAAA,EAC5D;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/basisPoints.ts","../src/chains.ts","../src/conversion.ts","../src/etherscan.ts","../src/formatting.ts"],"sourcesContent":["export function bipsToPercent(bp: number | string) {\n if (typeof bp !== \"number\") return null\n return parseInt(bp.toString()) / 100\n}\n\nexport function percentToBips(percent: number) {\n return percent * 100\n}\n\nexport function bipsToDecimal(bp: number | string) {\n if (typeof bp !== \"number\") return 0\n return parseInt(bp.toString()) / 10000\n}\n","export function chainName(chainId: number | string) {\n switch (parseInt(chainId.toString())) {\n case 1:\n return `Ethereum`\n case 3:\n return `Ropsten`\n case 4:\n return `Rinkeby`\n case 5:\n return `Goerli`\n case 137:\n return `Polygon`\n case 80001:\n return `Mumbai`\n }\n}\n","import { BigNumber, BigNumberish, ethers, utils } from \"ethers\"\n\nexport function weiToEth(wei: BigNumberish): number {\n return parseFloat(utils.formatEther(wei.toString()))\n}\n\nexport function ethToWei(eth: number): BigNumber | null {\n if (typeof eth === \"undefined\") return null\n return ethers.utils.parseUnits(eth.toString(), \"ether\")\n}\n","export function etherscanAddressURL(address: string, chainId = 1) {\n return etherscanHost(chainId) + \"/address/\" + address\n}\n\nexport function etherscanTxURL(hash: string, chainId = 1) {\n return etherscanHost(chainId) + \"/tx/\" + hash\n}\n\nexport function etherscanHost(chainId = 1) {\n switch (chainId) {\n case 1:\n return `https://etherscan.io`\n case 3:\n return `https://ropsten.etherscan.io`\n case 4:\n return `https://rinkeby.etherscan.io`\n case 5:\n return `https://goerli.etherscan.io`\n case 137:\n return `https://polygonscan.com`\n case 80001:\n return `https://mumbai.polygonscan.com`\n default:\n throw new Error(\"Etherscan: Unknown chain id \" + chainId)\n }\n}\n","export function truncateEthAddress(address: string | undefined) {\n if (!address) return null\n return address.slice(0, 6) + \"…\" + address.slice(38, 42)\n}\n"],"mappings":";AAAO,SAAS,cAAc,IAAqB;AACjD,MAAI,OAAO,OAAO;AAAU,WAAO;AACnC,SAAO,SAAS,GAAG,SAAS,CAAC,IAAI;AACnC;AAEO,SAAS,cAAc,SAAiB;AAC7C,SAAO,UAAU;AACnB;AAEO,SAAS,cAAc,IAAqB;AACjD,MAAI,OAAO,OAAO;AAAU,WAAO;AACnC,SAAO,SAAS,GAAG,SAAS,CAAC,IAAI;AACnC;;;ACZO,SAAS,UAAU,SAA0B;AAClD,UAAQ,SAAS,QAAQ,SAAS,CAAC,GAAG;AAAA,IACpC,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACX;AACF;;;ACfA,SAAkC,QAAQ,aAAa;AAEhD,SAAS,SAAS,KAA2B;AAClD,SAAO,WAAW,MAAM,YAAY,IAAI,SAAS,CAAC,CAAC;AACrD;AAEO,SAAS,SAAS,KAA+B;AACtD,MAAI,OAAO,QAAQ;AAAa,WAAO;AACvC,SAAO,OAAO,MAAM,WAAW,IAAI,SAAS,GAAG,OAAO;AACxD;;;ACTO,SAAS,oBAAoB,SAAiB,UAAU,GAAG;AAChE,SAAO,cAAc,OAAO,IAAI,cAAc;AAChD;AAEO,SAAS,eAAe,MAAc,UAAU,GAAG;AACxD,SAAO,cAAc,OAAO,IAAI,SAAS;AAC3C;AAEO,SAAS,cAAc,UAAU,GAAG;AACzC,UAAQ,SAAS;AAAA,IACf,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,YAAM,IAAI,MAAM,iCAAiC,OAAO;AAAA,EAC5D;AACF;;;ACzBO,SAAS,mBAAmB,SAA6B;AAC9D,MAAI,CAAC;AAAS,WAAO;AACrB,SAAO,QAAQ,MAAM,GAAG,CAAC,IAAI,WAAM,QAAQ,MAAM,IAAI,EAAE;AACzD;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hybrd/utils",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "Solidity + TypeScript Framework for Web3 Development",
5
5
  "author": "Ian Hunter <ian@ianh.xyz>",
6
6
  "homepage": "https://github.com/ian/hybrid#readme",
@@ -37,7 +37,7 @@
37
37
  "chokidar": "^3.5.3",
38
38
  "commander": "^10.0.0",
39
39
  "ethereum-private-key-to-address": "^0.0.7",
40
- "ethers": "^6.1.0",
40
+ "ethers": "^5.6.8",
41
41
  "figlet": "^1.5.2",
42
42
  "inquirer": "^9.1.4",
43
43
  "open": "^8.4.2",
@@ -46,7 +46,7 @@
46
46
  "viem": "^0.1.10"
47
47
  },
48
48
  "devDependencies": {
49
- "@hybrd/types": "^0.3.5",
49
+ "@hybrd/types": "^0.3.6",
50
50
  "@types/inquirer": "^9.0.3",
51
51
  "@types/node": "^18.14.6",
52
52
  "nodemon": "^2.0.21",
@@ -54,5 +54,5 @@
54
54
  "tsx": "^3.12.3",
55
55
  "typescript": "^4.9.5"
56
56
  },
57
- "gitHead": "6a0e97133b5847877725c59a684c4a79cd2871c5"
57
+ "gitHead": "1ace416af2f6c6a4c36654413f6c23dcb1c38170"
58
58
  }