From 911856fb0bf9fcf1a624ca7e90f0cc0a01dd04a0 Mon Sep 17 00:00:00 2001 From: sagar sapkota Date: Fri, 22 Nov 2024 11:14:22 +0545 Subject: [PATCH] onIRC31Received ib lp transfer method, depositOfUser removed.. --- .../score/core/dex/DexIntegrationTest.java | 4 ++-- .../balanced/score/core/dex/AbstractDex.java | 18 ------------------ .../balanced/score/core/dex/DexImpl.java | 11 ++--------- .../core/dex/IRC31StandardSpokeLpToken.java | 10 +++++++++- .../balanced/score/lib/interfaces/Dex.java | 2 -- 5 files changed, 13 insertions(+), 32 deletions(-) diff --git a/core-contracts/Dex/src/intTest/java/network/balanced/score/core/dex/DexIntegrationTest.java b/core-contracts/Dex/src/intTest/java/network/balanced/score/core/dex/DexIntegrationTest.java index 7cc52dbce..97dc444ae 100644 --- a/core-contracts/Dex/src/intTest/java/network/balanced/score/core/dex/DexIntegrationTest.java +++ b/core-contracts/Dex/src/intTest/java/network/balanced/score/core/dex/DexIntegrationTest.java @@ -223,11 +223,11 @@ void testWithdraw() { byte[] tokenDeposit = "{\"method\":\"_deposit\",\"params\":{\"none\":\"none\"}}".getBytes(); this.mintAndTransferTestTokens(tokenDeposit); BigInteger withdrawAMount = BigInteger.valueOf(50); - BigInteger balanceBeforeWithdraw = dexUserScoreClient.depositOfUser(userAddress, tokenAAddress); + BigInteger balanceBeforeWithdraw = dexUserScoreClient.getDeposit(userAddress, tokenAAddress); //withdraw test token dexUserScoreClient.withdraw(tokenAAddress, withdrawAMount); - BigInteger balanceAfterWithdraw = dexUserScoreClient.depositOfUser(userAddress, tokenAAddress); + BigInteger balanceAfterWithdraw = dexUserScoreClient.getDeposit(userAddress, tokenAAddress); assert balanceBeforeWithdraw.equals(balanceAfterWithdraw.add(withdrawAMount)); } 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 2f5ee1ac7..8556d1ebc 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 @@ -42,7 +42,6 @@ import static network.balanced.score.lib.utils.BalancedAddressManager.*; import static network.balanced.score.lib.utils.Check.onlyGovernance; import static network.balanced.score.lib.utils.Constants.*; -import static network.balanced.score.lib.utils.Math.pow; public abstract class AbstractDex extends IRC31StandardSpokeLpToken { @@ -97,10 +96,6 @@ public void RemoveV2(BigInteger _id, String _owner, BigInteger _value, BigIntege public void Deposit(Address _token, String _owner, BigInteger _value) { } -// @EventLog(indexed = 2) -// public void Withdraw(Address _token, Address _owner, BigInteger _value) { -// } - @EventLog(indexed = 2) public void Withdraw(Address _token, String _owner, BigInteger _value) { } @@ -500,10 +495,6 @@ public void delegate(PrepDelegations[] prepDelegations) { Context.call(getStaking(), "delegate", (Object) prepDelegations); } - private static BigInteger getPriceInUSD(String symbol) { - return (BigInteger) Context.call(getBalancedOracle(), "getLastPriceInUSD", symbol); - } - protected BigInteger getSicxRate() { return (BigInteger) Context.call(getStaking(), "getTodayRate"); } @@ -729,15 +720,6 @@ void swapIcx(Address sender, BigInteger value) { Context.transfer(sender, orderIcxValue); } - - private BigInteger getUnitValue(Address tokenAddress) { - if (tokenAddress == null) { - return EXA; - } else { - return pow(BigInteger.TEN, tokenPrecisions.get(tokenAddress).intValue()); - } - } - BigInteger snapshotValueAt(BigInteger _snapshot_id, BranchDB> snapshot) { Context.require(_snapshot_id.compareTo(BigInteger.ZERO) >= 0, 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 1b21ab10b..ca007853a 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 @@ -139,7 +139,7 @@ public void xTokenFallback(String _from, BigInteger _value, byte[] _data) { require(!unpackedData.equals(""), "Token Fallback: Data can't be empty"); JsonObject json = Json.parse(unpackedData).asObject(); String method = json.get("method").asString(); - Address fromToken = Context.getCaller(); + Address token = Context.getCaller(); require(_value.compareTo(BigInteger.ZERO) > 0, TAG + ": Invalid token transfer value"); @@ -149,7 +149,7 @@ public void xTokenFallback(String _from, BigInteger _value, byte[] _data) { if (params.get("address") != null) { to = params.get("address").asString(); } - deposit(fromToken, NetworkAddress.valueOf(to), _value); + deposit(token, NetworkAddress.valueOf(to), _value); } else { // If no supported method was sent, revert the transaction Context.revert(100, TAG + ": Unsupported method supplied"); @@ -264,13 +264,6 @@ private void _withdraw(NetworkAddress sender, Address _token, BigInteger _value) TokenTransfer.transfer(_token, sender.toString(), _value); } - @External(readonly = true) - public BigInteger depositOfUser(Address _owner, Address _token) { - NetworkAddress owner = new NetworkAddress(NATIVE_NID, _owner); - NetworkAddressDictDB depositDetails = deposit.at(_token); - return depositDetails.getOrDefault(owner, BigInteger.ZERO); - } - public void xRemove(String from, BigInteger id, BigInteger value, @Optional Boolean _withdraw) { NetworkAddress _from = NetworkAddress.valueOf(from); _remove(id, _from, value, _withdraw); 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 85833ea18..c965fe45b 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 @@ -120,7 +120,15 @@ void _transfer(NetworkAddress _from, NetworkAddress _to, BigInteger _value, Inte return; } - Context.call(contractAddress, "onXIRC31Received", _from.toString(), _from.toString(), _id, _value, dataBytes); + if(isNative(_from)){ + Context.call(contractAddress, "onIRC31Received", Address.fromString(_from.account()), Address.fromString(_from.account()), _id, _value, dataBytes); + }else { + Context.call(contractAddress, "onXIRC31Received", _from.toString(), _from.toString(), _id, _value, dataBytes); + } + } + + protected boolean isNative(NetworkAddress address) { + return address.net().equals(NATIVE_NID); } boolean isLockingPool(Integer id) { diff --git a/score-lib/src/main/java/network/balanced/score/lib/interfaces/Dex.java b/score-lib/src/main/java/network/balanced/score/lib/interfaces/Dex.java index f08ff4f9e..78eb9979d 100644 --- a/score-lib/src/main/java/network/balanced/score/lib/interfaces/Dex.java +++ b/score-lib/src/main/java/network/balanced/score/lib/interfaces/Dex.java @@ -207,7 +207,5 @@ void xAdd(String from, String _baseToken, String _quoteToken, BigInteger _baseVa @External void addLpAddresses(BigInteger _poolId, Address[] _addresses); - @External(readonly = true) - BigInteger depositOfUser(Address _owner, Address _token); }