Skip to content

Commit

Permalink
Basin subgraph - add token order field (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
soilking authored Jul 16, 2024
2 parents 31d18d8 + a568927 commit f74c1bb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 3 additions & 1 deletion projects/subgraph-basin/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ type Well @entity {
symbol: String

" Tokens that need to be deposited to take a position in protocol. e.g. WETH and USDC to deposit into the WETH-USDC well. Array to account for multi-asset wells like Curve and Balancer "
# Check for forced indexing of tokens
tokens: [Token!]!

" The order of the tokens in the Well. The above `tokens` association will be sorted by id on any retrieval. "
tokenOrder: [Bytes!]!

" Pricing function contract used with this well "
wellFunction: WellFunction! @derivedFrom(field: "well")

Expand Down
18 changes: 5 additions & 13 deletions projects/subgraph-basin/src/templates/AquiferHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address } from "@graphprotocol/graph-ts";
import { Address, Bytes, log } from "@graphprotocol/graph-ts";
import { BoreWell } from "../../generated/Aquifer/Aquifer";
import { ERC20 } from "../../generated/Aquifer/ERC20";
import { Well } from "../../generated/templates";
Expand All @@ -17,22 +17,14 @@ export function handleBoreWell(event: BoreWell): void {
Well.create(event.params.well);

let well = createWell(event.params.well, event.params.implementation, event.params.tokens);

well.aquifer = event.address;

// A bit crude, but it works

const tokens: Bytes[] = [];
for (let i = 0; i < event.params.tokens.length; i++) {
loadOrCreateToken(event.params.tokens[i]);
}

if (event.params.tokens.length == 2) {
well.tokens = [event.params.tokens[0], event.params.tokens[1]];
} else if (event.params.tokens.length == 3) {
well.tokens = [event.params.tokens[0], event.params.tokens[1], event.params.tokens[2]];
} else if (event.params.tokens.length == 4) {
well.tokens = [event.params.tokens[0], event.params.tokens[1], event.params.tokens[2], event.params.tokens[3]];
tokens.push(loadOrCreateToken(event.params.tokens[i]).id);
}
well.tokens = tokens;
well.tokenOrder = tokens;

for (let i = 0; i < event.params.pumps.length; i++) {
loadOrCreatePump(event.params.pumps[i], event.params.well);
Expand Down
1 change: 1 addition & 0 deletions projects/subgraph-basin/src/utils/Well.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function createWell(wellAddress: Address, implementation: Address, inputT
well.aquifer = Bytes.empty();
well.implementation = implementation;
well.tokens = []; // This is currently set in the `handleBoreWell` function
well.tokenOrder = [];
well.createdTimestamp = ZERO_BI;
well.createdBlockNumber = ZERO_BI;
well.lpTokenSupply = ZERO_BI;
Expand Down
5 changes: 5 additions & 0 deletions projects/subgraph-basin/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,8 @@ templates:
- event: Sync(uint256[],uint256,address)
handler: handleSync
file: ./src/WellHandler.ts
# features:
# - grafting
# graft:
# base: QmWHi6hu2wXnyxBHHmQHwCQLoq5KkoTX2qLm8MdyVXTyTu
# block: 20216425

0 comments on commit f74c1bb

Please sign in to comment.