@clonegod/ttd-sui-common 1.0.101 → 2.0.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/dist/appconfig/SuiQuoteAppConfig.d.ts +10 -0
- package/dist/appconfig/SuiQuoteAppConfig.js +35 -0
- package/dist/appconfig/SuiTradeAppConfig.d.ts +7 -0
- package/dist/appconfig/SuiTradeAppConfig.js +13 -0
- package/dist/appconfig/ensure_core_env.d.ts +1 -0
- package/dist/appconfig/ensure_core_env.js +18 -0
- package/dist/appconfig/index.d.ts +5 -0
- package/dist/appconfig/index.js +21 -0
- package/dist/appconfig/sui_dex_env_args.d.ts +5 -0
- package/dist/appconfig/sui_dex_env_args.js +28 -0
- package/dist/appconfig/sui_env_args.d.ts +4 -0
- package/dist/appconfig/sui_env_args.js +20 -0
- package/dist/grpc/gas-price-cache.js +19 -32
- package/dist/grpc/grpc-connection.js +5 -3
- package/dist/grpc/grpc_provider_registry.d.ts +14 -0
- package/dist/grpc/grpc_provider_registry.js +60 -0
- package/dist/grpc/index.d.ts +3 -0
- package/dist/grpc/index.js +13 -1
- package/dist/grpc/ledger-service.js +107 -128
- package/dist/grpc/proto_value.d.ts +4 -0
- package/dist/grpc/proto_value.js +59 -0
- package/dist/grpc/state-service.d.ts +1 -0
- package/dist/grpc/state-service.js +99 -102
- package/dist/grpc/sui-grpc-client.js +2 -13
- package/dist/grpc/sui_object_reader.d.ts +15 -0
- package/dist/grpc/sui_object_reader.js +60 -0
- package/dist/grpc/transaction-service.js +26 -37
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/quote/abstract_dex_quote.d.ts +60 -0
- package/dist/quote/abstract_dex_quote.js +186 -0
- package/dist/quote/chain_ops.d.ts +17 -0
- package/dist/quote/chain_ops.js +52 -0
- package/dist/quote/index.d.ts +7 -0
- package/dist/quote/index.js +7 -0
- package/dist/quote/pool_event.d.ts +21 -0
- package/dist/quote/pool_event.js +6 -0
- package/dist/quote/pricing/token_price_cache.js +18 -29
- package/dist/quote/quote_amount.d.ts +4 -0
- package/dist/quote/quote_amount.js +24 -0
- package/dist/quote/quote_trace.d.ts +16 -0
- package/dist/quote/quote_trace.js +40 -0
- package/dist/quote/tick/clmm_v3_engine.d.ts +32 -0
- package/dist/quote/tick/clmm_v3_engine.js +48 -0
- package/dist/quote/tick/index.d.ts +4 -0
- package/dist/quote/tick/index.js +20 -0
- package/dist/quote/tick/local_clmm_state.d.ts +17 -0
- package/dist/quote/tick/local_clmm_state.js +22 -0
- package/dist/quote/tick/sui_clmm_tick_cache.d.ts +42 -0
- package/dist/quote/tick/sui_clmm_tick_cache.js +163 -0
- package/dist/quote/tick/sui_tick_data_provider.d.ts +2 -0
- package/dist/quote/tick/sui_tick_data_provider.js +6 -0
- package/dist/quote/verify/index.d.ts +1 -0
- package/dist/quote/verify/index.js +17 -0
- package/dist/quote/verify/quote_price_verify.d.ts +30 -0
- package/dist/quote/verify/quote_price_verify.js +247 -0
- package/dist/redis/redis_client.d.ts +1 -0
- package/dist/redis/redis_client.js +88 -117
- package/dist/rpc/index.js +59 -75
- package/dist/test/test.js +1 -1
- package/dist/test/test_checkpoint.js +4 -13
- package/dist/test/test_grpc.js +32 -41
- package/dist/trade/abstract_sui_dex_trade.d.ts +43 -0
- package/dist/trade/abstract_sui_dex_trade.js +380 -0
- package/dist/trade/abstract_sui_dex_trade_plus.d.ts +3 -1
- package/dist/trade/abstract_sui_dex_trade_plus.js +232 -212
- package/dist/trade/check/tx_result_checker.js +65 -75
- package/dist/trade/coin/index.d.ts +1 -0
- package/dist/trade/coin/index.js +17 -0
- package/dist/trade/coin/lua_scripts.d.ts +5 -0
- package/dist/trade/coin/lua_scripts.js +130 -0
- package/dist/trade/coin/types.d.ts +30 -0
- package/dist/trade/coin/types.js +2 -0
- package/dist/trade/coin/wallet_coin_ledger.d.ts +22 -0
- package/dist/trade/coin/wallet_coin_ledger.js +85 -0
- package/dist/trade/executor/central_executor.d.ts +72 -0
- package/dist/trade/executor/central_executor.js +240 -0
- package/dist/trade/executor/coin_cache.d.ts +21 -0
- package/dist/trade/executor/coin_cache.js +143 -0
- package/dist/trade/executor/coin_maintainer.d.ts +32 -0
- package/dist/trade/executor/coin_maintainer.js +123 -0
- package/dist/trade/executor/core_channel.d.ts +38 -0
- package/dist/trade/executor/core_channel.js +131 -0
- package/dist/trade/executor/data_channel.d.ts +27 -0
- package/dist/trade/executor/data_channel.js +2 -0
- package/dist/trade/executor/effects.d.ts +16 -0
- package/dist/trade/executor/effects.js +63 -0
- package/dist/trade/executor/executor_client.d.ts +13 -0
- package/dist/trade/executor/executor_client.js +55 -0
- package/dist/trade/executor/executor_protocol.d.ts +26 -0
- package/dist/trade/executor/executor_protocol.js +32 -0
- package/dist/trade/executor/executor_server.d.ts +8 -0
- package/dist/trade/executor/executor_server.js +33 -0
- package/dist/trade/executor/executor_ws_client.d.ts +13 -0
- package/dist/trade/executor/executor_ws_client.js +58 -0
- package/dist/trade/executor/grpc_channel.d.ts +14 -0
- package/dist/trade/executor/grpc_channel.js +73 -0
- package/dist/trade/executor/index.d.ts +7 -0
- package/dist/trade/executor/index.js +23 -0
- package/dist/trade/executor/json_rpc_channel.d.ts +14 -0
- package/dist/trade/executor/json_rpc_channel.js +77 -0
- package/dist/trade/index.d.ts +5 -1
- package/dist/trade/index.js +5 -1
- package/dist/trade/parse/sui_tx_parser.js +98 -81
- package/dist/trade/send_tx/index.js +34 -47
- package/dist/trade/swap/builders/bluefin.d.ts +9 -0
- package/dist/trade/swap/builders/bluefin.js +60 -0
- package/dist/trade/swap/builders/cetus_magma.d.ts +13 -0
- package/dist/trade/swap/builders/cetus_magma.js +52 -0
- package/dist/trade/swap/builders/momentum.d.ts +9 -0
- package/dist/trade/swap/builders/momentum.js +80 -0
- package/dist/trade/swap/dex_swap_config.d.ts +28 -0
- package/dist/trade/swap/dex_swap_config.js +40 -0
- package/dist/trade/swap/index.d.ts +7 -0
- package/dist/trade/swap/index.js +36 -0
- package/dist/trade/swap/types.d.ts +20 -0
- package/dist/trade/swap/types.js +2 -0
- package/dist/trade/test/test_parse_sui_tx_result.js +33 -44
- package/dist/trade/tx_result_channel.d.ts +7 -0
- package/dist/trade/tx_result_channel.js +7 -0
- package/dist/utils/decode.js +1 -2
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/trade_direction.d.ts +14 -0
- package/dist/utils/trade_direction.js +23 -0
- package/package.json +3 -2
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.LedgerService = void 0;
|
|
13
4
|
class LedgerService {
|
|
@@ -15,145 +6,133 @@ class LedgerService {
|
|
|
15
6
|
this.connection = connection;
|
|
16
7
|
this.ledgerClient = connection.createServiceClient('ledger_service.proto', 'LedgerService');
|
|
17
8
|
}
|
|
18
|
-
getServiceInfo() {
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
resolve(response);
|
|
27
|
-
});
|
|
9
|
+
async getServiceInfo() {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const request = {};
|
|
12
|
+
this.ledgerClient.GetServiceInfo(request, this.connection.getMetadata(), (error, response) => {
|
|
13
|
+
if (error)
|
|
14
|
+
reject(error);
|
|
15
|
+
else
|
|
16
|
+
resolve(response);
|
|
28
17
|
});
|
|
29
18
|
});
|
|
30
19
|
}
|
|
31
|
-
getEpoch(
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
resolve(response);
|
|
49
|
-
});
|
|
20
|
+
async getEpoch(epoch, includeGasPrice = true) {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
const request = {};
|
|
23
|
+
if (epoch)
|
|
24
|
+
request.epoch = epoch;
|
|
25
|
+
const paths = ['epoch'];
|
|
26
|
+
if (includeGasPrice) {
|
|
27
|
+
paths.push('reference_gas_price');
|
|
28
|
+
}
|
|
29
|
+
request.read_mask = {
|
|
30
|
+
paths: paths
|
|
31
|
+
};
|
|
32
|
+
this.ledgerClient.GetEpoch(request, this.connection.getMetadata(), (error, response) => {
|
|
33
|
+
if (error)
|
|
34
|
+
reject(error);
|
|
35
|
+
else
|
|
36
|
+
resolve(response);
|
|
50
37
|
});
|
|
51
38
|
});
|
|
52
39
|
}
|
|
53
|
-
getCheckpoint(checkpointId) {
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
resolve(response);
|
|
62
|
-
});
|
|
40
|
+
async getCheckpoint(checkpointId) {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const request = checkpointId ? { digest: checkpointId } : {};
|
|
43
|
+
this.ledgerClient.GetCheckpoint(request, this.connection.getMetadata(), (error, response) => {
|
|
44
|
+
if (error)
|
|
45
|
+
reject(error);
|
|
46
|
+
else
|
|
47
|
+
resolve(response);
|
|
63
48
|
});
|
|
64
49
|
});
|
|
65
50
|
}
|
|
66
|
-
getObject(objectId, readMask) {
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
51
|
+
async getObject(objectId, readMask) {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const request = {
|
|
54
|
+
object_id: objectId
|
|
55
|
+
};
|
|
56
|
+
if (readMask && readMask.length > 0) {
|
|
57
|
+
request.read_mask = {
|
|
58
|
+
paths: readMask
|
|
71
59
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
request.read_mask = {
|
|
63
|
+
paths: [
|
|
64
|
+
"object_id",
|
|
65
|
+
"version",
|
|
66
|
+
"digest",
|
|
67
|
+
"owner",
|
|
68
|
+
"object_type",
|
|
69
|
+
"has_public_transfer",
|
|
70
|
+
"previous_transaction",
|
|
71
|
+
"storage_rebate",
|
|
72
|
+
"balance"
|
|
73
|
+
]
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
this.ledgerClient.GetObject(request, this.connection.getMetadata(), (error, response) => {
|
|
77
|
+
if (error)
|
|
78
|
+
reject(error);
|
|
77
79
|
else {
|
|
78
|
-
|
|
79
|
-
paths: [
|
|
80
|
-
"object_id",
|
|
81
|
-
"version",
|
|
82
|
-
"digest",
|
|
83
|
-
"owner",
|
|
84
|
-
"object_type",
|
|
85
|
-
"has_public_transfer",
|
|
86
|
-
"previous_transaction",
|
|
87
|
-
"storage_rebate",
|
|
88
|
-
"balance"
|
|
89
|
-
]
|
|
90
|
-
};
|
|
80
|
+
resolve(response);
|
|
91
81
|
}
|
|
92
|
-
this.ledgerClient.GetObject(request, this.connection.getMetadata(), (error, response) => {
|
|
93
|
-
if (error)
|
|
94
|
-
reject(error);
|
|
95
|
-
else {
|
|
96
|
-
resolve(response);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
82
|
});
|
|
100
83
|
});
|
|
101
84
|
}
|
|
102
|
-
batchGetObjects(objectIds, readMask) {
|
|
103
|
-
return
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
85
|
+
async batchGetObjects(objectIds, readMask) {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
const requests = objectIds.map(id => ({ object_id: id }));
|
|
88
|
+
const request = { requests };
|
|
89
|
+
if (readMask && readMask.length > 0) {
|
|
90
|
+
request.read_mask = {
|
|
91
|
+
paths: readMask
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
request.read_mask = {
|
|
96
|
+
paths: [
|
|
97
|
+
"object_id",
|
|
98
|
+
"version",
|
|
99
|
+
"digest",
|
|
100
|
+
"owner",
|
|
101
|
+
"object_type",
|
|
102
|
+
"has_public_transfer",
|
|
103
|
+
"previous_transaction",
|
|
104
|
+
"storage_rebate",
|
|
105
|
+
"balance"
|
|
106
|
+
]
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
this.ledgerClient.BatchGetObjects(request, this.connection.getMetadata(), (error, response) => {
|
|
110
|
+
if (error)
|
|
111
|
+
reject(error);
|
|
112
112
|
else {
|
|
113
|
-
|
|
114
|
-
paths: [
|
|
115
|
-
"object_id",
|
|
116
|
-
"version",
|
|
117
|
-
"digest",
|
|
118
|
-
"owner",
|
|
119
|
-
"object_type",
|
|
120
|
-
"has_public_transfer",
|
|
121
|
-
"previous_transaction",
|
|
122
|
-
"storage_rebate",
|
|
123
|
-
"balance"
|
|
124
|
-
]
|
|
125
|
-
};
|
|
113
|
+
resolve(response);
|
|
126
114
|
}
|
|
127
|
-
this.ledgerClient.BatchGetObjects(request, this.connection.getMetadata(), (error, response) => {
|
|
128
|
-
if (error)
|
|
129
|
-
reject(error);
|
|
130
|
-
else {
|
|
131
|
-
resolve(response);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
115
|
});
|
|
135
116
|
});
|
|
136
117
|
}
|
|
137
|
-
getTransaction(digest, readMask) {
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
resolve(response);
|
|
156
|
-
});
|
|
118
|
+
async getTransaction(digest, readMask) {
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
const request = { digest };
|
|
121
|
+
if (readMask && readMask.length > 0) {
|
|
122
|
+
request.read_mask = {
|
|
123
|
+
paths: readMask
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
request.read_mask = {
|
|
128
|
+
paths: ['digest', 'effects.gas_used', 'checkpoint', 'timestamp', 'balance_changes', 'input_objects', 'output_objects']
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
this.ledgerClient.GetTransaction(request, this.connection.getMetadata(), (error, response) => {
|
|
132
|
+
if (error)
|
|
133
|
+
reject(error);
|
|
134
|
+
else
|
|
135
|
+
resolve(response);
|
|
157
136
|
});
|
|
158
137
|
});
|
|
159
138
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unwrapProtoValue = unwrapProtoValue;
|
|
4
|
+
exports.readMoveI32 = readMoveI32;
|
|
5
|
+
exports.readMoveI128 = readMoveI128;
|
|
6
|
+
exports.parseGenericTypeArgs = parseGenericTypeArgs;
|
|
7
|
+
function unwrapProtoValue(v) {
|
|
8
|
+
if (v == null || typeof v !== 'object')
|
|
9
|
+
return v;
|
|
10
|
+
const kind = v.kind;
|
|
11
|
+
if (kind === 'stringValue')
|
|
12
|
+
return v.stringValue;
|
|
13
|
+
if (kind === 'numberValue')
|
|
14
|
+
return v.numberValue;
|
|
15
|
+
if (kind === 'boolValue')
|
|
16
|
+
return v.boolValue;
|
|
17
|
+
if (kind === 'nullValue')
|
|
18
|
+
return null;
|
|
19
|
+
if (kind === 'structValue' || v.structValue) {
|
|
20
|
+
const out = {};
|
|
21
|
+
const fields = (v.structValue || {}).fields || {};
|
|
22
|
+
for (const k of Object.keys(fields))
|
|
23
|
+
out[k] = unwrapProtoValue(fields[k]);
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
if (kind === 'listValue' || v.listValue) {
|
|
27
|
+
return ((v.listValue || {}).values || []).map(unwrapProtoValue);
|
|
28
|
+
}
|
|
29
|
+
return v;
|
|
30
|
+
}
|
|
31
|
+
function readMoveI32(v) {
|
|
32
|
+
const bits = v && typeof v === 'object' && 'bits' in v ? v.bits : v;
|
|
33
|
+
return Number(BigInt.asIntN(32, BigInt(bits)));
|
|
34
|
+
}
|
|
35
|
+
function readMoveI128(v) {
|
|
36
|
+
const bits = v && typeof v === 'object' && 'bits' in v ? v.bits : v;
|
|
37
|
+
return BigInt.asIntN(128, BigInt(bits));
|
|
38
|
+
}
|
|
39
|
+
function parseGenericTypeArgs(objectType) {
|
|
40
|
+
const lt = objectType.indexOf('<');
|
|
41
|
+
if (lt < 0)
|
|
42
|
+
return [];
|
|
43
|
+
const inner = objectType.slice(lt + 1, objectType.lastIndexOf('>'));
|
|
44
|
+
const args = [];
|
|
45
|
+
let depth = 0, start = 0;
|
|
46
|
+
for (let i = 0; i < inner.length; i++) {
|
|
47
|
+
const c = inner[i];
|
|
48
|
+
if (c === '<')
|
|
49
|
+
depth++;
|
|
50
|
+
else if (c === '>')
|
|
51
|
+
depth--;
|
|
52
|
+
else if (c === ',' && depth === 0) {
|
|
53
|
+
args.push(inner.slice(start, i).trim());
|
|
54
|
+
start = i + 1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
args.push(inner.slice(start).trim());
|
|
58
|
+
return args.filter(Boolean);
|
|
59
|
+
}
|
|
@@ -8,5 +8,6 @@ export declare class StateService {
|
|
|
8
8
|
listBalances(owner: string): Promise<unknown>;
|
|
9
9
|
getCoinInfo(coinType: string): Promise<unknown>;
|
|
10
10
|
listOwnedObjects(owner: string, coinType?: string, limit?: number, readMask?: string[], pageTokenHex?: string): Promise<ListOwnedObjectsResponse>;
|
|
11
|
+
listDynamicFields(parent: string, pageSize?: number, pageTokenHex?: string, readMask?: string[]): Promise<any>;
|
|
11
12
|
listAllOwnedObjects(owner: string, coinType?: string): Promise<SuiObjectData[]>;
|
|
12
13
|
}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.StateService = void 0;
|
|
13
4
|
const utils_1 = require("../utils");
|
|
@@ -18,114 +9,120 @@ class StateService {
|
|
|
18
9
|
this.connection = connection;
|
|
19
10
|
this.stateClient = connection.createServiceClient('state_service.proto', 'StateService');
|
|
20
11
|
}
|
|
21
|
-
getBalance(owner, coinType) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
resolve(response);
|
|
39
|
-
});
|
|
12
|
+
async getBalance(owner, coinType) {
|
|
13
|
+
if (!owner) {
|
|
14
|
+
throw new Error('owner 参数是必需的');
|
|
15
|
+
}
|
|
16
|
+
if (!coinType) {
|
|
17
|
+
coinType = '0x2::sui::SUI';
|
|
18
|
+
}
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
const request = {
|
|
21
|
+
owner: owner,
|
|
22
|
+
coin_type: coinType
|
|
23
|
+
};
|
|
24
|
+
this.stateClient.GetBalance(request, this.connection.getMetadata(), (error, response) => {
|
|
25
|
+
if (error)
|
|
26
|
+
reject(error);
|
|
27
|
+
else
|
|
28
|
+
resolve(response);
|
|
40
29
|
});
|
|
41
30
|
});
|
|
42
31
|
}
|
|
43
|
-
listBalances(owner) {
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
resolve(response);
|
|
51
|
-
});
|
|
32
|
+
async listBalances(owner) {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
this.stateClient.ListBalances({ owner }, this.connection.getMetadata(), (error, response) => {
|
|
35
|
+
if (error)
|
|
36
|
+
reject(error);
|
|
37
|
+
else
|
|
38
|
+
resolve(response);
|
|
52
39
|
});
|
|
53
40
|
});
|
|
54
41
|
}
|
|
55
|
-
getCoinInfo(coinType) {
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
resolve(response);
|
|
63
|
-
});
|
|
42
|
+
async getCoinInfo(coinType) {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
this.stateClient.GetCoinInfo({ coin_type: coinType }, this.connection.getMetadata(), (error, response) => {
|
|
45
|
+
if (error)
|
|
46
|
+
reject(error);
|
|
47
|
+
else
|
|
48
|
+
resolve(response);
|
|
64
49
|
});
|
|
65
50
|
});
|
|
66
51
|
}
|
|
67
|
-
listOwnedObjects(owner, coinType, limit, readMask, pageTokenHex) {
|
|
68
|
-
return
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
52
|
+
async listOwnedObjects(owner, coinType, limit, readMask, pageTokenHex) {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
const request = { owner };
|
|
55
|
+
if (coinType) {
|
|
56
|
+
const objectType = coinType.startsWith('0x2::coin::Coin<')
|
|
57
|
+
? coinType
|
|
58
|
+
: `0x2::coin::Coin<${coinType}>`;
|
|
59
|
+
request.object_type = objectType;
|
|
60
|
+
}
|
|
61
|
+
if (limit)
|
|
62
|
+
request.page_size = limit;
|
|
63
|
+
if (pageTokenHex && pageTokenHex.length > 0) {
|
|
64
|
+
request.page_token = Buffer.from(pageTokenHex, 'hex');
|
|
65
|
+
}
|
|
66
|
+
if (readMask && readMask.length > 0) {
|
|
67
|
+
request.read_mask = {
|
|
68
|
+
paths: readMask
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
request.read_mask = {
|
|
73
|
+
paths: [
|
|
74
|
+
"object_id",
|
|
75
|
+
"version",
|
|
76
|
+
"digest",
|
|
77
|
+
"owner",
|
|
78
|
+
"object_type",
|
|
79
|
+
"storage_rebate",
|
|
80
|
+
"balance"
|
|
81
|
+
]
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
this.stateClient.ListOwnedObjects(request, this.connection.getMetadata(), (error, response) => {
|
|
85
|
+
if (error)
|
|
86
|
+
reject(error);
|
|
87
87
|
else {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
"object_id",
|
|
91
|
-
"version",
|
|
92
|
-
"digest",
|
|
93
|
-
"owner",
|
|
94
|
-
"object_type",
|
|
95
|
-
"storage_rebate",
|
|
96
|
-
"balance"
|
|
97
|
-
]
|
|
98
|
-
};
|
|
88
|
+
let res = (0, utils_1.decodeBytes)(response);
|
|
89
|
+
resolve(res);
|
|
99
90
|
}
|
|
100
|
-
this.stateClient.ListOwnedObjects(request, this.connection.getMetadata(), (error, response) => {
|
|
101
|
-
if (error)
|
|
102
|
-
reject(error);
|
|
103
|
-
else {
|
|
104
|
-
let res = (0, utils_1.decodeBytes)(response);
|
|
105
|
-
resolve(res);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
91
|
});
|
|
109
92
|
});
|
|
110
93
|
}
|
|
111
|
-
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
return out;
|
|
94
|
+
async listDynamicFields(parent, pageSize, pageTokenHex, readMask) {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
const request = { parent };
|
|
97
|
+
if (pageSize)
|
|
98
|
+
request.page_size = pageSize;
|
|
99
|
+
if (pageTokenHex && pageTokenHex.length > 0)
|
|
100
|
+
request.page_token = Buffer.from(pageTokenHex, 'hex');
|
|
101
|
+
if (readMask && readMask.length > 0)
|
|
102
|
+
request.read_mask = { paths: readMask };
|
|
103
|
+
this.stateClient.ListDynamicFields(request, this.connection.getMetadata(), (error, response) => {
|
|
104
|
+
if (error)
|
|
105
|
+
reject(error);
|
|
106
|
+
else
|
|
107
|
+
resolve(response);
|
|
108
|
+
});
|
|
128
109
|
});
|
|
129
110
|
}
|
|
111
|
+
async listAllOwnedObjects(owner, coinType) {
|
|
112
|
+
const out = [];
|
|
113
|
+
let pageTokenHex;
|
|
114
|
+
for (let page = 0; page < LIST_OWNED_OBJECTS_MAX_PAGES; page++) {
|
|
115
|
+
const res = await this.listOwnedObjects(owner, coinType, LIST_OWNED_OBJECTS_PAGE_SIZE, undefined, pageTokenHex);
|
|
116
|
+
const r = res;
|
|
117
|
+
const chunk = r.objects || [];
|
|
118
|
+
out.push(...chunk);
|
|
119
|
+
const next = r.next_page_token ?? r.nextPageToken;
|
|
120
|
+
if (!next || (typeof next === 'string' && next.length === 0)) {
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
pageTokenHex = typeof next === 'string' ? next : Buffer.from(next).toString('hex');
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
130
127
|
}
|
|
131
128
|
exports.StateService = StateService;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.SuiGrpcClient = void 0;
|
|
13
4
|
const grpc_connection_1 = require("./grpc-connection");
|
|
@@ -29,10 +20,8 @@ class SuiGrpcClient {
|
|
|
29
20
|
this.subscriptionService = new subscription_service_1.SubscriptionService(grpcClient);
|
|
30
21
|
this.gasPriceCache = gas_price_cache_1.GasPriceCache.getInstance(this.ledgerService);
|
|
31
22
|
}
|
|
32
|
-
get_gas_price() {
|
|
33
|
-
return
|
|
34
|
-
return yield this.gasPriceCache.getGasPrice();
|
|
35
|
-
});
|
|
23
|
+
async get_gas_price() {
|
|
24
|
+
return await this.gasPriceCache.getGasPrice();
|
|
36
25
|
}
|
|
37
26
|
}
|
|
38
27
|
exports.SuiGrpcClient = SuiGrpcClient;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GrpcConnection } from './grpc-connection';
|
|
2
|
+
export interface ObjectJson {
|
|
3
|
+
objectId: string;
|
|
4
|
+
objectType: string;
|
|
5
|
+
json: any;
|
|
6
|
+
}
|
|
7
|
+
export declare class SuiObjectReader {
|
|
8
|
+
private ledger;
|
|
9
|
+
private state;
|
|
10
|
+
constructor(connection: GrpcConnection);
|
|
11
|
+
getCoinDecimals(coinType: string): Promise<number>;
|
|
12
|
+
getObjectJson(objectId: string): Promise<ObjectJson>;
|
|
13
|
+
batchGetObjectJsons(objectIds: string[]): Promise<ObjectJson[]>;
|
|
14
|
+
listAllDynamicFieldObjectJsons(parent: string): Promise<ObjectJson[]>;
|
|
15
|
+
}
|