superfluid-finance / protocol-monorepo

Superfluid Protocol Monorepo: the specification, implementations, peripherals and development kits.
https://www.superfluid.finance
Other
875 stars 239 forks source link

[SPEC] Define Contracts Compositionality #737

Open hellwolf opened 2 years ago

hellwolf commented 2 years ago

Overview of Superfluid Money Distribution

Denotational Payment Semantics and Organization of Agreements

The denotational semantics^1 of payment in the Superfluid Money Distribution is organized into a collection of primitives called "agreement". These classes of agreements is further organized into "indexes", where their availability to the bearers are quantified. E.g. universal index means they are always available to all bearers; proportional index means they model the relationship proportional ownership between subscribers, and a subscription is a explicit relationship between the publisher and the subscriber; etc.

Composing Payment Semantics into Contracts

Correctly designed denotational semantics are by definition compositional^1. Hence the ability of "bundling" of related contracts comes for free with the denotational semantics design.

However, the execution layer of the payment semantics also need to deal with the side effects such as "execution at certain time", which in turn is just a special case of "conditional execution". Sophisticated financial contracts can be built by creating such level of compositionality as domonstrated by Simon Peyton Jones et al. at Microsoft research back in year 2000 ^2.

By creating such contracts composition layer where the agreement payment semantics are primitives, powerful financial engines modeled in either Token or Note can be operating on the Superfluid Money Distribution. This vision is also called real time finance.

Example Contracts

Buffer Based Solvency

  1. Execute now: create a stream from bob to alice at $42 / mo.
  2. Execute now: withhold $5 from bob as deposit.
  3. Execute conditionally: upon stream updating, the $5 deposit is returned to bob.
  4. Execute conditionally: upon bob's available balances falls under $0, anyone may cancel this stream.

European Option Contract (An excerpt from SPJ paper)

(only as an inspiration):

european :: Date -> Contra t -> Contra t

c = european (date \1200GMT 24 Apr 2003") (
z b (mkDate \1200GMT 12 May 2003") 0:4 GBP `and `
z b (mkDate \1200GMT 12 May 2004") 9:3 GBP `and `
z b (mkDate \1200GMT 12 May 2005") 109:3 GBP `and `
give (z b (mkDate \1200GMT 26 Apr 2003") 100 GBP )
)

Questions

References

hellwolf commented 2 years ago

Overview of Superfluid Money Distribution

Denotational Payment Semantics and Organization of Agreements

The denotational semantics^1 of payment in the Superfluid Money Distribution is organized into a collection of primitives called "agreement". These classes of agreements is further organized into "indexes", where their availability to the bearers are quantified. E.g. universal index means they are always available to all bearers; proportional index means they model the relationship proportional ownership between subscribers, and a subscription is a explicit relationship between the publisher and the subscriber; etc.

Composing Payment Semantics into Contracts

Correctly designed denotational semantics are by definition compositional^1. Hence the ability of "bundling" of related contracts comes for free with the denotational semantics design.

However, the execution layer of the payment semantics also need to deal with the side effects such as "execution at certain time", which in turn is just a special case of "conditional execution". Sophisticated financial contracts can be built by creating such level of compositionality as domonstrated by Simon Peyton Jones et al. at Microsoft research back in year 2000 ^2.

By creating such contracts composition layer where the agreement payment semantics are primitives, powerful financial engines modeled in either Token or Note can be operating on the Superfluid Money Distribution. This vision is also called real time finance.

Example Contracts

Buffer Based Solvency

  1. Execute now: create a stream from bob to alice at $42 / mo.
  2. Execute now: withhold $5 from bob as deposit.
  3. Execute conditionally: upon stream updating, the $5 deposit is returned to bob.
  4. Execute conditionally: upon bob's available balances falls under $0, anyone may cancel this stream.

European Option Contract (An excerpt from SPJ paper)

(only as an inspiration):

european :: Date -> Contra t -> Contra t

c = european (date \1200GMT 24 Apr 2003") (
z b (mkDate \1200GMT 12 May 2003") 0:4 GBP `and `
z b (mkDate \1200GMT 12 May 2004") 9:3 GBP `and `
z b (mkDate \1200GMT 12 May 2005") 109:3 GBP `and `
give (z b (mkDate \1200GMT 26 Apr 2003") 100 GBP )
)

References