Skip to content

Instantly share code, notes, and snippets.

@abdelghafour
Last active April 10, 2024 17:35
Show Gist options
  • Save abdelghafour/85bd768fba5e81d09cc61ca5c5911553 to your computer and use it in GitHub Desktop.
Save abdelghafour/85bd768fba5e81d09cc61ca5c5911553 to your computer and use it in GitHub Desktop.

Create the Collateral:

import axios from "axios";


const headers = { };
const data = {
  collateralizer: {
    cardinal: {
      amount: LOCK_AMOUNT,
      value: COLLATERALIZER_BTC_ADDRESS,
      publicKey: COLLATERALIZER_BTC_PUBLIC_KEY,
    },
  },
  expiry: moment().add(1, "d").format(),
};

const { data: escrow } = await axios.post(
  `${DEEP_LAKE_REST_API_URL}/flows/execute`,
  { data },
  { headers }
);

Sign and broadcast the Collateral:

import axios from "axios";


const headers = { };
const data = {
  state: "broadcast-collateralize",
  flow: {
    flowEscrows: {
      tag: "collateralize",
      escrow: { transactions: [{base64: 'SIGNED_BASE_64'}] }
    }
  },
};


const { data: escrow } = await axios.post(
  `${DEEP_LAKE_REST_API_URL}/flows/execute`,
  { data },
  { headers }
);

Unlock the Collateral:

import axios from "axios";


const headers = { };
const data = {
  state: "uncollateralize",
  amount: LOCK_AMOUNT,
  index: INDEX_OF_THE_PATH_YOU_WOULD_LIKE_TO_UNLOCK,
};

const { data: escrow } = await axios.post(
  `${DEEP_LAKE_REST_API_URL}/flows/execute`,
  { data },
  { headers }
);

Sign and broadcast the Unlock of the collateral:

import axios from "axios";


const headers = { };
const data = {
  state: "broadcast-uncollateralize",
  flow: {
    flowEscrows: {
      tag: "collateralize",
      escrow: { transactions: [{base64: 'SIGNED_BASE_64'}] }
    }
  },
};

const { data: escrow } = await axios.post(
  `${DEEP_LAKE_REST_API_URL}/flows/execute`,
  { data },
  { headers }
);

The flow API uses these APIs under the hood:

Escrow:

  • Create Escrow
  • Execute Escrow
  • Broadcast Escrow
  • Collateral API
  • Asset API
  • Action API

Outcomes:

  • Create Outcomes and integration with the oracle
  • Check one Outcome

Signatures:

  • Execute signature

Logs:

  • Audit trails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment