From 72e693b2d3d2dd3e1b3fa1e471f4906797baf505 Mon Sep 17 00:00:00 2001 From: dylanyang Date: Mon, 13 May 2024 17:50:52 +0800 Subject: [PATCH] fix comment --- .dockerignore | 2 +- .gitignore | 3 + cmd/server/api_test.go | 3 +- cmd/server/main.go | 24 +++-- .../ethereum_contract/ethereum_client_test.go | 6 +- common/global_const/common_const.go | 13 +-- common/model/secret_config.go | 12 +++ common/network/arbitrum/arbitrum_test.go | 3 +- common/network/ethereum_adaptable_executor.go | 92 +++++++++++-------- .../ethereum_adaptable_executor_test.go | 21 ++++- common/network/pre_verification_gas_test.go | 4 +- common/network/starknet_executor.go | 2 +- common/paymaster_data/paymaster_data.go | 2 +- .../paymaster_data_generate.go | 88 ++++++++---------- common/utils/price_util.go | 2 +- common/utils/util.go | 18 ---- {envirment => config}/appsettings.yaml | 0 .../{business_config.go => basic_config.go} | 77 +++++++++------- ...ness_dev_config.json => basic_config.json} | 29 +++++- config/basic_strategy_config.go | 17 ++-- ...config.json => basic_strategy_config.json} | 40 -------- config/config.go | 7 ++ config/config_test.go | 12 ++- config/secret_config.go | 56 +++++++++++ envirment/app_config.go | 2 +- gas_executor/gas_computor_test.go | 12 ++- gas_executor/gas_validate.go | 68 +++++++------- go.mod | 18 +++- go.sum | 32 +++++++ service/chain_service/chain_service_test.go | 4 +- .../dashboard_service/dashboard_service.go | 11 ++- service/operator/operator_test.go | 4 +- service/operator/try_pay_user_op_execute.go | 2 +- 33 files changed, 413 insertions(+), 273 deletions(-) create mode 100644 common/model/secret_config.go rename {envirment => config}/appsettings.yaml (100%) rename config/{business_config.go => basic_config.go} (72%) rename config/{business_dev_config.json => basic_config.json} (66%) rename config/{basic_strategy_dev_config.json => basic_strategy_config.json} (67%) create mode 100644 config/config.go create mode 100644 config/secret_config.go diff --git a/.dockerignore b/.dockerignore index f1a1c691..5953a05f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1 @@ -envirment/appsettings.yaml +config/appsettings.yaml diff --git a/.gitignore b/.gitignore index d056db4f..82f1937b 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,8 @@ # Go workspace file go.work +.env + .idea .vscode/ build/ @@ -27,3 +29,4 @@ build/ vendor conf/appsettings.*.yaml +config/secret_*.json diff --git a/cmd/server/api_test.go b/cmd/server/api_test.go index 98dea87d..fc072816 100644 --- a/cmd/server/api_test.go +++ b/cmd/server/api_test.go @@ -40,7 +40,8 @@ func APITestCall(engine *gin.Engine, method, url string, body any, response any, } func TestAPI(t *testing.T) { - initEngine("../../config/basic_strategy_dev_config.json", "../../config/business_dev_config.json") + + initEngine("../../config/basic_strategy_config.json", "../../config/basic_config.json", "../../config/secret_config.json") tests := []struct { name string test func(t *testing.T) diff --git a/cmd/server/main.go b/cmd/server/main.go index 43f684f5..4c29167f 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -5,13 +5,17 @@ import ( "AAStarCommunity/EthPaymaster_BackService/envirment" "AAStarCommunity/EthPaymaster_BackService/rpc_server/routers" "flag" - "fmt" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" "os" "strings" ) +const ( + strategyPath = "./config/basic_strategy_config.json" + basicConfigPath = "./config/basic_config.json" +) + var aPort = flag.String("port", "", "Port") // runMode running mode @@ -44,17 +48,20 @@ var Engine *gin.Engine // @description Type 'Bearer \' to correctly set the AccessToken // @BasePath /api func main() { - strategyPath := fmt.Sprintf("./config/basic_strategy_%s_config.json", strings.ToLower(envirment.Environment.Name)) - businessConfigPath := fmt.Sprintf("./config/business_%s_config.json", strings.ToLower(envirment.Environment.Name)) - - initEngine(strategyPath, businessConfigPath) + secretPath := os.Getenv("secret_config_path") + if secretPath == "" { + secretPath = "./config/secret_config.json" + } + initEngine(strategyPath, basicConfigPath, secretPath) port := runMode() + os.Getenv("secret_config_path") _ = Engine.Run(port) } -func initEngine(strategyPath string, businessConfigPath string) { - config.BasicStrategyInit(strategyPath) - config.BusinessConfigInit(businessConfigPath) +func initEngine(strategyPath string, basicConfigPath string, secretPath string) { + + logrus.Infof("secretPath: %s", secretPath) + config.InitConfig(strategyPath, basicConfigPath, secretPath) if envirment.Environment.IsDevelopment() { logrus.SetLevel(logrus.DebugLevel) } else { @@ -62,6 +69,5 @@ func initEngine(strategyPath string, businessConfigPath string) { } logrus.Infof("Environment: %s", envirment.Environment.Name) logrus.Infof("Debugger: %v", envirment.Environment.Debugger) - logrus.Infof("Action ENV : [%v]", os.Getenv("GITHUB_ACTIONS")) Engine = routers.SetRouters() } diff --git a/common/ethereum_contract/ethereum_client_test.go b/common/ethereum_contract/ethereum_client_test.go index ba999a98..c0819fb7 100644 --- a/common/ethereum_contract/ethereum_client_test.go +++ b/common/ethereum_contract/ethereum_client_test.go @@ -15,10 +15,10 @@ import ( func TestPaymasterV07(t *testing.T) { - config.BasicStrategyInit("../../config/basic_strategy_dev_config.json") - config.BusinessConfigInit("../../config/business_dev_config.json") - network := config.GetEthereumRpcUrl(global_const.EthereumSepolia) + config.InitConfig("../../config/basic_strategy_config.json", "../../config/basic_config.json", "../../config/secret_config.json") + network := config.GetNewWorkClientURl(global_const.EthereumSepolia) contractAddress := common.HexToAddress("0x3Da96267B98a33267249734FD8FFeC75093D3085") + t.Logf("network URL %s", network) client, err := ethclient.Dial(network) if err != nil { t.Fatalf("Error: %v", err) diff --git a/common/global_const/common_const.go b/common/global_const/common_const.go index 2387fcf2..97d2c421 100644 --- a/common/global_const/common_const.go +++ b/common/global_const/common_const.go @@ -59,6 +59,11 @@ func init() { if err != nil { panic(err) } + signatureByte, err := hex.DecodeString(DummySignature[2:]) + if err != nil { + panic(err) + } + DummySignatureByte = signatureByte } var GasOverHand = struct { @@ -85,11 +90,3 @@ var GasOverHand = struct { BundleSize: 1, sigSize: 65, } - -func init() { - signatureByte, err := hex.DecodeString(DummySignature[2:]) - if err != nil { - panic(err) - } - DummySignatureByte = signatureByte -} diff --git a/common/model/secret_config.go b/common/model/secret_config.go new file mode 100644 index 00000000..cf7c7542 --- /dev/null +++ b/common/model/secret_config.go @@ -0,0 +1,12 @@ +package model + +type SecretConfig struct { + PriceOracleApiKey string `json:"price_oracle_api_key"` + + NetWorkSecretConfigMap map[string]NetWorkSecretConfig `json:"network_secret_configs"` +} + +type NetWorkSecretConfig struct { + RpcUrl string `json:"rpc_url"` + SignerKey string `json:"signer_key"` +} diff --git a/common/network/arbitrum/arbitrum_test.go b/common/network/arbitrum/arbitrum_test.go index 55418aa8..0f57d71a 100644 --- a/common/network/arbitrum/arbitrum_test.go +++ b/common/network/arbitrum/arbitrum_test.go @@ -11,8 +11,7 @@ import ( ) func TestGetArbitrumGas(t *testing.T) { - config.BasicStrategyInit("../../../config/basic_strategy_dev_config.json") - config.BusinessConfigInit("../../../config/business_dev_config.json") + config.InitConfig("../../../config/basic_strategy_config.json", "../../../config/basic_config.json", "../../../config/secret_config.json") strategy := config.GetBasicStrategyConfig("Arbitrum_Sepolia_v06_verifyPaymaster") if strategy == nil { t.Error("strategy is nil") diff --git a/common/network/ethereum_adaptable_executor.go b/common/network/ethereum_adaptable_executor.go index 6187ba10..444f4119 100644 --- a/common/network/ethereum_adaptable_executor.go +++ b/common/network/ethereum_adaptable_executor.go @@ -29,6 +29,7 @@ import ( "github.com/sirupsen/logrus" "golang.org/x/xerrors" "math/big" + "sync" ) var executorMap = make(map[global_const.Network]*EthereumExecutor) @@ -64,43 +65,56 @@ type EthereumExecutor struct { ChainId *big.Int } +var mu sync.Mutex + func GetEthereumExecutor(network global_const.Network) *EthereumExecutor { + executor, ok := executorMap[network] + if ok { + return executor + } - if executorMap[network] == nil { - // TODO need to check Out Client Connection Always Open - client, err := ethclient.Dial(config.GetEthereumRpcUrl(network)) - if err != nil { - panic(err) - } - chainId := big.NewInt(0) - _, success := chainId.SetString(config.GetChainId(network), 10) - if !success { - panic(xerrors.Errorf("chainId %s is invalid", config.GetChainId(network))) - } - geth := gethclient.New(client.Client()) - executorMap[network] = &EthereumExecutor{ - network: network, - Client: client, - ChainId: chainId, - GethClient: geth, - } + mu.Lock() + defer mu.Unlock() + executor, ok = executorMap[network] + if ok { + return executor + } + rpcUrl := config.GetNewWorkClientURl(network) + if rpcUrl == "" { + panic(xerrors.Errorf("network [%s] is not supported", network)) + } + client, err := ethclient.Dial(rpcUrl) + if err != nil { + panic(err) + } + chainId := big.NewInt(0) + _, success := chainId.SetString(config.GetChainId(network), 10) + if !success { + panic(xerrors.Errorf("chainId %s is invalid", config.GetChainId(network))) + } + geth := gethclient.New(client.Client()) + executorMap[network] = &EthereumExecutor{ + network: network, + Client: client, + ChainId: chainId, + GethClient: geth, } return executorMap[network] } -func (executor EthereumExecutor) GetEntryPointV6Deposit(entryPoint *common.Address, depoist common.Address) (*big.Int, error) { +func (executor *EthereumExecutor) GetEntryPointV6Deposit(entryPoint *common.Address, deposit common.Address) (*big.Int, error) { contract, err := executor.GetEntryPoint06(entryPoint) if err != nil { return nil, err } - depoistInfo, err := contract.GetDepositInfo(&bind.CallOpts{}, depoist) + depoistInfo, err := contract.GetDepositInfo(&bind.CallOpts{}, deposit) if err != nil { return nil, err } return depoistInfo.Deposit, nil } -func (executor EthereumExecutor) GetEntryPointV7Deposit(entryPoint *common.Address, depoist common.Address) (*big.Int, error) { +func (executor *EthereumExecutor) GetEntryPointV7Deposit(entryPoint *common.Address, depoist common.Address) (*big.Int, error) { contract, err := executor.GetEntryPoint07(entryPoint) if err != nil { return nil, err @@ -112,7 +126,7 @@ func (executor EthereumExecutor) GetEntryPointV7Deposit(entryPoint *common.Addre return depositInfo.Deposit, nil } -func (executor EthereumExecutor) GetUserTokenBalance(userAddress common.Address, token global_const.TokenType) (*big.Int, error) { +func (executor *EthereumExecutor) GetUserTokenBalance(userAddress common.Address, token global_const.TokenType) (*big.Int, error) { tokenAddress := config.GetTokenAddress(executor.network, token) //TODO if tokenAddress == "" { return nil, xerrors.Errorf("tokenType [%s] is not supported in [%s] network", token, executor.network) @@ -124,7 +138,7 @@ func (executor EthereumExecutor) GetUserTokenBalance(userAddress common.Address, } return tokenInstance.BalanceOf(&bind.CallOpts{}, userAddress) } -func (executor EthereumExecutor) CheckContractAddressAccess(contract *common.Address) (bool, error) { +func (executor *EthereumExecutor) CheckContractAddressAccess(contract *common.Address) (bool, error) { client := executor.Client code, err := client.CodeAt(context.Background(), *contract, nil) @@ -137,7 +151,7 @@ func (executor EthereumExecutor) CheckContractAddressAccess(contract *common.Add return true, nil } -func (executor EthereumExecutor) GetTokenContract(tokenAddress *common.Address) (*contract_erc20.Contract, error) { +func (executor *EthereumExecutor) GetTokenContract(tokenAddress *common.Address) (*contract_erc20.Contract, error) { client := executor.Client contract, ok := TokenContractCache[tokenAddress] if !ok { @@ -151,7 +165,7 @@ func (executor EthereumExecutor) GetTokenContract(tokenAddress *common.Address) return contract, nil } -func (executor EthereumExecutor) EstimateUserOpCallGas(entrypointAddress *common.Address, userOpParam *user_op.UserOpInput) (*big.Int, error) { +func (executor *EthereumExecutor) EstimateUserOpCallGas(entrypointAddress *common.Address, userOpParam *user_op.UserOpInput) (*big.Int, error) { client := executor.Client userOpValue := *userOpParam res, err := client.EstimateGas(context.Background(), ethereum.CallMsg{ @@ -164,7 +178,7 @@ func (executor EthereumExecutor) EstimateUserOpCallGas(entrypointAddress *common } return new(big.Int).SetUint64(res), nil } -func (executor EthereumExecutor) EstimateCreateSenderGas(entrypointAddress *common.Address, userOpParam *user_op.UserOpInput) (*big.Int, error) { +func (executor *EthereumExecutor) EstimateCreateSenderGas(entrypointAddress *common.Address, userOpParam *user_op.UserOpInput) (*big.Int, error) { client := executor.Client userOpValue := *userOpParam factoryAddress, err := userOpValue.GetFactoryAddress() @@ -184,7 +198,7 @@ func (executor EthereumExecutor) EstimateCreateSenderGas(entrypointAddress *comm // GetGasPrice uint256 gasFee = min(maxFeePerGas, maxPriorityFeePerGas + block.baseFee); // maxPriorityFeePerGasBuffer = L1_fee / verificationGasLimit -func (executor EthereumExecutor) GetGasPrice() (*model.GasPrice, error) { +func (executor *EthereumExecutor) GetGasPrice() (*model.GasPrice, error) { //The Arbitrum sequencer ignores priority fees and eth_maxPriorityFeePerGas always returns 0 //On Optimism we set maxPriorityFeePerGas = l1_gas / l2_base_fee @@ -239,7 +253,7 @@ func (executor EthereumExecutor) GetGasPrice() (*model.GasPrice, error) { // OpResource https://github.com/ethereum-optimism/optimism/blob/233ede59d16cb01bdd8e7ff662a153a4c3178bdd/packages/contracts/contracts/L2/predeploys/OVM_GasPriceOracle.sol#L109-L124 // l1Gas = zeros * TX_DATA_ZERO_GAS + (nonZeros + 4) * TX_DATA_NON_ZERO_GAS // l1GasFee = ((l1Gas + overhead) * l1BaseFee * scalar) / PRECISION -func (executor EthereumExecutor) GetL1DataFee(data []byte) (*big.Int, error) { +func (executor *EthereumExecutor) GetL1DataFee(data []byte) (*big.Int, error) { address, ok := config.L1GasOracleInL2[executor.network] if !ok { return nil, xerrors.Errorf("L1GasOracleInL2 not found in network %s", executor.network) @@ -266,7 +280,7 @@ func (executor EthereumExecutor) GetL1DataFee(data []byte) (*big.Int, error) { return fee, nil } -func (executor EthereumExecutor) SimulateV06HandleOp(v06 *user_op.UserOpInput, entryPoint *common.Address) (*model.SimulateHandleOpResult, error) { +func (executor *EthereumExecutor) SimulateV06HandleOp(v06 *user_op.UserOpInput, entryPoint *common.Address) (*model.SimulateHandleOpResult, error) { abi, err := contract_entrypoint_v06.ContractMetaData.GetAbi() if err != nil { return nil, err @@ -303,7 +317,7 @@ func (executor EthereumExecutor) SimulateV06HandleOp(v06 *user_op.UserOpInput, e }, nil } -func (executor EthereumExecutor) SimulateV07HandleOp(userOpV07 user_op.UserOpInput, entryPoint *common.Address) (*model.SimulateHandleOpResult, error) { +func (executor *EthereumExecutor) SimulateV07HandleOp(userOpV07 user_op.UserOpInput, entryPoint *common.Address) (*model.SimulateHandleOpResult, error) { var result *simulate_entrypoint.IEntryPointSimulationsExecutionResult simulateAbi, err := simulate_entrypoint.ContractMetaData.GetAbi() if err != nil { @@ -353,7 +367,7 @@ func (executor EthereumExecutor) SimulateV07HandleOp(userOpV07 user_op.UserOpInp TargetResult: result.TargetResult, }, nil } -func (executor EthereumExecutor) GetSimulateEntryPoint() (*simulate_entrypoint.Contract, error) { +func (executor *EthereumExecutor) GetSimulateEntryPoint() (*simulate_entrypoint.Contract, error) { contract, ok := SimulateEntryPointContractCache[executor.network] if !ok { contractInstance, err := simulate_entrypoint.NewContract(common.HexToAddress("0x"), executor.Client) @@ -365,7 +379,7 @@ func (executor EthereumExecutor) GetSimulateEntryPoint() (*simulate_entrypoint.C } return contract, nil } -func (executor EthereumExecutor) GetPaymasterDeposit(paymasterAddress *common.Address) (*big.Int, error) { +func (executor *EthereumExecutor) GetPaymasterDeposit(paymasterAddress *common.Address) (*big.Int, error) { contract, err := executor.GetPaymasterErc20AndVerifyV06(paymasterAddress) if err != nil { return nil, err @@ -377,7 +391,7 @@ func (executor EthereumExecutor) GetPaymasterDeposit(paymasterAddress *common.Ad return deposit, nil } -func (executor EthereumExecutor) GetEntryPoint07(entryPoint *common.Address) (*contract_entrypoint_v07.Contract, error) { +func (executor *EthereumExecutor) GetEntryPoint07(entryPoint *common.Address) (*contract_entrypoint_v07.Contract, error) { contract, ok := V07EntryPointContractCache[executor.network][*entryPoint] if !ok { contractInstance, err := contract_entrypoint_v07.NewContract(*entryPoint, executor.Client) @@ -389,7 +403,7 @@ func (executor EthereumExecutor) GetEntryPoint07(entryPoint *common.Address) (*c } return contract, nil } -func (executor EthereumExecutor) GetEntryPoint06(entryPoint *common.Address) (*contract_entrypoint_v06.Contract, error) { +func (executor *EthereumExecutor) GetEntryPoint06(entryPoint *common.Address) (*contract_entrypoint_v06.Contract, error) { contract, ok := V06EntryPointContractCache[executor.network][*entryPoint] if !ok { contractInstance, err := contract_entrypoint_v06.NewContract(*entryPoint, executor.Client) @@ -405,7 +419,7 @@ func (executor EthereumExecutor) GetEntryPoint06(entryPoint *common.Address) (*c return contract, nil } -func (executor EthereumExecutor) GetPaymasterErc20AndVerifyV06(paymasterAddress *common.Address) (*paymaster_verifying_erc20_v06.Contract, error) { +func (executor *EthereumExecutor) GetPaymasterErc20AndVerifyV06(paymasterAddress *common.Address) (*paymaster_verifying_erc20_v06.Contract, error) { contract, ok := V06PaymasterErc20AndPaymasterCache[executor.network][*paymasterAddress] if !ok { contractInstance, err := paymaster_verifying_erc20_v06.NewContract(*paymasterAddress, executor.Client) @@ -420,7 +434,7 @@ func (executor EthereumExecutor) GetPaymasterErc20AndVerifyV06(paymasterAddress } return contract, nil } -func (executor EthereumExecutor) GetPaymasterErc20AndVerifyV07(paymasterAddress *common.Address) (*paymaster_verifying_erc20_v07.Contract, error) { +func (executor *EthereumExecutor) GetPaymasterErc20AndVerifyV07(paymasterAddress *common.Address) (*paymaster_verifying_erc20_v07.Contract, error) { contract, ok := V07PaymasterErc20AndPaymasterCache[executor.network][*paymasterAddress] if !ok { contractInstance, err := paymaster_verifying_erc20_v07.NewContract(*paymasterAddress, executor.Client) @@ -436,7 +450,7 @@ func (executor EthereumExecutor) GetPaymasterErc20AndVerifyV07(paymasterAddress return contract, nil } -func (executor EthereumExecutor) GetAuth() (*bind.TransactOpts, error) { +func (executor *EthereumExecutor) GetAuth() (*bind.TransactOpts, error) { if executor.ChainId == nil { return nil, xerrors.Errorf("chainId is nil") } @@ -460,7 +474,7 @@ func GetAuth(chainId *big.Int, privateKey *ecdsa.PrivateKey) (*bind.TransactOpts Context: context.Background(), }, nil } -func (executor EthereumExecutor) GetUserOpHash(userOp *user_op.UserOpInput, strategy *model.Strategy) ([]byte, string, error) { +func (executor *EthereumExecutor) GetUserOpHash(userOp *user_op.UserOpInput, strategy *model.Strategy) ([]byte, string, error) { version := strategy.GetStrategyEntrypointVersion() erc20Token := common.HexToAddress("0x") payType := strategy.GetPayType() @@ -525,7 +539,7 @@ func (executor EthereumExecutor) GetUserOpHash(userOp *user_op.UserOpInput, stra } } -func (executor EthereumExecutor) GetPaymasterData(userOp *user_op.UserOpInput, strategy *model.Strategy, paymasterDataInput *paymaster_data.PaymasterDataInput) ([]byte, error) { +func (executor *EthereumExecutor) GetPaymasterData(userOp *user_op.UserOpInput, strategy *model.Strategy, paymasterDataInput *paymaster_data.PaymasterDataInput) ([]byte, error) { userOpHash, _, err := executor.GetUserOpHash(userOp, strategy) if err != nil { logrus.Errorf("GetUserOpHash error [%v]", err) diff --git a/common/network/ethereum_adaptable_executor_test.go b/common/network/ethereum_adaptable_executor_test.go index 378d1797..a655b547 100644 --- a/common/network/ethereum_adaptable_executor_test.go +++ b/common/network/ethereum_adaptable_executor_test.go @@ -9,14 +9,14 @@ import ( "AAStarCommunity/EthPaymaster_BackService/config" "context" "encoding/hex" + "encoding/json" "github.com/ethereum/go-ethereum/common" "github.com/sirupsen/logrus" "testing" ) func TestEthereumAdaptableExecutor(t *testing.T) { - config.BasicStrategyInit("../../config/basic_strategy_dev_config.json") - config.BusinessConfigInit("../../config/business_dev_config.json") + config.InitConfig("../../config/basic_strategy_config.json", "../../config/basic_config.json", "../../config/secret_config.json") logrus.SetLevel(logrus.DebugLevel) op, err := user_op.NewUserOp(utils.GenerateMockUservOperation()) if err != nil { @@ -304,6 +304,9 @@ func testSimulateHandleOp(t *testing.T, chain global_const.Network, strategy *mo return } op.PaymasterAndData = paymasterData + opMap := parseOpToMapV7(*op) + opJson, _ := json.Marshal(opMap) + t.Logf("SimulateHandleOp op: %v", string(opJson)) t.Logf("entryPoint Address %s", strategy.GetEntryPointAddress()) version := strategy.GetStrategyEntrypointVersion() @@ -328,6 +331,20 @@ func testSimulateHandleOp(t *testing.T, chain global_const.Network, strategy *mo callData := simulateResult.SimulateUserOpCallData t.Logf("callData: %v", hex.EncodeToString(callData)) } +func parseOpToMapV7(input user_op.UserOpInput) map[string]string { + opMap := make(map[string]string) + + opMap["accountGasLimits"] = utils.EncodeToStringWithPrefix(input.AccountGasLimits[:]) + opMap["callGasLimit"] = input.CallGasLimit.String() + opMap["gasFees"] = utils.EncodeToStringWithPrefix(input.GasFees[:]) + opMap["maxFeePerGas"] = input.MaxFeePerGas.String() + opMap["maxPriorityFeePerGas"] = input.MaxPriorityFeePerGas.String() + opMap["preVerificationGas"] = input.PreVerificationGas.String() + opMap["verificationGasLimit"] = input.VerificationGasLimit.String() + opMap["paymasterAndData"] = utils.EncodeToStringWithPrefix(input.PaymasterAndData[:]) + opMap["Nonce"] = input.Nonce.String() + return opMap +} func testEthereumExecutorClientConnect(t *testing.T, chain global_const.Network) { executor := GetEthereumExecutor(chain) diff --git a/common/network/pre_verification_gas_test.go b/common/network/pre_verification_gas_test.go index 8586aef6..3dfc187a 100644 --- a/common/network/pre_verification_gas_test.go +++ b/common/network/pre_verification_gas_test.go @@ -7,8 +7,8 @@ import ( ) func TestPreVerGas(t *testing.T) { - config.BasicStrategyInit("../../config/basic_strategy_dev_config.json") - config.BusinessConfigInit("../../config/business_dev_config.json") + + config.InitConfig("../../config/basic_strategy_config.json", "../../config/basic_config.json", "../../config/secret_config.json") logrus.SetLevel(logrus.DebugLevel) tests := []struct { diff --git a/common/network/starknet_executor.go b/common/network/starknet_executor.go index 1324ed14..dfe3db04 100644 --- a/common/network/starknet_executor.go +++ b/common/network/starknet_executor.go @@ -12,6 +12,6 @@ func init() { func GetStarknetExecutor() *StarknetExecutor { return &StarknetExecutor{} } -func (executor StarknetExecutor) GetGasPrice() (*model.GasPrice, error) { +func (executor *StarknetExecutor) GetGasPrice() (*model.GasPrice, error) { return nil, nil } diff --git a/common/paymaster_data/paymaster_data.go b/common/paymaster_data/paymaster_data.go index 276d0e5d..0a43692f 100644 --- a/common/paymaster_data/paymaster_data.go +++ b/common/paymaster_data/paymaster_data.go @@ -41,7 +41,7 @@ func NewPaymasterDataInput(strategy *model.Strategy) *PaymasterDataInput { ExchangeRate: big.NewInt(0), PayType: strategy.GetPayType(), EntryPointVersion: strategy.GetStrategyEntrypointVersion(), - PaymasterVerificationGasLimit: global_const.DummyVerificationGasLimit, + PaymasterVerificationGasLimit: global_const.DummyPaymasterOversimplificationBigint, PaymasterPostOpGasLimit: global_const.DummyPaymasterPostoperativelyBigint, } } diff --git a/common/paymaster_pay_type/paymaster_data_generate.go b/common/paymaster_pay_type/paymaster_data_generate.go index 562340df..c8414179 100644 --- a/common/paymaster_pay_type/paymaster_data_generate.go +++ b/common/paymaster_pay_type/paymaster_data_generate.go @@ -5,19 +5,52 @@ import ( "AAStarCommunity/EthPaymaster_BackService/common/global_const" "AAStarCommunity/EthPaymaster_BackService/common/paymaster_data" "AAStarCommunity/EthPaymaster_BackService/common/utils" - "golang.org/x/xerrors" - "github.com/ethereum/go-ethereum/accounts/abi" + "golang.org/x/xerrors" ) -var GenerateFuncMap = map[global_const.PayType]GeneratePaymasterDataFunc{} +var paymasterDataFuncMap = map[global_const.PayType]GeneratePaymasterDataFunc{} var BasicPaymasterDataAbiV06 abi.Arguments var BasicPaymasterDataAbiV07 abi.Arguments +var basicPaymasterDataFunc = func(data *paymaster_data.PaymasterDataInput, signature []byte) ([]byte, error) { + var packedRes []byte + if data.EntryPointVersion == global_const.EntrypointV06 { + v06Packed, err := BasicPaymasterDataAbiV06.Pack(data.ValidUntil, data.ValidAfter, data.ERC20Token, data.ExchangeRate) + if err != nil { + return nil, err + } + packedRes = v06Packed + } else if data.EntryPointVersion == global_const.EntrypointV07 { + accountGasLimit := utils.PackIntTo32Bytes(data.PaymasterVerificationGasLimit, data.PaymasterPostOpGasLimit) + v07Packed, err := BasicPaymasterDataAbiV07.Pack(accountGasLimit, data.ValidUntil, data.ValidAfter, data.ERC20Token, data.ExchangeRate) + if err != nil { + return nil, err + } + packedRes = v07Packed + } else { + return nil, xerrors.Errorf("unsupported entrypoint version") + } + + concat := data.Paymaster.Bytes() + concat = append(concat, packedRes...) + concat = append(concat, signature...) + return concat, nil +} func init() { - GenerateFuncMap[global_const.PayTypeVerifying] = GenerateBasicPaymasterData() - GenerateFuncMap[global_const.PayTypeERC20] = GenerateBasicPaymasterData() - GenerateFuncMap[global_const.PayTypeSuperVerifying] = GenerateSuperContractPaymasterData() + paymasterDataFuncMap[global_const.PayTypeVerifying] = basicPaymasterDataFunc + paymasterDataFuncMap[global_const.PayTypeERC20] = basicPaymasterDataFunc + paymasterDataFuncMap[global_const.PayTypeSuperVerifying] = func(data *paymaster_data.PaymasterDataInput, signature []byte) ([]byte, error) { + packed, err := BasicPaymasterDataAbiV06.Pack(data.ValidUntil, data.ValidAfter, data.ERC20Token, data.ExchangeRate) + if err != nil { + return nil, err + } + + concat := data.Paymaster.Bytes() + concat = append(concat, packed...) + concat = append(concat, signature...) + return concat, nil + } BasicPaymasterDataAbiV07 = abi.Arguments{ {Name: "accountGasLimit", Type: paymaster_abi.Bytes32Type}, {Name: "validUntil", Type: paymaster_abi.Uint48Type}, @@ -34,48 +67,7 @@ func init() { } func GetGenerateFunc(payType global_const.PayType) GeneratePaymasterDataFunc { - return GenerateFuncMap[payType] + return paymasterDataFuncMap[payType] } type GeneratePaymasterDataFunc = func(data *paymaster_data.PaymasterDataInput, signature []byte) ([]byte, error) - -func GenerateBasicPaymasterData() GeneratePaymasterDataFunc { - return func(data *paymaster_data.PaymasterDataInput, signature []byte) ([]byte, error) { - var packedRes []byte - if data.EntryPointVersion == global_const.EntrypointV06 { - v06Packed, err := BasicPaymasterDataAbiV06.Pack(data.ValidUntil, data.ValidAfter, data.ERC20Token, data.ExchangeRate) - if err != nil { - return nil, err - } - packedRes = v06Packed - } else if data.EntryPointVersion == global_const.EntrypointV07 { - accountGasLimit := utils.PackIntTo32Bytes(data.PaymasterVerificationGasLimit, data.PaymasterPostOpGasLimit) - v07Packed, err := BasicPaymasterDataAbiV07.Pack(accountGasLimit, data.ValidUntil, data.ValidAfter, data.ERC20Token, data.ExchangeRate) - if err != nil { - return nil, err - } - packedRes = v07Packed - } else { - return nil, xerrors.Errorf("unsupported entrypoint version") - } - - concat := data.Paymaster.Bytes() - concat = append(concat, packedRes...) - concat = append(concat, signature...) - return concat, nil - } -} - -func GenerateSuperContractPaymasterData() GeneratePaymasterDataFunc { - return func(data *paymaster_data.PaymasterDataInput, signature []byte) ([]byte, error) { - packed, err := BasicPaymasterDataAbiV06.Pack(data.ValidUntil, data.ValidAfter, data.ERC20Token, data.ExchangeRate) - if err != nil { - return nil, err - } - - concat := data.Paymaster.Bytes() - concat = append(concat, packed...) - concat = append(concat, signature...) - return concat, nil - } -} diff --git a/common/utils/price_util.go b/common/utils/price_util.go index c24a407e..76b6fdae 100644 --- a/common/utils/price_util.go +++ b/common/utils/price_util.go @@ -41,7 +41,7 @@ func GetPriceUsd(tokenType global_const.TokenType) (float64, error) { return 0, xerrors.Errorf("tokens type [%w] not found", tokenType) } req, _ := http.NewRequest("GET", tokenUrl, nil) - + //TODO remove APIKey req.Header.Add("x-cg-demo-api-key", "CG-ioE6p8cmmSFBFwJnKECCbZ7U\t") res, _ := http.DefaultClient.Do(req) diff --git a/common/utils/util.go b/common/utils/util.go index bc4530ea..59b84742 100644 --- a/common/utils/util.go +++ b/common/utils/util.go @@ -141,24 +141,6 @@ func ToEthSignedMessageHash(msg []byte) []byte { return crypto.Keccak256(buffer.Bytes()) } -func ReplaceLastTwoChars(str, replacement string) string { - if len(str) < 2 { - return str - } - return str[:len(str)-2] + replacement -} -func SupplyZero(prefix string, maxTo int) string { - padding := maxTo - len(prefix) - if padding > 0 { - prefix = "0" + prefix - prefix = fmt.Sprintf("%0*s", maxTo, prefix) - } - return prefix -} -func IsLessThanZero(value *big.Int) bool { - return false - //TODO -} func LeftIsLessTanRight(a *big.Int, b *big.Int) bool { return a.Cmp(b) < 0 } diff --git a/envirment/appsettings.yaml b/config/appsettings.yaml similarity index 100% rename from envirment/appsettings.yaml rename to config/appsettings.yaml diff --git a/config/business_config.go b/config/basic_config.go similarity index 72% rename from config/business_config.go rename to config/basic_config.go index 7248ad9f..ca6e57dc 100644 --- a/config/business_config.go +++ b/config/basic_config.go @@ -10,20 +10,13 @@ import ( ) var basicConfig *BusinessConfig -var signerConfig = make(SignerConfigMap) -type SignerConfigMap map[global_const.Network]*global_const.EOA - -func BusinessConfigInit(path string) { +func basicConfigInit(path string) { if path == "" { panic("pathParam is empty") } originConfig := initBusinessConfig(path) basicConfig = convertConfig(originConfig) - -} -func GetSigner(network global_const.Network) *global_const.EOA { - return signerConfig[network] } func convertConfig(originConfig *OriginBusinessConfig) *BusinessConfig { @@ -34,11 +27,14 @@ func convertConfig(originConfig *OriginBusinessConfig) *BusinessConfig { for network, originNetWorkConfig := range originConfig.NetworkConfigMap { //TODO valid basic.NetworkConfigMap[network] = NetWorkConfig{ - ChainId: originNetWorkConfig.ChainId, - IsTest: originNetWorkConfig.IsTest, - RpcUrl: fmt.Sprintf("%s/%s", originNetWorkConfig.RpcUrl, originNetWorkConfig.ApiKey), - TokenConfig: originNetWorkConfig.TokenConfig, - GasToken: originNetWorkConfig.GasToken, + ChainId: originNetWorkConfig.ChainId, + IsTest: originNetWorkConfig.IsTest, + TokenConfig: originNetWorkConfig.TokenConfig, + GasToken: originNetWorkConfig.GasToken, + V06EntryPointAddress: common.HexToAddress(originNetWorkConfig.V06EntryPointAddress), + V07EntryPointAddress: common.HexToAddress(originNetWorkConfig.V07EntryPointAddress), + V06PaymasterAddress: common.HexToAddress(originNetWorkConfig.V06PaymasterAddress), + V07PaymasterAddress: common.HexToAddress(originNetWorkConfig.V07PaymasterAddress), } paymasterArr := originConfig.SupportPaymaster[network] paymasterSet := mapset.NewSet[string]() @@ -49,12 +45,6 @@ func convertConfig(originConfig *OriginBusinessConfig) *BusinessConfig { entryPointSet := mapset.NewSet[string]() entryPointSet.Append(entryPointArr...) basic.SupportEntryPoint[network] = entryPointSet - //TODO starknet - eoa, err := global_const.NewEoa(originNetWorkConfig.SignerKey) - if err != nil { - panic(fmt.Sprintf("signer key error: %s", err)) - } - signerConfig[network] = eoa } return basic } @@ -80,14 +70,15 @@ type OriginBusinessConfig struct { SupportPaymaster map[global_const.Network][]string `json:"support_paymaster"` } type OriginNetWorkConfig struct { - ChainId string `json:"chain_id"` - IsTest bool `json:"is_test"` - RpcUrl string `json:"rpc_url"` - ApiKey string `json:"api_key"` - SignerKey string `json:"signer_key"` - TokenConfig map[global_const.TokenType]string `json:"token_config"` - GasToken global_const.TokenType `json:"gas_token"` - GasOracleAddress string + ChainId string `json:"chain_id"` + IsTest bool `json:"is_test"` + TokenConfig map[global_const.TokenType]string `json:"token_config"` + GasToken global_const.TokenType `json:"gas_token"` + V06PaymasterAddress string `json:"v06_paymaster_address"` + V07PaymasterAddress string `json:"v07_paymaster_address"` + V06EntryPointAddress string `json:"v06_entrypoint_address"` + V07EntryPointAddress string `json:"v07_entrypoint_address"` + GasOracleAddress string } type BusinessConfig struct { @@ -96,12 +87,15 @@ type BusinessConfig struct { SupportPaymaster map[global_const.Network]mapset.Set[string] `json:"support_paymaster"` } type NetWorkConfig struct { - ChainId string `json:"chain_id"` - IsTest bool `json:"is_test"` - RpcUrl string `json:"rpc_url"` - TokenConfig map[global_const.TokenType]string `json:"token_config"` - GasToken global_const.TokenType - GasOracleAddress common.Address + ChainId string `json:"chain_id"` + IsTest bool `json:"is_test"` + TokenConfig map[global_const.TokenType]string `json:"token_config"` + GasToken global_const.TokenType + GasOracleAddress common.Address + V06PaymasterAddress common.Address + V07PaymasterAddress common.Address + V06EntryPointAddress common.Address + V07EntryPointAddress common.Address } func GetSupportEntryPoints(network global_const.Network) (mapset.Set[string], error) { @@ -138,9 +132,22 @@ func GetChainId(networkParam global_const.Network) string { networkConfig := basicConfig.NetworkConfigMap[networkParam] return networkConfig.ChainId } -func GetEthereumRpcUrl(network global_const.Network) string { + +func GetPaymasterAddress(network global_const.Network, version global_const.EntrypointVersion) common.Address { networkConfig := basicConfig.NetworkConfigMap[network] - return networkConfig.RpcUrl + if version == global_const.EntrypointV07 { + return networkConfig.V07PaymasterAddress + } + return networkConfig.V06PaymasterAddress +} + +func GetEntrypointAddress(network global_const.Network, version global_const.EntrypointVersion) common.Address { + networkConfig := basicConfig.NetworkConfigMap[network] + if version == global_const.EntrypointV07 { + return networkConfig.V07EntryPointAddress + } + return networkConfig.V06EntryPointAddress + } var ( diff --git a/config/business_dev_config.json b/config/basic_config.json similarity index 66% rename from config/business_dev_config.json rename to config/basic_config.json index 5d0764f8..061fa5cc 100644 --- a/config/business_dev_config.json +++ b/config/basic_config.json @@ -6,6 +6,10 @@ "rpc_url": "https://eth-sepolia.g.alchemy.com/v2", "api_key": "wKeLycGxgYRykgf0aGfcpEkUtqyLQg4v", "signer_key" : "752d81d71afd0b25a09f24718baf82c0846cc3b68122cfb3a1d41529c8a46b05", + "v06_entrypoint_address" : "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", + "v07_entrypoint_address" : "0x0000000071727De22E5E9d8BAf0edAc6f37da032", + "v06_paymaster_address" : "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", + "v07_paymaster_address": "0x3Da96267B98a33267249734FD8FFeC75093D3085", "gas_token": "ETH", "token_config": { "USDT": "0x3870419Ba2BBf0127060bCB37f69A1b1C090992B", @@ -18,6 +22,10 @@ "rpc_url": "https://opt-sepolia.g.alchemy.com/v2", "api_key": "_z0GaU6Zk8RfIR1guuli8nqMdb8RPdp0", "signer_key" : "1d8a58126e87e53edc7b24d58d1328230641de8c4242c135492bf5560e0ff421", + "v06_entrypoint_address" : "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", + "v07_entrypoint_address" : "0x0000000071727De22E5E9d8BAf0edAc6f37da032", + "v06_paymaster_address" : "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", + "v07_paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "gas_token": "ETH", "token_config": { "USDT": "0x3870419Ba2BBf0127060bCB37f69A1b1C090992B", @@ -30,6 +38,10 @@ "rpc_url": "https://arb-sepolia.g.alchemy.com/v2", "api_key": "xSBkiidslrZmlcWUOSF3AluKx0A9g_kl", "signer_key" : "752d81d71afd0b25a09f24718baf82c0846cc3b68122cfb3a1d41529c8a46b05", + "v06_entrypoint_address" : "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", + "v07_entrypoint_address" : "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", + "v06_paymaster_address" : "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", + "v07_paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "gas_token": "ETH", "token_config": { "USDT": "0x3870419Ba2BBf0127060bCB37f69A1b1C090992B", @@ -42,6 +54,10 @@ "rpc_url": "https://sepolia-rpc.scroll.io", "api_key": "9DGRNUARDVGDPZWN2G55I3Y5NG7HQJBUTH", "signer_key" : "752d81d71afd0b25a09f24718baf82c0846cc3b68122cfb3a1d41529c8a46b05", + "v06_entrypoint_address" : "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", + "v07_entrypoint_address" : "0x0000000071727De22E5E9d8BAf0edAc6f37da032", + "v06_paymaster_address" : "0x0Fa9ee28202F8602E9a4C99Af799C75C29AFbC89", + "v07_paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "gas_token": "ETH", "token_config": { "USDT": "0x3870419Ba2BBf0127060bCB37f69A1b1C090992B", @@ -54,6 +70,10 @@ "rpc_url": "https://starknet-sepolia.infura.io/v3", "api_key": "0284f5a9fc55476698079b24e2f97909", "signer_key" : "752d81d71afd0b25a09f24718baf82c0846cc3b68122cfb3a1d41529c8a46b05", + "v06_entrypoint_address" : "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", + "v07_entrypoint_address" : "0x0000000071727De22E5E9d8BAf0edAc6f37da032", + "v06_paymaster_address" : "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", + "v07_paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "gas_token": "ETH", "token_config": { "USDT": "0x3870419Ba2BBf0127060bCB37f69A1b1C090992B", @@ -66,6 +86,10 @@ "rpc_url": "https://base-sepolia.g.alchemy.com/v2", "api_key": "zUhtd18b2ZOTIJME6rv2Uwz9q7PBnnsa", "signer_key" : "752d81d71afd0b25a09f24718baf82c0846cc3b68122cfb3a1d41529c8a46b05", + "v06_entrypoint_address" : "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", + "v07_entrypoint_address" : "0x0000000071727De22E5E9d8BAf0edAc6f37da032", + "v06_paymaster_address" : "0xa86cFf572E299B2704FBBCF77dcbbc7FEfFbcA06", + "v07_paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "gas_token": "ETH", "token_config": { "USDT": "0x3870419Ba2BBf0127060bCB37f69A1b1C090992B", @@ -98,7 +122,7 @@ "support_paymaster": { "ethereum-sepolia": [ "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", - "0x2" + "0x3Da96267B98a33267249734FD8FFeC75093D3085" ], "optimism-sepolia": [ "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", @@ -116,5 +140,6 @@ "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "0x2" ] - } + }, + "price_oracle_api_key": "CG-ioE6p8cmmSFBFwJnKECCbZ7U" } diff --git a/config/basic_strategy_config.go b/config/basic_strategy_config.go index 58bec7db..2462970d 100644 --- a/config/basic_strategy_config.go +++ b/config/basic_strategy_config.go @@ -6,7 +6,6 @@ import ( "AAStarCommunity/EthPaymaster_BackService/common/utils" "encoding/json" "fmt" - "github.com/ethereum/go-ethereum/common" "golang.org/x/xerrors" "math/big" "os" @@ -18,7 +17,13 @@ var basicStrategyConfig = make(map[string]*model.Strategy) var suitableStrategyMap = make(map[global_const.Network]map[global_const.EntrypointVersion]map[global_const.PayType]*model.Strategy) func GetBasicStrategyConfig(strategyCode global_const.BasicStrategyCode) *model.Strategy { - return basicStrategyConfig[string(strategyCode)] + strategy := basicStrategyConfig[string(strategyCode)] + paymasterAddress := GetPaymasterAddress(strategy.GetNewWork(), strategy.GetStrategyEntrypointVersion()) + strategy.PaymasterInfo.PayMasterAddress = &paymasterAddress + entryPointAddress := GetEntrypointAddress(strategy.GetNewWork(), strategy.GetStrategyEntrypointVersion()) + strategy.EntryPointInfo.EntryPointAddress = &entryPointAddress + return strategy + } func GetSuitableStrategy(entrypointVersion global_const.EntrypointVersion, chain global_const.Network, payType global_const.PayType) (*model.Strategy, error) { //TODO @@ -29,7 +34,7 @@ func GetSuitableStrategy(entrypointVersion global_const.EntrypointVersion, chain return strategy, nil } -func BasicStrategyInit(path string) { +func basicStrategyInit(path string) { if path == "" { panic("pathParam is empty") } @@ -55,8 +60,6 @@ func convertMapToStrategyConfig(data map[string]map[string]any) (map[string]*mod config := make(map[string]*model.Strategy) for key, value := range data { - paymasterAddress := common.HexToAddress(value["paymaster_address"].(string)) - entryPointAddress := common.HexToAddress(value["entrypoint_address"].(string)) effectiveStartTime, ok := new(big.Int).SetString(value["effective_start_time"].(string), 10) if !ok { return nil, xerrors.Errorf("effective_start_time illegal") @@ -73,7 +76,6 @@ func convertMapToStrategyConfig(data map[string]map[string]any) (map[string]*mod NetWork: global_const.Network(value["network"].(string)), }, EntryPointInfo: &model.EntryPointInfo{ - EntryPointAddress: &entryPointAddress, EntryPointVersion: global_const.EntrypointVersion(value["entrypoint_version"].(string)), }, @@ -83,8 +85,7 @@ func convertMapToStrategyConfig(data map[string]map[string]any) (map[string]*mod AccessProject: utils.ConvertStringToSet(accessProjectStr, ","), }, PaymasterInfo: &model.PaymasterInfo{ - PayMasterAddress: &paymasterAddress, - PayType: global_const.PayType(value["paymaster_pay_type"].(string)), + PayType: global_const.PayType(value["paymaster_pay_type"].(string)), }, } if strategy.GetPayType() == global_const.PayTypeERC20 { diff --git a/config/basic_strategy_dev_config.json b/config/basic_strategy_config.json similarity index 67% rename from config/basic_strategy_dev_config.json rename to config/basic_strategy_config.json index d6a069aa..47e0ea74 100644 --- a/config/basic_strategy_dev_config.json +++ b/config/basic_strategy_config.json @@ -1,210 +1,170 @@ { "Ethereum_Sepolia_v06_verifyPaymaster": { "network": "ethereum-sepolia", - "entrypoint_address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", "entrypoint_version": "v0.6", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "paymaster_pay_type": "PayTypeVerifying", "access_project": "official" }, "Ethereum_Sepolia_v07_verifyPaymaster": { "network": "ethereum-sepolia", - "entrypoint_address": "0x0000000071727De22E5E9d8BAf0edAc6f37da032", "entrypoint_version": "v0.7", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0x3Da96267B98a33267249734FD8FFeC75093D3085", "paymaster_pay_type": "PayTypeVerifying", "access_project": "official" }, "Ethereum_Sepolia_v06_erc20Paymaster": { "network": "ethereum-sepolia", - "entrypoint_address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", "entrypoint_version": "v0.6", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "paymaster_pay_type": "PayTypeERC20", "access_erc20": "USDT,USDC", "access_project": "official" }, "Ethereum_Sepolia_v07_erc20Paymaster": { "network": "ethereum-sepolia", - "entrypoint_address": "0x0000000071727De22E5E9d8BAf0edAc6f37da032", "entrypoint_version": "v0.7", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0x3Da96267B98a33267249734FD8FFeC75093D3085", "paymaster_pay_type": "PayTypeERC20", "access_erc20": "USDT,USDC", "access_project": "official" }, "Optimism_Sepolia_v06_verifyPaymaster": { "network": "optimism-sepolia", - "entrypoint_address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", "entrypoint_version": "v0.6", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "paymaster_pay_type": "PayTypeVerifying", "access_project": "official" }, "Optimism_Sepolia_v07_verifyPaymaster": { "network": "optimism-sepolia", - "entrypoint_address": "0x0000000071727De22E5E9d8BAf0edAc6f37da032", "entrypoint_version": "v0.7", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "paymaster_pay_type": "PayTypeVerifying", "access_project": "official" }, "Optimism_Sepolia_v06_erc20Paymaster": { "network": "optimism-sepolia", - "entrypoint_address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", "entrypoint_version": "v0.6", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "paymaster_pay_type": "PayTypeERC20", "access_erc20": "USDT,USDC", "access_project": "official" }, "Optimism_Sepolia_v07_erc20Paymaster": { "network": "optimism-sepolia", - "entrypoint_address": "0x0000000071727De22E5E9d8BAf0edAc6f37da032", "entrypoint_version": "v0.7", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "paymaster_pay_type": "PayTypeERC20", "access_erc20": "USDT,USDC", "access_project": "official" }, "Arbitrum_Sepolia_v06_verifyPaymaster": { "network": "arbitrum-sepolia", - "entrypoint_address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", "entrypoint_version": "v0.6", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "paymaster_pay_type": "PayTypeVerifying", "access_project": "official" }, "Arbitrum_Sepolia_v06_erc20Paymaster": { "network": "arbitrum-sepolia", - "entrypoint_address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", "entrypoint_version": "v0.6", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "paymaster_pay_type": "PayTypeERC20", "access_erc20": "USDT,USDC", "access_project": "official" }, "Arbitrum_Sepolia_v07_verifyPaymaster": { "network": "arbitrum-sepolia", - "entrypoint_address": "0x0000000071727De22E5E9d8BAf0edAc6f37da032", "entrypoint_version": "v0.7", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "paymaster_pay_type": "PayTypeVerifying", "access_project": "official" }, "Arbitrum_Sepolia_v07_erc20Paymaster": { "network": "arbitrum-sepolia", - "entrypoint_address": "0x0000000071727De22E5E9d8BAf0edAc6f37da032", "entrypoint_version": "v0.7", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "paymaster_pay_type": "PayTypeERC20", "access_erc20": "USDT,USDC", "access_project": "official" }, "Scroll_Sepolia_v06_verifyPaymaster": { "network": "scroll-sepolia", - "entrypoint_address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", "entrypoint_version": "v0.6", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0x0Fa9ee28202F8602E9a4C99Af799C75C29AFbC89", "paymaster_pay_type": "PayTypeVerifying", "access_project": "official" }, "Scroll_Sepolia_v06_erc20Paymaster": { "network": "scroll-sepolia", - "entrypoint_address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", "entrypoint_version": "v0.6", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0x0Fa9ee28202F8602E9a4C99Af799C75C29AFbC89", "paymaster_pay_type": "PayTypeERC20", "access_erc20": "USDT,USDC", "access_project": "official" }, "Scroll_Sepolia_v07_verifyPaymaster": { "network": "scroll-sepolia", - "entrypoint_address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", "entrypoint_version": "v0.7", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "paymaster_pay_type": "PayTypeVerifying", "access_project": "official" }, "Scroll_Sepolia_v07_erc20Paymaster": { "network": "scroll-sepolia", - "entrypoint_address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", "entrypoint_version": "v0.7", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xF2147CA7f18e8014b76e1A98BaffC96ebB90a29f", "paymaster_pay_type": "PayTypeERC20", "access_erc20": "USDT,USDC", "access_project": "official" }, "Base_Sepolia_v06_verifyPaymaster": { "network": "base-sepolia", - "entrypoint_address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", "entrypoint_version": "v0.6", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xa86cFf572E299B2704FBBCF77dcbbc7FEfFbcA06", "paymaster_pay_type": "PayTypeVerifying", "access_project": "official" }, "Base_Sepolia_v07_verifyPaymaster": { "network": "base-sepolia", - "entrypoint_address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", "entrypoint_version": "v0.7", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xa86cFf572E299B2704FBBCF77dcbbc7FEfFbcA06", "paymaster_pay_type": "PayTypeVerifying", "access_project": "official" }, "Base_Sepolia_v06_erc20Paymaster": { "network": "base-sepolia", - "entrypoint_address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", "entrypoint_version": "v0.6", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xa86cFf572E299B2704FBBCF77dcbbc7FEfFbcA06", "paymaster_pay_type": "PayTypeERC20", "access_erc20": "USDT,USDC", "access_project": "official" }, "Base_Sepolia_v07_erc20Paymaster": { "network": "base-sepolia", - "entrypoint_address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", "entrypoint_version": "v0.7", "effective_start_time": "1710044496", "effective_end_time": "1820044496", - "paymaster_address": "0xa86cFf572E299B2704FBBCF77dcbbc7FEfFbcA06", "paymaster_pay_type": "PayTypeERC20", "access_erc20": "USDT,USDC", "access_project": "official" diff --git a/config/config.go b/config/config.go new file mode 100644 index 00000000..74b46283 --- /dev/null +++ b/config/config.go @@ -0,0 +1,7 @@ +package config + +func InitConfig(basicStrategyPath string, basicConfigPath string, secretconfig string) { + secretConfigInit(secretconfig) + basicStrategyInit(basicStrategyPath) + basicConfigInit(basicConfigPath) +} diff --git a/config/config_test.go b/config/config_test.go index 999830c9..6740b9c5 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -5,9 +5,15 @@ import ( "testing" ) +func TestSecretConfigInit(t *testing.T) { + secretConfigInit("../config/secret_config.json") + config := GetNetworkSecretConfig(global_const.EthereumSepolia) + t.Log(config.RpcUrl) + t.Log(config.SignerKey) + t.Log(GetSigner(global_const.EthereumSepolia).Address.Hex()) +} func TestConfigInit(t *testing.T) { - BasicStrategyInit("../config/basic_strategy_dev_config.json") - BusinessConfigInit("../config/business_dev_config.json") + InitConfig("../config/basic_strategy_config.json", "../config/basic_config.json", "../config/secret_config.json") strategy := GetBasicStrategyConfig("Ethereum_Sepolia_v06_verifyPaymaster") if strategy == nil { t.Error("strategy is nil") @@ -29,7 +35,7 @@ func TestConfigInit(t *testing.T) { t.Error("chainid is 0") } t.Log(chainId) - rpcUrl := GetEthereumRpcUrl(global_const.EthereumSepolia) + rpcUrl := GetNewWorkClientURl(global_const.EthereumSepolia) if rpcUrl == "" { t.Error("rpcUrl is 0") } diff --git a/config/secret_config.go b/config/secret_config.go new file mode 100644 index 00000000..9148b405 --- /dev/null +++ b/config/secret_config.go @@ -0,0 +1,56 @@ +package config + +import ( + "AAStarCommunity/EthPaymaster_BackService/common/global_const" + "AAStarCommunity/EthPaymaster_BackService/common/model" + "encoding/json" + "fmt" + "os" +) + +var secretConfig *model.SecretConfig +var signerConfig = make(SignerConfigMap) + +type SignerConfigMap map[global_const.Network]*global_const.EOA + +func secretConfigInit(secretConfigPath string) { + if secretConfigPath == "" { + panic("secretConfigPath is empty") + } + file, err := os.Open(secretConfigPath) + if err != nil { + panic(err) + } + decoder := json.NewDecoder(file) + var config model.SecretConfig + err = decoder.Decode(&config) + if err != nil { + panic(fmt.Sprintf("parse file error: %s", err)) + } + secretConfig = &config + for network, originNetWorkConfig := range secretConfig.NetWorkSecretConfigMap { + signerKey := originNetWorkConfig.SignerKey + eoa, err := global_const.NewEoa(signerKey) + if err != nil { + panic(fmt.Sprintf("signer key error: %s", err)) + } + + signerConfig[global_const.Network(network)] = eoa + } +} +func GetNetworkSecretConfig(network global_const.Network) model.NetWorkSecretConfig { + return secretConfig.NetWorkSecretConfigMap[string(network)] +} + +func GetPriceOracleApiKey() string { + return secretConfig.PriceOracleApiKey +} +func GetNewWorkClientURl(network global_const.Network) string { + return secretConfig.NetWorkSecretConfigMap[string(network)].RpcUrl +} +func GetSignerKey(network global_const.Network) string { + return secretConfig.NetWorkSecretConfigMap[string(network)].SignerKey +} +func GetSigner(network global_const.Network) *global_const.EOA { + return signerConfig[network] +} diff --git a/envirment/app_config.go b/envirment/app_config.go index 7ee00306..bbc91bd5 100644 --- a/envirment/app_config.go +++ b/envirment/app_config.go @@ -44,7 +44,7 @@ func GetAppConf() *Conf { func getConfFilePath() *string { path := fmt.Sprintf("conf/appsettings.%s.yaml", strings.ToLower(Environment.Name)) if _, err := os.Stat(path); err != nil && os.IsNotExist(err) { - path = fmt.Sprintf("conf/appsettings.yaml") + path = fmt.Sprintf("config/appsettings.yaml") } return &path } diff --git a/gas_executor/gas_computor_test.go b/gas_executor/gas_computor_test.go index 12e75354..b7bfcad8 100644 --- a/gas_executor/gas_computor_test.go +++ b/gas_executor/gas_computor_test.go @@ -7,6 +7,7 @@ import ( "AAStarCommunity/EthPaymaster_BackService/common/user_op" "AAStarCommunity/EthPaymaster_BackService/common/utils" "AAStarCommunity/EthPaymaster_BackService/config" + "AAStarCommunity/EthPaymaster_BackService/service/dashboard_service" "encoding/json" "github.com/sirupsen/logrus" "math/big" @@ -42,8 +43,7 @@ func TestComputeGas(t *testing.T) { //assert.NotNil(t, gas) //jsonBypte, _ := json.Marshal(gas) //fmt.Println(string(jsonBypte)) - config.BasicStrategyInit("../config/basic_strategy_dev_config.json") - config.BusinessConfigInit("../config/business_dev_config.json") + config.InitConfig("../config/basic_strategy_config.json", "../config/basic_config.json", "../config/secret_config.json") logrus.SetLevel(logrus.DebugLevel) op, err := user_op.NewUserOp(utils.GenerateMockUservOperation()) if err != nil { @@ -70,14 +70,18 @@ func TestComputeGas(t *testing.T) { { "testEstimateVerificationGasLimit", func(*testing.T) { - strategy := config.GetBasicStrategyConfig("Ethereum_Sepolia_v06_verifyPaymaster") + strategy := dashboard_service.GetStrategyByCode("Ethereum_Sepolia_v06_verifyPaymaster") + if strategy == nil { + t.Fatal("strategy is nil") + } testGetUserOpEstimateGas(t, op, strategy) }, }, { "testScrollGetUserOpEstimateGas", func(*testing.T) { - strategy := config.GetBasicStrategyConfig(global_const.StrategyCodeScrollSepoliaV06Verify) + + strategy := dashboard_service.GetStrategyByCode(string(global_const.StrategyCodeScrollSepoliaV06Verify)) testGetUserOpEstimateGas(t, opFor1559NotSupport, strategy) }, diff --git a/gas_executor/gas_validate.go b/gas_executor/gas_validate.go index f5b40252..06fdc274 100644 --- a/gas_executor/gas_validate.go +++ b/gas_executor/gas_validate.go @@ -10,24 +10,27 @@ import ( ) var ( - GasValidateFuncMap = map[global_const.PayType]ValidatePaymasterGasFunc{} -) - -func init() { - GasValidateFuncMap[global_const.PayTypeVerifying] = VerifyingGasValidate() - GasValidateFuncMap[global_const.PayTypeERC20] = Erc20GasValidate() - GasValidateFuncMap[global_const.PayTypeSuperVerifying] = SuperGasValidate() -} - -type ValidatePaymasterGasFunc = func(userOp *user_op.UserOpInput, gasComputeResponse *model.ComputeGasResponse, strategy *model.Strategy) error + gasValidateFuncMap = map[global_const.PayType]ValidatePaymasterGasFunc{} + verifyingGasValidateFunc = func(userOp *user_op.UserOpInput, gasComputeResponse *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 -func SuperGasValidate() ValidatePaymasterGasFunc { - return func(userOp *user_op.UserOpInput, gasComputeResponse *model.ComputeGasResponse, strategy *model.Strategy) error { - return xerrors.Errorf("never reach here") + //check EntryPoint paymasterAddress balance + balance, err := chain_service.GetPaymasterEntryPointBalance(strategy) + if err != nil { + return err + } + // if balance < 0 + if balance.Cmp(big.NewFloat(0)) < 0 { + return xerrors.Errorf("paymaster EntryPoint balance < 0") + } + etherCost := gasComputeResponse.TotalGasDetail.MaxTxGasCostInEther + if balance.Cmp(etherCost) < 0 { + return xerrors.Errorf("paymaster EntryPoint Not Enough balance %s < %s", balance, etherCost) + } + return nil } -} -func Erc20GasValidate() ValidatePaymasterGasFunc { - return func(userOp *user_op.UserOpInput, gasComputeResponse *model.ComputeGasResponse, strategy *model.Strategy) error { + erc20GasValidateFunc = func(userOp *user_op.UserOpInput, gasComputeResponse *model.ComputeGasResponse, strategy *model.Strategy) error { userOpValue := *userOp sender := userOpValue.Sender tokenBalance, getTokenBalanceErr := chain_service.GetAddressTokenBalance(strategy.GetNewWork(), *sender, strategy.Erc20TokenType) @@ -41,26 +44,19 @@ func Erc20GasValidate() ValidatePaymasterGasFunc { } return nil } -} -func VerifyingGasValidate() ValidatePaymasterGasFunc { - return func(userOp *user_op.UserOpInput, gasComputeResponse *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 + superGasValidateFunc = func(userOp *user_op.UserOpInput, gasComputeResponse *model.ComputeGasResponse, strategy *model.Strategy) error { + return xerrors.Errorf("never reach here") + } +) - //check EntryPoint paymasterAddress balance - balance, err := chain_service.GetPaymasterEntryPointBalance(strategy) - if err != nil { - return err - } - // if balance < 0 - if balance.Cmp(big.NewFloat(0)) < 0 { - return xerrors.Errorf("paymaster EntryPoint balance < 0") - } - ethercost := gasComputeResponse.TotalGasDetail.MaxTxGasCostInEther - if balance.Cmp(ethercost) < 0 { - return xerrors.Errorf("paymaster EntryPoint Not Enough balance %s < %s", balance, ethercost) - } - return nil +func init() { + gasValidateFuncMap[global_const.PayTypeVerifying] = verifyingGasValidateFunc + gasValidateFuncMap[global_const.PayTypeERC20] = erc20GasValidateFunc + gasValidateFuncMap[global_const.PayTypeSuperVerifying] = superGasValidateFunc +} - } +func GetGasValidateFunc(payType global_const.PayType) ValidatePaymasterGasFunc { + return gasValidateFuncMap[payType] } + +type ValidatePaymasterGasFunc = func(userOp *user_op.UserOpInput, gasComputeResponse *model.ComputeGasResponse, strategy *model.Strategy) error diff --git a/go.mod b/go.mod index 8aa628ba..7cb8bb9e 100644 --- a/go.mod +++ b/go.mod @@ -25,12 +25,26 @@ require ( github.com/NethermindEth/juno v0.3.1 // indirect github.com/fxamacker/cbor/v2 v2.4.0 // indirect github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect + github.com/hashicorp/hcl v1.0.0 // indirect github.com/holiman/uint256 v1.2.4 // indirect github.com/huin/goupnp v1.3.0 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect + github.com/joho/godotenv v1.5.1 // indirect + github.com/magiconair/properties v1.8.7 // indirect + github.com/sagikazarmark/locafero v0.4.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect + github.com/spf13/afero v1.11.0 // indirect + github.com/spf13/cast v1.6.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/spf13/viper v1.18.2 // indirect + github.com/subosito/gotenv v1.6.0 // indirect github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect github.com/test-go/testify v1.1.4 // indirect github.com/x448/float16 v0.8.4 // indirect + go.uber.org/atomic v1.10.0 // indirect + go.uber.org/multierr v1.9.0 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect ) require ( @@ -44,7 +58,7 @@ require ( github.com/consensys/bavard v0.1.13 // indirect github.com/consensys/gnark-crypto v0.12.1 // indirect github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect; indirect(force degrade) - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect github.com/ethereum/c-kzg-4844 v0.4.0 // indirect; indirect (force degrade) github.com/fsnotify/fsnotify v1.7.0 // indirect @@ -71,7 +85,7 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.2.0 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/shirou/gopsutil v3.21.11+incompatible // indirect github.com/supranational/blst v0.3.11 // indirect github.com/tklauser/go-sysconf v0.3.13 // indirect diff --git a/go.sum b/go.sum index 5abdcf91..06e7de14 100644 --- a/go.sum +++ b/go.sum @@ -60,6 +60,8 @@ github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXk github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM= github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= @@ -149,6 +151,8 @@ github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/ github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE= github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 h1:X4egAf/gcS1zATw6wn4Ej8vjuVGxeHdan+bRb2ebyv4= github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= @@ -162,6 +166,8 @@ github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7Bd github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= @@ -182,6 +188,8 @@ github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7 github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -224,6 +232,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.12.0 h1:C+UIj/QWtmqY13Arb8kwMt5j34/0Z2iKamrJ+ryC0Gg= github.com/prometheus/client_golang v1.12.0/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a h1:CmF68hwI0XsOQ5UwlBopMi2Ow4Pbg32akc4KIVCOm+Y= @@ -240,10 +250,24 @@ github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= +github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -258,6 +282,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE= @@ -295,6 +321,10 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsr github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= +go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= +go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc= golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= @@ -378,6 +408,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= diff --git a/service/chain_service/chain_service_test.go b/service/chain_service/chain_service_test.go index 79e16711..0363e396 100644 --- a/service/chain_service/chain_service_test.go +++ b/service/chain_service/chain_service_test.go @@ -19,8 +19,8 @@ import ( ) func TestChainService(t *testing.T) { - config.BasicStrategyInit("../../config/basic_strategy_dev_config.json") - config.BusinessConfigInit("../../config/business_dev_config.json") + + config.InitConfig("../../config/basic_strategy_config.json", "../../config/basic_config.json", "../../config/secret_config.json") logrus.SetLevel(logrus.DebugLevel) op, err := user_op.NewUserOp(utils.GenerateMockUservOperation()) if err != nil { diff --git a/service/dashboard_service/dashboard_service.go b/service/dashboard_service/dashboard_service.go index 63ccef8d..a49ea4f3 100644 --- a/service/dashboard_service/dashboard_service.go +++ b/service/dashboard_service/dashboard_service.go @@ -8,7 +8,12 @@ import ( ) func GetStrategyByCode(strategyCode string) *model.Strategy { - return config.GetBasicStrategyConfig(global_const.BasicStrategyCode(strategyCode)) + strategy := config.GetBasicStrategyConfig(global_const.BasicStrategyCode(strategyCode)) + paymasterAddress := config.GetPaymasterAddress(strategy.GetNewWork(), strategy.GetStrategyEntrypointVersion()) + strategy.PaymasterInfo.PayMasterAddress = &paymasterAddress + entryPointAddress := config.GetEntrypointAddress(strategy.GetNewWork(), strategy.GetStrategyEntrypointVersion()) + strategy.EntryPointInfo.EntryPointAddress = &entryPointAddress + return strategy } func GetSuitableStrategy(entryPointVersion global_const.EntrypointVersion, chain global_const.Network, payType global_const.PayType) (*model.Strategy, error) { @@ -23,6 +28,10 @@ func GetSuitableStrategy(entryPointVersion global_const.EntrypointVersion, chain if strategy == nil { return nil, errors.New("strategy not found") } + paymasterAddress := config.GetPaymasterAddress(strategy.GetNewWork(), strategy.GetStrategyEntrypointVersion()) + strategy.PaymasterInfo.PayMasterAddress = &paymasterAddress + entryPointAddress := config.GetEntrypointAddress(strategy.GetNewWork(), strategy.GetStrategyEntrypointVersion()) + strategy.EntryPointInfo.EntryPointAddress = &entryPointAddress return strategy, nil } diff --git a/service/operator/operator_test.go b/service/operator/operator_test.go index 35b67626..c712aebb 100644 --- a/service/operator/operator_test.go +++ b/service/operator/operator_test.go @@ -16,8 +16,8 @@ import ( ) func TestOperator(t *testing.T) { - config.BasicStrategyInit("../../config/basic_strategy_dev_config.json") - config.BusinessConfigInit("../../config/business_dev_config.json") + + config.InitConfig("../../config/basic_strategy_config.json", "../../config/basic_config.json", "../../config/secret_config.json") logrus.SetLevel(logrus.DebugLevel) immutableRequest := getMockTryPayUserOpRequest() mockRequestNotSupport1559 := getMockTryPayUserOpRequest() diff --git a/service/operator/try_pay_user_op_execute.go b/service/operator/try_pay_user_op_execute.go index e6c5db47..0981134d 100644 --- a/service/operator/try_pay_user_op_execute.go +++ b/service/operator/try_pay_user_op_execute.go @@ -78,7 +78,7 @@ func estimateGas(userOp *user_op.UserOpInput, strategy *model.Strategy, paymaste } func ValidateGas(userOp *user_op.UserOpInput, gasComputeResponse *model.ComputeGasResponse, strategy *model.Strategy) error { - validateFunc := gas_executor.GasValidateFuncMap[strategy.GetPayType()] + validateFunc := gas_executor.GetGasValidateFunc(strategy.GetPayType()) err := validateFunc(userOp, gasComputeResponse, strategy) if err != nil { return err