Skip to content

Commit

Permalink
Merge branch 'dev' into 'master'
Browse files Browse the repository at this point in the history
Refactor the RWT Repo script and remove RWT/RSN factor

See merge request ergo/rosen-bridge/contract!70
  • Loading branch information
vorujack committed Dec 3, 2023
2 parents 6df6841 + be9498e commit b09e988
Show file tree
Hide file tree
Showing 38 changed files with 1,919 additions and 1,344 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: RELEASE
on:
push:
branches:
- master
- dev
tags:
- '*'
pull_request:
Expand Down Expand Up @@ -100,6 +100,14 @@ jobs:
tokensMap-*.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: git-sync
uses: wei/git-sync@v3
with:
source_repo: ${GITHUB_REPOSITORY}
source_branch: "refs/tags/*"
destination_repo: 'https://${{ secrets.DESTINATION_USER }}:${{ secrets.DESTINATION_TOKEN }}@${{ secrets.DESTINATION_SERVER }}/ergo/${GITHUB_REPOSITORY}.git'
destination_branch: "refs/tags/*"

- name: RUN Jar File release
if: github.ref_type == 'tag'
Expand Down
77 changes: 49 additions & 28 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ libraryDependencies ++= Seq(

name := "contract"
ThisBuild / scalaVersion := "2.12.7"
ThisBuild / version := "1.0.0"
ThisBuild / version := "2.0.0"
ThisBuild / organization := "rosen.bridge"
ThisBuild / organizationName := "rosen-bridge"
ThisBuild / publishMavenStyle := true
Expand Down
Binary file modified images/Get_Permit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Return_Total_Permit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 27 additions & 52 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,25 @@ box = {
}

network-general = {
mainnet-alpha-1 = {
public-launch = {
main-tokens = {
RepoNFT="3ac8a90d0aa8c5c50e99dd2588a990fd37b5d3aee70e32d56241f41ed49e9f03"
GuardNFT="a96b8049f0741c7255b60cf01954439d2e4b2d19ae7d8ebc688ecb190a33b538"
RSN="10278c102bf890fdab8ef5111e94053c90b3541bc25b0de2ee8aa6305ccec3de",
RSNRatioNFT="febf2d60bbcccb94ed27f49f496521415280bb7b59086455371808c4f740f36a"
RepoNFT="eceee4b72d8572c032789927a1847557292fb80b78fb58d6214754d2d474272d"
GuardNFT="55bf993b4376ba132264d084f06fe033321ab43c68db1435a0e7e0bf77ddb735"
RSN="8b08cdd5449a9592a9e79711d7d79249d7a03c535d17efaee83e216e80a44c4b"
RSNRatioNFT="1ce1ea41ceaed94a6976a047645ffb3f3da3916685268c8f2d8f80f892147caa"
}
ergo-network = {
node = "https://node.ergopool.io/"
explorer-url = "https://api.ergoplatform.com/"
type = "MAINNET"
}
}
softlaunch = {
loen = {
main-tokens = {
RepoNFT="4b1e5bcfbd6763b9cea8411841213611258fabed16293af6aa8cd8200b7e1286"
GuardNFT="b039e4445337697deaad703fc8d1fcb129c4577e8673394fa2403e54d484eeda"
RSN="51c1745883a62db6cf47f5765bd695317a01e54bcaaaeaa4aab0b517d2f46a24",
RSNRatioNFT="45e873d4e5af0d0fd6905ef51053fa7e9c672cd26b23b8a7f4feb17254f25392"
}
ergo-network = {
node = "https://node.ergopool.io/"
explorer-url = "https://api.ergoplatform.com/"
type = "MAINNET"
}
}
public-soft-launch = {
main-tokens = {
RepoNFT="a599bb94b230f8d3ac94856ab24c31b235ab493d3415097102916c600fbbf969"
GuardNFT="6721f30af5d1063bf0fd7dd2842e55f419bc79f4f1acb664352f2a02cc3c5017"
RSN="844e3cf44b3181b4cacbccbf7596d341f41147d73daf4b565ecaac983aba2508",
RSNRatioNFT="1ea49e1c052803576e91275b27dffbae3f4ccad9da5219bcda51ea5006fe7661"
RepoNFT="923aa955f4f1b67409044ee28b78bb6caff649c9de45a192fd313703743dd8e3"
GuardNFT="648e9cf0b39560dd33454bb8e5c5e5bf48f12e161dc7c3112d8edfdb1606c40d"
RSN="cdf549fccbb09ab8f38ecbf9a5ed37c926707753adf8fed19b039684a0772bfe",
RSNRatioNFT="05690d3e7a8daae13495b32af8ab58aaec8a5435f5974f6adf17095d28cac1f5"
}
ergo-network = {
node = "https://node.ergopool.io/"
Expand All @@ -52,48 +39,36 @@ network-general = {

networks = {
cardano = {
mainnet-alpha-1 = {
public-launch = {
tokens = {
RWTId="1d9a45e047b45a4a4c565ac49e70b5e2f03f625975cbe41912833e9a547d060d"
CleanupNFT="f833f756e1bf9d15b8f984aefa64482040d6c8b3ec217b2be8b8a477e82d900d"
RWTId="bee1398b0a7acc0a4a0bc8619ef473a462f4c23208072f2aaeddfef67d30166a"
CleanupNFT="cffae825313193178cfe8c528e521bc5c88f74a970ad1da6f25f12c728416a83"
}
cleanup-confirm = 7200
lock-address="addr1v8kqhz5lkdxqm8qtkn4lgd9f4890v0j6advjfmk5k9amu4c535lsu"
cleanup-confirm=21600
}
softlaunch = {
loen = {
tokens = {
RWTId="747ffbe3403d8013e5033398dc8f09a3594f51d0250f2075cc559782ae2fa846"
CleanupNFT="c79e1748e862a80c4f7193077b600f9ffb65c612297f9a8829407044c1eb1066"
RWTId="01553e0f9122ce7a8dc696fa227d6b09a63dc7eb20a351bfa4f1108c14238895"
CleanupNFT="0ca1d31e93b42f9e44e5290e3411aaa2ba67aac158e57916e645612d110729f5"
}
lock-address = "addr1v9kmp9flrq8gzh287q4kku8vmad3vkrw0rwqvjas6vyrf9s9at4dn"
cleanup-confirm = 7200
}
public-soft-launch = {
tokens = {
RWTId="8e5b02ba729ad364867619d2a8b9ff1438190c14979a12aa0a249e996194f074"
CleanupNFT="246eb5dd39a11d96d2bc7373b3166835fc72998b045d67ea7adce842c4585a62"
}
cleanup-confirm = 7200
}
idKey = "fingerprint"
idKey = "tokenId"
}
ergo = {
mainnet-alpha-1 = {
public-launch = {
tokens = {
RWTId="383d70ab083cc23336a46370fe730b2c51db0e831586b6d545202cbc33938ee1"
CleanupNFT="37080ea7925c407965f27013fe66d2e7d692e68dc0de9219effe4819cea8c7b3"
RWTId="b0eef7ef45e9c01845d9eb377561e0e06bb6ac4fa0261114ba20de2e5397dcfb"
CleanupNFT="af906a9ffa6f5b819872a135e2a7a6ddd52272e88e0f19842b3730fd9fb65477"
}
cleanup-confirm = 7200
}
softlaunch = {
tokens = {
RWTId="9410db5b39388c6b515160e7248346d7ec63d5457292326da12a26cc02efb526"
CleanupNFT="65214ca53fbf09c0875d71f67f28a0471a4d6d4f66c38ae47b6a417e645f68fd"
}
cleanup-confirm = 7200
cleanup-confirm = 21600
}
public-soft-launch = {
loen = {
tokens = {
RWTId="bd7ec56095ce16501dff9331ba7eb687805904b1ef97100dc4b8abaf472366b3"
CleanupNFT="3443950555c6088a4b3fbd99b853a1db89765c9c7be318a6134db2ee0f8ecbca"
RWTId="c5c6e337aa9bebf87b1f174e1bc1c3019be44ebf72de5b55fbbdcd1f659b4881"
CleanupNFT="eca2e0240bea93c5340cca325d1f1d7eea760ae44dbcf6bb3c2f35ca3329b33e"
}
cleanup-confirm = 7200
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/helpers/Configs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ object Configs extends ConfigHelper {
readKeyDynamic(networkTokensConfig, "CleanupNFT"),
readKeyDynamic(networkTokensConfig, "RWTId")
)
val lockAddress = if (networkName != "ergo") readKeyDynamic(networkDataConfig, "lock-address", "PLEASE SET LOCK_ADDRESS MANUALLY") else ""
allNetworksToken((networkName, networkType.toString)) = Network(
tokens,
lockAddress,
readKeyDynamic(networkDataConfig, "cleanup-confirm").toInt
)
})
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/helpers/Models.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ case class Tokens(CleanupNFT: String, RWTId: String) {
}
}

case class Network(tokens: Tokens, cleanupConfirm: Int)
case class Network(tokens: Tokens, lockAddress: String, cleanupConfirm: Int)
46 changes: 35 additions & 11 deletions src/main/scala/rosen/bridge/Contracts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import scorex.util.encode.{Base16, Base64}
import io.circe.Json

import java.io.PrintWriter
import scala.io.{BufferedSource, Source}

class Contracts(ergoGeneralConfig: ErgoNetwork, networkConfig: (Network, MainTokens)) {
lazy val WatcherCollateral: (ErgoContract, String) = generateWatcherCollateralContract()
lazy val RWTRepo: (ErgoContract, String) = generateRWTRepoContract()
lazy val WatcherPermit: (ErgoContract, String) = generateWatcherPermitContract()
lazy val Commitment: (ErgoContract, String) = generateCommitmentContract()
Expand All @@ -16,22 +18,31 @@ class Contracts(ergoGeneralConfig: ErgoNetwork, networkConfig: (Network, MainTok
lazy val Lock: (ErgoContract, String) = generateLockContract()
lazy val GuardSign: (ErgoContract, String) = generateGuardSignContract()

def toJsonAddresses: Json = {
def readScript(path: String) = {
val scriptSource: BufferedSource = Source.fromFile("src/main/scala/rosen/bridge/scripts/"+ path, "utf-8")
val script: String = scriptSource.getLines.mkString("\n")
scriptSource.close()
script
}

def toJsonAddresses(networkName: String): Json = {
val lockAddress = if (networkName != "ergo") networkConfig._1.lockAddress else Lock._2
Json.fromFields(List(
("RWTRepo", Json.fromString(RWTRepo._2)),
("WatcherPermit", Json.fromString(WatcherPermit._2)),
("Fraud", Json.fromString(Fraud._2)),
("lock", Json.fromString(Lock._2)),
("lock", Json.fromString(lockAddress)),
("guardSign", Json.fromString(GuardSign._2)),
("Commitment", Json.fromString(Commitment._2)),
("WatcherTriggerEvent", Json.fromString(WatcherTriggerEvent._2))
("WatcherTriggerEvent", Json.fromString(WatcherTriggerEvent._2)),
("WatcherCollateral", Json.fromString(WatcherCollateral._2))
))
}

def createContractsJson(networkName: String, networkType: String, networkVersion: String): Unit = {
val result = {
Json.fromFields(List(
("addresses", this.toJsonAddresses),
("addresses", this.toJsonAddresses(networkName)),
("tokens", networkConfig._1.tokens.toJson().deepMerge(networkConfig._2.toJson())),
("cleanupConfirm", Json.fromInt(networkConfig._1.cleanupConfirm))
))
Expand All @@ -43,13 +54,26 @@ class Contracts(ergoGeneralConfig: ErgoNetwork, networkConfig: (Network, MainTok
}
}

private def generateWatcherCollateralContract(): (ErgoContract, String) = {
ergoGeneralConfig.ergoClient.execute(ctx => {
val watcherCollateralScript = readScript("WatcherCollateral.es")
.replace("REPO_NFT", Base64.encode(Base16.decode(networkConfig._2.RepoNFT).get))
val contract = ctx.compileContract(ConstantsBuilder.create().build(), watcherCollateralScript)
val address = Utils.getContractAddress(contract, ergoGeneralConfig.addressEncoder)
println(s"Watcher collateral address is : \t\t\t$address")
(contract, address)
})
}

private def generateRWTRepoContract(): (ErgoContract, String) = {
ergoGeneralConfig.ergoClient.execute(ctx => {
val watcherPermitHash = Base64.encode(Utils.getContractScriptHash(WatcherPermit._1))
val RwtRepoScript = Scripts.RwtRepoScript
val watcherCollateralHash = Base64.encode(Utils.getContractScriptHash(WatcherCollateral._1))
val RwtRepoScript = readScript("RwtRepo.es")
.replace("GUARD_NFT", Base64.encode(Base16.decode(networkConfig._2.GuardNFT).get))
.replace("RSN_TOKEN", Base64.encode(Base16.decode(networkConfig._2.RSN).get))
.replace("PERMIT_SCRIPT_HASH", watcherPermitHash)
.replace("WATCHER_COLLATERAL_SCRIPT_HASH", watcherCollateralHash)
val contract = ctx.compileContract(ConstantsBuilder.create().build(), RwtRepoScript)
val address = Utils.getContractAddress(contract, ergoGeneralConfig.addressEncoder)
println(s"Watcher repo address is : \t\t\t$address")
Expand All @@ -60,7 +84,7 @@ class Contracts(ergoGeneralConfig: ErgoNetwork, networkConfig: (Network, MainTok
private def generateWatcherPermitContract(): (ErgoContract, String) = {
ergoGeneralConfig.ergoClient.execute(ctx => {
val commitmentHash = Base64.encode(Utils.getContractScriptHash(Commitment._1))
val watcherPermitScript = Scripts.WatcherPermitScript
val watcherPermitScript = readScript("Permit.es")
.replace("REPO_NFT", Base64.encode(Base16.decode(networkConfig._2.RepoNFT).get))
.replace("COMMITMENT_SCRIPT_HASH", commitmentHash)

Expand All @@ -74,7 +98,7 @@ class Contracts(ergoGeneralConfig: ErgoNetwork, networkConfig: (Network, MainTok
private def generateCommitmentContract(): (ErgoContract, String) = {
ergoGeneralConfig.ergoClient.execute(ctx => {
val triggerEvent = Base64.encode(Utils.getContractScriptHash(WatcherTriggerEvent._1))
val commitmentScript = Scripts.CommitmentScript
val commitmentScript = readScript("Commitment.es")
.replace("REPO_NFT", Base64.encode(Base16.decode(networkConfig._2.RepoNFT).get))
.replace("EVENT_TRIGGER_SCRIPT_HASH", triggerEvent)

Expand All @@ -89,7 +113,7 @@ class Contracts(ergoGeneralConfig: ErgoNetwork, networkConfig: (Network, MainTok
ergoGeneralConfig.ergoClient.execute(ctx => {
val fraud = Base64.encode(Utils.getContractScriptHash(Fraud._1))
val lock = Base64.encode(Utils.getContractScriptHash(Lock._1))
val triggerScript = Scripts.EventTriggerScript
val triggerScript = readScript("EventTrigger.es")
.replace("CLEANUP_NFT", Base64.encode(Base16.decode(networkConfig._1.tokens.CleanupNFT).get))
.replace("LOCK_SCRIPT_HASH", lock)
.replace("FRAUD_SCRIPT_HASH", fraud)
Expand All @@ -104,7 +128,7 @@ class Contracts(ergoGeneralConfig: ErgoNetwork, networkConfig: (Network, MainTok

private def generateFraudContract(): (ErgoContract, String) = {
ergoGeneralConfig.ergoClient.execute(ctx => {
val fraudScript = Scripts.FraudScript
val fraudScript = readScript("Fraud.es")
.replace("CLEANUP_NFT", Base64.encode(Base16.decode(networkConfig._1.tokens.CleanupNFT).get))
.replace("REPO_NFT", Base64.encode(Base16.decode(networkConfig._2.RepoNFT).get))

Expand All @@ -117,7 +141,7 @@ class Contracts(ergoGeneralConfig: ErgoNetwork, networkConfig: (Network, MainTok

private def generateLockContract(): (ErgoContract, String) = {
ergoGeneralConfig.ergoClient.execute(ctx => {
val lockScript = Scripts.LockScript
val lockScript = readScript("Lock.es")
.replace("GUARD_NFT", Base64.encode(Base16.decode(networkConfig._2.GuardNFT).get))

val contract = ctx.compileContract(ConstantsBuilder.create().build(), lockScript)
Expand All @@ -129,7 +153,7 @@ class Contracts(ergoGeneralConfig: ErgoNetwork, networkConfig: (Network, MainTok

private def generateGuardSignContract(): (ErgoContract, String) = {
ergoGeneralConfig.ergoClient.execute(ctx => {
val guardSignScript = Scripts.GuardSignScript
val guardSignScript = readScript("GuardSign.es")

val contract = ctx.compileContract(ConstantsBuilder.create().build(), guardSignScript)
val address = Utils.getContractAddress(contract, ergoGeneralConfig.addressEncoder)
Expand Down
Loading

0 comments on commit b09e988

Please sign in to comment.