diff --git a/common/model/api_response.go b/common/model/api_response.go index 2fd4dff..a618c99 100644 --- a/common/model/api_response.go +++ b/common/model/api_response.go @@ -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 { diff --git a/common/utils/util.go b/common/utils/util.go index 58418ee..3a173c6 100644 --- a/common/utils/util.go +++ b/common/utils/util.go @@ -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 @@ -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" { diff --git a/common/utils/util_test.go b/common/utils/util_test.go index cb9d0f4..3c3fa7f 100644 --- a/common/utils/util_test.go +++ b/common/utils/util_test.go @@ -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" diff --git a/service/operator/operator_test.go b/service/operator/operator_test.go index f71d2d0..7a72ee1 100644 --- a/service/operator/operator_test.go +++ b/service/operator/operator_test.go @@ -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) }, @@ -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) @@ -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 { diff --git a/service/operator/try_pay_user_op_execute.go b/service/operator/try_pay_user_op_execute.go index 252d1f3..8b38717 100644 --- a/service/operator/try_pay_user_op_execute.go +++ b/service/operator/try_pay_user_op_execute.go @@ -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