Commit 6cd7e2b2 authored by pengjun's avatar pengjun

#627 add price feed & system liquidation

parent 961263a5
......@@ -55,11 +55,31 @@ func newCollateralize() drivers.Driver {
}
// GetDriverName for Collateralize
func (Coll *Collateralize) GetDriverName() string {
func (c *Collateralize) GetDriverName() string {
return pty.CollateralizeX
}
func (Coll *Collateralize) addCollateralizeStatus(collateralizelog *pty.ReceiptCollateralize) (kvs []*types.KeyValue) {
func (c *Collateralize) addCollateralizeID(collateralizelog *pty.ReceiptCollateralize) (kvs []*types.KeyValue) {
key := calcCollateralizeKey(collateralizelog.CollateralizeId, collateralizelog.Index)
record := &pty.CollateralizeRecord{
CollateralizeId:collateralizelog.CollateralizeId,
Index: collateralizelog.Index,
}
kv := &types.KeyValue{Key: key, Value: types.Encode(record)}
kvs = append(kvs, kv)
return kvs
}
func (c *Collateralize) deleteCollateralizeID(collateralizelog *pty.ReceiptCollateralize) (kvs []*types.KeyValue) {
key := calcCollateralizeKey(collateralizelog.CollateralizeId, collateralizelog.Index)
kv := &types.KeyValue{Key: key, Value: nil}
kvs = append(kvs, kv)
return kvs
}
func (c *Collateralize) addCollateralizeStatus(collateralizelog *pty.ReceiptCollateralize) (kvs []*types.KeyValue) {
key := calcCollateralizeStatusKey(collateralizelog.Status, collateralizelog.Index)
record := &pty.CollateralizeRecord{
CollateralizeId:collateralizelog.CollateralizeId,
......@@ -71,7 +91,7 @@ func (Coll *Collateralize) addCollateralizeStatus(collateralizelog *pty.ReceiptC
return kvs
}
func (Coll *Collateralize) deleteCollateralizeStatus(collateralizelog *pty.ReceiptCollateralize) (kvs []*types.KeyValue) {
func (c *Collateralize) deleteCollateralizeStatus(collateralizelog *pty.ReceiptCollateralize) (kvs []*types.KeyValue) {
key := calcCollateralizeStatusKey(collateralizelog.Status, collateralizelog.Index)
kv := &types.KeyValue{Key: key, Value: nil}
......@@ -79,7 +99,7 @@ func (Coll *Collateralize) deleteCollateralizeStatus(collateralizelog *pty.Recei
return kvs
}
func (Coll *Collateralize) addCollateralizeAddr(collateralizelog *pty.ReceiptCollateralize) (kvs []*types.KeyValue) {
func (c *Collateralize) addCollateralizeAddr(collateralizelog *pty.ReceiptCollateralize) (kvs []*types.KeyValue) {
key := calcCollateralizeAddrKey(collateralizelog.AccountAddr, collateralizelog.Index)
record := &pty.CollateralizeRecord{
CollateralizeId:collateralizelog.CollateralizeId,
......@@ -91,10 +111,32 @@ func (Coll *Collateralize) addCollateralizeAddr(collateralizelog *pty.ReceiptCol
return kvs
}
func (Coll *Collateralize) deleteCollateralizeAddr(collateralizelog *pty.ReceiptCollateralize) (kvs []*types.KeyValue) {
func (c *Collateralize) deleteCollateralizeAddr(collateralizelog *pty.ReceiptCollateralize) (kvs []*types.KeyValue) {
key := calcCollateralizeAddrKey(collateralizelog.AccountAddr, collateralizelog.Index)
kv := &types.KeyValue{Key: key, Value: nil}
kvs = append(kvs, kv)
return kvs
}
func (c *Collateralize) addCollateralizeRecordStatus(collateralizelog *pty.ReceiptCollateralize) (kvs []*types.KeyValue) {
key := calcCollateralizeRecordStatusKey(collateralizelog.RecordStatus, collateralizelog.Index)
record := &pty.CollateralizeRecord{
CollateralizeId:collateralizelog.CollateralizeId,
Addr: collateralizelog.AccountAddr,
Index: collateralizelog.Index,
}
kv := &types.KeyValue{Key: key, Value: types.Encode(record)}
kvs = append(kvs, kv)
return kvs
}
func (c *Collateralize) deleteCollateralizeRecordStatus(collateralizelog *pty.ReceiptCollateralize) (kvs []*types.KeyValue) {
key := calcCollateralizeRecordStatusKey(collateralizelog.RecordStatus, collateralizelog.Index)
kv := &types.KeyValue{Key: key, Value: nil}
kvs = append(kvs, kv)
return kvs
}
\ No newline at end of file
......@@ -16,10 +16,10 @@ import (
// List control
const (
ListDESC = int32(0)
ListASC = int32(1)
DefultCount = int32(20) //默认一次取多少条记录
MaxCount = int32(100) //最多取100条
ListDESC = int32(0) // list降序
ListASC = int32(1) // list升序
DefultCount = int32(20) // 默认一次取多少条记录
MaxCount = int32(100) // 最多取100条
)
const (
......@@ -29,6 +29,7 @@ const (
MaxStabilityFee = 1000 // 最大稳定费
MaxLiquidationPenalty = 1000 // 最大清算罚金
MinCreatorAccount = 1000000 // 借贷创建者账户最小ccny余额
PriceWarningRate = 1.3
)
// CollateralizeDB def
......@@ -63,6 +64,7 @@ type Action struct {
coinsAccount *account.DB // bty账户
tokenAccount *account.DB // ccny账户
db dbm.KV
localDB dbm.Lister
txhash []byte
fromaddr string
blocktime int64
......@@ -84,10 +86,9 @@ func NewCollateralizeAction(c *Collateralize, tx *types.Transaction, index int)
}
return &Action{
coinsAccount: c.GetCoinsAccount(), tokenAccount:tokenDb, db: c.GetStateDB(),
txhash: hash, fromaddr: fromaddr, blocktime: c.GetBlockTime(),
height: c.GetHeight(), execaddr: dapp.ExecAddress(string(tx.Execer)),
difficulty: c.GetDifficulty(), index: index, Collateralize: c}
coinsAccount: c.GetCoinsAccount(), tokenAccount:tokenDb, db: c.GetStateDB(), localDB:c.GetLocalDB(),
txhash: hash, fromaddr: fromaddr, blocktime: c.GetBlockTime(), height: c.GetHeight(),
execaddr: dapp.ExecAddress(string(tx.Execer)), difficulty: c.GetDifficulty(), index: index, Collateralize: c}
}
// GetCollCommonRecipt generate logs for Collateralize common action
......@@ -96,6 +97,7 @@ func (action *Action) GetCollCommonRecipt(collateralize *pty.Collateralize, preS
c.CollateralizeId = collateralize.CollateralizeId
c.PreStatus = preStatus
c.Status = collateralize.Status
c.Index = action.GetIndex()
return c
}
......@@ -126,11 +128,11 @@ func (action *Action) GetBorrowReceiptLog(collateralize *pty.Collateralize, preS
}
// GetRepayReceiptLog generate logs for Collateralize Repay action
func (action *Action) GetRepayReceiptLog(Collateralize *pty.Collateralize, preStatus int32) *types.ReceiptLog {
func (action *Action) GetRepayReceiptLog(collateralize *pty.Collateralize, preStatus int32) *types.ReceiptLog {
log := &types.ReceiptLog{}
log.Ty = pty.TyLogCollateralizeRepay
c := action.GetCollCommonRecipt(Collateralize, preStatus)
c := action.GetCollCommonRecipt(collateralize, preStatus)
log.Log = types.Encode(c)
......@@ -138,11 +140,25 @@ func (action *Action) GetRepayReceiptLog(Collateralize *pty.Collateralize, preSt
}
// GetAppendReceiptLog generate logs for Collateralize append action
func (action *Action) GetAppendReceiptLog(Collateralize *pty.Collateralize, preStatus int32) *types.ReceiptLog {
func (action *Action) GetAppendReceiptLog(collateralize *pty.Collateralize, preStatus int32) *types.ReceiptLog {
log := &types.ReceiptLog{}
log.Ty = pty.TyLogCollateralizeAppend
c := action.GetCollCommonRecipt(Collateralize, preStatus)
c := action.GetCollCommonRecipt(collateralize, preStatus)
log.Log = types.Encode(c)
return log
}
// GetFeedReceiptLog generate logs for Collateralize price feed action
func (action *Action) GetFeedReceiptLog(collateralize *pty.Collateralize, borrowRecord *pty.BorrowRecord, preStatus int32) *types.ReceiptLog {
log := &types.ReceiptLog{}
log.Ty = pty.TyLogCollateralizeFeed
c := action.GetCollCommonRecipt(collateralize, preStatus)
c.AccountAddr = borrowRecord.AccountAddr
c.RecordStatus = borrowRecord.Status
log.Log = types.Encode(c)
......@@ -166,6 +182,17 @@ func (action *Action) GetIndex() int64 {
return action.height*types.MaxTxsPerBlock + int64(action.index)
}
func getLatestLiquidationPrice(coll *pty.Collateralize) float32 {
var latest float32
for _, collRecord := range coll.BorrowRecords {
if collRecord.LiquidationPrice > latest {
latest = collRecord.LiquidationPrice
}
}
return latest
}
// CollateralizeCreate 创建借贷,持有一定数量ccny的用户可创建借贷,提供给其他用户借贷
func (action *Action) CollateralizeCreate(create *pty.CollateralizeCreate) (*types.Receipt, error) {
var logs []*types.ReceiptLog
......@@ -189,7 +216,7 @@ func (action *Action) CollateralizeCreate(create *pty.CollateralizeCreate) (*typ
}
// 查找ID是否重复
_, err := findCollateralize(action.db, collateralizeID)
_, err := queryCollateralizeByID(action.db, collateralizeID)
if err != types.ErrNotFound {
clog.Error("CollateralizeCreate", "CollateralizeCreate repeated", collateralizeID)
return nil, pty.ErrCollateralizeRepeatHash
......@@ -233,7 +260,7 @@ func (action *Action) CollateralizeCreate(create *pty.CollateralizeCreate) (*typ
func getBtyNumToFrozen(value int64, price float32, ratio float32) (int64,error) {
if price == 0 {
clog.Error("Bty price should greate to 0")
return 0, pty.ErrPriceZero
return 0, pty.ErrPriceInvalid
}
btyValue := float32(value)/ratio
......@@ -244,11 +271,11 @@ func getBtyNumToFrozen(value int64, price float32, ratio float32) (int64,error)
// 计算清算价格
// value:借出ccny数量, colValue:抵押物数量, price:抵押物价格
func calcRepayPrice(value int64, colValue int64) float32 {
func calcLiquidationPrice(value int64, colValue int64) float32 {
liquidationRation := float32(value) / float32(colValue)
repayPrice := liquidationRation * pty.CollateralizeRepayRatio
liquidationPrice := liquidationRation * pty.CollateralizePreLiquidationRatio
return repayPrice
return liquidationPrice
}
// 获取最近抵押物价格
......@@ -299,7 +326,6 @@ func (action *Action) CheckExecTokenAccount(addr string, amount int64, isFrozen
return true
}
}
return false
}
......@@ -310,7 +336,7 @@ func (action *Action) CollateralizeBorrow(borrow *pty.CollateralizeBorrow) (*typ
var kv []*types.KeyValue
// 查找对应的借贷ID
collateralize, err := findCollateralize(action.db, borrow.CollateralizeId)
collateralize, err := queryCollateralizeByID(action.db, borrow.CollateralizeId)
if err != nil {
clog.Error("CollateralizeBorrow", "CollateralizeId", borrow.CollateralizeId, "err", err)
return nil, err
......@@ -405,12 +431,12 @@ func (action *Action) CollateralizeBorrow(borrow *pty.CollateralizeBorrow) (*typ
borrowRecord.StartTime = action.blocktime
borrowRecord.CollateralPrice = lastPrice
borrowRecord.DebtValue = borrow.Value
borrowRecord.LiquidationPrice = coll.LiquidationRatio * lastPrice * pty.CollateralizeRepayRatio
borrowRecord.LiquidationPrice = coll.LiquidationRatio * lastPrice * pty.CollateralizePreLiquidationRatio
borrowRecord.Status = pty.CollateralizeUserStatusCreate
// 记录当前借贷的最高自动清算价格
if coll.LatestRepayPrice < borrowRecord.LiquidationPrice {
coll.LatestRepayPrice = borrowRecord.LiquidationPrice
if coll.LatestLiquidationPrice < borrowRecord.LiquidationPrice {
coll.LatestLiquidationPrice = borrowRecord.LiquidationPrice
}
// 保存
......@@ -434,7 +460,7 @@ func (action *Action) CollateralizeRepay(repay *pty.CollateralizeRepay) (*types.
var receipt *types.Receipt
// 找到相应的借贷
collateralize, err := findCollateralize(action.db, repay.CollateralizeId)
collateralize, err := queryCollateralizeByID(action.db, repay.CollateralizeId)
if err != nil {
clog.Error("CollateralizeRepay", "CollID", repay.CollateralizeId, "err", err)
return nil, err
......@@ -501,6 +527,7 @@ func (action *Action) CollateralizeRepay(repay *pty.CollateralizeRepay) (*types.
// 保存
coll.Balance += repay.Value
coll.LatestLiquidationPrice = getLatestLiquidationPrice(&coll.Collateralize)
coll.Save(action.db)
kv = append(kv, coll.GetKVSet()...)
......@@ -517,7 +544,7 @@ func (action *Action) CollateralizeAppend(cAppend *pty.CollateralizeAppend) (*ty
var kv []*types.KeyValue
// 查找对应的借贷ID
collateralize, err := findCollateralize(action.db, cAppend.CollateralizeId)
collateralize, err := queryCollateralizeByID(action.db, cAppend.CollateralizeId)
if err != nil {
clog.Error("CollateralizeAppend", "CollateralizeId", cAppend.CollateralizeId, "err", err)
return nil, err
......@@ -563,7 +590,7 @@ func (action *Action) CollateralizeAppend(cAppend *pty.CollateralizeAppend) (*ty
// 抵押物转账
receipt, err := action.coinsAccount.ExecTransfer(action.fromaddr, coll.CreateAddr, action.execaddr, cAppend.CollateralValue*decimal)
if err != nil {
clog.Error("CollateralizeBorrow.ExecTransfer", "addr", action.fromaddr, "execaddr", action.execaddr, "amount", cAppend.CollateralValue)
clog.Error("CollateralizeBorrow.ExecTransfer", "addr", action.fromaddr, "execaddr", action.execaddr, "amount", cAppend.CollateralValue, "err", err)
return nil, err
}
logs = append(logs, receipt.Logs...)
......@@ -572,7 +599,7 @@ func (action *Action) CollateralizeAppend(cAppend *pty.CollateralizeAppend) (*ty
// 抵押物冻结
receipt, err = action.coinsAccount.ExecFrozen(coll.CreateAddr, action.execaddr, cAppend.CollateralValue)
if err != nil {
clog.Error("CollateralizeBorrow.Frozen", "addr", coll.CreateAddr, "execaddr", action.execaddr, "amount", cAppend.CollateralValue)
clog.Error("CollateralizeBorrow.Frozen", "addr", coll.CreateAddr, "execaddr", action.execaddr, "amount", cAppend.CollateralValue, "err", err)
return nil, err
}
logs = append(logs, receipt.Logs...)
......@@ -581,17 +608,12 @@ func (action *Action) CollateralizeAppend(cAppend *pty.CollateralizeAppend) (*ty
// 构造借出记录
borrowRecord.CollateralValue += cAppend.CollateralValue
borrowRecord.CollateralPrice = lastPrice
borrowRecord.LiquidationPrice = calcRepayPrice(borrowRecord.DebtValue, borrowRecord.CollateralValue)
borrowRecord.LiquidationPrice = calcLiquidationPrice(borrowRecord.DebtValue, borrowRecord.CollateralValue)
// 记录当前借贷的最高自动清算价格
if coll.LatestRepayPrice < borrowRecord.LiquidationPrice {
coll.LatestRepayPrice = borrowRecord.LiquidationPrice
}
// 保存
coll.BorrowRecords = append(coll.BorrowRecords, borrowRecord)
coll.Status = pty.CollateralizeStatusCreated
coll.LatestLiquidationPrice = getLatestLiquidationPrice(&coll.Collateralize)
coll.Save(action.db)
kv = append(kv, coll.GetKVSet()...)
receiptLog := action.GetAppendReceiptLog(&coll.Collateralize, preStatus)
......@@ -601,27 +623,221 @@ func (action *Action) CollateralizeAppend(cAppend *pty.CollateralizeAppend) (*ty
return receipt, nil
}
func getManageKey(key string, db dbm.KV) ([]byte, error) {
manageKey := types.ManageKey(key)
value, err := db.Get([]byte(manageKey))
if err != nil {
return nil, err
}
return value, nil
}
const (
priceFeedKey = "collateralize-price-feed"
guarantorKey = "collateralize-guarantor"
)
func isRightPriceFeed(addr string, db dbm.KV) bool {
value, err := getManageKey(priceFeedKey, db)
if err != nil {
clog.Error("CollateralizePriceFeed", "priceFeedKey", priceFeedKey)
return false
}
if value == nil {
clog.Error("CollateralizePriceFeed priceFeedKey found nil value")
return false
}
var item types.ConfigItem
err = types.Decode(value, &item)
if err != nil {
clog.Error("CollateralizePriceFeed", "Decode", value)
return false
}
for _, op := range item.GetArr().Value {
if op == addr {
return true
}
}
return false
}
func getGuarantorAddr(db dbm.KV) (string, error) {
value, err := getManageKey(guarantorKey, db)
if err != nil {
clog.Error("CollateralizePriceFeed", "getGuarantorAddr", err)
return "", err
}
if value == nil {
clog.Error("CollateralizePriceFeed guarantorKey found nil value")
return "", err
}
var item types.ConfigItem
err = types.Decode(value, &item)
if err != nil {
clog.Error("CollateralizePriceFeed", "getGuarantorAddr", err)
return "", err
}
return item.GetAddr(), nil
}
// 系统清算
func (action *Action) systemLiquidation(coll *pty.Collateralize, price float32) (*types.Receipt, error) {
var logs []*types.ReceiptLog
var kv []*types.KeyValue
collDB := &CollateralizeDB{*coll}
for _, borrowRecord := range coll.BorrowRecords {
var preStatus int32
if borrowRecord.LiquidationPrice * PriceWarningRate >= price {
if borrowRecord.LiquidationPrice >= price {
getGuarantorAddr, err := getGuarantorAddr(action.db)
if err != nil {
if err != nil {
clog.Error("systemLiquidation", "getGuarantorAddr", err)
continue
}
}
// 抵押物转移
receipt, err := action.coinsAccount.ExecTransferFrozen(action.fromaddr, getGuarantorAddr, action.execaddr, borrowRecord.CollateralValue)
if err != nil {
clog.Error("systemLiquidation", "addr", action.fromaddr, "execaddr", action.execaddr, "amount", borrowRecord.CollateralValue, "err", err)
continue
}
logs = append(logs, receipt.Logs...)
kv = append(kv, receipt.KV...)
// 借贷记录清算
borrowRecord.LiquidateTime = action.blocktime
preStatus = borrowRecord.Status
borrowRecord.Status = pty.CollateralizeUserStatusSystemLiquidate
} else {
preStatus = borrowRecord.Status
borrowRecord.Status = pty.CollateralizeUserStatusWarning
}
log := action.GetFeedReceiptLog(coll, borrowRecord, preStatus)
logs = append(logs, log)
}
}
// 保存
coll.LatestLiquidationPrice = getLatestLiquidationPrice(coll)
collDB.Save(action.db)
kv = append(kv, collDB.GetKVSet()...)
receipt := &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
return receipt, nil
}
// 价格计算策略
func pricePolicy(feed *pty.CollateralizeFeed) float32 {
var totalPrice float32
var totalVolume int64
for _, volume := range feed.Volume {
totalVolume += volume
}
for i, price := range feed.Price {
totalPrice += price * float32(float64(feed.Volume[i])/float64(totalVolume))
}
return totalPrice
}
// CollateralizeFeed 喂价
func (action *Action) CollateralizeFeed(repay *pty.CollateralizeFeed) (*types.Receipt, error) {
//TODO
return nil, nil
func (action *Action) CollateralizeFeed(feed *pty.CollateralizeFeed) (*types.Receipt, error) {
var logs []*types.ReceiptLog
var kv []*types.KeyValue
if feed == nil || len(feed.Price) == 0 || len(feed.Price) != len(feed.Volume) {
clog.Error("CollateralizePriceFeed", types.ErrInvalidParam)
return nil, types.ErrInvalidParam
}
if !isRightPriceFeed(action.fromaddr, action.db) {
clog.Error("CollateralizePriceFeed", "addr", action.fromaddr, "error", "Address has no permission to feed price")
return nil, pty.ErrPriceFeedPermissionDeny
}
price := pricePolicy(feed)
if price == 0 || price == -1 {
clog.Error("CollateralizePriceFeed", "price", price, "err", pty.ErrPriceInvalid)
return nil, pty.ErrPriceInvalid
}
collIDRecords, err := queryCollateralizes(action.localDB)
if err != nil {
clog.Error("CollateralizePriceFeed", "get collateralize record error", err)
return nil, err
}
for _, collID := range collIDRecords {
coll, err := queryCollateralizeByID(action.db, collID.CollateralizeId)
if err != nil {
clog.Error("CollateralizePriceFeed", "Collateralize ID", coll.CollateralizeId, "get collateralize record by id error", err)
continue
}
if coll.LatestLiquidationPrice >= price {
receipt, err := action.systemLiquidation(coll, price)
if err != nil {
clog.Error("CollateralizePriceFeed", "Collateralize ID", coll.CollateralizeId, "system liquidation error", err)
continue
}
logs = append(logs, receipt.Logs...)
kv = append(kv, receipt.KV...)
}
}
var priceRecord pty.AssetPriceRecord
if feed.CollType == pty.CollateralizeAssetTypeBty {
priceRecord.BtyPrice = price
} else if feed.CollType == pty.CollateralizeAssetTypeBtc {
priceRecord.BtcPrice = price
} else if feed.CollType == pty.CollateralizeAssetTypeEth {
priceRecord.EthPrice = price
} else {
priceRecord.BtyPrice = price
}
priceRecord.PreRecordTime = priceRecord.RecordTime
priceRecord.RecordTime = action.blocktime
// 喂价记录
pricekv := &types.KeyValue{Key: calcCollateralizePriceKey(string(action.blocktime)), Value: types.Encode(&priceRecord)}
action.db.Set(pricekv.Key, pricekv.Value)
kv = append(kv, pricekv)
// 最近喂价记录
pricekv = &types.KeyValue{Key: calcCollateralizeLatestPriceKey(), Value: types.Encode(&priceRecord)}
action.db.Set(pricekv.Key, pricekv.Value)
kv = append(kv, pricekv)
receipt := &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
return receipt, nil
}
// CollateralizeClose 终止借贷
//TODO 暂时只实现无人借贷可终止
func (action *Action) CollateralizeClose(close *pty.CollateralizeClose) (*types.Receipt, error) {
var logs []*types.ReceiptLog
var kv []*types.KeyValue
collateralize, err := findCollateralize(action.db, close.CollateralizeId)
collateralize, err := queryCollateralizeByID(action.db, close.CollateralizeId)
if err != nil {
clog.Error("CollateralizeClose", "CollateralizeId", close.CollateralizeId, "err", err)
return nil, err
}
if collateralize.Balance != collateralize.TotalBalance {
clog.Error("CollateralizeClose", "CollateralizeId", close.CollateralizeId, "addr", action.fromaddr, "execaddr", action.execaddr, "err", pty.ErrCollateralizeBalanceInvalid)
return nil, pty.ErrCollateralizeBalanceInvalid
for _, borrowRecord := range collateralize.BorrowRecords {
if borrowRecord.Status != pty.CollateralizeUserStatusClose {
clog.Error("CollateralizeClose", "CollateralizeId", close.CollateralizeId, "addr", action.fromaddr, "execaddr", action.execaddr, "err", pty.ErrCollateralizeRecordNotEmpty)
return nil, pty.ErrCollateralizeRecordNotEmpty
}
}
clog.Debug("CollateralizeClose", "ID", close.CollateralizeId)
......@@ -639,18 +855,39 @@ func (action *Action) CollateralizeClose(close *pty.CollateralizeClose) (*types.
}
// 查找借贷
func findCollateralize(db dbm.KV, CollateralizeID string) (*pty.Collateralize, error) {
func queryCollateralizeByID(db dbm.KV, CollateralizeID string) (*pty.Collateralize, error) {
data, err := db.Get(Key(CollateralizeID))
if err != nil {
clog.Debug("findCollateralize", "get", err)
clog.Debug("queryCollateralizeByID", "error", err)
return nil, err
}
var coll pty.Collateralize
//decode
err = types.Decode(data, &coll)
if err != nil {
clog.Debug("findCollateralize", "decode", err)
clog.Debug("queryCollateralizeByID", "decode", err)
return nil, err
}
return &coll, nil
}
func queryCollateralizes(localdb dbm.Lister) ([]*pty.CollateralizeRecord, error) {
data, err := localdb.List(calcCollateralizePrefix(), nil, DefultCount, ListDESC)
if err != nil {
clog.Debug("queryCollateralizes", "error", err)
return nil, err
}
var colls []*pty.CollateralizeRecord
var coll pty.CollateralizeRecord
for _, collBytes := range data {
err = types.Decode(collBytes, &coll)
if err != nil {
clog.Debug("queryCollateralizeByID", "decode", err)
return nil, err
}
colls = append(colls, &coll)
}
return colls, nil
}
\ No newline at end of file
......@@ -13,30 +13,35 @@ import (
func (c *Collateralize) execDelLocal(tx *types.Transaction, receiptData *types.ReceiptData) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
for _, item := range receiptData.Logs {
var collateralizelog pty.ReceiptCollateralize
err := types.Decode(item.Log, &collateralizelog)
var collateralizeLog pty.ReceiptCollateralize
err := types.Decode(item.Log, &collateralizeLog)
if err != nil {
return nil, err
}
switch item.Ty {
case pty.TyLogCollateralizeCreate:
kv := c.deleteCollateralizeStatus(&collateralizelog)
kv := c.deleteCollateralizeStatus(&collateralizeLog)
set.KV = append(set.KV, kv...)
break
case pty.TyLogCollateralizeBorrow:
kv := c.deleteCollateralizeAddr(&collateralizelog)
set.KV = append(set.KV, kv...)
set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(&collateralizeLog)...)
set.KV = append(set.KV, c.deleteCollateralizeAddr(&collateralizeLog)...)
break
case pty.TyLogCollateralizeAppend: // append没有状态变化
break
case pty.TyLogCollateralizeRepay:
kv := c.addCollateralizeAddr(&collateralizelog)
set.KV = append(set.KV, kv...)
set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(&collateralizeLog)...)
set.KV = append(set.KV, c.addCollateralizeAddr(&collateralizeLog)...)
break
case pty.TyLogCollateralizeFeed:
set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(&collateralizeLog)...)
if collateralizeLog.RecordStatus == pty.CollateralizeUserStatusSystemLiquidate {
set.KV = append(set.KV, c.addCollateralizeAddr(&collateralizeLog)...)
}
break
/*case pty.TyLogCollateralizeFeed:*/ // TODO
case pty.TyLogCollateralizeClose:
kv := c.addCollateralizeStatus(&collateralizelog)
kv := c.addCollateralizeStatus(&collateralizeLog)
set.KV = append(set.KV, kv...)
break
}
......
......@@ -13,31 +13,34 @@ import (
func (c *Collateralize) execLocal(tx *types.Transaction, receipt *types.ReceiptData) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{}
for _, item := range receipt.Logs {
var collateralizelog pty.ReceiptCollateralize
err := types.Decode(item.Log, &collateralizelog)
var collateralizeLog pty.ReceiptCollateralize
err := types.Decode(item.Log, &collateralizeLog)
if err != nil {
return nil, err
}
switch item.Ty {
case pty.TyLogCollateralizeCreate:
kv := c.addCollateralizeStatus(&collateralizelog)
set.KV = append(set.KV, kv...)
set.KV = append(set.KV, c.addCollateralizeStatus(&collateralizeLog)...)
break
case pty.TyLogCollateralizeBorrow:
kv := c.addCollateralizeAddr(&collateralizelog)
set.KV = append(set.KV, kv...)
set.KV = append(set.KV, c.addCollateralizeRecordStatus(&collateralizeLog)...)
set.KV = append(set.KV, c.addCollateralizeAddr(&collateralizeLog)...)
break
case pty.TyLogCollateralizeAppend://append没有状态变化
case pty.TyLogCollateralizeAppend: //append没有状态变化
break
case pty.TyLogCollateralizeRepay:
kv := c.deleteCollateralizeAddr(&collateralizelog)
set.KV = append(set.KV, kv...)
set.KV = append(set.KV, c.addCollateralizeRecordStatus(&collateralizeLog)...)
set.KV = append(set.KV, c.deleteCollateralizeAddr(&collateralizeLog)...)
break
case pty.TyLogCollateralizeFeed:
set.KV = append(set.KV, c.addCollateralizeRecordStatus(&collateralizeLog)...)
if collateralizeLog.RecordStatus == pty.CollateralizeUserStatusSystemLiquidate {
set.KV = append(set.KV, c.deleteCollateralizeAddr(&collateralizeLog)...)
}
break
/*case pty.TyLogCollateralizeFeed:*/ // TODO
case pty.TyLogCollateralizeClose:
kv := c.deleteCollateralizeStatus(&collateralizelog)
set.KV = append(set.KV, kv...)
set.KV = append(set.KV, c.deleteCollateralizeStatus(&collateralizeLog)...)
break
}
}
......
......@@ -6,8 +6,13 @@ package executor
import "fmt"
func calcCollateralizeKey(CollateralizeID string) []byte {
key := fmt.Sprintf("LODB-Collateralize-ID:%s", CollateralizeID)
func calcCollateralizeKey(collateralizeID string, index int64) []byte {
key := fmt.Sprintf("LODB-Collateralize-ID:%s:%018d", collateralizeID, index)
return []byte(key)
}
func calcCollateralizePrefix() []byte {
key := fmt.Sprintf("LODB-Collateralize-ID:")
return []byte(key)
}
......@@ -40,3 +45,13 @@ func calcCollateralizeLatestPriceKey() []byte {
key := fmt.Sprintf("LODB-Collateralize-latest-price")
return []byte(key)
}
func calcCollateralizeRecordStatusPrefix(status int32) []byte {
key := fmt.Sprintf("LODB-Collateralize-record-status:%d", status)
return []byte(key)
}
func calcCollateralizeRecordStatusKey(status int32, index int64) []byte {
key := fmt.Sprintf("LODB-Collateralize-record-status:%d:%018d", status, index)
return []byte(key)
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ syntax = "proto3";
package types;
// 借贷信息
message Collateralize {
string collateralizeId = 1; //借贷ID,一期借贷对应一个ID
int64 totalBalance = 2; //当期可借贷的总金额(ccny)
......@@ -12,12 +13,12 @@ message Collateralize {
string createAddr = 7; //创建人地址
int64 balance = 8; //剩余可借贷金额(ccny)
repeated BorrowRecord borrowRecords = 9; //借贷记录
repeated BorrowRecord badRecords = 10;//被系统清算的借贷
int32 status = 11;//当期借贷的状态,是否关闭
int32 collType = 12;//质押资产类型(1,bty,2,btc,3,eth...)
float latestRepayPrice = 13;//最大清算价格
int32 status = 10;//当期借贷的状态,是否关闭
int32 collType = 11;//质押资产类型(1,bty,2,btc,3,eth...)
float latestLiquidationPrice = 12;//最大清算价格
}
// 借出记录
message BorrowRecord {
string accountAddr = 1; //借贷人地址
int64 startTime = 2; //借贷时间
......@@ -26,16 +27,19 @@ message BorrowRecord {
int64 debtValue = 5; //债务价值(ccny)
float liquidationPrice = 6; //抵押物清算价格
int32 status = 7; //抵押状态,是否被清算
int64 liquidateTime = 8; //清算时间
}
// 资产价格记录
message AssetPriceRecord {
string recordTime = 1; //价格记录时间
int64 recordTime = 1; //价格记录时间
float btyPrice = 2; //bty价格
float btcPrice = 3; //btc价格
float ethPrice = 4; //eth价格
string preRecordTime = 5; //上一次记录时间
int64 preRecordTime = 5; //上一次记录时间
}
// action
message CollateralizeAction {
oneof value {
CollateralizeCreate create = 1; //创建一期借贷
......@@ -48,6 +52,7 @@ message CollateralizeAction {
int32 ty = 10;
}
// 创建借贷
message CollateralizeCreate {
int64 debtCeiling = 1; //单用户可借出的限额(ccny)
float liquidationRatio = 2; //清算比例
......@@ -56,37 +61,45 @@ message CollateralizeCreate {
int64 totalBalance = 5; //可借贷总金额
}
// 质押借出
message CollateralizeBorrow {
string collateralizeId = 1; //借贷期数ID
int64 value = 2; //借贷价值(ccny)
}
// 质押清算
message CollateralizeRepay {
string collateralizeId = 1; //借贷期数ID
int64 value = 2; //借贷价值(ccny)
}
// 追加抵押物
message CollateralizeAppend {
string collateralizeId = 1; //借贷期数ID
int64 collateralValue = 2; //追加价值(bty)
}
// 喂价
message CollateralizeFeed {
repeated int64 price = 1; //喂价
repeated int64 volume = 2; //成交量
int32 collType = 1; //抵押物价格类型(1,bty,2,btc,3,eth...)
repeated float price = 2; //喂价
repeated int64 volume = 3; //成交量
}
// 喂价关闭
message CollateralizeClose {
string collateralizeId = 1; //借贷期数ID
}
// exec_local记录信息
message ReceiptCollateralize {
string collateralizeId = 1;
string createAddr = 3;
string accountAddr = 4;
int32 status = 5;
int32 preStatus = 6;
int64 index = 7;
string createAddr = 2;
string accountAddr = 3;
int32 status = 4;
int32 preStatus = 5;
int64 index = 6;
int32 recordStatus = 7;
}
message ReqCollateralizeInfo {
......@@ -128,7 +141,8 @@ message ReplyCollateralizeBadDebt {
// used for execlocal
message CollateralizeRecord {
string collateralizeId = 1;
int64 index = 3;
string addr = 2;
int64 index = 3;
}
message CollateralizeRecords {
......
......@@ -20,23 +20,23 @@ var _ = math.Inf
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// 借贷信息
type Collateralize struct {
CollateralizeId string `protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
TotalBalance int64 `protobuf:"varint,2,opt,name=totalBalance,proto3" json:"totalBalance,omitempty"`
DebtCeiling int64 `protobuf:"varint,3,opt,name=debtCeiling,proto3" json:"debtCeiling,omitempty"`
LiquidationRatio float32 `protobuf:"fixed32,4,opt,name=liquidationRatio,proto3" json:"liquidationRatio,omitempty"`
StabilityFee int64 `protobuf:"varint,5,opt,name=stabilityFee,proto3" json:"stabilityFee,omitempty"`
LiquidationPenalty int64 `protobuf:"varint,6,opt,name=liquidationPenalty,proto3" json:"liquidationPenalty,omitempty"`
CreateAddr string `protobuf:"bytes,7,opt,name=createAddr,proto3" json:"createAddr,omitempty"`
Balance int64 `protobuf:"varint,8,opt,name=balance,proto3" json:"balance,omitempty"`
BorrowRecords []*BorrowRecord `protobuf:"bytes,9,rep,name=borrowRecords,proto3" json:"borrowRecords,omitempty"`
BadRecords []*BorrowRecord `protobuf:"bytes,10,rep,name=badRecords,proto3" json:"badRecords,omitempty"`
Status int32 `protobuf:"varint,11,opt,name=status,proto3" json:"status,omitempty"`
CollType int32 `protobuf:"varint,12,opt,name=collType,proto3" json:"collType,omitempty"`
LatestRepayPrice float32 `protobuf:"fixed32,13,opt,name=latestRepayPrice,proto3" json:"latestRepayPrice,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
CollateralizeId string `protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
TotalBalance int64 `protobuf:"varint,2,opt,name=totalBalance,proto3" json:"totalBalance,omitempty"`
DebtCeiling int64 `protobuf:"varint,3,opt,name=debtCeiling,proto3" json:"debtCeiling,omitempty"`
LiquidationRatio float32 `protobuf:"fixed32,4,opt,name=liquidationRatio,proto3" json:"liquidationRatio,omitempty"`
StabilityFee int64 `protobuf:"varint,5,opt,name=stabilityFee,proto3" json:"stabilityFee,omitempty"`
LiquidationPenalty int64 `protobuf:"varint,6,opt,name=liquidationPenalty,proto3" json:"liquidationPenalty,omitempty"`
CreateAddr string `protobuf:"bytes,7,opt,name=createAddr,proto3" json:"createAddr,omitempty"`
Balance int64 `protobuf:"varint,8,opt,name=balance,proto3" json:"balance,omitempty"`
BorrowRecords []*BorrowRecord `protobuf:"bytes,9,rep,name=borrowRecords,proto3" json:"borrowRecords,omitempty"`
Status int32 `protobuf:"varint,10,opt,name=status,proto3" json:"status,omitempty"`
CollType int32 `protobuf:"varint,11,opt,name=collType,proto3" json:"collType,omitempty"`
LatestLiquidationPrice float32 `protobuf:"fixed32,12,opt,name=latestLiquidationPrice,proto3" json:"latestLiquidationPrice,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Collateralize) Reset() { *m = Collateralize{} }
......@@ -127,13 +127,6 @@ func (m *Collateralize) GetBorrowRecords() []*BorrowRecord {
return nil
}
func (m *Collateralize) GetBadRecords() []*BorrowRecord {
if m != nil {
return m.BadRecords
}
return nil
}
func (m *Collateralize) GetStatus() int32 {
if m != nil {
return m.Status
......@@ -148,13 +141,14 @@ func (m *Collateralize) GetCollType() int32 {
return 0
}
func (m *Collateralize) GetLatestRepayPrice() float32 {
func (m *Collateralize) GetLatestLiquidationPrice() float32 {
if m != nil {
return m.LatestRepayPrice
return m.LatestLiquidationPrice
}
return 0
}
// 借出记录
type BorrowRecord struct {
AccountAddr string `protobuf:"bytes,1,opt,name=accountAddr,proto3" json:"accountAddr,omitempty"`
StartTime int64 `protobuf:"varint,2,opt,name=startTime,proto3" json:"startTime,omitempty"`
......@@ -163,6 +157,7 @@ type BorrowRecord struct {
DebtValue int64 `protobuf:"varint,5,opt,name=debtValue,proto3" json:"debtValue,omitempty"`
LiquidationPrice float32 `protobuf:"fixed32,6,opt,name=liquidationPrice,proto3" json:"liquidationPrice,omitempty"`
Status int32 `protobuf:"varint,7,opt,name=status,proto3" json:"status,omitempty"`
LiquidateTime int64 `protobuf:"varint,8,opt,name=liquidateTime,proto3" json:"liquidateTime,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
......@@ -242,12 +237,20 @@ func (m *BorrowRecord) GetStatus() int32 {
return 0
}
func (m *BorrowRecord) GetLiquidateTime() int64 {
if m != nil {
return m.LiquidateTime
}
return 0
}
// 资产价格记录
type AssetPriceRecord struct {
RecordTime string `protobuf:"bytes,1,opt,name=recordTime,proto3" json:"recordTime,omitempty"`
RecordTime int64 `protobuf:"varint,1,opt,name=recordTime,proto3" json:"recordTime,omitempty"`
BtyPrice float32 `protobuf:"fixed32,2,opt,name=btyPrice,proto3" json:"btyPrice,omitempty"`
BtcPrice float32 `protobuf:"fixed32,3,opt,name=btcPrice,proto3" json:"btcPrice,omitempty"`
EthPrice float32 `protobuf:"fixed32,4,opt,name=ethPrice,proto3" json:"ethPrice,omitempty"`
PreRecordTime string `protobuf:"bytes,5,opt,name=preRecordTime,proto3" json:"preRecordTime,omitempty"`
PreRecordTime int64 `protobuf:"varint,5,opt,name=preRecordTime,proto3" json:"preRecordTime,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
......@@ -278,11 +281,11 @@ func (m *AssetPriceRecord) XXX_DiscardUnknown() {
var xxx_messageInfo_AssetPriceRecord proto.InternalMessageInfo
func (m *AssetPriceRecord) GetRecordTime() string {
func (m *AssetPriceRecord) GetRecordTime() int64 {
if m != nil {
return m.RecordTime
}
return ""
return 0
}
func (m *AssetPriceRecord) GetBtyPrice() float32 {
......@@ -306,13 +309,14 @@ func (m *AssetPriceRecord) GetEthPrice() float32 {
return 0
}
func (m *AssetPriceRecord) GetPreRecordTime() string {
func (m *AssetPriceRecord) GetPreRecordTime() int64 {
if m != nil {
return m.PreRecordTime
}
return ""
return 0
}
// action
type CollateralizeAction struct {
// Types that are valid to be assigned to Value:
// *CollateralizeAction_Create
......@@ -461,6 +465,7 @@ func (*CollateralizeAction) XXX_OneofWrappers() []interface{} {
}
}
// 创建借贷
type CollateralizeCreate struct {
DebtCeiling int64 `protobuf:"varint,1,opt,name=debtCeiling,proto3" json:"debtCeiling,omitempty"`
LiquidationRatio float32 `protobuf:"fixed32,2,opt,name=liquidationRatio,proto3" json:"liquidationRatio,omitempty"`
......@@ -532,6 +537,7 @@ func (m *CollateralizeCreate) GetTotalBalance() int64 {
return 0
}
// 质押借出
type CollateralizeBorrow struct {
CollateralizeId string `protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"`
......@@ -579,6 +585,7 @@ func (m *CollateralizeBorrow) GetValue() int64 {
return 0
}
// 质押清算
type CollateralizeRepay struct {
CollateralizeId string `protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"`
......@@ -626,6 +633,7 @@ func (m *CollateralizeRepay) GetValue() int64 {
return 0
}
// 追加抵押物
type CollateralizeAppend struct {
CollateralizeId string `protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
CollateralValue int64 `protobuf:"varint,2,opt,name=collateralValue,proto3" json:"collateralValue,omitempty"`
......@@ -673,12 +681,14 @@ func (m *CollateralizeAppend) GetCollateralValue() int64 {
return 0
}
// 喂价
type CollateralizeFeed struct {
Price []int64 `protobuf:"varint,1,rep,packed,name=price,proto3" json:"price,omitempty"`
Volume []int64 `protobuf:"varint,2,rep,packed,name=volume,proto3" json:"volume,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
CollType int32 `protobuf:"varint,1,opt,name=collType,proto3" json:"collType,omitempty"`
Price []float32 `protobuf:"fixed32,2,rep,packed,name=price,proto3" json:"price,omitempty"`
Volume []int64 `protobuf:"varint,3,rep,packed,name=volume,proto3" json:"volume,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *CollateralizeFeed) Reset() { *m = CollateralizeFeed{} }
......@@ -706,7 +716,14 @@ func (m *CollateralizeFeed) XXX_DiscardUnknown() {
var xxx_messageInfo_CollateralizeFeed proto.InternalMessageInfo
func (m *CollateralizeFeed) GetPrice() []int64 {
func (m *CollateralizeFeed) GetCollType() int32 {
if m != nil {
return m.CollType
}
return 0
}
func (m *CollateralizeFeed) GetPrice() []float32 {
if m != nil {
return m.Price
}
......@@ -720,6 +737,7 @@ func (m *CollateralizeFeed) GetVolume() []int64 {
return nil
}
// 喂价关闭
type CollateralizeClose struct {
CollateralizeId string `protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
......@@ -759,13 +777,15 @@ func (m *CollateralizeClose) GetCollateralizeId() string {
return ""
}
// exec_local记录信息
type ReceiptCollateralize struct {
CollateralizeId string `protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
CreateAddr string `protobuf:"bytes,3,opt,name=createAddr,proto3" json:"createAddr,omitempty"`
AccountAddr string `protobuf:"bytes,4,opt,name=accountAddr,proto3" json:"accountAddr,omitempty"`
Status int32 `protobuf:"varint,5,opt,name=status,proto3" json:"status,omitempty"`
PreStatus int32 `protobuf:"varint,6,opt,name=preStatus,proto3" json:"preStatus,omitempty"`
Index int64 `protobuf:"varint,7,opt,name=index,proto3" json:"index,omitempty"`
CreateAddr string `protobuf:"bytes,2,opt,name=createAddr,proto3" json:"createAddr,omitempty"`
AccountAddr string `protobuf:"bytes,3,opt,name=accountAddr,proto3" json:"accountAddr,omitempty"`
Status int32 `protobuf:"varint,4,opt,name=status,proto3" json:"status,omitempty"`
PreStatus int32 `protobuf:"varint,5,opt,name=preStatus,proto3" json:"preStatus,omitempty"`
Index int64 `protobuf:"varint,6,opt,name=index,proto3" json:"index,omitempty"`
RecordStatus int32 `protobuf:"varint,7,opt,name=recordStatus,proto3" json:"recordStatus,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
......@@ -838,6 +858,13 @@ func (m *ReceiptCollateralize) GetIndex() int64 {
return 0
}
func (m *ReceiptCollateralize) GetRecordStatus() int32 {
if m != nil {
return m.RecordStatus
}
return 0
}
type ReqCollateralizeInfo struct {
CollateralizeId string `protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
......@@ -1171,6 +1198,7 @@ func (m *ReplyCollateralizeBadDebt) GetRecords() []*BorrowRecord {
// used for execlocal
type CollateralizeRecord struct {
CollateralizeId string `protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"`
Index int64 `protobuf:"varint,3,opt,name=index,proto3" json:"index,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
......@@ -1209,6 +1237,13 @@ func (m *CollateralizeRecord) GetCollateralizeId() string {
return ""
}
func (m *CollateralizeRecord) GetAddr() string {
if m != nil {
return m.Addr
}
return ""
}
func (m *CollateralizeRecord) GetIndex() int64 {
if m != nil {
return m.Index
......@@ -1280,62 +1315,63 @@ func init() {
func init() { proto.RegisterFile("collateralize.proto", fileDescriptor_a988fb4a61381972) }
var fileDescriptor_a988fb4a61381972 = []byte{
// 906 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x57, 0xcd, 0x6e, 0xfb, 0x44,
0x10, 0xff, 0xdb, 0x8e, 0x93, 0x66, 0xd2, 0x40, 0xd9, 0x56, 0xe0, 0x46, 0xa5, 0x8a, 0x2c, 0x0e,
0x11, 0x12, 0x91, 0x48, 0x7b, 0xe1, 0x82, 0x48, 0x83, 0xaa, 0x16, 0x71, 0xa8, 0x4c, 0xe1, 0xc0,
0x6d, 0x6d, 0x6f, 0xc1, 0x92, 0xb1, 0xdd, 0xf5, 0xa6, 0x60, 0xce, 0x5c, 0x78, 0x12, 0x2e, 0xdc,
0x79, 0x0b, 0x5e, 0x80, 0x3b, 0xcf, 0x81, 0x76, 0x76, 0x13, 0x7f, 0x46, 0x4a, 0xe8, 0xf1, 0x7f,
0xa9, 0xb2, 0xf3, 0x3d, 0xbf, 0xf9, 0x79, 0x76, 0x0b, 0xa7, 0x41, 0x1a, 0xc7, 0x54, 0x30, 0x4e,
0xe3, 0xe8, 0x57, 0x36, 0xcf, 0x78, 0x2a, 0x52, 0x62, 0x8b, 0x22, 0x63, 0xb9, 0xfb, 0x7b, 0x0f,
0xc6, 0xab, 0xaa, 0x9a, 0xcc, 0xe0, 0xdd, 0x9a, 0xfd, 0x7d, 0xe8, 0x18, 0x53, 0x63, 0x36, 0xf4,
0x9a, 0x62, 0xe2, 0xc2, 0xb1, 0x48, 0x05, 0x8d, 0x6f, 0x68, 0x4c, 0x93, 0x80, 0x39, 0xe6, 0xd4,
0x98, 0x59, 0x5e, 0x4d, 0x46, 0xa6, 0x30, 0x0a, 0x99, 0x2f, 0x56, 0x2c, 0x8a, 0xa3, 0xe4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0xff, 0xbb, 0x53, 0x0d, 0x10, 0x51, 0x0c, 0x00, 0x00,
// 922 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x57, 0x41, 0x6f, 0xe3, 0x44,
0x14, 0x5e, 0xdb, 0x71, 0xb2, 0x79, 0x69, 0x61, 0x99, 0x46, 0x8b, 0x37, 0x5a, 0x56, 0x91, 0xc5,
0xc1, 0x42, 0x22, 0x12, 0x61, 0x85, 0xc4, 0x05, 0x91, 0x06, 0xad, 0x5a, 0xd4, 0x03, 0x72, 0x0b,
0x07, 0x24, 0x0e, 0x13, 0x7b, 0x0a, 0x96, 0x5c, 0xdb, 0x1d, 0x4f, 0x0a, 0xe6, 0x0f, 0x21, 0x21,
0xee, 0xfc, 0x18, 0x2e, 0x9c, 0xf8, 0x01, 0xfc, 0x02, 0x34, 0x6f, 0x26, 0x89, 0xc7, 0x76, 0xa4,
0x84, 0x1e, 0xf7, 0x52, 0x65, 0xde, 0x7b, 0xf3, 0xe6, 0xbd, 0xef, 0x7d, 0xfe, 0x66, 0x0a, 0x67,
0x51, 0x9e, 0xa6, 0x54, 0x30, 0x4e, 0xd3, 0xe4, 0x57, 0x36, 0x2b, 0x78, 0x2e, 0x72, 0xe2, 0x8a,
0xaa, 0x60, 0xa5, 0xff, 0xb7, 0x03, 0xa7, 0xcb, 0xba, 0x9b, 0x04, 0xf0, 0xae, 0x11, 0x7f, 0x19,
0x7b, 0xd6, 0xd4, 0x0a, 0x86, 0x61, 0xd3, 0x4c, 0x7c, 0x38, 0x11, 0xb9, 0xa0, 0xe9, 0x39, 0x4d,
0x69, 0x16, 0x31, 0xcf, 0x9e, 0x5a, 0x81, 0x13, 0x1a, 0x36, 0x32, 0x85, 0x51, 0xcc, 0x56, 0x62,
0xc9, 0x92, 0x34, 0xc9, 0x7e, 0xf4, 0x1c, 0x0c, 0xa9, 0x9b, 0xc8, 0x47, 0xf0, 0x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x00, 0x00,
0xff, 0xff, 0x2e, 0xf8, 0x38, 0x08, 0xa2, 0x0c, 0x00, 0x00,
}
......@@ -12,7 +12,7 @@ var (
ErrCollateralizeRepeatHash = errors.New("ErrCollateralizeRepeatHash")
ErrCollateralizeStatus = errors.New("ErrCollateralizeStatus")
ErrCollateralizeExceedDebtCeiling = errors.New("ErrCollateralizeExceedDebtCeiling")
ErrPriceZero = errors.New("ErrPriceZero")
ErrPriceInvalid = errors.New("ErrPriceInvalid")
ErrAssetType = errors.New("ErrAssetType")
ErrRecordNotExist = errors.New("ErrRecordNotExist")
ErrCollateralizeErrCloser = errors.New("ErrCollateralizeErrCloser")
......@@ -20,4 +20,6 @@ var (
ErrCollateralizeAccountExist = errors.New("ErrCollateralizeAccountExist")
ErrCollateralizeLowBalance = errors.New("ErrCollateralizeLowBalance")
ErrCollateralizeBalanceInvalid = errors.New("ErrCollateralizeBalanceInvalid")
ErrPriceFeedPermissionDeny = errors.New("ErrPriceFeedPermissionDeny")
ErrCollateralizeRecordNotEmpty = errors.New("ErrCollateralizeRecordNotEmpty")
)
......@@ -14,19 +14,19 @@ const (
CollateralizeActionClose
//log for Collateralize
TyLogCollateralizeCreate = 801
TyLogCollateralizeBorrow = 802
TyLogCollateralizeRepay = 803
TyLogCollateralizeAppend = 804
TyLogCollateralizeFeed = 805
TyLogCollateralizeClose = 806
TyLogCollateralizeCreate = 731
TyLogCollateralizeBorrow = 732
TyLogCollateralizeRepay = 733
TyLogCollateralizeAppend = 734
TyLogCollateralizeFeed = 735
TyLogCollateralizeClose = 736
)
// Collateralize name
const (
CollateralizeX = "collateralize"
CCNYTokenName = "ccny"
CollateralizeRepayRatio = 1.1 //TODO 清算比例,抵押物价值跌到借出ccny价值110%的时候开始清算
CollateralizePreLiquidationRatio = 1.1 //TODO 预清算比例,抵押物价值跌到借出ccny价值110%的时候开始清算
)
//Collateralize status
......@@ -44,6 +44,6 @@ const (
const (
CollateralizeUserStatusCreate = 1 + iota
CollateralizeUserStatusWarning
CollateralizeUserStatusSystemRepayed
CollateralizeUserStatusSystemLiquidate
CollateralizeUserStatusClose
)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment