@0xmonaco/contracts 1.1.12 → 1.1.15

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/sweeper.d.ts CHANGED
@@ -18,28 +18,34 @@
18
18
  * spellings at registration because the lookup is an exact match.
19
19
  *
20
20
  * The deposit target is hashed the same way, through the encoding in
21
- * {@link encodeDepositApplicationData}, so `"spot"` and `"margin"` are two
22
- * different addresses for one application and user, each carrying its own
23
- * target. A `"spot"` address is never credited to margin.
21
+ * {@link encodeDepositApplicationData}, so `"spot"`, `"margin"` and
22
+ * `"cross_risk_bucket"` are three different addresses for one application and
23
+ * user, each carrying its own target. A `"spot"` address is never credited to
24
+ * margin.
24
25
  *
25
- * The reverse is not absolute: `"margin"` is a routing *request*. A deposit the
26
- * backend cannot route to collateral — an unsupported collateral asset, or a
27
- * margin account that fails validation — is credited to the spot wallet
28
- * instead, so funds are never stranded. Derivation fixes which request the
29
- * address carries, not which ledger the credit ultimately lands in.
26
+ * The reverse is not absolute: `"margin"` and `"cross_risk_bucket"` are routing
27
+ * *requests*. A deposit the backend cannot route to collateral — an
28
+ * unsupported collateral asset, or a margin account that fails validation — is
29
+ * credited to the spot wallet instead, so funds are never stranded. Derivation
30
+ * fixes which request the address carries, not which ledger the credit
31
+ * ultimately lands in.
30
32
  */
31
33
  export type Hex = `0x${string}`;
32
34
  /**
33
35
  * Which ledger a deposit asks to be credited to.
34
36
  *
35
37
  * `"spot"` credits the spot wallet; `"margin"` asks for the parent margin
36
- * account's collateral. The target is part of the sweeper address derivation,
37
- * so the same pair has one deposit address per target.
38
+ * account's collateral; `"cross_risk_bucket"` asks for the parent margin
39
+ * account's collateral, then allocates the amount to its cross risk bucket.
40
+ * The target is part of the sweeper address derivation, so the same pair has
41
+ * one deposit address per target.
38
42
  *
39
- * `"margin"` is a request: a deposit the backend cannot route to collateral
40
- * falls back to the spot wallet rather than being stranded.
43
+ * `"margin"` and `"cross_risk_bucket"` are requests: a deposit the backend
44
+ * cannot route to collateral falls back to the spot wallet rather than being
45
+ * stranded, and a cross risk bucket deposit whose allocation is refused (a
46
+ * bucket in bad debt) stays unallocated on the margin account.
41
47
  */
42
- export type DepositTarget = "spot" | "margin";
48
+ export type DepositTarget = "spot" | "margin" | "cross_risk_bucket";
43
49
  /**
44
50
  * Encodes the on-chain `applicationData` a deposit carries.
45
51
  *
@@ -48,10 +54,11 @@ export type DepositTarget = "spot" | "margin";
48
54
  * this string, so encoding spot any other way would move every address already
49
55
  * published to a user.
50
56
  *
51
- * Margin emits the canonical routing payload the backend decodes. It is built
52
- * with `JSON.stringify` rather than string concatenation so a client id
53
- * containing a quote, a backslash, or a brace is escaped instead of breaking
54
- * out of the object. Key order is fixed and part of the derivation.
57
+ * Margin and cross risk bucket emit the canonical routing payload the backend
58
+ * decodes. It is built with `JSON.stringify` rather than string concatenation
59
+ * so a client id containing a quote, a backslash, or a brace is escaped
60
+ * instead of breaking out of the object. Key order is fixed and part of the
61
+ * derivation.
55
62
  *
56
63
  * The byte-for-byte counterpart of `encode_application_data` in
57
64
  * `utils/src/deposit_routing.rs`.
@@ -80,8 +87,8 @@ export interface SweeperAddressInput {
80
87
  *
81
88
  * Must match the `depositTarget` the pair was registered with: the target is
82
89
  * inside the derivation, so a mismatch derives a real, fundable address that
83
- * nothing is monitoring. Anything but `"spot"` or `"margin"` throws rather
84
- * than defaulting, for the same reason.
90
+ * nothing is monitoring. Anything but `"spot"`, `"margin"` or
91
+ * `"cross_risk_bucket"` throws rather than defaulting, for the same reason.
85
92
  */
86
93
  depositTarget?: DepositTarget;
87
94
  }
@@ -90,7 +97,7 @@ export interface SweeperAddressInput {
90
97
  *
91
98
  * @returns The EIP-55 checksummed sweeper address, deployed or not.
92
99
  * @throws If any address is malformed, the client id is empty, or the deposit
93
- * target is not exactly `"spot"` or `"margin"`.
100
+ * target is not exactly `"spot"`, `"margin"` or `"cross_risk_bucket"`.
94
101
  */
95
102
  export declare function predictSweeperAddress({ factory, forwarder, clientId, user, depositTarget }: SweeperAddressInput): Hex;
96
103
  /**
package/dist/sweeper.js CHANGED
@@ -1,4 +1,8 @@
1
1
  import { keccak_256 } from "@noble/hashes/sha3.js";
2
+ /** Each routed target's `depositTarget` value in the canonical payload. */
3
+ function canonicalTarget(target) {
4
+ return target === "margin" ? "MARGIN" : "CROSS_RISK_BUCKET";
5
+ }
2
6
  const ADDRESS = /^0x[0-9a-fA-F]{40}$/;
3
7
  /** EIP-1167-with-immutable-args runtime prefix, up to the delegation target. */
4
8
  const CLONE_RUNTIME_PREFIX = "3d81600a3d39f3363d3d373d3d3d363d73";
@@ -21,31 +25,33 @@ const SALT = new Uint8Array(32);
21
25
  * this string, so encoding spot any other way would move every address already
22
26
  * published to a user.
23
27
  *
24
- * Margin emits the canonical routing payload the backend decodes. It is built
25
- * with `JSON.stringify` rather than string concatenation so a client id
26
- * containing a quote, a backslash, or a brace is escaped instead of breaking
27
- * out of the object. Key order is fixed and part of the derivation.
28
+ * Margin and cross risk bucket emit the canonical routing payload the backend
29
+ * decodes. It is built with `JSON.stringify` rather than string concatenation
30
+ * so a client id containing a quote, a backslash, or a brace is escaped
31
+ * instead of breaking out of the object. Key order is fixed and part of the
32
+ * derivation.
28
33
  *
29
34
  * The byte-for-byte counterpart of `encode_application_data` in
30
35
  * `utils/src/deposit_routing.rs`.
31
36
  */
32
37
  export function encodeDepositApplicationData(clientId, target) {
33
38
  assertDepositTarget(target);
34
- return target === "margin" ? JSON.stringify({ clientId, depositTarget: "MARGIN" }) : clientId;
39
+ return target === "spot" ? clientId : JSON.stringify({ clientId, depositTarget: canonicalTarget(target) });
35
40
  }
36
41
  /**
37
- * Rejects anything that is not exactly `"spot"` or `"margin"`.
42
+ * Rejects anything that is not exactly `"spot"`, `"margin"` or
43
+ * `"cross_risk_bucket"`.
38
44
  *
39
- * Without this, `target === "margin" ? … : …` sends every other value down the
40
- * spot branch, so an untyped JavaScript caller — or one who passed the wire
41
- * form `"MARGIN"` copied from the API reference — silently derives a real,
42
- * fundable **spot** address while believing it is a margin one. That is the
45
+ * Without this, an untyped JavaScript caller — or one who passed the wire
46
+ * form `"MARGIN"` copied from the API reference — could derive a real,
47
+ * fundable address for a ledger other than the one they meant. That is the
43
48
  * same failure the backend refuses with a 400 rather than defaulting, and it is
44
49
  * worse here: nothing round-trips through a server to reveal the mistake.
45
50
  */
46
51
  function assertDepositTarget(value) {
47
- if (value !== "spot" && value !== "margin") {
48
- throw new Error(`Invalid deposit target: ${JSON.stringify(value)}. ` + 'Expected "spot" or "margin" — lowercase, not the wire form "SPOT"/"MARGIN".');
52
+ if (value !== "spot" && value !== "margin" && value !== "cross_risk_bucket") {
53
+ throw new Error(`Invalid deposit target: ${JSON.stringify(value)}. ` +
54
+ 'Expected "spot", "margin" or "cross_risk_bucket" — lowercase, not the wire form "SPOT"/"MARGIN"/"CROSS_RISK_BUCKET".');
49
55
  }
50
56
  }
51
57
  /**
@@ -53,7 +59,7 @@ function assertDepositTarget(value) {
53
59
  *
54
60
  * @returns The EIP-55 checksummed sweeper address, deployed or not.
55
61
  * @throws If any address is malformed, the client id is empty, or the deposit
56
- * target is not exactly `"spot"` or `"margin"`.
62
+ * target is not exactly `"spot"`, `"margin"` or `"cross_risk_bucket"`.
57
63
  */
58
64
  export function predictSweeperAddress({ factory, forwarder, clientId, user, depositTarget = "spot" }) {
59
65
  const factoryAddress = assertAddress(factory, "factory");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmonaco/contracts",
3
- "version": "1.1.12",
3
+ "version": "1.1.15",
4
4
  "type": "module",
5
5
  "homepage": "https://docs.0xmonaco.com/sdk/typescript",
6
6
  "main": "./dist/index.js",