Type
CONTRACT
Validation date
2023-12-08 16:40:10 UTC
Fee
0.73750477 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: 1702060740 do
    Contract.set_type "transfer"
    # Burn the non withdrawed tokens
  Contract.add_token_transfer to: 0x00000000000000000000000000000000000000000000000000000000000000000000, amount: 2.41180809, token_address: 0x00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1

    Contract.set_code ""
  end

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

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

    Contract.set_code ""
  end

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

    FA3AE5129BF0E8BE3ABBEAD0AB2FA58D31B50E87B68B7F8447BD74AFF4C91F9D6897A8840A8699D10E6AE52B5415E73D9DFBCAB958E104C05E05E726

    Authorized keys

    • 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F

Contract recipients (1)

Inputs (0)

Contract inputs (0)

Unspent outputs (1)

Proofs and signatures

Previous public key

00018E9942B9AF82F4730B68580439F0BC72D606AED7BC106682C308C8E8B57A1730

Previous signature

499538580D8DCD87695692343C6AD91A3245D6DB7CF9D4B66BCAA153FA2855407D8E86595686D667ECEE859F9EA9B2ECE13F37E5F0E54CA9F77EB0F80B91770E

Origin signature

304402205F9E5F1E3F58D0F9211A22FE1C52F78BC6B897945C6021D4A56608AB5B6EE4D702200C34E47BC630A148A740867A425BB6CD0C7F1FADB3A267214E66C954F25FA4CC

Proof of work

010104AB41291F847A601055AEDD1AF24FF76FA970D6441E2DCA3818A8319B004C96B27B8FEB1DA31A044BA0A4800B4353359735719EBB3A05F98393A9CC599C3FAFD6

Proof of integrity

0012A233C4F9BFA0252580267BBEA679FC0BCCA715F5C1498B02F53B11DE61E33C

Coordinator signature

635086716131E6BAF686EA2511B828D3DB4FB473995B826B83BFBCD0D8FD388E5CCBD9BCB9B584BAF3228558A74B64751AA360E4FCDE5C07BB33706ADEE7A708

Validator #1 public key

0001B0A94804BF8ECC9897075C6207FF63EF4D339F57A0349888E6B77CD47DB53EF3

Validator #1 signature

CF78BB7A57CD021475CF8CDA968F6EC2B397467C153C895CF72A294677670A70B5134287E7DD0CDEDD0A525EFDA9D659AE4552BB44F303DFD92D77080EF03F0C

Validator #2 public key

000151C124A6211CD402FD1CFE560C5DB51ED0CBEF44B09B21A41206028E7E5942BF

Validator #2 signature

6984C5754EAC31BDEF0AD3DE2B8A1635E393772787051F770F9D58ADF3CCCA98DE6B50C2493B4827052A321DFE93C593E5C02D45D4D0F44187E19FE6105D730A