Skip to content

Commit

Permalink
update bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cherry-yl-sh committed Jun 25, 2024
1 parent 856e2c6 commit 01c189e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 27 deletions.
20 changes: 10 additions & 10 deletions common/model/api_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ type TryPayUserOpResponse struct {
UserOpResponse *UserOpResponse `json:"userOpResponse"`
}
type UserOpResponse struct {
PayMasterAndData string `json:"paymasterAndData"`
PreVerificationGas *big.Int `json:"preVerificationGas"`
VerificationGasLimit *big.Int `json:"verificationGasLimit"`
CallGasLimit *big.Int `json:"callGasLimit"`
MaxFeePerGas *big.Int `json:"maxFeePerGas"`
MaxPriorityFeePerGas *big.Int `json:"maxPriorityFeePerGas"`
PayMasterAndData string `json:"paymasterAndData"`
PreVerificationGas string `json:"preVerificationGas"`
VerificationGasLimit string `json:"verificationGasLimit"`
CallGasLimit string `json:"callGasLimit"`
MaxFeePerGas string `json:"maxFeePerGas"`
MaxPriorityFeePerGas string `json:"maxPriorityFeePerGas"`
//v0.7
AccountGasLimit string `json:"accountGasLimit" binding:"required"`
PaymasterVerificationGasLimit *big.Int `json:"paymasterVerificationGasLimit" binding:"required"`
PaymasterPostOpGasLimit *big.Int `json:"paymasterPostOpGasLimit" binding:"required"`
GasFees string `json:"gasFees" binding:"required"`
AccountGasLimit string `json:"accountGasLimit" binding:"required"`
PaymasterVerificationGasLimit string `json:"paymasterVerificationGasLimit" binding:"required"`
PaymasterPostOpGasLimit string `json:"paymasterPostOpGasLimit" binding:"required"`
GasFees string `json:"gasFees" binding:"required"`
}

type ComputeGasResponse struct {
Expand Down
9 changes: 9 additions & 0 deletions common/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ func PackIntTo32Bytes(left *big.Int, right *big.Int) [32]byte {

return result
}
func ConvertHexToBigInt(hex string) *big.Int {
bigInt := new(big.Int)
bigInt.SetString(hex, 0)
return bigInt

}
func GetGasEntryPointGasPrice(maxFeePerGas *big.Int, maxPriorityFeePerGas *big.Int, baseFee *big.Int) *big.Int {
if maxFeePerGas == maxPriorityFeePerGas {
// is 1559 not support
Expand All @@ -110,6 +115,10 @@ func EncodeToHexStringWithPrefix(data []byte) string {
}
return res
}
func ConvertBigIntToHexWithPrefix(data *big.Int) string {
res := fmt.Sprintf("0x%x", data)
return res
}

func DecodeStringWithPrefix(data string) ([]byte, error) {
if data[:2] == "0x" {
Expand Down
12 changes: 12 additions & 0 deletions common/utils/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ func TestPackIntTo32Bytes(t *testing.T) {
resStr := EncodeToHexStringWithPrefix(bytes[:])
t.Logf("resStr: %s\n", resStr)
}
func TestConvertBigIntToHexWithPrefix(t *testing.T) {
bigInt := big.NewInt(1500000000)
resStr := ConvertBigIntToHexWithPrefix(bigInt)
t.Logf("resStr: %s\n", resStr)
}
func TestConvertHexToBigInt(t *testing.T) {
hexStr := "0x5a0c"
bigInt := ConvertHexToBigInt(hexStr)

t.Logf("bigInt: %d\n", bigInt)

}

//func TestEthereumSign(t *testing.T) {
// messageStr := "hello world"
Expand Down
22 changes: 12 additions & 10 deletions service/operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,9 @@ func TestOperator(t *testing.T) {
"Test_NoSpectCode_TryPayUserOpExecute",
func(t *testing.T) {
request := model.UserOpRequest{
StrategyCode: "8bced19b-505e-4d11-ae80-abbee3d3a38c",
Network: global_const.EthereumSepolia,
UserOp: *utils.GenerateMockUservOperation(),
UserPayErc20Token: global_const.TokenTypeUSDT,
StrategyCode: "123__GhhSA",
Network: global_const.EthereumSepolia,
UserOp: *utils.GenerateMockUservOperation(),
}
testTryPayUserOpExecute(t, &request)
},
Expand Down Expand Up @@ -178,7 +177,10 @@ func testGetSupportEntrypointExecute(t *testing.T) {
}
func testTryPayUserOpExecute(t *testing.T, request *model.UserOpRequest) {
result, err := TryPayUserOpExecute(&model.ApiKeyModel{
UserId: 5,
UserId: 5,
ProjectSponsorPaymasterEnable: true,
UserPayPaymasterEnable: true,
Erc20PaymasterEnable: true,
}, request)
if err != nil {
t.Fatal(err)
Expand All @@ -204,11 +206,11 @@ func testTryPayUserOpExecute(t *testing.T, request *model.UserOpRequest) {
if result.EntrypointVersion == global_const.EntrypointV07 {
//TODO
} else {
userOp.VerificationGasLimit = result.UserOpResponse.VerificationGasLimit
userOp.PreVerificationGas = result.UserOpResponse.PreVerificationGas
userOp.MaxFeePerGas = result.UserOpResponse.MaxFeePerGas
userOp.MaxPriorityFeePerGas = result.UserOpResponse.MaxPriorityFeePerGas
userOp.CallGasLimit = result.UserOpResponse.CallGasLimit
userOp.VerificationGasLimit = utils.ConvertHexToBigInt(result.UserOpResponse.VerificationGasLimit)
userOp.PreVerificationGas = utils.ConvertHexToBigInt(result.UserOpResponse.PreVerificationGas)
userOp.MaxFeePerGas = utils.ConvertHexToBigInt(result.UserOpResponse.MaxFeePerGas)
userOp.MaxPriorityFeePerGas = utils.ConvertHexToBigInt(result.UserOpResponse.MaxPriorityFeePerGas)
userOp.CallGasLimit = utils.ConvertHexToBigInt(result.UserOpResponse.CallGasLimit)
address := common.HexToAddress(result.EntryPointAddress)
jsonUserOP, err := json.Marshal(userOp)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions service/operator/try_pay_user_op_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,19 @@ func postExecute(apiKeyModel *model.ApiKeyModel, userOp *user_op.UserOpInput, st

UserOpResponse: &model.UserOpResponse{
PayMasterAndData: utils.EncodeToHexStringWithPrefix(paymasterData),
PreVerificationGas: gasResponse.OpEstimateGas.PreVerificationGas,
MaxFeePerGas: gasResponse.OpEstimateGas.MaxFeePerGas,
MaxPriorityFeePerGas: gasResponse.OpEstimateGas.MaxPriorityFeePerGas,
VerificationGasLimit: gasResponse.OpEstimateGas.VerificationGasLimit,
CallGasLimit: gasResponse.OpEstimateGas.CallGasLimit,
PreVerificationGas: utils.ConvertBigIntToHexWithPrefix(gasResponse.OpEstimateGas.PreVerificationGas),
MaxFeePerGas: utils.ConvertBigIntToHexWithPrefix(gasResponse.OpEstimateGas.MaxFeePerGas),
MaxPriorityFeePerGas: utils.ConvertBigIntToHexWithPrefix(gasResponse.OpEstimateGas.MaxPriorityFeePerGas),
VerificationGasLimit: utils.ConvertBigIntToHexWithPrefix(gasResponse.OpEstimateGas.VerificationGasLimit),
CallGasLimit: utils.ConvertBigIntToHexWithPrefix(gasResponse.OpEstimateGas.CallGasLimit),
},
}

if strategy.GetStrategyEntrypointVersion() == global_const.EntrypointV07 {
result.UserOpResponse.AccountGasLimit = utils.EncodeToHexStringWithPrefix(gasResponse.OpEstimateGas.AccountGasLimit[:])
result.UserOpResponse.GasFees = utils.EncodeToHexStringWithPrefix(gasResponse.OpEstimateGas.GasFees[:])
result.UserOpResponse.PaymasterVerificationGasLimit = gasResponse.OpEstimateGas.PaymasterVerificationGasLimit
result.UserOpResponse.PaymasterPostOpGasLimit = gasResponse.OpEstimateGas.PaymasterPostOpGasLimit
result.UserOpResponse.PaymasterVerificationGasLimit = utils.ConvertBigIntToHexWithPrefix(gasResponse.OpEstimateGas.PaymasterVerificationGasLimit)
result.UserOpResponse.PaymasterPostOpGasLimit = utils.ConvertBigIntToHexWithPrefix(gasResponse.OpEstimateGas.PaymasterPostOpGasLimit)
}

return result, nil
Expand Down

0 comments on commit 01c189e

Please sign in to comment.