diff --git a/common/model/api_request.go b/common/model/api_request.go new file mode 100644 index 00000000..51ea0f26 --- /dev/null +++ b/common/model/api_request.go @@ -0,0 +1,35 @@ +package model + +import "errors" + +type TryPayUserOpRequest struct { + ForceStrategyId string `json:"force_strategy_id"` + ForceNetWork string `json:"force_network"` + ForceTokens string `json:"force_tokens"` + ForceEntryPointAddress string `json:"force_entrypoint_address"` + UserOperation UserOperationItem `json:"user_operation"` + Extra interface{} `json:"extra"` +} + +func (request *TryPayUserOpRequest) Validate() error { + if len(request.ForceStrategyId) == 0 { + if len(request.ForceNetWork) == 0 || len(request.ForceTokens) == 0 || len(request.ForceEntryPointAddress) == 0 { + return errors.New("strategy configuration illegal") + } + } + return nil +} + +type GetSupportEntrypointRequest struct { +} + +func (request *GetSupportEntrypointRequest) Validate() error { + return nil +} + +type GetSupportStrategyRequest struct { +} + +func (request *GetSupportStrategyRequest) Validate() error { + return nil +} diff --git a/common/model/api_response.go b/common/model/api_response.go new file mode 100644 index 00000000..6272ba12 --- /dev/null +++ b/common/model/api_response.go @@ -0,0 +1,18 @@ +package model + +type TryPayUserOpResponse struct { + StrategyId string `json:"strategy_id"` + EntryPointAddress string `json:"entrypoint_address"` + PayMasterAddress string `json:"paymaster_address"` + PayMasterSignature string `json:"paymaster_signature"` + PayReceipt interface{} `json:"pay_receipt"` + GasInfo *ComputeGasResponse `json:"gas_info"` +} + +type ComputeGasResponse struct { + StrategyId string `json:"strategy_id"` + TokenCost string `json:"token_cost"` + Network string `json:"network"` + Token string `json:"token"` + UsdCost string `json:"usd_cost"` +} diff --git a/common/model/chain.go b/common/model/chain.go new file mode 100644 index 00000000..8b537907 --- /dev/null +++ b/common/model/chain.go @@ -0,0 +1 @@ +package model diff --git a/rpc_server/models/client_credential.go b/common/model/client_credential.go similarity index 81% rename from rpc_server/models/client_credential.go rename to common/model/client_credential.go index 1a048c34..b38ab8ff 100644 --- a/rpc_server/models/client_credential.go +++ b/common/model/client_credential.go @@ -1,4 +1,4 @@ -package models +package model type ClientCredential struct { ApiKey string `json:"apiKey"` diff --git a/rpc_server/models/response.go b/common/model/response.go similarity index 98% rename from rpc_server/models/response.go rename to common/model/response.go index eabb3845..c335b834 100644 --- a/rpc_server/models/response.go +++ b/common/model/response.go @@ -1,4 +1,4 @@ -package models +package model import ( "github.com/gin-gonic/gin" @@ -10,7 +10,7 @@ func GetResponse() *Response { return &Response{ httpCode: http.StatusOK, Result: &Result{ - Code: 0, + Code: 200, Message: "", Data: nil, Cost: "", diff --git a/common/model/strategy.go b/common/model/strategy.go new file mode 100644 index 00000000..e23e5988 --- /dev/null +++ b/common/model/strategy.go @@ -0,0 +1,7 @@ +package model + +type Strategy struct { + Id string + EntryPointAddress string + PayMasterAddress string +} diff --git a/common/model/user_operation.go b/common/model/user_operation.go new file mode 100644 index 00000000..d7e2c9c1 --- /dev/null +++ b/common/model/user_operation.go @@ -0,0 +1,14 @@ +package model + +type UserOperationItem struct { + Sender string `json:"sender" binding:"required"` + Nonce string `json:"nonce" binding:"required"` + InitCode string `json:"init_code"` + CallGasLimit string `json:"call_gas_limit" binding:"required"` + VerificationGasList string `json:"verification_gas_list" binding:"required"` + PerVerificationGas string `json:"per_verification_gas" binding:"required"` + MaxFeePerGas string `json:"max_fee_per_gas" binding:"required"` + MaxPriorityFeePerGas string `json:"max_priority_fee_per_gas" binding:"required"` + Signature string `json:"signature"` + //paymasterAndData string `json:"paymaster_and_data"` +} diff --git a/common/types/strategy.go b/common/types/strategy.go deleted file mode 100644 index d0cc8bc2..00000000 --- a/common/types/strategy.go +++ /dev/null @@ -1,4 +0,0 @@ -package types - -type Strategy struct { -} diff --git a/conf/appsettings.yaml b/conf/appsettings.yaml index 65f51631..e86f54a2 100644 --- a/conf/appsettings.yaml +++ b/conf/appsettings.yaml @@ -1,4 +1,4 @@ jwt: - security: hello-eth-paymaster + security: hello-ethereum-paymaster realm: aastar idkey: id diff --git a/docs/docs.go b/docs/docs.go index 545cc0cb..a6959e2d 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -34,7 +34,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/models.ClientCredential" + "$ref": "#/definitions/model.ClientCredential" } } ], @@ -48,6 +48,9 @@ const docTemplate = `{ "/api/healthz": { "get": { "description": "Get Healthz", + "consumes": [ + "application/json" + ], "tags": [ "Healthz" ], @@ -117,6 +120,17 @@ const docTemplate = `{ "tags": [ "Sponsor" ], + "parameters": [ + { + "description": "UserOp Request", + "name": "tryPay", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.TryPayUserOpRequest" + } + } + ], "responses": { "200": { "description": "OK" @@ -126,13 +140,75 @@ const docTemplate = `{ } }, "definitions": { - "models.ClientCredential": { + "model.ClientCredential": { "type": "object", "properties": { "apiKey": { "type": "string" } } + }, + "model.TryPayUserOpRequest": { + "type": "object", + "properties": { + "extra": {}, + "force_entrypoint_address": { + "type": "string" + }, + "force_network": { + "type": "string" + }, + "force_strategy_id": { + "type": "string" + }, + "force_tokens": { + "type": "string" + }, + "user_operation": { + "$ref": "#/definitions/model.UserOperationItem" + } + } + }, + "model.UserOperationItem": { + "type": "object", + "required": [ + "call_gas_limit", + "max_fee_per_gas", + "max_priority_fee_per_gas", + "nonce", + "per_verification_gas", + "sender", + "verification_gas_list" + ], + "properties": { + "call_gas_limit": { + "type": "string" + }, + "init_code": { + "type": "string" + }, + "max_fee_per_gas": { + "type": "string" + }, + "max_priority_fee_per_gas": { + "type": "string" + }, + "nonce": { + "type": "string" + }, + "per_verification_gas": { + "type": "string" + }, + "sender": { + "type": "string" + }, + "signature": { + "type": "string" + }, + "verification_gas_list": { + "type": "string" + } + } } }, "securityDefinitions": { diff --git a/docs/swagger.json b/docs/swagger.json index fb2d35ee..f5b5ef35 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -23,7 +23,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/models.ClientCredential" + "$ref": "#/definitions/model.ClientCredential" } } ], @@ -37,6 +37,9 @@ "/api/healthz": { "get": { "description": "Get Healthz", + "consumes": [ + "application/json" + ], "tags": [ "Healthz" ], @@ -106,6 +109,17 @@ "tags": [ "Sponsor" ], + "parameters": [ + { + "description": "UserOp Request", + "name": "tryPay", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.TryPayUserOpRequest" + } + } + ], "responses": { "200": { "description": "OK" @@ -115,13 +129,75 @@ } }, "definitions": { - "models.ClientCredential": { + "model.ClientCredential": { "type": "object", "properties": { "apiKey": { "type": "string" } } + }, + "model.TryPayUserOpRequest": { + "type": "object", + "properties": { + "extra": {}, + "force_entrypoint_address": { + "type": "string" + }, + "force_network": { + "type": "string" + }, + "force_strategy_id": { + "type": "string" + }, + "force_tokens": { + "type": "string" + }, + "user_operation": { + "$ref": "#/definitions/model.UserOperationItem" + } + } + }, + "model.UserOperationItem": { + "type": "object", + "required": [ + "call_gas_limit", + "max_fee_per_gas", + "max_priority_fee_per_gas", + "nonce", + "per_verification_gas", + "sender", + "verification_gas_list" + ], + "properties": { + "call_gas_limit": { + "type": "string" + }, + "init_code": { + "type": "string" + }, + "max_fee_per_gas": { + "type": "string" + }, + "max_priority_fee_per_gas": { + "type": "string" + }, + "nonce": { + "type": "string" + }, + "per_verification_gas": { + "type": "string" + }, + "sender": { + "type": "string" + }, + "signature": { + "type": "string" + }, + "verification_gas_list": { + "type": "string" + } + } } }, "securityDefinitions": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 783b7916..8852545d 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,9 +1,52 @@ definitions: - models.ClientCredential: + model.ClientCredential: properties: apiKey: type: string type: object + model.TryPayUserOpRequest: + properties: + extra: {} + force_entrypoint_address: + type: string + force_network: + type: string + force_strategy_id: + type: string + force_tokens: + type: string + user_operation: + $ref: '#/definitions/model.UserOperationItem' + type: object + model.UserOperationItem: + properties: + call_gas_limit: + type: string + init_code: + type: string + max_fee_per_gas: + type: string + max_priority_fee_per_gas: + type: string + nonce: + type: string + per_verification_gas: + type: string + sender: + type: string + signature: + type: string + verification_gas_list: + type: string + required: + - call_gas_limit + - max_fee_per_gas + - max_priority_fee_per_gas + - nonce + - per_verification_gas + - sender + - verification_gas_list + type: object info: contact: name: AAStar Support @@ -20,7 +63,7 @@ paths: name: credential required: true schema: - $ref: '#/definitions/models.ClientCredential' + $ref: '#/definitions/model.ClientCredential' responses: "200": description: OK @@ -28,6 +71,8 @@ paths: - Auth /api/healthz: get: + consumes: + - application/json description: Get Healthz responses: "200": @@ -65,6 +110,13 @@ paths: consumes: - application/json description: sponsor the userOp + parameters: + - description: UserOp Request + in: body + name: tryPay + required: true + schema: + $ref: '#/definitions/model.TryPayUserOpRequest' responses: "200": description: OK diff --git a/go.mod b/go.mod index 2048c10f..410bb62c 100644 --- a/go.mod +++ b/go.mod @@ -49,6 +49,7 @@ require ( golang.org/x/sys v0.17.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.18.0 // indirect + golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect google.golang.org/protobuf v1.32.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index eae4b29c..106a0867 100644 --- a/go.sum +++ b/go.sum @@ -151,6 +151,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= +golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/rpc_server/api/auth.go b/rpc_server/api/auth.go index 21e39341..cad8302f 100644 --- a/rpc_server/api/auth.go +++ b/rpc_server/api/auth.go @@ -10,7 +10,7 @@ import ( // @Description Get AccessToken By ApiKey // @Accept json // @Product json -// @Param credential body models.ClientCredential true "AccessToken Model" +// @Param credential body model.ClientCredential true "AccessToken Model" // @Router /api/auth [post] // @Success 200 func Auth(ctx *gin.Context) { diff --git a/rpc_server/api/health.go b/rpc_server/api/health.go index c29c7ede..f7be562c 100644 --- a/rpc_server/api/health.go +++ b/rpc_server/api/health.go @@ -1,8 +1,8 @@ package api import ( + "AAStarCommunity/EthPaymaster_BackService/common/model" "AAStarCommunity/EthPaymaster_BackService/conf" - "AAStarCommunity/EthPaymaster_BackService/rpc_server/models" "github.com/gin-gonic/gin" "time" ) @@ -10,10 +10,12 @@ import ( // Healthz // @Tags Healthz // @Description Get Healthz +// @Accept json +// @Product json // @Router /api/healthz [get] // @Success 200 func Healthz(c *gin.Context) { - response := models.GetResponse() + response := model.GetResponse() response.WithDataSuccess(c, gin.H{ "hello": "Eth Paymaster", "environment": conf.Environment.Name, diff --git a/rpc_server/api/v1/get_support_entrypoint.go b/rpc_server/api/v1/get_support_entrypoint.go index 07304541..d3e0a0b8 100644 --- a/rpc_server/api/v1/get_support_entrypoint.go +++ b/rpc_server/api/v1/get_support_entrypoint.go @@ -1,9 +1,8 @@ package v1 import ( - "AAStarCommunity/EthPaymaster_BackService/rpc_server/api/utils" - "AAStarCommunity/EthPaymaster_BackService/rpc_server/models" - "AAStarCommunity/EthPaymaster_BackService/service" + "AAStarCommunity/EthPaymaster_BackService/common/model" + "AAStarCommunity/EthPaymaster_BackService/service/operator" "fmt" "github.com/gin-gonic/gin" "net/http" @@ -18,19 +17,26 @@ import ( // @Success 200 // @Security JWT func GetSupportEntrypoint(c *gin.Context) { - response := models.GetResponse() - if ok, apiKey := utils.CurrentUser(c); ok { - _ = apiKey + request := model.GetSupportEntrypointRequest{} + response := model.GetResponse() + //1. API validate + if err := c.ShouldBindJSON(&request); err != nil { + errStr := fmt.Sprintf("Request Error [%v]", err) + response.SetHttpCode(http.StatusBadRequest).FailCode(c, http.StatusBadRequest, errStr) + return + } + if err := request.Validate(); err != nil { + errStr := fmt.Sprintf("Request Error [%v]", err) + response.SetHttpCode(http.StatusBadRequest).FailCode(c, http.StatusBadRequest, errStr) + return + } - //1.TODO API validate - //2. recall service - result, err := service.GetSupportEntrypointExecute() - if err != nil { - errStr := fmt.Sprintf("%v", err) - response.SetHttpCode(http.StatusInternalServerError).FailCode(c, http.StatusInternalServerError, errStr) - } - response.WithData(result).Success(c) - } else { - response.SetHttpCode(http.StatusUnauthorized) + //2. recall service + result, err := operator.GetSupportEntrypointExecute(&request) + if err != nil { + errStr := fmt.Sprintf("%v", err) + response.SetHttpCode(http.StatusInternalServerError).FailCode(c, http.StatusInternalServerError, errStr) + return } + response.WithData(result).Success(c) } diff --git a/rpc_server/api/v1/get_support_strategy.go b/rpc_server/api/v1/get_support_strategy.go index 6143c786..76ce005a 100644 --- a/rpc_server/api/v1/get_support_strategy.go +++ b/rpc_server/api/v1/get_support_strategy.go @@ -1,8 +1,8 @@ package v1 import ( - "AAStarCommunity/EthPaymaster_BackService/rpc_server/models" - "AAStarCommunity/EthPaymaster_BackService/service" + "AAStarCommunity/EthPaymaster_BackService/common/model" + "AAStarCommunity/EthPaymaster_BackService/service/operator" "fmt" "github.com/gin-gonic/gin" "net/http" @@ -17,13 +17,27 @@ import ( // @Router /api/v1/get-support-strategy [GET] // @Security JWT func GetSupportStrategy(c *gin.Context) { - //1.TODO API validate - //2. recall service - result, err := service.GetSupportStrategyExecute() - response := models.GetResponse() - if err != nil { + request := model.GetSupportStrategyRequest{} + response := model.GetResponse() + + //1. API validate + if err := c.ShouldBindJSON(&request); err != nil { + errStr := fmt.Sprintf("Request Error [%v]", err) + response.SetHttpCode(http.StatusBadRequest).FailCode(c, http.StatusBadRequest, errStr) + return + } + if err := request.Validate(); err != nil { + errStr := fmt.Sprintf("Request Error [%v]", err) + response.SetHttpCode(http.StatusBadRequest).FailCode(c, http.StatusBadRequest, errStr) + return + } + + if result, err := operator.GetSupportStrategyExecute(&request); err != nil { errStr := fmt.Sprintf("%v", err) response.SetHttpCode(http.StatusInternalServerError).FailCode(c, http.StatusInternalServerError, errStr) + return + } else { + response.WithData(result).Success(c) + return } - response.WithData(result).Success(c) } diff --git a/rpc_server/api/v1/try_pay_user_operation.go b/rpc_server/api/v1/try_pay_user_operation.go index cc6caad9..b9ce5e1a 100644 --- a/rpc_server/api/v1/try_pay_user_operation.go +++ b/rpc_server/api/v1/try_pay_user_operation.go @@ -1,8 +1,8 @@ package v1 import ( - "AAStarCommunity/EthPaymaster_BackService/rpc_server/models" - "AAStarCommunity/EthPaymaster_BackService/service" + "AAStarCommunity/EthPaymaster_BackService/common/model" + "AAStarCommunity/EthPaymaster_BackService/service/operator" "fmt" "github.com/gin-gonic/gin" "net/http" @@ -14,16 +14,33 @@ import ( // @Accept json // @Product json // @Router /api/v1/try-pay-user-operation [POST] +// @Param tryPay body model.TryPayUserOpRequest true "UserOp Request" // @Success 200 // @Security JWT func TryPayUserOperation(c *gin.Context) { - //1.TODO API validate + request := model.TryPayUserOpRequest{} + response := model.GetResponse() + + //1. API validate + if err := c.ShouldBindJSON(&request); err != nil { + errStr := fmt.Sprintf("Request Error [%v]", err) + response.SetHttpCode(http.StatusBadRequest).FailCode(c, http.StatusBadRequest, errStr) + return + } + + if err := request.Validate(); err != nil { + errStr := fmt.Sprintf("Request Error [%v]", err) + response.SetHttpCode(http.StatusBadRequest).FailCode(c, http.StatusBadRequest, errStr) + return + } + //2. recall service - result, err := service.TryPayUserOpExecute() - response := models.GetResponse() - if err != nil { - errStr := fmt.Sprintf("%v", err) + if result, err := operator.TryPayUserOpExecute(&request); err != nil { + errStr := fmt.Sprintf("TryPayUserOpExecute ERROR [%v]", err) response.SetHttpCode(http.StatusInternalServerError).FailCode(c, http.StatusInternalServerError, errStr) + return + } else { + response.WithData(result).Success(c) + return } - response.WithData(result).Success(c) } diff --git a/rpc_server/middlewares/recovery.go b/rpc_server/middlewares/recovery.go index 5bb6a889..c6807e03 100644 --- a/rpc_server/middlewares/recovery.go +++ b/rpc_server/middlewares/recovery.go @@ -1,8 +1,8 @@ package middlewares import ( + "AAStarCommunity/EthPaymaster_BackService/common/model" "AAStarCommunity/EthPaymaster_BackService/conf" - "AAStarCommunity/EthPaymaster_BackService/rpc_server/models" "errors" "fmt" "github.com/gin-gonic/gin" @@ -18,7 +18,7 @@ func GenericRecoveryHandler() gin.HandlerFunc { if conf.Environment.Debugger { errStr = fmt.Sprintf("%v", err) } - models.GetResponse().SetHttpCode(http.StatusInternalServerError).FailCode(c, http.StatusInternalServerError, errStr) + model.GetResponse().SetHttpCode(http.StatusInternalServerError).FailCode(c, http.StatusInternalServerError, errStr) }) } diff --git a/rpc_server/models/userOperation.go b/rpc_server/models/userOperation.go deleted file mode 100644 index 2640e7f9..00000000 --- a/rpc_server/models/userOperation.go +++ /dev/null @@ -1 +0,0 @@ -package models diff --git a/rpc_server/routers/boot.go b/rpc_server/routers/boot.go index 94abcdb0..70263d43 100644 --- a/rpc_server/routers/boot.go +++ b/rpc_server/routers/boot.go @@ -1,10 +1,10 @@ package routers import ( + "AAStarCommunity/EthPaymaster_BackService/common/model" "AAStarCommunity/EthPaymaster_BackService/conf" "AAStarCommunity/EthPaymaster_BackService/docs" "AAStarCommunity/EthPaymaster_BackService/rpc_server/middlewares" - "AAStarCommunity/EthPaymaster_BackService/rpc_server/models" "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" @@ -19,7 +19,7 @@ func SetRouters() (routers *gin.Engine) { buildMod(routers) buildRoute(routers) routers.NoRoute(func(ctx *gin.Context) { - models.GetResponse().SetHttpCode(http.StatusNotFound).FailCode(ctx, http.StatusNotFound) + model.GetResponse().SetHttpCode(http.StatusNotFound).FailCode(ctx, http.StatusNotFound) }) return diff --git a/service/contractService/gethRecall.go b/service/contractService/gethRecall.go deleted file mode 100644 index 31437cc7..00000000 --- a/service/contractService/gethRecall.go +++ /dev/null @@ -1 +0,0 @@ -package contractService diff --git a/service/contract_service/geth_recall.go b/service/contract_service/geth_recall.go new file mode 100644 index 00000000..f300daad --- /dev/null +++ b/service/contract_service/geth_recall.go @@ -0,0 +1 @@ +package contract_service diff --git a/service/dashboard_service/dashboard_service.go b/service/dashboard_service/dashboard_service.go new file mode 100644 index 00000000..a8acdeec --- /dev/null +++ b/service/dashboard_service/dashboard_service.go @@ -0,0 +1,16 @@ +package dashboard_service + +import "AAStarCommunity/EthPaymaster_BackService/common/model" + +var mockStrategyMap = map[string]*model.Strategy{} + +func init() { + mockStrategyMap["1"] = &model.Strategy{ + Id: "1", + EntryPointAddress: "0x123", + PayMasterAddress: "0x123", + } +} +func GetStrategyById(strategyId string) *model.Strategy { + return mockStrategyMap[strategyId] +} diff --git a/service/dashboard_service/strategy_selector.go b/service/dashboard_service/strategy_selector.go new file mode 100644 index 00000000..e540d521 --- /dev/null +++ b/service/dashboard_service/strategy_selector.go @@ -0,0 +1,10 @@ +package dashboard_service + +import ( + "AAStarCommunity/EthPaymaster_BackService/common/model" + "errors" +) + +func GetSuitableStrategy(entrypoint string, network string, token string) (*model.Strategy, error) { + return nil, errors.New("not implemented") +} diff --git a/service/gasService/gasWeiGenerator.go b/service/gasService/gasWeiGenerator.go deleted file mode 100644 index 457c50b0..00000000 --- a/service/gasService/gasWeiGenerator.go +++ /dev/null @@ -1 +0,0 @@ -package gasService diff --git a/service/gas_service/gas_compotor.go b/service/gas_service/gas_compotor.go new file mode 100644 index 00000000..d80a4526 --- /dev/null +++ b/service/gas_service/gas_compotor.go @@ -0,0 +1,11 @@ +package gas_service + +import "AAStarCommunity/EthPaymaster_BackService/common/model" + +func ComputeGas(userOp *model.UserOperationItem, strategy *model.Strategy) (*model.ComputeGasResponse, error) { + return &model.ComputeGasResponse{}, nil +} + +func ValidateGas(userOp *model.UserOperationItem, gasComputeResponse *model.ComputeGasResponse) error { + return nil +} diff --git a/service/gas_service/gas_wei_generator.go b/service/gas_service/gas_wei_generator.go new file mode 100644 index 00000000..27fcf074 --- /dev/null +++ b/service/gas_service/gas_wei_generator.go @@ -0,0 +1 @@ +package gas_service diff --git a/service/monitorService/report.go b/service/monitorService/report.go deleted file mode 100644 index 201cc69a..00000000 --- a/service/monitorService/report.go +++ /dev/null @@ -1 +0,0 @@ -package monitorService diff --git a/service/monitor_service/report.go b/service/monitor_service/report.go new file mode 100644 index 00000000..44ddfaa8 --- /dev/null +++ b/service/monitor_service/report.go @@ -0,0 +1 @@ +package monitor_service diff --git a/service/operator/get_support_entry_point_execute.go b/service/operator/get_support_entry_point_execute.go new file mode 100644 index 00000000..b3f5cd9c --- /dev/null +++ b/service/operator/get_support_entry_point_execute.go @@ -0,0 +1,7 @@ +package operator + +import "AAStarCommunity/EthPaymaster_BackService/common/model" + +func GetSupportEntrypointExecute(request *model.GetSupportEntrypointRequest) (*model.Result, error) { + return &model.Result{}, nil +} diff --git a/service/operator/get_support_entry_point_execute_test.go b/service/operator/get_support_entry_point_execute_test.go new file mode 100644 index 00000000..18b97f2b --- /dev/null +++ b/service/operator/get_support_entry_point_execute_test.go @@ -0,0 +1 @@ +package operator diff --git a/service/operator/get_support_strategy_execute.go b/service/operator/get_support_strategy_execute.go new file mode 100644 index 00000000..b0cd18f4 --- /dev/null +++ b/service/operator/get_support_strategy_execute.go @@ -0,0 +1,9 @@ +package operator + +import ( + "AAStarCommunity/EthPaymaster_BackService/common/model" +) + +func GetSupportStrategyExecute(request *model.GetSupportStrategyRequest) (*model.Result, error) { + return &model.Result{}, nil +} diff --git a/service/operator/get_support_strategy_execute_test.go b/service/operator/get_support_strategy_execute_test.go new file mode 100644 index 00000000..18b97f2b --- /dev/null +++ b/service/operator/get_support_strategy_execute_test.go @@ -0,0 +1 @@ +package operator diff --git a/service/operator/try_pay_user_op_execute.go b/service/operator/try_pay_user_op_execute.go new file mode 100644 index 00000000..d2edc05a --- /dev/null +++ b/service/operator/try_pay_user_op_execute.go @@ -0,0 +1,93 @@ +package operator + +import ( + "AAStarCommunity/EthPaymaster_BackService/common/model" + "AAStarCommunity/EthPaymaster_BackService/service/dashboard_service" + "AAStarCommunity/EthPaymaster_BackService/service/gas_service" + "AAStarCommunity/EthPaymaster_BackService/service/validator_service" + "golang.org/x/xerrors" +) + +func TryPayUserOpExecute(request *model.TryPayUserOpRequest) (*model.Result, error) { + // validator + if err := businessParamValidate(request); err != nil { + return nil, err + } + userOp := request.UserOperation + + // getStrategy + var strategy *model.Strategy + if stg, err := strategyGenerate(request); err != nil { + return nil, err + } else if err = validator_service.ValidateStrategy(stg, &userOp); err != nil { + return nil, err + } else { + strategy = stg + } + + //base Strategy and UserOp computeGas + gasResponse, gasComputeError := gas_service.ComputeGas(&userOp, strategy) + if gasComputeError != nil { + return nil, gasComputeError + } + + //validate gas + if err := gas_service.ValidateGas(&userOp, gasResponse); err != nil { + return nil, err + } + //pay + payReceipt, payError := executePay(strategy, &userOp, gasResponse) + if payError != nil { + return nil, payError + } + paymasterSignature := getPayMasterSignature(strategy, &userOp) + var result = model.TryPayUserOpResponse{ + StrategyId: strategy.Id, + EntryPointAddress: strategy.EntryPointAddress, + PayMasterAddress: strategy.EntryPointAddress, + PayReceipt: payReceipt, + PayMasterSignature: paymasterSignature, + GasInfo: gasResponse, + } + + return &model.Result{ + Code: 200, + Data: result, + Message: "message", + Cost: "cost", + }, nil +} +func businessParamValidate(request *model.TryPayUserOpRequest) error { + //UserOp Validate + return nil +} + +func executePay(strategy *model.Strategy, userOp *model.UserOperationItem, gasResponse *model.ComputeGasResponse) (interface{}, error) { + //1.Recharge + //2.record account + //3.return Receipt + return nil, nil +} +func getPayMasterSignature(strategy *model.Strategy, userOp *model.UserOperationItem) string { + return "" +} + +func strategyGenerate(request *model.TryPayUserOpRequest) (*model.Strategy, error) { + if forceStrategyId := request.ForceStrategyId; forceStrategyId != "" { + //force strategy + if strategy := dashboard_service.GetStrategyById(forceStrategyId); strategy == nil { + return nil, xerrors.Errorf("Not Support Strategy ID: [%w]", forceStrategyId) + } else { + return strategy, nil + } + } + + suitableStrategy, err := dashboard_service.GetSuitableStrategy(request.ForceEntryPointAddress, request.ForceNetWork, request.ForceTokens) //TODO + if err != nil { + return nil, err + } + if suitableStrategy == nil { + return nil, xerrors.Errorf("Empty Strategies") + } + return suitableStrategy, nil +} diff --git a/service/operator/try_pay_user_op_execute_test.go b/service/operator/try_pay_user_op_execute_test.go new file mode 100644 index 00000000..937bcf85 --- /dev/null +++ b/service/operator/try_pay_user_op_execute_test.go @@ -0,0 +1,31 @@ +package operator + +import ( + "AAStarCommunity/EthPaymaster_BackService/common/model" + "fmt" + "github.com/stretchr/testify/assert" + + "testing" +) + +func TestTryPayUserOpExecute(t *testing.T) { + request := getMockTryPayUserOpRequest() + result, err := TryPayUserOpExecute(&request) + assert.NoError(t, err) + fmt.Printf("Result: %v", result) +} + +func getMockTryPayUserOpRequest() model.TryPayUserOpRequest { + return model.TryPayUserOpRequest{ + ForceStrategyId: "1", + UserOperation: model.UserOperationItem{ + Sender: "0x123", + Nonce: "", + CallGasLimit: "", + VerificationGasList: "", + PerVerificationGas: "", + MaxFeePerGas: "", + MaxPriorityFeePerGas: "", + }, + } +} diff --git a/service/tryPayUserOperationExecutor.go b/service/tryPayUserOperationExecutor.go deleted file mode 100644 index 62894b27..00000000 --- a/service/tryPayUserOperationExecutor.go +++ /dev/null @@ -1,13 +0,0 @@ -package service - -import "AAStarCommunity/EthPaymaster_BackService/rpc_server/models" - -func TryPayUserOpExecute() (models.Result, error) { - return models.Result{}, nil -} -func GetSupportEntrypointExecute() (models.Result, error) { - return models.Result{}, nil -} -func GetSupportStrategyExecute() (models.Result, error) { - return models.Result{}, nil -} diff --git a/service/validatorService/userOpValidator.go b/service/validatorService/userOpValidator.go deleted file mode 100644 index 0308dbe5..00000000 --- a/service/validatorService/userOpValidator.go +++ /dev/null @@ -1 +0,0 @@ -package validatorService diff --git a/service/validator_service/basic_validator.go b/service/validator_service/basic_validator.go new file mode 100644 index 00000000..d893f658 --- /dev/null +++ b/service/validator_service/basic_validator.go @@ -0,0 +1,7 @@ +package validator_service + +import "AAStarCommunity/EthPaymaster_BackService/common/model" + +func ValidateStrategy(strategy *model.Strategy, userOp *model.UserOperationItem) error { + return nil +} diff --git a/service/validator_service/user_op_validator.go b/service/validator_service/user_op_validator.go new file mode 100644 index 00000000..cb6263b0 --- /dev/null +++ b/service/validator_service/user_op_validator.go @@ -0,0 +1 @@ +package validator_service diff --git a/validator/chain/chain_validator.go b/validator/chain/chain_validator.go new file mode 100644 index 00000000..1cb6d7fc --- /dev/null +++ b/validator/chain/chain_validator.go @@ -0,0 +1,10 @@ +package chain + +type Validator interface { + PreValidate() (err error) + AfterGasValidate() (err error) + IsSupport() bool +} +type Base struct { + name string +} diff --git a/validator/chain/ethereum/ethereum_validator.go b/validator/chain/ethereum/ethereum_validator.go new file mode 100644 index 00000000..c6a7f7fe --- /dev/null +++ b/validator/chain/ethereum/ethereum_validator.go @@ -0,0 +1,24 @@ +package ethereum + +import ( + "AAStarCommunity/EthPaymaster_BackService/validator/chain" +) + +type Validator struct { + *chain.Base +} + +func (e *Validator) IsSupport() bool { + //TODO implement me + panic("implement me") +} + +func (e *Validator) PreValidate() (err error) { + //TODO implement me + panic("implement me") +} + +func (e *Validator) AfterGasValidate() (err error) { + //TODO implement me + panic("implement me") +} diff --git a/validator/eip/eip_4844/4844_validator.go b/validator/eip/eip_4844/4844_validator.go new file mode 100644 index 00000000..c847b0f8 --- /dev/null +++ b/validator/eip/eip_4844/4844_validator.go @@ -0,0 +1 @@ +package eip_4844 diff --git a/validator/other/eoa_enabled_validator.go b/validator/other/eoa_enabled_validator.go new file mode 100644 index 00000000..58a9531f --- /dev/null +++ b/validator/other/eoa_enabled_validator.go @@ -0,0 +1 @@ +package other