Description

This module offers capabalities for running an Atomic Swap Contract. Atomic swaps, offer a way to swap cryptocurrencies peer-to-peer directly without the requirement for a third party, such as an exchange.

This Marlowe Contract has 2 participants (A `Seller` and a `Buyer`) that will atomically exchange some tokens A for some tokens B. Sellers can retract their offer and every state of this contract are timeboxed. Sellers are known at the contract creation (fixed Address) and Buyers are unknown (This showcases a feature of marlowe that is called Open Roles.). There are 3 main stages : - The Offer : The Sellers create the contract and deposit their tokens at the same time via the initial account deposits feature. - The Ask : The Buyers deposit their tokens - The Swap Confirmation : an extra Notify input is added after the swap to avoid double-satisfaction attack (see link attached). (Any third participant could perform this action)

See

Example

import { AtomicSwap } from "@marlowe.io/language-examples";
import { datetoTimeout, tokenValue } from "@marlowe.io/language-core-v1";
import { addDays } from "date-fns";

const aSellerAddressBech32 = "addr_test1qqe342swyfn75mp2anj45f8ythjyxg6m7pu0pznptl6f2d84kwuzrh8c83gzhrq5zcw7ytmqc863z5rhhwst3w4x87eq0td9ja"

const tokenA = token("1f7a58a1aa1e6b047a42109ade331ce26c9c2cce027d043ff264fb1f","A")
const tokenB = token("1f7a58a1aa1e6b047a42109ade331ce26c9c2cce027d043ff264fb1f","B")

const scheme: AtomicSwap.Scheme = {
offer: {
seller: { address: aSellerAddressBech32 },
deadline: datetoTimeout(addDays(Date.now(), 1)),
asset: tokenValue(10n)(tokenA),
},
ask: {
buyer: { role_token: "buyer" },
deadline: datetoTimeout(addDays(Date.now(), 1)),
asset: tokenValue(10n)(tokenB),
},
swapConfirmation: {
deadline: datetoTimeout(addDays(Date.now(), 1)),
},
};

const myAtomicSwap = AtomicSwap.mkContract(scheme)

// .. Then you can use the runtime to pilot this contract over Cardano using `getState` ...

Index

Classes

Type Aliases

Variables

Functions