Skip to content

feat: update onBeforeMint logic to allow direct DEV staking #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
30 changes: 23 additions & 7 deletions contracts/SimpleCollections.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,30 @@ contract SimpleCollections is ITokenURIDescriptor, OwnableUpgradeable {
return false;
}

// Always only allow staking via the SwapAndStake contract.
ISwapAndStake.Amounts memory stakeVia = swapAndStake.gatewayOf(
img.gateway
);

// Validate the staking position.
bool valid = img.requiredETHAmount <= stakeVia.input &&
img.requiredETHFee <= stakeVia.fee;
bool valid = false;

// `requiredETHFee` will be 0 when using direct `DEV` otherwise it's assumed
// that input currency is `ETH`.
if (img.requiredETHFee > 0) {
// This condition validates input user ETH and fee.
// Always only allow staking via the SwapAndStake contract.
ISwapAndStake.Amounts memory stakeVia = swapAndStake.gatewayOf(
img.gateway
);

valid =
img.requiredETHAmount <= stakeVia.input &&
img.requiredETHFee <= stakeVia.fee;
} else {
// This condition validates input `DEV` equivalent `ETH` with required.
// Fetch the `amount of ETH` the `DEV staked` is equal to.
uint256 equivalentETHStaked = swapAndStake.getEstimatedEthForDev(
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if we can use this function. Since this uses
quoteExactInputSingle function which is a lens contract by uniswap meant only for off-chain calling since they are gas inefficient. here

Copy link
Member

Choose a reason for hiding this comment

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

Nice catch. But how else can DEV:ETH equivalence be verified on-chain?

_positions.amount
);

valid = img.requiredETHAmount <= equivalentETHStaked;
}

if (valid) {
stakedAmountAtMinted[_positions.property][id] = _positions.amount;
Expand Down
4 changes: 4 additions & 0 deletions contracts/interfaces/ISwapAndStake.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ interface ISwapAndStake {
uint256 fee;
}

function getEstimatedEthForDev(
uint256 devAmount
) external returns (uint256);

function gatewayOf(address _addr) external view returns (Amounts memory);
}