Skip to content

Instantly share code, notes, and snippets.

@katelynsills
katelynsills / freebieSwap.js
Last active May 18, 2020
Give a freebie to both participants while swapping
View freebieSwap.js
/* 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 Apr 22, 2020
How to mint payments and give them to users
View mintPaymentsContract.js
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 Apr 22, 2020
Sample Launch.json for VSCODE
View launch.json
{
// 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 Nov 5, 2019
Simplified version of offer safety
View offerSafety.js
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 Nov 5, 2019
without method for Lists
View withoutList.js
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);
}
View natExtentOps.js
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 Nov 5, 2019
Mint and get exclusive payment
View exclusivePayment.js
// 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
View offerRules.js
const offerRules = harden({
payoutRules: [
{
kind: 'want',
units: tickets(1),
},
{
kind: 'offer',
units: dollars(10),
},
View automaticRefund.js
export const makeContract = (zoe, terms) => {
return {
instance: {
makeOffer: async escrowReceipt => {
const { offerHandle } = await zoe.burnEscrowReceipt(escrowReceipt);
zoe.complete([offerHandle]);
},
},
assays: terms.assays,
};
View baytownbucks.js
import { makeMint } from '@agoric/ertp/core/mint';
const baytownBucksMint = makeMint('BaytownBucks');
const purse = baytownBucksMint.mint(1000, 'community treasury');
const paymentForAlice = purse.withdraw(10, `alice's community money`);
alice.receivePayment(paymentForAlice);
You can’t perform that action at this time.