Type
CONTRACT
Validation date
2023-12-09 15:26:50 UTC
Fee
0.70930451 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: 1702142760 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.00995, token_address: 0x00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

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

    51FA116D2CBFD1F886836A11D8356D56D5BB0E69F16C7365A99F15F3EA8DDF2299961E2CD2F1C6669C1864C20884A8748FC2D38C62711298A3C9637F

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

00015CB6DC693B7284B631BDC5FAA7A3A61E6521981256E75E74B237E6CD27A9B051

Previous signature

E63DD8461224E30FB1EA55B2E32CFAF0015FF5A4D6007094CC7C5E5222BC06152EA183F7A53D040E3F8CA2C4E5295A8C5569B27196B4B632EE9B0B6CD72BBA01

Origin signature

30440220108347823C639A38F73023B6B64192A6399EF03DD9C84588A3493AE5F54AEFBD022023437AD402E798824897C7C4301AEB0F45B2F1E1B00B020C44B864FED43F14D9

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

00D34D54D15445AFBE63CEA6432098CDAA8C8FC58BCC7BF7D736E32C31DB4AB3BB

Coordinator signature

4D14C8BAD6FE6E8385DD49E5CE36C0AE8F108FE0122957541484506A1139820B8B52AA9350CC83DE2EBDF52174372156D8A8CDC19EDD6AE3736194A77DA63A0F

Validator #1 public key

000151C124A6211CD402FD1CFE560C5DB51ED0CBEF44B09B21A41206028E7E5942BF

Validator #1 signature

87AA220238CF2F0B74682B75CCBEC23D5EB0B4625DD982CCDE03F5C0FF390F2253D6476536070C717985AE8FBFE67262B23B297B22D553FF7262F178F716E205

Validator #2 public key

0001B0A94804BF8ECC9897075C6207FF63EF4D339F57A0349888E6B77CD47DB53EF3

Validator #2 signature

E79B9EE7CFBD4F80D37FD54C2527FD8B2AE2279D2AF784BBCA2ACD7F778096CABC3208689478BC38932F7F3AB90AA8D4C4CB2E3F76F6A2AC2E8BFE7BC58F3504