-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feature) Add support for intial state computation; Bump Ergo 0.0.65
Signed-off-by: Jerome Simeon <[email protected]>
- Loading branch information
1 parent
e50b0e8
commit 8458c15
Showing
20 changed files
with
5,650 additions
and
3,140 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/cicero-cli/test/data/latedeliveryandpenalty/contract.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"$class":"org.accordproject.latedeliveryandpenalty.TemplateModel","clauseId":"09db8154-ee1c-47f5-96a5-a6120940d815","forceMajeure":true,"penaltyDuration":{"$class":"org.accordproject.time.Duration","amount":9,"unit":"days"},"penaltyPercentage":7,"capPercentage":2,"termination":{"$class":"org.accordproject.time.Duration","amount":2,"unit":"weeks"},"fractionalPart":"days"} | ||
{"$class":"org.accordproject.latedeliveryandpenalty.TemplateModel","clauseId":"abfb8f76-69b5-480e-a530-7f5c87779a8c","forceMajeure":true,"penaltyDuration":{"$class":"org.accordproject.time.Duration","amount":9,"unit":"days"},"penaltyPercentage":7,"capPercentage":2,"termination":{"$class":"org.accordproject.time.Duration","amount":2,"unit":"weeks"},"fractionalPart":"days"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/cicero-engine/test/data/installment-sale-ergo/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
# Installment Sale | ||
|
||
A simple clause for a sale paid in installments. |
7 changes: 7 additions & 0 deletions
7
packages/cicero-engine/test/data/installment-sale-ergo/grammar/template.tem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[{BUYER}] agrees to pay to [{SELLER}] the total sum e[{INITIAL_DUE}], in the manner following: | ||
|
||
E[{DUE_AT_CLOSING}] is to be paid at closing, and the remaining balance of E[{TOTAL_DUE_BEFORE_CLOSING}] shall be paid as follows: | ||
|
||
E[{MIN_PAYMENT}] or more per month on the first day of each and every month, and continuing until the entire balance, including both principal and interest, shall be paid in full -- provided, however, that the entire balance due plus accrued interest and any other amounts due here-under shall be paid in full on or before 24 months. | ||
|
||
Monthly payments shall include both principal and interest with interest at the rate of [{INTEREST_RATE}]%, computed monthly on the remaining balance from time to time unpaid. |
72 changes: 72 additions & 0 deletions
72
packages/cicero-engine/test/data/installment-sale-ergo/lib/logic.ergo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
namespace org.accordproject.installmentsale | ||
|
||
contract InstallmentSale over TemplateModel { | ||
clause init(request : InitializeRequest) : InitializeResponse { | ||
set state new InstallmentSaleState{ | ||
stateId: "org.accordproject.installmentsale.InstallmentSaleState#1", | ||
status: "WaitingForFirstDayOfNextMonth", | ||
balance_remaining: contract.INITIAL_DUE, | ||
total_paid: 0.0, | ||
next_payment_month: request.firstMonth | ||
}; | ||
return new InitializeResponse{} | ||
} | ||
|
||
clause PayInstallment(request : Installment) : Balance emits PaymentObligation { | ||
// enforce (state.status = "WaitingForFirstDayOfNextMonth"); // Make sure this is only called in the right state | ||
// enforce (contract.MIN_PAYMENT <= state.balance_remaining) and (state.next_payment_month < 23); | ||
// enforce (contract.MIN_PAYMENT <= request.amount); // Underpaying is forbidden | ||
// enforce (request.amount <= state.balance_remaining); // overpaying is forbidden. this is NOT checked statically. | ||
define variable before_interest = state.balance_remaining - request.amount; | ||
define variable balance = before_interest * (1.0 + contract.INTEREST_RATE/100.00); | ||
define variable total_paid = state.total_paid + request.amount; | ||
set state new InstallmentSaleState{ | ||
stateId: "1", | ||
status: "WaitingForFirstDayOfNextMonth", | ||
balance_remaining: balance, | ||
total_paid: total_paid, | ||
next_payment_month: state.next_payment_month + 1.0 | ||
}; | ||
emit new PaymentObligation{ | ||
party: contract.BUYER, | ||
amount: request.amount | ||
}; | ||
return new Balance{ | ||
balance: balance, | ||
total_paid: total_paid | ||
} | ||
} | ||
clause PayLastInstallment(request : ClosingPayment) : Balance emits PaymentObligation { | ||
enforce (request.amount = state.balance_remaining + contract.DUE_AT_CLOSING); | ||
define variable balance = state.balance_remaining + contract.DUE_AT_CLOSING - request.amount; | ||
define variable total_paid = state.total_paid + request.amount; | ||
set state new InstallmentSaleState{ | ||
stateId: "1", | ||
status: "Fulfilled", | ||
balance_remaining: balance, | ||
total_paid: total_paid, | ||
next_payment_month: 0.0 // ??? | ||
}; | ||
emit new PaymentObligation{ | ||
party: contract.BUYER, | ||
amount: request.amount | ||
}; | ||
return new Balance{ | ||
balance: balance, | ||
total_paid: total_paid | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.