Type
CONTRACT
Validation date
2024-11-10 10:45:09 UTC
Fee
1.49576886 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: 9431.2475298


    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)) == 0xD3BDFC09670351DA30658084104FF763C436F7FE7E431E7ADDB058C3137CE282,
    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: 0x000022FCA36772CDCAFA1032CC9EECE1D06C89B94F5283C5D10608F6D9896598BE62, amount: 9431.2475298


    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

    D60794E0F5F580621BD30F016AB0BE1A395078C5BDCA399176788B5C3827FF2A7664AD604DD62603997731F045B5C929811D06A45163E009CCBF81F2

    Authorized keys

    • 000122A6CD9ED07E46835D6E88E5BD0BEE84C3F5E5DBF8E916AD9B2EC912C44AFEC2

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001D51838BF826B6D2F5BF4AF782B0078FE513E03E4F5B84957108AD46F48B2A135

Previous signature

D90998D4697FF88E1C0CAA0144AC2F8D0A4B9B3C544E5961881E666AFE48F8C5E922EA4F581A46ADAB58211FBAA1AB902B528DBD2AE1A7B2355E4FF458475A06

Origin signature

3044022011E3A96D9D9A1BB76E6F76A919F14C78E3687EE0F9B288FD51EBFB94DEDC20770220646D6028248D506424A1C5906455B1BDA1B015699FD51F8D49218159DF6B7CD4

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00966399EBC4644FC43771B8ECDEFCF524931F6AD7FF93D5626D8965CA9F70D0AE

Coordinator signature

1A8428BFD06D85733703846B4CB98EBAE038E7DE6D430FC03AF5E210A110757780FA1282E67789D78D15E6B6FEE093ED7E4AE8E753B8BA8D6B4875C605F03901

Validator #1 public key

0001FDCD194785B82F4E02D02764800593CB3F2D7262D5F802BAC4A91CFD338F3963

Validator #1 signature

094820D722BCC424821A45ED4C079A8B7C0FB0F7813FA472B91DCD924E3ED1C3398ED893F0C76A7A34A47B152C767F2F1708F537FD866E8F4F27B7B2B48CAC01

Validator #2 public key

0001B8800415E75326411D65020B8E3E306F22CB1D72BC5FF5929B3EB58CDA511327

Validator #2 signature

E71FFB38126970C213E7B9763E1C0256D99D5F523FCC55CA7F4BDEB37509885666CF259865D2083998F0B37DFBE87F03BD6D27B7E8A18DE898A2B87F6F675700