Skip to content

Commit d3e4722

Browse files
mmibmmm24927605
andauthored
Add ironbank v1 Borrow Calls, Collateral Change Calls, Liquidation Calls and Repay Calls (#1259)
Co-authored-by: michael <[email protected]>
1 parent 923e03d commit d3e4722

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed

ethereum/ironbank/view_itokens.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
CREATE OR REPLACE VIEW ironbank.view_itokens (symbol, contract_address, decimals, underlying_token_address, underlying_decimals, underlying_symbol) AS VALUES
2+
('iCVX'::text, '\xE0B57FEEd45e7D908f2d0DaCd26F113Cf26715BF'::bytea, 8::numeric, '\x4e3FBD56CD56c3e72c1403e103b45Db9da5B9D2B'::bytea, 18::numeric, 'CVX'),
3+
('iMIM'::text, '\x9e8E207083ffd5BDc3D99A1F32D1e6250869C1A9'::bytea, 8::numeric, '\x99D8a9C45b2ecA8864373A26D1459e3Dff1e17F3'::bytea, 18::numeric, 'MIM'),
4+
('iZAR'::text, '\x672473908587b10e65DAB177Dbaeadcbb30BF40B'::bytea, 8::numeric, '\x81d66D255D47662b6B16f3C5bbfBb15283B05BC2'::bytea, 18::numeric, 'ZAR'),
5+
('iCRV'::text, '\xB8c5af54bbDCc61453144CF472A9276aE36109F9'::bytea, 8::numeric, '\xD533a949740bb3306d119CC777fa900bA034cd52'::bytea, 18::numeric, 'CRV'),
6+
('iAAVE'::text, '\x30190a3B52b5AB1daF70D46D72536F5171f22340'::bytea, 8::numeric, '\x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9'::bytea, 18::numeric, 'AAVE'),
7+
('iCHF'::text, '\x1b3E95E8ECF7A7caB6c4De1b344F94865aBD12d5'::bytea, 8::numeric, '\x1CC481cE2BD2EC7Bf67d1Be64d4878b16078F309'::bytea, 18::numeric, 'ibCHF'),
8+
('iGBP'::text, '\xecaB2C76f1A8359A06fAB5fA0CEea51280A97eCF'::bytea, 8::numeric, '\x69681f8fde45345C3870BCD5eaf4A05a60E7D227'::bytea, 18::numeric, 'ibGBP'),
9+
('iAUD'::text, '\x86BBD9ac8B9B44C95FFc6BAAe58E25033B7548AA'::bytea, 8::numeric, '\xFAFdF0C4c1CB09d430Bf88c75D88BB46DAe09967'::bytea, 18::numeric, 'ibAUD'),
10+
('iJPY'::text, '\x215F34af6557A6598DbdA9aa11cc556F5AE264B1'::bytea, 8::numeric, '\x5555f75e3d5278082200Fb451D1b6bA946D8e13b'::bytea, 18::numeric, 'ibJPY'),
11+
('iKRW'::text, '\x3c9f5385c288cE438Ed55620938A4B967c080101'::bytea, 8::numeric, '\x95dfdc8161832e4ff7816ac4b6367ce201538253'::bytea, 18::numeric, 'ibKRW'),
12+
('iEUR'::text, '\x00e5c0774A5F065c285068170b20393925C84BF3'::bytea, 8::numeric, '\x96E61422b6A9bA0e068B6c5ADd4fFaBC6a4aae27'::bytea, 18::numeric, 'ibEUR'),
13+
('iUSDC'::text, '\x76Eb2FE28b36B3ee97F3Adae0C69606eeDB2A37c'::bytea, 8::numeric, '\xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'::bytea, 6::numeric, 'USDC'),
14+
('iLINK'::text, '\xE7BFf2Da8A2f619c2586FB83938Fa56CE803aA16'::bytea, 8::numeric, '\x514910771AF9Ca656af840dff83E8264EcF986CA'::bytea, 18::numeric, 'LINK'),
15+
('iYFI'::text, '\xFa3472f7319477c9bFEcdD66E4B948569E7621b9'::bytea, 8::numeric, '\x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e'::bytea, 18::numeric, 'YFI'),
16+
('iSNX'::text, '\x12A9cC33A980DAa74E00cc2d1A0E74C57A93d12C'::bytea, 8::numeric, '\xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F'::bytea, 18::numeric, 'SNX'),
17+
('iWBTC'::text, '\x8Fc8BFD80d6A9F17Fb98A373023d72531792B431'::bytea, 8::numeric, '\x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599'::bytea, 8::numeric, 'WBTC'),
18+
('iEURS'::text, '\xA8caeA564811af0e92b1E044f3eDd18Fa9a73E4F'::bytea, 8::numeric, '\xdB25f211AB05b1c97D595516F45794528a807ad8'::bytea, 2::numeric, 'EURS'),
19+
('iSEUR'::text, '\xCA55F9C4E77f7B8524178583b0f7c798De17fD54'::bytea, 8::numeric, '\xD71eCFF9342A5Ced620049e616c5035F1dB98620'::bytea, 18::numeric, 'SEUR'),
20+
('iDPI'::text, '\x7736Ffb07104c0C400Bb0CC9A7C228452A732992'::bytea, 8::numeric, '\x1494CA1F11D487c2bBe4543E90080AeBa4BA3C2b'::bytea, 18::numeric, 'DPI'),
21+
('iSUSD'::text, '\xa7c4054AFD3DbBbF5bFe80f41862b89ea05c9806'::bytea, 8::numeric, '\x57Ab1ec28D129707052df4dF418D58a2D46d5f51'::bytea, 18::numeric, 'SUSD'),
22+
('iUSDT'::text, '\x48759F220ED983dB51fA7A8C0D2AAb8f3ce4166a'::bytea, 8::numeric, '\xdAC17F958D2ee523a2206206994597C13D831ec7'::bytea, 6::numeric, 'USDT'),
23+
('iDAI'::text, '\x8e595470Ed749b85C6F7669de83EAe304C2ec68F'::bytea, 8::numeric, '\x6B175474E89094C44Da98b954EedeAC495271d0F'::bytea, 18::numeric, 'DAI'),
24+
('iWETH'::text, '\x41c84c0e2EE0b740Cf0d31F63f3B6F627DC6b393'::bytea, 8::numeric, '\xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'::bytea, 18::numeric, 'WETH'),
25+
('iSUSHI'::text, '\x226F3738238932BA0dB2319a8117D9555446102f'::bytea, 8::numeric, '\x6B3595068778DD592e39A122f4f5a5cF09C90fE2'::bytea, 18::numeric, 'SUSHI'),
26+
('iUNI'::text, '\xFEEB92386A055E2eF7C2B598c872a4047a7dB59F'::bytea, 8::numeric, '\x1f9840a85d5aF5bf1D1762F925BDADdC4201F984'::bytea, 18::numeric, 'UNI')
27+
;

ethereum/lending/borrow.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,25 @@ WITH borrow AS (
120120

121121
UNION ALL
122122

123+
-- IronBank V1
124+
SELECT
125+
'IronBank' AS project,
126+
'1' AS version,
127+
evt_block_number AS block_number,
128+
evt_block_time AS block_time,
129+
evt_tx_hash AS tx_hash,
130+
evt_index,
131+
NULL::integer[] as trace_address,
132+
borrower,
133+
i."underlying_token_address" AS asset_address,
134+
"borrowAmount" AS asset_amount
135+
FROM (
136+
SELECT * FROM ironbank."CErc20Delegator_evt_Borrow" WHERE evt_block_time >= start_ts AND evt_block_time < end_ts
137+
) events
138+
LEFT JOIN ironbank.view_itokens i ON events.contract_address = i.contract_address
139+
140+
UNION ALL
141+
123142
-- MakerDAO
124143
SELECT
125144
'MakerDAO' AS project,

ethereum/lending/collateral_change.sql

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,42 @@ WITH collateral_change AS (
172172
) compound_redeem
173173
LEFT JOIN compound.view_ctokens c ON compound_redeem.contract_address = c.contract_address
174174

175+
UNION ALL
176+
-- IronBank add collateral
177+
SELECT
178+
'IronBank' AS project,
179+
'1' AS version,
180+
evt_block_number AS block_number,
181+
evt_block_time AS block_time,
182+
evt_tx_hash AS tx_hash,
183+
evt_index,
184+
NULL::integer[] AS trace_address,
185+
minter AS borrower,
186+
i."underlying_token_address" AS asset_address,
187+
"mintAmount" AS asset_amount
188+
FROM (
189+
SELECT * FROM ironbank."CErc20Delegator_evt_Mint" WHERE evt_block_time >= start_ts AND evt_block_time < end_ts
190+
) ironbank_add
191+
LEFT JOIN ironbank.view_itokens i ON ironbank_add.contract_address = i.contract_address
192+
193+
UNION ALL
194+
-- IronBank remove collateral
195+
SELECT
196+
'IronBank' AS project,
197+
'1' AS version,
198+
evt_block_number AS block_number,
199+
evt_block_time AS block_time,
200+
evt_tx_hash AS tx_hash,
201+
evt_index,
202+
NULL::integer[] AS trace_address,
203+
redeemer AS borrower,
204+
i."underlying_token_address" AS asset_address,
205+
-"redeemAmount" AS asset_amount
206+
FROM (
207+
SELECT * FROM ironbank."CErc20Delegator_evt_Redeem" WHERE evt_block_time >= start_ts AND evt_block_time < end_ts
208+
) ironbank_redeem
209+
LEFT JOIN ironbank.view_itokens i ON ironbank_redeem.contract_address = i.contract_address
210+
175211
UNION ALL
176212

177213
-- MakerDAO add collateral

ethereum/lending/liquidation.sql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,31 @@ WITH liquidation AS (
110110
FROM compound.view_ctokens) c_asset ON c.contract_address = c_asset.asset_contract_address
111111

112112
UNION ALL
113+
-- IronBank liquidation
114+
115+
SELECT
116+
'IronBank' AS project,
117+
'1' AS version,
118+
evt_block_number AS block_number,
119+
evt_block_time AS block_time,
120+
evt_tx_hash AS tx_hash,
121+
evt_index,
122+
NULL::integer[] AS trace_address,
123+
borrower AS liquidated_borrower,
124+
i_asset."asset_underlying_token_address" AS debt_to_cover_asset_address,
125+
i_collateral."collateral_underlying_token_address" AS collateral_asset_address,
126+
"repayAmount" AS debt_to_cover_amount
127+
FROM (
128+
SELECT * FROM ironbank."CErc20Delegator_evt_LiquidateBorrow" WHERE evt_block_time >= start_ts AND evt_block_time < end_ts
129+
) i
130+
LEFT JOIN (SELECT contract_address as collateral_contract_address,
131+
underlying_token_address as collateral_underlying_token_address
132+
FROM ironbank.view_itokens) i_collateral ON i."cTokenCollateral" = i_collateral.collateral_contract_address
133+
LEFT JOIN (SELECT contract_address as asset_contract_address,
134+
underlying_token_address as asset_underlying_token_address
135+
FROM ironbank.view_itokens) i_asset ON i.contract_address = i_asset.asset_contract_address
136+
137+
UNION ALL
113138
-- MakerDAO liquidation
114139
SELECT
115140
'MakerDAO' AS project,

ethereum/lending/repay.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ WITH repays AS (
118118
) compound
119119
LEFT JOIN compound.view_ctokens c ON compound.contract_address = c.contract_address
120120

121+
UNION ALL
122+
-- IronBank V1
123+
SELECT
124+
'IronBank' AS project,
125+
'1' AS version,
126+
evt_block_number AS block_number,
127+
evt_block_time AS block_time,
128+
evt_tx_hash AS tx_hash,
129+
evt_index,
130+
NULL::integer[] AS trace_address,
131+
borrower,
132+
i."underlying_token_address" AS asset_address,
133+
"repayAmount" AS asset_amount
134+
FROM (
135+
SELECT * FROM ironbank."CErc20Delegator_evt_RepayBorrow" WHERE evt_block_time >= start_ts AND evt_block_time < end_ts
136+
) ironbank
137+
LEFT JOIN ironbank.view_itokens i ON ironbank.contract_address = i.contract_address
138+
121139
UNION ALL
122140
--MAKER DAO
123141

0 commit comments

Comments
 (0)