Type
CONTRACT
Validation date
2024-11-15 10:17:05 UTC
Fee
1.40870732 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: 1006.88255315


    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)) == 0xEC004E46F7C9322BBD82439ECD4EF473715E93B3EC1B4F0F2873BA79E7C9D34E,
    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: 0x0000F199462325353B134DDD6C45DCA147DA0AE2D5B2611CEE0107D1D1F123314D00, amount: 1006.88255315


    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

    0F061DC006DE39A22952108A3133FAE3CD153D5BED9813E81CF6992EA1752086883578AFDBAF7C3B54EE032BD280A4383BE3F50714090E4C11EBB04E

    Authorized keys

    • 000122A6CD9ED07E46835D6E88E5BD0BEE84C3F5E5DBF8E916AD9B2EC912C44AFEC2

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

00010CE30BCC25AD5443409A8F7D613541CB185EA5EAACB6DC59D6DE0DF1B6C162E4

Previous signature

29BAA28440EEE73CCA296429B79E5D1273686DE525C1818F16276548C2C1506E948C8473F54FFF8348AA1403049D0A13D0ED29BD674ED84060A45680EA2DE405

Origin signature

3045022100FB165E357515191F095746FC165E574BA33D133F40A5E49BBA27832D0CFC71CB022028AF9E44C0B05EF354E94DF889AFA1252A96AD53483E339397C9A835AFEC0529

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00F2770707C46D06E82A6EA827FFD41ED4947CF78116DC89472FA1F3916AF16020

Coordinator signature

182940287BFD850C7401344E7131562558289ED0C84F844BF452B136665EEA88C06B83C207E82E23A150E741B092E96D00DCF269250557C364E5074180FC760A

Validator #1 public key

00016DC3C25720E8FB335A38DB1D57FA1CD8AD5287C212B53343907DFA124394C684

Validator #1 signature

7C360ED690215BED88C5C426A5D82A649BA231BDAB27AC030F5BA3CB51A262C86F3DF4597D3F88EC5D5BA31ED10FE8250892A314CCA2710688728E3E1C57CF00

Validator #2 public key

00016A24FA6FC34A345FB22A7E90CB6BC583AEA140B679549F745FB51D59A93F7868

Validator #2 signature

3185BA3028C83DF3F6C32EC64707883DD7CF5C0D8064BEF8CDFC25F502B034A02D2573F3568978B5FF41E85564CF1E084220BCD3222DC95E83775AEBA031B507