Skip to content

Commit 4e44871

Browse files
juliaklaueclaude
andcommitted
docs(derive): one sessionKeys per subaccount rules out transfers
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QraCJyGMpezNsrSbRD9yQU
1 parent 4a9eed5 commit 4e44871

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ Subaccounts are chosen up front. `derive.deposit` creates new ones only with
106106
`newSubaccounts` (the first deposit needs it); without it, deposits go to the
107107
listed `subaccounts` only. Session keys only ever act on listed subaccounts
108108
and can't create new ones. A key acts on one or several of them and, when a
109-
role lists several, may move collateral and positions between them.
109+
role lists several, may move collateral and positions between them. To rule
110+
out transfers, use `derive.sessionKeys` once for each subaccount: each key
111+
then acts on a single one.
110112

111113
```ts
112114
derive.sessionKeys({

‎src/derive/index.sim.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ describe.skipIf(!simulationEnabled)('derive presets on mainnet state', () => {
110110
subaccounts: OWN,
111111
}),
112112
],
113+
// Once per subaccount, so no key spans both or transfers
114+
derive_separate: OWN.map((subaccount) =>
115+
derive.sessionKeys({
116+
chain: 1,
117+
keys: [KEY],
118+
scopes: DERIVE_SCOPES.optionsDesk,
119+
subaccounts: [subaccount],
120+
})
121+
),
113122
derive_app: [
114123
derive.sessionKeys({
115124
chain: 1,
@@ -244,6 +253,13 @@ describe.skipIf(!simulationEnabled)('derive presets on mainnet state', () => {
244253
data: setKey(KEY, EXPIRY, [6, 12], [OWN[1]]),
245254
allowed: true,
246255
},
256+
{
257+
label: 'register a key on either subaccount',
258+
role: 'derive_separate',
259+
to: ACTION_MANAGER,
260+
data: setKey(KEY, EXPIRY, [6, 10], [OWN[1]]),
261+
allowed: true,
262+
},
247263
{
248264
label: 'top-up without new subaccounts',
249265
role: 'derive_topups',
@@ -402,6 +418,20 @@ describe.skipIf(!simulationEnabled)('derive presets on mainnet state', () => {
402418
data: setKey(KEY, EXPIRY, [10], [...OWN, OWN[0]]),
403419
allowed: false,
404420
},
421+
{
422+
label: 'separate keys: one key for both',
423+
role: 'derive_separate',
424+
to: ACTION_MANAGER,
425+
data: setKey(KEY, EXPIRY, [6, 10], [...OWN]),
426+
allowed: false,
427+
},
428+
{
429+
label: 'separate keys: a key that transfers',
430+
role: 'derive_separate',
431+
to: ACTION_MANAGER,
432+
data: setKey(KEY, EXPIRY, [6, 12], [OWN[0]]),
433+
allowed: false,
434+
},
405435
{
406436
label: 'the app’s admin key, unrestricted',
407437
role: 'derive_app',

‎src/derive/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ export type DeriveSessionKeysParams = {
208208
/**
209209
* The avatar's existing subaccounts the keys may act on. A key acts on one
210210
* or several of them, and may move collateral and positions between them
211-
* (`transferExistingSubaccount`).
211+
* (`transferExistingSubaccount`). To keep subaccounts apart, call
212+
* `derive.sessionKeys` once per subaccount instead.
212213
*/
213214
subaccounts: Subaccounts
214215
/** Latest expiry a key may get. Leave it out for no limit. */

0 commit comments

Comments
 (0)