Skip to content

Instantly share code, notes, and snippets.

@graemecode
Last active August 31, 2018 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graemecode/347225065ecd2ae8fa2f35c436e086f0 to your computer and use it in GitHub Desktop.
Save graemecode/347225065ecd2ae8fa2f35c436e086f0 to your computer and use it in GitHub Desktop.
Part 2/4 in a series on collateralizing ERC721s for loans on Dharma Protocol
/*********************
* Setup Dharma.js *
*********************/
// Import Dharma from Dharma.js
import Dharma from "@dharmaprotocol/dharma.js";
// Import BigNumber.js version 5.0.0, which we will use when posting numbers to the blockchain.
import * as BigNumber from "bignumber.js";
// Instantiate Dharma
const dharma = new Dharma();
/***********************
* Create Debt Order *
***********************/
const DEBTOR_ADDRESS = "0x601e6e7711b9e3b1b20e1e8016038a32dfc86ddd";
/*
* We will refer to our token using its index in the ERC721 contract. It's also possible to
* use the token's ID, in case the contract does not implement the standard
* Enumerable Extension (see https://eips.ethereum.org/EIPS/eip-721)
*/
const tokenReference = new BigNumber(0);
// We specify that the token implements the Enumerable Extension.
const isEnumerable = true;
// The symbol for our "Mintable ERC721 Token" that is registered in Dharma's ERC721 Token Registry.
const erc721Symbol = "MET";
// We define the data to create our debt order.
const debtOrderData = {
principalAmount: new BigNumber(1),
principalTokenSymbol: "REP",
interestRate: new BigNumber(1),
amortizationUnit: "days",
termLength: new BigNumber(5),
debtor: DEBTOR_ADDRESS,
isEnumerable,
erc721Symbol,
tokenReference,
};
// We define the adapter that we will use to create the debt order.
const adapter = dharma.adapters.erc721CollateralizedSimpleInterestLoan;
// We create an order using the information we just defined.
adapter.toDebtOrder(debtOrderData).then(async (order) => {
// Sign the debt order.
console.log("Please approve the request to sign the debt order.");
order.debtorSignature = await dharma.sign.asDebtor(order, false);
// Let's inspect the signed debt order:
console.log("The order has been signed, as follows:");
console.log(order);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment