Skip to content

Commit 3644423

Browse files
authored
feat: extsloads (#1101)
1 parent 521e38a commit 3644423

File tree

12 files changed

+182
-67
lines changed

12 files changed

+182
-67
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"borrowNative": "227619",
3-
"repayNative": "166091",
4-
"supplyAsCollateralNative": "159972",
5-
"supplyNative": "135681",
2+
"borrowNative": "227663",
3+
"repayNative": "166157",
4+
"supplyAsCollateralNative": "160016",
5+
"supplyNative": "135699",
66
"withdrawNative: full": "125318",
77
"withdrawNative: partial": "136447"
88
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"borrowWithSig": "212845",
3-
"repayWithSig": "186399",
2+
"borrowWithSig": "212889",
3+
"repayWithSig": "186465",
44
"setSelfAsUserPositionManagerWithSig": "75433",
5-
"setUsingAsCollateralWithSig": "85363",
6-
"supplyWithSig": "151942",
7-
"updateUserDynamicConfigWithSig": "63100",
8-
"updateUserRiskPremiumWithSig": "62082",
5+
"setUsingAsCollateralWithSig": "85385",
6+
"supplyWithSig": "151960",
7+
"updateUserDynamicConfigWithSig": "63122",
8+
"updateUserRiskPremiumWithSig": "62104",
99
"withdrawWithSig": "130601"
1010
}

snapshots/Spoke.Getters.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"getUserAccountData: supplies: 0, borrows: 0": "12918",
3-
"getUserAccountData: supplies: 1, borrows: 0": "49207",
4-
"getUserAccountData: supplies: 2, borrows: 0": "80782",
5-
"getUserAccountData: supplies: 2, borrows: 1": "100193",
6-
"getUserAccountData: supplies: 2, borrows: 2": "118950"
2+
"getUserAccountData: supplies: 0, borrows: 0": "12962",
3+
"getUserAccountData: supplies: 1, borrows: 0": "49251",
4+
"getUserAccountData: supplies: 2, borrows: 0": "80826",
5+
"getUserAccountData: supplies: 2, borrows: 1": "100237",
6+
"getUserAccountData: supplies: 2, borrows: 2": "118994"
77
}

snapshots/Spoke.Operations.ZeroRiskPremium.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
{
2-
"borrow: first": "189247",
3-
"borrow: second action, same reserve": "169196",
4-
"liquidationCall (receiveShares): full": "294934",
5-
"liquidationCall (receiveShares): partial": "294652",
6-
"liquidationCall: full": "304219",
7-
"liquidationCall: partial": "303937",
8-
"permitReserve + repay (multicall)": "164333",
9-
"permitReserve + supply (multicall)": "146622",
10-
"permitReserve + supply + enable collateral (multicall)": "161025",
11-
"repay: full": "123692",
12-
"repay: partial": "128662",
2+
"borrow: first": "189291",
3+
"borrow: second action, same reserve": "169240",
4+
"liquidationCall (receiveShares): full": "294978",
5+
"liquidationCall (receiveShares): partial": "294696",
6+
"liquidationCall: full": "304263",
7+
"liquidationCall: partial": "303981",
8+
"permitReserve + repay (multicall)": "164420",
9+
"permitReserve + supply (multicall)": "146687",
10+
"permitReserve + supply + enable collateral (multicall)": "161112",
11+
"repay: full": "123736",
12+
"repay: partial": "128706",
1313
"setUserPositionManagersWithSig: disable": "47351",
1414
"setUserPositionManagersWithSig: enable": "69263",
15-
"supply + enable collateral (multicall)": "141205",
16-
"supply: 0 borrows, collateral disabled": "122745",
17-
"supply: 0 borrows, collateral enabled": "105716",
18-
"supply: second action, same reserve": "105645",
19-
"updateUserDynamicConfig: 1 collateral": "74526",
20-
"updateUserDynamicConfig: 2 collaterals": "89431",
21-
"updateUserRiskPremium: 1 borrow": "94759",
22-
"updateUserRiskPremium: 2 borrows": "103894",
23-
"usingAsCollateral: 0 borrows, enable": "59556",
24-
"usingAsCollateral: 1 borrow, disable": "104874",
25-
"usingAsCollateral: 1 borrow, enable": "42444",
26-
"usingAsCollateral: 2 borrows, disable": "125970",
27-
"usingAsCollateral: 2 borrows, enable": "42456",
15+
"supply + enable collateral (multicall)": "141292",
16+
"supply: 0 borrows, collateral disabled": "122767",
17+
"supply: 0 borrows, collateral enabled": "105738",
18+
"supply: second action, same reserve": "105667",
19+
"updateUserDynamicConfig: 1 collateral": "74548",
20+
"updateUserDynamicConfig: 2 collaterals": "89453",
21+
"updateUserRiskPremium: 1 borrow": "94781",
22+
"updateUserRiskPremium: 2 borrows": "103916",
23+
"usingAsCollateral: 0 borrows, enable": "59578",
24+
"usingAsCollateral: 1 borrow, disable": "104896",
25+
"usingAsCollateral: 1 borrow, enable": "42466",
26+
"usingAsCollateral: 2 borrows, disable": "125992",
27+
"usingAsCollateral: 2 borrows, enable": "42478",
2828
"withdraw: 0 borrows, full": "127659",
2929
"withdraw: 0 borrows, partial": "132345",
3030
"withdraw: 1 borrow, partial": "158727",

snapshots/Spoke.Operations.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
{
2-
"borrow: first": "258149",
3-
"borrow: second action, same reserve": "201098",
4-
"liquidationCall (receiveShares): full": "326941",
5-
"liquidationCall (receiveShares): partial": "326659",
6-
"liquidationCall: full": "336226",
7-
"liquidationCall: partial": "335944",
8-
"permitReserve + repay (multicall)": "161850",
9-
"permitReserve + supply (multicall)": "146622",
10-
"permitReserve + supply + enable collateral (multicall)": "161025",
11-
"repay: full": "117771",
12-
"repay: partial": "137141",
2+
"borrow: first": "258193",
3+
"borrow: second action, same reserve": "201142",
4+
"liquidationCall (receiveShares): full": "326985",
5+
"liquidationCall (receiveShares): partial": "326703",
6+
"liquidationCall: full": "336270",
7+
"liquidationCall: partial": "335988",
8+
"permitReserve + repay (multicall)": "161920",
9+
"permitReserve + supply (multicall)": "146687",
10+
"permitReserve + supply + enable collateral (multicall)": "161112",
11+
"repay: full": "117815",
12+
"repay: partial": "137185",
1313
"setUserPositionManagersWithSig: disable": "47351",
1414
"setUserPositionManagersWithSig: enable": "69263",
15-
"supply + enable collateral (multicall)": "141205",
16-
"supply: 0 borrows, collateral disabled": "122745",
17-
"supply: 0 borrows, collateral enabled": "105716",
18-
"supply: second action, same reserve": "105645",
19-
"updateUserDynamicConfig: 1 collateral": "74526",
20-
"updateUserDynamicConfig: 2 collaterals": "89431",
21-
"updateUserRiskPremium: 1 borrow": "148082",
22-
"updateUserRiskPremium: 2 borrows": "197789",
23-
"usingAsCollateral: 0 borrows, enable": "59556",
24-
"usingAsCollateral: 1 borrow, disable": "158197",
25-
"usingAsCollateral: 1 borrow, enable": "42444",
26-
"usingAsCollateral: 2 borrows, disable": "227865",
27-
"usingAsCollateral: 2 borrows, enable": "42456",
15+
"supply + enable collateral (multicall)": "141292",
16+
"supply: 0 borrows, collateral disabled": "122767",
17+
"supply: 0 borrows, collateral enabled": "105738",
18+
"supply: second action, same reserve": "105667",
19+
"updateUserDynamicConfig: 1 collateral": "74548",
20+
"updateUserDynamicConfig: 2 collaterals": "89453",
21+
"updateUserRiskPremium: 1 borrow": "148104",
22+
"updateUserRiskPremium: 2 borrows": "197811",
23+
"usingAsCollateral: 0 borrows, enable": "59578",
24+
"usingAsCollateral: 1 borrow, disable": "158219",
25+
"usingAsCollateral: 1 borrow, enable": "42466",
26+
"usingAsCollateral: 2 borrows, disable": "227887",
27+
"usingAsCollateral: 2 borrows, enable": "42478",
2828
"withdraw: 0 borrows, full": "127659",
2929
"withdraw: 0 borrows, partial": "132345",
3030
"withdraw: 1 borrow, partial": "209548",

src/interfaces/IExtSload.sol

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
// Copyright (c) 2025 Aave Labs
3+
pragma solidity ^0.8.0;
4+
5+
/// @title IExtSload
6+
/// @author Aave Labs
7+
/// @notice Minimal interface to easily access storage of source contract externally. See https://eips.ethereum.org/EIPS/eip-2330#rationale.
8+
interface IExtSload {
9+
/// @notice Returns the storage `value` of this contract at a given `slot`.
10+
/// @param slot Slot to SLOAD from.
11+
function extSload(bytes32 slot) external view returns (bytes32 value);
12+
13+
/// @notice Returns the storage `values` of this contract at the given `slots`.
14+
/// @param slots Array of slots to SLOAD from.
15+
function extSloads(bytes32[] calldata slots) external view returns (bytes32[] memory values);
16+
}

src/spoke/Spoke.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {ReserveFlags, ReserveFlagsMap} from 'src/spoke/libraries/ReserveFlagsMap
1818
import {UserPositionDebt} from 'src/spoke/libraries/UserPositionDebt.sol';
1919
import {IntentConsumer} from 'src/utils/IntentConsumer.sol';
2020
import {Multicall} from 'src/utils/Multicall.sol';
21+
import {ExtSload} from 'src/utils/ExtSload.sol';
2122
import {IAaveOracle} from 'src/spoke/interfaces/IAaveOracle.sol';
2223
import {IHubBase} from 'src/hub/interfaces/IHubBase.sol';
2324
import {ISpokeBase, ISpoke} from 'src/spoke/interfaces/ISpoke.sol';
@@ -30,6 +31,7 @@ abstract contract Spoke is
3031
ISpoke,
3132
AccessManagedUpgradeable,
3233
IntentConsumer,
34+
ExtSload,
3335
Multicall,
3436
ReentrancyGuardTransient
3537
{

src/spoke/interfaces/ISpoke.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import {IIntentConsumer} from 'src/interfaces/IIntentConsumer.sol';
77
import {IMulticall} from 'src/interfaces/IMulticall.sol';
88
import {IHubBase} from 'src/hub/interfaces/IHubBase.sol';
99
import {ISpokeBase} from 'src/spoke/interfaces/ISpokeBase.sol';
10+
import {IExtSload} from 'src/interfaces/IExtSload.sol';
1011

1112
type ReserveFlags is uint8;
1213

1314
/// @title ISpoke
1415
/// @author Aave Labs
1516
/// @notice Full interface for Spoke.
16-
interface ISpoke is ISpokeBase, IAccessManaged, IIntentConsumer, IMulticall {
17+
interface ISpoke is ISpokeBase, IAccessManaged, IIntentConsumer, IExtSload, IMulticall {
1718
/// @notice Intent data to set user position managers with EIP712-typed signature.
1819
/// @param user The address of the user on whose behalf position manager can act.
1920
/// @param updates The array of position manager updates.

src/utils/ExtSload.sol

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
// Copyright (c) 2025 Aave Labs
3+
pragma solidity ^0.8.0;
4+
5+
import {IExtSload} from 'src/interfaces/IExtSload.sol';
6+
7+
/// @title ExtSload
8+
/// @author Aave Labs
9+
/// @notice This allows the source contract to make its state available to external contracts.
10+
abstract contract ExtSload is IExtSload {
11+
/// @inheritdoc IExtSload
12+
function extSload(bytes32 slot) external view returns (bytes32 ret) {
13+
assembly ('memory-safe') {
14+
ret := sload(slot)
15+
}
16+
}
17+
18+
/// @inheritdoc IExtSload
19+
function extSloads(bytes32[] calldata slots) external view returns (bytes32[] memory) {
20+
assembly ('memory-safe') {
21+
let m := mload(0x40) // grab fmp, will not be restored since we exit context here
22+
mstore(m, 0x20) // to abi-encode response, the array will be found at the next word
23+
mstore(add(m, 0x20), slots.length) // set the length of dynamic array
24+
let start := add(m, 0x40)
25+
let end := add(start, shl(5, slots.length))
26+
for {
27+
let input := slots.offset
28+
} lt(start, end) {
29+
start := add(start, 0x20)
30+
} {
31+
mstore(start, sload(calldataload(input)))
32+
input := add(input, 0x20)
33+
}
34+
return(m, sub(end, m)) // return abi-encoded dynamic array
35+
}
36+
}
37+
}

tests/mocks/ExtSloadWrapper.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
// Copyright (c) 2025 Aave Labs
3+
pragma solidity 0.8.28;
4+
5+
import {ExtSload} from 'src/utils/ExtSload.sol';
6+
7+
contract ExtSloadWrapper is ExtSload {}

0 commit comments

Comments
 (0)