-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tx receipt + base link + fix fees estimation (#28)
- Loading branch information
Showing
16 changed files
with
374 additions
and
199 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from "react"; | ||
import LoaderSVG from "./Loader.svg"; | ||
import Image from "next/image"; | ||
|
||
export default function LoadingSpinner() { | ||
return <Image src={LoaderSVG} className="spinner" alt="Loading..." />; | ||
} |
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
14 changes: 14 additions & 0 deletions
14
front/src/libs/smart-wallet/service/actions/estimateUserOperationGas.ts
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { SmartWalletClient } from "@/libs/smart-wallet/service/smart-wallet"; | ||
|
||
/* */ | ||
export type EstimateUserOperationGasReturnType = bigint; | ||
|
||
export async function estimateUserOperationGas( | ||
client: SmartWalletClient, | ||
args: any, | ||
): Promise<EstimateUserOperationGasReturnType> { | ||
return await client.request({ | ||
method: "eth_estimateUserOperationGas" as any, | ||
params: args, | ||
}); | ||
} |
13 changes: 13 additions & 0 deletions
13
front/src/libs/smart-wallet/service/actions/getIsValidSignature.ts
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { SmartWalletClient } from "@/libs/smart-wallet/service/smart-wallet"; | ||
|
||
export type GetIsValidSignatureReturnType = boolean; | ||
|
||
export async function getIsValidSignature( | ||
client: SmartWalletClient, | ||
args: any, | ||
): Promise<GetIsValidSignatureReturnType> { | ||
return await client.request({ | ||
method: "eth_call" as any, | ||
params: args, | ||
}); | ||
} |
14 changes: 14 additions & 0 deletions
14
front/src/libs/smart-wallet/service/actions/getUserOperationReceipt.ts
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { SmartWalletClient } from "@/libs/smart-wallet/service/smart-wallet"; | ||
import { Hash } from "viem"; | ||
|
||
export type GetUserOperationReceiptReturnType = Hash; | ||
|
||
export async function getUserOperationReceipt( | ||
client: SmartWalletClient, | ||
args: { hash: Hash }, | ||
): Promise<any> { | ||
return await client.request({ | ||
method: "eth_getUserOperationReceipt" as any, | ||
params: [args.hash], | ||
}); | ||
} |
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,123 +1,5 @@ | ||
import { UserOpBuilder } from "@/libs/smart-wallet/service/userOps"; | ||
import { P256Credential, WebAuthn } from "@/libs/webauthn"; | ||
import { | ||
Chain, | ||
Client, | ||
Hash, | ||
Hex, | ||
RpcTransactionRequest, | ||
encodeAbiParameters, | ||
encodePacked, | ||
} from "viem"; | ||
|
||
/* */ | ||
export type SendUserOperationReturnType = Hash; | ||
|
||
export async function sendUserOperation( | ||
client: Client, | ||
args: { to: Hex; value: bigint }, | ||
): Promise<SendUserOperationReturnType> { | ||
const builder = new UserOpBuilder(client.chain as Chain); | ||
|
||
const { userOp, msgToSign } = await builder.buildUserOp({ | ||
to: args.to, | ||
value: args.value, | ||
}); | ||
|
||
const credentials: P256Credential = (await new WebAuthn().get(msgToSign)) as P256Credential; | ||
|
||
const signatureUserOp = encodePacked( | ||
["uint8", "uint48", "bytes"], | ||
[ | ||
1, | ||
0, | ||
encodeAbiParameters( | ||
[ | ||
{ | ||
type: "tuple", | ||
name: "credentials", | ||
components: [ | ||
{ | ||
name: "authenticatorData", | ||
type: "bytes", | ||
}, | ||
{ | ||
name: "clientDataJSON", | ||
type: "string", | ||
}, | ||
{ | ||
name: "challengeLocation", | ||
type: "uint256", | ||
}, | ||
{ | ||
name: "responseTypeLocation", | ||
type: "uint256", | ||
}, | ||
{ | ||
name: "r", | ||
type: "bytes32", | ||
}, | ||
{ | ||
name: "s", | ||
type: "bytes32", | ||
}, | ||
], | ||
}, | ||
], | ||
[ | ||
{ | ||
authenticatorData: credentials.authenticatorData, | ||
clientDataJSON: JSON.stringify(credentials.clientData), | ||
challengeLocation: BigInt(23), | ||
responseTypeLocation: BigInt(1), | ||
r: credentials.signature.r, | ||
s: credentials.signature.s, | ||
}, | ||
], | ||
), | ||
], | ||
); | ||
|
||
const userOpAsParams = builder.toParams({ ...userOp, signature: signatureUserOp }); | ||
|
||
return await client.request({ | ||
method: "eth_sendUserOperation" as any, | ||
params: [userOpAsParams, builder.entryPoint], | ||
}); | ||
} | ||
|
||
/* */ | ||
export type EstimateUserOperationGasReturnType = bigint; | ||
|
||
export async function estimateUserOperationGas( | ||
client: Client, | ||
args: any, | ||
): Promise<EstimateUserOperationGasReturnType> { | ||
return await client.request({ | ||
method: "eth_estimateUserOperationGas" as any, | ||
params: args, | ||
}); | ||
} | ||
|
||
/* */ | ||
export type GetUserOperationReceiptReturnType = Hash; | ||
|
||
export async function getUserOperationReceipt(client: Client, args: any): Promise<any> { | ||
return await client.request({ | ||
method: "eth_getUserOperationReceipt" as any, | ||
params: args, | ||
}); | ||
} | ||
|
||
/* */ | ||
export type GetIsValidSignatureReturnType = boolean; | ||
|
||
export async function getIsValidSignature( | ||
client: Client, | ||
args: any, | ||
): Promise<GetIsValidSignatureReturnType> { | ||
return await client.request({ | ||
method: "eth_call" as any, | ||
params: args, | ||
}); | ||
} | ||
export * from "./getUserOperationReceipt"; | ||
export * from "./sendUserOperation"; | ||
export * from "./estimateUserOperationGas"; | ||
export * from "./getIsValidSignature"; | ||
export * from "./waitForUserOperationReceipt"; |
27 changes: 27 additions & 0 deletions
27
front/src/libs/smart-wallet/service/actions/sendUserOperation.ts
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { SmartWalletClient } from "@/libs/smart-wallet/service/smart-wallet"; | ||
import { UserOpBuilder } from "@/libs/smart-wallet/service/userOps"; | ||
import { Hash, Hex, Chain, EstimateFeesPerGasReturnType } from "viem"; | ||
|
||
/* */ | ||
export type SendUserOperationReturnType = Hash; | ||
|
||
export async function sendUserOperation( | ||
client: SmartWalletClient, | ||
args: { to: Hex; value: bigint }, | ||
): Promise<SendUserOperationReturnType> { | ||
const builder = new UserOpBuilder(client.chain as Chain); | ||
|
||
const gasPrice: EstimateFeesPerGasReturnType = await client.estimateFeesPerGas(); | ||
|
||
const userOp = await builder.buildUserOp({ | ||
to: args.to, | ||
value: args.value, | ||
maxFeePerGas: gasPrice.maxFeePerGas as bigint, | ||
maxPriorityFeePerGas: gasPrice.maxPriorityFeePerGas as bigint, | ||
}); | ||
|
||
return await client.request({ | ||
method: "eth_sendUserOperation" as any, | ||
params: [builder.toParams(userOp), builder.entryPoint], | ||
}); | ||
} |
Oops, something went wrong.