carbon-js-sdk 0.5.5 → 0.5.6
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/BatchQueryClient.js +4 -4
- package/lib/clients/CarbonQueryClient.js +2 -2
- package/lib/clients/ETHClient.js +15 -15
- package/lib/clients/EvmIbcClient.d.ts +86 -0
- package/lib/clients/EvmIbcClient.js +90 -0
- package/lib/clients/HydrogenClient.js +1 -1
- package/lib/clients/NEOClient.js +7 -7
- package/lib/clients/TokenClient.js +20 -16
- package/lib/clients/ZILClient.js +17 -17
- package/lib/codec/broker/incoming_pool_swap.d.ts +23 -0
- package/lib/codec/broker/incoming_pool_swap.js +136 -0
- 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/codec/crisis/genesis.d.ts +18 -0
- package/lib/codec/crisis/genesis.js +46 -0
- package/lib/codec/crisis/query.d.ts +43 -0
- package/lib/codec/crisis/query.js +103 -0
- package/lib/codec/crisis/tx.d.ts +12 -0
- package/lib/codec/crisis/tx.js +20 -0
- package/lib/codec/ibc/applications/interchain_accounts/v1/genesis.d.ts +76 -0
- package/lib/codec/ibc/applications/interchain_accounts/v1/genesis.js +424 -0
- package/lib/codec/market/legacy.d.ts +62 -0
- package/lib/codec/market/legacy.js +630 -0
- package/lib/codec/query/pagination.d.ts +29 -0
- package/lib/codec/query/pagination.js +126 -0
- package/lib/constant/generic.js +1 -1
- package/lib/modules/cdp.js +44 -44
- package/lib/modules/cosmwasm.js +1 -1
- package/lib/modules/evm.js +5 -5
- 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/alliance.d.ts +4 -0
- package/lib/provider/amino/types/alliance.js +56 -0
- 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/evm.js +2 -2
- package/lib/provider/amino/types/evmmerge.js +1 -1
- package/lib/provider/amino/types/feemarket.js +1 -1
- package/lib/provider/amino/types/gov.js +5 -5
- 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 +6 -6
- package/lib/provider/amino/types/oracle.js +2 -2
- 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/KeplrAccount.js +2 -2
- package/lib/provider/ledger/ledger.js +2 -2
- package/lib/provider/metamask/MetaMask.js +10 -10
- package/lib/provider/o3/O3Wallet.js +2 -2
- package/lib/util/address.js +14 -14
- package/lib/util/api.js +4 -4
- package/lib/util/blockchain.js +4 -4
- package/lib/util/eip712.js +3 -3
- package/lib/util/ethermint/evm-ibc.d.ts +97 -0
- package/lib/util/ethermint/evm-ibc.js +134 -0
- package/lib/util/ethermint/index.d.ts +3 -0
- package/lib/util/ethermint/index.js +12 -0
- package/lib/util/ethermint/keys.d.ts +39 -0
- package/lib/util/ethermint/keys.js +138 -0
- package/lib/util/ethermint/web3.d.ts +36 -0
- package/lib/util/ethermint/web3.js +124 -0
- package/lib/util/fetch.js +1 -1
- package/lib/util/generic.js +3 -3
- package/lib/util/legacyEIP712.js +2 -2
- package/lib/util/number.js +5 -5
- package/lib/wallet/CarbonSigner.js +2 -2
- package/lib/wallet/CarbonSigningClient.js +15 -15
- package/lib/wallet/CarbonWallet.js +9 -9
- package/lib/websocket/connector.js +3 -3
- package/package.json +1 -1
|
@@ -29,7 +29,7 @@ class BatchQueryClient {
|
|
|
29
29
|
};
|
|
30
30
|
if (typeof endpoint === "string") {
|
|
31
31
|
// accept host.name:port and assume http protocol
|
|
32
|
-
this.url =
|
|
32
|
+
this.url = rpcclient_1.hasProtocol(endpoint) ? endpoint : "http://" + endpoint;
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
35
|
this.url = endpoint.url;
|
|
@@ -71,7 +71,7 @@ class BatchQueryClient {
|
|
|
71
71
|
return;
|
|
72
72
|
const requests = batch.map((s) => s.request);
|
|
73
73
|
const requestIds = requests.map((request) => request.id);
|
|
74
|
-
|
|
74
|
+
http_1.http("POST", this.url, this.headers, requests).then((raw) => {
|
|
75
75
|
// Requests with a single entry return as an object
|
|
76
76
|
const arr = Array.isArray(raw) ? raw : [raw];
|
|
77
77
|
arr.forEach((el, i) => {
|
|
@@ -79,8 +79,8 @@ class BatchQueryClient {
|
|
|
79
79
|
if (!req)
|
|
80
80
|
return;
|
|
81
81
|
const { reject, resolve } = req;
|
|
82
|
-
const response =
|
|
83
|
-
if (
|
|
82
|
+
const response = json_rpc_1.parseJsonRpcResponse(el);
|
|
83
|
+
if (json_rpc_1.isJsonRpcErrorResponse(response)) {
|
|
84
84
|
reject(new Error(JSON.stringify(response.error)));
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
@@ -53,7 +53,7 @@ class CarbonQueryClient {
|
|
|
53
53
|
constructor(tmClient) {
|
|
54
54
|
this.tmClient = tmClient;
|
|
55
55
|
this.baseClient = new stargate_1.QueryClient(this.tmClient);
|
|
56
|
-
const rpcClient =
|
|
56
|
+
const rpcClient = stargate_1.createProtobufRpcClient(this.baseClient);
|
|
57
57
|
this.chain = BlockchainClient_1.default.connectWithTm(this.tmClient);
|
|
58
58
|
this.adl = new query_1.QueryClientImpl(rpcClient);
|
|
59
59
|
this.alliance = new query_44.QueryClientImpl(rpcClient);
|
|
@@ -106,7 +106,7 @@ class CarbonQueryClient {
|
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
getProtobufRpcClient() {
|
|
109
|
-
return
|
|
109
|
+
return stargate_1.createProtobufRpcClient(this.baseClient);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
exports.default = CarbonQueryClient;
|
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();
|
|
@@ -99,14 +99,14 @@ class ETHClient {
|
|
|
99
99
|
}
|
|
100
100
|
const carbonNetwork = networkConfig.network;
|
|
101
101
|
const fromTokenId = fromToken.id;
|
|
102
|
-
const fromTokenAddress =
|
|
102
|
+
const fromTokenAddress = generic_1.appendHexPrefix(fromToken.tokenAddress);
|
|
103
103
|
const toTokenDenom = toToken.denom;
|
|
104
104
|
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(util_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, carbonNetwork));
|
|
105
105
|
const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
|
|
106
106
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
|
|
107
107
|
const nonce = yield this.getTxNonce(fromAddress, params.nonce, rpcProvider);
|
|
108
108
|
const contract = new ethers_1.ethers.Contract(this.getBridgeEntranceAddr(), eth_1.ABIs.bridgeEntrance, rpcProvider);
|
|
109
|
-
const feeAddress =
|
|
109
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
110
110
|
const tokenCreator = fromToken.creator;
|
|
111
111
|
const targetAddressBytes = util_1.AddressUtils.SWTHAddress.getAddressBytes(tokenCreator, carbonNetwork);
|
|
112
112
|
const targetProxyHash = ethers_1.ethers.utils.hexlify(targetAddressBytes);
|
|
@@ -135,9 +135,9 @@ class ETHClient {
|
|
|
135
135
|
throw new Error("Minimum gas required: 150,000");
|
|
136
136
|
}
|
|
137
137
|
const networkConfig = this.getNetworkConfig();
|
|
138
|
-
const assetId =
|
|
139
|
-
const targetProxyHash =
|
|
140
|
-
const feeAddress =
|
|
138
|
+
const assetId = generic_1.appendHexPrefix(token.tokenAddress);
|
|
139
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
|
|
140
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
141
141
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
|
|
142
142
|
const swthAddress = ethers_1.ethers.utils.hexlify(address);
|
|
143
143
|
const contractAddress = this.getLockProxyAddress();
|
|
@@ -188,16 +188,16 @@ class ETHClient {
|
|
|
188
188
|
return "insufficient balance";
|
|
189
189
|
}
|
|
190
190
|
const networkConfig = this.getNetworkConfig();
|
|
191
|
-
const assetId =
|
|
192
|
-
const targetProxyHash =
|
|
193
|
-
const feeAddress =
|
|
191
|
+
const assetId = generic_1.appendHexPrefix(tokenWithExternalBalances.tokenAddress);
|
|
192
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(tokenWithExternalBalances));
|
|
193
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
194
194
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(tokenWithExternalBalances.id));
|
|
195
195
|
const nonce = Math.floor(Math.random() * 1000000000); // random nonce to prevent replay attacks
|
|
196
196
|
const message = ethers_1.ethers.utils.solidityKeccak256(["string", "address", "bytes", "bytes", "bytes", "uint256", "uint256", "uint256"], ["sendTokens", assetId, targetProxyHash, toAssetHash, feeAddress, amount, feeAmount, nonce]);
|
|
197
197
|
// logger("sendDeposit message", message)
|
|
198
198
|
let signatureResult;
|
|
199
199
|
const { address, signature } = yield getSignatureCallback(message);
|
|
200
|
-
const signatureBytes = ethers_1.ethers.utils.arrayify(
|
|
200
|
+
const signatureBytes = ethers_1.ethers.utils.arrayify(generic_1.appendHexPrefix(signature));
|
|
201
201
|
const rsv = ethers_1.ethers.utils.splitSignature(signatureBytes);
|
|
202
202
|
// logger("sign result", address, signature)
|
|
203
203
|
signatureResult = {
|
|
@@ -236,7 +236,7 @@ class ETHClient {
|
|
|
236
236
|
if (!feeInfo.deposit_fee) {
|
|
237
237
|
throw new Error("unsupported token");
|
|
238
238
|
}
|
|
239
|
-
if (
|
|
239
|
+
if (blockchain_1.blockchainForChainId(token.chainId.toNumber(), this.configProvider.getConfig().network) !== this.blockchain) {
|
|
240
240
|
throw new Error("unsupported token");
|
|
241
241
|
}
|
|
242
242
|
let feeAmount = ethers_1.ethers.BigNumber.from(feeInfo.deposit_fee);
|
|
@@ -302,7 +302,7 @@ class ETHClient {
|
|
|
302
302
|
getTargetProxyHash(token) {
|
|
303
303
|
const networkConfig = this.getNetworkConfig();
|
|
304
304
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
305
|
-
const addressHex =
|
|
305
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
306
306
|
return addressHex;
|
|
307
307
|
}
|
|
308
308
|
getProvider() {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Network } from "../constant";
|
|
2
|
+
import { StdSignDoc } from "@cosmjs/amino";
|
|
3
|
+
import { BlockchainUtils } from "../util";
|
|
4
|
+
declare type SupportedBlockchains = BlockchainUtils.Blockchain.Canto | BlockchainUtils.Blockchain.Evmos;
|
|
5
|
+
declare namespace EvmIbcClient {
|
|
6
|
+
interface TypedDomain {
|
|
7
|
+
name: string;
|
|
8
|
+
version: string;
|
|
9
|
+
chainId: number;
|
|
10
|
+
verifyingContract: string;
|
|
11
|
+
salt: string;
|
|
12
|
+
}
|
|
13
|
+
interface TypedDataV4 {
|
|
14
|
+
types: object;
|
|
15
|
+
primaryType: string;
|
|
16
|
+
message: StdSignDoc;
|
|
17
|
+
domain: TypedDomain;
|
|
18
|
+
}
|
|
19
|
+
const TYPED_DATA_REQUEST_METHOD = "eth_signTypedData_v4";
|
|
20
|
+
const DEFAULT_EIP712_TYPES: {
|
|
21
|
+
EIP712Domain: {
|
|
22
|
+
name: string;
|
|
23
|
+
type: string;
|
|
24
|
+
}[];
|
|
25
|
+
Tx: {
|
|
26
|
+
name: string;
|
|
27
|
+
type: string;
|
|
28
|
+
}[];
|
|
29
|
+
Fee: {
|
|
30
|
+
name: string;
|
|
31
|
+
type: string;
|
|
32
|
+
}[];
|
|
33
|
+
Coin: {
|
|
34
|
+
name: string;
|
|
35
|
+
type: string;
|
|
36
|
+
}[];
|
|
37
|
+
Msg: {
|
|
38
|
+
name: string;
|
|
39
|
+
type: string;
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
42
|
+
const getEvmChainId: (blockchain: SupportedBlockchains, network?: Network) => 7700 | 9001;
|
|
43
|
+
const getIbcTransferTypes: () => {
|
|
44
|
+
MsgValue: {
|
|
45
|
+
name: string;
|
|
46
|
+
type: string;
|
|
47
|
+
}[];
|
|
48
|
+
TypeToken: {
|
|
49
|
+
name: string;
|
|
50
|
+
type: string;
|
|
51
|
+
}[];
|
|
52
|
+
TypeTimeoutHeight: {
|
|
53
|
+
name: string;
|
|
54
|
+
type: string;
|
|
55
|
+
}[];
|
|
56
|
+
EIP712Domain: {
|
|
57
|
+
name: string;
|
|
58
|
+
type: string;
|
|
59
|
+
}[];
|
|
60
|
+
Tx: {
|
|
61
|
+
name: string;
|
|
62
|
+
type: string;
|
|
63
|
+
}[];
|
|
64
|
+
Fee: {
|
|
65
|
+
name: string;
|
|
66
|
+
type: string;
|
|
67
|
+
}[];
|
|
68
|
+
Coin: {
|
|
69
|
+
name: string;
|
|
70
|
+
type: string;
|
|
71
|
+
}[];
|
|
72
|
+
Msg: {
|
|
73
|
+
name: string;
|
|
74
|
+
type: string;
|
|
75
|
+
}[];
|
|
76
|
+
};
|
|
77
|
+
const getCosmosWeb3Domain: (blockchain: SupportedBlockchains) => {
|
|
78
|
+
name: string;
|
|
79
|
+
version: string;
|
|
80
|
+
chainId: number;
|
|
81
|
+
verifyingContract: string;
|
|
82
|
+
salt: string;
|
|
83
|
+
};
|
|
84
|
+
const getEIP712TypedData: (tx: StdSignDoc, blockchain: SupportedBlockchains, types?: object, domain?: EvmIbcClient.TypedDomain, primaryType?: string) => TypedDataV4;
|
|
85
|
+
}
|
|
86
|
+
export default EvmIbcClient;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constant_1 = require("../constant");
|
|
4
|
+
const util_1 = require("../util");
|
|
5
|
+
const _DEFAULT_EIP712_TYPES = {
|
|
6
|
+
EIP712Domain: [
|
|
7
|
+
{ name: 'name', type: 'string' },
|
|
8
|
+
{ name: 'version', type: 'string' },
|
|
9
|
+
{ name: 'chainId', type: 'uint256' },
|
|
10
|
+
{ name: 'verifyingContract', type: 'string' },
|
|
11
|
+
{ name: 'salt', type: 'string' },
|
|
12
|
+
],
|
|
13
|
+
Tx: [
|
|
14
|
+
{ name: 'account_number', type: 'string' },
|
|
15
|
+
{ name: 'chain_id', type: 'string' },
|
|
16
|
+
{ name: 'fee', type: 'Fee' },
|
|
17
|
+
{ name: 'memo', type: 'string' },
|
|
18
|
+
{ name: 'msgs', type: 'Msg[]' },
|
|
19
|
+
{ name: 'sequence', type: 'string' },
|
|
20
|
+
],
|
|
21
|
+
Fee: [
|
|
22
|
+
{ name: 'feePayer', type: 'string' },
|
|
23
|
+
{ name: 'amount', type: 'Coin[]' },
|
|
24
|
+
{ name: 'gas', type: 'string' },
|
|
25
|
+
],
|
|
26
|
+
Coin: [
|
|
27
|
+
{ name: 'denom', type: 'string' },
|
|
28
|
+
{ name: 'amount', type: 'string' },
|
|
29
|
+
],
|
|
30
|
+
Msg: [
|
|
31
|
+
{ name: 'type', type: 'string' },
|
|
32
|
+
{ name: 'value', type: 'MsgValue' },
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
var EvmIbcClient;
|
|
36
|
+
(function (EvmIbcClient) {
|
|
37
|
+
EvmIbcClient.TYPED_DATA_REQUEST_METHOD = "eth_signTypedData_v4";
|
|
38
|
+
EvmIbcClient.DEFAULT_EIP712_TYPES = _DEFAULT_EIP712_TYPES;
|
|
39
|
+
EvmIbcClient.getEvmChainId = (blockchain, network = constant_1.Network.MainNet) => {
|
|
40
|
+
switch (network) {
|
|
41
|
+
case constant_1.Network.MainNet:
|
|
42
|
+
switch (blockchain) {
|
|
43
|
+
case util_1.BlockchainUtils.Blockchain.Canto:
|
|
44
|
+
return 7700;
|
|
45
|
+
case util_1.BlockchainUtils.Blockchain.Evmos:
|
|
46
|
+
return 9001;
|
|
47
|
+
default:
|
|
48
|
+
throw new Error("network not supported");
|
|
49
|
+
}
|
|
50
|
+
default:
|
|
51
|
+
throw new Error("network not supported");
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
EvmIbcClient.getIbcTransferTypes = () => {
|
|
55
|
+
return Object.assign(Object.assign({}, EvmIbcClient.DEFAULT_EIP712_TYPES), { MsgValue: [
|
|
56
|
+
{ name: 'source_port', type: 'string' },
|
|
57
|
+
{ name: 'source_channel', type: 'string' },
|
|
58
|
+
{ name: 'token', type: 'TypeToken' },
|
|
59
|
+
{ name: 'sender', type: 'string' },
|
|
60
|
+
{ name: 'receiver', type: 'string' },
|
|
61
|
+
{ name: 'timeout_height', type: 'TypeTimeoutHeight' },
|
|
62
|
+
{ name: 'timeout_timestamp', type: 'uint64' },
|
|
63
|
+
], TypeToken: [
|
|
64
|
+
{ name: 'denom', type: 'string' },
|
|
65
|
+
{ name: 'amount', type: 'string' },
|
|
66
|
+
], TypeTimeoutHeight: [
|
|
67
|
+
{ name: 'revision_number', type: 'uint64' },
|
|
68
|
+
{ name: 'revision_height', type: 'uint64' },
|
|
69
|
+
] });
|
|
70
|
+
};
|
|
71
|
+
EvmIbcClient.getCosmosWeb3Domain = (blockchain) => {
|
|
72
|
+
return {
|
|
73
|
+
name: "Cosmos Web3",
|
|
74
|
+
version: "1.0.0",
|
|
75
|
+
chainId: EvmIbcClient.getEvmChainId(blockchain),
|
|
76
|
+
verifyingContract: "cosmos",
|
|
77
|
+
salt: "0",
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
EvmIbcClient.getEIP712TypedData = (tx, blockchain, types = EvmIbcClient.getIbcTransferTypes(), domain = EvmIbcClient.getCosmosWeb3Domain(blockchain), primaryType = "Tx") => {
|
|
81
|
+
const typedData = {
|
|
82
|
+
types,
|
|
83
|
+
primaryType,
|
|
84
|
+
domain,
|
|
85
|
+
message: tx,
|
|
86
|
+
};
|
|
87
|
+
return typedData;
|
|
88
|
+
};
|
|
89
|
+
})(EvmIbcClient || (EvmIbcClient = {}));
|
|
90
|
+
exports.default = EvmIbcClient;
|
|
@@ -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() {
|
|
@@ -67,22 +67,26 @@ class TokenClient {
|
|
|
67
67
|
initialize() {
|
|
68
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
69
|
this.setCommonAssetConfig();
|
|
70
|
-
// non-blocking reload
|
|
71
70
|
try {
|
|
72
|
-
|
|
73
|
-
this.
|
|
74
|
-
this.
|
|
75
|
-
|
|
71
|
+
yield Promise.all([
|
|
72
|
+
this.reloadTokens(),
|
|
73
|
+
this.reloadWrapperMap(),
|
|
74
|
+
this.getBridges(),
|
|
75
|
+
]);
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
finally {
|
|
78
|
+
// non-blocking reload
|
|
79
|
+
try {
|
|
80
|
+
this.reloadDenomGeckoMap().finally(() => {
|
|
81
|
+
this.reloadUSDValues();
|
|
82
|
+
this.reloadDenomTraces();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.error("failed to reload usd values");
|
|
87
|
+
console.error(error);
|
|
88
|
+
}
|
|
80
89
|
}
|
|
81
|
-
yield Promise.all([
|
|
82
|
-
this.reloadWrapperMap(),
|
|
83
|
-
this.reloadTokens(),
|
|
84
|
-
this.getBridges(),
|
|
85
|
-
]);
|
|
86
90
|
});
|
|
87
91
|
}
|
|
88
92
|
registerGeckoIdMap(map) {
|
|
@@ -565,7 +569,7 @@ class TokenClient {
|
|
|
565
569
|
if (!token)
|
|
566
570
|
return undefined;
|
|
567
571
|
const bridge = this.getBridgeFromToken(token);
|
|
568
|
-
if (!bridge || !
|
|
572
|
+
if (!bridge || !blockchain_1.isIbcBridge(bridge))
|
|
569
573
|
return undefined;
|
|
570
574
|
return bridge.chain_id_name;
|
|
571
575
|
}
|
|
@@ -574,7 +578,7 @@ class TokenClient {
|
|
|
574
578
|
// get swth on osmosis
|
|
575
579
|
const osmoTmClient = yield tendermint_rpc_1.Tendermint34Client.connect(network_1.publicRpcNodes.Osmosis);
|
|
576
580
|
const osmoClient = new stargate_1.QueryClient(osmoTmClient);
|
|
577
|
-
const osmosRpcClient =
|
|
581
|
+
const osmosRpcClient = stargate_1.createProtobufRpcClient(osmoClient);
|
|
578
582
|
const osmoIbcClient = new query_1.QueryClientImpl(osmosRpcClient);
|
|
579
583
|
const osmoDenomTraces = yield osmoIbcClient.DenomTraces({
|
|
580
584
|
pagination: pagination_1.PageRequest.fromPartial({
|
|
@@ -667,7 +671,7 @@ class TokenClient {
|
|
|
667
671
|
processTokenPrices(tokenPrices) {
|
|
668
672
|
return tokenPrices.reduce((prevPrices, price) => {
|
|
669
673
|
const newPrev = prevPrices;
|
|
670
|
-
newPrev[price.denom] =
|
|
674
|
+
newPrev[price.denom] = number_1.bnOrZero(price.twap).shiftedBy(-constant_1.decTypeDecimals);
|
|
671
675
|
return newPrev;
|
|
672
676
|
}, {});
|
|
673
677
|
}
|
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() {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Long from "long";
|
|
2
|
+
import _m0 from "protobufjs/minimal";
|
|
3
|
+
export declare const protobufPackage = "Switcheo.carbon.broker";
|
|
4
|
+
export interface IncomingPoolSwap {
|
|
5
|
+
poolId: Long;
|
|
6
|
+
market: string;
|
|
7
|
+
tokenATotalInput: string;
|
|
8
|
+
tokenATotalExpectedOutput: string;
|
|
9
|
+
tokenBTotalInput: string;
|
|
10
|
+
tokenBTotalExpectedOutput: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const IncomingPoolSwap: {
|
|
13
|
+
encode(message: IncomingPoolSwap, writer?: _m0.Writer): _m0.Writer;
|
|
14
|
+
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): IncomingPoolSwap;
|
|
15
|
+
fromJSON(object: any): IncomingPoolSwap;
|
|
16
|
+
toJSON(message: IncomingPoolSwap): unknown;
|
|
17
|
+
fromPartial(object: DeepPartial<IncomingPoolSwap>): IncomingPoolSwap;
|
|
18
|
+
};
|
|
19
|
+
declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
20
|
+
export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
21
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
22
|
+
} : Partial<T>;
|
|
23
|
+
export {};
|