Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/smart sessions (WIP) #582

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/sdk/__contracts/abi/CounterAbi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export const CounterAbi = [
{
inputs: [],
name: "decrementNumber",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [],
name: "getNumber",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "incrementNumber",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [],
name: "revertOperation",
outputs: [],
stateMutability: "pure",
type: "function"
}
] as const

7 changes: 6 additions & 1 deletion src/sdk/__contracts/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
export const addresses = {
Nexus: "0xcb56273F55Fde691f92976B976cf79f79a5B4c22",
K1Validator: "0x08FCa672878aD598FBDaDdEBFbB71Dd9BA90b75a",
K1ValidatorFactory: "0xEC6596Ca8ea4DBFb8Ca1B365490Dce8dAe2CCDcA"
K1ValidatorFactory: "0xEC6596Ca8ea4DBFb8Ca1B365490Dce8dAe2CCDcA",
UniActionPolicy: "0x28120dC008C36d95DE5fa0603526f219c1Ba80f6",
TimeframePolicy: "0x0B7BB9bD65858593D97f12001FaDa94828307805",
// Note: deployed smart sess on 17 apr with useRegistry:false
SmartSession: "0x3834aD7f5f73fAd19C089a924F18e6F3417d1ac2",
SimpleSessionValidator: "0xAAAdFd794A1781e4Fd3eA64985F107a7Ac2b3872", // K1 algorithm - single session key
} as const
export default addresses
1 change: 1 addition & 0 deletions src/sdk/clients/decorators/erc7579/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export function erc7579Actions() {
})
}

// Review: if this should be imported from module-sdk
export type Module = {
address: Address
data?: Hex
Expand Down
1 change: 1 addition & 0 deletions src/sdk/modules/base/BaseValidationModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export abstract class BaseValidationModule extends BaseModule {
return this.signer
}


getDummySignature(): Hex {
const moduleAddress = getAddress(this.getAddress())
const dynamicPart = moduleAddress.substring(2).padEnd(40, "0")
Expand Down
3 changes: 3 additions & 0 deletions src/sdk/modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { K1ValidatorModule } from "./validators/K1ValidatorModule.js"
import { OwnableValidator } from "./validators/OwnableValidator.js"
import { SmartSessionValidator } from "./validators/SmartSessionValidator.js"
import { ValidationModule } from "./validators/ValidationModule.js"

export * from "./utils/Types.js"
Expand All @@ -10,4 +11,6 @@ export * from "./interfaces/IValidationModule.js"
// export const createOwnableExecutorModule = OwnableExecutorModule.create
export const createK1ValidatorModule = K1ValidatorModule.create
export const createOwnableValidatorModule = OwnableValidator.create
// Review below should be Validator too
export const createValidationModule = ValidationModule.create
export const createSmartSessionValidatorModule = SmartSessionValidator.create
78 changes: 78 additions & 0 deletions src/sdk/modules/utils/Helper.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {
type Address,
type ByteArray,
type Chain,
type Hex,
type PrivateKeyAccount,
type PublicClient,
encodeAbiParameters,
isHex,
keccak256,
Expand All @@ -17,9 +19,13 @@ import {
getChain
} from "../../account/index.js"
import type {
ActionConfig,
ChainInfo
// createOwnableValidatorModule
} from "../../index.js"
import { type Session } from "@rhinestone/module-sdk"
import addresses from "../../__contracts/addresses.js"
import { smartSessionAbi } from "./abi.js"

/**
* Rule
Expand Down Expand Up @@ -202,3 +208,75 @@ export function parseReferenceValue(referenceValue: AnyReferenceValue): Hex {
}
return result
}

export const toActionConfig = (config: ActionConfig): ActionConfig => {
// Ensure we always have 16 rules, filling with default values if necessary
const filledRules = [...config.paramRules.rules];

// Fill the rest with default ParamRule if the length is less than 16
while (filledRules.length < 16) {
filledRules.push({
condition: 0, // Default condition (EQUAL)
offset: 0, // Default offsetIndex
isLimited: false, // Default isLimited flag
ref: "0x0000000000000000000000000000000000000000000000000000000000000000", // Default bytes32 ref
usage: {
limit: BigInt(0), // Default limit
used: BigInt(0) // Default used
}
});
}

return {
valueLimitPerUse: BigInt(config.valueLimitPerUse),
paramRules: {
length: config.paramRules.length,
rules: filledRules.map((rule) => {
const parsedRef = parseReferenceValue(rule.ref);
return {
condition: rule.condition,
offset: rule.offset * 32, // Ensure correct offset calculation
isLimited: rule.isLimited,
ref: parsedRef,
usage: rule.usage
};
})
}
};
};

// Review
// Note: presently created local helper.
// Todo: If any changes are approved in module-sdk then start importing from there.
export const getPermissionId = async ({
client,
session,
}: {
client: PublicClient
session: Session
}) => {
// Review address population
return (await client.readContract({
address: addresses.SmartSession,
abi: smartSessionAbi,
functionName: 'getPermissionId',
args: [session],
})) as Hex
}

export const isSessionEnabled = async ({
client,
accountAddress,
permissionId,
}: {
client: PublicClient
accountAddress: Address
permissionId: Hex
}) => {
return (await client.readContract({
address: addresses.SmartSession,
abi: smartSessionAbi,
functionName: 'isSessionEnabled',
args: [permissionId, accountAddress],
})) as boolean
}
Loading
Loading