Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ICS20 App on IBC #793

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
45e890d
initial commits
sdpisreddevil Nov 28, 2023
4b606e3
add ICS20Bank contract
sdpisreddevil Dec 12, 2023
c790b28
add ICS20Bank contract
sdpisreddevil Dec 12, 2023
bd9181f
add ICS20Lib contract
sdpisreddevil Dec 12, 2023
c074ebe
add ICS20TransferBank contract
sdpisreddevil Dec 12, 2023
750fa1e
add ICS20Transfer contract
sdpisreddevil Dec 12, 2023
c7789bd
fix comments on ICS20Bank
sdpisreddevil Dec 19, 2023
288e857
fix comments on ICS20Bank
sdpisreddevil Dec 19, 2023
a24d0ab
fix comments on ICS20Bank
sdpisreddevil Dec 20, 2023
4674725
fix comments on ICS20TransferBank on sendTransfer
sdpisreddevil Dec 20, 2023
6b0cfa0
chore remove whitespaces, unused imports
sdpisreddevil Dec 26, 2023
bec141a
add refund logic
sdpisreddevil Dec 26, 2023
31e14c1
fix: IIBCModule with added struct of messages
sdpisreddevil Dec 26, 2023
2a442e2
fix: build issues
sdpisreddevil Dec 26, 2023
1491efc
update: Struct on IIBCModule on msgTypes
sdpisreddevil Dec 26, 2023
099b387
fix: seperate ics20 contracts
viveksharmapoudel Dec 26, 2023
f6e7615
update: build.gradle
Dec 27, 2023
cc56743
remove: unused ibcbaseApp
Dec 27, 2023
a7ac65d
fix: setupRole on ics20Bank with primitive int inplace of Integer
Dec 27, 2023
1e40a29
fix: use of arrays.slice on ICS20Transfer
Dec 27, 2023
2668cc4
fix: set Address of IBChandler and bank
Dec 27, 2023
e35e841
fix: add onChanCloseConfirm and onchanOpenConfirm on ICS20Transfer
Dec 27, 2023
10955ff
fix: REMOVE the struct from IIBCModule
Dec 27, 2023
45ef0dd
fix: vardb message
Dec 27, 2023
0ccbb1b
fix: ics20App build.gradle with mainClassName to ICS20TransferBank
sdpisreddevil Dec 28, 2023
89e57ce
fix: remove unwanted params
sdpisreddevil Dec 28, 2023
1b7622a
fix: remove unused variables
sdpisreddevil Dec 28, 2023
33f9515
fix: getIBCAddress from parent class
sdpisreddevil Dec 28, 2023
ee328eb
fix: deploy of the contract
sdpisreddevil Dec 28, 2023
78aa099
update: add destinationPort and destinationChannel on ICS20Transfer o…
sdpisreddevil Dec 28, 2023
427b14b
fix: sendTransfer with packetMarshal data
sdpisreddevil Dec 28, 2023
75a89f5
fix: version check on onchanOpenTry
sdpisreddevil Dec 28, 2023
df44436
add: string split method on StringUtil for unmarshalJson
sdpisreddevil Dec 28, 2023
ad67542
add: onlyIBCHandler check on public methods
sdpisreddevil Dec 28, 2023
447f3ce
remove unused imports
sdpisreddevil Dec 28, 2023
aa659bc
fix:
sdpisreddevil Dec 28, 2023
6c96e08
update:
sdpisreddevil Dec 28, 2023
611c8c8
fix: unmarshal Json with better way to handle possible human issue on…
sdpisreddevil Dec 28, 2023
4dc2a46
fix: json unmarshal ics20 packet remove specific character
viveksharmapoudel Dec 29, 2023
c0a685f
add:
sdpisreddevil Dec 29, 2023
aa8ac65
add:
sdpisreddevil Dec 29, 2023
f8a1ec3
add:
sdpisreddevil Dec 29, 2023
4b52e25
update:
sdpisreddevil Dec 29, 2023
67d3212
update:
sdpisreddevil Dec 29, 2023
fe28512
fix: ics20 transfer issue
viveksharmapoudel Jan 3, 2024
9a1e784
fix:ics20Bank constructor for contract upgrade case and add todo for …
sdpisreddevil Jan 3, 2024
7703072
fix:
sdpisreddevil Jan 3, 2024
f6f40e5
fix:
sdpisreddevil Jan 3, 2024
505f952
chore: remove unused methods
sdpisreddevil Jan 3, 2024
ce504d9
chore: remove unused imports
sdpisreddevil Jan 3, 2024
c287d3c
fix: add getRole to get user role on ICS20Bank
sdpisreddevil Jan 4, 2024
17c84bb
fix: add contract name
sdpisreddevil Jan 4, 2024
0594a7b
fix: add contract name
sdpisreddevil Jan 4, 2024
60a0dff
add test cases for ics20Bank - WIP
sdpisreddevil Jan 4, 2024
c633bb3
add test cases for ics20app - WIP
sdpisreddevil Jan 4, 2024
e40fbb2
fix: comment failing test cases for ics20app - WIP
sdpisreddevil Jan 4, 2024
a9f18e0
fix: Add icx transfer case from app
sdpisreddevil Jan 8, 2024
a629251
fix: Add icx test case from app
sdpisreddevil Jan 8, 2024
301681c
fix: withdraw to be done by only caller wallet
sdpisreddevil Feb 12, 2024
0dc813c
fix: add interface details on each method
sdpisreddevil Feb 12, 2024
cbd799b
fix: replace `==` by equals for `byte`
sdpisreddevil Feb 12, 2024
7da48fd
fix: remove params on gradle
sdpisreddevil Feb 12, 2024
476d79b
Merge branch 'main' into feature/add-ics20-transfer-app
sdpisreddevil Feb 12, 2024
8e7ee1c
Merge pull request #2 from sdpisreddevil/fix/build-separate-ics20-tra…
sdpisreddevil Feb 12, 2024
5c97bc7
fix: remove temp variables and methods
sdpisreddevil Feb 12, 2024
7237b0b
fix: use TAG Variable for revert message
sdpisreddevil Feb 12, 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
2 changes: 2 additions & 0 deletions contracts/javascore/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ uat.contracts.mock-dapp=cx6a52b5f7e24c2bcea7758341dcb599f18dd03ecb
uat.contracts.xcall=cx1edf8867740f89866c6f92c50b707f2393d8fe12
uat.contracts.xcall-connection=cx5558aac127561b237dbf78845ad50e8bdba2a6b2
uat.contracts.xcall-multi-protocol=cxe31140b7cc953779fe33681020e08f9d0d158757
# uat.contracts.ics20-app=cxc44cfdfae14730bef8b8679b4409dee3cf5fbbb6


#LOCAL
local.contracts.ibc-core=hxb6b5791be0b5ef67063b3c10b840fb81514db2fd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface IIBCClient {
/**
* {@code @dev} registerClient registers a new client type into the client registry
* @param clientType Type of client
* @param lightClient Light client contract address
* @param client Light client contract address
*/
void registerClient(String clientType, Address client);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ibc.icon.interfaces;

import foundation.icon.score.client.ScoreInterface;
import icon.proto.core.channel.*;
import score.Address;

// IIBCModule defines an interface that implements all the callbacks
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package ibc.icon.interfaces;

import foundation.icon.score.client.ScoreInterface;
import score.Address;

import java.math.BigInteger;

@ScoreInterface
public interface IICS20Bank {
/**
* balanceOf returns the balance of the given account on the specified denom.
*/
void balanceOf(Address account, String denom);

/**
* transferFrom transfers amount of denom from sender to recipient.
*/
void transferFrom(Address from, Address to, String denom, BigInteger amount);

/**
* mint creates amount of denom and adds it to the balance of the given account.
*/
void mint(Address account, String denom, BigInteger amount);

/**
* burn subtracts amount of denom from the balance of the given account.
*/
void burn(Address account, String denom, BigInteger amount);

/**
* deposit transfers amount of tokenContract from caller to the bank and mints the same amount of tokenContract to the caller.
*/
void deposit(Address tokenContract, BigInteger amount, Address receiver);

/**
* withdraw transfers amount of tokenContract from the bank to receiver and burns the same amount of tokenContract from the bank.
*/
void withdraw(Address tokenContract, BigInteger amount, Address receiver);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ibc.icon.structs.messages;

import icon.proto.core.channel.Channel.Counterparty;
public class MsgOnChanOpenInit {
private String[] connectionHops;
private String portId;
private String channelId;
private Counterparty counterParty;
private String version;

public String[] getConnectionHops() {
return connectionHops;
}

public void setConnectionHops(String[] connectionHops) {
this.connectionHops = connectionHops;
}

public String getPortId() {
return portId;
}

public void setPortId(String portId) {
this.portId = portId;
}

public String getChannelId() {
return channelId;
}

public void setChannelId(String channelId) {
this.channelId = channelId;
}

public Counterparty getCounterParty() {
return counterParty;
}

public void setCounterParty(Counterparty counterParty) {
this.counterParty = counterParty;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}
}
80 changes: 80 additions & 0 deletions contracts/javascore/modules/ics20app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
version = '0.1.0'

dependencies {
compileOnly("foundation.icon:javaee-api:$javaeeVersion")
implementation("foundation.icon:javaee-scorex:$scorexVersion")
implementation project(':lib')
implementation project(':score-util')
implementation project(':ibc')

testImplementation 'com.google.protobuf:protobuf-javalite:3.13.0'
testImplementation 'foundation.icon:javaee-rt:0.9.3'
testImplementation("org.mockito:mockito-core:$mockitoCoreVersion")
testImplementation("org.mockito:mockito-inline:$mockitoCoreVersion")
testImplementation("foundation.icon:javaee-unittest:$javaeeUnittestVersion")
testAnnotationProcessor("foundation.icon:javaee-score-client:$scoreClientVersion")
testImplementation project(':test-lib')
testImplementation("foundation.icon:javaee-score-client:$scoreClientVersion")
testImplementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
testImplementation("foundation.icon:icon-sdk:$iconsdkVersion")
testImplementation("org.junit.jupiter:junit-jupiter-api:$jupiterApiVersion")
testImplementation("org.junit.jupiter:junit-jupiter-params:$jupiterParamsVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jupiterEngineVersion")
}

test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}

jacocoTestReport {
dependsOn test
reports {
xml.required = true
csv.required = false
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
}
}

tasks.named('compileJava') {
dependsOn(':ibc:optimizedJar')
dependsOn(':score-util:jar')
dependsOn(':lib:jar')
}

optimizedJar {
mainClassName = 'ibc.ics20app.ICS20TransferBank'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}


deployJar {
endpoints {
berlin {
uri = 'https://berlin.net.solidwallet.io/api/v3'
nid = 0x7
}
lisbon {
uri = 'https://lisbon.net.solidwallet.io/api/v3'
nid = 0x2
}
local {
uri = 'http://localhost:9082/api/v3'
nid = 0x3
}
uat {
uri = project.findProperty('uat.host') as String
nid = property('uat.nid') as Integer
// to = "$ics20app"?:null
}
}
keystore = rootProject.hasProperty('keystoreName') ? "$keystoreName" : ''
password = rootProject.hasProperty('keystorePass') ? "$keystorePass" : ''
parameters {
// arg('_ibcHandler', "$ibcCore"?:null)
// arg("_bank","$ics20Bank"?:null)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package ibc.ics20app;

import ibc.ics24.host.IBCCommitment;
import ibc.icon.score.util.StringUtil;
import java.math.BigInteger;

public class ICS20Lib {

public static class PacketData {
public String denom;
public String sender;
public String receiver;
public BigInteger amount;
public String memo;
}


public static final byte[] SUCCESSFUL_ACKNOWLEDGEMENT_JSON = "{\"result\":\"AQ==\"}".getBytes();
public static final byte[] FAILED_ACKNOWLEDGEMENT_JSON = "{\"error\":\"failed\"}".getBytes();
public static final byte[] KECCAK256_SUCCESSFUL_ACKNOWLEDGEMENT_JSON = IBCCommitment.keccak256(SUCCESSFUL_ACKNOWLEDGEMENT_JSON);
public static final Integer CHAR_SLASH = 0x2f;
public static final Integer CHAR_BACKSLASH = 0x5c;
public static final Integer CHAR_F = 0x66;
public static final Integer CHAR_R = 0x72;
public static final Integer CHAR_N = 0x6e;
public static final Integer CHAR_B = 0x62;
public static final Integer CHAR_T = 0x74;
public static final Integer CHAR_CLOSING_BRACE = 0x7d;
public static final Integer CHAR_M = 0x6d;
private static final char[] HEX_DIGITS = "0123456789abcdef".toCharArray();

private static final int CHAR_DOUBLE_QUOTE = '"';

static boolean isEscapeNeededString(byte[] bz) {
for (byte b : bz) {
int c = b & 0xFF;
if (c == CHAR_DOUBLE_QUOTE) {
return true;
}
}
return false;
}

public byte[] marshalUnsafeJSON(PacketData data) {
if (data.memo.isEmpty()) {
return marshalJson(data.denom, data.amount, data.sender, data.receiver);
} else {
return marshalJson(data.denom, data.amount, data.sender, data.receiver, data.memo);
}
}


public static byte[] marshalJson(String escapedDenom, BigInteger amount, String escapedSender, String escapedReceiver) {
String jsonString = "{" +
"\"amount\":\"" + amount.toString() + "\"," +
"\"denom\":\"" + escapedDenom + "\"," +
"\"receiver\":\"" + escapedReceiver + "\"," +
"\"sender\":\"" + escapedSender + "\"" +
"}";

return jsonString.getBytes();
}

public static byte[] marshalJson(String escapedDenom, BigInteger amount, String escapedSender, String escapedReceiver, String escapedMemo) {
String jsonString = "{" +
"\"amount\":\"" + amount.toString() + "\"," +
"\"denom\":\"" + escapedDenom + "\"," +
"\"receiver\":\"" + escapedReceiver + "\"," +
"\"sender\":\"" + escapedSender + "\"," +
"\"memo\":\"" + escapedMemo + "\"" +
"}";

return jsonString.getBytes();
}

public static PacketData unmarshalJSON(byte[] packet) {
StringBuilder sanitized = new StringBuilder();
String jsonString = new String(packet);

for (char c : jsonString.toCharArray()){
if (c != '\\' && c != '\"' && c !='{' && c!='}'){
sanitized.append(c);
}
}
jsonString=sanitized.toString();

String[] jsonParts = StringUtil.split(jsonString, ',');

PacketData data = new PacketData();

data.amount = new BigInteger(getValue(jsonParts[0]));

data.denom = getValue(jsonParts[1]);
data.receiver = getValue(jsonParts[2]);
data.sender = getValue(jsonParts[3]);
if (jsonParts.length > 4) {
data.memo = getValue(jsonParts[4]);
} else {
data.memo = "";
}

return data;
}

private static String getValue(String keyValue) {
return StringUtil.split(keyValue, ':')[1].trim();

}

}
Loading
Loading