Skip to content

Commit

Permalink
Remove staking from the Balanced token
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonAndell committed Dec 5, 2024
1 parent 094861e commit b3cf4d2
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 1,233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ void testBBaln_lock() {
Map<String, BigInteger> unclaimedDividendsBeforeBob = reader.dividends.getUnclaimedDividends(addressBob);

// user unstakes all the baln token
alice.baln.stake(BigInteger.ZERO);
BigInteger availableBalnBalance = alice.baln.availableBalanceOf(addressAlice);

long unlockTime =
Expand Down Expand Up @@ -257,35 +256,7 @@ void testBBaln_claimOnly() {
assertEquals(unclaimedDividendsAfterEve, BigInteger.ZERO);
}

@Test
@Order(6)
void testBBaln_claimAfterUnstake() {
/* Ferry claims the dividends after unstaking baln token. */
Address addressFerry = Ferry.getAddress();
BigInteger unclaimedDividendsBeforeFerry =
owner.dividends.getUnclaimedDividends(addressFerry).get(balanced.bnusd._address().toString());
BigInteger bnusdBeforeFerry = Ferry.bnUSD.balanceOf(addressFerry);
// Ferry unstakes baln token
Ferry.baln.stake(BigInteger.ZERO);
Ferry.dividends.claimDividends();
BigInteger unclaimedDividendsAfterFerry =
owner.dividends.getUnclaimedDividends(addressFerry).get(balanced.bnusd._address().toString());
BigInteger bnusdAfterFerry = Eve.bnUSD.balanceOf(addressFerry);
// unclaimed dividends become 0 after claiming
assertEquals(unclaimedDividendsAfterFerry, BigInteger.ZERO);
// unclaimed dividends should go to Eve's wallet after claiming
assertEquals(bnusdBeforeFerry.add(unclaimedDividendsBeforeFerry), bnusdAfterFerry);

BigInteger collateral = BigInteger.valueOf(500).multiply(BigInteger.TEN.pow(18));
BigInteger loanAmount = BigInteger.valueOf(100).multiply(BigInteger.TEN.pow(18));
owner.stakeDepositAndBorrow(collateral, loanAmount);
unclaimedDividendsAfterFerry =
owner.dividends.getUnclaimedDividends(addressFerry).get(balanced.bnusd._address().toString());

// unclaimed dividends remains 0 for that user
assertEquals(unclaimedDividendsAfterFerry, BigInteger.ZERO);

}

@Test
@Order(7)
Expand Down Expand Up @@ -520,13 +491,6 @@ void createNewUserForBBaln() {
owner.baln.transfer(addressEve, collateral, new byte[0]);
owner.baln.transfer(addressFerry, collateral, new byte[0]);

// staking baln token with multiple different users.
BigInteger stakedAmount = BigInteger.valueOf(50).multiply(BigInteger.TEN.pow(18));
alice.baln.stake(stakedAmount);
bob.baln.stake(stakedAmount);
Eve.baln.stake(stakedAmount);
Ferry.baln.stake(stakedAmount);

// loan taken to send some dividends to contract
owner.stakeDepositAndBorrow(collateral, loanAmount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ public class GovernanceConstants extends Constants {
public static Map<String, List<String>> ADDRESSES = Map.ofEntries(
entry("rewards", List.of("reserve", "baln", "bwt", "daofund", "stakedLp", "bBaln")),
entry("bnUSD", List.of("oracle")),
entry("baln", List.of("dividends", "oracle", "dex", "bnUSD")),
entry("bwt", List.of("baln")),
entry("stakedLp", List.of("dex", "rewards"))
);

public static Map<String, String> ADMIN_ADDRESSES = Map.ofEntries(
entry("baln", "rewards"),
entry("bwt", "governance")
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,11 @@

@ScoreClient
@ScoreInterface
public interface BalancedToken extends HubToken, IRC2BurnableInterface, GovernanceAddress, AdminAddress,
BnusdAddress, OracleAddress, DexAddress, DividendsAddress, Version {

@External
void setOracleName(String _name);

@External(readonly = true)
String getOracleName();
public interface BalancedToken extends HubToken, IRC2BurnableInterface, Version {

@External(readonly = true)
String getPeg();

@External
void setMinInterval(BigInteger _interval);

@External(readonly = true)
BigInteger getMinInterval();

@External(readonly = true)
BigInteger getPriceUpdateTime();

@External
BigInteger priceInLoop();

@External(readonly = true)
BigInteger lastPriceInLoop();

@External(readonly = true)
Map<String, BigInteger> detailsBalanceOf(Address _owner);

@External(readonly = true)
BigInteger unstakedBalanceOf(Address _owner);

Expand All @@ -72,54 +47,9 @@ public interface BalancedToken extends HubToken, IRC2BurnableInterface, Governan
@External(readonly = true)
BigInteger availableBalanceOf(Address _owner);

@External(readonly = true)
boolean getStakingEnabled();

@External(readonly = true)
BigInteger totalStakedBalance();

@External(readonly = true)
BigInteger getMinimumStake();

@External(readonly = true)
BigInteger getUnstakingPeriod();

@External
void toggleEnableSnapshot();

@External(readonly = true)
boolean getSnapshotEnabled();

@External
void toggleStakingEnabled();

@External
void stake(BigInteger _value);

@External
void setMinimumStake(BigInteger _amount);

@External
void setUnstakingPeriod(BigInteger _time);

@External
void setTimeOffset();

@External(readonly = true)
BigInteger getTimeOffset();

@External(readonly = true)
BigInteger getDay();

@External(readonly = true)
BigInteger stakedBalanceOfAt(Address _account, BigInteger _day);

@External(readonly = true)
BigInteger totalStakedBalanceOfAt(BigInteger _day);

@EventLog(indexed = 3)
void OraclePrice(String market, String oracle_name, Address oracle_address, BigInteger price);

@External
void setMinter(Address _address);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package network.balanced.score.lib.utils;

public class Versions {
public final static String BALN = "v1.1.0";
public final static String BALN = "v1.1.2";
public final static String DIVIDENDS = "v1.0.0";
public final static String LOANS = "v1.2.3";
public final static String RESERVE = "v1.0.0";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,5 @@ public void syncDistributions() {

public void increaseDay(int nrOfDays) {
ownerClient.governance.setTimeOffset(ownerClient.governance.getTimeOffset().subtract(MICRO_SECONDS_IN_A_DAY.multiply(BigInteger.valueOf(nrOfDays))));
JsonArray setTimeOffset = createSingleTransaction(baln._address(), "setTimeOffset", new JsonArray());

ownerClient.governance.execute(setTimeOffset.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,77 +59,6 @@ void testName() {
assertEquals("Balance Token", balnScore.name());
}

@Test
@Order(2)
void ShouldAUserMintAndTransferAndMakeStake() {
BigInteger loanAmount = BigInteger.valueOf(50).multiply(BigInteger.TEN.pow(18));
// take loans
BigInteger collateral = BigInteger.valueOf(500).multiply(BigInteger.TEN.pow(18));
balanced.ownerClient.stakeDepositAndBorrow(collateral, loanAmount);
balanced.increaseDay(1);
balanced.syncDistributions();

// balance token is minted in owner address
balanced.ownerClient.rewards.claimRewards(null);
BigInteger amountToMint = balnScore.balanceOf(Address.fromString(owner.getAddress().toString()));

//transfer some tokens to another user
BigInteger amountToTransferToReceiver = amountToMint.divide(BigInteger.TWO);
BigInteger amountRemaining = amountToMint.subtract(amountToTransferToReceiver);

balnScore.transfer(Address.fromString(tester.getAddress().toString()), amountToTransferToReceiver,
"mole".getBytes());
assertEquals(amountRemaining,
balnScore.balanceOf(Address.fromString(owner.getAddress().toString())));
assertEquals(amountToTransferToReceiver,
balnScore.balanceOf(Address.fromString(tester.getAddress().toString())));

BigInteger amountToStake = amountRemaining.divide(BigInteger.TWO);
BigInteger unstakedBalance = amountRemaining.subtract(amountToStake);

// stake some token
balnScore.stake(amountToStake);

Map<String, BigInteger> detailsBalanceOf =
balnScore.detailsBalanceOf(Address.fromString(owner.getAddress().toString()));

// assert if balance is staked or not.
assertEquals(detailsBalanceOf.get("Staked balance"), amountToStake);
assertEquals(detailsBalanceOf.get("Available balance"), unstakedBalance);
assertEquals(detailsBalanceOf.get("Unstaking balance"), BigInteger.ZERO);

//unstake some tokens
BigInteger remainingStake = amountToStake.divide(BigInteger.TWO);
BigInteger unstakeAmount = amountToStake.subtract(remainingStake);
balnScore.stake(remainingStake);

detailsBalanceOf = balnScore.detailsBalanceOf(Address.fromString(owner.getAddress().toString()));

// assert if balance is unstaked or not.
assertEquals(detailsBalanceOf.get("Staked balance"), remainingStake);
assertEquals(detailsBalanceOf.get("Available balance"), unstakedBalance);
assertEquals(detailsBalanceOf.get("Unstaking balance"), unstakeAmount);

BigInteger totalBalance = balnScore.totalStakedBalance();
// assert totalStakedBalance
assertEquals(amountToStake.divide(BigInteger.TWO), totalBalance);

// unstake completely

// wait for few days
balanced.increaseDay(4);
balanced.syncDistributions();

// unstake completely
balnScore.stake(BigInteger.ZERO);

detailsBalanceOf = balnScore.detailsBalanceOf(Address.fromString(owner.getAddress().toString()));

// assert if balance is unstaked or not.
assertEquals(detailsBalanceOf.get("Staked balance"), BigInteger.ZERO);
assertEquals(detailsBalanceOf.get("Unstaking balance"), amountToStake);
}

@Test
@Order(3)
void mint() {
Expand Down
Loading

0 comments on commit b3cf4d2

Please sign in to comment.