Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dantrevino/0c2e3b97310ce525edc538e5dbea8ba5 to your computer and use it in GitHub Desktop.
Save dantrevino/0c2e3b97310ce525edc538e5dbea8ba5 to your computer and use it in GitHub Desktop.
BTC Collateralization Through Flow API

Create the collateral:

const headers = { Authorization: MY_COMPANY_API_KEY };
const data = {
  where: {},
  data: {
    fee: 100,
    borrower: {
      cardinal: {
        amount: 100,
        value: item.address,
        publicKey: item.pubkey.toString("hex"),
      },
    },
    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:

const headers = { Authorization: MY_COMPANY_API_KEY };
const data = {
  where: { id: flow.id },
  data: {
    state: "broadcast-lock",
    transactions,
  },
};

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

Unlock the collateral:

const headers = { Authorization: MY_COMPANY_API_KEY };
const data = {
  where: { id: flow.id },
  data: {
    state: "unlock",
    fee: 200,
    index: 0,
  },
};

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

Sign and broadcast the unlock:

const headers = { Authorization: MY_COMPANY_API_KEY };
const data = {
  where: { id: flow.id },
  data: {
    state: "broadcast-unlock",
    transactions,
  },
};

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