Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
2f57d651
Commit
2f57d651
authored
Nov 28, 2019
by
pengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#627 update balance value to float64
parent
2e4b635d
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
136 additions
and
125 deletions
+136
-125
cmd.go
plugin/dapp/collateralize/commands/cmd.go
+20
-20
collateralize_test.go
plugin/dapp/collateralize/executor/collateralize_test.go
+7
-10
collateralizedb.go
plugin/dapp/collateralize/executor/collateralizedb.go
+0
-0
query.go
plugin/dapp/collateralize/executor/query.go
+4
-4
collateralize.proto
plugin/dapp/collateralize/proto/collateralize.proto
+20
-19
collateralize.go
plugin/dapp/collateralize/types/collateralize.go
+8
-7
collateralize.pb.go
plugin/dapp/collateralize/types/collateralize.pb.go
+0
-0
errors.go
plugin/dapp/collateralize/types/errors.go
+0
-1
tx.go
plugin/dapp/collateralize/types/tx.go
+9
-9
cmd.go
plugin/dapp/issuance/commands/cmd.go
+9
-9
exec_del_local.go
plugin/dapp/issuance/executor/exec_del_local.go
+6
-0
exec_local.go
plugin/dapp/issuance/executor/exec_local.go
+5
-0
issuance.go
plugin/dapp/issuance/executor/issuance.go
+1
-1
issuancedb.go
plugin/dapp/issuance/executor/issuancedb.go
+27
-27
issuance.proto
plugin/dapp/issuance/proto/issuance.proto
+11
-10
issuance.go
plugin/dapp/issuance/types/issuance.go
+4
-3
issuance.pb.go
plugin/dapp/issuance/types/issuance.pb.go
+0
-0
tx.go
plugin/dapp/issuance/types/tx.go
+5
-5
No files found.
plugin/dapp/collateralize/commands/cmd.go
View file @
2f57d651
...
...
@@ -44,7 +44,7 @@ func CollateralizeCreateRawTxCmd() *cobra.Command {
}
func
addCollateralizeCreateFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Uin
t64P
(
"balance"
,
"b"
,
0
,
"balance"
)
cmd
.
Flags
()
.
Floa
t64P
(
"balance"
,
"b"
,
0
,
"balance"
)
cmd
.
MarkFlagRequired
(
"balance"
)
}
...
...
@@ -56,12 +56,12 @@ func CollateralizeCreate(cmd *cobra.Command, args []string) {
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
balance
,
_
:=
cmd
.
Flags
()
.
Get
Uin
t64
(
"balance"
)
balance
,
_
:=
cmd
.
Flags
()
.
Get
Floa
t64
(
"balance"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeCreate"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
totalBalance
\"
:%
d
}"
,
balance
)),
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
totalBalance
\"
:%
f
}"
,
balance
)),
}
var
res
string
...
...
@@ -83,7 +83,7 @@ func CollateralizeBorrowRawTxCmd() *cobra.Command {
func
addCollateralizeBorrowFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"collateralizeID"
,
"g"
,
""
,
"collateralize ID"
)
cmd
.
MarkFlagRequired
(
"collateralizeID"
)
cmd
.
Flags
()
.
Uin
t64P
(
"value"
,
"v"
,
0
,
"value"
)
cmd
.
Flags
()
.
Floa
t64P
(
"value"
,
"v"
,
0
,
"value"
)
cmd
.
MarkFlagRequired
(
"value"
)
}
...
...
@@ -96,12 +96,12 @@ func CollateralizeBorrow(cmd *cobra.Command, args []string) {
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
value
,
_
:=
cmd
.
Flags
()
.
Get
Uin
t64
(
"value"
)
value
,
_
:=
cmd
.
Flags
()
.
Get
Floa
t64
(
"value"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeBorrow"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
\"
%s
\"
,
\"
value
\"
:%
d
}"
,
collateralizeID
,
value
)),
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
\"
%s
\"
,
\"
value
\"
:%
f
}"
,
collateralizeID
,
value
)),
}
var
res
string
...
...
@@ -125,7 +125,7 @@ func addCollateralizeAppendFlags(cmd *cobra.Command) {
cmd
.
MarkFlagRequired
(
"collateralizeID"
)
cmd
.
Flags
()
.
StringP
(
"recordID"
,
"r"
,
""
,
"recordID"
)
cmd
.
MarkFlagRequired
(
"recordID"
)
cmd
.
Flags
()
.
Uin
t64P
(
"value"
,
"v"
,
0
,
"value"
)
cmd
.
Flags
()
.
Floa
t64P
(
"value"
,
"v"
,
0
,
"value"
)
cmd
.
MarkFlagRequired
(
"value"
)
}
...
...
@@ -139,12 +139,12 @@ func CollateralizeAppend(cmd *cobra.Command, args []string) {
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
recordID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"recordID"
)
value
,
_
:=
cmd
.
Flags
()
.
Get
Uin
t64
(
"value"
)
value
,
_
:=
cmd
.
Flags
()
.
Get
Floa
t64
(
"value"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeAppend"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
\"
%s
\"
,
\"
recordID
\"
:
\"
%s
\"
,
\"
value
\"
:%
d
}"
,
collateralizeID
,
recordID
,
value
)),
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
\"
%s
\"
,
\"
recordID
\"
:
\"
%s
\"
,
\"
value
\"
:%
f
}"
,
collateralizeID
,
recordID
,
value
)),
}
var
res
string
...
...
@@ -204,7 +204,7 @@ func CollateralizePriceFeedRawTxCmd() *cobra.Command {
}
func
addCollateralizePriceFeedFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Float
32
P
(
"price"
,
"p"
,
0
,
"price"
)
cmd
.
Flags
()
.
Float
64
P
(
"price"
,
"p"
,
0
,
"price"
)
cmd
.
MarkFlagRequired
(
"price"
)
cmd
.
Flags
()
.
Uint64P
(
"volume"
,
"v"
,
0
,
"volume"
)
cmd
.
MarkFlagRequired
(
"volume"
)
...
...
@@ -246,7 +246,7 @@ func CollateralizeRetrieveRawTxCmd() *cobra.Command {
func
addCollateralizeRetrieveFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"collateralizeID"
,
"g"
,
""
,
"collateralize ID"
)
cmd
.
MarkFlagRequired
(
"collateralizeID"
)
cmd
.
Flags
()
.
StringP
(
"balance"
,
"b"
,
""
,
"retrieve balance"
)
cmd
.
Flags
()
.
Float64P
(
"balance"
,
"b"
,
0
,
"retrieve balance"
)
cmd
.
MarkFlagRequired
(
"balance"
)
}
...
...
@@ -259,12 +259,12 @@ func CollateralizeRetrieve(cmd *cobra.Command, args []string) {
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
balance
,
_
:=
cmd
.
Flags
()
.
Get
In
t64
(
"balance"
)
balance
,
_
:=
cmd
.
Flags
()
.
Get
Floa
t64
(
"balance"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeRetrieve"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
\"
%s
\"
,
\"
balance
\"
: %
d
}"
,
collateralizeID
,
balance
)),
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
\"
%s
\"
,
\"
balance
\"
: %
f
}"
,
collateralizeID
,
balance
)),
}
var
res
string
...
...
@@ -284,11 +284,11 @@ func CollateralizeManageRawTxCmd() *cobra.Command {
}
func
addCollateralizeManageFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Uin
t64P
(
"debtCeiling"
,
"d"
,
0
,
"debtCeiling"
)
cmd
.
Flags
()
.
Float
32
P
(
"liquidationRatio"
,
"l"
,
0
,
"liquidationRatio"
)
cmd
.
Flags
()
.
Float
32
P
(
"stabilityFeeRatio"
,
"s"
,
0
,
"stabilityFeeRatio"
)
cmd
.
Flags
()
.
Floa
t64P
(
"debtCeiling"
,
"d"
,
0
,
"debtCeiling"
)
cmd
.
Flags
()
.
Float
64
P
(
"liquidationRatio"
,
"l"
,
0
,
"liquidationRatio"
)
cmd
.
Flags
()
.
Float
64
P
(
"stabilityFeeRatio"
,
"s"
,
0
,
"stabilityFeeRatio"
)
cmd
.
Flags
()
.
Uint64P
(
"period"
,
"p"
,
0
,
"period"
)
cmd
.
Flags
()
.
Uin
t64P
(
"totalBalance"
,
"t"
,
0
,
"totalBalance"
)
cmd
.
Flags
()
.
Floa
t64P
(
"totalBalance"
,
"t"
,
0
,
"totalBalance"
)
}
func
CollateralizeManage
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
...
...
@@ -299,16 +299,16 @@ func CollateralizeManage(cmd *cobra.Command, args []string) {
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
debtCeiling
,
_
:=
cmd
.
Flags
()
.
Get
Uint64
(
"debtCeiling"
)
debtCeiling
,
_
:=
cmd
.
Flags
()
.
Get
Float32
(
"debtCeiling"
)
liquidationRatio
,
_
:=
cmd
.
Flags
()
.
GetFloat32
(
"liquidationRatio"
)
stabilityFeeRatio
,
_
:=
cmd
.
Flags
()
.
GetFloat32
(
"stabilityFeeRatio"
)
period
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"period"
)
totalBalance
,
_
:=
cmd
.
Flags
()
.
Get
Uint64
(
"totalBalance"
)
totalBalance
,
_
:=
cmd
.
Flags
()
.
Get
Float32
(
"totalBalance"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeManage"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
debtCeiling
\"
:%
d,
\"
liquidationRatio
\"
:%f,
\"
stabilityFeeRatio
\"
:%f,
\"
period
\"
:%d,
\"
totalBalance
\"
:%d
}"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
debtCeiling
\"
:%
f,
\"
liquidationRatio
\"
:%f,
\"
stabilityFeeRatio
\"
:%f,
\"
period
\"
:%d,
\"
totalBalance
\"
:%f
}"
,
debtCeiling
,
liquidationRatio
,
stabilityFeeRatio
,
period
,
totalBalance
)),
}
...
...
plugin/dapp/collateralize/executor/collateralize_test.go
View file @
2f57d651
...
...
@@ -93,6 +93,11 @@ func initEnv() *execEnv {
Frozen
:
0
,
Addr
:
string
(
Nodes
[
1
]),
}
accountBToken
:=
types
.
Account
{
Balance
:
types
.
Coin
/
10
,
Frozen
:
0
,
Addr
:
string
(
Nodes
[
1
]),
}
accountC
:=
types
.
Account
{
Balance
:
total
,
Frozen
:
0
,
...
...
@@ -117,6 +122,8 @@ func initEnv() *execEnv {
accB
.
SetDB
(
stateDB
)
accB
.
SaveExecAccount
(
execAddr
,
&
accountB
)
manageKeySet
(
"issuance-price-feed"
,
accountB
.
Addr
,
stateDB
)
tokenAccB
,
_
:=
account
.
NewAccountDB
(
cfg
,
tokenE
.
GetName
(),
pkt
.
CCNYTokenName
,
stateDB
)
tokenAccB
.
SaveExecAccount
(
execAddr
,
&
accountBToken
)
accC
:=
account
.
NewCoinsAccount
(
cfg
)
accC
.
SetDB
(
stateDB
)
...
...
@@ -584,12 +591,3 @@ func signTx(tx *types.Transaction, hexPrivKey string) (*types.Transaction, error
tx
.
Sign
(
int32
(
signType
),
privKey
)
return
tx
,
nil
}
//func TestSlice(t *testing.T) {
// var a []int
// a = append(a, 1)
// fmt.Println(a)
//
// a = append(a[:0], a[1:]...)
// fmt.Println(a)
//}
\ No newline at end of file
plugin/dapp/collateralize/executor/collateralizedb.go
View file @
2f57d651
This diff is collapsed.
Click to expand it.
plugin/dapp/collateralize/executor/query.go
View file @
2f57d651
...
...
@@ -144,7 +144,7 @@ func (c *Collateralize) Query_CollateralizeConfig(req *pty.ReqCollateralizeRecor
clog
.
Debug
(
"Query_CollateralizeByStatus"
,
"get collateralize record error"
,
err
)
}
collBalance
:=
config
.
Coll
TotalBalance
balance
:=
config
.
TotalBalance
for
_
,
id
:=
range
collIDRecords
{
coll
,
err
:=
queryCollateralizeByID
(
c
.
GetStateDB
(),
id
)
if
err
!=
nil
{
...
...
@@ -152,15 +152,15 @@ func (c *Collateralize) Query_CollateralizeConfig(req *pty.ReqCollateralizeRecor
return
nil
,
err
}
collB
alance
-=
coll
.
TotalBalance
b
alance
-=
coll
.
TotalBalance
}
ret
:=
&
pty
.
RepCollateralizeConfig
{
CollTotalBalance
:
config
.
Coll
TotalBalance
,
TotalBalance
:
config
.
TotalBalance
,
DebtCeiling
:
config
.
DebtCeiling
,
LiquidationRatio
:
config
.
LiquidationRatio
,
StabilityFeeRatio
:
config
.
StabilityFeeRatio
,
Period
:
config
.
Period
,
CollBalance
:
collB
alance
,
Balance
:
b
alance
,
CurrentTime
:
config
.
CurrentTime
,
}
...
...
plugin/dapp/collateralize/proto/collateralize.proto
View file @
2f57d651
...
...
@@ -7,14 +7,14 @@ message Collateralize {
string
collateralizeId
=
1
;
//放贷ID,一期放贷对应一个ID
int64
totalBalance
=
2
;
//当期放贷的总金额(ccny)
int64
debtCeiling
=
3
;
//单用户可借出的限额(ccny)
float
liquidationRatio
=
4
;
//清算比例
float
stabilityFeeRatio
=
5
;
//稳定费率
double
liquidationRatio
=
4
;
//清算比例
double
stabilityFeeRatio
=
5
;
//稳定费率
string
createAddr
=
6
;
//创建人地址
int64
balance
=
7
;
//放贷剩余金额(ccny)
repeated
BorrowRecord
borrowRecords
=
8
;
//借贷记录
repeated
BorrowRecord
InvalidRecords
=
9
;
//失效的借贷记录
int32
status
=
10
;
//当期借贷的状态,是否关闭
float
latestLiquidationPrice
=
11
;
//最高清算价格
double
latestLiquidationPrice
=
11
;
//最高清算价格
int64
period
=
12
;
//借贷最大期限
int64
latestExpireTime
=
13
;
//最近超期时间
int64
index
=
14
;
//当前索引
...
...
@@ -27,9 +27,9 @@ message BorrowRecord {
string
accountAddr
=
1
;
//借贷人地址
int64
startTime
=
2
;
//借贷时间
int64
collateralValue
=
3
;
//抵押物价值(bty)
float
collateralPrice
=
4
;
//抵押物价格
double
collateralPrice
=
4
;
//抵押物价格
int64
debtValue
=
5
;
//债务价值(ccny)
float
liquidationPrice
=
6
;
//抵押物清算价格
double
liquidationPrice
=
6
;
//抵押物清算价格
int32
status
=
7
;
//抵押状态,是否被清算
int64
liquidateTime
=
8
;
//清算时间
int64
expireTime
=
9
;
//超时清算时间
...
...
@@ -43,9 +43,9 @@ message BorrowRecord {
// 资产价格记录
message
AssetPriceRecord
{
int64
recordTime
=
1
;
//价格记录时间
float
btyPrice
=
2
;
//bty价格
float
btcPrice
=
3
;
//btc价格
float
ethPrice
=
4
;
//eth价格
double
btyPrice
=
2
;
//bty价格
double
btcPrice
=
3
;
//btc价格
double
ethPrice
=
4
;
//eth价格
}
// action
...
...
@@ -64,10 +64,10 @@ message CollateralizeAction {
message
CollateralizeManage
{
int64
debtCeiling
=
1
;
//单用户可借出的限额(ccny)
float
liquidationRatio
=
2
;
//清算比例
float
stabilityFeeRatio
=
3
;
//稳定费
double
liquidationRatio
=
2
;
//清算比例
double
stabilityFeeRatio
=
3
;
//稳定费
int64
period
=
4
;
//合约期限
int64
collTotalBalance
=
5
;
//放贷总量
int64
totalBalance
=
5
;
//放贷总量
int64
currentTime
=
6
;
//设置时间
}
...
...
@@ -101,7 +101,7 @@ message CollateralizeAppend {
// 喂价
message
CollateralizeFeed
{
int32
collType
=
1
;
//抵押物价格类型(1,bty,2,btc,3,eth...)
repeated
float
price
=
2
;
//喂价
repeated
double
price
=
2
;
//喂价
repeated
int64
volume
=
3
;
//成交量
}
...
...
@@ -147,8 +147,8 @@ message RepCollateralizeCurrentInfo {
int32
status
=
1
;
//当期借贷的状态,是否关闭
int64
totalBalance
=
2
;
//当期可借贷的总金额(ccny)
int64
debtCeiling
=
3
;
//单用户可借出的限额(ccny)
float
liquidationRatio
=
4
;
//清算比例
float
stabilityFeeRatio
=
5
;
//稳定费
double
liquidationRatio
=
4
;
//清算比例
double
stabilityFeeRatio
=
5
;
//稳定费
string
createAddr
=
6
;
//创建人地址
int64
balance
=
7
;
//剩余可借贷金额(ccny)
int64
period
=
8
;
//合约期限
...
...
@@ -219,15 +219,15 @@ message RepCollateralizeRecord {
// 返回放贷配置
message
RepCollateralizeConfig
{
int64
debtCeiling
=
1
;
//单用户可借出的限额(ccny)
float
liquidationRatio
=
2
;
//清算比例
float
stabilityFeeRatio
=
3
;
//稳定费
double
liquidationRatio
=
2
;
//清算比例
double
stabilityFeeRatio
=
3
;
//稳定费
int64
period
=
4
;
//合约期限
int64
collTotalBalance
=
5
;
//放贷总量
int64
collBalance
=
6
;
//剩余放贷额度
int64
totalBalance
=
5
;
//放贷总量
int64
balance
=
6
;
//剩余放贷额度
int64
currentTime
=
7
;
//设置时间
}
// 返回最新抵押物价格
message
RepCollateralizePrice
{
float
price
=
1
;
//当前抵押物最新价格
double
price
=
1
;
//当前抵押物最新价格
}
\ No newline at end of file
plugin/dapp/collateralize/types/collateralize.go
View file @
2f57d651
...
...
@@ -6,6 +6,7 @@ package types
import
(
"encoding/json"
"math"
"reflect"
"github.com/33cn/chain33/common/address"
...
...
@@ -111,7 +112,7 @@ func (collateralize CollateralizeType) CreateTx(action string, message json.RawM
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawCollateralizeFeedTx
(
cfg
,
&
param
)
}
else
if
action
==
"CollateralizeRetrive"
{
}
else
if
action
==
"CollateralizeRetri
e
ve"
{
var
param
CollateralizeRetrieveTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
...
...
@@ -153,7 +154,7 @@ func CreateRawCollateralizeCreateTx(cfg *types.Chain33Config, parm *Collateraliz
}
v
:=
&
CollateralizeCreate
{
TotalBalance
:
parm
.
TotalBalance
,
TotalBalance
:
int64
(
math
.
Trunc
((
parm
.
TotalBalance
+
0.0000001
)
*
1e4
))
*
1e4
,
}
create
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionCreate
,
...
...
@@ -182,7 +183,7 @@ func CreateRawCollateralizeBorrowTx(cfg *types.Chain33Config, parm *Collateraliz
v
:=
&
CollateralizeBorrow
{
CollateralizeId
:
parm
.
CollateralizeID
,
Value
:
parm
.
Value
,
Value
:
int64
(
math
.
Trunc
((
parm
.
Value
+
0.0000001
)
*
1e4
))
*
1e4
,
}
borrow
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionBorrow
,
...
...
@@ -241,7 +242,7 @@ func CreateRawCollateralizeAppendTx(cfg *types.Chain33Config, parm *Collateraliz
v
:=
&
CollateralizeAppend
{
CollateralizeId
:
parm
.
CollateralizeID
,
RecordId
:
parm
.
RecordID
,
CollateralValue
:
parm
.
Value
,
CollateralValue
:
int64
(
math
.
Trunc
((
parm
.
Value
+
0.0000001
)
*
1e4
))
*
1e4
,
}
append
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionAppend
,
...
...
@@ -299,7 +300,7 @@ func CreateRawCollateralizeRetrieveTx(cfg *types.Chain33Config, parm *Collateral
v
:=
&
CollateralizeRetrieve
{
CollateralizeId
:
parm
.
CollateralizeID
,
Balance
:
parm
.
Balance
,
Balance
:
int64
(
math
.
Trunc
((
parm
.
Balance
+
0.0000001
)
*
1e4
))
*
1e4
,
}
close
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionRetrieve
,
...
...
@@ -328,11 +329,11 @@ func CreateRawCollateralizeManageTx(cfg *types.Chain33Config, parm *Collateraliz
}
v
:=
&
CollateralizeManage
{
DebtCeiling
:
parm
.
DebtCeiling
,
DebtCeiling
:
int64
(
math
.
Trunc
((
parm
.
DebtCeiling
+
0.0000001
)
*
1e4
))
*
1e4
,
LiquidationRatio
:
parm
.
LiquidationRatio
,
StabilityFeeRatio
:
parm
.
StabilityFeeRatio
,
Period
:
parm
.
Period
,
CollTotalBalance
:
parm
.
CollTotalBalance
,
TotalBalance
:
int64
(
math
.
Trunc
((
parm
.
TotalBalance
+
0.0000001
)
*
1e4
))
*
1e4
,
}
manage
:=
&
CollateralizeAction
{
...
...
plugin/dapp/collateralize/types/collateralize.pb.go
View file @
2f57d651
This diff is collapsed.
Click to expand it.
plugin/dapp/collateralize/types/errors.go
View file @
2f57d651
...
...
@@ -9,7 +9,6 @@ import "errors"
// Errors for lottery
var
(
ErrRiskParam
=
errors
.
New
(
"ErrRiskParam"
)
ErrCollateralizeRepeatHash
=
errors
.
New
(
"ErrCollateralizeRepeatHash"
)
ErrCollateralizeStatus
=
errors
.
New
(
"ErrCollateralizeStatus"
)
ErrCollateralizeExceedDebtCeiling
=
errors
.
New
(
"ErrCollateralizeExceedDebtCeiling"
)
ErrPriceInvalid
=
errors
.
New
(
"ErrPriceInvalid"
)
...
...
plugin/dapp/collateralize/types/tx.go
View file @
2f57d651
...
...
@@ -6,14 +6,14 @@ package types
// CollateralizeCreateTx for construction
type
CollateralizeCreateTx
struct
{
TotalBalance
in
t64
`json:"totalBalance"`
TotalBalance
floa
t64
`json:"totalBalance"`
Fee
int64
`json:"fee"`
}
// CollateralizeBorrowTx for construction
type
CollateralizeBorrowTx
struct
{
CollateralizeID
string
`json:"collateralizeId"`
Value
in
t64
`json:"value"`
Value
floa
t64
`json:"value"`
Fee
int64
`json:"fee"`
}
...
...
@@ -28,13 +28,13 @@ type CollateralizeRepayTx struct {
type
CollateralizeAppendTx
struct
{
CollateralizeID
string
`json:"collateralizeId"`
RecordID
string
`json:"recordID"`
Value
in
t64
`json:"value"`
Value
floa
t64
`json:"value"`
Fee
int64
`json:"fee"`
}
// CollateralizeFeedTx for construction
type
CollateralizeFeedTx
struct
{
Price
[]
float
32
`json:"price"`
Price
[]
float
64
`json:"price"`
Volume
[]
int64
`json:"volume"`
Fee
int64
`json:"fee"`
}
...
...
@@ -42,16 +42,16 @@ type CollateralizeFeedTx struct {
// CollateralizeRetrieveTx for construction
type
CollateralizeRetrieveTx
struct
{
CollateralizeID
string
`json:"collateralizeId"`
Balance
in
t64
`json:"Balance"`
Balance
floa
t64
`json:"Balance"`
Fee
int64
`json:"fee"`
}
// CollateralizeManageTx for construction
type
CollateralizeManageTx
struct
{
DebtCeiling
in
t64
`json:"debtCeiling"`
LiquidationRatio
float
32
`json:"liquidationRatio"`
StabilityFeeRatio
float
32
`json:"stabilityFeeRatio"`
DebtCeiling
floa
t64
`json:"debtCeiling"`
LiquidationRatio
float
64
`json:"liquidationRatio"`
StabilityFeeRatio
float
64
`json:"stabilityFeeRatio"`
Period
int64
`json:"period"`
CollTotalBalance
int64
`json:"collT
otalBalance"`
TotalBalance
float64
`json:"t
otalBalance"`
Fee
int64
`json:"fee"`
}
plugin/dapp/issuance/commands/cmd.go
View file @
2f57d651
...
...
@@ -43,11 +43,11 @@ func IssuanceCreateRawTxCmd() *cobra.Command {
}
func
addIssuanceCreateFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Uin
t64P
(
"balance"
,
"b"
,
0
,
"balance"
)
cmd
.
Flags
()
.
Floa
t64P
(
"balance"
,
"b"
,
0
,
"balance"
)
cmd
.
MarkFlagRequired
(
"balance"
)
cmd
.
Flags
()
.
Uin
t64P
(
"debtCeiling"
,
"d"
,
0
,
"debtCeiling"
)
cmd
.
Flags
()
.
Floa
t64P
(
"debtCeiling"
,
"d"
,
0
,
"debtCeiling"
)
cmd
.
Flags
()
.
Float32P
(
"liquidationRatio"
,
"l"
,
0
,
"liquidationRatio"
)
cmd
.
Flags
()
.
Uint64
P
(
"period"
,
"p"
,
0
,
"period"
)
cmd
.
Flags
()
.
Float32
P
(
"period"
,
"p"
,
0
,
"period"
)
}
func
IssuanceCreate
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
...
...
@@ -58,15 +58,15 @@ func IssuanceCreate(cmd *cobra.Command, args []string) {
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
balance
,
_
:=
cmd
.
Flags
()
.
Get
Uin
t64
(
"balance"
)
debtCeiling
,
_
:=
cmd
.
Flags
()
.
Get
Uin
t64
(
"debtCeiling"
)
balance
,
_
:=
cmd
.
Flags
()
.
Get
Floa
t64
(
"balance"
)
debtCeiling
,
_
:=
cmd
.
Flags
()
.
Get
Floa
t64
(
"debtCeiling"
)
liquidationRatio
,
_
:=
cmd
.
Flags
()
.
GetFloat32
(
"liquidationRatio"
)
period
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"period"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
IssuanceX
),
ActionName
:
"IssuanceCreate"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
totalBalance
\"
:%
d,
\"
debtCeiling
\"
:%d
,
\"
liquidationRatio
\"
:%f,
\"
period
\"
:%d}"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
totalBalance
\"
:%
f,
\"
debtCeiling
\"
:%f
,
\"
liquidationRatio
\"
:%f,
\"
period
\"
:%d}"
,
balance
,
debtCeiling
,
liquidationRatio
,
period
)),
}
...
...
@@ -89,7 +89,7 @@ func IssuanceDebtRawTxCmd() *cobra.Command {
func
addIssuanceDebtFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"issuanceID"
,
"g"
,
""
,
"issuance ID"
)
cmd
.
MarkFlagRequired
(
"issuanceID"
)
cmd
.
Flags
()
.
Uin
t64P
(
"value"
,
"v"
,
0
,
"value"
)
cmd
.
Flags
()
.
Floa
t64P
(
"value"
,
"v"
,
0
,
"value"
)
cmd
.
MarkFlagRequired
(
"value"
)
}
...
...
@@ -102,12 +102,12 @@ func IssuanceDebt(cmd *cobra.Command, args []string) {
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
issuanceID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"issuanceID"
)
value
,
_
:=
cmd
.
Flags
()
.
Get
Uin
t64
(
"value"
)
value
,
_
:=
cmd
.
Flags
()
.
Get
Floa
t64
(
"value"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
IssuanceX
),
ActionName
:
"IssuanceDebt"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
issuanceID
\"
:
\"
%s
\"
,
\"
value
\"
:%
d
}"
,
issuanceID
,
value
)),
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
issuanceID
\"
:
\"
%s
\"
,
\"
value
\"
:%
f
}"
,
issuanceID
,
value
)),
}
var
res
string
...
...
plugin/dapp/issuance/executor/exec_del_local.go
View file @
2f57d651
...
...
@@ -82,3 +82,8 @@ func (c *Issuance) ExecDelLocal_Feed(payload *pty.IssuanceFeed, tx *types.Transa
func
(
c
*
Issuance
)
ExecDelLocal_Close
(
payload
*
pty
.
IssuanceClose
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
// ExecDelLocal_Manage Action
func
(
c
*
Issuance
)
ExecDelLocal_Manage
(
payload
*
pty
.
IssuanceManage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
\ No newline at end of file
plugin/dapp/issuance/executor/exec_local.go
View file @
2f57d651
...
...
@@ -83,3 +83,8 @@ func (c *Issuance) ExecLocal_Feed(payload *pty.IssuanceFeed, tx *types.Transacti
func
(
c
*
Issuance
)
ExecLocal_Close
(
payload
*
pty
.
IssuanceClose
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
// ExecLocal_Manage Action
func
(
c
*
Issuance
)
ExecLocal_Manage
(
payload
*
pty
.
IssuanceManage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
plugin/dapp/issuance/executor/issuance.go
View file @
2f57d651
...
...
@@ -144,7 +144,7 @@ func (c *Issuance) deleteIssuanceRecordStatus(status int32, index int64) (kvs []
return
kvs
}
func
(
c
*
Issuance
)
addIssuancePriceRecord
(
recordTime
int64
,
price
float
32
)
(
kvs
[]
*
types
.
KeyValue
)
{
func
(
c
*
Issuance
)
addIssuancePriceRecord
(
recordTime
int64
,
price
float
64
)
(
kvs
[]
*
types
.
KeyValue
)
{
key
:=
calcIssuancePriceKey
(
string
(
recordTime
))
record
:=
&
pty
.
IssuanceAssetPriceRecord
{
...
...
plugin/dapp/issuance/executor/issuancedb.go
View file @
2f57d651
...
...
@@ -13,6 +13,7 @@ import (
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/issuance/types"
tokenE
"github.com/33cn/plugin/plugin/dapp/token/executor"
"math"
)
// List control
...
...
@@ -25,7 +26,7 @@ const (
const
(
Coin
=
types
.
Coin
// 1e8
DefaultDebtCeiling
=
100000
// 默认借贷限额
DefaultDebtCeiling
=
100000
*
Coin
// 默认借贷限额
DefaultLiquidationRatio
=
0.25
// 默认质押比
DefaultPeriod
=
3600
*
24
*
365
// 默认合约限期
PriceWarningRate
=
1.3
// 价格提前预警率
...
...
@@ -289,8 +290,8 @@ func (action *Action) GetIndex() int64 {
return
action
.
height
*
types
.
MaxTxsPerBlock
+
int64
(
action
.
index
)
}
func
getLatestLiquidationPrice
(
issu
*
pty
.
Issuance
)
float
32
{
var
latest
float
32
func
getLatestLiquidationPrice
(
issu
*
pty
.
Issuance
)
float
64
{
var
latest
float
64
for
_
,
collRecord
:=
range
issu
.
DebtRecords
{
if
collRecord
.
LiquidationPrice
>
latest
{
latest
=
collRecord
.
LiquidationPrice
...
...
@@ -385,7 +386,7 @@ func (action *Action) IssuanceCreate(create *pty.IssuanceCreate) (*types.Receipt
}
// 检查ccny余额
if
!
action
.
CheckExecTokenAccount
(
action
.
fromaddr
,
create
.
TotalBalance
*
Coin
,
false
)
{
if
!
action
.
CheckExecTokenAccount
(
action
.
fromaddr
,
create
.
TotalBalance
,
false
)
{
return
nil
,
types
.
ErrInsufficientBalance
}
...
...
@@ -398,7 +399,7 @@ func (action *Action) IssuanceCreate(create *pty.IssuanceCreate) (*types.Receipt
}
// 冻结ccny
receipt
,
err
=
action
.
tokenAccount
.
ExecFrozen
(
action
.
fromaddr
,
action
.
execaddr
,
create
.
TotalBalance
*
Coin
)
receipt
,
err
=
action
.
tokenAccount
.
ExecFrozen
(
action
.
fromaddr
,
action
.
execaddr
,
create
.
TotalBalance
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceCreate.Frozen"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
create
.
TotalBalance
)
return
nil
,
err
...
...
@@ -445,20 +446,19 @@ func (action *Action) IssuanceCreate(create *pty.IssuanceCreate) (*types.Receipt
}
// 根据最近抵押物价格计算需要冻结的BTY数量
func
getBtyNumToFrozen
(
value
int64
,
price
float
32
,
ratio
float32
)
(
int64
,
error
)
{
func
getBtyNumToFrozen
(
value
int64
,
price
float
64
,
ratio
float64
)
(
int64
,
error
)
{
if
price
==
0
{
clog
.
Error
(
"Bty price should greate to 0"
)
return
0
,
pty
.
ErrPriceInvalid
}
btyValue
:=
float32
(
value
)
/
ratio
btyNum
:=
int64
(
btyValue
/
price
)
+
1
return
btyNum
,
nil
valueReal
:=
float64
(
value
)
/
1e8
btyValue
:=
valueReal
/
(
price
*
ratio
)
return
int64
(
math
.
Trunc
((
btyValue
+
0.0000001
)
*
1e4
))
*
1e4
,
nil
}
// 获取最近抵押物价格
func
getLatestPrice
(
db
dbm
.
KV
)
(
float
32
,
error
)
{
func
getLatestPrice
(
db
dbm
.
KV
)
(
float
64
,
error
)
{
data
,
err
:=
db
.
Get
(
PriceKey
())
if
err
!=
nil
{
clog
.
Error
(
"getLatestPrice"
,
"get"
,
err
)
...
...
@@ -558,13 +558,13 @@ func (action *Action) IssuanceDebt(debt *pty.IssuanceDebt) (*types.Receipt, erro
}
// 检查抵押物账户余额
if
!
action
.
CheckExecAccountBalance
(
action
.
fromaddr
,
btyFrozen
*
Coin
,
0
)
{
if
!
action
.
CheckExecAccountBalance
(
action
.
fromaddr
,
btyFrozen
,
0
)
{
clog
.
Error
(
"IssuanceDebt.CheckExecAccountBalance"
,
"CollID"
,
issu
.
IssuanceId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"btyFrozen"
,
btyFrozen
,
"err"
,
types
.
ErrNoBalance
)
return
nil
,
types
.
ErrNoBalance
}
// 抵押物转账
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransfer
(
action
.
fromaddr
,
issu
.
IssuerAddr
,
action
.
execaddr
,
btyFrozen
*
Coin
)
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransfer
(
action
.
fromaddr
,
issu
.
IssuerAddr
,
action
.
execaddr
,
btyFrozen
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceDebt.ExecTransfer"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
btyFrozen
)
return
nil
,
err
...
...
@@ -573,7 +573,7 @@ func (action *Action) IssuanceDebt(debt *pty.IssuanceDebt) (*types.Receipt, erro
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 抵押物冻结
receipt
,
err
=
action
.
coinsAccount
.
ExecFrozen
(
issu
.
IssuerAddr
,
action
.
execaddr
,
btyFrozen
*
Coin
)
receipt
,
err
=
action
.
coinsAccount
.
ExecFrozen
(
issu
.
IssuerAddr
,
action
.
execaddr
,
btyFrozen
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceDebt.Frozen"
,
"addr"
,
issu
.
IssuerAddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
btyFrozen
)
return
nil
,
err
...
...
@@ -582,7 +582,7 @@ func (action *Action) IssuanceDebt(debt *pty.IssuanceDebt) (*types.Receipt, erro
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 借出ccny
receipt
,
err
=
action
.
tokenAccount
.
ExecTransferFrozen
(
issu
.
IssuerAddr
,
action
.
fromaddr
,
action
.
execaddr
,
debt
.
Value
*
Coin
)
receipt
,
err
=
action
.
tokenAccount
.
ExecTransferFrozen
(
issu
.
IssuerAddr
,
action
.
fromaddr
,
action
.
execaddr
,
debt
.
Value
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceDebt.ExecTokenTransfer"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
debt
.
Value
)
return
nil
,
err
...
...
@@ -663,13 +663,13 @@ func (action *Action) IssuanceRepay(repay *pty.IssuanceRepay) (*types.Receipt, e
}
// 检查
if
!
action
.
CheckExecTokenAccount
(
action
.
fromaddr
,
debtRecord
.
DebtValue
*
Coin
,
false
)
{
if
!
action
.
CheckExecTokenAccount
(
action
.
fromaddr
,
debtRecord
.
DebtValue
,
false
)
{
clog
.
Error
(
"IssuanceRepay"
,
"CollID"
,
issu
.
IssuanceId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"err"
,
types
.
ErrInsufficientBalance
)
return
nil
,
types
.
ErrNoBalance
}
// ccny转移
receipt
,
err
=
action
.
tokenAccount
.
ExecTransfer
(
action
.
fromaddr
,
issu
.
IssuerAddr
,
action
.
execaddr
,
debtRecord
.
DebtValue
*
Coin
)
receipt
,
err
=
action
.
tokenAccount
.
ExecTransfer
(
action
.
fromaddr
,
issu
.
IssuerAddr
,
action
.
execaddr
,
debtRecord
.
DebtValue
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceRepay.ExecTokenTransfer"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
debtRecord
.
DebtValue
)
return
nil
,
err
...
...
@@ -678,7 +678,7 @@ func (action *Action) IssuanceRepay(repay *pty.IssuanceRepay) (*types.Receipt, e
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 冻结ccny
receipt
,
err
=
action
.
tokenAccount
.
ExecFrozen
(
issu
.
IssuerAddr
,
action
.
execaddr
,
debtRecord
.
DebtValue
*
Coin
)
receipt
,
err
=
action
.
tokenAccount
.
ExecFrozen
(
issu
.
IssuerAddr
,
action
.
execaddr
,
debtRecord
.
DebtValue
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceCreate.Frozen"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
debtRecord
.
DebtValue
)
return
nil
,
err
...
...
@@ -687,7 +687,7 @@ func (action *Action) IssuanceRepay(repay *pty.IssuanceRepay) (*types.Receipt, e
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 抵押物归还
receipt
,
err
=
action
.
coinsAccount
.
ExecTransferFrozen
(
issu
.
IssuerAddr
,
action
.
fromaddr
,
action
.
execaddr
,
debtRecord
.
CollateralValue
*
Coin
)
receipt
,
err
=
action
.
coinsAccount
.
ExecTransferFrozen
(
issu
.
IssuerAddr
,
action
.
fromaddr
,
action
.
execaddr
,
debtRecord
.
CollateralValue
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceRepay.ExecTransferFrozen"
,
"addr"
,
issu
.
IssuerAddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
debtRecord
.
CollateralValue
)
return
nil
,
err
...
...
@@ -720,7 +720,7 @@ func (action *Action) IssuanceRepay(repay *pty.IssuanceRepay) (*types.Receipt, e
}
// 系统清算
func
(
action
*
Action
)
systemLiquidation
(
issu
*
pty
.
Issuance
,
price
float
32
)
(
*
types
.
Receipt
,
error
)
{
func
(
action
*
Action
)
systemLiquidation
(
issu
*
pty
.
Issuance
,
price
float
64
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
...
...
@@ -743,7 +743,7 @@ func (action *Action) systemLiquidation(issu *pty.Issuance, price float32) (*typ
}
// 抵押物转移
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransferFrozen
(
issu
.
IssuerAddr
,
getGuarantorAddr
,
action
.
execaddr
,
debtRecord
.
CollateralValue
*
Coin
)
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransferFrozen
(
issu
.
IssuerAddr
,
getGuarantorAddr
,
action
.
execaddr
,
debtRecord
.
CollateralValue
)
if
err
!=
nil
{
clog
.
Error
(
"systemLiquidation"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
debtRecord
.
CollateralValue
,
"err"
,
err
)
continue
...
...
@@ -801,7 +801,7 @@ func (action *Action) expireLiquidation(issu *pty.Issuance) (*types.Receipt, err
}
// 抵押物转移
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransferFrozen
(
issu
.
IssuerAddr
,
getGuarantorAddr
,
action
.
execaddr
,
debtRecord
.
CollateralValue
*
Coin
)
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransferFrozen
(
issu
.
IssuerAddr
,
getGuarantorAddr
,
action
.
execaddr
,
debtRecord
.
CollateralValue
)
if
err
!=
nil
{
clog
.
Error
(
"systemLiquidation"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
debtRecord
.
CollateralValue
,
"err"
,
err
)
continue
...
...
@@ -840,8 +840,8 @@ func (action *Action) expireLiquidation(issu *pty.Issuance) (*types.Receipt, err
}
// 价格计算策略
func
pricePolicy
(
feed
*
pty
.
IssuanceFeed
)
float
32
{
var
totalPrice
float
32
func
pricePolicy
(
feed
*
pty
.
IssuanceFeed
)
float
64
{
var
totalPrice
float
64
var
totalVolume
int64
for
_
,
volume
:=
range
feed
.
Volume
{
totalVolume
+=
volume
...
...
@@ -852,7 +852,7 @@ func pricePolicy(feed *pty.IssuanceFeed) float32 {
return
0
}
for
i
,
price
:=
range
feed
.
Price
{
totalPrice
+=
price
*
float32
(
float64
(
feed
.
Volume
[
i
])
/
float64
(
totalVolume
))
totalPrice
+=
price
*
(
float64
(
feed
.
Volume
[
i
])
/
float64
(
totalVolume
))
}
return
totalPrice
...
...
@@ -955,9 +955,9 @@ func (action *Action) IssuanceClose(close *pty.IssuanceClose) (*types.Receipt, e
}
// 解冻ccny
receipt
,
err
=
action
.
tokenAccount
.
ExecActive
(
action
.
fromaddr
,
action
.
execaddr
,
issuance
.
Balance
*
Coin
)
receipt
,
err
=
action
.
tokenAccount
.
ExecActive
(
action
.
fromaddr
,
action
.
execaddr
,
issuance
.
Balance
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceClose.ExecActive"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
issuance
.
TotalBalance
)
clog
.
Error
(
"IssuanceClose.ExecActive"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
issuance
.
Balance
,
"err"
,
err
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
...
...
plugin/dapp/issuance/proto/issuance.proto
View file @
2f57d651
...
...
@@ -7,13 +7,13 @@ message Issuance {
string
issuanceId
=
1
;
//发行ID,一期发行对应一个ID
int64
totalBalance
=
2
;
//当期发行的总金额(ccny)
int64
debtCeiling
=
3
;
//单用户可借出的限额(ccny)
float
liquidationRatio
=
4
;
//清算比例
double
liquidationRatio
=
4
;
//清算比例
int64
collateralValue
=
5
;
//抵押物总数量(bty)
int64
debtValue
=
6
;
//产生的ccny数量
repeated
DebtRecord
debtRecords
=
7
;
//大户抵押记录
repeated
DebtRecord
invalidRecords
=
8
;
//大户抵押记录
int32
status
=
9
;
//当期发行的状态,是否关闭
float
latestLiquidationPrice
=
10
;
//最高清算价格
double
latestLiquidationPrice
=
10
;
//最高清算价格
int64
period
=
11
;
//发行最大期限
int64
latestExpireTime
=
12
;
//最近超期时间
int64
createTime
=
13
;
//创建时间
...
...
@@ -28,9 +28,9 @@ message DebtRecord {
string
accountAddr
=
1
;
//抵押人地址
int64
startTime
=
2
;
//抵押时间
int64
collateralValue
=
3
;
//抵押物价值(bty)
float
collateralPrice
=
4
;
//抵押物价格
double
collateralPrice
=
4
;
//抵押物价格
int64
debtValue
=
5
;
//债务价值(ccny)
float
liquidationPrice
=
6
;
//抵押物清算价格
double
liquidationPrice
=
6
;
//抵押物清算价格
int32
status
=
7
;
//抵押状态,是否被清算
int64
liquidateTime
=
8
;
//清算时间
int64
expireTime
=
9
;
//超时清算时间
...
...
@@ -44,7 +44,7 @@ message DebtRecord {
// 资产价格记录
message
IssuanceAssetPriceRecord
{
int64
recordTime
=
1
;
//价格记录时间
float
btyPrice
=
2
;
//bty价格
double
btyPrice
=
2
;
//bty价格
}
// action
...
...
@@ -68,7 +68,7 @@ message IssuanceManage {
message
IssuanceCreate
{
int64
totalBalance
=
1
;
//发行总金额
int64
debtCeiling
=
2
;
//单用户可借出的限额(ccny)
float
liquidationRatio
=
3
;
//清算比例
double
liquidationRatio
=
3
;
//清算比例
int64
period
=
4
;
//发行最大期限
}
...
...
@@ -87,7 +87,7 @@ message IssuanceRepay {
// 喂价
message
IssuanceFeed
{
int32
collType
=
1
;
//抵押物价格类型(1,bty,2,btc,3,eth...)
repeated
float
price
=
2
;
//喂价
repeated
double
price
=
2
;
//喂价
repeated
int64
volume
=
3
;
//成交量
}
...
...
@@ -106,7 +106,7 @@ message ReceiptIssuance {
int64
index
=
6
;
int64
preIndex
=
7
;
int64
recordTime
=
8
;
//价格记录时间
float
btyPrice
=
9
;
//bty价格
double
btyPrice
=
9
;
//bty价格
}
// exec_local 抵押记录信息
...
...
@@ -132,7 +132,7 @@ message RepIssuanceCurrentInfo {
int32
status
=
1
;
//当期发行的状态,是否关闭
int64
totalBalance
=
2
;
//当期发行总金额(ccny)
int64
debtCeiling
=
3
;
//单用户可借出的限额(ccny)
float
liquidationRatio
=
4
;
//清算比例
double
liquidationRatio
=
4
;
//清算比例
int64
balance
=
5
;
//剩余可借贷金额(ccny)
int64
collateralValue
=
6
;
//抵押物总数量(bty)
int64
debtValue
=
7
;
//产生的ccny数量
...
...
@@ -195,5 +195,5 @@ message RepIssuanceDebtInfo {
// 返回最新抵押物价格
message
RepIssuancePrice
{
float
price
=
1
;
//当前抵押物最新价格
double
price
=
1
;
//当前抵押物最新价格
}
\ No newline at end of file
plugin/dapp/issuance/types/issuance.go
View file @
2f57d651
...
...
@@ -6,6 +6,7 @@ package types
import
(
"encoding/json"
"math"
"reflect"
"github.com/33cn/chain33/common/address"
...
...
@@ -143,8 +144,8 @@ func CreateRawIssuanceCreateTx(cfg *types.Chain33Config, parm *IssuanceCreateTx)
}
v
:=
&
IssuanceCreate
{
TotalBalance
:
parm
.
TotalBalance
,
DebtCeiling
:
parm
.
DebtCeiling
,
TotalBalance
:
int64
(
math
.
Trunc
((
parm
.
TotalBalance
+
0.0000001
)
*
1e4
))
*
1e4
,
DebtCeiling
:
int64
(
math
.
Trunc
((
parm
.
DebtCeiling
+
0.0000001
)
*
1e4
))
*
1e4
,
LiquidationRatio
:
parm
.
LiquidationRatio
,
Period
:
parm
.
Period
,
}
...
...
@@ -175,7 +176,7 @@ func CreateRawIssuanceDebtTx(cfg *types.Chain33Config, parm *IssuanceDebtTx) (*t
v
:=
&
IssuanceDebt
{
IssuanceId
:
parm
.
IssuanceID
,
Value
:
parm
.
Value
,
Value
:
int64
(
math
.
Trunc
((
parm
.
Value
+
0.0000001
)
*
1e4
))
*
1e4
,
}
debt
:=
&
IssuanceAction
{
Ty
:
IssuanceActionDebt
,
...
...
plugin/dapp/issuance/types/issuance.pb.go
View file @
2f57d651
This diff is collapsed.
Click to expand it.
plugin/dapp/issuance/types/tx.go
View file @
2f57d651
...
...
@@ -6,17 +6,17 @@ package types
// IssuanceCreateTx for construction
type
IssuanceCreateTx
struct
{
DebtCeiling
in
t64
`json:"debtCeiling"`
LiquidationRatio
float
32
`json:"liquidationRatio"`
DebtCeiling
floa
t64
`json:"debtCeiling"`
LiquidationRatio
float
64
`json:"liquidationRatio"`
Period
int64
`json:"period"`
TotalBalance
in
t64
`json:"totalBalance"`
TotalBalance
floa
t64
`json:"totalBalance"`
Fee
int64
`json:"fee"`
}
// IssuanceDebtTx for construction
type
IssuanceDebtTx
struct
{
IssuanceID
string
`json:"issuanceId"`
Value
in
t64
`json:"value"`
Value
floa
t64
`json:"value"`
Fee
int64
`json:"fee"`
}
...
...
@@ -29,7 +29,7 @@ type IssuanceRepayTx struct {
// IssuanceFeedTx for construction
type
IssuanceFeedTx
struct
{
Price
[]
float
32
`json:"price"`
Price
[]
float
64
`json:"price"`
Volume
[]
int64
`json:"volume"`
Fee
int64
`json:"fee"`
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment