@pioneer-platform/0x-client 0.1.0 → 0.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @pioneer-platform/0x-client
2
2
 
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Automated patch version bump for all packages
8
+ - Updated dependencies
9
+ - @pioneer-platform/loggerdog@8.4.1
10
+ - @pioneer-platform/pioneer-coins@9.4.1
11
+ - @pioneer-platform/pioneer-caip@9.3.1
12
+
3
13
  ## 0.1.0
4
14
 
5
15
  ### Minor Changes
package/package.json CHANGED
@@ -1,16 +1,23 @@
1
1
  {
2
2
  "name": "@pioneer-platform/0x-client",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "dependencies": {
7
- "@pioneer-platform/loggerdog": "^8.4.0",
8
- "@pioneer-platform/pioneer-caip": "^9.3.0",
9
- "@pioneer-platform/pioneer-coins": "^9.4.0",
7
+ "@pioneer-platform/loggerdog": "^8.4.1",
8
+ "@pioneer-platform/pioneer-caip": "^9.3.1",
9
+ "@pioneer-platform/pioneer-coins": "^9.4.1",
10
10
  "axios": "^1.6.0",
11
11
  "dotenv": "^8.2.0",
12
12
  "uuidv4": "^6.2.13"
13
13
  },
14
+ "scripts": {
15
+ "npm": "pnpm i",
16
+ "test": "pnpm run build && node __tests__/test-module.js",
17
+ "build": "tsc -p .",
18
+ "prepublish": "pnpm run build",
19
+ "refresh": "rm -rf ./node_modules ./package-lock.json && pnpm install"
20
+ },
14
21
  "devDependencies": {
15
22
  "@types/jest": "^25.2.3",
16
23
  "@types/node": "^18.16.0",
@@ -21,12 +28,5 @@
21
28
  "ts-jest": "^29.0.5",
22
29
  "typescript": "^5.0.4"
23
30
  },
24
- "gitHead": "a76012f6693a12181c4744e53e977a9eaeef0ed3",
25
- "scripts": {
26
- "npm": "pnpm i",
27
- "test": "pnpm run build && node __tests__/test-module.js",
28
- "build": "tsc -p .",
29
- "prepublish": "pnpm run build",
30
- "refresh": "rm -rf ./node_modules ./package-lock.json && pnpm install"
31
- }
31
+ "gitHead": "a76012f6693a12181c4744e53e977a9eaeef0ed3"
32
32
  }
package/lib/index.d.ts DELETED
@@ -1,17 +0,0 @@
1
- declare const TAG = " | 0x | ";
2
- type BaseDecimal = string | number;
3
- declare const uuid: any;
4
- declare const log: any;
5
- declare let caipToNetworkId: any, shortListSymbolToCaip: any, ChainToNetworkId: any;
6
- declare let network: any;
7
- declare const axios: any;
8
- declare const API_KEY: string | undefined;
9
- declare let networkSupport: any[];
10
- declare const EIP155_MAINNET_CHAINS: any;
11
- declare const networkApis: any;
12
- interface QuoteResult {
13
- amountOutMin: string;
14
- amountOut: string;
15
- slippage: string;
16
- }
17
- declare const get_quote: (quote: any) => Promise<any>;
package/lib/index.js DELETED
@@ -1,203 +0,0 @@
1
- "use strict";
2
- /*
3
- 0x Swap Integration
4
- - Highlander
5
- */
6
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
- return new (P || (P = Promise))(function (resolve, reject) {
9
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
- step((generator = generator.apply(thisArg, _arguments || [])).next());
13
- });
14
- };
15
- var __generator = (this && this.__generator) || function (thisArg, body) {
16
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
17
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
18
- function verb(n) { return function (v) { return step([n, v]); }; }
19
- function step(op) {
20
- if (f) throw new TypeError("Generator is already executing.");
21
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
22
- 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;
23
- if (y = 0, t) op = [op[0] & 2, t.value];
24
- switch (op[0]) {
25
- case 0: case 1: t = op; break;
26
- case 4: _.label++; return { value: op[1], done: false };
27
- case 5: _.label++; y = op[1]; op = [0]; continue;
28
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
29
- default:
30
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
31
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
32
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
33
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
34
- if (t[2]) _.ops.pop();
35
- _.trys.pop(); continue;
36
- }
37
- op = body.call(thisArg, _);
38
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
39
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
40
- }
41
- };
42
- var TAG = " | 0x | ";
43
- var uuid = require('uuidv4').uuid;
44
- var log = require('@pioneer-platform/loggerdog')();
45
- var _a = require("@pioneer-platform/pioneer-caip"), caipToNetworkId = _a.caipToNetworkId, shortListSymbolToCaip = _a.shortListSymbolToCaip, ChainToNetworkId = _a.ChainToNetworkId;
46
- var network = require("@pioneer-platform/maya-network");
47
- var axios = require('axios');
48
- var API_KEY = process.env['0X_API_SECRET'];
49
- if (!API_KEY)
50
- throw Error("Missing 0X_API_SECRET");
51
- var networkSupport = [
52
- ChainToNetworkId["ETH"],
53
- ChainToNetworkId["BASE"]
54
- ];
55
- var EIP155_MAINNET_CHAINS = {
56
- 'eip155:1': {
57
- chainId: 1,
58
- WETH: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
59
- name: 'Ethereum',
60
- rgb: '99, 125, 234',
61
- rpc: 'https://eth.llamarpc.com',
62
- defaultGasLimit: 250000,
63
- namespace: 'eip155'
64
- },
65
- // 'eip155:43114': {
66
- // chainId: 43114,
67
- // name: 'Avalanche C-Chain',
68
- // logo: '/chain-logos/eip155-43113.png',
69
- // rgb: '232, 65, 66',
70
- // rpc: 'https://api.avax.network/ext/bc/C/rpc',
71
- // namespace: 'eip155'
72
- // },
73
- // 'eip155:137': {
74
- // chainId: 137,
75
- // name: 'Polygon',
76
- // logo: '/chain-logos/eip155-137.png',
77
- // rgb: '130, 71, 229',
78
- // rpc: 'https://polygon-rpc.com/',
79
- // namespace: 'eip155'
80
- // },
81
- // 'eip155:10': {
82
- // chainId: 10,
83
- // name: 'Optimism',
84
- // logo: '/chain-logos/eip155-10.png',
85
- // rgb: '235, 0, 25',
86
- // rpc: 'https://mainnet.optimism.io',
87
- // namespace: 'eip155'
88
- // },
89
- // 'eip155:324': {
90
- // chainId: 324,
91
- // name: 'zkSync Era',
92
- // logo: '/chain-logos/eip155-324.svg',
93
- // rgb: '242, 242, 242',
94
- // rpc: 'https://mainnet.era.zksync.io/',
95
- // namespace: 'eip155'
96
- // },
97
- 'eip155:8453': {
98
- chainId: 8453,
99
- WETH: '0x4200000000000000000000000000000000000006',
100
- name: 'Base',
101
- rgb: '242, 242, 242',
102
- rpc: 'https://mainnet.base.org',
103
- defaultGasLimit: 135120,
104
- namespace: 'eip155'
105
- }
106
- };
107
- var networkApis = {
108
- "eip155:1": "https://api.0x.org/",
109
- "eip155:11155111": "https://sepolia.api.0x.org/",
110
- "eip155:137": "https://polygon.api.0x.org/",
111
- "eip155:56": "https://bsc.api.0x.org/",
112
- "eip155:10": "https://optimism.api.0x.org/",
113
- "eip155:250": "https://fantom.api.0x.org/",
114
- "eip155:42220": "https://celo.api.0x.org/",
115
- "eip155:43114": "https://avalanche.api.0x.org/",
116
- "eip155:42161": "https://arbitrum.api.0x.org/",
117
- "eip155:8453": "https://base.api.0x.org/"
118
- };
119
- module.exports = {
120
- init: function (settings) {
121
- return true;
122
- },
123
- networkSupport: function () {
124
- return networkSupport;
125
- },
126
- getQuote: function (quote) {
127
- return get_quote(quote);
128
- },
129
- };
130
- var get_quote = function (quote) {
131
- return __awaiter(this, void 0, void 0, function () {
132
- var tag, output, inputChain, outputChain, buyToken, sellToken, sellAmount, apiUrl, url, headers, response, e_1;
133
- return __generator(this, function (_a) {
134
- switch (_a.label) {
135
- case 0:
136
- tag = TAG + " | get_quote | ";
137
- _a.label = 1;
138
- case 1:
139
- _a.trys.push([1, 3, , 4]);
140
- output = {};
141
- if (!quote.sellAsset)
142
- throw new Error("missing sellAsset");
143
- if (!quote.buyAsset)
144
- throw new Error("missing buyAsset");
145
- if (!quote.sellAmount)
146
- throw new Error("missing sellAmount");
147
- if (!quote.senderAddress)
148
- throw new Error("missing senderAddress");
149
- if (!quote.recipientAddress)
150
- throw new Error("missing recipientAddress");
151
- if (!quote.slippage)
152
- throw new Error("missing slippage");
153
- inputChain = caipToNetworkId(quote.sellAsset);
154
- outputChain = caipToNetworkId(quote.buyAsset);
155
- if (inputChain != outputChain)
156
- throw new Error("Cross Chain not supported");
157
- buyToken = quote.buyAsset.split(':')[2];
158
- log.info(tag, "buyToken: ", buyToken);
159
- if (buyToken === "60") { // Assuming the '60' refers to ETH
160
- buyToken = EIP155_MAINNET_CHAINS[outputChain].WETH; // Use WETH address if available, else fallback to the original token
161
- }
162
- sellToken = quote.sellAsset.split(':')[2];
163
- log.info(tag, "sellToken: ", sellToken);
164
- if (sellToken === "slip44:60") { // Assuming the '60' refers to ETH
165
- sellToken = EIP155_MAINNET_CHAINS[inputChain].WETH; // Use WETH address if available, else fallback to the original token
166
- }
167
- sellAmount = quote.sellAmount;
168
- output.meta = {
169
- quoteMode: "ERC20-ERC20"
170
- };
171
- output.steps = 1;
172
- output.complete = true;
173
- output.id = uuid();
174
- log.info(tag, "sellToken: ", sellToken);
175
- log.info(tag, "buyToken: ", buyToken);
176
- log.info(tag, "sellAmount: ", sellAmount);
177
- apiUrl = networkApis[inputChain];
178
- if (!apiUrl)
179
- throw new Error("Network not supported");
180
- if (!sellToken || !buyToken || !sellAmount)
181
- throw new Error("missing required params");
182
- url = "".concat(apiUrl, "swap/v1/quote?sellToken=").concat(sellToken.toLowerCase(), "&buyToken=").concat(buyToken.toLowerCase(), "&sellAmount=").concat(sellAmount);
183
- headers = {
184
- '0x-api-key': API_KEY
185
- };
186
- return [4 /*yield*/, axios.get(url, { headers: headers })];
187
- case 2:
188
- response = _a.sent();
189
- log.info(tag, "response: ", response.data);
190
- output.txs = [
191
- // tx
192
- ];
193
- return [2 /*return*/, output];
194
- case 3:
195
- e_1 = _a.sent();
196
- console.error(tag, "e: ", e_1);
197
- console.error(tag, "e: ", JSON.stringify(e_1));
198
- throw e_1;
199
- case 4: return [2 /*return*/];
200
- }
201
- });
202
- });
203
- };