@mentaproject/client 0.0.3

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.
Files changed (42) hide show
  1. package/dist/index.d.ts +3 -0
  2. package/dist/index.js +3 -0
  3. package/dist/managers/AccountManager.d.ts +8 -0
  4. package/dist/managers/AccountManager.js +11 -0
  5. package/dist/managers/BlockManager.d.ts +8 -0
  6. package/dist/managers/BlockManager.js +13 -0
  7. package/dist/managers/ContractManager.d.ts +7 -0
  8. package/dist/managers/ContractManager.js +12 -0
  9. package/dist/managers/TransactionManager.d.ts +8 -0
  10. package/dist/managers/TransactionManager.js +19 -0
  11. package/dist/managers/index.d.ts +4 -0
  12. package/dist/managers/index.js +4 -0
  13. package/dist/structures/Account.d.ts +41 -0
  14. package/dist/structures/Account.js +86 -0
  15. package/dist/structures/Block.d.ts +36 -0
  16. package/dist/structures/Block.js +37 -0
  17. package/dist/structures/MentaClient.d.ts +13 -0
  18. package/dist/structures/MentaClient.js +16 -0
  19. package/dist/structures/Transaction.d.ts +30 -0
  20. package/dist/structures/Transaction.js +45 -0
  21. package/dist/structures/TransactionReceipt.d.ts +0 -0
  22. package/dist/structures/TransactionReceipt.js +1 -0
  23. package/dist/structures/index.d.ts +5 -0
  24. package/dist/structures/index.js +5 -0
  25. package/dist/types/Account.d.ts +5 -0
  26. package/dist/types/Account.js +1 -0
  27. package/dist/types/Block.d.ts +56 -0
  28. package/dist/types/Block.js +2 -0
  29. package/dist/types/Transaction.d.ts +45 -0
  30. package/dist/types/Transaction.js +1 -0
  31. package/dist/types/TransactionReceipt.d.ts +9 -0
  32. package/dist/types/TransactionReceipt.js +3 -0
  33. package/dist/types/index.d.ts +4 -0
  34. package/dist/types/index.js +4 -0
  35. package/dist/utils/IsContractCompliantWithAbi.d.ts +15 -0
  36. package/dist/utils/IsContractCompliantWithAbi.js +280 -0
  37. package/dist/utils/abis/ERC20.d.ts +168 -0
  38. package/dist/utils/abis/ERC20.js +222 -0
  39. package/dist/utils/abis/index.d.ts +1 -0
  40. package/dist/utils/abis/index.js +1 -0
  41. package/package.json +53 -0
  42. package/test.ts +60 -0
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@mentaproject/client",
3
+ "version": "0.0.3",
4
+ "description": "High level EVM library used into the Menta App to facilitate Blockchain interactions. ",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.js"
14
+ },
15
+ "./types": {
16
+ "types": "./dist/types/index.d.ts",
17
+ "import": "./dist/types/index.mjs",
18
+ "require": "./dist/types/index.js"
19
+ },
20
+ "./package.json": "./package.json"
21
+ },
22
+ "scripts": {
23
+ "test": "tsx test.ts",
24
+ "build": "tsc --project tsconfig.json",
25
+ "patch": "npm version patch && npm run build && npm publish --access public",
26
+ "minor": "npm version minor && npm run build && npm publish --access public",
27
+ "major": "npm version major && npm run build && npm publish --access public"
28
+ },
29
+ "author": "@mentaproject",
30
+ "license": "ISC",
31
+ "dependencies": {
32
+ "@shazow/whatsabi": "^0.21.1",
33
+ "@mentaproject/contracts": "0.0.2",
34
+ "@mentaproject/core": "0.0.3"
35
+ },
36
+ "devDependencies": {
37
+ "@rollup/plugin-commonjs": "^28.0.3",
38
+ "@rollup/plugin-node-resolve": "^16.0.1",
39
+ "@rollup/plugin-typescript": "^12.1.2",
40
+ "rollup": "^4.40.1",
41
+ "tslib": "^2.8.1",
42
+ "tsx": "^4.19.4",
43
+ "typescript": "^5.8.3"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/mentaproject/client.git"
48
+ },
49
+ "bugs": {
50
+ "url": "https://github.com/mentaproject/client/issues"
51
+ },
52
+ "homepage": "https://github.com/mentaproject/client#readme"
53
+ }
package/test.ts ADDED
@@ -0,0 +1,60 @@
1
+ import { Address, erc20Abi, getAddress, http, toFunctionSelector, zeroAddress } from "viem";
2
+ import { MentaClient } from "./src";
3
+ import { privateKeyToAccount, generatePrivateKey } from "viem/accounts"
4
+ import { mainnet } from "@mentaproject/core/chains";
5
+ import { getCode, getStorageAt } from "@mentaproject/core/actions";
6
+ import { selectorsFromBytecode } from "@shazow/whatsabi";
7
+ import { toFunctionSignature } from "viem"
8
+ import { bytes32ToAddress } from "@mentaproject/core/utils";
9
+
10
+ const viemAccount = privateKeyToAccount(generatePrivateKey());
11
+
12
+ const client = new MentaClient({
13
+ account: viemAccount,
14
+ transport: http("https://red-nameless-panorama.quiknode.pro/0f30278c4c66afdc9f8679975e13cd5a92c7d937/"),
15
+ chain: mainnet
16
+ });
17
+
18
+ (async () => {
19
+ // const firstTx = await client.transactions.get({ hash: "0x1ac2418d94a069d3460b7dd52cfc251879da4948bb0df8362598b5595d28cbf1" });
20
+ // const receipt = await firstTx.receipt();
21
+
22
+ // const log = receipt.logs[0];
23
+
24
+ // if (!log) return;
25
+
26
+ // const decoded = decodeEventLog({
27
+ // abi: erc20Abi,
28
+ // data: receipt.logs[0].data,
29
+ // topics: receipt.logs[0].topics,
30
+ // });
31
+
32
+ // console.log(decoded.args)
33
+
34
+ const erc20Signatures = erc20Abi.filter(item => item.type === "function").map(item => ({ signature:toFunctionSignature(item), selector: toFunctionSelector(item)}));
35
+
36
+ const code = await getCode(client.rpcClient, { address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" });
37
+ const infos = selectorsFromBytecode(code as string);
38
+
39
+ console.log(infos);
40
+
41
+ async function getImplementationAddress(proxyAddr: Address) {
42
+ const storageValue = await getStorageAt(client.rpcClient, {
43
+ address: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
44
+ slot: "0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3"
45
+ });
46
+
47
+ if (storageValue) {
48
+
49
+ console.log(storageValue);
50
+ // La valeur retournée est un hex de 32 octets. L'adresse est dans les 20 derniers octets.
51
+ const address = getAddress(bytes32ToAddress(storageValue))
52
+ if (address !== zeroAddress) {
53
+ return address;
54
+ }
55
+ }
56
+ return null; // Pas d'adresse trouvée ou contrat non EIP-1967
57
+ };
58
+
59
+ getImplementationAddress("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48").then(console.log);
60
+ })()