carbon-js-sdk 0.3.27 → 0.3.28
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/CarbonSDK.d.ts +1 -0
- package/lib/CarbonSDK.js +10 -0
- package/lib/clients/ETHClient.d.ts +1 -0
- package/lib/clients/ETHClient.js +2 -1
- package/lib/clients/HydrogenClient.d.ts +2 -2
- package/lib/clients/HydrogenClient.js +7 -1
- package/lib/constant/network.d.ts +1 -0
- package/lib/constant/network.js +36 -0
- package/lib/provider/ledger/ledger.d.ts +2 -0
- package/lib/provider/ledger/ledger.js +39 -23
- package/lib/provider/metamask/MetaMask.d.ts +2 -2
- package/lib/provider/metamask/MetaMask.js +43 -0
- package/lib/util/blockchain.js +2 -0
- package/package.json +1 -1
package/lib/CarbonSDK.d.ts
CHANGED
package/lib/CarbonSDK.js
CHANGED
|
@@ -106,10 +106,20 @@ class CarbonSDK {
|
|
|
106
106
|
blockchain: blockchain_1.Blockchain.BinanceSmartChain,
|
|
107
107
|
tokenClient: this.token,
|
|
108
108
|
});
|
|
109
|
+
this.arbitrum = clients_1.ETHClient.instance({
|
|
110
|
+
configProvider: this,
|
|
111
|
+
blockchain: blockchain_1.Blockchain.Arbitrum,
|
|
112
|
+
tokenClient: this.token,
|
|
113
|
+
});
|
|
109
114
|
this.zil = clients_1.ZILClient.instance({
|
|
110
115
|
configProvider: this,
|
|
111
116
|
blockchain: blockchain_1.Blockchain.Zilliqa,
|
|
112
117
|
});
|
|
118
|
+
this.arbitrum = clients_1.ETHClient.instance({
|
|
119
|
+
configProvider: this,
|
|
120
|
+
blockchain: blockchain_1.Blockchain.Arbitrum,
|
|
121
|
+
tokenClient: this.token,
|
|
122
|
+
});
|
|
113
123
|
}
|
|
114
124
|
static instance(opts = DEFAULT_SDK_INIT_OPTS) {
|
|
115
125
|
var _a, _b, _c, _d;
|
package/lib/clients/ETHClient.js
CHANGED
|
@@ -349,9 +349,10 @@ class ETHClient {
|
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
351
|
exports.ETHClient = ETHClient;
|
|
352
|
-
ETHClient.SUPPORTED_BLOCKCHAINS = [blockchain_1.Blockchain.BinanceSmartChain, blockchain_1.Blockchain.Ethereum];
|
|
352
|
+
ETHClient.SUPPORTED_BLOCKCHAINS = [blockchain_1.Blockchain.BinanceSmartChain, blockchain_1.Blockchain.Ethereum, blockchain_1.Blockchain.Arbitrum];
|
|
353
353
|
ETHClient.BLOCKCHAIN_KEY = {
|
|
354
354
|
[blockchain_1.Blockchain.BinanceSmartChain]: "bsc",
|
|
355
355
|
[blockchain_1.Blockchain.Ethereum]: "eth",
|
|
356
|
+
[blockchain_1.Blockchain.Arbitrum]: "arbitrum",
|
|
356
357
|
};
|
|
357
358
|
exports.default = ETHClient;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NetworkConfig } from "../constant";
|
|
2
|
-
import { GetDetailedTransfersResponse, GetRelaysRequest, GetStatsResponse, GetTransfersRequest, GetTransfersResponse } from "../hydrogen";
|
|
2
|
+
import { GetDetailedTransfersResponse, GetRelaysRequest, GetRelaysResponse, GetStatsResponse, GetTransfersRequest, GetTransfersResponse } from "../hydrogen";
|
|
3
3
|
import { GetFeeQuoteRequest, GetFeeQuoteResponse } from "../hydrogen/feeQuote";
|
|
4
4
|
export declare const HydrogenEndpoints: {
|
|
5
5
|
stats: string;
|
|
@@ -15,7 +15,7 @@ declare class HydrogenClient {
|
|
|
15
15
|
getStats(): Promise<GetStatsResponse>;
|
|
16
16
|
getTransfers(req: GetTransfersRequest): Promise<GetTransfersResponse>;
|
|
17
17
|
getDetailedTransfers(req: GetTransfersRequest): Promise<GetDetailedTransfersResponse>;
|
|
18
|
-
getRelaysTransfers(req: GetRelaysRequest): Promise<
|
|
18
|
+
getRelaysTransfers(req: GetRelaysRequest): Promise<GetRelaysResponse>;
|
|
19
19
|
getFeeQuote(req: GetFeeQuoteRequest): Promise<GetFeeQuoteResponse>;
|
|
20
20
|
}
|
|
21
21
|
export default HydrogenClient;
|
|
@@ -42,6 +42,12 @@ const formatCrossChainTransferDetailed = (value) => {
|
|
|
42
42
|
return value;
|
|
43
43
|
return Object.assign(Object.assign({}, formatCrossChainTransfer(value)), { source_event: formatChainEvent(value.source_event), bridging_event: formatChainEvent(value.bridging_event), destination_event: formatChainEvent(value.destination_event) });
|
|
44
44
|
};
|
|
45
|
+
const formatRelaysTransfers = (value) => {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
if (!value || typeof value !== "object")
|
|
48
|
+
return value;
|
|
49
|
+
return Object.assign(Object.assign({}, value), { created_at: formatDateField((_a = value.created_at) === null || _a === void 0 ? void 0 : _a.toString()), updated_at: formatDateField((_b = value.updated_at) === null || _b === void 0 ? void 0 : _b.toString()), source_blockchain: util_1.BlockchainUtils.parseBlockchain(value.source_blockchain), bridging_blockchain: util_1.BlockchainUtils.parseBlockchain(value.bridging_blockchain), destination_blockchain: util_1.BlockchainUtils.parseBlockchain(value.destination_blockchain) });
|
|
50
|
+
};
|
|
45
51
|
const formatChainEvent = (value) => {
|
|
46
52
|
var _a, _b, _c;
|
|
47
53
|
if (!value || typeof value !== "object")
|
|
@@ -100,7 +106,7 @@ class HydrogenClient {
|
|
|
100
106
|
const request = this.apiManager.path('relays', {}, Object.assign(Object.assign({}, req), { include_tx: true }));
|
|
101
107
|
const response = yield request.get();
|
|
102
108
|
const result = response.data;
|
|
103
|
-
return Object.assign(Object.assign({}, result), { data: result.data.map(
|
|
109
|
+
return Object.assign(Object.assign({}, result), { data: result.data.map(formatRelaysTransfers) });
|
|
104
110
|
});
|
|
105
111
|
}
|
|
106
112
|
getFeeQuote(req) {
|
package/lib/constant/network.js
CHANGED
|
@@ -50,6 +50,15 @@ exports.NetworkConfigs = {
|
|
|
50
50
|
balanceReader: "0x2b18c5e1edaa7e27d40fec8d0b7d96c5eefa35df",
|
|
51
51
|
byteCodeHash: "0x1b147c1cef546fcbcc1284df778073d65b90f80d5b649a69d5f8a01e186c0ec1",
|
|
52
52
|
},
|
|
53
|
+
arbitrum: {
|
|
54
|
+
rpcURL: "https://arb1.arbitrum.io/rpc",
|
|
55
|
+
wsURL: "",
|
|
56
|
+
payerURL: "https://payer.carbon.network",
|
|
57
|
+
bridgeEntranceAddr: "0x7b1c7216c117cc62d875e3086518b238392cf04d",
|
|
58
|
+
lockProxyAddr: "0xb1e6f8820826491fcc5519f84ff4e2bdbb6e3cad",
|
|
59
|
+
balanceReader: "0x7e8d8c98a016877cb3103e837fc71d41b155af70",
|
|
60
|
+
byteCodeHash: "", // TODO: update when byteCodeHash is added
|
|
61
|
+
},
|
|
53
62
|
neo: {
|
|
54
63
|
rpcURL: "https://mainnet2.neo2.coz.io:443",
|
|
55
64
|
wrapperScriptHash: "f46719e2d16bf50cddcef9d4bbfece901f73cbb6",
|
|
@@ -98,6 +107,15 @@ exports.NetworkConfigs = {
|
|
|
98
107
|
balanceReader: "0x25c22f65cb820e787a13951f295d0b86db7b07b5",
|
|
99
108
|
byteCodeHash: "0x1b147c1cef546fcbcc1284df778073d65b90f80d5b649a69d5f8a01e186c0ec1",
|
|
100
109
|
},
|
|
110
|
+
arbitrum: {
|
|
111
|
+
rpcURL: "https://rinkeby.arbitrum.io/rpc",
|
|
112
|
+
wsURL: "",
|
|
113
|
+
payerURL: "https://test-payer.carbon.network",
|
|
114
|
+
bridgeEntranceAddr: "",
|
|
115
|
+
lockProxyAddr: "",
|
|
116
|
+
balanceReader: "",
|
|
117
|
+
byteCodeHash: "",
|
|
118
|
+
},
|
|
101
119
|
neo: {
|
|
102
120
|
rpcURL: "https://g30trj885e.execute-api.ap-southeast-1.amazonaws.com",
|
|
103
121
|
wrapperScriptHash: "f46719e2d16bf50cddcef9d4bbfece901f73cbb6",
|
|
@@ -146,6 +164,15 @@ exports.NetworkConfigs = {
|
|
|
146
164
|
balanceReader: "0x25c22f65cb820e787a13951f295d0b86db7b07b5",
|
|
147
165
|
byteCodeHash: "0x1b147c1cef546fcbcc1284df778073d65b90f80d5b649a69d5f8a01e186c0ec1",
|
|
148
166
|
},
|
|
167
|
+
arbitrum: {
|
|
168
|
+
rpcURL: "https://rinkeby.arbitrum.io/rpc",
|
|
169
|
+
wsURL: "",
|
|
170
|
+
payerURL: "https://test-payer.carbon.network",
|
|
171
|
+
bridgeEntranceAddr: "",
|
|
172
|
+
lockProxyAddr: "",
|
|
173
|
+
balanceReader: "",
|
|
174
|
+
byteCodeHash: "",
|
|
175
|
+
},
|
|
149
176
|
neo: {
|
|
150
177
|
rpcURL: "https://g30trj885e.execute-api.ap-southeast-1.amazonaws.com",
|
|
151
178
|
wrapperScriptHash: "f46719e2d16bf50cddcef9d4bbfece901f73cbb6",
|
|
@@ -194,6 +221,15 @@ exports.NetworkConfigs = {
|
|
|
194
221
|
balanceReader: "",
|
|
195
222
|
byteCodeHash: "",
|
|
196
223
|
},
|
|
224
|
+
arbitrum: {
|
|
225
|
+
rpcURL: "https://rinkeby.arbitrum.io/rpc",
|
|
226
|
+
wsURL: "",
|
|
227
|
+
payerURL: "https://test-payer.carbon.network",
|
|
228
|
+
bridgeEntranceAddr: "",
|
|
229
|
+
lockProxyAddr: "",
|
|
230
|
+
balanceReader: "",
|
|
231
|
+
byteCodeHash: "",
|
|
232
|
+
},
|
|
197
233
|
neo: {
|
|
198
234
|
rpcURL: "https://g30trj885e.execute-api.ap-southeast-1.amazonaws.com",
|
|
199
235
|
wrapperScriptHash: "f46719e2d16bf50cddcef9d4bbfece901f73cbb6",
|
|
@@ -16,6 +16,8 @@ declare class CosmosLedger {
|
|
|
16
16
|
getOpenApp(): Promise<any>;
|
|
17
17
|
getPubKey(): Promise<any>;
|
|
18
18
|
getCosmosAddress(): Promise<string>;
|
|
19
|
+
generateCosmosAddress(hdPath: Array<number>): Promise<string>;
|
|
20
|
+
changeBIP44Path(hdPath: Array<number>, hrp: string): Promise<void>;
|
|
19
21
|
confirmLedgerAddress(): Promise<void>;
|
|
20
22
|
sign(signMessage: string): Promise<Uint8Array>;
|
|
21
23
|
private checkLedgerErrors;
|
|
@@ -38,12 +38,12 @@ exports.checkAppMode = void 0;
|
|
|
38
38
|
// original implementation: https://github.com/luniehq/cosmos-ledger
|
|
39
39
|
const ledger_cosmos_js_1 = __importDefault(require("ledger-cosmos-js"));
|
|
40
40
|
const secp256k1_1 = require("secp256k1");
|
|
41
|
-
const semver = require(
|
|
41
|
+
const semver = require("semver");
|
|
42
42
|
const crypto = __importStar(require("crypto"));
|
|
43
43
|
const ripemd160_1 = __importDefault(require("ripemd160"));
|
|
44
44
|
const bech32 = __importStar(require("bech32"));
|
|
45
45
|
const INTERACTION_TIMEOUT = 120; // seconds to wait for user action on Ledger, currently is always limited to 60
|
|
46
|
-
const REQUIRED_COSMOS_APP_VERSION =
|
|
46
|
+
const REQUIRED_COSMOS_APP_VERSION = "1.5.3";
|
|
47
47
|
/*
|
|
48
48
|
HD wallet derivation path (BIP44)
|
|
49
49
|
DerivationPath{44, 118, account, 0, index}
|
|
@@ -98,35 +98,33 @@ class CosmosLedger {
|
|
|
98
98
|
if (!navigator.hid) {
|
|
99
99
|
throw new Error(`Your browser doesn't have HID enabled. Please enable this feature by visiting: chrome://flags/#enable-experimental-web-platform-features`);
|
|
100
100
|
}
|
|
101
|
-
const { default: TransportWebHID } = yield Promise.resolve().then(() => __importStar(require(
|
|
102
|
-
/* webpackChunkName: "webhid" */ '@ledgerhq/hw-transport-webhid')));
|
|
101
|
+
const { default: TransportWebHID } = yield Promise.resolve().then(() => __importStar(require(/* webpackChunkName: "webhid" */ "@ledgerhq/hw-transport-webhid")));
|
|
103
102
|
transport = yield TransportWebHID.create(timeout * 1000);
|
|
104
103
|
}
|
|
105
104
|
// OSX / Linux
|
|
106
105
|
else {
|
|
107
106
|
try {
|
|
108
|
-
const { default: TransportWebUSB } = yield Promise.resolve().then(() => __importStar(require(
|
|
109
|
-
/* webpackChunkName: "webusb" */ '@ledgerhq/hw-transport-webusb')));
|
|
107
|
+
const { default: TransportWebUSB } = yield Promise.resolve().then(() => __importStar(require(/* webpackChunkName: "webusb" */ "@ledgerhq/hw-transport-webusb")));
|
|
110
108
|
transport = yield TransportWebUSB.create(timeout * 1000);
|
|
111
109
|
}
|
|
112
110
|
catch (err) {
|
|
113
111
|
if (err instanceof Error) {
|
|
114
112
|
/* istanbul ignore next: specific error rewrite */
|
|
115
|
-
if (err.message.trim().startsWith(
|
|
113
|
+
if (err.message.trim().startsWith("No WebUSB interface found for your Ledger device")) {
|
|
116
114
|
throw new Error("Couldn't connect to a Ledger device. Please use Ledger Live to upgrade the Ledger firmware to version 1.5.5 or later.");
|
|
117
115
|
}
|
|
118
116
|
/* istanbul ignore next: specific error rewrite */
|
|
119
|
-
if (err.message.trim().startsWith(
|
|
117
|
+
if (err.message.trim().startsWith("Unable to claim interface")) {
|
|
120
118
|
// apparently can't use it in several tabs in parallel
|
|
121
|
-
throw new Error(
|
|
119
|
+
throw new Error("Could not access Ledger device. Is it being used in another tab?");
|
|
122
120
|
}
|
|
123
121
|
/* istanbul ignore next: specific error rewrite */
|
|
124
|
-
if (err.message.trim().startsWith(
|
|
122
|
+
if (err.message.trim().startsWith("Not supported")) {
|
|
125
123
|
// apparently can't use it in several tabs in parallel
|
|
126
124
|
throw new Error("Your browser doesn't seem to support WebUSB yet. Try updating it to the latest version.");
|
|
127
125
|
}
|
|
128
126
|
/* istanbul ignore next: specific error rewrite */
|
|
129
|
-
if (err.message.trim().startsWith(
|
|
127
|
+
if (err.message.trim().startsWith("No device selected")) {
|
|
130
128
|
// apparently can't use it in several tabs in parallel
|
|
131
129
|
throw new Error("You did not select a Ledger device. If you didn't see your Ledger, check if the Ledger is plugged in and unlocked.");
|
|
132
130
|
}
|
|
@@ -194,6 +192,28 @@ class CosmosLedger {
|
|
|
194
192
|
return res;
|
|
195
193
|
});
|
|
196
194
|
}
|
|
195
|
+
generateCosmosAddress(hdPath) {
|
|
196
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
197
|
+
yield this.connect();
|
|
198
|
+
const pubKey = yield this.cosmosApp.publicKey(hdPath);
|
|
199
|
+
this.checkLedgerErrors(pubKey);
|
|
200
|
+
const compressedPk = pubKey.compressed_pk;
|
|
201
|
+
const response = yield getBech32FromPK(this.hrp, compressedPk);
|
|
202
|
+
return response;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
changeBIP44Path(hdPath, hrp) {
|
|
206
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
try {
|
|
208
|
+
this.hdPath = hdPath;
|
|
209
|
+
this.hrp = hrp;
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
throw new Error(`error`);
|
|
213
|
+
}
|
|
214
|
+
return;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
197
217
|
// triggers a confirmation request of the cosmos address on the Ledger device
|
|
198
218
|
confirmLedgerAddress() {
|
|
199
219
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -205,7 +225,7 @@ class CosmosLedger {
|
|
|
205
225
|
}
|
|
206
226
|
const response = yield this.cosmosApp.showAddressAndPubKey(this.hdPath, this.hrp);
|
|
207
227
|
this.checkLedgerErrors(response, {
|
|
208
|
-
rejectionMessage:
|
|
228
|
+
rejectionMessage: "Displayed address was rejected",
|
|
209
229
|
});
|
|
210
230
|
});
|
|
211
231
|
}
|
|
@@ -224,7 +244,7 @@ class CosmosLedger {
|
|
|
224
244
|
}
|
|
225
245
|
// parse Ledger errors in a more user friendly format
|
|
226
246
|
/* istanbul ignore next: maps a bunch of errors */
|
|
227
|
-
checkLedgerErrors({ error_message, device_locked }, { timeoutMessag =
|
|
247
|
+
checkLedgerErrors({ error_message, device_locked }, { timeoutMessag = "Connection timed out. Please try again.", rejectionMessage = "User rejected the transaction" } = {}) {
|
|
228
248
|
if (device_locked) {
|
|
229
249
|
throw new Error(`Ledger's screensaver mode is on`);
|
|
230
250
|
}
|
|
@@ -240,8 +260,7 @@ class CosmosLedger {
|
|
|
240
260
|
case `Unknown Status Code: 26628`:
|
|
241
261
|
throw new Error(`Ledger's screensaver mode is on`);
|
|
242
262
|
case `Instruction not supported`:
|
|
243
|
-
throw new Error(`Your Cosmos Ledger App is not up to date.
|
|
244
|
-
`Please update to version ${REQUIRED_COSMOS_APP_VERSION}.`);
|
|
263
|
+
throw new Error(`Your Cosmos Ledger App is not up to date. Please update to version ${REQUIRED_COSMOS_APP_VERSION}.`);
|
|
245
264
|
case `No errors`:
|
|
246
265
|
// do nothing
|
|
247
266
|
break;
|
|
@@ -264,17 +283,14 @@ exports.checkAppMode = checkAppMode;
|
|
|
264
283
|
// doesn't properly work in ledger-cosmos-js
|
|
265
284
|
function getBech32FromPK(hrp, pk) {
|
|
266
285
|
if (pk.length !== 33) {
|
|
267
|
-
throw new Error(
|
|
286
|
+
throw new Error("expected compressed public key [31 bytes]");
|
|
268
287
|
}
|
|
269
|
-
const hashSha256 = crypto
|
|
270
|
-
.createHash('sha256')
|
|
271
|
-
.update(pk)
|
|
272
|
-
.digest();
|
|
288
|
+
const hashSha256 = crypto.createHash("sha256").update(pk).digest();
|
|
273
289
|
const hashRip = new ripemd160_1.default().update(hashSha256).digest();
|
|
274
290
|
return bech32.encode(hrp, bech32.toWords(hashRip));
|
|
275
291
|
}
|
|
276
292
|
function isWindows(platform) {
|
|
277
|
-
return platform.indexOf(
|
|
293
|
+
return platform.indexOf("Win") > -1;
|
|
278
294
|
}
|
|
279
295
|
function getBrowser(userAgent) {
|
|
280
296
|
var _a;
|
|
@@ -285,8 +301,8 @@ function getBrowser(userAgent) {
|
|
|
285
301
|
throw new Error("Your browser doesn't support Ledger devices.");
|
|
286
302
|
}
|
|
287
303
|
if (isBrave)
|
|
288
|
-
return
|
|
304
|
+
return "brave";
|
|
289
305
|
else
|
|
290
|
-
return
|
|
306
|
+
return "chrome";
|
|
291
307
|
}
|
|
292
308
|
exports.default = CosmosLedger;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Network } from '../../constant';
|
|
2
2
|
import { Blockchain } from '../../util/blockchain';
|
|
3
3
|
import { ethers } from 'ethers';
|
|
4
|
-
export declare type EVMChain = Blockchain.Ethereum | Blockchain.BinanceSmartChain;
|
|
4
|
+
export declare type EVMChain = Blockchain.Ethereum | Blockchain.BinanceSmartChain | Blockchain.Arbitrum;
|
|
5
5
|
interface RequestArguments {
|
|
6
6
|
method: string;
|
|
7
7
|
params?: unknown[] | object;
|
|
@@ -38,7 +38,7 @@ export declare class MetaMask {
|
|
|
38
38
|
readonly network: Network;
|
|
39
39
|
private blockchain;
|
|
40
40
|
static getNetworkParams(network: Network, blockchain?: EVMChain): MetaMaskChangeNetworkParam;
|
|
41
|
-
static getRequiredChainId(network: Network, blockchain?: Blockchain): 1 | 4 | 56 | 97;
|
|
41
|
+
static getRequiredChainId(network: Network, blockchain?: Blockchain): 1 | 4 | 56 | 97 | 42161 | 421611;
|
|
42
42
|
constructor(network: Network);
|
|
43
43
|
private checkProvider;
|
|
44
44
|
getBlockchain(): Blockchain;
|
|
@@ -49,6 +49,13 @@ const CONTRACT_HASH = {
|
|
|
49
49
|
[constant_1.Network.LocalHost]: '0x06E949ec2d6737ff57859CdcE426C5b5CA2Fc085',
|
|
50
50
|
[constant_1.Network.MainNet]: '0x3786d94AC6B15FE2eaC72c3CA78cB82578Fc66f4',
|
|
51
51
|
},
|
|
52
|
+
[blockchain_1.Blockchain.Arbitrum]: {
|
|
53
|
+
// use same testnet contract for all non-mainnet uses
|
|
54
|
+
[constant_1.Network.TestNet]: '',
|
|
55
|
+
[constant_1.Network.DevNet]: '',
|
|
56
|
+
[constant_1.Network.LocalHost]: '',
|
|
57
|
+
[constant_1.Network.MainNet]: '0x43138036d1283413035b8eca403559737e8f7980',
|
|
58
|
+
},
|
|
52
59
|
};
|
|
53
60
|
const REGISTRY_CONTRACT_ABI = eth_1.ABIs.keyStorage;
|
|
54
61
|
const ENCRYPTION_VERSION = 'x25519-xsalsa20-poly1305';
|
|
@@ -112,6 +119,28 @@ const ETH_TESTNET = {
|
|
|
112
119
|
chainId: '0x4',
|
|
113
120
|
rpcUrls: ['https://rinkeby.infura.io/v3/'],
|
|
114
121
|
};
|
|
122
|
+
const ARBITRUM_MAINNET = {
|
|
123
|
+
chainId: '0xA4B1',
|
|
124
|
+
blockExplorerUrls: ['https://explorer.arbitrum.io'],
|
|
125
|
+
chainName: 'Arbitrum One',
|
|
126
|
+
rpcUrls: ['https://arb1.arbitrum.io/rpc'],
|
|
127
|
+
nativeCurrency: {
|
|
128
|
+
decimals: 18,
|
|
129
|
+
name: 'Ethereum',
|
|
130
|
+
symbol: 'ETH',
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
const ARBITRUM_TESTNET = {
|
|
134
|
+
chainId: '0x66EEB',
|
|
135
|
+
blockExplorerUrls: [''],
|
|
136
|
+
chainName: 'Arbitrum Testnet',
|
|
137
|
+
rpcUrls: ['https://rinkeby.arbitrum.io/rpc'],
|
|
138
|
+
nativeCurrency: {
|
|
139
|
+
decimals: 18,
|
|
140
|
+
name: 'Ethereum',
|
|
141
|
+
symbol: 'ETH',
|
|
142
|
+
},
|
|
143
|
+
};
|
|
115
144
|
/**
|
|
116
145
|
* TODO: Add docs
|
|
117
146
|
*/
|
|
@@ -125,6 +154,8 @@ class MetaMask {
|
|
|
125
154
|
switch (blockchain) {
|
|
126
155
|
case blockchain_1.Blockchain.BinanceSmartChain:
|
|
127
156
|
return BSC_MAINNET;
|
|
157
|
+
case blockchain_1.Blockchain.Arbitrum:
|
|
158
|
+
return ARBITRUM_MAINNET;
|
|
128
159
|
default:
|
|
129
160
|
// metamask should come with Ethereum configs
|
|
130
161
|
return ETH_MAINNET;
|
|
@@ -133,6 +164,8 @@ class MetaMask {
|
|
|
133
164
|
switch (blockchain) {
|
|
134
165
|
case blockchain_1.Blockchain.BinanceSmartChain:
|
|
135
166
|
return BSC_TESTNET;
|
|
167
|
+
case blockchain_1.Blockchain.Arbitrum:
|
|
168
|
+
return ARBITRUM_TESTNET;
|
|
136
169
|
default:
|
|
137
170
|
// metamask should come with Ethereum configs
|
|
138
171
|
return ETH_TESTNET;
|
|
@@ -142,11 +175,13 @@ class MetaMask {
|
|
|
142
175
|
if (network === constant_1.Network.MainNet) {
|
|
143
176
|
switch (blockchain) {
|
|
144
177
|
case blockchain_1.Blockchain.BinanceSmartChain: return 56;
|
|
178
|
+
case blockchain_1.Blockchain.Arbitrum: return 42161;
|
|
145
179
|
default: return 1;
|
|
146
180
|
}
|
|
147
181
|
}
|
|
148
182
|
switch (blockchain) {
|
|
149
183
|
case blockchain_1.Blockchain.BinanceSmartChain: return 97;
|
|
184
|
+
case blockchain_1.Blockchain.Arbitrum: return 421611;
|
|
150
185
|
default: return 4;
|
|
151
186
|
}
|
|
152
187
|
}
|
|
@@ -319,6 +354,10 @@ class MetaMask {
|
|
|
319
354
|
this.blockchain = blockchain_1.Blockchain.BinanceSmartChain;
|
|
320
355
|
return currentChainId;
|
|
321
356
|
}
|
|
357
|
+
if (currentChainId === 42161) {
|
|
358
|
+
this.blockchain = blockchain_1.Blockchain.Arbitrum;
|
|
359
|
+
return currentChainId;
|
|
360
|
+
}
|
|
322
361
|
return 1;
|
|
323
362
|
}
|
|
324
363
|
if (currentChainId === 4) {
|
|
@@ -329,6 +368,10 @@ class MetaMask {
|
|
|
329
368
|
this.blockchain = blockchain_1.Blockchain.BinanceSmartChain;
|
|
330
369
|
return currentChainId;
|
|
331
370
|
}
|
|
371
|
+
if (currentChainId === 421611) {
|
|
372
|
+
this.blockchain = blockchain_1.Blockchain.Arbitrum;
|
|
373
|
+
return currentChainId;
|
|
374
|
+
}
|
|
332
375
|
// Deal with cases where users are logging in to devnet using mainnet chains
|
|
333
376
|
if (currentChainId === 56) {
|
|
334
377
|
return 97;
|
package/lib/util/blockchain.js
CHANGED