Skip to content

Commit

Permalink
[language/examples] Vesting Contract
Browse files Browse the repository at this point in the history
  • Loading branch information
nhenin committed Oct 4, 2023
1 parent 8f48d98 commit df2cf0a
Show file tree
Hide file tree
Showing 15 changed files with 727 additions and 314 deletions.
4 changes: 1 addition & 3 deletions packages/adapter/src/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ export const ISO8601 = t.string;
export type POSIXTime = t.TypeOf<typeof POSIXTime>;
export const POSIXTime = t.number;

export const datetoIso8601 = (date: Date): ISO8601 =>
pipe(date, (date) => format(date, "yyyy-MM-dd'T'HH:mm:ss'Z'"));
export const datetoIso8601Bis = (date: Date): ISO8601 => pipe(date, formatISO);
export const datetoIso8601 = (date: Date): ISO8601 => date.toISOString();

// a minute in milliseconds
export const MINUTES = 1000 * 60;
3 changes: 3 additions & 0 deletions packages/language/core/v1/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ export const datetoTimeout = (date: Date): Timeout =>
(a) => a.valueOf()
);

export const timeoutToDate = (timeout: Timeout): Date =>
new Date(Number(timeout));

export type Contract = Close | Pay | If | When | Let | Assert;

export const Contract: t.Type<Contract> = t.recursion("Contract", () =>
Expand Down
2 changes: 2 additions & 0 deletions packages/language/core/v1/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export {
Contract,
Case,
Assert,
Close,
close,
Expand All @@ -10,6 +11,7 @@ export {
Pay,
When,
datetoTimeout,
timeoutToDate,
Timeout,
} from "./contract.js";
export { role, Party } from "./participants.js";
Expand Down
22 changes: 21 additions & 1 deletion packages/language/core/v1/src/next/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import * as t from "io-ts/lib/index.js";
import { ApplicableInputs } from "./applicables/index.js";
export { toInput } from "./applicables/canDeposit.js";
import { isNone, none } from "fp-ts/lib/Option.js";
export * as Deposit from "./applicables/canDeposit.js";
export * as Choice from "./applicables/canChoose.js";
export * as Notify from "./applicables/canNotify.js";

export type Next = t.TypeOf<typeof Next>;
export const Next = t.type({
can_reduce: t.boolean,
applicable_inputs: ApplicableInputs,
});

export const emptyApplicables = (next: Next) => {
return (
next.applicable_inputs.choices.length === 0 &&
next.applicable_inputs.deposits.length === 0 &&
isNone(next.applicable_inputs.notify)
);
};

export const noNext: Next = {
can_reduce: false,
applicable_inputs: {
deposits: [],
choices: [],
notify: none,
},
};
4 changes: 3 additions & 1 deletion packages/language/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
}
},
"dependencies": {
"@marlowe.io/language-core-v1": "0.2.0-alpha-3"
"@marlowe.io/language-core-v1": "0.2.0-alpha-3",
"date-fns": "2.29.3",
"fp-ts": "^2.16.1"
}
}
1 change: 1 addition & 0 deletions packages/language/examples/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * as SwapADAToken from "./swaps/swap-token-token.js";
export { oneNotifyTrue } from "./contract-one-notify.js";
export * as Vesting from "./vesting.js";
Loading

0 comments on commit df2cf0a

Please sign in to comment.