Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paymaster optimize remove jwt #27

Merged
merged 46 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
84502e7
update go.mod
cherry-yl-sh May 13, 2024
c80f2b1
update relay model
cherry-yl-sh May 17, 2024
45a67c0
update relay model
cherry-yl-sh May 17, 2024
f863ebf
Strategy Restriction
cherry-yl-sh May 20, 2024
4f6cae7
Strategy Restriction
cherry-yl-sh May 21, 2024
1d82fee
Strategy Restriction
cherry-yl-sh May 21, 2024
1e8de6f
mod init add DeleteAt
cherry-yl-sh May 21, 2024
317455d
go mod init
cherry-yl-sh May 21, 2024
69d948b
optimize API
cherry-yl-sh May 21, 2024
2a1f57e
optimize API
cherry-yl-sh May 21, 2024
1d26e1b
Merge remote-tracking branch 'origin/dylan/config_interate' into gas_…
cherry-yl-sh May 21, 2024
7b1c01d
Gas Tank
cherry-yl-sh May 21, 2024
37e82f1
Merge remote-tracking branch 'origin/main' into gas_tank_v1
cherry-yl-sh May 21, 2024
0b9f00f
update merge
cherry-yl-sh May 21, 2024
2d8fcb5
add DB
cherry-yl-sh May 23, 2024
2498654
add DB
cherry-yl-sh May 23, 2024
e7cf691
add Sponsor
cherry-yl-sh May 24, 2024
499de5e
update Sponsor
cherry-yl-sh May 24, 2024
3f6e98e
update Sponsor
cherry-yl-sh May 27, 2024
c4141cf
Fix Float Problem
cherry-yl-sh May 27, 2024
9754d6d
update Sponsor
cherry-yl-sh May 28, 2024
3d9736b
update Sponsor
cherry-yl-sh May 28, 2024
2ab2e64
update Sponsor
cherry-yl-sh May 28, 2024
7c79240
update Sponsor
cherry-yl-sh May 28, 2024
cdc3a21
add Paymaster Mertics Log
cherry-yl-sh May 29, 2024
12d8c55
add Paymaster Mertics Log
cherry-yl-sh May 29, 2024
f99e5e4
resolve Comment
cherry-yl-sh Jun 4, 2024
6c60da7
Merge branch 'main' into monitor_and_optimize
cherry-yl-sh Jun 5, 2024
3c1391f
resolve Comment
cherry-yl-sh Jun 5, 2024
0bc2ba2
resolve Comment
cherry-yl-sh Jun 5, 2024
e679ad7
update
cherry-yl-sh Jun 6, 2024
17efd31
Merge branch 'main' into paymaster_optimize_remove_jwt
cherry-yl-sh Jun 6, 2024
1bd6aa1
remove AUth
cherry-yl-sh Jun 6, 2024
b9830dc
update Deposit
cherry-yl-sh Jun 7, 2024
2fcf3ca
update Deposit
cherry-yl-sh Jun 14, 2024
605c33c
update WithDraw
cherry-yl-sh Jun 15, 2024
9474418
update WithDraw
cherry-yl-sh Jun 15, 2024
56fc09f
update WithDraw
cherry-yl-sh Jun 16, 2024
130a092
Merge branch 'main' into paymaster_optimize_remove_jwt
cherry-yl-sh Jun 16, 2024
3017c31
update WithDraw
cherry-yl-sh Jun 16, 2024
9d73507
update error Guide
cherry-yl-sh Jun 16, 2024
3ee9e00
update error Guide
cherry-yl-sh Jun 17, 2024
1c41e80
update error Guide
cherry-yl-sh Jun 17, 2024
ef40144
update Auth Test
cherry-yl-sh Jun 17, 2024
663872d
fix Test
cherry-yl-sh Jun 17, 2024
eefe6e3
fix Test
cherry-yl-sh Jun 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ var Engine *gin.Engine

// @contact.name AAStar Support
// @contact.url https://aastar.xyz
// @securityDefinitions.apikey JWT
// @in header
// @name Authorization
// @description Type 'Bearer \<TOKEN\>' to correctly set the AccessToken
// @BasePath /api
func main() {
secretPath := os.Getenv("secret_config_path")
Expand All @@ -61,7 +57,6 @@ func main() {
}

func initEngine(strategyPath string, basicConfigPath string, secretPath string) {

logrus.Infof("secretPath: %s", secretPath)
config.InitConfig(strategyPath, basicConfigPath, secretPath)
if envirment.Environment.IsDevelopment() {
Expand Down
20 changes: 15 additions & 5 deletions common/model/secret_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ type SecretConfig struct {

NetWorkSecretConfigMap map[string]NetWorkSecretConfig `json:"network_secret_configs"`

ConfigDBConfig DBConfig `json:"config_db_config"`
RelayDBConfig DBConfig `json:"relay_db_config"`
ApiKeyTableName string `json:"api_key_table_name"`
StrategyConfigTableName string `json:"strategy_config_table_name"`
FreeSponsorWhitelist []string `json:"free_sponsor_whitelist"`
ConfigDBConfig DBConfig `json:"config_db_config"`
RelayDBConfig DBConfig `json:"relay_db_config"`
ApiKeyTableName string `json:"api_key_table_name"`
StrategyConfigTableName string `json:"strategy_config_table_name"`
FreeSponsorWhitelist []string `json:"free_sponsor_whitelist"`
SponsorConfig SponsorConfig `json:"sponsor_config"`
}
type SponsorConfig struct {
SponsorDepositAddress string `json:"sponsor_deposit_address"`
SponsorDepositPrivateKey string `json:"sponsor_deposit_private_key"`
DashBoardSignerAddress string `json:"dashboard_signer_address"`
DepositTestNetUrl string `json:"deposit_test_net_url"`
DepositMainNetUrl string `json:"deposit_main_net_url"`
SponsorTestClientUrl string `json:"sponsor_client_rpc_test_net"`
SponsorMainClientUrl string `json:"sponsor_client_rpc_main_net"`
}

type NetWorkSecretConfig struct {
Expand Down
35 changes: 13 additions & 22 deletions common/model/sponsor.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
package model

import "math/big"

type DepositSponsorRequest struct {
Source string `json:"source"`
Amount *big.Float `json:"amount"`
TxHash string `json:"tx_hash"`

TxInfo map[string]string `json:"tx_info"`
PayUserId string `json:"pay_user_id"`
IsTestNet bool `json:"is_test_net"`
TimeStamp int64 `json:"time_stamp"`
DepositAddress string `json:"deposit_address"`
TxHash string `json:"tx_hash"`
IsTestNet bool `json:"is_test_net"`
PayUserId string `json:"pay_user_id"`
DepositSource string `json:"deposit_source"`
}
type WithdrawSponsorRequest struct {
Amount *big.Float

PayUserId string
IsTestNet bool
TxInfo map[string]string
TxHash string
}
type GetSponsorTransactionsRequest struct {
}
type GetSponsorMetaDataRequest struct {
}

type Transaction struct {
Amount float64 `json:"amount"`
TimeStamp int64 `json:"time_stamp"`
PayUserId string `json:"pay_user_id"`
IsTestNet bool `json:"is_test_net"`
WithdrawSource string `json:"withdraw_source"`
RefundAddress string `json:"refund_address"`
DepositSource string `json:"deposit_source"`
}
64 changes: 59 additions & 5 deletions common/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ package utils
import (
"AAStarCommunity/EthPaymaster_BackService/common/global_const"
"bytes"
"context"
"crypto/ecdsa"
"encoding/hex"
"fmt"
mapset "github.com/deckarep/golang-set/v2"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
"github.com/sirupsen/logrus"
"golang.org/x/xerrors"
"gorm.io/gorm"
"log"
"math/big"
"regexp"
"runtime"
Expand All @@ -24,7 +28,7 @@ import (

var HexPattern = regexp.MustCompile(`^0x[a-fA-F\d]*$`)

const defaultStackSize = 4096
const defaultStackSize = 10000

type EthCallReq struct {
From common.Address `json:"from"`
Expand Down Expand Up @@ -164,6 +168,11 @@ func ConvertBalanceToEther(balance *big.Int) *big.Float {
balanceFloat = new(big.Float).Quo(balanceFloat, global_const.EthWeiFactor)
return balanceFloat
}
func CounverEtherToWei(ether *big.Float) *big.Int {
afterEther := ether.Mul(ether, global_const.EthWeiFactor)
afterEtherInt, _ := afterEther.Int(nil)
return afterEtherInt
}
func ConvertStringToSet(input string, split string) mapset.Set[string] {
set := mapset.NewSet[string]()
arr := strings.Split(input, split)
Expand Down Expand Up @@ -202,18 +211,63 @@ func GetCurrentGoroutineStack() string {
n := runtime.Stack(buf[:], false)
return string(buf[:n])
}
func DBTransactional(db *gorm.DB, handle func() error) (err error) {
func DBTransactional(db *gorm.DB, handle func(tx *gorm.DB) error) (err error) {
cherry-yl-sh marked this conversation as resolved.
Show resolved Hide resolved
tx := db.Begin()
defer func() {
if p := recover(); p != nil {
tx.Rollback()
panic(p)
logrus.Errorf("TX ERROR [%s] ", GetCurrentGoroutineStack())
err = xerrors.Errorf("TX ERROR [%v]", p)
//panic(p)
} else if err != nil {
tx.Rollback()
} else {
err = tx.Commit().Error
}
}()
err = handle()
return
err = handle(tx)
return err
}

func TransEth(from *ecdsa.PrivateKey, toAddress *common.Address, client *ethclient.Client, amount *big.Int, chainID *big.Int) (*types.Transaction, error) {
fromPrivateKey := from.Public()
fromPublicKeyECDSA, ok := fromPrivateKey.(*ecdsa.PublicKey)
if !ok {
logrus.Error("error casting public key to ECDSA")
return nil, xerrors.Errorf("error casting public key to ECDSA")
}
fromAddress := crypto.PubkeyToAddress(*fromPublicKeyECDSA)
nonce, err := client.PendingNonceAt(context.Background(), fromAddress)
if err != nil {
return nil, err

}
gasLimit := uint64(21000) // in units
gasPrice, err := client.SuggestGasPrice(context.Background())
if err != nil {
return nil, err
}

var data []byte
tx := types.NewTx(&types.DynamicFeeTx{

Nonce: nonce,
Data: data,
Gas: gasLimit,
GasFeeCap: gasPrice,
GasTipCap: gasPrice,
Value: amount,
To: toAddress,
})

signTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), from)

if err != nil {
log.Fatal(err)
}
err = client.SendTransaction(context.Background(), signTx)
if err != nil {
log.Fatal(err)
}
return signTx, nil
}
4 changes: 0 additions & 4 deletions config/appsettings.yaml

This file was deleted.

58 changes: 58 additions & 0 deletions config/secret_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,44 @@ package config
import (
"AAStarCommunity/EthPaymaster_BackService/common/global_const"
"AAStarCommunity/EthPaymaster_BackService/common/model"
"context"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/ethclient"
"math/big"
"os"
)

var dsnTemplate = "host=%s port=%v user=%s password=%s dbname=%s TimeZone=%s sslmode=%s"

var secretConfig *model.SecretConfig
var signerConfig = make(SignerConfigMap)
var depositer *global_const.EOA

var sponsorTestNetClient *ethclient.Client
var sponsorTestNetClientChainId *big.Int
var sponsorMainNetClient *ethclient.Client
var sponsorMainNetClinetChainId *big.Int

func GetPaymasterSponsorClient(isTestNet bool) *ethclient.Client {
if isTestNet {
return sponsorTestNetClient

}
return sponsorMainNetClient
}
func GetPaymasterSponsorChainId(isTestNet bool) *big.Int {
if isTestNet {
return sponsorTestNetClientChainId
}
return sponsorMainNetClinetChainId
}

type SignerConfigMap map[global_const.Network]*global_const.EOA

func GetDepositer() *global_const.EOA {
return depositer
}
func secretConfigInit(secretConfigPath string) {
if secretConfigPath == "" {
panic("secretConfigPath is empty")
Expand All @@ -39,7 +65,35 @@ func secretConfigInit(secretConfigPath string) {

signerConfig[global_const.Network(network)] = eoa
}
depositer, err = global_const.NewEoa(secretConfig.SponsorConfig.SponsorDepositPrivateKey)
if err != nil {
panic(fmt.Sprintf("signer key error: %s", err))
}

paymasterSponsorMainNetClient, err := ethclient.Dial(secretConfig.SponsorConfig.SponsorMainClientUrl)
cherry-yl-sh marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
panic(fmt.Sprintf("paymaster inner client error: %s", err))
}
paymasterInnerClientChainId, err := paymasterSponsorMainNetClient.ChainID(context.Background())
if err != nil {
panic(fmt.Sprintf("paymaster inner client chain id error: %s", err))
}
sponsorMainNetClient = paymasterSponsorMainNetClient
sponsorMainNetClinetChainId = paymasterInnerClientChainId

paymasterSponsorTestNetClient, err := ethclient.Dial(secretConfig.SponsorConfig.SponsorTestClientUrl)
if err != nil {
panic(fmt.Sprintf("paymaster inner client error: %s", err))
}
paymasterInnerClientChainId, err = paymasterSponsorTestNetClient.ChainID(context.Background())
if err != nil {
panic(fmt.Sprintf("paymaster inner client chain id error: %s", err))
}
sponsorTestNetClient = paymasterSponsorTestNetClient
sponsorTestNetClientChainId = paymasterInnerClientChainId

}

func IsSponsorWhitelist(address string) bool {

//TODO
Expand Down Expand Up @@ -68,6 +122,10 @@ func GetSigner(network global_const.Network) *global_const.EOA {
func GetAPIKeyTableName() string {
return secretConfig.ApiKeyTableName
}
func GetSponsorConfig() *model.SponsorConfig {
//TODO
return &secretConfig.SponsorConfig
}
func GetStrategyConfigTableName() string {
return secretConfig.StrategyConfigTableName
}
Expand Down
Loading
Loading