Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a832ca7
cross chain lp functionalities and unit test
sagars Oct 2, 2024
3d20a79
Merge branch 'main' into feature/crosschain_lp
sagars Oct 3, 2024
24eed8e
integration test and fixes - crosschain lp feature
sagars Oct 8, 2024
39aaec5
integration test issues fixed
sagars Oct 23, 2024
ad6b8ac
Token transfer utility implementation, crossTransfer commented out
sagars Oct 26, 2024
1079d2f
Merge remote-tracking branch 'origin/feat/sicx-baln' into feat/crossc…
sagars Oct 27, 2024
558117e
test: all test pass including router update
sagars Oct 28, 2024
ea47433
Merge branch 'main' into feature/crosschain_lp
sagars Oct 29, 2024
eaa39ef
Fixes: review fixes
sagars Oct 29, 2024
dbcb461
Fix: review additional fixes, cleanups, formats
sagars Oct 30, 2024
1b20143
to param optional on xTokenFallback deposit, xWithdraw replaced with …
sagars Nov 6, 2024
fd54215
unit tests for optional to in xTokenFallback and xWithdraw on xAdd
sagars Nov 7, 2024
73adf70
fix: Address type changed to String type on xcall annotated methods
sagars Nov 15, 2024
3be7c9b
crosschain lp feature implementation guidance doc
sagars Nov 15, 2024
465d286
fallback method added to rewards and stakedLp, router tested
sagars Nov 18, 2024
102174f
fallback method removed from stakedLp contract
sagars Nov 19, 2024
14ad807
unused variables, imports and commented codes removed
sagars Nov 20, 2024
f792a5e
unused variables, imports and commented codes removed
sagars Nov 20, 2024
0973021
addressManagerMock static mock issue on TokenTransfer test is fixed
sagars Nov 21, 2024
e218850
test updates on xcall, transfer method merged in token class,exceptio…
sagars Nov 21, 2024
911856f
onIRC31Received ib lp transfer method, depositOfUser removed..
sagars Nov 22, 2024
68d6cbf
getDeposit method params position updated in dex inttest
sagars Nov 22, 2024
a00b28c
optional data on route methods - Router
sagars Nov 22, 2024
7a326cf
NetworkAddress Improvements
sagars Nov 22, 2024
1f487ca
NetworkAddress missed - fixed
sagars Nov 22, 2024
db53648
RouteData update to add data property, unit tests added for usdc staking
sagars Nov 26, 2024
4c2f87a
Merge branch 'main' into feat/usdc_staking
sagars Nov 29, 2024
c970764
re-fix the previous update
sagars Nov 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,11 @@ private void executeRoute(String _from, byte[] data) {
} else {
receiver = _from;
}

route(receiver, fromToken, routeData.actions, minimumReceive, EMPTY_DATA);
byte[] _data = EMPTY_DATA;
if(routeData.data!=null){
_data = routeData.data;
}
route(receiver, fromToken, routeData.actions, minimumReceive, _data);
}

private void jsonRoute(String _from, byte[] data) {
Expand Down Expand Up @@ -308,7 +311,11 @@ private void jsonRoute(String _from, byte[] data) {
}

Address fromToken = Context.getCaller();
route(receiver, fromToken, actions, minimumReceive, EMPTY_DATA);
byte[] _data = EMPTY_DATA;
if(params.get("data")!=null){
_data = params.get("data").asString().getBytes();
}
route(receiver, fromToken, actions, minimumReceive, _data);
}

@Payable
Expand All @@ -318,4 +325,4 @@ public void fallback() {
@EventLog(indexed = 1)
public void Route(Address from, BigInteger fromAmount, Address to, BigInteger toAmount) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@
import network.balanced.score.lib.structs.RouteData;
import network.balanced.score.lib.test.mock.MockBalanced;
import network.balanced.score.lib.test.mock.MockContract;
import network.balanced.score.lib.tokens.HubTokenImpl;
import network.balanced.score.lib.tokens.IRC2Base;
import network.balanced.score.lib.tokens.IRC2Mintable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import score.Address;
import score.Context;
import scorex.util.ArrayList;

import java.math.BigInteger;
Expand All @@ -44,11 +40,8 @@

import static network.balanced.score.core.router.RouterImpl.*;
import static network.balanced.score.lib.test.UnitTest.*;
import static network.balanced.score.lib.utils.Constants.EXA;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -182,14 +175,7 @@ void tokenFallback() throws Exception {
when(balanced.baln.mock.balanceOf(routerScore.getAddress())).thenReturn(BigInteger.TEN);
when(balanced.sicx.mock.balanceOf(routerScore.getAddress())).thenReturn(BigInteger.TEN);

// byte[] invalidPathWithSicxTerminalToken = tokenData("_swap", Map.of("path",
// new Object[]{balanced.baln.getAddress().toString(), null}));
// Executable nonSicxIcxTrade = () -> routerScore.invoke(sicxScore.account, "tokenFallback", owner.getAddress(),
// BigInteger.TEN, invalidPathWithSicxTerminalToken);
// expectedErrorMessage = "Reverted(0): " + TAG + ": Native swaps not available to icon from " + balanced.baln.getAddress();
// expectErrorMessage(nonSicxIcxTrade, expectedErrorMessage);
//
// resetInRoute();

Account newReceiver = sm.createAccount();
byte[] pathWithSicxTerminalToken = tokenData("_swap", Map.of("path",
new Object[]{sicxScore.getAddress().toString(), null}, "receiver",
Expand Down Expand Up @@ -501,7 +487,7 @@ void tokenFallback_swapStable() throws Exception {
}

Account newReceiver = sm.createAccount();
byte[] data = new RouteData("_swap", newReceiver.getAddress().toString(), BigInteger.ZERO, actions).toBytes();
byte[] data = new RouteData("_swap", newReceiver.getAddress().toString(), BigInteger.ZERO, actions, null).toBytes();

// Act
routerScore.invoke(balanced.baln.account, "tokenFallback", owner.getAddress(), balnToSwap,
Expand Down Expand Up @@ -531,7 +517,7 @@ void tokenFallback_swapToICX() throws Exception {
routerScore.getAccount().addBalance("ICX", ICXResult);

Account newReceiver = sm.createAccount();
byte[] data = new RouteData("_swap", newReceiver.getAddress().toString(), BigInteger.ZERO, actions).toBytes();
byte[] data = new RouteData("_swap", newReceiver.getAddress().toString(), BigInteger.ZERO, actions, null).toBytes();

// Act
routerScore.invoke(balanced.baln.account, "tokenFallback", owner.getAddress(), USDToSwap,
Expand Down Expand Up @@ -586,4 +572,51 @@ private void resetInRoute() {
// in Production this happens between each tx
((RouterImpl)routerScore.getInstance()).inRoute = false;
}

@Test
void stakeToSavingsWithJSONRoute(){
// Arrange
//baln as usdc
when(balanced.baln.mock.balanceOf(routerScore.getAddress())).thenReturn(BigInteger.TEN);
when(balanced.bnUSD.mock.balanceOf(routerScore.getAddress())).thenReturn(BigInteger.TEN);

String data = new String(tokenData("_lock", Map.of()));
Account newReceiver = balanced.savings.account;
byte[] pathWithUSDCBnUSD = tokenData("_swap", Map.of("path",
new Object[]{balanced.bnUSD.getAddress().toString()}, "receiver",
newReceiver.getAddress().toString(), "data", data));

// Act
routerScore.invoke(balanced.baln.account, "tokenFallback", owner.getAddress(), BigInteger.TEN,
pathWithUSDCBnUSD);


// Verify
verify(balanced.bnUSD.mock).transfer(balanced.savings.getAddress(), BigInteger.TEN, data.getBytes());
}

@Test
void stakeToSavingsWithRLPData(){
// Arrange
//baln as usdc
BigInteger balnToSwap = BigInteger.TEN.multiply(ICX);
when(balanced.baln.mock.balanceOf(routerScore.getAddress())).thenReturn(balnToSwap);
when(balanced.bnUSD.mock.balanceOf(routerScore.getAddress())).thenReturn(balnToSwap);

List<RouteAction> actions = new ArrayList<>(1);
actions.add(new RouteAction(SWAP, balanced.bnUSD.getAddress()));

byte[] data = tokenData("_lock", Map.of());
Account newReceiver = balanced.savings.account;
byte[] routeData = new RouteData("_swap", newReceiver.getAddress().toString(), BigInteger.ZERO, actions, data).toBytes();

// Act
routerScore.invoke(balanced.baln.account, "tokenFallback", owner.getAddress(), balnToSwap,
routeData);


// Verify
verify(balanced.bnUSD.mock).transfer(balanced.savings.getAddress(), balnToSwap, data);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import static network.balanced.score.lib.utils.BalancedAddressManager.resetAddress;
import static network.balanced.score.lib.utils.Check.checkStatus;
import static network.balanced.score.lib.utils.Check.onlyGovernance;
import static network.balanced.score.lib.utils.Constants.EXA;

import java.math.BigInteger;
import java.util.Map;
Expand All @@ -45,12 +44,10 @@
import score.annotation.External;

public class SavingsImpl extends FloorLimited implements Savings {
public static final String LOCKED_SAVINGS = "Locked savings";
public static final String VERSION = "version";
private static final DictDB<Address, BigInteger> totalPayout = Context.newDictDB("TOTAL_PAYOUT", BigInteger.class);

private final VarDB<String> currentVersion = Context.newVarDB(VERSION, String.class);
public static final String TAG = Names.SAVINGS;

public SavingsImpl(Address _governance) {
BalancedAddressManager.setGovernance(_governance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import network.balanced.score.lib.interfaces.addresses.AddressManager;
import network.balanced.score.lib.interfaces.base.Name;
import network.balanced.score.lib.interfaces.base.Version;
import network.balanced.score.lib.interfaces.tokens.XTokenReceiver;
import score.annotation.External;
import score.Address;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ public class RouteData {
public String method;
public String receiver;
public BigInteger minimumReceive;
public byte[] data;
public List<RouteAction> actions;

public RouteData(){}

public RouteData(String method, String receiver, BigInteger minimumReceive, List<RouteAction> actions) {
public RouteData(String method, String receiver, BigInteger minimumReceive, List<RouteAction> actions, byte[] data) {
this.method = method;
this.receiver = receiver;
this.minimumReceive = minimumReceive;
this.data = data;
this.actions = actions;
}

Expand All @@ -34,6 +37,7 @@ public static RouteData readObject(ObjectReader reader) {
obj.method = reader.readString();
obj.receiver = reader.readNullable(String.class);
obj.minimumReceive = reader.readNullable((BigInteger.class));
obj.data = reader.readNullable(byte[].class);
while (reader.hasNext()) {
RouteAction data = reader.read(RouteAction.class);
actions.add(data);
Expand All @@ -48,6 +52,7 @@ public static void writeObject(ObjectWriter w, RouteData obj) {
w.write(obj.method);
w.writeNullable(obj.receiver);
w.writeNullable(obj.minimumReceive);
w.writeNullable(obj.data);
for (RouteAction action : obj.actions) {
w.write(action);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Versions {
public final static String DIVIDENDS = "v1.0.0";
public final static String LOANS = "v1.2.3";
public final static String RESERVE = "v1.0.0";
public final static String SICX = "v1.1.1";
public final static String SICX = "v1.1.0";
public final static String STAKING = "v1.0.1";
public final static String WORKERTOKEN = "v1.0.0";
public final static String BNUSD = "v1.1.1";
Expand All @@ -33,7 +33,7 @@ public class Versions {
public final static String DEX = "v1.1.8";
public final static String GOVERNANCE = "v1.0.2";
public final static String REBALANCING = "v1.0.0";
public final static String ROUTER = "v1.1.8";
public final static String ROUTER = "v1.1.9";
public final static String STAKEDLP = "v1.0.8";
public final static String BOOSTED_BALN = "v1.1.0";
public final static String BRIBING = "v1.0.1";
Expand All @@ -42,7 +42,7 @@ public class Versions {
public final static String BALANCED_ASSET_MANAGER = "v1.0.6";
public final static String XCALL_MANAGER = "v1.0.2";
public final static String BURNER = "v1.0.0";
public final static String SAVINGS = "v1.0.0";
public final static String SAVINGS = "v1.0.1";
public final static String TRICKLER = "v1.0.0";

public final static String SPOKE_ASSET_MANAGER = "v1.0.2";
Expand Down
Loading