Skip to content

Instantly share code, notes, and snippets.

@abdelghafour
Last active January 20, 2024 14:45
Show Gist options
  • Save abdelghafour/2e86d2070cfb1dd5ea27e986ccd3fb7f to your computer and use it in GitHub Desktop.
Save abdelghafour/2e86d2070cfb1dd5ea27e986ccd3fb7f to your computer and use it in GitHub Desktop.
Wagers using Deep Lake API

Create the collateral:

const qs = require("qs");
const axios = require("axios");
const headers = { Authorization: MY_COMPANY_API_KEY };
const data = {
  fee: 100,
  locks: [
    {
      amount: 100,
      expiry: moment().add(1, "d").format(),
      locker: {
        cardinal: {
          value: item.address,
          publicKey: item.pubkey?.toString("hex"),
        },
      },
      destination: {
        cardinal: {
          value: item.address,
          publicKey: item.pubkey?.toString("hex"),
        },
      },
    },
    {
      amount: 100,
      expiry: moment().add(1, "d").format(),
      locker: {
        cardinal: {
          value: item.address,
          publicKey: item.pubkey?.toString("hex"),
        },
      },
      destination: {
        cardinal: {
          value: item.address,
          publicKey: item.pubkey?.toString("hex"),
        },
      },
    },
  ],
  product: {
    id: 11,
  },
};

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

Sign and broadcast the collateral:

const qs = require("qs");
const axios = require("axios");
const headers = { Authorization: MY_COMPANY_API_KEY };
const data = {
  state: "broadcast-lock",
  transactions,
  product: {
    id: 11,
  },
};
const where = qs.stringify({ where: { id: flow.id } });
const { data: escrow } = await axios.post(
  `${DEEP_LAKE_REST_API_URL}/flows/execute?${where}`,
  { data },
  { headers }
);

Unlock the collateral:

const qs = require("qs");
const axios = require("axios");
const headers = { Authorization: MY_COMPANY_API_KEY };
const data = {
  state: "unlock",
  fee: 200,
  index: 0,
  product: {
    id: 11,
  },
};
const where = qs.stringify({ where: { id: flow.id } });
const { data: escrow } = await axios.post(
  `${DEEP_LAKE_REST_API_URL}/flows/execute?${where}`,
  { data },
  { headers }
);

Sign and broadcast the unlock:

const qs = require("qs");
const headers = { Authorization: MY_COMPANY_API_KEY };
const data = {
  state: "broadcast-unlock",
  transactions,
  product: {
    id: 11,
  },
};
const where = qs.stringify({ where: { id: flow.id } });
const { data: escrow } = await axios.post(
  `${DEEP_LAKE_REST_API_URL}/flows/execute?${where}`,
  { 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