From 7a326cf081e9b90fee7291c45009bc95185970fa Mon Sep 17 00:00:00 2001 From: sagar sapkota Date: Fri, 22 Nov 2024 13:07:47 +0545 Subject: [PATCH] NetworkAddress Improvements --- .../main/java/network/balanced/score/core/dex/AbstractDex.java | 2 +- .../src/main/java/network/balanced/score/core/dex/DexImpl.java | 2 +- .../balanced/score/core/dex/IRC31StandardSpokeLpToken.java | 2 +- .../test/java/network/balanced/score/core/dex/DexTestBase.java | 2 +- .../java/network/balanced/score/core/stakedlp/StakedLPImpl.java | 2 +- .../java/network/balanced/score/lib/utils/TokenTransfer.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/AbstractDex.java b/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/AbstractDex.java index 8556d1ebc..eefdbf0e6 100644 --- a/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/AbstractDex.java +++ b/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/AbstractDex.java @@ -264,7 +264,7 @@ public BigInteger getDeposit(Address _tokenAddress, Address _user) { @External(readonly = true) public BigInteger getDepositV2(Address _tokenAddress, String _user) { - NetworkAddress user = NetworkAddress.valueOf(_user); + NetworkAddress user = NetworkAddress.valueOf(_user, NATIVE_NID); return deposit.at(_tokenAddress).getOrDefault(user, BigInteger.ZERO); } diff --git a/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/DexImpl.java b/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/DexImpl.java index ca007853a..79ceee74e 100644 --- a/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/DexImpl.java +++ b/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/DexImpl.java @@ -340,7 +340,7 @@ public void xAdd(String from, String _baseToken, String _quoteToken, BigInteger checkStatus(); isValidPercent(_slippagePercentage.intValue()); - addInternal(NetworkAddress.parse(from), Address.fromString(_baseToken), Address.fromString(_quoteToken), _baseValue, _quoteValue, + addInternal(NetworkAddress.valueOf(from), Address.fromString(_baseToken), Address.fromString(_quoteToken), _baseValue, _quoteValue, _withdraw_unused, _slippagePercentage); } diff --git a/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/IRC31StandardSpokeLpToken.java b/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/IRC31StandardSpokeLpToken.java index c965fe45b..a4285670b 100644 --- a/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/IRC31StandardSpokeLpToken.java +++ b/core-contracts/Dex/src/main/java/network/balanced/score/core/dex/IRC31StandardSpokeLpToken.java @@ -36,7 +36,7 @@ public BigInteger balanceOf(Address _owner, BigInteger _id) { @External(readonly = true) public BigInteger xBalanceOf(String _owner, BigInteger _id) { - NetworkAddress address = NetworkAddress.valueOf(_owner); + NetworkAddress address = NetworkAddress.valueOf(_owner, NATIVE_NID); return DexDBVariables.balance.at(_id.intValue()).getOrDefault(address, BigInteger.ZERO); } diff --git a/core-contracts/Dex/src/test/java/network/balanced/score/core/dex/DexTestBase.java b/core-contracts/Dex/src/test/java/network/balanced/score/core/dex/DexTestBase.java index 9a4e5850d..e486e51d9 100644 --- a/core-contracts/Dex/src/test/java/network/balanced/score/core/dex/DexTestBase.java +++ b/core-contracts/Dex/src/test/java/network/balanced/score/core/dex/DexTestBase.java @@ -118,7 +118,7 @@ protected void xDepositTokenWithoutTo(String depositor, String to, Account token * */ protected void handleCallMessageWithOutProtocols(String from, byte[] data, String[] protocols ) { - NetworkAddress fromNetworkAddress = NetworkAddress.parse(from); + NetworkAddress fromNetworkAddress = NetworkAddress.valueOf(from); contextMock.when(() -> Context.call(eq(BalancedAddressManager.getXCallManager()), eq("verifyProtocols"), eq(fromNetworkAddress.net()), eq(protocols))).thenReturn(true); dexScore.invoke(xcallScore, "handleCallMessage", from, data, protocols); } diff --git a/core-contracts/StakedLP/src/main/java/network/balanced/score/core/stakedlp/StakedLPImpl.java b/core-contracts/StakedLP/src/main/java/network/balanced/score/core/stakedlp/StakedLPImpl.java index 8521a983f..4d3366ef5 100644 --- a/core-contracts/StakedLP/src/main/java/network/balanced/score/core/stakedlp/StakedLPImpl.java +++ b/core-contracts/StakedLP/src/main/java/network/balanced/score/core/stakedlp/StakedLPImpl.java @@ -130,7 +130,7 @@ public BigInteger balanceOf(Address _owner, BigInteger _id) { @External(readonly = true) public BigInteger xBalanceOf(String _owner, BigInteger _id) { - NetworkAddress owner = NetworkAddress.valueOf(_owner); + NetworkAddress owner = NetworkAddress.valueOf(_owner, NATIVE_NID); return poolStakedDetails.at(owner).getOrDefault(_id, BigInteger.ZERO); } diff --git a/score-lib/src/main/java/network/balanced/score/lib/utils/TokenTransfer.java b/score-lib/src/main/java/network/balanced/score/lib/utils/TokenTransfer.java index 09561e198..94b65b681 100644 --- a/score-lib/src/main/java/network/balanced/score/lib/utils/TokenTransfer.java +++ b/score-lib/src/main/java/network/balanced/score/lib/utils/TokenTransfer.java @@ -11,8 +11,8 @@ public class TokenTransfer { public static void transfer(Address token, String to, BigInteger amount, byte[] data){ - NetworkAddress toNetworkAddress = NetworkAddress.parse(to); String NATIVE_NID = (String) Context.call(BalancedAddressManager.getXCall(), "getNetworkId"); + NetworkAddress toNetworkAddress = NetworkAddress.valueOf(to, NATIVE_NID); if(!NATIVE_NID.equals(toNetworkAddress.net())) { if(canWithdraw(toNetworkAddress.net())) { String nativeAddress = (String) Context.call(BalancedAddressManager.getAssetManager(), "getNativeAssetAddress", token, toNetworkAddress.net());