Type
CONTRACT
Validation date
2023-12-06 09:10:52 UTC
Fee
0.73695891 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) == 0x00008DD22E7496E86901E9B276A1BE6F9512EB09980CC04C7B76495EF37D5666A709
 )
]

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: 1701860340 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.0199, token_address: 0x0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0x39DD8452A0173F6BA7CEBAEEFF7148B32B65CE9B97F424030F70FA6DD4F35CB5,
    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: 0x0000EF7F5DADD1E56D5DD8460A4C5053B1403716AB605B376E343F792A68D1E2F29F, amount: 0.0198403, token_address: 0x0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 5.97e-5, token_address: 0x0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827

    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

    44C67D1C913534FA54CC7E8E6F1F77FE14156D6A397F921B45E2C091E91EBC5DA957B3D66F8D7022BB09F00D49B0E63D0EF579A1422FB411A016486E

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

00010C814A23DF4DEA58B24E8F411BAA5F375349F512FC2DCC246CE8EBE5E4113BE8

Previous signature

5A16CE7BAA76BFC43A6E66A1723A02F6F4EDC7EB1A8E6AC76938985F6497EE470AC9E62D93BC2A200279F8A460A6BF27EA5754C0FC9F3548B632BECFE20AB709

Origin signature

30440220263DEF12477972B35320CC745F77F3A1DA46A83AA44B10C3D35E9279FD739A5A022006A2B8DA7E2AAD115DCC073AE6569A2D636E96D885CCFB258BA05F1E454E94C8

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

008ABE11F0B364ACA89CAB6BFBF7D88DA60A4BB34437266C08BD7E2BC4A09DCAEB

Coordinator signature

7CF860AA18AD5B94F3CC9145D8917F3F99956DF69905B0F20F4AD72D3D7F51710E59430BA448B23B0DC9126DE260C86EDE961E1D6E27267CE7015DFFEF66AD05

Validator #1 public key

000151C124A6211CD402FD1CFE560C5DB51ED0CBEF44B09B21A41206028E7E5942BF

Validator #1 signature

DF879A04893E65638B98A1EF2CFBF136D26D4A04C88056383DA56001E684F9F60F1DFF412C34D8E3DB8B263FFB0291582E5C0873A4995B7F7A852F8FF1098004

Validator #2 public key

0001B0A94804BF8ECC9897075C6207FF63EF4D339F57A0349888E6B77CD47DB53EF3

Validator #2 signature

8DCD873CD9F0F187E03E4FFFF8322D5188869A822B233FB4FFDAF775F823CDEAE2FF8CC813E2FC9392FEE7F12C683158236FC1663F8B0BE8388347565CFBC40F