carbon-js-sdk 0.4.3-dev.2 → 0.4.4
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.js +1 -1
- package/lib/clients/ETHClient.d.ts +4 -11
- package/lib/clients/ETHClient.js +6 -20
- package/lib/clients/HydrogenClient.d.ts +7 -16
- package/lib/clients/HydrogenClient.js +9 -55
- package/lib/clients/NEOClient.d.ts +1 -1
- package/lib/clients/NEOClient.js +4 -9
- package/lib/clients/TokenClient.d.ts +5 -29
- package/lib/clients/TokenClient.js +52 -257
- package/lib/clients/ZILClient.d.ts +1 -1
- package/lib/clients/ZILClient.js +4 -9
- package/lib/constant/ibc.d.ts +0 -7
- package/lib/constant/ibc.js +1 -4
- package/lib/constant/network.d.ts +0 -2
- package/lib/constant/network.js +1 -5
- package/lib/hydrogen/transfer.d.ts +5 -5
- package/lib/modules/ibc.d.ts +17 -5
- package/lib/modules/ibc.js +20 -75
- package/lib/provider/keplr/KeplrStore.d.ts +1 -1
- package/lib/provider/keplr/KeplrStore.js +5 -2
- package/lib/provider/metamask/MetaMask.d.ts +5 -5
- package/lib/provider/metamask/MetaMask.js +37 -37
- package/lib/util/blockchain.d.ts +0 -26
- package/lib/util/blockchain.js +1 -160
- package/lib/util/ibc.d.ts +3 -5
- package/lib/util/ibc.js +1 -26
- package/package.json +1 -1
package/lib/modules/ibc.js
CHANGED
|
@@ -14,11 +14,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.IBCModule = void 0;
|
|
16
16
|
const tx_1 = require("../codec/ibc/applications/transfer/v1/tx");
|
|
17
|
-
const constant_1 = require("../constant");
|
|
18
|
-
const provider_1 = require("../provider");
|
|
19
17
|
const util_1 = require("../util");
|
|
18
|
+
const long_1 = __importDefault(require("long"));
|
|
20
19
|
const base_1 = __importDefault(require("./base"));
|
|
21
20
|
class IBCModule extends base_1.default {
|
|
21
|
+
/** @deprecated please use sendIbcTransferUpdated instead */
|
|
22
22
|
sendIBCTransfer(params, msgOpts) {
|
|
23
23
|
var _a, _b;
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -43,80 +43,25 @@ class IBCModule extends base_1.default {
|
|
|
43
43
|
}, msgOpts);
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
var _a
|
|
46
|
+
sendIbcTransferV2(params, msgOpts) {
|
|
47
|
+
var _a;
|
|
48
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const coinMinimalDenom = util_1.IBCUtils.makeIBCMinimalDenom(denomTrace.path, denomTrace.baseDenom);
|
|
66
|
-
const tokenInfo = denomTrace.token;
|
|
67
|
-
const isNativeDenom = tokenClient.isCarbonToken(tokenInfo);
|
|
68
|
-
if (!(((rootPath.length > 0 || (cw20RegexArr === null || cw20RegexArr === void 0 ? void 0 : cw20RegexArr.length)) && firstTransferChannel === ibcBridge.channels.src_channel)
|
|
69
|
-
|| (firstTransferChannel === ibcBridge.channels.dst_channel && isNativeDenom))) {
|
|
70
|
-
if (firstTransferChannel === ibcBridge.channels.src_channel && rootPath.length === 0) {
|
|
71
|
-
extendedChainInfo.minimalDenomMap[coinMinimalDenom] = denomTrace.baseDenom;
|
|
72
|
-
}
|
|
73
|
-
return prev;
|
|
74
|
-
}
|
|
75
|
-
let initCoinMinimalDenom = denomTrace.baseDenom;
|
|
76
|
-
if (cw20RegexArr === null || cw20RegexArr === void 0 ? void 0 : cw20RegexArr.length) {
|
|
77
|
-
prev.push({
|
|
78
|
-
coinDenom: (_c = tokenInfo === null || tokenInfo === void 0 ? void 0 : tokenInfo.symbol) !== null && _c !== void 0 ? _c : "",
|
|
79
|
-
coinMinimalDenom: initCoinMinimalDenom,
|
|
80
|
-
coinDecimals: (_d = tokenInfo === null || tokenInfo === void 0 ? void 0 : tokenInfo.decimals.toNumber()) !== null && _d !== void 0 ? _d : 0,
|
|
81
|
-
coinGeckoId: (_h = (_f = (_e = tokenClient === null || tokenClient === void 0 ? void 0 : tokenClient.geckoTokenNames) === null || _e === void 0 ? void 0 : _e[coinMinimalDenom]) !== null && _f !== void 0 ? _f : (_g = tokenClient === null || tokenClient === void 0 ? void 0 : tokenClient.geckoTokenNames) === null || _g === void 0 ? void 0 : _g[denomTrace.baseDenom]) !== null && _h !== void 0 ? _h : "",
|
|
82
|
-
type: "cw20",
|
|
83
|
-
contractAddress: (_j = cw20RegexArr[1]) !== null && _j !== void 0 ? _j : "",
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
initCoinMinimalDenom = isNativeDenom ? coinMinimalDenom : util_1.IBCUtils.makeIBCMinimalDenom(rootPath, denomTrace.baseDenom);
|
|
88
|
-
prev.push({
|
|
89
|
-
coinDenom: (_k = tokenInfo === null || tokenInfo === void 0 ? void 0 : tokenInfo.symbol) !== null && _k !== void 0 ? _k : "",
|
|
90
|
-
coinMinimalDenom: initCoinMinimalDenom,
|
|
91
|
-
coinDecimals: (_l = tokenInfo === null || tokenInfo === void 0 ? void 0 : tokenInfo.decimals.toNumber()) !== null && _l !== void 0 ? _l : 0,
|
|
92
|
-
coinGeckoId: (_q = (_o = (_m = tokenClient === null || tokenClient === void 0 ? void 0 : tokenClient.geckoTokenNames) === null || _m === void 0 ? void 0 : _m[coinMinimalDenom]) !== null && _o !== void 0 ? _o : (_p = tokenClient === null || tokenClient === void 0 ? void 0 : tokenClient.geckoTokenNames) === null || _p === void 0 ? void 0 : _p[denomTrace.baseDenom]) !== null && _q !== void 0 ? _q : "",
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
extendedChainInfo.minimalDenomMap[isNativeDenom ? denomTrace.baseDenom : coinMinimalDenom] = initCoinMinimalDenom;
|
|
96
|
-
return prev;
|
|
97
|
-
}, []);
|
|
98
|
-
chainInfoMap[ibcBridge.chain_id_name] = Object.assign(Object.assign({}, extendedChainInfo), { currencies: chainInfo.currencies.concat(extraCurrencies) });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const swthChainInfo = yield provider_1.KeplrAccount.getChainInfo(this.sdkProvider);
|
|
102
|
-
if (swthChainInfo) {
|
|
103
|
-
chainInfoMap[swthChainInfo.chainId] = Object.assign(Object.assign({}, swthChainInfo), { minimalDenomMap: {} });
|
|
104
|
-
}
|
|
105
|
-
return chainInfoMap;
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
getChainInfo(chainName, chainId) {
|
|
109
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
if (!chainName)
|
|
111
|
-
return undefined;
|
|
112
|
-
try {
|
|
113
|
-
const chainInfoResponse = yield fetch(`https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/master/cosmos/${chainName}.json`);
|
|
114
|
-
const chainInfoJson = yield chainInfoResponse.json();
|
|
115
|
-
return chainInfoJson;
|
|
116
|
-
}
|
|
117
|
-
catch (err) {
|
|
118
|
-
return util_1.IBCUtils.EmbedChainInfos[chainId];
|
|
119
|
-
}
|
|
49
|
+
const wallet = this.getWallet();
|
|
50
|
+
const value = tx_1.MsgTransfer.fromPartial(Object.assign(Object.assign({ sourcePort: params.sourcePort, sourceChannel: params.sourceChannel, token: {
|
|
51
|
+
denom: params.denom,
|
|
52
|
+
amount: params.amount.toString(10),
|
|
53
|
+
}, sender: (_a = params.sender) !== null && _a !== void 0 ? _a : wallet.bech32Address, receiver: params.receiver }, params.timeoutHeight && ({
|
|
54
|
+
timeoutHeight: {
|
|
55
|
+
revisionHeight: new long_1.default(params.timeoutHeight.revisionHeight.toNumber()),
|
|
56
|
+
revisionNumber: new long_1.default(params.timeoutHeight.revisionNumber.toNumber()),
|
|
57
|
+
},
|
|
58
|
+
})), params.timeoutTimestamp && ({
|
|
59
|
+
timeoutTimestamp: params.timeoutTimestamp.toNumber(),
|
|
60
|
+
})));
|
|
61
|
+
return yield wallet.sendTx({
|
|
62
|
+
typeUrl: util_1.CarbonTx.Types.MsgTransfer,
|
|
63
|
+
value,
|
|
64
|
+
}, msgOpts);
|
|
120
65
|
});
|
|
121
66
|
}
|
|
122
67
|
}
|
|
@@ -4,6 +4,6 @@ export declare class RootStore {
|
|
|
4
4
|
readonly chainStore: ChainStore;
|
|
5
5
|
readonly queriesStore: QueriesStore<[CosmosQueries, CosmwasmQueries]>;
|
|
6
6
|
readonly accountStore: AccountStore<[CosmosAccount, CosmwasmAccount]>;
|
|
7
|
-
constructor(getKeplr: () => Promise<any>,
|
|
7
|
+
constructor(getKeplr: () => Promise<any>, additionalChains?: ChainInfo[]);
|
|
8
8
|
}
|
|
9
9
|
export declare function createRootStore(getKeplr: () => Promise<any>, additionalChains?: ChainInfo[]): RootStore | null;
|
|
@@ -21,7 +21,7 @@ const stores_1 = require("@keplr-wallet/stores");
|
|
|
21
21
|
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
22
22
|
const semver_1 = __importDefault(require("semver"));
|
|
23
23
|
class RootStore {
|
|
24
|
-
constructor(getKeplr,
|
|
24
|
+
constructor(getKeplr, additionalChains) {
|
|
25
25
|
const embedChainInfos = Object.values(ibc_2.EmbedChainInfos).map((chainInfo) => {
|
|
26
26
|
const newChainInfo = chainInfo;
|
|
27
27
|
if (newChainInfo.tmRpc)
|
|
@@ -30,6 +30,9 @@ class RootStore {
|
|
|
30
30
|
delete newChainInfo.explorerUrlToTx;
|
|
31
31
|
return newChainInfo;
|
|
32
32
|
});
|
|
33
|
+
if (additionalChains && (additionalChains === null || additionalChains === void 0 ? void 0 : additionalChains.length) > 0) {
|
|
34
|
+
embedChainInfos.push(...additionalChains);
|
|
35
|
+
}
|
|
33
36
|
const eventListener = (() => {
|
|
34
37
|
// On client-side (web browser), use the global window object.
|
|
35
38
|
if (typeof window !== "undefined") {
|
|
@@ -53,7 +56,7 @@ class RootStore {
|
|
|
53
56
|
yield keplr.experimentalSuggestChain(info);
|
|
54
57
|
});
|
|
55
58
|
}
|
|
56
|
-
this.chainStore = new stores_1.ChainStore(
|
|
59
|
+
this.chainStore = new stores_1.ChainStore(embedChainInfos);
|
|
57
60
|
this.queriesStore = new stores_1.QueriesStore(new common_1.IndexedDBKVStore("store_web_queries"), this.chainStore, stores_1.CosmosQueries.use(), stores_1.CosmwasmQueries.use());
|
|
58
61
|
this.accountStore = new stores_1.AccountStore(eventListener, this.chainStore, () => {
|
|
59
62
|
return {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Network } from "../../constant";
|
|
2
|
-
import { Blockchain
|
|
2
|
+
import { Blockchain } from "../../util/blockchain";
|
|
3
3
|
import { ethers } from "ethers";
|
|
4
|
-
export declare type EVMChain =
|
|
4
|
+
export declare type EVMChain = Blockchain.Ethereum | Blockchain.BinanceSmartChain | Blockchain.Arbitrum | Blockchain.Polygon | Blockchain.Okc;
|
|
5
5
|
interface RequestArguments {
|
|
6
6
|
method: string;
|
|
7
7
|
params?: unknown[] | object;
|
|
@@ -28,7 +28,7 @@ export interface CallContractArgs {
|
|
|
28
28
|
data?: string;
|
|
29
29
|
}
|
|
30
30
|
export interface MetaMaskSyncResult {
|
|
31
|
-
blockchain?: Blockchain
|
|
31
|
+
blockchain?: Blockchain;
|
|
32
32
|
chainId?: number;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
@@ -38,10 +38,10 @@ 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?:
|
|
41
|
+
static getRequiredChainId(network: Network, blockchain?: Blockchain): 1 | 5 | 66 | 56 | 137 | 97 | 65 | 80001 | 42161 | 421611;
|
|
42
42
|
constructor(network: Network);
|
|
43
43
|
private checkProvider;
|
|
44
|
-
getBlockchain():
|
|
44
|
+
getBlockchain(): Blockchain;
|
|
45
45
|
syncBlockchain(): Promise<MetaMaskSyncResult>;
|
|
46
46
|
getSigner(): Promise<ethers.Signer>;
|
|
47
47
|
getAPI(): MetaMaskAPI | null;
|
|
@@ -35,35 +35,35 @@ const blockchain_1 = require("../../util/blockchain");
|
|
|
35
35
|
const ethers_1 = require("ethers");
|
|
36
36
|
const ethSignUtils = __importStar(require("eth-sig-util"));
|
|
37
37
|
const CONTRACT_HASH = {
|
|
38
|
-
Ethereum: {
|
|
38
|
+
[blockchain_1.Blockchain.Ethereum]: {
|
|
39
39
|
// use same rinkeby contract for all non-mainnet uses
|
|
40
40
|
[constant_1.Network.TestNet]: "0x086e1b5f67c0f7ca8eb202d35553e27e964899e2",
|
|
41
41
|
[constant_1.Network.DevNet]: "0x086e1b5f67c0f7ca8eb202d35553e27e964899e2",
|
|
42
42
|
[constant_1.Network.LocalHost]: "0x086e1b5f67c0f7ca8eb202d35553e27e964899e2",
|
|
43
43
|
[constant_1.Network.MainNet]: "0xf4552877A40c1527D38970F170993660084D4541",
|
|
44
44
|
},
|
|
45
|
-
[
|
|
45
|
+
[blockchain_1.Blockchain.BinanceSmartChain]: {
|
|
46
46
|
// use same testnet contract for all non-mainnet uses
|
|
47
47
|
[constant_1.Network.TestNet]: "0x06E949ec2d6737ff57859CdcE426C5b5CA2Fc085",
|
|
48
48
|
[constant_1.Network.DevNet]: "0x06E949ec2d6737ff57859CdcE426C5b5CA2Fc085",
|
|
49
49
|
[constant_1.Network.LocalHost]: "0x06E949ec2d6737ff57859CdcE426C5b5CA2Fc085",
|
|
50
50
|
[constant_1.Network.MainNet]: "0x3786d94AC6B15FE2eaC72c3CA78cB82578Fc66f4",
|
|
51
51
|
},
|
|
52
|
-
Arbitrum: {
|
|
52
|
+
[blockchain_1.Blockchain.Arbitrum]: {
|
|
53
53
|
// use same testnet contract for all non-mainnet uses
|
|
54
54
|
[constant_1.Network.TestNet]: "",
|
|
55
55
|
[constant_1.Network.DevNet]: "",
|
|
56
56
|
[constant_1.Network.LocalHost]: "",
|
|
57
57
|
[constant_1.Network.MainNet]: "0x43138036d1283413035b8eca403559737e8f7980",
|
|
58
58
|
},
|
|
59
|
-
Polygon: {
|
|
59
|
+
[blockchain_1.Blockchain.Polygon]: {
|
|
60
60
|
// use same testnet contract for all non-mainnet uses
|
|
61
61
|
[constant_1.Network.TestNet]: "",
|
|
62
62
|
[constant_1.Network.DevNet]: "",
|
|
63
63
|
[constant_1.Network.LocalHost]: "",
|
|
64
64
|
[constant_1.Network.MainNet]: "0x61B9503Fe023E1F1Dd0ab7417923cB0A41DD9E0c",
|
|
65
65
|
},
|
|
66
|
-
|
|
66
|
+
[blockchain_1.Blockchain.Okc]: {
|
|
67
67
|
// use same testnet contract for all non-mainnet uses
|
|
68
68
|
[constant_1.Network.TestNet]: "",
|
|
69
69
|
[constant_1.Network.DevNet]: "",
|
|
@@ -207,18 +207,18 @@ const OKC_TESTNET = {
|
|
|
207
207
|
class MetaMask {
|
|
208
208
|
constructor(network) {
|
|
209
209
|
this.network = network;
|
|
210
|
-
this.blockchain =
|
|
210
|
+
this.blockchain = blockchain_1.Blockchain.Ethereum;
|
|
211
211
|
}
|
|
212
|
-
static getNetworkParams(network, blockchain =
|
|
212
|
+
static getNetworkParams(network, blockchain = blockchain_1.Blockchain.Ethereum) {
|
|
213
213
|
if (network === constant_1.Network.MainNet) {
|
|
214
214
|
switch (blockchain) {
|
|
215
|
-
case
|
|
215
|
+
case blockchain_1.Blockchain.BinanceSmartChain:
|
|
216
216
|
return BSC_MAINNET;
|
|
217
|
-
case
|
|
217
|
+
case blockchain_1.Blockchain.Arbitrum:
|
|
218
218
|
return ARBITRUM_MAINNET;
|
|
219
|
-
case
|
|
219
|
+
case blockchain_1.Blockchain.Polygon:
|
|
220
220
|
return POLYGON_MAINNET;
|
|
221
|
-
case
|
|
221
|
+
case blockchain_1.Blockchain.Okc:
|
|
222
222
|
return OKC_MAINNET;
|
|
223
223
|
default:
|
|
224
224
|
// metamask should come with Ethereum configs
|
|
@@ -226,42 +226,42 @@ class MetaMask {
|
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
switch (blockchain) {
|
|
229
|
-
case
|
|
229
|
+
case blockchain_1.Blockchain.BinanceSmartChain:
|
|
230
230
|
return BSC_TESTNET;
|
|
231
|
-
case
|
|
231
|
+
case blockchain_1.Blockchain.Arbitrum:
|
|
232
232
|
return ARBITRUM_TESTNET;
|
|
233
|
-
case
|
|
233
|
+
case blockchain_1.Blockchain.Polygon:
|
|
234
234
|
return POLYGON_TESTNET;
|
|
235
|
-
case
|
|
235
|
+
case blockchain_1.Blockchain.Okc:
|
|
236
236
|
return OKC_TESTNET;
|
|
237
237
|
default:
|
|
238
238
|
// metamask should come with Ethereum configs
|
|
239
239
|
return ETH_TESTNET;
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
|
-
static getRequiredChainId(network, blockchain =
|
|
242
|
+
static getRequiredChainId(network, blockchain = blockchain_1.Blockchain.Ethereum) {
|
|
243
243
|
if (network === constant_1.Network.MainNet) {
|
|
244
244
|
switch (blockchain) {
|
|
245
|
-
case
|
|
245
|
+
case blockchain_1.Blockchain.BinanceSmartChain:
|
|
246
246
|
return 56;
|
|
247
|
-
case
|
|
247
|
+
case blockchain_1.Blockchain.Arbitrum:
|
|
248
248
|
return 42161;
|
|
249
|
-
case
|
|
249
|
+
case blockchain_1.Blockchain.Polygon:
|
|
250
250
|
return 137;
|
|
251
|
-
case
|
|
251
|
+
case blockchain_1.Blockchain.Okc:
|
|
252
252
|
return 66;
|
|
253
253
|
default:
|
|
254
254
|
return 1;
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
switch (blockchain) {
|
|
258
|
-
case
|
|
258
|
+
case blockchain_1.Blockchain.BinanceSmartChain:
|
|
259
259
|
return 97;
|
|
260
|
-
case
|
|
260
|
+
case blockchain_1.Blockchain.Arbitrum:
|
|
261
261
|
return 421611;
|
|
262
|
-
case
|
|
262
|
+
case blockchain_1.Blockchain.Polygon:
|
|
263
263
|
return 80001;
|
|
264
|
-
case
|
|
264
|
+
case blockchain_1.Blockchain.Okc:
|
|
265
265
|
return 65;
|
|
266
266
|
default:
|
|
267
267
|
return 5;
|
|
@@ -269,10 +269,10 @@ class MetaMask {
|
|
|
269
269
|
}
|
|
270
270
|
checkProvider(blockchain = this.blockchain) {
|
|
271
271
|
const config = constant_1.NetworkConfigs[this.network];
|
|
272
|
-
if (!config[
|
|
272
|
+
if (!config[blockchain]) {
|
|
273
273
|
throw new Error(`MetaMask login not supported for this network ${this.network}`);
|
|
274
274
|
}
|
|
275
|
-
const ethNetworkConfig = config[
|
|
275
|
+
const ethNetworkConfig = config[blockchain];
|
|
276
276
|
const provider = new ethers_1.ethers.providers.JsonRpcProvider(ethNetworkConfig.rpcURL);
|
|
277
277
|
return provider;
|
|
278
278
|
}
|
|
@@ -284,7 +284,7 @@ class MetaMask {
|
|
|
284
284
|
return __awaiter(this, void 0, void 0, function* () {
|
|
285
285
|
const chainIdHex = (yield ((_a = this.getAPI()) === null || _a === void 0 ? void 0 : _a.request({ method: "eth_chainId" })));
|
|
286
286
|
const chainId = !!chainIdHex ? parseInt(chainIdHex, 16) : undefined;
|
|
287
|
-
const blockchain = (0, blockchain_1.
|
|
287
|
+
const blockchain = (0, blockchain_1.getBlockchainFromChain)(chainId);
|
|
288
288
|
this.blockchain = blockchain;
|
|
289
289
|
return { chainId, blockchain };
|
|
290
290
|
});
|
|
@@ -426,45 +426,45 @@ class MetaMask {
|
|
|
426
426
|
// set correct blockchain given the chain ID
|
|
427
427
|
if (network === constant_1.Network.MainNet) {
|
|
428
428
|
if (currentChainId === 1) {
|
|
429
|
-
this.blockchain =
|
|
429
|
+
this.blockchain = blockchain_1.Blockchain.Ethereum;
|
|
430
430
|
return currentChainId;
|
|
431
431
|
}
|
|
432
432
|
if (currentChainId === 56) {
|
|
433
|
-
this.blockchain =
|
|
433
|
+
this.blockchain = blockchain_1.Blockchain.BinanceSmartChain;
|
|
434
434
|
return currentChainId;
|
|
435
435
|
}
|
|
436
436
|
if (currentChainId === 42161) {
|
|
437
|
-
this.blockchain =
|
|
437
|
+
this.blockchain = blockchain_1.Blockchain.Arbitrum;
|
|
438
438
|
return currentChainId;
|
|
439
439
|
}
|
|
440
440
|
if (currentChainId === 137) {
|
|
441
|
-
this.blockchain =
|
|
441
|
+
this.blockchain = blockchain_1.Blockchain.Polygon;
|
|
442
442
|
return currentChainId;
|
|
443
443
|
}
|
|
444
444
|
if (currentChainId === 66) {
|
|
445
|
-
this.blockchain =
|
|
445
|
+
this.blockchain = blockchain_1.Blockchain.Okc;
|
|
446
446
|
return currentChainId;
|
|
447
447
|
}
|
|
448
448
|
return 1;
|
|
449
449
|
}
|
|
450
450
|
if (currentChainId === 5) {
|
|
451
|
-
this.blockchain =
|
|
451
|
+
this.blockchain = blockchain_1.Blockchain.Ethereum;
|
|
452
452
|
return currentChainId;
|
|
453
453
|
}
|
|
454
454
|
if (currentChainId === 97) {
|
|
455
|
-
this.blockchain =
|
|
455
|
+
this.blockchain = blockchain_1.Blockchain.BinanceSmartChain;
|
|
456
456
|
return currentChainId;
|
|
457
457
|
}
|
|
458
458
|
if (currentChainId === 421611) {
|
|
459
|
-
this.blockchain =
|
|
459
|
+
this.blockchain = blockchain_1.Blockchain.Arbitrum;
|
|
460
460
|
return currentChainId;
|
|
461
461
|
}
|
|
462
462
|
if (currentChainId === 80001) {
|
|
463
|
-
this.blockchain =
|
|
463
|
+
this.blockchain = blockchain_1.Blockchain.Polygon;
|
|
464
464
|
return currentChainId;
|
|
465
465
|
}
|
|
466
466
|
if (currentChainId === 65) {
|
|
467
|
-
this.blockchain =
|
|
467
|
+
this.blockchain = blockchain_1.Blockchain.Okc;
|
|
468
468
|
return currentChainId;
|
|
469
469
|
}
|
|
470
470
|
// Deal with cases where users are logging in to devnet using mainnet chains
|
package/lib/util/blockchain.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { TokenClient } from '../clients';
|
|
2
|
-
import { Bridge } from '../codec';
|
|
3
1
|
import { Network } from "../constant/network";
|
|
4
2
|
import { SimpleMap } from "./type";
|
|
5
3
|
export declare enum Blockchain {
|
|
@@ -37,28 +35,10 @@ export declare enum Blockchain {
|
|
|
37
35
|
Agoric = "agoric",
|
|
38
36
|
Sommelier = "sommelier"
|
|
39
37
|
}
|
|
40
|
-
export declare type BlockchainV2 = ReturnType<TokenClient['getAllBlockchainNames']>[number] | "Native" | "Carbon" | "Tradehub" | "Ibc" | "Polynetwork";
|
|
41
|
-
export declare const BLOCKCHAIN_V2_TO_V1_MAPPING: SimpleMap<Blockchain>;
|
|
42
38
|
export declare const BRIDGE_IDS: {
|
|
43
39
|
polynetwork: number;
|
|
44
40
|
ibc: number;
|
|
45
41
|
};
|
|
46
|
-
export interface PolyNetworkBridge extends Bridge {
|
|
47
|
-
isEvmChain: boolean;
|
|
48
|
-
}
|
|
49
|
-
export interface IbcBridge extends Bridge {
|
|
50
|
-
chain_id_name: string;
|
|
51
|
-
channels: {
|
|
52
|
-
src_channel: string;
|
|
53
|
-
dst_channel: string;
|
|
54
|
-
port_id: string;
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
export declare function isIbcBridge(object: Bridge): object is IbcBridge;
|
|
58
|
-
export interface BridgeMap {
|
|
59
|
-
polynetwork: PolyNetworkBridge[];
|
|
60
|
-
ibc: IbcBridge[];
|
|
61
|
-
}
|
|
62
42
|
export declare type ChainIds = SimpleMap<number>;
|
|
63
43
|
export declare const ChainNames: {
|
|
64
44
|
readonly 1: "MainNet";
|
|
@@ -84,9 +64,3 @@ export declare function parseBlockchain(value: string | null): Blockchain | null
|
|
|
84
64
|
export declare function getChainFromID(id: number): string | undefined;
|
|
85
65
|
export declare const getBlockchainFromChain: (chainId?: number | undefined) => Blockchain.Ethereum | Blockchain.BinanceSmartChain | Blockchain.Zilliqa | Blockchain.Arbitrum | Blockchain.Polygon | Blockchain.Okc | undefined;
|
|
86
66
|
export declare const blockchainForChainId: (chainId?: number | undefined, network?: Network) => Blockchain | undefined;
|
|
87
|
-
export declare const getBlockchainFromChainV2: (chainId?: number | undefined) => "Ethereum" | "Binance Smart Chain" | "Arbitrum" | "Polygon" | "Okc" | "Zilliqa" | undefined;
|
|
88
|
-
export declare const blockchainForChainIdV2: (chainId?: number | undefined, network?: Network) => Blockchain | BlockchainV2 | undefined;
|
|
89
|
-
declare const evmChains: readonly ["Ethereum", "Binance Smart Chain", "Arbitrum", "Polygon", "OKC"];
|
|
90
|
-
export declare type EVMChain = (typeof evmChains)[number];
|
|
91
|
-
export declare const isEvmChain: (chain: string) => chain is "Ethereum" | "Binance Smart Chain" | "Arbitrum" | "Polygon" | "OKC";
|
|
92
|
-
export {};
|
package/lib/util/blockchain.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.blockchainForChainId = exports.getBlockchainFromChain = exports.getChainFromID = exports.parseBlockchain = exports.chainIdsByBlockchain = exports.CHAIN_IDS_TEST = exports.CHAIN_IDS_DEV = exports.CHAIN_IDS = exports.ChainNames = exports.BRIDGE_IDS = exports.Blockchain = void 0;
|
|
4
4
|
const network_1 = require("../constant/network");
|
|
5
5
|
var Blockchain;
|
|
6
6
|
(function (Blockchain) {
|
|
@@ -38,24 +38,10 @@ var Blockchain;
|
|
|
38
38
|
Blockchain["Agoric"] = "agoric";
|
|
39
39
|
Blockchain["Sommelier"] = "sommelier";
|
|
40
40
|
})(Blockchain = exports.Blockchain || (exports.Blockchain = {}));
|
|
41
|
-
exports.BLOCKCHAIN_V2_TO_V1_MAPPING = {
|
|
42
|
-
"Binance Smart Chain": Blockchain.BinanceSmartChain,
|
|
43
|
-
"Ethereum": Blockchain.Ethereum,
|
|
44
|
-
"Arbitrum": Blockchain.Arbitrum,
|
|
45
|
-
"Polygon": Blockchain.Polygon,
|
|
46
|
-
"OKC": Blockchain.Okc,
|
|
47
|
-
"Zilliqa": Blockchain.Zilliqa,
|
|
48
|
-
"Neo": Blockchain.Neo,
|
|
49
|
-
"Neo3": Blockchain.Neo3
|
|
50
|
-
};
|
|
51
41
|
exports.BRIDGE_IDS = {
|
|
52
42
|
polynetwork: 1,
|
|
53
43
|
ibc: 2,
|
|
54
44
|
};
|
|
55
|
-
function isIbcBridge(object) {
|
|
56
|
-
return Object.prototype.hasOwnProperty.call(object, "chain_id_name");
|
|
57
|
-
}
|
|
58
|
-
exports.isIbcBridge = isIbcBridge;
|
|
59
45
|
exports.ChainNames = {
|
|
60
46
|
1: "MainNet",
|
|
61
47
|
3: "Ropsten",
|
|
@@ -274,148 +260,3 @@ const blockchainForChainId = (chainId, network = network_1.Network.MainNet) => {
|
|
|
274
260
|
}
|
|
275
261
|
};
|
|
276
262
|
exports.blockchainForChainId = blockchainForChainId;
|
|
277
|
-
const getBlockchainFromChainV2 = (chainId) => {
|
|
278
|
-
switch (chainId) {
|
|
279
|
-
case 1:
|
|
280
|
-
case 3:
|
|
281
|
-
case 4:
|
|
282
|
-
case 5:
|
|
283
|
-
return 'Ethereum';
|
|
284
|
-
case 56:
|
|
285
|
-
case 97:
|
|
286
|
-
return 'Binance Smart Chain';
|
|
287
|
-
case 65:
|
|
288
|
-
case 66:
|
|
289
|
-
return 'Okc';
|
|
290
|
-
case 137:
|
|
291
|
-
case 80001:
|
|
292
|
-
return 'Polygon';
|
|
293
|
-
case 110:
|
|
294
|
-
case 111:
|
|
295
|
-
return 'Zilliqa';
|
|
296
|
-
case 42161:
|
|
297
|
-
case 421611:
|
|
298
|
-
return 'Arbitrum';
|
|
299
|
-
}
|
|
300
|
-
return undefined;
|
|
301
|
-
};
|
|
302
|
-
exports.getBlockchainFromChainV2 = getBlockchainFromChainV2;
|
|
303
|
-
const blockchainForChainIdV2 = (chainId, network = network_1.Network.MainNet) => {
|
|
304
|
-
switch (network) {
|
|
305
|
-
case network_1.Network.MainNet:
|
|
306
|
-
switch (chainId) {
|
|
307
|
-
case 0:
|
|
308
|
-
return "Native";
|
|
309
|
-
case 1:
|
|
310
|
-
return "Bitcoin";
|
|
311
|
-
case 2:
|
|
312
|
-
return "Ethereum";
|
|
313
|
-
case 4:
|
|
314
|
-
return "Neo";
|
|
315
|
-
case 6:
|
|
316
|
-
return "Binance Smart Chain";
|
|
317
|
-
case 14:
|
|
318
|
-
return "Neo3";
|
|
319
|
-
case 9: /* FALLTHROUGH */
|
|
320
|
-
case 18:
|
|
321
|
-
return "Zilliqa";
|
|
322
|
-
case 12: /* FALLTHROUGH */
|
|
323
|
-
case 66:
|
|
324
|
-
return 'Okc';
|
|
325
|
-
case 17: /* FALLTHROUGH */
|
|
326
|
-
case 137:
|
|
327
|
-
return 'Polygon';
|
|
328
|
-
case 244:
|
|
329
|
-
return "Osmosis";
|
|
330
|
-
case 13: /* FALLTHROUGH */
|
|
331
|
-
case 245:
|
|
332
|
-
return "Terra Classic";
|
|
333
|
-
case 246:
|
|
334
|
-
return "Cosmos Hub";
|
|
335
|
-
case 5: /* FALLTHROUGH */
|
|
336
|
-
case 247:
|
|
337
|
-
return "Juno";
|
|
338
|
-
case 7: /* FALLTHROUGH */
|
|
339
|
-
case 248:
|
|
340
|
-
return "Evmos";
|
|
341
|
-
case 8: /* FALLTHROUGH */
|
|
342
|
-
case 249:
|
|
343
|
-
return "Axelar";
|
|
344
|
-
case 313:
|
|
345
|
-
return "Stride";
|
|
346
|
-
case 314:
|
|
347
|
-
return "Kujira";
|
|
348
|
-
case 315:
|
|
349
|
-
return "Terra";
|
|
350
|
-
case 316:
|
|
351
|
-
return "Quicksilver";
|
|
352
|
-
case 12: /* FALLTHROUGH */
|
|
353
|
-
case 317:
|
|
354
|
-
return "Comdex";
|
|
355
|
-
case 318:
|
|
356
|
-
return "Stafihub";
|
|
357
|
-
case 15: /* FALLTHROUGH */
|
|
358
|
-
case 319:
|
|
359
|
-
return "Persistence Core";
|
|
360
|
-
case 16: /* FALLTHROUGH */
|
|
361
|
-
case 320:
|
|
362
|
-
return "Stargaze";
|
|
363
|
-
case 321:
|
|
364
|
-
return "Canto";
|
|
365
|
-
case 322:
|
|
366
|
-
return "OmniFlix Hub";
|
|
367
|
-
case 323:
|
|
368
|
-
return "Agoric";
|
|
369
|
-
case 19: /* FALLTHROUGH */
|
|
370
|
-
case 42161:
|
|
371
|
-
return "Arbitrum";
|
|
372
|
-
default:
|
|
373
|
-
return undefined;
|
|
374
|
-
}
|
|
375
|
-
case network_1.Network.TestNet:
|
|
376
|
-
switch (chainId) {
|
|
377
|
-
case 1:
|
|
378
|
-
return "Bitcoin";
|
|
379
|
-
case 0:
|
|
380
|
-
case 5:
|
|
381
|
-
return "Carbon";
|
|
382
|
-
case 79:
|
|
383
|
-
return "Binance Smart Chain";
|
|
384
|
-
case 88:
|
|
385
|
-
return "Neo3";
|
|
386
|
-
case 111:
|
|
387
|
-
return "Zilliqa";
|
|
388
|
-
case 2: /* FALLTHROUGH */
|
|
389
|
-
case 502:
|
|
390
|
-
return "Ethereum";
|
|
391
|
-
default:
|
|
392
|
-
return undefined;
|
|
393
|
-
}
|
|
394
|
-
case network_1.Network.DevNet:
|
|
395
|
-
switch (chainId) {
|
|
396
|
-
case 0:
|
|
397
|
-
return 'Carbon';
|
|
398
|
-
case 1:
|
|
399
|
-
return 'Bitcoin';
|
|
400
|
-
case 2:
|
|
401
|
-
case 350:
|
|
402
|
-
return "Ethereum";
|
|
403
|
-
case 5:
|
|
404
|
-
return "Neo";
|
|
405
|
-
case 79:
|
|
406
|
-
return "Binance Smart Chain";
|
|
407
|
-
case 111:
|
|
408
|
-
return 'Zilliqa';
|
|
409
|
-
default:
|
|
410
|
-
return undefined;
|
|
411
|
-
}
|
|
412
|
-
case network_1.Network.LocalHost:
|
|
413
|
-
return undefined;
|
|
414
|
-
default:
|
|
415
|
-
return undefined;
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
exports.blockchainForChainIdV2 = blockchainForChainIdV2;
|
|
419
|
-
const evmChains = ['Ethereum', 'Binance Smart Chain', 'Arbitrum', 'Polygon', 'OKC'];
|
|
420
|
-
const isEvmChain = (chain) => evmChains.includes(chain);
|
|
421
|
-
exports.isEvmChain = isEvmChain;
|
package/lib/util/ibc.d.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import { ChainInfoExplorerTmRpc, ChainIds, GasPriceStep, AssetListObj } from "../constant";
|
|
2
2
|
import { AppCurrency } from "@keplr-wallet/types";
|
|
3
|
-
import { Blockchain
|
|
3
|
+
import { Blockchain } from "./blockchain";
|
|
4
4
|
import { SimpleMap } from "./type";
|
|
5
5
|
export declare function makeIBCMinimalDenom(sourceChannelId: string, coinMinimalDenom: string): string;
|
|
6
6
|
export declare const EmbedChainInfos: SimpleMap<ChainInfoExplorerTmRpc>;
|
|
7
7
|
export declare const totalAssetObj: AssetListObj;
|
|
8
|
-
export declare const ChainIdBlockchainMapV2: SimpleMap<BlockchainV2>;
|
|
9
8
|
export declare const ChainIdBlockchainMap: SimpleMap<Blockchain>;
|
|
10
|
-
export declare const getIbcChainFromBlockchain: (blockchain:
|
|
11
|
-
export declare const BlockchainMap: SimpleMap<
|
|
9
|
+
export declare const getIbcChainFromBlockchain: (blockchain: Blockchain | undefined) => ChainIds | undefined;
|
|
10
|
+
export declare const BlockchainMap: SimpleMap<Blockchain | undefined>;
|
|
12
11
|
export interface ChainIdOutput {
|
|
13
12
|
identifier: string;
|
|
14
13
|
version: number;
|
|
15
14
|
}
|
|
16
15
|
export declare const parseChainId: (chainId: string) => ChainIdOutput;
|
|
17
16
|
export declare const calculateMaxFee: (gasStep?: GasPriceStep, gas?: number) => number;
|
|
18
|
-
export declare const estimateFeeStep: (gasStep?: GasPriceStep, gas?: number, stepId?: keyof GasPriceStep) => number;
|
|
19
17
|
export declare const isCw20Token: (currency: AppCurrency) => boolean;
|