@pioneer-platform/across-client 0.0.2

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,240 @@
1
+ "use strict";
2
+ /*
3
+ Uniswap Integration
4
+ - Highlander
5
+
6
+ BASE
7
+ https://docs.base.org/contracts/
8
+
9
+
10
+
11
+ */
12
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
25
+ }) : function(o, v) {
26
+ o["default"] = v;
27
+ });
28
+ var __importStar = (this && this.__importStar) || function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const TAG = " | Uniswap | ";
37
+ const { uuid } = require('uuidv4');
38
+ const log = require('@pioneer-platform/loggerdog')();
39
+ let { caipToNetworkId, shortListSymbolToCaip, ChainToNetworkId } = require("@pioneer-platform/pioneer-caip");
40
+ const typechain_1 = require("@across-protocol/contracts-v2/dist/typechain");
41
+ const ethers_1 = require("ethers");
42
+ const sdk = __importStar(require("@across-protocol/sdk-v2"));
43
+ const EIP155_MAINNET_CHAINS = {
44
+ 'eip155:1': {
45
+ chainId: 1,
46
+ WETH: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
47
+ name: 'Ethereum',
48
+ logo: '/chain-logos/eip155-1.png',
49
+ rgb: '99, 125, 234',
50
+ rpc: 'https://eth.llamarpc.com',
51
+ defaultGasLimit: 250000,
52
+ namespace: 'eip155'
53
+ },
54
+ // 'eip155:43114': {
55
+ // chainId: 43114,
56
+ // name: 'Avalanche C-Chain',
57
+ // logo: '/chain-logos/eip155-43113.png',
58
+ // rgb: '232, 65, 66',
59
+ // rpc: 'https://api.avax.network/ext/bc/C/rpc',
60
+ // namespace: 'eip155'
61
+ // },
62
+ // 'eip155:137': {
63
+ // chainId: 137,
64
+ // name: 'Polygon',
65
+ // logo: '/chain-logos/eip155-137.png',
66
+ // rgb: '130, 71, 229',
67
+ // rpc: 'https://polygon-rpc.com/',
68
+ // namespace: 'eip155'
69
+ // },
70
+ // 'eip155:10': {
71
+ // chainId: 10,
72
+ // name: 'Optimism',
73
+ // logo: '/chain-logos/eip155-10.png',
74
+ // rgb: '235, 0, 25',
75
+ // rpc: 'https://mainnet.optimism.io',
76
+ // namespace: 'eip155'
77
+ // },
78
+ // 'eip155:324': {
79
+ // chainId: 324,
80
+ // name: 'zkSync Era',
81
+ // logo: '/chain-logos/eip155-324.svg',
82
+ // rgb: '242, 242, 242',
83
+ // rpc: 'https://mainnet.era.zksync.io/',
84
+ // namespace: 'eip155'
85
+ // },
86
+ 'eip155:8453': {
87
+ chainId: 8453,
88
+ WETH: '0x4200000000000000000000000000000000000006',
89
+ name: 'Base',
90
+ logo: '/chain-logos/base.png',
91
+ rgb: '242, 242, 242',
92
+ rpc: 'https://mainnet.base.org',
93
+ defaultGasLimit: 135120,
94
+ namespace: 'eip155'
95
+ }
96
+ };
97
+ let networkSupport = [
98
+ ChainToNetworkId["ETH"],
99
+ ChainToNetworkId["BASE"],
100
+ ];
101
+ module.exports = {
102
+ init: function (settings) {
103
+ return true;
104
+ },
105
+ networkSupport: function () {
106
+ return networkSupport;
107
+ },
108
+ getQuote: function (quote) {
109
+ return get_quote(quote);
110
+ },
111
+ };
112
+ const buildTx = async function (txData, from, chainId, provider) {
113
+ let tag = TAG + " | buildTx | ";
114
+ try {
115
+ //buildTx
116
+ log.info(tag, "txData: ", txData);
117
+ // let { callData: data, value} = responseRouter
118
+ let data = txData.data;
119
+ let value = "0x0";
120
+ //get fee's
121
+ const nonce = await provider.getTransactionCount(from, "latest");
122
+ let gas = `0x${BigInt("135120").toString(16)}`;
123
+ try {
124
+ const estimatedGas = await provider.estimateGas({
125
+ from: from,
126
+ to: EIP155_MAINNET_CHAINS['eip155:' + chainId].universalRouter, // Uniswap Router address
127
+ data: data,
128
+ value: ethers_1.ethers.utils.parseEther("0"), // Value for token swaps
129
+ });
130
+ console.log("estimatedGas: ", estimatedGas);
131
+ gas = `0x${estimatedGas.toString(16)}`;
132
+ }
133
+ catch (e) {
134
+ console.error("Error in estimateGas: ", e);
135
+ //@TODO get custom gas limit defaults per chain
136
+ gas = `0x${BigInt("335120").toString(16)}`;
137
+ }
138
+ // Get current gas price from the network
139
+ const gasPrice = await provider.getGasPrice();
140
+ // Optional: Adjust gas price based on your strategy (e.g., increase for faster confirmation)
141
+ const adjustedGasPrice = gasPrice.mul(ethers_1.ethers.BigNumber.from(110)).div(ethers_1.ethers.BigNumber.from(100)); // Example: Increase by 10%
142
+ /*
143
+ Nonce
144
+
145
+ Fee's
146
+ @TODO make sure +1 if creationg multiple tx's
147
+ */
148
+ const tx = {
149
+ from,
150
+ to: txData.to,
151
+ chainId,
152
+ data,
153
+ value,
154
+ gas,
155
+ gasPrice,
156
+ nonce,
157
+ };
158
+ return tx;
159
+ }
160
+ catch (e) {
161
+ console.error(e);
162
+ }
163
+ };
164
+ const get_token = async function (caip) {
165
+ let tag = TAG + " | get_token | ";
166
+ try {
167
+ //if native get WETH token?
168
+ }
169
+ catch (e) {
170
+ console.error();
171
+ }
172
+ };
173
+ const get_quote = async function (quote) {
174
+ let tag = TAG + " | get_quote | ";
175
+ try {
176
+ let output = {};
177
+ if (!quote.sellAsset)
178
+ throw new Error("missing sellAsset");
179
+ if (!quote.buyAsset)
180
+ throw new Error("missing buyAsset");
181
+ if (!quote.sellAmount)
182
+ throw new Error("missing sellAmount");
183
+ if (!quote.senderAddress)
184
+ throw new Error("missing senderAddress");
185
+ if (!quote.recipientAddress)
186
+ throw new Error("missing recipientAddress");
187
+ if (!quote.slippage)
188
+ throw new Error("missing slippage");
189
+ output.txs = [];
190
+ log.info(tag, "quote.sellAsset: ", quote.sellAsset);
191
+ let originChainId = caipToNetworkId(quote.sellAsset).replace('eip155:', '');
192
+ log.info(tag, "originChainId: ", originChainId);
193
+ let destinationChainId = caipToNetworkId(quote.buyAsset).replace('eip155:', '');
194
+ log.info(tag, "destinationChainId: ", destinationChainId);
195
+ let pools = await sdk.utils.getDeployedAddress("SpokePool", originChainId);
196
+ log.info(tag, "pools: ", pools);
197
+ let providerUrl = EIP155_MAINNET_CHAINS[caipToNetworkId(quote.sellAsset)].rpc;
198
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(providerUrl); // Set your Ethereum RPC URL
199
+ const spokePoolCode = await provider.getCode(pools);
200
+ log.info(tag, "spokePoolCode: ", spokePoolCode);
201
+ if (!spokePoolCode || spokePoolCode === "0x") {
202
+ throw new Error(`SpokePool not deployed at ${pools}`);
203
+ }
204
+ const getSpokePool = (_chainId, address, provider) => {
205
+ return typechain_1.SpokePool__factory.connect(address, provider);
206
+ };
207
+ let spokePool = await getSpokePool(originChainId, pools, provider);
208
+ log.info(tag, "spokePool: ", spokePool);
209
+ let recipient = quote.recipientAddress;
210
+ let token = EIP155_MAINNET_CHAINS[caipToNetworkId(quote.sellAsset)].WETH;
211
+ let amount = ethers_1.ethers.BigNumber.from(quote.sellAmount);
212
+ let relayerFeePct = 0;
213
+ let quoteTimestamp = 0;
214
+ let message = "0x";
215
+ let maxCount = ethers_1.ethers.constants.MaxUint256.toString();
216
+ let value = 0;
217
+ log.info(tag, "inputs: ", { recipient, token, amount, destinationChainId, relayerFeePct, quoteTimestamp, message, maxCount, value });
218
+ const txData = await spokePool.populateTransaction.deposit(recipient, token, amount, destinationChainId, relayerFeePct, quoteTimestamp, message, maxCount, { value });
219
+ log.info(tag, "tx: ", txData);
220
+ let tx = await buildTx(txData, quote.senderAddress, originChainId, provider);
221
+ output.meta = {
222
+ quoteMode: "ERC20-ERC20"
223
+ };
224
+ output.steps = 1;
225
+ output.complete = true;
226
+ output.type = 'EVM';
227
+ output.id = uuid();
228
+ output.txs.push({
229
+ type: "evm",
230
+ description: 'swap tokens',
231
+ chain: caipToNetworkId(quote.sellAsset),
232
+ txParams: tx
233
+ });
234
+ return output;
235
+ }
236
+ catch (e) {
237
+ console.error(tag, "e: ", e);
238
+ throw e;
239
+ }
240
+ };
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@pioneer-platform/across-client",
3
+ "version": "0.0.2",
4
+ "main": "./lib/index.js",
5
+ "types": "./lib/index.d.ts",
6
+ "dependencies": {
7
+ "@pioneer-platform/loggerdog": "^8.3.1",
8
+ "@pioneer-platform/pioneer-caip": "^9.2.23",
9
+ "@pioneer-platform/pioneer-coins": "^9.2.13",
10
+ "@across-protocol/constants-v2": "^1.0.14",
11
+ "@across-protocol/contracts-v2": "2.5.4",
12
+ "@across-protocol/sdk-v2": "^0.22.18",
13
+ "axios": "^1.3.4",
14
+ "dotenv": "^8.2.0",
15
+ "uuidv4": "^6.2.13"
16
+ },
17
+ "scripts": {
18
+ "npm": "npm i",
19
+ "test": "npm run build && node __tests__/test-module.js",
20
+ "build": "tsc -p .",
21
+ "prepublish": "npm run build",
22
+ "refresh": "rm -rf ./node_modules ./package-lock.json && npm install"
23
+ },
24
+ "devDependencies": {
25
+ "@types/async-retry": "^1.4.8",
26
+ "@types/bunyan": "^1.8.11",
27
+ "@types/jest": "^25.2.3",
28
+ "@types/node": "^13.13.21",
29
+ "@types/source-map-support": "^0.5.3",
30
+ "babel-plugin-macros": "^3.1.0",
31
+ "jest": "^26.4.2",
32
+ "onchange": "^7.0.2",
33
+ "serve": "^11.3.2",
34
+ "ts-jest": "^29.0.5",
35
+ "typescript": "^5.0.2"
36
+ },
37
+ "gitHead": "a76012f6693a12181c4744e53e977a9eaeef0ed3"
38
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": ["ES2020", "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
+ }