Skip to content

Commit 74f8b0f

Browse files
authored
Merge pull request #464 from balancednetwork/feat/dex-borrowing
feat: Add option for governance to borrow from dex
2 parents 3155575 + 1aa2624 commit 74f8b0f

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,19 @@ public void govWithdraw(int id, Address token, BigInteger value) {
644644
Context.call(token, "transfer", getDaofund(), value);
645645
}
646646

647+
@External
648+
public void governanceBorrow(Address token, BigInteger amount, Address recipient) {
649+
onlyGovernance();
650+
BigInteger currentDebt = governanceDebt.getOrDefault(token, BigInteger.ZERO);
651+
governanceDebt.set(token, currentDebt.add(amount));
652+
Context.call(token, "transfer", recipient, amount);
653+
}
654+
655+
@External(readonly=true)
656+
public BigInteger getGovernanceDebt(Address token) {
657+
return governanceDebt.getOrDefault(token, BigInteger.ZERO);
658+
}
659+
647660
@External
648661
public void govSetPoolTotal(int pid, BigInteger total) {
649662
onlyGovernance();

core-contracts/Dex/src/main/java/network/balanced/score/core/dex/DexDBVariables.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class DexDBVariables {
5858
private static final String TOKEN_PRECISIONS = "token_precisions";
5959
public static final String VERSION = "version";
6060
public static final String ORACLE_PROTECTION = "oracle_protection";
61+
public static final String GOV_DEBT = "governance_debt";
6162

6263

6364
final static VarDB<Address> governance = Context.newVarDB(GOVERNANCE_ADDRESS, Address.class);
@@ -137,4 +138,8 @@ public class DexDBVariables {
137138

138139
//Map: pid -> percentage
139140
public final static DictDB<BigInteger, BigInteger> oracleProtection = Context.newDictDB(ORACLE_PROTECTION, BigInteger.class);
141+
142+
//Map: token -> amount
143+
final static DictDB<Address, BigInteger> governanceDebt = Context.newDictDB(GOV_DEBT, BigInteger.class);
144+
140145
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,5 +207,10 @@ void xAdd(String from, String _baseToken, String _quoteToken, BigInteger _baseVa
207207
@External
208208
void addLpAddresses(BigInteger _poolId, Address[] _addresses);
209209

210+
@External
211+
void governanceBorrow(Address token, BigInteger amount, Address recipient);
212+
213+
@External(readonly=true)
214+
BigInteger getGovernanceDebt(Address token);
210215
}
211216

0 commit comments

Comments
 (0)