carbon-js-sdk 0.3.43 → 0.3.45
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 +2 -2
- package/lib/codec/liquiditypool/legacy.d.ts +18 -0
- package/lib/codec/liquiditypool/legacy.js +64 -0
- package/lib/constant/ibc.js +1 -1
- package/lib/provider/amino/types/coin.js +2 -2
- package/lib/provider/keplr/KeplrAccount.d.ts +2 -0
- package/lib/provider/keplr/KeplrAccount.js +37 -8
- package/lib/util/blockchain.js +10 -0
- package/lib/wallet/CarbonWallet.js +2 -2
- package/package.json +1 -1
package/lib/CarbonSDK.js
CHANGED
|
@@ -258,8 +258,8 @@ class CarbonSDK {
|
|
|
258
258
|
return __awaiter(this, void 0, void 0, function* () {
|
|
259
259
|
const chainInfo = yield provider_1.KeplrAccount.getChainInfo(this);
|
|
260
260
|
const chainId = chainInfo.chainId;
|
|
261
|
-
const keplrKey = yield keplr.getKey(chainId);
|
|
262
261
|
yield keplr.experimentalSuggestChain(chainInfo);
|
|
262
|
+
const keplrKey = yield keplr.getKey(chainId);
|
|
263
263
|
yield keplr.enable(chainId);
|
|
264
264
|
const wallet = wallet_1.CarbonWallet.withKeplr(keplr, chainInfo, keplrKey, Object.assign(Object.assign({}, opts), { network: this.network, config: this.configOverride }));
|
|
265
265
|
return this.connect(wallet);
|
|
@@ -269,8 +269,8 @@ class CarbonSDK {
|
|
|
269
269
|
return __awaiter(this, void 0, void 0, function* () {
|
|
270
270
|
const chainId = this.chainId;
|
|
271
271
|
const chainInfo = yield provider_1.LeapAccount.getChainInfo(this);
|
|
272
|
-
const leapKey = yield leap.getKey(chainId);
|
|
273
272
|
yield leap.experimentalSuggestChain(chainInfo);
|
|
273
|
+
const leapKey = yield leap.getKey(chainId);
|
|
274
274
|
yield leap.enable(chainId);
|
|
275
275
|
const wallet = wallet_1.CarbonWallet.withLeap(leap, chainId, leapKey, Object.assign(Object.assign({}, opts), { network: this.network, config: this.configOverride }));
|
|
276
276
|
return this.connect(wallet);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Long from "long";
|
|
2
|
+
import _m0 from "protobufjs/minimal";
|
|
3
|
+
export declare const protobufPackage = "Switcheo.carbon.liquiditypool";
|
|
4
|
+
export interface ParamsV2170 {
|
|
5
|
+
rewardReductionThreshold: Long;
|
|
6
|
+
}
|
|
7
|
+
export declare const ParamsV2170: {
|
|
8
|
+
encode(message: ParamsV2170, writer?: _m0.Writer): _m0.Writer;
|
|
9
|
+
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): ParamsV2170;
|
|
10
|
+
fromJSON(object: any): ParamsV2170;
|
|
11
|
+
toJSON(message: ParamsV2170): unknown;
|
|
12
|
+
fromPartial(object: DeepPartial<ParamsV2170>): ParamsV2170;
|
|
13
|
+
};
|
|
14
|
+
declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
15
|
+
export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
16
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
17
|
+
} : Partial<T>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ParamsV2170 = exports.protobufPackage = void 0;
|
|
7
|
+
/* eslint-disable */
|
|
8
|
+
const long_1 = __importDefault(require("long"));
|
|
9
|
+
const minimal_1 = __importDefault(require("protobufjs/minimal"));
|
|
10
|
+
exports.protobufPackage = "Switcheo.carbon.liquiditypool";
|
|
11
|
+
const baseParamsV2170 = { rewardReductionThreshold: long_1.default.UZERO };
|
|
12
|
+
exports.ParamsV2170 = {
|
|
13
|
+
encode(message, writer = minimal_1.default.Writer.create()) {
|
|
14
|
+
if (!message.rewardReductionThreshold.isZero()) {
|
|
15
|
+
writer.uint32(8).uint64(message.rewardReductionThreshold);
|
|
16
|
+
}
|
|
17
|
+
return writer;
|
|
18
|
+
},
|
|
19
|
+
decode(input, length) {
|
|
20
|
+
const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
|
|
21
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
22
|
+
const message = Object.assign({}, baseParamsV2170);
|
|
23
|
+
while (reader.pos < end) {
|
|
24
|
+
const tag = reader.uint32();
|
|
25
|
+
switch (tag >>> 3) {
|
|
26
|
+
case 1:
|
|
27
|
+
message.rewardReductionThreshold = reader.uint64();
|
|
28
|
+
break;
|
|
29
|
+
default:
|
|
30
|
+
reader.skipType(tag & 7);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return message;
|
|
35
|
+
},
|
|
36
|
+
fromJSON(object) {
|
|
37
|
+
const message = Object.assign({}, baseParamsV2170);
|
|
38
|
+
message.rewardReductionThreshold =
|
|
39
|
+
object.rewardReductionThreshold !== undefined &&
|
|
40
|
+
object.rewardReductionThreshold !== null
|
|
41
|
+
? long_1.default.fromString(object.rewardReductionThreshold)
|
|
42
|
+
: long_1.default.UZERO;
|
|
43
|
+
return message;
|
|
44
|
+
},
|
|
45
|
+
toJSON(message) {
|
|
46
|
+
const obj = {};
|
|
47
|
+
message.rewardReductionThreshold !== undefined &&
|
|
48
|
+
(obj.rewardReductionThreshold = (message.rewardReductionThreshold || long_1.default.UZERO).toString());
|
|
49
|
+
return obj;
|
|
50
|
+
},
|
|
51
|
+
fromPartial(object) {
|
|
52
|
+
const message = Object.assign({}, baseParamsV2170);
|
|
53
|
+
message.rewardReductionThreshold =
|
|
54
|
+
object.rewardReductionThreshold !== undefined &&
|
|
55
|
+
object.rewardReductionThreshold !== null
|
|
56
|
+
? long_1.default.fromValue(object.rewardReductionThreshold)
|
|
57
|
+
: long_1.default.UZERO;
|
|
58
|
+
return message;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
if (minimal_1.default.util.Long !== long_1.default) {
|
|
62
|
+
minimal_1.default.util.Long = long_1.default;
|
|
63
|
+
minimal_1.default.configure();
|
|
64
|
+
}
|
package/lib/constant/ibc.js
CHANGED
|
@@ -661,7 +661,7 @@ exports.EmbedChainInfosInit = {
|
|
|
661
661
|
},
|
|
662
662
|
},
|
|
663
663
|
],
|
|
664
|
-
features: ["ibc-transfer", "ibc-go"],
|
|
664
|
+
features: ["ibc-transfer", "ibc-go", "eth-address-gen", "eth-key-sign"],
|
|
665
665
|
explorerUrlToTx: "https://www.mintscan.io/evmos/txs/{txHash}",
|
|
666
666
|
},
|
|
667
667
|
[ChainIds.Microtick]: {
|
|
@@ -24,8 +24,8 @@ const utils_1 = require("../utils");
|
|
|
24
24
|
const TxTypes = {
|
|
25
25
|
MintToken: "carbon/MsgMintToken",
|
|
26
26
|
Withdraw: "carbon/MsgWithdraw",
|
|
27
|
-
DepositToGroup: "
|
|
28
|
-
WithdrawFromGroup: "
|
|
27
|
+
DepositToGroup: "coin/DepositToGroup",
|
|
28
|
+
WithdrawFromGroup: "coin/WithdrawFromGroup",
|
|
29
29
|
};
|
|
30
30
|
const MsgWithdraw = {
|
|
31
31
|
aminoType: TxTypes.Withdraw,
|
|
@@ -16,6 +16,8 @@ declare class KeplrAccount {
|
|
|
16
16
|
} | undefined;
|
|
17
17
|
};
|
|
18
18
|
static createKeplrSigner(keplr: Keplr, chainInfo: ChainInfo, account: Key): CarbonSigner;
|
|
19
|
+
static queryFeeCurrencies(configProvider: SDKProvider): Promise<FeeCurrency[]>;
|
|
20
|
+
static processCurrencies(feeCurrencies: FeeCurrency[]): AppCurrency[];
|
|
19
21
|
static getChainInfo(configProvider: SDKProvider): Promise<ChainInfo>;
|
|
20
22
|
}
|
|
21
23
|
declare namespace KeplrAccount { }
|
|
@@ -45,14 +45,12 @@ class KeplrAccount {
|
|
|
45
45
|
getAccounts,
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
-
static
|
|
48
|
+
static queryFeeCurrencies(configProvider) {
|
|
49
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const config = configProvider.getConfig();
|
|
51
|
-
const bech32Prefix = config.Bech32Prefix;
|
|
52
|
-
const chainId = yield configProvider.query.chain.getChainId();
|
|
53
|
-
const gasPricesResult = yield configProvider.query.fee.MinGasPriceAll({});
|
|
54
50
|
const tokenClient = configProvider.getTokenClient();
|
|
55
51
|
const coingeckoIdMap = tokenClient.geckoTokenNames;
|
|
52
|
+
// Query minGasPrices from on-chain (for testnet/devnet/localhost)
|
|
53
|
+
const gasPricesResult = yield configProvider.query.fee.MinGasPriceAll({});
|
|
56
54
|
const feeCurrencies = gasPricesResult.minGasPrices.reduce((result, price) => {
|
|
57
55
|
var _a, _b, _c;
|
|
58
56
|
const token = tokenClient.tokenForDenom(price.denom);
|
|
@@ -76,14 +74,45 @@ class KeplrAccount {
|
|
|
76
74
|
});
|
|
77
75
|
return result;
|
|
78
76
|
}, []);
|
|
77
|
+
return feeCurrencies;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
static processCurrencies(feeCurrencies) {
|
|
81
|
+
return feeCurrencies.reduce((prevCurrencies, feeCurrency) => {
|
|
82
|
+
const currentFeeCurrency = {
|
|
83
|
+
coinDenom: feeCurrency.coinDenom,
|
|
84
|
+
coinMinimalDenom: feeCurrency.coinMinimalDenom,
|
|
85
|
+
coinDecimals: feeCurrency.coinDecimals,
|
|
86
|
+
coinGeckoId: feeCurrency.coinGeckoId,
|
|
87
|
+
};
|
|
88
|
+
prevCurrencies.push(currentFeeCurrency);
|
|
89
|
+
return prevCurrencies;
|
|
90
|
+
}, []);
|
|
91
|
+
}
|
|
92
|
+
static getChainInfo(configProvider) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const config = configProvider.getConfig();
|
|
95
|
+
const bech32Prefix = config.Bech32Prefix;
|
|
96
|
+
const chainId = yield configProvider.query.chain.getChainId();
|
|
97
|
+
// Query fee currencies from keplr-chain-registry
|
|
98
|
+
const keplrChainInfo = yield (yield util_1.FetchUtils.fetch("https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/master/cosmos/carbon.json")).json();
|
|
99
|
+
if (config.network === constant_1.Network.MainNet) {
|
|
100
|
+
if (keplrChainInfo.nodeProvider) {
|
|
101
|
+
delete keplrChainInfo.nodeProvider;
|
|
102
|
+
}
|
|
103
|
+
return keplrChainInfo;
|
|
104
|
+
}
|
|
105
|
+
const feeCurrencies = yield this.queryFeeCurrencies(configProvider);
|
|
106
|
+
const networkFees = [KeplrAccount.SWTH_CURRENCY, ...feeCurrencies];
|
|
107
|
+
const currencies = this.processCurrencies(networkFees);
|
|
79
108
|
return {
|
|
80
|
-
feeCurrencies:
|
|
109
|
+
feeCurrencies: networkFees,
|
|
81
110
|
bip44: KeplrAccount.BASE_CHAIN_INFO.bip44,
|
|
82
|
-
currencies:
|
|
111
|
+
currencies: currencies,
|
|
83
112
|
stakeCurrency: KeplrAccount.SWTH_CURRENCY,
|
|
84
113
|
rest: config.restUrl,
|
|
85
114
|
rpc: config.tmRpcUrl,
|
|
86
|
-
chainName:
|
|
115
|
+
chainName: `Carbon (${config.network})`,
|
|
87
116
|
chainId: chainId,
|
|
88
117
|
bech32Config: {
|
|
89
118
|
bech32PrefixAccAddr: `${bech32Prefix}`,
|
package/lib/util/blockchain.js
CHANGED
|
@@ -199,6 +199,7 @@ const blockchainForChainId = (chainId, network = network_1.Network.MainNet) => {
|
|
|
199
199
|
switch (chainId) {
|
|
200
200
|
case 1:
|
|
201
201
|
return Blockchain.Btc;
|
|
202
|
+
case 0:
|
|
202
203
|
case 5:
|
|
203
204
|
return Blockchain.Carbon;
|
|
204
205
|
case 79:
|
|
@@ -215,12 +216,21 @@ const blockchainForChainId = (chainId, network = network_1.Network.MainNet) => {
|
|
|
215
216
|
}
|
|
216
217
|
case network_1.Network.DevNet:
|
|
217
218
|
switch (chainId) {
|
|
219
|
+
case 0:
|
|
220
|
+
return Blockchain.Carbon;
|
|
221
|
+
case 1:
|
|
222
|
+
return Blockchain.Btc;
|
|
223
|
+
case 2:
|
|
218
224
|
case 350:
|
|
219
225
|
return Blockchain.Ethereum;
|
|
220
226
|
case 5:
|
|
221
227
|
return Blockchain.Neo;
|
|
222
228
|
case 79:
|
|
223
229
|
return Blockchain.BinanceSmartChain;
|
|
230
|
+
case 111:
|
|
231
|
+
return Blockchain.Zilliqa;
|
|
232
|
+
default:
|
|
233
|
+
return undefined;
|
|
224
234
|
}
|
|
225
235
|
case network_1.Network.LocalHost:
|
|
226
236
|
return undefined;
|
|
@@ -112,13 +112,13 @@ class CarbonWallet {
|
|
|
112
112
|
static withKeplr(keplr, chainInfo, keplrKey, opts = {}) {
|
|
113
113
|
const signer = provider_1.KeplrAccount.createKeplrSigner(keplr, chainInfo, keplrKey);
|
|
114
114
|
const publicKeyBase64 = Buffer.from(keplrKey.pubKey).toString("base64");
|
|
115
|
-
const wallet = CarbonWallet.withSigner(signer, publicKeyBase64, opts);
|
|
115
|
+
const wallet = CarbonWallet.withSigner(signer, publicKeyBase64, Object.assign(Object.assign({}, opts), { providerAgent: 'keplr-extension' }));
|
|
116
116
|
return wallet;
|
|
117
117
|
}
|
|
118
118
|
static withLeap(leap, chainId, leapKey, opts = {}) {
|
|
119
119
|
const signer = provider_1.LeapAccount.createLeapSigner(leap, chainId);
|
|
120
120
|
const publicKeyBase64 = Buffer.from(leapKey.pubKey).toString("base64");
|
|
121
|
-
const wallet = CarbonWallet.withSigner(signer, publicKeyBase64, opts);
|
|
121
|
+
const wallet = CarbonWallet.withSigner(signer, publicKeyBase64, Object.assign(Object.assign({}, opts), { providerAgent: 'leap-extension' }));
|
|
122
122
|
return wallet;
|
|
123
123
|
}
|
|
124
124
|
static withAddress(bech32Address, opts = {}) {
|