Type
CONTRACT
Validation date
2024-11-14 17:04:18 UTC
Fee
1.47250145 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: 2822.08268288


    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)) == 0xB498256F90444C9905D15EC35E11D541AAF1AA567C99E74ED505C811987D8E64,
    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: 0x0000FEDE37A5AC35A79092D88C0F1F170EE9C1EF9938C1117D0D463A0C26CD43EF17, amount: 2822.08268288


    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

    E42BED5E30B8BCB140BFEACDF4E3168DED71B09E5894ECD189D3D390051DFCE29890F117D48C1698C3372F63E97486E62A610056DF22819BD5C5ECB9

    Authorized keys

    • 000122A6CD9ED07E46835D6E88E5BD0BEE84C3F5E5DBF8E916AD9B2EC912C44AFEC2

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

000136041EB616D94198D30EDAEFB463BF08F6C4C9A9494CCCE85BBF308CB6CA43B1

Previous signature

66A905C3C27CCC7999C67546975832FBB6A6F4C36C4D37717D84A05534825E89DAE17B19BDBA90AAD9389A51E1F2C45763857B1D1C3AEFCCA9328B0085D96E06

Origin signature

30440220403247EB8C36BA12E2D7DAB2C35746F5E37A1AF8BC2BEA458473490C0D5A724302205EB1A62B98F1D3E49E5A788192F50E4D71DE21939308B71279E06269C5A8723B

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

001DBB6002D25C07A3FC24BDB935CA75C3679BE3FC8A1CEDB83D663402CE5E016C

Coordinator signature

CDD6DD8400E22D9F2186EC6BBE7053B4B4CC12ECAF77C6444854F23AED5D0101599B706D90AFC71F16849C7D4573F97B79AB5B192353A447F44D163C7B8C1D07

Validator #1 public key

00011518CD02E2B0009F828843512538A3F44A9CB493EB5E288376E4E45AD727AB3E

Validator #1 signature

C55F268DBD5D8915ED1D6B7D028C131E9A6876436A3CDA5164F8F2FA6B9C2797F637896636E29F898D38E6FD6A336122D0F132CBEDBD73895923390B04FAA109