Skip to content

Instantly share code, notes, and snippets.

@katelynsills
katelynsills / reputationOTCDesk.js
Created February 12, 2021 03:55
Reputation-based OTC Desk contract
// @ts-check
import { E } from '@agoric/eventual-send';
import { assert, details } from '@agoric/assert';
import { trade } from '../contractSupport';
import '../../exported';
/**
* This OTC Desk contract does not assume that the underlying assets
@katelynsills
katelynsills / freebieSwap.js
Last active May 18, 2020 08:45
Give a freebie to both participants while swapping
/* eslint-disable no-use-before-define */
import harden from '@agoric/harden';
import produceIssuer from '@agoric/ertp';
//import { makeZoeHelpers } from './contractSupport';
import { makeZoeHelpers, defaultAcceptanceMsg } from '@agoric/zoe/src/contractSupport';
// zcf is the Zoe Contract Facet, i.e. the contract-facing API of Zoe
export const makeContract = harden(zcf => {
const helpers = makeZoeHelpers(zcf);
const { assertKeywords, checkHook, swap } = helpers;
@katelynsills
katelynsills / mintPaymentsContract.js
Last active April 22, 2020 04:14
How to mint payments and give them to users
const offerHook = userOfferHandle => {
const ticketsAmount = baytownBucks(1000);
const ticketsPayment = baytownBucksMint.mintPayment(ticketsAmount);
let tempContractHandle;
const contractSelfInvite = zcf.makeInvitation(
offerHandle => (tempContractHandle = offerHandle),
);
zcf
.getZoeService()
.offer(
@katelynsills
katelynsills / launch.json
Created April 22, 2020 01:46
Sample Launch.json for VSCODE
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Run Test",
@katelynsills
katelynsills / offerSafety.js
Created November 5, 2019 23:46
Simplified version of offer safety
const refundOk = payoutRules.every((payoutRule, i) => {
if (payoutRule.kind === 'offer') {
return extentOpsArray[i].includes(
extents[i],
payoutRule.units.extent
);
}
return true;
});
@katelynsills
katelynsills / withoutList.js
Created November 5, 2019 22:37
without method for Lists
function without(whole, part) {
insist(listExtentOps.includes(whole, part))`part is not in whole`;
const wholeMinusPart = [];
for (const wholeElement of whole) {
if (!includesElement(part, wholeElement)) {
wholeMinusPart.push(wholeElement);
}
}
return harden(wholeMinusPart);
}
@katelynsills
katelynsills / natExtentOps.js
Last active November 5, 2019 22:33
natExtentOps
const makeNatExtentOps = () => {
insistKind: Nat,
empty: _ => 0,
isEmpty: nat => nat === 0,
includes: (whole, part) => whole >= part,
equals: (left, right) => left === right,
with: (left, right) => Nat(left + right),
without: (whole, part) => Nat(whole - part),
};
@katelynsills
katelynsills / exclusivePayment.js
Created November 5, 2019 22:09
Mint and get exclusive payment
// Alice withdraws a payment for Bob from her purse.
import { makeMint } from '@agoric/ertp/core/mint';
const bucksMint = makeMint('bucks');
const purse = bucksMint.mint(1000, `alice's purse`);
const paymentForBob = purse.withdraw(10, `bob's money`);
// The particular methods of the bobsAgent object are up to Bob.
bobsAgent.receivePayment(paymentForBob);
// Bob receives an alleged payment from Alice.
// Bob claims it exclusively and validates it
@katelynsills
katelynsills / offerRules.js
Created November 5, 2019 20:04
offerRules
const offerRules = harden({
payoutRules: [
{
kind: 'want',
units: tickets(1),
},
{
kind: 'offer',
units: dollars(10),
},
@katelynsills
katelynsills / automaticRefund.js
Created November 2, 2019 02:09
Automatic Refund
export const makeContract = (zoe, terms) => {
return {
instance: {
makeOffer: async escrowReceipt => {
const { offerHandle } = await zoe.burnEscrowReceipt(escrowReceipt);
zoe.complete([offerHandle]);
},
},
assays: terms.assays,
};