@usesigil/kit 0.2.2 → 0.2.3
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 +2 -2
- package/dist/advanced-analytics.d.ts +3 -1
- package/dist/advanced-analytics.d.ts.map +1 -1
- package/dist/advanced-analytics.js +31 -15
- package/dist/advanced-analytics.js.map +1 -1
- package/dist/agent-analytics.d.ts +6 -6
- package/dist/agent-analytics.d.ts.map +1 -1
- package/dist/agent-analytics.js +16 -14
- package/dist/agent-analytics.js.map +1 -1
- package/dist/agent-errors.d.ts +4 -3
- package/dist/agent-errors.d.ts.map +1 -1
- package/dist/agent-errors.js +83 -7
- package/dist/agent-errors.js.map +1 -1
- package/dist/create-vault.js +1 -1
- package/dist/create-vault.js.map +1 -1
- package/dist/dashboard/constraint-reads.d.ts +50 -0
- package/dist/dashboard/constraint-reads.d.ts.map +1 -0
- package/dist/dashboard/constraint-reads.js +119 -0
- package/dist/dashboard/constraint-reads.js.map +1 -0
- package/dist/dashboard/errors.d.ts +14 -0
- package/dist/dashboard/errors.d.ts.map +1 -0
- package/dist/dashboard/errors.js +71 -0
- package/dist/dashboard/errors.js.map +1 -0
- package/dist/dashboard/index.d.ts +11 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +19 -0
- package/dist/dashboard/index.js.map +1 -1
- package/dist/dashboard/mutations.d.ts +18 -0
- package/dist/dashboard/mutations.d.ts.map +1 -1
- package/dist/dashboard/mutations.js +36 -34
- package/dist/dashboard/mutations.js.map +1 -1
- package/dist/dashboard/reads.d.ts.map +1 -1
- package/dist/dashboard/reads.js +385 -274
- package/dist/dashboard/reads.js.map +1 -1
- package/dist/dashboard/types.d.ts +8 -6
- package/dist/dashboard/types.d.ts.map +1 -1
- package/dist/event-analytics.d.ts +5 -0
- package/dist/event-analytics.d.ts.map +1 -1
- package/dist/event-analytics.js +40 -3
- package/dist/event-analytics.js.map +1 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +6 -1
- package/dist/events.js.map +1 -1
- package/dist/formatting.d.ts +40 -1
- package/dist/formatting.d.ts.map +1 -1
- package/dist/formatting.js +53 -5
- package/dist/formatting.js.map +1 -1
- package/dist/generated/accounts/index.d.ts +1 -0
- package/dist/generated/accounts/index.d.ts.map +1 -1
- package/dist/generated/accounts/index.js +1 -0
- package/dist/generated/accounts/index.js.map +1 -1
- package/dist/generated/accounts/instructionConstraints.d.ts +20 -11
- package/dist/generated/accounts/instructionConstraints.d.ts.map +1 -1
- package/dist/generated/accounts/instructionConstraints.js +17 -8
- package/dist/generated/accounts/instructionConstraints.js.map +1 -1
- package/dist/generated/accounts/pendingAgentPermissionsUpdate.d.ts +4 -2
- package/dist/generated/accounts/pendingAgentPermissionsUpdate.d.ts.map +1 -1
- package/dist/generated/accounts/pendingAgentPermissionsUpdate.js +4 -2
- package/dist/generated/accounts/pendingAgentPermissionsUpdate.js.map +1 -1
- package/dist/generated/accounts/pendingConstraintsUpdate.d.ts +30 -21
- package/dist/generated/accounts/pendingConstraintsUpdate.d.ts.map +1 -1
- package/dist/generated/accounts/pendingConstraintsUpdate.js +17 -10
- package/dist/generated/accounts/pendingConstraintsUpdate.js.map +1 -1
- package/dist/generated/accounts/policyConfig.d.ts +14 -8
- package/dist/generated/accounts/policyConfig.d.ts.map +1 -1
- package/dist/generated/accounts/policyConfig.js +2 -0
- package/dist/generated/accounts/policyConfig.js.map +1 -1
- package/dist/generated/accounts/postExecutionAssertions.d.ts +50 -0
- package/dist/generated/accounts/postExecutionAssertions.d.ts.map +1 -0
- package/dist/generated/accounts/postExecutionAssertions.js +72 -0
- package/dist/generated/accounts/postExecutionAssertions.js.map +1 -0
- package/dist/generated/accounts/sessionAuthority.d.ts +14 -5
- package/dist/generated/accounts/sessionAuthority.d.ts.map +1 -1
- package/dist/generated/accounts/sessionAuthority.js +5 -4
- package/dist/generated/accounts/sessionAuthority.js.map +1 -1
- package/dist/generated/errors/sigil.d.ts +16 -2
- package/dist/generated/errors/sigil.d.ts.map +1 -1
- package/dist/generated/errors/sigil.js +23 -2
- package/dist/generated/errors/sigil.js.map +1 -1
- package/dist/generated/event-discriminators.d.ts.map +1 -1
- package/dist/generated/event-discriminators.js +6 -1
- package/dist/generated/event-discriminators.js.map +1 -1
- package/dist/generated/instructions/allocateConstraintsPda.d.ts +62 -0
- package/dist/generated/instructions/allocateConstraintsPda.d.ts.map +1 -0
- package/dist/generated/instructions/allocateConstraintsPda.js +134 -0
- package/dist/generated/instructions/allocateConstraintsPda.js.map +1 -0
- package/dist/generated/instructions/allocatePendingConstraintsPda.d.ts +66 -0
- package/dist/generated/instructions/allocatePendingConstraintsPda.d.ts.map +1 -0
- package/dist/generated/instructions/allocatePendingConstraintsPda.js +157 -0
- package/dist/generated/instructions/allocatePendingConstraintsPda.js.map +1 -0
- package/dist/generated/instructions/applyConstraintsUpdate.d.ts +3 -12
- package/dist/generated/instructions/applyConstraintsUpdate.d.ts.map +1 -1
- package/dist/generated/instructions/applyConstraintsUpdate.js.map +1 -1
- package/dist/generated/instructions/closePostAssertions.d.ts +59 -0
- package/dist/generated/instructions/closePostAssertions.d.ts.map +1 -0
- package/dist/generated/instructions/closePostAssertions.js +137 -0
- package/dist/generated/instructions/closePostAssertions.js.map +1 -0
- package/dist/generated/instructions/createInstructionConstraints.d.ts +10 -11
- package/dist/generated/instructions/createInstructionConstraints.d.ts.map +1 -1
- package/dist/generated/instructions/createInstructionConstraints.js +2 -16
- package/dist/generated/instructions/createInstructionConstraints.js.map +1 -1
- package/dist/generated/instructions/createPostAssertions.d.ts +65 -0
- package/dist/generated/instructions/createPostAssertions.d.ts.map +1 -0
- package/dist/generated/instructions/createPostAssertions.js +146 -0
- package/dist/generated/instructions/createPostAssertions.js.map +1 -0
- package/dist/generated/instructions/extendPda.d.ts +52 -0
- package/dist/generated/instructions/extendPda.d.ts.map +1 -0
- package/dist/generated/instructions/extendPda.js +86 -0
- package/dist/generated/instructions/extendPda.js.map +1 -0
- package/dist/generated/instructions/index.d.ts +5 -0
- package/dist/generated/instructions/index.d.ts.map +1 -1
- package/dist/generated/instructions/index.js +5 -0
- package/dist/generated/instructions/index.js.map +1 -1
- package/dist/generated/instructions/queueAgentPermissionsUpdate.d.ts +4 -4
- package/dist/generated/instructions/queueAgentPermissionsUpdate.d.ts.map +1 -1
- package/dist/generated/instructions/queueAgentPermissionsUpdate.js +3 -3
- package/dist/generated/instructions/queueAgentPermissionsUpdate.js.map +1 -1
- package/dist/generated/instructions/queueConstraintsUpdate.d.ts +13 -11
- package/dist/generated/instructions/queueConstraintsUpdate.d.ts.map +1 -1
- package/dist/generated/instructions/queueConstraintsUpdate.js +2 -16
- package/dist/generated/instructions/queueConstraintsUpdate.js.map +1 -1
- package/dist/generated/instructions/reactivateVault.d.ts +3 -3
- package/dist/generated/instructions/reactivateVault.d.ts.map +1 -1
- package/dist/generated/instructions/reactivateVault.js +3 -3
- package/dist/generated/instructions/reactivateVault.js.map +1 -1
- package/dist/generated/instructions/registerAgent.d.ts +3 -3
- package/dist/generated/instructions/registerAgent.d.ts.map +1 -1
- package/dist/generated/instructions/registerAgent.js +3 -3
- package/dist/generated/instructions/registerAgent.js.map +1 -1
- package/dist/generated/instructions/validateAndAuthorize.d.ts +4 -13
- package/dist/generated/instructions/validateAndAuthorize.d.ts.map +1 -1
- package/dist/generated/instructions/validateAndAuthorize.js +1 -6
- package/dist/generated/instructions/validateAndAuthorize.js.map +1 -1
- package/dist/generated/programs/sigil.d.ts +56 -34
- package/dist/generated/programs/sigil.d.ts.map +1 -1
- package/dist/generated/programs/sigil.js +99 -34
- package/dist/generated/programs/sigil.js.map +1 -1
- package/dist/generated/types/accountConstraintZC.d.ts +18 -0
- package/dist/generated/types/accountConstraintZC.d.ts.map +1 -0
- package/dist/generated/types/accountConstraintZC.js +26 -0
- package/dist/generated/types/accountConstraintZC.js.map +1 -0
- package/dist/generated/types/actionAuthorized.d.ts +2 -13
- package/dist/generated/types/actionAuthorized.d.ts.map +1 -1
- package/dist/generated/types/actionAuthorized.js +2 -3
- package/dist/generated/types/actionAuthorized.js.map +1 -1
- package/dist/generated/types/agentEntry.d.ts +13 -3
- package/dist/generated/types/agentEntry.d.ts.map +1 -1
- package/dist/generated/types/agentEntry.js +5 -3
- package/dist/generated/types/agentEntry.js.map +1 -1
- package/dist/generated/types/agentRegistered.d.ts +2 -2
- package/dist/generated/types/agentRegistered.d.ts.map +1 -1
- package/dist/generated/types/agentRegistered.js +3 -3
- package/dist/generated/types/agentRegistered.js.map +1 -1
- package/dist/generated/types/constraintEntry.d.ts +11 -1
- package/dist/generated/types/constraintEntry.d.ts.map +1 -1
- package/dist/generated/types/constraintEntry.js +8 -2
- package/dist/generated/types/constraintEntry.js.map +1 -1
- package/dist/generated/types/constraintEntryZC.d.ts +51 -0
- package/dist/generated/types/constraintEntryZC.d.ts.map +1 -0
- package/dist/generated/types/constraintEntryZC.js +49 -0
- package/dist/generated/types/constraintEntryZC.js.map +1 -0
- package/dist/generated/types/constraintsChangeApplied.d.ts +6 -4
- package/dist/generated/types/constraintsChangeApplied.d.ts.map +1 -1
- package/dist/generated/types/constraintsChangeApplied.js +3 -1
- package/dist/generated/types/constraintsChangeApplied.js.map +1 -1
- package/dist/generated/types/constraintsChangeQueued.d.ts +6 -4
- package/dist/generated/types/constraintsChangeQueued.d.ts.map +1 -1
- package/dist/generated/types/constraintsChangeQueued.js +3 -1
- package/dist/generated/types/constraintsChangeQueued.js.map +1 -1
- package/dist/generated/types/dataConstraintZC.d.ts +20 -0
- package/dist/generated/types/dataConstraintZC.d.ts.map +1 -0
- package/dist/generated/types/dataConstraintZC.js +30 -0
- package/dist/generated/types/dataConstraintZC.js.map +1 -0
- package/dist/generated/types/discriminatorFormat.d.ts +17 -0
- package/dist/generated/types/discriminatorFormat.d.ts.map +1 -0
- package/dist/generated/types/discriminatorFormat.js +23 -0
- package/dist/generated/types/discriminatorFormat.js.map +1 -0
- package/dist/generated/types/index.d.ts +11 -1
- package/dist/generated/types/index.d.ts.map +1 -1
- package/dist/generated/types/index.js +11 -1
- package/dist/generated/types/index.js.map +1 -1
- package/dist/generated/types/instructionConstraintsCreated.d.ts +6 -4
- package/dist/generated/types/instructionConstraintsCreated.d.ts.map +1 -1
- package/dist/generated/types/instructionConstraintsCreated.js +3 -1
- package/dist/generated/types/instructionConstraintsCreated.js.map +1 -1
- package/dist/generated/types/pdaAllocated.d.ts +24 -0
- package/dist/generated/types/pdaAllocated.d.ts.map +1 -0
- package/dist/generated/types/pdaAllocated.js +28 -0
- package/dist/generated/types/pdaAllocated.js.map +1 -0
- package/dist/generated/types/pdaExtended.d.ts +24 -0
- package/dist/generated/types/pdaExtended.d.ts.map +1 -0
- package/dist/generated/types/pdaExtended.js +28 -0
- package/dist/generated/types/pdaExtended.js.map +1 -0
- package/dist/generated/types/postAssertionChecked.d.ts +24 -0
- package/dist/generated/types/postAssertionChecked.d.ts.map +1 -0
- package/dist/generated/types/postAssertionChecked.js +28 -0
- package/dist/generated/types/postAssertionChecked.js.map +1 -0
- package/dist/generated/types/postAssertionEntry.d.ts +22 -0
- package/dist/generated/types/postAssertionEntry.d.ts.map +1 -0
- package/dist/generated/types/postAssertionEntry.js +32 -0
- package/dist/generated/types/postAssertionEntry.js.map +1 -0
- package/dist/generated/types/postAssertionEntryZC.d.ts +54 -0
- package/dist/generated/types/postAssertionEntryZC.d.ts.map +1 -0
- package/dist/generated/types/postAssertionEntryZC.js +34 -0
- package/dist/generated/types/postAssertionEntryZC.js.map +1 -0
- package/dist/generated/types/postAssertionsClosed.d.ts +20 -0
- package/dist/generated/types/postAssertionsClosed.d.ts.map +1 -0
- package/dist/generated/types/postAssertionsClosed.js +24 -0
- package/dist/generated/types/postAssertionsClosed.js.map +1 -0
- package/dist/generated/types/postAssertionsCreated.d.ts +22 -0
- package/dist/generated/types/postAssertionsCreated.d.ts.map +1 -0
- package/dist/generated/types/postAssertionsCreated.js +26 -0
- package/dist/generated/types/postAssertionsCreated.js.map +1 -0
- package/dist/generated/types/sessionFinalized.d.ts +10 -12
- package/dist/generated/types/sessionFinalized.d.ts.map +1 -1
- package/dist/generated/types/sessionFinalized.js +4 -2
- package/dist/generated/types/sessionFinalized.js.map +1 -1
- package/dist/generated/types/vaultReactivated.d.ts +2 -2
- package/dist/generated/types/vaultReactivated.d.ts.map +1 -1
- package/dist/generated/types/vaultReactivated.js +3 -3
- package/dist/generated/types/vaultReactivated.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/inscribe.d.ts +1 -1
- package/dist/inscribe.d.ts.map +1 -1
- package/dist/integrations/compose-errors.d.ts +64 -0
- package/dist/integrations/compose-errors.d.ts.map +1 -0
- package/dist/integrations/compose-errors.js +105 -0
- package/dist/integrations/compose-errors.js.map +1 -0
- package/dist/integrations/protocol-handler.d.ts +59 -0
- package/dist/integrations/protocol-handler.d.ts.map +1 -0
- package/dist/integrations/protocol-handler.js +9 -0
- package/dist/integrations/protocol-handler.js.map +1 -0
- package/dist/presets.d.ts +10 -4
- package/dist/presets.d.ts.map +1 -1
- package/dist/presets.js +8 -4
- package/dist/presets.js.map +1 -1
- package/dist/seal.d.ts +2 -17
- package/dist/seal.d.ts.map +1 -1
- package/dist/seal.js +18 -62
- package/dist/seal.js.map +1 -1
- package/dist/security-analytics.d.ts +1 -1
- package/dist/security-analytics.d.ts.map +1 -1
- package/dist/security-analytics.js +48 -20
- package/dist/security-analytics.js.map +1 -1
- package/dist/testing/devnet.js +3 -3
- package/dist/testing/devnet.js.map +1 -1
- package/dist/testing/mock-state.d.ts +2 -0
- package/dist/testing/mock-state.d.ts.map +1 -1
- package/dist/testing/mock-state.js +6 -2
- package/dist/testing/mock-state.js.map +1 -1
- package/dist/types.d.ts +16 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +15 -4
- package/dist/types.js.map +1 -1
- package/dist/vault-analytics.d.ts.map +1 -1
- package/dist/vault-analytics.js +3 -3
- package/dist/vault-analytics.js.map +1 -1
- package/package.json +4 -4
- package/dist/generated/types/actionType.d.ts +0 -37
- package/dist/generated/types/actionType.d.ts.map +0 -1
- package/dist/generated/types/actionType.js +0 -43
- package/dist/generated/types/actionType.js.map +0 -1
package/dist/dashboard/reads.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Each function is stateless (fetches fresh from RPC), composes existing
|
|
5
5
|
* SDK functions, and returns raw values with toJSON() for MCP serialization.
|
|
6
6
|
*/
|
|
7
|
+
import { isSome } from "@solana/kit";
|
|
8
|
+
import { toDxError } from "./errors.js";
|
|
7
9
|
import { resolveVaultStateForOwner, getSpendingHistory, getPendingPolicyForVault, } from "../state-resolver.js";
|
|
8
10
|
import { getVaultPnL } from "../balance-tracker.js";
|
|
9
11
|
import { getSecurityPosture } from "../security-analytics.js";
|
|
@@ -42,209 +44,273 @@ function serializeBigints(obj) {
|
|
|
42
44
|
}
|
|
43
45
|
// ─── getVaultState ───────────────────────────────────────────────────────────
|
|
44
46
|
export async function getVaultState(rpc, vault, network) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
openPositions: v.openPositions,
|
|
73
|
-
totalVolume: v.totalVolume,
|
|
74
|
-
totalFees: v.totalFeesCollected,
|
|
75
|
-
},
|
|
76
|
-
balance: { total, tokens },
|
|
77
|
-
pnl: {
|
|
78
|
-
percent: Number.isFinite(pnl.pnlPercent) ? pnl.pnlPercent : 0,
|
|
79
|
-
absolute: pnl.pnl,
|
|
80
|
-
},
|
|
81
|
-
health: { level, alertCount: posture.failCount, checks },
|
|
82
|
-
toJSON: () => ({
|
|
47
|
+
try {
|
|
48
|
+
const [state, pnl] = await Promise.all([
|
|
49
|
+
resolveVaultStateForOwner(rpc, vault, undefined, toNet(network)),
|
|
50
|
+
getVaultPnL(rpc, vault, toNet(network)),
|
|
51
|
+
]);
|
|
52
|
+
const posture = getSecurityPosture(asVaultState(state));
|
|
53
|
+
const v = state.vault;
|
|
54
|
+
const bal = state.stablecoinBalances;
|
|
55
|
+
const total = bal.usdc + bal.usdt;
|
|
56
|
+
const tokens = [
|
|
57
|
+
...(bal.usdc > 0n
|
|
58
|
+
? [{ mint: "USDC", amount: bal.usdc, decimals: 6 }]
|
|
59
|
+
: []),
|
|
60
|
+
...(bal.usdt > 0n
|
|
61
|
+
? [{ mint: "USDT", amount: bal.usdt, decimals: 6 }]
|
|
62
|
+
: []),
|
|
63
|
+
];
|
|
64
|
+
const checks = posture.checks.map((c) => ({
|
|
65
|
+
name: c.id,
|
|
66
|
+
passed: c.passed,
|
|
67
|
+
}));
|
|
68
|
+
const level = posture.criticalFailures.length > 0
|
|
69
|
+
? "critical"
|
|
70
|
+
: posture.failCount > 0
|
|
71
|
+
? "elevated"
|
|
72
|
+
: "healthy";
|
|
73
|
+
return {
|
|
83
74
|
vault: {
|
|
84
75
|
address: vault,
|
|
85
|
-
status:
|
|
86
|
-
? "active"
|
|
87
|
-
: v.status === 1
|
|
88
|
-
? "frozen"
|
|
89
|
-
: "closed"),
|
|
76
|
+
status: v.status === 0 ? "active" : v.status === 1 ? "frozen" : "closed",
|
|
90
77
|
owner: v.owner,
|
|
91
78
|
agentCount: v.agents?.length ?? 0,
|
|
92
79
|
openPositions: v.openPositions,
|
|
93
|
-
totalVolume:
|
|
94
|
-
totalFees:
|
|
95
|
-
},
|
|
96
|
-
balance: {
|
|
97
|
-
total: bs(total),
|
|
98
|
-
tokens: tokens.map((t) => ({ ...t, amount: bs(t.amount) })),
|
|
80
|
+
totalVolume: v.totalVolume,
|
|
81
|
+
totalFees: v.totalFeesCollected,
|
|
99
82
|
},
|
|
83
|
+
balance: { total, tokens },
|
|
100
84
|
pnl: {
|
|
101
85
|
percent: Number.isFinite(pnl.pnlPercent) ? pnl.pnlPercent : 0,
|
|
102
|
-
absolute:
|
|
86
|
+
absolute: pnl.pnl,
|
|
103
87
|
},
|
|
104
88
|
health: { level, alertCount: posture.failCount, checks },
|
|
105
|
-
|
|
106
|
-
|
|
89
|
+
toJSON: () => ({
|
|
90
|
+
vault: {
|
|
91
|
+
address: vault,
|
|
92
|
+
status: (v.status === 0
|
|
93
|
+
? "active"
|
|
94
|
+
: v.status === 1
|
|
95
|
+
? "frozen"
|
|
96
|
+
: "closed"),
|
|
97
|
+
owner: v.owner,
|
|
98
|
+
agentCount: v.agents?.length ?? 0,
|
|
99
|
+
openPositions: v.openPositions,
|
|
100
|
+
totalVolume: bs(v.totalVolume),
|
|
101
|
+
totalFees: bs(v.totalFeesCollected),
|
|
102
|
+
},
|
|
103
|
+
balance: {
|
|
104
|
+
total: bs(total),
|
|
105
|
+
tokens: tokens.map((t) => ({ ...t, amount: bs(t.amount) })),
|
|
106
|
+
},
|
|
107
|
+
pnl: {
|
|
108
|
+
percent: Number.isFinite(pnl.pnlPercent) ? pnl.pnlPercent : 0,
|
|
109
|
+
absolute: bs(pnl.pnl),
|
|
110
|
+
},
|
|
111
|
+
health: { level, alertCount: posture.failCount, checks },
|
|
112
|
+
}),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
throw toDxError(err, "OwnerClient.getVaultState");
|
|
117
|
+
}
|
|
107
118
|
}
|
|
108
119
|
// ─── getAgents ───────────────────────────────────────────────────────────────
|
|
109
120
|
export async function getAgents(rpc, vault, network) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
lastActionTimestamp: 0,
|
|
130
|
-
blockedCount24h: 0,
|
|
131
|
-
toJSON: () => ({
|
|
132
|
-
address: addr,
|
|
133
|
-
status: profile?.paused ? "paused" : "active",
|
|
134
|
-
permissions: profile?.permissionStrings ?? [],
|
|
135
|
-
permissionBitmask: bs(profile?.permissions ?? 0n),
|
|
136
|
-
spending: { amount: bs(spentAmt), limit: bs(capAmt), percent: pct },
|
|
137
|
-
lastActionType: "",
|
|
138
|
-
lastActionProtocol: "",
|
|
139
|
-
lastActionTimestamp: 0,
|
|
140
|
-
blockedCount24h: 0,
|
|
121
|
+
try {
|
|
122
|
+
// Fetch vault state and activity feed in parallel. Single getVaultActivity
|
|
123
|
+
// call is shared across all agents (N+1 prevention). Activity is enrichment,
|
|
124
|
+
// so a fetch failure degrades gracefully to empty last-action fields.
|
|
125
|
+
// Window: 100 most recent signatures — large enough to surface last action
|
|
126
|
+
// for low-volume agents without inflating RPC cost.
|
|
127
|
+
const [state, activity] = await Promise.all([
|
|
128
|
+
resolveVaultStateForOwner(rpc, vault, undefined, toNet(network)),
|
|
129
|
+
// Fix for docs/SECURITY-FINDINGS-2026-04-07.md Finding 5: the
|
|
130
|
+
// previous `.catch(() => [])` swallowed activity-fetch failures
|
|
131
|
+
// silently. If Helius started rate-limiting getSignaturesForAddress,
|
|
132
|
+
// every dashboard call would show "last action: never" for every
|
|
133
|
+
// agent forever and nobody would notice. Graceful degradation is
|
|
134
|
+
// still the right behavior (activity is enrichment, not core), but
|
|
135
|
+
// it must be observable — console.warn is the minimum bar.
|
|
136
|
+
getVaultActivity(rpc, vault, 100, toNet(network)).catch((err) => {
|
|
137
|
+
// eslint-disable-next-line no-console
|
|
138
|
+
console.warn("[OwnerClient.getAgents] activity enrichment failed — falling back to empty last-action fields:", err instanceof Error ? err.message : String(err));
|
|
139
|
+
return [];
|
|
141
140
|
}),
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
]);
|
|
142
|
+
const vaultAgents = state.vault.agents;
|
|
143
|
+
if (!vaultAgents || vaultAgents.length === 0)
|
|
144
|
+
return [];
|
|
145
|
+
const blockedCutoffMs = Date.now() - 24 * 3600 * 1000;
|
|
146
|
+
return vaultAgents.map((entry) => {
|
|
147
|
+
const addr = entry.pubkey;
|
|
148
|
+
const profile = getAgentProfile(asVaultState(state), addr);
|
|
149
|
+
const budget = state.allAgentBudgets.get(addr);
|
|
150
|
+
const spentAmt = budget?.spent24h ?? 0n;
|
|
151
|
+
const capAmt = budget?.cap ?? 0n;
|
|
152
|
+
const pct = capAmt > 0n ? Number((spentAmt * 10000n) / capAmt) / 100 : 0;
|
|
153
|
+
// Derive last-action and blocked-count fields from the shared activity
|
|
154
|
+
// feed. Items are newest-first (getSignaturesForAddress ordering).
|
|
155
|
+
const agentActivity = activity.filter((item) => item.agent !== null && item.agent === addr);
|
|
156
|
+
const last = agentActivity[0];
|
|
157
|
+
const lastActionType = last
|
|
158
|
+
? mapCategory(last.category ?? "unknown", last.eventType ?? "", last.actionType ?? undefined)
|
|
159
|
+
: "";
|
|
160
|
+
const lastActionProtocol = last?.protocolName ?? "";
|
|
161
|
+
const lastActionTimestamp = last ? last.timestamp * 1000 : 0;
|
|
162
|
+
const blockedCount24h = agentActivity.filter((item) => !item.success && item.timestamp * 1000 >= blockedCutoffMs).length;
|
|
163
|
+
return {
|
|
164
|
+
address: addr,
|
|
165
|
+
status: (profile?.paused ? "paused" : "active"),
|
|
166
|
+
capabilityLabel: profile?.capabilityLabel ?? "Disabled",
|
|
167
|
+
capability: profile?.capability ?? 0,
|
|
168
|
+
spending: { amount: spentAmt, limit: capAmt, percent: pct },
|
|
169
|
+
lastActionType,
|
|
170
|
+
lastActionProtocol,
|
|
171
|
+
lastActionTimestamp,
|
|
172
|
+
blockedCount24h,
|
|
173
|
+
toJSON: () => ({
|
|
174
|
+
address: addr,
|
|
175
|
+
status: profile?.paused ? "paused" : "active",
|
|
176
|
+
capabilityLabel: profile?.capabilityLabel ?? "Disabled",
|
|
177
|
+
capability: profile?.capability ?? 0,
|
|
178
|
+
spending: { amount: bs(spentAmt), limit: bs(capAmt), percent: pct },
|
|
179
|
+
lastActionType,
|
|
180
|
+
lastActionProtocol,
|
|
181
|
+
lastActionTimestamp,
|
|
182
|
+
blockedCount24h,
|
|
183
|
+
}),
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
throw toDxError(err, "OwnerClient.getAgents");
|
|
189
|
+
}
|
|
144
190
|
}
|
|
145
191
|
// ─── getSpending ─────────────────────────────────────────────────────────────
|
|
146
192
|
export async function getSpending(rpc, vault, network) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
protocolBreakdown: protoBreak,
|
|
171
|
-
toJSON: () => ({
|
|
172
|
-
global: {
|
|
173
|
-
today: bs(spent),
|
|
174
|
-
cap: bs(cap),
|
|
175
|
-
remaining: bs(remaining),
|
|
176
|
-
percent,
|
|
177
|
-
rundownMs: rundown,
|
|
178
|
-
},
|
|
193
|
+
try {
|
|
194
|
+
const state = await resolveVaultStateForOwner(rpc, vault, undefined, toNet(network));
|
|
195
|
+
const breakdown = getSpendingBreakdown(asVaultState(state));
|
|
196
|
+
const nowUnix = BigInt(Math.floor(Date.now() / 1000));
|
|
197
|
+
const epochs = getSpendingHistory(state.tracker, nowUnix);
|
|
198
|
+
const chart = epochs.map((e) => ({
|
|
199
|
+
time: new Date(e.timestamp * 1000).toISOString(),
|
|
200
|
+
amount: Number(e.usdAmount) / 1_000_000,
|
|
201
|
+
}));
|
|
202
|
+
const { spent24h: spent, cap, remaining } = state.globalBudget;
|
|
203
|
+
const percent = cap > 0n ? Number((spent * 10000n) / cap) / 100 : 0;
|
|
204
|
+
const velocityPerMs = spent > 0n ? Number(spent) / (24 * 3600 * 1000) : 0;
|
|
205
|
+
const rundown = velocityPerMs > 0 && remaining > 0n
|
|
206
|
+
? Math.floor(Number(remaining) / velocityPerMs)
|
|
207
|
+
: 0;
|
|
208
|
+
const protoBreak = breakdown.byProtocol.map((p) => ({
|
|
209
|
+
name: resolveProtocolName(p.protocol),
|
|
210
|
+
programId: p.protocol,
|
|
211
|
+
amount: p.spent24h,
|
|
212
|
+
percent: p.utilization,
|
|
213
|
+
}));
|
|
214
|
+
return {
|
|
215
|
+
global: { today: spent, cap, remaining, percent, rundownMs: rundown },
|
|
179
216
|
chart,
|
|
180
|
-
protocolBreakdown: protoBreak
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
217
|
+
protocolBreakdown: protoBreak,
|
|
218
|
+
toJSON: () => ({
|
|
219
|
+
global: {
|
|
220
|
+
today: bs(spent),
|
|
221
|
+
cap: bs(cap),
|
|
222
|
+
remaining: bs(remaining),
|
|
223
|
+
percent,
|
|
224
|
+
rundownMs: rundown,
|
|
225
|
+
},
|
|
226
|
+
chart,
|
|
227
|
+
protocolBreakdown: protoBreak.map((p) => ({
|
|
228
|
+
...p,
|
|
229
|
+
amount: bs(p.amount),
|
|
230
|
+
})),
|
|
231
|
+
}),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
catch (err) {
|
|
235
|
+
throw toDxError(err, "OwnerClient.getSpending");
|
|
236
|
+
}
|
|
186
237
|
}
|
|
187
238
|
// ─── getActivity ─────────────────────────────────────────────────────────────
|
|
188
239
|
export async function getActivity(rpc, vault, network, filters) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
type,
|
|
202
|
-
protocol: item.protocolName || "",
|
|
203
|
-
protocolId: item.protocol || "",
|
|
204
|
-
agent: item.agent || "",
|
|
205
|
-
amount: amt,
|
|
206
|
-
status: item.success ? "approved" : "blocked",
|
|
207
|
-
reason: item.success ? undefined : item.description,
|
|
208
|
-
txSignature: item.txSignature,
|
|
209
|
-
toJSON: () => ({
|
|
240
|
+
try {
|
|
241
|
+
const limit = filters?.limit ?? 50;
|
|
242
|
+
const items = await getVaultActivity(rpc, vault, limit, toNet(network));
|
|
243
|
+
let rows = items.map((item, i) => {
|
|
244
|
+
const cat = item.category ?? "unknown";
|
|
245
|
+
const evt = item.eventType ?? "";
|
|
246
|
+
const act = item.actionType ?? undefined;
|
|
247
|
+
const posEffect = item.positionEffect ?? undefined;
|
|
248
|
+
const type = mapCategory(cat, evt, act, posEffect);
|
|
249
|
+
const amt = item.amount ?? 0n;
|
|
250
|
+
const sig = item.txSignature || `evt-${item.timestamp}-${item.eventType}`;
|
|
251
|
+
return {
|
|
210
252
|
id: sig,
|
|
211
253
|
timestamp: item.timestamp * 1000,
|
|
212
254
|
type,
|
|
213
255
|
protocol: item.protocolName || "",
|
|
214
256
|
protocolId: item.protocol || "",
|
|
215
257
|
agent: item.agent || "",
|
|
216
|
-
amount:
|
|
258
|
+
amount: amt,
|
|
217
259
|
status: item.success ? "approved" : "blocked",
|
|
218
260
|
reason: item.success ? undefined : item.description,
|
|
219
261
|
txSignature: item.txSignature,
|
|
262
|
+
toJSON: () => ({
|
|
263
|
+
id: sig,
|
|
264
|
+
timestamp: item.timestamp * 1000,
|
|
265
|
+
type,
|
|
266
|
+
protocol: item.protocolName || "",
|
|
267
|
+
protocolId: item.protocol || "",
|
|
268
|
+
agent: item.agent || "",
|
|
269
|
+
amount: bs(amt),
|
|
270
|
+
status: item.success ? "approved" : "blocked",
|
|
271
|
+
reason: item.success ? undefined : item.description,
|
|
272
|
+
txSignature: item.txSignature,
|
|
273
|
+
}),
|
|
274
|
+
};
|
|
275
|
+
});
|
|
276
|
+
if (filters?.agent)
|
|
277
|
+
rows = rows.filter((r) => r.agent === filters.agent);
|
|
278
|
+
if (filters?.protocol)
|
|
279
|
+
rows = rows.filter((r) => r.protocolId === filters.protocol || r.protocol === filters.protocol);
|
|
280
|
+
if (filters?.status)
|
|
281
|
+
rows = rows.filter((r) => r.status === filters.status);
|
|
282
|
+
if (filters?.type)
|
|
283
|
+
rows = rows.filter((r) => r.type === filters.type);
|
|
284
|
+
if (filters?.timeRange) {
|
|
285
|
+
const cutoff = Date.now() - rangeToMs(filters.timeRange);
|
|
286
|
+
rows = rows.filter((r) => r.timestamp >= cutoff);
|
|
287
|
+
}
|
|
288
|
+
const approved = rows.filter((r) => r.status === "approved").length;
|
|
289
|
+
const blocked = rows.length - approved;
|
|
290
|
+
const volume = rows.reduce((s, r) => s + r.amount, 0n);
|
|
291
|
+
return {
|
|
292
|
+
rows,
|
|
293
|
+
summary: { total: rows.length, approved, blocked, volume },
|
|
294
|
+
toJSON: () => ({
|
|
295
|
+
rows: rows.map((r) => r.toJSON()),
|
|
296
|
+
summary: { total: rows.length, approved, blocked, volume: bs(volume) },
|
|
220
297
|
}),
|
|
221
298
|
};
|
|
222
|
-
});
|
|
223
|
-
if (filters?.agent)
|
|
224
|
-
rows = rows.filter((r) => r.agent === filters.agent);
|
|
225
|
-
if (filters?.protocol)
|
|
226
|
-
rows = rows.filter((r) => r.protocolId === filters.protocol || r.protocol === filters.protocol);
|
|
227
|
-
if (filters?.status)
|
|
228
|
-
rows = rows.filter((r) => r.status === filters.status);
|
|
229
|
-
if (filters?.timeRange) {
|
|
230
|
-
const cutoff = Date.now() - rangeToMs(filters.timeRange);
|
|
231
|
-
rows = rows.filter((r) => r.timestamp >= cutoff);
|
|
232
299
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return {
|
|
237
|
-
rows,
|
|
238
|
-
summary: { total: rows.length, approved, blocked, volume },
|
|
239
|
-
toJSON: () => ({
|
|
240
|
-
rows: rows.map((r) => r.toJSON()),
|
|
241
|
-
summary: { total: rows.length, approved, blocked, volume: bs(volume) },
|
|
242
|
-
}),
|
|
243
|
-
};
|
|
300
|
+
catch (err) {
|
|
301
|
+
throw toDxError(err, "OwnerClient.getActivity");
|
|
302
|
+
}
|
|
244
303
|
}
|
|
245
|
-
function mapCategory(cat, evt, actionType) {
|
|
304
|
+
function mapCategory(cat, evt, actionType, positionEffect) {
|
|
246
305
|
if (cat === "trade") {
|
|
247
|
-
//
|
|
306
|
+
// v6 events carry positionEffect ("increment"/"decrement"/"none") instead
|
|
307
|
+
// of actionType. Prefer it when present — actionType is null for post-
|
|
308
|
+
// ActionType-elimination events.
|
|
309
|
+
if (positionEffect === "increment")
|
|
310
|
+
return "open_position";
|
|
311
|
+
if (positionEffect === "decrement")
|
|
312
|
+
return "close_position";
|
|
313
|
+
// Legacy v5 event path: actionType carries swap vs lend vs perps detail.
|
|
248
314
|
if (actionType) {
|
|
249
315
|
const at = actionType.toLowerCase();
|
|
250
316
|
if (at.includes("lend") ||
|
|
@@ -284,128 +350,173 @@ function rangeToMs(r) {
|
|
|
284
350
|
}
|
|
285
351
|
// ─── getHealth ───────────────────────────────────────────────────────────────
|
|
286
352
|
export async function getHealth(rpc, vault, network) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
blockedCount24h: critAlerts.length,
|
|
311
|
-
checks,
|
|
312
|
-
lastBlock,
|
|
313
|
-
toJSON: () => ({
|
|
353
|
+
try {
|
|
354
|
+
const state = await resolveVaultStateForOwner(rpc, vault, undefined, toNet(network));
|
|
355
|
+
const posture = getSecurityPosture(asVaultState(state));
|
|
356
|
+
const alerts = evaluateAlertConditions(state, vault);
|
|
357
|
+
const level = posture.criticalFailures.length > 0
|
|
358
|
+
? "critical"
|
|
359
|
+
: posture.failCount > 0
|
|
360
|
+
? "elevated"
|
|
361
|
+
: "healthy";
|
|
362
|
+
const critAlerts = alerts.filter((a) => a.severity === "critical");
|
|
363
|
+
const lastBlock = critAlerts.length > 0
|
|
364
|
+
? {
|
|
365
|
+
agent: critAlerts[0].agentAddress || "",
|
|
366
|
+
reason: critAlerts[0].title,
|
|
367
|
+
amount: 0n,
|
|
368
|
+
timestamp: Date.now(),
|
|
369
|
+
}
|
|
370
|
+
: undefined;
|
|
371
|
+
const checks = posture.checks.map((c) => ({
|
|
372
|
+
name: c.id,
|
|
373
|
+
passed: c.passed,
|
|
374
|
+
}));
|
|
375
|
+
return {
|
|
314
376
|
level,
|
|
315
377
|
blockedCount24h: critAlerts.length,
|
|
316
378
|
checks,
|
|
317
|
-
lastBlock
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
379
|
+
lastBlock,
|
|
380
|
+
toJSON: () => ({
|
|
381
|
+
level,
|
|
382
|
+
blockedCount24h: critAlerts.length,
|
|
383
|
+
checks,
|
|
384
|
+
lastBlock: lastBlock
|
|
385
|
+
? { ...lastBlock, amount: bs(lastBlock.amount) }
|
|
386
|
+
: undefined,
|
|
387
|
+
}),
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
catch (err) {
|
|
391
|
+
throw toDxError(err, "OwnerClient.getHealth");
|
|
392
|
+
}
|
|
322
393
|
}
|
|
323
394
|
// ─── getPolicy ───────────────────────────────────────────────────────────────
|
|
324
395
|
export async function getPolicy(rpc, vault, network) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
err
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const maxPerTrade = p.maxTransactionSizeUsd ?? 0n;
|
|
350
|
-
const protocolCaps = (p.protocolCaps || []);
|
|
351
|
-
const sessionExpiry = p.sessionExpirySlots;
|
|
352
|
-
const policyVer = (p.policyVersion ?? 0n);
|
|
353
|
-
const timelockSec = Number(p.timelockDuration);
|
|
354
|
-
let pendingUpdate;
|
|
355
|
-
if (pendingPolicy) {
|
|
356
|
-
const pp = pendingPolicy;
|
|
357
|
-
const executesAtSec = Number(pp.executesAt ?? 0);
|
|
358
|
-
const appliesAt = Number.isFinite(executesAtSec) ? executesAtSec * 1000 : 0;
|
|
359
|
-
const nowSec = Math.floor(Date.now() / 1000);
|
|
360
|
-
pendingUpdate = {
|
|
361
|
-
changes: {},
|
|
362
|
-
appliesAt,
|
|
363
|
-
canApply: executesAtSec > 0 && executesAtSec <= nowSec,
|
|
364
|
-
canCancel: true,
|
|
396
|
+
try {
|
|
397
|
+
const [state, pendingPolicy] = await Promise.all([
|
|
398
|
+
resolveVaultStateForOwner(rpc, vault, undefined, toNet(network)),
|
|
399
|
+
getPendingPolicyForVault(rpc, vault).catch((err) => {
|
|
400
|
+
// Account-not-found is expected (no pending update) — return null.
|
|
401
|
+
// Re-throw RPC errors so they're not silently swallowed.
|
|
402
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
403
|
+
if (message.includes("could not find") ||
|
|
404
|
+
message.includes("Account does not exist")) {
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
throw err;
|
|
408
|
+
}),
|
|
409
|
+
]);
|
|
410
|
+
const p = state.policy;
|
|
411
|
+
const protocols = (p.protocols || []);
|
|
412
|
+
const approvedApps = protocols.map((addr) => ({
|
|
413
|
+
name: resolveProtocolName(addr),
|
|
414
|
+
programId: addr,
|
|
415
|
+
}));
|
|
416
|
+
const modeMap = {
|
|
417
|
+
0: "unrestricted",
|
|
418
|
+
1: "whitelist",
|
|
419
|
+
2: "blacklist",
|
|
365
420
|
};
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
421
|
+
const dailyCap = p.dailySpendingCapUsd;
|
|
422
|
+
const maxPerTrade = p.maxTransactionSizeUsd ?? 0n;
|
|
423
|
+
const protocolCaps = (p.protocolCaps || []);
|
|
424
|
+
const sessionExpiry = p.sessionExpirySlots;
|
|
425
|
+
const policyVer = (p.policyVersion ?? 0n);
|
|
426
|
+
const timelockSec = Number(p.timelockDuration);
|
|
427
|
+
let pendingUpdate;
|
|
428
|
+
if (pendingPolicy) {
|
|
429
|
+
const pp = pendingPolicy;
|
|
430
|
+
const executesAtSec = Number(pp.executesAt ?? 0);
|
|
431
|
+
const appliesAt = Number.isFinite(executesAtSec)
|
|
432
|
+
? executesAtSec * 1000
|
|
433
|
+
: 0;
|
|
434
|
+
const nowSec = Math.floor(Date.now() / 1000);
|
|
435
|
+
// Decode each Option<T> field from PendingPolicyUpdate. Only Some fields
|
|
436
|
+
// land in `changes`. 14 fields total — every timelockable PolicyConfig field.
|
|
437
|
+
// Source: programs/sigil/src/state/pending_policy.rs
|
|
438
|
+
const changes = {};
|
|
439
|
+
if (isSome(pp.dailySpendingCapUsd))
|
|
440
|
+
changes.dailyCap = pp.dailySpendingCapUsd.value;
|
|
441
|
+
if (isSome(pp.maxTransactionAmountUsd))
|
|
442
|
+
changes.maxPerTrade = pp.maxTransactionAmountUsd.value;
|
|
443
|
+
if (isSome(pp.protocols))
|
|
444
|
+
changes.approvedApps = pp.protocols.value;
|
|
445
|
+
if (isSome(pp.protocolMode))
|
|
446
|
+
changes.protocolMode = modeMap[pp.protocolMode.value] || "unrestricted";
|
|
447
|
+
if (isSome(pp.hasProtocolCaps))
|
|
448
|
+
changes.hasProtocolCaps = pp.hasProtocolCaps.value;
|
|
449
|
+
if (isSome(pp.protocolCaps))
|
|
450
|
+
changes.protocolCaps = pp.protocolCaps.value;
|
|
451
|
+
if (isSome(pp.canOpenPositions))
|
|
452
|
+
changes.canOpenPositions = pp.canOpenPositions.value;
|
|
453
|
+
if (isSome(pp.maxConcurrentPositions))
|
|
454
|
+
changes.maxConcurrentPositions = pp.maxConcurrentPositions.value;
|
|
455
|
+
if (isSome(pp.maxSlippageBps))
|
|
456
|
+
changes.maxSlippageBps = pp.maxSlippageBps.value;
|
|
457
|
+
if (isSome(pp.maxLeverageBps))
|
|
458
|
+
changes.leverageLimit = pp.maxLeverageBps.value;
|
|
459
|
+
if (isSome(pp.allowedDestinations))
|
|
460
|
+
changes.allowedDestinations = pp.allowedDestinations.value;
|
|
461
|
+
if (isSome(pp.developerFeeRate))
|
|
462
|
+
changes.developerFeeRate = pp.developerFeeRate.value;
|
|
463
|
+
if (isSome(pp.sessionExpirySlots))
|
|
464
|
+
changes.sessionExpirySlots = pp.sessionExpirySlots.value;
|
|
465
|
+
if (isSome(pp.timelockDuration))
|
|
466
|
+
changes.timelock = Number(pp.timelockDuration.value);
|
|
467
|
+
pendingUpdate = {
|
|
468
|
+
changes,
|
|
469
|
+
appliesAt,
|
|
470
|
+
canApply: executesAtSec > 0 && executesAtSec <= nowSec,
|
|
471
|
+
canCancel: true,
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
return {
|
|
475
|
+
dailyCap,
|
|
476
|
+
maxPerTrade,
|
|
387
477
|
approvedApps,
|
|
388
478
|
protocolMode: modeMap[p.protocolMode] || "unrestricted",
|
|
389
479
|
hasProtocolCaps: p.hasProtocolCaps,
|
|
390
|
-
protocolCaps
|
|
480
|
+
protocolCaps,
|
|
391
481
|
canOpenPositions: p.canOpenPositions,
|
|
392
482
|
maxConcurrentPositions: p.maxConcurrentPositions,
|
|
393
483
|
maxSlippageBps: p.maxSlippageBps,
|
|
394
484
|
leverageLimitBps: p.maxLeverageBps,
|
|
395
485
|
allowedDestinations: (p.allowedDestinations || []),
|
|
396
486
|
developerFeeRate: p.developerFeeRate,
|
|
397
|
-
sessionExpirySlots:
|
|
487
|
+
sessionExpirySlots: sessionExpiry,
|
|
398
488
|
timelockSeconds: timelockSec,
|
|
399
|
-
policyVersion:
|
|
400
|
-
pendingUpdate
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
:
|
|
408
|
-
|
|
409
|
-
|
|
489
|
+
policyVersion: policyVer,
|
|
490
|
+
pendingUpdate,
|
|
491
|
+
toJSON: () => ({
|
|
492
|
+
dailyCap: bs(dailyCap),
|
|
493
|
+
maxPerTrade: bs(maxPerTrade),
|
|
494
|
+
approvedApps,
|
|
495
|
+
protocolMode: modeMap[p.protocolMode] || "unrestricted",
|
|
496
|
+
hasProtocolCaps: p.hasProtocolCaps,
|
|
497
|
+
protocolCaps: protocolCaps.map(bs),
|
|
498
|
+
canOpenPositions: p.canOpenPositions,
|
|
499
|
+
maxConcurrentPositions: p.maxConcurrentPositions,
|
|
500
|
+
maxSlippageBps: p.maxSlippageBps,
|
|
501
|
+
leverageLimitBps: p.maxLeverageBps,
|
|
502
|
+
allowedDestinations: (p.allowedDestinations || []),
|
|
503
|
+
developerFeeRate: p.developerFeeRate,
|
|
504
|
+
sessionExpirySlots: bs(sessionExpiry),
|
|
505
|
+
timelockSeconds: timelockSec,
|
|
506
|
+
policyVersion: bs(policyVer),
|
|
507
|
+
pendingUpdate: pendingUpdate
|
|
508
|
+
? {
|
|
509
|
+
changes: serializeBigints(pendingUpdate.changes),
|
|
510
|
+
appliesAt: pendingUpdate.appliesAt,
|
|
511
|
+
canApply: pendingUpdate.canApply,
|
|
512
|
+
canCancel: pendingUpdate.canCancel,
|
|
513
|
+
}
|
|
514
|
+
: undefined,
|
|
515
|
+
}),
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
catch (err) {
|
|
519
|
+
throw toDxError(err, "OwnerClient.getPolicy");
|
|
520
|
+
}
|
|
410
521
|
}
|
|
411
522
|
//# sourceMappingURL=reads.js.map
|