Type
CONTRACT
Validation date
2024-01-27 17:41:12 UTC
Fee
0.70515934 UCO

Code (1.07 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: 1706384400 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.034825, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0x45351D0BB7D50AC5B951A2E5EE91A8FE048ADE66A652FB415FA707D7FAEA3281,
    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: 0x0000FEA155AEF688306C66CCDF1B83DB3429E948EB5F57C006128669401B9B906720, amount: 0.03472053, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 1.0447e-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

    8FEEEA3AD940349AD4313043A3382496A05207C3D0CB5E3AF678587E316007F8BE4B84214E27F9D26E25570F58AA0521129C06ADA0C1274215DAF3E8

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

000182B4FECDA0894B180E59D5E40A606C4D94590837C2086E4704B498BE93A020D0

Previous signature

B07A47007233BABA90B56E26296DD388B4BCD1513D44A48B0EECEF6D8FF81B524EB44EC6010ED5A3E39E5DA96E853A466F545F98B85751A0DF77BB80052FAF00

Origin signature

304402206ED87AFB9832DC83FB9F9684CD3B4047B87FF8B03CB14B4884A9555482E39DAB0220545246027520FD2B3FF44A06E744A3E67F4567EC14BD600FD5ECCB2D4CB63FDB

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00AD60B1E71CD2D5EABE22D0BE7ADCC910DC161BBF03248512F444C2651FFC618F

Coordinator signature

BFCCC0DA34B429B6DFEE58CAD9F3BCA92695C46570926C3251B8DC0579C1E6360BE171E7E6B2BB4589586353A0256A65D9C26F85D1CA142FD56ADCD7680F6209

Validator #1 public key

000134772A943DC0F7038B1BABA39E18841C12DD6682B1B6D1D15E08D7CAF5339AB0

Validator #1 signature

33D718952FD79B9ECAD0109EA3675EE7163356A69A92AB9CC3D48AAA7873C44474000F6C1AF0B7EBC0323B31DF3043D5BBB70F878CFEE9E427628F852520910F

Validator #2 public key

000162E6ADFF9FBBBC4BDBB3CD56A5A13A1E8576C3619ADC58A189F7E9A3A77FF95D

Validator #2 signature

D29CA8EDE7A6BD9EB64D73D2A6C5F093A0CBACEFAD2153A9FC174E74FA2A479C8AB1985ED2FE7EB4EAC6138643FB4AC19C90261033A79A27C2B3305C49D8ED04