carbon-js-sdk 0.3.4 → 0.3.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/CarbonQueryClient.js +2 -2
- package/lib/clients/CarbonTendermintClient.d.ts +117 -0
- package/lib/clients/CarbonTendermintClient.js +376 -0
- package/lib/clients/ETHClient.js +15 -15
- package/lib/clients/HydrogenClient.js +1 -1
- package/lib/clients/N3Client.js +3 -2
- package/lib/clients/NEOClient.js +8 -7
- package/lib/clients/ZILClient.js +16 -16
- package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
- package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
- package/lib/codec/cosmos/tx/v1beta1/tx.js +2 -2
- package/lib/constant/address.d.ts +1 -0
- package/lib/constant/address.js +2 -1
- package/lib/constant/generic.js +1 -1
- package/lib/modules/cdp.js +43 -43
- package/lib/modules/gov.js +14 -14
- package/lib/modules/liquiditypool.js +1 -1
- package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
- package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
- package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +1 -1
- package/lib/provider/amino/types/admin.js +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 +4 -4
- package/lib/provider/amino/types/ibc.js +1 -1
- package/lib/provider/amino/types/leverage.js +1 -1
- package/lib/provider/amino/types/liquidityPool.js +7 -7
- package/lib/provider/amino/types/market.js +1 -1
- package/lib/provider/amino/types/oracle.js +1 -1
- package/lib/provider/amino/types/order.js +4 -4
- package/lib/provider/amino/types/position.js +1 -1
- package/lib/provider/amino/types/profile.js +1 -1
- package/lib/provider/amino/types/staking.js +4 -4
- package/lib/provider/amino/types/subaccount.js +3 -3
- package/lib/provider/amino/utils.js +11 -11
- package/lib/provider/keplr/KeplrStore.js +1 -1
- package/lib/provider/ledger/ledger.js +2 -2
- package/lib/provider/metamask/MetaMask.js +1 -1
- package/lib/provider/o3/O3Wallet.js +2 -2
- package/lib/util/address.js +13 -13
- package/lib/util/api.js +4 -4
- package/lib/util/fetch.js +1 -1
- package/lib/util/generic.js +3 -3
- package/lib/util/number.js +5 -5
- package/lib/wallet/CarbonSigner.js +2 -2
- package/lib/wallet/CarbonSigningClient.js +8 -8
- package/lib/wallet/CarbonTendermintClient.js +376 -0
- package/lib/wallet/CarbonWallet.js +6 -6
- package/lib/websocket/connector.js +3 -3
- package/package.json +1 -1
- package/lib/codec/bank/tx.d.ts +0 -64
- package/lib/codec/bank/tx.js +0 -236
|
@@ -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 = stargate_1.createProtobufRpcClient(this.baseClient);
|
|
47
|
+
const rpcClient = (0, 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 stargate_1.createProtobufRpcClient(this.baseClient);
|
|
88
|
+
return (0, stargate_1.createProtobufRpcClient)(this.baseClient);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
exports.default = CarbonQueryClient;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Stream } from "xstream";
|
|
2
|
+
import { JsonRpcSuccessResponse } from "@cosmjs/json-rpc/build/types";
|
|
3
|
+
import * as requests from "@cosmjs/tendermint-rpc/build/tendermint34/requests";
|
|
4
|
+
import * as responses from "@cosmjs/tendermint-rpc/build/tendermint34/responses";
|
|
5
|
+
export interface SubscriptionEvent {
|
|
6
|
+
readonly query: string;
|
|
7
|
+
readonly data: {
|
|
8
|
+
readonly type: string;
|
|
9
|
+
readonly value: any;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare type JsonRpcId = number | string;
|
|
13
|
+
export interface JsonRpcRequest {
|
|
14
|
+
readonly jsonrpc: "2.0";
|
|
15
|
+
readonly id: JsonRpcId;
|
|
16
|
+
readonly method: string;
|
|
17
|
+
readonly params: JsonCompatibleArray | JsonCompatibleDictionary;
|
|
18
|
+
}
|
|
19
|
+
export interface JsonCompatibleArray extends ReadonlyArray<JsonCompatibleValue> {
|
|
20
|
+
}
|
|
21
|
+
export interface JsonCompatibleDictionary {
|
|
22
|
+
readonly [key: string]: JsonCompatibleValue | readonly JsonCompatibleValue[];
|
|
23
|
+
}
|
|
24
|
+
export declare type JsonCompatibleValue = JsonCompatibleDictionary | JsonCompatibleArray | string | number | boolean | null;
|
|
25
|
+
export interface RpcClient {
|
|
26
|
+
readonly execute: (request: JsonRpcRequest) => Promise<JsonRpcSuccessResponse>;
|
|
27
|
+
readonly disconnect: () => void;
|
|
28
|
+
}
|
|
29
|
+
export declare function instanceOfRpcStreamingClient(client: RpcClient): client is RpcStreamingClient;
|
|
30
|
+
export interface RpcStreamingClient extends RpcClient {
|
|
31
|
+
readonly listen: (request: JsonRpcRequest) => Stream<SubscriptionEvent>;
|
|
32
|
+
}
|
|
33
|
+
export default class CarbonTendermintClient {
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new Tendermint client for the given endpoint.
|
|
36
|
+
*
|
|
37
|
+
* Uses HTTP when the URL schema is http or https. Uses WebSockets otherwise.
|
|
38
|
+
*/
|
|
39
|
+
static connect(endpoint: string): Promise<CarbonTendermintClient>;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new Tendermint client given an RPC client.
|
|
42
|
+
*/
|
|
43
|
+
static create(rpcClient: RpcClient): Promise<CarbonTendermintClient>;
|
|
44
|
+
private static detectVersion;
|
|
45
|
+
private readonly client;
|
|
46
|
+
private readonly p;
|
|
47
|
+
private readonly r;
|
|
48
|
+
/**
|
|
49
|
+
* Use `CarbonTendermintClient.connect` or `CarbonTendermintClient.create` to create an instance.
|
|
50
|
+
*/
|
|
51
|
+
private constructor();
|
|
52
|
+
disconnect(): void;
|
|
53
|
+
abciInfo(): Promise<responses.AbciInfoResponse>;
|
|
54
|
+
abciQuery(params: requests.AbciQueryParams): Promise<responses.AbciQueryResponse>;
|
|
55
|
+
block(height?: number): Promise<responses.BlockResponse>;
|
|
56
|
+
blockResults(height?: number): Promise<responses.BlockResultsResponse>;
|
|
57
|
+
/**
|
|
58
|
+
* Search for events that are in a block.
|
|
59
|
+
*
|
|
60
|
+
* NOTE
|
|
61
|
+
* This method will error on any node that is running a Tendermint version lower than 0.34.9.
|
|
62
|
+
*
|
|
63
|
+
* @see https://docs.tendermint.com/master/rpc/#/Info/block_search
|
|
64
|
+
*/
|
|
65
|
+
blockSearch(params: requests.BlockSearchParams): Promise<responses.BlockSearchResponse>;
|
|
66
|
+
blockSearchAll(params: requests.BlockSearchParams): Promise<responses.BlockSearchResponse>;
|
|
67
|
+
/**
|
|
68
|
+
* Queries block headers filtered by minHeight <= height <= maxHeight.
|
|
69
|
+
*
|
|
70
|
+
* @param minHeight The minimum height to be included in the result. Defaults to 0.
|
|
71
|
+
* @param maxHeight The maximum height to be included in the result. Defaults to infinity.
|
|
72
|
+
*/
|
|
73
|
+
blockchain(minHeight?: number, maxHeight?: number): Promise<responses.BlockchainResponse>;
|
|
74
|
+
/**
|
|
75
|
+
* Broadcast transaction to mempool and wait for response
|
|
76
|
+
*
|
|
77
|
+
* @see https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_sync
|
|
78
|
+
*/
|
|
79
|
+
broadcastTxSync(params: requests.BroadcastTxParams): Promise<responses.BroadcastTxSyncResponse>;
|
|
80
|
+
/**
|
|
81
|
+
* Broadcast transaction to mempool and do not wait for result
|
|
82
|
+
*
|
|
83
|
+
* @see https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_async
|
|
84
|
+
*/
|
|
85
|
+
broadcastTxAsync(params: requests.BroadcastTxParams): Promise<responses.BroadcastTxAsyncResponse>;
|
|
86
|
+
/**
|
|
87
|
+
* Broadcast transaction to mempool and wait for block
|
|
88
|
+
*
|
|
89
|
+
* @see https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_commit
|
|
90
|
+
*/
|
|
91
|
+
broadcastTxCommit(params: requests.BroadcastTxParams): Promise<responses.BroadcastTxCommitResponse>;
|
|
92
|
+
commit(height?: number): Promise<responses.CommitResponse>;
|
|
93
|
+
genesis(): Promise<responses.GenesisResponse>;
|
|
94
|
+
health(): Promise<responses.HealthResponse>;
|
|
95
|
+
numUnconfirmedTxs(): Promise<responses.NumUnconfirmedTxsResponse>;
|
|
96
|
+
status(): Promise<responses.StatusResponse>;
|
|
97
|
+
subscribeNewBlock(): Stream<responses.NewBlockEvent>;
|
|
98
|
+
subscribeNewBlockHeader(): Stream<responses.NewBlockHeaderEvent>;
|
|
99
|
+
subscribeTx(query?: string): Stream<responses.TxEvent>;
|
|
100
|
+
/**
|
|
101
|
+
* Get a single transaction by hash
|
|
102
|
+
*
|
|
103
|
+
* @see https://docs.tendermint.com/master/rpc/#/Info/tx
|
|
104
|
+
*/
|
|
105
|
+
tx(params: requests.TxParams): Promise<responses.TxResponse>;
|
|
106
|
+
/**
|
|
107
|
+
* Search for transactions that are in a block
|
|
108
|
+
*
|
|
109
|
+
* @see https://docs.tendermint.com/master/rpc/#/Info/tx_search
|
|
110
|
+
*/
|
|
111
|
+
txSearch(params: requests.TxSearchParams): Promise<responses.TxSearchResponse>;
|
|
112
|
+
txSearchAll(params: requests.TxSearchParams): Promise<responses.TxSearchResponse>;
|
|
113
|
+
validators(params: requests.ValidatorsParams): Promise<responses.ValidatorsResponse>;
|
|
114
|
+
validatorsAll(height?: number): Promise<responses.ValidatorsResponse>;
|
|
115
|
+
private doCall;
|
|
116
|
+
private subscribe;
|
|
117
|
+
}
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.instanceOfRpcStreamingClient = void 0;
|
|
32
|
+
const jsonrpc_1 = require("@cosmjs/tendermint-rpc/build/jsonrpc");
|
|
33
|
+
const httpclient_1 = require("@cosmjs/tendermint-rpc/build/rpcclients/httpclient");
|
|
34
|
+
const adaptor_1 = require("@cosmjs/tendermint-rpc/build/tendermint34/adaptor");
|
|
35
|
+
const requests = __importStar(require("@cosmjs/tendermint-rpc/build/tendermint34/requests"));
|
|
36
|
+
function instanceOfRpcStreamingClient(client) {
|
|
37
|
+
return typeof client.listen === "function";
|
|
38
|
+
}
|
|
39
|
+
exports.instanceOfRpcStreamingClient = instanceOfRpcStreamingClient;
|
|
40
|
+
class CarbonTendermintClient {
|
|
41
|
+
/**
|
|
42
|
+
* Use `CarbonTendermintClient.connect` or `CarbonTendermintClient.create` to create an instance.
|
|
43
|
+
*/
|
|
44
|
+
constructor(client) {
|
|
45
|
+
this.client = client;
|
|
46
|
+
this.p = adaptor_1.adaptor34.params;
|
|
47
|
+
this.r = adaptor_1.adaptor34.responses;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new Tendermint client for the given endpoint.
|
|
51
|
+
*
|
|
52
|
+
* Uses HTTP when the URL schema is http or https. Uses WebSockets otherwise.
|
|
53
|
+
*/
|
|
54
|
+
static connect(endpoint) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const useHttp = endpoint.startsWith("http://") || endpoint.startsWith("https://");
|
|
57
|
+
if (!useHttp) {
|
|
58
|
+
throw new Error('this client only uses httpClient.');
|
|
59
|
+
}
|
|
60
|
+
const rpcClient = new httpclient_1.HttpClient(endpoint);
|
|
61
|
+
return CarbonTendermintClient.create(rpcClient);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new Tendermint client given an RPC client.
|
|
66
|
+
*/
|
|
67
|
+
static create(rpcClient) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
// For some very strange reason I don't understand, tests start to fail on some systems
|
|
70
|
+
// (our CI) when skipping the status call before doing other queries. Sleeping a little
|
|
71
|
+
// while did not help. Thus we query the version as a way to say "hi" to the backend,
|
|
72
|
+
// even in cases where we don't use the result.
|
|
73
|
+
const _version = yield this.detectVersion(rpcClient);
|
|
74
|
+
return new CarbonTendermintClient(rpcClient);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
static detectVersion(client) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const req = (0, jsonrpc_1.createJsonRpcRequest)(requests.Method.Status);
|
|
80
|
+
const response = yield client.execute(req);
|
|
81
|
+
const result = response.result;
|
|
82
|
+
if (!result || !result.node_info) {
|
|
83
|
+
throw new Error("Unrecognized format for status response");
|
|
84
|
+
}
|
|
85
|
+
const version = result.node_info.version;
|
|
86
|
+
if (typeof version !== "string") {
|
|
87
|
+
throw new Error("Unrecognized version format: must be string");
|
|
88
|
+
}
|
|
89
|
+
return version;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
disconnect() {
|
|
93
|
+
this.client.disconnect();
|
|
94
|
+
}
|
|
95
|
+
abciInfo() {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const query = { method: requests.Method.AbciInfo };
|
|
98
|
+
return this.doCall(query, this.p.encodeAbciInfo, this.r.decodeAbciInfo);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
abciQuery(params) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const query = { params: params, method: requests.Method.AbciQuery };
|
|
104
|
+
return this.doCall(query, this.p.encodeAbciQuery, this.r.decodeAbciQuery);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
block(height) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const query = { method: requests.Method.Block, params: { height: height } };
|
|
110
|
+
return this.doCall(query, this.p.encodeBlock, this.r.decodeBlock);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
blockResults(height) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
const query = {
|
|
116
|
+
method: requests.Method.BlockResults,
|
|
117
|
+
params: { height: height },
|
|
118
|
+
};
|
|
119
|
+
return this.doCall(query, this.p.encodeBlockResults, this.r.decodeBlockResults);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Search for events that are in a block.
|
|
124
|
+
*
|
|
125
|
+
* NOTE
|
|
126
|
+
* This method will error on any node that is running a Tendermint version lower than 0.34.9.
|
|
127
|
+
*
|
|
128
|
+
* @see https://docs.tendermint.com/master/rpc/#/Info/block_search
|
|
129
|
+
*/
|
|
130
|
+
blockSearch(params) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
const query = { params: params, method: requests.Method.BlockSearch };
|
|
133
|
+
const resp = yield this.doCall(query, this.p.encodeBlockSearch, this.r.decodeBlockSearch);
|
|
134
|
+
return Object.assign(Object.assign({}, resp), {
|
|
135
|
+
// make sure we sort by height, as tendermint may be sorting by string value of the height
|
|
136
|
+
blocks: [...resp.blocks].sort((a, b) => a.block.header.height - b.block.header.height) });
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
// this should paginate through all blockSearch options to ensure it returns all results.
|
|
140
|
+
// starts with page 1 or whatever was provided (eg. to start on page 7)
|
|
141
|
+
//
|
|
142
|
+
// NOTE
|
|
143
|
+
// This method will error on any node that is running a Tendermint version lower than 0.34.9.
|
|
144
|
+
blockSearchAll(params) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
let page = params.page || 1;
|
|
147
|
+
const blocks = [];
|
|
148
|
+
let done = false;
|
|
149
|
+
while (!done) {
|
|
150
|
+
const resp = yield this.blockSearch(Object.assign(Object.assign({}, params), { page: page }));
|
|
151
|
+
blocks.push(...resp.blocks);
|
|
152
|
+
if (blocks.length < resp.totalCount) {
|
|
153
|
+
page++;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
done = true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// make sure we sort by height, as tendermint may be sorting by string value of the height
|
|
160
|
+
// and the earlier items may be in a higher page than the later items
|
|
161
|
+
blocks.sort((a, b) => a.block.header.height - b.block.header.height);
|
|
162
|
+
return {
|
|
163
|
+
totalCount: blocks.length,
|
|
164
|
+
blocks: blocks,
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Queries block headers filtered by minHeight <= height <= maxHeight.
|
|
170
|
+
*
|
|
171
|
+
* @param minHeight The minimum height to be included in the result. Defaults to 0.
|
|
172
|
+
* @param maxHeight The maximum height to be included in the result. Defaults to infinity.
|
|
173
|
+
*/
|
|
174
|
+
blockchain(minHeight, maxHeight) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
const query = {
|
|
177
|
+
method: requests.Method.Blockchain,
|
|
178
|
+
params: {
|
|
179
|
+
minHeight: minHeight,
|
|
180
|
+
maxHeight: maxHeight,
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
return this.doCall(query, this.p.encodeBlockchain, this.r.decodeBlockchain);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Broadcast transaction to mempool and wait for response
|
|
188
|
+
*
|
|
189
|
+
* @see https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_sync
|
|
190
|
+
*/
|
|
191
|
+
broadcastTxSync(params) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
const query = { params: params, method: requests.Method.BroadcastTxSync };
|
|
194
|
+
return this.doCall(query, this.p.encodeBroadcastTx, this.r.decodeBroadcastTxSync);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Broadcast transaction to mempool and do not wait for result
|
|
199
|
+
*
|
|
200
|
+
* @see https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_async
|
|
201
|
+
*/
|
|
202
|
+
broadcastTxAsync(params) {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
const query = { params: params, method: requests.Method.BroadcastTxAsync };
|
|
205
|
+
return this.doCall(query, this.p.encodeBroadcastTx, this.r.decodeBroadcastTxAsync);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Broadcast transaction to mempool and wait for block
|
|
210
|
+
*
|
|
211
|
+
* @see https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_commit
|
|
212
|
+
*/
|
|
213
|
+
broadcastTxCommit(params) {
|
|
214
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
const query = { params: params, method: requests.Method.BroadcastTxCommit };
|
|
216
|
+
return this.doCall(query, this.p.encodeBroadcastTx, this.r.decodeBroadcastTxCommit);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
commit(height) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
const query = { method: requests.Method.Commit, params: { height: height } };
|
|
222
|
+
return this.doCall(query, this.p.encodeCommit, this.r.decodeCommit);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
genesis() {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
const query = { method: requests.Method.Genesis };
|
|
228
|
+
return this.doCall(query, this.p.encodeGenesis, this.r.decodeGenesis);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
health() {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
const query = { method: requests.Method.Health };
|
|
234
|
+
return this.doCall(query, this.p.encodeHealth, this.r.decodeHealth);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
numUnconfirmedTxs() {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
const query = { method: requests.Method.NumUnconfirmedTxs };
|
|
240
|
+
return this.doCall(query, this.p.encodeNumUnconfirmedTxs, this.r.decodeNumUnconfirmedTxs);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
status() {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
const query = { method: requests.Method.Status };
|
|
246
|
+
return this.doCall(query, this.p.encodeStatus, this.r.decodeStatus);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
subscribeNewBlock() {
|
|
250
|
+
const request = {
|
|
251
|
+
method: requests.Method.Subscribe,
|
|
252
|
+
query: { type: requests.SubscriptionEventType.NewBlock },
|
|
253
|
+
};
|
|
254
|
+
return this.subscribe(request, this.r.decodeNewBlockEvent);
|
|
255
|
+
}
|
|
256
|
+
subscribeNewBlockHeader() {
|
|
257
|
+
const request = {
|
|
258
|
+
method: requests.Method.Subscribe,
|
|
259
|
+
query: { type: requests.SubscriptionEventType.NewBlockHeader },
|
|
260
|
+
};
|
|
261
|
+
return this.subscribe(request, this.r.decodeNewBlockHeaderEvent);
|
|
262
|
+
}
|
|
263
|
+
subscribeTx(query) {
|
|
264
|
+
const request = {
|
|
265
|
+
method: requests.Method.Subscribe,
|
|
266
|
+
query: {
|
|
267
|
+
type: requests.SubscriptionEventType.Tx,
|
|
268
|
+
raw: query,
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
return this.subscribe(request, this.r.decodeTxEvent);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Get a single transaction by hash
|
|
275
|
+
*
|
|
276
|
+
* @see https://docs.tendermint.com/master/rpc/#/Info/tx
|
|
277
|
+
*/
|
|
278
|
+
tx(params) {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
280
|
+
const query = { params: params, method: requests.Method.Tx };
|
|
281
|
+
return this.doCall(query, this.p.encodeTx, this.r.decodeTx);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Search for transactions that are in a block
|
|
286
|
+
*
|
|
287
|
+
* @see https://docs.tendermint.com/master/rpc/#/Info/tx_search
|
|
288
|
+
*/
|
|
289
|
+
txSearch(params) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
const query = { params: params, method: requests.Method.TxSearch };
|
|
292
|
+
return this.doCall(query, this.p.encodeTxSearch, this.r.decodeTxSearch);
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
// this should paginate through all txSearch options to ensure it returns all results.
|
|
296
|
+
// starts with page 1 or whatever was provided (eg. to start on page 7)
|
|
297
|
+
txSearchAll(params) {
|
|
298
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
299
|
+
let page = params.page || 1;
|
|
300
|
+
const txs = [];
|
|
301
|
+
let done = false;
|
|
302
|
+
while (!done) {
|
|
303
|
+
const resp = yield this.txSearch(Object.assign(Object.assign({}, params), { page: page }));
|
|
304
|
+
txs.push(...resp.txs);
|
|
305
|
+
if (txs.length < resp.totalCount) {
|
|
306
|
+
page++;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
done = true;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
totalCount: txs.length,
|
|
314
|
+
txs: txs,
|
|
315
|
+
};
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
validators(params) {
|
|
319
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
320
|
+
const query = {
|
|
321
|
+
method: requests.Method.Validators,
|
|
322
|
+
params: params,
|
|
323
|
+
};
|
|
324
|
+
return this.doCall(query, this.p.encodeValidators, this.r.decodeValidators);
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
validatorsAll(height) {
|
|
328
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
329
|
+
const validators = [];
|
|
330
|
+
let page = 1;
|
|
331
|
+
let done = false;
|
|
332
|
+
let blockHeight = height;
|
|
333
|
+
while (!done) {
|
|
334
|
+
const response = yield this.validators({
|
|
335
|
+
per_page: 50,
|
|
336
|
+
height: blockHeight,
|
|
337
|
+
page: page,
|
|
338
|
+
});
|
|
339
|
+
validators.push(...response.validators);
|
|
340
|
+
blockHeight = blockHeight || response.blockHeight;
|
|
341
|
+
if (validators.length < response.total) {
|
|
342
|
+
page++;
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
done = true;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
// NOTE: Default value is for type safety but this should always be set
|
|
350
|
+
blockHeight: blockHeight !== null && blockHeight !== void 0 ? blockHeight : 0,
|
|
351
|
+
count: validators.length,
|
|
352
|
+
total: validators.length,
|
|
353
|
+
validators: validators,
|
|
354
|
+
};
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
// doCall is a helper to handle the encode/call/decode logic
|
|
358
|
+
doCall(request, encode, decode) {
|
|
359
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
360
|
+
const req = encode(request);
|
|
361
|
+
const result = yield this.client.execute(req);
|
|
362
|
+
return decode(result);
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
subscribe(request, decode) {
|
|
366
|
+
if (!instanceOfRpcStreamingClient(this.client)) {
|
|
367
|
+
throw new Error("This RPC client type cannot subscribe to events");
|
|
368
|
+
}
|
|
369
|
+
const req = this.p.encodeSubscribe(request);
|
|
370
|
+
const eventStream = this.client.listen(req);
|
|
371
|
+
return eventStream.map((event) => {
|
|
372
|
+
return decode(event);
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
exports.default = CarbonTendermintClient;
|
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) => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
43
|
+
const tokens = tokenQueryResults.filter((token) => (0, blockchain_1.blockchainForChainId)(token.chainId.toNumber()) == this.blockchain &&
|
|
44
44
|
token.tokenAddress.length == 40 &&
|
|
45
|
-
token.bridgeAddress.toLowerCase() == generic_1.stripHexPrefix(lockProxyAddress) &&
|
|
45
|
+
token.bridgeAddress.toLowerCase() == (0, generic_1.stripHexPrefix)(lockProxyAddress) &&
|
|
46
46
|
(!whitelistDenoms || whitelistDenoms.includes(token.denom)) &&
|
|
47
|
-
this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress)));
|
|
47
|
+
this.verifyChecksum((0, generic_1.appendHexPrefix)(token.tokenAddress)));
|
|
48
48
|
const assetIds = tokens.map((token) => {
|
|
49
|
-
return this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress));
|
|
49
|
+
return this.verifyChecksum((0, generic_1.appendHexPrefix)(token.tokenAddress));
|
|
50
50
|
});
|
|
51
51
|
const provider = this.getProvider();
|
|
52
52
|
const contractAddress = this.getBalanceReaderAddress();
|
|
@@ -95,14 +95,14 @@ class ETHClient {
|
|
|
95
95
|
throw new Error("Invalid recovery address");
|
|
96
96
|
}
|
|
97
97
|
const fromTokenId = fromToken.id;
|
|
98
|
-
const fromTokenAddress = generic_1.appendHexPrefix(fromToken.tokenAddress);
|
|
98
|
+
const fromTokenAddress = (0, 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 = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
105
|
+
const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
|
|
106
106
|
const tokenCreator = fromToken.creator;
|
|
107
107
|
const targetAddressBytes = util_1.AddressUtils.SWTHAddress.getAddressBytes(tokenCreator, CarbonSDK_1.default.Network.MainNet);
|
|
108
108
|
const targetProxyHash = ethers_1.ethers.utils.hexlify(targetAddressBytes);
|
|
@@ -137,9 +137,9 @@ class ETHClient {
|
|
|
137
137
|
throw new Error("Minimum gas required: 150,000");
|
|
138
138
|
}
|
|
139
139
|
const networkConfig = this.getNetworkConfig();
|
|
140
|
-
const assetId = generic_1.appendHexPrefix(token.tokenAddress);
|
|
141
|
-
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
|
|
142
|
-
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
140
|
+
const assetId = (0, generic_1.appendHexPrefix)(token.tokenAddress);
|
|
141
|
+
const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(token));
|
|
142
|
+
const feeAddress = (0, 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 = generic_1.appendHexPrefix(tokenWithExternalBalances.tokenAddress);
|
|
194
|
-
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(tokenWithExternalBalances));
|
|
195
|
-
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
193
|
+
const assetId = (0, generic_1.appendHexPrefix)(tokenWithExternalBalances.tokenAddress);
|
|
194
|
+
const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(tokenWithExternalBalances));
|
|
195
|
+
const feeAddress = (0, 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(generic_1.appendHexPrefix(signature));
|
|
202
|
+
const signatureBytes = ethers_1.ethers.utils.arrayify((0, 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 (blockchain_1.blockchainForChainId(token.chainId.toNumber()) !== this.blockchain) {
|
|
241
|
+
if ((0, 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 = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
307
|
+
const addressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
308
308
|
return addressHex;
|
|
309
309
|
}
|
|
310
310
|
getProvider() {
|
|
@@ -29,7 +29,7 @@ exports.HydrogenEndpoints = {
|
|
|
29
29
|
const formatDateField = (value) => {
|
|
30
30
|
if (typeof value !== "string")
|
|
31
31
|
return null;
|
|
32
|
-
return dayjs_1.default(value);
|
|
32
|
+
return (0, dayjs_1.default)(value);
|
|
33
33
|
};
|
|
34
34
|
const formatCrossChainTransfer = (value) => {
|
|
35
35
|
var _a, _b;
|
package/lib/clients/N3Client.js
CHANGED
|
@@ -97,7 +97,7 @@ class N3Client {
|
|
|
97
97
|
neon_core_next_1.sc.ContractParam.byteArray(neon_core_next_1.u.HexString.fromHex(toAddressHex, true)),
|
|
98
98
|
neon_core_next_1.sc.ContractParam.integer(amount.toString(10)),
|
|
99
99
|
neon_core_next_1.sc.ContractParam.integer(feeAmount.toString(10)),
|
|
100
|
-
neon_core_next_1.sc.ContractParam.byteArray(neon_core_next_1.u.HexString.fromHex(networkConfig.feeAddress, true)),
|
|
100
|
+
neon_core_next_1.sc.ContractParam.byteArray(neon_core_next_1.u.HexString.fromHex(feeAmount.isZero() ? "" : networkConfig.feeAddress, true)),
|
|
101
101
|
neon_core_next_1.sc.ContractParam.integer(nonce),
|
|
102
102
|
];
|
|
103
103
|
const script = neon_core_next_1.sc.createScript({
|
|
@@ -160,13 +160,14 @@ class N3Client {
|
|
|
160
160
|
const fromAddressHex = o3Wallet.address;
|
|
161
161
|
const publicKeyOutput = yield o3Wallet.getPublicKeyOutput();
|
|
162
162
|
const accountScriptHash = address_1.N3Address.publicKeyToScriptHash(publicKeyOutput.publicKey);
|
|
163
|
+
const feeAddress = feeAmount.isZero() ? "" : neon_core_next_1.u.HexString.fromHex(networkConfig.feeAddress).toBase64();
|
|
163
164
|
const args = [
|
|
164
165
|
{ type: o3_1.O3Types.ArgTypes.Hash160, value: tokenScriptHash },
|
|
165
166
|
{ type: o3_1.O3Types.ArgTypes.Hash160, value: fromAddressHex },
|
|
166
167
|
{ type: o3_1.O3Types.ArgTypes.ByteArray, value: neon_core_next_1.u.HexString.fromHex(toAddressHex).toBase64() },
|
|
167
168
|
{ type: o3_1.O3Types.ArgTypes.Integer, value: amount.toString(10) },
|
|
168
169
|
{ type: o3_1.O3Types.ArgTypes.Integer, value: feeAmount.toString(10) },
|
|
169
|
-
{ type: o3_1.O3Types.ArgTypes.ByteArray, value:
|
|
170
|
+
{ type: o3_1.O3Types.ArgTypes.ByteArray, value: feeAddress },
|
|
170
171
|
{ type: o3_1.O3Types.ArgTypes.Integer, value: nonce.toString() },
|
|
171
172
|
];
|
|
172
173
|
const result = yield o3Wallet.getDAPI().invoke({
|