Skip to content

Commit

Permalink
chore: prep penalty paid
Browse files Browse the repository at this point in the history
  • Loading branch information
naneey committed Apr 10, 2024
1 parent d09eb5f commit bc2a119
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import static community.icon.cps.score.cpscore.utils.Constants.*;
import static community.icon.cps.score.test.AssertRevertedException.assertUserRevert;
import static community.icon.cps.score.test.integration.Environment.godClient;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.math.BigInteger;
Expand Down Expand Up @@ -67,6 +68,8 @@ public static void setup() throws Exception{
cpsClients.put(i,cps.customClient(privKey));

}
// ICX swap purpose
godClient._transfer(addressMap.get("dex"),BigInteger.valueOf(200).multiply(EXA),"transferICX to dex");

}

Expand Down Expand Up @@ -117,7 +120,6 @@ public void registerPrepExceptions(){
assertUserRevert(new UserRevertException(TAG+": P-Rep is already registered."),
() -> registeredPrep.cpsCore.registerPrep(),null);

// TODO: handle deny list
}

@DisplayName("unregister prep")
Expand Down Expand Up @@ -183,7 +185,7 @@ public void submitProposal(){
CPSCoreInterface.MilestonesAttributes milestonesAttributes3 = new CPSCoreInterface.MilestonesAttributes();
milestonesAttributes3.completionPeriod = 3;
milestonesAttributes3.budget = BigInteger.valueOf(20).multiply(ICX);
milestonesAttributes3.id = 3; // TODO: check if same id is sent
milestonesAttributes3.id = 3;

CPSCoreInterface.MilestonesAttributes[] milestonesAttributes =new CPSCoreInterface.MilestonesAttributes[]
{milestonesAttributes1, milestonesAttributes2,milestonesAttributes3};
Expand Down Expand Up @@ -258,7 +260,6 @@ public void voteProposal() throws InterruptedException {
assertEquals(toInt((String)proposalVote.get("total_voters")),7);
assertEquals(toInt((String)proposalVote.get("approve_voters")),7);
assertEquals(toInt((String)proposalVote.get("reject_voters")),0);
// TODO: approved votes does not match up
// assertEquals(toBigInt((String)proposalVote.get("approved_votes")),BigInteger.valueOf(9540000).multiply(ICX));
}

Expand Down Expand Up @@ -941,7 +942,6 @@ public void votePriority() {

}

// trying to Register by deny prep TODO
}


Expand Down Expand Up @@ -1002,19 +1002,19 @@ public void prepPayPenalty() {
bnUSDMint(prep.getAddress(), BigInteger.TWO.multiply(ICX));

byte[] data = penaltyByteArray("payPrepPenalty");
// TODO: pay the penalty
ownerClient.cpsCore.removeDenylistPreps();
// prep.bnUSD.transfer(addressMap.get("cpsCore"),penaltyAmount,data);
// ownerClient.cpsCore.removeDenylistPreps();

prep.bnUSD.transfer(addressMap.get("cpsCore"),penaltyAmount,data);

Map<String, BigInteger> prepData = loginPrep(prep.getAddress());
assertEquals(prepData, unregisteredPrepData());

Map<String, BigInteger> prepData = loginPrep(prep.getAddress());
assertEquals(prepData, votingPrepData());

prep.cpsCore.registerPrep();
Map<String, BigInteger> prepData2 = loginPrep(prep.getAddress());

assertEquals(prepData2, votingPrepData());
// prep.cpsCore.registerPrep();
// Map<String, BigInteger> prepData2 = loginPrep(prep.getAddress());
//
// assertEquals(prepData2, votingPrepData());
}


Expand Down Expand Up @@ -1738,6 +1738,13 @@ private Map<String,BigInteger> unregisteredPrepData(){
VOTING_PREP, BigInteger.ZERO);
}

private Map<String,BigInteger> normalPrepData(){
return Map.of(IS_PREP, BigInteger.ONE,
IS_REGISTERED, BigInteger.ZERO,
PAY_PENALTY, BigInteger.ZERO,
VOTING_PREP, BigInteger.ZERO);
}

private Map<String,BigInteger> votingPrepData(){
return Map.of(IS_PREP, BigInteger.ONE,
IS_REGISTERED, BigInteger.ONE,
Expand Down
17 changes: 17 additions & 0 deletions dummy/Dex/src/main/java/dummy/contract/dex/Dex.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Arrays;

import community.icon.cps.score.lib.interfaces.DexInterface;
import score.annotation.Payable;

public class Dex implements DexInterface {
private static final String TAG = "Balanced DEX";
Expand Down Expand Up @@ -45,6 +46,12 @@ public void Swap(BigInteger _id, Address _baseToken, Address _fromToken, Address
BigInteger _poolQuote, BigInteger _endingPrice, BigInteger _effectiveFillPrice) {
}


@Payable
public void fallback(){

}

@Override
@External
public void tokenFallback(Address _from, BigInteger _value, byte[] _data) {
Expand Down Expand Up @@ -72,6 +79,7 @@ public void tokenFallback(Address _from, BigInteger _value, byte[] _data) {

}
case "_swap": {
Context.println("the thus us called");

// Parse the slippage sent by the user in minimumReceive.
// If none is sent, use the maximum.
Expand All @@ -96,7 +104,12 @@ public void tokenFallback(Address _from, BigInteger _value, byte[] _data) {
Address toToken = Address.fromString(params.get("toToken").asString());

// Perform the swap
Context.println("from token "+ fromToken);
Context.println("from token "+ toToken);
Context.println("from "+ _from);
Context.println("receiver "+ receiver);
exchange(fromToken, toToken, _from, receiver, _value, minimumReceive);
Context.println("after the exchange ");

break;
}
Expand All @@ -123,7 +136,11 @@ void exchange(Address fromToken, Address toToken, Address sender,
}

// Send the trader their funds
Context.println("is it heree?");
Context.println("roe "+ toToken);
Context.println("roe "+ receiver);
Context.call(toToken, "transfer", receiver, value);
Context.println("lets check this " + Context.getAddress());

Swap(BigInteger.valueOf(0), fromToken, fromToken, toToken, sender, receiver, value, value,
BigInteger.valueOf(Context.getBlockTimestamp()), BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO
Expand Down

0 comments on commit bc2a119

Please sign in to comment.