Skip to content
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

feat: Add option to exempt collaterals from redemptions #461

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ private void _returnAsset(String _from, BigInteger _value, String _collateralSym
public void redeemCollateral(Address _collateralAddress, BigInteger _amount) {
checkStatus();
loansOn();
Context.require(!getRedemptionExemption(_collateralAddress), "bnUSD cannot be redeemed for this collateral");
Address caller = Context.getCaller();
String collateralSymbol = CollateralDB.getSymbol(_collateralAddress);
BigInteger daofundFee = redemptionDaoFee.getOrDefault(BigInteger.ZERO).multiply(_amount).divide(POINTS);
Expand Down Expand Up @@ -888,6 +889,17 @@ public BigInteger getRedemptionFee() {
return redemptionFee.get();
}

@External
public void setRedemptionExemption(Address token, boolean exempt) {
onlyGovernance();
redemptionExemptions.set(token, exempt);
}

@External(readonly = true)
public boolean getRedemptionExemption(Address token) {
return redemptionExemptions.getOrDefault(token, false);
}

@External
public void setRedemptionDaoFee(BigInteger _fee) {
onlyGovernance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class LoansVariables {
private static final String REDEMPTION_DAO_FEE = "redemption_dao_fee";
private static final String RETIREMENT_BONUS = "retirement_bonus";
private static final String NEW_LOAN_MINIMUM = "new_loan_minimum";
private static final String REDEMPTION_EXEMPTIONS = "redemption_exemptions";

private static final String REDEEM_BATCH_SIZE = "redeem_batch_size";
private static final String MAX_RETIRE_PERCENT = "max_retire_percent";
Expand Down Expand Up @@ -69,6 +70,7 @@ public class LoansVariables {
static final VarDB<BigInteger> newLoanMinimum = Context.newVarDB(NEW_LOAN_MINIMUM, BigInteger.class);
static final VarDB<Integer> redeemBatch = Context.newVarDB(REDEEM_BATCH_SIZE, Integer.class);
static final VarDB<BigInteger> maxRetirePercent = Context.newVarDB(MAX_RETIRE_PERCENT, BigInteger.class);
static final DictDB<Address, Boolean> redemptionExemptions= Context.newDictDB(REDEMPTION_EXEMPTIONS, Boolean.class);

static final VarDB<Address> expectedToken = Context.newVarDB(EXPECTED_TOKEN, Address.class);
static final VarDB<BigInteger> amountReceived = Context.newVarDB(AMOUNT_RECEIVED, BigInteger.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,27 @@ void redeemCollateral_redeemAboveMax() {
expectErrorMessage(redeemAboveMaxSize, expectedErrorMessage);
}

@Test
void redeemCollateral_exemptCollateral() {
// Arrange
Account account1 = sm.createAccount();
Account redeemer = sm.createAccount();
BigInteger collateral = BigInteger.valueOf(4000).multiply(EXA);
BigInteger loan = BigInteger.valueOf(400).multiply(EXA);

BigInteger sICXRate = EXA.divide(BigInteger.TWO);
mockOraclePrice("sICX", sICXRate);

// Act && Assert
loans.invoke(governance.account, "setRedemptionExemption", sicx.getAddress(), true);
takeLoanICX(account1, "bnUSD", collateral, loan);

String expectedErrorMessage = "bnUSD cannot be redeemed for this collateral";
Executable redeemExemptToken = () -> loans.invoke(redeemer, "redeemCollateral", sicx.getAddress(), BigInteger.ONE);
expectErrorMessage(redeemExemptToken, expectedErrorMessage);
}


@Test
void redeemCollateral_iETH() {
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ void depositAndBorrow(@Optional String _asset, @Optional BigInteger _amount, @Op
@External(readonly = true)
BigInteger getRedemptionDaoFee();

@External
void setRedemptionExemption(Address token, boolean exempt);

@External(readonly = true)
boolean getRedemptionExemption(Address token);

@External
void setNewLoanMinimum(BigInteger _minimum);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class Versions {
public final static String BALN = "v1.1.0";
public final static String DIVIDENDS = "v1.0.0";
public final static String LOANS = "v1.2.0";
public final static String LOANS = "v1.2.1";
public final static String RESERVE = "v1.0.0";
public final static String SICX = "v1.1.1";
public final static String STAKING = "v1.0.1";
Expand Down
Loading