Type
CONTRACT
Validation date
2023-11-14 16:05:26 UTC
Fee
0.57567733 UCO

Code (1.06 KB)

@version 1

condition triggered_by: transaction, on: provision(_evm_contract, _url), 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) == 0x000066706D704329CA8C2A4153991E2DDACC968622CA10217CA14952EB7ABB966C30
 )
]

actions triggered_by: transaction, on: provision(evm_contract, url) do
  next_code = """
    @version 1

  # Automate the refunding after the given timestamp
  actions triggered_by: datetime, at: 1699985100 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.0995, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: refund(), as: [
    timestamp: timestamp >= 1699985100
  ]

  actions triggered_by: transaction, on: refund() do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.0995, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0x1B4AD3DE32E4BBEBA8E0C0883A806E42AFED227708CADC5D9AEEFEB614C9EA8C,
    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)

      res = Http.request("#{url}", "POST", headers, body)
      if 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

      valid?
    )
  ]

  actions triggered_by: transaction, on: reveal_secret(secret) do
    Contract.set_type "transfer"
    Contract.add_token_transfer to: 0x0000422C61F773320F920624B9E9E7553FDCBE8E2A291554503340669CA86788CDA4, amount: 0.0992015, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 2.985e-4, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

  """

  Contract.set_code next_code
end

Content (0 B)

State (0 B)

Movements (0)

Ownerships (1)

  • Secret shared with 1 key

    Encoded secret

    3136F32AC2BEDDE6EE740BE4D27E8AD74260BA2E3F7E34BBB3662DE8973EDF32A4ACBA585397F1B7E6CEA1D98830107C746F54AC54731EFC3934DEC8

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001DB47218BD392CA0F8A67B906696AE0225ED4F6D0C5D188C11AE783D504CEAA45

Previous signature

5519E01C3F593B708FB4631E7851ADEFBD2BBC099219FBDDFEBDB8D432BAF6F89EFC11A8B1DAAE70E00C1019AB1D48D6CAE3E3B390877EC47C6921BAB4146F00

Origin signature

3044022065C31451EE36B31DA96C0FA52AAC5342159CE261FEF480963C86DB9D9F80425A02201A92380373A29E103AA9CF47C941D98DA7C271DB127D2ECF88B124E9D01315BC

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00BDD791F642DD80417CB45F76BDBE669AE9A452BF38FEE3060DD8C2335818E1E7

Coordinator signature

7417230DE3BEEC9082184A15D40936EE603F43490506CAE22DDC7CBEB4F759F89A8C51C9283D77EE73A1BF4F8BBDB6DA9D259C14DB675F80A30258AC0B1B5804

Validator #1 public key

0001B0A94804BF8ECC9897075C6207FF63EF4D339F57A0349888E6B77CD47DB53EF3

Validator #1 signature

AB61631F2BC89F0242F514FAB3E1999DAEC85B202661DC2D76B8E745968CEC776C224C571127710F015FDBD8964B257A14EA1381D53BB48383D321F4993B180B

Validator #2 public key

00011B58ED42235461734EAF253BD97A80B92899ABCC3BE680D44B6825DD2A88A947

Validator #2 signature

9495D4CC748052872C35B462E10203B0F1EB78A80D0901BCC004782745631C1746540132BB58696E4DC44226B62DA9D278A951F0116A8CCE3EF829899CFC4907