@pioneer-platform/tenderly-client 8.3.1 → 8.3.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.
package/lib/index.d.ts CHANGED
@@ -1,9 +1 @@
1
- declare const TAG = " | blocknative | ";
2
- declare const Axios: any;
3
- declare const https: any;
4
- declare const axios: any;
5
- declare let URL_HARPIE: string;
6
- declare let TENDERLY_ACCESS_KEY: string | undefined;
7
- declare let TENDERLY_USER: string;
8
- declare let TENDERLY_PROJECT: string;
9
- declare const submit_tx: (from: string, to: string, data: string) => Promise<any>;
1
+ export {};
package/lib/index.js CHANGED
@@ -1,8 +1,4 @@
1
1
  "use strict";
2
- /*
3
- https://docs.blocknative.com/webhook-api
4
-
5
- */
6
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -39,65 +35,96 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
39
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
40
36
  }
41
37
  };
42
- var TAG = " | blocknative | ";
43
- var Axios = require('axios');
44
- var https = require('https');
45
- var axios = Axios.create({
46
- httpsAgent: new https.Agent({
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var axios_1 = __importDefault(require("axios"));
43
+ var https_1 = __importDefault(require("https"));
44
+ var TAG = " | tenderly | ";
45
+ // Ensure API key is set
46
+ var TENDERLY_ACCESS_KEY = process.env.TENDERLY_ACCESS_KEY;
47
+ if (!TENDERLY_ACCESS_KEY) {
48
+ throw new Error("API key required! Set env TENDERLY_ACCESS_KEY");
49
+ }
50
+ var TENDERLY_USER = 'highlander2';
51
+ var TENDERLY_PROJECT = 'project';
52
+ // Axios instance with custom HTTPS agent
53
+ var axiosInstance = axios_1.default.create({
54
+ httpsAgent: new https_1.default.Agent({
47
55
  rejectUnauthorized: false
48
56
  })
49
57
  });
50
- var URL_HARPIE = "https://api.harpie.io";
51
- var TENDERLY_ACCESS_KEY = process.env['TENDERLY_ACCESS_KEY'];
52
- if (!TENDERLY_ACCESS_KEY)
53
- throw Error("api key required! set env TENDERLY_ACCESS_KEY");
54
- var TENDERLY_USER = 'highlander2';
55
- var TENDERLY_PROJECT = 'keepkey';
56
58
  module.exports = {
57
- validateTransaction: function (from, to, data) {
58
- return submit_tx(from, to, data);
59
+ validateTransaction: function (tx) {
60
+ return simulateTransaction(tx);
59
61
  },
60
62
  };
61
- var submit_tx = function (from, to, data) {
63
+ // Function to simulate a transaction
64
+ function simulateTransaction(tx) {
65
+ var _a;
62
66
  return __awaiter(this, void 0, void 0, function () {
63
- var tag, apiURL, body, headers, resp, e_1;
64
- return __generator(this, function (_a) {
65
- switch (_a.label) {
67
+ var tag, apiURL, body, headers, response, summary, error_1;
68
+ return __generator(this, function (_b) {
69
+ switch (_b.label) {
66
70
  case 0:
67
- tag = TAG + " | submit_address | ";
68
- _a.label = 1;
71
+ tag = " | simulateTransaction | ";
72
+ _b.label = 1;
69
73
  case 1:
70
- _a.trys.push([1, 3, , 4]);
71
- apiURL = "https://api.tenderly.co/api/v1/account/highlander2/project/keepkey/simulate";
74
+ _b.trys.push([1, 3, , 4]);
75
+ apiURL = "https://api.tenderly.co/api/v1/account/highlander2/project/project/simulate";
72
76
  body = {
73
- "network_id": "1",
74
- "from": from,
75
- "to": to,
76
- "input": data,
77
- "gas": 21204,
78
- "gas_price": "0",
79
- "value": 0,
80
- "save_if_fails": true
77
+ network_id: tx.chainId || "1",
78
+ from: tx.from,
79
+ to: tx.to,
80
+ input: tx.data,
81
+ value: tx.value || 0,
82
+ save_if_fails: true
81
83
  };
84
+ //eip1559
85
+ if (tx.gas) {
86
+ body.gas = tx.gas;
87
+ body.gas_price = tx.gasPrice;
88
+ }
89
+ if (tx.maxPriorityFeePerGas) {
90
+ body.max_priority_fee_per_gas = tx.maxPriorityFeePerGas;
91
+ body.max_fee_per_gas = tx.maxFeePerGas;
92
+ }
82
93
  headers = {
83
94
  headers: {
84
- 'content-type': 'application/JSON',
95
+ 'Content-Type': 'application/json',
85
96
  'X-Access-Key': TENDERLY_ACCESS_KEY,
86
97
  }
87
98
  };
88
- return [4 /*yield*/, axios.post(apiURL, body, headers)];
99
+ return [4 /*yield*/, axiosInstance.post(apiURL, body, headers)];
89
100
  case 2:
90
- resp = _a.sent();
91
- if (resp.data.simulation.status === false) {
92
- // it failed, do as you please
101
+ response = _b.sent();
102
+ // console.log(tag,'response: ',Object.keys(response.data))
103
+ // console.log(tag,'response simulation: ',Object.keys(response.data.simulation))
104
+ console.log(tag, 'response simulation: ', response.data.simulation);
105
+ summary = {
106
+ isValid: response.data.simulation.status,
107
+ method: response.data.simulation.method,
108
+ gas_used: response.data.simulation.gas_used,
109
+ nonce: response.data.simulation.nonce,
110
+ addresses: response.data.simulation.addresses,
111
+ };
112
+ if (!response.data.simulation.status) {
113
+ summary.error = response.data.simulation.error_message;
93
114
  }
94
- return [2 /*return*/, resp.data];
115
+ summary.raw = response.data.simulation;
116
+ return [2 /*return*/, summary];
95
117
  case 3:
96
- e_1 = _a.sent();
97
- console.error(tag, "e: ", e_1);
98
- return [3 /*break*/, 4];
118
+ error_1 = _b.sent();
119
+ if (axios_1.default.isAxiosError(error_1)) {
120
+ console.error(TAG, "Axios error in simulateTransaction:", ((_a = error_1.response) === null || _a === void 0 ? void 0 : _a.data) || error_1.message);
121
+ }
122
+ else {
123
+ console.error(TAG, "Unknown error in simulateTransaction:", error_1);
124
+ }
125
+ throw new Error("Transaction simulation failed.");
99
126
  case 4: return [2 /*return*/];
100
127
  }
101
128
  });
102
129
  });
103
- };
130
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/tenderly-client",
3
- "version": "8.3.1",
3
+ "version": "8.3.3",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "dependencies": {
@@ -26,5 +26,5 @@
26
26
  "ts-jest": "^29.0.5",
27
27
  "typescript": "^5.0.2"
28
28
  },
29
- "gitHead": "bb1ba4da55a6b00c29e335c6680a591cf319ce6b"
29
+ "gitHead": "e4a7114f00103ee48533c369dba4a02021ddcbe4"
30
30
  }