viz-js-lib 0.13.4 → 0.14.0
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/api-frontend/app.js +2 -0
- package/dist/statistics.html +1 -1
- package/dist/viz-tests.min.js +1 -1
- package/dist/viz-tests.min.js.gz +0 -0
- package/dist/viz.min.js +4 -4
- package/dist/viz.min.js.gz +0 -0
- package/lib/api/methods.js +9 -1
- package/lib/auth/serializer/src/ChainTypes.js +2 -0
- package/lib/auth/serializer/src/operations.js +18 -3
- package/lib/auth/serializer/src/types.js +12 -0
- package/lib/formatter.js +20 -5
- package/package.json +1 -1
- package/test/methods_by_version.js +2 -0
- package/test/pm_create_market_order_test.js +50 -0
- package/test/pm_dispute_oracle_history_test.js +66 -0
package/dist/viz.min.js.gz
CHANGED
|
Binary file
|
package/lib/api/methods.js
CHANGED
|
@@ -274,11 +274,15 @@ module.exports = [{
|
|
|
274
274
|
}, {
|
|
275
275
|
"api": "prediction_market_api",
|
|
276
276
|
"method": "list_markets",
|
|
277
|
-
"params": ["status", "from", "limit", "show_risky"]
|
|
277
|
+
"params": ["status", "from", "limit", "show_risky", "order"]
|
|
278
278
|
}, {
|
|
279
279
|
"api": "prediction_market_api",
|
|
280
280
|
"method": "list_markets_by_oracle",
|
|
281
281
|
"params": ["oracle", "from", "limit"]
|
|
282
|
+
}, {
|
|
283
|
+
"api": "prediction_market_api",
|
|
284
|
+
"method": "list_markets_awaiting_resolution",
|
|
285
|
+
"params": ["oracle", "from", "limit"]
|
|
282
286
|
}, {
|
|
283
287
|
"api": "prediction_market_api",
|
|
284
288
|
"method": "list_markets_by_creator",
|
|
@@ -373,6 +377,10 @@ module.exports = [{
|
|
|
373
377
|
"api": "prediction_market_api",
|
|
374
378
|
"method": "list_markets_by_category",
|
|
375
379
|
"params": ["category", "from", "limit", "jurisdiction", "subcategory", "tag", "sort"]
|
|
380
|
+
}, {
|
|
381
|
+
"api": "prediction_market_api",
|
|
382
|
+
"method": "list_markets_by_event",
|
|
383
|
+
"params": ["event", "from", "limit"]
|
|
376
384
|
}, {
|
|
377
385
|
"api": "prediction_market_api",
|
|
378
386
|
"method": "get_market_categories"
|
|
@@ -120,6 +120,8 @@ ChainTypes.operations = {
|
|
|
120
120
|
pm_ban_expired: 100,
|
|
121
121
|
// Prediction Markets (HF14) — oracle-accept-window expiry virtual operation
|
|
122
122
|
pm_market_expired: 101,
|
|
123
|
+
// Prediction Markets (HF14) — dispute-opened virtual operation (oracle history)
|
|
124
|
+
pm_dispute_opened: 102,
|
|
123
125
|
// Aliases for backward compatibility (old witness names)
|
|
124
126
|
witness_update: 6,
|
|
125
127
|
account_witness_vote: 7,
|
|
@@ -679,8 +679,10 @@ var chain_properties_hf14 = new Serializer(5, {
|
|
|
679
679
|
pm_leverage_max_position_ratio_percent: uint16,
|
|
680
680
|
pm_leverage_expiration_buffer_sec: uint32,
|
|
681
681
|
pm_leverage_m_factor_percent: uint16,
|
|
682
|
+
pm_leverage_funding_rate_ppm_per_day: uint32,
|
|
682
683
|
pm_conversion_profit_cost_percent: uint16,
|
|
683
|
-
pm_closed_market_retention_sec: uint32
|
|
684
|
+
pm_closed_market_retention_sec: uint32,
|
|
685
|
+
pm_early_exit_reward_cap_percent: uint16
|
|
684
686
|
});
|
|
685
687
|
|
|
686
688
|
var versioned_chain_properties_update = new Serializer("versioned_chain_properties_update", {
|
|
@@ -854,7 +856,10 @@ var pm_create_market = new Serializer("pm_create_market", {
|
|
|
854
856
|
creator: string,
|
|
855
857
|
oracle: string,
|
|
856
858
|
market_type: uint8,
|
|
857
|
-
|
|
859
|
+
// Order is positional: outcome_index/side map to the array index on-chain.
|
|
860
|
+
// C++ stores outcomes as a std::vector (order preserved), so the JS
|
|
861
|
+
// serializer must NOT sort them (Types.array sorts unless nosort).
|
|
862
|
+
outcomes: array(_types2.default.nosort(string)),
|
|
858
863
|
url: string,
|
|
859
864
|
oracle_fee_percent: uint16,
|
|
860
865
|
oracle_fixed_fee: asset,
|
|
@@ -1047,6 +1052,7 @@ var pm_auto_payout = new Serializer("pm_auto_payout", {
|
|
|
1047
1052
|
|
|
1048
1053
|
// 87 — pm_dispute_finalize (virtual)
|
|
1049
1054
|
var pm_dispute_finalize = new Serializer("pm_dispute_finalize", {
|
|
1055
|
+
oracle: string,
|
|
1050
1056
|
market_id: int64,
|
|
1051
1057
|
winning_outcome: int16,
|
|
1052
1058
|
oracle_penalty: asset
|
|
@@ -1054,10 +1060,19 @@ var pm_dispute_finalize = new Serializer("pm_dispute_finalize", {
|
|
|
1054
1060
|
|
|
1055
1061
|
// 88 — pm_dispute_auto_close (virtual)
|
|
1056
1062
|
var pm_dispute_auto_close = new Serializer("pm_dispute_auto_close", {
|
|
1063
|
+
oracle: string,
|
|
1057
1064
|
market_id: int64,
|
|
1058
1065
|
oracle_penalty: asset
|
|
1059
1066
|
});
|
|
1060
1067
|
|
|
1068
|
+
// 102 — pm_dispute_opened (virtual)
|
|
1069
|
+
var pm_dispute_opened = new Serializer("pm_dispute_opened", {
|
|
1070
|
+
oracle: string,
|
|
1071
|
+
disputer: string,
|
|
1072
|
+
market_id: int64,
|
|
1073
|
+
proposed_outcome: int16
|
|
1074
|
+
});
|
|
1075
|
+
|
|
1061
1076
|
// 89 — pm_oracle_missed_penalty (virtual)
|
|
1062
1077
|
var pm_oracle_missed_penalty = new Serializer("pm_oracle_missed_penalty", {
|
|
1063
1078
|
oracle: string,
|
|
@@ -1177,7 +1192,7 @@ var pm_market_expired = new Serializer("pm_market_expired", {
|
|
|
1177
1192
|
|
|
1178
1193
|
operation.st_operations = [vote, content, transfer, transfer_to_vesting, withdraw_vesting, account_update, validator_update, account_validator_vote, account_validator_proxy, delete_content, custom, set_withdraw_vesting_route, request_account_recovery, recover_account, change_recovery_account, escrow_transfer, escrow_dispute, escrow_release, escrow_approve, delegate_vesting_shares, account_create, account_metadata, proposal_create, proposal_update, proposal_delete, chain_properties_update, author_reward, curation_reward, content_reward, fill_vesting_withdraw, shutdown_validator, hardfork, content_payout_update, content_benefactor_reward, return_vesting_delegation, committee_worker_create_request, committee_worker_cancel_request, committee_vote_request, committee_cancel_request, committee_approve_request, committee_pay_request, committee_payout_request, validator_reward, create_invite, claim_invite_balance, invite_registration, versioned_chain_properties_update, award, receive_award, benefactor_award, set_paid_subscription, paid_subscribe, paid_subscription_action, cancel_paid_subscription, set_account_price, set_subaccount_price, buy_account, account_sale, use_invite_balance, expire_escrow_ratification, fixed_award, target_account_sale, bid, outbid, set_reward_sharing, stakeholder_reward,
|
|
1179
1194
|
// Prediction Markets (HF14) — op-ids 66..101, positional order is the tag
|
|
1180
|
-
pm_oracle_register, pm_oracle_update, pm_create_market, pm_oracle_accept_market, pm_place_bet, pm_commit_bet, pm_reveal_bet, pm_cancel_bet, pm_add_liquidity, pm_withdraw_liquidity, pm_resolve_market, pm_no_contest, pm_dispute_create, pm_dispute_vote, pm_dispute_resolve, pm_transfer_position, pm_lazy_deposit, pm_lazy_withdraw, pm_batch_settle, pm_commit_forfeit, pm_auto_payout, pm_dispute_finalize, pm_dispute_auto_close, pm_oracle_missed_penalty, pm_lazy_recall, pm_leverage_open, pm_leverage_close, pm_leverage_convert, pm_leverage_liquidate, pm_leverage_resolve, pm_market_accepted, pm_payout, pm_dispute_oracle_respond, pm_unban, pm_ban_expired, pm_market_expired];
|
|
1195
|
+
pm_oracle_register, pm_oracle_update, pm_create_market, pm_oracle_accept_market, pm_place_bet, pm_commit_bet, pm_reveal_bet, pm_cancel_bet, pm_add_liquidity, pm_withdraw_liquidity, pm_resolve_market, pm_no_contest, pm_dispute_create, pm_dispute_vote, pm_dispute_resolve, pm_transfer_position, pm_lazy_deposit, pm_lazy_withdraw, pm_batch_settle, pm_commit_forfeit, pm_auto_payout, pm_dispute_finalize, pm_dispute_auto_close, pm_oracle_missed_penalty, pm_lazy_recall, pm_leverage_open, pm_leverage_close, pm_leverage_convert, pm_leverage_liquidate, pm_leverage_resolve, pm_market_accepted, pm_payout, pm_dispute_oracle_respond, pm_unban, pm_ban_expired, pm_market_expired, pm_dispute_opened];
|
|
1181
1196
|
|
|
1182
1197
|
// Export old witness names as aliases for backward compatibility
|
|
1183
1198
|
module.exports.witness_update = validator_update;
|
|
@@ -1103,4 +1103,16 @@ var sortOperation = function sortOperation(array, st_operation) {
|
|
|
1103
1103
|
// A binary string compare does not work. Performanance is very good so HEX is used.. localeCompare is another option.
|
|
1104
1104
|
Buffer.isBuffer(firstEl(a)) && Buffer.isBuffer(firstEl(b)) ? strCmp(firstEl(a).toString("hex"), firstEl(b).toString("hex")) : strCmp(firstEl(a).toString(), firstEl(b).toString());
|
|
1105
1105
|
});
|
|
1106
|
+
};
|
|
1107
|
+
|
|
1108
|
+
/**
|
|
1109
|
+
* Order-preserving variant of a base type for use inside `array(...)`.
|
|
1110
|
+
*
|
|
1111
|
+
* `Types.array` sorts its elements via `sortOperation` unless the element type
|
|
1112
|
+
* carries `nosort: true`. Order is significant for some protocol fields
|
|
1113
|
+
* (e.g. `pm_create_market.outcomes` — outcome_index/side are positional),
|
|
1114
|
+
* so callers wrap the base type with `nosort(...)` to keep submission order.
|
|
1115
|
+
*/
|
|
1116
|
+
Types.nosort = function (base) {
|
|
1117
|
+
return Object.assign({}, base, { nosort: true });
|
|
1106
1118
|
};
|
package/lib/formatter.js
CHANGED
|
@@ -16,10 +16,13 @@ module.exports = function (VIZ_API) {
|
|
|
16
16
|
// Convert an amount to raw milli-VIZ (share_type). Accepts a raw integer
|
|
17
17
|
// (number/string of milli-VIZ) or a 3-decimal VIZ asset string ("10.000 VIZ").
|
|
18
18
|
function toMilliVIZ(amount) {
|
|
19
|
+
// Returns a plain integer Number (milli-VIZ fits well within 2^53). Kept BigInt-free so the public
|
|
20
|
+
// helper doesn't hand callers a BigInt (BigInt+Number throws) and to stay parseable by the ancient
|
|
21
|
+
// build Babel (no BigInt literals anywhere). The commitment writer floors/mods this by hand.
|
|
19
22
|
if (typeof amount === "string" && amount.indexOf(" ") !== -1) {
|
|
20
|
-
return
|
|
23
|
+
return Math.round(parseFloat(amount.trim().split(" ")[0]) * 1000);
|
|
21
24
|
}
|
|
22
|
-
return
|
|
25
|
+
return Math.round(Number(amount));
|
|
23
26
|
}
|
|
24
27
|
function numberWithCommas(x) {
|
|
25
28
|
return x.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
@@ -106,12 +109,24 @@ module.exports = function (VIZ_API) {
|
|
|
106
109
|
*/
|
|
107
110
|
predictionMarketCommitment: function predictionMarketCommitment(marketId, account, side, outcomeIndex, amount, minTokens, salt) {
|
|
108
111
|
var fixed = Buffer.alloc(59);
|
|
109
|
-
|
|
112
|
+
// Portable little-endian int64 writer. The bundled buffer polyfill (buffer@5.0.x) predates
|
|
113
|
+
// Buffer.writeBigInt64LE (added in 5.2.0), so calling it throws in the browser build. Write the
|
|
114
|
+
// 8 bytes by hand with plain Number math (%256 / floor, NOT bitwise — `&` coerces to int32 and
|
|
115
|
+
// would corrupt bytes above 2^31). No BigInt: the ancient build Babel (preset-es2015) can't parse
|
|
116
|
+
// BigInt literals (`8n`). Byte-identical to writeBigInt64LE for our non-negative values < 2^53
|
|
117
|
+
// (market id / milliVIZ amount / min_tokens are all well within the safe-integer range).
|
|
118
|
+
var writeI64LE = function writeI64LE(buf, val, off) {
|
|
119
|
+
var v = Math.floor(Number(val));
|
|
120
|
+
for (var k = 0; k < 8; k++) {
|
|
121
|
+
buf[off + k] = v % 256;v = Math.floor(v / 256);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
writeI64LE(fixed, marketId, 0);
|
|
110
125
|
Buffer.from(String(account), "ascii").copy(fixed, 8, 0, 32);
|
|
111
126
|
fixed.writeInt8(side, 40);
|
|
112
127
|
fixed.writeInt16LE(outcomeIndex, 41);
|
|
113
|
-
fixed
|
|
114
|
-
fixed
|
|
128
|
+
writeI64LE(fixed, toMilliVIZ(amount), 43);
|
|
129
|
+
writeI64LE(fixed, minTokens, 51);
|
|
115
130
|
var preimage = Buffer.concat([fixed, Buffer.from(salt, "utf8")]);
|
|
116
131
|
return _hash2.default.sha256(preimage, "hex");
|
|
117
132
|
},
|
package/package.json
CHANGED
|
@@ -72,6 +72,7 @@ export const methods_test = [
|
|
|
72
72
|
"get_market",
|
|
73
73
|
"list_markets",
|
|
74
74
|
"list_markets_by_oracle",
|
|
75
|
+
"list_markets_awaiting_resolution",
|
|
75
76
|
"list_markets_by_creator",
|
|
76
77
|
"get_market_outcomes",
|
|
77
78
|
"get_market_weight_sums",
|
|
@@ -96,6 +97,7 @@ export const methods_test = [
|
|
|
96
97
|
"get_pm_chain_properties",
|
|
97
98
|
"get_market_meta",
|
|
98
99
|
"list_markets_by_category",
|
|
100
|
+
"list_markets_by_event",
|
|
99
101
|
"get_market_categories",
|
|
100
102
|
"get_market_kline",
|
|
101
103
|
]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var ops = require('../src/auth/serializer/src/operations');
|
|
3
|
+
var Convert = require('../src/auth/serializer/src/convert');
|
|
4
|
+
|
|
5
|
+
describe("viz.auth: pm_create_market outcomes order preservation", () => {
|
|
6
|
+
|
|
7
|
+
it("keeps ['Yes','No'] order instead of sorting to ['No','Yes']", () => {
|
|
8
|
+
var op = ops.pm_create_market;
|
|
9
|
+
var sample = {
|
|
10
|
+
creator: "dream-world",
|
|
11
|
+
oracle: "dream-world",
|
|
12
|
+
market_type: 0,
|
|
13
|
+
outcomes: ["Yes", "No"],
|
|
14
|
+
url: "qa-order-test",
|
|
15
|
+
oracle_fee_percent: 100,
|
|
16
|
+
oracle_fixed_fee: "0.000 VIZ",
|
|
17
|
+
creator_fee_percent: 100,
|
|
18
|
+
liquidity_fee_percent: 200,
|
|
19
|
+
liquidity: "100.000 VIZ",
|
|
20
|
+
lmsr_b: 0,
|
|
21
|
+
betting_expiration: "2026-08-08T00:00:00",
|
|
22
|
+
result_expiration: "2026-08-09T00:00:00",
|
|
23
|
+
time_penalty_type: 1,
|
|
24
|
+
time_penalty_value: 10,
|
|
25
|
+
penalty_curve_type: 0,
|
|
26
|
+
allow_early_resolution: true,
|
|
27
|
+
allow_cancellation: true,
|
|
28
|
+
allow_batch: true,
|
|
29
|
+
allow_instant_bet: true,
|
|
30
|
+
endogeneity_tier: 1,
|
|
31
|
+
dispute_mode: 0,
|
|
32
|
+
dispute_resolver: "",
|
|
33
|
+
dispute_penalty_percent: 0,
|
|
34
|
+
metadata: "{}",
|
|
35
|
+
extensions: []
|
|
36
|
+
};
|
|
37
|
+
var hex = Convert(op).toHex(sample);
|
|
38
|
+
var back = Convert(op).fromHex(hex);
|
|
39
|
+
assert.equal(back.outcomes[0].toString(), "Yes");
|
|
40
|
+
assert.equal(back.outcomes[1].toString(), "No");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("non-outcomes arrays still sort (regression guard)", () => {
|
|
44
|
+
var t = require('../src/auth/serializer/src/types');
|
|
45
|
+
var arr = t.array(t.string);
|
|
46
|
+
var obj = arr.toObject(["b", "a"], {});
|
|
47
|
+
assert.deepEqual(obj, ["a", "b"]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var ops = require('../src/auth/serializer/src/operations');
|
|
3
|
+
var Convert = require('../src/auth/serializer/src/convert');
|
|
4
|
+
|
|
5
|
+
// Lock-step regression: the C++ pm_evaluator oracle-metrics round (PR VIZ-Blockchain/viz-cpp-node#124)
|
|
6
|
+
// added pm_dispute_opened (variant index 102) and an `oracle` first field on pm_dispute_finalize /
|
|
7
|
+
// pm_dispute_auto_close so disputes land in the oracle's own account history. These asserts pin the
|
|
8
|
+
// JS serializer to the C++ FC_REFLECT field order so history decoders don't silently misparse.
|
|
9
|
+
describe("viz.auth: PM dispute oracle-history serializers", () => {
|
|
10
|
+
|
|
11
|
+
it("pm_dispute_opened is registered at index 102", () => {
|
|
12
|
+
var opsTypes = require('../src/auth/serializer/src/ChainTypes');
|
|
13
|
+
assert.equal(opsTypes.operations.pm_dispute_opened, 102);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("round-trips pm_dispute_opened", () => {
|
|
17
|
+
var op = ops.pm_dispute_opened;
|
|
18
|
+
var sample = {
|
|
19
|
+
oracle: "vizoracle",
|
|
20
|
+
disputer: "disputant",
|
|
21
|
+
market_id: "42",
|
|
22
|
+
proposed_outcome: 1
|
|
23
|
+
};
|
|
24
|
+
var hex = Convert(op).toHex(sample);
|
|
25
|
+
var back = Convert(op).fromHex(hex);
|
|
26
|
+
assert.equal(back.oracle.toString(), sample.oracle);
|
|
27
|
+
assert.equal(back.disputer.toString(), sample.disputer);
|
|
28
|
+
assert.equal(back.market_id.toString(), sample.market_id);
|
|
29
|
+
assert.equal(back.proposed_outcome, sample.proposed_outcome);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("pm_dispute_finalize carries oracle as the first field", () => {
|
|
33
|
+
var op = ops.pm_dispute_finalize;
|
|
34
|
+
// Serializer field order must match C++ FC_REFLECT: (oracle)(market_id)(winning_outcome)(oracle_penalty)
|
|
35
|
+
assert.equal(op.keys[0], "oracle");
|
|
36
|
+
var sample = {
|
|
37
|
+
oracle: "vizoracle",
|
|
38
|
+
market_id: "42",
|
|
39
|
+
winning_outcome: 0,
|
|
40
|
+
oracle_penalty: "1.000 VIZ"
|
|
41
|
+
};
|
|
42
|
+
var hex = Convert(op).toHex(sample);
|
|
43
|
+
var back = Convert(op).fromHex(hex);
|
|
44
|
+
assert.equal(back.oracle.toString(), sample.oracle);
|
|
45
|
+
assert.equal(back.market_id.toString(), sample.market_id);
|
|
46
|
+
assert.equal(back.winning_outcome, sample.winning_outcome);
|
|
47
|
+
assert.equal(back.oracle_penalty, sample.oracle_penalty);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("pm_dispute_auto_close carries oracle as the first field", () => {
|
|
51
|
+
var op = ops.pm_dispute_auto_close;
|
|
52
|
+
// C++ FC_REFLECT: (oracle)(market_id)(oracle_penalty)
|
|
53
|
+
assert.equal(op.keys[0], "oracle");
|
|
54
|
+
var sample = {
|
|
55
|
+
oracle: "vizoracle",
|
|
56
|
+
market_id: "42",
|
|
57
|
+
oracle_penalty: "0.500 VIZ"
|
|
58
|
+
};
|
|
59
|
+
var hex = Convert(op).toHex(sample);
|
|
60
|
+
var back = Convert(op).fromHex(hex);
|
|
61
|
+
assert.equal(back.oracle.toString(), sample.oracle);
|
|
62
|
+
assert.equal(back.market_id.toString(), sample.market_id);
|
|
63
|
+
assert.equal(back.oracle_penalty, sample.oracle_penalty);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
});
|