carbon-js-sdk 0.4.11 → 0.4.12
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.d.ts +3 -0
- package/lib/clients/ETHClient.js +27 -18
- package/lib/clients/HydrogenClient.js +1 -1
- package/lib/clients/NEOClient.js +7 -7
- package/lib/clients/TokenClient.js +3 -3
- package/lib/clients/ZILClient.js +17 -17
- package/lib/codec/cosmos/gov/v1/query.js +2 -2
- package/lib/codec/cosmos/gov/v1/tx.js +2 -2
- package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
- package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
- package/lib/codec/cosmos/group/v1/events.js +2 -2
- package/lib/codec/cosmos/group/v1/tx.js +4 -4
- package/lib/codec/cosmos/tx/v1beta1/tx.js +4 -4
- package/lib/constant/generic.js +1 -1
- package/lib/modules/cdp.js +43 -43
- package/lib/modules/cosmwasm.js +1 -1
- package/lib/modules/evm.js +6 -6
- package/lib/modules/evmmerge.js +2 -2
- package/lib/modules/gov.js +12 -12
- 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 +27 -27
- 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 +25 -25
- package/lib/provider/amino/types/coin.js +4 -4
- 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 +2 -2
- 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 +10 -6
- 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/ledger.js +2 -1
- 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
|
@@ -47,7 +47,7 @@ class CarbonQueryClient {
|
|
|
47
47
|
constructor(tmClient) {
|
|
48
48
|
this.tmClient = tmClient;
|
|
49
49
|
this.baseClient = new stargate_1.QueryClient(this.tmClient);
|
|
50
|
-
const rpcClient =
|
|
50
|
+
const rpcClient = stargate_1.createProtobufRpcClient(this.baseClient);
|
|
51
51
|
this.chain = BlockchainClient_1.default.connectWithTm(this.tmClient);
|
|
52
52
|
this.adl = new query_1.QueryClientImpl(rpcClient);
|
|
53
53
|
this.book = new query_2.QueryClientImpl(rpcClient);
|
|
@@ -91,7 +91,7 @@ class CarbonQueryClient {
|
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
getProtobufRpcClient() {
|
|
94
|
-
return
|
|
94
|
+
return stargate_1.createProtobufRpcClient(this.baseClient);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
exports.default = CarbonQueryClient;
|
|
@@ -16,6 +16,7 @@ interface ETHTxParams {
|
|
|
16
16
|
gasLimit: BigNumber;
|
|
17
17
|
ethAddress: string;
|
|
18
18
|
signer: ethers.Signer;
|
|
19
|
+
nonce?: number;
|
|
19
20
|
}
|
|
20
21
|
export interface BridgeParams {
|
|
21
22
|
fromToken: Models.Token;
|
|
@@ -29,6 +30,7 @@ export interface BridgeParams {
|
|
|
29
30
|
gasLimit: BigNumber;
|
|
30
31
|
signer: ethers.Signer;
|
|
31
32
|
signCompleteCallback?: () => void;
|
|
33
|
+
nonce?: number;
|
|
32
34
|
}
|
|
33
35
|
export interface LockParams extends ETHTxParams {
|
|
34
36
|
address: Uint8Array;
|
|
@@ -107,5 +109,6 @@ export declare class ETHClient {
|
|
|
107
109
|
* @input address to be verified
|
|
108
110
|
*/
|
|
109
111
|
verifyChecksum(input: string): string | undefined;
|
|
112
|
+
getTxNonce(ethAddress: string, customNonce?: number, provider?: ethers.providers.JsonRpcProvider): Promise<number>;
|
|
110
113
|
}
|
|
111
114
|
export default ETHClient;
|
package/lib/clients/ETHClient.js
CHANGED
|
@@ -44,15 +44,15 @@ class ETHClient {
|
|
|
44
44
|
?
|
|
45
45
|
this.tokenClient.getBlockchainV2(token.denom) == ETHClient.BLOCKCHAINV2_MAPPING[this.blockchain]
|
|
46
46
|
:
|
|
47
|
-
|
|
47
|
+
blockchain_1.blockchainForChainId(token.chainId.toNumber(), api.network) == this.blockchain;
|
|
48
48
|
return isCorrectBlockchain &&
|
|
49
49
|
token.tokenAddress.length == 40 &&
|
|
50
|
-
token.bridgeAddress.toLowerCase() ==
|
|
50
|
+
token.bridgeAddress.toLowerCase() == generic_1.stripHexPrefix(lockProxyAddress) &&
|
|
51
51
|
(!whitelistDenoms || whitelistDenoms.includes(token.denom)) &&
|
|
52
|
-
this.verifyChecksum(
|
|
52
|
+
this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress));
|
|
53
53
|
});
|
|
54
54
|
const assetIds = tokens.map((token) => {
|
|
55
|
-
return this.verifyChecksum(
|
|
55
|
+
return this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress));
|
|
56
56
|
});
|
|
57
57
|
const provider = this.getProvider();
|
|
58
58
|
const contractAddress = this.getBalanceReaderAddress();
|
|
@@ -74,7 +74,7 @@ class ETHClient {
|
|
|
74
74
|
const contractAddress = token.tokenAddress;
|
|
75
75
|
const rpcProvider = this.getProvider();
|
|
76
76
|
const contract = new ethers_1.ethers.Contract(contractAddress, eth_1.ABIs.erc20, rpcProvider);
|
|
77
|
-
const nonce = yield
|
|
77
|
+
const nonce = yield this.getTxNonce(ethAddress, params.nonce, rpcProvider);
|
|
78
78
|
const approveResultTx = yield contract.connect(signer).approve(spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : token.bridgeAddress, ethers_1.ethers.constants.MaxUint256, {
|
|
79
79
|
nonce,
|
|
80
80
|
gasPrice: gasPriceGwei.shiftedBy(9).toString(10),
|
|
@@ -103,14 +103,14 @@ class ETHClient {
|
|
|
103
103
|
}
|
|
104
104
|
const carbonNetwork = networkConfig.network;
|
|
105
105
|
const fromTokenId = fromToken.id;
|
|
106
|
-
const fromTokenAddress =
|
|
106
|
+
const fromTokenAddress = generic_1.appendHexPrefix(fromToken.tokenAddress);
|
|
107
107
|
const toTokenDenom = toToken.denom;
|
|
108
108
|
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(util_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, carbonNetwork));
|
|
109
109
|
const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
|
|
110
110
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
|
|
111
|
-
const nonce = yield
|
|
111
|
+
const nonce = yield this.getTxNonce(fromAddress, params.nonce, rpcProvider);
|
|
112
112
|
const contract = new ethers_1.ethers.Contract(this.getBridgeEntranceAddr(), eth_1.ABIs.bridgeEntrance, rpcProvider);
|
|
113
|
-
const feeAddress =
|
|
113
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
114
114
|
const tokenCreator = fromToken.creator;
|
|
115
115
|
const targetAddressBytes = util_1.AddressUtils.SWTHAddress.getAddressBytes(tokenCreator, carbonNetwork);
|
|
116
116
|
const targetProxyHash = ethers_1.ethers.utils.hexlify(targetAddressBytes);
|
|
@@ -145,14 +145,14 @@ class ETHClient {
|
|
|
145
145
|
throw new Error("Minimum gas required: 150,000");
|
|
146
146
|
}
|
|
147
147
|
const networkConfig = this.getNetworkConfig();
|
|
148
|
-
const assetId =
|
|
149
|
-
const targetProxyHash =
|
|
150
|
-
const feeAddress =
|
|
148
|
+
const assetId = generic_1.appendHexPrefix(token.tokenAddress);
|
|
149
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
|
|
150
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
151
151
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
|
|
152
152
|
const swthAddress = ethers_1.ethers.utils.hexlify(address);
|
|
153
153
|
const contractAddress = this.getLockProxyAddress();
|
|
154
154
|
const rpcProvider = this.getProvider();
|
|
155
|
-
const nonce = yield
|
|
155
|
+
const nonce = yield this.getTxNonce(ethAddress, params.nonce, rpcProvider);
|
|
156
156
|
const contract = new ethers_1.ethers.Contract(contractAddress, eth_1.ABIs.lockProxy, rpcProvider);
|
|
157
157
|
const lockResultTx = yield contract.connect(signer).lock(assetId, // _assetHash
|
|
158
158
|
targetProxyHash, // _targetProxyHash
|
|
@@ -198,16 +198,16 @@ class ETHClient {
|
|
|
198
198
|
return "insufficient balance";
|
|
199
199
|
}
|
|
200
200
|
const networkConfig = this.getNetworkConfig();
|
|
201
|
-
const assetId =
|
|
202
|
-
const targetProxyHash =
|
|
203
|
-
const feeAddress =
|
|
201
|
+
const assetId = generic_1.appendHexPrefix(tokenWithExternalBalances.tokenAddress);
|
|
202
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(tokenWithExternalBalances));
|
|
203
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
204
204
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(tokenWithExternalBalances.id));
|
|
205
205
|
const nonce = Math.floor(Math.random() * 1000000000); // random nonce to prevent replay attacks
|
|
206
206
|
const message = ethers_1.ethers.utils.solidityKeccak256(["string", "address", "bytes", "bytes", "bytes", "uint256", "uint256", "uint256"], ["sendTokens", assetId, targetProxyHash, toAssetHash, feeAddress, amount, feeAmount, nonce]);
|
|
207
207
|
// logger("sendDeposit message", message)
|
|
208
208
|
let signatureResult;
|
|
209
209
|
const { address, signature } = yield getSignatureCallback(message);
|
|
210
|
-
const signatureBytes = ethers_1.ethers.utils.arrayify(
|
|
210
|
+
const signatureBytes = ethers_1.ethers.utils.arrayify(generic_1.appendHexPrefix(signature));
|
|
211
211
|
const rsv = ethers_1.ethers.utils.splitSignature(signatureBytes);
|
|
212
212
|
// logger("sign result", address, signature)
|
|
213
213
|
signatureResult = {
|
|
@@ -246,7 +246,7 @@ class ETHClient {
|
|
|
246
246
|
if (!feeInfo.deposit_fee) {
|
|
247
247
|
throw new Error("unsupported token");
|
|
248
248
|
}
|
|
249
|
-
if (
|
|
249
|
+
if (blockchain_1.blockchainForChainId(token.chainId.toNumber(), this.configProvider.getConfig().network) !== this.blockchain) {
|
|
250
250
|
throw new Error("unsupported token");
|
|
251
251
|
}
|
|
252
252
|
let feeAmount = ethers_1.ethers.BigNumber.from(feeInfo.deposit_fee);
|
|
@@ -312,7 +312,7 @@ class ETHClient {
|
|
|
312
312
|
getTargetProxyHash(token) {
|
|
313
313
|
const networkConfig = this.getNetworkConfig();
|
|
314
314
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
315
|
-
const addressHex =
|
|
315
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
316
316
|
return addressHex;
|
|
317
317
|
}
|
|
318
318
|
getProvider() {
|
|
@@ -355,6 +355,15 @@ class ETHClient {
|
|
|
355
355
|
}
|
|
356
356
|
catch (_a) { }
|
|
357
357
|
}
|
|
358
|
+
getTxNonce(ethAddress, customNonce, provider) {
|
|
359
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
360
|
+
if (customNonce && isFinite(customNonce))
|
|
361
|
+
return customNonce;
|
|
362
|
+
const rpcProvider = provider !== null && provider !== void 0 ? provider : this.getProvider();
|
|
363
|
+
const nonce = yield rpcProvider.getTransactionCount(ethAddress);
|
|
364
|
+
return nonce;
|
|
365
|
+
});
|
|
366
|
+
}
|
|
358
367
|
}
|
|
359
368
|
exports.ETHClient = ETHClient;
|
|
360
369
|
ETHClient.SUPPORTED_BLOCKCHAINS = [blockchain_1.Blockchain.BinanceSmartChain, blockchain_1.Blockchain.Ethereum, blockchain_1.Blockchain.Arbitrum, blockchain_1.Blockchain.Polygon, blockchain_1.Blockchain.Okc];
|
|
@@ -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
|
// temporary function to parse okt/okc blockchain
|
|
35
35
|
// to remove when automatic deposit/withdraw feature is deployed
|
package/lib/clients/NEOClient.js
CHANGED
|
@@ -69,13 +69,13 @@ class NEOClient {
|
|
|
69
69
|
?
|
|
70
70
|
!!sdk.token.getBlockchainV2(token.denom) && (blockchain_1.BLOCKCHAIN_V2_TO_V1_MAPPING[sdk.token.getBlockchainV2(token.denom)] == this.blockchain)
|
|
71
71
|
:
|
|
72
|
-
|
|
72
|
+
blockchain_1.blockchainForChainId(token.chainId.toNumber(), sdk.network) == this.blockchain;
|
|
73
73
|
return (isCorrectBlockchain || token.denom === "swth") && token.tokenAddress.length == 40 && token.bridgeAddress.length == 40;
|
|
74
74
|
});
|
|
75
75
|
const client = new Neon.rpc.RPCClient(url, "2.5.2"); // TODO: should we change the RPC version??
|
|
76
76
|
// NOTE: fetching of tokens is chunked in sets of 15 as we may hit
|
|
77
77
|
// the gas limit on the RPC node and error out otherwise
|
|
78
|
-
const promises =
|
|
78
|
+
const promises = lodash_1.chunk(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
|
|
79
79
|
var _a, _b, _c;
|
|
80
80
|
let acc = {};
|
|
81
81
|
for (const token of partition) {
|
|
@@ -117,8 +117,8 @@ class NEOClient {
|
|
|
117
117
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
118
118
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
119
119
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(swthAddress, networkConfig.network);
|
|
120
|
-
const toAddress =
|
|
121
|
-
const zeroAddressHex =
|
|
120
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
121
|
+
const zeroAddressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(constant_1.ZeroAddress));
|
|
122
122
|
const amount = ethers_1.ethers.BigNumber.from(token.externalBalance);
|
|
123
123
|
const feeAmount = ethers_1.ethers.BigNumber.from(feeAmountInput !== null && feeAmountInput !== void 0 ? feeAmountInput : "100000000");
|
|
124
124
|
const feeAddress = feeAmount.isZero() ? zeroAddressHex : networkConfig.feeAddress;
|
|
@@ -165,7 +165,7 @@ class NEOClient {
|
|
|
165
165
|
const fromAddress = util_1.AddressUtils.NEOAddress.publicKeyToAddress(publicKeyOutput.publicKey);
|
|
166
166
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
167
167
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
168
|
-
const toAddress =
|
|
168
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
169
169
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
170
170
|
if (amount.lt(feeAmount)) {
|
|
171
171
|
throw new Error("Invalid amount");
|
|
@@ -201,7 +201,7 @@ class NEOClient {
|
|
|
201
201
|
const fromAddress = ledger.scriptHash;
|
|
202
202
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
203
203
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
204
|
-
const toAddress =
|
|
204
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
205
205
|
const feeAddress = networkConfig.feeAddress;
|
|
206
206
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
207
207
|
if (amount.lt(feeAmount)) {
|
|
@@ -321,7 +321,7 @@ class NEOClient {
|
|
|
321
321
|
getTargetProxyHash(token) {
|
|
322
322
|
const networkConfig = this.getNetworkConfig();
|
|
323
323
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
324
|
-
const addressHex =
|
|
324
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
325
325
|
return addressHex;
|
|
326
326
|
}
|
|
327
327
|
getNetworkConfig() {
|
|
@@ -571,7 +571,7 @@ class TokenClient {
|
|
|
571
571
|
if (!token)
|
|
572
572
|
return undefined;
|
|
573
573
|
const bridge = this.getBridgeFromToken(token);
|
|
574
|
-
if (!bridge || !
|
|
574
|
+
if (!bridge || !blockchain_1.isIbcBridge(bridge))
|
|
575
575
|
return undefined;
|
|
576
576
|
return bridge.chain_id_name;
|
|
577
577
|
}
|
|
@@ -580,7 +580,7 @@ class TokenClient {
|
|
|
580
580
|
// get swth on osmosis
|
|
581
581
|
const osmoTmClient = yield tendermint_rpc_1.Tendermint34Client.connect(network_1.publicRpcNodes.Osmosis);
|
|
582
582
|
const osmoClient = new stargate_1.QueryClient(osmoTmClient);
|
|
583
|
-
const osmosRpcClient =
|
|
583
|
+
const osmosRpcClient = stargate_1.createProtobufRpcClient(osmoClient);
|
|
584
584
|
const osmoIbcClient = new query_1.QueryClientImpl(osmosRpcClient);
|
|
585
585
|
const osmoDenomTraces = yield osmoIbcClient.DenomTraces({
|
|
586
586
|
pagination: pagination_1.PageRequest.fromPartial({
|
|
@@ -672,7 +672,7 @@ class TokenClient {
|
|
|
672
672
|
processTokenPrices(tokenPrices) {
|
|
673
673
|
return tokenPrices.reduce((prevPrices, price) => {
|
|
674
674
|
const newPrev = prevPrices;
|
|
675
|
-
newPrev[price.denom] =
|
|
675
|
+
newPrev[price.denom] = number_1.bnOrZero(price.twap).shiftedBy(-constant_1.decTypeDecimals);
|
|
676
676
|
return newPrev;
|
|
677
677
|
}, {});
|
|
678
678
|
}
|
package/lib/clients/ZILClient.js
CHANGED
|
@@ -77,12 +77,12 @@ class ZILClient {
|
|
|
77
77
|
?
|
|
78
78
|
!!sdk.token.getBlockchainV2(token.denom) && (blockchain_1.BLOCKCHAIN_V2_TO_V1_MAPPING[sdk.token.getBlockchainV2(token.denom)] == this.blockchain)
|
|
79
79
|
:
|
|
80
|
-
|
|
80
|
+
blockchain_1.blockchainForChainId(token.chainId.toNumber(), sdk.network) == this.blockchain;
|
|
81
81
|
return isCorrectBlockchain && token.tokenAddress.length == 40 && (!whitelistDenoms || whitelistDenoms.includes(token.denom));
|
|
82
82
|
});
|
|
83
83
|
const requests = tokens.map((token) => token.tokenAddress === zeroAddress
|
|
84
|
-
?
|
|
85
|
-
:
|
|
84
|
+
? exports.balanceBatchRequest(address.replace(/^0x/i, ""))
|
|
85
|
+
: exports.tokenBalanceBatchRequest(token.tokenAddress, address));
|
|
86
86
|
const response = yield fetch(this.getProviderUrl(), {
|
|
87
87
|
method: "post",
|
|
88
88
|
headers: { "content-type": "application/json" },
|
|
@@ -107,7 +107,7 @@ class ZILClient {
|
|
|
107
107
|
// if (!isValidAddress) {
|
|
108
108
|
// throw new Error("invalid address")
|
|
109
109
|
// }
|
|
110
|
-
return
|
|
110
|
+
return zilliqa_1.fromBech32Address(bech32Address).toLowerCase().substr(2);
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
113
|
// see examplesV2/zil_client.ts on how to confirm the transactions
|
|
@@ -153,7 +153,7 @@ class ZILClient {
|
|
|
153
153
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
154
154
|
}
|
|
155
155
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
156
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(
|
|
156
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
|
|
157
157
|
if (balanceAndNonceResp.error !== undefined) {
|
|
158
158
|
throw new Error(balanceAndNonceResp.error.message);
|
|
159
159
|
}
|
|
@@ -171,7 +171,7 @@ class ZILClient {
|
|
|
171
171
|
vname: "spender",
|
|
172
172
|
type: "ByStr20",
|
|
173
173
|
// TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
|
|
174
|
-
value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress :
|
|
174
|
+
value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : generic_1.appendHexPrefix(token.bridgeAddress),
|
|
175
175
|
},
|
|
176
176
|
{
|
|
177
177
|
vname: "amount",
|
|
@@ -189,7 +189,7 @@ class ZILClient {
|
|
|
189
189
|
}
|
|
190
190
|
checkAllowanceZRC2(token, owner, spender) {
|
|
191
191
|
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
-
const contractAddress =
|
|
192
|
+
const contractAddress = generic_1.appendHexPrefix(token.tokenAddress);
|
|
193
193
|
const zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
194
194
|
const resp = yield zilliqa.blockchain.getSmartContractSubState(contractAddress, "allowances", [owner, spender]);
|
|
195
195
|
if (resp.error !== undefined) {
|
|
@@ -211,13 +211,13 @@ class ZILClient {
|
|
|
211
211
|
}
|
|
212
212
|
const carbonNetwork = networkConfig.network;
|
|
213
213
|
const fromTokenId = fromToken.id;
|
|
214
|
-
const fromTokenAddr =
|
|
214
|
+
const fromTokenAddr = generic_1.appendHexPrefix(fromToken.tokenAddress);
|
|
215
215
|
const toTokenDenom = toToken.denom;
|
|
216
|
-
const targetProxyHash =
|
|
216
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(fromToken));
|
|
217
217
|
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(index_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, carbonNetwork));
|
|
218
218
|
const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
|
|
219
219
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
|
|
220
|
-
const feeAddress =
|
|
220
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
221
221
|
const contractAddress = this.getBridgeEntranceAddr();
|
|
222
222
|
let zilliqa;
|
|
223
223
|
if (typeof signer === "string") {
|
|
@@ -232,7 +232,7 @@ class ZILClient {
|
|
|
232
232
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
233
233
|
}
|
|
234
234
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
235
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(
|
|
235
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(fromAddress));
|
|
236
236
|
if (balanceAndNonceResp.error !== undefined) {
|
|
237
237
|
throw new Error(balanceAndNonceResp.error.message);
|
|
238
238
|
}
|
|
@@ -309,13 +309,13 @@ class ZILClient {
|
|
|
309
309
|
return __awaiter(this, void 0, void 0, function* () {
|
|
310
310
|
const { address, amount, token, gasPrice, gasLimit, zilAddress, signer } = params;
|
|
311
311
|
const networkConfig = this.getNetworkConfig();
|
|
312
|
-
const assetId =
|
|
313
|
-
const targetProxyHash =
|
|
314
|
-
const feeAddress =
|
|
312
|
+
const assetId = generic_1.appendHexPrefix(token.tokenAddress);
|
|
313
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
|
|
314
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
315
315
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
|
|
316
316
|
const swthAddress = ethers_1.ethers.utils.hexlify(address);
|
|
317
317
|
// TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
|
|
318
|
-
const contractAddress =
|
|
318
|
+
const contractAddress = generic_1.appendHexPrefix(token.bridgeAddress);
|
|
319
319
|
let zilliqa;
|
|
320
320
|
if (typeof signer === "string") {
|
|
321
321
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
@@ -329,7 +329,7 @@ class ZILClient {
|
|
|
329
329
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
330
330
|
}
|
|
331
331
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
332
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(
|
|
332
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
|
|
333
333
|
if (balanceAndNonceResp.error !== undefined) {
|
|
334
334
|
throw new Error(balanceAndNonceResp.error.message);
|
|
335
335
|
}
|
|
@@ -414,7 +414,7 @@ class ZILClient {
|
|
|
414
414
|
getTargetProxyHash(token) {
|
|
415
415
|
const networkConfig = this.getNetworkConfig();
|
|
416
416
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
417
|
-
const addressHex =
|
|
417
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
418
418
|
return addressHex;
|
|
419
419
|
}
|
|
420
420
|
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 &&
|
|
@@ -300,7 +300,7 @@ exports.MsgVote = {
|
|
|
300
300
|
: "";
|
|
301
301
|
message.option =
|
|
302
302
|
object.option !== undefined && object.option !== null
|
|
303
|
-
?
|
|
303
|
+
? gov_1.voteOptionFromJSON(object.option)
|
|
304
304
|
: 0;
|
|
305
305
|
message.metadata =
|
|
306
306
|
object.metadata !== undefined && object.metadata !== null
|
|
@@ -314,7 +314,7 @@ exports.MsgVote = {
|
|
|
314
314
|
(obj.proposalId = (message.proposalId || long_1.default.UZERO).toString());
|
|
315
315
|
message.voter !== undefined && (obj.voter = message.voter);
|
|
316
316
|
message.option !== undefined &&
|
|
317
|
-
(obj.option =
|
|
317
|
+
(obj.option = gov_1.voteOptionToJSON(message.option));
|
|
318
318
|
message.metadata !== undefined && (obj.metadata = message.metadata);
|
|
319
319
|
return obj;
|
|
320
320
|
},
|
|
@@ -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) {
|
|
@@ -384,7 +384,7 @@ exports.EventExec = {
|
|
|
384
384
|
: long_1.default.UZERO;
|
|
385
385
|
message.result =
|
|
386
386
|
object.result !== undefined && object.result !== null
|
|
387
|
-
?
|
|
387
|
+
? types_1.proposalExecutorResultFromJSON(object.result)
|
|
388
388
|
: 0;
|
|
389
389
|
message.logs =
|
|
390
390
|
object.logs !== undefined && object.logs !== null
|
|
@@ -397,7 +397,7 @@ exports.EventExec = {
|
|
|
397
397
|
message.proposalId !== undefined &&
|
|
398
398
|
(obj.proposalId = (message.proposalId || long_1.default.UZERO).toString());
|
|
399
399
|
message.result !== undefined &&
|
|
400
|
-
(obj.result =
|
|
400
|
+
(obj.result = types_1.proposalExecutorResultToJSON(message.result));
|
|
401
401
|
message.logs !== undefined && (obj.logs = message.logs);
|
|
402
402
|
return obj;
|
|
403
403
|
},
|
|
@@ -1474,7 +1474,7 @@ exports.MsgVote = {
|
|
|
1474
1474
|
: "";
|
|
1475
1475
|
message.option =
|
|
1476
1476
|
object.option !== undefined && object.option !== null
|
|
1477
|
-
?
|
|
1477
|
+
? types_1.voteOptionFromJSON(object.option)
|
|
1478
1478
|
: 0;
|
|
1479
1479
|
message.metadata =
|
|
1480
1480
|
object.metadata !== undefined && object.metadata !== null
|
|
@@ -1492,7 +1492,7 @@ exports.MsgVote = {
|
|
|
1492
1492
|
(obj.proposalId = (message.proposalId || long_1.default.UZERO).toString());
|
|
1493
1493
|
message.voter !== undefined && (obj.voter = message.voter);
|
|
1494
1494
|
message.option !== undefined &&
|
|
1495
|
-
(obj.option =
|
|
1495
|
+
(obj.option = types_1.voteOptionToJSON(message.option));
|
|
1496
1496
|
message.metadata !== undefined && (obj.metadata = message.metadata);
|
|
1497
1497
|
message.exec !== undefined && (obj.exec = execToJSON(message.exec));
|
|
1498
1498
|
return obj;
|
|
@@ -1633,14 +1633,14 @@ exports.MsgExecResponse = {
|
|
|
1633
1633
|
const message = Object.assign({}, baseMsgExecResponse);
|
|
1634
1634
|
message.result =
|
|
1635
1635
|
object.result !== undefined && object.result !== null
|
|
1636
|
-
?
|
|
1636
|
+
? types_1.proposalExecutorResultFromJSON(object.result)
|
|
1637
1637
|
: 0;
|
|
1638
1638
|
return message;
|
|
1639
1639
|
},
|
|
1640
1640
|
toJSON(message) {
|
|
1641
1641
|
const obj = {};
|
|
1642
1642
|
message.result !== undefined &&
|
|
1643
|
-
(obj.result =
|
|
1643
|
+
(obj.result = types_1.proposalExecutorResultToJSON(message.result));
|
|
1644
1644
|
return obj;
|
|
1645
1645
|
},
|
|
1646
1646
|
fromPartial(object) {
|
|
@@ -763,13 +763,13 @@ exports.ModeInfo_Single = {
|
|
|
763
763
|
const message = Object.assign({}, baseModeInfo_Single);
|
|
764
764
|
message.mode =
|
|
765
765
|
object.mode !== undefined && object.mode !== null
|
|
766
|
-
?
|
|
766
|
+
? signing_1.signModeFromJSON(object.mode)
|
|
767
767
|
: 0;
|
|
768
768
|
return message;
|
|
769
769
|
},
|
|
770
770
|
toJSON(message) {
|
|
771
771
|
const obj = {};
|
|
772
|
-
message.mode !== undefined && (obj.mode =
|
|
772
|
+
message.mode !== undefined && (obj.mode = signing_1.signModeToJSON(message.mode));
|
|
773
773
|
return obj;
|
|
774
774
|
},
|
|
775
775
|
fromPartial(object) {
|
|
@@ -1052,7 +1052,7 @@ exports.AuxSignerData = {
|
|
|
1052
1052
|
: undefined;
|
|
1053
1053
|
message.mode =
|
|
1054
1054
|
object.mode !== undefined && object.mode !== null
|
|
1055
|
-
?
|
|
1055
|
+
? signing_1.signModeFromJSON(object.mode)
|
|
1056
1056
|
: 0;
|
|
1057
1057
|
message.sig =
|
|
1058
1058
|
object.sig !== undefined && object.sig !== null
|
|
@@ -1067,7 +1067,7 @@ exports.AuxSignerData = {
|
|
|
1067
1067
|
(obj.signDoc = message.signDoc
|
|
1068
1068
|
? exports.SignDocDirectAux.toJSON(message.signDoc)
|
|
1069
1069
|
: undefined);
|
|
1070
|
-
message.mode !== undefined && (obj.mode =
|
|
1070
|
+
message.mode !== undefined && (obj.mode = signing_1.signModeToJSON(message.mode));
|
|
1071
1071
|
message.sig !== undefined &&
|
|
1072
1072
|
(obj.sig = base64FromBytes(message.sig !== undefined ? message.sig : new Uint8Array()));
|
|
1073
1073
|
return obj;
|
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 = {
|