Type
CONTRACT
Validation date
2024-10-29 21:16:29 UTC
Fee
1.47280162 UCO

Code (1.2 KB)

@version 1

condition triggered_by: transaction, on: provision(_evm_contract, _endpoints, _signature, _evm_pool), as: [
previous_public_key: (
   # Transaction is not yet validated so we need to use previous address
  # to get the genesis address
  previous_address = Chain.get_previous_address()
  Chain.get_genesis_address(previous_address) == 0x00002075E9FB5329C7F5149802EB75F925D79B5FEC5BFCF09DC81993CB9C39FEAF5D
 )
]

actions triggered_by: transaction, on: provision(evm_contract, endpoints, signature, evm_pool) do
  endpoints = Json.to_string(endpoints)
  Contract.set_code """
  @version 1

  condition triggered_by: transaction, on: refund(), as: [
    content: (
      valid? = false

      abi_data = Evm.abi_encode("status()")
      tx = [to: "#{evm_contract}", data: "0x\#{abi_data}"]
      request = [jsonrpc: "2.0", id: "1", method: "eth_call", params: [tx, "latest"]]

      headers = ["Content-Type": "application/json"]
      body = Json.to_string(request)

      evm_responses = query_evm_apis(#{endpoints}, "POST", headers, body)
      for res in evm_responses do
        if !valid? && res.status == 200 && Json.is_valid?(res.body) do
          response = Json.parse(res.body)
          result = Map.get(response, "result")
          if result != nil do
            decoded_abi = Evm.abi_decode("(uint)", result)
            # Refund status is 2
            valid? = List.at(decoded_abi, 0) == 2
          end
        end
      end

      valid?
    )
  ]

  actions triggered_by: transaction, on: refund() do
    Contract.set_type "transfer"
    # Send back UCO to bridge pool
  Contract.add_uco_transfer to: 0x00002075E9FB5329C7F5149802EB75F925D79B5FEC5BFCF09DC81993CB9C39FEAF5D, amount: 257000


    Contract.set_code \"""
    @version 1

    export fun info() do
      [
        evm_contract: #{evm_contract},
        evm_pool: #{evm_pool},
        ae_pool: 0x00002075E9FB5329C7F5149802EB75F925D79B5FEC5BFCF09DC81993CB9C39FEAF5D,
        status: 2 # REFUNDED
      ]
    end
    \"""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0xEB6A6F2873829C460D9851972BB4C2063EC1FAD97697E2CD2CDECDB5FFA53952,
    address: (
      valid? = false

      abi_data = Evm.abi_encode("status()")
      tx = [to: "#{evm_contract}", data: "0x\#{abi_data}"]
      request = [jsonrpc: "2.0", id: "1", method: "eth_call", params: [tx, "latest"]]

      headers = ["Content-Type": "application/json"]
      body = Json.to_string(request)

      responses = query_evm_apis(#{endpoints}, "POST", headers, body)
      for res in responses do
        if !valid? && res.status == 200 && Json.is_valid?(res.body) do
          response = Json.parse(res.body)
          result = Map.get(response, "result")

          if result != nil do
            decoded_abi = Evm.abi_decode("(uint)", result)
            # Withdrawn status is 1
            valid? = List.at(decoded_abi, 0) == 1
          end
        end
      end

      valid?
    )
  ]

  actions triggered_by: transaction, on: reveal_secret(secret) do
    Contract.set_type "transfer"
    Contract.add_uco_transfer to: 0x000058994EC0F27F98C9AFA6920C888EC70F79A0A67DB5A7CA137779BD556BFFA6EF, amount: 257000


    Contract.set_code \"""
    @version 1

    export fun info() do
      [
        evm_contract: #{evm_contract},
        evm_pool: #{evm_pool},
        ae_pool: 0x00002075E9FB5329C7F5149802EB75F925D79B5FEC5BFCF09DC81993CB9C39FEAF5D,
        status: 1 # WITHDRAWN
      ]
    end
    \"""
  end

  fun query_evm_apis(endpoints, method, headers, body) do
    requests = []
    for endpoint in endpoints do
      requests = List.append(requests, url: endpoint, method: method, headers: headers, body: body)
    end
    Http.request_many(requests, false)
  end

  export fun get_provision_signature() do
    [
      r: 0x#{signature.r},
      s: 0x#{signature.s},
      v: #{signature.v}
    ]
  end

  export fun info() do
    [
      evm_contract: #{evm_contract},
      evm_pool: #{evm_pool},
      ae_pool: 0x00002075E9FB5329C7F5149802EB75F925D79B5FEC5BFCF09DC81993CB9C39FEAF5D,
      status: 0 # PENDING
    ]
  end

  """
end

export fun info() do
  [
    ae_pool: 0x00002075E9FB5329C7F5149802EB75F925D79B5FEC5BFCF09DC81993CB9C39FEAF5D,
    status: 0 # PENDING
  ]
end

Content (0 B)

State (0 B)

Movements (0)

Ownerships (1)

  • Secret shared with 1 key

    Encoded secret

    0FCB33A27B3F1120AB2A13EA1B104AB55C7E56332AC60C433BC158F6FEAEA754C9B781B9A56F0EA58C1956CFA4F76572A356E0199E0E6A42FFDE256A

    Authorized keys

    • 000122A6CD9ED07E46835D6E88E5BD0BEE84C3F5E5DBF8E916AD9B2EC912C44AFEC2

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001908DD0B60A714CF3166B69519DD96D183E6D6F05FA953640F1A9623DE39BF0DE

Previous signature

4220FEA2C74BECB9F3DCD6DADC6DB959E7E21E1EBB2BE53FB060D88FD15ED408EB2CFBBE1DF604ED182381E09AC781AD19B31BE8425A5B8FA58FE9A625F6DD06

Origin signature

30440220404E9658FD1CC9BAA976D0FDAED976E40267A5AE21764D1016A3B7C3629A25CE02205443BBAE0909CACCA884014A622A3C9A2C1F740815DB6E1A4F768723B4E1DD56

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00842543C7194F68BBFAE61E21DDE93C6ADBC2182882E47910001412BD4CB728A5

Coordinator signature

C171D9E58012F9F9AAFF1FEAE9FB7078BA6B33C16A8AC0A2A58F8903907E350BCCC04967464B5D063FA3A0E8A29AA4EDDE71A7BE9656CFF49F0DB3610DF27607

Validator #1 public key

000105B4FDF46B9FE90C30A471DCE4D296CCCDC27242C6CDA6E48622F4330C646100

Validator #1 signature

3A319B8AAF3314F38562C7CDAD24850F6F29D0E89B0D0CCCF67059063CE1C072649C1F5863E08D6B58B6EE9AC533C6FD3D74455DB963E17D369A6A3CEACBA00A

Validator #2 public key

0001172FBEC021CA921A9A771C312FCAD74E84CF0A466F5F662630C70E7BD8699587

Validator #2 signature

2CC9EDF9E4733E78B9664BB6A5174F7F99B94728B9C45A9E195BC9CC9E8D58AD555C66E9550B9B052A6440CB0D79567C3D7458B35781BCCEAD633C61E7BA8C09