What is Ergo?
Ergo is a domain-specific language (DSL) that captures the execution logic of legal contracts.
Ergo is intended to be accessible to both Lawyers and Developers, helping ensure that the executable logic and the corresponding legal prose are always consistent.
Ergo is based on the following principles:
- Ergo contracts have a class-like structure with clauses akin to methods
- Ergo can handle types (concepts, transations, etc) defined with the Composer Concerto Modeling Language (so called CML models), as mandated by the Accord Project Template Specification
- Ergo borrows from strongly-typed functional programming languages: clauses have a well-defined type signature (input and output), they are functions without side effects
- The compiler guarantees error-free execution for well-typed Ergo programs
- Clauses and functions are written in an expression language with limited expressiveness (it allows conditional and bounded iteration)
- Most of the compiler is written in Coq as a stepping stone for formal specification and verification
See Ergo in action with some code snippets from real smart legal contracts.
You can write Ergo directly within you contract text. Use ergo to calculate monthly payments for a loan, to calculate the tax for a purchase order, and more.
The following example illustrate an Ergo expression which determines the governing jurisdiction based on a complex condition.
Find more about how to use Ergo in your contracts in the Ergo Expression section of the Accord Project documentation.
Ergo borrows from strongly-typed functional programming languages. Contract clauses and user-defined functions have a well-defined type signature (input and output).
Functions in Ergo are deterministic and without side-effect. Strong typing guarantees that your programs never result in unintended runtime failures.
For instance, the following compoundInterestMultiple function calculates the compound interests based on the annual interest rate. The function has two parameters annualInterest and numberOfDays, both of which are floating-point numbers. And the function returns the calculated compounded rate for the given number of dates.
A contract can require some preconditions to be met before the contract is satisfied, such as consideration, and mutuality of obligation.
Ergo has the ability to create enforce statements which can determine if preconditions have been met, and what actions to take if they are not.
In the following example, the code ensures the values in the contract are not negative.
The structure of an Ergo program parallels the structure of the legal text, with contracts containing one or more clauses.
The following example shows a safte contract containing an equity financing clause template.
Your contract can have a state, for instance to keep track of a loan balance, to remember how many late deliveries occurred, etc. Contract clauses in Ergo can examine, check, and modify the current state of the contract.
For instance, the following example uses the contract state to keep track of the remaining balance on a loan.
Find more information about contract state in the Ergo Language Guide.
Obligations are central to the logic of Contract. Ergo comes with the ability to model, access, and emit obligations for your contract.
The following examples emits a PaymentObligation between two parties of the contract.
Time is an important aspect of legal contracts. Ergo comes bundled with a library for manipulating dates, times and durations which lets you express conditions on dates, calculate a contract obligation should be met, etc.
The following example illustrate how to enforce that a lateDelivery clause does not get called unless the delivery is late, and calculate penalties based on the duration of the delay.
Find more information about date and time support in Ergo in the Time Section of the Standard Library.
The Ergo language facilitates reuse of existing contract or clause logic
Ergo prevents run-time errors and non-terminating logic
Ergo is consistent with the Accord Project Template Specification
The same contract logic can be executed either on and off chain on a variety of distributed ledger technologies
The meaning of contracts should be well defined so it can be verified and preserved during execution