Skip to content

Commit

Permalink
fix: aqf extra price feeds and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
5lliot committed Aug 29, 2023
1 parent 9fbf488 commit eff34ea
Show file tree
Hide file tree
Showing 19 changed files with 507 additions and 49 deletions.
44 changes: 44 additions & 0 deletions db_scripts/local_testing/local_db_copy.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

--------
CREATE TABLE debt_sync (
last_calculated_at integer,
field_set boolean PRIMARY KEY
);

CREATE TABLE debts (
block_num integer,
cal_health_factor varchar(80),
cal_threshold_value_bi character varying(80),
cal_borrowed_amt_with_interest_bi character varying(80),
cal_total_value_bi character varying(80),
profit_underlying DOUBLE PRECISION,
profit_usd DOUBLE PRECISION,
collateral_usd DOUBLE PRECISION,
collateral_underlying DOUBLE PRECISION,
id SERIAL NOT NULL,
session_id character varying(100),
total_value_usd DOUBLE PRECISION
);
create index debts_block_num on debts using BTREE (block_num);
create index debts_session_id on debts using BTREE (session_id);


CREATE TABLE current_debts (
session_id varchar(80) PRIMARY KEY,
block_num integer,
cal_health_factor varchar(80),
cal_threshold_value DOUBLE PRECISION,
cal_threshold_value_bi varchar(80),
cal_borrowed_amt_with_interest DOUBLE PRECISION,
cal_borrowed_amt_with_interest_bi varchar(80),
cal_total_value DOUBLE PRECISION,
cal_total_value_bi varchar(80),
profit_usd DOUBLE PRECISION,
profit_underlying DOUBLE PRECISION,
collateral_usd DOUBLE PRECISION,
collateral_underlying DOUBLE PRECISION,
repay_amount DOUBLE PRECISION,
repay_amount_bi varchar(80));

ALTER TABLE ONLY current_debts
ADD CONSTRAINT current_debts_block_num_fkey FOREIGN KEY (block_num) REFERENCES blocks(id) ON DELETE CASCADE;
12 changes: 12 additions & 0 deletions db_scripts/local_testing/oracle_reset_to_block.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
update sync_adapters set last_sync=18020893-1 where type='PriceOracle'; -- priceoracle
delete from token_oracle where block_num>=18020893;
delete from price_feeds where block_num>=18020893;
delete from sync_adapters where type in ('QueryPriceFeed', 'ChainlinkPriceFeed', 'CompositeChainlinkPF') and discovered_at>=18020893;
update sync_adapters set last_sync= 18020893-1 , disabled='f' where type in ('QueryPriceFeed', 'ChainlinkPriceFeed', 'CompositeChainlinkPF') and last_sync>=18020893;


delete from debts where block_num>=18020893;
delete from current_debts where block_num>=18020893;
update debt_sync set last_calculated_at=18020893-1 where last_calculated_at>=18020893;

-- check if for QueryPriceFeed there is an entry of closure for tokens
12 changes: 0 additions & 12 deletions db_scripts/oracle_reset_to_block.sql

This file was deleted.

2 changes: 1 addition & 1 deletion debts/debt_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (eng *DebtEngine) liquidationCheck(debt *schemas.Debt, cmAddr, borrower str
HF: %s
CreditManager: %s
Borrower: %s Debt:%f %s
web: %s/accounts/history/%s`,
web: %s/accounts/%s`,
sendMsgAfterXBlocks,
debt.SessionId, debt.CalHealthFactor,
urls.ExplorerAddrUrl(cmAddr),
Expand Down
2 changes: 0 additions & 2 deletions ds/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ type RepositoryI interface {
GetExecuteParser() ExecuteParserI
// price feed/oracle funcs
GetTokenOracles() map[core.VersionType]map[string]*schemas.TokenOracle
// if returned value is nil, it means that token oracle hasn't been added yet.
GetOracleForV2Token(token string) *schemas.TokenOracle
DirectlyAddTokenOracle(tokenOracle *schemas.TokenOracle)
AddNewPriceOracleEvent(tokenOracle *schemas.TokenOracle, bounded bool)
//
Expand Down
7 changes: 3 additions & 4 deletions ds/repo_dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

type DummyRepo struct {
PFs []*schemas.PriceFeed
}

func (DummyRepo) Init() {
Expand Down Expand Up @@ -69,7 +70,8 @@ func (DummyRepo) DirectlyAddTokenOracle(tokenOracle *schemas.TokenOracle) {
func (DummyRepo) GetPrice(token string) *big.Int {
return nil
}
func (DummyRepo) AddPriceFeed(pf *schemas.PriceFeed) {
func (r *DummyRepo) AddPriceFeed(pf *schemas.PriceFeed) {
r.PFs = append(r.PFs, pf)
}

// token funcs
Expand Down Expand Up @@ -206,9 +208,6 @@ func (DummyRepo) GetYearnFeedAddrs() []string {
// has mutex lock
func (DummyRepo) AddNewPriceOracleEvent(tokenOracle *schemas.TokenOracle, bounded bool) {
}
func (DummyRepo) GetOracleForV2Token(token string) *schemas.TokenOracle {
return nil
}

func (DummyRepo) LoadLastDebtSync() int64 {
return 0
Expand Down
175 changes: 175 additions & 0 deletions jsonnet/aqf/blocks.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
{
data: [
{
blockNum: 4,
feed: '#YearnFeed_1',
isPriceInUSD: true,
price: 0.00001004,
priceBI: '1004',
roundId: 0,
token: '#Token_2',
},
{
blockNum: 4,
feed: '#YearnFeed_1',
isPriceInUSD: true,
price: 0.00001004,
priceBI: '1004',
roundId: 0,
token: '#Token_3',
},
{
blockNum: 4,
feed: '#YearnFeed_1',
isPriceInUSD: true,
price: 0.00001004,
priceBI: '1004',
roundId: 0,
token: '#Token_4',
},
{
blockNum: 11,
feed: '#YearnFeed_1',
isPriceInUSD: true,
price: 0.00001011,
priceBI: '1011',
roundId: 0,
token: '#Token_2',
},
{
blockNum: 11,
feed: '#YearnFeed_1',
isPriceInUSD: true,
price: 0.00001011,
priceBI: '1011',
roundId: 0,
token: '#Token_3',
},
{
blockNum: 11,
feed: '#YearnFeed_1',
isPriceInUSD: true,
price: 0.00001011,
priceBI: '1011',
roundId: 0,
token: '#Token_4',
},
{
blockNum: 26,
feed: '#YearnFeed_1',
isPriceInUSD: true,
price: 0.00001026,
priceBI: '1026',
roundId: 0,
token: '#Token_2',
},
{
blockNum: 26,
feed: '#YearnFeed_1',
isPriceInUSD: true,
price: 0.00001026,
priceBI: '1026',
roundId: 0,
token: '#Token_3',
},
{
blockNum: 26,
feed: '#YearnFeed_1',
isPriceInUSD: true,
price: 0.00001026,
priceBI: '1026',
roundId: 0,
token: '#Token_4',
},
{
blockNum: 51,
feed: '#YearnFeed_3',
isPriceInUSD: true,
price: 0.00003051,
priceBI: '3051',
roundId: 0,
token: '#Token_2',
},
{
blockNum: 51,
feed: '#YearnFeed_3',
isPriceInUSD: true,
price: 0.00003051,
priceBI: '3051',
roundId: 0,
token: '#Token_3',
},
{
blockNum: 51,
feed: '#YearnFeed_3',
isPriceInUSD: true,
price: 0.00003051,
priceBI: '3051',
roundId: 0,
token: '#Token_4',
},
{
blockNum: 53,
feed: '#YearnFeed_3',
isPriceInUSD: true,
price: 0.00003053,
priceBI: '3053',
roundId: 0,
token: '#Token_2',
},
{
blockNum: 53,
feed: '#YearnFeed_3',
isPriceInUSD: true,
price: 0.00003053,
priceBI: '3053',
roundId: 0,
token: '#Token_3',
},
{
blockNum: 53,
feed: '#YearnFeed_3',
isPriceInUSD: true,
price: 0.00003053,
priceBI: '3053',
roundId: 0,
token: '#Token_4',
},
{
blockNum: 56,
feed: '#YearnFeed_4',
isPriceInUSD: true,
price: 0.0001647,
priceBI: '16470',
roundId: 0,
token: '#Token_4',
},
{
blockNum: 58,
feed: '#YearnFeed_3',
isPriceInUSD: true,
price: 0.00003058,
priceBI: '3058',
roundId: 0,
token: '#Token_2',
},
{
blockNum: 58,
feed: '#YearnFeed_3',
isPriceInUSD: true,
price: 0.00003058,
priceBI: '3058',
roundId: 0,
token: '#Token_3',
},
{
blockNum: 58,
feed: '#YearnFeed_4',
isPriceInUSD: true,
price: 0.00004058,
priceBI: '4058',
roundId: 0,
token: '#Token_4',
},
],
}
89 changes: 89 additions & 0 deletions jsonnet/aqf/input.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
local utils = import '../utils.libsonnet';
local borrowedAmount = 4000;
local extraBorrowedAmount = 1000;
local initialAmount = 1000;
local newCollateral = 1;
{
mocks: {
syncAdapters: 'mocks/yearn_feed.json',
},
blocks: {
'4': {
calls: {
others: {
feaf968c: {
'#YearnFeed_1': utils.bigIntTopic(1004, 0),
'#YearnFeed_3': utils.bigIntTopic(3004, 0),
},
},
},
},
'11': {
calls: {
others: {
feaf968c: {
'#YearnFeed_1': utils.bigIntTopic(1011, 0),
},
},
},
},
'26': {
calls: {
others: {
feaf968c: {
'#YearnFeed_1': utils.bigIntTopic(1026, 0),
'#YearnFeed_3': utils.bigIntTopic(3026, 0),
},
},
},
},
'31': {
calls: {
others: {
feaf968c: {
'#YearnFeed_3': utils.bigIntTopic(3031, 0),
},
},
},
},
'51': {
calls: {
others: {
feaf968c: {
'#YearnFeed_1': utils.bigIntTopic(1051, 0),
'#YearnFeed_3': utils.bigIntTopic(3051, 0),
},
},
},
},
'53': {
calls: {
others: {
feaf968c: {
'#YearnFeed_1': utils.bigIntTopic(1053, 0),
'#YearnFeed_3': utils.bigIntTopic(3053, 0),
},
},
},
},
'56': {
calls: {
others: {
feaf968c: {
'#YearnFeed_4': utils.latestRoundData('4056'),
},
},
},
},
'58': {
calls: {
others: {
feaf968c: {
'#YearnFeed_3': utils.bigIntTopic(3058, 0),
'#YearnFeed_4': utils.bigIntTopic(4058, 0),
},
},
},
},
},
}
Loading

0 comments on commit eff34ea

Please sign in to comment.