Skip to content

Commit adc19f9

Browse files
committed
fix: expanded mixins
1 parent 28e5f9d commit adc19f9

File tree

6 files changed

+70
-37
lines changed

6 files changed

+70
-37
lines changed

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
isa = PBXProject;
218218
attributes = {
219219
BuildIndependentTargetsInParallel = YES;
220-
LastUpgradeCheck = 1430;
220+
LastUpgradeCheck = 1510;
221221
ORGANIZATIONNAME = "";
222222
TargetAttributes = {
223223
331C8080294A63A400263BE5 = {

example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1430"
3+
LastUpgradeVersion = "1510"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

example/ios/Runner/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import UIKit
22
import Flutter
33

4-
@UIApplicationMain
4+
@main
55
@objc class AppDelegate: FlutterAppDelegate {
66
override func application(
77
_ application: UIApplication,

example/lib/providers/wallet_provider.dart

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,38 @@ class WalletProvider extends ChangeNotifier {
1515
String get errorMessage => _errorMessage;
1616

1717
final EthereumAddress nft =
18-
EthereumAddress.fromHex("0x4B509a7e891Dc8fd45491811d67a8B9e7ef547B9");
18+
EthereumAddress.fromHex("0x3661b40C520a273214d281bd84730BA68604d874");
1919
final EthereumAddress erc20 =
20-
EthereumAddress.fromHex("0xAEaF19097D8a8da728438D6B57edd9Bc5DAc4795");
20+
EthereumAddress.fromHex("0x69583ED4AA579fdc83FB6CCF13A5Ffd9B39F62aF");
2121
final EthereumAddress deployer =
2222
EthereumAddress.fromHex("0xf5bb7f874d8e3f41821175c0aa9910d30d10e193");
23+
final EthereumAddress sharedSigner =
24+
EthereumAddress.fromHex("0x94a4F6affBd8975951142c3999aEAB7ecee555c2");
25+
final EthereumAddress p256Verifier =
26+
EthereumAddress.fromHex("0xc2b78104907F722DABAc4C69f826a522B2754De4");
2327

2428
final salt = Uint256.zero;
25-
static const rpc = "https://api.pimlico.io/v2/84532/rpc?apikey=API_KEY";
29+
static const rpc =
30+
"https://api.pimlico.io/v2/123/rpc?apikey=${"PIMLICO_API_KEY"}";
2631

2732
WalletProvider()
28-
: _chain = Chains.getChain(Network.baseTestnet)
29-
..accountFactory = Constants.lightAccountFactoryAddressv07
30-
..bundlerUrl = rpc
31-
..paymasterUrl = rpc;
33+
: _chain = Chain(
34+
bundlerUrl: rpc,
35+
// paymasterUrl: rpc, // for fuse network, not really working.
36+
testnet: true,
37+
chainId: 123,
38+
jsonRpcUrl: "https://rpc.fusespark.io",
39+
accountFactory: Constants.safeProxyFactoryAddress,
40+
explorer: "https://explorer.fusespark.io/",
41+
entrypoint: EntryPointAddress.v07);
3242

3343
Future<void> registerWithPassKey(String name,
3444
{bool? requiresUserVerification}) async {
35-
_chain.accountFactory = Constants.safeProxyFactoryAddress;
36-
3745
final options = PassKeysOptions(
38-
name: "variance",
39-
namespace: "variance.space",
40-
sharedWebauthnSigner: EthereumAddress.fromHex(
41-
"0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9"));
46+
name: "variance",
47+
namespace: "variance.space",
48+
sharedWebauthnSigner: sharedSigner,
49+
);
4250
final pkpSigner = PassKeySigner(options: options);
4351

4452
try {
@@ -48,8 +56,8 @@ class WalletProvider extends ChangeNotifier {
4856
"${DateTime.timestamp().millisecondsSinceEpoch}@variance.space",
4957
name);
5058
_wallet = await walletFactory.createSafeAccountWithPasskey(
51-
keypair, salt, options.sharedWebauthnSigner);
52-
59+
keypair, salt, options.sharedWebauthnSigner, p256Verifier);
60+
overrideGas();
5361
log("wallet created ${_wallet?.address.hex} ");
5462
} catch (e) {
5563
_errorMessage = e.toString();
@@ -60,6 +68,8 @@ class WalletProvider extends ChangeNotifier {
6068
}
6169

6270
Future<void> createEOAWallet() async {
71+
_chain.accountFactory = Constants.lightAccountFactoryAddressv07;
72+
6373
final signer = EOAWallet.createWallet(
6474
WordLength.word_12, const SignatureOptions(prefix: [0]));
6575
final SmartWalletFactory walletFactory = SmartWalletFactory(_chain, signer);
@@ -75,6 +85,8 @@ class WalletProvider extends ChangeNotifier {
7585
}
7686

7787
Future<void> createPrivateKeyWallet() async {
88+
_chain.accountFactory = Constants.lightAccountFactoryAddressv07;
89+
7890
final signer = PrivateKeySigner.createRandom(
7991
"password", const SignatureOptions(prefix: [0]));
8092
final SmartWalletFactory walletFactory = SmartWalletFactory(_chain, signer);
@@ -90,13 +102,12 @@ class WalletProvider extends ChangeNotifier {
90102
}
91103

92104
Future<void> createSafeWallet() async {
93-
_chain.accountFactory = Constants.safeProxyFactoryAddress;
94-
95105
final signer = EOAWallet.createWallet();
96106
final SmartWalletFactory walletFactory = SmartWalletFactory(_chain, signer);
97107

98108
try {
99109
_wallet = await walletFactory.createSafeAccount(salt);
110+
overrideGas();
100111
log("wallet created ${_wallet?.address.hex} ");
101112
} catch (e) {
102113
log("something happened: $e");
@@ -132,11 +143,21 @@ class WalletProvider extends ChangeNotifier {
132143
final etherAmount = EtherAmount.fromBigInt(
133144
EtherUnit.wei, BigInt.from(double.parse(amount) * math.pow(10, 18)));
134145

135-
final response = await _wallet?.send(
136-
EthereumAddress.fromHex("0xF5bB7F874D8e3f41821175c0Aa9910d30d10e193"),
137-
etherAmount);
146+
final response = await _wallet?.send(deployer, etherAmount);
138147
final receipt = await response?.wait();
139148

140149
log("Transaction receipt Hash: ${receipt?.userOpHash}");
141150
}
151+
152+
overrideGas() {
153+
//@dev use only when using contract verifier,
154+
// do not use this function with precompiles.
155+
// for the safe deployment transaction do not use the multiplier
156+
// multiply verification gas until it exceeds 400k gas
157+
_wallet?.gasSettings = GasSettings(
158+
verificationGasMultiplierPercentage:
159+
650, //7.5x higher than base - about 410k. adjust if needed
160+
userDefinedMaxFeePerGas: BigInt.from(24500000000),
161+
userDefinedMaxPriorityFeePerGas: BigInt.from(12300000000));
162+
}
142163
}

lib/src/4337/wallet.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase {
144144
@override
145145
Future<UserOperationResponse> sendUserOperation(UserOperation op) =>
146146
prepareUserOperation(op)
147+
.then(applyCustomGasSettings)
147148
.then(signUserOperation)
148149
.then(sendSignedUserOperation);
149150

@@ -152,16 +153,12 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase {
152153
{bool update = true}) async {
153154
// Update the user operation with the latest nonce and gas prices if needed
154155
if (update) op = await _updateUserOperation(op);
155-
156156
// If the 'paymaster' plugin is enabled, intercept the user operation
157157
if (hasPlugin('paymaster')) {
158158
op = await plugin<Paymaster>('paymaster').intercept(op);
159159
}
160-
161-
op = applyCustomGasSettings(op);
162160
// Validate the user operation
163161
op.validate(op.nonce > BigInt.zero, initCode);
164-
165162
return op;
166163
}
167164

@@ -171,7 +168,7 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase {
171168
final blockInfo =
172169
await plugin<JsonRPCProviderBase>('jsonRpc').getBlockInformation();
173170

174-
calculateOperationHash(UserOperation op, BlockInformation blockInfo) async {
171+
calculateOperationHash(UserOperation op) async {
175172
if (isSafe) {
176173
return plugin<_SafePlugin>('safe').getSafeOperationHash(op, blockInfo);
177174
} else {
@@ -190,7 +187,7 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase {
190187
return signatureHex;
191188
}
192189

193-
final opHash = await calculateOperationHash(op, blockInfo);
190+
final opHash = await calculateOperationHash(op);
194191
op.signature = await signOperationHash(opHash, index);
195192
return op;
196193
}

lib/src/common/mixins.dart

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ class GasSettings {
77
/// The percentage by which the gas limits should be multiplied.
88
///
99
/// This value should be between 0 and 100.
10-
Percent gasMultiplierPercentage;
10+
Percent callGasMultiplierPercentage;
11+
Percent verificationGasMultiplierPercentage;
12+
Percent preVerificationGasMultiplierPercentage;
1113

1214
/// The user-defined maximum fee per gas for the transaction.
1315
BigInt? userDefinedMaxFeePerGas;
@@ -26,10 +28,16 @@ class GasSettings {
2628
///
2729
/// An assertion is made to ensure that [gasMultiplierPercentage] is between 0 and 100.
2830
GasSettings({
29-
this.gasMultiplierPercentage = 0,
31+
this.callGasMultiplierPercentage = 0,
32+
this.verificationGasMultiplierPercentage = 0,
33+
this.preVerificationGasMultiplierPercentage = 0,
3034
this.userDefinedMaxFeePerGas,
3135
this.userDefinedMaxPriorityFeePerGas,
32-
}) : assert(gasMultiplierPercentage >= 0,
36+
}) : assert(
37+
callGasMultiplierPercentage >= 0 &&
38+
callGasMultiplierPercentage <= 100 &&
39+
verificationGasMultiplierPercentage >= 0 &&
40+
preVerificationGasMultiplierPercentage >= 0,
3341
RangeOutOfBounds("Wrong Gas multiplier percentage", 0, 100));
3442
}
3543

@@ -49,16 +57,23 @@ mixin _GasSettings {
4957
///
5058
/// Returns a new [UserOperation] object with the updated gas settings.
5159
UserOperation applyCustomGasSettings(UserOperation op) {
52-
final multiplier = _gasParams.gasMultiplierPercentage / 100 + 1;
60+
final cglMultiplier = _gasParams.callGasMultiplierPercentage / 100 + 1;
61+
final vglMultiplier =
62+
_gasParams.verificationGasMultiplierPercentage / 100 + 1;
63+
final preVglMultiplier =
64+
_gasParams.preVerificationGasMultiplierPercentage / 100 + 1;
65+
final multiplier = cglMultiplier * vglMultiplier * preVglMultiplier;
5366

54-
if (multiplier == 1) return op;
67+
if (multiplier == 1 &&
68+
_gasParams.userDefinedMaxFeePerGas == null &&
69+
_gasParams.userDefinedMaxPriorityFeePerGas == null) return op;
5570

5671
return op.copyWith(
57-
callGasLimit: BigInt.from(op.callGasLimit.toDouble() * multiplier),
72+
callGasLimit: BigInt.from(op.callGasLimit.toDouble() * cglMultiplier),
5873
verificationGasLimit:
59-
BigInt.from(op.verificationGasLimit.toDouble() * multiplier),
74+
BigInt.from(op.verificationGasLimit.toDouble() * vglMultiplier),
6075
preVerificationGas:
61-
BigInt.from(op.preVerificationGas.toDouble() * multiplier),
76+
BigInt.from(op.preVerificationGas.toDouble() * preVglMultiplier),
6277
maxFeePerGas: _gasParams.userDefinedMaxFeePerGas,
6378
maxPriorityFeePerGas: _gasParams.userDefinedMaxPriorityFeePerGas);
6479
}

0 commit comments

Comments
 (0)