-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab09981
commit 00ebc7d
Showing
14 changed files
with
203 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
paymaster_data_generator/vertifying_paymaster_generator.go
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.