Type
CONTRACT
Validation date
2024-11-12 22:09:52 UTC
Fee
1.41750731 UCO

Code (1.21 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: 1203.644475


    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)) == 0xE2D3670BB33F7C6260216B71372EF59B4D5EF8AA44AE84CDCE9851E0E27EDBCC,
    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: 0x00007902534FCF30F00D85D34D2754F9ECEE11BB8346CD00444DA27E9940E2226C14, amount: 1203.644475


    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

    D382C8051552F7F848686C470A327B97706471C8300F740B8B2C12B2E26FB0DCBC4A4554647DC4056C4EF9B9E12B5F180D2F0AECB388BE7D3649F7E1

    Authorized keys

    • 000122A6CD9ED07E46835D6E88E5BD0BEE84C3F5E5DBF8E916AD9B2EC912C44AFEC2

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

000139F244537CD3921FBB557FE3C91C449046A001FDC4265689D543EF0C9B3CF899

Previous signature

8383B0B68500E3233DAFBBDC3DBC7E0F3E7CFF3B69134EC4AA7F9AE3D74F1408C4DC3F8D2549BCCDC56C206412662F86E97791DE9C1CB659CEDDC74BD339F506

Origin signature

304402206269D4B080E62766ADA13D3E1519FFF66FB01AFA1E9DA5DD86509788F943C7400220520DA318B2DECEAE44AA90C1FB1EA517166F733F8712926465252005759EA57C

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

008BDE6A859A9930035E4037862321D2F737F11708BB321FE67B9C7BE69E1ECDED

Coordinator signature

C57388A12FD9C861F680CA0D7C221F55EF811D03D81057658D587ABC5ED732B1088D683D333483F2AA0804BE1618B509884CE643907B4822B59E9750ABABE003

Validator #1 public key

00010F74B5FEB03F130C26B66BB24AA5066168510220DC9D6C2590294863AC9C8DEE

Validator #1 signature

B0568F02086D465724D73911B89E4E48A274A53FBF8D21C4009FEC860E8C00D1BB094A44CEA24CD406837953AC4EC474FAE73F349C2F099BC7EFCA2336A48A0D

Validator #2 public key

0001A6201599712BCE8837B0E841A875DF0042FA049626A0CF674EFA574BDCDA3221

Validator #2 signature

B8C03AB5EBE20687C7AEC891AF8E7C8576BB4F50F31C603E5F39B69734A9861B6F14FA85E9FC1F69948A969344A4D7A01CFA5A6DE3BC9BFE1F8BE24264F1DC0B