Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Insurance / Crowdfunding
- In this case, we want to add token's users' protection from financial loss. For example, users want to have a guarantee that in the case of token depreciation they will get a full initial price of this tokens, For this service, they must pay some reasonable amount of money in addition to token price.
- For an implementation of token insurance, you can issue “insured tokens”. Then you need to set a script to the wallet-account which allows ExchangeTransactions that satisfy the following conditions. To prevent double-spending you should ask a client to send a DataTransaction beforehand to your account with (key, value) = (purchaseTransactionId, sellOrderId) and prohibit setting DataTransactions with the same keys. It is the reason why the proof must contain the ID of the insured-token purchase transaction. Asset pair must be the same as in the purchase transaction, the price must be equal to the purchase price minus the price of the insurance itself.
- It is implied that you're gonna buy insured-tokens from a client at a price not lower than the purchase price: you create an ExchangeTransaction, the client signs an order (if everything suits them), you sign the second order and the whole transaction and put it in the blockchain. If you do not do this, then after a certain time the client is able to an ExchangeTransaction according to the rules described in the script, and put it in the blockchain - that is, the client is able to return the money for which this token was bought.
- # insuranceWalletAccount
- let insuranceToken = base58'8jfD2JBLe23XtCCSQoTx5eAW5QCU6Mbxi3r78aNQLcNf'
- let this = extract(tx.sender)
- let freezePeriod = 150000
- let insurancePrice = 10000
- match tx {
- case d : DataTransaction => size(d.data) == 1 && !isDefined(getBinary(this, d.data[0].key))
- case e : ExchangeTransaction =>
- if !isDefined(e.proofs[7]) then
- sigVerify(e.bodyBytes, e.proofs[0], e.senderPublicKey)
- else
- let purchaseTx = transactionById(e.proofs[7])
- let purchaseTxHeight = extract(transactionHeightById(e.proofs[7]))
- match purchaseTx {
- case purchase : ExchangeTransaction =>
- let correctSender = purchase.sender == e.sellOrder.sender
- let correctAssetPair = e.sellOrder.assetPair.amountAsset == insuranceToken &&
- purchase.sellOrder.assetPair.amountAsset == insuranceToken &&
- e.sellOrder.assetPair.priceAsset == purchase.sellOrder.assetPair.priceAsset
- let correctPrice = e.price == purchase.price - insurancePrice && e.amount == purchase.amount
- let correctHeight = height > purchaseTxHeight + freezePeriod
- let correctProof = extract(getBinary(this, toBase58String(purchase.id))) == e.sellOrder.id
- correctSender && correctAssetPair && correctPrice && correctHeight && correctProof
- case _ => false
- }
- case _ => sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement