Skip to content

Commit

Permalink
onIRC31Received ib lp transfer method, depositOfUser removed..
Browse files Browse the repository at this point in the history
  • Loading branch information
sagars committed Nov 22, 2024
1 parent e218850 commit 911856f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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) {
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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<String, DictDB<BigInteger, BigInteger>> snapshot) {
Context.require(_snapshot_id.compareTo(BigInteger.ZERO) >= 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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");
Expand Down Expand Up @@ -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<BigInteger> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 124 in core-contracts/Dex/src/main/java/network/balanced/score/core/dex/IRC31StandardSpokeLpToken.java

View check run for this annotation

Codecov / codecov/patch

core-contracts/Dex/src/main/java/network/balanced/score/core/dex/IRC31StandardSpokeLpToken.java#L124

Added line #L124 was not covered by tests
}else {
Context.call(contractAddress, "onXIRC31Received", _from.toString(), _from.toString(), _id, _value, dataBytes);

Check warning on line 126 in core-contracts/Dex/src/main/java/network/balanced/score/core/dex/IRC31StandardSpokeLpToken.java

View check run for this annotation

Codecov / codecov/patch

core-contracts/Dex/src/main/java/network/balanced/score/core/dex/IRC31StandardSpokeLpToken.java#L126

Added line #L126 was not covered by tests
}
}

Check warning on line 128 in core-contracts/Dex/src/main/java/network/balanced/score/core/dex/IRC31StandardSpokeLpToken.java

View check run for this annotation

Codecov / codecov/patch

core-contracts/Dex/src/main/java/network/balanced/score/core/dex/IRC31StandardSpokeLpToken.java#L128

Added line #L128 was not covered by tests

protected boolean isNative(NetworkAddress address) {
return address.net().equals(NATIVE_NID);

Check warning on line 131 in core-contracts/Dex/src/main/java/network/balanced/score/core/dex/IRC31StandardSpokeLpToken.java

View check run for this annotation

Codecov / codecov/patch

core-contracts/Dex/src/main/java/network/balanced/score/core/dex/IRC31StandardSpokeLpToken.java#L131

Added line #L131 was not covered by tests
}

boolean isLockingPool(Integer id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 911856f

Please sign in to comment.