viz-js-lib 0.12.7 → 0.13.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.
@@ -196,4 +196,96 @@ module.exports = [{
196
196
  "roles": ["active"],
197
197
  "operation": "set_reward_sharing",
198
198
  "params": ["owner", "sharing_rate"]
199
+ }, {
200
+ "roles": ["active"],
201
+ "operation": "pm_oracle_register",
202
+ "params": ["owner", "insurance", "fee_percent", "fixed_fee", "rules_url", "auto_accept_creator", "auto_accept_resolver", "auto_accept", "extensions"]
203
+ }, {
204
+ "roles": ["active"],
205
+ "operation": "pm_oracle_update",
206
+ "params": ["owner", "insurance_delta", "fee_percent", "fixed_fee", "rules_url", "auto_accept_creator", "auto_accept_resolver", "auto_accept", "extensions"]
207
+ }, {
208
+ "roles": ["active"],
209
+ "operation": "pm_create_market",
210
+ "params": ["creator", "oracle", "market_type", "outcomes", "url", "oracle_fee_percent", "oracle_fixed_fee", "creator_fee_percent", "liquidity_fee_percent", "liquidity", "lmsr_b", "betting_expiration", "result_expiration", "time_penalty_type", "time_penalty_value", "penalty_curve_type", "allow_early_resolution", "allow_cancellation", "allow_batch", "allow_instant_bet", "endogeneity_tier", "dispute_mode", "dispute_resolver", "dispute_penalty_percent", "metadata", "extensions"]
211
+ }, {
212
+ "roles": ["active"],
213
+ "operation": "pm_oracle_accept_market",
214
+ "params": ["oracle", "market_id", "accept", "oracle_fee_percent", "oracle_fixed_fee", "extensions"]
215
+ }, {
216
+ "roles": ["active"],
217
+ "operation": "pm_place_bet",
218
+ "params": ["account", "market_id", "side", "outcome_index", "amount", "min_tokens", "mode", "extensions"]
219
+ }, {
220
+ "roles": ["active"],
221
+ "operation": "pm_commit_bet",
222
+ "params": ["account", "market_id", "commitment", "escrow_amount", "no_reveal_fee_percent", "extensions"]
223
+ }, {
224
+ "roles": ["active"],
225
+ "operation": "pm_reveal_bet",
226
+ "params": ["account", "commit_id", "side", "outcome_index", "amount", "salt", "min_tokens", "extensions"]
227
+ }, {
228
+ "roles": ["active"],
229
+ "operation": "pm_cancel_bet",
230
+ "params": ["account", "bet_id", "min_return", "extensions"]
231
+ }, {
232
+ "roles": ["active"],
233
+ "operation": "pm_add_liquidity",
234
+ "params": ["provider", "market_id", "amount", "extensions"]
235
+ }, {
236
+ "roles": ["active"],
237
+ "operation": "pm_withdraw_liquidity",
238
+ "params": ["provider", "liquidity_id", "amount", "extensions"]
239
+ }, {
240
+ "roles": ["active"],
241
+ "operation": "pm_resolve_market",
242
+ "params": ["oracle", "market_id", "winning_outcome", "decision_url", "decision_reason", "extensions"]
243
+ }, {
244
+ "roles": ["active"],
245
+ "operation": "pm_no_contest",
246
+ "params": ["oracle", "market_id", "reason", "extensions"]
247
+ }, {
248
+ "roles": ["active"],
249
+ "operation": "pm_dispute_create",
250
+ "params": ["disputer", "market_id", "proposed_outcome", "reason", "extensions"]
251
+ }, {
252
+ "roles": ["regular"],
253
+ "operation": "pm_dispute_vote",
254
+ "params": ["voter", "market_id", "vote_outcome", "vote_percent", "extensions"]
255
+ }, {
256
+ "roles": ["active"],
257
+ "operation": "pm_dispute_resolve",
258
+ "params": ["resolver", "market_id", "correct_outcome", "penalty_amount", "ban_oracle", "ban_oracle_until", "ban_creator", "ban_creator_until", "extensions"]
259
+ }, {
260
+ "roles": ["active"],
261
+ "operation": "pm_transfer_position",
262
+ "params": ["from", "bet_id", "to", "amount", "memo", "extensions"]
263
+ }, {
264
+ "roles": ["active"],
265
+ "operation": "pm_lazy_deposit",
266
+ "params": ["account", "amount", "extensions"]
267
+ }, {
268
+ "roles": ["active"],
269
+ "operation": "pm_lazy_withdraw",
270
+ "params": ["account", "shares", "emergency", "extensions"]
271
+ }, {
272
+ "roles": ["active"],
273
+ "operation": "pm_leverage_open",
274
+ "params": ["account", "market_id", "outcome_index", "collateral", "loan", "min_tokens", "max_slippage_percent", "extensions"]
275
+ }, {
276
+ "roles": ["active"],
277
+ "operation": "pm_leverage_close",
278
+ "params": ["account", "position_id", "min_return", "extensions"]
279
+ }, {
280
+ "roles": ["active"],
281
+ "operation": "pm_leverage_convert",
282
+ "params": ["account", "position_id", "conversion_profit_cost", "extensions"]
283
+ }, {
284
+ "roles": ["active"],
285
+ "operation": "pm_dispute_oracle_respond",
286
+ "params": ["oracle", "market_id", "response", "extensions"]
287
+ }, {
288
+ "roles": ["active"],
289
+ "operation": "pm_unban",
290
+ "params": ["resolver", "target", "unban_oracle", "unban_creator", "extensions"]
199
291
  }];
package/lib/formatter.js CHANGED
@@ -6,9 +6,21 @@ var _get2 = _interopRequireDefault(_get);
6
6
 
7
7
  var _ecc = require("./auth/ecc");
8
8
 
9
+ var _hash = require("./auth/ecc/src/hash");
10
+
11
+ var _hash2 = _interopRequireDefault(_hash);
12
+
9
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
14
 
11
15
  module.exports = function (VIZ_API) {
16
+ // Convert an amount to raw milli-VIZ (share_type). Accepts a raw integer
17
+ // (number/string of milli-VIZ) or a 3-decimal VIZ asset string ("10.000 VIZ").
18
+ function toMilliVIZ(amount) {
19
+ if (typeof amount === "string" && amount.indexOf(" ") !== -1) {
20
+ return BigInt(Math.round(parseFloat(amount.trim().split(" ")[0]) * 1000));
21
+ }
22
+ return BigInt(amount);
23
+ }
12
24
  function numberWithCommas(x) {
13
25
  return x.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
14
26
  }
@@ -70,6 +82,41 @@ module.exports = function (VIZ_API) {
70
82
  amount: function amount(_amount, asset) {
71
83
  return _amount.toFixed(3) + " " + asset;
72
84
  },
85
+
86
+ /**
87
+ * Build the byte-exact commitment hash for `pm_commit_bet` (HF14
88
+ * prediction markets, spec §3.6.1). The node recomputes this in the
89
+ * `pm_reveal_bet` evaluator and forfeits the escrow on any mismatch, so
90
+ * the same side/outcome_index/amount/min_tokens/salt MUST be re-supplied
91
+ * to `pm_reveal_bet`.
92
+ *
93
+ * Preimage = raw little-endian binary concatenation (no separators):
94
+ * market_id (int64 LE, 8) | account (ASCII, 32-byte zero-padded) |
95
+ * side (int8, 1) | outcome_index (int16 LE, 2) |
96
+ * amount (int64 LE, 8, milli-VIZ) | min_tokens (int64 LE, 8) | salt (utf8)
97
+ *
98
+ * @arg {number|string} marketId numeric market instance
99
+ * @arg {string} account bettor account name
100
+ * @arg {number} side binary 0/1, multi -1
101
+ * @arg {number} outcomeIndex multi 0..N-1, binary -1
102
+ * @arg {number|string} amount revealed stake — milli-VIZ integer or "10.000 VIZ"
103
+ * @arg {number|string} minTokens slippage floor (milli-VIZ / weight units)
104
+ * @arg {string} salt entropy string bound into the hash
105
+ * @return {string} 64-char hex SHA-256 commitment
106
+ */
107
+ predictionMarketCommitment: function predictionMarketCommitment(marketId, account, side, outcomeIndex, amount, minTokens, salt) {
108
+ var fixed = Buffer.alloc(59);
109
+ fixed.writeBigInt64LE(BigInt(marketId), 0);
110
+ Buffer.from(String(account), "ascii").copy(fixed, 8, 0, 32);
111
+ fixed.writeInt8(side, 40);
112
+ fixed.writeInt16LE(outcomeIndex, 41);
113
+ fixed.writeBigInt64LE(toMilliVIZ(amount), 43);
114
+ fixed.writeBigInt64LE(BigInt(minTokens), 51);
115
+ var preimage = Buffer.concat([fixed, Buffer.from(salt, "utf8")]);
116
+ return _hash2.default.sha256(preimage, "hex");
117
+ },
118
+
119
+ toMilliVIZ: toMilliVIZ,
73
120
  numberWithCommas: numberWithCommas,
74
121
  vestingVIZ: vestingVIZ,
75
122
  estimateAccountValue: estimateAccountValue,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viz-js-lib",
3
- "version": "0.12.7",
3
+ "version": "0.13.1",
4
4
  "description": "viz.js the JavaScript Library with API support for VIZ blockchain",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -69,4 +69,33 @@ export const methods_test = [
69
69
  "set_block_applied_callback",
70
70
  "verify_account_authority",
71
71
  "verify_authority",
72
+ "get_market",
73
+ "list_markets",
74
+ "list_markets_by_oracle",
75
+ "list_markets_by_creator",
76
+ "get_market_outcomes",
77
+ "get_market_weight_sums",
78
+ "get_market_bets",
79
+ "get_account_positions",
80
+ "get_market_liquidity",
81
+ "get_market_full",
82
+ "get_account_leverage_positions",
83
+ "get_market_leverage_positions",
84
+ "get_creator_ban",
85
+ "get_leverage_quote",
86
+ "get_leverage_close_preview",
87
+ "get_leverage_convert_preview",
88
+ "get_oracle",
89
+ "list_oracles",
90
+ "get_dispute",
91
+ "get_dispute_votes",
92
+ "get_lazy_pool",
93
+ "get_lazy_deposit",
94
+ "get_lazy_allocations",
95
+ "get_market_lazy_allocation",
96
+ "get_pm_chain_properties",
97
+ "get_market_meta",
98
+ "list_markets_by_category",
99
+ "get_market_categories",
100
+ "get_market_kline",
72
101
  ]