Type
CONTRACT
Validation date
2024-11-09 00:31:49 UTC
Fee
1.60242966 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: 26504.37232673


    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)) == 0xB44970DE4D92D9B6B040DEE8498A0DED622B52D8EFE56BFEFFB39B63BB167B8F,
    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: 0x00000D21A9B99A69D3D5C3A6F7A8B7CC643EA064F3C736B28AD1402143AB237693E8, amount: 26504.37232673


    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

    BA81DE8827300B4CA6CCD04F0EC2BB2B8B3ED74E79DB9BF2A439329F2908CC6C5AC656E4DF1FE9E82EDB04C4342F354BA9EBCF51B02D492747274F1D

    Authorized keys

    • 000122A6CD9ED07E46835D6E88E5BD0BEE84C3F5E5DBF8E916AD9B2EC912C44AFEC2

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

000175F5A42BF009D45357F97259D441B2BE58DFAC44AB1C7B51C00C3FC857FBCAB9

Previous signature

F04FB290737310228051DBC7286D27D012D797D4822E1C618E9841EFB5806252973D9843F9A935CC98470BC2E5BAEF9E1B0BDE40A981903DE00C7A97CDCC470A

Origin signature

30440220230F5C44F905DD19DF683A2F2561602BE3E74495227C5BF3623459A89846838F022056D1C19F1DD310B2F0BE411D5F32F2C934CC74336D11C4888D9531855F5993E3

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00F3AA4D26CBD8F5F434BBE40DF6AF7AFA34F7CD74F13DF5A49461684D9803ADF3

Coordinator signature

47C207D4918A3D338B0AB36FB0A5BFBCEB260FF5BFA7CD4014F9519B3FA60A611D893A3F8C1D66894927FAAC6F47FC2E4CE613CC4F3114EE7B151ED6BC432107

Validator #1 public key

0001B8800415E75326411D65020B8E3E306F22CB1D72BC5FF5929B3EB58CDA511327

Validator #1 signature

B689A9A70CE423AB84C8DB15BFB4DBD2643B11059C36AB42DA82E7F110808B67145F66058374B73673F90C2A8DA8AB8AF0A4F6AF484399CCAFDAC6A2FD036F03

Validator #2 public key

00011518CD02E2B0009F828843512538A3F44A9CB493EB5E288376E4E45AD727AB3E

Validator #2 signature

1B0AC55A87F9D579AB1481B70ED935F398126D5B3B96EB187BED08E69C174C96FD89FFFF4A8A358D868C0DBCB6D9485B9C4733258C361708B461271F2ECA0E08