Skip to content

Commit 82d11cc

Browse files
authored
Merge pull request #364 from LIT-Protocol/feature/aerodrome-fee
Aerodrome swap fee contract
2 parents bf44771 + 8145f62 commit 82d11cc

31 files changed

+733
-220
lines changed

.github/workflows/contract_tests.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- name: Install Foundry
3333
uses: foundry-rs/foundry-toolchain@v1
3434
with:
35-
version: nightly
35+
version: stable
3636

3737
- name: Run Forge fmt
3838
run: |
@@ -57,5 +57,6 @@ jobs:
5757
env:
5858
BASE_RPC_URL: ${{ secrets.BASE_RPC_URL }}
5959
run: |
60-
forge test --ffi -vvv --match-path 'test/**/*ForkTest*.t.sol' --fork-url "$BASE_RPC_URL"
60+
LATEST_BLOCK=$(cast block-number --rpc-url "$BASE_RPC_URL")
61+
forge test --ffi -vvv --match-path 'test/**/*ForkTest*.t.sol' --fork-url "$BASE_RPC_URL" --fork-block-number "$LATEST_BLOCK"
6162
id: test-forked

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "packages/libs/contracts-sdk/lib/forge-std"]
22
path = packages/libs/contracts-sdk/lib/forge-std
33
url = https://github.com/foundry-rs/forge-std
4+
[submodule "packages/libs/contracts-sdk/lib/contracts"]
5+
path = packages/libs/contracts-sdk/lib/contracts
6+
url = https://github.com/aerodrome-finance/contracts

packages/libs/contracts-sdk/contracts/diamond-base/interfaces/IDiamondLoupe.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pragma solidity ^0.8.0;
99
interface IDiamondLoupe {
1010
/// These functions are expected to be called frequently
1111
/// by abilities.
12-
1312
struct Facet {
1413
address facetAddress;
1514
bytes4[] functionSelectors;

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ contract VincentAppFacet is VincentBase {
4848
* @param versionAbilities Abilities and policies for the app version
4949
*/
5050
function registerApp(uint40 appId, address[] calldata delegatees, AppVersionAbilities calldata versionAbilities)
51-
external returns (uint24 newAppVersion)
51+
external
52+
returns (uint24 newAppVersion)
5253
{
5354
if (appId == 0) {
5455
revert LibVincentAppFacet.ZeroAppIdNotAllowed();
@@ -181,7 +182,7 @@ contract VincentAppFacet is VincentBase {
181182
VincentAppStorage.App storage app = as_.appIdToApp[appId];
182183

183184
address[] memory currentDelegatees = app.delegatees.values();
184-
185+
185186
// Remove all current delegatees
186187
for (uint256 i = 0; i < currentDelegatees.length; i++) {
187188
address currentDelegatee = currentDelegatees[i];
@@ -193,7 +194,7 @@ contract VincentAppFacet is VincentBase {
193194
// Add new delegatees
194195
for (uint256 i = 0; i < delegatees.length; i++) {
195196
address delegatee = delegatees[i];
196-
197+
197198
if (delegatee == address(0)) {
198199
revert LibVincentAppFacet.ZeroAddressDelegateeNotAllowed();
199200
}
@@ -307,8 +308,7 @@ contract VincentAppFacet is VincentBase {
307308
uint256 abilityCount = versionAbilities.abilityIpfsCids.length;
308309
if (abilityCount != versionAbilities.abilityPolicies.length) {
309310
revert LibVincentAppFacet.AbilityArrayDimensionMismatch(
310-
abilityCount,
311-
versionAbilities.abilityPolicies.length
311+
abilityCount, versionAbilities.abilityPolicies.length
312312
);
313313
}
314314

@@ -362,7 +362,8 @@ contract VincentAppFacet is VincentBase {
362362
}
363363

364364
bytes32 hashedAbilityPolicy = keccak256(abi.encodePacked(policyIpfsCid));
365-
EnumerableSet.Bytes32Set storage abilityPolicyIpfsCidHashes = versionedApp.abilityIpfsCidHashToAbilityPolicyIpfsCidHashes[hashedAbilityCid];
365+
EnumerableSet.Bytes32Set storage abilityPolicyIpfsCidHashes =
366+
versionedApp.abilityIpfsCidHashToAbilityPolicyIpfsCidHashes[hashedAbilityCid];
366367

367368
// Step 7.1: Add the policy hash to the AbilityPolicies
368369
if (!abilityPolicyIpfsCidHashes.add(hashedAbilityPolicy)) {

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// SPDX-License-Identifier: MIT
32
pragma solidity ^0.8.29;
43

@@ -122,9 +121,11 @@ contract VincentAppViewFacet is VincentBase {
122121
* @param offset The offset of the first token ID to retrieve
123122
* @return delegatedAgentPkpTokenIds Array of delegated agent PKP token IDs
124123
*/
125-
function getDelegatedAgentPkpTokenIds(uint40 appId, uint24 version, uint256 offset)
126-
external view onlyRegisteredAppVersion(appId, version)
127-
returns (uint256[] memory delegatedAgentPkpTokenIds)
124+
function getDelegatedAgentPkpTokenIds(uint40 appId, uint24 version, uint256 offset)
125+
external
126+
view
127+
onlyRegisteredAppVersion(appId, version)
128+
returns (uint256[] memory delegatedAgentPkpTokenIds)
128129
{
129130
VincentAppStorage.AppVersion storage versionedApp =
130131
VincentAppStorage.appStorage().appIdToApp[appId].appVersions[getAppVersionIndex(version)];
@@ -168,8 +169,7 @@ contract VincentAppViewFacet is VincentBase {
168169
VincentAppStorage.App storage storedApp = as_.appIdToApp[appId];
169170

170171
// Step 2: Retrieve the specific version data
171-
VincentAppStorage.AppVersion storage storedVersionedApp =
172-
storedApp.appVersions[getAppVersionIndex(version)];
172+
VincentAppStorage.AppVersion storage storedVersionedApp = storedApp.appVersions[getAppVersionIndex(version)];
173173

174174
// Step 3: Set basic version information (excluding delegatedAgentPkpTokenIds)
175175
appVersion.version = version;
@@ -226,7 +226,11 @@ contract VincentAppViewFacet is VincentBase {
226226
* @return appIds Array of app IDs managed by the specified address
227227
* @return appVersionCounts Array of version counts for each app ID
228228
*/
229-
function getAppsByManager(address manager, uint256 offset) external view returns (uint40[] memory appIds, uint24[] memory appVersionCounts) {
229+
function getAppsByManager(address manager, uint256 offset)
230+
external
231+
view
232+
returns (uint40[] memory appIds, uint24[] memory appVersionCounts)
233+
{
230234
if (manager == address(0)) {
231235
revert ZeroAddressNotAllowed();
232236
}

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

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,20 @@ contract VincentUserFacet is VincentBase {
6060
string[] calldata abilityIpfsCids,
6161
string[][] calldata policyIpfsCids,
6262
bytes[][] calldata policyParameterValues
63-
) external appNotDeleted(appId) onlyRegisteredAppVersion(appId, appVersion) appEnabled(appId, appVersion) onlyPkpOwner(pkpTokenId) {
63+
)
64+
external
65+
appNotDeleted(appId)
66+
onlyRegisteredAppVersion(appId, appVersion)
67+
appEnabled(appId, appVersion)
68+
onlyPkpOwner(pkpTokenId)
69+
{
6470
uint256 abilityCount = abilityIpfsCids.length;
6571

6672
if (abilityCount == 0 || policyIpfsCids.length == 0 || policyParameterValues.length == 0) {
6773
revert LibVincentUserFacet.InvalidInput();
6874
}
6975

70-
if (
71-
abilityCount != policyIpfsCids.length || abilityCount != policyParameterValues.length
72-
) {
76+
if (abilityCount != policyIpfsCids.length || abilityCount != policyParameterValues.length) {
7377
revert LibVincentUserFacet.AbilitiesAndPoliciesLengthMismatch();
7478
}
7579

@@ -119,7 +123,7 @@ contract VincentUserFacet is VincentBase {
119123

120124
// Set the new permitted app version
121125
agentStorage.permittedAppVersion[appId] = appVersion;
122-
126+
123127
// Store this version as the last permitted version for potential re-permitting
124128
agentStorage.lastPermittedVersion[appId] = appVersion;
125129

@@ -188,44 +192,42 @@ contract VincentUserFacet is VincentBase {
188192
* @param pkpTokenId The token ID of the PKP to re-permit the app for
189193
* @param appId The ID of the app to re-permit
190194
*/
191-
function rePermitApp(uint256 pkpTokenId, uint40 appId)
192-
external
193-
appNotDeleted(appId)
194-
onlyPkpOwner(pkpTokenId)
195-
{
195+
function rePermitApp(uint256 pkpTokenId, uint40 appId) external appNotDeleted(appId) onlyPkpOwner(pkpTokenId) {
196196
VincentUserStorage.UserStorage storage us_ = VincentUserStorage.userStorage();
197197
VincentUserStorage.AgentStorage storage agentStorage = us_.agentPkpTokenIdToAgentStorage[pkpTokenId];
198-
198+
199199
// Check if app is currently permitted
200200
if (agentStorage.permittedApps.contains(appId)) {
201-
revert LibVincentUserFacet.AppVersionAlreadyPermitted(pkpTokenId, appId, agentStorage.permittedAppVersion[appId]);
201+
revert LibVincentUserFacet.AppVersionAlreadyPermitted(
202+
pkpTokenId, appId, agentStorage.permittedAppVersion[appId]
203+
);
202204
}
203-
205+
204206
// Check if app was ever permitted (exists in allPermittedApps)
205207
if (!agentStorage.allPermittedApps.contains(appId)) {
206208
revert LibVincentUserFacet.AppNeverPermitted(pkpTokenId, appId, 0);
207209
}
208-
210+
209211
// Get the last permitted version
210212
// Note: lastPermittedVersion should never be 0 here because:
211213
// - If app is currently permitted, we already reverted above
212214
// - If app was unpermitted, unPermitAppVersion sets lastPermittedVersion
213215
uint24 lastPermittedVersion = agentStorage.lastPermittedVersion[appId];
214-
216+
215217
// Check if the last permitted version is still enabled
216218
VincentAppStorage.AppStorage storage as_ = VincentAppStorage.appStorage();
217219
VincentAppStorage.AppVersion storage appVersion =
218220
as_.appIdToApp[appId].appVersions[getAppVersionIndex(lastPermittedVersion)];
219-
221+
220222
if (!appVersion.enabled) {
221223
revert LibVincentUserFacet.AppVersionNotEnabled(appId, lastPermittedVersion);
222224
}
223-
225+
224226
// Re-permit the app with the last permitted version
225227
appVersion.delegatedAgentPkps.add(pkpTokenId);
226228
agentStorage.permittedApps.add(appId);
227229
agentStorage.permittedAppVersion[appId] = lastPermittedVersion;
228-
230+
229231
emit LibVincentUserFacet.AppVersionRePermitted(pkpTokenId, appId, lastPermittedVersion);
230232
}
231233

@@ -256,9 +258,7 @@ contract VincentUserFacet is VincentBase {
256258
revert LibVincentUserFacet.InvalidInput();
257259
}
258260

259-
if (
260-
abilityIpfsCids.length != policyIpfsCids.length || abilityIpfsCids.length != policyParameterValues.length
261-
) {
261+
if (abilityIpfsCids.length != policyIpfsCids.length || abilityIpfsCids.length != policyParameterValues.length) {
262262
revert LibVincentUserFacet.AbilitiesAndPoliciesLengthMismatch();
263263
}
264264

@@ -320,9 +320,7 @@ contract VincentUserFacet is VincentBase {
320320
// Check nested array lengths at policy level
321321
uint256 policyCount = policyIpfsCids[i].length;
322322
if (policyCount != policyParameterValues[i].length) {
323-
revert LibVincentUserFacet.PolicyArrayLengthMismatch(
324-
i, policyCount, policyParameterValues[i].length
325-
);
323+
revert LibVincentUserFacet.PolicyArrayLengthMismatch(i, policyCount, policyParameterValues[i].length);
326324
}
327325

328326
bytes32 hashedAbilityIpfsCid = keccak256(abi.encodePacked(abilityIpfsCid));
@@ -343,8 +341,8 @@ contract VincentUserFacet is VincentBase {
343341
EnumerableSet.Bytes32Set storage abilityPolicyIpfsCidHashes =
344342
versionedApp.abilityIpfsCidHashToAbilityPolicyIpfsCidHashes[hashedAbilityIpfsCid];
345343

346-
mapping(bytes32 => bytes) storage abilityPolicyParameterValues =
347-
us_.agentPkpTokenIdToAgentStorage[pkpTokenId].abilityPolicyParameterValues[appId][appVersion][hashedAbilityIpfsCid];
344+
mapping(bytes32 => bytes) storage abilityPolicyParameterValues = us_.agentPkpTokenIdToAgentStorage[pkpTokenId]
345+
.abilityPolicyParameterValues[appId][appVersion][hashedAbilityIpfsCid];
348346

349347
// Step 4: Iterate through each policy associated with the ability.
350348
for (uint256 j = 0; j < policyCount; j++) {
@@ -367,15 +365,22 @@ contract VincentUserFacet is VincentBase {
367365
// Check for duplicate ability policy IPFS CIDs
368366
for (uint256 k = j + 1; k < policyCount; k++) {
369367
if (keccak256(abi.encodePacked(policyIpfsCids[i][k])) == hashedAbilityPolicy) {
370-
revert LibVincentUserFacet.DuplicateAbilityPolicyIpfsCid(appId, appVersion, abilityIpfsCid, policyIpfsCids[i][k]);
368+
revert LibVincentUserFacet.DuplicateAbilityPolicyIpfsCid(
369+
appId, appVersion, abilityIpfsCid, policyIpfsCids[i][k]
370+
);
371371
}
372372
}
373373

374374
// Step 5: Store the policy parameter metadata
375375
abilityPolicyParameterValues[hashedAbilityPolicy] = policyParameterValues[i][j];
376376

377377
emit LibVincentUserFacet.AbilityPolicyParametersSet(
378-
pkpTokenId, appId, appVersion, hashedAbilityIpfsCid, hashedAbilityPolicy, policyParameterValues[i][j]
378+
pkpTokenId,
379+
appId,
380+
appVersion,
381+
hashedAbilityIpfsCid,
382+
hashedAbilityPolicy,
383+
policyParameterValues[i][j]
379384
);
380385
}
381386
}

0 commit comments

Comments
 (0)