Type
CONTRACT
Validation date
2024-01-26 09:56:52 UTC
Fee
0.74618091 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: 1706270160 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 0.199, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

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

    A5BF58DE9B095E7059AC501BE016BFDB2B78FAA5A7B0E555472A244143DCA66A62A4920C33E0993EA6C196039A28117DF020782A8F3588FDBFA596A0

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

0001035FCF8E835C07770709C7FBE59F86CEEE6F13DA0DBF7C2126FD4A9D4D28D5EF

Previous signature

7DD1D24D4288A5B61085772DB2A37E874E22E8D9136313A7333AE1BE58E3E975410435DA97A4262D94C2DDB0741A043C233C2C1178FBEE9B7762025744930807

Origin signature

3044022049488968D17E1E277D5D77630DF67698B4A8C67AED1EEDFD787459E7E23611AF022002F01D73406962ADEC537BE2CD8DDFE50BBC166EEF46925BBEDB2921557607D1

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

0035804F52452AE8D7551306A9A8F038365DB87EBCF3ED31EEF09C21939FFEB9B9

Coordinator signature

780C5EE1CCC04382C4AEDF8016FE5254CE9F647EFAB7FC5E65E55111C4D6AB6A30CC8B06D1118C04B2C42A82C7AE0B94A8AEBE02D65978B989A90516A7348B04

Validator #1 public key

0001B01EEF96BA7E95FC844D456CE8868F18864519FC9532E1751C2035FD044DD5D0

Validator #1 signature

CAA5A766CF58FDA7E711F4329EFBD91E303EA74552E8B961C87069581DCE99C22FCE45880A6B66DD09AB391DA86AA7573B10F0BB6F8AE726785325427E87930B

Validator #2 public key

000177BA744AC778DC2D51A1B7C622E7AC4BD1E1AA8DA2D0FCE71BAAB7DAD0E020E0

Validator #2 signature

4B8C760E2F2414EB135E13E8E582956486C3B0873AF59B3C7FA698FB9BE4E4F134D2A667F4C7586AE0C6DEEC3C9A8BDF1808F35EF5795B775DC0B5FD4840AC07