Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Use specific contract types #542

Merged
merged 13 commits into from
Mar 26, 2020
Merged

Use specific contract types #542

merged 13 commits into from
Mar 26, 2020

Conversation

NicholasDotSol
Copy link
Contributor

closes: #507

Rather than storing addresses and then casting to the known contract type, it’s better to use the best type available so the compiler can check for type safety.

NicholasDotSol added 3 commits March 25, 2020 13:25
Only TBTCDepositToken should be changed since it is the only
contract used.
The rest are just address placeholders for init funcitons.
FeeRebateToken not using IERC721 since the interface does
not expose an exists() function
Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few questions/notes.

solidity/contracts/deposit/Deposit.sol Outdated Show resolved Hide resolved
solidity/contracts/deposit/DepositFunding.sol Outdated Show resolved Hide resolved
@@ -354,8 +350,7 @@ library DepositUtils {
/// @dev We cast the address to a uint256 to match the 721 standard.
/// @return The current deposit beneficiary.
function depositOwner(Deposit storage _d) public view returns (address payable) {
IERC721 _tbtcDepositToken = IERC721(_d.TBTCDepositToken);
return address(uint160(_tbtcDepositToken.ownerOf(uint256(address(this)))));
return address(uint160(_d.tbtcDepositToken.ownerOf(uint256(address(this)))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there room here for an overload of ownerAddressOf that takes a Deposit and returns an address and does all of the weird type conversions for us as needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that might be a good idea.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not worth cycles unless you're motivated, but yeah, seems cleaner.

solidity/contracts/system/TBTCSystem.sol Outdated Show resolved Hide resolved
NicholasDotSol added 3 commits March 25, 2020 16:02
Instead of casting the parameter adress, accept Contract type directly
Add functions needed to create a new Deposit.
The interface should contain all function sneeded to
create the Deposit.
address public feeRebateToken;
TBTCSystem public tbtcSystem;
TBTCToken public tbtcToken;
FeeRebateToken public feeRebateToken;
address public vendingMachine;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we hit this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only use the address and never call any VendingMachine contract functions.
Hitting this would be counterproductive since we would just have to cast it back to use it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use the address? createNewDeposit should likewise take a VendingMachine, right? Generally eschewing the type check is a bad idea, and if we have to cast to a looser type at the use point, that's fine---otherwise you're leaving on the table the capacity of the compiler to bonk you when you mishandle some point in the initialization chain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use the address?

It's just used for redemption logic:
if(tdtHolder == vendingMachine){...}

Worth noting, It's introduced into the system as a contract type via tbtcSystem.initialize().
Then it's passed along and stored as an address. Might be worth renaming it to vendingMachineAddress to avoid confusion?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this. Makes it clear that we're really only interested in the address.

Also makes it clear this is a dirty dirty hack and in another life where we had more time we'd try to get around it haha.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok awesome

function requestNewKeep(uint256 _m, uint256 _n, uint256 _bond) external payable returns (address);
function getSignerFeeDivisor() external view returns (uint256);
function getUndercollateralizedThresholdPercent() external view returns (uint128);
function getSeverelyUndercollateralizedThresholdPercent() external view returns (uint128);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably our docs should be here rather than on TBTCSystem, but I need to see how our documentation generator is operating.

NicholasDotSol added 2 commits March 25, 2020 18:04
Explicit visibility for consistency
When a contract has use beyon it's address,
Pass the contract type isntead of the address.
NicholasDotSol added 3 commits March 26, 2020 15:30
Use `this` instead of casting twice to get to the same result.
Take an explicit contract type over an address
We're not using the contract instance, clarify that
we are only using the address
@@ -35,7 +36,7 @@ contract ECDSAKeepStub is IBondedECDSAKeep {
// solium-disable-previous-line no-empty-blocks
}

function distributeERC20Reward(address _asset, uint256 _value) external {
function distributeERC20Reward(IERC20 _asset, uint256 _value) external {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be enough, we have to play this out over both repos. Let's do that in a separate PR.

Copy link
Contributor Author

@NicholasDotSol NicholasDotSol Mar 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be enough

We just need an interface change from keep-ecdsa. This should be enough for Deposit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to play this out over both repos

Okay with moving to separate PR to unblock

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the interface change will also require changing the implementors of the interface, etc. It's not going to be huge, just needs a little more finesse :)

NicholasDotSol added 2 commits March 26, 2020 16:25
Changing distributeERC20Reward to accept IERC20 param
Requires some dependency syncing

Revert the change for now
Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok let's do ittt.

@Shadowfiend Shadowfiend merged commit c397657 into master Mar 26, 2020
@Shadowfiend Shadowfiend deleted the contract-types branch March 26, 2020 23:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use specific contract type instead of address
2 participants