Skip to content

Commit

Permalink
(feature) Add support for intial state computation; Bump Ergo 0.0.65
Browse files Browse the repository at this point in the history
Signed-off-by: Jerome Simeon <[email protected]>
  • Loading branch information
jeromesimeon committed Jun 12, 2018
1 parent e50b0e8 commit 8458c15
Show file tree
Hide file tree
Showing 20 changed files with 5,650 additions and 3,140 deletions.
5,616 changes: 2,633 additions & 2,983 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/cicero-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"dependencies": {
"@accordproject/cicero-core": "0.4.1",
"@accordproject/cicero-engine": "0.4.1",
"@accordproject/ergo-compiler": "0.0.63",
"@accordproject/ergo-compiler": "0.0.65",
"composer-common": "0.19.8",
"uuid": "3.2.1",
"yargs": "9.0.1"
Expand Down
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"}
2 changes: 1 addition & 1 deletion packages/cicero-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"nyc": "11.7.2"
},
"dependencies": {
"@accordproject/ergo-compiler": "0.0.63",
"@accordproject/ergo-compiler": "0.0.65",
"composer-common": "0.19.8",
"debug": "2.6.2",
"glob": "7.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/cicero-engine/lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class Engine {
let methods = '';
if (functionDeclarations.length === 0) {
methods += `
return { response: null, state: { '$class': 'org.accordproject.cicero.contract.AccordContractState', 'stateId' : '1' }, emit: [] };`;
return { response: serializer.fromJSON({ '$class': 'org.accordproject.cicero.runtime.Response' }, {validate: false, acceptResourcesForRelationships: true}), state: serializer.fromJSON({ '$class': 'org.accordproject.cicero.contract.AccordContractState', 'stateId' : 'org.accordproject.cicero.contract.AccordContractState#1' }, {validate: false, acceptResourcesForRelationships: true}), emit: [] };`;
} else {
const ele = functionDeclarations[0];
methods += `
Expand Down
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.
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.
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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import org.accordproject.cicero.contract.* from https://models.accordproject.org
import org.accordproject.cicero.runtime.* from https://models.accordproject.org/cicero/runtime.cto
import org.accordproject.money.MonetaryAmount from https://models.accordproject.org/money.cto

import org.accordproject.purchaseorder.*

transaction Initialize {
transaction InitializeRequest {
o Double firstMonth
}
transaction InitializeResponse {
}

transaction Installment extends Request {
o Double amount
Expand All @@ -34,10 +34,6 @@ enum ContractStatus {
concept MyObligation {
o String party
}
concept DeliveryObligation extends MyObligation {
o DateTime expectedDelivery
o OrderItem[] deliverables
}
concept PurchaseObligation extends MyObligation {
o Double requiredPurchase
o Integer year
Expand Down
Loading

0 comments on commit 8458c15

Please sign in to comment.