Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#major); eBTC; new subgraph #2301

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ec49472
feat: price feed mappings including native btc price
gosuto-inzasheru Jun 19, 2023
df1daa4
feat: add support for hosted subgraph
gosuto-inzasheru Jun 20, 2023
e0ac3da
chore: record cli commands in notes
gosuto-inzasheru Jun 20, 2023
56c9755
chore: add urls
gosuto-inzasheru Jun 20, 2023
c089ce0
chore: yaml is always being built, no bool needed
gosuto-inzasheru Jun 20, 2023
ac9b6c3
Merge branch 'messari:master' into feat/sdk_pivot
gosuto-inzasheru Jun 21, 2023
7fff7c3
chore: add goerli bpt pools
gosuto-inzasheru Jun 21, 2023
9b80d8a
chore: consolidate sdk constants
gosuto-inzasheru Jun 21, 2023
df408af
fix: `constants.ts` got moved
gosuto-inzasheru Jun 23, 2023
18cdd15
fix: add missing type helper
gosuto-inzasheru Jun 23, 2023
2d4f042
feat: add `ActivePool` data source
gosuto-inzasheru Jun 28, 2023
264c215
fix: adjust relative import dir
gosuto-inzasheru Jun 28, 2023
a3746b3
fix: only comment actual lines in the functions
gosuto-inzasheru Jun 29, 2023
ea331db
fix: `decimalValue` needs to be `i32`
gosuto-inzasheru Jun 29, 2023
a97040c
fix: `decimalValue` needs to be of type `i32`
gosuto-inzasheru Jun 29, 2023
e435522
fix: add `PRICE_FEED` constant
gosuto-inzasheru Jun 29, 2023
3a6b4b5
perf: grab blocks and timestamps from actual event
gosuto-inzasheru Jun 30, 2023
24b3b0b
feat: update market with ebtc specifics
gosuto-inzasheru Jun 30, 2023
c576297
Merge pull request #21 from Badger-Finance/feat/init_protocol
gosuto-inzasheru Jun 30, 2023
015d1dd
refactor: add helper for instantiating data manager
gosuto-inzasheru Jun 30, 2023
adf0f81
chore: rename `_ERC20` to `ERC20`
gosuto-inzasheru Jun 30, 2023
4d14147
refactor: use data and token managers instead of custom functions
gosuto-inzasheru Jun 30, 2023
2be5864
chore: remove unused imports
gosuto-inzasheru Jun 30, 2023
45db46e
refactor: move all erc20 interfaces to `PriceFeed`
gosuto-inzasheru Jun 30, 2023
4d38a32
fix: correct name for protocol
gosuto-inzasheru Jun 30, 2023
5ef84cc
chore: clean up comments
gosuto-inzasheru Jul 5, 2023
c2b3977
chore: bump schema and sdk
gosuto-inzasheru Jul 5, 2023
e2f84c7
feat: handle `CdpUpdated`
gosuto-inzasheru Jul 5, 2023
9fe2cac
docs: add query that returns most important fields
gosuto-inzasheru Jul 5, 2023
3aeb340
fix: erc20 interface for prices is different from erc20
gosuto-inzasheru Jul 5, 2023
0bd8ffc
fix: more erc20 related changes
gosuto-inzasheru Jul 5, 2023
72dd798
Merge pull request #22 from Badger-Finance/feat/leverage_token_manager
gosuto-inzasheru Jul 7, 2023
b91c5d8
chore: update prices sdk to newer version
gosuto-inzasheru Jul 7, 2023
a241cda
Merge pull request #23 from Badger-Finance/chore/update_sdk_prices
gosuto-inzasheru Jul 7, 2023
6df8c23
chore: include abi
gosuto-inzasheru Jul 7, 2023
a6e3549
chore: include `BorrowerOperations` in template
gosuto-inzasheru Jul 7, 2023
e7901de
feat: track all events for now
gosuto-inzasheru Jul 11, 2023
3156e2a
feat: handle user deposits and withdrawals
gosuto-inzasheru Jul 11, 2023
32a75e7
feat: handle flash loans
gosuto-inzasheru Jul 11, 2023
903a679
fix: revert to previous price lib
gosuto-inzasheru Jul 11, 2023
fcaca03
chore: move `handelSystemDeployed` to `ActivePool`
gosuto-inzasheru Jul 11, 2023
0b7e947
fix: `handleSystemDeployed` is now in `ActivePool`
gosuto-inzasheru Jul 11, 2023
af160cd
fix: each data source needs its reference to the jsons
gosuto-inzasheru Jul 11, 2023
3bccffb
fix: functions need to be exported explicitly
gosuto-inzasheru Jul 11, 2023
08e8a86
docs: add instructions for deploying a scaffold subgraph
gosuto-inzasheru Jul 12, 2023
a5c7aed
chore: move `createLiquidate` to `CdpManager`
gosuto-inzasheru Jul 12, 2023
a9c3dc3
docs: extend query with lending protocol fields
gosuto-inzasheru Jul 14, 2023
1b9be2f
feat: handle liquidations
gosuto-inzasheru Jul 14, 2023
7714e36
fix: `CdpManager` needs price oracle abis
gosuto-inzasheru Jul 14, 2023
de0af46
feat: add borrows and repays, fix when delta is zero
gosuto-inzasheru Jul 14, 2023
1795d2b
docs: add `flashloans` to query
gosuto-inzasheru Jul 14, 2023
8074111
fix: listen for `CdpLiquidated` instead of `Liquidation`
gosuto-inzasheru Jul 14, 2023
af0b95d
docs: add liquidates to query
gosuto-inzasheru Jul 14, 2023
f2c9109
chore: add note about price calc
gosuto-inzasheru Jul 14, 2023
75e15ee
Merge pull request #24 from Badger-Finance/feat/include_borrow_ops
gosuto-inzasheru Jul 14, 2023
28a248b
Merge branch 'master' into feat/sdk_pivot
gosuto-inzasheru Jul 27, 2023
69966f8
style: lint for upstream
gosuto-inzasheru Jul 27, 2023
e06587e
perf: remove unused imports
gosuto-inzasheru Jul 27, 2023
cb073db
Merge branch 'master' into feat/sdk_pivot
gosuto-inzasheru Aug 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions deployment/deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -9148,5 +9148,38 @@
}
}
}
},
"ebtc": {
"schema": "lending",
"base": "ebtc",
"protocol": "ebtc",
"project": "ebtc",
"deployments": {
"ebtc-goerli": {
"network": "goerli",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When ebtc is deployed on mainnet, will we just change this? As a note, I think we will want to wait until a mainnet deployment to merge this PR too

"status": "dev",
"versions": {
"schema": "3.0.1",
"subgraph": "0.0.1",
"methodology": "0.0.1"
Comment on lines +9163 to +9164
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start version is 1.0.0

},
"files": {
"template": "ebtc.template.yaml"
},
"options": {
"prepare:constants": true
},
"services": {
"decentralized-network": {
"slug": "ebtc-goerli",
"query-id": "QmdZphstRBDgd6teT5dhQDZ84H6bsqwTy8tEj579JFhqwU"
},
"hosted-service": {
"slug": "ebtc-goerli",
"query-id": "ebtc-goerli"
}
}
}
}
}
}
1 change: 1 addition & 0 deletions schema-lending.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum Network {
OSMOSIS
MATIC # aka Polygon
GNOSIS
GOERLI
}

enum ProtocolType {
Expand Down
3 changes: 3 additions & 0 deletions subgraphs/_reference_/src/prices/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as XDAI from "../config/gnosis";
import * as CRONOS from "../config/cronos";
import * as AURORA from "../config/aurora";
import * as FANTOM from "../config/fantom";
import * as GOERLI from "../config/goerli";
import * as POLYGON from "../config/polygon";
import * as MAINNET from "../config/mainnet";
import * as HARMONY from "../config/harmony";
Expand Down Expand Up @@ -96,6 +97,8 @@ export function getConfig(): Configurations {
return new CELO.config();
} else if (network == FUSE.NETWORK_STRING) {
return new FUSE.config();
} else if (network == GOERLI.NETWORK_STRING) {
return new GOERLI.config();
}

return new TEMPLATE.config();
Expand Down
122 changes: 122 additions & 0 deletions subgraphs/_reference_/src/prices/config/goerli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/* eslint-disable @typescript-eslint/no-magic-numbers */
import { Address, BigInt } from "@graphprotocol/graph-ts";
import { Configurations, OracleContract } from "../common/types";

export const NETWORK_STRING = "goerli";

///////////////////////////////////////////////////////////////////////////
///////////////////// CALCULATIONS/ORACLE CONTRACT ////////////////////////
///////////////////////////////////////////////////////////////////////////

export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract();
export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract();
export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract();
export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract();

///////////////////////////////////////////////////////////////////////////
///////////////////////////// CURVE CONTRACT //////////////////////////////
///////////////////////////////////////////////////////////////////////////

export const CURVE_CALCULATIONS_ADDRESS = new OracleContract();
export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = [];

///////////////////////////////////////////////////////////////////////////
/////////////////////////// UNISWAP FORKS CONTRACT ////////////////////////
///////////////////////////////////////////////////////////////////////////

export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = [
new OracleContract("0x7a250d5630b4cf539739df2c5dacb4c659f2488d", 2822883), // Uniswap
];

///////////////////////////////////////////////////////////////////////////
/////////////////////////// BLACKLISTED TOKENS ////////////////////////////
///////////////////////////////////////////////////////////////////////////

export const YEARN_LENS_BLACKLIST: Address[] = [];
export const AAVE_ORACLE_BLACKLIST: Address[] = [];
export const CURVE_CALCULATIONS_BLACKSLIST: Address[] = [];
export const SUSHI_CALCULATIONS_BLACKSLIST: Address[] = [];

///////////////////////////////////////////////////////////////////////////
//////////////////////////// HARDCODED STABLES ////////////////////////////
///////////////////////////////////////////////////////////////////////////

export const HARDCODED_STABLES: Address[] = [];

///////////////////////////////////////////////////////////////////////////
///////////////////////////////// HELPERS /////////////////////////////////
///////////////////////////////////////////////////////////////////////////

export const USDC_TOKEN_DECIMALS = BigInt.fromI32(6);

export const ETH_ADDRESS = Address.fromString(
"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
);
export const WETH_ADDRESS = Address.fromString(
"0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6"
);
export const USDC_ADDRESS = Address.fromString(
"0xd87ba7a50b2e7e660f678a895e4b72e7cb4ccd9c"
);

export class config implements Configurations {
network(): string {
return NETWORK_STRING;
}

yearnLens(): OracleContract {
return YEARN_LENS_CONTRACT_ADDRESS;
}
chainLink(): OracleContract {
return CHAIN_LINK_CONTRACT_ADDRESS;
}
yearnLensBlacklist(): Address[] {
return YEARN_LENS_BLACKLIST;
}

aaveOracle(): OracleContract {
return AAVE_ORACLE_CONTRACT_ADDRESS;
}
aaveOracleBlacklist(): Address[] {
return AAVE_ORACLE_BLACKLIST;
}

curveCalculations(): OracleContract {
return CURVE_CALCULATIONS_ADDRESS;
}
curveCalculationsBlacklist(): Address[] {
return CURVE_CALCULATIONS_BLACKSLIST;
}

sushiCalculations(): OracleContract {
return SUSHISWAP_CALCULATIONS_ADDRESS;
}
sushiCalculationsBlacklist(): Address[] {
return SUSHI_CALCULATIONS_BLACKSLIST;
}

uniswapForks(): OracleContract[] {
return UNISWAP_FORKS_ROUTER_ADDRESSES;
}
curveRegistry(): OracleContract[] {
return CURVE_REGISTRY_ADDRESSES;
}

hardcodedStables(): Address[] {
return HARDCODED_STABLES;
}

ethAddress(): Address {
return ETH_ADDRESS;
}
wethAddress(): Address {
return WETH_ADDRESS;
}
usdcAddress(): Address {
return USDC_ADDRESS;
}

usdcTokenDecimals(): BigInt {
return USDC_TOKEN_DECIMALS;
}
}
2 changes: 2 additions & 0 deletions subgraphs/ebtc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# gets generated from constants.mustache
src/constants.ts
56 changes: 56 additions & 0 deletions subgraphs/ebtc/NOTES.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be merged into the README.md and the CLI Command portion is unnecessary

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
### URLs

- `hosted-service`: https://thegraph.com/hosted-service/subgraph/badger-finance/ebtc-goerli
- `decentralized-network`: https://testnet.thegraph.com/explorer/subgraphs/HgyK4pup4x75snqPrvTbbzeRsqPExHXmf2zRJPiXFjiU

### Goerli

- https://docs.chain.link/data-feeds/price-feeds/addresses#Goerli%20Testnet
- collEthCLFeed: `0xb4c4a493AB6356497713A78FFA6c60FB53517c63`
- ethBtcCLFeed: `0x779877A7B0D9E8603169DdbD7836e478b4624789`
- testMsig (account holder for decentralised subgraph studio): `0xfA87ce273f8C254F345Bc7de42F30e2d2FEe6779`
- ebtc/wbtc bpt pool: `0x070d3BDf2cd2e7067AFADC40857E8b657a057417`
- ebtc/collateral bpt pool: `0xB1d4d8eFe062C83F1e7C816E9fbd74D752927250`

### CLI Commands

```
graph auth --product subgraph-studio ***
messari b -l -s subgraph-studio ebtc -r ebtc-goerli -v 0.0.0 -d
```

```
graph auth --product hosted-service ***
messari b -l -s hosted-service ebtc -r badger-finance -d
```

```
graph init --product=hosted-service --protocol=ethereum --from-contract=0x7Cbde961F8aDB94c8A7660Abe1f3e647dbB8513f --network=goerli --index-events --start-block=9129595 --contract-name=CdpManager badger-finance/ebtc-goerli-scaffold

cd ebtc-goerli-scaffold

***change graph-cli and graph-ts version to "*" in package.json***

yarn

yarn codegen && yarn build && yarn deploy
```

**NOTE: Omit the `-d` for a dry run without deployment**

### Test GQL Queries

`PriceFeed`:

```
{
tokens(first: 5) {
id
name
symbol
decimals
lastPriceUSD
lastPriceBlockNumber
}
}
```
147 changes: 147 additions & 0 deletions subgraphs/ebtc/QUERY.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
protocols {
borrowerPermissionType
collateralizationType
cumulativeProtocolSideRevenueUSD
cumulativeSupplySideRevenueUSD
cumulativeTotalRevenueUSD
cumulativeUniqueUsers
id
lenderPermissionType
lendingType
methodologyVersion
name
network
poolCreatorPermissionType
protocol
protocolControlledValueUSD
riskType
schemaVersion
slug
subgraphVersion
totalPoolCount
totalValueLockedUSD
type
... on LendingProtocol {
borrowCount
borrowerPermissionType
collateralizationType
cumulativeBorrowUSD
cumulativeDepositUSD
cumulativeLiquidateUSD
cumulativePositionCount
cumulativeProtocolSideRevenueUSD
cumulativeSupplySideRevenueUSD
cumulativeTotalRevenueUSD
cumulativeUniqueBorrowers
cumulativeUniqueDepositors
cumulativeUniqueLiquidatees
cumulativeUniqueLiquidators
cumulativeUniqueUsers
depositCount
flashloanCount
id
lenderPermissionType
lendingType
liquidationCount
methodologyVersion
mintedTokenSupplies
name
network
openPositionCount
poolCreatorPermissionType
protocol
protocolControlledValueUSD
repayCount
rewardTokenEmissionsAmount
rewardTokenEmissionsUSD
riskType
schemaVersion
slug
subgraphVersion
totalBorrowBalanceUSD
totalDepositBalanceUSD
totalPoolCount
totalValueLockedUSD
transactionCount
transferCount
type
withdrawCount
}
}
tokens {
decimals
id
lastPriceBlockNumber
lastPriceUSD
name
symbol
type
}
accounts {
borrowCount
closedPositionCount
depositCount
flashloanCount
id
liquidateCount
liquidationCount
openPositionCount
positionCount
receivedCount
repayCount
rewardsClaimedUSD
transferredCount
withdrawCount
}
positions {
balance
blockNumberClosed
blockNumberOpened
borrowCount
depositCount
hashClosed
hashOpened
id
isCollateral
isIsolated
liquidationCount
receivedCount
repayCount
side
timestampClosed
timestampOpened
transferredCount
type
withdrawCount
}
flashloans {
amount
amountUSD
blockNumber
feeAmount
feeAmountUSD
gasLimit
gasPrice
gasUsed
hash
id
logIndex
nonce
timestamp
}
liquidates {
amount
amountUSD
blockNumber
gasLimit
gasPrice
gasUsed
hash
id
logIndex
nonce
profitUSD
timestamp
}
}
Loading
Loading