Skip to content

Commit

Permalink
feat(relay-kit): Set default module version to 0.2.0 (#1148)
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv authored Feb 20, 2025
1 parent a197435 commit 873f495
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 35 deletions.
3 changes: 1 addition & 2 deletions packages/api-kit/tests/e2e/addSafeOperation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ describe('addSafeOperation', () => {
provider: protocolKit.getSafeProvider().provider,
signer: protocolKit.getSafeProvider().signer,
options: { safeAddress: SAFE_ADDRESS },
bundlerUrl: BUNDLER_URL,
safeModulesVersion: '0.2.0'
bundlerUrl: BUNDLER_URL
})
})

Expand Down
3 changes: 1 addition & 2 deletions packages/api-kit/tests/e2e/confirmSafeOperation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ describe('confirmSafeOperation', () => {
provider: options.provider || getEip1193Provider(),
signer: options.signer || PRIVATE_KEY_1,
options: { safeAddress: SAFE_ADDRESS },
bundlerUrl: BUNDLER_URL,
safeModulesVersion: '0.2.0'
bundlerUrl: BUNDLER_URL
})

const createSignature = async (safeOperation: SafeOperation, signer: string) => {
Expand Down
77 changes: 49 additions & 28 deletions packages/relay-kit/src/packs/safe-4337/Safe4337Pack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ describe('Safe4337Pack', () => {
it('should throw an error if the 4337 Module is not enabled in the Safe account', async () => {
await expect(
createSafe4337Pack({
options: { safeAddress: fixtures.SAFE_ADDRESS_4337_MODULE_NOT_ENABLED },
safeModulesVersion: '0.2.0'
options: { safeAddress: fixtures.SAFE_ADDRESS_4337_MODULE_NOT_ENABLED }
})
).rejects.toThrow(
`Incompatibility detected: The EIP-4337 module is not enabled in the provided Safe Account. Enable this module (address: ${fixtures.SAFE_4337_MODULE_ADDRESS_V0_2_0}) to add compatibility.`
Expand All @@ -87,8 +86,7 @@ describe('Safe4337Pack', () => {
it('should throw an error if the 4337 fallbackhandler is not attached to the Safe account', async () => {
await expect(
createSafe4337Pack({
options: { safeAddress: fixtures.SAFE_ADDRESS_4337_FALLBACKHANDLER_NOT_ENABLED },
safeModulesVersion: '0.2.0'
options: { safeAddress: fixtures.SAFE_ADDRESS_4337_FALLBACKHANDLER_NOT_ENABLED }
})
).rejects.toThrow(
`Incompatibility detected: The EIP-4337 fallbackhandler is not attached to the Safe Account. Attach this fallbackhandler (address: ${fixtures.SAFE_4337_MODULE_ADDRESS_V0_2_0}) to ensure compatibility.`
Expand All @@ -112,7 +110,8 @@ describe('Safe4337Pack', () => {
await expect(
createSafe4337Pack({
options: { safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE },
customContracts: { entryPointAddress: fixtures.ENTRYPOINT_ADDRESS_V06 }
customContracts: { entryPointAddress: fixtures.ENTRYPOINT_ADDRESS_V06 },
safeModulesVersion: '0.3.0'
})
).rejects.toThrow(
`The selected entrypoint ${fixtures.ENTRYPOINT_ADDRESS_V06} is not compatible with version 0.3.0 of Safe modules`
Expand All @@ -133,7 +132,8 @@ describe('Safe4337Pack', () => {

await expect(
createSafe4337Pack({
options: { safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE }
options: { safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE },
safeModulesVersion: '0.3.0'
})
).rejects.toThrow(
`Incompatibility detected: None of the entrypoints provided by the bundler is compatible with the Safe modules version 0.3.0`
Expand All @@ -142,7 +142,8 @@ describe('Safe4337Pack', () => {

it('should be able to instantiate the pack using a existing Safe', async () => {
const safe4337Pack = await createSafe4337Pack({
options: { safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE }
options: { safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE },
safeModulesVersion: '0.3.0'
})

expect(safe4337Pack).toBeInstanceOf(Safe4337Pack)
Expand All @@ -155,7 +156,8 @@ describe('Safe4337Pack', () => {

it('should have the 4337 module enabled', async () => {
const safe4337Pack = await createSafe4337Pack({
options: { safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE }
options: { safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE },
safeModulesVersion: '0.3.0'
})

expect(await safe4337Pack.protocolKit.getModules()).toContain(safe4337ModuleAddress)
Expand All @@ -169,7 +171,8 @@ describe('Safe4337Pack', () => {
},
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE
}
},
safeModulesVersion: '0.3.0'
})
).rejects.toThrow(
'Incompatibility detected: The EIP-4337 module is not enabled in the provided Safe Account. Enable this module (address: 0xCustomModule) to add compatibility.'
Expand All @@ -180,7 +183,8 @@ describe('Safe4337Pack', () => {
const safe4337Pack = await createSafe4337Pack({
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE
}
},
safeModulesVersion: '0.3.0'
})

expect(await safe4337Pack.protocolKit.getFallbackHandler()).toEqual(safe4337ModuleAddress)
Expand All @@ -193,7 +197,8 @@ describe('Safe4337Pack', () => {
options: {
owners: [fixtures.OWNER_1],
threshold: 1
}
},
safeModulesVersion: '0.3.0'
})

expect(await safe4337Pack.protocolKit.getAddress()).toBe(fixtures.PREDICTED_SAFE_ADDRESS)
Expand All @@ -206,7 +211,8 @@ describe('Safe4337Pack', () => {
owners: [fixtures.OWNER_1],
threshold: 1
},
customContracts: { entryPointAddress: fixtures.ENTRYPOINT_ADDRESS_V06 }
customContracts: { entryPointAddress: fixtures.ENTRYPOINT_ADDRESS_V06 },
safeModulesVersion: '0.3.0'
})
).rejects.toThrow(
`The selected entrypoint ${fixtures.ENTRYPOINT_ADDRESS_V06} is not compatible with version 0.3.0 of Safe modules`
Expand Down Expand Up @@ -241,7 +247,8 @@ describe('Safe4337Pack', () => {
options: {
owners: [fixtures.OWNER_1, fixtures.OWNER_2],
threshold: 1
}
},
safeModulesVersion: '0.3.0'
})

expect(encodeFunctionDataSpy).toHaveBeenCalledWith({
Expand Down Expand Up @@ -284,6 +291,7 @@ describe('Safe4337Pack', () => {
owners: [fixtures.OWNER_1],
threshold: 1
},
safeModulesVersion: '0.3.0',
paymasterOptions: {
paymasterUrl: fixtures.PAYMASTER_URL,
paymasterAddress: fixtures.PAYMASTER_ADDRESS,
Expand Down Expand Up @@ -364,7 +372,8 @@ describe('Safe4337Pack', () => {
safe4337Pack = await createSafe4337Pack({
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE
}
},
safeModulesVersion: '0.3.0'
})

transferUSDC = {
Expand Down Expand Up @@ -450,7 +459,8 @@ describe('Safe4337Pack', () => {
options: {
owners: [fixtures.OWNER_1],
threshold: 1
}
},
safeModulesVersion: '0.3.0'
})

const getInitCodeSpy = jest.spyOn(safe4337Pack.protocolKit, 'getInitCode')
Expand All @@ -470,6 +480,7 @@ describe('Safe4337Pack', () => {
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE
},
safeModulesVersion: '0.3.0',
paymasterOptions: {
isSponsored: true,
paymasterUrl: fixtures.PAYMASTER_URL
Expand Down Expand Up @@ -512,6 +523,7 @@ describe('Safe4337Pack', () => {
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE
},
safeModulesVersion: '0.3.0',
paymasterOptions: {
paymasterUrl: fixtures.PAYMASTER_URL,
paymasterTokenAddress: fixtures.PAYMASTER_TOKEN_ADDRESS,
Expand Down Expand Up @@ -615,7 +627,8 @@ describe('Safe4337Pack', () => {
options: {
owners: [fixtures.OWNER_1],
threshold: 1
}
},
safeModulesVersion: '0.3.0'
})

const passkeyOwnerConfiguration = {
Expand Down Expand Up @@ -740,7 +753,6 @@ describe('Safe4337Pack', () => {

const safe4337Pack = await createSafe4337Pack({
signer: passkey,
safeModulesVersion: '0.2.0',
options: {
safeAddress: fixtures.SAFE_ADDRESS_4337_PASSKEY
}
Expand Down Expand Up @@ -770,7 +782,8 @@ describe('Safe4337Pack', () => {
const safe4337Pack = await createSafe4337Pack({
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE
}
},
safeModulesVersion: '0.3.0'
})

expect(await safe4337Pack.protocolKit.getFallbackHandler()).toBe(
Expand All @@ -789,7 +802,8 @@ describe('Safe4337Pack', () => {
const safe4337Pack = await createSafe4337Pack({
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE
}
},
safeModulesVersion: '0.3.0'
})

const safeOperation = await safe4337Pack.createTransaction({
Expand All @@ -812,7 +826,8 @@ describe('Safe4337Pack', () => {
const safe4337Pack = await createSafe4337Pack({
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE
}
},
safeModulesVersion: '0.3.0'
})

expect(await safe4337Pack.signSafeOperation(fixtures.SAFE_OPERATION_RESPONSE)).toMatchObject({
Expand Down Expand Up @@ -847,7 +862,8 @@ describe('Safe4337Pack', () => {
const safe4337Pack = await createSafe4337Pack({
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE
}
},
safeModulesVersion: '0.3.0'
})
const readContractSpy = jest.spyOn(safe4337Pack.protocolKit.getSafeProvider(), 'readContract')

Expand Down Expand Up @@ -879,7 +895,6 @@ describe('Safe4337Pack', () => {

it('should allow to send a UserOperation to the bundler using a SafeOperationResponse object from the api', async () => {
const safe4337Pack = await createSafe4337Pack({
safeModulesVersion: '0.2.0',
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_2_0_MODULE
}
Expand Down Expand Up @@ -917,7 +932,8 @@ describe('Safe4337Pack', () => {
const safe4337Pack = await createSafe4337Pack({
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE
}
},
safeModulesVersion: '0.3.0'
})

const { userOperation, entryPoint, transactionHash, blockHash, blockNumber } =
Expand Down Expand Up @@ -953,7 +969,8 @@ describe('Safe4337Pack', () => {
const safe4337Pack = await createSafe4337Pack({
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE
}
},
safeModulesVersion: '0.3.0'
})

const userOperationReceipt = await safe4337Pack.getUserOperationReceipt(
Expand Down Expand Up @@ -991,7 +1008,8 @@ describe('Safe4337Pack', () => {
const safe4337Pack = await createSafe4337Pack({
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE
}
},
safeModulesVersion: '0.3.0'
})

const supportedEntryPoints = await safe4337Pack.getSupportedEntryPoints()
Expand All @@ -1008,7 +1026,8 @@ describe('Safe4337Pack', () => {
},
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE
}
},
safeModulesVersion: '0.3.0'
})

const onchainIdentifier = await safe4337Pack.getOnchainIdentifier()
Expand Down Expand Up @@ -1038,7 +1057,8 @@ describe('Safe4337Pack', () => {
},
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE
}
},
safeModulesVersion: '0.3.0'
})

const transferUSDC = {
Expand Down Expand Up @@ -1075,7 +1095,8 @@ describe('Safe4337Pack', () => {
const safe4337Pack = await createSafe4337Pack({
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1_WITH_0_3_0_MODULE
}
},
safeModulesVersion: '0.3.0'
})

const customNonce = utils.encodeNonce({
Expand Down
2 changes: 1 addition & 1 deletion packages/relay-kit/src/packs/safe-4337/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parseAbi } from 'viem'

export const DEFAULT_SAFE_VERSION = '1.4.1'
export const DEFAULT_SAFE_MODULES_VERSION = '0.3.0'
export const DEFAULT_SAFE_MODULES_VERSION = '0.2.0'

export const EIP712_SAFE_OPERATION_TYPE_V06 = {
SafeOp: [
Expand Down
2 changes: 0 additions & 2 deletions playground/relay-kit/userop-api-kit-interoperability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ async function main() {
provider: RPC_URL,
signer: OWNER_1_PRIVATE_KEY,
bundlerUrl: BUNDLER_URL,
safeModulesVersion: '0.2.0',
paymasterOptions: {
isSponsored: true,
paymasterUrl: PAYMASTER_URL
Expand Down Expand Up @@ -61,7 +60,6 @@ async function main() {
provider: RPC_URL,
signer: OWNER_2_PRIVATE_KEY,
bundlerUrl: BUNDLER_URL,
safeModulesVersion: '0.2.0',
paymasterOptions: {
isSponsored: true,
paymasterUrl: PAYMASTER_URL
Expand Down

0 comments on commit 873f495

Please sign in to comment.