-
Notifications
You must be signed in to change notification settings - Fork 33
/
Taxation.ride
33 lines (29 loc) · 1.44 KB
/
Taxation.ride
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# This script allows to apply taxation models to assets
# Token owners can transfer it only if they pay taxes to the issuer
# The tax size is defined by token issuer in data transaction
{-# STDLIB_VERSION 2 #-}
{-# CONTENT_TYPE EXPRESSION #-}
{-# SCRIPT_TYPE ASSET #-}
match (tx) {
# we allow only mass transfer transactions
# first transfer in MassTransfer should always go to the issuer
case mtt:MassTransferTransaction => {
let firstRecipient = mtt.transfers[0].recipient
let firstAmount = mtt.transfers[0].amount
let assetId = extract(mtt.assetId)
let issueTransaction = transactionById(assetId)
# assetId equals to issue transaction id, so we can get issuer public key (and address) from the issue transaction
match(issueTransaction) {
case issueTx: IssueTransaction => {
let issuerAddress = addressFromPublicKey(issueTx.senderPublicKey)
# to set tax amount, issuer should make a data transaction with integer value by key matching assetId
let taxSize = extract(getInteger(issuerAddress, toBase58String(assetId)))
firstRecipient == issuerAddress # recipient for the first transfer should be the issuer address
&&
firstAmount >= mtt.totalAmount / 100 * taxSize # tax amount can't be less than defined in data transaction
}
case _ => false
}
}
case _ => false
}