From c1f8d0c92566646c29c72f11f13e2a732669f41d Mon Sep 17 00:00:00 2001 From: AntonAndell Date: Mon, 18 Nov 2024 16:15:48 +0100 Subject: [PATCH] feat: Add option for governance to borrow from dex --- .../balanced/score/core/dex/AbstractDex.java | 13 +++++++++++++ .../balanced/score/core/dex/DexDBVariables.java | 5 +++++ .../network/balanced/score/lib/interfaces/Dex.java | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/AbstractDex.java b/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/AbstractDex.java index 2f5ee1ac7..6c6390fbb 100644 --- a/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/AbstractDex.java +++ b/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/AbstractDex.java @@ -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); + } + + @External(readonly=true) + public BigInteger getGovernanceDebt(Address token) { + return governanceDebt.getOrDefault(token, BigInteger.ZERO); + } + @External public void govSetPoolTotal(int pid, BigInteger total) { onlyGovernance(); diff --git a/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/DexDBVariables.java b/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/DexDBVariables.java index b33080391..93d31e41a 100644 --- a/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/DexDBVariables.java +++ b/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/DexDBVariables.java @@ -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
governance = Context.newVarDB(GOVERNANCE_ADDRESS, Address.class); @@ -154,4 +155,8 @@ public class DexDBVariables { //Map: pid -> percentage public final static DictDB oracleProtection = Context.newDictDB(ORACLE_PROTECTION, BigInteger.class); + + //Map: token -> amount + final static DictDB governanceDebt = Context.newDictDB(GOV_DEBT, BigInteger.class); + } diff --git a/score-lib/src/main/java/network/balanced/score/lib/interfaces/Dex.java b/score-lib/src/main/java/network/balanced/score/lib/interfaces/Dex.java index f08ff4f9e..dd9761264 100644 --- a/score-lib/src/main/java/network/balanced/score/lib/interfaces/Dex.java +++ b/score-lib/src/main/java/network/balanced/score/lib/interfaces/Dex.java @@ -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); }