Type
CONTRACT
Validation date
2024-01-06 10:14:53 UTC
Fee
0.71696325 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) == 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: 1704543240 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.2985, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

  condition triggered_by: transaction, on: reveal_secret(secret), as: [
    content: Crypto.hash(String.to_hex(secret)) == 0xD2CBC142852720EA0FD9C48BD72CA9D44A4543863C41F0E1A7BB9E726256854F,
    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: 0x00006B9CCB37C75E9FCA0AF14F7DA483D1962AA7E3652B2D737920FCB07F74D44FC4, amount: 0.2976045, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1
  Contract.add_token_transfer to: 0x0000749d250560bf06c079832e0e9a24509b1e440a45c33bd9448b41b6a056fc6201, amount: 8.955e-4, 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

    D85D4167FA2877D3611908CF5716C9DFAE42E1CDDD8723C0117AD7DEE74B0200FF544B99C145D001FF5BCFC43F621D5B71136194286C045419930DDC

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

000159DD4DB7A0D0F869F03227A0BA7C3F943520D15D8B0F47F3A383FED92D5C1BB5

Previous signature

BE1A490FFB3ABA6DD1258368250056419E23957EC1DE121373716824D7A9C4A3C1AC1EBA8BD69CF9D5E39060FEADB81DA818FE2918DB7CE89A4ACF22C1098805

Origin signature

3045022100E4EC28C5708578B1D4BE5BAA92ADB391826588BB33F5E8A9E2079888049E9EB102200AE973AB8029C345940280263E678BDFEDEBA16786129B1F97507AE39E0CA3DF

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

000FECEB75329433AE87F5CE9C078CE2DE8261B23E44B92C2F63BD311A7BBDAF4C

Coordinator signature

021B350054B9349B5454A14492D1F0FCB3F39CD2C033B15F49FAF41C3147C79C336C215EF22875FEB77160BE9764A81E42BD1C66AD88610DBB4946983FBB0F0A

Validator #1 public key

0001B01EEF96BA7E95FC844D456CE8868F18864519FC9532E1751C2035FD044DD5D0

Validator #1 signature

3B91658A4C3C7A1A6BCFD984209FC9D658C6BD67C4B7D724D6563C1A55B8BC6986F90D4ACD4710C743A6DAFC6376DB3621DE52B9A2130E4545EE2666F1914D03

Validator #2 public key

00010F2A0E4C424582A94BD90E05FE6931628F91988ABBE387D365994F1F3FCF5A12

Validator #2 signature

F234D2D748E3F570FDCF70E46F8F452E5CF6C769B11C72689A68B14EF7FAB3A5E5ABA1676CE95E1FF9F3ACAA8B70348C49069036D847423659A7BBC66C7C8F01