Skip to content

Commit 5a059c6

Browse files
authored
Merge pull request #461 from balancednetwork/feat/loans-redemption-exemptions
feat: Add option to exempt collaterals from redemptions
2 parents ab614ab + 181beab commit 5a059c6

5 files changed

Lines changed: 42 additions & 1 deletion

File tree

core-contracts/Loans/src/main/java/network/balanced/score/core/loans/LoansImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ private void _returnAsset(String _from, BigInteger _value, String _collateralSym
464464
public void redeemCollateral(Address _collateralAddress, BigInteger _amount) {
465465
checkStatus();
466466
loansOn();
467+
Context.require(!getRedemptionExemption(_collateralAddress), "bnUSD cannot be redeemed for this collateral");
467468
Address caller = Context.getCaller();
468469
String collateralSymbol = CollateralDB.getSymbol(_collateralAddress);
469470
BigInteger daofundFee = redemptionDaoFee.getOrDefault(BigInteger.ZERO).multiply(_amount).divide(POINTS);
@@ -888,6 +889,17 @@ public BigInteger getRedemptionFee() {
888889
return redemptionFee.get();
889890
}
890891

892+
@External
893+
public void setRedemptionExemption(Address token, boolean exempt) {
894+
onlyGovernance();
895+
redemptionExemptions.set(token, exempt);
896+
}
897+
898+
@External(readonly = true)
899+
public boolean getRedemptionExemption(Address token) {
900+
return redemptionExemptions.getOrDefault(token, false);
901+
}
902+
891903
@External
892904
public void setRedemptionDaoFee(BigInteger _fee) {
893905
onlyGovernance();

core-contracts/Loans/src/main/java/network/balanced/score/core/loans/LoansVariables.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class LoansVariables {
4242
private static final String REDEMPTION_DAO_FEE = "redemption_dao_fee";
4343
private static final String RETIREMENT_BONUS = "retirement_bonus";
4444
private static final String NEW_LOAN_MINIMUM = "new_loan_minimum";
45+
private static final String REDEMPTION_EXEMPTIONS = "redemption_exemptions";
4546

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

7375
static final VarDB<Address> expectedToken = Context.newVarDB(EXPECTED_TOKEN, Address.class);
7476
static final VarDB<BigInteger> amountReceived = Context.newVarDB(AMOUNT_RECEIVED, BigInteger.class);

core-contracts/Loans/src/test/java/network/balanced/score/core/loans/LoansTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,27 @@ void redeemCollateral_redeemAboveMax() {
16791679
expectErrorMessage(redeemAboveMaxSize, expectedErrorMessage);
16801680
}
16811681

1682+
@Test
1683+
void redeemCollateral_exemptCollateral() {
1684+
// Arrange
1685+
Account account1 = sm.createAccount();
1686+
Account redeemer = sm.createAccount();
1687+
BigInteger collateral = BigInteger.valueOf(4000).multiply(EXA);
1688+
BigInteger loan = BigInteger.valueOf(400).multiply(EXA);
1689+
1690+
BigInteger sICXRate = EXA.divide(BigInteger.TWO);
1691+
mockOraclePrice("sICX", sICXRate);
1692+
1693+
// Act && Assert
1694+
loans.invoke(governance.account, "setRedemptionExemption", sicx.getAddress(), true);
1695+
takeLoanICX(account1, "bnUSD", collateral, loan);
1696+
1697+
String expectedErrorMessage = "bnUSD cannot be redeemed for this collateral";
1698+
Executable redeemExemptToken = () -> loans.invoke(redeemer, "redeemCollateral", sicx.getAddress(), BigInteger.ONE);
1699+
expectErrorMessage(redeemExemptToken, expectedErrorMessage);
1700+
}
1701+
1702+
16821703
@Test
16831704
void redeemCollateral_iETH() {
16841705
// Arrange

score-lib/src/main/java/network/balanced/score/lib/interfaces/Loans.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ void depositAndBorrow(@Optional String _asset, @Optional BigInteger _amount, @Op
148148
@External(readonly = true)
149149
BigInteger getRedemptionDaoFee();
150150

151+
@External
152+
void setRedemptionExemption(Address token, boolean exempt);
153+
154+
@External(readonly = true)
155+
boolean getRedemptionExemption(Address token);
156+
151157
@External
152158
void setNewLoanMinimum(BigInteger _minimum);
153159

score-lib/src/main/java/network/balanced/score/lib/utils/Versions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
public class Versions {
2020
public final static String BALN = "v1.1.0";
2121
public final static String DIVIDENDS = "v1.0.0";
22-
public final static String LOANS = "v1.2.0";
22+
public final static String LOANS = "v1.2.1";
2323
public final static String RESERVE = "v1.0.0";
2424
public final static String SICX = "v1.1.1";
2525
public final static String STAKING = "v1.0.1";

0 commit comments

Comments
 (0)