Skip to content

Commit

Permalink
Merge pull request #34 from dselman/master
Browse files Browse the repository at this point in the history
wip for promissory note
  • Loading branch information
dselman authored May 9, 2018
2 parents c95f47d + 0d98b8a commit e0f8aba
Show file tree
Hide file tree
Showing 10 changed files with 2,175 additions and 0 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
95 changes: 95 additions & 0 deletions promissory-note/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Promissory Note

This is a smart legal clause that conforms to the [Accord Project Template Specification](https://docs.google.com/document/d/1UacA_r2KGcBA2D4voDgGE8jqid-Uh4Dt09AE-shBKR0), the protocol is managed by the open-source community of the [Accord Project](https://accordproject.org). The clause can be parsed and executed by the [Cicero](https://github.com/accordproject/cicero) engine.

## Description

> This clause specifies how an interest bearing loan should be repaid.
This clause contains:
- *Sample Clause Text* - [sample.txt](sample.txt)
- *A template* - [grammar/template.tem](grammar/template.tem)
- *Some data models* - [models/model.cto](models/model.cto), [models/contact.cto](models/contact.cto)
- *Contact logic* (in Ergo) - [logic/logic.ergo](lib/logic.ergo)

## Running this clause

### On your own machine

1. [Download the Cicero template library](https://github.com/accordproject/cicero-template-library/archive/master.zip)

2. Unzip the library with your favourite tool

3. Then from the command-line, change the current directory to the folder containing this README.md file.
```
cd promissory-note
```
4. With the [Cicero command-line tool](https://github.com/accordproject/cicero#installation):
```
cicero execute --template ./ --dsl ./sample.txt --data ./data.json
```
> Note, all of the command-line flags (like `--template`) are optional.
Alternatively you can use the simpler command below if you want to use all of the default files.
```
cicero execute
```

### Sample Payload Data


Request, as in [data.json](https://github.com/accordproject/cicero-template-library/blob/master/promissory-note/data.json)
```json
{
"$class": "org.accordproject.promissorynote.Request",
"amountPaid": 100.50
}
```

For the request above, you should see the following response:
```json
{
"$class": "org.accordproject.promissorynote.Response",
"outstandingBalance": 300.23
}
```


## Testing this clause

This clause comes with an automated test that ensures that it executes correctly under different conditions. To test the clause, complete the following steps.

You need npm and node to test a clause. You can download both from [here](https://nodejs.org/).

> This clause was tested with Node v8.9.3 and NPM v5.6.0
From the `promissory-note` directory.

1. Install all of the dependencies.
```
npm install
```

2. Run the tests
```
npm test
```
If successful, you should see the following output
```
dselman$ npm test
> promissory-note@0.0.1 test /Users/dselman/dev/cicero-template-library/promissory-note
> mocha
13:51:10 - info: Logging initialized. 2018-05-09T12:51:10.359Z
Logic
#PromissoryNote
✓ should execute a smart clause
1 passing (437ms)
```
> Output above is abbreviated for clarity at `...`
4 changes: 4 additions & 0 deletions promissory-note/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$class": "org.accordproject.promissorynote.Request",
"amountPaid": 100
}
29 changes: 29 additions & 0 deletions promissory-note/grammar/template.tem
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
PROMISSORY NOTE
[{dollarAmount}] USD [{date}]

FOR VALUE RECEIVED, the undersigned, [{maker}], an [{"individual residing":? individual}] at [{makerAddress}] (“Maker”), hereby promises to pay to the order of [{lender}], a [{legalEntity}], having offices at [{lenderAddress}], or its successors and permitted assigns (“Lender” or the “Company”), the principal sum of [{principal}] USD, plus any and all interest accrued thereon at the Note Rate (defined below), each due and payable in cash in lawful money of the United States on the dates and in the manner set forth in this Promissory Note (this “Note”).
1. Interest. The principal amount of this Note shall bear interest at [{interestRate}]% per annum (the “Note Rate”). Interest shall be computed on the basis of a three hundred and sixty-five (365) day year and charged for the actual number of days elapsed. Interest shall accrue on the original principal balance only and there shall be no accrual of interest upon interest.
2. Payment of Principal and Interest. The principal amount of this Note and the interest thereon shall be due and payable in full on the earlier of (a) [{maturityDate}] or (b) ten (10) days prior to the Company filing an S-1 registration statement with the U.S. Securities and Exchange Commission in contemplation of an initial public offering (“IPO”). As used herein, IPO means the closing of a firm commitment underwritten public offering pursuant to a registration statement under the Securities Act of 1933, as amended.
4. Prepayment. The Maker may prepay any portion of the principal balance of this Note at any time without penalty.

6. Default. Each of the following shall constitute an event of default (“Event of Default”) under this Note:
(a) the Maker shall fail to pay when due (whether by acceleration or otherwise) principal or interest on this Note, and such default shall have continued for a period of [{defaultDays}] days;
(b) a proceeding (other than a proceeding commenced by the Maker) shall have been instituted in a court having jurisdiction seeking a decree or order for relief in respect of the Maker in an involuntary case under any applicable bankruptcy, insolvency or other similar law now or hereafter in effect, and such proceedings shall remain undismissed or unstayed and in effect for a period of [{insolvencyDays}] days (so long as the Maker is diligently proceeding to effect such dismissal or stay) or such court shall enter a decree or order granting the relief sought in such proceeding; or
(c) the Maker commences a voluntary case under any applicable bankruptcy, insolvency or other similar law now or hereafter in effect, consents to the entry of an order for relief in an involuntary case under any such law, or makes a general assignment for the benefit of creditors, or fails generally to pay his debts as they become due, or takes any action in furtherance of any of the foregoing.
7. Remedies. Upon the occurrence of any Event of Default, the Lender may, without notice or demand to the Maker, exercise any or all of the following remedies:
(a) declare all unpaid principal owing under this Note, together with all accrued and unpaid interest and other amounts owing hereunder, to be immediately due and payable without demand, protest, notice of protest, notice of default, presentment for payment or further notice of any kind; or
(b) proceed to enforce such other and additional rights and remedies as the Lender may be provided by applicable law.

9. Governing Law. This Note shall be governed by, and construed and enforced in accordance with, the internal laws (other than the choice of law principles thereof) of [{jurisdiction}].
10. Waiver. No failure to exercise and no delay in exercising any right, power or privilege hereunder shall operate as a waiver thereof, nor shall any single or partial exercise of any right, power or privilege hereunder preclude any other or further exercise thereof or the exercise of any other right, power or privilege. The rights and remedies herein provided are cumulative and not exclusive of any rights or remedies provided by law.
11. Savings Clause. Notwithstanding any provision contained in this Note, the Lender shall not be entitled to receive, collect or apply as interest on this Note any amount in excess of the highest lawful rate permissible under any law which a court of competent jurisdiction may deem applicable hereto. If the Lender ever receives, collects or applies as interest any such excess, the amount that would be excessive interest shall be deemed to be a partial payment of principal and treated hereunder as such, and, if the principal balance of this Note is paid in full, any remaining excess shall promptly be paid to the Maker.
12. Amendment. This Note may be amended or modified only upon the written consent of both the Lender and the Maker. Any amendment must specifically state the provision or provisions to be amended and the manner in which such provision or provisions are to be amended.
13. Entire Agreement. This Note constitutes the entire agreement of the Maker and the Lender with respect to the subject matter hereof and supersedes all other prior arrangements, understandings, statements, representations and warranties, expressed or implied, and no oral statements or prior written statements not contained in this Note shall have any force and effect.
14. Counterparts. This Note may be executed in counterparts, each of which shall constitute an original and all of which shall constitute one and the same instrument.
15. Assignment. This Note may not be assigned and/or transferred in whole or in part by the Maker without the prior written consent of the Lender, which consent shall be in the Lender’s sole and absolute discretion. This Note may be assigned and/or transferred in whole or in part by the Lender at any time. The obligations of the Maker hereunder shall bind his heirs and permitted assigns, and all rights, benefits and privileges conferred on the Lender by this Note shall be and hereby are extended to, conferred upon, and may be enforced by, the successors and assigns of the Lender.

IN WITNESS WHEREOF, the Maker has executed this Note as of the date and year first above written.




40 changes: 40 additions & 0 deletions promissory-note/lib/logic.ergo
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.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: compounded
}
}
}
40 changes: 40 additions & 0 deletions promissory-note/models/model.cto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace org.accordproject.promissorynote

transaction Request {
o Double amountPaid
}

transaction Response {
o Double outstandingBalance
}

enum LegalEntity {
o PLC
o LLC
o INC
o Corporation
}

/**
* The template model
*/
@AccordTemplateModel("promissory-note")
concept TemplateModel {
/**
* The name for the clause
*/
o Double dollarAmount
o DateTime date
o String maker
o Double interestRate
o Boolean individual
o String makerAddress
o String lender
o LegalEntity legalEntity
o String lenderAddress
o Double principal
o DateTime maturityDate
o Integer defaultDays
o Integer insolvencyDays
o String jurisdiction
}
Loading

0 comments on commit e0f8aba

Please sign in to comment.