Skip to content

Commit

Permalink
Merge pull request rhinestonewtf#82 from rhinestonewtf/feat/update-sm…
Browse files Browse the repository at this point in the history
…art-sessions

feat: update smart sessions to latest
  • Loading branch information
kopy-kat authored Oct 10, 2024
2 parents b72f4c1 + 04ea2c4 commit 0213d05
Show file tree
Hide file tree
Showing 23 changed files with 227 additions and 145 deletions.
19 changes: 14 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
services:
anvil:
image: ghcr.io/foundry-rs/foundry:nightly-f6208d8db68f9acbe4ff8cd76958309efb61ea0b
ports: [ "8545:8545" ]
entrypoint: [ "anvil", "--fork-url", "https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}", "--host", "0.0.0.0", "--block-time", "0.1", "--silent"]
ports: ['8545:8545']
entrypoint:
[
'anvil',
'--fork-url',
'https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}',
'--host',
'0.0.0.0',
'--silent',
]
platform: linux/x86_64

alto:
image: ghcr.io/pimlicolabs/mock-alto-bundler:main
ports: [ "4337:4337" ]
ports: ['4337:4337']
environment:
- ANVIL_RPC=http://anvil:8545
- SKIP_DEPLOYMENTS=true
- SKIP_DEPLOYMENTS=true

5 changes: 4 additions & 1 deletion src/module/auto-savings/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export const AUTO_SAVINGS_ADDRESS = '0x6AE48bD83B6bdc8489584Ea0814086f963d1BD95'
import { Address } from 'viem'

export const AUTO_SAVINGS_ADDRESS: Address =
'0x6AE48bD83B6bdc8489584Ea0814086f963d1BD95'
6 changes: 4 additions & 2 deletions src/module/cold-storage/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const COLD_STORAGE_HOOK_ADDRESS =
import { Address } from 'viem'

export const COLD_STORAGE_HOOK_ADDRESS: Address =
'0x7E31543b269632ddc55a23553f902f84C9DD8454'

export const COLD_STORAGE_FLASHLOAN_ADDRESS =
export const COLD_STORAGE_FLASHLOAN_ADDRESS: Address =
'0x4422dbC3D055D59ee08F4A4D60E1046A9aFb287f'
4 changes: 3 additions & 1 deletion src/module/deadman-switch/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const DEADMAN_SWITCH_ADDRESS =
import { Address } from 'viem'

export const DEADMAN_SWITCH_ADDRESS: Address =
'0x291B3335EC9fC04BcC7446851812FDD55Ad0706E'
4 changes: 3 additions & 1 deletion src/module/hook-multi-plexer/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const HOOK_MULTI_PLEXER_ADDRESS =
import { Address } from 'viem'

export const HOOK_MULTI_PLEXER_ADDRESS: Address =
'0xF6782ed057F95f334D04F0Af1Af4D14fb84DE549'
4 changes: 3 additions & 1 deletion src/module/multi-factor-validator/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const MULTI_FACTOR_VALIDATOR_ADDRESS =
import { Address } from 'viem'

export const MULTI_FACTOR_VALIDATOR_ADDRESS: Address =
'0xf6bDf42c9BE18cEcA5C06c42A43DAf7FBbe7896b'
4 changes: 3 additions & 1 deletion src/module/ownable-executor/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const OWNABLE_EXECUTOR_ADDRESS =
import { Address } from 'viem'

export const OWNABLE_EXECUTOR_ADDRESS: Address =
'0x4Fd8d57b94966982B62e9588C27B4171B55E8354'
4 changes: 3 additions & 1 deletion src/module/ownable-validator/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const OWNABLE_VALIDATOR_ADDRESS =
import { Address } from 'viem'

export const OWNABLE_VALIDATOR_ADDRESS: Address =
'0x2483DA3A338895199E5e538530213157e931Bf06'
4 changes: 3 additions & 1 deletion src/module/registry-hook/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const REGISTRY_HOOK_ADDRESS =
import { Address } from 'viem'

export const REGISTRY_HOOK_ADDRESS: Address =
'0x0ac6160DBA30d665cCA6e6b6a2CDf147DC3dED22'
9 changes: 6 additions & 3 deletions src/module/registry/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export const REGISTRY_ADDRESS = '0x000000000069E2a187AEFFb852bF3cCdC95151B2'
export const RHINESTONE_ATTESTER_ADDRESS =
import { Address } from 'viem'

export const REGISTRY_ADDRESS: Address =
'0x000000000069E2a187AEFFb852bF3cCdC95151B2'
export const RHINESTONE_ATTESTER_ADDRESS: Address =
'0x000000333034E9f539ce08819E12c1b8Cb29084d'
export const MOCK_ATTESTER_ADDRESS =
export const MOCK_ATTESTER_ADDRESS: Address =
'0xA4C777199658a41688E9488c4EcbD7a2925Cc23A'
4 changes: 3 additions & 1 deletion src/module/scheduled-orders/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const SCHEDULED_ORDERS_EXECUTOR_ADDRESS =
import { Address } from 'viem'

export const SCHEDULED_ORDERS_EXECUTOR_ADDRESS: Address =
'0x40dc90D670C89F322fa8b9f685770296428DCb6b'
4 changes: 3 additions & 1 deletion src/module/scheduled-transfers/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const SCHEDULED_TRANSFERS_EXECUTOR_ADDRESS =
import { Address } from 'viem'

export const SCHEDULED_TRANSFERS_EXECUTOR_ADDRESS: Address =
'0xA8E374779aeE60413c974b484d6509c7E4DDb6bA'
1 change: 1 addition & 0 deletions src/module/smart-sessions/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ export const abi = [
inputs: [
{ internalType: 'PermissionId', name: 'permissionId', type: 'bytes32' },
{ internalType: 'address[]', name: 'policies', type: 'address[]' },
{ internalType: 'string[]', name: 'contents', type: 'string[]' },
],
name: 'disableERC1271Policies',
outputs: [],
Expand Down
4 changes: 3 additions & 1 deletion src/module/smart-sessions/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const SMART_SESSIONS_ADDRESS =
import { Address } from 'viem'

export const SMART_SESSIONS_ADDRESS: Address =
'0xDDFF43A42726df11E34123f747bDce0f755F784d'
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const SPENDING_LIMITS_POLICY_ADDRESS =
import { Address } from 'viem'

export const SPENDING_LIMITS_POLICY_ADDRESS: Address =
'0x8e58f4945e6ba2a11b184a9c20b6c765a0891b95'
5 changes: 4 additions & 1 deletion src/module/smart-sessions/policies/sudo-policy/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export const SUDO_POLICY_ADDRESS = '0x529Ad04F4D83aAb25144a90267D4a1443B84f5A6'
import { Address } from 'viem'

export const SUDO_POLICY_ADDRESS: Address =
'0x529Ad04F4D83aAb25144a90267D4a1443B84f5A6'
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const UNIVERSAL_ACTION_POLICY_ADDRESS =
import { Address } from 'viem'

export const UNIVERSAL_ACTION_POLICY_ADDRESS: Address =
'0x148CD6c24F4dd23C396E081bBc1aB1D92eeDe2BF'

export const MAX_RULES = 16
87 changes: 64 additions & 23 deletions src/module/smart-sessions/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,30 @@ import {
import { LibZip } from 'solady'
import { Account, AccountType, Execution } from '../../account'

export const getPermissionId = async ({
client,
session,
}: {
client: PublicClient
session: Session
}) => {
return (await client.readContract({
address: SMART_SESSIONS_ADDRESS,
abi,
functionName: 'getPermissionId',
args: [session],
})) as string
export const getPermissionId = ({ session }: { session: Session }): Hex => {
return keccak256(
encodeAbiParameters(
[
{
type: 'address',
name: 'sessionValidator',
},
{
type: 'bytes',
name: 'sessionValidatorInitData',
},
{
type: 'bytes32',
name: 'salt',
},
],
[
session.sessionValidator,
session.sessionValidatorInitData,
session.salt,
],
),
)
}

export const getActionId = async ({
Expand Down Expand Up @@ -142,10 +153,9 @@ export const encodeSmartSessionSignature = ({
}

return encodePacked(
['bytes1', 'bytes32', 'bytes'],
['bytes1', 'bytes'],
[
mode,
permissionId,
LibZip.flzCompress(
encodeEnableSessionSignature({ enableSessionData, signature }),
) as Hex,
Expand Down Expand Up @@ -213,12 +223,16 @@ export const decodeSmartSessionSignature = ({
account?: Account
}) => {
const mode = slice(signature, 0, 1)
const permissionId = slice(signature, 1, 33)
const compressedData = slice(signature, 33)
const data = LibZip.flzDecompress(compressedData) as Hex
let permissionId
let compressedData
let data

switch (mode) {
case SmartSessionMode.USE:
const signature = decodeAbiParameters(
permissionId = slice(signature, 1, 33)
compressedData = slice(signature, 33)
data = LibZip.flzDecompress(compressedData) as Hex
const decodedSignature = decodeAbiParameters(
[
{
type: 'bytes',
Expand All @@ -229,10 +243,13 @@ export const decodeSmartSessionSignature = ({
return {
mode,
permissionId,
signature,
signature: decodedSignature,
}
case SmartSessionMode.ENABLE:
case SmartSessionMode.UNSAFE_ENABLE:
compressedData = slice(signature, 1)
data = LibZip.flzDecompress(compressedData) as Hex

if (!account) {
throw new Error('account is required for ENABLE mode decoding')
}
Expand Down Expand Up @@ -260,8 +277,30 @@ export const decodeSmartSessionSignature = ({
20 + permissionEnableSigSlice,
)
return {
mode,
permissionId,
mode: mode,
permissionId: keccak256(
encodeAbiParameters(
[
{
type: 'address',
name: 'sessionValidator',
},
{
type: 'bytes',
name: 'sessionValidatorInitData',
},
{
type: 'bytes32',
name: 'salt',
},
],
[
enableSession.sessionToEnable.sessionValidator,
enableSession.sessionToEnable.sessionValidatorInitData,
enableSession.sessionToEnable.salt,
],
),
),
signature: decodedData[1],
enableSessionData: {
enableSession: {
Expand Down Expand Up @@ -481,14 +520,16 @@ export const getEnableERC1271PoliciesAction = ({
export const getDisableERC1271PoliciesAction = ({
permissionId,
policies,
contents,
}: {
permissionId: Hex
policies: Address[]
contents: string[]
}): Execution => {
const data = encodeFunctionData({
abi,
functionName: 'disableERC1271Policies',
args: [permissionId, policies],
args: [permissionId, policies, contents],
})

return {
Expand Down
4 changes: 3 additions & 1 deletion src/module/social-recovery/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const SOCIAL_RECOVERY_ADDRESS =
import { Address } from 'viem'

export const SOCIAL_RECOVERY_ADDRESS: Address =
'0xA04D053b3C8021e8D5bF641816c42dAA75D8b597'
4 changes: 3 additions & 1 deletion src/module/webauthn-validator/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const WEBAUTHN_VALIDATOR_ADDRESS =
import { Address } from 'viem'

export const WEBAUTHN_VALIDATOR_ADDRESS: Address =
'0xD990393C670dCcE8b4d8F858FB98c9912dBFAa06'
3 changes: 1 addition & 2 deletions test/e2e/infra/installModuleActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ export const getInstallModuleData = ({ account }: Pick<Params, 'account'>) => ({
smartSessions: {
sessions: [
{
sessionValidator:
'0x6605F8785E09a245DD558e55F9A0f4A508434503' as Address,
sessionValidator: OWNABLE_VALIDATOR_ADDRESS,
sessionValidatorInitData: encodeAbiParameters(
[
{
Expand Down
Loading

0 comments on commit 0213d05

Please sign in to comment.