Skip to content

Commit e6df368

Browse files
feat: safe contract v1_5_0
1 parent 0403a30 commit e6df368

File tree

5 files changed

+129
-11
lines changed

5 files changed

+129
-11
lines changed

src/abstractionkit.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export {
1616
} from "./account/Safe/modules/AllowanceModule";
1717
export { SafeAccountV0_2_0 } from "./account/Safe/SafeAccountV0_2_0";
1818
export { SafeAccountV0_3_0 } from "./account/Safe/SafeAccountV0_3_0";
19+
export { SafeAccountV1_5_0_M_0_3_0 } from "./account/Safe/SafeAccountV1_5_0_M_0_3_0";
1920

2021
export { SendUseroperationResponse } from "./account/SendUseroperationResponse";
2122

src/account/Safe/SafeAccount.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
BaseInitOverrides,
5959
WebauthnDummySignerSignaturePair,
6060
WebauthnPublicKey,
61+
SafeAccountSingleton,
6162
} from "./types";
6263
import { decodeMultiSendCallData, encodeMultiSendCallData } from "./multisend";
6364
import { AbstractionKitError, ensureError } from "src/errors";
@@ -67,8 +68,6 @@ import { SafeAccountFactory } from "src/factory/SafeAccountFactory";
6768
import { getSafeMessageEip712Data, SafeMessageTypedDataDomain, SafeMessageTypedMessageValue } from "./safeMessage";
6869

6970
export class SafeAccount extends SmartAccount {
70-
static readonly DEFAULT_SAFE_SINGLETON = Safe_L2_V1_4_1;
71-
7271
static readonly DEFAULT_WEB_AUTHN_SHARED_SIGNER: string =
7372
"0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9";
7473
static readonly DEFAULT_WEB_AUTHN_SIGNER_SINGLETON: string =
@@ -110,6 +109,7 @@ export class SafeAccount extends SmartAccount {
110109
protected x: bigint | null = null;
111110
protected y: bigint | null = null;
112111

112+
readonly safeAccountSingleton:SafeAccountSingleton;
113113
readonly entrypointAddress: string;
114114
readonly safe4337ModuleAddress: string;
115115
protected factoryAddress: string | null;
@@ -124,6 +124,7 @@ export class SafeAccount extends SmartAccount {
124124
overrides: {
125125
onChainIdentifierParams?: OnChainIdentifierParamsType;
126126
onChainIdentifier?: string;
127+
safeAccountSingleton?: SafeAccountSingleton;
127128
} = {}
128129
) {
129130
super(accountAddress);
@@ -160,6 +161,7 @@ export class SafeAccount extends SmartAccount {
160161
}else{
161162
this.onChainIdentifier = null;
162163
}
164+
this.safeAccountSingleton = overrides.safeAccountSingleton?? Safe_L2_V1_4_1;
163165
}
164166

165167
/**
@@ -172,7 +174,7 @@ export class SafeAccount extends SmartAccount {
172174
* SafeAccountFactory.DEFAULT_FACTORY_ADDRESS
173175
* @param overrides.singletonInitHash - a hash that includes the singleton address and thr proxy bytecode
174176
* keccak256(solidityPacked(["bytes", "bytes"], [proxyByteCode, abiCoder.encode(["uint256"], [singletonAddress])]))
175-
* defaults to SafeAccount.DEFAULT_SAFE_SINGLETON.singletonInitHash
177+
* defaults to SafeAccount.safeAccountSingleton.singletonInitHash
176178
* @returns proxy/account address
177179
*/
178180
public static createProxyAddress(
@@ -191,8 +193,7 @@ export class SafeAccount extends SmartAccount {
191193
overrides.safeFactoryAddress ??
192194
SafeAccountFactory.DEFAULT_FACTORY_ADDRESS;
193195
const singletonInitHash =
194-
overrides.singletonInitHash ??
195-
SafeAccount.DEFAULT_SAFE_SINGLETON.singletonInitHash;
196+
overrides.singletonInitHash ?? Safe_L2_V1_4_1.singletonInitHash;
196197
const salt = keccak256(
197198
solidityPacked(
198199
["bytes32", "uint256"],
@@ -914,9 +915,8 @@ export class SafeAccount extends SmartAccount {
914915
} else {
915916
safeAccountFactory = new SafeAccountFactory();
916917
}
917-
918918
const safeSingleton =
919-
overrides.safeAccountSingleton ?? SafeAccount.DEFAULT_SAFE_SINGLETON;
919+
overrides.safeAccountSingleton ?? Safe_L2_V1_4_1;
920920
const sender = this.createProxyAddress(initializerCallData, {
921921
c2Nonce: overrides.c2Nonce ?? 0n,
922922
safeFactoryAddress: safeAccountFactory.address,
@@ -1118,7 +1118,7 @@ export class SafeAccount extends SmartAccount {
11181118
}
11191119

11201120
const safeSingleton =
1121-
overrides.safeAccountSingleton ?? SafeAccount.DEFAULT_SAFE_SINGLETON;
1121+
overrides.safeAccountSingleton ?? Safe_L2_V1_4_1;
11221122

11231123
const generatorFunctionInputParameters = [
11241124
safeSingleton.singletonAddress,

src/account/Safe/SafeAccountV0_3_0.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import {
55
CreateUserOperationV7Overrides,
66
SafeUserOperationTypedDataDomain,
77
SafeUserOperationV7TypedMessageValue,
8+
SafeAccountSingleton,
89
} from "./types";
910

1011
import { UserOperationV7, MetaTransaction, OnChainIdentifierParamsType } from "../../types";
11-
import { ENTRYPOINT_V7 } from "src/constants";
12+
import { ENTRYPOINT_V7, Safe_L2_V1_4_1 } from "src/constants";
1213

1314
export class SafeAccountV0_3_0 extends SafeAccount {
1415
static readonly DEFAULT_ENTRYPOINT_ADDRESS = ENTRYPOINT_V7;
@@ -24,6 +25,7 @@ export class SafeAccountV0_3_0 extends SafeAccount {
2425
entrypointAddress?: string;
2526
onChainIdentifierParams?: OnChainIdentifierParamsType;
2627
onChainIdentifier?: string
28+
safeAccountSingleton?: SafeAccountSingleton;
2729
} = {},
2830
) {
2931
const safe4337ModuleAddress =
@@ -37,7 +39,8 @@ export class SafeAccountV0_3_0 extends SafeAccount {
3739
accountAddress, safe4337ModuleAddress, entrypointAddress,
3840
{
3941
onChainIdentifierParams: overrides.onChainIdentifierParams,
40-
onChainIdentifier: overrides.onChainIdentifier
42+
onChainIdentifier: overrides.onChainIdentifier,
43+
safeAccountSingleton: overrides.safeAccountSingleton
4144
}
4245
);
4346
}
@@ -100,7 +103,7 @@ export class SafeAccountV0_3_0 extends SafeAccount {
100103
}
101104
}
102105
const [accountAddress, factoryAddress, factoryData] =
103-
SafeAccountV0_3_0.createAccountAddressAndFactoryAddressAndData(
106+
SafeAccount.createAccountAddressAndFactoryAddressAndData(
104107
owners,
105108
overrides,
106109
overrides.safe4337ModuleAddress ??
@@ -298,3 +301,6 @@ export class SafeAccountV0_3_0 extends SafeAccount {
298301
return userOperationV7;
299302
}
300303
}
304+
305+
export class SafeAccountV1_4_1_M_0_3_0 extends SafeAccountV0_3_0 {
306+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { OnChainIdentifierParamsType } from "src/types";
2+
import { SafeAccountV0_3_0 } from "./SafeAccountV0_3_0";
3+
import { Signer, InitCodeOverrides } from "./types";
4+
import { Safe_L2_V1_5_0 } from "src/constants";
5+
import { AbiCoder, keccak256, solidityPacked } from "ethers";
6+
import { SafeAccount } from "./SafeAccount";
7+
8+
export class SafeAccountV1_5_0_M_0_3_0 extends SafeAccountV0_3_0 {
9+
constructor(
10+
accountAddress: string,
11+
overrides: {
12+
safe4337ModuleAddress?: string;
13+
entrypointAddress?: string;
14+
onChainIdentifierParams?: OnChainIdentifierParamsType;
15+
onChainIdentifier?: string
16+
} = {},
17+
) {
18+
super(
19+
accountAddress,
20+
{
21+
onChainIdentifierParams: overrides.onChainIdentifierParams,
22+
onChainIdentifier: overrides.onChainIdentifier,
23+
safeAccountSingleton: Safe_L2_V1_5_0
24+
}
25+
);
26+
}
27+
28+
public static createProxyAddress(
29+
initializerCallData: string,
30+
overrides: {
31+
c2Nonce?: bigint;
32+
safeFactoryAddress?: string;
33+
singletonInitHash?: string;
34+
} = {},
35+
): string {
36+
const modOverrides = overrides;
37+
modOverrides.singletonInitHash =
38+
overrides.singletonInitHash??Safe_L2_V1_5_0.singletonInitHash;
39+
return SafeAccountV0_3_0.createProxyAddress(
40+
initializerCallData,
41+
modOverrides
42+
);
43+
}
44+
45+
/**
46+
* To create and initialize a SafeAccount object from its
47+
* initial owners
48+
* @remarks
49+
* initializeNewAccount only needed when the smart account
50+
* have not been deployed yet and the account address is unknown.
51+
* @param owners - list of account owners signers
52+
* @param overrides - override values to change the initialization default values
53+
* @returns a SafeAccount object
54+
*/
55+
public static initializeNewAccount(
56+
owners: Signer[],
57+
overrides: InitCodeOverrides = {},
58+
): SafeAccountV1_5_0_M_0_3_0 {
59+
const modOverrides = overrides;
60+
modOverrides.safeAccountSingleton =
61+
overrides.safeAccountSingleton??Safe_L2_V1_5_0;
62+
return SafeAccountV0_3_0.initializeNewAccount(
63+
owners,
64+
overrides
65+
);
66+
}
67+
68+
/**
69+
* calculate account addressfrom initial owners signers
70+
* @param owners - list of account owners addresses
71+
* @param overrides - override values to change the initialization default values
72+
* @returns account address
73+
*/
74+
public static createAccountAddress(
75+
owners: Signer[],
76+
overrides: InitCodeOverrides = {},
77+
): string {
78+
const modOverrides = overrides;
79+
modOverrides.safeAccountSingleton =
80+
overrides.safeAccountSingleton??Safe_L2_V1_5_0;
81+
return SafeAccountV0_3_0.createAccountAddress(
82+
owners,
83+
modOverrides
84+
);
85+
}
86+
87+
/**
88+
* create account factory address and factory data
89+
* @param owners - list of account owners signers
90+
* @param overrides - override values to change the initialization default values
91+
* @returns factoryAddress and factoryData
92+
*/
93+
public static createFactoryAddressAndData(
94+
owners: Signer[],
95+
overrides: InitCodeOverrides = {},
96+
): [string, string] {
97+
const modOverrides = overrides;
98+
modOverrides.safeAccountSingleton =
99+
overrides.safeAccountSingleton??Safe_L2_V1_5_0;
100+
return SafeAccountV0_3_0.createFactoryAddressAndData(
101+
owners,
102+
overrides
103+
);
104+
}
105+
}

src/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ export const ENTRYPOINT_V8 = "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108";
66
export const ENTRYPOINT_V7 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
77
export const ENTRYPOINT_V6 = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
88

9+
export const Safe_L2_V1_5_0: SafeAccountSingleton = {
10+
singletonAddress: "0xEdd160fEBBD92E350D4D398fb636302fccd67C7e",
11+
singletonInitHash:
12+
"0x1b94aebb5a7df6dff11d93589204a6bbc99b4b8c9014bf1d386d006c2c17a881",
13+
};
14+
915
export const Safe_L2_V1_4_1: SafeAccountSingleton = {
1016
singletonAddress: "0x29fcB43b46531BcA003ddC8FCB67FFE91900C762",
1117
singletonInitHash:

0 commit comments

Comments
 (0)