carbon-js-sdk 0.3.31 → 0.3.32-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/CarbonSDK.js +1 -1
- package/lib/clients/CarbonQueryClient.js +2 -2
- package/lib/clients/ETHClient.js +17 -17
- package/lib/clients/HydrogenClient.js +10 -10
- package/lib/clients/InsightsQueryClient.js +45 -45
- package/lib/clients/N3Client.js +28 -25
- package/lib/clients/NEOClient.js +21 -20
- package/lib/clients/TokenClient.js +24 -27
- package/lib/clients/ZILClient.d.ts +1 -1
- package/lib/clients/ZILClient.js +66 -65
- package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
- package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
- package/lib/codec/cosmos/tx/v1beta1/tx.js +2 -2
- package/lib/constant/generic.js +1 -1
- package/lib/constant/ibc.js +13 -13
- package/lib/constant/network.d.ts +1 -1
- package/lib/constant/network.js +18 -18
- package/lib/constant/node.js +16 -11
- package/lib/constant/token.js +348 -348
- package/lib/eth/abis/index.d.ts +7 -7
- package/lib/eth/index.d.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/insights/common.d.ts +29 -29
- package/lib/insights/common.js +29 -29
- package/lib/modules/admin.js +29 -30
- package/lib/modules/bank.js +1 -2
- package/lib/modules/broker.js +1 -2
- package/lib/modules/cdp.d.ts +3 -3
- package/lib/modules/cdp.js +76 -77
- package/lib/modules/coin.js +0 -1
- package/lib/modules/fee.js +2 -2
- package/lib/modules/gov.js +14 -15
- package/lib/modules/ibc.js +2 -3
- package/lib/modules/leverage.js +1 -2
- package/lib/modules/liquiditypool.d.ts +1 -1
- package/lib/modules/liquiditypool.js +3 -4
- package/lib/modules/market.js +1 -2
- package/lib/modules/oracle.js +0 -1
- package/lib/modules/order.js +4 -5
- package/lib/modules/position.js +1 -2
- package/lib/modules/profile.js +0 -1
- package/lib/modules/staking.js +1 -2
- package/lib/modules/subaccount.js +0 -1
- package/lib/modules/xchain.js +1 -1
- package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.d.ts +2 -2
- package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +10 -8
- package/lib/provider/account/EthLedgerAccount/EthLedgerSigner.d.ts +2 -2
- package/lib/provider/account/EthLedgerAccount/EthLedgerSigner.js +5 -4
- package/lib/provider/account/EthLedgerAccount/index.d.ts +2 -2
- 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 +8 -6
- package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +2 -3
- package/lib/provider/amino/types/admin.js +30 -30
- package/lib/provider/amino/types/bank.js +1 -1
- package/lib/provider/amino/types/broker.js +1 -1
- package/lib/provider/amino/types/cdp.js +22 -22
- package/lib/provider/amino/types/coin.js +2 -2
- package/lib/provider/amino/types/gov.js +7 -8
- 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 +6 -10
- 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 +17 -27
- package/lib/provider/chainProvider/GetSigningCosmosClientOptions.d.ts +1 -1
- package/lib/provider/chainProvider/GetSigningCosmosClientOptions.js +1 -1
- package/lib/provider/chainProvider/index.d.ts +2 -2
- package/lib/provider/keplr/KeplrAccount.d.ts +1 -2
- package/lib/provider/keplr/KeplrAccount.js +7 -5
- package/lib/provider/keplr/KeplrStore.d.ts +2 -8
- package/lib/provider/keplr/KeplrStore.js +1 -7
- package/lib/provider/leap/LeapAccount.d.ts +1 -2
- package/lib/provider/leap/LeapAccount.js +7 -5
- package/lib/provider/ledger/ledger.js +2 -2
- package/lib/provider/metamask/MetaMask.d.ts +3 -3
- package/lib/provider/metamask/MetaMask.js +99 -94
- package/lib/provider/metamask/index.d.ts +1 -1
- package/lib/provider/o3/O3Wallet.js +14 -10
- package/lib/provider/zilpay/Zilpay.js +9 -9
- package/lib/util/address.js +14 -20
- package/lib/util/api.js +11 -11
- package/lib/util/blockchain.d.ts +1 -1
- package/lib/util/blockchain.js +43 -44
- package/lib/util/external.js +1 -2
- package/lib/util/fetch.js +2 -3
- package/lib/util/generic.js +6 -6
- package/lib/util/gov.js +1 -2
- package/lib/util/ibc.js +4 -7
- package/lib/util/number.js +5 -5
- package/lib/util/token.js +3 -3
- package/lib/util/tx.js +5 -5
- package/lib/util/type.js +6 -10
- package/lib/wallet/CarbonSigner.d.ts +3 -3
- package/lib/wallet/CarbonSigner.js +2 -2
- package/lib/wallet/CarbonSigningClient.js +12 -13
- package/lib/wallet/CarbonWallet.js +13 -16
- package/lib/websocket/channel.d.ts +1 -1
- package/lib/websocket/channel.js +30 -30
- package/lib/websocket/connector.d.ts +3 -3
- package/lib/websocket/connector.js +23 -23
- package/lib/websocket/index.d.ts +1 -1
- package/lib/websocket/models.d.ts +4 -5
- package/package.json +1 -1
- package/lib/codec/ibc/applications/fee/v1/ack.d.ts +0 -24
- package/lib/codec/ibc/applications/fee/v1/ack.js +0 -125
- package/lib/codec/ibc/applications/fee/v1/fee.d.ts +0 -68
- package/lib/codec/ibc/applications/fee/v1/fee.js +0 -289
- package/lib/codec/ibc/applications/fee/v1/genesis.d.ts +0 -93
- package/lib/codec/ibc/applications/fee/v1/genesis.js +0 -390
- package/lib/codec/ibc/applications/fee/v1/metadata.d.ts +0 -25
- package/lib/codec/ibc/applications/fee/v1/metadata.js +0 -71
- package/lib/codec/ibc/applications/fee/v1/query.d.ts +0 -312
- package/lib/codec/ibc/applications/fee/v1/query.js +0 -1187
- package/lib/codec/ibc/applications/fee/v1/tx.d.ts +0 -171
- package/lib/codec/ibc/applications/fee/v1/tx.js +0 -524
- package/lib/codec/ibc/applications/interchain_accounts/controller/v1/tx.d.ts +0 -78
- package/lib/codec/ibc/applications/interchain_accounts/controller/v1/tx.js +0 -296
- package/lib/codec/ibc/applications/interchain_accounts/genesis/v1/genesis.d.ts +0 -80
- package/lib/codec/ibc/applications/interchain_accounts/genesis/v1/genesis.js +0 -439
package/lib/CarbonSDK.js
CHANGED
|
@@ -216,7 +216,7 @@ class CarbonSDK {
|
|
|
216
216
|
const errorTyped = err;
|
|
217
217
|
// In the case where account does not exist on chain, still allow wallet connection.
|
|
218
218
|
// Else, throw an error as per normal
|
|
219
|
-
if (!errorTyped.message.includes(
|
|
219
|
+
if (!errorTyped.message.includes("Account does not exist on chain. Send some tokens there before trying to query sequence.")) {
|
|
220
220
|
throw new Error(errorTyped.message);
|
|
221
221
|
}
|
|
222
222
|
}
|
|
@@ -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();
|
|
@@ -88,21 +88,21 @@ class ETHClient {
|
|
|
88
88
|
}
|
|
89
89
|
bridgeTokens(params) {
|
|
90
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
const { fromToken, toToken, amount, toAddress, fromAddress, recoveryAddress, signer, gasPriceGwei, gasLimit, feeAmount, signCompleteCallback } = params;
|
|
91
|
+
const { fromToken, toToken, amount, toAddress, fromAddress, recoveryAddress, signer, gasPriceGwei, gasLimit, feeAmount, signCompleteCallback, } = params;
|
|
92
92
|
const networkConfig = this.getNetworkConfig();
|
|
93
93
|
const rpcProvider = this.getProvider();
|
|
94
94
|
if (!recoveryAddress.match(/^swth[a-z0-9]{39}$/)) {
|
|
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);
|
|
@@ -118,7 +118,7 @@ class ETHClient {
|
|
|
118
118
|
], [
|
|
119
119
|
amount.toString(10),
|
|
120
120
|
feeAmount.toString(10),
|
|
121
|
-
amount.toString(10)
|
|
121
|
+
amount.toString(10),
|
|
122
122
|
], // callAmount
|
|
123
123
|
{
|
|
124
124
|
gasLimit: gasLimit.toString(10),
|
|
@@ -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() {
|
|
@@ -18,18 +18,18 @@ const util_1 = require("../util");
|
|
|
18
18
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
19
19
|
exports.HydrogenEndpoints = {
|
|
20
20
|
// Status api
|
|
21
|
-
|
|
21
|
+
stats: "/stats",
|
|
22
22
|
// Transfer Payloads api
|
|
23
|
-
|
|
23
|
+
transfer_payloads: "/transfer_payloads",
|
|
24
24
|
// Relays api
|
|
25
|
-
|
|
25
|
+
relays: "/relays",
|
|
26
26
|
// Fee service api
|
|
27
|
-
|
|
27
|
+
fee_quote: "/fee_quote",
|
|
28
28
|
};
|
|
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;
|
|
@@ -77,7 +77,7 @@ class HydrogenClient {
|
|
|
77
77
|
getStats() {
|
|
78
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
79
|
this.checkState();
|
|
80
|
-
const request = this.apiManager.path(
|
|
80
|
+
const request = this.apiManager.path("stats");
|
|
81
81
|
const response = yield request.get();
|
|
82
82
|
return response.data;
|
|
83
83
|
});
|
|
@@ -85,7 +85,7 @@ class HydrogenClient {
|
|
|
85
85
|
getTransfers(req) {
|
|
86
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
87
|
this.checkState();
|
|
88
|
-
const request = this.apiManager.path(
|
|
88
|
+
const request = this.apiManager.path("transfer_payloads", {}, Object.assign(Object.assign({}, req), { include_tx: false }));
|
|
89
89
|
const response = yield request.get();
|
|
90
90
|
const result = response.data;
|
|
91
91
|
return Object.assign(Object.assign({}, result), { data: result.data.map(formatCrossChainTransfer) });
|
|
@@ -94,7 +94,7 @@ class HydrogenClient {
|
|
|
94
94
|
getDetailedTransfers(req) {
|
|
95
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
96
|
this.checkState();
|
|
97
|
-
const request = this.apiManager.path(
|
|
97
|
+
const request = this.apiManager.path("transfer_payloads", {}, Object.assign(Object.assign({}, req), { include_tx: true }));
|
|
98
98
|
const response = yield request.get();
|
|
99
99
|
const result = response.data;
|
|
100
100
|
return Object.assign(Object.assign({}, result), { data: result.data.map(formatCrossChainTransferDetailed) });
|
|
@@ -103,7 +103,7 @@ class HydrogenClient {
|
|
|
103
103
|
getRelaysTransfers(req) {
|
|
104
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
105
|
this.checkState();
|
|
106
|
-
const request = this.apiManager.path(
|
|
106
|
+
const request = this.apiManager.path("relays", {}, Object.assign(Object.assign({}, req), { include_tx: true }));
|
|
107
107
|
const response = yield request.get();
|
|
108
108
|
const result = response.data;
|
|
109
109
|
return Object.assign(Object.assign({}, result), { data: result.data.map(formatRelaysTransfers) });
|
|
@@ -112,7 +112,7 @@ class HydrogenClient {
|
|
|
112
112
|
getFeeQuote(req) {
|
|
113
113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
114
|
this.checkState();
|
|
115
|
-
const request = this.apiManager.path(
|
|
115
|
+
const request = this.apiManager.path("fee_quote", {}, Object.assign({}, req));
|
|
116
116
|
const response = yield request.get();
|
|
117
117
|
const result = response.data;
|
|
118
118
|
return formatFeeQuote(result);
|
|
@@ -29,7 +29,7 @@ class InsightsQueryClient {
|
|
|
29
29
|
console.error(e);
|
|
30
30
|
}
|
|
31
31
|
if (response.status >= 400 && response.status < 600) {
|
|
32
|
-
throw new util_1.APIUtils.RequestError(result, ((_b = (_a = result.data) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.message) ||
|
|
32
|
+
throw new util_1.APIUtils.RequestError(result, ((_b = (_a = result.data) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.message) || "unknown error");
|
|
33
33
|
}
|
|
34
34
|
return result;
|
|
35
35
|
});
|
|
@@ -37,14 +37,14 @@ class InsightsQueryClient {
|
|
|
37
37
|
// Chain api
|
|
38
38
|
Stake(req = {}) {
|
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
const request = this.apiManager.path(
|
|
40
|
+
const request = this.apiManager.path("chain/stake", {}, req);
|
|
41
41
|
const response = yield request.get();
|
|
42
42
|
return response.data;
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
Transaction(req = {}) {
|
|
46
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
const request = this.apiManager.path(
|
|
47
|
+
const request = this.apiManager.path("chain/transaction", {}, req);
|
|
48
48
|
const response = yield request.get();
|
|
49
49
|
return response.data;
|
|
50
50
|
});
|
|
@@ -52,9 +52,9 @@ class InsightsQueryClient {
|
|
|
52
52
|
AvgBlockTime(req) {
|
|
53
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
54
|
const queryParams = {
|
|
55
|
-
hours: req.hours
|
|
55
|
+
hours: req.hours,
|
|
56
56
|
};
|
|
57
|
-
const request = this.apiManager.path(
|
|
57
|
+
const request = this.apiManager.path("chain/blocktime", {}, queryParams);
|
|
58
58
|
const response = yield request.get();
|
|
59
59
|
return response.data;
|
|
60
60
|
});
|
|
@@ -62,28 +62,28 @@ class InsightsQueryClient {
|
|
|
62
62
|
// User api
|
|
63
63
|
ActiveAccounts(req = {}) {
|
|
64
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
const request = this.apiManager.path(
|
|
65
|
+
const request = this.apiManager.path("user/active", {}, req);
|
|
66
66
|
const response = yield request.get();
|
|
67
67
|
return response.data;
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
UserProfile(req) {
|
|
71
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
const request = this.apiManager.path(
|
|
72
|
+
const request = this.apiManager.path("user/profile", {}, req);
|
|
73
73
|
const response = yield request.get();
|
|
74
74
|
return response.data;
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
UserGrowth(req = {}) {
|
|
78
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
const request = this.apiManager.path(
|
|
79
|
+
const request = this.apiManager.path("user/growth", {}, req);
|
|
80
80
|
const response = yield request.get();
|
|
81
81
|
return response.data;
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
TotalUsers(req = {}) {
|
|
85
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
const request = this.apiManager.path(
|
|
86
|
+
const request = this.apiManager.path("user/total", {}, req);
|
|
87
87
|
const response = yield request.get();
|
|
88
88
|
return response.data;
|
|
89
89
|
});
|
|
@@ -91,7 +91,7 @@ class InsightsQueryClient {
|
|
|
91
91
|
// Pool api
|
|
92
92
|
Pools(req = {}) {
|
|
93
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const request = this.apiManager.path(
|
|
94
|
+
const request = this.apiManager.path("pool/list", {}, req);
|
|
95
95
|
const response = yield request.get();
|
|
96
96
|
return response.data;
|
|
97
97
|
});
|
|
@@ -99,11 +99,11 @@ class InsightsQueryClient {
|
|
|
99
99
|
PoolHistory(query) {
|
|
100
100
|
var _a, _b, _c;
|
|
101
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
const request = this.apiManager.path(
|
|
103
|
-
sort: (_a = query.sort) !== null && _a !== void 0 ? _a :
|
|
102
|
+
const request = this.apiManager.path("pool/history", {}, {
|
|
103
|
+
sort: (_a = query.sort) !== null && _a !== void 0 ? _a : "DESC",
|
|
104
104
|
limit: (_b = query.limit) !== null && _b !== void 0 ? _b : 100,
|
|
105
105
|
offset: (_c = query.offset) !== null && _c !== void 0 ? _c : 0,
|
|
106
|
-
poolId: query.poolId
|
|
106
|
+
poolId: query.poolId,
|
|
107
107
|
});
|
|
108
108
|
const response = yield request.get();
|
|
109
109
|
return response.data;
|
|
@@ -117,7 +117,7 @@ class InsightsQueryClient {
|
|
|
117
117
|
from: req.from,
|
|
118
118
|
until: req.until,
|
|
119
119
|
};
|
|
120
|
-
const request = this.apiManager.path(
|
|
120
|
+
const request = this.apiManager.path("pool/volume", routeParams, queryParams);
|
|
121
121
|
const response = yield request.get();
|
|
122
122
|
return response.data;
|
|
123
123
|
});
|
|
@@ -130,30 +130,30 @@ class InsightsQueryClient {
|
|
|
130
130
|
from: req.from,
|
|
131
131
|
until: req.until,
|
|
132
132
|
};
|
|
133
|
-
const request = this.apiManager.path(
|
|
133
|
+
const request = this.apiManager.path("pools/volume", {}, queryParams);
|
|
134
134
|
const response = yield request.get();
|
|
135
135
|
return response.data;
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
CompetitionList(req = {}) {
|
|
139
139
|
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
-
const request = this.apiManager.path(
|
|
140
|
+
const request = this.apiManager.path("competition/list", {}, req);
|
|
141
141
|
const response = yield request.get();
|
|
142
142
|
return response.data;
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
VolumeCompetitionLeaderboard(req) {
|
|
146
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
const queryParams = Object.assign(Object.assign(Object.assign({ competitionId: req.competitionId }, req.from && { from: req.from }), req.until && { until: req.until }), req.market && { market: req.market });
|
|
148
|
-
const request = this.apiManager.path(
|
|
147
|
+
const queryParams = Object.assign(Object.assign(Object.assign({ competitionId: req.competitionId }, (req.from && { from: req.from })), (req.until && { until: req.until })), (req.market && { market: req.market }));
|
|
148
|
+
const request = this.apiManager.path("competition/leaderboard", {}, queryParams);
|
|
149
149
|
const response = yield request.get();
|
|
150
150
|
return response.data;
|
|
151
151
|
});
|
|
152
152
|
}
|
|
153
153
|
PNLCompetitionLeaderboard(req) {
|
|
154
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
const queryParams = Object.assign({ competitionId: req.competitionId }, req.market && { market: req.market });
|
|
156
|
-
const request = this.apiManager.path(
|
|
155
|
+
const queryParams = Object.assign({ competitionId: req.competitionId }, (req.market && { market: req.market }));
|
|
156
|
+
const request = this.apiManager.path("competition/leaderboardpnl", {}, queryParams);
|
|
157
157
|
const response = yield request.get();
|
|
158
158
|
return response.data;
|
|
159
159
|
});
|
|
@@ -166,7 +166,7 @@ class InsightsQueryClient {
|
|
|
166
166
|
from: req.from,
|
|
167
167
|
until: req.until,
|
|
168
168
|
};
|
|
169
|
-
const request = this.apiManager.path(
|
|
169
|
+
const request = this.apiManager.path("pools/liquidity", {}, queryParams);
|
|
170
170
|
const response = yield request.get();
|
|
171
171
|
return response.data;
|
|
172
172
|
});
|
|
@@ -179,7 +179,7 @@ class InsightsQueryClient {
|
|
|
179
179
|
from: req.from,
|
|
180
180
|
until: req.until,
|
|
181
181
|
};
|
|
182
|
-
const request = this.apiManager.path(
|
|
182
|
+
const request = this.apiManager.path("market/volume", {}, queryParams);
|
|
183
183
|
const response = yield request.get();
|
|
184
184
|
return response.data;
|
|
185
185
|
});
|
|
@@ -187,7 +187,7 @@ class InsightsQueryClient {
|
|
|
187
187
|
// Node api
|
|
188
188
|
Nodes(req = {}) {
|
|
189
189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
-
const request = this.apiManager.path(
|
|
190
|
+
const request = this.apiManager.path("node/list", {}, req);
|
|
191
191
|
const response = yield request.get();
|
|
192
192
|
return response.data;
|
|
193
193
|
});
|
|
@@ -195,21 +195,21 @@ class InsightsQueryClient {
|
|
|
195
195
|
// Balance api
|
|
196
196
|
BalanceTotal(req) {
|
|
197
197
|
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
-
const request = this.apiManager.path(
|
|
198
|
+
const request = this.apiManager.path("balance/total", {}, req);
|
|
199
199
|
const response = yield request.get();
|
|
200
200
|
return response.data;
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
203
|
BalanceList(req) {
|
|
204
204
|
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
-
const request = this.apiManager.path(
|
|
205
|
+
const request = this.apiManager.path("balance/list", {}, req);
|
|
206
206
|
const response = yield request.get();
|
|
207
207
|
return response.data;
|
|
208
208
|
});
|
|
209
209
|
}
|
|
210
210
|
BalanceChange(req) {
|
|
211
211
|
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
-
const request = this.apiManager.path(
|
|
212
|
+
const request = this.apiManager.path("balance/change", req);
|
|
213
213
|
const response = yield request.get();
|
|
214
214
|
return response.data;
|
|
215
215
|
});
|
|
@@ -224,21 +224,21 @@ class InsightsQueryClient {
|
|
|
224
224
|
interval: req.interval,
|
|
225
225
|
limit: req.limit,
|
|
226
226
|
};
|
|
227
|
-
const request = this.apiManager.path(
|
|
227
|
+
const request = this.apiManager.path("balance/history", routeParams, queryParams);
|
|
228
228
|
const response = yield request.get();
|
|
229
229
|
return response.data;
|
|
230
230
|
});
|
|
231
231
|
}
|
|
232
232
|
BalanceSupply() {
|
|
233
233
|
return __awaiter(this, void 0, void 0, function* () {
|
|
234
|
-
const request = this.apiManager.path(
|
|
234
|
+
const request = this.apiManager.path("balance/supply");
|
|
235
235
|
const response = yield request.get();
|
|
236
236
|
return response.data;
|
|
237
237
|
});
|
|
238
238
|
}
|
|
239
239
|
BalanceDistribution(req = {}) {
|
|
240
240
|
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
-
const request = this.apiManager.path(
|
|
241
|
+
const request = this.apiManager.path("balance/distribution", {}, req);
|
|
242
242
|
const response = yield request.get();
|
|
243
243
|
return response.data;
|
|
244
244
|
});
|
|
@@ -247,10 +247,10 @@ class InsightsQueryClient {
|
|
|
247
247
|
LiquidationEngine(query) {
|
|
248
248
|
var _a, _b, _c;
|
|
249
249
|
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
-
const request = this.apiManager.path(
|
|
251
|
-
sort: (_a = query.sort) !== null && _a !== void 0 ? _a :
|
|
250
|
+
const request = this.apiManager.path("position/liquidation/engine", {}, {
|
|
251
|
+
sort: (_a = query.sort) !== null && _a !== void 0 ? _a : "DESC",
|
|
252
252
|
limit: (_b = query.limit) !== null && _b !== void 0 ? _b : 100,
|
|
253
|
-
offset: (_c = query.offset) !== null && _c !== void 0 ? _c : 0
|
|
253
|
+
offset: (_c = query.offset) !== null && _c !== void 0 ? _c : 0,
|
|
254
254
|
});
|
|
255
255
|
const response = yield request.get();
|
|
256
256
|
return response.data;
|
|
@@ -259,10 +259,10 @@ class InsightsQueryClient {
|
|
|
259
259
|
LiquidationAndADL(query) {
|
|
260
260
|
var _a, _b, _c;
|
|
261
261
|
return __awaiter(this, void 0, void 0, function* () {
|
|
262
|
-
const request = this.apiManager.path(
|
|
263
|
-
sort: (_a = query.sort) !== null && _a !== void 0 ? _a :
|
|
262
|
+
const request = this.apiManager.path("position/liquidation", {}, {
|
|
263
|
+
sort: (_a = query.sort) !== null && _a !== void 0 ? _a : "DESC",
|
|
264
264
|
limit: (_b = query.limit) !== null && _b !== void 0 ? _b : 100,
|
|
265
|
-
offset: (_c = query.offset) !== null && _c !== void 0 ? _c : 0
|
|
265
|
+
offset: (_c = query.offset) !== null && _c !== void 0 ? _c : 0,
|
|
266
266
|
});
|
|
267
267
|
const response = yield request.get();
|
|
268
268
|
return response.data;
|
|
@@ -271,11 +271,11 @@ class InsightsQueryClient {
|
|
|
271
271
|
PositionsView(req, query) {
|
|
272
272
|
var _a, _b, _c, _d;
|
|
273
273
|
return __awaiter(this, void 0, void 0, function* () {
|
|
274
|
-
const request = this.apiManager.path(
|
|
275
|
-
sort: (_a = query.sort) !== null && _a !== void 0 ? _a :
|
|
274
|
+
const request = this.apiManager.path("position/view", req, {
|
|
275
|
+
sort: (_a = query.sort) !== null && _a !== void 0 ? _a : "DESC",
|
|
276
276
|
limit: (_b = query.limit) !== null && _b !== void 0 ? _b : 100,
|
|
277
277
|
offset: (_c = query.offset) !== null && _c !== void 0 ? _c : 0,
|
|
278
|
-
market: (_d = query.market) !== null && _d !== void 0 ? _d :
|
|
278
|
+
market: (_d = query.market) !== null && _d !== void 0 ? _d : "",
|
|
279
279
|
});
|
|
280
280
|
const response = yield request.get();
|
|
281
281
|
return response.data;
|
|
@@ -284,12 +284,12 @@ class InsightsQueryClient {
|
|
|
284
284
|
Leaderboard(req, query) {
|
|
285
285
|
var _a, _b, _c, _d, _e;
|
|
286
286
|
return __awaiter(this, void 0, void 0, function* () {
|
|
287
|
-
const request = this.apiManager.path(
|
|
288
|
-
market: (_a = query.market) !== null && _a !== void 0 ? _a :
|
|
289
|
-
sort: (_b = query.sort) !== null && _b !== void 0 ? _b :
|
|
287
|
+
const request = this.apiManager.path("position/leaderboard", req, {
|
|
288
|
+
market: (_a = query.market) !== null && _a !== void 0 ? _a : "",
|
|
289
|
+
sort: (_b = query.sort) !== null && _b !== void 0 ? _b : "DESC",
|
|
290
290
|
limit: (_c = query.limit) !== null && _c !== void 0 ? _c : 100,
|
|
291
291
|
offset: (_d = query.offset) !== null && _d !== void 0 ? _d : 0,
|
|
292
|
-
address: (_e = query.address) !== null && _e !== void 0 ? _e :
|
|
292
|
+
address: (_e = query.address) !== null && _e !== void 0 ? _e : "",
|
|
293
293
|
});
|
|
294
294
|
const response = yield request.get();
|
|
295
295
|
return response.data;
|
|
@@ -298,7 +298,7 @@ class InsightsQueryClient {
|
|
|
298
298
|
//Coin Gecko Tokens
|
|
299
299
|
DenomToGeckoIdMap() {
|
|
300
300
|
return __awaiter(this, void 0, void 0, function* () {
|
|
301
|
-
const request = this.apiManager.path(
|
|
301
|
+
const request = this.apiManager.path("info/denom_gecko_map");
|
|
302
302
|
const response = yield request.get();
|
|
303
303
|
return response.data;
|
|
304
304
|
});
|
|
@@ -306,8 +306,8 @@ class InsightsQueryClient {
|
|
|
306
306
|
FundingHistory(query) {
|
|
307
307
|
var _a, _b, _c;
|
|
308
308
|
return __awaiter(this, void 0, void 0, function* () {
|
|
309
|
-
const request = this.apiManager.path(
|
|
310
|
-
market: (_a = query.market) !== null && _a !== void 0 ? _a :
|
|
309
|
+
const request = this.apiManager.path("market/funding", {}, {
|
|
310
|
+
market: (_a = query.market) !== null && _a !== void 0 ? _a : "",
|
|
311
311
|
limit: (_b = query.limit) !== null && _b !== void 0 ? _b : 100,
|
|
312
312
|
offset: (_c = query.offset) !== null && _c !== void 0 ? _c : 0,
|
|
313
313
|
});
|
package/lib/clients/N3Client.js
CHANGED
|
@@ -18,7 +18,6 @@ const address_1 = require("../util/address");
|
|
|
18
18
|
const blockchain_1 = require("../util/blockchain");
|
|
19
19
|
const neon_core_next_1 = require("@cityofzion/neon-core-next");
|
|
20
20
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
21
|
-
;
|
|
22
21
|
class N3Client {
|
|
23
22
|
constructor(configProvider, blockchain) {
|
|
24
23
|
var _a;
|
|
@@ -50,7 +49,7 @@ class N3Client {
|
|
|
50
49
|
};
|
|
51
50
|
}
|
|
52
51
|
static instance(opts) {
|
|
53
|
-
const { configProvider, blockchain = blockchain_1.Blockchain.Neo3
|
|
52
|
+
const { configProvider, blockchain = blockchain_1.Blockchain.Neo3 } = opts;
|
|
54
53
|
if (!N3Client.SUPPORTED_BLOCKCHAINS.includes(blockchain))
|
|
55
54
|
throw new Error(`unsupported blockchain - ${blockchain}`);
|
|
56
55
|
return new N3Client(configProvider, blockchain);
|
|
@@ -109,17 +108,21 @@ class N3Client {
|
|
|
109
108
|
const txn = new neon_core_next_1.tx.Transaction({
|
|
110
109
|
script,
|
|
111
110
|
validUntilBlock: currentHeight + 100,
|
|
112
|
-
signers: [
|
|
111
|
+
signers: [
|
|
112
|
+
{
|
|
113
113
|
account: signer.scriptHash,
|
|
114
114
|
scopes: neon_core_next_1.tx.WitnessScope.Global,
|
|
115
|
-
}
|
|
115
|
+
},
|
|
116
|
+
],
|
|
116
117
|
});
|
|
117
118
|
const networkFee = yield this.getNetworkFee(txn, 0);
|
|
118
119
|
txn.networkFee = networkFee;
|
|
119
|
-
const systemFee = yield this.getSystemFee(txn, 0, [
|
|
120
|
+
const systemFee = yield this.getSystemFee(txn, 0, [
|
|
121
|
+
{
|
|
120
122
|
account: signer.scriptHash,
|
|
121
123
|
scopes: neon_core_next_1.tx.WitnessScope.Global.toString(),
|
|
122
|
-
}
|
|
124
|
+
},
|
|
125
|
+
]);
|
|
123
126
|
txn.systemFee = systemFee;
|
|
124
127
|
if (amount.lt(feeAmount)) {
|
|
125
128
|
return false;
|
|
@@ -149,7 +152,7 @@ class N3Client {
|
|
|
149
152
|
}
|
|
150
153
|
lockO3Deposit(params) {
|
|
151
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
const { feeAmount, toAddressHex, amount, token, o3Wallet, signCompleteCallback
|
|
155
|
+
const { feeAmount, toAddressHex, amount, token, o3Wallet, signCompleteCallback } = params;
|
|
153
156
|
if (!o3Wallet.isConnected()) {
|
|
154
157
|
throw new Error("O3 wallet not connected. Please reconnect and try again.");
|
|
155
158
|
}
|
|
@@ -158,7 +161,7 @@ class N3Client {
|
|
|
158
161
|
const lockProxyScriptHash = neon_core_next_1.u.reverseHex(token.bridgeAddress);
|
|
159
162
|
const tokenScriptHash = neon_core_next_1.u.reverseHex(token.tokenAddress);
|
|
160
163
|
const fromAddressHex = o3Wallet.address;
|
|
161
|
-
const publicKeyOutput = yield o3Wallet.getPublicKeyOutput();
|
|
164
|
+
const publicKeyOutput = (yield o3Wallet.getPublicKeyOutput());
|
|
162
165
|
const accountScriptHash = address_1.N3Address.publicKeyToScriptHash(publicKeyOutput.publicKey);
|
|
163
166
|
const feeAddress = feeAmount.isZero() ? "" : neon_core_next_1.u.HexString.fromHex(networkConfig.feeAddress).toBase64();
|
|
164
167
|
const args = [
|
|
@@ -175,17 +178,19 @@ class N3Client {
|
|
|
175
178
|
scriptHash: lockProxyScriptHash,
|
|
176
179
|
args,
|
|
177
180
|
network: o3Wallet.neoNetwork,
|
|
178
|
-
signers: [
|
|
181
|
+
signers: [
|
|
182
|
+
{
|
|
179
183
|
account: accountScriptHash,
|
|
180
184
|
scopes: neon_core_next_1.tx.WitnessScope.Global,
|
|
181
|
-
}
|
|
185
|
+
},
|
|
186
|
+
],
|
|
182
187
|
});
|
|
183
188
|
return result.txid;
|
|
184
189
|
});
|
|
185
190
|
}
|
|
186
191
|
lockLedgerDeposit(params) {
|
|
187
192
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
const { feeAmount, toAddressHex, amount, token, ledger, signCompleteCallback
|
|
193
|
+
const { feeAmount, toAddressHex, amount, token, ledger, signCompleteCallback } = params;
|
|
189
194
|
const scriptHash = neon_core_next_1.u.reverseHex(token.bridgeAddress);
|
|
190
195
|
const tokenScriptHash = neon_core_next_1.u.reverseHex(token.tokenAddress);
|
|
191
196
|
const fromAddressHex = ledger.displayAddress;
|
|
@@ -209,9 +214,7 @@ class N3Client {
|
|
|
209
214
|
const transactionByteSize = txn.serialize().length / 2 + 109;
|
|
210
215
|
// Hardcoded. Running a witness is always the same cost for the basic account.
|
|
211
216
|
const witnessProcessingFee = new bignumber_js_1.default(1000390);
|
|
212
|
-
const networkFeeEstimate = feePerByte
|
|
213
|
-
.times(transactionByteSize)
|
|
214
|
-
.plus(witnessProcessingFee);
|
|
217
|
+
const networkFeeEstimate = feePerByte.times(transactionByteSize).plus(witnessProcessingFee);
|
|
215
218
|
if (networkFee && networkFee >= networkFeeEstimate.toNumber()) {
|
|
216
219
|
return neon_core_next_1.u.BigInteger.fromNumber(networkFee);
|
|
217
220
|
}
|
|
@@ -250,29 +253,29 @@ class N3Client {
|
|
|
250
253
|
return __awaiter(this, void 0, void 0, function* () {
|
|
251
254
|
const result = yield this.rpcClient.executeAll([
|
|
252
255
|
new neon_core_next_1.rpc.Query({
|
|
253
|
-
method:
|
|
254
|
-
params: [address,
|
|
256
|
+
method: "invokefunction",
|
|
257
|
+
params: [address, "decimals"],
|
|
255
258
|
}),
|
|
256
259
|
new neon_core_next_1.rpc.Query({
|
|
257
|
-
method:
|
|
258
|
-
params: [address,
|
|
260
|
+
method: "invokefunction",
|
|
261
|
+
params: [address, "symbol"],
|
|
259
262
|
}),
|
|
260
263
|
new neon_core_next_1.rpc.Query({
|
|
261
|
-
method:
|
|
264
|
+
method: "getcontractstate",
|
|
262
265
|
params: [address],
|
|
263
266
|
}),
|
|
264
267
|
]);
|
|
265
268
|
const [decimalRaw, symbolRaw, nameRaw] = result;
|
|
266
269
|
let decimals = 0;
|
|
267
|
-
let symbol =
|
|
268
|
-
let name =
|
|
269
|
-
if (typeof decimalRaw.stack[0].value ===
|
|
270
|
+
let symbol = "";
|
|
271
|
+
let name = "";
|
|
272
|
+
if (typeof decimalRaw.stack[0].value === "string") {
|
|
270
273
|
decimals = Number(decimalRaw.stack[0].value);
|
|
271
274
|
}
|
|
272
|
-
if (typeof symbolRaw.stack[0].value ===
|
|
273
|
-
symbol = Buffer.from(symbolRaw.stack[0].value,
|
|
275
|
+
if (typeof symbolRaw.stack[0].value === "string") {
|
|
276
|
+
symbol = Buffer.from(symbolRaw.stack[0].value, "base64").toString("ascii");
|
|
274
277
|
}
|
|
275
|
-
if (typeof nameRaw.manifest.name ===
|
|
278
|
+
if (typeof nameRaw.manifest.name === "string") {
|
|
276
279
|
name = nameRaw.manifest.name;
|
|
277
280
|
}
|
|
278
281
|
return { name, symbol, address, decimals };
|