From b5092016c9e385cac08cc28bc763fc2984c0fe9f Mon Sep 17 00:00:00 2001 From: AntonAndell Date: Mon, 24 Jun 2024 10:03:14 +0200 Subject: [PATCH 1/2] fix: Make ToAddress in routeAction nullable --- .../score/core/router/RouterTest.java | 23 +++++++++++++++++++ .../score/lib/structs/RouteAction.java | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/core-contracts/Router/src/test/java/network/balanced/score/core/router/RouterTest.java b/core-contracts/Router/src/test/java/network/balanced/score/core/router/RouterTest.java index 0a4be782b..1c249703d 100644 --- a/core-contracts/Router/src/test/java/network/balanced/score/core/router/RouterTest.java +++ b/core-contracts/Router/src/test/java/network/balanced/score/core/router/RouterTest.java @@ -584,6 +584,29 @@ void tokenFallback_swapStable() throws Exception { } } + @Test + void tokenFallback_swapToICX() throws Exception { + // Arrange + BigInteger USDToSwap = BigInteger.TEN.multiply(ICX); + BigInteger sICXResult = BigInteger.valueOf(100).multiply(ICX); + BigInteger ICXResult = BigInteger.valueOf(110).multiply(ICX); + List actions = new ArrayList<>(2); + actions.add(new RouteAction(SWAP, balanced.sicx.getAddress())); + actions.add(new RouteAction(SWAP, null)); + when(balanced.sicx.mock.balanceOf(routerScore.getAddress())).thenReturn(sICXResult); + routerScore.getAccount().addBalance("ICX", ICXResult); + + Account newReceiver = sm.createAccount(); + byte[] data = new RouteData("_swap", newReceiver.getAddress().toString(), BigInteger.ZERO, actions).toBytes(); + + // Act + routerScore.invoke(balanced.baln.account, "tokenFallback", owner.getAddress(), USDToSwap, + data); + + // Assert + assertEquals(ICXResult, newReceiver.getBalance()); + } + @Test void tokenFallback_swapStableWithoutOptField_AndMixedSwapTypes() throws Exception { // Arrange diff --git a/score-lib/src/main/java/network/balanced/score/lib/structs/RouteAction.java b/score-lib/src/main/java/network/balanced/score/lib/structs/RouteAction.java index fa40e3b4f..c2e7c5b98 100644 --- a/score-lib/src/main/java/network/balanced/score/lib/structs/RouteAction.java +++ b/score-lib/src/main/java/network/balanced/score/lib/structs/RouteAction.java @@ -25,7 +25,7 @@ public static RouteAction readObject(ObjectReader reader) { RouteAction obj = new RouteAction(); reader.beginList(); obj.action = reader.readInt(); - obj.toAddress = reader.readAddress(); + obj.toAddress = reader.readNullable(Address.class); reader.end(); return obj; } @@ -33,7 +33,7 @@ public static RouteAction readObject(ObjectReader reader) { public void writeObject(ObjectWriter writer) { writer.beginList(2); writer.write(this.action); - writer.write(this.toAddress); + writer.writeNullable(this.toAddress); writer.end(); } From e9aefb31e9255f2a1feb2bf841d8fb6bb50c79dc Mon Sep 17 00:00:00 2001 From: AntonAndell Date: Mon, 24 Jun 2024 10:24:29 +0200 Subject: [PATCH 2/2] update Router and xCall manager version --- .../main/java/network/balanced/score/lib/utils/Versions.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/score-lib/src/main/java/network/balanced/score/lib/utils/Versions.java b/score-lib/src/main/java/network/balanced/score/lib/utils/Versions.java index 6e1ece716..a376311e8 100644 --- a/score-lib/src/main/java/network/balanced/score/lib/utils/Versions.java +++ b/score-lib/src/main/java/network/balanced/score/lib/utils/Versions.java @@ -33,7 +33,7 @@ public class Versions { public final static String DEX = "v1.1.1"; public final static String GOVERNANCE = "v1.0.2"; public final static String REBALANCING = "v1.0.0"; - public final static String ROUTER = "v1.1.3"; + public final static String ROUTER = "v1.1.4"; public final static String STAKEDLP = "v1.0.1"; public final static String BOOSTED_BALN = "v1.1.0"; public final static String BRIBING = "v1.0.1"; @@ -45,7 +45,7 @@ public class Versions { public final static String SAVINGS = "v1.0.0"; public final static String TRICKLER = "v1.0.0"; - public final static String SPOKE_ASSET_MANAGER = "v1.0.0"; + public final static String SPOKE_ASSET_MANAGER = "v1.0.1"; public final static String SPOKE_XCALL_MANAGER = "v1.0.0"; public final static String SPOKE_BNUSD = "v1.0.0"; }