Type
CONTRACT
Validation date
2024-01-25 16:48:27 UTC
Fee
0.75458223 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: 1706208420 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 >= 1706208420
  ]

  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)) == 0x003E90427246F5691DA95EBB0FE1BF2AA4ADDD171A2EED40CF02E74BD292C3B2,
    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: 0x00004B312A76B650FA1735CA2679CD4D1F3320095F9394CB072CDE835B6C95B6BC03, 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

    535F81FD879BC13BDCE563797F00ED54B72B37AAAC465B45F2472BD5D47461E4964A46423BB2788E16946AEF8485C3980C71A290F03B42233D6A9473

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

00016CA6EBD3B561E7D83B92E07F3C8E8C63E604F484F0D3EFFE9281F38E180B006F

Previous signature

47005AE335F9F4C17482990DB83F41C30A3AF3CE49B5F978E92FC6DCF34BE629895A6D42E1D5DF1B479016B6D4EB7C5E555E0E71ACBDC38560F7E062EE463F01

Origin signature

3045022100E55137AC4545449F851B833A93167B8FED9F115D88B6D76B4C881655FEA917500220789744F8F7E25AB3BAA68114DDF1941993F957957DC198B7ACF9BA79FAF22BD7

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

005EC0BAB99E2B852895A6DFAB9D215941AC788FFA590E6ED58923916EBBFD706B

Coordinator signature

DF90AD5670364F3D0B75DF37DD3A5A401156A211301B696B756A9859B47C19A0BD53E7CE76E31FF3FEC696589A4FF8552639EC6B720994F18CC79781E7763601

Validator #1 public key

000134772A943DC0F7038B1BABA39E18841C12DD6682B1B6D1D15E08D7CAF5339AB0

Validator #1 signature

6CD603E8984FF2B2415A6539466877B2C89AF914ED8F8C1B4006519A969F6184BF2EAB3BA0DF72FD2397FA3FB95B5EA995BCC1CB3CC6BC0AC4F2DB4709072301

Validator #2 public key

000162E6ADFF9FBBBC4BDBB3CD56A5A13A1E8576C3619ADC58A189F7E9A3A77FF95D

Validator #2 signature

8DFB22A90068331BDD46C37E9A19D6FCDC8211AB9B2BBF56E37CD523858B5555FEEFF969EE18E7105079F763DA5AAA5A282BA1B1E53E78E92ED77CF33B6FB807