Last active
August 31, 2018 08:25
-
-
Save graemecode/fd2c4ed72d026dc625aa1b3e73de70e7 to your computer and use it in GitHub Desktop.
Part 3/4 in a series on collateralizing ERC721s for loans on Dharma Protocol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************* | |
* Setup Dharma.js * | |
*********************/ | |
// Import Dharma from Dharma.js | |
import Dharma from "@dharmaprotocol/dharma.js"; | |
// Import BigNumber.js version 5.0.0, for wrapping numbers before sending to blockchain. | |
import * as BigNumber from "bignumber.js"; | |
// Instantiate Dharma | |
const dharma = new Dharma(); | |
/********************** | |
* Fill a Debt Order * | |
**********************/ | |
const CREDITOR_ADDRESS = "0x601e6e7711b9e3b1b20e1e8016038a32dfc86ddd"; | |
const MAX_GAS = 4712388; | |
const TX_DEFAULTS = { | |
from: CREDITOR_ADDRESS, | |
gas: MAX_GAS, | |
}; | |
/** | |
* This is an example of a debt order that can be transmitted or stored, and used | |
* to establish a debt agreement on Dharma Protocol. | |
*/ | |
let debtOrder = { | |
"principalAmount": new BigNumber(1), | |
"debtor": "0x601e6e7711b9e3b1b20e1e8016038a32dfc86ddd", | |
"principalToken": "0x2ecf4e28b0387113012ab2e6d5f60d5333ea2180", | |
"termsContract": "0xeef7d84ab274d3d288e26538893fb3768bff7d12", | |
"termsContractParameters": "0x0100000000000000000000000100271010005000000000001000000000000001", | |
"kernelVersion": "0x755e131019e5ab3e213dc269a4020e3e82e06e20", | |
"issuanceVersion": "0x0688659d5e36896da7e5d44ebe3e10aa9d2c9968", | |
"debtorFee": new BigNumber(0), | |
"creditor": "0x0000000000000000000000000000000000000000", | |
"creditorFee": new BigNumber(0), | |
"relayer": "0x0000000000000000000000000000000000000000", | |
"relayerFee": new BigNumber(0), | |
"underwriter": "0x0000000000000000000000000000000000000000", | |
"underwriterFee": new BigNumber(0), | |
"underwriterRiskRating": new BigNumber(0), | |
"expirationTimestampInSec": new BigNumber(1538292323), | |
"salt": new BigNumber(0), | |
"debtorSignature": { | |
"v": 27, | |
"r": "0x5b2db210d77482c1690e9f3fe15fd3356f05ed288c7b7f2dc9e6cde5588756d2", | |
"s": "0x3b27919d6f41df36078b3df00861eb62547ce3d7b89a91c05ef0a40790cdb6af" | |
}, | |
"creditorSignature": {"r": "", "s": "", "v": new BigNumber(0)}, | |
"underwriterSignature": {"r": "", "s": "", "v": new BigNumber(0)} | |
}; | |
// Fill the debt order as the creditor. | |
console.log(`Specifying address ${CREDITOR_ADDRESS} as creditor`); | |
debtOrder.creditor = CREDITOR_ADDRESS; | |
console.log( | |
"Please make sure you have access to the private key of the above address and sign " + | |
"the transaction to fill the debt order." | |
); | |
dharma.order.fillAsync(debtOrder, TX_DEFAULTS).then(async (txHash) => { | |
console.log("Waiting for transaction to be mined (may take a while)..."); | |
await dharma.blockchain.awaitTransactionMinedAsync(txHash); | |
console.log("The order has been filled."); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment