version: 2
models:
  - name: silver__swaps_intermediate_jupiterv6_2
    tests:
      - dbt_utils.unique_combination_of_columns:
          combination_of_columns:
            - TX_ID
            - INDEX
            - INNER_INDEX
            - SWAP_INDEX
          where: block_timestamp::date > current_date - 30
      - compare_model_subset:
          name: silver__swaps_intermediate_jupiterv6_2_business_logic_test
          compare_model: ref('testing__swaps_intermediate_jupiterv6_2')
          compare_columns: 
            - tx_id
            - swapper
            - from_mint
            - round(from_amount,2)
            - to_mint
            - round(to_amount,2)
            - swap_index
          model_condition: "where tx_id in ('33NLhAHDz2dAVRCqfgankDS2CAr78J1Q7LorotWhTaqcT2EDAVzPaWDK2sQsw4zSJM1KVXWzxvx6mDpvzAmNkzN1',
          '3DqnEWswNa8qD7GrqxUi7yyD2fgAk8GYdykHX6aZRQpxbVrdkj3rcFHPF13WuS7oMRs2gqtJGDcjCkDXzD5geprS',
          '5nhXU7f282fFdi3FynukwNLiybV5NYqptUNU6BJH7RpYRPe4mcporxadKmhC9ioxx3vJp9uVmMbXz35QffHTxrFz',
          '5YrfH1RDhZkhh98eikYFcuqRxHY8K87A7hBBFAasaJyCeMW1dr1nG5xNDps3e3GaHnt2cp1tssZJQS2eFaUwcPz9',
          'GD7mFaoiFFxRKEi4EfYbRHmCRN1Q7hCwrQaZbiRq998vXU7bwY22ET1SwXcgDYKSbVLVTmkbM7HgE7G1HSJDT4T',
          'JLHisghyiom2v1fY4z2tntjQYz7Fupe679pTJSuWaPvymEwEau9WvFbxGEyvvM1SPZqZPHKroLWqZkrrXtH9WkP',
          'LVwfUycnkCw93ywALBfm1zvBcx7sDT9HdTo8wYQooan9CsKTU7BmZLhwQ3mpRSMFCRhDm5Q5GFASAGUmjQTQrJj',
          '2HDxbrNSMrbGGu1xKKGNm3EbNmqaYxq2Dqpwe6tpKeLXevV2zCdA1feq61kfEVmDvu7mn9cwV9AbQWRE4VQbLkTY',
          'sbMujMpco3YpH1DSpBnU2gXU2xEbCkWcsg95HCHBXe3SsiEsEKYv4TAZjaSEGYKSCmp1hRBdoWxXWvDZbWPXoXD',
          '51zH6E9Q3KknnUwPpJeV9Au6zSzxT6ZmGbEW3v8Lk3GLjcUBosChbyWBWf7NTZEpBiqameEwRPCqio1XdsXPnC4k',
          '5vdYEWuHxJAwENhZdUAqsAaV7mxRVcxPQkS5V4m5yCroSpox1LG1LNLmQnpyfEBbQkikLhxWVYbBkTc9f3BGi5ZU',
          '3ysjbsjuwREA7QNvm8SmFv5fjkTzZysPn3D5SZWibKoiXPRgniqmV9e5tqz1BZBqmHkbdUQb6tQpoCk9yJcayQDk',
          '2G8raofwNadUPTAUWuuFbYtw18DGpqshRMkoVFU1LbyccfDKX1vFgv8QiPFmTq36UAjKaA12crGP3tcpMP94YAnD',
          '3B6UatG5gvCrGY5bMQUJaHUpbNXzn8iR92Ze7rsB1pmAmzdUtY1GZd7QSc2C1KgsR5g61skB5LqrM5j6QJoHXY35',
          '5UMtTnzJRZDnKYjM1nnVzU46gnys98EZySiUUkWEaWj2G82D7EhzxQHdPJ6nYDDd5T9dB7KanGQHKwWdXN5KXjGh',
          '3ho3m3EYmWy5T3GPvL83HQw2ntezXYXYiwqhJyV6izFGPUEkRMgtzT9Hp67ftvaXxCpbZH2W4LWTDR55G7DMEAcF',
          '3BBroFipCBy5oh8tktjJrJnDaAsfXVhKixhSTbBNyfKAt5Pa6Httav2dJjgqeU62k82cHoEEKf2wZoahz9bA7mRg',
          'P7hjHyhT9RJwJ2n8jd3srwKVyb9TR6UZwExT3T2VyGdYbQ5HLTb6iN4nR3NZdx39vKz1mZ7PkM5rxTScdZ79D1s')"  
    recent_date_filter: &recent_date_filter
      config:
        where: >
          /* this model does not work before this date as inner_swaps encoded data was not working. Use v1 model instead */
          block_timestamp::date >= '2023-08-03' 
          AND _inserted_timestamp >= current_date - 7
    columns:
      - name: BLOCK_TIMESTAMP
        description: "{{ doc('block_timestamp') }}"
        tests:
          - not_null: *recent_date_filter
          - dbt_expectations.expect_row_values_to_have_recent_data:
              datepart: day
              interval: 2
      - name: BLOCK_ID
        description: "{{ doc('block_id') }}"
        tests:
          - not_null: *recent_date_filter
      - name: TX_ID
        description: "{{ doc('tx_id') }}"
        tests:
          - not_null: *recent_date_filter
      - name: INDEX
        description: "{{ doc('event_index') }}"
        tests: 
          - not_null: *recent_date_filter
      - name: INNER_INDEX
        description: "{{ doc('inner_index') }}"
      - name: SWAP_INDEX
        description: "{{ doc('swaps_swap_index') }}"
        tests: 
          - not_null: *recent_date_filter
      - name: SUCCEEDED
        description: "{{ doc('tx_succeeded') }}"
        tests: 
          - not_null: *recent_date_filter
      - name: PROGRAM_ID
        description: "{{ doc('program_id') }}"
        tests: 
          - not_null: *recent_date_filter
      - name: SWAPPER
        description: "{{ doc('swaps_swapper') }}"
        tests: 
          - not_null:
              where: succeeded = TRUE AND _inserted_timestamp >= current_date - 7
      - name: FROM_MINT
        description:  "{{ doc('swaps_from_mint') }}"
        tests: 
          - not_null: *recent_date_filter
      - name: FROM_AMOUNT
        description:  "{{ doc('swaps_from_amt') }}"
        tests: 
          - not_null: *recent_date_filter
      - name: TO_MINT
        description:  "{{ doc('swaps_to_mint') }}"
        tests: 
          - not_null: *recent_date_filter
      - name: TO_AMOUNT
        description:  "{{ doc('swaps_to_amt') }}"
        tests: 
          - not_null: *recent_date_filter
      - name: IS_DCA_SWAP
        description: "Whether the swap was initiated by a Jupiter DCA. If value is NULL then it is NOT a DCA Swap"
        tests:
          - dbt_utils.expression_is_true:
              expression: "= True"
              config:
                where: >
                  swapper IN ('DCAKuApAuZtVNYLk3KTAVW9GLWVvPbnb5CxxRRmVgcTr','DCAKxn5PFNN1mBREPWGdk1RXg5aVH9rPErLfBFEi2Emb','DCAK36VfExkPdAkYUQg6ewgxyinvcEyPLyHjRbmveKFw','BFQ2te7ERN319HA87mn6NJ9oxMUvNxyifqEhUWHFTie9','JD1dHSqYkrXvqUVL8s6gzL1yB7kpYymsHfwsGxgwp55h','JD38n7ynKYcgPpF7k1BhXEeREu1KqptU93fVGy3S624k','JD25qVdtd65FoiXNmR89JjmoJdYk9sjYQeSTZAALFiMy')
                  AND _inserted_timestamp >= current_date - 7
                  AND block_timestamp >= '2024-05-12' /* last recorded date where some txs used the Beta DCA program (Betam4GuxvAes2uQ5vX8SackcxL5pxRuHowM5m2Ykmcq) */
                  AND dca_requester IS NOT NULL
      - name: DCA_REQUESTER
        description: "Original address that requested the DCA swap"
        tests:
          - not_null:
              config:
                where: >
                  is_dca_swap
                  AND _inserted_timestamp >= current_date - 7
                  AND block_timestamp >= '2024-05-12' /* last recorded date where some txs used the Beta DCA program (Betam4GuxvAes2uQ5vX8SackcxL5pxRuHowM5m2Ykmcq)  */
      - name: IS_LIMIT_SWAP
        description: "Whether the swap was initiated by a Jupiter limit order. If value is NULL then it is NOT a limit order swap"
        tests:
          - dbt_utils.expression_is_true:
              expression: "= True"
              config:
                where: >
                  swapper IN ('j1oAbxxiDUWvoHxEDhWE7THLjEkDQW2cSHYn2vttxTF','Gw9QoW4y72hFDVt3RRzyqcD4qrV4pSqjhMMzwdGunz6H','LoAFmGjxUL84rWHk4X6k8jzrw12Hmb5yyReUXfkFRY6','71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6','EccxYg7rViwYfn9EMoNu7sUaV82QGyFt6ewiQaH1GYjv','j1oeQoPeuEDmjvyMwBmCWexzCQup77kbKKxV59CnYbd','JTJ9Cz7i43DBeps5PZdX1QVKbEkbWegBzKPxhWgkAf1','j1opmdubY84LUeidrPCsSGskTCYmeJVzds1UWm6nngb','AfQ1oaudsGjvznX4JNEw671hi57JfWo4CWqhtkdgoVHU')
                  AND _inserted_timestamp >= current_date - 7
                  AND block_timestamp >= '2023-10-01'
                  AND limit_requester IS NOT NULL
      - name: LIMIT_REQUESTER
        description: "Original address that requested the limit order swap"
        tests:
          - not_null:
              config:
                where: >
                  is_limit_swap
                  AND _inserted_timestamp >= current_date - 7
                  AND block_timestamp >= '2023-10-01'
      - name: _INSERTED_TIMESTAMP
        description: "{{ doc('_inserted_timestamp') }}"
        tests: 
          - not_null
      - name: SWAPS_INTERMEDIATE_JUPITERV6_ID
        description: '{{ doc("pk") }}'   
        tests: 
          - unique: *recent_date_filter
      - name: INSERTED_TIMESTAMP
        description: '{{ doc("inserted_timestamp") }}'   
        tests: 
          - not_null: *recent_date_filter
      - name: MODIFIED_TIMESTAMP
        description: '{{ doc("modified_timestamp") }}' 
        tests: 
          - not_null: *recent_date_filter
      - name: _INVOCATION_ID
        description: '{{ doc("_invocation_id") }}' 
        tests: 
          - not_null: 
              name: test_silver__not_null_swaps_intermediate_jupiterv6_2__invocation_id
              <<: *recent_date_filter
