Skip to content

Commit

Permalink
wip promissory note using Ergo
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Selman <danscode@selman.org>
  • Loading branch information
dselman committed May 9, 2018
1 parent 3d3adbb commit 0d98b8a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
6 changes: 6 additions & 0 deletions latedeliveryandpenalty/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
"name": "latedeliveryandpenalty",
"version": "0.0.4",
"description": "A sample Late Delivery And Penalty clause.",
"author": "clause.io",
"license": "Apache-2.0",
"engines": {
"cicero": "^0.2.28"
},
"repository": {
"type": "git",
"url": "git+https://github.com/accordproject/cicero-template-library.git"
},
"scripts": {
"test": "mocha"
},
Expand Down
19 changes: 18 additions & 1 deletion promissory-note/lib/logic.ergo
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,27 @@

namespace org.accordproject.promissorynote

//import ergo.moment.*

define function compoundInterestMultiple(annualInterest Double, numberOfDays Double) : Double {
enforce annualInterest >= 0.0;
enforce numberOfDays >= 0.0;
// TODO (DCS) replace * with pow when supported
(1.0 + annualInterest) * (numberOfDays / 365.0)
}

contract PromissoryNote over TemplateModel {
clause check(request Request) : Response {
enforce contract.dollarAmount >= 0.0;
let outstanding = contract.dollarAmount - request.amountPaid;
enforce outstanding >= 0.0;

let numberOfDays = momentDiff(request.timestamp,contract.date);
enforce numberOfDays >= 0.0;
let compounded = outstanding * compoundInterestMultiple(contract.interestRate, numberOfDays);

return new Response{
outstandingBalance: 200.0
outstandingBalance: compounded
}
}
}
8 changes: 4 additions & 4 deletions promissory-note/models/model.cto
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace org.accordproject.promissorynote

transaction Request {
o Integer amountPaid
o Double amountPaid
}

transaction Response {
o Integer outstandingBalance
o Double outstandingBalance
}

enum LegalEntity {
Expand All @@ -23,7 +23,7 @@ concept TemplateModel {
/**
* The name for the clause
*/
o Integer dollarAmount
o Double dollarAmount
o DateTime date
o String maker
o Double interestRate
Expand All @@ -32,7 +32,7 @@ concept TemplateModel {
o String lender
o LegalEntity legalEntity
o String lenderAddress
o Integer principal
o Double principal
o DateTime maturityDate
o Integer defaultDays
o Integer insolvencyDays
Expand Down
6 changes: 6 additions & 0 deletions promissory-note/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
"name": "promissory-note",
"version": "0.0.1",
"description": "A promissory note",
"author": "clause.io",
"license": "Apache-2.0",
"engines": {
"cicero": "^0.2.54"
},
"repository": {
"type": "git",
"url": "git+https://github.com/accordproject/cicero-template-library.git"
},
"scripts": {
"test": "mocha"
},
Expand Down
4 changes: 2 additions & 2 deletions promissory-note/test/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ describe('Logic', () => {
it('should execute a smart clause', async function () {
const request = {
"$class": "org.accordproject.promissorynote.Request",
"amountPaid": 100
"amountPaid": 100.0
};
const result = await engine.execute(clause, request);
result.should.not.be.null;
result.response.outstandingBalance.should.equal(200);
result.response.outstandingBalance.should.greaterThan(200);
});
});
});

0 comments on commit 0d98b8a

Please sign in to comment.