Type
CONTRACT
Validation date
2023-10-23 11:46:26 UTC
Fee
0.86474671 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: 1698068760 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 >= 1698068760
  ]

  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)) == 0x7EFD386CDCFE1EAE3693FDBCD8E805B8FF6C9D888A586C67E7D154972369227D,
    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: 0x0000CB30ACA5320066B4413E9D4190EA13562F3225BB5F49A975ABD91CFFDAFED88D, 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

    F752B2D2D59C6FE1FDBBB60C5BD0C59B334EFED1D4C3982615E7580C2C58ED68CE62C64F85D8B98706E2664BB829ED1AD2D8D3D56D85D5FA0A877C4E

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

000199DEAA24FC4CB3014C4E5EAF1F414B9C9673A5C477ED27487996562C10A88382

Previous signature

DF979D452E61F7F840BCB83AB575A8BC594424E06EF1E5C4A7D1BDDAA0CEBD84CBE3321CC8A398A5E92A57E52D9A105FA04A151C66EBBBFF6C3FEB8116F63D03

Origin signature

30450221008F737A4C989EC3AD1B27C95136CEA7948405692E8A99B5F374B1C61528573B9B02203FF9CFA44EFC003252AA45651B8AC7527CA117B7A5FC19E58DE5C5614593B437

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00FCAAD36F6E53363897A2C40F5BBB147F7D594E8A34E7B67B8582846832A27685

Coordinator signature

37243486D00688C4C7435D9AF143DD39E0DA130FA0EE1C130F7E2B74A188E0945C29B18FEB575F1D1D6C0C819B01462C52520F6E5B346A076180141F4F56D103

Validator #1 public key

0001500FBE298B79FFBDD5CCA1798F30FD88A53D26EC39DE5DDE1F4137B032A4BC34

Validator #1 signature

F12E29DBDE5FD0CB95CDEBA6163C7A0E5938A7529F3D3AAF3C895E4A2B723C0E16DEA55D0C9D697DEFB9B7915A9C926CEB1A5007F0A60AB391C35C117AE0A800

Validator #2 public key

00018A312AFA617E98B343D09AD2E73F0AB661DB0A59FB986D5DB8CE7664E14C25FC

Validator #2 signature

16D4EB610275D8E20AB1FBEA0F8109AE5DA0EF05D5F8FDBB663822DE54DE913186723C18E00EA4B0520F3332F89A8F532AC91F87C3D8DC0465BCF802C4360803