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

fix(#patch); Level Finance Arbitrum; fix negative balance error #2374

Merged
merged 7 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion deployment/deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -9154,7 +9154,7 @@
"status": "prod",
"versions": {
"schema": "1.3.1",
"subgraph": "1.0.1",
"subgraph": "1.0.2",
"methodology": "1.0.0"
},
"services": {
Expand Down
9 changes: 9 additions & 0 deletions subgraphs/level-finance/abis/Pool.json
Original file line number Diff line number Diff line change
Expand Up @@ -3003,6 +3003,15 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "token", "type": "address" }
],
"name": "poolBalances",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
4 changes: 2 additions & 2 deletions subgraphs/level-finance/src/common/constants.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export const DEFAULT_DECIMALS_PRECISION =
BigInt.fromI32(10).pow(DEFAULT_DECIMALS);

export const PRICE_FEED_PRECISION = BigInt.fromI32(10).pow(PRICE_FEED_DECIMALS);

export const FUNDING_RATE_PRECISION = BigDecimal.fromString("0.00001");
export enum Side {
LONG,
SHORT,
Expand All @@ -217,4 +217,4 @@ export namespace MasterChef {
}
export const INFLATION_INTERVAL = "TIMESTAMP";
export const STARTING_INFLATION_RATE = BIGINT_ZERO;
export const IS_COLLATERAL_IN_USD = {{isCollateralInUSD}}
export const IS_COLLATERAL_IN_USD = {{isCollateralInUSD}};
3 changes: 3 additions & 0 deletions subgraphs/level-finance/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { LpToken as LpTokenContract } from "../../generated/Pool/LpToken";
export function enumToPrefix(snake: string): string {
return snake.toLowerCase().replace("_", "-") + "-";
}
export function equalsIgnoreCase(a: string, b: string): boolean {
return a.replace("-", "_").toLowerCase() == b.replace("-", "_").toLowerCase();
}

export function readValue<T>(
callResult: ethereum.CallResult<T>,
Expand Down
27 changes: 21 additions & 6 deletions subgraphs/level-finance/src/modules/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import * as constants from "../common/constants";
import { SDK } from "../sdk/protocols/perpfutures";
import { Pool } from "../sdk/protocols/perpfutures/pool";
import { getOrCreateAccount } from "../common/initializers";
import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts";
import { Address, BigInt, Bytes, dataSource } from "@graphprotocol/graph-ts";
import { Pool as PoolContract } from "../../generated/Pool/Pool";
import { TransactionType } from "../sdk/protocols/perpfutures/enums";

export function transaction(
Expand All @@ -31,11 +32,25 @@ export function transaction(
const poolInputTokens = pool.getInputTokens();
const idx = pool.getInputTokens().indexOf(token.id);
const inputTokenBalances = pool.pool.inputTokenBalances;
if (transactionType === TransactionType.DEPOSIT) {
inputTokenBalances[idx] = inputTokenBalances[idx].plus(amount);
}
if (transactionType === TransactionType.WITHDRAW) {
inputTokenBalances[idx] = inputTokenBalances[idx].minus(amount);
const network = dataSource.network();
const poolContract = PoolContract.bind(Address.fromBytes(pool.getBytesID()));
if (utils.equalsIgnoreCase(network, constants.Network.ARBITRUM_ONE)) {
const tokenBalance = utils.readValue(
poolContract.try_poolBalances(Address.fromBytes(token.id)),
constants.BIGINT_ZERO
);
inputTokenBalances[idx] = tokenBalance;
} else {
shashwatS22 marked this conversation as resolved.
Show resolved Hide resolved
const poolTokenResult = poolContract.try_poolTokens(
Address.fromBytes(token.id)
);
if (!poolTokenResult.reverted) {
let tokenBalance = poolTokenResult.value.getPoolBalance();
if (!tokenBalance) {
tokenBalance = constants.BIGINT_ZERO;
}
inputTokenBalances[idx] = tokenBalance;
}
}
const amountsArray = new Array<BigInt>(poolInputTokens.length).fill(
constants.BIGINT_ZERO
Expand Down
Loading