Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async getCdp()
{
const maker = await Maker.create("http", {
privateKey: 'dbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdb',
url: 'https://mainnet.infura.io/nWQTOIHYhOavIVKVvNah'
});
// await maker.authenticate();
// const cdp = await maker.getCdp(420);
// console.log(cdp);
// await Maker.authenticate();
// const objCdp = await Maker.getCdp(4335);
// const debtLevel = objCdp.getDebtValue(Maker.USD);
// this.setState({
// CDP: {
// Debt: {
// usd: debtLevel
module.exports = async (iterations, priceFloor, principal) => {
try {
// connect to blockchain using infura
const maker = await Maker.create('http', {
privateKey: process.env.PRIVATE_KEY,
plugins: [Eth2DaiInstant],
log: true,
url: 'https://kovan.infura.io/v3/11465e3f27b247eb8b785c23047b29fd'
});
await maker.authenticate();
invariant(
iterations !== undefined &&
priceFloor !== undefined &&
principal !== undefined,
'Not all parameters (iterations, priceFloor, principal) were received'
);
log.title('Creating a leveraged cdp with the following parameters:');
log.title(`Iterations: ${iterations}`);
module.exports = async function(cdpId, options) {
let targetRatio;
try {
targetRatio = Maker.USD_DAI(options.targetRatio);
} catch (err) {
throw new Error(`Invalid value for targetRatio: ${err}`);
}
const maker = Maker.create(process.env.NETWORK, {
privateKey: process.env.PRIVATE_KEY,
log: false,
provider: {
infuraProjectId
}
});
const cdp = await maker.getCdp(cdpId);
const collateral = await cdp.getCollateralValue();
console.log(`collateral: ${collateral}`);
const debt = await cdp.getDebtValue(Maker.USD);
console.log(`debt: ${debt}`);
const collateralPrice = await maker.service('price').getEthPrice();
console.log(`price: ${collateralPrice}`);
export const startAsync = () => async dispatch => {
dispatch(started());
const maker = await Maker.create(process.env.REACT_APP_NETWORK, {
privateKey: process.env.REACT_APP_PRIVATE_KEY,
overrideMetamask: true,
provider: {
infuraProjectId
}
});
await maker.authenticate();
console.log('maker:', maker);
dispatch(makerCreated());
const cdp = await maker.openCdp();
console.log('cdp:', cdp);
dispatch(cdpOpened());
const lockEthTx = await cdp.lockEth(0.01);
console.log('transaction to lock eth:', lockEthTx);
dispatch(ethLocked());
await dispatch(drawDaiAsync(maker, cdp));
async function start(wyreWallet, amountToTransfer, accountPrivateKey) {
try {
const maker = Maker.create('kovan', {
privateKey: accountPrivateKey,
web3: {
confirmedBlockCount: 15
},
provider: {
infuraProjectId
}
});
await maker.authenticate();
console.log('Authenticated');
//Get account and balance
const balance = await maker.getToken('ETH').balanceOf(maker.currentAddress());
console.log('Account: ', maker.currentAddress());
console.log('balance', balance.toString());
const connect = async () => {
maker = await Maker.create('browser', {
plugins: [
[
McdPlugin,
{
network: 'kovan',
cdpTypes: [
{ currency: ETH, ilk: 'ETH-A' },
{ currency: BAT, ilk: 'BAT-A' },
]
}
]
]
});
await maker.authenticate();
await maker.service('proxy').ensureProxy();
async setup() {
this.activeCdps = {};
this.currentCdp = {};
const web3 = this.web3;
const _self = this;
this.gotoHome();
const MewMakerPlugin = MewPlugin(
web3,
_self.account.address,
async () => {
if (_self.$route.path.includes('maker-sai')) {
await _self.doUpdate();
}
}
);
this.maker = await Maker.create('inject', {
provider: { inject: web3.currentProvider },
plugins: [MewMakerPlugin],
accounts: {
myLedger1: { type: 'mew' }
}
});
await this.maker.authenticate();
this._priceService = this.maker.service('price');
this._cdpService = await this.maker.service('cdp');
this._proxyService = await this.maker.service('proxy');
this._tokenService = await this.maker.service('token');
this.pethMin = toBigNumber(0.005);
this.ethPrice = toBigNumber(
this.gotoLoading();
}
try {
this.curentlyLoading = this.$t('dappsMaker.loading-wallet');
const MewMakerPlugin = MewPlugin(
web3,
_self.account.address,
async () => {
if (_self.$route.path.includes('maker-dai')) {
await _self.doUpdate();
}
}
);
this.maker = await Maker.create('inject', {
provider: { inject: web3.currentProvider },
plugins: [
[
McdPlugin,
{
network: this.network.type.name === 'KOV' ? 'kovan' : 'mainnet',
prefetch: true
}
],
MewMakerPlugin,
MigrationPlugin
],
log: false,
web3: {
pollingInterval: null
},
async _initialize() {
this._maker = Maker.create('browser')
await this._maker.authenticate()
this.dai = this._maker.service('token').getToken(DAI)
this.accounts = await this.dai._web3.eth.getAccounts()
this.getNetwork()
}
export default async function(useMetaMask) {
window.Maker = Maker;
const maker = Maker.create(useMetaMask ? 'browser' : 'http', {
url: TESTNET_URL,
plugins: [trezorPlugin, ledgerPlugin],
accounts: {
test1: { type: 'privateKey', key: keys[0] }
}
});
await maker.authenticate();
if (maker.service('web3').networkId() !== 999) {
alert(
'To work with testchain accounts, configure MetaMask to use ' +
`"Custom RPC" with address "${TESTNET_URL}".`
);
}
window.maker = maker;
return maker;