-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
272 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,55 @@ | ||
part of '../../variance.dart'; | ||
|
||
abstract class PaymasterBase {} | ||
class PaymasterResponse { | ||
final Uint8List paymasterAndData; | ||
final BigInt preVerificationGas; | ||
final BigInt verificationGasLimit; | ||
final BigInt callGasLimit; | ||
|
||
class Paymaster {} | ||
PaymasterResponse({ | ||
required this.paymasterAndData, | ||
required this.preVerificationGas, | ||
required this.verificationGasLimit, | ||
required this.callGasLimit, | ||
}); | ||
|
||
factory PaymasterResponse.fromMap(Map<String, dynamic> map) { | ||
return PaymasterResponse( | ||
paymasterAndData: hexToBytes(map['paymasterAndData']), | ||
preVerificationGas: BigInt.parse(map['preVerificationGas']), | ||
verificationGasLimit: BigInt.parse(map['verificationGasLimit']), | ||
callGasLimit: BigInt.parse(map['callGasLimit']), | ||
); | ||
} | ||
} | ||
|
||
class Paymaster { | ||
final RPCProviderBase _rpc; | ||
final Chain _chain; | ||
Map<String, String>? _context; | ||
|
||
set context(Map<String, String>? context) { | ||
_context = context; | ||
} | ||
|
||
Paymaster(this._chain, this._rpc, [this._context]); | ||
|
||
Future<UserOperation> intercept(UserOperation operation) async { | ||
final paymasterResponse = await sponsorUserOperation( | ||
operation.toMap(), _chain.entrypoint, _context); | ||
|
||
return operation.copyWith( | ||
paymasterAndData: paymasterResponse.paymasterAndData, | ||
preVerificationGas: paymasterResponse.preVerificationGas, | ||
verificationGasLimit: paymasterResponse.verificationGasLimit, | ||
callGasLimit: paymasterResponse.callGasLimit, | ||
); | ||
} | ||
|
||
Future<PaymasterResponse> sponsorUserOperation(Map<String, dynamic> userOp, | ||
EthereumAddress entrypoint, Map<String, String>? context) async { | ||
final response = await _rpc.send<Map<String, dynamic>>( | ||
'pm_sponsorUserOperation', [userOp, entrypoint.hex, context]); | ||
return PaymasterResponse.fromMap(response); | ||
} | ||
} |
Oops, something went wrong.