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

Remove legacy code for rewards #403

Merged
merged 9 commits into from
Aug 14, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class GovernanceConstants extends Constants {
);

public static Map<String, String> ADMIN_ADDRESSES = Map.ofEntries(
entry("rewards", "governance"),
entry("baln", "rewards"),
entry("bwt", "governance")
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonObject;
import network.balanced.score.lib.structs.DistributionPercentage;
import network.balanced.score.lib.utils.Names;
import score.Address;
import score.Context;
Expand All @@ -28,6 +27,7 @@

import static network.balanced.score.core.governance.GovernanceImpl.*;
import static network.balanced.score.core.governance.utils.GovernanceConstants.*;
import static network.balanced.score.lib.utils.Constants.EXA;
import static network.balanced.score.lib.utils.Math.pow;

public class SetupManager {
Expand Down Expand Up @@ -75,12 +75,16 @@ public static void launchBalanced() {
_setTimeOffset(timeDelta);

for (Map<String, String> source : DATA_SOURCES) {
call(ContractManager.getAddress(Names.REWARDS), "addNewDataSource", source.get("name"),
ContractManager.get(source.get("address")));
call(ContractManager.getAddress(Names.REWARDS), "createDataSource", source.get("name"),
ContractManager.get(source.get("address")), 0);
}

call(ContractManager.getAddress(Names.REWARDS), "updateBalTokenDistPercentage", (Object) RECIPIENTS);
}
call(ContractManager.getAddress(Names.REWARDS), "setPlatformDistPercentage", Names.DAOFUND, BigInteger.valueOf(5).multiply(pow(BigInteger.TEN, 16)));
call(ContractManager.getAddress(Names.REWARDS), "setPlatformDistPercentage", Names.RESERVE, BigInteger.valueOf(5).multiply(pow(BigInteger.TEN, 16)));
call(ContractManager.getAddress(Names.REWARDS), "setPlatformDistPercentage", Names.WORKERTOKEN, BigInteger.valueOf(20).multiply(pow(BigInteger.TEN, 16)));
call(ContractManager.getAddress(Names.REWARDS), "setFixedSourcePercentage", "Loans", BigInteger.valueOf(20).multiply(pow(BigInteger.TEN, 16)));
call(ContractManager.getAddress(Names.REWARDS), "setFixedSourcePercentage", "sICX/ICX", BigInteger.TEN.multiply(pow(BigInteger.TEN, 16)));
};

public static void createBnusdMarket() {
BigInteger value = Context.getValue();
Expand Down Expand Up @@ -115,16 +119,9 @@ public static void createBnusdMarket() {

_addLPDataSource(name, pid);

DistributionPercentage[] recipients = new DistributionPercentage[]{
createDistributionPercentage("Loans", BigInteger.valueOf(25).multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("sICX/ICX", BigInteger.TEN.multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("Worker Tokens", BigInteger.valueOf(20).multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("Reserve Fund", BigInteger.valueOf(5).multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("DAOfund", BigInteger.valueOf(225).multiply(pow(BigInteger.TEN, 15))),
createDistributionPercentage("sICX/bnUSD", BigInteger.valueOf(175).multiply(pow(BigInteger.TEN, 15)))
};
call(ContractManager.getAddress(Names.REWARDS), "setFixedSourcePercentage", "sICX/bnUSD", BigInteger.valueOf(15).multiply(pow(BigInteger.TEN, 16)));


call(ContractManager.getAddress(Names.REWARDS), "updateBalTokenDistPercentage", (Object) recipients);
}

public static void createBalnMarket(BigInteger _bnUSD_amount, BigInteger _baln_amount) {
Expand All @@ -149,18 +146,7 @@ public static void createBalnMarket(BigInteger _bnUSD_amount, BigInteger _baln_a
call(dexAddress, "setMarketName", pid, name);

_addLPDataSource(name, pid);

DistributionPercentage[] recipients = new DistributionPercentage[]{
createDistributionPercentage("Loans", BigInteger.valueOf(25).multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("sICX/ICX", BigInteger.TEN.multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("Worker Tokens", BigInteger.valueOf(20).multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("Reserve Fund", BigInteger.valueOf(5).multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("DAOfund", BigInteger.valueOf(5).multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("sICX/bnUSD", BigInteger.valueOf(175).multiply(pow(BigInteger.TEN, 15))),
createDistributionPercentage("BALN/bnUSD", BigInteger.valueOf(175).multiply(pow(BigInteger.TEN, 15)))
};

call(rewardsAddress, "updateBalTokenDistPercentage", (Object) recipients);
call(ContractManager.getAddress(Names.REWARDS), "setFixedSourcePercentage", "BALN/bnUSD", BigInteger.valueOf(15).multiply(pow(BigInteger.TEN, 16)));
}

public static void createBalnSicxMarket(BigInteger _sicx_amount, BigInteger _baln_amount) {
Expand All @@ -184,23 +170,13 @@ public static void createBalnSicxMarket(BigInteger _sicx_amount, BigInteger _bal

_addLPDataSource(name, pid);

DistributionPercentage[] recipients = new DistributionPercentage[]{
createDistributionPercentage("Loans", BigInteger.valueOf(20).multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("sICX/ICX", BigInteger.TEN.multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("Worker Tokens", BigInteger.valueOf(20).multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("Reserve Fund", BigInteger.valueOf(5).multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("DAOfund", BigInteger.valueOf(5).multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("sICX/bnUSD", BigInteger.valueOf(15).multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("BALN/bnUSD", BigInteger.valueOf(15).multiply(pow(BigInteger.TEN, 16))),
createDistributionPercentage("BALN/sICX", BigInteger.valueOf(10).multiply(pow(BigInteger.TEN, 16)))
};
call(ContractManager.getAddress(Names.REWARDS), "setFixedSourcePercentage", "BALN/sICX", BigInteger.valueOf(10).multiply(pow(BigInteger.TEN, 16)));

call(ContractManager.getAddress(Names.REWARDS), "updateBalTokenDistPercentage", (Object) recipients);
}

private static void _addNewDataSource(String _data_source_name, String _contract_address) {
Context.call(ContractManager.getAddress(Names.REWARDS), "addNewDataSource", _data_source_name,
Address.fromString(_contract_address));
Context.call(ContractManager.getAddress(Names.REWARDS), "createDataSource", _data_source_name,
Address.fromString(_contract_address), 0);
}

private static void _addLPDataSource(String _name, BigInteger _poolId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@ void launchBalanced() {
verify(rewards.mock).setTimeOffset(any(BigInteger.class));
verify(dex.mock).setTimeOffset(any(BigInteger.class));

verify(rewards.mock).addNewDataSource("Loans", loans.getAddress());
verify(rewards.mock).addNewDataSource("sICX/ICX", dex.getAddress());

verify(rewards.mock).updateBalTokenDistPercentage(any(DistributionPercentage[].class));
}

@Test
Expand Down Expand Up @@ -254,9 +250,7 @@ void createBnusdMarket() {
verify(dex.mock).add(sicx.getAddress(), bnUSD.getAddress(), sICXValue, bnUSDValue, false, BigInteger.ZERO);
verify(dex.mock).setMarketName(sicxBnusdPid, "sICX/bnUSD");

verify(rewards.mock).addNewDataSource("sICX/bnUSD", stakedLp.getAddress());
verify(stakedLp.mock).addDataSource(sicxBnusdPid, "sICX/bnUSD");
verify(rewards.mock, times(2)).updateBalTokenDistPercentage(any(DistributionPercentage[].class));
}

@Test
Expand Down Expand Up @@ -286,9 +280,7 @@ void createBalnMarket() {
verify(dex.mock).add(baln.getAddress(), bnUSD.getAddress(), balnValue, bnUSDValue, false, BigInteger.ZERO);
verify(dex.mock).setMarketName(balnBnusdPid, "BALN/bnUSD");

verify(rewards.mock).addNewDataSource("BALN/bnUSD", stakedLp.getAddress());
verify(stakedLp.mock).addDataSource(balnBnusdPid, "BALN/bnUSD");
verify(rewards.mock, times(3)).updateBalTokenDistPercentage(any(DistributionPercentage[].class));
}

@Test
Expand Down Expand Up @@ -320,9 +312,7 @@ void createBalnSicxMarket() {
verify(dex.mock).add(baln.getAddress(), sicx.getAddress(), balnValue, sicxValue, false, BigInteger.ZERO);
verify(dex.mock).setMarketName(balnSicxPid, "BALN/sICX");

verify(rewards.mock).addNewDataSource("BALN/sICX", stakedLp.getAddress());
verify(stakedLp.mock).addDataSource(balnSicxPid, "BALN/sICX");
verify(rewards.mock, times(4)).updateBalTokenDistPercentage(any(DistributionPercentage[].class));
}

@Test
Expand Down
2 changes: 2 additions & 0 deletions core-contracts/Rewards/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ dependencies {
compileOnly Dependencies.javaeeApi
implementation Dependencies.javaeeScorex
implementation project(':score-lib')
implementation Dependencies.minimalJson

testImplementation Dependencies.javaeeUnitTest
testImplementation Dependencies.junitJupiter
testRuntimeOnly Dependencies.junitJupiterEngine
testImplementation Dependencies.mockitoCore
testImplementation Dependencies.mockitoInline
testImplementation project(':test-lib')
testImplementation Dependencies.json

intTestAnnotationProcessor project(':score-client')
intTestImplementation project(':score-client')
Expand Down
Loading
Loading