Skip to content

Commit

Permalink
feat: intent contract after review
Browse files Browse the repository at this point in the history
  • Loading branch information
0ptimizerr committed Jan 17, 2025
1 parent 19bdb66 commit 8818d2a
Show file tree
Hide file tree
Showing 9 changed files with 807 additions and 1,275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public BigInteger getConnSn() {
}

void onlyRelay() {
Context.println(relayAddress.get().toString());
Context.require(Context.getCaller().equals(relayAddress.get()), "OnlyRelayer");
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@
import java.math.BigInteger;

public class Constant {
public static final BigInteger FILL = new BigInteger("1");
public static final BigInteger CANCEL = new BigInteger("2");
public enum OrderAction {
FILL(BigInteger.ONE),
CANCEL(BigInteger.TWO);

private final BigInteger value;

OrderAction(BigInteger value) {
this.value = value;
}

public BigInteger getValue() {
return value;
}
}

// Generalized Connection Variables
public final static String RECEIPTS = "receipts";
Expand All @@ -16,10 +28,7 @@ public class Constant {
public final static String NETWORK_ID = "networkId";
public final static String PROTOCOL_FEE = "protocolFee";
public final static String FEE_HANDLER = "feeHandler";
public final static String OWNER = "owner";
public final static String NATIVE_ADDRESS = "nativeAddress";
public final static String DEPOSIT = "deposit";
public final static String ORDERS = "orders";
public final static String FINISHED_ORDERS = "finishedOrders";
public final static String PERMIT = "permit";

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package network.icon.intent.structs;
package network.icon.intent.db;

import java.math.BigInteger;

import score.ByteArrayObjectWriter;
import score.Context;
import score.ObjectReader;
import score.ObjectWriter;

public class SwapOrder {
public class SwapOrderDb {
public BigInteger id; // unique ID
public String emitter;// Address of emitter contract
public String srcNID; // Source Network ID
Expand All @@ -20,7 +19,7 @@ public class SwapOrder {
public BigInteger toAmount; // Minimum amount of the toToken to receive
public byte[] data; // Additional data (if any) for future use (is this the right type?)

public SwapOrder(BigInteger id, String emitter, String srcNID, String dstNID, String creator,
public SwapOrderDb(BigInteger id, String emitter, String srcNID, String dstNID, String creator,
String destinationAddress, String token, BigInteger amount, String toToken, BigInteger toAmount,
byte[] data) {
this.id = id;
Expand All @@ -36,50 +35,27 @@ public SwapOrder(BigInteger id, String emitter, String srcNID, String dstNID, St
this.data = data;
}

private SwapOrder() {
private SwapOrderDb() {
}

public static void writeObject(ObjectWriter writer, SwapOrder obj) {
public static void writeObject(ObjectWriter writer, SwapOrderDb obj) {
obj.writeObject(writer);
}

// add read object method
public static SwapOrder readObject(ObjectReader reader) {
SwapOrder obj = new SwapOrder();
public static SwapOrderDb readObject(ObjectReader reader) {
SwapOrderDb obj = new SwapOrderDb();
reader.beginList();
Context.println("reading swap order");
obj.id = reader.readBigInteger();
Context.println(obj.id.toString());
obj.emitter = reader.readString();
Context.println(obj.emitter.toString());

obj.srcNID = reader.readString();
Context.println(obj.srcNID.toString());

obj.dstNID = reader.readString();
Context.println(obj.dstNID.toString());

obj.creator = reader.readString();
Context.println(obj.creator.toString());

obj.destinationAddress = reader.readString();
Context.println(obj.destinationAddress.toString());

obj.token = reader.readString();
Context.println(obj.token.toString());

obj.amount = reader.readBigInteger();
Context.println(obj.amount.toString());

obj.toToken = reader.readString();
Context.println(obj.toToken.toString());

obj.toAmount = reader.readBigInteger();
Context.println(obj.toAmount.toString());

obj.data = reader.readByteArray();
Context.println(obj.data.toString());

reader.end();
return obj;
}
Expand All @@ -102,12 +78,21 @@ public void writeObject(ObjectWriter writer) {

public byte[] toBytes() {
ByteArrayObjectWriter writer = Context.newByteArrayObjectWriter("RLPn");
SwapOrder.writeObject(writer, this);
SwapOrderDb.writeObject(writer, this);
return writer.toByteArray();
}

public static SwapOrder fromBytes(byte[] bytes) {
public static SwapOrderDb fromBytes(byte[] bytes) {
ObjectReader reader = Context.newByteArrayObjectReader("RLPn", bytes);
return readObject(reader);
}

public SwapOrderDb fromBytesAndProperties(byte[] bytes, String token, BigInteger amount) {
ObjectReader reader = Context.newByteArrayObjectReader("RLPn", bytes);
this.token = token;
this.amount = amount;
this.emitter = Context.getAddress().toString();
this.creator = Context.getCaller().toString();
return readObject(reader);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package network.icon.intent.structs;

import score.Address;
import score.ByteArrayObjectWriter;
import score.Context;
import score.ObjectReader;
import score.ObjectWriter;

public class TokenFallbackData {
public byte[] swapOrderData;
public String type;
public Address solver;

public TokenFallbackData(byte[] _swapOrderData, String _type, Address _solver) {
this.swapOrderData = _swapOrderData;
this.type = _type;
this.solver = _solver;
}

private TokenFallbackData() {
}

public static void writeObject(ObjectWriter writer, TokenFallbackData obj) {
obj.writeObject(writer);
}

public void writeObject(ObjectWriter writer) {
writer.beginList(3);
writer.write(this.swapOrderData);
writer.write(this.type);
writer.write(this.solver);
writer.end();
}

public static TokenFallbackData readObject(ObjectReader reader) {
TokenFallbackData obj = new TokenFallbackData();
reader.beginList();
obj.swapOrderData = reader.readByteArray();
obj.type = reader.readString();
obj.solver = reader.readAddress();
reader.end();
return obj;
}

public byte[] toBytes() {
ByteArrayObjectWriter writer = Context.newByteArrayObjectWriter("RLPn");
TokenFallbackData.writeObject(writer, this);
return writer.toByteArray();
}

public static TokenFallbackData fromBytes(byte[] bytes) {
ObjectReader reader = Context.newByteArrayObjectReader("RLPn", bytes);
return readObject(reader);
}

public byte[] getSwapOrder() {
return swapOrderData;
}

public void setSwapOrder(byte[] _swapOrderData) {
this.swapOrderData = _swapOrderData;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public Address getSolver() {
return solver;
}

public void setSolver(Address solver) {
this.solver = solver;
}
}

This file was deleted.

Loading

0 comments on commit 8818d2a

Please sign in to comment.