Skip to content

Commit

Permalink
Merge branch 'dev' into 'master'
Browse files Browse the repository at this point in the history
Dev

See merge request ergo/rosen-bridge/contract!113
  • Loading branch information
vorujack committed Sep 7, 2024
2 parents 391dde0 + 12134df commit d69957a
Show file tree
Hide file tree
Showing 18 changed files with 587 additions and 23 deletions.
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 := "3.2.2"
ThisBuild / version := "3.3.0"
ThisBuild / organization := "rosen.bridge"
ThisBuild / organizationName := "rosen-bridge"
ThisBuild / publishMavenStyle := true
Expand Down
18 changes: 18 additions & 0 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ network-general = {
GuardNFT="55bf993b4376ba132264d084f06fe033321ab43c68db1435a0e7e0bf77ddb735"
RSN="8b08cdd5449a9592a9e79711d7d79249d7a03c535d17efaee83e216e80a44c4b"
RSNRatioNFT="e2ed4d64393222db666f20e67803e9e6fbe6d64531e14ff52ddd95615b0cbf17"
EmissionNFT="c5bf77f7edf6b8e793692f6535c28cf67712a5c2efc014637aedad1321f50eaf"
ERSN="dede2cf5c1a2966453ffec198a9b97b53d281e548903a905519b3525d59cdc3c"
}
ergo-network = {
node = "https://node.ergopool.io/"
Expand All @@ -28,6 +30,8 @@ network-general = {
GuardNFT="648e9cf0b39560dd33454bb8e5c5e5bf48f12e161dc7c3112d8edfdb1606c40d"
RSN="cdf549fccbb09ab8f38ecbf9a5ed37c926707753adf8fed19b039684a0772bfe",
RSNRatioNFT="05690d3e7a8daae13495b32af8ab58aaec8a5435f5974f6adf17095d28cac1f5"
EmissionNFT="68e0238a06f5c61ab813a1f9f6eb0cdf9d02d2e8fc1dc4165b8ab37c731205a8"
ERSN="6210a801f4fbe487ca55594b0eaee96b9e440747b84f55d916d9c7dfdae5d622"
}
ergo-network = {
node = "https://node.ergopool.io/"
Expand Down Expand Up @@ -111,4 +115,18 @@ networks = {
}
idKey = "tokenId"
}
ethereum = {
loen = {
tokens = {
RWTId="2a4ed39265dc9454565c681323dcb06a8e46bb52f49c146b2c2f9bfb99c93208"
CleanupNFT="25e2aca04a0c1fde171066468644e710dffe9cdfce48b01c408dd52385df2d14"
AwcNFT="a438fddc6aba3303dbbcdabe8dcc98b3ab3a62b4e4b5e2d4782e0db618f4ec32"
RepoConfigNFT="c4c9b9e27b120d4dc92b177f25583064ca123a90ab8a6fbdd9f389c70e427cda"
}
lock-address="0x8875f643f13309fc624d8090023b9f876da16b1e"
cold-address=""
cleanup-confirm = 10
}
idKey = "tokenId"
}
}
4 changes: 3 additions & 1 deletion src/main/scala/helpers/Configs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ object Configs extends ConfigHelper {
readKeyDynamic(mainTokensConfig, "RepoNFT"),
readKeyDynamic(mainTokensConfig, "GuardNFT"),
readKeyDynamic(mainTokensConfig, "RSN"),
readKeyDynamic(mainTokensConfig, "RSNRatioNFT")
readKeyDynamic(mainTokensConfig, "RSNRatioNFT"),
readKeyDynamic(mainTokensConfig, "EmissionNFT"),
readKeyDynamic(mainTokensConfig, "ERSN")
)

// Prepare general network config
Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/helpers/Models.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import io.circe.Json
import org.ergoplatform.ErgoAddressEncoder
import org.ergoplatform.appkit.ErgoClient

case class MainTokens(RepoNFT: String, GuardNFT: String, RSN: String, RSNRatioNFT: String) {
case class MainTokens(RepoNFT: String, GuardNFT: String, RSN: String, RSNRatioNFT: String, EmissionNFT: String, ERSN: String) {
def toJson(): Json = {
Json.fromFields(List(
("RepoNFT", Json.fromString(RepoNFT)),
("GuardNFT", Json.fromString(GuardNFT)),
("RSN", Json.fromString(RSN)),
("RSNRatioNFT", Json.fromString(RSNRatioNFT))
("RSNRatioNFT", Json.fromString(RSNRatioNFT)),
("EmissionNFT", Json.fromString(EmissionNFT)),
("ERSN", Json.fromString(ERSN)),
))
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/scala/rosen/bridge/Contracts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Contracts(networkGeneral: NetworkGeneral, networkConfig: Network) {
lazy val Lock: (ErgoContract, String) = generateLockContract()
lazy val GuardSign: (ErgoContract, String) = generateGuardSignContract()
lazy val RepoConfig: (ErgoContract, String) = generateRepoConfigContract()
lazy val Emission: (ErgoContract, String) = generateEmissionContract()

def readScript(path: String) = {
val scriptSource: BufferedSource = Source.fromFile("src/main/scala/rosen/bridge/scripts/" + path, "utf-8")
Expand All @@ -39,6 +40,7 @@ class Contracts(networkGeneral: NetworkGeneral, networkConfig: Network) {
("WatcherTriggerEvent", Json.fromString(WatcherTriggerEvent._2)),
("WatcherCollateral", Json.fromString(WatcherCollateral._2)),
("RepoConfig", Json.fromString(RepoConfig._2)),
("Emission", Json.fromString(Emission._2)),
))
}

Expand Down Expand Up @@ -177,4 +179,17 @@ class Contracts(networkGeneral: NetworkGeneral, networkConfig: Network) {
(contract, address)
})
}

private def generateEmissionContract(): (ErgoContract, String) = {
networkGeneral.ergoNetwork.ergoClient.execute(ctx => {
val emissionScript = readScript("Emission.es")
.replace("EMISSION_NFT", Base64.encode(Base16.decode(networkGeneral.mainTokens.EmissionNFT).get))
.replace("GUARD_NFT", Base64.encode(Base16.decode(networkGeneral.mainTokens.GuardNFT).get))

val contract = ctx.compileContract(ConstantsBuilder.create().build(), emissionScript)
val address = Utils.getContractAddress(contract, networkGeneral.ergoNetwork.addressEncoder)
println(s"emission address is : \t\t\t$address")
(contract, address)
})
}
}
48 changes: 48 additions & 0 deletions src/main/scala/rosen/bridge/scripts/Emission.es
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
// ----------------- REGISTERS
// ----------------- TOKENS
// 0: EmissionNFT
// 1: RSN
// 2: EmittedRSN

val EmissionNFT = fromBase64("EMISSION_NFT");
val GuardNFT = fromBase64("GUARD_NFT");

if (CONTEXT.dataInputs.size > 0) {
// Emission Box Update transaction
val GuardBox = CONTEXT.dataInputs(0);
val verifyGuard = GuardBox.tokens.exists { (token: (Coll[Byte], Long)) => token._1 == GuardNFT };
val updateSignCount = GuardBox.R5[Coll[Int]].get(1);
val signedColl = GuardBox.R4[Coll[Coll[Byte]]].get.map { (row: Coll[Byte]) => proveDlog(decodePoint(row)) };
sigmaProp(
allOf(
Coll(
verifyGuard,
atLeast(updateSignCount, signedColl),
OUTPUTS(0).tokens(0)._1 == SELF.tokens(0)._1,
OUTPUTS(0).tokens(0)._2 == SELF.tokens(0)._2
)
)
)
} else {
// Emission transaction
val emissionOut = OUTPUTS(0)
val emission = SELF
sigmaProp(
allOf(
Coll(
emissionOut.propositionBytes == emission.propositionBytes,
emissionOut.value >= emission.value,
emissionOut.tokens.size == emission.tokens.size,
emission.tokens.size == 3,
emissionOut.tokens(0)._1 == emission.tokens(0)._1,
emissionOut.tokens(0)._2 == emission.tokens(0)._2,
emissionOut.tokens(1)._1 == emission.tokens(1)._1,
emissionOut.tokens(2)._1 == emission.tokens(2)._1,
emissionOut.tokens(2)._2 > emission.tokens(2)._2,
emission.tokens(1)._2 - emissionOut.tokens(1)._2 == emissionOut.tokens(2)._2 - emission.tokens(2)._2
)
)
)
}
}
2 changes: 2 additions & 0 deletions src/test/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ network-general = {
RepoNFT="2222222222222222222222222222222222222222222222222222222222222222"
GuardNFT="3333333333333333333333333333333333333333333333333333333333333333"
RSN="1111111111111111111111111111111111111111111111111111111111111111"
EmissionNFT="8888888888888888888888888888888888888888888888888888888888888888"
ERSN="9999999999999999999999999999999999999999999999999999999999999999"
}
ergo-network = {
node = "https://node.ergopool.io/"
Expand Down
Loading

0 comments on commit d69957a

Please sign in to comment.