@pioneer-platform/pro-token 0.0.1

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 ADDED
@@ -0,0 +1 @@
1
+ export {};
package/lib/index.js ADDED
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ /*
3
+ Uniswap Integration
4
+ - Highlander
5
+
6
+ BASE
7
+ https://docs.base.org/contracts/
8
+
9
+
10
+
11
+ */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ Object.defineProperty(exports, "__esModule", { value: true });
49
+ var TAG = " | Uniswap | ";
50
+ var _a = require("@pioneer-platform/pioneer-caip"), caipToNetworkId = _a.caipToNetworkId, shortListSymbolToCaip = _a.shortListSymbolToCaip, ChainToNetworkId = _a.ChainToNetworkId;
51
+ var uuid = require('uuidv4').uuid;
52
+ var log = require('@pioneer-platform/loggerdog')();
53
+ var _b = require('ethers'), ethers = _b.ethers, BigNumber = _b.BigNumber;
54
+ var sdk_core_1 = require("@uniswap/sdk-core");
55
+ var smart_order_router_1 = require("@uniswap/smart-order-router");
56
+ var networkSupport = [
57
+ ChainToNetworkId["ETH"],
58
+ ChainToNetworkId["BASE"],
59
+ ];
60
+ var EIP155_MAINNET_CHAINS = {
61
+ 'eip155:1': {
62
+ chainId: 1,
63
+ WETH: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
64
+ name: 'Ethereum',
65
+ logo: '/chain-logos/eip155-1.png',
66
+ rgb: '99, 125, 234',
67
+ universalRouter: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',
68
+ rpc: 'https://ethereum-rpc.publicnode.com',
69
+ defaultGasLimit: 250000,
70
+ namespace: 'eip155'
71
+ },
72
+ 'eip155:8453': {
73
+ chainId: 8453,
74
+ WETH: '0x4200000000000000000000000000000000000006',
75
+ name: 'Base',
76
+ logo: '/chain-logos/base.png',
77
+ rgb: '242, 242, 242',
78
+ universalRouter: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
79
+ rpc: 'https://mainnet.base.org',
80
+ defaultGasLimit: 135120,
81
+ namespace: 'eip155'
82
+ }
83
+ };
84
+ var ERC20_ABI = [
85
+ "function allowance(address owner, address spender) view returns (uint256)",
86
+ "function balanceOf(address owner) view returns (uint256)",
87
+ "function approve(address spender, uint256 amount) returns (bool)",
88
+ "function transfer(address to, uint256 amount) returns (bool)",
89
+ "function symbol() view returns (string)",
90
+ "function decimals() view returns (uint8)"
91
+ ];
92
+ module.exports = {
93
+ init: function (settings) {
94
+ return true;
95
+ },
96
+ getRateEthPro: function () {
97
+ return get_rate_eth();
98
+ },
99
+ getRateEth: function () {
100
+ return get_rate_usdc();
101
+ },
102
+ getRateProUsd: function () {
103
+ return get_rate_pro();
104
+ }
105
+ };
106
+ var get_rate_pro = function () {
107
+ return __awaiter(this, void 0, void 0, function () {
108
+ var tag, proEth, ethUSD, proUSD, e_1;
109
+ return __generator(this, function (_a) {
110
+ switch (_a.label) {
111
+ case 0:
112
+ tag = TAG + " | get_rate_pro | ";
113
+ _a.label = 1;
114
+ case 1:
115
+ _a.trys.push([1, 4, , 5]);
116
+ return [4 /*yield*/, get_rate_eth()];
117
+ case 2:
118
+ proEth = _a.sent();
119
+ return [4 /*yield*/, get_rate_usdc()];
120
+ case 3:
121
+ ethUSD = _a.sent();
122
+ console.log("proEth: ".concat(proEth, ", ethUSD: ").concat(ethUSD));
123
+ proUSD = (1 / parseFloat(proEth)) * parseFloat(ethUSD);
124
+ console.log("1 PRO is approximately worth ".concat(proUSD, " USDC"));
125
+ return [2 /*return*/, proUSD.toFixed(2)]; // Formatting the output for consistency
126
+ case 4:
127
+ e_1 = _a.sent();
128
+ console.error(tag, "e: ", e_1);
129
+ throw e_1;
130
+ case 5: return [2 /*return*/];
131
+ }
132
+ });
133
+ });
134
+ };
135
+ var get_rate_usdc = function () {
136
+ return __awaiter(this, void 0, void 0, function () {
137
+ var tag, SELL_TOKEN, BUY_TOKEN, chainId, provider, router, amount, Protocol, swapRoute, output, e_2;
138
+ return __generator(this, function (_a) {
139
+ switch (_a.label) {
140
+ case 0:
141
+ tag = TAG + " | get_rate_usdc | ";
142
+ _a.label = 1;
143
+ case 1:
144
+ _a.trys.push([1, 3, , 4]);
145
+ SELL_TOKEN = new sdk_core_1.Token(1, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18, 'WETH', 'Wrapped Ether');
146
+ BUY_TOKEN = new sdk_core_1.Token(1, '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', 6, 'USDC', 'USD Coin');
147
+ chainId = 1;
148
+ provider = new ethers.providers.JsonRpcProvider(EIP155_MAINNET_CHAINS['eip155:1'].rpc);
149
+ router = new smart_order_router_1.AlphaRouter({ chainId: chainId, provider: provider });
150
+ amount = sdk_core_1.CurrencyAmount.fromRawAmount(SELL_TOKEN, BigNumber.from("1000000000000000000"));
151
+ Protocol = void 0;
152
+ (function (Protocol) {
153
+ Protocol["V2"] = "V2";
154
+ Protocol["V3"] = "V3";
155
+ Protocol["MIXED"] = "MIXED";
156
+ })(Protocol || (Protocol = {}));
157
+ return [4 /*yield*/, router.route(amount, BUY_TOKEN, sdk_core_1.TradeType.EXACT_INPUT, /*swapConfig=*/ undefined, {
158
+ protocols: [Protocol.V2, Protocol.V3, Protocol.MIXED],
159
+ })];
160
+ case 2:
161
+ swapRoute = _a.sent();
162
+ if (!swapRoute)
163
+ throw Error("Failed to get swapRoute");
164
+ output = swapRoute.route[0].quote.toFixed(6);
165
+ return [2 /*return*/, output];
166
+ case 3:
167
+ e_2 = _a.sent();
168
+ console.error(tag, "e: ", e_2);
169
+ throw e_2;
170
+ case 4: return [2 /*return*/];
171
+ }
172
+ });
173
+ });
174
+ };
175
+ var get_rate_eth = function () {
176
+ return __awaiter(this, void 0, void 0, function () {
177
+ var tag, BUY_TOKEN, SELL_TOKEN, chainId, provider, router, amount, Protocol, swapRoute, output, e_3;
178
+ return __generator(this, function (_a) {
179
+ switch (_a.label) {
180
+ case 0:
181
+ tag = TAG + " | get_rate_eth | ";
182
+ _a.label = 1;
183
+ case 1:
184
+ _a.trys.push([1, 3, , 4]);
185
+ BUY_TOKEN = void 0, SELL_TOKEN = void 0;
186
+ BUY_TOKEN = new sdk_core_1.Token(8453, '0xef743df8eda497bcf1977393c401a636518dd630', 18, 'PRO', 'swaps.PRO');
187
+ // SELL_TOKEN = new Token(8453, '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', 18, 'USD')
188
+ SELL_TOKEN = new sdk_core_1.Token(8453, '0x4200000000000000000000000000000000000006', 18, 'WETH');
189
+ chainId = 8453;
190
+ provider = new ethers.providers.JsonRpcProvider(EIP155_MAINNET_CHAINS['eip155:8453'].rpc);
191
+ router = new smart_order_router_1.AlphaRouter({ chainId: chainId, provider: provider });
192
+ amount = sdk_core_1.CurrencyAmount.fromRawAmount(SELL_TOKEN, BigNumber.from("1000000000000000000"));
193
+ Protocol = void 0;
194
+ (function (Protocol) {
195
+ Protocol["V2"] = "V2";
196
+ Protocol["V3"] = "V3";
197
+ Protocol["MIXED"] = "MIXED";
198
+ })(Protocol || (Protocol = {}));
199
+ return [4 /*yield*/, router.route(amount, BUY_TOKEN, sdk_core_1.TradeType.EXACT_INPUT, /*swapConfig=*/ undefined, {
200
+ protocols: [Protocol.V2, Protocol.V3, Protocol.MIXED],
201
+ })];
202
+ case 2:
203
+ swapRoute = _a.sent();
204
+ if (!swapRoute)
205
+ throw Error("Failed to get swapRoute");
206
+ console.log("swapRoute details:", JSON.stringify(swapRoute, null, 2));
207
+ output = swapRoute.route[0].quote.toFixed(18);
208
+ return [2 /*return*/, output];
209
+ case 3:
210
+ e_3 = _a.sent();
211
+ console.error(tag, "e: ", e_3);
212
+ throw e_3;
213
+ case 4: return [2 /*return*/];
214
+ }
215
+ });
216
+ });
217
+ };
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@pioneer-platform/pro-token",
3
+ "version": "0.0.1",
4
+ "main": "./lib/index.js",
5
+ "types": "./lib/index.d.ts",
6
+ "dependencies": {
7
+ "@keepkey/keepkey-sdk": "^0.2.57",
8
+ "@pioneer-platform/loggerdog": "^8.3.1",
9
+ "@pioneer-platform/maya-network": "^8.3.7",
10
+ "@pioneer-platform/pioneer-caip": "^9.2.23",
11
+ "@pioneer-platform/pioneer-coins": "^9.2.13",
12
+ "@types/ms": "^0.7.34",
13
+ "@types/ms.macro": "^2.0.2",
14
+ "@uniswap/router-sdk": "1.9.0",
15
+ "@uniswap/sdk": "^3.0.3",
16
+ "@uniswap/sdk-core": "4.2.0",
17
+ "@uniswap/smart-order-router": "3.26.0",
18
+ "@uniswap/token-lists": "^1.0.0-beta.34",
19
+ "@uniswap/uniswapx-sdk": "^2.0.1-alpha.10",
20
+ "@uniswap/universal-router-sdk": "1.8.2",
21
+ "@uniswap/v2-sdk": "4.3.0",
22
+ "@uniswap/v3-sdk": "3.11.0",
23
+ "axios": "^1.3.4",
24
+ "dayjs": "^1.11.10",
25
+ "dotenv": "^8.2.0",
26
+ "ms": "^2.1.3",
27
+ "ms.macro": "^2.0.0",
28
+ "uuidv4": "^6.2.13"
29
+ },
30
+ "scripts": {
31
+ "npm": "npm i",
32
+ "test": "npm run build && node __tests__/test-module.js",
33
+ "build": "tsc -p .",
34
+ "prepublish": "npm run build",
35
+ "refresh": "rm -rf ./node_modules ./package-lock.json && npm install"
36
+ },
37
+ "devDependencies": {
38
+ "@types/async-retry": "^1.4.8",
39
+ "@types/bunyan": "^1.8.11",
40
+ "@types/jest": "^25.2.3",
41
+ "@types/node": "^13.13.21",
42
+ "@types/source-map-support": "^0.5.3",
43
+ "babel-plugin-macros": "^3.1.0",
44
+ "jest": "^26.4.2",
45
+ "onchange": "^7.0.2",
46
+ "serve": "^11.3.2",
47
+ "ts-jest": "^29.0.5",
48
+ "typescript": "^5.0.2"
49
+ },
50
+ "gitHead": "a76012f6693a12181c4744e53e977a9eaeef0ed3"
51
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es5",
4
+ "module": "commonjs",
5
+ "lib": ["es6", "es2015", "dom"],
6
+ "declaration": true,
7
+ "outDir": "lib",
8
+ "rootDir": "src",
9
+ "strict": true,
10
+ "types": ["node"],
11
+ "esModuleInterop": true,
12
+ "resolveJsonModule": true
13
+ }
14
+ }