carbon-js-sdk 0.3.14 → 0.3.16-beta.1
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/CarbonTendermintClient.d.ts +117 -0
- package/lib/clients/CarbonTendermintClient.js +376 -0
- package/lib/clients/NEOClient.js +2 -1
- package/lib/codec/cdp/tx.d.ts +57 -1
- package/lib/codec/cdp/tx.js +367 -1
- package/lib/codec/index.d.ts +5 -1
- package/lib/codec/index.js +23 -11
- package/lib/constant/ibc.js +2 -2
- package/lib/modules/cdp.d.ts +20 -0
- package/lib/modules/cdp.js +38 -0
- package/lib/util/token.d.ts +14 -0
- package/lib/util/token.js +16 -1
- package/lib/util/tx.d.ts +4 -0
- package/lib/wallet/CarbonTendermintClient.js +376 -0
- package/package.json +1 -1
- package/lib/codec/bank/tx.d.ts +0 -64
- package/lib/codec/bank/tx.js +0 -236
|
@@ -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/NEOClient.js
CHANGED
|
@@ -112,9 +112,10 @@ class NEOClient {
|
|
|
112
112
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
113
113
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(swthAddress, networkConfig.network);
|
|
114
114
|
const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
115
|
+
const zeroAddressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(constant_1.ZeroAddress));
|
|
115
116
|
const amount = ethers_1.ethers.BigNumber.from(token.externalBalance);
|
|
116
117
|
const feeAmount = ethers_1.ethers.BigNumber.from(feeAmountInput !== null && feeAmountInput !== void 0 ? feeAmountInput : "100000000");
|
|
117
|
-
const feeAddress = feeAmount.isZero() ?
|
|
118
|
+
const feeAddress = feeAmount.isZero() ? zeroAddressHex : networkConfig.feeAddress;
|
|
118
119
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
119
120
|
if (amount.lt(feeAmount)) {
|
|
120
121
|
return false;
|
package/lib/codec/cdp/tx.d.ts
CHANGED
|
@@ -266,6 +266,30 @@ export interface MsgReturnStablecoinWithInterestInCdpTokens {
|
|
|
266
266
|
}
|
|
267
267
|
export interface MsgReturnStablecoinWithInterestInCdpTokensResponse {
|
|
268
268
|
}
|
|
269
|
+
export interface MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens {
|
|
270
|
+
creator: string;
|
|
271
|
+
debtor: string;
|
|
272
|
+
collateralDenom: string;
|
|
273
|
+
minCollateralAmount: string;
|
|
274
|
+
debtDenom: string;
|
|
275
|
+
debtAmount: string;
|
|
276
|
+
interestCdpDenom: string;
|
|
277
|
+
interestCdpAmount: string;
|
|
278
|
+
}
|
|
279
|
+
export interface MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse {
|
|
280
|
+
}
|
|
281
|
+
export interface MsgLiquidateCollateralWithStablecoinAndInterestInCollateral {
|
|
282
|
+
creator: string;
|
|
283
|
+
debtor: string;
|
|
284
|
+
collateralDenom: string;
|
|
285
|
+
minCollateralAmount: string;
|
|
286
|
+
debtDenom: string;
|
|
287
|
+
debtAmount: string;
|
|
288
|
+
interestCdpDenom: string;
|
|
289
|
+
interestCdpAmount: string;
|
|
290
|
+
}
|
|
291
|
+
export interface MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse {
|
|
292
|
+
}
|
|
269
293
|
export declare const MsgAddRateStrategy: {
|
|
270
294
|
encode(message: MsgAddRateStrategy, writer?: _m0.Writer): _m0.Writer;
|
|
271
295
|
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): MsgAddRateStrategy;
|
|
@@ -756,6 +780,34 @@ export declare const MsgReturnStablecoinWithInterestInCdpTokensResponse: {
|
|
|
756
780
|
toJSON(_: MsgReturnStablecoinWithInterestInCdpTokensResponse): unknown;
|
|
757
781
|
fromPartial(_: DeepPartial<MsgReturnStablecoinWithInterestInCdpTokensResponse>): MsgReturnStablecoinWithInterestInCdpTokensResponse;
|
|
758
782
|
};
|
|
783
|
+
export declare const MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens: {
|
|
784
|
+
encode(message: MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens, writer?: _m0.Writer): _m0.Writer;
|
|
785
|
+
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens;
|
|
786
|
+
fromJSON(object: any): MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens;
|
|
787
|
+
toJSON(message: MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens): unknown;
|
|
788
|
+
fromPartial(object: DeepPartial<MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens>): MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens;
|
|
789
|
+
};
|
|
790
|
+
export declare const MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse: {
|
|
791
|
+
encode(_: MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse, writer?: _m0.Writer): _m0.Writer;
|
|
792
|
+
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse;
|
|
793
|
+
fromJSON(_: any): MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse;
|
|
794
|
+
toJSON(_: MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse): unknown;
|
|
795
|
+
fromPartial(_: DeepPartial<MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse>): MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse;
|
|
796
|
+
};
|
|
797
|
+
export declare const MsgLiquidateCollateralWithStablecoinAndInterestInCollateral: {
|
|
798
|
+
encode(message: MsgLiquidateCollateralWithStablecoinAndInterestInCollateral, writer?: _m0.Writer): _m0.Writer;
|
|
799
|
+
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): MsgLiquidateCollateralWithStablecoinAndInterestInCollateral;
|
|
800
|
+
fromJSON(object: any): MsgLiquidateCollateralWithStablecoinAndInterestInCollateral;
|
|
801
|
+
toJSON(message: MsgLiquidateCollateralWithStablecoinAndInterestInCollateral): unknown;
|
|
802
|
+
fromPartial(object: DeepPartial<MsgLiquidateCollateralWithStablecoinAndInterestInCollateral>): MsgLiquidateCollateralWithStablecoinAndInterestInCollateral;
|
|
803
|
+
};
|
|
804
|
+
export declare const MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse: {
|
|
805
|
+
encode(_: MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse, writer?: _m0.Writer): _m0.Writer;
|
|
806
|
+
decode(input: _m0.Reader | Uint8Array, length?: number | undefined): MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse;
|
|
807
|
+
fromJSON(_: any): MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse;
|
|
808
|
+
toJSON(_: MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse): unknown;
|
|
809
|
+
fromPartial(_: DeepPartial<MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse>): MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse;
|
|
810
|
+
};
|
|
759
811
|
/** Msg defines the Msg service. */
|
|
760
812
|
export interface Msg {
|
|
761
813
|
AddRateStrategy(request: MsgAddRateStrategy): Promise<MsgAddRateStrategyResponse>;
|
|
@@ -792,8 +844,10 @@ export interface Msg {
|
|
|
792
844
|
SetStalePriceGracePeriod(request: MsgSetStalePriceGracePeriod): Promise<MsgSetStalePriceGracePeriodResponse>;
|
|
793
845
|
SetCdpPaused(request: MsgSetCdpPaused): Promise<MsgSetCdpPausedResponse>;
|
|
794
846
|
ReturnStablecoinWithInterestInCdpTokens(request: MsgReturnStablecoinWithInterestInCdpTokens): Promise<MsgReturnStablecoinWithInterestInCdpTokensResponse>;
|
|
795
|
-
/** this line is used by starport scaffolding # proto/tx/rpc */
|
|
796
847
|
ReturnStablecoinWithInterestInCollateral(request: MsgReturnStablecoinWithInterestInCollateral): Promise<MsgReturnStablecoinWithInterestInCollateralResponse>;
|
|
848
|
+
LiquidateCollateralWithStablecoinAndInterestInCdpTokens(request: MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens): Promise<MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse>;
|
|
849
|
+
/** this line is used by starport scaffolding # proto/tx/rpc */
|
|
850
|
+
LiquidateCollateralWithStablecoinAndInterestInCollateral(request: MsgLiquidateCollateralWithStablecoinAndInterestInCollateral): Promise<MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse>;
|
|
797
851
|
}
|
|
798
852
|
export declare class MsgClientImpl implements Msg {
|
|
799
853
|
private readonly rpc;
|
|
@@ -833,6 +887,8 @@ export declare class MsgClientImpl implements Msg {
|
|
|
833
887
|
SetCdpPaused(request: MsgSetCdpPaused): Promise<MsgSetCdpPausedResponse>;
|
|
834
888
|
ReturnStablecoinWithInterestInCdpTokens(request: MsgReturnStablecoinWithInterestInCdpTokens): Promise<MsgReturnStablecoinWithInterestInCdpTokensResponse>;
|
|
835
889
|
ReturnStablecoinWithInterestInCollateral(request: MsgReturnStablecoinWithInterestInCollateral): Promise<MsgReturnStablecoinWithInterestInCollateralResponse>;
|
|
890
|
+
LiquidateCollateralWithStablecoinAndInterestInCdpTokens(request: MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokens): Promise<MsgLiquidateCollateralWithStablecoinAndInterestInCdpTokensResponse>;
|
|
891
|
+
LiquidateCollateralWithStablecoinAndInterestInCollateral(request: MsgLiquidateCollateralWithStablecoinAndInterestInCollateral): Promise<MsgLiquidateCollateralWithStablecoinAndInterestInCollateralResponse>;
|
|
836
892
|
}
|
|
837
893
|
interface Rpc {
|
|
838
894
|
request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
|