Type
CONTRACT
Validation date
2024-01-16 16:03:15 UTC
Fee
0.714648 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) == 0x0000072E418B60C6DABD272BC2728B17B352B8104F068D11365D50134F96A4199609
 )
]

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

    Contract.set_code ""
  end

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

  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: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0x7079E14B9CFD5566D715EFAE511EB66EC48BD6FE7786AF27152540F5FFBC9B46,
    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: 0x00008ACE40EA6A16F6E4391B69E052EAE9DAFA934E023FB2D511AB6893644C5285F3, amount: 0.0992015, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 2.985e-4, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    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

    FD1029BD20CC2ACB0595CF3403C7AD2282405AB3BABF78DFC92CC47910F7266EEECF4B1FC7111708A09BE4608E76838048CD6EE280E6AF09EF795E6B

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

00010E9C074489C3B647F9169395319419F8012080D021AAE6633C41851A623B332A

Previous signature

C8BD1773E31A05C503AB6958D4FC067F12648A5802478551E618CB8CA952337A5089B68A6E3BB798411DA2CBA8815F0189222A8714403B08C6493205B8066009

Origin signature

3044022073128AD00954E7A5DFF2E98513DB55704C80310672677488324D4C6629B85AED022079E83E040925A4415E5B35C8C2BED7DC9463149CDD42F4F72EC5E8CFB0C37AF3

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00963A8C1A9AF79C9E82D9B42BDB5F48ECA21C37F73C8B1174EF9E2C07B24885E9

Coordinator signature

9B7884D10B77B3827371511EB1E3DB402F506B54B4280BE2E0EDDD4994EBF184D2CDF17238FF4851A7436C42FDE274F5419D7FA792F61D2C70555DA9A414540D

Validator #1 public key

00010F2A0E4C424582A94BD90E05FE6931628F91988ABBE387D365994F1F3FCF5A12

Validator #1 signature

121D455986F671BD6F8A1E4E599FF9DABEE6DE3E9093A407964F8EA5670FA2C7C4BBD1445E9DF9E1434FD8BAC0501164B55CCF483F82733EC321669A61E2790B

Validator #2 public key

000134772A943DC0F7038B1BABA39E18841C12DD6682B1B6D1D15E08D7CAF5339AB0

Validator #2 signature

9ECAA7ED49CF4C3A5558499645DECD9375BC08144463730199B542A362AD10F75537EF3A4DACD21819385299325EA3024D045720EC438D6066083D18C175DC0D