carbon-js-sdk 0.3.38 → 0.3.40
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/clients/CarbonQueryClient.js +2 -2
- package/lib/clients/ETHClient.js +15 -15
- package/lib/clients/HydrogenClient.js +1 -1
- package/lib/clients/NEOClient.js +7 -7
- package/lib/clients/TokenClient.d.ts +3 -1
- package/lib/clients/TokenClient.js +48 -8
- package/lib/clients/ZILClient.js +17 -17
- package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
- package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
- package/lib/codec/cosmos/tx/v1beta1/tx.js +2 -2
- package/lib/constant/generic.js +1 -1
- package/lib/constant/ibc.js +5 -0
- package/lib/modules/cdp.js +43 -43
- package/lib/modules/gov.js +14 -14
- package/lib/modules/liquiditypool.js +1 -1
- package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
- package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
- package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +1 -1
- package/lib/provider/amino/types/admin.js +30 -30
- package/lib/provider/amino/types/bank.js +1 -1
- package/lib/provider/amino/types/broker.js +1 -1
- package/lib/provider/amino/types/cdp.js +22 -22
- package/lib/provider/amino/types/coin.js +2 -2
- package/lib/provider/amino/types/gov.js +4 -4
- package/lib/provider/amino/types/ibc.js +1 -1
- package/lib/provider/amino/types/leverage.js +1 -1
- package/lib/provider/amino/types/liquidityPool.js +7 -7
- package/lib/provider/amino/types/market.js +1 -1
- package/lib/provider/amino/types/oracle.js +1 -1
- package/lib/provider/amino/types/order.js +4 -4
- package/lib/provider/amino/types/position.js +1 -1
- package/lib/provider/amino/types/profile.js +1 -1
- package/lib/provider/amino/types/staking.js +4 -4
- package/lib/provider/amino/types/subaccount.js +3 -3
- package/lib/provider/amino/utils.js +11 -11
- package/lib/provider/ledger/ledger.js +2 -2
- package/lib/provider/metamask/MetaMask.js +1 -1
- package/lib/provider/o3/O3Wallet.js +2 -2
- package/lib/util/address.js +13 -13
- package/lib/util/api.js +4 -4
- package/lib/util/fetch.js +1 -1
- package/lib/util/generic.js +3 -3
- package/lib/util/number.js +5 -5
- package/lib/wallet/CarbonSigner.js +2 -2
- package/lib/wallet/CarbonSigningClient.js +8 -8
- package/lib/wallet/CarbonWallet.js +6 -6
- package/lib/websocket/connector.js +3 -3
- package/package.json +1 -1
|
@@ -44,7 +44,7 @@ class CarbonQueryClient {
|
|
|
44
44
|
constructor(tmClient) {
|
|
45
45
|
this.tmClient = tmClient;
|
|
46
46
|
this.baseClient = new stargate_1.QueryClient(this.tmClient);
|
|
47
|
-
const rpcClient =
|
|
47
|
+
const rpcClient = stargate_1.createProtobufRpcClient(this.baseClient);
|
|
48
48
|
this.chain = BlockchainClient_1.default.connectWithTm(this.tmClient);
|
|
49
49
|
this.adl = new query_1.QueryClientImpl(rpcClient);
|
|
50
50
|
this.book = new query_2.QueryClientImpl(rpcClient);
|
|
@@ -85,7 +85,7 @@ class CarbonQueryClient {
|
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
getProtobufRpcClient() {
|
|
88
|
-
return
|
|
88
|
+
return stargate_1.createProtobufRpcClient(this.baseClient);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
exports.default = CarbonQueryClient;
|
package/lib/clients/ETHClient.js
CHANGED
|
@@ -40,13 +40,13 @@ class ETHClient {
|
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
41
|
const tokenQueryResults = yield api.token.getAllTokens();
|
|
42
42
|
const lockProxyAddress = this.getLockProxyAddress().toLowerCase();
|
|
43
|
-
const tokens = tokenQueryResults.filter((token) =>
|
|
43
|
+
const tokens = tokenQueryResults.filter((token) => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
44
44
|
token.tokenAddress.length == 40 &&
|
|
45
|
-
token.bridgeAddress.toLowerCase() ==
|
|
45
|
+
token.bridgeAddress.toLowerCase() == generic_1.stripHexPrefix(lockProxyAddress) &&
|
|
46
46
|
(!whitelistDenoms || whitelistDenoms.includes(token.denom)) &&
|
|
47
|
-
this.verifyChecksum(
|
|
47
|
+
this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress)));
|
|
48
48
|
const assetIds = tokens.map((token) => {
|
|
49
|
-
return this.verifyChecksum(
|
|
49
|
+
return this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress));
|
|
50
50
|
});
|
|
51
51
|
const provider = this.getProvider();
|
|
52
52
|
const contractAddress = this.getBalanceReaderAddress();
|
|
@@ -95,14 +95,14 @@ class ETHClient {
|
|
|
95
95
|
throw new Error("Invalid recovery address");
|
|
96
96
|
}
|
|
97
97
|
const fromTokenId = fromToken.id;
|
|
98
|
-
const fromTokenAddress =
|
|
98
|
+
const fromTokenAddress = generic_1.appendHexPrefix(fromToken.tokenAddress);
|
|
99
99
|
const toTokenDenom = toToken.denom;
|
|
100
100
|
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(util_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, CarbonSDK_1.default.Network.MainNet));
|
|
101
101
|
const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
|
|
102
102
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
|
|
103
103
|
const nonce = yield rpcProvider.getTransactionCount(fromAddress);
|
|
104
104
|
const contract = new ethers_1.ethers.Contract(this.getBridgeEntranceAddr(), eth_1.ABIs.bridgeEntrance, rpcProvider);
|
|
105
|
-
const feeAddress =
|
|
105
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
106
106
|
const tokenCreator = fromToken.creator;
|
|
107
107
|
const targetAddressBytes = util_1.AddressUtils.SWTHAddress.getAddressBytes(tokenCreator, CarbonSDK_1.default.Network.MainNet);
|
|
108
108
|
const targetProxyHash = ethers_1.ethers.utils.hexlify(targetAddressBytes);
|
|
@@ -137,9 +137,9 @@ class ETHClient {
|
|
|
137
137
|
throw new Error("Minimum gas required: 150,000");
|
|
138
138
|
}
|
|
139
139
|
const networkConfig = this.getNetworkConfig();
|
|
140
|
-
const assetId =
|
|
141
|
-
const targetProxyHash =
|
|
142
|
-
const feeAddress =
|
|
140
|
+
const assetId = generic_1.appendHexPrefix(token.tokenAddress);
|
|
141
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
|
|
142
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
143
143
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
|
|
144
144
|
const swthAddress = ethers_1.ethers.utils.hexlify(address);
|
|
145
145
|
const contractAddress = this.getLockProxyAddress();
|
|
@@ -190,16 +190,16 @@ class ETHClient {
|
|
|
190
190
|
return "insufficient balance";
|
|
191
191
|
}
|
|
192
192
|
const networkConfig = this.getNetworkConfig();
|
|
193
|
-
const assetId =
|
|
194
|
-
const targetProxyHash =
|
|
195
|
-
const feeAddress =
|
|
193
|
+
const assetId = generic_1.appendHexPrefix(tokenWithExternalBalances.tokenAddress);
|
|
194
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(tokenWithExternalBalances));
|
|
195
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
196
196
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(tokenWithExternalBalances.id));
|
|
197
197
|
const nonce = Math.floor(Math.random() * 1000000000); // random nonce to prevent replay attacks
|
|
198
198
|
const message = ethers_1.ethers.utils.solidityKeccak256(["string", "address", "bytes", "bytes", "bytes", "uint256", "uint256", "uint256"], ["sendTokens", assetId, targetProxyHash, toAssetHash, feeAddress, amount, feeAmount, nonce]);
|
|
199
199
|
// logger("sendDeposit message", message)
|
|
200
200
|
let signatureResult;
|
|
201
201
|
const { address, signature } = yield getSignatureCallback(message);
|
|
202
|
-
const signatureBytes = ethers_1.ethers.utils.arrayify(
|
|
202
|
+
const signatureBytes = ethers_1.ethers.utils.arrayify(generic_1.appendHexPrefix(signature));
|
|
203
203
|
const rsv = ethers_1.ethers.utils.splitSignature(signatureBytes);
|
|
204
204
|
// logger("sign result", address, signature)
|
|
205
205
|
signatureResult = {
|
|
@@ -238,7 +238,7 @@ class ETHClient {
|
|
|
238
238
|
if (!feeInfo.deposit_fee) {
|
|
239
239
|
throw new Error("unsupported token");
|
|
240
240
|
}
|
|
241
|
-
if (
|
|
241
|
+
if (blockchain_1.blockchainForChainId(token.chainId.toNumber()) !== this.blockchain) {
|
|
242
242
|
throw new Error("unsupported token");
|
|
243
243
|
}
|
|
244
244
|
let feeAmount = ethers_1.ethers.BigNumber.from(feeInfo.deposit_fee);
|
|
@@ -304,7 +304,7 @@ class ETHClient {
|
|
|
304
304
|
getTargetProxyHash(token) {
|
|
305
305
|
const networkConfig = this.getNetworkConfig();
|
|
306
306
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
307
|
-
const addressHex =
|
|
307
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
308
308
|
return addressHex;
|
|
309
309
|
}
|
|
310
310
|
getProvider() {
|
|
@@ -29,7 +29,7 @@ exports.HydrogenEndpoints = {
|
|
|
29
29
|
const formatDateField = (value) => {
|
|
30
30
|
if (typeof value !== "string")
|
|
31
31
|
return null;
|
|
32
|
-
return
|
|
32
|
+
return dayjs_1.default(value);
|
|
33
33
|
};
|
|
34
34
|
const formatCrossChainTransfer = (value) => {
|
|
35
35
|
var _a, _b;
|
package/lib/clients/NEOClient.js
CHANGED
|
@@ -64,13 +64,13 @@ class NEOClient {
|
|
|
64
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
65
|
const tokenQueryResults = yield sdk.token.getAllTokens();
|
|
66
66
|
const account = new Neon.wallet.Account(address);
|
|
67
|
-
const tokens = tokenQueryResults.filter((token) =>
|
|
67
|
+
const tokens = tokenQueryResults.filter((token) => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
68
68
|
token.tokenAddress.length == 40 &&
|
|
69
69
|
token.bridgeAddress.length == 40);
|
|
70
70
|
const client = new Neon.rpc.RPCClient(url, "2.5.2"); // TODO: should we change the RPC version??
|
|
71
71
|
// NOTE: fetching of tokens is chunked in sets of 15 as we may hit
|
|
72
72
|
// the gas limit on the RPC node and error out otherwise
|
|
73
|
-
const promises =
|
|
73
|
+
const promises = lodash_1.chunk(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
|
|
74
74
|
var _a, _b, _c;
|
|
75
75
|
let acc = {};
|
|
76
76
|
for (const token of partition) {
|
|
@@ -112,8 +112,8 @@ class NEOClient {
|
|
|
112
112
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
113
113
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
114
114
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(swthAddress, networkConfig.network);
|
|
115
|
-
const toAddress =
|
|
116
|
-
const zeroAddressHex =
|
|
115
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
116
|
+
const zeroAddressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(constant_1.ZeroAddress));
|
|
117
117
|
const amount = ethers_1.ethers.BigNumber.from(token.externalBalance);
|
|
118
118
|
const feeAmount = ethers_1.ethers.BigNumber.from(feeAmountInput !== null && feeAmountInput !== void 0 ? feeAmountInput : "100000000");
|
|
119
119
|
const feeAddress = feeAmount.isZero() ? zeroAddressHex : networkConfig.feeAddress;
|
|
@@ -160,7 +160,7 @@ class NEOClient {
|
|
|
160
160
|
const fromAddress = util_1.AddressUtils.NEOAddress.publicKeyToAddress(publicKeyOutput.publicKey);
|
|
161
161
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
162
162
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
163
|
-
const toAddress =
|
|
163
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
164
164
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
165
165
|
if (amount.lt(feeAmount)) {
|
|
166
166
|
throw new Error("Invalid amount");
|
|
@@ -196,7 +196,7 @@ class NEOClient {
|
|
|
196
196
|
const fromAddress = ledger.scriptHash;
|
|
197
197
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
198
198
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
199
|
-
const toAddress =
|
|
199
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
200
200
|
const feeAddress = networkConfig.feeAddress;
|
|
201
201
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
202
202
|
if (amount.lt(feeAmount)) {
|
|
@@ -316,7 +316,7 @@ class NEOClient {
|
|
|
316
316
|
getTargetProxyHash(token) {
|
|
317
317
|
const networkConfig = this.getNetworkConfig();
|
|
318
318
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
319
|
-
const addressHex =
|
|
319
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
320
320
|
return addressHex;
|
|
321
321
|
}
|
|
322
322
|
getNetworkConfig() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Token } from "../codec";
|
|
1
|
+
import { Token, TokenPrice } from "../codec";
|
|
2
2
|
import { NetworkConfigProvider } from "../constant";
|
|
3
3
|
import { FeeQuote } from "../hydrogen/feeQuote";
|
|
4
4
|
import { BlockchainUtils, TypeUtils } from "../util";
|
|
@@ -57,6 +57,8 @@ declare class TokenClient {
|
|
|
57
57
|
reloadDenomGeckoMap(): Promise<void>;
|
|
58
58
|
reloadUSDValues(denoms?: string[]): Promise<TypeUtils.SimpleMap<BigNumber>>;
|
|
59
59
|
getUSDValuesFromCoinGecko(geckoIds: string[]): Promise<any>;
|
|
60
|
+
processTokenPrices(tokenPrices: TokenPrice[]): TypeUtils.SimpleMap<BigNumber>;
|
|
61
|
+
getUSDValuesFromPricingModule(): Promise<TypeUtils.SimpleMap<BigNumber>>;
|
|
60
62
|
getDenomToGeckoIdMap(): Promise<TypeUtils.SimpleMap<string>>;
|
|
61
63
|
setCommonAssetConfig(): void;
|
|
62
64
|
}
|
|
@@ -415,25 +415,30 @@ class TokenClient {
|
|
|
415
415
|
this.usdValues.iusd = number_1.BN_ONE;
|
|
416
416
|
//Get corresponding geckoId for denoms and removes any duplicated geckoIds (espeically for different wrapped tokens as they correspond to the same geckoId(same price))
|
|
417
417
|
const geckoIds = denoms.reduce((coinIds, denom) => {
|
|
418
|
-
|
|
419
|
-
const geckoId =
|
|
418
|
+
// To ensure that ibc denoms are not added to the gecko ids list, the default is removed.
|
|
419
|
+
const geckoId = this.geckoTokenNames[denom];
|
|
420
420
|
if (geckoId && !coinIds.includes(geckoId)) {
|
|
421
421
|
coinIds.push(geckoId);
|
|
422
422
|
}
|
|
423
423
|
return coinIds;
|
|
424
424
|
}, []);
|
|
425
425
|
const geckoIdToUsdPriceMap = yield this.getUSDValuesFromCoinGecko(geckoIds);
|
|
426
|
+
const carbonTokenPrices = yield this.getUSDValuesFromPricingModule();
|
|
426
427
|
const uscStablecoin = this.getNativeStablecoin();
|
|
427
428
|
//store price based on denoms
|
|
428
429
|
for (const denom of denoms) {
|
|
430
|
+
const carbonTokenPrice = carbonTokenPrices[denom];
|
|
431
|
+
// if token price in pricing module exists for denom, return that as usd price first
|
|
432
|
+
// else check coingecko
|
|
433
|
+
if (carbonTokenPrice) {
|
|
434
|
+
this.usdValues[denom] = carbonTokenPrice;
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
429
437
|
const coinId = (_a = this.geckoTokenNames[denom]) !== null && _a !== void 0 ? _a : denom;
|
|
430
438
|
const price = util_1.NumberUtils.bnOrZero((_b = geckoIdToUsdPriceMap === null || geckoIdToUsdPriceMap === void 0 ? void 0 : geckoIdToUsdPriceMap[coinId]) === null || _b === void 0 ? void 0 : _b.usd);
|
|
431
439
|
if (price.gt(0)) {
|
|
432
|
-
if
|
|
433
|
-
|
|
434
|
-
continue;
|
|
435
|
-
}
|
|
436
|
-
this.usdValues[denom] = price;
|
|
440
|
+
// if denom is usc, then return uscUsdValue, else return coingecko usd price
|
|
441
|
+
this.usdValues[denom] = denom === (uscStablecoin === null || uscStablecoin === void 0 ? void 0 : uscStablecoin.denom) ? constant_1.uscUsdValue : price;
|
|
437
442
|
}
|
|
438
443
|
}
|
|
439
444
|
return this.usdValues;
|
|
@@ -441,10 +446,45 @@ class TokenClient {
|
|
|
441
446
|
}
|
|
442
447
|
getUSDValuesFromCoinGecko(geckoIds) {
|
|
443
448
|
return __awaiter(this, void 0, void 0, function* () {
|
|
444
|
-
const response = yield util_1.FetchUtils.fetch(`https://coingecko-proxy.dem.exchange/price?ids=${geckoIds.join(",")}&vs_currencies=usd`);
|
|
449
|
+
const response = yield util_1.FetchUtils.fetch(`https://coingecko-proxy.dem.exchange/api/v3/simple/price?ids=${geckoIds.join(",")}&vs_currencies=usd`);
|
|
445
450
|
return yield response.json();
|
|
446
451
|
});
|
|
447
452
|
}
|
|
453
|
+
processTokenPrices(tokenPrices) {
|
|
454
|
+
return tokenPrices.reduce((prevPrices, price) => {
|
|
455
|
+
const newPrev = prevPrices;
|
|
456
|
+
newPrev[price.denom] = number_1.bnOrZero(price.twap).shiftedBy(-constant_1.decTypeDecimals);
|
|
457
|
+
return newPrev;
|
|
458
|
+
}, {});
|
|
459
|
+
}
|
|
460
|
+
getUSDValuesFromPricingModule() {
|
|
461
|
+
var _a, _b, _c, _d;
|
|
462
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
463
|
+
const initTokenPrices = yield this.query.pricing.TokenPriceAll({
|
|
464
|
+
pagination: {
|
|
465
|
+
limit: new long_1.default(10000),
|
|
466
|
+
offset: new long_1.default(0),
|
|
467
|
+
key: new Uint8Array(),
|
|
468
|
+
countTotal: true,
|
|
469
|
+
reverse: false,
|
|
470
|
+
},
|
|
471
|
+
});
|
|
472
|
+
if (((_a = initTokenPrices.pagination) === null || _a === void 0 ? void 0 : _a.total) && ((_b = initTokenPrices.pagination) === null || _b === void 0 ? void 0 : _b.total.lt(10000))) {
|
|
473
|
+
const tokenPricesMap = this.processTokenPrices(initTokenPrices.tokenPrices);
|
|
474
|
+
return tokenPricesMap;
|
|
475
|
+
}
|
|
476
|
+
const fullTokenPrices = yield this.query.pricing.TokenPriceAll({
|
|
477
|
+
pagination: {
|
|
478
|
+
limit: (_d = (_c = initTokenPrices.pagination) === null || _c === void 0 ? void 0 : _c.total) !== null && _d !== void 0 ? _d : new long_1.default(0),
|
|
479
|
+
offset: new long_1.default(0),
|
|
480
|
+
key: new Uint8Array(),
|
|
481
|
+
countTotal: true,
|
|
482
|
+
reverse: false,
|
|
483
|
+
},
|
|
484
|
+
});
|
|
485
|
+
return this.processTokenPrices(fullTokenPrices.tokenPrices);
|
|
486
|
+
});
|
|
487
|
+
}
|
|
448
488
|
getDenomToGeckoIdMap() {
|
|
449
489
|
var _a;
|
|
450
490
|
return __awaiter(this, void 0, void 0, function* () {
|
package/lib/clients/ZILClient.js
CHANGED
|
@@ -73,12 +73,12 @@ class ZILClient {
|
|
|
73
73
|
getExternalBalances(sdk, address, whitelistDenoms) {
|
|
74
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
75
|
const tokenQueryResults = yield sdk.token.getAllTokens();
|
|
76
|
-
const tokens = tokenQueryResults.filter((token) =>
|
|
76
|
+
const tokens = tokenQueryResults.filter((token) => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
77
77
|
token.tokenAddress.length == 40 &&
|
|
78
78
|
(!whitelistDenoms || whitelistDenoms.includes(token.denom)));
|
|
79
79
|
const requests = tokens.map((token) => token.tokenAddress === zeroAddress
|
|
80
|
-
?
|
|
81
|
-
:
|
|
80
|
+
? exports.balanceBatchRequest(address.replace(/^0x/i, ""))
|
|
81
|
+
: exports.tokenBalanceBatchRequest(token.tokenAddress, address));
|
|
82
82
|
const response = yield fetch(this.getProviderUrl(), {
|
|
83
83
|
method: "post",
|
|
84
84
|
headers: { "content-type": "application/json" },
|
|
@@ -103,7 +103,7 @@ class ZILClient {
|
|
|
103
103
|
// if (!isValidAddress) {
|
|
104
104
|
// throw new Error("invalid address")
|
|
105
105
|
// }
|
|
106
|
-
return
|
|
106
|
+
return zilliqa_1.fromBech32Address(bech32Address).toLowerCase().substr(2);
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
// see examplesV2/zil_client.ts on how to confirm the transactions
|
|
@@ -149,7 +149,7 @@ class ZILClient {
|
|
|
149
149
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
150
150
|
}
|
|
151
151
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
152
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(
|
|
152
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
|
|
153
153
|
if (balanceAndNonceResp.error !== undefined) {
|
|
154
154
|
throw new Error(balanceAndNonceResp.error.message);
|
|
155
155
|
}
|
|
@@ -167,7 +167,7 @@ class ZILClient {
|
|
|
167
167
|
vname: "spender",
|
|
168
168
|
type: "ByStr20",
|
|
169
169
|
// TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
|
|
170
|
-
value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress :
|
|
170
|
+
value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : generic_1.appendHexPrefix(token.bridgeAddress),
|
|
171
171
|
},
|
|
172
172
|
{
|
|
173
173
|
vname: "amount",
|
|
@@ -185,7 +185,7 @@ class ZILClient {
|
|
|
185
185
|
}
|
|
186
186
|
checkAllowanceZRC2(token, owner, spender) {
|
|
187
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
const contractAddress =
|
|
188
|
+
const contractAddress = generic_1.appendHexPrefix(token.tokenAddress);
|
|
189
189
|
const zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
190
190
|
const resp = yield zilliqa.blockchain.getSmartContractSubState(contractAddress, "allowances", [owner, spender]);
|
|
191
191
|
if (resp.error !== undefined) {
|
|
@@ -205,13 +205,13 @@ class ZILClient {
|
|
|
205
205
|
throw new Error("Invalid recovery address");
|
|
206
206
|
}
|
|
207
207
|
const fromTokenId = fromToken.id;
|
|
208
|
-
const fromTokenAddr =
|
|
208
|
+
const fromTokenAddr = generic_1.appendHexPrefix(fromToken.tokenAddress);
|
|
209
209
|
const toTokenDenom = toToken.denom;
|
|
210
|
-
const targetProxyHash =
|
|
210
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(fromToken));
|
|
211
211
|
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(index_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, CarbonSDK_1.default.Network.MainNet));
|
|
212
212
|
const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
|
|
213
213
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
|
|
214
|
-
const feeAddress =
|
|
214
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
215
215
|
const contractAddress = this.getBridgeEntranceAddr();
|
|
216
216
|
let zilliqa;
|
|
217
217
|
if (typeof signer === "string") {
|
|
@@ -226,7 +226,7 @@ class ZILClient {
|
|
|
226
226
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
227
227
|
}
|
|
228
228
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
229
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(
|
|
229
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(fromAddress));
|
|
230
230
|
if (balanceAndNonceResp.error !== undefined) {
|
|
231
231
|
throw new Error(balanceAndNonceResp.error.message);
|
|
232
232
|
}
|
|
@@ -303,13 +303,13 @@ class ZILClient {
|
|
|
303
303
|
return __awaiter(this, void 0, void 0, function* () {
|
|
304
304
|
const { address, amount, token, gasPrice, gasLimit, zilAddress, signer } = params;
|
|
305
305
|
const networkConfig = this.getNetworkConfig();
|
|
306
|
-
const assetId =
|
|
307
|
-
const targetProxyHash =
|
|
308
|
-
const feeAddress =
|
|
306
|
+
const assetId = generic_1.appendHexPrefix(token.tokenAddress);
|
|
307
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
|
|
308
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
309
309
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
|
|
310
310
|
const swthAddress = ethers_1.ethers.utils.hexlify(address);
|
|
311
311
|
// TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
|
|
312
|
-
const contractAddress =
|
|
312
|
+
const contractAddress = generic_1.appendHexPrefix(token.bridgeAddress);
|
|
313
313
|
let zilliqa;
|
|
314
314
|
if (typeof signer === "string") {
|
|
315
315
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
@@ -323,7 +323,7 @@ class ZILClient {
|
|
|
323
323
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
324
324
|
}
|
|
325
325
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
326
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(
|
|
326
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
|
|
327
327
|
if (balanceAndNonceResp.error !== undefined) {
|
|
328
328
|
throw new Error(balanceAndNonceResp.error.message);
|
|
329
329
|
}
|
|
@@ -408,7 +408,7 @@ class ZILClient {
|
|
|
408
408
|
getTargetProxyHash(token) {
|
|
409
409
|
const networkConfig = this.getNetworkConfig();
|
|
410
410
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
411
|
-
const addressHex =
|
|
411
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
412
412
|
return addressHex;
|
|
413
413
|
}
|
|
414
414
|
getNetworkConfig() {
|
|
@@ -159,7 +159,7 @@ exports.QueryProposalsRequest = {
|
|
|
159
159
|
const message = Object.assign({}, baseQueryProposalsRequest);
|
|
160
160
|
message.proposalStatus =
|
|
161
161
|
object.proposalStatus !== undefined && object.proposalStatus !== null
|
|
162
|
-
?
|
|
162
|
+
? gov_1.proposalStatusFromJSON(object.proposalStatus)
|
|
163
163
|
: 0;
|
|
164
164
|
message.voter =
|
|
165
165
|
object.voter !== undefined && object.voter !== null
|
|
@@ -178,7 +178,7 @@ exports.QueryProposalsRequest = {
|
|
|
178
178
|
toJSON(message) {
|
|
179
179
|
const obj = {};
|
|
180
180
|
message.proposalStatus !== undefined &&
|
|
181
|
-
(obj.proposalStatus =
|
|
181
|
+
(obj.proposalStatus = gov_1.proposalStatusToJSON(message.proposalStatus));
|
|
182
182
|
message.voter !== undefined && (obj.voter = message.voter);
|
|
183
183
|
message.depositor !== undefined && (obj.depositor = message.depositor);
|
|
184
184
|
message.pagination !== undefined &&
|
|
@@ -185,7 +185,7 @@ exports.MsgVote = {
|
|
|
185
185
|
: "";
|
|
186
186
|
message.option =
|
|
187
187
|
object.option !== undefined && object.option !== null
|
|
188
|
-
?
|
|
188
|
+
? gov_1.voteOptionFromJSON(object.option)
|
|
189
189
|
: 0;
|
|
190
190
|
return message;
|
|
191
191
|
},
|
|
@@ -195,7 +195,7 @@ exports.MsgVote = {
|
|
|
195
195
|
(obj.proposalId = (message.proposalId || long_1.default.UZERO).toString());
|
|
196
196
|
message.voter !== undefined && (obj.voter = message.voter);
|
|
197
197
|
message.option !== undefined &&
|
|
198
|
-
(obj.option =
|
|
198
|
+
(obj.option = gov_1.voteOptionToJSON(message.option));
|
|
199
199
|
return obj;
|
|
200
200
|
},
|
|
201
201
|
fromPartial(object) {
|
|
@@ -618,13 +618,13 @@ exports.ModeInfo_Single = {
|
|
|
618
618
|
const message = Object.assign({}, baseModeInfo_Single);
|
|
619
619
|
message.mode =
|
|
620
620
|
object.mode !== undefined && object.mode !== null
|
|
621
|
-
?
|
|
621
|
+
? signing_1.signModeFromJSON(object.mode)
|
|
622
622
|
: 0;
|
|
623
623
|
return message;
|
|
624
624
|
},
|
|
625
625
|
toJSON(message) {
|
|
626
626
|
const obj = {};
|
|
627
|
-
message.mode !== undefined && (obj.mode =
|
|
627
|
+
message.mode !== undefined && (obj.mode = signing_1.signModeToJSON(message.mode));
|
|
628
628
|
return obj;
|
|
629
629
|
},
|
|
630
630
|
fromPartial(object) {
|
package/lib/constant/generic.js
CHANGED
|
@@ -12,7 +12,7 @@ exports.DEFAULT_FEE_DENOM = "swth";
|
|
|
12
12
|
exports.DEFAULT_GAS_PRICE = new bignumber_js_1.default(10);
|
|
13
13
|
exports.DEFAULT_GAS = new bignumber_js_1.default(10000000);
|
|
14
14
|
exports.DEFAULT_FEE = {
|
|
15
|
-
amount:
|
|
15
|
+
amount: proto_signing_1.coins(exports.DEFAULT_GAS_PRICE.times(exports.DEFAULT_GAS).dp(0).toString(), "swth"),
|
|
16
16
|
gas: exports.DEFAULT_GAS.toString(10),
|
|
17
17
|
};
|
|
18
18
|
exports.CARBON_GAS_PRICE = {
|
package/lib/constant/ibc.js
CHANGED
|
@@ -1660,6 +1660,11 @@ exports.EmbedChainInfosInit = {
|
|
|
1660
1660
|
coinMinimalDenom: "stuluna",
|
|
1661
1661
|
coinDecimals: 6,
|
|
1662
1662
|
},
|
|
1663
|
+
{
|
|
1664
|
+
"coinDenom": "stEVMOS",
|
|
1665
|
+
"coinMinimalDenom": "staevmos",
|
|
1666
|
+
"coinDecimals": 18
|
|
1667
|
+
},
|
|
1663
1668
|
],
|
|
1664
1669
|
feeCurrencies: [
|
|
1665
1670
|
{
|