Skip to content

Commit

Permalink
fixed mint flow
Browse files Browse the repository at this point in the history
  • Loading branch information
David405 committed Sep 27, 2023
1 parent 0d4e6d1 commit 4f66355
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions contracts/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ contract Vault is

uint256 netMintChange;

_mint(zUSD, msg.sender, _mintAmount);

if(globalDebt == 0 || netMintGlobal == 0) {
netMintChange = _mintAmount;
} else {
Expand All @@ -210,8 +212,8 @@ contract Vault is
grossMintUser[msg.sender] += _mintAmount;

netMintUser[msg.sender] += netMintChange;
netMintGlobal += netMintChange;
netMintGlobal += netMintChange;

/**
* if this is user's first mint, add to minters list
*/
Expand All @@ -222,8 +224,6 @@ contract Vault is

_testImpact();

_mint(zUSD, msg.sender, _mintAmount);

collateral.safeTransferFrom(
msg.sender,
address(this),
Expand Down Expand Up @@ -284,6 +284,10 @@ contract Vault is

totalSwapVolume += swapAmountInUSD;

_burn(_zTokenFromAddress, msg.sender, _amount);

_mint(_zTokenToAddress, msg.sender, mintAmount);

/**
* Handle swap fees and rewards
*/
Expand All @@ -303,7 +307,7 @@ contract Vault is

treasuryFeePerTransaction = treasuryFeePerTransaction / MULTIPLIER;

uint256 len = mintersAddresses.length;
uint256 len = mintersAddresses.length;

for(uint256 i; i < len; i++) {
mintersRewardPerTransaction[mintersAddresses[i]] =
Expand All @@ -316,16 +320,12 @@ contract Vault is
MULTIPLIER;
}

_burn(_zTokenFromAddress, msg.sender, _amount);

_mint(_zTokenToAddress, msg.sender, mintAmount);

/**
* Send the treasury amount to a treasury wallet
*/
_mint(zUSD, treasuryWallet, treasuryFeePerTransaction);

/**
/**
* Send the global minters fee from User to the global minters fee wallet
*/
_mint(zUSD, address(this), globalMintersFeePerTransaction);
Expand Down Expand Up @@ -372,14 +372,14 @@ contract Vault is
netMintGlobal -= amountToSubtract;
}

_burn(zUSD, msg.sender, amountToRepayinUSD);

userCollateralBalance[msg.sender] -= _amountToWithdraw;

totalCollateral -= _amountToWithdraw;

_testImpact();

_burn(zUSD, msg.sender, amountToRepayinUSD);

collateral.safeTransfer(
msg.sender,
_amountToWithdraw
Expand Down Expand Up @@ -435,7 +435,7 @@ contract Vault is
emit Liquidate(_user, userDebt, totalRewards, msg.sender);
}

/**
/**
* Allow minters to claim rewards/fees on swap
*/
function claimFees() external nonReentrant {
Expand Down Expand Up @@ -864,11 +864,25 @@ contract Vault is

treasuryFeePerTransaction = treasuryFeePerTransaction / MULTIPLIER;

uint256 len = mintersAddresses.length;

for(uint256 i; i < len; i++) {
mintersRewardPerTransaction[mintersAddresses[i]] =
((netMintUser[mintersAddresses[i]] * MULTIPLIER) /
netMintGlobal) *
globalMintersFeePerTransaction;

userAccruedFeeBalance[mintersAddresses[i]] +=
mintersRewardPerTransaction[mintersAddresses[i]] /
MULTIPLIER;
}

/**
* Send the treasury amount to a treasury wallet
*/
_mint(zUSD, treasuryWallet, treasuryFeePerTransaction);
/**

/**
* Send the global minters fee from User to the global minters fee wallet
*/
_mint(zUSD, address(this), globalMintersFeePerTransaction);
Expand Down Expand Up @@ -940,7 +954,7 @@ contract Vault is
return globalDebt;
}

function getUserDebt(address user) external view returns (uint256) {
function getUserDebt(address user) public view returns (uint256) {
return _updateUserDebtOutstanding(netMintUser[user], netMintGlobal);
}

Expand All @@ -950,7 +964,7 @@ contract Vault is
function _updateUserDebtOutstanding(
uint256 _netMintUserzUSDValue,
uint256 _netMintGlobalzUSDValue
) public view returns (uint256) {
) internal view returns (uint256) {
if (_netMintGlobalzUSDValue != 0) {
uint256 globalDebt = getGlobalDebt();
uint256 userDebtOutstanding;
Expand Down

0 comments on commit 4f66355

Please sign in to comment.