SUSY Gateway (Gravity)

SUSY gateway:

Overview:

LU-Port has already implemented on waves and eth chains:

https://github.com/Gravity-Tech/gateway/blob/main/contracts/waves/luport.ride

To work with another TargetChain (ERGO) we have to see the following functionality of IB port:

  1. ERGO SC must support external call of “attachEventData” with parameters:
  • Token ID (optional since different tokens will have their own gateways)
  • Amount
  • Receiver

Only one from 5 admin accounts have a chance to call this method.

  1. After attachEventData Receiver must receive its amount of wrapped tokens
  2. Holder of wrapped tokens has to have an ability to send tokens to the gateway address and this should trigger API (rpc) call.

For all statements 1-3 there must be an API (open and public).

Solidity example of IB (issue/burn port):

https://github.com/Gravity-Tech/gateway/blob/main/contracts/ethereum/IBPort.sol

Ergo Solution

As Ergo is UTXO blockchain with in which contracts are focused on checking on-chain work done off-chain, Ergo solution for 1-2) would be quite different from Ethereum (as usually):

  • create a lot of UTXOs (e.g. 50) with e.g. swETH tokens locked with a contract
  • the lock contract is waiting for amount and receiver to be provided in context extension, checking admin signature and also that asked amount of swETH unlocked indeed. Something like:

{
val amount = getVarLong.get
val receiver = getVarGroupElement.get

val selfOut = OUTPUTS(0)
val selfAmt = ((SELF.tokens(0)._2 - selfOut.tokens(0)._2) == amount) && selfOut.tokens(0)._1 == fromBase64(“swETHtokenid”)
val selfScript = selfOut.propositionBytes == SELF.propositionBytes
val rcvOut = OUTPUTS(1)
val rcvScript = rcvOut.propositionBytes == proveDlog(receiver).propBytes
val rcvAmt = (rcvOut.tokens(0)._2 == amount) && selfOut.tokens(0)._1 == fromBase64(“swETHtokenid”)

val adminApproval = PK(“9eg2Rz3tGogzLaVZhG1ycPj1dJtN4Jn8ySa2mnVLJyVJryb13QB”) || PK(“9eg2Rz3tGogzLaVZhG1ycPj1dJtN4Jn8ySa2mnVLJyVJryb13QB”) || PK(“9eg2Rz3tGogzLaVZhG1ycPj1dJtN4Jn8ySa2mnVLJyVJryb13QB”) || PK(“9eg2Rz3tGogzLaVZhG1ycPj1dJtN4Jn8ySa2mnVLJyVJryb13QB”) || PK(“9eg2Rz3tGogzLaVZhG1ycPj1dJtN4Jn8ySa2mnVLJyVJryb13QB”)

selfAmt && selfScript && rcvScript && rcvAmt && adminApproval
}

P2S playground link: ErgoScript Playground | PlutoMonkey Wallet

For 3) we can have offchain component just and script which is checking that the only one output is merging all the input swETH tokens and output script is from above.

3 Likes

Nice, this doesn’t seem too complicated overall even in the UTXO model.

2 Likes