@vordium/sdk 0.2.2 → 0.4.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/README.md +19 -1
- package/dist/cjs/agents.js +28 -1
- package/dist/cjs/client.js +265 -52
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/network.js +36 -14
- package/dist/cjs/outcome.js +649 -0
- package/dist/cjs/outcomeWords.js +172 -0
- package/dist/cjs/pins.js +5 -0
- package/dist/cjs/releaseRecord.js +48 -11
- package/dist/cjs/types.js +2 -1
- package/dist/esm/agents.d.ts +14 -0
- package/dist/esm/agents.js +25 -1
- package/dist/esm/client.d.ts +89 -7
- package/dist/esm/client.js +266 -53
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/network.d.ts +6 -0
- package/dist/esm/network.js +36 -14
- package/dist/esm/outcome.d.ts +201 -0
- package/dist/esm/outcome.js +623 -0
- package/dist/esm/outcomeWords.d.ts +168 -0
- package/dist/esm/outcomeWords.js +169 -0
- package/dist/esm/pins.d.ts +5 -0
- package/dist/esm/pins.js +5 -0
- package/dist/esm/releaseRecord.d.ts +6 -0
- package/dist/esm/releaseRecord.js +47 -10
- package/dist/esm/types.d.ts +1 -0
- package/dist/esm/types.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OUTCOME_WORDS = void 0;
|
|
4
|
+
// GENERATED from the shared outcome word file (sha256 dc1376362841a1bd9e4870c3471b9a0a7b4f1246ab6736a5f42a10747422920f). Do not edit by hand: regenerate it.
|
|
5
|
+
/** The words of an action whose outcome is not yet known: {action: {state: {text, next}}}. Placeholders in
|
|
6
|
+
* braces are filled by the caller. */
|
|
7
|
+
exports.OUTCOME_WORDS = {
|
|
8
|
+
"headline": {
|
|
9
|
+
"pending_checking": "Pending — checking"
|
|
10
|
+
},
|
|
11
|
+
"limit_s": 120,
|
|
12
|
+
"actions": {
|
|
13
|
+
"order": {
|
|
14
|
+
"pending_checking": {
|
|
15
|
+
"text": "Pending — checking. Your order was sent but the answer was lost. Checking the network for it.",
|
|
16
|
+
"next": "Do not place it again. This takes up to 2 minutes."
|
|
17
|
+
},
|
|
18
|
+
"applied": {
|
|
19
|
+
"text": "{order_words}. Found on the network at block {height}.",
|
|
20
|
+
"next": ""
|
|
21
|
+
},
|
|
22
|
+
"refused": {
|
|
23
|
+
"text": "Not placed: {meaning}.",
|
|
24
|
+
"next": "{action}"
|
|
25
|
+
},
|
|
26
|
+
"not_applied": {
|
|
27
|
+
"text": "Not placed. The network did not take it, and its time to apply has passed.",
|
|
28
|
+
"next": "You can place it again."
|
|
29
|
+
},
|
|
30
|
+
"still_unknown": {
|
|
31
|
+
"text": "Still not known after 2 minutes. It was not sent again and may still apply.",
|
|
32
|
+
"next": "Check your open orders before you place it again."
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"cancel": {
|
|
36
|
+
"pending_checking": {
|
|
37
|
+
"text": "Pending — checking. Your cancel was sent but the answer was lost. Checking whether the order is gone.",
|
|
38
|
+
"next": "Wait. This takes up to 2 minutes."
|
|
39
|
+
},
|
|
40
|
+
"applied": {
|
|
41
|
+
"text": "Cancelled. The order is off the book.",
|
|
42
|
+
"next": ""
|
|
43
|
+
},
|
|
44
|
+
"applied_other": {
|
|
45
|
+
"text": "Filled before the cancel.",
|
|
46
|
+
"next": "Check your position."
|
|
47
|
+
},
|
|
48
|
+
"refused": {
|
|
49
|
+
"text": "Not cancelled: {meaning}.",
|
|
50
|
+
"next": "{action}"
|
|
51
|
+
},
|
|
52
|
+
"still_unknown": {
|
|
53
|
+
"text": "Still not known after 2 minutes. The order is still on the book.",
|
|
54
|
+
"next": "You can cancel it again: cancelling twice has no extra effect."
|
|
55
|
+
},
|
|
56
|
+
"still_unknown_gone": {
|
|
57
|
+
"text": "Still not known after 2 minutes. The order is off the book: it was cancelled or filled.",
|
|
58
|
+
"next": "Check your position."
|
|
59
|
+
},
|
|
60
|
+
"still_unknown_unread": {
|
|
61
|
+
"text": "Still not known after 2 minutes. The network's reads did not answer.",
|
|
62
|
+
"next": "You can cancel it again: cancelling twice has no extra effect."
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"cancel_all": {
|
|
66
|
+
"pending_checking": {
|
|
67
|
+
"text": "Pending — checking. Cancel all was sent but the answer was lost. Checking your open orders.",
|
|
68
|
+
"next": "Wait. This takes up to 2 minutes."
|
|
69
|
+
},
|
|
70
|
+
"applied": {
|
|
71
|
+
"text": "All {n} orders cancelled.",
|
|
72
|
+
"next": ""
|
|
73
|
+
},
|
|
74
|
+
"applied_other": {
|
|
75
|
+
"text": "{n} of {m} cancelled; {k} filled first.",
|
|
76
|
+
"next": ""
|
|
77
|
+
},
|
|
78
|
+
"refused": {
|
|
79
|
+
"text": "Not cancelled: {meaning}.",
|
|
80
|
+
"next": ""
|
|
81
|
+
},
|
|
82
|
+
"still_unknown": {
|
|
83
|
+
"text": "Still not known after 2 minutes. {n} orders are still open.",
|
|
84
|
+
"next": "Check your open orders; cancel what is still open."
|
|
85
|
+
},
|
|
86
|
+
"still_unknown_unread": {
|
|
87
|
+
"text": "Still not known after 2 minutes. The network's reads did not answer.",
|
|
88
|
+
"next": "Check your open orders; cancel what is still open."
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"close_all": {
|
|
92
|
+
"pending_checking": {
|
|
93
|
+
"text": "Pending — checking. The closes were sent but the answers were lost. Checking your positions.",
|
|
94
|
+
"next": "Wait. This takes up to 2 minutes."
|
|
95
|
+
},
|
|
96
|
+
"applied": {
|
|
97
|
+
"text": "{n} positions closed.",
|
|
98
|
+
"next": ""
|
|
99
|
+
},
|
|
100
|
+
"applied_other": {
|
|
101
|
+
"text": "{n} of {m} closed. {k} still open.",
|
|
102
|
+
"next": "Close them on the trading page."
|
|
103
|
+
},
|
|
104
|
+
"refused": {
|
|
105
|
+
"text": "Not closed: {meaning}.",
|
|
106
|
+
"next": ""
|
|
107
|
+
},
|
|
108
|
+
"still_unknown": {
|
|
109
|
+
"text": "Still not known after 2 minutes. {n} positions are still open.",
|
|
110
|
+
"next": "Close what is still open on the trading page."
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"revoke": {
|
|
114
|
+
"pending_checking": {
|
|
115
|
+
"text": "Pending — checking. The revoke was sent. Checking that the agent is revoked.",
|
|
116
|
+
"next": "Wait. This takes up to 2 minutes."
|
|
117
|
+
},
|
|
118
|
+
"applied": {
|
|
119
|
+
"text": "Agent revoked at block {height}. {m} orders cancelled.",
|
|
120
|
+
"next": ""
|
|
121
|
+
},
|
|
122
|
+
"refused": {
|
|
123
|
+
"text": "Not revoked: {meaning}.",
|
|
124
|
+
"next": ""
|
|
125
|
+
},
|
|
126
|
+
"still_unknown": {
|
|
127
|
+
"text": "Still not known after 2 minutes. The agent is still live.",
|
|
128
|
+
"next": "You can revoke again: it has no extra effect."
|
|
129
|
+
},
|
|
130
|
+
"still_unknown_unread": {
|
|
131
|
+
"text": "Still not known after 2 minutes. The network's reads did not answer.",
|
|
132
|
+
"next": "You can revoke again: it has no extra effect."
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
"stop": {
|
|
136
|
+
"pending_checking": {
|
|
137
|
+
"text": "Pending — checking. The stop was sent. Checking that your trading key and agents are stopped.",
|
|
138
|
+
"next": "Wait. This takes up to 2 minutes."
|
|
139
|
+
},
|
|
140
|
+
"applied": {
|
|
141
|
+
"text": "Stopped on the network: no trading key, no live agent, no open order.",
|
|
142
|
+
"next": ""
|
|
143
|
+
},
|
|
144
|
+
"applied_other": {
|
|
145
|
+
"text": "Your trading key and every agent are stopped. {n} orders your wallet placed itself stay open.",
|
|
146
|
+
"next": ""
|
|
147
|
+
},
|
|
148
|
+
"refused": {
|
|
149
|
+
"text": "Not stopped: {meaning}.",
|
|
150
|
+
"next": ""
|
|
151
|
+
},
|
|
152
|
+
"not_applied": {
|
|
153
|
+
"text": "Not stopped. That signature has passed its time to apply.",
|
|
154
|
+
"next": "Press Stop everything now again."
|
|
155
|
+
},
|
|
156
|
+
"still_unknown": {
|
|
157
|
+
"text": "Still not known after 2 minutes. {what_is_live}.",
|
|
158
|
+
"next": "You can stop again: it has no extra effect."
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
"resend_while_pending": {
|
|
163
|
+
"order": null,
|
|
164
|
+
"cancel": "Send the same cancel again",
|
|
165
|
+
"cancel_all": null,
|
|
166
|
+
"close_all": null,
|
|
167
|
+
"revoke": "Send the same revoke again",
|
|
168
|
+
"stop": "Send the same stop again"
|
|
169
|
+
},
|
|
170
|
+
"check_again": "Check again",
|
|
171
|
+
"place_as_new": "Place as a new order"
|
|
172
|
+
};
|
package/dist/cjs/pins.js
CHANGED
|
@@ -12,6 +12,9 @@ exports.PINS = Object.freeze({
|
|
|
12
12
|
});
|
|
13
13
|
/** The network reports a chain id or genesis other than its pin. Nothing was signed. */
|
|
14
14
|
class PinMismatch extends errors_js_1.NetworkMismatch {
|
|
15
|
+
/** When the reason is the signed release record: its code (`expired`, `rollback`, `not_served`, `unsigned`,
|
|
16
|
+
* `bad_signature`, `not_listed`, …), else null. */
|
|
17
|
+
recordCode = null;
|
|
15
18
|
constructor(message) {
|
|
16
19
|
super(message);
|
|
17
20
|
this.name = 'PinMismatch';
|
|
@@ -20,6 +23,8 @@ class PinMismatch extends errors_js_1.NetworkMismatch {
|
|
|
20
23
|
exports.PinMismatch = PinMismatch;
|
|
21
24
|
/** The network is not a named network and carries no pin. It can be read; nothing is signed for it. */
|
|
22
25
|
class UnpinnedNetwork extends errors_js_1.NetworkMismatch {
|
|
26
|
+
/** When the reason is the signed release record (a network named only by its chain id): its code, else null. */
|
|
27
|
+
recordCode = null;
|
|
23
28
|
constructor(message) {
|
|
24
29
|
super(message);
|
|
25
30
|
this.name = 'UnpinnedNetwork';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RecordRefused = exports.KEY_RETRY_S = exports.KEY_REFRESH_TTL_S = exports.KEY_REFRESH_BEFORE_S = exports.KEY_URLS = exports.RELEASE_RECORD_SCHEMA = exports.RELEASE_RECORD_URLS = exports.RELEASE_KEY = exports.RELEASE_KEY_FINGERPRINT = void 0;
|
|
3
|
+
exports.RecordRefused = exports.KEY_RETRY_S = exports.KEY_REFRESH_TTL_S = exports.KEY_REFRESH_BEFORE_S = exports.KEY_URLS = exports.RELEASE_RECORD_SCHEMA = exports.MIN_RECORD_SEQUENCE = exports.RELEASE_RECORD_URLS = exports.RELEASE_KEY = exports.RELEASE_KEY_FINGERPRINT = void 0;
|
|
4
4
|
exports.crc24 = crc24;
|
|
5
5
|
exports.dearmor = dearmor;
|
|
6
6
|
exports.parsePublicKey = parsePublicKey;
|
|
@@ -53,6 +53,10 @@ exports.RELEASE_RECORD_URLS = Object.freeze({
|
|
|
53
53
|
mainnet: Object.freeze(['https://binaries.vordium.com/mainnet/releases.json', 'https://rpc.vordium.com/releases.json']),
|
|
54
54
|
testnet: Object.freeze(['https://binaries.vordium.com/testnet/releases.json']),
|
|
55
55
|
});
|
|
56
|
+
/** The lowest record sequence this SDK release accepts for each chain id, also on a computer that has read no record yet
|
|
57
|
+
* (an empty state folder): the release process sets it to the sequence of the record served when the release is made.
|
|
58
|
+
* 0 = no floor. A floor above 0 also counts as a record already seen: while none is served, nothing is signed. */
|
|
59
|
+
exports.MIN_RECORD_SEQUENCE = Object.freeze({ 101101: 0, 101102: 0 });
|
|
56
60
|
/** The record format this SDK reads. */
|
|
57
61
|
exports.RELEASE_RECORD_SCHEMA = 'vordium.release-record/3';
|
|
58
62
|
/** Where the release key is served. Read only when the key's expiry is near or past (see {@link refreshKey}). */
|
|
@@ -735,18 +739,48 @@ async function mark(store, key, fn) {
|
|
|
735
739
|
throw new RecordRefused('state', `The stored sequence of the release record cannot be read (${e.message}). Nothing is signed. Check the file, or remove it to accept the next record.`);
|
|
736
740
|
}
|
|
737
741
|
}
|
|
738
|
-
/** The
|
|
739
|
-
|
|
742
|
+
/** The sequence the Python SDK keeps in the same state folder (its file holds the plain sequence), or null. A file that
|
|
743
|
+
* cannot be read is not counted here (that SDK refuses on it itself). */
|
|
744
|
+
async function otherSdkSequence(store, fp, chainId) {
|
|
745
|
+
const file = store.where?.(stateKey(fp, chainId));
|
|
746
|
+
if (!file)
|
|
747
|
+
return null;
|
|
748
|
+
try {
|
|
749
|
+
const fs = (await Promise.resolve(`${'node:fs/promises'}`).then(s => require(s)));
|
|
750
|
+
const text = (await fs.readFile(file.replace(/release-record-mark\.([^/\\]+)$/, 'release-record.$1'), 'utf8')).trim();
|
|
751
|
+
return /^\d+$/.test(text) ? Number(text) : null;
|
|
752
|
+
}
|
|
753
|
+
catch {
|
|
754
|
+
return null;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
const floorOf = (chainId, min) => {
|
|
758
|
+
const v = (min ?? exports.MIN_RECORD_SEQUENCE)[chainId];
|
|
759
|
+
return typeof v === 'number' && Number.isSafeInteger(v) && v > 0 ? v : null;
|
|
760
|
+
};
|
|
761
|
+
/** The highest sequence of a verified record seen for `chainId` on this computer, by this SDK or the Python SDK in the
|
|
762
|
+
* same state folder, and at least this release's {@link MIN_RECORD_SEQUENCE} (null when none). Kept in `store` as
|
|
763
|
+
* sequence + 1. */
|
|
764
|
+
async function seenSequence(store, fp, chainId, min) {
|
|
740
765
|
const v = await mark(store, stateKey(fp, chainId), (last) => last);
|
|
741
|
-
|
|
766
|
+
const vals = [v > 0 ? v - 1 : null, await otherSdkSequence(store, fp, chainId), floorOf(chainId, min)].filter((x) => x !== null);
|
|
767
|
+
return vals.length ? Math.max(...vals) : null;
|
|
742
768
|
}
|
|
743
|
-
/** Refuse `sequence` when it is lower than the highest seen for `chainId
|
|
744
|
-
|
|
745
|
-
|
|
769
|
+
/** Refuse `sequence` when it is lower than this release's floor or the highest seen for `chainId` (by either SDK); else
|
|
770
|
+
* keep the highest. */
|
|
771
|
+
async function acceptSequence(store, fp, chainId, sequence, min) {
|
|
772
|
+
const floor = floorOf(chainId, min);
|
|
773
|
+
if (floor !== null && sequence < floor) {
|
|
774
|
+
throw new RecordRefused('rollback', `The signed release record for chain ${chainId} has sequence ${sequence}, lower than sequence ${floor}, the lowest this SDK release accepts: an older record is being served. It is not used.`);
|
|
775
|
+
}
|
|
776
|
+
await mark(store, stateKey(fp, chainId), (own) => own); // the store knows its folder once it has been used
|
|
777
|
+
const other = await otherSdkSequence(store, fp, chainId);
|
|
778
|
+
await mark(store, stateKey(fp, chainId), (own) => {
|
|
779
|
+
const last = other === null ? own : Math.max(own, other + 1);
|
|
746
780
|
if (last > 0 && sequence < last - 1) {
|
|
747
781
|
throw new RecordRefused('rollback', `The signed release record for chain ${chainId} has sequence ${sequence}, lower than sequence ${last - 1} already seen on this computer: an older record is being served. It is not used.`);
|
|
748
782
|
}
|
|
749
|
-
return Math.max(
|
|
783
|
+
return Math.max(own, sequence + 1);
|
|
750
784
|
});
|
|
751
785
|
}
|
|
752
786
|
async function fetchBytes(t, url, timeoutMs, limit) {
|
|
@@ -807,12 +841,12 @@ async function readRecord(chainId, urls, keys, opts) {
|
|
|
807
841
|
if (!record)
|
|
808
842
|
continue;
|
|
809
843
|
if (nowMs() / 1000 > record.validUntil) {
|
|
810
|
-
throw new RecordRefused('expired', `The signed release record expired at ${new Date(record.validUntil * 1000).toISOString().slice(0, 16).replace('T', ' ')} UTC. It is not used.`);
|
|
844
|
+
throw new RecordRefused('expired', `The signed release record expired at ${new Date(record.validUntil * 1000).toISOString().slice(0, 16).replace('T', ' ')} UTC. It is not used. Try again later; if this persists, check this computer's clock.`);
|
|
811
845
|
}
|
|
812
846
|
const entry = record.networks.get(chainId);
|
|
813
847
|
if (!entry)
|
|
814
848
|
throw new RecordRefused('not_listed', `The signed release record does not list chain ${chainId}. Nothing is signed for it.`);
|
|
815
|
-
await acceptSequence(store, signed.fingerprint, chainId, record.sequence);
|
|
849
|
+
await acceptSequence(store, signed.fingerprint, chainId, record.sequence, opts.minSequence);
|
|
816
850
|
return { record, entry, url };
|
|
817
851
|
}
|
|
818
852
|
catch (e) {
|
|
@@ -824,7 +858,10 @@ async function readRecord(chainId, urls, keys, opts) {
|
|
|
824
858
|
if (problem)
|
|
825
859
|
throw problem;
|
|
826
860
|
for (const k of keys) {
|
|
827
|
-
const last = await seenSequence(store, k.fingerprint, chainId);
|
|
861
|
+
const last = await seenSequence(store, k.fingerprint, chainId, opts.minSequence);
|
|
862
|
+
if (last !== null && (await seenSequence(store, k.fingerprint, chainId, {})) === null) {
|
|
863
|
+
throw new RecordRefused('not_served', `No signed release record for chain ${chainId} is served now, and this SDK release needs one with sequence ${last} or later. Nothing is signed until it is served.`);
|
|
864
|
+
}
|
|
828
865
|
if (last !== null) {
|
|
829
866
|
throw new RecordRefused('not_served', `No signed release record for chain ${chainId} is served now, though one (sequence ${last}) was read on this computer before. Nothing is signed until it is served again.`);
|
|
830
867
|
}
|
package/dist/cjs/types.js
CHANGED
|
@@ -33,6 +33,7 @@ exports.TYPE_STRINGS = {
|
|
|
33
33
|
// VordexSession
|
|
34
34
|
SessionCreate: 'SessionCreate(address sessionKey,uint256 expiresAt,uint256 nonce)',
|
|
35
35
|
SessionRevoke: 'SessionRevoke(address owner,uint256 nonce)',
|
|
36
|
+
StopAllSigners: 'StopAllSigners(address owner,uint256 nonce,uint256 validUntil)',
|
|
36
37
|
};
|
|
37
38
|
function parseTypeString(s) {
|
|
38
39
|
const m = /^([A-Za-z0-9]+)\(([^()]*)\)$/.exec(s);
|
|
@@ -57,5 +58,5 @@ function typesFor(primary) {
|
|
|
57
58
|
}
|
|
58
59
|
/** Which domain each operation is signed in. */
|
|
59
60
|
function domainOf(primary) {
|
|
60
|
-
return primary === 'SessionCreate' || primary === 'SessionRevoke' ? 'VordexSession' : 'VordCore';
|
|
61
|
+
return primary === 'SessionCreate' || primary === 'SessionRevoke' || primary === 'StopAllSigners' ? 'VordexSession' : 'VordCore';
|
|
61
62
|
}
|
package/dist/esm/agents.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { VordiumError } from './errors.js';
|
|
1
2
|
/**
|
|
2
3
|
* Agents: a key that trades for an account within the limits its owner signs. The operations in force:
|
|
3
4
|
* RegisterAgentV2 (a name is required), SetAgentName, SetAgentPolicyV1, SetAgentMarketLimit, ClearAgentLock and
|
|
@@ -57,6 +58,19 @@ export interface PolicyV1 {
|
|
|
57
58
|
export declare function policyProblems(p: PolicyV1, nowMs: number): string[];
|
|
58
59
|
/** What in `next` would LOOSEN `prev`; [] = a tightening or no change (and always [] with nothing stored). */
|
|
59
60
|
export declare function loosens(prev: PolicyV1 | null, next: PolicyV1): string[];
|
|
61
|
+
/** The agent's record shows it was revoked before: it is never registered again. Make a new key for a new agent. */
|
|
62
|
+
export declare class AgentWasRevoked extends VordiumError {
|
|
63
|
+
readonly agent: string;
|
|
64
|
+
constructor(agent: string);
|
|
65
|
+
}
|
|
66
|
+
/** True when `rec` is an agent read the network answered: `found` true (an agent record) or false (never added). Any
|
|
67
|
+
* other answer counts as not read, and nothing is signed on it. */
|
|
68
|
+
export declare function agentRecordRead(rec: unknown): rec is Record<string, unknown> & {
|
|
69
|
+
found: boolean;
|
|
70
|
+
};
|
|
71
|
+
/** True when the agent's record (`GET /agents/{owner}/{agent}`) shows it was ever revoked: `revoked_at_ms` or
|
|
72
|
+
* `revoked_height` set, `revoked` true, or `status` "revoked". The network's `found: false` is never revoked. */
|
|
73
|
+
export declare function agentWasRevoked(rec: unknown): boolean;
|
|
60
74
|
export type AgentOp = 'RegisterAgentV2' | 'SetAgentName' | 'SetAgentPolicyV1' | 'SetAgentMarketLimit' | 'ClearAgentLock' | 'RevokeAgent';
|
|
61
75
|
type Kind = 'address' | 'string' | 'bool' | 'u8' | 'u32' | 'u64' | 'u128';
|
|
62
76
|
/** Per operation: [struct name, wire name, kind], in the order the node reads them. */
|
package/dist/esm/agents.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InvalidRequest } from './errors.js';
|
|
1
|
+
import { InvalidRequest, VordiumError } from './errors.js';
|
|
2
2
|
/**
|
|
3
3
|
* Agents: a key that trades for an account within the limits its owner signs. The operations in force:
|
|
4
4
|
* RegisterAgentV2 (a name is required), SetAgentName, SetAgentPolicyV1, SetAgentMarketLimit, ClearAgentLock and
|
|
@@ -131,6 +131,30 @@ export function loosens(prev, next) {
|
|
|
131
131
|
out.push('changes the active hours');
|
|
132
132
|
return out;
|
|
133
133
|
}
|
|
134
|
+
// ── A revoked agent is never registered again ─────────────────────────────────────────────────────────────────────
|
|
135
|
+
/** The agent's record shows it was revoked before: it is never registered again. Make a new key for a new agent. */
|
|
136
|
+
export class AgentWasRevoked extends VordiumError {
|
|
137
|
+
agent;
|
|
138
|
+
constructor(agent) {
|
|
139
|
+
super('agent_revoked_before', `Agent ${agent} was revoked before. A revoked agent is never registered again: make a new key for a new agent. Nothing was signed.`);
|
|
140
|
+
this.name = 'AgentWasRevoked';
|
|
141
|
+
this.agent = agent;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** True when `rec` is an agent read the network answered: `found` true (an agent record) or false (never added). Any
|
|
145
|
+
* other answer counts as not read, and nothing is signed on it. */
|
|
146
|
+
export function agentRecordRead(rec) {
|
|
147
|
+
return !!rec && typeof rec === 'object' && !Array.isArray(rec) && typeof rec.found === 'boolean';
|
|
148
|
+
}
|
|
149
|
+
/** True when the agent's record (`GET /agents/{owner}/{agent}`) shows it was ever revoked: `revoked_at_ms` or
|
|
150
|
+
* `revoked_height` set, `revoked` true, or `status` "revoked". The network's `found: false` is never revoked. */
|
|
151
|
+
export function agentWasRevoked(rec) {
|
|
152
|
+
if (!agentRecordRead(rec) || rec.found === false)
|
|
153
|
+
return false;
|
|
154
|
+
const set = (v) => v !== undefined && v !== null && v !== 0 && v !== '0' && v !== '' && v !== false;
|
|
155
|
+
return set(rec.revoked_at_ms) || set(rec.revoked_height) || rec.revoked === true
|
|
156
|
+
|| (typeof rec.status === 'string' && rec.status.toLowerCase().includes('revoked'));
|
|
157
|
+
}
|
|
134
158
|
/** Per operation: [struct name, wire name, kind], in the order the node reads them. */
|
|
135
159
|
export const SUBMIT_FIELDS = {
|
|
136
160
|
RegisterAgentV2: [['owner', 'owner', 'address'], ['agent', 'agent', 'address'], ['name', 'name', 'string'], ['mandate', 'mandate', 'string'], ['expiresMs', 'expires_ms', 'u64'], ['nonce', 'nonce', 'u64']],
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { type Transport } from './http.js';
|
|
|
5
5
|
import { type Network, type NetworkPreset } from './network.js';
|
|
6
6
|
import { type NonceSource, type NonceStore } from './nonce.js';
|
|
7
7
|
import { ChainClock } from './resend.js';
|
|
8
|
+
import { NodeReads, PendingWrite, type Outcome } from './outcome.js';
|
|
8
9
|
import { type BatchAction, type OrderInput, type Submitted } from './orders.js';
|
|
9
10
|
import { type AgentRefusal, type Equity, type OpenOrder, type Position } from './reads.js';
|
|
10
11
|
import { type TypedSigner } from './sign.js';
|
|
@@ -23,6 +24,15 @@ export interface Result {
|
|
|
23
24
|
detail: string;
|
|
24
25
|
/** It may have been received, and the chain's read did not show it yet: read the account before sending it anew. */
|
|
25
26
|
unknown?: boolean;
|
|
27
|
+
/** For {@link Account.revokeAgent} and {@link Account.stopAll}: what the node's reads made of it (null when nothing was
|
|
28
|
+
* signed or sent), and, while that is not final, the {@link PendingWrite} that goes on reading. */
|
|
29
|
+
outcome?: Outcome | null;
|
|
30
|
+
pending?: PendingWrite | null;
|
|
31
|
+
}
|
|
32
|
+
/** What a lost write's outcome adds to an answer: the outcome, and the handle that goes on reading while it is not final. */
|
|
33
|
+
export interface Checked {
|
|
34
|
+
outcome?: Outcome;
|
|
35
|
+
pending?: PendingWrite | null;
|
|
26
36
|
}
|
|
27
37
|
export interface ConnectOptions {
|
|
28
38
|
network?: 'mainnet' | 'testnet' | NetworkPreset;
|
|
@@ -43,7 +53,11 @@ export interface ConnectOptions {
|
|
|
43
53
|
releaseRecordStore?: NonceStore;
|
|
44
54
|
/** Tests only: this computer's clock in milliseconds, for the release record's expiry. */
|
|
45
55
|
releaseRecordNow?: () => number;
|
|
56
|
+
/** Tests only: the lowest record sequence accepted per chain id, instead of `MIN_RECORD_SEQUENCE`. */
|
|
57
|
+
releaseRecordMinSequence?: Readonly<Record<number, number>>;
|
|
46
58
|
}
|
|
59
|
+
/** Seconds ahead a stop's deadline is set (the chain takes at most 300). */
|
|
60
|
+
export declare const STOP_ALL_AHEAD_S = 120;
|
|
47
61
|
/** A connection to one Vordium network: reads, and the signing domains of its node. */
|
|
48
62
|
export declare class Vordium {
|
|
49
63
|
readonly network: Network;
|
|
@@ -66,6 +80,13 @@ export declare class Vordium {
|
|
|
66
80
|
domain(cls: DomainClass): Promise<TypedDomain>;
|
|
67
81
|
/** GET a path of the REST API; null on 404, raises on another failure. */
|
|
68
82
|
get(path: string): Promise<unknown>;
|
|
83
|
+
/** One read while an outcome is checked: {status, body} with its own time limit; status null when it failed. */
|
|
84
|
+
read(path: string): Promise<{
|
|
85
|
+
status: number | null;
|
|
86
|
+
body: unknown;
|
|
87
|
+
}>;
|
|
88
|
+
/** Reads of this client's node for an outcome check (never an explorer). */
|
|
89
|
+
nodeReads(): NodeReads;
|
|
69
90
|
post(path: string, body: string): Promise<{
|
|
70
91
|
status: number;
|
|
71
92
|
body: unknown;
|
|
@@ -184,12 +205,20 @@ export declare class Account {
|
|
|
184
205
|
* Sign and submit one order (Market or Limit). The answer is a submission; the order is on the book when
|
|
185
206
|
* {@link Vordium.openOrders} lists its `clientNonce`, or filled when the account's fills show it. Use
|
|
186
207
|
* {@link waitForOrder} to read it back.
|
|
208
|
+
*
|
|
209
|
+
* The order is signed ONCE; a lost answer or a busy gateway sends the same signed body again (never a new nonce). When
|
|
210
|
+
* an earlier copy may have arrived and no 2xx came back, the outcome is read from the node (the account's orders by
|
|
211
|
+
* this client nonce AND what was signed, then its records: placed, closed, refused) for up to `settleMs` (default 30 s;
|
|
212
|
+
* 0 returns at once): the answer carries `outcome` (`state` pending_checking, applied, refused, not_applied or
|
|
213
|
+
* still_unknown, with `text` and `next`) and, while it is not final, `pending` (`check()`, `wait()`). It is never
|
|
214
|
+
* signed again. When no copy left this machine, {@link DeliveryUnknown} is thrown (`neverSent`).
|
|
187
215
|
*/
|
|
188
216
|
placeOrder(o: Omit<OrderInput, 'owner' | 'clientNonce'> & {
|
|
189
217
|
clientNonce?: number;
|
|
190
218
|
builder?: OrderBuilder | null;
|
|
191
219
|
worstPrice?: string | number | null;
|
|
192
|
-
|
|
220
|
+
settleMs?: number;
|
|
221
|
+
}): Promise<Submitted & Checked & {
|
|
193
222
|
clientNonce: number;
|
|
194
223
|
attempts: number;
|
|
195
224
|
alreadyReceived: boolean;
|
|
@@ -212,7 +241,16 @@ export declare class Account {
|
|
|
212
241
|
waitForOrder(clientNonce: number, ms?: number, opts?: {
|
|
213
242
|
final?: boolean;
|
|
214
243
|
}): Promise<'resting' | 'filled' | 'cancelled' | 'expired' | null>;
|
|
215
|
-
|
|
244
|
+
/**
|
|
245
|
+
* Cancel one order. A cancel carries no nonce and the network cancels an order once, so a lost answer sends the SAME
|
|
246
|
+
* signed body again. When an earlier copy may have arrived and no 2xx came back, the outcome is read from the node
|
|
247
|
+
* (the order no longer listed, and its record: cancelled, or filled first) for up to `settleMs` (default 30 s; 0
|
|
248
|
+
* returns at once): `done` / `filled` / `unknown`, with `outcome` and, while it is not final, `pending` (whose
|
|
249
|
+
* `resendSame()` sends the same signed cancel again).
|
|
250
|
+
*/
|
|
251
|
+
cancelOrder(orderId: bigint | number, opts?: {
|
|
252
|
+
settleMs?: number;
|
|
253
|
+
}): Promise<Submitted & Checked & {
|
|
216
254
|
done?: boolean;
|
|
217
255
|
filled?: boolean;
|
|
218
256
|
unknown?: boolean;
|
|
@@ -220,20 +258,37 @@ export declare class Account {
|
|
|
220
258
|
}>;
|
|
221
259
|
/** Take-profit / stop-loss on an open position (8-decimal prices; 0 leaves a leg unset). */
|
|
222
260
|
setTpSl(pairId: number, positionId: bigint | number, takeProfit8: bigint, stopLoss8: bigint): Promise<Submitted>;
|
|
223
|
-
/**
|
|
261
|
+
/**
|
|
262
|
+
* Up to the published maximum of place / cancel actions in one signed batch. Cancels apply first. A batch is never
|
|
263
|
+
* sent again after a lost answer; its outcome is then read from the node (each place by its client nonce, each
|
|
264
|
+
* cancelled order no longer listed) for up to `settleMs` (default 30 s; 0 returns at once).
|
|
265
|
+
*/
|
|
224
266
|
batch(actions: BatchAction[], opts?: {
|
|
225
267
|
nonce?: number;
|
|
226
268
|
maxActions?: number;
|
|
227
|
-
|
|
269
|
+
settleMs?: number;
|
|
270
|
+
}): Promise<Submitted & Checked & {
|
|
228
271
|
nonce: number;
|
|
229
272
|
}>;
|
|
273
|
+
/** A write the network is not known to apply once, whose answer was lost: never sent again; the node's reads decide. */
|
|
274
|
+
private checked;
|
|
230
275
|
/**
|
|
231
276
|
* The batch as it will be signed: every place action's price and size on its market's tick and lot (one rules read
|
|
232
277
|
* per batch). Refuses, before signing, a size that rounds to 0 or an order below the network's minimum.
|
|
233
278
|
*/
|
|
234
279
|
onSteps(actions: BatchAction[]): Promise<BatchAction[]>;
|
|
235
|
-
/**
|
|
236
|
-
|
|
280
|
+
/**
|
|
281
|
+
* Cancel every open order on `pairId` (0 = every market). The open orders are read first. A cancel-all is never sent
|
|
282
|
+
* again after a lost answer (a late copy could cancel orders placed after the first applied); its outcome is then read
|
|
283
|
+
* from the node — none of the orders listed before is still listed — for up to `settleMs` (default 30 s; 0 returns
|
|
284
|
+
* at once): `outcome` and, while it is not final, `pending`.
|
|
285
|
+
*/
|
|
286
|
+
cancelAll(pairId?: number, opts?: {
|
|
287
|
+
settleMs?: number;
|
|
288
|
+
}): Promise<Submitted & Checked & {
|
|
289
|
+
attempts: number;
|
|
290
|
+
unknown: boolean;
|
|
291
|
+
}>;
|
|
237
292
|
/**
|
|
238
293
|
* Cancel-and-replace at a new price and size (a new order id, no time priority). The new price and size go onto the
|
|
239
294
|
* order's market tick and lot (a buy's price down, a sell's up, the size down); the market and side come from `opts`,
|
|
@@ -300,7 +355,12 @@ export declare class Account {
|
|
|
300
355
|
setMarginMode(pairId: number, mode: MarginMode, waitMs?: number): Promise<Result>;
|
|
301
356
|
private submitAgentOp;
|
|
302
357
|
private addr;
|
|
303
|
-
/**
|
|
358
|
+
/**
|
|
359
|
+
* Register an agent key with a name (the chain's name rule) and a mandate; applied once the chain lists it. The
|
|
360
|
+
* agent's record is read first: an agent that was ever revoked throws {@link AgentWasRevoked} (make a new key), a
|
|
361
|
+
* live agent may be registered again (renew / extend), and a record that cannot be read throws
|
|
362
|
+
* {@link NotAvailable}. Nothing is signed in either refusal.
|
|
363
|
+
*/
|
|
304
364
|
registerAgent(a: {
|
|
305
365
|
agent: string;
|
|
306
366
|
name: string;
|
|
@@ -313,7 +373,29 @@ export declare class Account {
|
|
|
313
373
|
* chain did not show the new name.
|
|
314
374
|
*/
|
|
315
375
|
renameAgent(agent: string, name: string, waitMs?: number): Promise<Result>;
|
|
376
|
+
/**
|
|
377
|
+
* Revoke an agent (RevokeAgent, owner key, its nonce above the chain's mark for that agent). An agent the chain already
|
|
378
|
+
* lists as revoked is not signed for. A lost answer sends the same bytes again (the network applies it once). It is
|
|
379
|
+
* applied only when the agent's committed record reads `revoked`: even after a 2xx the state is `pending_checking`
|
|
380
|
+
* until then. Reads for up to `waitMs` (default 30 s; 0 returns at once); `outcome` and, while not final, `pending`.
|
|
381
|
+
*/
|
|
316
382
|
revokeAgent(agent: string, waitMs?: number): Promise<Result>;
|
|
383
|
+
/** An owner write whose effect the node's reads decide: same bytes on every copy; pending until the read shows it. */
|
|
384
|
+
private ownerChecked;
|
|
385
|
+
/** Whether this network takes StopAllSigners, asked without signing: an empty body is refused as unreadable by a
|
|
386
|
+
* network that has the route; a missing route (404 / 405) or `not_in_force` means it does not take it yet. Null when
|
|
387
|
+
* the network did not answer (not known). */
|
|
388
|
+
takesStopAll(): Promise<boolean | null>;
|
|
389
|
+
/**
|
|
390
|
+
* Stop, on the chain, this account's trading key and every one of its agents with ONE owner signature (StopAllSigners,
|
|
391
|
+
* VordexSession domain, a deadline 120 s after block time — this computer's clock when block time cannot be read —, the
|
|
392
|
+
* session nonce above the stored one). It does not cancel resting orders. Nothing is signed where the network says it
|
|
393
|
+
* does not take it (`applied` false, `outcome` null). A lost
|
|
394
|
+
* answer sends the same bytes again. Applied only when the node reads no trading key and no live agent
|
|
395
|
+
* (`applied_other` when orders the wallet placed itself stay open); not_applied once its deadline passed with a key or
|
|
396
|
+
* an agent still live. Reads for up to `settleMs` (default 30 s; 0 returns at once).
|
|
397
|
+
*/
|
|
398
|
+
stopAll(settleMs?: number): Promise<Result>;
|
|
317
399
|
/**
|
|
318
400
|
* Set an agent's policy. Refused before signing when the chain would refuse it at apply (it does so silently). The
|
|
319
401
|
* agent itself may sign only a tightening of the stored policy, with its own nonce; the owner may loosen (the chain
|