-
Notifications
You must be signed in to change notification settings - Fork 55
Ethers.js Update #303
Ethers.js Update #303
Changes from 8 commits
06a1840
8679eea
f66dc9e
872100b
97fcea6
5b6baef
3200731
5d77617
fc3a8ac
1ed7521
048d2b9
32acd54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
yarn-path ".yarn/releases/yarn-1.19.1.cjs" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,13 +223,13 @@ export default class ChiefService extends LocalService { | |
getNumDeposits(address) { | ||
return this._chiefContract() | ||
.deposits(address) | ||
.then(MKR.wei); | ||
.then(n => MKR.wei(n._hex)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since all our contracts are now created with ethers 5, the returned number value is of BN.js bignumber type (not bignumber.js). Passing a BN bignumber into This is the first of many examples of converting an ethers returned BN type into a hex for |
||
} | ||
|
||
getApprovalCount(address) { | ||
return this._chiefContract() | ||
.approvals(address) | ||
.then(MKR.wei); | ||
.then(n => MKR.wei(n._hex)); | ||
} | ||
|
||
getHat() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { | |
numberToBytes32 | ||
} from '@makerdao/dai/src/utils/conversion'; | ||
import assert from 'assert'; | ||
import { utils } from 'ethers'; | ||
import tracksTransactions from './utils/tracksTransactions'; | ||
const MAINNET_SERVER_URL = 'https://api.makerdao.com/graphql'; | ||
//const LOCAL_URL = 'http://localhost:3001/graphql'; | ||
|
@@ -15,11 +16,9 @@ export const RAY = new BigNumber('1e27'); | |
|
||
export const nullBytes = '0x'; | ||
|
||
export const stringToBytes = str => { | ||
assert(!!str, 'argument is falsy'); | ||
assert(typeof str === 'string', 'argument is not a string'); | ||
return '0x' + Buffer.from(str).toString('hex'); | ||
}; | ||
export function stringToBytes(str) { | ||
return utils.formatBytes32String(str); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ethers is more strict about types, in some places where we used to pass a function signature as |
||
} | ||
|
||
//hard-coded for now, but can get from pips, which you can get from ilk registry | ||
const medianizers = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,9 +68,9 @@ export default async function getEventHistory(cdpManager, managedCdp, cache) { | |
const MCD_JOIN_DAI = cdpManager | ||
.get('smartContract') | ||
.getContractAddress('MCD_JOIN_DAI'); | ||
const MCD_JOIN_SAI = cdpManager | ||
.get('smartContract') | ||
.getContractAddress('MCD_JOIN_SAI'); | ||
// const MCD_JOIN_SAI = cdpManager | ||
// .get('smartContract') | ||
// .getContractAddress('MCD_JOIN_SAI'); | ||
Comment on lines
+71
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to leave this commented out? |
||
const CDP_MANAGER = cdpManager | ||
.get('smartContract') | ||
.getContractAddress('CDP_MANAGER'); | ||
|
@@ -87,7 +87,6 @@ export default async function getEventHistory(cdpManager, managedCdp, cache) { | |
if (cache[id]) return cache[id]; | ||
|
||
const web3 = cdpManager.get('web3'); | ||
const utils = web3._web3.utils; | ||
|
||
// 8600000 is 2019-09-22 on mainnet and 2018-09-04 on kovan | ||
const genesis = [1, 42].includes(web3.network) ? 8600000 : 1; | ||
|
@@ -103,19 +102,26 @@ export default async function getEventHistory(cdpManager, managedCdp, cache) { | |
const urnHandler = (await cdpManager.getUrn(id)).toLowerCase(); | ||
const ilk = managedCdp.ilk; | ||
|
||
const { NewCdp } = cdpManager | ||
const Bite = cdpManager | ||
.get('smartContract') | ||
.getContract('MCD_CAT') | ||
.interface.getEvent('Bite'); | ||
|
||
const [newCdpTopic0] = cdpManager | ||
.get('smartContract') | ||
.getContract('CDP_MANAGER').interface.events; | ||
.getContract('CDP_MANAGER') | ||
.interface.encodeFilterTopics('NewCdp', []); | ||
|
||
const { Bite } = cdpManager | ||
const [biteTopic0] = cdpManager | ||
.get('smartContract') | ||
.getContract('MCD_CAT').interface.events; | ||
.getContract('MCD_CAT') | ||
.interface.encodeFilterTopics('Bite', []); | ||
|
||
const cdpManagerNewCdp = { | ||
request: web3.getPastLogs({ | ||
address: CDP_MANAGER, | ||
topics: [ | ||
utils.keccak256(utils.toHex(NewCdp.signature)), | ||
newCdpTopic0, | ||
null, | ||
null, | ||
'0x' + padStart(id.toString(16), 64, '0') | ||
|
@@ -157,7 +163,13 @@ export default async function getEventHistory(cdpManager, managedCdp, cache) { | |
|
||
const [joinDaiEvents, cdpMoveEvents] = await Promise.all([ | ||
web3.getPastLogs({ | ||
address: [MCD_JOIN_DAI, MCD_JOIN_SAI], | ||
/* | ||
FIXME: ethers 5 doesn't support passing an array of addresses into getLogs | ||
as we move further away from SCD, join Sai events are less likely, but | ||
we should eventually re-add this functionality by duplicating this call for MCD_JOIN_SAI. | ||
*/ | ||
// address: [MCD_JOIN_DAI, MCD_JOIN_SAI], | ||
address: MCD_JOIN_DAI, | ||
Comment on lines
+166
to
+172
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here. How do you think we should address this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left it there commented out as a reminder, but I don't know if we should prioritize it at the moment. Given that nobody uses the event history in the mcd plugin anymore since Oasis moved away from it, and given that it only affects parsing SCD events, I'm willing to release this version without it. If anyone feels differently let me know. The fix would be to duplicate the same function using |
||
topics: [ | ||
dart.lt(0) ? EVENT_DAI_ADAPTER_JOIN : EVENT_DAI_ADAPTER_EXIT, | ||
proxy | ||
|
@@ -277,11 +289,7 @@ export default async function getEventHistory(cdpManager, managedCdp, cache) { | |
const catBite = (address, fromBlock, toBlock) => ({ | ||
request: web3.getPastLogs({ | ||
address, | ||
topics: [ | ||
utils.keccak256(utils.toHex(Bite.signature)), | ||
null, | ||
'0x' + padStart(urnHandler.slice(2), 64, '0') | ||
], | ||
topics: [biteTopic0, null, '0x' + padStart(urnHandler.slice(2), 64, '0')], | ||
fromBlock, | ||
toBlock | ||
}), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good example of an ethers built in function that simplifies things a little bit from before.