From 00ebc7db221fb136acf1e279af0a32510daac78f Mon Sep 17 00:00:00 2001 From: dylanyang Date: Thu, 14 Mar 2024 13:38:53 +0800 Subject: [PATCH] optimize gas compute --- common/model/api_response.go | 4 +- common/types/token.go | 13 +++++ common/utils/util.go | 22 +++---- .../erc20_paymaster_generator.go | 17 ------ .../paymaster_generator.go | 29 ---------- .../vertifying_paymaster_generator.go | 20 ------- .../erc20_paymaster_generator.go | 34 +++++++++++ paymaster_pay_type/paymaster_generator.go | 29 ++++++++++ .../vertifying_paymaster_generator.go | 39 +++++++++++++ service/chain_service/chain_service.go | 58 +++++++++++++------ service/chain_service/chain_test.go | 6 ++ .../dashboard_service/dashboard_service.go | 4 ++ service/gas_service/gas_computor.go | 45 ++++++-------- service/operator/try_pay_user_op_execute.go | 9 +-- 14 files changed, 203 insertions(+), 126 deletions(-) delete mode 100644 paymaster_data_generator/erc20_paymaster_generator.go delete mode 100644 paymaster_data_generator/paymaster_generator.go delete mode 100644 paymaster_data_generator/vertifying_paymaster_generator.go create mode 100644 paymaster_pay_type/erc20_paymaster_generator.go create mode 100644 paymaster_pay_type/paymaster_generator.go create mode 100644 paymaster_pay_type/vertifying_paymaster_generator.go diff --git a/common/model/api_response.go b/common/model/api_response.go index 072e21e5..b1293e8c 100644 --- a/common/model/api_response.go +++ b/common/model/api_response.go @@ -17,11 +17,11 @@ type TryPayUserOpResponse struct { type ComputeGasResponse struct { GasInfo *GasPrice `json:"gas_info"` - TokenCost string `json:"token_cost"` + TokenCost *big.Float `json:"token_cost"` Network types.Network `json:"network"` Token types.TokenType `json:"token"` TokenCount string `json:"token_count"` - UsdCost string `json:"usd_cost"` + UsdCost float64 `json:"usd_cost"` BlobEnable bool `json:"blob_enable"` MaxFee big.Int `json:"max_fee"` } diff --git a/common/types/token.go b/common/types/token.go index c53b4445..a9694f46 100644 --- a/common/types/token.go +++ b/common/types/token.go @@ -2,6 +2,19 @@ package types type TokenType string +var StableCoinMap map[TokenType]bool + +func init() { + StableCoinMap = map[TokenType]bool{ + USDT: true, + USDC: true, + } +} +func IsStableToken(token TokenType) bool { + _, ok := StableCoinMap[token] + return ok +} + const ( USDT TokenType = "usdt" USDC TokenType = "usdc" diff --git a/common/utils/util.go b/common/utils/util.go index b91dedf7..5ba491c1 100644 --- a/common/utils/util.go +++ b/common/utils/util.go @@ -14,17 +14,17 @@ var HexPattern = regexp.MustCompile(`^0x[a-fA-F\d]*$`) func GenerateMockUserOperation() *map[string]any { //TODO use config var MockUserOpData = map[string]any{ - "sender": "0x4A2FD3215420376DA4eD32853C19E4755deeC4D1", - "nonce": "1", - "initCode": "0xe19e9755942bb0bd0cccce25b1742596b8a8250b3bf2c3e700000000000000000000000078d4f01f56b982a3b03c4e127a5d3afa8ebee6860000000000000000000000008b388a082f370d8ac2e2b3997e9151168bd09ff50000000000000000000000000000000000000000000000000000000000000000", - "callData": "0xb61d27f6000000000000000000000000c206b552ab127608c3f666156c8e03a8471c72df000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000", - "callGasLimit": "39837", - "verificationGasLimit": "100000", - "maxFeePerGas": "44020", - "maxPriorityFeePerGas": "1743509478", - "paymasterAndData": "0x", - "preVerificationGas": "44020", - "signature": "0x760868cd7d9539c6e31c2169c4cab6817beb8247516a90e4301e929011451658623455035b83d38e987ef2e57558695040a25219c39eaa0e31a0ead16a5c925c1c", + "sender": "0x4A2FD3215420376DA4eD32853C19E4755deeC4D1", + "nonce": "1", + "init_code": "0xe19e9755942bb0bd0cccce25b1742596b8a8250b3bf2c3e700000000000000000000000078d4f01f56b982a3b03c4e127a5d3afa8ebee6860000000000000000000000008b388a082f370d8ac2e2b3997e9151168bd09ff50000000000000000000000000000000000000000000000000000000000000000", + "call_data": "0xb61d27f6000000000000000000000000c206b552ab127608c3f666156c8e03a8471c72df000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000", + "call_gas_limit": "39837", + "verification_gas_limit": "100000", + "max_fee_per_gas": "44020", + "max_priority_fee_per_gas": "1743509478", + "paymaster_and_data": "0x", + "pre_verification_gas": "44020", + "signature": "0x760868cd7d9539c6e31c2169c4cab6817beb8247516a90e4301e929011451658623455035b83d38e987ef2e57558695040a25219c39eaa0e31a0ead16a5c925c1c", } return &MockUserOpData diff --git a/paymaster_data_generator/erc20_paymaster_generator.go b/paymaster_data_generator/erc20_paymaster_generator.go deleted file mode 100644 index 54bd670f..00000000 --- a/paymaster_data_generator/erc20_paymaster_generator.go +++ /dev/null @@ -1,17 +0,0 @@ -package paymaster_data_generator - -import ( - "AAStarCommunity/EthPaymaster_BackService/common/model" - "AAStarCommunity/EthPaymaster_BackService/common/types" - "encoding/hex" -) - -type Erc20PaymasterGenerator struct { -} - -func (e *Erc20PaymasterGenerator) GeneratePayMaster(strategy *model.Strategy, userOp *model.UserOperation, gasResponse *model.ComputeGasResponse, extra map[string]any) ([]byte, error) { - //ERC20:[0-1]pay type,[1-21]paymaster address,[21-53]token Amount - res := "0x" + string(types.PayTypeERC20) + strategy.PayMasterAddress + gasResponse.TokenCost - //TODO implement me - return hex.DecodeString(res) -} diff --git a/paymaster_data_generator/paymaster_generator.go b/paymaster_data_generator/paymaster_generator.go deleted file mode 100644 index e50b6c16..00000000 --- a/paymaster_data_generator/paymaster_generator.go +++ /dev/null @@ -1,29 +0,0 @@ -package paymaster_data_generator - -import ( - "AAStarCommunity/EthPaymaster_BackService/common/model" - "AAStarCommunity/EthPaymaster_BackService/common/types" -) - -var ( - PaymasterDataGeneratorFactories map[types.PayType]PaymasterDataGenerator -) - -func init() { - PaymasterDataGeneratorFactories = make(map[types.PayType]PaymasterDataGenerator) - PaymasterDataGeneratorFactories[types.PayTypeVerifying] = &VerifyingPaymasterGenerator{} - PaymasterDataGeneratorFactories[types.PayTypeERC20] = &Erc20PaymasterGenerator{} -} - -type PaymasterDataGenerator interface { - GeneratePayMaster(strategy *model.Strategy, userOp *model.UserOperation, gasResponse *model.ComputeGasResponse, extra map[string]any) ([]byte, error) -} - -func GetPaymasterDataGenerator(payType types.PayType) PaymasterDataGenerator { - - paymasterDataGenerator, ok := PaymasterDataGeneratorFactories[payType] - if !ok { - return nil - } - return paymasterDataGenerator -} diff --git a/paymaster_data_generator/vertifying_paymaster_generator.go b/paymaster_data_generator/vertifying_paymaster_generator.go deleted file mode 100644 index cf9ed963..00000000 --- a/paymaster_data_generator/vertifying_paymaster_generator.go +++ /dev/null @@ -1,20 +0,0 @@ -package paymaster_data_generator - -import ( - "AAStarCommunity/EthPaymaster_BackService/common/model" - "AAStarCommunity/EthPaymaster_BackService/common/types" - "golang.org/x/xerrors" -) - -type VerifyingPaymasterGenerator struct { -} - -func (v VerifyingPaymasterGenerator) GeneratePayMaster(strategy *model.Strategy, userOp *model.UserOperation, gasResponse *model.ComputeGasResponse, extra map[string]any) ([]byte, error) { - //verifying:[0-1]pay type,[1-21]paymaster address,[21-85]valid timestamp,[85-] signature - signature, ok := extra["signature"] - if !ok { - return nil, xerrors.Errorf("signature not found") - } - res := "0x" + string(types.PayTypeVerifying) + strategy.PayMasterAddress + "" + signature.(string) - return []byte(res), nil -} diff --git a/paymaster_pay_type/erc20_paymaster_generator.go b/paymaster_pay_type/erc20_paymaster_generator.go new file mode 100644 index 00000000..27b9f029 --- /dev/null +++ b/paymaster_pay_type/erc20_paymaster_generator.go @@ -0,0 +1,34 @@ +package paymaster_pay_type + +import ( + "AAStarCommunity/EthPaymaster_BackService/common/model" + "AAStarCommunity/EthPaymaster_BackService/common/types" + "AAStarCommunity/EthPaymaster_BackService/service/chain_service" + "encoding/hex" + "golang.org/x/xerrors" + "math/big" +) + +type Erc20PaymasterExecutor struct { +} + +func (e *Erc20PaymasterExecutor) ValidateGas(userOp *model.UserOperation, gasResponse *model.ComputeGasResponse, strategy *model.Strategy) error { + tokenBalance, getTokenBalanceErr := chain_service.GetAddressTokenBalance(strategy.NetWork, userOp.Sender, strategy.Token) + if getTokenBalanceErr != nil { + return getTokenBalanceErr + } + tokenCost := gasResponse.TokenCost + bigFloatValue := new(big.Float).SetFloat64(tokenBalance) + if bigFloatValue.Cmp(tokenCost) < 0 { + return xerrors.Errorf("user Token Not Enough tokenBalance %s < tokenCost %s", tokenBalance, tokenCost) + } + return nil +} + +func (e *Erc20PaymasterExecutor) GeneratePayMasterAndData(strategy *model.Strategy, userOp *model.UserOperation, gasResponse *model.ComputeGasResponse, extra map[string]any) ([]byte, error) { + //ERC20:[0-1]pay type,[1-21]paymaster address,[21-53]token Amount + //tokenCost := gasResponse.TokenCost.Float64() + res := "0x" + string(types.PayTypeERC20) + strategy.PayMasterAddress + //TODO implement me + return hex.DecodeString(res) +} diff --git a/paymaster_pay_type/paymaster_generator.go b/paymaster_pay_type/paymaster_generator.go new file mode 100644 index 00000000..87e491f4 --- /dev/null +++ b/paymaster_pay_type/paymaster_generator.go @@ -0,0 +1,29 @@ +package paymaster_pay_type + +import ( + "AAStarCommunity/EthPaymaster_BackService/common/model" + "AAStarCommunity/EthPaymaster_BackService/common/types" +) + +var ( + PaymasterDataGeneratorFactories map[types.PayType]PaymasterPayTypeExecutor +) + +func init() { + PaymasterDataGeneratorFactories = make(map[types.PayType]PaymasterPayTypeExecutor) + PaymasterDataGeneratorFactories[types.PayTypeVerifying] = &VerifyingPaymasterExecutor{} + PaymasterDataGeneratorFactories[types.PayTypeERC20] = &Erc20PaymasterExecutor{} +} + +type PaymasterPayTypeExecutor interface { + GeneratePayMasterAndData(strategy *model.Strategy, userOp *model.UserOperation, gasResponse *model.ComputeGasResponse, extra map[string]any) ([]byte, error) + ValidateGas(userOp *model.UserOperation, response *model.ComputeGasResponse, strategy *model.Strategy) error +} + +func GetPaymasterDataExecutor(payType types.PayType) PaymasterPayTypeExecutor { + paymasterDataGenerator, ok := PaymasterDataGeneratorFactories[payType] + if !ok { + return nil + } + return paymasterDataGenerator +} diff --git a/paymaster_pay_type/vertifying_paymaster_generator.go b/paymaster_pay_type/vertifying_paymaster_generator.go new file mode 100644 index 00000000..75bb7ee5 --- /dev/null +++ b/paymaster_pay_type/vertifying_paymaster_generator.go @@ -0,0 +1,39 @@ +package paymaster_pay_type + +import ( + "AAStarCommunity/EthPaymaster_BackService/common/model" + "AAStarCommunity/EthPaymaster_BackService/common/types" + "AAStarCommunity/EthPaymaster_BackService/service/chain_service" + "github.com/ethereum/go-ethereum/common" + "golang.org/x/xerrors" + "math/big" +) + +type VerifyingPaymasterExecutor struct { +} + +func (v VerifyingPaymasterExecutor) ValidateGas(userOp *model.UserOperation, response *model.ComputeGasResponse, strategy *model.Strategy) error { + //Validate the account’s deposit in the entryPoint is high enough to cover the max possible cost (cover the already-done verification and max execution gas) + // Paymaster check paymaster balance + + //check EntryPoint paymasterAddress balance + tokenBalance, getTokenBalanceErr := chain_service.GetAddressTokenBalance(strategy.NetWork, common.HexToAddress(strategy.PayMasterAddress), strategy.Token) + if getTokenBalanceErr != nil { + return getTokenBalanceErr + } + tokenBalanceBigFloat := new(big.Float).SetFloat64(tokenBalance) + if tokenBalanceBigFloat.Cmp(response.TokenCost) > 0 { + return xerrors.Errorf("paymaster Token Not Enough tokenBalance %s < tokenCost %s", tokenBalance, response.TokenCost) + } + return nil +} + +func (v VerifyingPaymasterExecutor) GeneratePayMasterAndData(strategy *model.Strategy, userOp *model.UserOperation, gasResponse *model.ComputeGasResponse, extra map[string]any) ([]byte, error) { + //verifying:[0-1]pay type,[1-21]paymaster address,[21-85]valid timestamp,[85-] signature + signature, ok := extra["signature"] + if !ok { + return nil, xerrors.Errorf("signature not found") + } + res := "0x" + string(types.PayTypeVerifying) + strategy.PayMasterAddress + "" + signature.(string) + return []byte(res), nil +} diff --git a/service/chain_service/chain_service.go b/service/chain_service/chain_service.go index 889720d5..27e0c244 100644 --- a/service/chain_service/chain_service.go +++ b/service/chain_service/chain_service.go @@ -9,6 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/holiman/uint256" "golang.org/x/xerrors" + "math" "math/big" "strings" ) @@ -16,6 +17,21 @@ import ( var GweiFactor = new(big.Float).SetInt(big.NewInt(1e9)) var EthWeiFactor = new(big.Float).SetInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)) +const balanceOfAbi = `[{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]` + +var TokenAddressMap map[types.Network]*map[types.TokenType]common.Address + +func init() { + TokenAddressMap = map[types.Network]*map[types.TokenType]common.Address{ + types.Ethereum: { + types.ETH: common.HexToAddress("0xdac17f958d2ee523a2206206994597c13d831ec7"), + }, + types.Sepolia: { + types.USDT: common.HexToAddress("0xaa8e23fb1079ea71e0a56f48a2aa51851d8433d0"), + types.USDC: common.HexToAddress("0x1c7d4b196cb0c7b01d743fbc6116a902379c7238"), + }, + } +} func CheckContractAddressAccess(contract common.Address, chain types.Network) (bool, error) { if chain == "" { return false, xerrors.Errorf("chain can not be empty") @@ -103,36 +119,44 @@ func EstimateGasLimitAndCost(chain types.Network, msg ethereum.CallMsg) (uint64, } return client.EstimateGas(context.Background(), msg) } -func GetAddressTokenBalance(network types.Network, address common.Address, token types.TokenType) ([]interface{}, error) { +func GetAddressTokenBalance(network types.Network, address common.Address, token types.TokenType) (float64, error) { client, exist := EthCompatibleNetWorkClientMap[network] if !exist { - return nil, xerrors.Errorf("chain Client [%s] not exist", network) + return 0, xerrors.Errorf("chain Client [%s] not exist", network) + } + if token == types.ETH { + res, err := client.BalanceAt(context.Background(), address, nil) + if err != nil { + return 0, err + } + bananceV := float64(res.Int64()) * math.Pow(10, -18) + return bananceV, nil } - client.BalanceAt(context.Background(), address, nil) - usdtContractAddress := common.HexToAddress("0xdac17f958d2ee523a2206206994597c13d831ec7") - //address := common.HexToAddress("0xDf7093eF81fa23415bb703A685c6331584D30177") - const bananceABI = `[{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]` - usdtABI, jsonErr := abi.JSON(strings.NewReader(bananceABI)) + + tokenContractAddress := (*TokenAddressMap[network])[token] + usdtABI, jsonErr := abi.JSON(strings.NewReader(balanceOfAbi)) if jsonErr != nil { - return nil, jsonErr + return 0, jsonErr } data, backErr := usdtABI.Pack("balanceOf", address) if backErr != nil { - return nil, backErr - + return 0, backErr } - //usdtInstance, err := ethclient.NewContract(usdtContractAddress, usdtAbi, client) result, callErr := client.CallContract(context.Background(), ethereum.CallMsg{ - To: &usdtContractAddress, + To: &tokenContractAddress, Data: data, }, nil) if callErr != nil { - return nil, callErr + return 0, callErr } - var balanceResult, unpackErr = usdtABI.Unpack("balanceOf", result) + + var balanceResult *big.Int + unpackErr := usdtABI.UnpackIntoInterface(&balanceResult, "balanceOf", result) if unpackErr != nil { - return nil, unpackErr + return 0, unpackErr } - //TODO get token balance - return balanceResult, nil + balanceResultFloat := float64(balanceResult.Int64()) * math.Pow(10, -6) + + return balanceResultFloat, nil + } diff --git a/service/chain_service/chain_test.go b/service/chain_service/chain_test.go index bdc5dbc5..729d1154 100644 --- a/service/chain_service/chain_test.go +++ b/service/chain_service/chain_test.go @@ -30,3 +30,9 @@ func TestGethClient(t *testing.T) { assert.NotEqual(t, 0, num) fmt.Println(num) } +func TestGetAddressTokenBalance(t *testing.T) { + + res, err := GetAddressTokenBalance(types.Sepolia, common.HexToAddress("0xDf7093eF81fa23415bb703A685c6331584D30177"), types.USDC) + assert.NoError(t, err) + fmt.Println(res) +} diff --git a/service/dashboard_service/dashboard_service.go b/service/dashboard_service/dashboard_service.go index ba5feec6..f9016f00 100644 --- a/service/dashboard_service/dashboard_service.go +++ b/service/dashboard_service/dashboard_service.go @@ -17,12 +17,16 @@ func init() { EntryPointAddress: "0x0576a174D229E3cFA37253523E645A78A0C91B57", PayMasterAddress: "0x0000000000325602a77416A16136FDafd04b299f", NetWork: types.Sepolia, + PayType: types.PayTypeVerifying, + EntryPointTag: types.EntrypointV06, Token: types.USDT, } mockStrategyMap["2"] = &model.Strategy{ Id: "2", EntryPointAddress: "0x0576a174D229E3cFA37253523E645A78A0C91B57", PayMasterAddress: "0x0000000000325602a77416A16136FDafd04b299f", + PayType: types.PayTypeERC20, + EntryPointTag: types.EntrypointV06, NetWork: types.Sepolia, Token: types.ETH, } diff --git a/service/gas_service/gas_computor.go b/service/gas_service/gas_computor.go index ac1d9e56..0c3ee50e 100644 --- a/service/gas_service/gas_computor.go +++ b/service/gas_service/gas_computor.go @@ -4,6 +4,7 @@ import ( "AAStarCommunity/EthPaymaster_BackService/common/model" "AAStarCommunity/EthPaymaster_BackService/common/types" "AAStarCommunity/EthPaymaster_BackService/common/utils" + "AAStarCommunity/EthPaymaster_BackService/paymaster_pay_type" "AAStarCommunity/EthPaymaster_BackService/service/chain_service" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" @@ -26,40 +27,33 @@ func ComputeGas(userOp *model.UserOperation, strategy *model.Strategy) (*model.C if estimateCallGasLimit > userOpCallGasLimit { return nil, xerrors.Errorf("estimateCallGasLimit %d > userOpCallGasLimit %d", estimateCallGasLimit, userOpCallGasLimit) } - //x := gasPrice.MaxBasePriceWei.Int64() + gasPrice.MaxPriorityPriceWei.Int64() - //maxFeePerGas := (x, userOp.MaxFeePerGas.Uint64()) - payMasterPostGasLimit := GetPayMasterGasLimit() + payMasterPostGasLimit := GetPayMasterGasLimit() maxGasLimit := big.NewInt(0).Add(userOp.CallGasLimit, userOp.VerificationGasLimit) maxGasLimit = maxGasLimit.Add(maxGasLimit, payMasterPostGasLimit) maxFee := new(big.Int).Mul(maxGasLimit, gasPrice.MaxBasePriceWei) maxFeePriceInEther := new(big.Float).SetInt(maxFee) maxFeePriceInEther.Quo(maxFeePriceInEther, chain_service.EthWeiFactor) tokenCost, _ := getTokenCost(strategy, maxFeePriceInEther) - if strategy.PayType == types.PayTypeERC20 { - //TODO get ERC20 balance - if err := validateErc20Paymaster(tokenCost, strategy); err != nil { - return nil, err - } + var usdCost float64 + if types.IsStableToken(strategy.Token) { + usdCost, _ = tokenCost.Float64() + } else { + usdCost, _ = utils.GetPriceUsd(strategy.Token) } // TODO get PaymasterCallGasLimit return &model.ComputeGasResponse{ GasInfo: gasPrice, - TokenCost: tokenCost.Text('f', 18), + TokenCost: tokenCost, Network: strategy.NetWork, Token: strategy.Token, - UsdCost: "0.4", + UsdCost: usdCost, BlobEnable: strategy.Enable4844, MaxFee: *maxFee, }, nil } -func validateErc20Paymaster(tokenCost *big.Float, strategy *model.Strategy) error { - //useToken := strategy.Token - //// get User address balance - //TODO - return nil -} + func getTokenCost(strategy *model.Strategy, tokenCount *big.Float) (*big.Float, error) { formTokenType := chain_service.NetworkInfoMap[strategy.NetWork].GasToken toTokenType := strategy.Token @@ -67,22 +61,21 @@ func getTokenCost(strategy *model.Strategy, tokenCount *big.Float) (*big.Float, if err != nil { return nil, err } + if toTokenPrice == 0 { + return nil, xerrors.Errorf("toTokenPrice can not be 0") + } tokenCost := new(big.Float).Mul(tokenCount, big.NewFloat(toTokenPrice)) return tokenCost, nil } func GetPayMasterGasLimit() *big.Int { - return nil + //TODO + return big.NewInt(0) } func ValidateGas(userOp *model.UserOperation, gasComputeResponse *model.ComputeGasResponse, strategy *model.Strategy) error { - //1.if ERC20 check address balacnce - //Validate the account’s deposit in the entryPoint is high enough to cover the max possible cost (cover the already-done verification and max execution gas) - //2 if Paymaster check paymaster balance - //The maxFeePerGas and maxPriorityFeePerGas are above a configurable minimum value that the client is willing to accept. At the minimum, they are sufficiently high to be included with the current block.basefee. - if strategy.PayType == types.PayTypeERC20 { - //TODO check address balance - } else if strategy.PayType == types.PayTypeVerifying { - //TODO check paymaster balance + paymasterDataExecutor := paymaster_pay_type.GetPaymasterDataExecutor(strategy.PayType) + if paymasterDataExecutor == nil { + return xerrors.Errorf(" %s paymasterDataExecutor not found", strategy.PayType) } - return nil + return paymasterDataExecutor.ValidateGas(userOp, gasComputeResponse, strategy) } diff --git a/service/operator/try_pay_user_op_execute.go b/service/operator/try_pay_user_op_execute.go index 4e968393..d37afcfa 100644 --- a/service/operator/try_pay_user_op_execute.go +++ b/service/operator/try_pay_user_op_execute.go @@ -5,7 +5,7 @@ import ( "AAStarCommunity/EthPaymaster_BackService/common/types" "AAStarCommunity/EthPaymaster_BackService/common/utils" "AAStarCommunity/EthPaymaster_BackService/conf" - "AAStarCommunity/EthPaymaster_BackService/paymaster_data_generator" + "AAStarCommunity/EthPaymaster_BackService/paymaster_pay_type" "AAStarCommunity/EthPaymaster_BackService/service/chain_service" "AAStarCommunity/EthPaymaster_BackService/service/dashboard_service" "AAStarCommunity/EthPaymaster_BackService/service/gas_service" @@ -51,6 +51,7 @@ func TryPayUserOpExecute(request *model.TryPayUserOpRequest) (*model.TryPayUserO if gasComputeError != nil { return nil, gasComputeError } + //The maxFeePerGas and maxPriorityFeePerGas are above a configurable minimum value that the client is willing to accept. At the minimum, they are sufficiently high to be included with the current block.basefee. //validate gas if err := gas_service.ValidateGas(userOp, gasResponse, strategy); err != nil { @@ -125,13 +126,13 @@ func getPayMasterSignature(strategy *model.Strategy, userOp *model.UserOperation return hex.EncodeToString(signatureBytes) } func getPayMasterAndData(strategy *model.Strategy, userOp *model.UserOperation, gasResponse *model.ComputeGasResponse, paymasterSign string) ([]byte, error) { - paymasterDataGenerator := paymaster_data_generator.GetPaymasterDataGenerator(strategy.PayType) - if paymasterDataGenerator == nil { + paymasterDataExecutor := paymaster_pay_type.GetPaymasterDataExecutor(strategy.PayType) + if paymasterDataExecutor == nil { return nil, xerrors.Errorf("Not Support PayType: [%w]", strategy.PayType) } extra := make(map[string]any) extra["signature"] = paymasterSign - return paymasterDataGenerator.GeneratePayMaster(strategy, userOp, gasResponse, extra) + return paymasterDataExecutor.GeneratePayMasterAndData(strategy, userOp, gasResponse, extra) } func strategyGenerate(request *model.TryPayUserOpRequest) (*model.Strategy, error) {