Type
CONTRACT
Validation date
2024-01-25 15:05:44 UTC
Fee
0.74949049 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: 1706201820 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.995, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0x05AD310EB3DC36A4788E893640BA8E2CBABF479DEFD3E69F852C67AEC7379CBD,
    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: 0x0000B3C419BA2FDFA2DAEF6B333EB6E1E23EE55D4E0EFAA6B67AF97187FFCC927460, amount: 0.992015, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 0.002985, 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

    6928235940D28EC2436FD3ADC5F4C4347EE04A013D5D147693A20BE2C1D704E4FB4D991562F2DD2023EEAD1F697E905600ED9A375F40711FFCFA4EE1

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

000124C59F59A06DD769CFF8710F3DE05751FC6E10BC42AE55D5DFACB91FFD799B0E

Previous signature

C41B653627219E6BFDEF71C64C936AB6C8F0FECFAA3DDD16861F9CFD5599545BCD71576E01BD345FDE20E54B5B40CDD3D65B8EE6588D2A7AD1BBDA7C08DFC500

Origin signature

3044022075EBFD974D4C10AFB8500943B8F07412A5DA27B326F36EDA638BC6EC1D70A44C02200A22940470096D8B7F2060E9BBEC51397A3C7796E0BE142856D0DA528493207E

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00699DCD3A8378A69596934A29251A99BDB5F50D11083C9B9CBC00DDC3C0E7E0A7

Coordinator signature

E134F22B4BCE35E8E2548B1121F9AA47B54417296FA43E395872F0D3C1126B9194E97CC988CC83D25EF1CEBCE25FCB81E226054B8D2B91AA06595782454AE206

Validator #1 public key

000151C124A6211CD402FD1CFE560C5DB51ED0CBEF44B09B21A41206028E7E5942BF

Validator #1 signature

275CE43306A91795A575B2E967FE044B2144280F687F63398990E7444E7FBF3CFD1CE044C905C4E10851FCDACC11DBF1185A47AE2E9C205B335018F962720A01

Validator #2 public key

0001B01EEF96BA7E95FC844D456CE8868F18864519FC9532E1751C2035FD044DD5D0

Validator #2 signature

5F6E9AE5E5CC20E09B38DDF95F6583D37BB2B4FC2AC0B413FD17E4DAB432417A46544890231A0779B0E82D6EEBF016703D941FA6B4AE220E1E2D097D5AD42B0B