Skip to content

Commit

Permalink
Add ironbank v1 Borrow Calls, Collateral Change Calls, Liquidation Ca…
Browse files Browse the repository at this point in the history
…lls and Repay Calls (#1259)

Co-authored-by: michael <[email protected]>
  • Loading branch information
mmibmm and m24927605 authored Jul 7, 2022
1 parent 923e03d commit d3e4722
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
27 changes: 27 additions & 0 deletions ethereum/ironbank/view_itokens.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CREATE OR REPLACE VIEW ironbank.view_itokens (symbol, contract_address, decimals, underlying_token_address, underlying_decimals, underlying_symbol) AS VALUES
('iCVX'::text, '\xE0B57FEEd45e7D908f2d0DaCd26F113Cf26715BF'::bytea, 8::numeric, '\x4e3FBD56CD56c3e72c1403e103b45Db9da5B9D2B'::bytea, 18::numeric, 'CVX'),
('iMIM'::text, '\x9e8E207083ffd5BDc3D99A1F32D1e6250869C1A9'::bytea, 8::numeric, '\x99D8a9C45b2ecA8864373A26D1459e3Dff1e17F3'::bytea, 18::numeric, 'MIM'),
('iZAR'::text, '\x672473908587b10e65DAB177Dbaeadcbb30BF40B'::bytea, 8::numeric, '\x81d66D255D47662b6B16f3C5bbfBb15283B05BC2'::bytea, 18::numeric, 'ZAR'),
('iCRV'::text, '\xB8c5af54bbDCc61453144CF472A9276aE36109F9'::bytea, 8::numeric, '\xD533a949740bb3306d119CC777fa900bA034cd52'::bytea, 18::numeric, 'CRV'),
('iAAVE'::text, '\x30190a3B52b5AB1daF70D46D72536F5171f22340'::bytea, 8::numeric, '\x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9'::bytea, 18::numeric, 'AAVE'),
('iCHF'::text, '\x1b3E95E8ECF7A7caB6c4De1b344F94865aBD12d5'::bytea, 8::numeric, '\x1CC481cE2BD2EC7Bf67d1Be64d4878b16078F309'::bytea, 18::numeric, 'ibCHF'),
('iGBP'::text, '\xecaB2C76f1A8359A06fAB5fA0CEea51280A97eCF'::bytea, 8::numeric, '\x69681f8fde45345C3870BCD5eaf4A05a60E7D227'::bytea, 18::numeric, 'ibGBP'),
('iAUD'::text, '\x86BBD9ac8B9B44C95FFc6BAAe58E25033B7548AA'::bytea, 8::numeric, '\xFAFdF0C4c1CB09d430Bf88c75D88BB46DAe09967'::bytea, 18::numeric, 'ibAUD'),
('iJPY'::text, '\x215F34af6557A6598DbdA9aa11cc556F5AE264B1'::bytea, 8::numeric, '\x5555f75e3d5278082200Fb451D1b6bA946D8e13b'::bytea, 18::numeric, 'ibJPY'),
('iKRW'::text, '\x3c9f5385c288cE438Ed55620938A4B967c080101'::bytea, 8::numeric, '\x95dfdc8161832e4ff7816ac4b6367ce201538253'::bytea, 18::numeric, 'ibKRW'),
('iEUR'::text, '\x00e5c0774A5F065c285068170b20393925C84BF3'::bytea, 8::numeric, '\x96E61422b6A9bA0e068B6c5ADd4fFaBC6a4aae27'::bytea, 18::numeric, 'ibEUR'),
('iUSDC'::text, '\x76Eb2FE28b36B3ee97F3Adae0C69606eeDB2A37c'::bytea, 8::numeric, '\xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'::bytea, 6::numeric, 'USDC'),
('iLINK'::text, '\xE7BFf2Da8A2f619c2586FB83938Fa56CE803aA16'::bytea, 8::numeric, '\x514910771AF9Ca656af840dff83E8264EcF986CA'::bytea, 18::numeric, 'LINK'),
('iYFI'::text, '\xFa3472f7319477c9bFEcdD66E4B948569E7621b9'::bytea, 8::numeric, '\x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e'::bytea, 18::numeric, 'YFI'),
('iSNX'::text, '\x12A9cC33A980DAa74E00cc2d1A0E74C57A93d12C'::bytea, 8::numeric, '\xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F'::bytea, 18::numeric, 'SNX'),
('iWBTC'::text, '\x8Fc8BFD80d6A9F17Fb98A373023d72531792B431'::bytea, 8::numeric, '\x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599'::bytea, 8::numeric, 'WBTC'),
('iEURS'::text, '\xA8caeA564811af0e92b1E044f3eDd18Fa9a73E4F'::bytea, 8::numeric, '\xdB25f211AB05b1c97D595516F45794528a807ad8'::bytea, 2::numeric, 'EURS'),
('iSEUR'::text, '\xCA55F9C4E77f7B8524178583b0f7c798De17fD54'::bytea, 8::numeric, '\xD71eCFF9342A5Ced620049e616c5035F1dB98620'::bytea, 18::numeric, 'SEUR'),
('iDPI'::text, '\x7736Ffb07104c0C400Bb0CC9A7C228452A732992'::bytea, 8::numeric, '\x1494CA1F11D487c2bBe4543E90080AeBa4BA3C2b'::bytea, 18::numeric, 'DPI'),
('iSUSD'::text, '\xa7c4054AFD3DbBbF5bFe80f41862b89ea05c9806'::bytea, 8::numeric, '\x57Ab1ec28D129707052df4dF418D58a2D46d5f51'::bytea, 18::numeric, 'SUSD'),
('iUSDT'::text, '\x48759F220ED983dB51fA7A8C0D2AAb8f3ce4166a'::bytea, 8::numeric, '\xdAC17F958D2ee523a2206206994597C13D831ec7'::bytea, 6::numeric, 'USDT'),
('iDAI'::text, '\x8e595470Ed749b85C6F7669de83EAe304C2ec68F'::bytea, 8::numeric, '\x6B175474E89094C44Da98b954EedeAC495271d0F'::bytea, 18::numeric, 'DAI'),
('iWETH'::text, '\x41c84c0e2EE0b740Cf0d31F63f3B6F627DC6b393'::bytea, 8::numeric, '\xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'::bytea, 18::numeric, 'WETH'),
('iSUSHI'::text, '\x226F3738238932BA0dB2319a8117D9555446102f'::bytea, 8::numeric, '\x6B3595068778DD592e39A122f4f5a5cF09C90fE2'::bytea, 18::numeric, 'SUSHI'),
('iUNI'::text, '\xFEEB92386A055E2eF7C2B598c872a4047a7dB59F'::bytea, 8::numeric, '\x1f9840a85d5aF5bf1D1762F925BDADdC4201F984'::bytea, 18::numeric, 'UNI')
;
19 changes: 19 additions & 0 deletions ethereum/lending/borrow.sql
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,25 @@ WITH borrow AS (

UNION ALL

-- IronBank V1
SELECT
'IronBank' AS project,
'1' AS version,
evt_block_number AS block_number,
evt_block_time AS block_time,
evt_tx_hash AS tx_hash,
evt_index,
NULL::integer[] as trace_address,
borrower,
i."underlying_token_address" AS asset_address,
"borrowAmount" AS asset_amount
FROM (
SELECT * FROM ironbank."CErc20Delegator_evt_Borrow" WHERE evt_block_time >= start_ts AND evt_block_time < end_ts
) events
LEFT JOIN ironbank.view_itokens i ON events.contract_address = i.contract_address

UNION ALL

-- MakerDAO
SELECT
'MakerDAO' AS project,
Expand Down
36 changes: 36 additions & 0 deletions ethereum/lending/collateral_change.sql
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,42 @@ WITH collateral_change AS (
) compound_redeem
LEFT JOIN compound.view_ctokens c ON compound_redeem.contract_address = c.contract_address

UNION ALL
-- IronBank add collateral
SELECT
'IronBank' AS project,
'1' AS version,
evt_block_number AS block_number,
evt_block_time AS block_time,
evt_tx_hash AS tx_hash,
evt_index,
NULL::integer[] AS trace_address,
minter AS borrower,
i."underlying_token_address" AS asset_address,
"mintAmount" AS asset_amount
FROM (
SELECT * FROM ironbank."CErc20Delegator_evt_Mint" WHERE evt_block_time >= start_ts AND evt_block_time < end_ts
) ironbank_add
LEFT JOIN ironbank.view_itokens i ON ironbank_add.contract_address = i.contract_address

UNION ALL
-- IronBank remove collateral
SELECT
'IronBank' AS project,
'1' AS version,
evt_block_number AS block_number,
evt_block_time AS block_time,
evt_tx_hash AS tx_hash,
evt_index,
NULL::integer[] AS trace_address,
redeemer AS borrower,
i."underlying_token_address" AS asset_address,
-"redeemAmount" AS asset_amount
FROM (
SELECT * FROM ironbank."CErc20Delegator_evt_Redeem" WHERE evt_block_time >= start_ts AND evt_block_time < end_ts
) ironbank_redeem
LEFT JOIN ironbank.view_itokens i ON ironbank_redeem.contract_address = i.contract_address

UNION ALL

-- MakerDAO add collateral
Expand Down
25 changes: 25 additions & 0 deletions ethereum/lending/liquidation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,31 @@ WITH liquidation AS (
FROM compound.view_ctokens) c_asset ON c.contract_address = c_asset.asset_contract_address

UNION ALL
-- IronBank liquidation

SELECT
'IronBank' AS project,
'1' AS version,
evt_block_number AS block_number,
evt_block_time AS block_time,
evt_tx_hash AS tx_hash,
evt_index,
NULL::integer[] AS trace_address,
borrower AS liquidated_borrower,
i_asset."asset_underlying_token_address" AS debt_to_cover_asset_address,
i_collateral."collateral_underlying_token_address" AS collateral_asset_address,
"repayAmount" AS debt_to_cover_amount
FROM (
SELECT * FROM ironbank."CErc20Delegator_evt_LiquidateBorrow" WHERE evt_block_time >= start_ts AND evt_block_time < end_ts
) i
LEFT JOIN (SELECT contract_address as collateral_contract_address,
underlying_token_address as collateral_underlying_token_address
FROM ironbank.view_itokens) i_collateral ON i."cTokenCollateral" = i_collateral.collateral_contract_address
LEFT JOIN (SELECT contract_address as asset_contract_address,
underlying_token_address as asset_underlying_token_address
FROM ironbank.view_itokens) i_asset ON i.contract_address = i_asset.asset_contract_address

UNION ALL
-- MakerDAO liquidation
SELECT
'MakerDAO' AS project,
Expand Down
18 changes: 18 additions & 0 deletions ethereum/lending/repay.sql
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,24 @@ WITH repays AS (
) compound
LEFT JOIN compound.view_ctokens c ON compound.contract_address = c.contract_address

UNION ALL
-- IronBank V1
SELECT
'IronBank' AS project,
'1' AS version,
evt_block_number AS block_number,
evt_block_time AS block_time,
evt_tx_hash AS tx_hash,
evt_index,
NULL::integer[] AS trace_address,
borrower,
i."underlying_token_address" AS asset_address,
"repayAmount" AS asset_amount
FROM (
SELECT * FROM ironbank."CErc20Delegator_evt_RepayBorrow" WHERE evt_block_time >= start_ts AND evt_block_time < end_ts
) ironbank
LEFT JOIN ironbank.view_itokens i ON ironbank.contract_address = i.contract_address

UNION ALL
--MAKER DAO

Expand Down

0 comments on commit d3e4722

Please sign in to comment.