-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
1b6e992
commit 7a91bbb
Showing
18 changed files
with
1,313 additions
and
98 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 |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package rpccalls | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/san-lab/go4337/userop" | ||
) | ||
|
||
// providers | ||
const AlchemyProvider = "alchemy" | ||
const StackUpProvider = "stackup" | ||
const PimlicoProvider = "pimlico" | ||
const BiconomyProvider = "biconomy" | ||
|
||
func Eth_sendUserOperation(url, key string, usop *userop.UserOperation, entrypoint string, entrypointVersion int, provider string) (*string, error) { | ||
var usopdata interface{} | ||
switch entrypointVersion { | ||
case 6: | ||
usopdata = usop.ToUserOpForApiV6() | ||
case 7: | ||
usopdata = usop.ToUserOpForApiV6() | ||
default: | ||
return nil, fmt.Errorf("Unsupported entrypoint version: %d", entrypointVersion) | ||
} | ||
|
||
ar := &APIRequest{ | ||
ID: 1, | ||
Jsonrpc: "2.0", | ||
Method: "eth_sendUserOperation", | ||
Params: []interface{}{usopdata, entrypoint}, | ||
} | ||
result := new(string) | ||
_, err := ApiCall(url, key, ar, result) | ||
if err != nil { | ||
return nil, fmt.Errorf("API Call error: %w", err) | ||
} | ||
return result, nil | ||
|
||
} | ||
|
||
func Eth_estimateUserOperationGas(url, key string, usop *userop.UserOperation, entrypoint string, entrypointVersion int, provider string) (*EthEstimateUserOperationGasResult, error) { | ||
var usopdata interface{} | ||
switch entrypointVersion { | ||
case 6: | ||
usopdata = usop.ToUserOpForApiV6() | ||
case 7: | ||
usopdata = usop.ToUserOpForApiV6() | ||
default: | ||
return nil, fmt.Errorf("Unsupported entrypoint version: %d", entrypointVersion) | ||
} | ||
|
||
ar := &APIRequest{ | ||
ID: 1, | ||
Jsonrpc: "2.0", | ||
Method: "eth_estimateUserOperationGas", | ||
Params: []interface{}{usopdata, entrypoint}, | ||
} | ||
var result interface{} | ||
var finalResult = &EthEstimateUserOperationGasResult{} | ||
switch provider { | ||
case AlchemyProvider, PimlicoProvider: | ||
result = &AlchemyEstimateGasCostResponse{} | ||
default: | ||
result = finalResult | ||
} | ||
_, err := ApiCall(url, key, ar, result) | ||
if err != nil { | ||
return nil, fmt.Errorf("API Call error: %w", err) | ||
} | ||
|
||
//Transcode | ||
switch provider { | ||
case AlchemyProvider, PimlicoProvider: | ||
finalResult.CallGasLimit, _ = strconv.ParseUint(result.(*AlchemyEstimateGasCostResponse).CallGasLimit[2:], 16, 64) | ||
finalResult.VerificationGasLimit, _ = strconv.ParseUint(result.(*AlchemyEstimateGasCostResponse).VerificationGasLimit[2:], 16, 64) | ||
finalResult.PreVerificationGas, _ = strconv.ParseUint(result.(*AlchemyEstimateGasCostResponse).PreVerificationGas[2:], 16, 64) | ||
default: | ||
finalResult = result.(*EthEstimateUserOperationGasResult) | ||
} | ||
|
||
return finalResult, nil | ||
|
||
} | ||
|
||
type EthEstimateUserOperationGasResult struct { | ||
CallGasLimit uint64 `json:"callGasLimit"` | ||
VerificationGasLimit uint64 `json:"verificationGasLimit"` | ||
PreVerificationGas uint64 `json:"preVerificationGas"` | ||
ValidUntil string `json:"validUntil"` | ||
ValidAfter string `json:"validAfter"` | ||
MaxPriorityFeePerGas string `json:"maxPriorityFeePerGas"` | ||
MaxFeePerGas string `json:"maxFeePerGas"` | ||
} | ||
|
||
type AlchemyEstimateGasCostResponse struct { | ||
PreVerificationGas string `json:"preVerificationGas"` | ||
CallGasLimit string `json:"callGasLimit"` | ||
VerificationGasLimit string `json:"verificationGasLimit"` | ||
} | ||
|
||
func Eth_getUserOperationByHash(url, key string, hash string, provider string) ([]byte, error) { | ||
ar := &APIRequest{ | ||
ID: 1, | ||
Jsonrpc: "2.0", | ||
Method: "eth_getUserOperationByHash", | ||
Params: []interface{}{hash}, | ||
} | ||
bt, err := ApiCall(url, key, ar, nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("API Call error: %w", err) | ||
} | ||
return bt, nil | ||
|
||
} | ||
|
||
func Eth_getUserOperationReceipt(url, key string, hash string, provider string) ([]byte, error) { | ||
//fmt.Println("eth_getUserOperationReceipt not implemented") | ||
ar := &APIRequest{ | ||
ID: 1, | ||
Jsonrpc: "2.0", | ||
Method: "eth_getUserOperationReceipt", | ||
Params: []interface{}{hash}, | ||
} | ||
|
||
return ApiCall(url, key, ar, nil) | ||
|
||
} | ||
|
||
func Eth_supportedEntryPoints(url, key string) (*[]string, error) { | ||
ar := &APIRequest{ | ||
ID: 1, | ||
Jsonrpc: "2.0", | ||
Method: "eth_supportedEntryPoints", | ||
Params: []interface{}{}, | ||
} | ||
result := &[]string{} | ||
_, err := ApiCall(url, key, ar, result) | ||
if err != nil { | ||
return nil, fmt.Errorf("API Call error: %w", err) | ||
} | ||
return result, nil | ||
|
||
} |
Oops, something went wrong.