-
Notifications
You must be signed in to change notification settings - Fork 55
Conversation
This is ready to begin the review process. There are some comments and console.logs that I will need to clean up, as well as fixing the package imports. I changed these to read from my local version so I didn't have to keep publishing alphas repeatedly. I will try to add context in the comments to some of the changes to make it easier to review. |
const [topic] = this._contract.interface.encodeFilterTopics( | ||
'LinkConfirmed', | ||
[] |
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.
@@ -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 comment
The 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 currency
does not work, so instead we now have to pass it's hex value (passing .toString()
would also work, but I figure the hex value is less prone to a conversion error).
This is the first of many examples of converting an ethers returned BN type into a hex for currency
to consume.
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 comment
The 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 0x4554482d41
, we now have to pass the full 32 bytes, eg. 0x4554482d41000000000000000000000000000000000000000000000000000000
. Fortunately ethers utils has a built in function for that.
@@ -59,7 +61,8 @@ export default class Erc20Token { | |||
|
|||
approveUnlimited(spender, options = {}) { | |||
if (!spender) spender = this._web3.currentAddress(); | |||
return this._contract.approve(spender, -1, { | |||
return this._contract.approve(spender, ethers.BigNumber.from(UINT256_MAX), { |
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.
can no longer approve -1
as a shortcut for unlimited in ethers 5.
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.
i tried to find documentation for this but i can not
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.
@rafinskipg in web3.js it seems a negative number is interpreted as int256
. Maybe ethers v3 accepted this as well? But you can't send a negative number in EVM according to this.
@@ -196,13 +196,16 @@ export default class TransactionManager extends PublicService { | |||
|
|||
async _getGasLimit(options, contract, method, args) { | |||
let transaction = {}; | |||
let data = contract.interface.functions[method](...args).data; | |||
let data = contract.interface.encodeFunctionData(method, args); |
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.
The old way to get contract function data was deprecated, now we use encodeFunctionData
Codecov Report
@@ Coverage Diff @@
## dev #303 +/- ##
==========================================
- Coverage 86.13% 86.11% -0.02%
==========================================
Files 139 139
Lines 6310 6339 +29
Branches 1247 1258 +11
==========================================
+ Hits 5435 5459 +24
- Misses 870 875 +5
Partials 5 5
Continue to review full report at Codecov.
|
for (const fnKey in contract.interface.functions) { | ||
// Match the function override with key that has the same number of inputs | ||
if ( | ||
contract.interface.functions[fnKey].name === key && | ||
contract.interface.functions[fnKey].inputs.length === | ||
functionInputsLength | ||
) { | ||
key = fnKey; | ||
} | ||
} | ||
return txManager.sendContractCall(contract, key, args, name); | ||
}; |
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.
We now have to be more specific with function overloads in ethers 5, so we have to specify the exact function signature, rather than the function name. Here we determine the correct key by matching the number of inputs from the interface with the number of args passed in (minus the business object at the end).
e529a1a
to
5d77617
Compare
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.
Left a couple questions but looks good to me otherwise. Nice work. Looks like it was a fun one 😛
// const MCD_JOIN_SAI = cdpManager | ||
// .get('smartContract') | ||
// .getContractAddress('MCD_JOIN_SAI'); |
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.
Do we want to leave this commented out?
/* | ||
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, |
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.
Same question here. How do you think we should address this?
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.
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 MCD_JOIN_SAI
as the address, merge & sort the results.
export function stringToBytes(str) { | ||
assert(!!str, 'argument is falsy'); | ||
assert(typeof str === 'string', 'argument is not a string'); | ||
return '0x' + Buffer.from(str).toString('hex'); | ||
return ethersUtils.formatBytes32String(str); |
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.
🤘
@@ -3,5 +3,5 @@ set -e | |||
|
|||
CWD="${0%/*}" | |||
|
|||
$CWD/set-polling-interval.sh |
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.
Not sure if this should be left commented out either. Flagging to review as well.
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.
it was making a change to a file in ethers that no longer exists, but I'll double check if I can change the path to the file it was looking for.
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.
i trust you , and i trust the test suite
- @makerdao/[email protected] - @makerdao/[email protected] - @makerdao/[email protected] - @makerdao/[email protected] - @makerdao/[email protected] - @makerdao/[email protected] - @makerdao/[email protected] - @makerdao/[email protected]
No description provided.