syntax = "proto3";

package types;

// 借贷信息
message Collateralize {
    string      collateralizeId          = 1; //借贷ID,一期借贷对应一个ID
    int64       totalBalance             = 2; //当期可借贷的总金额(ccny)
    int64       debtCeiling              = 3; //单用户可借出的限额(ccny)
    float       liquidationRatio         = 4; //清算比例
    float       stabilityFeeRatio        = 5; //稳定费率
    string      createAddr               = 6; //创建人地址
    int64       balance                  = 7; //剩余可借贷金额(ccny)
    repeated BorrowRecord borrowRecords  = 8; //借贷记录
    repeated BorrowRecord InvalidRecords = 9; //失效的借贷记录
    int32       status                   = 10;//当期借贷的状态，是否关闭
    int32       collType                 = 11;//质押资产类型(1，bty，2，btc，3，eth...)
    float       latestLiquidationPrice   = 12;//最高清算价格
    int64       period                   = 13;//借贷最大期限
    int64       latestExpireTime         = 14;//最近超期时间
}

// 借出记录
message BorrowRecord {
    string      accountAddr          = 1; //借贷人地址
    int64       startTime            = 2; //借贷时间
    int64       collateralValue      = 3; //抵押物价值(bty)
    float       collateralPrice      = 4; //抵押物价格
    int64       debtValue            = 5; //债务价值(ccny)
    float       liquidationPrice     = 6; //抵押物清算价格
    int32       status               = 7; //抵押状态，是否被清算
    int64       liquidateTime        = 8; //清算时间
    int64       expireTime           = 9; //超时清算时间
}

// 资产价格记录
message AssetPriceRecord {
    int64      recordTime      = 1; //价格记录时间
    float      btyPrice        = 2; //bty价格
    float      btcPrice        = 3; //btc价格
    float      ethPrice        = 4; //eth价格
    int64      preRecordTime   = 5; //上一次记录时间
}

// action
message CollateralizeAction {
    oneof value {
        CollateralizeCreate    create = 1; //创建一期借贷
        CollateralizeBorrow    borrow = 2; //借贷
        CollateralizeRepay     repay  = 3; //清算
        CollateralizeAppend    append = 4; //追加
        CollateralizeFeed      feed   = 5; //喂价
        CollateralizeClose     close  = 6; //关闭
        CollateralizeManage    manage = 7; //全局配置
    }
    int32 ty = 10;
}

message CollateralizeManage {
    CollateralizeConfig cfg  = 1; //借贷配置
    CollateralizeAddr   addr = 2; //地址配置
}

message CollateralizeConfig {
    int64 debtCeiling        = 1; //单用户可借出的限额(ccny)
    float liquidationRatio   = 2; //清算比例
    float stabilityFeeRatio  = 3; //稳定费
    int64 period             = 4; //合约期限
}

message CollateralizeAddr {
    repeated string superAddrs = 1; //大户地址
}
// 创建借贷
message CollateralizeCreate {
    int64 totalBalance       = 1; //可借贷总金额
}

// 质押借出
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 {
    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         = 2;
    string      accountAddr        = 3;
    int32       status             = 4;
    int32       preStatus          = 5;
    int64       index              = 6;
    int32       recordStatus       = 7;
}

// exec_local 借贷记录信息
message CollateralizeRecord {
    string collateralizeId = 1;
    string addr            = 2;
    int64  index           = 3;
}

// exec_local 借贷记录信息列表
message CollateralizeRecords {
    repeated CollateralizeRecord records = 1;
}

// 根据ID查询一期借贷信息
message ReqCollateralizeInfo {
    string collateralizeId = 1;
}

// 返回一期借贷信息
message RepCollateralizeCurrentInfo {
    int32       status                  = 1;//当期借贷的状态，是否关闭
    int64       totalBalance            = 2; //当期可借贷的总金额(ccny)
    int64       debtCeiling             = 3; //单用户可借出的限额(ccny)
    float       liquidationRatio        = 4; //清算比例
    float       stabilityFeeRatio       = 5; //稳定费
    int64       liquidationPenalty      = 6; //清算罚金
    string      createAddr              = 7; //创建人地址
    int64       balance                 = 8; //剩余可借贷金额(ccny)
}

// 根据ID列表查询多期借贷信息
message ReqCollateralizeInfos {
    repeated string collateralizeIds = 1;
}

// 返回多期借贷信息
message RepCollateralizeCurrentInfos {
    repeated RepCollateralizeCurrentInfo infos = 1;
}

// 根据借贷状态查询
message ReqCollateralizeByStatus {
    int32 status = 1;
}

// 根据用户地址查询
message ReqCollateralizeByAddr {
    string addr = 1;
}

// 返回借贷ID列表
message RepCollateralizeIDs {
    repeated string IDs = 1;
}

// 根据地址和借贷ID混合查询具体借贷记录
message ReqCollateralizeBorrowInfoByAddr {
    string collateralizeId = 1;
    string addr            = 2;
}

// 根据状态和借贷ID混合查询具体借贷记录
message ReqCollateralizeBorrowInfoByStatus {
    string collateralizeId = 1;
    int32 status           = 2;
}

// 返回借贷记录
message RepCollateralizeBorrowInfos {
    repeated BorrowRecord record = 1;
}
