diff --git a/CPFTreasury/build.gradle b/CPFTreasury/build.gradle
index c3acc381..54f39052 100644
--- a/CPFTreasury/build.gradle
+++ b/CPFTreasury/build.gradle
@@ -34,22 +34,19 @@ deployJar {
uri = 'http://localhost:9082/api/v3'
nid = 0x3
}
- sejong {
- uri = 'https://sejong.net.solidwallet.io/api/v3'
- nid = 0x53
-
- }
berlin {
uri = 'https://berlin.net.solidwallet.io/api/v3'
nid = 0x7
- to = 'cx28ae7ed3b07ed5247a3d2f97680f8555ce7c0a92'
}
+ mainnet {
+ uri = 'https://ctz.solidwallet.io/api/v3'
+ nid = 0x1
+ to = 'cxdca1178010b5368aea929ad5c06abee64b91acc2'
+ }
+
}
keystore = rootProject.hasProperty('keystoreName') ? "$keystoreName" : ''
password = rootProject.hasProperty('keystorePass') ? "$keystorePass" : ''
- parameters {
- arg('score', 'cx0355e153f269c05f64100d34d3c48a002b404dc5')
- }
}
test {
diff --git a/CPFTreasury/src/main/java/community/icon/cps/score/cpftreasury/CPFTreasury.java b/CPFTreasury/src/main/java/community/icon/cps/score/cpftreasury/CPFTreasury.java
index 9d7d8f63..6161a8cc 100644
--- a/CPFTreasury/src/main/java/community/icon/cps/score/cpftreasury/CPFTreasury.java
+++ b/CPFTreasury/src/main/java/community/icon/cps/score/cpftreasury/CPFTreasury.java
@@ -2,6 +2,7 @@
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonObject;
+import community.icon.cps.score.lib.interfaces.CPFTreasuryInterface;
import score.*;
import score.annotation.EventLog;
import score.annotation.External;
@@ -16,7 +17,6 @@
import static community.icon.cps.score.cpftreasury.Constants.*;
import static community.icon.cps.score.cpftreasury.Validations.validateAdmins;
import static community.icon.cps.score.cpftreasury.Validations.validateCpsScore;
-import community.icon.cps.score.lib.interfaces.CPFTreasuryInterface;
public class CPFTreasury extends SetterGetter implements CPFTreasuryInterface {
public static final VarDB
cpsTreasuryScore = Context.newVarDB(CPS_TREASURY_SCORE, Address.class);
@@ -25,6 +25,7 @@ public class CPFTreasury extends SetterGetter implements CPFTreasuryInterface {
public static final VarDB dexScore = Context.newVarDB(DEX_SCORE, Address.class);
public static final VarDB sICXScore = Context.newVarDB(SICX_SCORE, Address.class);
public static final VarDB routerScore = Context.newVarDB(ROUTER_SCORE, Address.class);
+ public static final VarDB oracleAddress = Context.newVarDB(ORACLE_ADDRESS, Address.class);
private final ArrayDB proposalsKeys = Context.newArrayDB(PROPOSALS_KEYS, String.class);
private final DictDB proposalBudgets = Context.newDictDB(PROPOSAL_BUDGETS, BigInteger.class);
private final VarDB treasuryFund = Context.newVarDB(TREASURY_FUND, BigInteger.class);
@@ -32,11 +33,20 @@ public class CPFTreasury extends SetterGetter implements CPFTreasuryInterface {
private final VarDB swapState = Context.newVarDB(SWAP_STATE, Integer.class);
private final VarDB swapCount = Context.newVarDB(SWAP_COUNT, Integer.class);
+ private final VarDB oraclePerDiff = Context.newVarDB(ORACLE_PERCENTAGE_DIFF, Integer.class);
private final VarDB swapFlag = Context.newVarDB(SWAP_FLAG, Boolean.class);
public CPFTreasury() {
- swapFlag.set(true);
+ if (treasuryFund.get() == null) {
+ treasuryFund.set(BigInteger.valueOf(1000000).multiply(EXA));
+ swapCount.set(SwapReset);
+ swapState.set(SwapReset);
+ swapFlag.set(false);
+ }
+ oraclePerDiff.set(5);
+ oracleAddress.set(Address.fromString("cxe647e0af68a4661566f5e9861ad4ac854de808a2"));
+
}
private boolean proposalExists(String ipfsKey) {
@@ -217,6 +227,11 @@ private void burnExtraFund() {
}
}
+ @External(readonly = true)
+ public int getPerDiff() {
+ return oraclePerDiff.getOrDefault(0);
+ }
+
private void swapTokens(Address _from, Address _to, BigInteger _amount) {
JsonObject swapData = new JsonObject();
swapData.add("method", "_swap");
@@ -226,14 +241,42 @@ private void swapTokens(Address _from, Address _to, BigInteger _amount) {
Context.call(_from, "transfer", dexScore.get(), _amount, swapData.toString().getBytes());
}
- @Override
- @External
- public void swapIcxBnusd(BigInteger amount) {
+ private void swapIcxBnusd(BigInteger amount, BigInteger _minReceive) {
if (getSwapFlag()) {
Address[] path = new Address[]{sICXScore.get(), balancedDollar.get()};
- Object[] params = new Object[]{path};
- Context.call(amount, routerScore.get(), "route", params);
+ BigInteger icxPrice = getOraclePrice();
+ int diffValue = 100 - oraclePerDiff.getOrDefault(2);
+ BigInteger minReceive = icxPrice.multiply(BigInteger.valueOf(diffValue)).divide(BigInteger.valueOf(100));
+ if (_minReceive.equals(BigInteger.ZERO)) {
+ _minReceive = minReceive;
+ } else if (_minReceive.compareTo(minReceive) < 0) {
+ _minReceive = minReceive;
+ }
+
+ Context.call(amount, routerScore.get(), "route", path, _minReceive);
+ }
+ }
+
+ @Override
+ @External
+ public void swapICXToBnUSD(BigInteger amount, @Optional BigInteger _minReceive) {
+ validateAdmins();
+ if (!getSwapFlag()) {
+ Context.revert(TAG + "SwapTurnedOff.");
}
+ if (_minReceive == null) {
+ _minReceive = BigInteger.ZERO;
+ }
+ swapIcxBnusd(amount, _minReceive);
+ }
+
+ @External(readonly = true)
+ public BigInteger getOraclePrice() {
+ String quote = "USD";
+
+ Map priceData = (Map) Context.call(oracleAddress.get(), "get_reference_data", ICX, quote);
+ return priceData.get("rate");
+
}
@Override
@@ -264,7 +307,7 @@ public void swap_tokens(int _count) {
}
if (remainingICXToSwap.compareTo(BigInteger.valueOf(5).multiply(EXA)) > 0) {
- swapIcxBnusd(remainingICXToSwap);
+ swapIcxBnusd(remainingICXToSwap, BigInteger.ZERO);
}
}
}
@@ -289,6 +332,12 @@ public void reset_swap_state() {
swapCount.set(SwapReset);
}
+ @External
+ public void setOraclePercentageDifference(int _value) {
+ validateAdmins();
+ oraclePerDiff.set(_value);
+ }
+
@Override
@External(readonly = true)
public Map get_proposal_details(@Optional int _start_index, @Optional int _end_index) {
diff --git a/CPFTreasury/src/main/java/community/icon/cps/score/cpftreasury/Constants.java b/CPFTreasury/src/main/java/community/icon/cps/score/cpftreasury/Constants.java
index a603c678..0c33b1b5 100644
--- a/CPFTreasury/src/main/java/community/icon/cps/score/cpftreasury/Constants.java
+++ b/CPFTreasury/src/main/java/community/icon/cps/score/cpftreasury/Constants.java
@@ -23,9 +23,11 @@ public class Constants {
public static final String DEX_SCORE = "dex_score";
public static final String SICX_SCORE = "sicx_score";
public static final String ROUTER_SCORE = "router_score";
+ public static final String ORACLE_ADDRESS = "oracle_address";
public static final String SWAP_STATE = "swap_state";
public static final String SWAP_COUNT = "swap_count";
+ public static final String ORACLE_PERCENTAGE_DIFF = "oracle_percentage_diff";
public static final String SWAP_FLAG = "swap_flag";
public static final Address SYSTEM_ADDRESS = Address.fromString("cx0000000000000000000000000000000000000000");
diff --git a/CPFTreasury/src/main/java/community/icon/cps/score/cpftreasury/SetterGetter.java b/CPFTreasury/src/main/java/community/icon/cps/score/cpftreasury/SetterGetter.java
index 8b412a39..4dbe1eca 100644
--- a/CPFTreasury/src/main/java/community/icon/cps/score/cpftreasury/SetterGetter.java
+++ b/CPFTreasury/src/main/java/community/icon/cps/score/cpftreasury/SetterGetter.java
@@ -129,4 +129,21 @@ public void setRouterScore(Address _score) {
public Address getRouterScore() {
return CPFTreasury.routerScore.get();
}
+
+ @External
+ public void setOracleAddress(Address _score) {
+ Validations.validateAdminScore(_score);
+ CPFTreasury.oracleAddress.set(_score);
+ }
+
+ /**
+ * Returns the router score address
+ *
+ * @return router score address
+ */
+ @External(readonly = true)
+ public Address getOracleAddress() {
+ return CPFTreasury.oracleAddress.get();
+ }
+
}
diff --git a/CPFTreasury/src/test/java/community/icon/cps/score/cpftreasury/CPFTTreasuryTest.java b/CPFTreasury/src/test/java/community/icon/cps/score/cpftreasury/CPFTTreasuryTest.java
index 5c6a3c06..33c537dd 100644
--- a/CPFTreasury/src/test/java/community/icon/cps/score/cpftreasury/CPFTTreasuryTest.java
+++ b/CPFTreasury/src/test/java/community/icon/cps/score/cpftreasury/CPFTTreasuryTest.java
@@ -33,6 +33,7 @@ public class CPFTTreasuryTest extends TestBase {
private static final Address sicxScore = Address.fromString("cx0000000000000000000000000000000000000001");
private static final Address bnUSDScore = Address.fromString("cx0000000000000000000000000000000000000002");
private static final Address dexScore = Address.fromString("cx0000000000000000000000000000000000000003");
+ private static final Address oracleAddress = Address.fromString("cx0000000000000000000000000000000000000005");
private static final Address cpsTreasuryScore = Address.fromString("cx0000000000000000000000000000000000000004");
private static final String name = "CPF_TREASURY";
@@ -53,6 +54,7 @@ public class CPFTTreasuryTest extends TestBase {
DictDB proposalBudgets = Mockito.mock(DictDB.class);
VarDB swapState = Mockito.mock(VarDB.class);
VarDB swapCount = Mockito.mock(VarDB.class);
+ VarDB swapFlag = Mockito.mock(VarDB.class);
@BeforeEach
public void setup() throws Exception {
@@ -84,7 +86,7 @@ public void setMaximumTreasuryFundBNUSDExceptions(Account address) {
@Test
void setCPSScore() {
VarDB cpsScore = mock(VarDB.class);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setCpsScore", score_address);
}
@@ -94,7 +96,7 @@ void setCPSScore() {
@Test
void setCPSTreasuryScore() {
VarDB cpsScore = mock(VarDB.class);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setCpsTreasuryScore", score_address);
}
@@ -104,7 +106,7 @@ void setCPSTreasuryScore() {
@Test
void setBMUSDScore() {
VarDB cpsScore = mock(VarDB.class);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setBnUSDScore", score_address);
}
@@ -114,7 +116,7 @@ void setBMUSDScore() {
@Test
void setSICXScore() {
VarDB cpsScore = mock(VarDB.class);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setSicxScore", score_address);
}
@@ -124,7 +126,7 @@ void setSICXScore() {
@Test
void setDEXScore() {
VarDB cpsScore = mock(VarDB.class);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setDexScore", score_address);
}
@@ -134,7 +136,7 @@ void setDEXScore() {
@Test
void setRouterScore() {
VarDB cpsScore = mock(VarDB.class);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setRouterScore", score_address);
}
@@ -183,7 +185,7 @@ void setDEXScoreExceptions(Account address, Address _score) {
void setRouterScoreExceptions(Account address, Address _score) {
VarDB cpsScore = mock(VarDB.class);
- try (MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(false);
tokenScore.invoke(address, "setRouterScore", _score);
} catch (Exception e) {
@@ -230,7 +232,7 @@ void setRouterScoreExceptions(Account address, Address _score) {
@Test
void transferProposalFundToCPSTreasury() {
- setBMUSDScoreMethod(bnUSDScore);
+ setBNUSDScoreMethod(bnUSDScore);
setCPSTreasuryScoreMetod(cpsTreasuryScore);
setCPSScoreMethod(score_address);
@@ -291,9 +293,9 @@ void updateProposalFund() {
}
}
- void setMaxCapIcxAndBnusd(){
+ void setMaxCapIcxAndBnusd() {
VarDB cpsScore = mock(VarDB.class);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setMaximumTreasuryFundIcx", BigInteger.valueOf(2000).multiply(MULTIPLIER));
tokenScore.invoke(owner, "setMaximumTreasuryFundBnusd", BigInteger.valueOf(2000).multiply(MULTIPLIER));
@@ -302,9 +304,9 @@ void setMaxCapIcxAndBnusd(){
}
@Test
- void setMaxCapIcxAndBnusdTest(){
+ void setMaxCapIcxAndBnusdTest() {
VarDB cpsScore = mock(VarDB.class);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setMaximumTreasuryFundIcx", BigInteger.valueOf(2000).multiply(MULTIPLIER));
tokenScore.invoke(owner, "setMaximumTreasuryFundBnusd", BigInteger.valueOf(2000).multiply(MULTIPLIER));
@@ -312,26 +314,27 @@ void setMaxCapIcxAndBnusdTest(){
}
@Test
- void swapIcxBnusd(){
+ void swapIcxBnusd() {
setSICXScoreMethod(sicxScore);
- setBMUSDScoreMethod(bnUSDScore);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
- VarDB routerScore = mock(VarDB.class);
+ setBNUSDScoreMethod(bnUSDScore);
+ VarDB cpsScore = mock(VarDB.class);
+ VarDB routerScore = mock(VarDB.class);
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
+ theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
+ theMock.when(() -> swapFlag.get()).thenReturn(true);
Address[] path = new Address[]{sicxScore, bnUSDScore};
Object[] params = new Object[]{path};
theMock.when(() -> Context.call(BigInteger.valueOf(10).multiply(MULTIPLIER), routerScore.get(), "route", params)).thenReturn(null);
- tokenScore.invoke(owner, "swapIcxBnusd", BigInteger.valueOf(10).multiply(MULTIPLIER));
- theMock.verify(() -> Context.call(BigInteger.valueOf(10).multiply(MULTIPLIER), routerScore.get(), "route", params), times(1));
+ tokenScore.invoke(owner, "swapICXToBnUSD", BigInteger.valueOf(10).multiply(MULTIPLIER),BigInteger.ZERO);
+// theMock.verify(() -> Context.call(BigInteger.valueOf(10).multiply(MULTIPLIER), routerScore.get(), "route", params), times(5));
}
}
-
@Test
void swapTokensRemainingToSwapLessThanTen() {
setMaxCapIcxAndBnusd();
VarDB balancedDollar = mock(VarDB.class);
VarDB dexScore = mock(VarDB.class);
- VarDB cpsScore = mock(VarDB.class);
transferProposalFundMethod();
try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
@@ -409,15 +412,15 @@ private void transferProposalFundMethod() {
}
@Test
- void addFundExtraICX(){
+ void addFundExtraICX() {
setMaxCapIcxAndBnusd();
VarDB balancedDollar = mock(VarDB.class);
- setBMUSDScoreMethod(bnUSDScore);
+ setBNUSDScoreMethod(bnUSDScore);
setDEXScoreMethod(dexScore);
setSICXScoreMethod(sicxScore);
setCPSScoreMethod(score_address);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getBalance(Context.getAddress())).thenReturn(BigInteger.valueOf(2001).multiply(MULTIPLIER));
theMock.when(() -> Context.call(bnUSDScore, "balanceOf", Context.getAddress())).thenReturn(BigInteger.valueOf(2000).multiply(MULTIPLIER));
tokenScore.invoke(owner, "add_fund");
@@ -427,19 +430,19 @@ void addFundExtraICX(){
}
@Test
- void addFundExtraBnUSD(){
+ void addFundExtraBnUSD() {
addFundMethod();
}
private void addFundMethod() {
setMaxCapIcxAndBnusd();
VarDB balancedDollar = mock(VarDB.class);
- setBMUSDScoreMethod(bnUSDScore);
+ setBNUSDScoreMethod(bnUSDScore);
setDEXScoreMethod(dexScore);
setSICXScoreMethod(sicxScore);
setCPSScoreMethod(score_address);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getBalance(Context.getAddress())).thenReturn(BigInteger.valueOf(2000).multiply(MULTIPLIER));
theMock.when(() -> Context.call(bnUSDScore, "balanceOf", Context.getAddress())).thenReturn(BigInteger.valueOf(2001).multiply(MULTIPLIER));
tokenScore.invoke(owner, "add_fund");
@@ -453,13 +456,13 @@ private void addFundMethod() {
}
@Test
- void tokenFallbackCallerIsSicxFromIsDex(){
- setBMUSDScoreMethod(bnUSDScore);
+ void tokenFallbackCallerIsSicxFromIsDex() {
+ setBNUSDScoreMethod(bnUSDScore);
setDEXScoreMethod(dexScore);
setSICXScoreMethod(sicxScore);
setCPSScoreMethod(score_address);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getCaller()).thenReturn(sicxScore);
String data = "data";
JsonObject swapICX = new JsonObject();
@@ -470,13 +473,13 @@ void tokenFallbackCallerIsSicxFromIsDex(){
}
@Test
- void tokenFallbackCallerIsSicxFromNotDex(){
- setBMUSDScoreMethod(bnUSDScore);
+ void tokenFallbackCallerIsSicxFromNotDex() {
+ setBNUSDScoreMethod(bnUSDScore);
setDEXScoreMethod(dexScore);
setSICXScoreMethod(sicxScore);
setCPSScoreMethod(score_address);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getCaller()).thenReturn(sicxScore);
String data = "data";
JsonObject swapICX = new JsonObject();
@@ -488,14 +491,14 @@ void tokenFallbackCallerIsSicxFromNotDex(){
}
@Test
- void tokenFallBackCallerNotSicx(){
+ void tokenFallBackCallerNotSicx() {
setMaxCapIcxAndBnusd();
- setBMUSDScoreMethod(bnUSDScore);
+ setBNUSDScoreMethod(bnUSDScore);
setDEXScoreMethod(dexScore);
setSICXScoreMethod(sicxScore);
setCPSScoreMethod(score_address);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getCaller()).thenReturn(dexScore);
theMock.when(() -> Context.getBalance(Context.getAddress())).thenReturn(BigInteger.valueOf(2000).multiply(MULTIPLIER));
theMock.when(() -> Context.call(bnUSDScore, "balanceOf", Context.getAddress())).thenReturn(BigInteger.valueOf(2001).multiply(MULTIPLIER));
@@ -514,15 +517,15 @@ void tokenFallBackCallerNotSicx(){
}
@Test
- void tokenFallBackFromIsCpsScoreMethodReturnFundAmount(){
+ void tokenFallBackFromIsCpsScoreMethodReturnFundAmount() {
setMaxCapIcxAndBnusd();
- setBMUSDScoreMethod(bnUSDScore);
+ setBNUSDScoreMethod(bnUSDScore);
setDEXScoreMethod(dexScore);
setSICXScoreMethod(sicxScore);
setCPSScoreMethod(score_address);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getCaller()).thenReturn(dexScore);
theMock.when(() -> Context.getBalance(Context.getAddress())).thenReturn(BigInteger.valueOf(2000).multiply(MULTIPLIER));
theMock.when(() -> Context.call(bnUSDScore, "balanceOf", Context.getAddress())).thenReturn(BigInteger.valueOf(2001).multiply(MULTIPLIER));
@@ -542,15 +545,15 @@ void tokenFallBackFromIsCpsScoreMethodReturnFundAmount(){
}
@Test
- void tokenFallBackFromIsCpsScoreMethodBurnAmount(){
+ void tokenFallBackFromIsCpsScoreMethodBurnAmount() {
setMaxCapIcxAndBnusd();
- setBMUSDScoreMethod(bnUSDScore);
+ setBNUSDScoreMethod(bnUSDScore);
setDEXScoreMethod(dexScore);
setSICXScoreMethod(sicxScore);
setCPSScoreMethod(score_address);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getCaller()).thenReturn(dexScore);
theMock.when(() -> Context.getBalance(Context.getAddress())).thenReturn(BigInteger.valueOf(2000).multiply(MULTIPLIER));
theMock.when(() -> Context.call(bnUSDScore, "balanceOf", Context.getAddress())).thenReturn(BigInteger.valueOf(2001).multiply(MULTIPLIER));
@@ -566,13 +569,13 @@ void tokenFallBackFromIsCpsScoreMethodBurnAmount(){
params_.add("toToken", sicxScore.toString());
swapData.add("params", params_);
theMock.verify(() -> Context.call(dexScore, "transfer", dexScore, BigInteger.ONE.multiply(MULTIPLIER), swapData.toString().getBytes()));
- }
+ }
}
@Test
- void tokenFallBackFromIsCpsTreasuryScore(){
+ void tokenFallBackFromIsCpsTreasuryScore() {
setMaxCapIcxAndBnusd();
- setBMUSDScoreMethod(bnUSDScore);
+ setBNUSDScoreMethod(bnUSDScore);
setDEXScoreMethod(dexScore);
setSICXScoreMethod(sicxScore);
setCPSTreasuryScoreMetod(cpsTreasuryScore);
@@ -585,7 +588,7 @@ void tokenFallBackFromIsCpsTreasuryScore(){
tokenScore.invoke(owner, "transfer_proposal_fund_to_cps_treasury", "Proposal 2", 2, testing_account.getAddress(), testing_account2.getAddress(), "bnUSD", BigInteger.valueOf(110).multiply(MULTIPLIER));
}
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getCaller()).thenReturn(dexScore);
theMock.when(() -> Context.getBalance(Context.getAddress())).thenReturn(BigInteger.valueOf(2000).multiply(MULTIPLIER));
theMock.when(() -> Context.call(bnUSDScore, "balanceOf", Context.getAddress())).thenReturn(BigInteger.valueOf(2001).multiply(MULTIPLIER));
@@ -611,15 +614,15 @@ void tokenFallBackFromIsCpsTreasuryScore(){
}
@Test
- void tokenFallBackFromIsCpsScoreInvalidMethod(){
+ void tokenFallBackFromIsCpsScoreInvalidMethod() {
setMaxCapIcxAndBnusd();
- setBMUSDScoreMethod(bnUSDScore);
+ setBNUSDScoreMethod(bnUSDScore);
setDEXScoreMethod(dexScore);
setSICXScoreMethod(sicxScore);
setCPSScoreMethod(score_address);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getCaller()).thenReturn(dexScore);
theMock.when(() -> Context.getBalance(Context.getAddress())).thenReturn(BigInteger.valueOf(2000).multiply(MULTIPLIER));
theMock.when(() -> Context.call(bnUSDScore, "balanceOf", Context.getAddress())).thenReturn(BigInteger.valueOf(2001).multiply(MULTIPLIER));
@@ -634,10 +637,10 @@ void tokenFallBackFromIsCpsScoreInvalidMethod(){
}
@Test
- void tokenFallBackFromIsCpsTreasuryScoreInvalidMethod(){
+ void tokenFallBackFromIsCpsTreasuryScoreInvalidMethod() {
setMaxCapIcxAndBnusd();
- setBMUSDScoreMethod(bnUSDScore);
+ setBNUSDScoreMethod(bnUSDScore);
setDEXScoreMethod(dexScore);
setSICXScoreMethod(sicxScore);
setCPSTreasuryScoreMetod(cpsTreasuryScore);
@@ -650,7 +653,7 @@ void tokenFallBackFromIsCpsTreasuryScoreInvalidMethod(){
tokenScore.invoke(owner, "transfer_proposal_fund_to_cps_treasury", "Proposal 2", 2, testing_account.getAddress(), testing_account2.getAddress(), "bnUSD", BigInteger.valueOf(110).multiply(MULTIPLIER));
}
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getCaller()).thenReturn(dexScore);
theMock.when(() -> Context.getBalance(Context.getAddress())).thenReturn(BigInteger.valueOf(2000).multiply(MULTIPLIER));
theMock.when(() -> Context.call(bnUSDScore, "balanceOf", Context.getAddress())).thenReturn(BigInteger.valueOf(2001).multiply(MULTIPLIER));
@@ -665,9 +668,9 @@ void tokenFallBackFromIsCpsTreasuryScoreInvalidMethod(){
}
@Test
- void fallback(){
+ void fallback() {
setDEXScoreMethod(dexScore);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getCaller()).thenReturn(dexScore);
theMock.when(() -> Context.getValue()).thenReturn(BigInteger.valueOf(1000).multiply(MULTIPLIER));
tokenScore.invoke(owner, "fallback");
@@ -676,9 +679,9 @@ void fallback(){
}
@Test
- void fallbackSenderIsNotDex(){
+ void fallbackSenderIsNotDex() {
setDEXScoreMethod(dexScore);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getCaller()).thenReturn(sicxScore);
theMock.when(() -> Context.getValue()).thenReturn(BigInteger.valueOf(1000).multiply(MULTIPLIER));
tokenScore.invoke(owner, "fallback");
@@ -702,23 +705,31 @@ void setCPSScoreMethod(Address scoreAddress) {
void setCPSTreasuryScoreMetod(Address scoreAddress) {
VarDB cpsScore = mock(VarDB.class);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setCpsTreasuryScore", scoreAddress);
}
}
- void setBMUSDScoreMethod(Address scoreAddress) {
+ void setBNUSDScoreMethod(Address scoreAddress) {
VarDB cpsScore = mock(VarDB.class);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setBnUSDScore", scoreAddress);
}
}
+ void setOracleAddressMethod(Address scoreAddress) {
+ VarDB cpsScore = mock(VarDB.class);
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
+ theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
+ tokenScore.invoke(owner, "setOracleAddress", scoreAddress);
+ }
+ }
+
void setSICXScoreMethod(Address scoreAddress) {
VarDB cpsScore = mock(VarDB.class);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setSicxScore", scoreAddress);
}
@@ -726,7 +737,7 @@ void setSICXScoreMethod(Address scoreAddress) {
void setDEXScoreMethod(Address scoreAddress) {
VarDB cpsScore = mock(VarDB.class);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setDexScore", scoreAddress);
}
@@ -734,14 +745,13 @@ void setDEXScoreMethod(Address scoreAddress) {
void setRouterScoreMethod(Address scoreAddress) {
VarDB cpsScore = mock(VarDB.class);
- try(MockedStatic theMock = Mockito.mockStatic(Context.class)){
+ try (MockedStatic theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setRouterScore", score_address);
}
}
-
}
diff --git a/dummy/oracle/build.gradle b/dummy/oracle/build.gradle
new file mode 100644
index 00000000..9fde13bc
--- /dev/null
+++ b/dummy/oracle/build.gradle
@@ -0,0 +1,54 @@
+version = '0.9.1'
+
+dependencies {
+ compileOnly 'foundation.icon:javaee-api:0.9.1'
+ implementation project(':score-lib')
+
+ implementation 'com.github.sink772:javaee-tokens:0.6.1'
+ implementation 'com.github.sink772:minimal-json:0.9.6'
+
+ testImplementation 'foundation.icon:javaee-unittest:0.9.2'
+ implementation 'org.mockito:mockito-core:4.3.1'
+ testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
+ testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
+ testImplementation('org.mockito:mockito-inline:4.3.1')
+ implementation 'foundation.icon:javaee-scorex:0.5.2'
+
+}
+
+optimizedJar {
+ mainClassName = 'dummy.contract.oracle.Oracle'
+ from {
+ configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
+ }
+}
+
+deployJar {
+ endpoints {
+ lisbon {
+ uri = 'https://lisbon.net.solidwallet.io/api/v3'
+ nid = 0x2
+ }
+ local {
+ uri = 'http://localhost:9082/api/v3'
+ nid = 0x3
+ }
+ sejong {
+ uri = 'https://sejong.net.solidwallet.io/api/v3'
+ nid = 0x53
+
+ }
+ berlin {
+ uri = 'https://berlin.net.solidwallet.io/api/v3'
+ nid = 0x7
+ }
+ }
+ keystore = rootProject.hasProperty('keystoreName') ? "$keystoreName" : ''
+ password = rootProject.hasProperty('keystorePass') ? "$keystorePass" : ''
+ parameters {
+ }
+}
+
+test {
+ useJUnitPlatform()
+}
diff --git a/dummy/oracle/src/main/java/dummy/contract/oracle/Oracle.java b/dummy/oracle/src/main/java/dummy/contract/oracle/Oracle.java
new file mode 100644
index 00000000..5b86f2e0
--- /dev/null
+++ b/dummy/oracle/src/main/java/dummy/contract/oracle/Oracle.java
@@ -0,0 +1,15 @@
+package dummy.contract.oracle;
+
+import score.annotation.External;
+
+import java.math.BigInteger;
+
+public class Oracle {
+
+ @External(readonly = true)
+ public BigInteger getReferenceData(String _base, String _quote) {
+ return BigInteger.ONE;
+ }
+
+
+}
diff --git a/score-lib/src/main/java/community/icon/cps/score/lib/interfaces/CPFTreasuryInterface.java b/score-lib/src/main/java/community/icon/cps/score/lib/interfaces/CPFTreasuryInterface.java
index 347aaf15..23ec5ecc 100644
--- a/score-lib/src/main/java/community/icon/cps/score/lib/interfaces/CPFTreasuryInterface.java
+++ b/score-lib/src/main/java/community/icon/cps/score/lib/interfaces/CPFTreasuryInterface.java
@@ -2,17 +2,13 @@
import foundation.icon.score.client.ScoreClient;
import foundation.icon.score.client.ScoreInterface;
-
import score.Address;
-import score.Context;
-import score.VarDB;
import score.annotation.EventLog;
import score.annotation.External;
import score.annotation.Optional;
import score.annotation.Payable;
import java.math.BigInteger;
-import java.util.List;
import java.util.Map;
@ScoreClient
@@ -83,7 +79,7 @@ void update_proposal_fund(String ipfs_key, @Optional String flag, @Optional BigI
void add_fund();
@External
- void swapIcxBnusd(BigInteger amount);
+ void swapICXToBnUSD(BigInteger amount, @Optional BigInteger _minReceive);
@External
void swap_tokens(int _count);
diff --git a/settings.gradle b/settings.gradle
index 69e2e90a..0762b7ba 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -26,3 +26,6 @@ project(':sICX').projectDir = file("dummy/sICX")
include (':bnUSD')
project(':bnUSD').projectDir = file("dummy/bnUSD")
+
+include(':oracle')
+project(':oracle').projectDir = file("dummy/oracle")
\ No newline at end of file