您好,登錄后才能下訂單哦!
本篇內容介紹了“Bytom儲蓄分紅合約怎么實現”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
儲蓄分紅合約指的是項目方發起了一個鎖倉計劃(即儲蓄合約和取現合約),用戶可以在準備期自由選擇鎖倉金額參與該計劃,等到鎖倉到期之后還可以自動獲取鎖倉的利潤。用戶可以在準備期內(dueBlockHeight
)參與儲蓄,按照合約規定可以 1:1
獲取同等數量的儲蓄票據資產,同時用戶鎖倉的資產(deposit
)將放到取現合約中,并且項目方是無法動用的,等到鎖倉期限(expireBlockHeight
)一到,用戶便可以調用取現合約將自己儲蓄的資產連本待息一同取出來。
// 儲蓄合約 import "./FixedLimitProfit" contract FixedLimitCollect(assetDeposited: Asset, totalAmountBill: Amount, totalAmountCapital: Amount, dueBlockHeight: Integer, expireBlockHeight: Integer, additionalBlockHeight: Integer, banker: Program, bankerKey: PublicKey) locks billAmount of billAsset { clause collect(amountDeposited: Amount, saver: Program) { verify below(dueBlockHeight) verify amountDeposited <= billAmount && totalAmountBill <= totalAmountCapital define sAmountDeposited: Integer = amountDeposited/100000000 define sTotalAmountBill: Integer = totalAmountBill/100000000 verify sAmountDeposited > 0 && sTotalAmountBill > 0 if amountDeposited < billAmount { lock amountDeposited of assetDeposited with FixedLimitProfit(billAsset, totalAmountBill, totalAmountCapital, expireBlockHeight, additionalBlockHeight, banker, bankerKey) lock amountDeposited of billAsset with saver lock billAmount-amountDeposited of billAsset with FixedLimitCollect(assetDeposited, totalAmountBill, totalAmountCapital, dueBlockHeight, expireBlockHeight, additionalBlockHeight, banker, bankerKey) } else { lock amountDeposited of assetDeposited with FixedLimitProfit(billAsset, totalAmountBill, totalAmountCapital, expireBlockHeight, additionalBlockHeight, banker, bankerKey) lock billAmount of billAsset with saver } } clause cancel(bankerSig: Signature) { verify above(dueBlockHeight) verify checkTxSig(bankerKey, bankerSig) unlock billAmount of billAsset } }
// 取現合約(本金加利息) contract FixedLimitProfit(assetBill: Asset, totalAmountBill: Amount, totalAmountCapital: Amount, expireBlockHeight: Integer, additionalBlockHeight: Integer, banker: Program, bankerKey: PublicKey) locks capitalAmount of capitalAsset { clause profit(amountBill: Amount, saver: Program) { verify above(expireBlockHeight) define sAmountBill: Integer = amountBill/100000000 define sTotalAmountBill: Integer = totalAmountBill/100000000 verify sAmountBill > 0 && sTotalAmountBill > 0 && amountBill < totalAmountBill define gain: Integer = totalAmountCapital*sAmountBill/sTotalAmountBill verify gain > 0 && gain <= capitalAmount if gain < capitalAmount { lock amountBill of assetBill with banker lock gain of capitalAsset with saver lock capitalAmount - gain of capitalAsset with FixedLimitProfit(assetBill, totalAmountBill, totalAmountCapital, expireBlockHeight, additionalBlockHeight, banker, bankerKey) } else { lock amountBill of assetBill with banker lock capitalAmount of capitalAsset with saver } } clause cancel(bankerSig: Signature) { verify above(additionalBlockHeight) verify checkTxSig(bankerKey, bankerSig) unlock capitalAmount of capitalAsset } }
合約的源代碼說明可以具體參考Equity合約介紹
.
時間期限不是具體的時間,而是通過區塊高度來大概估算的(平均區塊時間間隔大概為2.5
分鐘)
比原的精度是8
, 即 1BTM = 100000000 neu
,正常情況下參與計算都是以neu
為單位的,然而虛擬機的int64
類型的最大值是9223372036854775807
,為了避免數值太大導致計算溢出,所以對計算的金額提出了金額限制(即amountBill/100000000
)
另外clause cancel
是項目方的管理方法,如果儲蓄或者取現沒有滿額,項目方也可以回收剩余的資產
編譯Equity
合約可以參考一下Equity
編譯器的介紹說明。假如儲蓄合約FixedLimitCollect
的參數如下:
assetDeposited :c6b12af8326df37b8d77c77bfa2547e083cbacde15cc48da56d4aa4e4235a3ee totalAmountBill :10000000000 totalAmountCapital :20000000000 dueBlockHeight :1070 expireBlockHeight :1090 additionalBlockHeight :1100 banker :0014dedfd406c591aa221a047a260107f877da92fec5 bankerKey :055539eb36abcaaf127c63ae20e3d049cd28d0f1fe569df84da3aedb018ca1bf
其中bankerKey
是管理員的publicKey
,可以通過比原鏈的接口list-pubkeys
來獲取,注意管理員需要保存一下對應的rootXpub
和Path
,否則無法正確調用clause cancel
。
實例化合約命令如下:
// 儲蓄合約 ./equity FixedLimitCollect --instance c6b12af8326df37b8d77c77bfa2547e083cbacde15cc48da56d4aa4e4235a3ee 10000000000 20000000000 1070 1090 1100 0014dedfd406c591aa221a047a260107f877da92fec5 055539eb36abcaaf127c63ae20e3d049cd28d0f1fe569df84da3aedb018ca1bf // 取現合約 ./equity FixedLimitProfit --instance c6b12af8326df37b8d77c77bfa2547e083cbacde15cc48da56d4aa4e4235a3ee 10000000000 20000000000 1090 1100 0014dedfd406c591aa221a047a260107f877da92fec5 055539eb36abcaaf127c63ae20e3d049cd28d0f1fe569df84da3aedb018ca1bf
發布合約交易即將資產鎖定到合約中。由于目前無法在比原的dashboard
上構造合約交易,所以需要借助外部工具來發送合約交易,比如postman
。按照上述示意圖所示,項目方需要發布1000
個儲蓄資產的儲蓄合約和200
個利息資產取現合約。假設項目方需要發布1000
個儲蓄資產(假如精度為8
,那么1000
個在比原鏈中表示為100000000000
)的鎖倉合約,那么他需要將對應數量的票據鎖定在儲蓄合約中,其交易模板如下:
{ "base_transaction": null, "actions": [ { "account_id": "0ILGLSTC00A02", "amount": 20000000, "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "type": "spend_account" }, { "account_id": "0ILGLSTC00A02", "amount": 100000000000, "asset_id": "13016eff73ffb7539a69e122f80f5c1cc94446773ac3f64dec290429f87e73b3", "type": "spend_account" }, { "amount": 100000000000, "asset_id": "13016eff73ffb7539a69e122f80f5c1cc94446773ac3f64dec290429f87e73b3", "control_program": "20055539eb36abcaaf127c63ae20e3d049cd28d0f1fe569df84da3aedb018ca1bf160014dedfd406c591aa221a047a260107f877da92fec5024c04024204022e040500c817a8040500e40b540220c6b12af8326df37b8d77c77bfa2547e083cbacde15cc48da56d4aa4e4235a3ee4d3b02597a642f0200005479cda069c35b797ca153795579a19a695a790400e1f5059653790400e1f505967c00a07c00a09a69c35b797c9f9161644d010000005b79c2547951005e79895d79895c79895b7989597989587989537a894caa587a649e0000005479cd9f6959790400e1f5059653790400e1f505967800a07800a09a5c7956799f9a6955797b957c96c37800a052797ba19a69c3787c9f91616487000000005b795479515b79c1695178c2515d79c16952c3527994c251005d79895c79895b79895a79895979895879895779895679890274787e008901c07ec1696399000000005b795479515b79c16951c3c2515d79c16963aa000000557acd9f69577a577aae7cac890274787e008901c07ec169515b79c2515d79c16952c35c7994c251005d79895c79895b79895a79895979895879895779895679895579890274787e008901c07ec169632a020000005b79c2547951005e79895d79895c79895b7989597989587989537a894caa587a649e0000005479cd9f6959790400e1f5059653790400e1f505967800a07800a09a5c7956799f9a6955797b957c96c37800a052797ba19a69c3787c9f91616487000000005b795479515b79c1695178c2515d79c16952c3527994c251005d79895c79895b79895a79895979895879895779895679890274787e008901c07ec1696399000000005b795479515b79c16951c3c2515d79c16963aa000000557acd9f69577a577aae7cac890274787e008901c07ec16951c3c2515d79c169633b020000547acd9f69587a587aae7cac747800c0", "type": "control_program" } ], "ttl": 0, "time_range": 1521625823 }
合約交易成功后,合約control_program
對應的UTXO
將會被所有用戶查詢到,使用比原鏈的接口list-unspent-outputs
即可查詢。
此外,開發者需要存儲一下合約UTXO
的assetID
和program
,以便在DAPP
的前端頁面的config
配置文件和bufferserver
緩沖服務器中調用。如上所示:
// 儲蓄合約 assetID:13016eff73ffb7539a69e122f80f5c1cc94446773ac3f64dec290429f87e73b3 program:20055539eb36abcaaf127c63ae20e3d049cd28d0f1fe569df84da3aedb018ca1bf160014dedfd406c591aa221a047a260107f877da92fec5024c04024204022e040500c817a8040500e40b540220c6b12af8326df37b8d77c77bfa2547e083cbacde15cc48da56d4aa4e4235a3ee4d3b02597a642f0200005479cda069c35b797ca153795579a19a695a790400e1f5059653790400e1f505967c00a07c00a09a69c35b797c9f9161644d010000005b79c2547951005e79895d79895c79895b7989597989587989537a894caa587a649e0000005479cd9f6959790400e1f5059653790400e1f505967800a07800a09a5c7956799f9a6955797b957c96c37800a052797ba19a69c3787c9f91616487000000005b795479515b79c1695178c2515d79c16952c3527994c251005d79895c79895b79895a79895979895879895779895679890274787e008901c07ec1696399000000005b795479515b79c16951c3c2515d79c16963aa000000557acd9f69577a577aae7cac890274787e008901c07ec169515b79c2515d79c16952c35c7994c251005d79895c79895b79895a79895979895879895779895679895579890274787e008901c07ec169632a020000005b79c2547951005e79895d79895c79895b7989597989587989537a894caa587a649e0000005479cd9f6959790400e1f5059653790400e1f505967800a07800a09a5c7956799f9a6955797b957c96c37800a052797ba19a69c3787c9f91616487000000005b795479515b79c1695178c2515d79c16952c3527994c251005d79895c79895b79895a79895979895879895779895679890274787e008901c07ec1696399000000005b795479515b79c16951c3c2515d79c16963aa000000557acd9f69577a577aae7cac890274787e008901c07ec16951c3c2515d79c169633b020000547acd9f69587a587aae7cac747800c0 // 取現合約 assetID:c6b12af8326df37b8d77c77bfa2547e083cbacde15cc48da56d4aa4e4235a3ee program:20055539eb36abcaaf127c63ae20e3d049cd28d0f1fe569df84da3aedb018ca1bf160014dedfd406c591aa221a047a260107f877da92fec5024c040242040500c817a8040500e40b540220c6b12af8326df37b8d77c77bfa2547e083cbacde15cc48da56d4aa4e4235a3ee4caa587a649e0000005479cd9f6959790400e1f5059653790400e1f505967800a07800a09a5c7956799f9a6955797b957c96c37800a052797ba19a69c3787c9f91616487000000005b795479515b79c1695178c2515d79c16952c3527994c251005d79895c79895b79895a79895979895879895779895679890274787e008901c07ec1696399000000005b795479515b79c16951c3c2515d79c16963aa000000557acd9f69577a577aae7cac747800c0
“Bytom儲蓄分紅合約怎么實現”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。