Skip to content

Commit

Permalink
feat: Add option for governance to borrow from dex
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonAndell committed Nov 18, 2024
1 parent 3be7c9b commit c1f8d0c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,19 @@ public void govWithdraw(int id, Address token, BigInteger value) {
Context.call(token, "transfer", getDaofund(), value);
}

@External
public void governanceBorrow(Address token, BigInteger amount, Address recipient) {
onlyGovernance();
BigInteger currentDebt = governanceDebt.getOrDefault(token, BigInteger.ZERO);
governanceDebt.set(token, currentDebt.add(amount));
Context.call(token, "transfer", recipient, amount);
}

Check warning on line 662 in core-contracts/Dex/src/main/java/network/balanced/score/core/dex/AbstractDex.java

View check run for this annotation

Codecov / codecov/patch

core-contracts/Dex/src/main/java/network/balanced/score/core/dex/AbstractDex.java#L658-L662

Added lines #L658 - L662 were not covered by tests

@External(readonly=true)
public BigInteger getGovernanceDebt(Address token) {
return governanceDebt.getOrDefault(token, BigInteger.ZERO);

Check warning on line 666 in core-contracts/Dex/src/main/java/network/balanced/score/core/dex/AbstractDex.java

View check run for this annotation

Codecov / codecov/patch

core-contracts/Dex/src/main/java/network/balanced/score/core/dex/AbstractDex.java#L666

Added line #L666 was not covered by tests
}

@External
public void govSetPoolTotal(int pid, BigInteger total) {
onlyGovernance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class DexDBVariables {
private static final String CONTINUOUS_REWARDS_DAY = "continuous_rewards_day";
public static final String VERSION = "version";
public static final String ORACLE_PROTECTION = "oracle_protection";
public static final String GOV_DEBT = "governance_debt";


final static VarDB<Address> governance = Context.newVarDB(GOVERNANCE_ADDRESS, Address.class);
Expand Down Expand Up @@ -154,4 +155,8 @@ public class DexDBVariables {

//Map: pid -> percentage
public final static DictDB<BigInteger, BigInteger> oracleProtection = Context.newDictDB(ORACLE_PROTECTION, BigInteger.class);

//Map: token -> amount
final static DictDB<Address, BigInteger> governanceDebt = Context.newDictDB(GOV_DEBT, BigInteger.class);

}
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,11 @@ void xAdd(String from, String _baseToken, String _quoteToken, BigInteger _baseVa

@External(readonly = true)
BigInteger depositOfUser(Address _owner, Address _token);

@External
void governanceBorrow(Address token, BigInteger amount, Address recipient);

@External(readonly=true)
BigInteger getGovernanceDebt(Address token);
}

0 comments on commit c1f8d0c

Please sign in to comment.