Type
CONTRACT
Validation date
2024-01-09 15:50:07 UTC
Fee
0.74384331 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: 1704822420 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.04975, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

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

    029C60783CD93BEE6EA3E4C1B9F6E061AC3C218D4CBB6FD4158B5A087F5B7E70D32EECC63FF887BBF47CB0C6B2B602AD25FD0A603BEB469E7E029C3E

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

00013F93B990C1718DD6278CB974A65E09C63CE39DDA292185ED6A85B42CD3EF3906

Previous signature

B01B28BCD0E14A41DDBB6637A70B31E96785AAAB22843B9C7A0520FAC0584753442CC87168EA08EEA051E6F9CFE5A55AC409A73B24014E9F0FDBEC86D123570E

Origin signature

3044022013A17256BB49B1E6D630CA3557A7AFEE3116928FE721D38BB063CF70425FBB160220112A63900B7D09265BDADB4C9B03E97080713FE03EC2955EEC2397DE8F5651AB

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00BE8A606A34334B0EF21F57380E6B368CDE7CC083C3987F86815C8A71DA9678C6

Coordinator signature

AF941B0FCE95DB187E5E4DD9065350A0510BD89A8C569B95802957ABF576EF0CE4EE5F7777935448A17B49D97FF3C74200366AE91139580120882D59C7810C03

Validator #1 public key

00010F2A0E4C424582A94BD90E05FE6931628F91988ABBE387D365994F1F3FCF5A12

Validator #1 signature

E83363A03349C4C726CB32BB3EA2D898B573C954A981AF2C0762F91647C2AF364D908C78D8142BC6349855F507128841993DA09C73FFBB6EC789BAD59305AF03

Validator #2 public key

0001B01EEF96BA7E95FC844D456CE8868F18864519FC9532E1751C2035FD044DD5D0

Validator #2 signature

FE5275FD0426A271C186DFA666C7FA6104C1D7AEEEE4E65CC73FFD70615C2125CA1E5CE69740EAE7B9233737C4ABA20C4FF9212DA801952623402806459CA70B