Skip to content

Commit 6fcbffa

Browse files
authored
Merge pull request #8 from quantnetwork/dev
Dev
2 parents 29cf393 + d1604e0 commit 6fcbffa

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
trigger = "transaction"; // Trigger definition - The automation will trigger on specified transactions.
2+
3+
// Define the parameters required
4+
def reserveId = ${reserveId:String}; // The reserve where tax will be sent to
5+
def taxFactor = ${taxFactor:decimal}; // What portion of the payment is owed in taxes
6+
7+
8+
// Basic validation
9+
if (taxFactor <= BigDecimal.ZERO || taxFactor > BigDecimal.ONE) {
10+
throw new IllegalArgumentException("Invalid taxFactor: ${taxFactor}. Must be > 0 and ≤ 1.");
11+
}
12+
13+
14+
// Unpack values from the payment event that triggered this script.
15+
def eventPaymentId = event[paymentId:string];
16+
def eventPaymentInfo = getPaymentInfo(eventPaymentId);
17+
def eventPaymentAmount = eventPaymentInfo.amountInfo.amount;
18+
19+
20+
// Calculate the tax amount to be saved
21+
def saveTaxAmount = eventPaymentAmount.multiply(taxFactor);
22+
23+
// Add funds to reserve
24+
addFundsToReserve(eventPaymentInfo.payee.identifier, reserveId, saveTaxAmount, "Automated tax optimisation");
25+
26+
// Log useful information
27+
println("Saving tax completed successfully to reserve: ${reserveId}");
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Tax Optimisation
3+
parent: Example Scripts
4+
layout: page
5+
---
6+
7+
# Reserve Funds
8+
This script triggers on incoming transactions to set aside a percentage of the transaction into a reserve, for the purposes of saving it for tax payments.
9+
10+
<div style="text-align: center;" markdown="1">
11+
[Download](tax_optimisation.groovy){: .btn }
12+
</div>
13+
14+
{% highlight groovy %}
15+
{% include_relative tax_optimisation.groovy %}
16+
{% endhighlight %}

docs/payscript/example_scripts/topup.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def account_parent = ${account_parent:scan};
44
def account_child = ${account_child:scan};
55
def topUpGoal = ${topUpGoal:decimal};
66

7-
balance = getBalance(account_child);
7+
balance = getBalance(account_child).getAvailableBalance();
88

99
if (balance < topUpGoal) {
1010
def payment = PaymentInfo.builder()

docs/tutorials/tutorial_reserves.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ nav_order: 4
66
---
77

88
# Reserves
9-
Reserves are an abstract segregation of funds that can be used to help manage an account's funds. Funds that are moved to a reserve are still in that acconut, and count toward its total balance, however they won't count towards their available balance and won't be able to be used until it is moved out of the reserve.
9+
Reserves are an abstract segregation of funds that can be used to help manage an account's funds. Funds that are moved to a reserve are still in that acconut, and count toward its total balance, however they won't count towards their available balance and won't be able to be used until they are moved out of the reserve. Reserves also keep a history of the transactions made to and from them.
10+
1011

1112
<div style="text-align: center;">
1213
<img src="/assets/images/tutorial3/reserves.png" width="90%">
1314
</div>
1415

15-
Reserves also keep a history of the transactions made to and from them.
16+
{% highlight groovy %}
17+
{% include payscript/example_scripts/tax_optimisation.groovy %}
18+
{% endhighlight %}

0 commit comments

Comments
 (0)