Skip to content

Commit 1a00b83

Browse files
authored
Merge pull request #354 from LIT-Protocol/fix/add-deleted-apps
Return deleted Apps for get Apps contract methods
2 parents afe9c98 + 8b15232 commit 1a00b83

File tree

8 files changed

+70
-54
lines changed

8 files changed

+70
-54
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
contracts-sdk: major
3+
---
4+
5+
getPermittedAppsForPkps and getUnpermittedAppsForPkps now return deleted Apps. A new isDeleted property has been added to the return value of these methods to indicate if each returned App is currently marked as deleted

packages/libs/contracts-sdk/abis/VincentUserViewFacet.abi.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@
206206
"name": "versionEnabled",
207207
"type": "bool",
208208
"internalType": "bool"
209+
},
210+
{
211+
"name": "isDeleted",
212+
"type": "bool",
213+
"internalType": "bool"
209214
}
210215
]
211216
}
@@ -259,6 +264,11 @@
259264
"name": "versionEnabled",
260265
"type": "bool",
261266
"internalType": "bool"
267+
},
268+
{
269+
"name": "isDeleted",
270+
"type": "bool",
271+
"internalType": "bool"
262272
}
263273
]
264274
}

packages/libs/contracts-sdk/contracts/facets/VincentUserViewFacet.sol

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,13 @@ contract VincentUserViewFacet is VincentBase {
9696
* @param appId The ID of the permitted app
9797
* @param version The permitted version of the app
9898
* @param versionEnabled Whether the permitted version is currently enabled
99+
* @param isDeleted Whether the app has been deleted
99100
*/
100101
struct PermittedApp {
101102
uint40 appId;
102103
uint24 version;
103104
bool versionEnabled;
105+
bool isDeleted;
104106
}
105107

106108
/**
@@ -109,11 +111,13 @@ contract VincentUserViewFacet is VincentBase {
109111
* @param appId The ID of the unpermitted app
110112
* @param previousPermittedVersion The last permitted version before unpermitting
111113
* @param versionEnabled Whether the previous permitted version is currently enabled
114+
* @param isDeleted Whether the app has been deleted
112115
*/
113116
struct UnpermittedApp {
114117
uint40 appId;
115118
uint24 previousPermittedVersion;
116119
bool versionEnabled;
120+
bool isDeleted;
117121
}
118122

119123
/**
@@ -177,15 +181,14 @@ contract VincentUserViewFacet is VincentBase {
177181
}
178182

179183
/**
180-
* @dev Gets all permitted app versions for a specific app and PKP token
184+
* @dev Gets the permitted app version for a specific app and PKP token, even if the app has been deleted
181185
* @param pkpTokenId The PKP token ID
182186
* @param appId The app ID
183-
* @return An array of app versions that are permitted for the PKP token
187+
* @return The permitted app version for the PKP token and app
184188
*/
185189
function getPermittedAppVersionForPkp(uint256 pkpTokenId, uint40 appId)
186190
external
187191
view
188-
appNotDeleted(appId)
189192
returns (uint24)
190193
{
191194
// Check for invalid PKP token ID and app ID
@@ -228,56 +231,40 @@ contract VincentUserViewFacet is VincentBase {
228231

229232
/**
230233
* @notice DEPRECATED: Use {getPermittedAppsForPkps} instead. This function will be removed in future releases.
231-
* @dev Gets all app IDs that have permissions for a specific PKP token, excluding deleted apps, with pagination support.
234+
* @dev Gets all app IDs that have permissions for a specific PKP token, including deleted apps, with pagination support.
232235
* @dev Migration guidance: Replace calls to this function with {getPermittedAppsForPkps}, which returns both app IDs and their permitted versions for a PKP token. Update your code to handle the new return type and logic as needed.
233236
* @param pkpTokenId The PKP token ID
234237
* @param offset The offset of the first app ID to retrieve
235-
* @return An array of app IDs that have permissions for the PKP token and haven't been deleted
238+
* @return An array of app IDs that have permissions for the PKP token (including deleted apps)
236239
*/
237240
function getAllPermittedAppIdsForPkp(uint256 pkpTokenId, uint256 offset) external view returns (uint40[] memory) {
238241
if (pkpTokenId == 0) {
239242
revert InvalidPkpTokenId();
240243
}
241244

242245
VincentUserStorage.UserStorage storage us_ = VincentUserStorage.userStorage();
243-
VincentAppStorage.AppStorage storage as_ = VincentAppStorage.appStorage();
244246

245247
EnumerableSet.UintSet storage permittedAppSet = us_.agentPkpTokenIdToAgentStorage[pkpTokenId].permittedApps;
246248
uint256 permittedAppCount = permittedAppSet.length();
247249

248-
uint40[] memory nonDeletedAppIds = new uint40[](permittedAppCount);
249-
uint256 nonDeletedCount = 0;
250-
251-
for (uint256 i = 0; i < permittedAppCount; i++) {
252-
uint40 appId = uint40(permittedAppSet.at(i));
253-
if (!as_.appIdToApp[appId].isDeleted) {
254-
nonDeletedAppIds[nonDeletedCount] = appId;
255-
nonDeletedCount++;
256-
}
257-
}
258-
259-
if (nonDeletedCount == 0) {
250+
if (permittedAppCount == 0) {
260251
return new uint40[](0);
261252
}
262253

263-
assembly {
264-
mstore(nonDeletedAppIds, nonDeletedCount)
265-
}
266-
267-
if (offset >= nonDeletedCount) {
268-
revert InvalidOffset(offset, nonDeletedCount);
254+
if (offset >= permittedAppCount) {
255+
revert InvalidOffset(offset, permittedAppCount);
269256
}
270257

271258
uint256 end = offset + AGENT_PAGE_SIZE;
272-
if (end > nonDeletedCount) {
273-
end = nonDeletedCount;
259+
if (end > permittedAppCount) {
260+
end = permittedAppCount;
274261
}
275262

276263
uint256 resultCount = end - offset;
277264
uint40[] memory result = new uint40[](resultCount);
278265

279266
for (uint256 i = offset; i < end; i++) {
280-
result[i - offset] = nonDeletedAppIds[i];
267+
result[i - offset] = uint40(permittedAppSet.at(i));
281268
}
282269

283270
return result;
@@ -316,32 +303,30 @@ contract VincentUserViewFacet is VincentBase {
316303
EnumerableSet.UintSet storage permittedApps = agentStorage.permittedApps;
317304
uint256 appCount = permittedApps.length();
318305

319-
// Count non-deleted permitted apps
306+
// Collect all permitted apps including deleted ones
320307
PermittedApp[] memory tempPermittedApps = new PermittedApp[](appCount);
321-
uint256 permittedCount;
322308

323309
for (uint256 j; j < appCount; j++) {
324310
uint40 appId = uint40(permittedApps.at(j));
325-
if (!as_.appIdToApp[appId].isDeleted) {
326-
// Get version details for the permitted app
327-
uint24 version = agentStorage.permittedAppVersion[appId];
328-
bool enabled = as_.appIdToApp[appId].appVersions[getAppVersionIndex(version)].enabled;
329-
tempPermittedApps[permittedCount] = PermittedApp({
330-
appId: appId,
331-
version: version,
332-
versionEnabled: enabled
333-
});
334-
permittedCount++;
335-
}
311+
// Get version details for the permitted app
312+
uint24 version = agentStorage.permittedAppVersion[appId];
313+
bool enabled = as_.appIdToApp[appId].appVersions[getAppVersionIndex(version)].enabled;
314+
bool isDeleted = as_.appIdToApp[appId].isDeleted;
315+
tempPermittedApps[j] = PermittedApp({
316+
appId: appId,
317+
version: version,
318+
versionEnabled: enabled,
319+
isDeleted: isDeleted
320+
});
336321
}
337322

338323
// Apply pagination
339324
uint256 resultCount;
340-
if (offset < permittedCount) {
341-
uint256 end = offset + pageSize > permittedCount ? permittedCount : offset + pageSize;
325+
if (offset < appCount) {
326+
uint256 end = offset + pageSize > appCount ? appCount : offset + pageSize;
342327
resultCount = end - offset;
343328
}
344-
329+
345330
results[i].permittedApps = new PermittedApp[](resultCount);
346331
for (uint256 k; k < resultCount; k++) {
347332
results[i].permittedApps[k] = tempPermittedApps[offset + k];
@@ -595,20 +580,22 @@ contract VincentUserViewFacet is VincentBase {
595580
VincentUserStorage.AgentStorage storage agentStorage = us_.agentPkpTokenIdToAgentStorage[pkpTokenId];
596581
uint256 allAppCount = agentStorage.allPermittedApps.length();
597582

598-
// Collect all unpermitted apps
583+
// Collect all unpermitted apps including deleted ones
599584
UnpermittedApp[] memory tempUnpermittedApps = new UnpermittedApp[](allAppCount);
600585
uint256 unpermittedCount;
601-
586+
602587
for (uint256 j; j < allAppCount; j++) {
603588
uint40 appId = uint40(agentStorage.allPermittedApps.at(j));
604-
if (!agentStorage.permittedApps.contains(appId) && !as_.appIdToApp[appId].isDeleted) {
589+
if (!agentStorage.permittedApps.contains(appId)) {
605590
uint24 lastPermittedVersion = agentStorage.lastPermittedVersion[appId];
606591
bool enabled = as_.appIdToApp[appId].appVersions[getAppVersionIndex(lastPermittedVersion)].enabled;
607-
592+
bool isDeleted = as_.appIdToApp[appId].isDeleted;
593+
608594
tempUnpermittedApps[unpermittedCount] = UnpermittedApp({
609595
appId: appId,
610596
previousPermittedVersion: lastPermittedVersion,
611-
versionEnabled: enabled
597+
versionEnabled: enabled,
598+
isDeleted: isDeleted
612599
});
613600
unpermittedCount++;
614601
}
@@ -620,7 +607,7 @@ contract VincentUserViewFacet is VincentBase {
620607
uint256 end = offset + AGENT_PAGE_SIZE > unpermittedCount ? unpermittedCount : offset + AGENT_PAGE_SIZE;
621608
resultCount = end - offset;
622609
}
623-
610+
624611
results[i].unpermittedApps = new UnpermittedApp[](resultCount);
625612
for (uint256 k; k < resultCount; k++) {
626613
results[i].unpermittedApps[k] = tempUnpermittedApps[offset + k];

packages/libs/contracts-sdk/src/internal/user/UserView.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export async function getPermittedAppsForPkps(
129129
appId: app.appId,
130130
version: app.version,
131131
versionEnabled: app.versionEnabled,
132+
isDeleted: app.isDeleted,
132133
})),
133134
}));
134135
} catch (error: unknown) {
@@ -247,6 +248,7 @@ export async function getUnpermittedAppsForPkps(
247248
appId: app.appId,
248249
previousPermittedVersion: app.previousPermittedVersion,
249250
versionEnabled: app.versionEnabled,
251+
isDeleted: app.isDeleted,
250252
})),
251253
}));
252254
} catch (error: unknown) {

packages/libs/contracts-sdk/src/internal/user/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export interface ContractPkpPermittedApps {
149149
appId: number;
150150
version: number;
151151
versionEnabled: boolean;
152+
isDeleted: boolean;
152153
}[];
153154
}
154155

@@ -163,5 +164,6 @@ export interface ContractPkpUnpermittedApps {
163164
appId: number;
164165
previousPermittedVersion: number;
165166
versionEnabled: boolean;
167+
isDeleted: boolean;
166168
}[];
167169
}

packages/libs/contracts-sdk/src/types.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ export interface PermittedApp {
299299
appId: number;
300300
version: number;
301301
versionEnabled: boolean;
302+
isDeleted: boolean;
302303
}
303304

304305
/**
@@ -359,6 +360,7 @@ export interface UnpermittedApp {
359360
appId: number;
360361
previousPermittedVersion: number;
361362
versionEnabled: boolean;
363+
isDeleted: boolean;
362364
}
363365

364366
/**
@@ -514,18 +516,18 @@ export interface ContractClient {
514516
params: GetAllRegisteredAgentPkpsParams,
515517
): ReturnType<typeof _getAllRegisteredAgentPkpEthAddresses>;
516518

517-
/** Get the permitted app version for a specific PKP token and app
519+
/** Get the permitted app version for a specific PKP token and app, even if the app has been deleted
518520
*
519521
* @returns The permitted app version for the PKP token and app
520522
*/
521523
getPermittedAppVersionForPkp(
522524
params: GetPermittedAppVersionForPkpParams,
523525
): ReturnType<typeof _getPermittedAppVersionForPkp>;
524526

525-
/** Get all app IDs that have permissions for a specific PKP token, excluding deleted apps
527+
/** Get all app IDs that have permissions for a specific PKP token, including deleted apps
526528
*
527529
* @deprecated Use getPermittedAppsForPkps instead
528-
* @returns Array of app IDs that have permissions for the PKP token and haven't been deleted
530+
* @returns Array of app IDs that have permissions for the PKP token (including deleted apps)
529531
*/
530532
getAllPermittedAppIdsForPkp(
531533
params: GetAllPermittedAppIdsForPkpParams,

packages/libs/contracts-sdk/test/facets/VincentAppFacet.t.sol

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,11 +671,17 @@ contract VincentAppFacetTest is Test {
671671

672672
assertEq(vincentAppViewFacet.getAppById(newAppId).isDeleted, true);
673673

674-
// Verify deleted app is filtered out from getPermittedAppsForPkps
674+
// Verify deleted app is still returned but with isDeleted flag set to true
675675
permittedAppsResults = vincentUserViewFacet.getPermittedAppsForPkps(pkpTokenIds, 0, 10);
676676
assertEq(permittedAppsResults.length, 1);
677677
assertEq(permittedAppsResults[0].pkpTokenId, PKP_TOKEN_ID_1);
678-
assertEq(permittedAppsResults[0].permittedApps.length, 0); // Deleted app should not appear
678+
assertEq(permittedAppsResults[0].permittedApps.length, 1); // Deleted app should still appear
679+
assertEq(permittedAppsResults[0].permittedApps[0].appId, newAppId);
680+
assertTrue(permittedAppsResults[0].permittedApps[0].isDeleted); // isDeleted flag should be true
681+
682+
// Verify permitted app version is still returned even if the app has been deleted
683+
uint24 permittedAppVersion = vincentUserViewFacet.getPermittedAppVersionForPkp(PKP_TOKEN_ID_1, newAppId);
684+
assertEq(permittedAppVersion, newAppVersion);
679685
}
680686

681687
function test_fetchDelegatedAgentPkpTokenIds() public {

packages/libs/contracts-sdk/test/sdk.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ describe('Vincent Contracts SDK E2E', () => {
245245
expect(testApp).toBeDefined();
246246
expect(testApp!.version).toBe(TEST_CONFIG.appVersion);
247247
expect(testApp!.versionEnabled).toBe(true);
248+
expect(testApp!.isDeleted).toBe(false);
248249
});
249250

250251
it('should get all registered agent PKPs', async () => {
@@ -382,6 +383,7 @@ describe('Vincent Contracts SDK E2E', () => {
382383
expect(testApp).toBeDefined();
383384
expect(testApp!.previousPermittedVersion).toBe(TEST_CONFIG.appVersion);
384385
expect(testApp!.versionEnabled).toBe(true);
386+
expect(testApp!.isDeleted).toBe(false);
385387
});
386388

387389
it('should get last permitted app version', async () => {

0 commit comments

Comments
 (0)