Query editor
-- Amp Open Letters of Credit-- Dune query 8754667: https://dune.com/queries/8754667-- From dashboard: https://dune.com/ampdotxyz/amp-token---- Every currently open Anvil letter of credit collateralized with AMP,-- largest first. An LOC is open when it has no terminal event-- (LOCRedeemed / LOCCanceled / LOCConverted) and its latest expiration-- (LOCExtended-aware) is in the future. Collateral amounts reflect the-- latest LOCCollateralModified event where one exists. USD values use the-- latest prices; collateralization = AMP collateral value / credit value.---- Sibling of anvil-dashboard/anvil-open-locs.sql, restricted to-- collateralTokenAddress = AMP (0xfF20…95C2).WITHcreated AS (SELECTid, evt_block_time, evt_tx_hash, creator, beneficiary,collateralTokenAddress, collateralTokenAmount,creditedTokenAddress, creditedTokenAmount,collateralFactorBasisPoints, expirationTimestampFROM anvil_ethereum.letterofcredit_evt_loccreatedWHERE collateralTokenAddress = 0xfF20817765cB7f73d4bde2e66e067E58D11095C2UNION ALLSELECTid, evt_block_time, evt_tx_hash, creator, beneficiary,collateralTokenAddress, collateralTokenAmount,creditedTokenAddress, creditedTokenAmount,collateralFactorBasisPoints, expirationTimestampFROM anvil_ethereum.letterofcredit_evt_loccreatedv2WHERE collateralTokenAddress = 0xfF20817765cB7f73d4bde2e66e067E58D11095C2),terminal AS (SELECT id FROM anvil_ethereum.letterofcredit_evt_locredeemedUNIONSELECT id FROM anvil_ethereum.letterofcredit_evt_loccanceledUNIONSELECT id FROM anvil_ethereum.letterofcredit_evt_locconverted),latest_collateral AS (SELECT id, MAX_BY(newCollateralAmount, evt_block_number) AS amountFROM anvil_ethereum.letterofcredit_evt_loccollateralmodifiedGROUP BY 1),latest_expiry AS (SELECT id, MAX(newExpirationTimestamp) AS expirationFROM anvil_ethereum.letterofcredit_evt_locextendedGROUP BY 1),amp_price AS (SELECT priceFROM prices.latestWHERE blockchain = 'ethereum'AND contract_address = 0xfF20817765cB7f73d4bde2e66e067E58D11095C2),