Type
CONTRACT
Validation date
2024-10-31 14:49:52 UTC
Fee
1.5795003 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: 3780.86


    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)) == 0x8F92BEEB3229E6417D9401954D50ABC7523B5EBE0AF3403E0396CB0EA2E7E50F,
    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: 0x000060F7B04583EE32DAD3408295873DF7F87F3686491873E8009F9639F2CD2B6DD1, amount: 3780.86


    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

    B8874525244134B284D4EF92D62DA9B9C2FEE572C9984DED6075A6BCF076C56850C545E78F5EB4B6C1F64897F4A99DE1F187197F9CAAC81AEC013EDD

    Authorized keys

    • 000122A6CD9ED07E46835D6E88E5BD0BEE84C3F5E5DBF8E916AD9B2EC912C44AFEC2

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001DD80A2A794AEEF4310279D06FF5B50E06FB266E385C0FEB7E553AC73DFF8A621

Previous signature

E767488D3B51BE6C58C56709C1B104D7A322AC0F2482E6EFDA765034D5D8EAE2A1DFE856EA169E9D26D89E51B5C0A37C985511DA16361B31490306BE47BCF307

Origin signature

3044022050C4EDC58C18D68F2C8EA2A238D27279142C4083F59D2D942A9958AE0184697D0220611A1B41597986337E352AF985438DBA46CDADDEA0926E9028B507C49CB0D810

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00254317279C170A5D127ACA684D5F5FBBBDB8DFC6E3E75297AA964C4B1EC8116E

Coordinator signature

CCFD4BF8E1D0AD1530F3A3F629AD6CFAAACFF180063FC0225888292275E76ECCA7CBADBD8662D4FC178906B4A8F1AEAD46A3A6CE5B17D3DF0B39C76D59E0520B

Validator #1 public key

0001FDCD194785B82F4E02D02764800593CB3F2D7262D5F802BAC4A91CFD338F3963

Validator #1 signature

F6EE18F7B202D5B05F2C0AD0721266A2C2665DBDB31435E387C94CC85381E2A160158554FECBFF0A99B3589CB3136CAECEA395D13C443FFECC24B5B720C5890B

Validator #2 public key

0001172FBEC021CA921A9A771C312FCAD74E84CF0A466F5F662630C70E7BD8699587

Validator #2 signature

AFC95FBE9AB1D8561AFA87D734CC0FB7F43DCA0D99D7954538A64E3D051C53A57C2B7752248EFBF2CD329311B5170943B20335F1894D740C91B6A12924D49D0A