carbon-js-sdk 0.2.17 → 0.2.18
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/N3Client.js +3 -2
- package/lib/clients/NEOClient.js +6 -6
- package/lib/clients/ZILClient.js +16 -16
- 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/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 +20 -20
- 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 +4 -4
- 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/keplr/KeplrStore.js +1 -1
- 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/N3Client.js
CHANGED
|
@@ -65,9 +65,10 @@ class N3Client {
|
|
|
65
65
|
continue;
|
|
66
66
|
if (whitelistDenoms && !whitelistDenoms.includes(token.denom))
|
|
67
67
|
continue;
|
|
68
|
-
|
|
68
|
+
const tokenScriptHash = neon_core_next_1.u.reverseHex(token.tokenAddress);
|
|
69
|
+
if (!balances[tokenScriptHash])
|
|
69
70
|
continue;
|
|
70
|
-
tokensWithBalance.push(Object.assign(Object.assign({}, token), { externalBalance: balances[
|
|
71
|
+
tokensWithBalance.push(Object.assign(Object.assign({}, token), { externalBalance: balances[tokenScriptHash] }));
|
|
71
72
|
}
|
|
72
73
|
return tokensWithBalance;
|
|
73
74
|
});
|
package/lib/clients/NEOClient.js
CHANGED
|
@@ -63,13 +63,13 @@ class NEOClient {
|
|
|
63
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
64
|
const tokenQueryResults = yield sdk.token.getAllTokens();
|
|
65
65
|
const account = new Neon.wallet.Account(address);
|
|
66
|
-
const tokens = tokenQueryResults.filter(token =>
|
|
66
|
+
const tokens = tokenQueryResults.filter(token => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
67
67
|
token.tokenAddress.length == 40 &&
|
|
68
68
|
token.bridgeAddress.length == 40);
|
|
69
69
|
const client = new Neon.rpc.RPCClient(url, "2.5.2"); // TODO: should we change the RPC version??
|
|
70
70
|
// NOTE: fetching of tokens is chunked in sets of 15 as we may hit
|
|
71
71
|
// the gas limit on the RPC node and error out otherwise
|
|
72
|
-
const promises =
|
|
72
|
+
const promises = lodash_1.chunk(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
|
|
73
73
|
var _a, _b, _c;
|
|
74
74
|
let acc = {};
|
|
75
75
|
for (const token of partition) {
|
|
@@ -110,7 +110,7 @@ class NEOClient {
|
|
|
110
110
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
111
111
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
112
112
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(swthAddress, networkConfig.network);
|
|
113
|
-
const toAddress =
|
|
113
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
114
114
|
const amount = ethers_1.ethers.BigNumber.from(token.externalBalance);
|
|
115
115
|
const feeAmount = ethers_1.ethers.BigNumber.from(feeAmountInput !== null && feeAmountInput !== void 0 ? feeAmountInput : "100000000");
|
|
116
116
|
const feeAddress = networkConfig.feeAddress;
|
|
@@ -157,7 +157,7 @@ class NEOClient {
|
|
|
157
157
|
const fromAddress = util_1.AddressUtils.NEOAddress.publicKeyToAddress(publicKeyOutput.publicKey);
|
|
158
158
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
159
159
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
160
|
-
const toAddress =
|
|
160
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
161
161
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
162
162
|
if (amount.lt(feeAmount)) {
|
|
163
163
|
throw new Error("Invalid amount");
|
|
@@ -193,7 +193,7 @@ class NEOClient {
|
|
|
193
193
|
const fromAddress = ledger.scriptHash;
|
|
194
194
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
195
195
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
196
|
-
const toAddress =
|
|
196
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
197
197
|
const feeAddress = networkConfig.feeAddress;
|
|
198
198
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
199
199
|
if (amount.lt(feeAmount)) {
|
|
@@ -313,7 +313,7 @@ class NEOClient {
|
|
|
313
313
|
getTargetProxyHash(token) {
|
|
314
314
|
const networkConfig = this.getNetworkConfig();
|
|
315
315
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
316
|
-
const addressHex =
|
|
316
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
317
317
|
return addressHex;
|
|
318
318
|
}
|
|
319
319
|
getNetworkConfig() {
|
package/lib/clients/ZILClient.js
CHANGED
|
@@ -74,10 +74,10 @@ class ZILClient {
|
|
|
74
74
|
getExternalBalances(sdk, address, whitelistDenoms) {
|
|
75
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
76
|
const tokenQueryResults = yield sdk.token.getAllTokens();
|
|
77
|
-
const tokens = tokenQueryResults.filter(token =>
|
|
77
|
+
const tokens = tokenQueryResults.filter(token => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
78
78
|
token.tokenAddress.length == 40 &&
|
|
79
79
|
(!whitelistDenoms || whitelistDenoms.includes(token.denom)));
|
|
80
|
-
const requests = tokens.map(token => token.tokenAddress === zeroAddress ?
|
|
80
|
+
const requests = tokens.map(token => token.tokenAddress === zeroAddress ? exports.balanceBatchRequest(address.replace(/^0x/i, "")) : exports.tokenBalanceBatchRequest(token.tokenAddress, address));
|
|
81
81
|
const response = yield fetch(this.getProviderUrl(), {
|
|
82
82
|
method: "post",
|
|
83
83
|
headers: { "content-type": "application/json" },
|
|
@@ -102,7 +102,7 @@ class ZILClient {
|
|
|
102
102
|
// if (!isValidAddress) {
|
|
103
103
|
// throw new Error("invalid address")
|
|
104
104
|
// }
|
|
105
|
-
return
|
|
105
|
+
return zilliqa_1.fromBech32Address(bech32Address).toLowerCase().substr(2);
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
// see examplesV2/zil_client.ts on how to confirm the transactions
|
|
@@ -148,7 +148,7 @@ class ZILClient {
|
|
|
148
148
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
149
149
|
}
|
|
150
150
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
151
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(
|
|
151
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
|
|
152
152
|
if (balanceAndNonceResp.error !== undefined) {
|
|
153
153
|
throw new Error(balanceAndNonceResp.error.message);
|
|
154
154
|
}
|
|
@@ -166,7 +166,7 @@ class ZILClient {
|
|
|
166
166
|
vname: 'spender',
|
|
167
167
|
type: 'ByStr20',
|
|
168
168
|
// TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
|
|
169
|
-
value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress :
|
|
169
|
+
value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : generic_1.appendHexPrefix(token.bridgeAddress),
|
|
170
170
|
},
|
|
171
171
|
{
|
|
172
172
|
vname: 'amount',
|
|
@@ -184,7 +184,7 @@ class ZILClient {
|
|
|
184
184
|
}
|
|
185
185
|
checkAllowanceZRC2(token, owner, spender) {
|
|
186
186
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
-
const contractAddress =
|
|
187
|
+
const contractAddress = generic_1.appendHexPrefix(token.tokenAddress);
|
|
188
188
|
const zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
189
189
|
const resp = yield zilliqa.blockchain.getSmartContractSubState(contractAddress, "allowances", [owner, spender]);
|
|
190
190
|
if (resp.error !== undefined) {
|
|
@@ -204,13 +204,13 @@ class ZILClient {
|
|
|
204
204
|
throw new Error("Invalid recovery address");
|
|
205
205
|
}
|
|
206
206
|
const fromTokenId = fromToken.id;
|
|
207
|
-
const fromTokenAddr =
|
|
207
|
+
const fromTokenAddr = generic_1.appendHexPrefix(fromToken.tokenAddress);
|
|
208
208
|
const toTokenDenom = toToken.denom;
|
|
209
|
-
const targetProxyHash =
|
|
209
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(fromToken));
|
|
210
210
|
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(index_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, CarbonSDK_1.default.Network.MainNet));
|
|
211
211
|
const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
|
|
212
212
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
|
|
213
|
-
const feeAddress =
|
|
213
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
214
214
|
const contractAddress = this.getBridgeEntranceAddr();
|
|
215
215
|
let zilliqa;
|
|
216
216
|
if (typeof signer === 'string') {
|
|
@@ -225,7 +225,7 @@ class ZILClient {
|
|
|
225
225
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
226
226
|
}
|
|
227
227
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
228
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(
|
|
228
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(fromAddress));
|
|
229
229
|
if (balanceAndNonceResp.error !== undefined) {
|
|
230
230
|
throw new Error(balanceAndNonceResp.error.message);
|
|
231
231
|
}
|
|
@@ -302,13 +302,13 @@ class ZILClient {
|
|
|
302
302
|
return __awaiter(this, void 0, void 0, function* () {
|
|
303
303
|
const { address, amount, token, gasPrice, gasLimit, zilAddress, signer } = params;
|
|
304
304
|
const networkConfig = this.getNetworkConfig();
|
|
305
|
-
const assetId =
|
|
306
|
-
const targetProxyHash =
|
|
307
|
-
const feeAddress =
|
|
305
|
+
const assetId = generic_1.appendHexPrefix(token.tokenAddress);
|
|
306
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
|
|
307
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
308
308
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
|
|
309
309
|
const swthAddress = ethers_1.ethers.utils.hexlify(address);
|
|
310
310
|
// TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
|
|
311
|
-
const contractAddress =
|
|
311
|
+
const contractAddress = generic_1.appendHexPrefix(token.bridgeAddress);
|
|
312
312
|
let zilliqa;
|
|
313
313
|
if (typeof signer === 'string') {
|
|
314
314
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
@@ -322,7 +322,7 @@ class ZILClient {
|
|
|
322
322
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
323
323
|
}
|
|
324
324
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
325
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(
|
|
325
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
|
|
326
326
|
if (balanceAndNonceResp.error !== undefined) {
|
|
327
327
|
throw new Error(balanceAndNonceResp.error.message);
|
|
328
328
|
}
|
|
@@ -407,7 +407,7 @@ class ZILClient {
|
|
|
407
407
|
getTargetProxyHash(token) {
|
|
408
408
|
const networkConfig = this.getNetworkConfig();
|
|
409
409
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
410
|
-
const addressHex =
|
|
410
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
411
411
|
return addressHex;
|
|
412
412
|
}
|
|
413
413
|
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.CURRENT_GAS_PRICE = 769.23077;
|
package/lib/modules/gov.js
CHANGED
|
@@ -48,7 +48,7 @@ class GovModule extends base_1.default {
|
|
|
48
48
|
const value = tx_1.MsgDeposit.fromPartial({
|
|
49
49
|
proposalId: new long_1.default(params.proposalId),
|
|
50
50
|
depositor: wallet.bech32Address,
|
|
51
|
-
amount:
|
|
51
|
+
amount: amino_1.coins(params.amount, params.denom)
|
|
52
52
|
});
|
|
53
53
|
return yield wallet.sendTx({
|
|
54
54
|
typeUrl: util_1.CarbonTx.Types.MsgDeposit,
|
|
@@ -78,21 +78,21 @@ class GovModule extends base_1.default {
|
|
|
78
78
|
const createTokenMsg = {
|
|
79
79
|
title: title,
|
|
80
80
|
description: description,
|
|
81
|
-
msg:
|
|
81
|
+
msg: admin_1.transfromCreateTokenParams(msg, wallet.bech32Address)
|
|
82
82
|
};
|
|
83
83
|
return proposal_1.CreateTokenProposal.encode(createTokenMsg).finish();
|
|
84
84
|
case "SetMsgGasCostProposal":
|
|
85
85
|
const setMsgGasCostMsg = {
|
|
86
86
|
title: title,
|
|
87
87
|
description: description,
|
|
88
|
-
msg:
|
|
88
|
+
msg: admin_1.transfromSetMsgGasCostParams(msg)
|
|
89
89
|
};
|
|
90
90
|
return proposal_2.SetMsgGasCostProposal.encode(setMsgGasCostMsg).finish();
|
|
91
91
|
case "SetMinGasPriceProposal":
|
|
92
92
|
const setMinGasPriceMsg = {
|
|
93
93
|
title: title,
|
|
94
94
|
description: description,
|
|
95
|
-
msg:
|
|
95
|
+
msg: admin_1.transfromSetMinGasPriceParams(msg)
|
|
96
96
|
};
|
|
97
97
|
return proposal_2.SetMinGasPriceProposal.encode(setMinGasPriceMsg).finish();
|
|
98
98
|
case "RemoveMsgGasCostProposal":
|
|
@@ -113,63 +113,63 @@ class GovModule extends base_1.default {
|
|
|
113
113
|
const linkPoolMsg = {
|
|
114
114
|
title: title,
|
|
115
115
|
description: description,
|
|
116
|
-
msg:
|
|
116
|
+
msg: admin_1.transfromLinkPoolParams(msg)
|
|
117
117
|
};
|
|
118
118
|
return proposal_3.LinkPoolProposal.encode(linkPoolMsg).finish();
|
|
119
119
|
case "UnlinkPoolProposal":
|
|
120
120
|
const unlinkPoolMsg = {
|
|
121
121
|
title: title,
|
|
122
122
|
description: description,
|
|
123
|
-
msg:
|
|
123
|
+
msg: admin_1.transfromUnlinkPoolParams(msg)
|
|
124
124
|
};
|
|
125
125
|
return proposal_3.UnlinkPoolProposal.encode(unlinkPoolMsg).finish();
|
|
126
126
|
case "SetRewardCurveProposal":
|
|
127
127
|
const setRewardCurveMsg = {
|
|
128
128
|
title: title,
|
|
129
129
|
description: description,
|
|
130
|
-
msg:
|
|
130
|
+
msg: admin_1.transfromSetRewardCurveParams(msg)
|
|
131
131
|
};
|
|
132
132
|
return proposal_3.SetRewardCurveProposal.encode(setRewardCurveMsg).finish();
|
|
133
133
|
case "SetCommitmentCurveProposal":
|
|
134
134
|
const setCommitmentCurveMsg = {
|
|
135
135
|
title: title,
|
|
136
136
|
description: description,
|
|
137
|
-
msg:
|
|
137
|
+
msg: admin_1.transfromSetCommitmentCurveParams(msg)
|
|
138
138
|
};
|
|
139
139
|
return proposal_3.SetCommitmentCurveProposal.encode(setCommitmentCurveMsg).finish();
|
|
140
140
|
case "SetRewardsWeightsProposal":
|
|
141
141
|
const setRewardsWeightsMsg = {
|
|
142
142
|
title: title,
|
|
143
143
|
description: description,
|
|
144
|
-
msg:
|
|
144
|
+
msg: admin_1.transfromSetRewardsWeightsParams(msg)
|
|
145
145
|
};
|
|
146
146
|
return proposal_3.SetRewardsWeightsProposal.encode(setRewardsWeightsMsg).finish();
|
|
147
147
|
case "UpdatePoolProposal":
|
|
148
148
|
const updatePoolProposalMsg = {
|
|
149
149
|
title: title,
|
|
150
150
|
description: description,
|
|
151
|
-
msg:
|
|
151
|
+
msg: admin_1.transfromUpdatePoolParams(msg)
|
|
152
152
|
};
|
|
153
153
|
return proposal_3.UpdatePoolProposal.encode(updatePoolProposalMsg).finish();
|
|
154
154
|
case "UpdateMarketProposal":
|
|
155
155
|
const updateMarketProposalMsg = {
|
|
156
156
|
title: title,
|
|
157
157
|
description: description,
|
|
158
|
-
msg:
|
|
158
|
+
msg: market_1.transfromUpdateMarketParams(msg)
|
|
159
159
|
};
|
|
160
160
|
return proposal_4.UpdateMarketProposal.encode(updateMarketProposalMsg).finish();
|
|
161
161
|
case "CreateOracleProposal":
|
|
162
162
|
const createOracleProposalMsg = {
|
|
163
163
|
title: title,
|
|
164
164
|
description: description,
|
|
165
|
-
msg:
|
|
165
|
+
msg: admin_1.transfromCreateOracleParams(msg, wallet.bech32Address)
|
|
166
166
|
};
|
|
167
167
|
return proposal_5.CreateOracleProposal.encode(createOracleProposalMsg).finish();
|
|
168
168
|
case "SettlementPriceProposal":
|
|
169
169
|
const settlementPriceProposalMsg = {
|
|
170
170
|
title: title,
|
|
171
171
|
description: description,
|
|
172
|
-
msg:
|
|
172
|
+
msg: admin_1.transformSetSettlementPriceParams(msg),
|
|
173
173
|
};
|
|
174
174
|
return proposal_6.SettlementPriceProposal.encode(settlementPriceProposalMsg).finish();
|
|
175
175
|
case "ParameterChangeProposal":
|
|
@@ -191,7 +191,7 @@ class GovModule extends base_1.default {
|
|
|
191
191
|
title: title,
|
|
192
192
|
description: description,
|
|
193
193
|
recipient: proposalMsg.recipient,
|
|
194
|
-
amount:
|
|
194
|
+
amount: admin_1.transformCommunityPoolSpendAmount(proposalMsg.amount),
|
|
195
195
|
};
|
|
196
196
|
return distribution_1.CommunityPoolSpendProposal.encode(communityPoolSpendProposalMsg).finish();
|
|
197
197
|
case "CancelSoftwareUpgradeProposal":
|
|
@@ -145,7 +145,7 @@ class LiquidityPoolModule extends base_1.default {
|
|
|
145
145
|
const SECONDS_IN_A_WEEK = new bignumber_js_1.BigNumber(604800);
|
|
146
146
|
const mintDataResponse = yield this.sdkProvider.query.inflation.MintData({});
|
|
147
147
|
const mintData = mintDataResponse.mintData;
|
|
148
|
-
const nowTime = new bignumber_js_1.BigNumber(
|
|
148
|
+
const nowTime = new bignumber_js_1.BigNumber(dayjs_1.default().unix());
|
|
149
149
|
const firstBlockTime = (_a = mintData === null || mintData === void 0 ? void 0 : mintData.firstBlockTime.toNumber()) !== null && _a !== void 0 ? _a : 0;
|
|
150
150
|
const difference = nowTime.minus(firstBlockTime);
|
|
151
151
|
const currentWeek = difference.div(SECONDS_IN_A_WEEK).dp(0, bignumber_js_1.BigNumber.ROUND_DOWN);
|
|
@@ -85,7 +85,7 @@ class EthLedgerAccount {
|
|
|
85
85
|
static tryConnect() {
|
|
86
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
87
|
try {
|
|
88
|
-
const transport = yield
|
|
88
|
+
const transport = yield ledger_1.getLedgerTransport();
|
|
89
89
|
// get public key to assert that NEO app is open
|
|
90
90
|
const ethApp = new hw_app_eth_1.default(transport);
|
|
91
91
|
const bipString = EthLedgerAccount.getETHBIP44String();
|
|
@@ -39,7 +39,7 @@ exports.looksLikeTransportStatusError = looksLikeTransportStatusError;
|
|
|
39
39
|
* @returns error with modified message if found.
|
|
40
40
|
*/
|
|
41
41
|
function evalTransportError(err) {
|
|
42
|
-
const transportErr =
|
|
42
|
+
const transportErr = lodash_1.cloneDeep(err);
|
|
43
43
|
switch (transportErr.statusCode) {
|
|
44
44
|
case StatusWord.APP_CLOSED:
|
|
45
45
|
transportErr.message = "Your NEO app is closed! Please login.";
|
|
@@ -49,8 +49,8 @@ function getAppName(ledger) {
|
|
|
49
49
|
return version.substring(0, version.length - 2); // take of status word
|
|
50
50
|
}
|
|
51
51
|
catch (e) {
|
|
52
|
-
if (
|
|
53
|
-
throw
|
|
52
|
+
if (ErrorCode_1.looksLikeTransportStatusError(e)) {
|
|
53
|
+
throw ErrorCode_1.evalTransportError(e);
|
|
54
54
|
}
|
|
55
55
|
throw e;
|
|
56
56
|
}
|
|
@@ -72,8 +72,8 @@ function getAppVersion(ledger) {
|
|
|
72
72
|
return major.toString() + "." + minor.toString() + "." + patch.toString();
|
|
73
73
|
}
|
|
74
74
|
catch (e) {
|
|
75
|
-
if (
|
|
76
|
-
throw
|
|
75
|
+
if (ErrorCode_1.looksLikeTransportStatusError(e)) {
|
|
76
|
+
throw ErrorCode_1.evalTransportError(e);
|
|
77
77
|
}
|
|
78
78
|
throw e;
|
|
79
79
|
}
|
|
@@ -109,8 +109,8 @@ function getPublicKey(ledger, bip44String, showAddressOnDevice = false) {
|
|
|
109
109
|
return response.toString("hex").substring(0, 130);
|
|
110
110
|
}
|
|
111
111
|
catch (e) {
|
|
112
|
-
if (
|
|
113
|
-
throw
|
|
112
|
+
if (ErrorCode_1.looksLikeTransportStatusError(e)) {
|
|
113
|
+
throw ErrorCode_1.evalTransportError(e);
|
|
114
114
|
}
|
|
115
115
|
throw e;
|
|
116
116
|
}
|
|
@@ -142,8 +142,8 @@ function getSignature(ledger, payload, bip44String, network) {
|
|
|
142
142
|
return DerToHexSignature(response.toString("hex"));
|
|
143
143
|
}
|
|
144
144
|
catch (e) {
|
|
145
|
-
if (
|
|
146
|
-
throw
|
|
145
|
+
if (ErrorCode_1.looksLikeTransportStatusError(e)) {
|
|
146
|
+
throw ErrorCode_1.evalTransportError(e);
|
|
147
147
|
}
|
|
148
148
|
throw e;
|
|
149
149
|
}
|
|
@@ -109,8 +109,8 @@ class NeoLedgerAccount {
|
|
|
109
109
|
*/
|
|
110
110
|
static tryConnect(version = "neo") {
|
|
111
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
const bipString =
|
|
113
|
-
const ledger = yield
|
|
112
|
+
const bipString = NeonLedger_1.getNEOBIP44String();
|
|
113
|
+
const ledger = yield ledger_1.getLedgerTransport();
|
|
114
114
|
// get public key to assert that NEO app is open
|
|
115
115
|
const ledgerAdapter = adapterForVersion(version);
|
|
116
116
|
const publicKey = yield ledgerAdapter.getPublicKey(ledger, bipString);
|
|
@@ -127,7 +127,7 @@ class NeoLedgerAccount {
|
|
|
127
127
|
}
|
|
128
128
|
sign(msg, magic = neon_core_next_1.CONST.MAGIC_NUMBER.MainNet) {
|
|
129
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
const bipString =
|
|
130
|
+
const bipString = NeonLedger_1.getNEOBIP44String();
|
|
131
131
|
const ledger = this.useLedger();
|
|
132
132
|
const ledgerAdapter = adapterForVersion(this.version);
|
|
133
133
|
console.log("getsignature", ledgerAdapter, ledger, msg, bipString, magic);
|
|
@@ -41,7 +41,7 @@ function evalTransportError(err) {
|
|
|
41
41
|
transportErr.message = "Transaction signing denied";
|
|
42
42
|
break;
|
|
43
43
|
default:
|
|
44
|
-
transportErr.message =
|
|
44
|
+
transportErr.message = hw_transport_1.getAltStatusMessage(transportErr.statusCode);
|
|
45
45
|
}
|
|
46
46
|
return err;
|
|
47
47
|
}
|
|
@@ -178,25 +178,25 @@ const MsgEditValidator = {
|
|
|
178
178
|
},
|
|
179
179
|
};
|
|
180
180
|
const AdminAmino = {
|
|
181
|
-
[CarbonTx.Types.MsgCreateOracle]:
|
|
182
|
-
[CarbonTx.Types.MsgBindToken]:
|
|
183
|
-
[CarbonTx.Types.MsgCreateToken]:
|
|
184
|
-
[CarbonTx.Types.MsgLinkToken]:
|
|
185
|
-
[CarbonTx.Types.MsgSyncToken]:
|
|
186
|
-
[CarbonTx.Types.MsgCreateMarket]:
|
|
187
|
-
[CarbonTx.Types.MsgCreateVaultType]:
|
|
188
|
-
[CarbonTx.Types.MsgLinkPool]:
|
|
189
|
-
[CarbonTx.Types.MsgUnlinkPool]:
|
|
190
|
-
[CarbonTx.Types.MsgUpdatePool]:
|
|
191
|
-
[CarbonTx.Types.MsgSetRewardsWeights]:
|
|
192
|
-
[CarbonTx.Types.MsgSetRewardCurve]:
|
|
193
|
-
[CarbonTx.Types.MsgSetCommitmentCurve]:
|
|
194
|
-
[CarbonTx.Types.MsgSetTradingFlag]:
|
|
195
|
-
[CarbonTx.Types.MsgSetGasCost]:
|
|
196
|
-
[CarbonTx.Types.MsgSetMinGasPrice]:
|
|
197
|
-
[CarbonTx.Types.MsgRemoveGasCost]:
|
|
198
|
-
[CarbonTx.Types.MsgRemoveMinGasPrice]:
|
|
199
|
-
[CarbonTx.Types.MsgCreateValidator]:
|
|
200
|
-
[CarbonTx.Types.MsgEditValidator]:
|
|
181
|
+
[CarbonTx.Types.MsgCreateOracle]: utils_1.generateAminoType(MsgCreateOracle),
|
|
182
|
+
[CarbonTx.Types.MsgBindToken]: utils_1.generateAminoType(MsgBindToken),
|
|
183
|
+
[CarbonTx.Types.MsgCreateToken]: utils_1.generateAminoType(MsgCreateToken),
|
|
184
|
+
[CarbonTx.Types.MsgLinkToken]: utils_1.generateAminoType(MsgLinkToken),
|
|
185
|
+
[CarbonTx.Types.MsgSyncToken]: utils_1.generateAminoType(MsgSyncToken),
|
|
186
|
+
[CarbonTx.Types.MsgCreateMarket]: utils_1.generateAminoType(MsgCreateMarket),
|
|
187
|
+
[CarbonTx.Types.MsgCreateVaultType]: utils_1.generateAminoType(MsgCreateVaultType),
|
|
188
|
+
[CarbonTx.Types.MsgLinkPool]: utils_1.generateAminoType(MsgLinkPool),
|
|
189
|
+
[CarbonTx.Types.MsgUnlinkPool]: utils_1.generateAminoType(MsgUnlinkPool),
|
|
190
|
+
[CarbonTx.Types.MsgUpdatePool]: utils_1.generateAminoType(MsgUpdatePool),
|
|
191
|
+
[CarbonTx.Types.MsgSetRewardsWeights]: utils_1.generateAminoType(MsgSetRewardsWeights),
|
|
192
|
+
[CarbonTx.Types.MsgSetRewardCurve]: utils_1.generateAminoType(MsgSetRewardCurve),
|
|
193
|
+
[CarbonTx.Types.MsgSetCommitmentCurve]: utils_1.generateAminoType(MsgSetCommitmentCurve),
|
|
194
|
+
[CarbonTx.Types.MsgSetTradingFlag]: utils_1.generateAminoType(MsgSetTradingFlag),
|
|
195
|
+
[CarbonTx.Types.MsgSetGasCost]: utils_1.generateAminoType(MsgSetGasCost),
|
|
196
|
+
[CarbonTx.Types.MsgSetMinGasPrice]: utils_1.generateAminoType(MsgSetMinGasPrice),
|
|
197
|
+
[CarbonTx.Types.MsgRemoveGasCost]: utils_1.generateAminoType(MsgRemoveGasCost),
|
|
198
|
+
[CarbonTx.Types.MsgRemoveMinGasPrice]: utils_1.generateAminoType(MsgRemoveMinGasPrice),
|
|
199
|
+
[CarbonTx.Types.MsgCreateValidator]: utils_1.generateAminoType(MsgCreateValidator),
|
|
200
|
+
[CarbonTx.Types.MsgEditValidator]: utils_1.generateAminoType(MsgEditValidator),
|
|
201
201
|
};
|
|
202
202
|
exports.default = AdminAmino;
|