Skip to content

Commit

Permalink
Merge branch 'price'
Browse files Browse the repository at this point in the history
# Conflicts:
#	go.mod
#	go.sum
#	tables/t_smt_record_info.go
  • Loading branch information
scorpiotzh committed Oct 8, 2023
2 parents 8ad3c5b + 6c6f79b commit 75ea76f
Show file tree
Hide file tree
Showing 25 changed files with 517 additions and 99 deletions.
2 changes: 1 addition & 1 deletion block_parser/das_action_create_sub_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (b *BlockParser) DasActionCreateSubAccount(req FuncTransactionHandleReq) (r
// add task and smt records
if selfTask.TaskId != "" {
// maybe rollback
if err := b.DbDao.UpdateToChainTask(selfTask.TaskId, req.BlockNumber); err != nil {
if err := b.DbDao.UpdateToChainTask(selfTask.TaskId, req.BlockNumber, 0); err != nil {
resp.Err = fmt.Errorf("UpdateToChainTask err: %s", err.Error())
return
}
Expand Down
2 changes: 1 addition & 1 deletion block_parser/das_action_edit_sub_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (b *BlockParser) DasActionEditSubAccount(req FuncTransactionHandleReq) (res
// add task and smt records
if selfTask.TaskId != "" {
// maybe rollback
if err := b.DbDao.UpdateToChainTask(selfTask.TaskId, req.BlockNumber); err != nil {
if err := b.DbDao.UpdateToChainTask(selfTask.TaskId, req.BlockNumber, 0); err != nil {
resp.Err = fmt.Errorf("UpdateToChainTask err: %s", err.Error())
return
}
Expand Down
14 changes: 11 additions & 3 deletions block_parser/das_action_update_sub_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/dotbitHQ/das-lib/common"
"github.com/dotbitHQ/das-lib/core"
"github.com/dotbitHQ/das-lib/witness"
"github.com/shopspring/decimal"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -40,9 +41,15 @@ func (b *BlockParser) DasActionUpdateSubAccount(req FuncTransactionHandleReq) (r
parentAccountId = common.Bytes2Hex(v.Type.Args)
}
}
// get quote cell
quote, err := b.DasCore.GetTxQuote(req.Tx)
if err != nil {
resp.Err = fmt.Errorf("GetTxQuote err: %s", err.Error())
return
}

// get task , smt-record
taskInfo, smtRecordList, err := b.getTaskAndSmtRecordsNew(b.Slb, &req, parentAccountId, refOutpoint, outpoint)
taskInfo, smtRecordList, err := b.getTaskAndSmtRecordsNew(b.Slb, &req, parentAccountId, refOutpoint, outpoint, quote)
if err != nil {
resp.Err = fmt.Errorf("getTaskAndSmtRecordsNew err: %s", err.Error())
return
Expand All @@ -57,7 +64,7 @@ func (b *BlockParser) DasActionUpdateSubAccount(req FuncTransactionHandleReq) (r

// add task and smt records
if selfTask.TaskId != "" {
if err := b.DbDao.UpdateToChainTask(selfTask.TaskId, req.BlockNumber); err != nil {
if err := b.DbDao.UpdateToChainTask(selfTask.TaskId, req.BlockNumber, quote); err != nil {
resp.Err = fmt.Errorf("UpdateToChainTask err: %s", err.Error())
return
}
Expand Down Expand Up @@ -194,7 +201,7 @@ func (b *BlockParser) getOutpoint(req FuncTransactionHandleReq, dasContractName
return refOutpoint, outpoint, nil
}

func (b *BlockParser) getTaskAndSmtRecordsNew(slb *lb.LoadBalancing, req *FuncTransactionHandleReq, parentAccountId, refOutpoint, outpoint string) (*tables.TableTaskInfo, []tables.TableSmtRecordInfo, error) {
func (b *BlockParser) getTaskAndSmtRecordsNew(slb *lb.LoadBalancing, req *FuncTransactionHandleReq, parentAccountId, refOutpoint, outpoint string, quote uint64) (*tables.TableTaskInfo, []tables.TableSmtRecordInfo, error) {
svrName := ""
if slb != nil {
s := slb.GetServer(parentAccountId)
Expand Down Expand Up @@ -249,6 +256,7 @@ func (b *BlockParser) getTaskAndSmtRecordsNew(slb *lb.LoadBalancing, req *FuncTr
SubAction: v.Action,
MintSignId: "",
ExpiredAt: v.SignExpiredAt,
Quote: decimal.NewFromInt(int64(quote)),
}
switch v.Action {
case common.SubActionCreate:
Expand Down
11 changes: 11 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,14 @@ func GetUnipayAddress(tokenId tables.TokenId) string {
}
return ""
}

func PriceToCKB(price, quote, years uint64) (total uint64) {
log.Info("PriceToCKB:", price, quote, years)
if price > quote {
total = price / quote * common.OneCkb * years
} else {
total = price * common.OneCkb / quote * years
}
log.Info("PriceToCKB:", price, quote, total)
return
}
14 changes: 13 additions & 1 deletion dao/t_smt_record_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,19 @@ func (d *DbDao) FindSmtRecordInfoByActions(parentAccountId string, actions, subA

func (d *DbDao) GetSmtRecordManualMintYears(parentAccountId string) (total uint64, err error) {
err = d.db.Model(&tables.TableSmtRecordInfo{}).Select("IFNULL(sum(register_years+renew_years),0)").
Where("parent_account_id=? and mint_type in (?) and sub_action in (?) and record_type=?",
Where("parent_account_id=? and mint_type in (?) and sub_action in (?) and record_type=? and quote=0",
parentAccountId, []tables.MintType{tables.MintTypeDefault, tables.MintTypeManual},
[]common.DasAction{common.SubActionCreate, common.SubActionRenew}, tables.RecordTypeChain).Scan(&total).Error
if err == gorm.ErrRecordNotFound {
err = nil
}
return
}

func (d *DbDao) GetSmtRecordManualCKB(parentAccountId string) (total uint64, err error) {
err = d.db.Model(&tables.TableSmtRecordInfo{}).
Select("IFNULL(sum(round(990000/quote,0)*(register_years+renew_years)),0)").
Where("parent_account_id=? and mint_type in (?) and sub_action in (?) and record_type=? and quote>0",
parentAccountId, []tables.MintType{tables.MintTypeDefault, tables.MintTypeManual},
[]common.DasAction{common.SubActionCreate, common.SubActionRenew}, tables.RecordTypeChain).Scan(&total).Error
if err == gorm.ErrRecordNotFound {
Expand Down
18 changes: 18 additions & 0 deletions dao/t_sub_account_auto_mint_statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,28 @@ func (d *DbDao) GetLatestSubAccountAutoMintStatementByType(providerId string, tx
return
}

func (d *DbDao) GetLatestSubAccountAutoMintStatementByType2(providerId, parentAccountId string, txType tables.SubAccountAutoMintTxType) (info tables.TableSubAccountAutoMintStatement, err error) {
err = d.parserDb.Where("service_provider_id=? and parent_account_id=? and tx_type=?",
providerId, parentAccountId, txType).Order("id desc").First(&info).Error
if err == gorm.ErrRecordNotFound {
err = nil
}
return
}

func (d *DbDao) FindSubAccountAutoMintStatements(providerId string, txType tables.SubAccountAutoMintTxType, blockNumber uint64) (list []*tables.TableSubAccountAutoMintStatement, err error) {
err = d.parserDb.Where("service_provider_id=? and tx_type=? and block_number > ?", providerId, txType, blockNumber).Find(&list).Error
if err == gorm.ErrRecordNotFound {
err = nil
}
return
}

func (d *DbDao) FindSubAccountAutoMintStatements2(providerId, parentAccountId string, txType tables.SubAccountAutoMintTxType, blockNumber uint64) (list []*tables.TableSubAccountAutoMintStatement, err error) {
err = d.parserDb.Where("service_provider_id=? and parent_account_id=? and tx_type=? and block_number > ?",
providerId, parentAccountId, txType, blockNumber).Find(&list).Error
if err == gorm.ErrRecordNotFound {
err = nil
}
return
}
5 changes: 3 additions & 2 deletions dao/t_task_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (d *DbDao) CreateChainTask(task *tables.TableTaskInfo, list []tables.TableS
})
}

func (d *DbDao) UpdateToChainTask(taskId string, blockNumber uint64) error {
func (d *DbDao) UpdateToChainTask(taskId string, blockNumber, quote uint64) error {
return d.db.Transaction(func(tx *gorm.DB) error {
if err := tx.Model(tables.TableTaskInfo{}).Where("task_id=?", taskId).
Updates(map[string]interface{}{
Expand All @@ -194,7 +194,8 @@ func (d *DbDao) UpdateToChainTask(taskId string, blockNumber uint64) error {
Where("task_id=?", taskId).
Updates(map[string]interface{}{
"record_type": tables.RecordTypeChain,
"RecordBN": blockNumber,
"record_bn": blockNumber,
"quote": quote,
}).Error; err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions example/api_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestInternalSubAccountMint(t *testing.T) {
Account: "10086.bit",
SubAccountList: []handle.CreateSubAccount{
{
Account: "test1.10086.bit",
Account: "test12.10086.bit",
RegisterYears: 1,
ChainTypeAddress: core.ChainTypeAddress{
Type: "blockchain",
Expand All @@ -43,7 +43,7 @@ func TestInternalSubAccountMint(t *testing.T) {
},
},
{
Account: "test2.10086.bit",
Account: "test22.10086.bit",
RegisterYears: 2,
ChainTypeAddress: core.ChainTypeAddress{
Type: "blockchain",
Expand Down
24 changes: 24 additions & 0 deletions example/custom_script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/dotbitHQ/das-lib/molecule"
"github.com/dotbitHQ/das-lib/witness"
"github.com/nervosnetwork/ckb-sdk-go/types"
"github.com/scorpiotzh/toolib"
"testing"
)

Expand All @@ -34,6 +35,7 @@ func TestCustomScript(t *testing.T) {
5: {1000000, 1000000},
},
}
fmt.Println(toolib.JsonString(&req))
var data handle.RespCustomScript
if err := doReq(url, req, &data); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -128,3 +130,25 @@ func TestCustomScriptPrice(t *testing.T) {
}

}

func TestPrice(t *testing.T) {
dc, err := getNewDasCoreTestnet2()
if err != nil {
t.Fatal(err)
}
qCell, err := dc.GetQuoteCell()
if err != nil {
t.Fatal(err)
}
fmt.Println(qCell.Quote())
quote := uint64(12632) //0.012632
yearlyPrice := uint64(12000) //uint64(990000) //0.99
if yearlyPrice < quote {
fmt.Println("<", yearlyPrice*common.OneCkb/quote*1)
//fmt.Println(">", yearlyPrice/quote*common.OneCkb*1)
} else {
//fmt.Println("<", yearlyPrice*common.OneCkb/quote*1)
fmt.Println(">", yearlyPrice/quote*common.OneCkb*1)
}

}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module das_sub_account
go 1.18

require (
github.com/dotbitHQ/das-lib v1.1.1-0.20230915031854-7f69edfd6582
github.com/dotbitHQ/das-lib v1.1.1-0.20231008024610-0511cd287954
github.com/fsnotify/fsnotify v1.5.4
github.com/getsentry/sentry-go v0.24.0
github.com/gin-gonic/gin v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5O
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
github.com/dotbitHQ/das-lib v1.1.1-0.20230915031854-7f69edfd6582 h1:QVovYJfsPq5qRKD0MkOh91+8p8lWdkEFmkh/+/S/c94=
github.com/dotbitHQ/das-lib v1.1.1-0.20230915031854-7f69edfd6582/go.mod h1:bWgGqfGuc9moidjzK7MpC0q80d694ucm0961MEMNiaI=
github.com/dotbitHQ/das-lib v1.1.1-0.20231008024610-0511cd287954 h1:WcuZsczQ6/tm8nSWehmhDiczq0IPV4ZqqfE6Jjyg7bE=
github.com/dotbitHQ/das-lib v1.1.1-0.20231008024610-0511cd287954/go.mod h1:bWgGqfGuc9moidjzK7MpC0q80d694ucm0961MEMNiaI=
github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts=
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 h1:RIB4cRk+lBqKK3Oy0r2gRX4ui7tuhiZq2SuTtTCi0/0=
Expand Down
17 changes: 17 additions & 0 deletions http_server/handle/auto_account_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/dotbitHQ/das-lib/common"
"github.com/dotbitHQ/das-lib/core"
api_code "github.com/dotbitHQ/das-lib/http_api"
"github.com/dotbitHQ/das-lib/molecule"
"github.com/dotbitHQ/das-lib/witness"
"github.com/gin-gonic/gin"
"github.com/nervosnetwork/ckb-sdk-go/types"
Expand Down Expand Up @@ -120,6 +121,22 @@ func (h *HttpHandle) doAutoAccountSearch(req *ReqAutoAccountSearch, apiResp *api
} else if apiResp.ErrNo != api_code.ApiCodeSuccess {
return nil
}
// check min price 0.99$
builder, err := h.DasCore.ConfigCellDataBuilderByTypeArgsList(common.ConfigCellTypeArgsSubAccount)
if err != nil {
apiResp.ApiRespErr(api_code.ApiCodeError500, "Failed to get config info")
return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList err: %s", err.Error())
}
newSubAccountPrice, _ := molecule.Bytes2GoU64(builder.ConfigCellSubAccount.NewSubAccountPrice().RawData())
minPrice := decimal.NewFromInt(int64(newSubAccountPrice)).DivRound(decimal.NewFromInt(common.UsdRateBase), 2)
if req.ActionType == tables.ActionTypeRenew {
renewSubAccountPrice, _ := molecule.Bytes2GoU64(builder.ConfigCellSubAccount.RenewSubAccountPrice().RawData())
minPrice = decimal.NewFromInt(int64(renewSubAccountPrice)).DivRound(decimal.NewFromInt(common.UsdRateBase), 2)
}
if minPrice.GreaterThan(resp.Price) {
apiResp.ApiRespErr(api_code.ApiCodePriceRulePriceNotBeLessThanMin, "Pricing below minimum")
return fmt.Errorf("price not be less than min: %s$", minPrice.String())
}

resp.PremiumPercentage = config.Cfg.Stripe.PremiumPercentage
resp.PremiumBase = config.Cfg.Stripe.PremiumBase
Expand Down
19 changes: 18 additions & 1 deletion http_server/handle/auto_order_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/dotbitHQ/das-lib/common"
"github.com/dotbitHQ/das-lib/core"
api_code "github.com/dotbitHQ/das-lib/http_api"
"github.com/dotbitHQ/das-lib/molecule"
"github.com/gin-gonic/gin"
"github.com/scorpiotzh/toolib"
"github.com/shopspring/decimal"
Expand Down Expand Up @@ -122,7 +123,6 @@ func (h *HttpHandle) doAutoOrderCreate(req *ReqAutoOrderCreate, apiResp *api_cod
apiResp.ApiRespErr(api_code.ApiCodeBeyondMaxYears, "The main account is valid for less than one year")
return nil
}

// get rule price
usdAmount, err := h.getRulePrice(parentAccount.Account, parentAccountId, req.SubAccount, apiResp)
if err != nil {
Expand All @@ -138,6 +138,23 @@ func (h *HttpHandle) doAutoOrderCreate(req *ReqAutoOrderCreate, apiResp *api_cod
apiResp.ApiRespErr(api_code.ApiCodeTokenIdNotSupported, "payment method not supported")
return nil
}
// check min price 0.99$
builder, err := h.DasCore.ConfigCellDataBuilderByTypeArgsList(common.ConfigCellTypeArgsSubAccount)
if err != nil {
apiResp.ApiRespErr(api_code.ApiCodeError500, "Failed to get config info")
return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList err: %s", err.Error())
}
newSubAccountPrice, _ := molecule.Bytes2GoU64(builder.ConfigCellSubAccount.NewSubAccountPrice().RawData())
minPrice := decimal.NewFromInt(int64(newSubAccountPrice)).DivRound(decimal.NewFromInt(common.UsdRateBase), 2)
if req.ActionType == tables.ActionTypeRenew {
renewSubAccountPrice, _ := molecule.Bytes2GoU64(builder.ConfigCellSubAccount.RenewSubAccountPrice().RawData())
minPrice = decimal.NewFromInt(int64(renewSubAccountPrice)).DivRound(decimal.NewFromInt(common.UsdRateBase), 2)
}
if minPrice.GreaterThan(usdAmount) {
apiResp.ApiRespErr(api_code.ApiCodePriceRulePriceNotBeLessThanMin, "Pricing below minimum")
return fmt.Errorf("price not be less than min: %s$", minPrice.String())
}

log.Info("usdAmount:", usdAmount.String(), req.Years)
usdAmount = usdAmount.Mul(decimal.NewFromInt(int64(req.Years)))
//log.Info("usdAmount:", usdAmount.String(), req.Years)
Expand Down
18 changes: 11 additions & 7 deletions http_server/handle/config_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type RespConfigInfo struct {
PaymentMinPrice int64 `json:"payment_min_price"`
ServiceFeeRatio string `json:"service_fee_ratio"`
} `json:"auto_mint"`
MintCostsManually uint64 `json:"mint_costs_manually"`
RenewCostsManually uint64 `json:"renew_costs_manually"`
ManagementTimes uint64 `json:"management_times"`
MintCostsManually decimal.Decimal `json:"mint_costs_manually"`
RenewCostsManually decimal.Decimal `json:"renew_costs_manually"`
ManagementTimes uint64 `json:"management_times"`
}

func (h *HttpHandle) ConfigInfo(ctx *gin.Context) {
Expand Down Expand Up @@ -57,20 +57,24 @@ func (h *HttpHandle) doConfigInfo(apiResp *api_code.ApiResp) error {
}
resp.SubAccountBasicCapacity, _ = molecule.Bytes2GoU64(builder.ConfigCellSubAccount.BasicCapacity().RawData())
resp.SubAccountPreparedFeeCapacity, _ = molecule.Bytes2GoU64(builder.ConfigCellSubAccount.PreparedFeeCapacity().RawData())
resp.SubAccountNewSubAccountPrice, _ = molecule.Bytes2GoU64(builder.ConfigCellSubAccount.NewSubAccountPrice().RawData())
resp.SubAccountRenewSubAccountPrice, _ = molecule.Bytes2GoU64(builder.ConfigCellSubAccount.RenewSubAccountPrice().RawData())
resp.SubAccountCommonFee, _ = molecule.Bytes2GoU64(builder.ConfigCellSubAccount.CommonFee().RawData())
resp.MintCostsManually, _ = molecule.Bytes2GoU64(builder.ConfigCellSubAccount.NewSubAccountPrice().RawData())
resp.RenewCostsManually, _ = molecule.Bytes2GoU64(builder.ConfigCellSubAccount.RenewSubAccountPrice().RawData())
resp.ManagementTimes = 10000

mintPrice, _ := builder.NewSubAccountPrice()
renewPrice, _ := builder.RenewSubAccountPrice()

resp.MintCostsManually = decimal.NewFromInt(int64(mintPrice)).DivRound(decimal.NewFromInt(common.UsdRateBase), 2)
resp.RenewCostsManually = decimal.NewFromInt(int64(renewPrice)).DivRound(decimal.NewFromInt(common.UsdRateBase), 2)

quoteCell, err := h.DasCore.GetQuoteCell()
if err != nil {
apiResp.ApiRespErr(api_code.ApiCodeError500, err.Error())
return nil
}
quote := decimal.NewFromInt(int64(quoteCell.Quote()))
resp.CkbQuote = quote.Div(decimal.NewFromInt(int64(common.OneCkb))).String()
resp.SubAccountNewSubAccountPrice = config.PriceToCKB(mintPrice, quoteCell.Quote(), 1)
resp.SubAccountRenewSubAccountPrice = config.PriceToCKB(renewPrice, quoteCell.Quote(), 1)

resp.AutoMint.PaymentMinPrice = config.Cfg.Das.AutoMint.PaymentMinPrice
resp.AutoMint.ServiceFeeRatio = fmt.Sprintf("%s%%", decimal.NewFromFloat(config.Cfg.Das.AutoMint.ServiceFeeRatio*100).String())
Expand Down
18 changes: 10 additions & 8 deletions http_server/handle/price_rule_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ func (h *HttpHandle) rulesTxAssemble(params RulesTxAssembleParams) (*txbuilder.B
return nil, nil, err
}

token, err := h.DbDao.GetTokenById(tables.TokenIdCkb)
if err != nil {
params.ApiResp.ApiRespErr(api_code.ApiCodeError500, err.Error())
return nil, nil, err
}
//token, err := h.DbDao.GetTokenById(tables.TokenIdCkb)
//if err != nil {
// params.ApiResp.ApiRespErr(api_code.ApiCodeError500, err.Error())
// return nil, nil, err
//}

builder, err := h.DasCore.ConfigCellDataBuilderByTypeArgsList(common.ConfigCellTypeArgsSubAccount)
if err != nil {
Expand All @@ -296,14 +296,16 @@ func (h *HttpHandle) rulesTxAssemble(params RulesTxAssembleParams) (*txbuilder.B
}

if math.Round(v.Price*10000)/10000 != v.Price {
err = errors.New("price most be two decimal places")
err = errors.New("price most be four decimal places")
params.ApiResp.ApiRespErr(api_code.ApiCodePriceMostReserveTwoDecimal, err.Error())
return nil, nil, err
}

price := decimal.NewFromInt(int64(newSubAccountPrice)).Mul(token.Price).Div(decimal.NewFromFloat(math.Pow10(int(token.Decimals))))
// check min price 0.99$
price := decimal.NewFromInt(int64(newSubAccountPrice)).DivRound(decimal.NewFromInt(common.UsdRateBase), 2)
//price := decimal.NewFromInt(int64(newSubAccountPrice)).Mul(token.Price).Div(decimal.NewFromFloat(math.Pow10(int(token.Decimals))))
if price.GreaterThan(decimal.NewFromFloat(v.Price)) {
err = fmt.Errorf("price not be less than min: %s$", price)
err = fmt.Errorf("price not be less than min: %s$", price.String())
params.ApiResp.ApiRespErr(api_code.ApiCodePriceRulePriceNotBeLessThanMin, err.Error())
return nil, nil, err
}
Expand Down
Loading

0 comments on commit 75ea76f

Please sign in to comment.