Skip to content

Commit

Permalink
feat: fix against contract data
Browse files Browse the repository at this point in the history
  • Loading branch information
SissonJ committed Aug 28, 2024
1 parent fae6c9c commit bad56e3
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 133 deletions.
125 changes: 62 additions & 63 deletions src/contracts/services/moneyMarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,44 @@ import { msgQueryMoneyMarketCollaterals, msgQueryMoneyMarketConfig, msgQueryMone
const parseMoneyMarketGetMarkets = (
response: GetMarketsResponse,
): ParsedGetMarketsResponse => ({
page: response.paginated_response.page,
pageSize: response.paginated_response.page_size,
totalPages: response.paginated_response.total_pages,
totalItems: response.paginated_response.total_items,
data: response.paginated_response.data.reduce((prev, cur) => ({
page: response.page,
pageSize: response.page_size,
totalPages: response.total_pages,
totalItems: response.total_items,
data: response.data.reduce((prev, cur) => ({
...prev,
[cur.market.market_token.address]: {
[cur.market_token.address]: {
marketToken: {
contractAddress: cur.market.market_token.address,
codeHash: cur.market.market_token.code_hash,
contractAddress: cur.market_token.address,
codeHash: cur.market_token.code_hash,
},
lToken: {
contractAddress: cur.market.l_token.address,
codeHash: cur.market.l_token.address,
contractAddress: cur.l_token.address,
codeHash: cur.l_token.address,
},
decimals: cur.market.decimals,
oracleKey: cur.market.oracle_key,
decimals: cur.decimals,
oracleKey: cur.oracle_key,
interest: {
base: cur.market.interest.inner.interest.linear?.base
?? cur.market.interest.inner.interest.piecewise_linear!.base,
slope1: cur.market.interest.inner.interest.linear?.slope
?? cur.market.interest.inner.interest.piecewise_linear!.slope1,
slope2: cur.market.interest.inner.interest.piecewise_linear?.slope2,
base: cur.interest.base,
slope1: cur.interest.slope1,
slope2: cur.interest.slope2,
optimalUtilisation:
cur.market.interest.inner.interest.piecewise_linear?.optimal_utilisation,
cur.interest.optimal_utilisation,
},
loanableAmount: cur.market.loanable,
lentAmount: cur.market.lent_amount,
lifetimeInterestPaid: cur.market.lifetime_interest_paid,
lifetimeInterestOwed: cur.market.lifetime_interest_owed,
interestPerUtoken: cur.market.interest_per_utoken,
lastInterestAccrued: new Date(cur.market.last_interest_accrued),
maxSupplyAmount: cur.market.max_supply,
flashLoanInterest: cur.market.flash_loan_interest,
supplyEnabled: cur.market.status.market_status.supply_enabled,
borrowEnabled: cur.market.status.market_status.borrow_enabled,
repayEnabled: cur.market.status.market_status.repay_enabled,
liquidationEnabled: cur.market.status.market_status.liquidation_enabled,
interestAccrualEnabled: cur.market.status.market_status.interest_accrual_enabled,
loanableAmount: cur.loanable,
lentAmount: cur.lent_amount,
lifetimeInterestPaid: cur.lifetime_interest_paid,
lifetimeInterestOwed: cur.lifetime_interest_owed,
interestPerUtoken: cur.interest_per_utoken,
lastInterestAccrued: new Date(cur.last_interest_accrued),
maxSupplyAmount: cur.max_supply,
daoInterestFee: cur.dao_interest_fee,
flashLoanInterest: cur.flash_loan_interest,
supplyEnabled: cur.status.supply_enabled,
borrowEnabled: cur.status.borrow_enabled,
repayEnabled: cur.status.repay_enabled,
liquidationEnabled: cur.status.liquidation_enabled,
interestAccrualEnabled: cur.status.interest_accrual_enabled,
},
}), {}),
});
Expand All @@ -80,27 +79,27 @@ const parseMoneyMarketConfig = (
response: ConfigResponse,
):ParsedConfigResponse => ({
adminAuth: {
contractAddress: response.config.admin_auth.address,
codeHash: response.config.admin_auth.code_hash,
contractAddress: response.admin_auth.address,
codeHash: response.admin_auth.code_hash,
},
queryAuth: {
contractAddress: response.config.query_auth.address,
codeHash: response.config.query_auth.code_hash,
contractAddress: response.query_auth.address,
codeHash: response.query_auth.code_hash,
},
oracle: {
contractAddress: response.config.oracle.address,
codeHash: response.config.query_auth.code_hash,
contractAddress: response.oracle.address,
codeHash: response.query_auth.code_hash,
},
feeCollector: response.config.fee_collector,
lTokenId: response.config.l_token_id,
lTokenCodeHash: response.config.l_token_code_hash,
lTokenBlockchainAdmin: response.config.l_token_blockchain_admin,
supplyEnabled: response.config.status.global_status.supply_enabled,
borrowEnabled: response.config.status.global_status.borrow_enabled,
repayEnabled: response.config.status.global_status.repay_enabled,
liquidationEnabled: response.config.status.global_status.liquidation_enabled,
interestAccrualEnabled: response.config.status.global_status.interest_accrual_enabled,
collateralDepositEnabled: response.config.status.global_status.collateral_deposit_enabled,
feeCollector: response.fee_collector,
lTokenId: response.l_token_id,
lTokenCodeHash: response.l_token_code_hash,
lTokenBlockchainAdmin: response.l_token_blockchain_admin,
supplyEnabled: response.status.supply_enabled,
borrowEnabled: response.status.borrow_enabled,
repayEnabled: response.status.repay_enabled,
liquidationEnabled: response.status.liquidation_enabled,
interestAccrualEnabled: response.status.interest_accrual_enabled,
collateralDepositEnabled: response.status.collateral_deposit_enabled,
});

/**
Expand All @@ -110,25 +109,25 @@ const parseMoneyMarketConfig = (
const parseMoneyMarketGetCollateral = (
response: GetCollateralResponse,
): ParsedGetCollateralResponse => ({
page: response.paginated_response.page,
pageSize: response.paginated_response.page_size,
totalPages: response.paginated_response.total_pages,
totalItems: response.paginated_response.total_items,
data: response.paginated_response.data.reduce((prev, cur) => ({
page: response.page,
pageSize: response.page_size,
totalPages: response.total_pages,
totalItems: response.total_items,
data: response.data.reduce((prev, cur) => ({
...prev,
[cur.collateral_state.token.address]: {
[cur.token.address]: {
token: {
contractAddress: cur.collateral_state.token.address,
codeHash: cur.collateral_state.token.code_hash,
contractAddress: cur.token.address,
codeHash: cur.token.code_hash,
},
collateralAmount: cur.collateral_state.amount,
decimals: cur.collateral_state.decimals,
maxInitialLtv: cur.collateral_state.max_initial_ltv,
liquidationThreshold: cur.collateral_state.liquidation_threshold,
liquidationDiscount: cur.collateral_state.liquidation_discount,
oracleKey: cur.collateral_state.oracle_key,
depositEnabled: cur.collateral_state.status.collateral_status.deposit_enabled,
liquidationEnabled: cur.collateral_state.status.collateral_status.liquidation_enabled,
collateralAmount: cur.amount,
decimals: cur.decimals,
maxInitialLtv: cur.max_initial_ltv,
liquidationThreshold: cur.liquidation_threshold,
liquidationDiscount: cur.liquidation_discount,
oracleKey: cur.oracle_key,
depositEnabled: cur.status.deposit_enabled,
liquidationEnabled: cur.status.liquidations_enabled,
},
}), {}),
});
Expand Down
1 change: 1 addition & 0 deletions src/types/contracts/moneyMarket/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type ParsedMarketResponse = {
interestPerUtoken: string,
lastInterestAccrued: Date,
maxSupplyAmount: string,
daoInterestFee: string,
flashLoanInterest: string,
supplyEnabled: boolean,
borrowEnabled: boolean,
Expand Down
117 changes: 47 additions & 70 deletions src/types/contracts/moneyMarket/response.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@
type ConfigResponse = {
config: {
admin_auth: {
address: string,
code_hash: string,
}
query_auth: {
address: string,
code_hash: string,
}
oracle: {
address: string,
code_hash: string,
}
fee_collector: string,
l_token_id: number,
l_token_code_hash: string,
l_token_blockchain_admin: string,
status: {
global_status: {
supply_enabled: boolean,
borrow_enabled: boolean,
repay_enabled: boolean,
liquidation_enabled: boolean,
interest_accrual_enabled: boolean,
collateral_deposit_enabled: boolean,
}
}
admin_auth: {
address: string,
code_hash: string,
}
query_auth: {
address: string,
code_hash: string,
}
oracle: {
address: string,
code_hash: string,
}
fee_collector: string,
l_token_id: number,
l_token_code_hash: string,
l_token_blockchain_admin: string,
status: {
supply_enabled: boolean,
borrow_enabled: boolean,
repay_enabled: boolean,
liquidation_enabled: boolean,
interest_accrual_enabled: boolean,
collateral_deposit_enabled: boolean,
}
}

type PaginatedResponse<T> = {
paginated_response: {
page: number,
page_size: number,
total_pages: number,
total_items: number,
data: T[]
}
page: number,
page_size: number,
total_pages: number,
total_items: number,
data: T[]
}

type MarketReponse = {
market: {
market_token: {
address: string,
code_hash: string,
Expand All @@ -52,61 +45,45 @@ type MarketReponse = {
decimals: number,
oracle_key: string,
interest: {
inner: {
interest: {
linear?: {
base: string,
slope: string,
},
piecewise_linear?: {
base: string,
slope1: string,
slope2: string,
optimal_utilisation: string,
}
}
}
}
base: string,
slope1: string,
slope2: string,
optimal_utilisation: string,
},
loanable: string,
lent_amount: string,
lifetime_interest_paid: string,
lifetime_interest_owed: string,
interest_per_utoken: string,
last_interest_accrued: number,
max_supply: string,
dao_interest_fee: string,
flash_loan_interest: string,
status: {
market_status: {
supply_enabled: boolean,
borrow_enabled: boolean,
repay_enabled: boolean,
liquidation_enabled: boolean,
interest_accrual_enabled: boolean,
}
}
}
}

type GetMarketsResponse = PaginatedResponse<MarketReponse>;

type CollateralReponse = {
collateral_state: {
token: {
address: string,
code_hash: string,
},
amount: string,
decimals: number,
max_initial_ltv: string,
liquidation_threshold: string,
liquidation_discount: string,
oracle_key: string,
status: {
collateral_status: {
deposit_enabled: boolean,
liquidation_enabled: boolean,
}
}
token: {
address: string,
code_hash: string,
},
amount: string,
decimals: number,
max_initial_ltv: string,
liquidation_threshold: string,
liquidation_discount: string,
oracle_key: string,
status: {
deposit_enabled: boolean,
liquidations_enabled: boolean,
}
}

Expand Down

0 comments on commit bad56e3

Please sign in to comment.