carbon-js-sdk 0.4.32 → 0.4.33
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.d.ts +26 -0
- package/lib/clients/BatchQueryClient.js +100 -0
- package/lib/clients/CarbonQueryClient.js +2 -2
- package/lib/clients/ETHClient.js +15 -15
- package/lib/clients/HydrogenClient.js +1 -1
- package/lib/clients/NEOClient.js +7 -7
- package/lib/clients/TokenClient.js +3 -3
- package/lib/clients/ZILClient.js +17 -17
- package/lib/codec/cdp/cdp_liquidations.d.ts +32 -0
- package/lib/codec/cdp/cdp_liquidations.js +288 -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/erc20/erc20.d.ts +41 -0
- package/lib/codec/erc20/erc20.js +144 -0
- package/lib/codec/erc20/events.d.ts +76 -0
- package/lib/codec/erc20/events.js +330 -0
- package/lib/codec/erc20/genesis.d.ts +40 -0
- package/lib/codec/erc20/genesis.js +139 -0
- package/lib/codec/erc20/query.d.ts +117 -0
- package/lib/codec/erc20/query.js +333 -0
- package/lib/codec/erc20/tx.d.ts +232 -0
- package/lib/codec/erc20/tx.js +765 -0
- package/lib/codec/ethermint/crypto/v1/ethsecp256k1/export.d.ts +1 -0
- package/lib/codec/ethermint/crypto/v1/ethsecp256k1/export.js +6 -0
- package/lib/codec/ethermint/evm/v1/export.d.ts +5 -0
- package/lib/codec/ethermint/evm/v1/export.js +53 -0
- package/lib/codec/ethermint/feemarket/v1/export.d.ts +4 -0
- package/lib/codec/ethermint/feemarket/v1/export.js +18 -0
- package/lib/codec/ethermint/types/v1/export.d.ts +4 -0
- package/lib/codec/ethermint/types/v1/export.js +11 -0
- package/lib/codec/ethermint-models.d.ts +4 -0
- package/lib/codec/ethermint-models.js +26 -0
- package/lib/codec/evmmerge/address.d.ts +19 -0
- package/lib/codec/evmmerge/address.js +75 -0
- package/lib/codec/market/fee.d.ts +123 -0
- package/lib/codec/market/fee.js +334 -0
- package/lib/codec/perpsliquidity/event.d.ts +103 -0
- package/lib/codec/perpsliquidity/event.js +596 -0
- package/lib/codec/perpsliquidity/genesis.d.ts +35 -0
- package/lib/codec/perpsliquidity/genesis.js +162 -0
- package/lib/codec/perpsliquidity/params.d.ts +22 -0
- package/lib/codec/perpsliquidity/params.js +86 -0
- package/lib/codec/perpsliquidity/pool.d.ts +155 -0
- package/lib/codec/perpsliquidity/pool.js +871 -0
- package/lib/codec/perpsliquidity/query.d.ts +194 -0
- package/lib/codec/perpsliquidity/query.js +876 -0
- package/lib/codec/perpsliquidity/tx.d.ts +202 -0
- package/lib/codec/perpsliquidity/tx.js +970 -0
- package/lib/constant/eip712.d.ts +46 -0
- package/lib/constant/eip712.js +106 -0
- package/lib/constant/generic.js +1 -1
- package/lib/insights/delegation.d.ts +26 -0
- package/lib/insights/delegation.js +2 -0
- package/lib/insights/oracles.d.ts +17 -0
- package/lib/insights/oracles.js +2 -0
- package/lib/modules/cdp.js +44 -44
- package/lib/modules/cosmwasm.js +1 -1
- package/lib/modules/erc20.d.ts +26 -0
- package/lib/modules/erc20.js +79 -0
- package/lib/modules/evm.d.ts +46 -0
- package/lib/modules/evm.js +127 -0
- package/lib/modules/evmmerge.d.ts +12 -0
- package/lib/modules/evmmerge.js +35 -0
- package/lib/modules/feemarket.d.ts +20 -0
- package/lib/modules/feemarket.js +45 -0
- package/lib/modules/gov.js +12 -12
- package/lib/modules/ibc.d.ts +2 -1
- package/lib/modules/ibc.js +2 -2
- package/lib/modules/liquiditypool.js +1 -1
- package/lib/modules/perpsliquidity.d.ts +51 -0
- package/lib/modules/perpsliquidity.js +129 -0
- 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/erc20.d.ts +4 -0
- package/lib/provider/amino/types/erc20.js +40 -0
- package/lib/provider/amino/types/evm.d.ts +4 -0
- package/lib/provider/amino/types/evm.js +40 -0
- package/lib/provider/amino/types/evmmerge.d.ts +4 -0
- package/lib/provider/amino/types/evmmerge.js +34 -0
- package/lib/provider/amino/types/feemarket.d.ts +4 -0
- package/lib/provider/amino/types/feemarket.js +34 -0
- 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/perpsliquidity.d.ts +4 -0
- package/lib/provider/amino/types/perpsliquidity.js +73 -0
- package/lib/provider/amino/types/position.js +1 -1
- package/lib/provider/amino/types/profile.js +1 -1
- package/lib/provider/amino/types/staking.js +4 -4
- package/lib/provider/amino/types/subaccount.js +3 -3
- package/lib/provider/amino/utils.js +11 -11
- package/lib/provider/ledger/ledger.js +2 -2
- package/lib/provider/metamask/MetaMask.js +1 -1
- package/lib/provider/metamask/legacy-accounts.d.ts +11 -0
- package/lib/provider/metamask/legacy-accounts.js +2233 -0
- 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/eip712.d.ts +10 -0
- package/lib/util/eip712.js +195 -0
- package/lib/util/ethermint.d.ts +8 -0
- package/lib/util/ethermint.js +70 -0
- package/lib/util/fetch.js +1 -1
- package/lib/util/generic.js +3 -3
- package/lib/util/legacyEIP712.d.ts +20 -0
- package/lib/util/legacyEIP712.js +98 -0
- 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
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { JsonRpcRequest, JsonRpcSuccessResponse } from "@cosmjs/json-rpc";
|
|
2
|
+
import { HttpEndpoint } from "@cosmjs/tendermint-rpc/build/rpcclients/httpclient";
|
|
3
|
+
import { RpcClient } from "@cosmjs/tendermint-rpc/build/rpcclients/rpcclient";
|
|
4
|
+
export interface BatchQueryClientOptions {
|
|
5
|
+
/** Interval for dispatching batches (in milliseconds) */
|
|
6
|
+
dispatchInterval: number;
|
|
7
|
+
/** Max number of items sent in one request */
|
|
8
|
+
batchSizeLimit: number;
|
|
9
|
+
}
|
|
10
|
+
declare class BatchQueryClient implements RpcClient {
|
|
11
|
+
protected readonly url: string;
|
|
12
|
+
protected readonly headers: Record<string, string> | undefined;
|
|
13
|
+
protected readonly options: BatchQueryClientOptions;
|
|
14
|
+
private timer?;
|
|
15
|
+
private readonly queue;
|
|
16
|
+
constructor(endpoint: string | HttpEndpoint, options?: Partial<BatchQueryClientOptions>);
|
|
17
|
+
disconnect(): void;
|
|
18
|
+
execute(request: JsonRpcRequest): Promise<JsonRpcSuccessResponse>;
|
|
19
|
+
private validate;
|
|
20
|
+
/**
|
|
21
|
+
* This is called in an interval where promise rejections cannot be handled.
|
|
22
|
+
* So this is not async and HTTP errors need to be handled by the queued promises.
|
|
23
|
+
*/
|
|
24
|
+
private tick;
|
|
25
|
+
}
|
|
26
|
+
export default BatchQueryClient;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const json_rpc_1 = require("@cosmjs/json-rpc");
|
|
13
|
+
const http_1 = require("@cosmjs/tendermint-rpc/build/rpcclients/http");
|
|
14
|
+
const rpcclient_1 = require("@cosmjs/tendermint-rpc/build/rpcclients/rpcclient");
|
|
15
|
+
// Those values are private and can change any time.
|
|
16
|
+
// Does a user need to know them? I don't think so. You either set
|
|
17
|
+
// a custom value or leave the option field unset.
|
|
18
|
+
const defaultBatchQueryClientOptions = {
|
|
19
|
+
dispatchInterval: 20,
|
|
20
|
+
batchSizeLimit: 20,
|
|
21
|
+
};
|
|
22
|
+
class BatchQueryClient {
|
|
23
|
+
constructor(endpoint, options = {}) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
this.queue = [];
|
|
26
|
+
this.options = {
|
|
27
|
+
batchSizeLimit: (_a = options.batchSizeLimit) !== null && _a !== void 0 ? _a : defaultBatchQueryClientOptions.batchSizeLimit,
|
|
28
|
+
dispatchInterval: (_b = options.dispatchInterval) !== null && _b !== void 0 ? _b : defaultBatchQueryClientOptions.dispatchInterval,
|
|
29
|
+
};
|
|
30
|
+
if (typeof endpoint === "string") {
|
|
31
|
+
// accept host.name:port and assume http protocol
|
|
32
|
+
this.url = rpcclient_1.hasProtocol(endpoint) ? endpoint : "http://" + endpoint;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
this.url = endpoint.url;
|
|
36
|
+
this.headers = endpoint.headers;
|
|
37
|
+
}
|
|
38
|
+
this.timer = (setInterval(() => this.tick(), options.dispatchInterval));
|
|
39
|
+
this.validate();
|
|
40
|
+
}
|
|
41
|
+
disconnect() {
|
|
42
|
+
this.timer && clearInterval(this.timer);
|
|
43
|
+
this.timer = undefined;
|
|
44
|
+
}
|
|
45
|
+
execute(request) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
this.queue.push({ request, resolve, reject });
|
|
49
|
+
if (this.queue.length >= this.options.batchSizeLimit) {
|
|
50
|
+
// this train is full, let's go
|
|
51
|
+
this.tick();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
validate() {
|
|
57
|
+
if (!this.options.batchSizeLimit ||
|
|
58
|
+
!Number.isSafeInteger(this.options.batchSizeLimit) ||
|
|
59
|
+
this.options.batchSizeLimit < 1) {
|
|
60
|
+
throw new Error("batchSizeLimit must be a safe integer >= 1");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* This is called in an interval where promise rejections cannot be handled.
|
|
65
|
+
* So this is not async and HTTP errors need to be handled by the queued promises.
|
|
66
|
+
*/
|
|
67
|
+
tick() {
|
|
68
|
+
// Avoid race conditions
|
|
69
|
+
const batch = this.queue.splice(0, this.options.batchSizeLimit);
|
|
70
|
+
if (!batch.length)
|
|
71
|
+
return;
|
|
72
|
+
const requests = batch.map((s) => s.request);
|
|
73
|
+
const requestIds = requests.map((request) => request.id);
|
|
74
|
+
http_1.http("POST", this.url, this.headers, requests).then((raw) => {
|
|
75
|
+
// Requests with a single entry return as an object
|
|
76
|
+
const arr = Array.isArray(raw) ? raw : [raw];
|
|
77
|
+
arr.forEach((el, i) => {
|
|
78
|
+
const req = batch[i];
|
|
79
|
+
if (!req)
|
|
80
|
+
return;
|
|
81
|
+
const { reject, resolve } = req;
|
|
82
|
+
const response = json_rpc_1.parseJsonRpcResponse(el);
|
|
83
|
+
if (json_rpc_1.isJsonRpcErrorResponse(response)) {
|
|
84
|
+
reject(new Error(JSON.stringify(response.error)));
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
resolve(response);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}, (error) => {
|
|
91
|
+
for (const requestId of requestIds) {
|
|
92
|
+
const req = batch.find((s) => s.request.id === requestId);
|
|
93
|
+
if (!req)
|
|
94
|
+
return;
|
|
95
|
+
req.reject(error);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.default = BatchQueryClient;
|
|
@@ -48,7 +48,7 @@ class CarbonQueryClient {
|
|
|
48
48
|
constructor(tmClient) {
|
|
49
49
|
this.tmClient = tmClient;
|
|
50
50
|
this.baseClient = new stargate_1.QueryClient(this.tmClient);
|
|
51
|
-
const rpcClient =
|
|
51
|
+
const rpcClient = stargate_1.createProtobufRpcClient(this.baseClient);
|
|
52
52
|
this.chain = BlockchainClient_1.default.connectWithTm(this.tmClient);
|
|
53
53
|
this.adl = new query_1.QueryClientImpl(rpcClient);
|
|
54
54
|
this.alliance = new query_39.QueryClientImpl(rpcClient);
|
|
@@ -93,7 +93,7 @@ class CarbonQueryClient {
|
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
95
|
getProtobufRpcClient() {
|
|
96
|
-
return
|
|
96
|
+
return stargate_1.createProtobufRpcClient(this.baseClient);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
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() {
|
|
@@ -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() {
|
|
@@ -570,7 +570,7 @@ class TokenClient {
|
|
|
570
570
|
if (!token)
|
|
571
571
|
return undefined;
|
|
572
572
|
const bridge = this.getBridgeFromToken(token);
|
|
573
|
-
if (!bridge || !
|
|
573
|
+
if (!bridge || !blockchain_1.isIbcBridge(bridge))
|
|
574
574
|
return undefined;
|
|
575
575
|
return bridge.chain_id_name;
|
|
576
576
|
}
|
|
@@ -579,7 +579,7 @@ class TokenClient {
|
|
|
579
579
|
// get swth on osmosis
|
|
580
580
|
const osmoTmClient = yield tendermint_rpc_1.Tendermint34Client.connect(network_1.publicRpcNodes.Osmosis);
|
|
581
581
|
const osmoClient = new stargate_1.QueryClient(osmoTmClient);
|
|
582
|
-
const osmosRpcClient =
|
|
582
|
+
const osmosRpcClient = stargate_1.createProtobufRpcClient(osmoClient);
|
|
583
583
|
const osmoIbcClient = new query_1.QueryClientImpl(osmosRpcClient);
|
|
584
584
|
const osmoDenomTraces = yield osmoIbcClient.DenomTraces({
|
|
585
585
|
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() {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import Long from "long";
|
|
2
|
+
import _m0 from "protobufjs/minimal";
|
|
3
|
+
export declare const protobufPackage = "Switcheo.carbon.cdp";
|
|
4
|
+
export interface CDPLiquidations {
|
|
5
|
+
id: Long;
|
|
6
|
+
liquidator: string;
|
|
7
|
+
debtor: string;
|
|
8
|
+
collateralDenom: string;
|
|
9
|
+
collateralAmountLiquidated: string;
|
|
10
|
+
collateralAmountLiquidator: string;
|
|
11
|
+
collateralAmountFee: string;
|
|
12
|
+
liquidationPrice: string;
|
|
13
|
+
marketPrice: string;
|
|
14
|
+
discount: string;
|
|
15
|
+
debtDenom: string;
|
|
16
|
+
debtAmount: string;
|
|
17
|
+
blockHeight: Long;
|
|
18
|
+
blockTime?: Date;
|
|
19
|
+
transactionHash: string;
|
|
20
|
+
}
|
|
21
|
+
export declare const CDPLiquidations: {
|
|
22
|
+
encode(message: CDPLiquidations, writer?: _m0.Writer): _m0.Writer;
|
|
23
|
+
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): CDPLiquidations;
|
|
24
|
+
fromJSON(object: any): CDPLiquidations;
|
|
25
|
+
toJSON(message: CDPLiquidations): unknown;
|
|
26
|
+
fromPartial(object: DeepPartial<CDPLiquidations>): CDPLiquidations;
|
|
27
|
+
};
|
|
28
|
+
declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
29
|
+
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 {} ? {
|
|
30
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
31
|
+
} : Partial<T>;
|
|
32
|
+
export {};
|