From e2a938e89df84077f2c6bdf3328cddf795554590 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Tue, 4 Jun 2024 21:12:14 +0400 Subject: [PATCH 01/20] Initial version of Base subgraph --- subgraphs/base/config.json | 6 + .../TokenRecords-base/ChainlinkPriceFeed.ts | 907 ++++++++ .../base/generated/TokenRecords-base/ERC20.ts | 401 ++++ .../TokenRecords-base/UniswapV2Pair.ts | 1093 ++++++++++ .../TokenRecords-base/UniswapV3Pair.ts | 1880 +++++++++++++++++ subgraphs/base/generated/schema.ts | 1678 +++++++++++++++ subgraphs/base/src/contracts/Constants.ts | 70 + subgraphs/base/src/contracts/Contracts.ts | 70 + subgraphs/base/src/price/PriceBase.ts | 49 + subgraphs/base/src/price/PriceChainlink.ts | 39 + subgraphs/base/src/price/PriceLookup.ts | 71 + subgraphs/base/src/treasury/Assets.ts | 63 + .../base/src/treasury/OhmCalculations.ts | 117 + subgraphs/base/src/treasury/OwnedLiquidity.ts | 98 + subgraphs/base/src/treasury/TokenBalances.ts | 72 + subgraphs/base/subgraph.yaml | 38 + 16 files changed, 6652 insertions(+) create mode 100644 subgraphs/base/config.json create mode 100644 subgraphs/base/generated/TokenRecords-base/ChainlinkPriceFeed.ts create mode 100644 subgraphs/base/generated/TokenRecords-base/ERC20.ts create mode 100644 subgraphs/base/generated/TokenRecords-base/UniswapV2Pair.ts create mode 100644 subgraphs/base/generated/TokenRecords-base/UniswapV3Pair.ts create mode 100644 subgraphs/base/generated/schema.ts create mode 100644 subgraphs/base/src/contracts/Constants.ts create mode 100644 subgraphs/base/src/contracts/Contracts.ts create mode 100644 subgraphs/base/src/price/PriceBase.ts create mode 100644 subgraphs/base/src/price/PriceChainlink.ts create mode 100644 subgraphs/base/src/price/PriceLookup.ts create mode 100644 subgraphs/base/src/treasury/Assets.ts create mode 100644 subgraphs/base/src/treasury/OhmCalculations.ts create mode 100644 subgraphs/base/src/treasury/OwnedLiquidity.ts create mode 100644 subgraphs/base/src/treasury/TokenBalances.ts create mode 100644 subgraphs/base/subgraph.yaml diff --git a/subgraphs/base/config.json b/subgraphs/base/config.json new file mode 100644 index 00000000..6147f004 --- /dev/null +++ b/subgraphs/base/config.json @@ -0,0 +1,6 @@ +{ + "id": "QmRf3fo7tVsXsj9cQZSgT3Y2R67Hv41T1Ph559oQAmTLe1", + "org": "olympusdao", + "name": "protocol-metrics-base", + "version": "0.0.1" +} \ No newline at end of file diff --git a/subgraphs/base/generated/TokenRecords-base/ChainlinkPriceFeed.ts b/subgraphs/base/generated/TokenRecords-base/ChainlinkPriceFeed.ts new file mode 100644 index 00000000..b065e3e0 --- /dev/null +++ b/subgraphs/base/generated/TokenRecords-base/ChainlinkPriceFeed.ts @@ -0,0 +1,907 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + Address, + BigInt, + Bytes, + Entity, + ethereum, + JSONValue, + TypedMap, +} from "@graphprotocol/graph-ts"; + +export class AnswerUpdated extends ethereum.Event { + get params(): AnswerUpdated__Params { + return new AnswerUpdated__Params(this); + } +} + +export class AnswerUpdated__Params { + _event: AnswerUpdated; + + constructor(event: AnswerUpdated) { + this._event = event; + } + + get current(): BigInt { + return this._event.parameters[0].value.toBigInt(); + } + + get roundId(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } + + get updatedAt(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class NewRound extends ethereum.Event { + get params(): NewRound__Params { + return new NewRound__Params(this); + } +} + +export class NewRound__Params { + _event: NewRound; + + constructor(event: NewRound) { + this._event = event; + } + + get roundId(): BigInt { + return this._event.parameters[0].value.toBigInt(); + } + + get startedBy(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get startedAt(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class OwnershipTransferRequested extends ethereum.Event { + get params(): OwnershipTransferRequested__Params { + return new OwnershipTransferRequested__Params(this); + } +} + +export class OwnershipTransferRequested__Params { + _event: OwnershipTransferRequested; + + constructor(event: OwnershipTransferRequested) { + this._event = event; + } + + get from(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get to(): Address { + return this._event.parameters[1].value.toAddress(); + } +} + +export class OwnershipTransferred extends ethereum.Event { + get params(): OwnershipTransferred__Params { + return new OwnershipTransferred__Params(this); + } +} + +export class OwnershipTransferred__Params { + _event: OwnershipTransferred; + + constructor(event: OwnershipTransferred) { + this._event = event; + } + + get from(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get to(): Address { + return this._event.parameters[1].value.toAddress(); + } +} + +export class ChainlinkPriceFeed__getRoundDataResult { + value0: BigInt; + value1: BigInt; + value2: BigInt; + value3: BigInt; + value4: BigInt; + + constructor( + value0: BigInt, + value1: BigInt, + value2: BigInt, + value3: BigInt, + value4: BigInt, + ) { + this.value0 = value0; + this.value1 = value1; + this.value2 = value2; + this.value3 = value3; + this.value4 = value4; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromSignedBigInt(this.value1)); + map.set("value2", ethereum.Value.fromUnsignedBigInt(this.value2)); + map.set("value3", ethereum.Value.fromUnsignedBigInt(this.value3)); + map.set("value4", ethereum.Value.fromUnsignedBigInt(this.value4)); + return map; + } + + getRoundId(): BigInt { + return this.value0; + } + + getAnswer(): BigInt { + return this.value1; + } + + getStartedAt(): BigInt { + return this.value2; + } + + getUpdatedAt(): BigInt { + return this.value3; + } + + getAnsweredInRound(): BigInt { + return this.value4; + } +} + +export class ChainlinkPriceFeed__latestRoundDataResult { + value0: BigInt; + value1: BigInt; + value2: BigInt; + value3: BigInt; + value4: BigInt; + + constructor( + value0: BigInt, + value1: BigInt, + value2: BigInt, + value3: BigInt, + value4: BigInt, + ) { + this.value0 = value0; + this.value1 = value1; + this.value2 = value2; + this.value3 = value3; + this.value4 = value4; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromSignedBigInt(this.value1)); + map.set("value2", ethereum.Value.fromUnsignedBigInt(this.value2)); + map.set("value3", ethereum.Value.fromUnsignedBigInt(this.value3)); + map.set("value4", ethereum.Value.fromUnsignedBigInt(this.value4)); + return map; + } + + getRoundId(): BigInt { + return this.value0; + } + + getAnswer(): BigInt { + return this.value1; + } + + getStartedAt(): BigInt { + return this.value2; + } + + getUpdatedAt(): BigInt { + return this.value3; + } + + getAnsweredInRound(): BigInt { + return this.value4; + } +} + +export class ChainlinkPriceFeed__proposedGetRoundDataResult { + value0: BigInt; + value1: BigInt; + value2: BigInt; + value3: BigInt; + value4: BigInt; + + constructor( + value0: BigInt, + value1: BigInt, + value2: BigInt, + value3: BigInt, + value4: BigInt, + ) { + this.value0 = value0; + this.value1 = value1; + this.value2 = value2; + this.value3 = value3; + this.value4 = value4; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromSignedBigInt(this.value1)); + map.set("value2", ethereum.Value.fromUnsignedBigInt(this.value2)); + map.set("value3", ethereum.Value.fromUnsignedBigInt(this.value3)); + map.set("value4", ethereum.Value.fromUnsignedBigInt(this.value4)); + return map; + } + + getRoundId(): BigInt { + return this.value0; + } + + getAnswer(): BigInt { + return this.value1; + } + + getStartedAt(): BigInt { + return this.value2; + } + + getUpdatedAt(): BigInt { + return this.value3; + } + + getAnsweredInRound(): BigInt { + return this.value4; + } +} + +export class ChainlinkPriceFeed__proposedLatestRoundDataResult { + value0: BigInt; + value1: BigInt; + value2: BigInt; + value3: BigInt; + value4: BigInt; + + constructor( + value0: BigInt, + value1: BigInt, + value2: BigInt, + value3: BigInt, + value4: BigInt, + ) { + this.value0 = value0; + this.value1 = value1; + this.value2 = value2; + this.value3 = value3; + this.value4 = value4; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromSignedBigInt(this.value1)); + map.set("value2", ethereum.Value.fromUnsignedBigInt(this.value2)); + map.set("value3", ethereum.Value.fromUnsignedBigInt(this.value3)); + map.set("value4", ethereum.Value.fromUnsignedBigInt(this.value4)); + return map; + } + + getRoundId(): BigInt { + return this.value0; + } + + getAnswer(): BigInt { + return this.value1; + } + + getStartedAt(): BigInt { + return this.value2; + } + + getUpdatedAt(): BigInt { + return this.value3; + } + + getAnsweredInRound(): BigInt { + return this.value4; + } +} + +export class ChainlinkPriceFeed extends ethereum.SmartContract { + static bind(address: Address): ChainlinkPriceFeed { + return new ChainlinkPriceFeed("ChainlinkPriceFeed", address); + } + + accessController(): Address { + const result = super.call( + "accessController", + "accessController():(address)", + [], + ); + + return result[0].toAddress(); + } + + try_accessController(): ethereum.CallResult
{ + const result = super.tryCall( + "accessController", + "accessController():(address)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + aggregator(): Address { + const result = super.call("aggregator", "aggregator():(address)", []); + + return result[0].toAddress(); + } + + try_aggregator(): ethereum.CallResult
{ + const result = super.tryCall("aggregator", "aggregator():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + decimals(): i32 { + const result = super.call("decimals", "decimals():(uint8)", []); + + return result[0].toI32(); + } + + try_decimals(): ethereum.CallResult { + const result = super.tryCall("decimals", "decimals():(uint8)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toI32()); + } + + description(): string { + const result = super.call("description", "description():(string)", []); + + return result[0].toString(); + } + + try_description(): ethereum.CallResult { + const result = super.tryCall("description", "description():(string)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toString()); + } + + getAnswer(_roundId: BigInt): BigInt { + const result = super.call("getAnswer", "getAnswer(uint256):(int256)", [ + ethereum.Value.fromUnsignedBigInt(_roundId), + ]); + + return result[0].toBigInt(); + } + + try_getAnswer(_roundId: BigInt): ethereum.CallResult { + const result = super.tryCall("getAnswer", "getAnswer(uint256):(int256)", [ + ethereum.Value.fromUnsignedBigInt(_roundId), + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + getRoundData(_roundId: BigInt): ChainlinkPriceFeed__getRoundDataResult { + const result = super.call( + "getRoundData", + "getRoundData(uint80):(uint80,int256,uint256,uint256,uint80)", + [ethereum.Value.fromUnsignedBigInt(_roundId)], + ); + + return new ChainlinkPriceFeed__getRoundDataResult( + result[0].toBigInt(), + result[1].toBigInt(), + result[2].toBigInt(), + result[3].toBigInt(), + result[4].toBigInt(), + ); + } + + try_getRoundData( + _roundId: BigInt, + ): ethereum.CallResult { + const result = super.tryCall( + "getRoundData", + "getRoundData(uint80):(uint80,int256,uint256,uint256,uint80)", + [ethereum.Value.fromUnsignedBigInt(_roundId)], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new ChainlinkPriceFeed__getRoundDataResult( + value[0].toBigInt(), + value[1].toBigInt(), + value[2].toBigInt(), + value[3].toBigInt(), + value[4].toBigInt(), + ), + ); + } + + getTimestamp(_roundId: BigInt): BigInt { + const result = super.call("getTimestamp", "getTimestamp(uint256):(uint256)", [ + ethereum.Value.fromUnsignedBigInt(_roundId), + ]); + + return result[0].toBigInt(); + } + + try_getTimestamp(_roundId: BigInt): ethereum.CallResult { + const result = super.tryCall( + "getTimestamp", + "getTimestamp(uint256):(uint256)", + [ethereum.Value.fromUnsignedBigInt(_roundId)], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + latestAnswer(): BigInt { + const result = super.call("latestAnswer", "latestAnswer():(int256)", []); + + return result[0].toBigInt(); + } + + try_latestAnswer(): ethereum.CallResult { + const result = super.tryCall("latestAnswer", "latestAnswer():(int256)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + latestRound(): BigInt { + const result = super.call("latestRound", "latestRound():(uint256)", []); + + return result[0].toBigInt(); + } + + try_latestRound(): ethereum.CallResult { + const result = super.tryCall("latestRound", "latestRound():(uint256)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + latestRoundData(): ChainlinkPriceFeed__latestRoundDataResult { + const result = super.call( + "latestRoundData", + "latestRoundData():(uint80,int256,uint256,uint256,uint80)", + [], + ); + + return new ChainlinkPriceFeed__latestRoundDataResult( + result[0].toBigInt(), + result[1].toBigInt(), + result[2].toBigInt(), + result[3].toBigInt(), + result[4].toBigInt(), + ); + } + + try_latestRoundData(): ethereum.CallResult { + const result = super.tryCall( + "latestRoundData", + "latestRoundData():(uint80,int256,uint256,uint256,uint80)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new ChainlinkPriceFeed__latestRoundDataResult( + value[0].toBigInt(), + value[1].toBigInt(), + value[2].toBigInt(), + value[3].toBigInt(), + value[4].toBigInt(), + ), + ); + } + + latestTimestamp(): BigInt { + const result = super.call( + "latestTimestamp", + "latestTimestamp():(uint256)", + [], + ); + + return result[0].toBigInt(); + } + + try_latestTimestamp(): ethereum.CallResult { + const result = super.tryCall( + "latestTimestamp", + "latestTimestamp():(uint256)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + owner(): Address { + const result = super.call("owner", "owner():(address)", []); + + return result[0].toAddress(); + } + + try_owner(): ethereum.CallResult
{ + const result = super.tryCall("owner", "owner():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + phaseAggregators(param0: i32): Address { + const result = super.call( + "phaseAggregators", + "phaseAggregators(uint16):(address)", + [ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(param0))], + ); + + return result[0].toAddress(); + } + + try_phaseAggregators(param0: i32): ethereum.CallResult
{ + const result = super.tryCall( + "phaseAggregators", + "phaseAggregators(uint16):(address)", + [ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(param0))], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + phaseId(): i32 { + const result = super.call("phaseId", "phaseId():(uint16)", []); + + return result[0].toI32(); + } + + try_phaseId(): ethereum.CallResult { + const result = super.tryCall("phaseId", "phaseId():(uint16)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toI32()); + } + + proposedAggregator(): Address { + const result = super.call( + "proposedAggregator", + "proposedAggregator():(address)", + [], + ); + + return result[0].toAddress(); + } + + try_proposedAggregator(): ethereum.CallResult
{ + const result = super.tryCall( + "proposedAggregator", + "proposedAggregator():(address)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + proposedGetRoundData( + _roundId: BigInt, + ): ChainlinkPriceFeed__proposedGetRoundDataResult { + const result = super.call( + "proposedGetRoundData", + "proposedGetRoundData(uint80):(uint80,int256,uint256,uint256,uint80)", + [ethereum.Value.fromUnsignedBigInt(_roundId)], + ); + + return new ChainlinkPriceFeed__proposedGetRoundDataResult( + result[0].toBigInt(), + result[1].toBigInt(), + result[2].toBigInt(), + result[3].toBigInt(), + result[4].toBigInt(), + ); + } + + try_proposedGetRoundData( + _roundId: BigInt, + ): ethereum.CallResult { + const result = super.tryCall( + "proposedGetRoundData", + "proposedGetRoundData(uint80):(uint80,int256,uint256,uint256,uint80)", + [ethereum.Value.fromUnsignedBigInt(_roundId)], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new ChainlinkPriceFeed__proposedGetRoundDataResult( + value[0].toBigInt(), + value[1].toBigInt(), + value[2].toBigInt(), + value[3].toBigInt(), + value[4].toBigInt(), + ), + ); + } + + proposedLatestRoundData(): ChainlinkPriceFeed__proposedLatestRoundDataResult { + const result = super.call( + "proposedLatestRoundData", + "proposedLatestRoundData():(uint80,int256,uint256,uint256,uint80)", + [], + ); + + return new ChainlinkPriceFeed__proposedLatestRoundDataResult( + result[0].toBigInt(), + result[1].toBigInt(), + result[2].toBigInt(), + result[3].toBigInt(), + result[4].toBigInt(), + ); + } + + try_proposedLatestRoundData(): ethereum.CallResult { + const result = super.tryCall( + "proposedLatestRoundData", + "proposedLatestRoundData():(uint80,int256,uint256,uint256,uint80)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new ChainlinkPriceFeed__proposedLatestRoundDataResult( + value[0].toBigInt(), + value[1].toBigInt(), + value[2].toBigInt(), + value[3].toBigInt(), + value[4].toBigInt(), + ), + ); + } + + version(): BigInt { + const result = super.call("version", "version():(uint256)", []); + + return result[0].toBigInt(); + } + + try_version(): ethereum.CallResult { + const result = super.tryCall("version", "version():(uint256)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } +} + +export class ConstructorCall extends ethereum.Call { + get inputs(): ConstructorCall__Inputs { + return new ConstructorCall__Inputs(this); + } + + get outputs(): ConstructorCall__Outputs { + return new ConstructorCall__Outputs(this); + } +} + +export class ConstructorCall__Inputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } + + get _aggregator(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get _accessController(): Address { + return this._call.inputValues[1].value.toAddress(); + } +} + +export class ConstructorCall__Outputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } +} + +export class AcceptOwnershipCall extends ethereum.Call { + get inputs(): AcceptOwnershipCall__Inputs { + return new AcceptOwnershipCall__Inputs(this); + } + + get outputs(): AcceptOwnershipCall__Outputs { + return new AcceptOwnershipCall__Outputs(this); + } +} + +export class AcceptOwnershipCall__Inputs { + _call: AcceptOwnershipCall; + + constructor(call: AcceptOwnershipCall) { + this._call = call; + } +} + +export class AcceptOwnershipCall__Outputs { + _call: AcceptOwnershipCall; + + constructor(call: AcceptOwnershipCall) { + this._call = call; + } +} + +export class ConfirmAggregatorCall extends ethereum.Call { + get inputs(): ConfirmAggregatorCall__Inputs { + return new ConfirmAggregatorCall__Inputs(this); + } + + get outputs(): ConfirmAggregatorCall__Outputs { + return new ConfirmAggregatorCall__Outputs(this); + } +} + +export class ConfirmAggregatorCall__Inputs { + _call: ConfirmAggregatorCall; + + constructor(call: ConfirmAggregatorCall) { + this._call = call; + } + + get _aggregator(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class ConfirmAggregatorCall__Outputs { + _call: ConfirmAggregatorCall; + + constructor(call: ConfirmAggregatorCall) { + this._call = call; + } +} + +export class ProposeAggregatorCall extends ethereum.Call { + get inputs(): ProposeAggregatorCall__Inputs { + return new ProposeAggregatorCall__Inputs(this); + } + + get outputs(): ProposeAggregatorCall__Outputs { + return new ProposeAggregatorCall__Outputs(this); + } +} + +export class ProposeAggregatorCall__Inputs { + _call: ProposeAggregatorCall; + + constructor(call: ProposeAggregatorCall) { + this._call = call; + } + + get _aggregator(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class ProposeAggregatorCall__Outputs { + _call: ProposeAggregatorCall; + + constructor(call: ProposeAggregatorCall) { + this._call = call; + } +} + +export class SetControllerCall extends ethereum.Call { + get inputs(): SetControllerCall__Inputs { + return new SetControllerCall__Inputs(this); + } + + get outputs(): SetControllerCall__Outputs { + return new SetControllerCall__Outputs(this); + } +} + +export class SetControllerCall__Inputs { + _call: SetControllerCall; + + constructor(call: SetControllerCall) { + this._call = call; + } + + get _accessController(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class SetControllerCall__Outputs { + _call: SetControllerCall; + + constructor(call: SetControllerCall) { + this._call = call; + } +} + +export class TransferOwnershipCall extends ethereum.Call { + get inputs(): TransferOwnershipCall__Inputs { + return new TransferOwnershipCall__Inputs(this); + } + + get outputs(): TransferOwnershipCall__Outputs { + return new TransferOwnershipCall__Outputs(this); + } +} + +export class TransferOwnershipCall__Inputs { + _call: TransferOwnershipCall; + + constructor(call: TransferOwnershipCall) { + this._call = call; + } + + get _to(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class TransferOwnershipCall__Outputs { + _call: TransferOwnershipCall; + + constructor(call: TransferOwnershipCall) { + this._call = call; + } +} diff --git a/subgraphs/base/generated/TokenRecords-base/ERC20.ts b/subgraphs/base/generated/TokenRecords-base/ERC20.ts new file mode 100644 index 00000000..9621a171 --- /dev/null +++ b/subgraphs/base/generated/TokenRecords-base/ERC20.ts @@ -0,0 +1,401 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + Address, + BigInt, + Bytes, + Entity, + ethereum, + JSONValue, + TypedMap, +} from "@graphprotocol/graph-ts"; + +export class Approval extends ethereum.Event { + get params(): Approval__Params { + return new Approval__Params(this); + } +} + +export class Approval__Params { + _event: Approval; + + constructor(event: Approval) { + this._event = event; + } + + get owner(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get spender(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get value(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class Transfer extends ethereum.Event { + get params(): Transfer__Params { + return new Transfer__Params(this); + } +} + +export class Transfer__Params { + _event: Transfer; + + constructor(event: Transfer) { + this._event = event; + } + + get from(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get to(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get value(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class ERC20 extends ethereum.SmartContract { + static bind(address: Address): ERC20 { + return new ERC20("ERC20", address); + } + + name(): string { + const result = super.call("name", "name():(string)", []); + + return result[0].toString(); + } + + try_name(): ethereum.CallResult { + const result = super.tryCall("name", "name():(string)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toString()); + } + + approve(_spender: Address, _value: BigInt): boolean { + const result = super.call("approve", "approve(address,uint256):(bool)", [ + ethereum.Value.fromAddress(_spender), + ethereum.Value.fromUnsignedBigInt(_value), + ]); + + return result[0].toBoolean(); + } + + try_approve(_spender: Address, _value: BigInt): ethereum.CallResult { + const result = super.tryCall("approve", "approve(address,uint256):(bool)", [ + ethereum.Value.fromAddress(_spender), + ethereum.Value.fromUnsignedBigInt(_value), + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + totalSupply(): BigInt { + const result = super.call("totalSupply", "totalSupply():(uint256)", []); + + return result[0].toBigInt(); + } + + try_totalSupply(): ethereum.CallResult { + const result = super.tryCall("totalSupply", "totalSupply():(uint256)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + transferFrom(_from: Address, _to: Address, _value: BigInt): boolean { + const result = super.call( + "transferFrom", + "transferFrom(address,address,uint256):(bool)", + [ + ethereum.Value.fromAddress(_from), + ethereum.Value.fromAddress(_to), + ethereum.Value.fromUnsignedBigInt(_value), + ], + ); + + return result[0].toBoolean(); + } + + try_transferFrom( + _from: Address, + _to: Address, + _value: BigInt, + ): ethereum.CallResult { + const result = super.tryCall( + "transferFrom", + "transferFrom(address,address,uint256):(bool)", + [ + ethereum.Value.fromAddress(_from), + ethereum.Value.fromAddress(_to), + ethereum.Value.fromUnsignedBigInt(_value), + ], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + decimals(): i32 { + const result = super.call("decimals", "decimals():(uint8)", []); + + return result[0].toI32(); + } + + try_decimals(): ethereum.CallResult { + const result = super.tryCall("decimals", "decimals():(uint8)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toI32()); + } + + balanceOf(_owner: Address): BigInt { + const result = super.call("balanceOf", "balanceOf(address):(uint256)", [ + ethereum.Value.fromAddress(_owner), + ]); + + return result[0].toBigInt(); + } + + try_balanceOf(_owner: Address): ethereum.CallResult { + const result = super.tryCall("balanceOf", "balanceOf(address):(uint256)", [ + ethereum.Value.fromAddress(_owner), + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + symbol(): string { + const result = super.call("symbol", "symbol():(string)", []); + + return result[0].toString(); + } + + try_symbol(): ethereum.CallResult { + const result = super.tryCall("symbol", "symbol():(string)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toString()); + } + + transfer(_to: Address, _value: BigInt): boolean { + const result = super.call("transfer", "transfer(address,uint256):(bool)", [ + ethereum.Value.fromAddress(_to), + ethereum.Value.fromUnsignedBigInt(_value), + ]); + + return result[0].toBoolean(); + } + + try_transfer(_to: Address, _value: BigInt): ethereum.CallResult { + const result = super.tryCall("transfer", "transfer(address,uint256):(bool)", [ + ethereum.Value.fromAddress(_to), + ethereum.Value.fromUnsignedBigInt(_value), + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + allowance(_owner: Address, _spender: Address): BigInt { + const result = super.call( + "allowance", + "allowance(address,address):(uint256)", + [ + ethereum.Value.fromAddress(_owner), + ethereum.Value.fromAddress(_spender), + ], + ); + + return result[0].toBigInt(); + } + + try_allowance( + _owner: Address, + _spender: Address, + ): ethereum.CallResult { + const result = super.tryCall( + "allowance", + "allowance(address,address):(uint256)", + [ + ethereum.Value.fromAddress(_owner), + ethereum.Value.fromAddress(_spender), + ], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } +} + +export class ApproveCall extends ethereum.Call { + get inputs(): ApproveCall__Inputs { + return new ApproveCall__Inputs(this); + } + + get outputs(): ApproveCall__Outputs { + return new ApproveCall__Outputs(this); + } +} + +export class ApproveCall__Inputs { + _call: ApproveCall; + + constructor(call: ApproveCall) { + this._call = call; + } + + get _spender(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get _value(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class ApproveCall__Outputs { + _call: ApproveCall; + + constructor(call: ApproveCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} + +export class TransferFromCall extends ethereum.Call { + get inputs(): TransferFromCall__Inputs { + return new TransferFromCall__Inputs(this); + } + + get outputs(): TransferFromCall__Outputs { + return new TransferFromCall__Outputs(this); + } +} + +export class TransferFromCall__Inputs { + _call: TransferFromCall; + + constructor(call: TransferFromCall) { + this._call = call; + } + + get _from(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get _to(): Address { + return this._call.inputValues[1].value.toAddress(); + } + + get _value(): BigInt { + return this._call.inputValues[2].value.toBigInt(); + } +} + +export class TransferFromCall__Outputs { + _call: TransferFromCall; + + constructor(call: TransferFromCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} + +export class TransferCall extends ethereum.Call { + get inputs(): TransferCall__Inputs { + return new TransferCall__Inputs(this); + } + + get outputs(): TransferCall__Outputs { + return new TransferCall__Outputs(this); + } +} + +export class TransferCall__Inputs { + _call: TransferCall; + + constructor(call: TransferCall) { + this._call = call; + } + + get _to(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get _value(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class TransferCall__Outputs { + _call: TransferCall; + + constructor(call: TransferCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} + +export class DefaultCall extends ethereum.Call { + get inputs(): DefaultCall__Inputs { + return new DefaultCall__Inputs(this); + } + + get outputs(): DefaultCall__Outputs { + return new DefaultCall__Outputs(this); + } +} + +export class DefaultCall__Inputs { + _call: DefaultCall; + + constructor(call: DefaultCall) { + this._call = call; + } +} + +export class DefaultCall__Outputs { + _call: DefaultCall; + + constructor(call: DefaultCall) { + this._call = call; + } +} diff --git a/subgraphs/base/generated/TokenRecords-base/UniswapV2Pair.ts b/subgraphs/base/generated/TokenRecords-base/UniswapV2Pair.ts new file mode 100644 index 00000000..cd337614 --- /dev/null +++ b/subgraphs/base/generated/TokenRecords-base/UniswapV2Pair.ts @@ -0,0 +1,1093 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + Address, + BigInt, + Bytes, + Entity, + ethereum, + JSONValue, + TypedMap, +} from "@graphprotocol/graph-ts"; + +export class Approval extends ethereum.Event { + get params(): Approval__Params { + return new Approval__Params(this); + } +} + +export class Approval__Params { + _event: Approval; + + constructor(event: Approval) { + this._event = event; + } + + get owner(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get spender(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get value(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class Burn extends ethereum.Event { + get params(): Burn__Params { + return new Burn__Params(this); + } +} + +export class Burn__Params { + _event: Burn; + + constructor(event: Burn) { + this._event = event; + } + + get sender(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get amount0(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } + + get amount1(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } + + get to(): Address { + return this._event.parameters[3].value.toAddress(); + } +} + +export class Mint extends ethereum.Event { + get params(): Mint__Params { + return new Mint__Params(this); + } +} + +export class Mint__Params { + _event: Mint; + + constructor(event: Mint) { + this._event = event; + } + + get sender(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get amount0(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } + + get amount1(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class Swap extends ethereum.Event { + get params(): Swap__Params { + return new Swap__Params(this); + } +} + +export class Swap__Params { + _event: Swap; + + constructor(event: Swap) { + this._event = event; + } + + get sender(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get amount0In(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } + + get amount1In(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } + + get amount0Out(): BigInt { + return this._event.parameters[3].value.toBigInt(); + } + + get amount1Out(): BigInt { + return this._event.parameters[4].value.toBigInt(); + } + + get to(): Address { + return this._event.parameters[5].value.toAddress(); + } +} + +export class Sync extends ethereum.Event { + get params(): Sync__Params { + return new Sync__Params(this); + } +} + +export class Sync__Params { + _event: Sync; + + constructor(event: Sync) { + this._event = event; + } + + get reserve0(): BigInt { + return this._event.parameters[0].value.toBigInt(); + } + + get reserve1(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } +} + +export class Transfer extends ethereum.Event { + get params(): Transfer__Params { + return new Transfer__Params(this); + } +} + +export class Transfer__Params { + _event: Transfer; + + constructor(event: Transfer) { + this._event = event; + } + + get from(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get to(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get value(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class UniswapV2Pair__burnResult { + value0: BigInt; + value1: BigInt; + + constructor(value0: BigInt, value1: BigInt) { + this.value0 = value0; + this.value1 = value1; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromUnsignedBigInt(this.value1)); + return map; + } + + getAmount0(): BigInt { + return this.value0; + } + + getAmount1(): BigInt { + return this.value1; + } +} + +export class UniswapV2Pair__getReservesResult { + value0: BigInt; + value1: BigInt; + value2: BigInt; + + constructor(value0: BigInt, value1: BigInt, value2: BigInt) { + this.value0 = value0; + this.value1 = value1; + this.value2 = value2; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromUnsignedBigInt(this.value1)); + map.set("value2", ethereum.Value.fromUnsignedBigInt(this.value2)); + return map; + } + + get_reserve0(): BigInt { + return this.value0; + } + + get_reserve1(): BigInt { + return this.value1; + } + + get_blockTimestampLast(): BigInt { + return this.value2; + } +} + +export class UniswapV2Pair extends ethereum.SmartContract { + static bind(address: Address): UniswapV2Pair { + return new UniswapV2Pair("UniswapV2Pair", address); + } + + DOMAIN_SEPARATOR(): Bytes { + const result = super.call( + "DOMAIN_SEPARATOR", + "DOMAIN_SEPARATOR():(bytes32)", + [], + ); + + return result[0].toBytes(); + } + + try_DOMAIN_SEPARATOR(): ethereum.CallResult { + const result = super.tryCall( + "DOMAIN_SEPARATOR", + "DOMAIN_SEPARATOR():(bytes32)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBytes()); + } + + MINIMUM_LIQUIDITY(): BigInt { + const result = super.call( + "MINIMUM_LIQUIDITY", + "MINIMUM_LIQUIDITY():(uint256)", + [], + ); + + return result[0].toBigInt(); + } + + try_MINIMUM_LIQUIDITY(): ethereum.CallResult { + const result = super.tryCall( + "MINIMUM_LIQUIDITY", + "MINIMUM_LIQUIDITY():(uint256)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + PERMIT_TYPEHASH(): Bytes { + const result = super.call( + "PERMIT_TYPEHASH", + "PERMIT_TYPEHASH():(bytes32)", + [], + ); + + return result[0].toBytes(); + } + + try_PERMIT_TYPEHASH(): ethereum.CallResult { + const result = super.tryCall( + "PERMIT_TYPEHASH", + "PERMIT_TYPEHASH():(bytes32)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBytes()); + } + + allowance(param0: Address, param1: Address): BigInt { + const result = super.call( + "allowance", + "allowance(address,address):(uint256)", + [ethereum.Value.fromAddress(param0), ethereum.Value.fromAddress(param1)], + ); + + return result[0].toBigInt(); + } + + try_allowance(param0: Address, param1: Address): ethereum.CallResult { + const result = super.tryCall( + "allowance", + "allowance(address,address):(uint256)", + [ethereum.Value.fromAddress(param0), ethereum.Value.fromAddress(param1)], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + approve(spender: Address, value: BigInt): boolean { + const result = super.call("approve", "approve(address,uint256):(bool)", [ + ethereum.Value.fromAddress(spender), + ethereum.Value.fromUnsignedBigInt(value), + ]); + + return result[0].toBoolean(); + } + + try_approve(spender: Address, value: BigInt): ethereum.CallResult { + const result = super.tryCall("approve", "approve(address,uint256):(bool)", [ + ethereum.Value.fromAddress(spender), + ethereum.Value.fromUnsignedBigInt(value), + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + balanceOf(param0: Address): BigInt { + const result = super.call("balanceOf", "balanceOf(address):(uint256)", [ + ethereum.Value.fromAddress(param0), + ]); + + return result[0].toBigInt(); + } + + try_balanceOf(param0: Address): ethereum.CallResult { + const result = super.tryCall("balanceOf", "balanceOf(address):(uint256)", [ + ethereum.Value.fromAddress(param0), + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + burn(to: Address): UniswapV2Pair__burnResult { + const result = super.call("burn", "burn(address):(uint256,uint256)", [ + ethereum.Value.fromAddress(to), + ]); + + return new UniswapV2Pair__burnResult( + result[0].toBigInt(), + result[1].toBigInt(), + ); + } + + try_burn(to: Address): ethereum.CallResult { + const result = super.tryCall("burn", "burn(address):(uint256,uint256)", [ + ethereum.Value.fromAddress(to), + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new UniswapV2Pair__burnResult(value[0].toBigInt(), value[1].toBigInt()), + ); + } + + decimals(): i32 { + const result = super.call("decimals", "decimals():(uint8)", []); + + return result[0].toI32(); + } + + try_decimals(): ethereum.CallResult { + const result = super.tryCall("decimals", "decimals():(uint8)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toI32()); + } + + factory(): Address { + const result = super.call("factory", "factory():(address)", []); + + return result[0].toAddress(); + } + + try_factory(): ethereum.CallResult
{ + const result = super.tryCall("factory", "factory():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + getReserves(): UniswapV2Pair__getReservesResult { + const result = super.call( + "getReserves", + "getReserves():(uint112,uint112,uint32)", + [], + ); + + return new UniswapV2Pair__getReservesResult( + result[0].toBigInt(), + result[1].toBigInt(), + result[2].toBigInt(), + ); + } + + try_getReserves(): ethereum.CallResult { + const result = super.tryCall( + "getReserves", + "getReserves():(uint112,uint112,uint32)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new UniswapV2Pair__getReservesResult( + value[0].toBigInt(), + value[1].toBigInt(), + value[2].toBigInt(), + ), + ); + } + + kLast(): BigInt { + const result = super.call("kLast", "kLast():(uint256)", []); + + return result[0].toBigInt(); + } + + try_kLast(): ethereum.CallResult { + const result = super.tryCall("kLast", "kLast():(uint256)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + mint(to: Address): BigInt { + const result = super.call("mint", "mint(address):(uint256)", [ + ethereum.Value.fromAddress(to), + ]); + + return result[0].toBigInt(); + } + + try_mint(to: Address): ethereum.CallResult { + const result = super.tryCall("mint", "mint(address):(uint256)", [ + ethereum.Value.fromAddress(to), + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + name(): string { + const result = super.call("name", "name():(string)", []); + + return result[0].toString(); + } + + try_name(): ethereum.CallResult { + const result = super.tryCall("name", "name():(string)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toString()); + } + + nonces(param0: Address): BigInt { + const result = super.call("nonces", "nonces(address):(uint256)", [ + ethereum.Value.fromAddress(param0), + ]); + + return result[0].toBigInt(); + } + + try_nonces(param0: Address): ethereum.CallResult { + const result = super.tryCall("nonces", "nonces(address):(uint256)", [ + ethereum.Value.fromAddress(param0), + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + price0CumulativeLast(): BigInt { + const result = super.call( + "price0CumulativeLast", + "price0CumulativeLast():(uint256)", + [], + ); + + return result[0].toBigInt(); + } + + try_price0CumulativeLast(): ethereum.CallResult { + const result = super.tryCall( + "price0CumulativeLast", + "price0CumulativeLast():(uint256)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + price1CumulativeLast(): BigInt { + const result = super.call( + "price1CumulativeLast", + "price1CumulativeLast():(uint256)", + [], + ); + + return result[0].toBigInt(); + } + + try_price1CumulativeLast(): ethereum.CallResult { + const result = super.tryCall( + "price1CumulativeLast", + "price1CumulativeLast():(uint256)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + symbol(): string { + const result = super.call("symbol", "symbol():(string)", []); + + return result[0].toString(); + } + + try_symbol(): ethereum.CallResult { + const result = super.tryCall("symbol", "symbol():(string)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toString()); + } + + token0(): Address { + const result = super.call("token0", "token0():(address)", []); + + return result[0].toAddress(); + } + + try_token0(): ethereum.CallResult
{ + const result = super.tryCall("token0", "token0():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + token1(): Address { + const result = super.call("token1", "token1():(address)", []); + + return result[0].toAddress(); + } + + try_token1(): ethereum.CallResult
{ + const result = super.tryCall("token1", "token1():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + totalSupply(): BigInt { + const result = super.call("totalSupply", "totalSupply():(uint256)", []); + + return result[0].toBigInt(); + } + + try_totalSupply(): ethereum.CallResult { + const result = super.tryCall("totalSupply", "totalSupply():(uint256)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + transfer(to: Address, value: BigInt): boolean { + const result = super.call("transfer", "transfer(address,uint256):(bool)", [ + ethereum.Value.fromAddress(to), + ethereum.Value.fromUnsignedBigInt(value), + ]); + + return result[0].toBoolean(); + } + + try_transfer(to: Address, value: BigInt): ethereum.CallResult { + const result = super.tryCall("transfer", "transfer(address,uint256):(bool)", [ + ethereum.Value.fromAddress(to), + ethereum.Value.fromUnsignedBigInt(value), + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + transferFrom(from: Address, to: Address, value: BigInt): boolean { + const result = super.call( + "transferFrom", + "transferFrom(address,address,uint256):(bool)", + [ + ethereum.Value.fromAddress(from), + ethereum.Value.fromAddress(to), + ethereum.Value.fromUnsignedBigInt(value), + ], + ); + + return result[0].toBoolean(); + } + + try_transferFrom( + from: Address, + to: Address, + value: BigInt, + ): ethereum.CallResult { + const result = super.tryCall( + "transferFrom", + "transferFrom(address,address,uint256):(bool)", + [ + ethereum.Value.fromAddress(from), + ethereum.Value.fromAddress(to), + ethereum.Value.fromUnsignedBigInt(value), + ], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } +} + +export class ConstructorCall extends ethereum.Call { + get inputs(): ConstructorCall__Inputs { + return new ConstructorCall__Inputs(this); + } + + get outputs(): ConstructorCall__Outputs { + return new ConstructorCall__Outputs(this); + } +} + +export class ConstructorCall__Inputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } +} + +export class ConstructorCall__Outputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } +} + +export class ApproveCall extends ethereum.Call { + get inputs(): ApproveCall__Inputs { + return new ApproveCall__Inputs(this); + } + + get outputs(): ApproveCall__Outputs { + return new ApproveCall__Outputs(this); + } +} + +export class ApproveCall__Inputs { + _call: ApproveCall; + + constructor(call: ApproveCall) { + this._call = call; + } + + get spender(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get value(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class ApproveCall__Outputs { + _call: ApproveCall; + + constructor(call: ApproveCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} + +export class BurnCall extends ethereum.Call { + get inputs(): BurnCall__Inputs { + return new BurnCall__Inputs(this); + } + + get outputs(): BurnCall__Outputs { + return new BurnCall__Outputs(this); + } +} + +export class BurnCall__Inputs { + _call: BurnCall; + + constructor(call: BurnCall) { + this._call = call; + } + + get to(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class BurnCall__Outputs { + _call: BurnCall; + + constructor(call: BurnCall) { + this._call = call; + } + + get amount0(): BigInt { + return this._call.outputValues[0].value.toBigInt(); + } + + get amount1(): BigInt { + return this._call.outputValues[1].value.toBigInt(); + } +} + +export class InitializeCall extends ethereum.Call { + get inputs(): InitializeCall__Inputs { + return new InitializeCall__Inputs(this); + } + + get outputs(): InitializeCall__Outputs { + return new InitializeCall__Outputs(this); + } +} + +export class InitializeCall__Inputs { + _call: InitializeCall; + + constructor(call: InitializeCall) { + this._call = call; + } + + get _token0(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get _token1(): Address { + return this._call.inputValues[1].value.toAddress(); + } +} + +export class InitializeCall__Outputs { + _call: InitializeCall; + + constructor(call: InitializeCall) { + this._call = call; + } +} + +export class MintCall extends ethereum.Call { + get inputs(): MintCall__Inputs { + return new MintCall__Inputs(this); + } + + get outputs(): MintCall__Outputs { + return new MintCall__Outputs(this); + } +} + +export class MintCall__Inputs { + _call: MintCall; + + constructor(call: MintCall) { + this._call = call; + } + + get to(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class MintCall__Outputs { + _call: MintCall; + + constructor(call: MintCall) { + this._call = call; + } + + get liquidity(): BigInt { + return this._call.outputValues[0].value.toBigInt(); + } +} + +export class PermitCall extends ethereum.Call { + get inputs(): PermitCall__Inputs { + return new PermitCall__Inputs(this); + } + + get outputs(): PermitCall__Outputs { + return new PermitCall__Outputs(this); + } +} + +export class PermitCall__Inputs { + _call: PermitCall; + + constructor(call: PermitCall) { + this._call = call; + } + + get owner(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get spender(): Address { + return this._call.inputValues[1].value.toAddress(); + } + + get value(): BigInt { + return this._call.inputValues[2].value.toBigInt(); + } + + get deadline(): BigInt { + return this._call.inputValues[3].value.toBigInt(); + } + + get v(): i32 { + return this._call.inputValues[4].value.toI32(); + } + + get r(): Bytes { + return this._call.inputValues[5].value.toBytes(); + } + + get s(): Bytes { + return this._call.inputValues[6].value.toBytes(); + } +} + +export class PermitCall__Outputs { + _call: PermitCall; + + constructor(call: PermitCall) { + this._call = call; + } +} + +export class SkimCall extends ethereum.Call { + get inputs(): SkimCall__Inputs { + return new SkimCall__Inputs(this); + } + + get outputs(): SkimCall__Outputs { + return new SkimCall__Outputs(this); + } +} + +export class SkimCall__Inputs { + _call: SkimCall; + + constructor(call: SkimCall) { + this._call = call; + } + + get to(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class SkimCall__Outputs { + _call: SkimCall; + + constructor(call: SkimCall) { + this._call = call; + } +} + +export class SwapCall extends ethereum.Call { + get inputs(): SwapCall__Inputs { + return new SwapCall__Inputs(this); + } + + get outputs(): SwapCall__Outputs { + return new SwapCall__Outputs(this); + } +} + +export class SwapCall__Inputs { + _call: SwapCall; + + constructor(call: SwapCall) { + this._call = call; + } + + get amount0Out(): BigInt { + return this._call.inputValues[0].value.toBigInt(); + } + + get amount1Out(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } + + get to(): Address { + return this._call.inputValues[2].value.toAddress(); + } + + get data(): Bytes { + return this._call.inputValues[3].value.toBytes(); + } +} + +export class SwapCall__Outputs { + _call: SwapCall; + + constructor(call: SwapCall) { + this._call = call; + } +} + +export class SyncCall extends ethereum.Call { + get inputs(): SyncCall__Inputs { + return new SyncCall__Inputs(this); + } + + get outputs(): SyncCall__Outputs { + return new SyncCall__Outputs(this); + } +} + +export class SyncCall__Inputs { + _call: SyncCall; + + constructor(call: SyncCall) { + this._call = call; + } +} + +export class SyncCall__Outputs { + _call: SyncCall; + + constructor(call: SyncCall) { + this._call = call; + } +} + +export class TransferCall extends ethereum.Call { + get inputs(): TransferCall__Inputs { + return new TransferCall__Inputs(this); + } + + get outputs(): TransferCall__Outputs { + return new TransferCall__Outputs(this); + } +} + +export class TransferCall__Inputs { + _call: TransferCall; + + constructor(call: TransferCall) { + this._call = call; + } + + get to(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get value(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class TransferCall__Outputs { + _call: TransferCall; + + constructor(call: TransferCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} + +export class TransferFromCall extends ethereum.Call { + get inputs(): TransferFromCall__Inputs { + return new TransferFromCall__Inputs(this); + } + + get outputs(): TransferFromCall__Outputs { + return new TransferFromCall__Outputs(this); + } +} + +export class TransferFromCall__Inputs { + _call: TransferFromCall; + + constructor(call: TransferFromCall) { + this._call = call; + } + + get from(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get to(): Address { + return this._call.inputValues[1].value.toAddress(); + } + + get value(): BigInt { + return this._call.inputValues[2].value.toBigInt(); + } +} + +export class TransferFromCall__Outputs { + _call: TransferFromCall; + + constructor(call: TransferFromCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} diff --git a/subgraphs/base/generated/TokenRecords-base/UniswapV3Pair.ts b/subgraphs/base/generated/TokenRecords-base/UniswapV3Pair.ts new file mode 100644 index 00000000..948126af --- /dev/null +++ b/subgraphs/base/generated/TokenRecords-base/UniswapV3Pair.ts @@ -0,0 +1,1880 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + Address, + BigInt, + Bytes, + Entity, + ethereum, + JSONValue, + TypedMap, +} from "@graphprotocol/graph-ts"; + +export class Burn extends ethereum.Event { + get params(): Burn__Params { + return new Burn__Params(this); + } +} + +export class Burn__Params { + _event: Burn; + + constructor(event: Burn) { + this._event = event; + } + + get owner(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get tickLower(): i32 { + return this._event.parameters[1].value.toI32(); + } + + get tickUpper(): i32 { + return this._event.parameters[2].value.toI32(); + } + + get amount(): BigInt { + return this._event.parameters[3].value.toBigInt(); + } + + get amount0(): BigInt { + return this._event.parameters[4].value.toBigInt(); + } + + get amount1(): BigInt { + return this._event.parameters[5].value.toBigInt(); + } +} + +export class Collect extends ethereum.Event { + get params(): Collect__Params { + return new Collect__Params(this); + } +} + +export class Collect__Params { + _event: Collect; + + constructor(event: Collect) { + this._event = event; + } + + get owner(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get recipient(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get tickLower(): i32 { + return this._event.parameters[2].value.toI32(); + } + + get tickUpper(): i32 { + return this._event.parameters[3].value.toI32(); + } + + get amount0(): BigInt { + return this._event.parameters[4].value.toBigInt(); + } + + get amount1(): BigInt { + return this._event.parameters[5].value.toBigInt(); + } +} + +export class CollectProtocol extends ethereum.Event { + get params(): CollectProtocol__Params { + return new CollectProtocol__Params(this); + } +} + +export class CollectProtocol__Params { + _event: CollectProtocol; + + constructor(event: CollectProtocol) { + this._event = event; + } + + get sender(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get recipient(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get amount0(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } + + get amount1(): BigInt { + return this._event.parameters[3].value.toBigInt(); + } +} + +export class Flash extends ethereum.Event { + get params(): Flash__Params { + return new Flash__Params(this); + } +} + +export class Flash__Params { + _event: Flash; + + constructor(event: Flash) { + this._event = event; + } + + get sender(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get recipient(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get amount0(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } + + get amount1(): BigInt { + return this._event.parameters[3].value.toBigInt(); + } + + get paid0(): BigInt { + return this._event.parameters[4].value.toBigInt(); + } + + get paid1(): BigInt { + return this._event.parameters[5].value.toBigInt(); + } +} + +export class IncreaseObservationCardinalityNext extends ethereum.Event { + get params(): IncreaseObservationCardinalityNext__Params { + return new IncreaseObservationCardinalityNext__Params(this); + } +} + +export class IncreaseObservationCardinalityNext__Params { + _event: IncreaseObservationCardinalityNext; + + constructor(event: IncreaseObservationCardinalityNext) { + this._event = event; + } + + get observationCardinalityNextOld(): i32 { + return this._event.parameters[0].value.toI32(); + } + + get observationCardinalityNextNew(): i32 { + return this._event.parameters[1].value.toI32(); + } +} + +export class Initialize extends ethereum.Event { + get params(): Initialize__Params { + return new Initialize__Params(this); + } +} + +export class Initialize__Params { + _event: Initialize; + + constructor(event: Initialize) { + this._event = event; + } + + get sqrtPriceX96(): BigInt { + return this._event.parameters[0].value.toBigInt(); + } + + get tick(): i32 { + return this._event.parameters[1].value.toI32(); + } +} + +export class Mint extends ethereum.Event { + get params(): Mint__Params { + return new Mint__Params(this); + } +} + +export class Mint__Params { + _event: Mint; + + constructor(event: Mint) { + this._event = event; + } + + get sender(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get owner(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get tickLower(): i32 { + return this._event.parameters[2].value.toI32(); + } + + get tickUpper(): i32 { + return this._event.parameters[3].value.toI32(); + } + + get amount(): BigInt { + return this._event.parameters[4].value.toBigInt(); + } + + get amount0(): BigInt { + return this._event.parameters[5].value.toBigInt(); + } + + get amount1(): BigInt { + return this._event.parameters[6].value.toBigInt(); + } +} + +export class SetFeeProtocol extends ethereum.Event { + get params(): SetFeeProtocol__Params { + return new SetFeeProtocol__Params(this); + } +} + +export class SetFeeProtocol__Params { + _event: SetFeeProtocol; + + constructor(event: SetFeeProtocol) { + this._event = event; + } + + get feeProtocol0Old(): i32 { + return this._event.parameters[0].value.toI32(); + } + + get feeProtocol1Old(): i32 { + return this._event.parameters[1].value.toI32(); + } + + get feeProtocol0New(): i32 { + return this._event.parameters[2].value.toI32(); + } + + get feeProtocol1New(): i32 { + return this._event.parameters[3].value.toI32(); + } +} + +export class Swap extends ethereum.Event { + get params(): Swap__Params { + return new Swap__Params(this); + } +} + +export class Swap__Params { + _event: Swap; + + constructor(event: Swap) { + this._event = event; + } + + get sender(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get recipient(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get amount0(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } + + get amount1(): BigInt { + return this._event.parameters[3].value.toBigInt(); + } + + get sqrtPriceX96(): BigInt { + return this._event.parameters[4].value.toBigInt(); + } + + get liquidity(): BigInt { + return this._event.parameters[5].value.toBigInt(); + } + + get tick(): i32 { + return this._event.parameters[6].value.toI32(); + } +} + +export class UniswapV3Pair__burnResult { + value0: BigInt; + value1: BigInt; + + constructor(value0: BigInt, value1: BigInt) { + this.value0 = value0; + this.value1 = value1; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromUnsignedBigInt(this.value1)); + return map; + } + + getAmount0(): BigInt { + return this.value0; + } + + getAmount1(): BigInt { + return this.value1; + } +} + +export class UniswapV3Pair__collectResult { + value0: BigInt; + value1: BigInt; + + constructor(value0: BigInt, value1: BigInt) { + this.value0 = value0; + this.value1 = value1; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromUnsignedBigInt(this.value1)); + return map; + } + + getAmount0(): BigInt { + return this.value0; + } + + getAmount1(): BigInt { + return this.value1; + } +} + +export class UniswapV3Pair__collectProtocolResult { + value0: BigInt; + value1: BigInt; + + constructor(value0: BigInt, value1: BigInt) { + this.value0 = value0; + this.value1 = value1; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromUnsignedBigInt(this.value1)); + return map; + } + + getAmount0(): BigInt { + return this.value0; + } + + getAmount1(): BigInt { + return this.value1; + } +} + +export class UniswapV3Pair__mintResult { + value0: BigInt; + value1: BigInt; + + constructor(value0: BigInt, value1: BigInt) { + this.value0 = value0; + this.value1 = value1; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromUnsignedBigInt(this.value1)); + return map; + } + + getAmount0(): BigInt { + return this.value0; + } + + getAmount1(): BigInt { + return this.value1; + } +} + +export class UniswapV3Pair__observationsResult { + value0: BigInt; + value1: BigInt; + value2: BigInt; + value3: boolean; + + constructor(value0: BigInt, value1: BigInt, value2: BigInt, value3: boolean) { + this.value0 = value0; + this.value1 = value1; + this.value2 = value2; + this.value3 = value3; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromSignedBigInt(this.value1)); + map.set("value2", ethereum.Value.fromUnsignedBigInt(this.value2)); + map.set("value3", ethereum.Value.fromBoolean(this.value3)); + return map; + } + + getBlockTimestamp(): BigInt { + return this.value0; + } + + getTickCumulative(): BigInt { + return this.value1; + } + + getSecondsPerLiquidityCumulativeX128(): BigInt { + return this.value2; + } + + getInitialized(): boolean { + return this.value3; + } +} + +export class UniswapV3Pair__observeResult { + value0: Array; + value1: Array; + + constructor(value0: Array, value1: Array) { + this.value0 = value0; + this.value1 = value1; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromSignedBigIntArray(this.value0)); + map.set("value1", ethereum.Value.fromUnsignedBigIntArray(this.value1)); + return map; + } + + getTickCumulatives(): Array { + return this.value0; + } + + getSecondsPerLiquidityCumulativeX128s(): Array { + return this.value1; + } +} + +export class UniswapV3Pair__positionsResult { + value0: BigInt; + value1: BigInt; + value2: BigInt; + value3: BigInt; + value4: BigInt; + + constructor( + value0: BigInt, + value1: BigInt, + value2: BigInt, + value3: BigInt, + value4: BigInt, + ) { + this.value0 = value0; + this.value1 = value1; + this.value2 = value2; + this.value3 = value3; + this.value4 = value4; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromUnsignedBigInt(this.value1)); + map.set("value2", ethereum.Value.fromUnsignedBigInt(this.value2)); + map.set("value3", ethereum.Value.fromUnsignedBigInt(this.value3)); + map.set("value4", ethereum.Value.fromUnsignedBigInt(this.value4)); + return map; + } + + getLiquidity(): BigInt { + return this.value0; + } + + getFeeGrowthInside0LastX128(): BigInt { + return this.value1; + } + + getFeeGrowthInside1LastX128(): BigInt { + return this.value2; + } + + getTokensOwed0(): BigInt { + return this.value3; + } + + getTokensOwed1(): BigInt { + return this.value4; + } +} + +export class UniswapV3Pair__protocolFeesResult { + value0: BigInt; + value1: BigInt; + + constructor(value0: BigInt, value1: BigInt) { + this.value0 = value0; + this.value1 = value1; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromUnsignedBigInt(this.value1)); + return map; + } + + getToken0(): BigInt { + return this.value0; + } + + getToken1(): BigInt { + return this.value1; + } +} + +export class UniswapV3Pair__slot0Result { + value0: BigInt; + value1: i32; + value2: i32; + value3: i32; + value4: i32; + value5: i32; + value6: boolean; + + constructor( + value0: BigInt, + value1: i32, + value2: i32, + value3: i32, + value4: i32, + value5: i32, + value6: boolean, + ) { + this.value0 = value0; + this.value1 = value1; + this.value2 = value2; + this.value3 = value3; + this.value4 = value4; + this.value5 = value5; + this.value6 = value6; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromI32(this.value1)); + map.set( + "value2", + ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(this.value2)), + ); + map.set( + "value3", + ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(this.value3)), + ); + map.set( + "value4", + ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(this.value4)), + ); + map.set( + "value5", + ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(this.value5)), + ); + map.set("value6", ethereum.Value.fromBoolean(this.value6)); + return map; + } + + getSqrtPriceX96(): BigInt { + return this.value0; + } + + getTick(): i32 { + return this.value1; + } + + getObservationIndex(): i32 { + return this.value2; + } + + getObservationCardinality(): i32 { + return this.value3; + } + + getObservationCardinalityNext(): i32 { + return this.value4; + } + + getFeeProtocol(): i32 { + return this.value5; + } + + getUnlocked(): boolean { + return this.value6; + } +} + +export class UniswapV3Pair__snapshotCumulativesInsideResult { + value0: BigInt; + value1: BigInt; + value2: BigInt; + + constructor(value0: BigInt, value1: BigInt, value2: BigInt) { + this.value0 = value0; + this.value1 = value1; + this.value2 = value2; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromSignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromUnsignedBigInt(this.value1)); + map.set("value2", ethereum.Value.fromUnsignedBigInt(this.value2)); + return map; + } + + getTickCumulativeInside(): BigInt { + return this.value0; + } + + getSecondsPerLiquidityInsideX128(): BigInt { + return this.value1; + } + + getSecondsInside(): BigInt { + return this.value2; + } +} + +export class UniswapV3Pair__swapResult { + value0: BigInt; + value1: BigInt; + + constructor(value0: BigInt, value1: BigInt) { + this.value0 = value0; + this.value1 = value1; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromSignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromSignedBigInt(this.value1)); + return map; + } + + getAmount0(): BigInt { + return this.value0; + } + + getAmount1(): BigInt { + return this.value1; + } +} + +export class UniswapV3Pair__ticksResult { + value0: BigInt; + value1: BigInt; + value2: BigInt; + value3: BigInt; + value4: BigInt; + value5: BigInt; + value6: BigInt; + value7: boolean; + + constructor( + value0: BigInt, + value1: BigInt, + value2: BigInt, + value3: BigInt, + value4: BigInt, + value5: BigInt, + value6: BigInt, + value7: boolean, + ) { + this.value0 = value0; + this.value1 = value1; + this.value2 = value2; + this.value3 = value3; + this.value4 = value4; + this.value5 = value5; + this.value6 = value6; + this.value7 = value7; + } + + toMap(): TypedMap { + const map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromSignedBigInt(this.value1)); + map.set("value2", ethereum.Value.fromUnsignedBigInt(this.value2)); + map.set("value3", ethereum.Value.fromUnsignedBigInt(this.value3)); + map.set("value4", ethereum.Value.fromSignedBigInt(this.value4)); + map.set("value5", ethereum.Value.fromUnsignedBigInt(this.value5)); + map.set("value6", ethereum.Value.fromUnsignedBigInt(this.value6)); + map.set("value7", ethereum.Value.fromBoolean(this.value7)); + return map; + } + + getLiquidityGross(): BigInt { + return this.value0; + } + + getLiquidityNet(): BigInt { + return this.value1; + } + + getFeeGrowthOutside0X128(): BigInt { + return this.value2; + } + + getFeeGrowthOutside1X128(): BigInt { + return this.value3; + } + + getTickCumulativeOutside(): BigInt { + return this.value4; + } + + getSecondsPerLiquidityOutsideX128(): BigInt { + return this.value5; + } + + getSecondsOutside(): BigInt { + return this.value6; + } + + getInitialized(): boolean { + return this.value7; + } +} + +export class UniswapV3Pair extends ethereum.SmartContract { + static bind(address: Address): UniswapV3Pair { + return new UniswapV3Pair("UniswapV3Pair", address); + } + + burn( + tickLower: i32, + tickUpper: i32, + amount: BigInt, + ): UniswapV3Pair__burnResult { + const result = super.call( + "burn", + "burn(int24,int24,uint128):(uint256,uint256)", + [ + ethereum.Value.fromI32(tickLower), + ethereum.Value.fromI32(tickUpper), + ethereum.Value.fromUnsignedBigInt(amount), + ], + ); + + return new UniswapV3Pair__burnResult( + result[0].toBigInt(), + result[1].toBigInt(), + ); + } + + try_burn( + tickLower: i32, + tickUpper: i32, + amount: BigInt, + ): ethereum.CallResult { + const result = super.tryCall( + "burn", + "burn(int24,int24,uint128):(uint256,uint256)", + [ + ethereum.Value.fromI32(tickLower), + ethereum.Value.fromI32(tickUpper), + ethereum.Value.fromUnsignedBigInt(amount), + ], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new UniswapV3Pair__burnResult(value[0].toBigInt(), value[1].toBigInt()), + ); + } + + collect( + recipient: Address, + tickLower: i32, + tickUpper: i32, + amount0Requested: BigInt, + amount1Requested: BigInt, + ): UniswapV3Pair__collectResult { + const result = super.call( + "collect", + "collect(address,int24,int24,uint128,uint128):(uint128,uint128)", + [ + ethereum.Value.fromAddress(recipient), + ethereum.Value.fromI32(tickLower), + ethereum.Value.fromI32(tickUpper), + ethereum.Value.fromUnsignedBigInt(amount0Requested), + ethereum.Value.fromUnsignedBigInt(amount1Requested), + ], + ); + + return new UniswapV3Pair__collectResult( + result[0].toBigInt(), + result[1].toBigInt(), + ); + } + + try_collect( + recipient: Address, + tickLower: i32, + tickUpper: i32, + amount0Requested: BigInt, + amount1Requested: BigInt, + ): ethereum.CallResult { + const result = super.tryCall( + "collect", + "collect(address,int24,int24,uint128,uint128):(uint128,uint128)", + [ + ethereum.Value.fromAddress(recipient), + ethereum.Value.fromI32(tickLower), + ethereum.Value.fromI32(tickUpper), + ethereum.Value.fromUnsignedBigInt(amount0Requested), + ethereum.Value.fromUnsignedBigInt(amount1Requested), + ], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new UniswapV3Pair__collectResult( + value[0].toBigInt(), + value[1].toBigInt(), + ), + ); + } + + collectProtocol( + recipient: Address, + amount0Requested: BigInt, + amount1Requested: BigInt, + ): UniswapV3Pair__collectProtocolResult { + const result = super.call( + "collectProtocol", + "collectProtocol(address,uint128,uint128):(uint128,uint128)", + [ + ethereum.Value.fromAddress(recipient), + ethereum.Value.fromUnsignedBigInt(amount0Requested), + ethereum.Value.fromUnsignedBigInt(amount1Requested), + ], + ); + + return new UniswapV3Pair__collectProtocolResult( + result[0].toBigInt(), + result[1].toBigInt(), + ); + } + + try_collectProtocol( + recipient: Address, + amount0Requested: BigInt, + amount1Requested: BigInt, + ): ethereum.CallResult { + const result = super.tryCall( + "collectProtocol", + "collectProtocol(address,uint128,uint128):(uint128,uint128)", + [ + ethereum.Value.fromAddress(recipient), + ethereum.Value.fromUnsignedBigInt(amount0Requested), + ethereum.Value.fromUnsignedBigInt(amount1Requested), + ], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new UniswapV3Pair__collectProtocolResult( + value[0].toBigInt(), + value[1].toBigInt(), + ), + ); + } + + factory(): Address { + const result = super.call("factory", "factory():(address)", []); + + return result[0].toAddress(); + } + + try_factory(): ethereum.CallResult
{ + const result = super.tryCall("factory", "factory():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + fee(): i32 { + const result = super.call("fee", "fee():(uint24)", []); + + return result[0].toI32(); + } + + try_fee(): ethereum.CallResult { + const result = super.tryCall("fee", "fee():(uint24)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toI32()); + } + + feeGrowthGlobal0X128(): BigInt { + const result = super.call( + "feeGrowthGlobal0X128", + "feeGrowthGlobal0X128():(uint256)", + [], + ); + + return result[0].toBigInt(); + } + + try_feeGrowthGlobal0X128(): ethereum.CallResult { + const result = super.tryCall( + "feeGrowthGlobal0X128", + "feeGrowthGlobal0X128():(uint256)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + feeGrowthGlobal1X128(): BigInt { + const result = super.call( + "feeGrowthGlobal1X128", + "feeGrowthGlobal1X128():(uint256)", + [], + ); + + return result[0].toBigInt(); + } + + try_feeGrowthGlobal1X128(): ethereum.CallResult { + const result = super.tryCall( + "feeGrowthGlobal1X128", + "feeGrowthGlobal1X128():(uint256)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + liquidity(): BigInt { + const result = super.call("liquidity", "liquidity():(uint128)", []); + + return result[0].toBigInt(); + } + + try_liquidity(): ethereum.CallResult { + const result = super.tryCall("liquidity", "liquidity():(uint128)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + maxLiquidityPerTick(): BigInt { + const result = super.call( + "maxLiquidityPerTick", + "maxLiquidityPerTick():(uint128)", + [], + ); + + return result[0].toBigInt(); + } + + try_maxLiquidityPerTick(): ethereum.CallResult { + const result = super.tryCall( + "maxLiquidityPerTick", + "maxLiquidityPerTick():(uint128)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + mint( + recipient: Address, + tickLower: i32, + tickUpper: i32, + amount: BigInt, + data: Bytes, + ): UniswapV3Pair__mintResult { + const result = super.call( + "mint", + "mint(address,int24,int24,uint128,bytes):(uint256,uint256)", + [ + ethereum.Value.fromAddress(recipient), + ethereum.Value.fromI32(tickLower), + ethereum.Value.fromI32(tickUpper), + ethereum.Value.fromUnsignedBigInt(amount), + ethereum.Value.fromBytes(data), + ], + ); + + return new UniswapV3Pair__mintResult( + result[0].toBigInt(), + result[1].toBigInt(), + ); + } + + try_mint( + recipient: Address, + tickLower: i32, + tickUpper: i32, + amount: BigInt, + data: Bytes, + ): ethereum.CallResult { + const result = super.tryCall( + "mint", + "mint(address,int24,int24,uint128,bytes):(uint256,uint256)", + [ + ethereum.Value.fromAddress(recipient), + ethereum.Value.fromI32(tickLower), + ethereum.Value.fromI32(tickUpper), + ethereum.Value.fromUnsignedBigInt(amount), + ethereum.Value.fromBytes(data), + ], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new UniswapV3Pair__mintResult(value[0].toBigInt(), value[1].toBigInt()), + ); + } + + observations(param0: BigInt): UniswapV3Pair__observationsResult { + const result = super.call( + "observations", + "observations(uint256):(uint32,int56,uint160,bool)", + [ethereum.Value.fromUnsignedBigInt(param0)], + ); + + return new UniswapV3Pair__observationsResult( + result[0].toBigInt(), + result[1].toBigInt(), + result[2].toBigInt(), + result[3].toBoolean(), + ); + } + + try_observations( + param0: BigInt, + ): ethereum.CallResult { + const result = super.tryCall( + "observations", + "observations(uint256):(uint32,int56,uint160,bool)", + [ethereum.Value.fromUnsignedBigInt(param0)], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new UniswapV3Pair__observationsResult( + value[0].toBigInt(), + value[1].toBigInt(), + value[2].toBigInt(), + value[3].toBoolean(), + ), + ); + } + + observe(secondsAgos: Array): UniswapV3Pair__observeResult { + const result = super.call( + "observe", + "observe(uint32[]):(int56[],uint160[])", + [ethereum.Value.fromUnsignedBigIntArray(secondsAgos)], + ); + + return new UniswapV3Pair__observeResult( + result[0].toBigIntArray(), + result[1].toBigIntArray(), + ); + } + + try_observe( + secondsAgos: Array, + ): ethereum.CallResult { + const result = super.tryCall( + "observe", + "observe(uint32[]):(int56[],uint160[])", + [ethereum.Value.fromUnsignedBigIntArray(secondsAgos)], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new UniswapV3Pair__observeResult( + value[0].toBigIntArray(), + value[1].toBigIntArray(), + ), + ); + } + + positions(param0: Bytes): UniswapV3Pair__positionsResult { + const result = super.call( + "positions", + "positions(bytes32):(uint128,uint256,uint256,uint128,uint128)", + [ethereum.Value.fromFixedBytes(param0)], + ); + + return new UniswapV3Pair__positionsResult( + result[0].toBigInt(), + result[1].toBigInt(), + result[2].toBigInt(), + result[3].toBigInt(), + result[4].toBigInt(), + ); + } + + try_positions( + param0: Bytes, + ): ethereum.CallResult { + const result = super.tryCall( + "positions", + "positions(bytes32):(uint128,uint256,uint256,uint128,uint128)", + [ethereum.Value.fromFixedBytes(param0)], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new UniswapV3Pair__positionsResult( + value[0].toBigInt(), + value[1].toBigInt(), + value[2].toBigInt(), + value[3].toBigInt(), + value[4].toBigInt(), + ), + ); + } + + protocolFees(): UniswapV3Pair__protocolFeesResult { + const result = super.call( + "protocolFees", + "protocolFees():(uint128,uint128)", + [], + ); + + return new UniswapV3Pair__protocolFeesResult( + result[0].toBigInt(), + result[1].toBigInt(), + ); + } + + try_protocolFees(): ethereum.CallResult { + const result = super.tryCall( + "protocolFees", + "protocolFees():(uint128,uint128)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new UniswapV3Pair__protocolFeesResult( + value[0].toBigInt(), + value[1].toBigInt(), + ), + ); + } + + slot0(): UniswapV3Pair__slot0Result { + const result = super.call( + "slot0", + "slot0():(uint160,int24,uint16,uint16,uint16,uint8,bool)", + [], + ); + + return new UniswapV3Pair__slot0Result( + result[0].toBigInt(), + result[1].toI32(), + result[2].toI32(), + result[3].toI32(), + result[4].toI32(), + result[5].toI32(), + result[6].toBoolean(), + ); + } + + try_slot0(): ethereum.CallResult { + const result = super.tryCall( + "slot0", + "slot0():(uint160,int24,uint16,uint16,uint16,uint8,bool)", + [], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new UniswapV3Pair__slot0Result( + value[0].toBigInt(), + value[1].toI32(), + value[2].toI32(), + value[3].toI32(), + value[4].toI32(), + value[5].toI32(), + value[6].toBoolean(), + ), + ); + } + + snapshotCumulativesInside( + tickLower: i32, + tickUpper: i32, + ): UniswapV3Pair__snapshotCumulativesInsideResult { + const result = super.call( + "snapshotCumulativesInside", + "snapshotCumulativesInside(int24,int24):(int56,uint160,uint32)", + [ethereum.Value.fromI32(tickLower), ethereum.Value.fromI32(tickUpper)], + ); + + return new UniswapV3Pair__snapshotCumulativesInsideResult( + result[0].toBigInt(), + result[1].toBigInt(), + result[2].toBigInt(), + ); + } + + try_snapshotCumulativesInside( + tickLower: i32, + tickUpper: i32, + ): ethereum.CallResult { + const result = super.tryCall( + "snapshotCumulativesInside", + "snapshotCumulativesInside(int24,int24):(int56,uint160,uint32)", + [ethereum.Value.fromI32(tickLower), ethereum.Value.fromI32(tickUpper)], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new UniswapV3Pair__snapshotCumulativesInsideResult( + value[0].toBigInt(), + value[1].toBigInt(), + value[2].toBigInt(), + ), + ); + } + + swap( + recipient: Address, + zeroForOne: boolean, + amountSpecified: BigInt, + sqrtPriceLimitX96: BigInt, + data: Bytes, + ): UniswapV3Pair__swapResult { + const result = super.call( + "swap", + "swap(address,bool,int256,uint160,bytes):(int256,int256)", + [ + ethereum.Value.fromAddress(recipient), + ethereum.Value.fromBoolean(zeroForOne), + ethereum.Value.fromSignedBigInt(amountSpecified), + ethereum.Value.fromUnsignedBigInt(sqrtPriceLimitX96), + ethereum.Value.fromBytes(data), + ], + ); + + return new UniswapV3Pair__swapResult( + result[0].toBigInt(), + result[1].toBigInt(), + ); + } + + try_swap( + recipient: Address, + zeroForOne: boolean, + amountSpecified: BigInt, + sqrtPriceLimitX96: BigInt, + data: Bytes, + ): ethereum.CallResult { + const result = super.tryCall( + "swap", + "swap(address,bool,int256,uint160,bytes):(int256,int256)", + [ + ethereum.Value.fromAddress(recipient), + ethereum.Value.fromBoolean(zeroForOne), + ethereum.Value.fromSignedBigInt(amountSpecified), + ethereum.Value.fromUnsignedBigInt(sqrtPriceLimitX96), + ethereum.Value.fromBytes(data), + ], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new UniswapV3Pair__swapResult(value[0].toBigInt(), value[1].toBigInt()), + ); + } + + tickBitmap(param0: i32): BigInt { + const result = super.call("tickBitmap", "tickBitmap(int16):(uint256)", [ + ethereum.Value.fromI32(param0), + ]); + + return result[0].toBigInt(); + } + + try_tickBitmap(param0: i32): ethereum.CallResult { + const result = super.tryCall("tickBitmap", "tickBitmap(int16):(uint256)", [ + ethereum.Value.fromI32(param0), + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + tickSpacing(): i32 { + const result = super.call("tickSpacing", "tickSpacing():(int24)", []); + + return result[0].toI32(); + } + + try_tickSpacing(): ethereum.CallResult { + const result = super.tryCall("tickSpacing", "tickSpacing():(int24)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toI32()); + } + + ticks(param0: i32): UniswapV3Pair__ticksResult { + const result = super.call( + "ticks", + "ticks(int24):(uint128,int128,uint256,uint256,int56,uint160,uint32,bool)", + [ethereum.Value.fromI32(param0)], + ); + + return new UniswapV3Pair__ticksResult( + result[0].toBigInt(), + result[1].toBigInt(), + result[2].toBigInt(), + result[3].toBigInt(), + result[4].toBigInt(), + result[5].toBigInt(), + result[6].toBigInt(), + result[7].toBoolean(), + ); + } + + try_ticks(param0: i32): ethereum.CallResult { + const result = super.tryCall( + "ticks", + "ticks(int24):(uint128,int128,uint256,uint256,int56,uint160,uint32,bool)", + [ethereum.Value.fromI32(param0)], + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue( + new UniswapV3Pair__ticksResult( + value[0].toBigInt(), + value[1].toBigInt(), + value[2].toBigInt(), + value[3].toBigInt(), + value[4].toBigInt(), + value[5].toBigInt(), + value[6].toBigInt(), + value[7].toBoolean(), + ), + ); + } + + token0(): Address { + const result = super.call("token0", "token0():(address)", []); + + return result[0].toAddress(); + } + + try_token0(): ethereum.CallResult
{ + const result = super.tryCall("token0", "token0():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + token1(): Address { + const result = super.call("token1", "token1():(address)", []); + + return result[0].toAddress(); + } + + try_token1(): ethereum.CallResult
{ + const result = super.tryCall("token1", "token1():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + const value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } +} + +export class ConstructorCall extends ethereum.Call { + get inputs(): ConstructorCall__Inputs { + return new ConstructorCall__Inputs(this); + } + + get outputs(): ConstructorCall__Outputs { + return new ConstructorCall__Outputs(this); + } +} + +export class ConstructorCall__Inputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } +} + +export class ConstructorCall__Outputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } +} + +export class BurnCall extends ethereum.Call { + get inputs(): BurnCall__Inputs { + return new BurnCall__Inputs(this); + } + + get outputs(): BurnCall__Outputs { + return new BurnCall__Outputs(this); + } +} + +export class BurnCall__Inputs { + _call: BurnCall; + + constructor(call: BurnCall) { + this._call = call; + } + + get tickLower(): i32 { + return this._call.inputValues[0].value.toI32(); + } + + get tickUpper(): i32 { + return this._call.inputValues[1].value.toI32(); + } + + get amount(): BigInt { + return this._call.inputValues[2].value.toBigInt(); + } +} + +export class BurnCall__Outputs { + _call: BurnCall; + + constructor(call: BurnCall) { + this._call = call; + } + + get amount0(): BigInt { + return this._call.outputValues[0].value.toBigInt(); + } + + get amount1(): BigInt { + return this._call.outputValues[1].value.toBigInt(); + } +} + +export class CollectCall extends ethereum.Call { + get inputs(): CollectCall__Inputs { + return new CollectCall__Inputs(this); + } + + get outputs(): CollectCall__Outputs { + return new CollectCall__Outputs(this); + } +} + +export class CollectCall__Inputs { + _call: CollectCall; + + constructor(call: CollectCall) { + this._call = call; + } + + get recipient(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get tickLower(): i32 { + return this._call.inputValues[1].value.toI32(); + } + + get tickUpper(): i32 { + return this._call.inputValues[2].value.toI32(); + } + + get amount0Requested(): BigInt { + return this._call.inputValues[3].value.toBigInt(); + } + + get amount1Requested(): BigInt { + return this._call.inputValues[4].value.toBigInt(); + } +} + +export class CollectCall__Outputs { + _call: CollectCall; + + constructor(call: CollectCall) { + this._call = call; + } + + get amount0(): BigInt { + return this._call.outputValues[0].value.toBigInt(); + } + + get amount1(): BigInt { + return this._call.outputValues[1].value.toBigInt(); + } +} + +export class CollectProtocolCall extends ethereum.Call { + get inputs(): CollectProtocolCall__Inputs { + return new CollectProtocolCall__Inputs(this); + } + + get outputs(): CollectProtocolCall__Outputs { + return new CollectProtocolCall__Outputs(this); + } +} + +export class CollectProtocolCall__Inputs { + _call: CollectProtocolCall; + + constructor(call: CollectProtocolCall) { + this._call = call; + } + + get recipient(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get amount0Requested(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } + + get amount1Requested(): BigInt { + return this._call.inputValues[2].value.toBigInt(); + } +} + +export class CollectProtocolCall__Outputs { + _call: CollectProtocolCall; + + constructor(call: CollectProtocolCall) { + this._call = call; + } + + get amount0(): BigInt { + return this._call.outputValues[0].value.toBigInt(); + } + + get amount1(): BigInt { + return this._call.outputValues[1].value.toBigInt(); + } +} + +export class FlashCall extends ethereum.Call { + get inputs(): FlashCall__Inputs { + return new FlashCall__Inputs(this); + } + + get outputs(): FlashCall__Outputs { + return new FlashCall__Outputs(this); + } +} + +export class FlashCall__Inputs { + _call: FlashCall; + + constructor(call: FlashCall) { + this._call = call; + } + + get recipient(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get amount0(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } + + get amount1(): BigInt { + return this._call.inputValues[2].value.toBigInt(); + } + + get data(): Bytes { + return this._call.inputValues[3].value.toBytes(); + } +} + +export class FlashCall__Outputs { + _call: FlashCall; + + constructor(call: FlashCall) { + this._call = call; + } +} + +export class IncreaseObservationCardinalityNextCall extends ethereum.Call { + get inputs(): IncreaseObservationCardinalityNextCall__Inputs { + return new IncreaseObservationCardinalityNextCall__Inputs(this); + } + + get outputs(): IncreaseObservationCardinalityNextCall__Outputs { + return new IncreaseObservationCardinalityNextCall__Outputs(this); + } +} + +export class IncreaseObservationCardinalityNextCall__Inputs { + _call: IncreaseObservationCardinalityNextCall; + + constructor(call: IncreaseObservationCardinalityNextCall) { + this._call = call; + } + + get observationCardinalityNext(): i32 { + return this._call.inputValues[0].value.toI32(); + } +} + +export class IncreaseObservationCardinalityNextCall__Outputs { + _call: IncreaseObservationCardinalityNextCall; + + constructor(call: IncreaseObservationCardinalityNextCall) { + this._call = call; + } +} + +export class InitializeCall extends ethereum.Call { + get inputs(): InitializeCall__Inputs { + return new InitializeCall__Inputs(this); + } + + get outputs(): InitializeCall__Outputs { + return new InitializeCall__Outputs(this); + } +} + +export class InitializeCall__Inputs { + _call: InitializeCall; + + constructor(call: InitializeCall) { + this._call = call; + } + + get sqrtPriceX96(): BigInt { + return this._call.inputValues[0].value.toBigInt(); + } +} + +export class InitializeCall__Outputs { + _call: InitializeCall; + + constructor(call: InitializeCall) { + this._call = call; + } +} + +export class MintCall extends ethereum.Call { + get inputs(): MintCall__Inputs { + return new MintCall__Inputs(this); + } + + get outputs(): MintCall__Outputs { + return new MintCall__Outputs(this); + } +} + +export class MintCall__Inputs { + _call: MintCall; + + constructor(call: MintCall) { + this._call = call; + } + + get recipient(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get tickLower(): i32 { + return this._call.inputValues[1].value.toI32(); + } + + get tickUpper(): i32 { + return this._call.inputValues[2].value.toI32(); + } + + get amount(): BigInt { + return this._call.inputValues[3].value.toBigInt(); + } + + get data(): Bytes { + return this._call.inputValues[4].value.toBytes(); + } +} + +export class MintCall__Outputs { + _call: MintCall; + + constructor(call: MintCall) { + this._call = call; + } + + get amount0(): BigInt { + return this._call.outputValues[0].value.toBigInt(); + } + + get amount1(): BigInt { + return this._call.outputValues[1].value.toBigInt(); + } +} + +export class SetFeeProtocolCall extends ethereum.Call { + get inputs(): SetFeeProtocolCall__Inputs { + return new SetFeeProtocolCall__Inputs(this); + } + + get outputs(): SetFeeProtocolCall__Outputs { + return new SetFeeProtocolCall__Outputs(this); + } +} + +export class SetFeeProtocolCall__Inputs { + _call: SetFeeProtocolCall; + + constructor(call: SetFeeProtocolCall) { + this._call = call; + } + + get feeProtocol0(): i32 { + return this._call.inputValues[0].value.toI32(); + } + + get feeProtocol1(): i32 { + return this._call.inputValues[1].value.toI32(); + } +} + +export class SetFeeProtocolCall__Outputs { + _call: SetFeeProtocolCall; + + constructor(call: SetFeeProtocolCall) { + this._call = call; + } +} + +export class SwapCall extends ethereum.Call { + get inputs(): SwapCall__Inputs { + return new SwapCall__Inputs(this); + } + + get outputs(): SwapCall__Outputs { + return new SwapCall__Outputs(this); + } +} + +export class SwapCall__Inputs { + _call: SwapCall; + + constructor(call: SwapCall) { + this._call = call; + } + + get recipient(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get zeroForOne(): boolean { + return this._call.inputValues[1].value.toBoolean(); + } + + get amountSpecified(): BigInt { + return this._call.inputValues[2].value.toBigInt(); + } + + get sqrtPriceLimitX96(): BigInt { + return this._call.inputValues[3].value.toBigInt(); + } + + get data(): Bytes { + return this._call.inputValues[4].value.toBytes(); + } +} + +export class SwapCall__Outputs { + _call: SwapCall; + + constructor(call: SwapCall) { + this._call = call; + } + + get amount0(): BigInt { + return this._call.outputValues[0].value.toBigInt(); + } + + get amount1(): BigInt { + return this._call.outputValues[1].value.toBigInt(); + } +} diff --git a/subgraphs/base/generated/schema.ts b/subgraphs/base/generated/schema.ts new file mode 100644 index 00000000..b1414626 --- /dev/null +++ b/subgraphs/base/generated/schema.ts @@ -0,0 +1,1678 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + BigDecimal, + BigInt, + Bytes, + Entity, + store, + TypedMap, + Value, + ValueKind, +} from "@graphprotocol/graph-ts"; + +export class ProtocolMetric extends Entity { + constructor(id: Bytes) { + super(); + this.set("id", Value.fromBytes(id)); + } + + save(): void { + const id = this.get("id"); + assert(id != null, "Cannot save ProtocolMetric entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.BYTES, + `Entities of type ProtocolMetric must have an ID of type Bytes but the id '${id.displayData()}' is of type ${id.displayKind()}`, + ); + store.set("ProtocolMetric", id.toBytes().toHexString(), this); + } + } + + static loadInBlock(id: Bytes): ProtocolMetric | null { + return changetype( + store.get_in_block("ProtocolMetric", id.toHexString()), + ); + } + + static load(id: Bytes): ProtocolMetric | null { + return changetype( + store.get("ProtocolMetric", id.toHexString()), + ); + } + + get id(): Bytes { + const value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set id(value: Bytes) { + this.set("id", Value.fromBytes(value)); + } + + get block(): BigInt { + const value = this.get("block"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set block(value: BigInt) { + this.set("block", Value.fromBigInt(value)); + } + + get currentAPY(): BigDecimal { + const value = this.get("currentAPY"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set currentAPY(value: BigDecimal) { + this.set("currentAPY", Value.fromBigDecimal(value)); + } + + get currentIndex(): BigDecimal { + const value = this.get("currentIndex"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set currentIndex(value: BigDecimal) { + this.set("currentIndex", Value.fromBigDecimal(value)); + } + + get date(): string { + const value = this.get("date"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set date(value: string) { + this.set("date", Value.fromString(value)); + } + + get gOhmPrice(): BigDecimal { + const value = this.get("gOhmPrice"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set gOhmPrice(value: BigDecimal) { + this.set("gOhmPrice", Value.fromBigDecimal(value)); + } + + get gOhmSyntheticSupply(): BigDecimal | null { + const value = this.get("gOhmSyntheticSupply"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBigDecimal(); + } + } + + set gOhmSyntheticSupply(value: BigDecimal | null) { + if (!value) { + this.unset("gOhmSyntheticSupply"); + } else { + this.set("gOhmSyntheticSupply", Value.fromBigDecimal(value)); + } + } + + get gOhmTotalSupply(): BigDecimal { + const value = this.get("gOhmTotalSupply"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set gOhmTotalSupply(value: BigDecimal) { + this.set("gOhmTotalSupply", Value.fromBigDecimal(value)); + } + + get marketCap(): BigDecimal | null { + const value = this.get("marketCap"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBigDecimal(); + } + } + + set marketCap(value: BigDecimal | null) { + if (!value) { + this.unset("marketCap"); + } else { + this.set("marketCap", Value.fromBigDecimal(value)); + } + } + + get nextDistributedOhm(): BigDecimal { + const value = this.get("nextDistributedOhm"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set nextDistributedOhm(value: BigDecimal) { + this.set("nextDistributedOhm", Value.fromBigDecimal(value)); + } + + get nextEpochRebase(): BigDecimal { + const value = this.get("nextEpochRebase"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set nextEpochRebase(value: BigDecimal) { + this.set("nextEpochRebase", Value.fromBigDecimal(value)); + } + + get ohmCirculatingSupply(): BigDecimal | null { + const value = this.get("ohmCirculatingSupply"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBigDecimal(); + } + } + + set ohmCirculatingSupply(value: BigDecimal | null) { + if (!value) { + this.unset("ohmCirculatingSupply"); + } else { + this.set("ohmCirculatingSupply", Value.fromBigDecimal(value)); + } + } + + get ohmFloatingSupply(): BigDecimal | null { + const value = this.get("ohmFloatingSupply"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBigDecimal(); + } + } + + set ohmFloatingSupply(value: BigDecimal | null) { + if (!value) { + this.unset("ohmFloatingSupply"); + } else { + this.set("ohmFloatingSupply", Value.fromBigDecimal(value)); + } + } + + get ohmPrice(): BigDecimal { + const value = this.get("ohmPrice"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set ohmPrice(value: BigDecimal) { + this.set("ohmPrice", Value.fromBigDecimal(value)); + } + + get ohmTotalSupply(): BigDecimal { + const value = this.get("ohmTotalSupply"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set ohmTotalSupply(value: BigDecimal) { + this.set("ohmTotalSupply", Value.fromBigDecimal(value)); + } + + get sOhmCirculatingSupply(): BigDecimal { + const value = this.get("sOhmCirculatingSupply"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set sOhmCirculatingSupply(value: BigDecimal) { + this.set("sOhmCirculatingSupply", Value.fromBigDecimal(value)); + } + + get timestamp(): BigInt { + const value = this.get("timestamp"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set timestamp(value: BigInt) { + this.set("timestamp", Value.fromBigInt(value)); + } + + get totalValueLocked(): BigDecimal { + const value = this.get("totalValueLocked"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set totalValueLocked(value: BigDecimal) { + this.set("totalValueLocked", Value.fromBigDecimal(value)); + } + + get treasuryLiquidBacking(): BigDecimal | null { + const value = this.get("treasuryLiquidBacking"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBigDecimal(); + } + } + + set treasuryLiquidBacking(value: BigDecimal | null) { + if (!value) { + this.unset("treasuryLiquidBacking"); + } else { + this.set( + "treasuryLiquidBacking", + Value.fromBigDecimal(value), + ); + } + } + + get treasuryLiquidBackingPerGOhmSynthetic(): BigDecimal | null { + const value = this.get("treasuryLiquidBackingPerGOhmSynthetic"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBigDecimal(); + } + } + + set treasuryLiquidBackingPerGOhmSynthetic(value: BigDecimal | null) { + if (!value) { + this.unset("treasuryLiquidBackingPerGOhmSynthetic"); + } else { + this.set( + "treasuryLiquidBackingPerGOhmSynthetic", + Value.fromBigDecimal(value), + ); + } + } + + get treasuryLiquidBackingPerOhmFloating(): BigDecimal | null { + const value = this.get("treasuryLiquidBackingPerOhmFloating"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBigDecimal(); + } + } + + set treasuryLiquidBackingPerOhmFloating(value: BigDecimal | null) { + if (!value) { + this.unset("treasuryLiquidBackingPerOhmFloating"); + } else { + this.set( + "treasuryLiquidBackingPerOhmFloating", + Value.fromBigDecimal(value), + ); + } + } + + get treasuryMarketValue(): BigDecimal | null { + const value = this.get("treasuryMarketValue"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBigDecimal(); + } + } + + set treasuryMarketValue(value: BigDecimal | null) { + if (!value) { + this.unset("treasuryMarketValue"); + } else { + this.set("treasuryMarketValue", Value.fromBigDecimal(value)); + } + } +} + +export class TokenRecord extends Entity { + constructor(id: Bytes) { + super(); + this.set("id", Value.fromBytes(id)); + } + + save(): void { + const id = this.get("id"); + assert(id != null, "Cannot save TokenRecord entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.BYTES, + `Entities of type TokenRecord must have an ID of type Bytes but the id '${id.displayData()}' is of type ${id.displayKind()}`, + ); + store.set("TokenRecord", id.toBytes().toHexString(), this); + } + } + + static loadInBlock(id: Bytes): TokenRecord | null { + return changetype( + store.get_in_block("TokenRecord", id.toHexString()), + ); + } + + static load(id: Bytes): TokenRecord | null { + return changetype( + store.get("TokenRecord", id.toHexString()), + ); + } + + get id(): Bytes { + const value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set id(value: Bytes) { + this.set("id", Value.fromBytes(value)); + } + + get block(): BigInt { + const value = this.get("block"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set block(value: BigInt) { + this.set("block", Value.fromBigInt(value)); + } + + get timestamp(): BigInt { + const value = this.get("timestamp"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set timestamp(value: BigInt) { + this.set("timestamp", Value.fromBigInt(value)); + } + + get date(): string { + const value = this.get("date"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set date(value: string) { + this.set("date", Value.fromString(value)); + } + + get token(): string { + const value = this.get("token"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set token(value: string) { + this.set("token", Value.fromString(value)); + } + + get tokenAddress(): string { + const value = this.get("tokenAddress"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set tokenAddress(value: string) { + this.set("tokenAddress", Value.fromString(value)); + } + + get source(): string { + const value = this.get("source"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set source(value: string) { + this.set("source", Value.fromString(value)); + } + + get sourceAddress(): string { + const value = this.get("sourceAddress"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set sourceAddress(value: string) { + this.set("sourceAddress", Value.fromString(value)); + } + + get rate(): BigDecimal { + const value = this.get("rate"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set rate(value: BigDecimal) { + this.set("rate", Value.fromBigDecimal(value)); + } + + get balance(): BigDecimal { + const value = this.get("balance"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set balance(value: BigDecimal) { + this.set("balance", Value.fromBigDecimal(value)); + } + + get multiplier(): BigDecimal { + const value = this.get("multiplier"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set multiplier(value: BigDecimal) { + this.set("multiplier", Value.fromBigDecimal(value)); + } + + get value(): BigDecimal { + const value = this.get("value"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set value(value: BigDecimal) { + this.set("value", Value.fromBigDecimal(value)); + } + + get valueExcludingOhm(): BigDecimal { + const value = this.get("valueExcludingOhm"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set valueExcludingOhm(value: BigDecimal) { + this.set("valueExcludingOhm", Value.fromBigDecimal(value)); + } + + get category(): string { + const value = this.get("category"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set category(value: string) { + this.set("category", Value.fromString(value)); + } + + get isLiquid(): boolean { + const value = this.get("isLiquid"); + if (!value || value.kind == ValueKind.NULL) { + return false; + } else { + return value.toBoolean(); + } + } + + set isLiquid(value: boolean) { + this.set("isLiquid", Value.fromBoolean(value)); + } + + get isBluechip(): boolean { + const value = this.get("isBluechip"); + if (!value || value.kind == ValueKind.NULL) { + return false; + } else { + return value.toBoolean(); + } + } + + set isBluechip(value: boolean) { + this.set("isBluechip", Value.fromBoolean(value)); + } + + get blockchain(): string { + const value = this.get("blockchain"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set blockchain(value: string) { + this.set("blockchain", Value.fromString(value)); + } +} + +export class TokenSupply extends Entity { + constructor(id: Bytes) { + super(); + this.set("id", Value.fromBytes(id)); + } + + save(): void { + const id = this.get("id"); + assert(id != null, "Cannot save TokenSupply entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.BYTES, + `Entities of type TokenSupply must have an ID of type Bytes but the id '${id.displayData()}' is of type ${id.displayKind()}`, + ); + store.set("TokenSupply", id.toBytes().toHexString(), this); + } + } + + static loadInBlock(id: Bytes): TokenSupply | null { + return changetype( + store.get_in_block("TokenSupply", id.toHexString()), + ); + } + + static load(id: Bytes): TokenSupply | null { + return changetype( + store.get("TokenSupply", id.toHexString()), + ); + } + + get id(): Bytes { + const value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set id(value: Bytes) { + this.set("id", Value.fromBytes(value)); + } + + get block(): BigInt { + const value = this.get("block"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set block(value: BigInt) { + this.set("block", Value.fromBigInt(value)); + } + + get timestamp(): BigInt { + const value = this.get("timestamp"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set timestamp(value: BigInt) { + this.set("timestamp", Value.fromBigInt(value)); + } + + get date(): string { + const value = this.get("date"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set date(value: string) { + this.set("date", Value.fromString(value)); + } + + get token(): string { + const value = this.get("token"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set token(value: string) { + this.set("token", Value.fromString(value)); + } + + get tokenAddress(): string { + const value = this.get("tokenAddress"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set tokenAddress(value: string) { + this.set("tokenAddress", Value.fromString(value)); + } + + get pool(): string | null { + const value = this.get("pool"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set pool(value: string | null) { + if (!value) { + this.unset("pool"); + } else { + this.set("pool", Value.fromString(value)); + } + } + + get poolAddress(): string | null { + const value = this.get("poolAddress"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set poolAddress(value: string | null) { + if (!value) { + this.unset("poolAddress"); + } else { + this.set("poolAddress", Value.fromString(value)); + } + } + + get source(): string | null { + const value = this.get("source"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set source(value: string | null) { + if (!value) { + this.unset("source"); + } else { + this.set("source", Value.fromString(value)); + } + } + + get sourceAddress(): string | null { + const value = this.get("sourceAddress"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set sourceAddress(value: string | null) { + if (!value) { + this.unset("sourceAddress"); + } else { + this.set("sourceAddress", Value.fromString(value)); + } + } + + get type(): string { + const value = this.get("type"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set type(value: string) { + this.set("type", Value.fromString(value)); + } + + get balance(): BigDecimal { + const value = this.get("balance"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set balance(value: BigDecimal) { + this.set("balance", Value.fromBigDecimal(value)); + } + + get supplyBalance(): BigDecimal { + const value = this.get("supplyBalance"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set supplyBalance(value: BigDecimal) { + this.set("supplyBalance", Value.fromBigDecimal(value)); + } +} + +export class PriceSnapshot extends Entity { + constructor(id: string) { + super(); + this.set("id", Value.fromString(id)); + } + + save(): void { + const id = this.get("id"); + assert(id != null, "Cannot save PriceSnapshot entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.STRING, + `Entities of type PriceSnapshot must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}`, + ); + store.set("PriceSnapshot", id.toString(), this); + } + } + + static loadInBlock(id: string): PriceSnapshot | null { + return changetype( + store.get_in_block("PriceSnapshot", id), + ); + } + + static load(id: string): PriceSnapshot | null { + return changetype(store.get("PriceSnapshot", id)); + } + + get id(): string { + const value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set id(value: string) { + this.set("id", Value.fromString(value)); + } + + get block(): BigInt { + const value = this.get("block"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set block(value: BigInt) { + this.set("block", Value.fromBigInt(value)); + } + + get timestamp(): BigInt { + const value = this.get("timestamp"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set timestamp(value: BigInt) { + this.set("timestamp", Value.fromBigInt(value)); + } + + get date(): string { + const value = this.get("date"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set date(value: string) { + this.set("date", Value.fromString(value)); + } + + get priceOhm(): BigDecimal { + const value = this.get("priceOhm"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set priceOhm(value: BigDecimal) { + this.set("priceOhm", Value.fromBigDecimal(value)); + } + + get priceGOhm(): BigDecimal { + const value = this.get("priceGOhm"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set priceGOhm(value: BigDecimal) { + this.set("priceGOhm", Value.fromBigDecimal(value)); + } +} + +export class GnosisAuctionRoot extends Entity { + constructor(id: string) { + super(); + this.set("id", Value.fromString(id)); + } + + save(): void { + const id = this.get("id"); + assert(id != null, "Cannot save GnosisAuctionRoot entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.STRING, + `Entities of type GnosisAuctionRoot must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}`, + ); + store.set("GnosisAuctionRoot", id.toString(), this); + } + } + + static loadInBlock(id: string): GnosisAuctionRoot | null { + return changetype( + store.get_in_block("GnosisAuctionRoot", id), + ); + } + + static load(id: string): GnosisAuctionRoot | null { + return changetype( + store.get("GnosisAuctionRoot", id), + ); + } + + get id(): string { + const value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set id(value: string) { + this.set("id", Value.fromString(value)); + } + + get markets(): Array { + const value = this.get("markets"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigIntArray(); + } + } + + set markets(value: Array) { + this.set("markets", Value.fromBigIntArray(value)); + } +} + +export class GnosisAuction extends Entity { + constructor(id: string) { + super(); + this.set("id", Value.fromString(id)); + } + + save(): void { + const id = this.get("id"); + assert(id != null, "Cannot save GnosisAuction entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.STRING, + `Entities of type GnosisAuction must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}`, + ); + store.set("GnosisAuction", id.toString(), this); + } + } + + static loadInBlock(id: string): GnosisAuction | null { + return changetype( + store.get_in_block("GnosisAuction", id), + ); + } + + static load(id: string): GnosisAuction | null { + return changetype(store.get("GnosisAuction", id)); + } + + get id(): string { + const value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set id(value: string) { + this.set("id", Value.fromString(value)); + } + + get auctionOpenTimestamp(): BigInt { + const value = this.get("auctionOpenTimestamp"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set auctionOpenTimestamp(value: BigInt) { + this.set("auctionOpenTimestamp", Value.fromBigInt(value)); + } + + get payoutCapacity(): BigDecimal { + const value = this.get("payoutCapacity"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set payoutCapacity(value: BigDecimal) { + this.set("payoutCapacity", Value.fromBigDecimal(value)); + } + + get termSeconds(): BigInt { + const value = this.get("termSeconds"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set termSeconds(value: BigInt) { + this.set("termSeconds", Value.fromBigInt(value)); + } + + get bidQuantity(): BigDecimal | null { + const value = this.get("bidQuantity"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBigDecimal(); + } + } + + set bidQuantity(value: BigDecimal | null) { + if (!value) { + this.unset("bidQuantity"); + } else { + this.set("bidQuantity", Value.fromBigDecimal(value)); + } + } + + get auctionCloseTimestamp(): BigInt | null { + const value = this.get("auctionCloseTimestamp"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBigInt(); + } + } + + set auctionCloseTimestamp(value: BigInt | null) { + if (!value) { + this.unset("auctionCloseTimestamp"); + } else { + this.set("auctionCloseTimestamp", Value.fromBigInt(value)); + } + } +} + +export class ERC20TokenSnapshot extends Entity { + constructor(id: Bytes) { + super(); + this.set("id", Value.fromBytes(id)); + } + + save(): void { + const id = this.get("id"); + assert(id != null, "Cannot save ERC20TokenSnapshot entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.BYTES, + `Entities of type ERC20TokenSnapshot must have an ID of type Bytes but the id '${id.displayData()}' is of type ${id.displayKind()}`, + ); + store.set("ERC20TokenSnapshot", id.toBytes().toHexString(), this); + } + } + + static loadInBlock(id: Bytes): ERC20TokenSnapshot | null { + return changetype( + store.get_in_block("ERC20TokenSnapshot", id.toHexString()), + ); + } + + static load(id: Bytes): ERC20TokenSnapshot | null { + return changetype( + store.get("ERC20TokenSnapshot", id.toHexString()), + ); + } + + get id(): Bytes { + const value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set id(value: Bytes) { + this.set("id", Value.fromBytes(value)); + } + + get address(): Bytes { + const value = this.get("address"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set address(value: Bytes) { + this.set("address", Value.fromBytes(value)); + } + + get decimals(): i32 { + const value = this.get("decimals"); + if (!value || value.kind == ValueKind.NULL) { + return 0; + } else { + return value.toI32(); + } + } + + set decimals(value: i32) { + this.set("decimals", Value.fromI32(value)); + } + + get totalSupply(): BigDecimal | null { + const value = this.get("totalSupply"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBigDecimal(); + } + } + + set totalSupply(value: BigDecimal | null) { + if (!value) { + this.unset("totalSupply"); + } else { + this.set("totalSupply", Value.fromBigDecimal(value)); + } + } +} + +export class BalancerPoolSnapshot extends Entity { + constructor(id: Bytes) { + super(); + this.set("id", Value.fromBytes(id)); + } + + save(): void { + const id = this.get("id"); + assert(id != null, "Cannot save BalancerPoolSnapshot entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.BYTES, + `Entities of type BalancerPoolSnapshot must have an ID of type Bytes but the id '${id.displayData()}' is of type ${id.displayKind()}`, + ); + store.set("BalancerPoolSnapshot", id.toBytes().toHexString(), this); + } + } + + static loadInBlock(id: Bytes): BalancerPoolSnapshot | null { + return changetype( + store.get_in_block("BalancerPoolSnapshot", id.toHexString()), + ); + } + + static load(id: Bytes): BalancerPoolSnapshot | null { + return changetype( + store.get("BalancerPoolSnapshot", id.toHexString()), + ); + } + + get id(): Bytes { + const value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set id(value: Bytes) { + this.set("id", Value.fromBytes(value)); + } + + get block(): BigInt { + const value = this.get("block"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set block(value: BigInt) { + this.set("block", Value.fromBigInt(value)); + } + + get pool(): Bytes { + const value = this.get("pool"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set pool(value: Bytes) { + this.set("pool", Value.fromBytes(value)); + } + + get poolToken(): Bytes { + const value = this.get("poolToken"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set poolToken(value: Bytes) { + this.set("poolToken", Value.fromBytes(value)); + } + + get decimals(): i32 { + const value = this.get("decimals"); + if (!value || value.kind == ValueKind.NULL) { + return 0; + } else { + return value.toI32(); + } + } + + set decimals(value: i32) { + this.set("decimals", Value.fromI32(value)); + } + + get totalSupply(): BigDecimal { + const value = this.get("totalSupply"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set totalSupply(value: BigDecimal) { + this.set("totalSupply", Value.fromBigDecimal(value)); + } + + get tokens(): Array { + const value = this.get("tokens"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytesArray(); + } + } + + set tokens(value: Array) { + this.set("tokens", Value.fromBytesArray(value)); + } + + get balances(): Array { + const value = this.get("balances"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimalArray(); + } + } + + set balances(value: Array) { + this.set("balances", Value.fromBigDecimalArray(value)); + } + + get weights(): Array { + const value = this.get("weights"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimalArray(); + } + } + + set weights(value: Array) { + this.set("weights", Value.fromBigDecimalArray(value)); + } +} + +export class PoolSnapshot extends Entity { + constructor(id: Bytes) { + super(); + this.set("id", Value.fromBytes(id)); + } + + save(): void { + const id = this.get("id"); + assert(id != null, "Cannot save PoolSnapshot entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.BYTES, + `Entities of type PoolSnapshot must have an ID of type Bytes but the id '${id.displayData()}' is of type ${id.displayKind()}`, + ); + store.set("PoolSnapshot", id.toBytes().toHexString(), this); + } + } + + static loadInBlock(id: Bytes): PoolSnapshot | null { + return changetype( + store.get_in_block("PoolSnapshot", id.toHexString()), + ); + } + + static load(id: Bytes): PoolSnapshot | null { + return changetype( + store.get("PoolSnapshot", id.toHexString()), + ); + } + + get id(): Bytes { + const value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set id(value: Bytes) { + this.set("id", Value.fromBytes(value)); + } + + get block(): BigInt { + const value = this.get("block"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set block(value: BigInt) { + this.set("block", Value.fromBigInt(value)); + } + + get pool(): Bytes { + const value = this.get("pool"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set pool(value: Bytes) { + this.set("pool", Value.fromBytes(value)); + } + + get poolToken(): Bytes | null { + const value = this.get("poolToken"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBytes(); + } + } + + set poolToken(value: Bytes | null) { + if (!value) { + this.unset("poolToken"); + } else { + this.set("poolToken", Value.fromBytes(value)); + } + } + + get decimals(): i32 { + const value = this.get("decimals"); + if (!value || value.kind == ValueKind.NULL) { + return 0; + } else { + return value.toI32(); + } + } + + set decimals(value: i32) { + this.set("decimals", Value.fromI32(value)); + } + + get totalSupply(): BigDecimal { + const value = this.get("totalSupply"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set totalSupply(value: BigDecimal) { + this.set("totalSupply", Value.fromBigDecimal(value)); + } + + get tokens(): Array { + const value = this.get("tokens"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytesArray(); + } + } + + set tokens(value: Array) { + this.set("tokens", Value.fromBytesArray(value)); + } + + get balances(): Array { + const value = this.get("balances"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimalArray(); + } + } + + set balances(value: Array) { + this.set("balances", Value.fromBigDecimalArray(value)); + } + + get weights(): Array | null { + const value = this.get("weights"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBigDecimalArray(); + } + } + + set weights(value: Array | null) { + if (!value) { + this.unset("weights"); + } else { + this.set("weights", Value.fromBigDecimalArray(>value)); + } + } +} + +export class TokenPriceSnapshot extends Entity { + constructor(id: Bytes) { + super(); + this.set("id", Value.fromBytes(id)); + } + + save(): void { + const id = this.get("id"); + assert(id != null, "Cannot save TokenPriceSnapshot entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.BYTES, + `Entities of type TokenPriceSnapshot must have an ID of type Bytes but the id '${id.displayData()}' is of type ${id.displayKind()}`, + ); + store.set("TokenPriceSnapshot", id.toBytes().toHexString(), this); + } + } + + static loadInBlock(id: Bytes): TokenPriceSnapshot | null { + return changetype( + store.get_in_block("TokenPriceSnapshot", id.toHexString()), + ); + } + + static load(id: Bytes): TokenPriceSnapshot | null { + return changetype( + store.get("TokenPriceSnapshot", id.toHexString()), + ); + } + + get id(): Bytes { + const value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set id(value: Bytes) { + this.set("id", Value.fromBytes(value)); + } + + get block(): BigInt { + const value = this.get("block"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set block(value: BigInt) { + this.set("block", Value.fromBigInt(value)); + } + + get token(): Bytes { + const value = this.get("token"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set token(value: Bytes) { + this.set("token", Value.fromBytes(value)); + } + + get price(): BigDecimal { + const value = this.get("price"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigDecimal(); + } + } + + set price(value: BigDecimal) { + this.set("price", Value.fromBigDecimal(value)); + } +} + +export class StakingPoolSnapshot extends Entity { + constructor(id: Bytes) { + super(); + this.set("id", Value.fromBytes(id)); + } + + save(): void { + const id = this.get("id"); + assert(id != null, "Cannot save StakingPoolSnapshot entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.BYTES, + `Entities of type StakingPoolSnapshot must have an ID of type Bytes but the id '${id.displayData()}' is of type ${id.displayKind()}`, + ); + store.set("StakingPoolSnapshot", id.toBytes().toHexString(), this); + } + } + + static loadInBlock(id: Bytes): StakingPoolSnapshot | null { + return changetype( + store.get_in_block("StakingPoolSnapshot", id.toHexString()), + ); + } + + static load(id: Bytes): StakingPoolSnapshot | null { + return changetype( + store.get("StakingPoolSnapshot", id.toHexString()), + ); + } + + get id(): Bytes { + const value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set id(value: Bytes) { + this.set("id", Value.fromBytes(value)); + } + + get block(): BigInt { + const value = this.get("block"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set block(value: BigInt) { + this.set("block", Value.fromBigInt(value)); + } + + get contractAddress(): Bytes { + const value = this.get("contractAddress"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set contractAddress(value: Bytes) { + this.set("contractAddress", Value.fromBytes(value)); + } + + get stakingToken(): Bytes | null { + const value = this.get("stakingToken"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBytes(); + } + } + + set stakingToken(value: Bytes | null) { + if (!value) { + this.unset("stakingToken"); + } else { + this.set("stakingToken", Value.fromBytes(value)); + } + } +} diff --git a/subgraphs/base/src/contracts/Constants.ts b/subgraphs/base/src/contracts/Constants.ts new file mode 100644 index 00000000..5de21499 --- /dev/null +++ b/subgraphs/base/src/contracts/Constants.ts @@ -0,0 +1,70 @@ +import { BigDecimal, BigInt, log } from "@graphprotocol/graph-ts"; +import { TokenCategoryPOL, TokenCategoryVolatile, TokenDefinition } from "../../../shared/src/contracts/TokenDefinition"; + +export const BLOCKCHAIN = "Base"; + +export const ERC20_OHM = "0x060cb087a9730E13aa191f31A6d86bFF8DfcdCC0".toLowerCase(); +export const ERC20_WETH = "0x4200000000000000000000000000000000000006".toLowerCase(); + +export const LP_UNISWAP_V2_OHM_WETH = "0x5ab4b9e96aeed4820e4be267f42411d722985482".toLowerCase(); + +export const ERC20_TOKENS_BASE = new Map(); +ERC20_TOKENS_BASE.set(ERC20_WETH, new TokenDefinition(ERC20_WETH, TokenCategoryVolatile, true, true)); +ERC20_TOKENS_BASE.set(LP_UNISWAP_V2_OHM_WETH, new TokenDefinition(LP_UNISWAP_V2_OHM_WETH, TokenCategoryPOL, true, false)); + +export const OHM_TOKENS = [ERC20_OHM]; + +export const DAO_MULTISIG = "0x18a390bD45bCc92652b9A91AD51Aed7f1c1358f5".toLowerCase(); + +export const PROTOCOL_ADDRESSES = [ + DAO_MULTISIG +]; + +const TREASURY_BLACKLIST = new Map(); +TREASURY_BLACKLIST.set(ERC20_OHM, [DAO_MULTISIG]); + +/** + * Some wallets (e.g. {DAO_WALLET}) have specific treasury assets mixed into them. + * For this reason, the wallets to be used differ on a per-contract basis. + * + * This function returns the wallets that should be iterated over for the given + * contract, {contractAddress}. + * + * @param contractAddress + * @returns + */ +export const getWalletAddressesForContract = (contractAddress: string): string[] => { + const walletAddresses = PROTOCOL_ADDRESSES.slice(0); + + // If the contract isn't on the blacklist, return as normal + if (!TREASURY_BLACKLIST.has(contractAddress.toLowerCase())) { + log.debug("getWalletAddressesForContract: token {} is not on treasury blacklist", [contractAddress]); + return walletAddresses; + } + + // Otherwise remove the values in the blacklist + // AssemblyScript doesn't yet have closures, so filter() cannot be used + const walletBlacklist = TREASURY_BLACKLIST.get(contractAddress.toLowerCase()); + for (let i = 0; i < walletBlacklist.length; i++) { + // If the blacklisted address is not in the array, skip + const arrayIndex = walletAddresses.indexOf(walletBlacklist[i]); + if (arrayIndex < 0) { + continue; + } + + // Otherwise the blacklist address is removed from the array in-place + const splicedValues = walletAddresses.splice(arrayIndex, 1); + log.debug("getWalletAddressesForContract: removed values: {}", [splicedValues.toString()]); + } + + return walletAddresses; + }; + +export const CONTRACT_NAME_MAP = new Map(); +CONTRACT_NAME_MAP.set(ERC20_OHM, "OHM"); +CONTRACT_NAME_MAP.set(ERC20_WETH, "Wrapped Ether"); +CONTRACT_NAME_MAP.set(LP_UNISWAP_V2_OHM_WETH, "Uniswap V2 OHM-WETH LP"); + +export const CONTRACT_ABBREVIATION_MAP = new Map(); +CONTRACT_ABBREVIATION_MAP.set(ERC20_OHM, "OHM"); +CONTRACT_ABBREVIATION_MAP.set(ERC20_WETH, "wETH"); diff --git a/subgraphs/base/src/contracts/Contracts.ts b/subgraphs/base/src/contracts/Contracts.ts new file mode 100644 index 00000000..aa950162 --- /dev/null +++ b/subgraphs/base/src/contracts/Contracts.ts @@ -0,0 +1,70 @@ +import { BigDecimal, BigInt } from "@graphprotocol/graph-ts"; +import { BLOCKCHAIN, CONTRACT_ABBREVIATION_MAP, CONTRACT_NAME_MAP, ERC20_TOKENS_BASE, getWalletAddressesForContract } from "./Constants"; +import { TokenRecord } from "../../../shared/generated/schema"; +import { getERC20TokenRecordFromWallet } from "../../../shared/src/contracts/ERC20"; +import { ERC20 } from "../../generated/TokenRecords-base/ERC20"; + +export function getContractName( + contractAddress: string, + suffix: string | null = null, + abbreviation: string | null = null, +): string { + const contractAddressLower = contractAddress.toLowerCase(); + + const contractName = CONTRACT_NAME_MAP.has(contractAddressLower) + ? CONTRACT_NAME_MAP.get(contractAddressLower) + : contractAddressLower; + + // Suffix + const contractSuffix = suffix ? ` - ${suffix}` : ""; + + // Abbreviation + const contractAbbreviation = abbreviation + ? ` (${abbreviation})` + : CONTRACT_ABBREVIATION_MAP.has(contractAddressLower) + ? ` (${CONTRACT_ABBREVIATION_MAP.get(contractAddressLower)})` + : ""; + + return `${contractName}${contractSuffix}${contractAbbreviation}`; +} + +/** +* Fetches the balances of the given ERC20 token from +* the wallets defined in {getWalletAddressesForContract}. +* +* @param metricName The name of the current metric, which is used for entity ids +* @param contractAddress ERC20 contract address +* @param contract ERC20 contract +* @param rate the unit price/rate of the token +* @param blockNumber the current block number +* @returns TokenRecord array +*/ +export function getERC20TokenRecordsFromWallets( + timestamp: BigInt, + contractAddress: string, + contract: ERC20, + rate: BigDecimal, + blockNumber: BigInt, +): TokenRecord[] { + const records: TokenRecord[] = []; + const wallets = getWalletAddressesForContract(contractAddress); + + for (let i = 0; i < wallets.length; i++) { + const record = getERC20TokenRecordFromWallet( + timestamp, + contractAddress, + wallets[i], + contract, + rate, + blockNumber, + getContractName, + ERC20_TOKENS_BASE, + BLOCKCHAIN, + ); + if (!record) continue; + + records.push(record); + } + + return records; +} \ No newline at end of file diff --git a/subgraphs/base/src/price/PriceBase.ts b/subgraphs/base/src/price/PriceBase.ts new file mode 100644 index 00000000..60be6419 --- /dev/null +++ b/subgraphs/base/src/price/PriceBase.ts @@ -0,0 +1,49 @@ +import { Address, BigDecimal, BigInt, log } from "@graphprotocol/graph-ts"; + +import { getContractName } from "../contracts/Contracts"; +import { getPriceFeedValue } from "./PriceChainlink"; + +export function isBaseToken(baseToken: string): boolean { + const FUNC = "isBaseToken"; + const priceFeedValue = getPriceFeedValue(baseToken); + + if (priceFeedValue !== null) { + log.debug("{}: Token {} is a base token", [FUNC, getContractName(baseToken)]); + return true; + } + + log.debug("{}: Token {} is not a base token", [FUNC, getContractName(baseToken)]); + return false; +} + +/** + * Gets the USD value of the base token. + * + * This enables pairs to have ETH or DAI/USDC/USDT as the base token. + * + * @param baseToken + * @param blockNumber + * @returns + */ +export function getBaseTokenRate( + baseToken: Address, + blockNumber: BigInt, +): BigDecimal { + const FUNC = "getBaseTokenRate"; + const baseTokenAddress = baseToken.toHexString().toLowerCase(); + if (!isBaseToken(baseTokenAddress)) { + throw new Error( + `${FUNC}: Token ${getContractName( + baseTokenAddress, + )} is unsupported for base token price lookup`, + ); + } + + const usdRate = getPriceFeedValue(baseTokenAddress); + if (usdRate === null || usdRate.equals(BigDecimal.zero())) { + throw new Error(`${FUNC}: Unable to determine USD rate for token ${getContractName(baseTokenAddress)} (${baseTokenAddress}) at block ${blockNumber.toString()}`); + } + + log.debug(`${FUNC}: USD rate for token ${getContractName(baseTokenAddress)} (${baseTokenAddress}) is ${usdRate.toString()}`, []); + return usdRate; +} diff --git a/subgraphs/base/src/price/PriceChainlink.ts b/subgraphs/base/src/price/PriceChainlink.ts new file mode 100644 index 00000000..c8bb4e41 --- /dev/null +++ b/subgraphs/base/src/price/PriceChainlink.ts @@ -0,0 +1,39 @@ +import { Address, BigDecimal } from "@graphprotocol/graph-ts"; + +import { toDecimal } from "../../../shared/src/utils/Decimals"; +import { ChainlinkPriceFeed } from "../../generated/TokenRecords-base/ChainlinkPriceFeed"; +import { ERC20_WETH } from "../contracts/Constants"; + +const tokenPriceFeedMap: Map = new Map(); +tokenPriceFeedMap.set(ERC20_WETH, "0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70".toLowerCase()); + +export function getPriceFeedTokens(): string[] { + return tokenPriceFeedMap.keys(); +} + +export function getPriceFeed(token: string): string | null { + const tokenLower = token.toLowerCase(); + if (!tokenPriceFeedMap.has(tokenLower)) { + return null; + } + + return tokenPriceFeedMap.get(tokenLower); +} + +export function getPriceFeedValue(tokenAddress: string): BigDecimal | null { + const tokenAddressLower = tokenAddress.toLowerCase(); + if (!tokenPriceFeedMap.has(tokenAddressLower)) { + return null; + } + + const priceFeedAddress = tokenPriceFeedMap.get(tokenAddressLower); + const priceFeed = ChainlinkPriceFeed.bind(Address.fromString(priceFeedAddress)); + const decimalsResult = priceFeed.try_decimals(); + const answerResult = priceFeed.try_latestAnswer(); + + if (decimalsResult.reverted || answerResult.reverted) { + return null; + } + + return toDecimal(answerResult.value, decimalsResult.value); +} \ No newline at end of file diff --git a/subgraphs/base/src/price/PriceLookup.ts b/subgraphs/base/src/price/PriceLookup.ts new file mode 100644 index 00000000..d808c004 --- /dev/null +++ b/subgraphs/base/src/price/PriceLookup.ts @@ -0,0 +1,71 @@ +import { Address, BigDecimal, BigInt, log } from "@graphprotocol/graph-ts"; + +import { PriceHandler, PriceLookupResult } from "../../../shared/src/price/PriceHandler"; +import { PriceHandlerUniswapV2 } from "../../../shared/src/price/PriceHandlerUniswapV2"; +import { getUSDRate } from "../../../shared/src/price/PriceRouter"; +import { + ERC20_OHM, + ERC20_WETH, + LP_UNISWAP_V2_OHM_WETH +} from "../contracts/Constants"; +import { getContractName } from "../contracts/Contracts"; +import { getBaseTokenRate, isBaseToken } from "./PriceBase"; + +export const PRICE_HANDLERS: PriceHandler[] = [ + new PriceHandlerUniswapV2([ERC20_OHM, ERC20_WETH], LP_UNISWAP_V2_OHM_WETH, getContractName), +]; + +/** + * Internal function to determine the price, using the shared price functions. + * + * It simply injects {HANDLERS}, so that {getUSDRate} can operate. + * + * @param tokenAddress + * @param block + * @param currentPool + * @returns + */ +export function getPriceRecursive( + tokenAddress: string, + block: BigInt, + currentPool: string | null, +): PriceLookupResult | null { + const FUNC = "getPriceRecursive"; + + /** + * Check for a base token in this function, instead of getPrice, so that recursive checks can use price feeds. + */ + if (isBaseToken(tokenAddress)) { + const usdRate = getBaseTokenRate(Address.fromString(tokenAddress), block); + return { + price: usdRate, + liquidity: new BigDecimal(BigInt.fromU64(U64.MAX_VALUE)) + } + } + + log.debug("{}: Determining price for {} ({}) and current pool id {}", [FUNC, getContractName(tokenAddress), tokenAddress, currentPool ? currentPool : ""]); + return getUSDRate(tokenAddress, PRICE_HANDLERS, getPriceRecursive, block, currentPool); +} + +/** + * External-facing function that determines the price of {tokenAddress}. + * + * @param tokenAddress + * @param block + * @returns BigDecimal + * @throws Error if a price cannot be found, so that the subgraph indexing fails quickly + */ +export function getPrice(tokenAddress: string, block: BigInt): BigDecimal { + const FUNC = "getPrice"; + log.debug(`${FUNC}: Determining price for ${getContractName(tokenAddress)} (${tokenAddress}) at block ${block.toString()}`, []); + + const priceResult = getPriceRecursive(tokenAddress, block, null); + + if (priceResult === null) { + log.warning("Unable to determine price for token {} ({}) at block {}", [getContractName(tokenAddress), tokenAddress, block.toString()]); + return BigDecimal.zero(); + } + + log.debug("Price for {} ({}) at block {} was: {}", [getContractName(tokenAddress), tokenAddress, block.toString(), priceResult.price.toString()]); + return priceResult.price; +} diff --git a/subgraphs/base/src/treasury/Assets.ts b/subgraphs/base/src/treasury/Assets.ts new file mode 100644 index 00000000..fe23934f --- /dev/null +++ b/subgraphs/base/src/treasury/Assets.ts @@ -0,0 +1,63 @@ +import { BigInt, ethereum, log } from "@graphprotocol/graph-ts"; + +import { TokenRecord, TokenSupply } from "../../../shared/generated/schema"; +import { + TokenCategoryStable, + TokenCategoryVolatile, +} from "../../../shared/src/contracts/TokenDefinition"; +import { pushTokenRecordArray, pushTokenSupplyArray } from "../../../shared/src/utils/ArrayHelper"; +import { getTokenBalances } from "./TokenBalances"; +import { getProtocolOwnedLiquiditySupplyRecords, getTotalSupply, getTreasuryOHMRecords } from "./OhmCalculations"; +import { getOwnedLiquidityBalances } from "./OwnedLiquidity"; + +function generateTokenRecords(timestamp: BigInt, blockNumber: BigInt): TokenRecord[] { + const records: TokenRecord[] = []; + + pushTokenRecordArray( + records, + getTokenBalances(timestamp, TokenCategoryStable, blockNumber), + ); + + + pushTokenRecordArray( + records, + getTokenBalances(timestamp, TokenCategoryVolatile, blockNumber) + ); + + pushTokenRecordArray( + records, + getOwnedLiquidityBalances(timestamp, blockNumber) + ); + + return records; +} + +function generateTokenSupplies(timestamp: BigInt, blockNumber: BigInt): TokenSupply[] { + const records: TokenSupply[] = []; + + // Total supply + pushTokenSupplyArray( + records, + getTotalSupply(timestamp, blockNumber), + ); + + // Treasury OHM + pushTokenSupplyArray( + records, + getTreasuryOHMRecords(timestamp, blockNumber), + ); + + // POL + pushTokenSupplyArray( + records, + getProtocolOwnedLiquiditySupplyRecords(timestamp, blockNumber), + ); + + return records; +} + +export function handleBlock(block: ethereum.Block): void { + log.debug("handleBlock: *** Indexing block {}", [block.number.toString()]); + generateTokenRecords(block.timestamp, block.number); + generateTokenSupplies(block.timestamp, block.number); +} diff --git a/subgraphs/base/src/treasury/OhmCalculations.ts b/subgraphs/base/src/treasury/OhmCalculations.ts new file mode 100644 index 00000000..fc50d4a8 --- /dev/null +++ b/subgraphs/base/src/treasury/OhmCalculations.ts @@ -0,0 +1,117 @@ +import { Address, BigDecimal, BigInt } from "@graphprotocol/graph-ts"; + +import { TokenSupply } from "../../../shared/generated/schema"; +import { getERC20DecimalBalance } from "../../../shared/src/contracts/ERC20"; +import { toDecimal } from "../../../shared/src/utils/Decimals"; +import { createTokenSupply, TYPE_LIQUIDITY, TYPE_TOTAL_SUPPLY, TYPE_TREASURY } from "../../../shared/src/utils/TokenSupplyHelper"; +import { ERC20 } from "../../generated/TokenRecords-base/ERC20"; +import { PROTOCOL_ADDRESSES, ERC20_OHM } from "../contracts/Constants"; +import { getContractName } from "../contracts/Contracts"; +import { PRICE_HANDLERS } from "../price/PriceLookup"; + +export function getTotalSupply(timestamp: BigInt, blockNumber: BigInt): TokenSupply[] { + const contract = ERC20.bind(Address.fromString(ERC20_OHM)); + const totalSupplyResult = contract.try_totalSupply(); + const decimalsResult = contract.try_decimals(); + if (totalSupplyResult.reverted || decimalsResult.reverted) { + return []; + } + + const totalSupply = toDecimal(totalSupplyResult.value, decimalsResult.value); + return [createTokenSupply( + timestamp, getContractName(ERC20_OHM), ERC20_OHM, null, null, null, null, TYPE_TOTAL_SUPPLY, totalSupply, blockNumber)]; +} + +/** + * Returns the supply of protocol- and DAO-owned OHM and gOHM at the given block number. + * + * Unlike on Ethereum mainnet, the raw gOHM value is added to the TokenSupply records. + * This will be converted later into a quantity of OHM. + * + * @param timestamp the current timestamp + * @param blockNumber the current block number + * @returns TokenSupply records + */ +export function getTreasuryOHMRecords(timestamp: BigInt, blockNumber: BigInt): TokenSupply[] { + const records: TokenSupply[] = []; + + // Add native OHM + for (let i = 0; i < PROTOCOL_ADDRESSES.length; i++) { + const currentWallet = PROTOCOL_ADDRESSES[i]; + const balance = getERC20DecimalBalance(ERC20_OHM, currentWallet, blockNumber, getContractName); + if (balance.equals(BigDecimal.zero())) continue; + + records.push( + createTokenSupply( + timestamp, + getContractName(ERC20_OHM), + ERC20_OHM, + null, + null, + getContractName(currentWallet), + currentWallet, + TYPE_TREASURY, + balance, + blockNumber, + -1, // Subtract + ), + ); + } + + return records; +} + +/** + * Returns the quantity of OHM owned by the treasury in + * liquidity pools. + * + * @param blockNumber + * @returns + */ +export function getProtocolOwnedLiquiditySupplyRecords( + timestamp: BigInt, + blockNumber: BigInt, +): TokenSupply[] { + const records: TokenSupply[] = []; + + const ohmTokens = [ERC20_OHM]; + const wallets = PROTOCOL_ADDRESSES; + + for (let i = 0; i < PRICE_HANDLERS.length; i++) { + const pairHandler = PRICE_HANDLERS[i]; + + for (let j = 0; j < ohmTokens.length; j++) { + const currentOhmToken = ohmTokens[j]; + // We only want to look at pairs that contain an OHM token + if (!pairHandler.matches(currentOhmToken)) { + continue; + } + + for (let k = 0; k < wallets.length; k++) { + const currentWallet = wallets[k]; + const balance: BigDecimal = pairHandler.getUnderlyingTokenBalance(currentWallet, currentOhmToken, blockNumber); + if (balance.equals(BigDecimal.zero())) { + continue; + } + + records.push( + createTokenSupply( + timestamp, + getContractName(currentOhmToken), + currentOhmToken, + getContractName(pairHandler.getId()), + pairHandler.getId(), + getContractName(currentWallet), + currentWallet, + TYPE_LIQUIDITY, + balance, + blockNumber, + -1, // Subtract + ), + ) + } + } + } + + return records; +} diff --git a/subgraphs/base/src/treasury/OwnedLiquidity.ts b/subgraphs/base/src/treasury/OwnedLiquidity.ts new file mode 100644 index 00000000..71b88e46 --- /dev/null +++ b/subgraphs/base/src/treasury/OwnedLiquidity.ts @@ -0,0 +1,98 @@ +import { BigDecimal, BigInt, log } from "@graphprotocol/graph-ts"; + +import { TokenRecord } from "../../../shared/generated/schema"; +import { PriceHandler } from "../../../shared/src/price/PriceHandler"; +import { pushTokenRecordArray } from "../../../shared/src/utils/ArrayHelper"; +import { + createTokenRecord, + getIsTokenLiquid, +} from "../../../shared/src/utils/TokenRecordHelper"; +import { BLOCKCHAIN, ERC20_TOKENS_BASE, OHM_TOKENS, PROTOCOL_ADDRESSES } from "../contracts/Constants"; +import { getContractName } from "../contracts/Contracts"; +import { getPriceRecursive, PRICE_HANDLERS } from "../price/PriceLookup"; + +/** + * Returns the token records for a given token. This includes: + * - Wallets + * - Allocators + * + * @param contractAddress the address of the ERC20 contract + * @param block the current block + * @returns TokenRecord array + */ +function getOwnedLiquidityBalance( + timestamp: BigInt, + liquidityHandler: PriceHandler, + block: BigInt, +): TokenRecord[] { + const contractName = getContractName(liquidityHandler.getId()); + log.info("getOwnedLiquidityBalance: Calculating balance for {} ({}) at block number {}", [ + contractName, + liquidityHandler.getId(), + block.toString(), + ]); + const records: TokenRecord[] = []; + + // Calculate the multiplier + const totalValue = liquidityHandler.getTotalValue([], getPriceRecursive, block); + if (!totalValue || totalValue.equals(BigDecimal.zero())) { + return records; + } + const includedValue = liquidityHandler.getTotalValue(OHM_TOKENS, getPriceRecursive, block); + if (!includedValue) { + return records; + } + const multiplier = includedValue.div(totalValue); + + // Get the unit rate + const unitRate = liquidityHandler.getUnitPrice(getPriceRecursive, block); + if (!unitRate) { + return records; + } + + for (let i = 0; i < PROTOCOL_ADDRESSES.length; i++) { + const currentWalletAddress = PROTOCOL_ADDRESSES[i]; + + // Get the balance + const balance = liquidityHandler.getBalance(currentWalletAddress, block); + if (balance.equals(BigDecimal.zero())) { + continue; + } + + // Create record + const record = createTokenRecord( + timestamp, + getContractName(liquidityHandler.getId()), + liquidityHandler.getId(), + getContractName(currentWalletAddress), + currentWalletAddress, + unitRate, + balance, + block, + getIsTokenLiquid(liquidityHandler.getId(), ERC20_TOKENS_BASE), + ERC20_TOKENS_BASE, + BLOCKCHAIN, + multiplier, + ); + records.push(record); + } + + return records; +} + +/** + * Gets the balances for all tokens in the category, using {getTokenBalance}. + * + * @param timestamp + * @param blockNumber the current block + * @returns TokenRecord array + */ +export function getOwnedLiquidityBalances(timestamp: BigInt, blockNumber: BigInt): TokenRecord[] { + const records: TokenRecord[] = []; + + for (let i = 0; i < PRICE_HANDLERS.length; i++) { + pushTokenRecordArray(records, getOwnedLiquidityBalance(timestamp, PRICE_HANDLERS[i], blockNumber)); + } + + return records; +} diff --git a/subgraphs/base/src/treasury/TokenBalances.ts b/subgraphs/base/src/treasury/TokenBalances.ts new file mode 100644 index 00000000..bd8eda81 --- /dev/null +++ b/subgraphs/base/src/treasury/TokenBalances.ts @@ -0,0 +1,72 @@ +import { BigInt, log } from "@graphprotocol/graph-ts"; + +import { TokenRecord } from "../../../shared/generated/schema"; +import { getERC20 } from "../../../shared/src/contracts/ERC20"; +import { pushTokenRecordArray } from "../../../shared/src/utils/ArrayHelper"; +import { getTokensInCategory } from "../../../shared/src/utils/TokenRecordHelper"; +import { ERC20_TOKENS_BASE } from "../contracts/Constants"; +import { getContractName, getERC20TokenRecordsFromWallets } from "../contracts/Contracts"; +import { getPrice } from "../price/PriceLookup"; + +/** + * Returns the token records for a given token. This includes: + * - Wallets + * - Allocators + * + * @param contractAddress the address of the ERC20 contract + * @param blockNumber the current block + * @returns TokenRecord array + */ +function getTokenBalance( + timestamp: BigInt, + contractAddress: string, + blockNumber: BigInt, +): TokenRecord[] { + const contractName = getContractName(contractAddress); + log.info("getTokenBalance: Calculating balance for {} ({}) at block number {}", [ + contractName, + contractAddress, + blockNumber.toString(), + ]); + const records: TokenRecord[] = []; + const contract = getERC20(contractAddress, blockNumber); + if (!contract) { + log.info("getTokenBalance: Skipping ERC20 contract {} that returned empty at block {}", [ + getContractName(contractAddress), + blockNumber.toString(), + ]); + return records; + } + + const rate = getPrice(contractAddress, blockNumber); + + // Standard ERC20 + pushTokenRecordArray( + records, + getERC20TokenRecordsFromWallets(timestamp, contractAddress, contract, rate, blockNumber), + ); + + return records; +} + +/** + * Gets the balances for all tokens in the category, using {getTokenBalance}. + * + * @param timestamp + * @param blockNumber the current block + * @returns TokenRecord array + */ +export function getTokenBalances( + timestamp: BigInt, + category: string, + blockNumber: BigInt, +): TokenRecord[] { + const records: TokenRecord[] = []; + + const categoryTokens = getTokensInCategory(category, ERC20_TOKENS_BASE); + for (let i = 0; i < categoryTokens.length; i++) { + pushTokenRecordArray(records, getTokenBalance(timestamp, categoryTokens[i].getAddress(), blockNumber)); + } + + return records; +} diff --git a/subgraphs/base/subgraph.yaml b/subgraphs/base/subgraph.yaml new file mode 100644 index 00000000..54bb01e0 --- /dev/null +++ b/subgraphs/base/subgraph.yaml @@ -0,0 +1,38 @@ +specVersion: 0.0.4 +description: Olympus Protocol Metrics Subgraph - Base +repository: https://github.com/OlympusDAO/olympus-protocol-metrics-subgraph +schema: + file: ../../schema.graphql +dataSources: + - kind: ethereum/contract + name: TokenRecords-base + network: base + source: + address: "0x060cb087a9730E13aa191f31A6d86bFF8DfcdCC0" # OHM + abi: ERC20 + startBlock: 13204827 # 2024-04-15 + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - TokenRecord + - TokenSupply + abis: + - name: ERC20 + file: ../shared/abis/ERC20.json + # Price Lookup + - name: UniswapV2Pair + file: ../shared/abis/UniswapV2Pair.json + - name: UniswapV3Pair + file: ../shared/abis/UniswapV3Pair.json + - name: ChainlinkPriceFeed + file: ../shared/abis/ChainlinkPriceFeed.json + blockHandlers: + - handler: handleBlock + filter: + kind: polling + # Every 8 hours + # 0.5 blocks every second * 60 seconds * 60 minutes * 8 hours + every: 7200 + file: ./src/treasury/Assets.ts From c5b8864903f081587836080ee1ee76b9fae8a475 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Tue, 4 Jun 2024 21:15:30 +0400 Subject: [PATCH 02/20] Build fix --- subgraphs/base/src/contracts/Contracts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgraphs/base/src/contracts/Contracts.ts b/subgraphs/base/src/contracts/Contracts.ts index aa950162..e5a58073 100644 --- a/subgraphs/base/src/contracts/Contracts.ts +++ b/subgraphs/base/src/contracts/Contracts.ts @@ -2,7 +2,7 @@ import { BigDecimal, BigInt } from "@graphprotocol/graph-ts"; import { BLOCKCHAIN, CONTRACT_ABBREVIATION_MAP, CONTRACT_NAME_MAP, ERC20_TOKENS_BASE, getWalletAddressesForContract } from "./Constants"; import { TokenRecord } from "../../../shared/generated/schema"; import { getERC20TokenRecordFromWallet } from "../../../shared/src/contracts/ERC20"; -import { ERC20 } from "../../generated/TokenRecords-base/ERC20"; +import { ERC20 } from "../../../shared/generated/Price/ERC20"; export function getContractName( contractAddress: string, From 75f83a79db7399bd9d26f5571000187214740703 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Tue, 4 Jun 2024 21:24:09 +0400 Subject: [PATCH 03/20] Bump spec version --- subgraphs/base/subgraph.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgraphs/base/subgraph.yaml b/subgraphs/base/subgraph.yaml index 54bb01e0..e9be76be 100644 --- a/subgraphs/base/subgraph.yaml +++ b/subgraphs/base/subgraph.yaml @@ -1,4 +1,4 @@ -specVersion: 0.0.4 +specVersion: 0.0.8 description: Olympus Protocol Metrics Subgraph - Base repository: https://github.com/OlympusDAO/olympus-protocol-metrics-subgraph schema: From 588b017ddd72dd04463958e6a8e1b09c4a9908b3 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Tue, 4 Jun 2024 21:24:24 +0400 Subject: [PATCH 04/20] Check PriceHandler for reverts --- subgraphs/base/config.json | 2 +- subgraphs/base/src/treasury/OhmCalculations.ts | 15 ++++++++++----- subgraphs/shared/src/price/PriceHandler.ts | 17 +++++++++++------ .../shared/src/price/PriceHandlerBalancer.ts | 4 ++++ .../src/price/PriceHandlerCustomMapping.ts | 4 ++++ .../shared/src/price/PriceHandlerStablecoin.ts | 5 +++++ .../shared/src/price/PriceHandlerUniswapV2.ts | 6 +++++- .../shared/src/price/PriceHandlerUniswapV3.ts | 4 ++++ 8 files changed, 44 insertions(+), 13 deletions(-) diff --git a/subgraphs/base/config.json b/subgraphs/base/config.json index 6147f004..5f6b7c83 100644 --- a/subgraphs/base/config.json +++ b/subgraphs/base/config.json @@ -2,5 +2,5 @@ "id": "QmRf3fo7tVsXsj9cQZSgT3Y2R67Hv41T1Ph559oQAmTLe1", "org": "olympusdao", "name": "protocol-metrics-base", - "version": "0.0.1" + "version": "0.0.2" } \ No newline at end of file diff --git a/subgraphs/base/src/treasury/OhmCalculations.ts b/subgraphs/base/src/treasury/OhmCalculations.ts index fc50d4a8..25157e1b 100644 --- a/subgraphs/base/src/treasury/OhmCalculations.ts +++ b/subgraphs/base/src/treasury/OhmCalculations.ts @@ -78,18 +78,23 @@ export function getProtocolOwnedLiquiditySupplyRecords( const wallets = PROTOCOL_ADDRESSES; for (let i = 0; i < PRICE_HANDLERS.length; i++) { - const pairHandler = PRICE_HANDLERS[i]; + const priceHandler = PRICE_HANDLERS[i]; for (let j = 0; j < ohmTokens.length; j++) { const currentOhmToken = ohmTokens[j]; // We only want to look at pairs that contain an OHM token - if (!pairHandler.matches(currentOhmToken)) { + if (!priceHandler.matches(currentOhmToken)) { + continue; + } + + // Ignore if the price handler is not available yet + if (!priceHandler.exists()) { continue; } for (let k = 0; k < wallets.length; k++) { const currentWallet = wallets[k]; - const balance: BigDecimal = pairHandler.getUnderlyingTokenBalance(currentWallet, currentOhmToken, blockNumber); + const balance: BigDecimal = priceHandler.getUnderlyingTokenBalance(currentWallet, currentOhmToken, blockNumber); if (balance.equals(BigDecimal.zero())) { continue; } @@ -99,8 +104,8 @@ export function getProtocolOwnedLiquiditySupplyRecords( timestamp, getContractName(currentOhmToken), currentOhmToken, - getContractName(pairHandler.getId()), - pairHandler.getId(), + getContractName(priceHandler.getId()), + priceHandler.getId(), getContractName(currentWallet), currentWallet, TYPE_LIQUIDITY, diff --git a/subgraphs/shared/src/price/PriceHandler.ts b/subgraphs/shared/src/price/PriceHandler.ts index 799fae0f..a6e88a59 100644 --- a/subgraphs/shared/src/price/PriceHandler.ts +++ b/subgraphs/shared/src/price/PriceHandler.ts @@ -36,6 +36,11 @@ export interface PriceHandler { */ getId(): string; + /** + * @returns true if the liquidity pool exists at the current block + */ + exists(): boolean; + /** * @returns true if {tokenAddress} can be handled */ @@ -74,17 +79,17 @@ export interface PriceHandler { /** * Returns the balance of the liquidity pool held by {walletAddress}. - * - * @param walletAddress - * @param block + * + * @param walletAddress + * @param block */ getBalance(walletAddress: string, block: BigInt): BigDecimal; /** * Returns the balance of the underlying token held by the liquidity pool. - * - * @param tokenAddress - * @param block + * + * @param tokenAddress + * @param block */ getUnderlyingTokenBalance(walletAddress: string, tokenAddress: string, block: BigInt): BigDecimal; } diff --git a/subgraphs/shared/src/price/PriceHandlerBalancer.ts b/subgraphs/shared/src/price/PriceHandlerBalancer.ts index beb790a4..808c5d31 100644 --- a/subgraphs/shared/src/price/PriceHandlerBalancer.ts +++ b/subgraphs/shared/src/price/PriceHandlerBalancer.ts @@ -61,6 +61,10 @@ export class PriceHandlerBalancer implements PriceHandler { return vault; } + exists(): boolean { + return this.getVault(BigInt.zero()) !== null; + } + private getPoolToken(block: BigInt): BalancerPoolToken | null { const FUNCTION = `${CLASS}: getPoolToken:`; const vault = this.getVault(block); diff --git a/subgraphs/shared/src/price/PriceHandlerCustomMapping.ts b/subgraphs/shared/src/price/PriceHandlerCustomMapping.ts index 570cab80..9bedfbea 100644 --- a/subgraphs/shared/src/price/PriceHandlerCustomMapping.ts +++ b/subgraphs/shared/src/price/PriceHandlerCustomMapping.ts @@ -28,6 +28,10 @@ export class PriceHandlerCustomMapping implements PriceHandler { return `${this.tokenAddress}-${this.mappedTokenAddresses.join("/")}`; } + exists(): boolean { + return true; + } + matches(tokenAddress: string): boolean { return arrayIncludesLoose(this.mappedTokenAddresses, tokenAddress); } diff --git a/subgraphs/shared/src/price/PriceHandlerStablecoin.ts b/subgraphs/shared/src/price/PriceHandlerStablecoin.ts index c59cbcb8..fa78f6d6 100644 --- a/subgraphs/shared/src/price/PriceHandlerStablecoin.ts +++ b/subgraphs/shared/src/price/PriceHandlerStablecoin.ts @@ -15,10 +15,15 @@ export class PriceHandlerStablecoin implements PriceHandler { this.addresses = addresses; this.contractLookup = contractLookup; } + getId(): string { return "PriceHandlerStablecoin"; } + exists(): boolean { + return true; + } + matches(tokenAddress: string): boolean { return arrayIncludesLoose(this.addresses, tokenAddress); } diff --git a/subgraphs/shared/src/price/PriceHandlerUniswapV2.ts b/subgraphs/shared/src/price/PriceHandlerUniswapV2.ts index dc38ba1a..85ee8868 100644 --- a/subgraphs/shared/src/price/PriceHandlerUniswapV2.ts +++ b/subgraphs/shared/src/price/PriceHandlerUniswapV2.ts @@ -1,4 +1,4 @@ -import { Address, BigDecimal, BigInt, log } from "@graphprotocol/graph-ts"; +import { Address, BigDecimal, BigInt, dataSource, log } from "@graphprotocol/graph-ts"; import { UniswapV2Pair } from "../../generated/Price/UniswapV2Pair"; import { ContractNameLookup } from "../contracts/ContractLookup"; @@ -25,6 +25,10 @@ export class PriceHandlerUniswapV2 implements PriceHandler { return this.poolAddress; } + exists(): boolean { + return this.getContract(BigInt.zero()) !== null; + } + matches(tokenAddress: string): boolean { return arrayIncludesLoose(this.tokens, tokenAddress); } diff --git a/subgraphs/shared/src/price/PriceHandlerUniswapV3.ts b/subgraphs/shared/src/price/PriceHandlerUniswapV3.ts index 4997755c..39f37e64 100644 --- a/subgraphs/shared/src/price/PriceHandlerUniswapV3.ts +++ b/subgraphs/shared/src/price/PriceHandlerUniswapV3.ts @@ -42,6 +42,10 @@ export class PriceHandlerUniswapV3 implements PriceHandler { return this.poolAddress; } + exists(): boolean { + return this.getContract(BigInt.zero()) !== null; + } + matches(tokenAddress: string): boolean { return arrayIncludesLoose(this.tokens, tokenAddress); } From 1e9ef6a6b9df85543b49955f5f023064d466fa08 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Tue, 4 Jun 2024 21:24:38 +0400 Subject: [PATCH 05/20] Version bump --- subgraphs/base/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgraphs/base/config.json b/subgraphs/base/config.json index 5f6b7c83..31cbf6b9 100644 --- a/subgraphs/base/config.json +++ b/subgraphs/base/config.json @@ -1,5 +1,5 @@ { - "id": "QmRf3fo7tVsXsj9cQZSgT3Y2R67Hv41T1Ph559oQAmTLe1", + "id": "QmdqJ1zoExrs8u2T93wXSRWSx5VSKqKWTV4gCE2vszGwgt", "org": "olympusdao", "name": "protocol-metrics-base", "version": "0.0.2" From d2acd1e9a9fb405736d30b8e6a9058f96959e603 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Tue, 4 Jun 2024 21:25:13 +0400 Subject: [PATCH 06/20] TODO --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5cde29c7..d4533ee8 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Deployed at: - [Polygon](https://thegraph.com/explorer/subgraphs/aF7zBXagiSjwwM1yAUiyrWFJDhh5RLpVn2nuvVbKwDw?view=Overview&chain=arbitrum-one) - [Arbitrum](https://thegraph.com/explorer/subgraphs/8Zxb1kVv9ZBChHXEPSgtC5u5gjCijMn5k8ErpzRYWNgH?view=Overview&chain=arbitrum-one) - [Fantom](https://thegraph.com/hosted-service/subgraph/olympusdao/protocol-metrics-polygon) +- TODO: [Base]() ## Initial Setup From 854ea230fec6578d5a3de74044cae24f6bba7b9a Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Tue, 4 Jun 2024 21:41:46 +0400 Subject: [PATCH 07/20] Add CHANGELOG for Base --- subgraphs/base/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 subgraphs/base/CHANGELOG.md diff --git a/subgraphs/base/CHANGELOG.md b/subgraphs/base/CHANGELOG.md new file mode 100644 index 00000000..e00fbba5 --- /dev/null +++ b/subgraphs/base/CHANGELOG.md @@ -0,0 +1,5 @@ +# Base Subgraph Changelog + +## 0.0.1 (2024-06-04) + +- Adds POL in Uniswap V2 From ad982f182ea1cb6bc71e74d17165144bdc4e17a1 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Tue, 4 Jun 2024 21:42:59 +0400 Subject: [PATCH 08/20] Adds Camelot POL on Arbitrum --- subgraphs/arbitrum/CHANGELOG.md | 4 ++++ subgraphs/arbitrum/config.json | 4 ++-- subgraphs/arbitrum/src/contracts/Constants.ts | 18 ++++++++++++++---- subgraphs/arbitrum/src/contracts/Contracts.ts | 5 +++-- subgraphs/arbitrum/subgraph.yaml | 4 ++-- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/subgraphs/arbitrum/CHANGELOG.md b/subgraphs/arbitrum/CHANGELOG.md index 3b956f25..00a8eec0 100644 --- a/subgraphs/arbitrum/CHANGELOG.md +++ b/subgraphs/arbitrum/CHANGELOG.md @@ -1,5 +1,9 @@ # Arbitrum Subgraph Changelog +## 1.7.0 (2024-06-04) + +- Adds POL in Camelot + ## 1.6.4 (2023-09-13) - Apply write-off of JonesDAO token, since it cannot be sold. diff --git a/subgraphs/arbitrum/config.json b/subgraphs/arbitrum/config.json index 43effae5..33c6fe62 100644 --- a/subgraphs/arbitrum/config.json +++ b/subgraphs/arbitrum/config.json @@ -1,6 +1,6 @@ { - "id": "QmRf3fo7tVsXsj9cQZSgT3Y2R67Hv41T1Ph559oQAmTLe1", + "id": "Qmb57LCGXQ6EQcDwKVgTx6U9ChuAEcdrQ63YpBkbk3yyhX", "org": "olympusdao", "name": "protocol-metrics-arbitrum", - "version": "1.6.4" + "version": "1.7.0" } \ No newline at end of file diff --git a/subgraphs/arbitrum/src/contracts/Constants.ts b/subgraphs/arbitrum/src/contracts/Constants.ts index c1a6a4f3..12c29dfa 100644 --- a/subgraphs/arbitrum/src/contracts/Constants.ts +++ b/subgraphs/arbitrum/src/contracts/Constants.ts @@ -27,6 +27,7 @@ export const LP_UNISWAP_V2_JONES_GOHM_GOHM = "0x292d1587a6bb37e34574c9ad5993f221 export const LP_UNISWAP_V2_JONES_WETH = "0xe8ee01ae5959d3231506fcdef2d5f3e85987a39c".toLowerCase(); export const LP_UNISWAP_V2_LQTY_WETH = "0x8e78f0f6d116f94252d3bcd73d8ade63d415c1bf".toLowerCase(); export const LP_UNISWAP_V2_MAGIC_WETH = "0xb7e50106a5bd3cf21af210a755f9c8740890a8c9".toLowerCase(); +export const LP_CAMELOT_OHM_WETH = "0x8aCd42e4B5A5750B44A28C5fb50906eBfF145359".toLowerCase(); export const LP_UNISWAP_V3_ARB_WETH = "0xc6f780497a95e246eb9449f5e4770916dcd6396a".toLowerCase(); export const LP_UNISWAP_V3_WETH_USDC = "0xc31e54c7a869b9fcbecc14363cf510d1c41fa443".toLowerCase(); @@ -71,19 +72,27 @@ ERC20_TOKENS_ARBITRUM.set(LP_UNISWAP_V2_GOHM_WETH, new TokenDefinition(LP_UNISWA ERC20_TOKENS_ARBITRUM.set(LP_UNISWAP_V2_JONES_GOHM_GOHM, new TokenDefinition(LP_UNISWAP_V2_JONES_GOHM_GOHM, TokenCategoryPOL, true, false)); ERC20_TOKENS_ARBITRUM.set(LP_UNISWAP_V2_JONES_WETH, new TokenDefinition(LP_UNISWAP_V2_JONES_WETH, TokenCategoryPOL, true, false)); ERC20_TOKENS_ARBITRUM.set(LP_UNISWAP_V2_MAGIC_WETH, new TokenDefinition(LP_UNISWAP_V2_MAGIC_WETH, TokenCategoryPOL, true, false)); +ERC20_TOKENS_ARBITRUM.set(LP_CAMELOT_OHM_WETH, new TokenDefinition(LP_CAMELOT_OHM_WETH, TokenCategoryPOL, true, false)); ERC20_TOKENS_ARBITRUM.set(LP_UNISWAP_V3_ARB_WETH, new TokenDefinition(LP_UNISWAP_V3_ARB_WETH, TokenCategoryPOL, true, false)); ERC20_TOKENS_ARBITRUM.set(LP_UNISWAP_V3_WETH_USDC, new TokenDefinition(LP_UNISWAP_V3_WETH_USDC, TokenCategoryPOL, true, false)); export const OHM_TOKENS = [ERC20_GOHM_SYNAPSE, ERC20_OHM]; +export const DAO_MULTISIG = "0x012BBf0481b97170577745D2167ee14f63E2aD4C".toLowerCase(); + +export const getProtocolAddresses = (): string[] => { + // Combine the wallet addresses with DAO multisig + return WALLET_ADDRESSES.concat([DAO_MULTISIG]); +}; + const TREASURY_BLACKLIST = new Map(); /** * OHM and gOHM in the following wallets are blacklisted (not indexed) as we do not want the value * being considered as part of the protocol or DAO treasuries. */ -TREASURY_BLACKLIST.set(ERC20_GOHM_SYNAPSE, WALLET_ADDRESSES); -TREASURY_BLACKLIST.set(ERC20_OHM, WALLET_ADDRESSES); +TREASURY_BLACKLIST.set(ERC20_GOHM_SYNAPSE, getProtocolAddresses()); +TREASURY_BLACKLIST.set(ERC20_OHM, getProtocolAddresses()); /** * Some wallets (e.g. {DAO_WALLET}) have specific treasury assets mixed into them. @@ -96,7 +105,7 @@ TREASURY_BLACKLIST.set(ERC20_OHM, WALLET_ADDRESSES); * @returns */ export const getWalletAddressesForContract = (contractAddress: string): string[] => { - const walletAddresses = WALLET_ADDRESSES.slice(0); + const walletAddresses = getProtocolAddresses().slice(0); // If the contract isn't on the blacklist, return as normal if (!TREASURY_BLACKLIST.has(contractAddress.toLowerCase())) { @@ -124,7 +133,7 @@ export const getWalletAddressesForContract = (contractAddress: string): string[] /** * Defines the contract addresses that belong to the protocol & DAO treasuries. - * + * * This is normally deducted from total supply to determine circulating supply. */ export const CIRCULATING_SUPPLY_WALLETS = [ @@ -176,6 +185,7 @@ CONTRACT_NAME_MAP.set(LP_UNISWAP_V2_JONES_GOHM_GOHM, "UniswapV2 jgOHM-gOHM Liqui CONTRACT_NAME_MAP.set(LP_UNISWAP_V2_JONES_WETH, "UniswapV2 JONES-wETH Liquidity Pool"); CONTRACT_NAME_MAP.set(LP_UNISWAP_V2_LQTY_WETH, "Ramses LQTY-wETH Liquidity Pool"); CONTRACT_NAME_MAP.set(LP_UNISWAP_V2_MAGIC_WETH, "UniswapV2 MAGIC-wETH Liquidity Pool"); +CONTRACT_NAME_MAP.set(LP_CAMELOT_OHM_WETH, "Camelot OHM-wETH Liquidity Pool"); CONTRACT_NAME_MAP.set(LP_UNISWAP_V3_ARB_WETH, "UniswapV3 ARB-wETH Liquidity Pool"); CONTRACT_NAME_MAP.set(LP_UNISWAP_V3_WETH_USDC, "UniswapV3 wETH-USDC Liquidity Pool"); CONTRACT_NAME_MAP.set(LUSD_ALLOCATOR, "LUSD Allocator"); diff --git a/subgraphs/arbitrum/src/contracts/Contracts.ts b/subgraphs/arbitrum/src/contracts/Contracts.ts index 122c8aec..1fa14183 100644 --- a/subgraphs/arbitrum/src/contracts/Contracts.ts +++ b/subgraphs/arbitrum/src/contracts/Contracts.ts @@ -3,7 +3,7 @@ import { BigDecimal, BigInt, log } from "@graphprotocol/graph-ts"; import { ERC20 } from "../../../shared/generated/Price/ERC20"; import { TokenRecord } from "../../../shared/generated/schema"; import { getERC20TokenRecordFromWallet } from "../../../shared/src/contracts/ERC20"; -import { DAO_WALLET, WALLET_ADDRESSES } from "../../../shared/src/Wallets"; +import { DAO_WALLET } from "../../../shared/src/Wallets"; import { BLOCKCHAIN, CONTRACT_ABBREVIATION_MAP, @@ -12,6 +12,7 @@ import { ERC20_TOKENS_ARBITRUM, ERC20_WETH, JONES_WRITE_OFF_BLOCK, + getProtocolAddresses, } from "./Constants"; import { getTokenRecordValue } from "../../../shared/src/utils/TokenRecordHelper"; @@ -56,7 +57,7 @@ export const getWalletAddressesForContract = (contractAddress: string): string[] const nonTreasuryAddresses = NON_TREASURY_ASSET_WHITELIST.has(contractAddress.toLowerCase()) ? NON_TREASURY_ASSET_WHITELIST.get(contractAddress.toLowerCase()) : []; - const newAddresses = WALLET_ADDRESSES.slice(0); + const newAddresses = getProtocolAddresses().slice(0); // Add the values of nonTreasuryAddresses, but filter duplicates for (let i = 0; i < nonTreasuryAddresses.length; i++) { diff --git a/subgraphs/arbitrum/subgraph.yaml b/subgraphs/arbitrum/subgraph.yaml index dfa2e18c..e289e162 100644 --- a/subgraphs/arbitrum/subgraph.yaml +++ b/subgraphs/arbitrum/subgraph.yaml @@ -6,8 +6,8 @@ repository: https://github.com/OlympusDAO/olympus-protocol-metrics-subgraph features: - grafting graft: - base: QmXVMuS639JzTTq9ZVkRnGFTftiYJ8c6FPrB52qCshSnFa # 1.5.3 - block: 130482707 # JonesDAO write-off + base: QmRf3fo7tVsXsj9cQZSgT3Y2R67Hv41T1Ph559oQAmTLe1 # 1.6.4 + block: 190428287 # POL deployment schema: file: ../../schema.graphql dataSources: From 2d42c35ec6fbaa77328aa68517901959f2902d83 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Wed, 5 Jun 2024 21:06:25 +0400 Subject: [PATCH 09/20] Shift Arbitrum to polling block handler --- subgraphs/arbitrum/CHANGELOG.md | 2 +- subgraphs/arbitrum/config.json | 4 ++-- subgraphs/arbitrum/subgraph.yaml | 30 +++++++++++++----------------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/subgraphs/arbitrum/CHANGELOG.md b/subgraphs/arbitrum/CHANGELOG.md index 00a8eec0..2863a4b9 100644 --- a/subgraphs/arbitrum/CHANGELOG.md +++ b/subgraphs/arbitrum/CHANGELOG.md @@ -1,6 +1,6 @@ # Arbitrum Subgraph Changelog -## 1.7.0 (2024-06-04) +## 1.7.1 (2024-06-04) - Adds POL in Camelot diff --git a/subgraphs/arbitrum/config.json b/subgraphs/arbitrum/config.json index 33c6fe62..add42e8f 100644 --- a/subgraphs/arbitrum/config.json +++ b/subgraphs/arbitrum/config.json @@ -1,6 +1,6 @@ { - "id": "Qmb57LCGXQ6EQcDwKVgTx6U9ChuAEcdrQ63YpBkbk3yyhX", + "id": "QmYSsMwPJPzaLELSYLWqaQ21Rz5VjMNrVh7SsUW4dcqGXu", "org": "olympusdao", "name": "protocol-metrics-arbitrum", - "version": "1.7.0" + "version": "1.7.1" } \ No newline at end of file diff --git a/subgraphs/arbitrum/subgraph.yaml b/subgraphs/arbitrum/subgraph.yaml index e289e162..2bbe4d84 100644 --- a/subgraphs/arbitrum/subgraph.yaml +++ b/subgraphs/arbitrum/subgraph.yaml @@ -1,13 +1,13 @@ -specVersion: 0.0.4 +specVersion: 0.0.8 description: Olympus Protocol Metrics Subgraph - Arbitrum repository: https://github.com/OlympusDAO/olympus-protocol-metrics-subgraph # Given the block speed of Arbitrum, it is abominably slow to index from scratch. # Avoid changing the schema, as it will require indexing from scratch. -features: - - grafting -graft: - base: QmRf3fo7tVsXsj9cQZSgT3Y2R67Hv41T1Ph559oQAmTLe1 # 1.6.4 - block: 190428287 # POL deployment +# features: +# - grafting +# graft: +# base: QmRf3fo7tVsXsj9cQZSgT3Y2R67Hv41T1Ph559oQAmTLe1 # 1.6.4 +# block: 190428287 # POL deployment schema: file: ../../schema.graphql dataSources: @@ -50,15 +50,11 @@ dataSources: file: abis/TreasureMining.json - name: ChainlinkAggregator file: abis/ChainlinkAggregator.json - # This can be re-enabled, but likely needs a reindexing from scratch - # blockHandlers: - # - handler: handleBlock - # filter: - # kind: polling - # # Every 4 hours - # # 4 blocks per second * 60 seconds * 60 minutes * 4 hours - # every: 57600 - eventHandlers: - - event: NewRound(indexed uint256,indexed address,uint256) - handler: handleEvent + blockHandlers: + - handler: handleBlock + filter: + kind: polling + # Every 8 hours + # 4 blocks per second * 60 seconds * 60 minutes * 8 hours + every: 115200 file: ./src/treasury/Assets.ts From c6daef0414cf84c332ae8399a48d920c81dbc760 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Thu, 6 Jun 2024 21:46:58 +0400 Subject: [PATCH 10/20] Update URL for Fantom --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d4533ee8..f39185ec 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Deployed at: - [Ethereum mainnet](https://thegraph.com/explorer/subgraphs/7jeChfyUTWRyp2JxPGuuzxvGt3fDKMkC9rLjm7sfLcNp?view=Overview&chain=arbitrum-one) - [Polygon](https://thegraph.com/explorer/subgraphs/aF7zBXagiSjwwM1yAUiyrWFJDhh5RLpVn2nuvVbKwDw?view=Overview&chain=arbitrum-one) - [Arbitrum](https://thegraph.com/explorer/subgraphs/8Zxb1kVv9ZBChHXEPSgtC5u5gjCijMn5k8ErpzRYWNgH?view=Overview&chain=arbitrum-one) -- [Fantom](https://thegraph.com/hosted-service/subgraph/olympusdao/protocol-metrics-polygon) +- [Fantom](https://thegraph.com/explorer/subgraphs/3qSJTWdWJETFzht814HVV9rVafwRLQp3k9mZhCF39bYd?v=1&view=Query&chain=arbitrum-one) - TODO: [Base]() ## Initial Setup From 6d5a404d6b2b36dba7279a490f8bdb2ebd3355b6 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Fri, 7 Jun 2024 21:31:36 +0400 Subject: [PATCH 11/20] Add Base address --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f39185ec..2b8990b7 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Deployed at: - [Polygon](https://thegraph.com/explorer/subgraphs/aF7zBXagiSjwwM1yAUiyrWFJDhh5RLpVn2nuvVbKwDw?view=Overview&chain=arbitrum-one) - [Arbitrum](https://thegraph.com/explorer/subgraphs/8Zxb1kVv9ZBChHXEPSgtC5u5gjCijMn5k8ErpzRYWNgH?view=Overview&chain=arbitrum-one) - [Fantom](https://thegraph.com/explorer/subgraphs/3qSJTWdWJETFzht814HVV9rVafwRLQp3k9mZhCF39bYd?v=1&view=Query&chain=arbitrum-one) -- TODO: [Base]() +- [Base](https://thegraph.com/explorer/subgraphs/3YAC1Gj2AUFCQ8wd4DaBQmqU3DJZjKyr45dQykAtXuMU?view=Overview&chain=arbitrum-one) ## Initial Setup From 21f9593121e52acf13ba6b6a9a4cf6ad19bec5db Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Thu, 11 Jul 2024 21:47:41 +0400 Subject: [PATCH 12/20] Handle revert from LUSD --- subgraphs/arbitrum/src/contracts/Constants.ts | 1 + subgraphs/arbitrum/src/treasury/TokenBalances.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/subgraphs/arbitrum/src/contracts/Constants.ts b/subgraphs/arbitrum/src/contracts/Constants.ts index 12c29dfa..c0849b82 100644 --- a/subgraphs/arbitrum/src/contracts/Constants.ts +++ b/subgraphs/arbitrum/src/contracts/Constants.ts @@ -46,6 +46,7 @@ export const SILO_ADDRESS = "0x9992f660137979C1ca7f8b119Cd16361594E3681".toLower export const SENTIMENT_LTOKEN = "0x37E6a0EcB9e8E5D90104590049a0A197E1363b67".toLowerCase(); export const JONES_WRITE_OFF_BLOCK = "130482707"; +export const LUSD_START_BLOCK = "80000000"; export const SILO_DEPLOYMENTS = new Array(); SILO_DEPLOYMENTS.push(new LendingMarketDeployment(ERC20_OHM, BigInt.fromString("99067079"), BigDecimal.fromString("25000"), SILO_ADDRESS)); // https://arbiscan.io/tx/0x55cabbd6cd41d2fa79a6c93743729bbfa85577ff3e92255f27bfd832344871f6 diff --git a/subgraphs/arbitrum/src/treasury/TokenBalances.ts b/subgraphs/arbitrum/src/treasury/TokenBalances.ts index 79f47b40..791cad12 100644 --- a/subgraphs/arbitrum/src/treasury/TokenBalances.ts +++ b/subgraphs/arbitrum/src/treasury/TokenBalances.ts @@ -4,7 +4,7 @@ import { TokenRecord } from "../../../shared/generated/schema"; import { getERC20 } from "../../../shared/src/contracts/ERC20"; import { pushTokenRecordArray } from "../../../shared/src/utils/ArrayHelper"; import { getTokensInCategory } from "../../../shared/src/utils/TokenRecordHelper"; -import { ERC20_TOKENS_ARBITRUM } from "../contracts/Constants"; +import { ERC20_LUSD, ERC20_TOKENS_ARBITRUM, LUSD_START_BLOCK } from "../contracts/Constants"; import { getContractName, getERC20TokenRecordsFromWallets } from "../contracts/Contracts"; import { getStakedBalances as getJonesStakedBalances } from "../contracts/JonesStaking"; import { getStakedBalances as getTreasureStakedBalances } from "../contracts/TreasureMining"; @@ -40,6 +40,14 @@ function getTokenBalance( return records; } + // If the token is LUSD and the block number is less that the start block of the Chainlink feed, skip it + if (contractAddress.toLowerCase() == ERC20_LUSD.toLowerCase() + && + blockNumber.lt(BigInt.fromString(LUSD_START_BLOCK))) { + log.info("getTokenBalance: Skipping {} token record at block {}", [getContractName(ERC20_LUSD), blockNumber.toString()]); + return records; + } + const rate = getPrice(contractAddress, blockNumber); // Standard ERC20 From c970767d62c0c20dbd857bd4740cf35171159016 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Thu, 11 Jul 2024 21:48:35 +0400 Subject: [PATCH 13/20] Revert to event handler --- subgraphs/arbitrum/CHANGELOG.md | 3 ++- subgraphs/arbitrum/config.json | 2 +- subgraphs/arbitrum/subgraph.yaml | 12 ++++-------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/subgraphs/arbitrum/CHANGELOG.md b/subgraphs/arbitrum/CHANGELOG.md index 2863a4b9..56c0d359 100644 --- a/subgraphs/arbitrum/CHANGELOG.md +++ b/subgraphs/arbitrum/CHANGELOG.md @@ -1,8 +1,9 @@ # Arbitrum Subgraph Changelog -## 1.7.1 (2024-06-04) +## 1.7.5 (2024-07-XX) - Adds POL in Camelot +- Change the Chainlink price feed used as a trigger in order to increase indexing speed ## 1.6.4 (2023-09-13) diff --git a/subgraphs/arbitrum/config.json b/subgraphs/arbitrum/config.json index add42e8f..37e81762 100644 --- a/subgraphs/arbitrum/config.json +++ b/subgraphs/arbitrum/config.json @@ -2,5 +2,5 @@ "id": "QmYSsMwPJPzaLELSYLWqaQ21Rz5VjMNrVh7SsUW4dcqGXu", "org": "olympusdao", "name": "protocol-metrics-arbitrum", - "version": "1.7.1" + "version": "1.7.5" } \ No newline at end of file diff --git a/subgraphs/arbitrum/subgraph.yaml b/subgraphs/arbitrum/subgraph.yaml index 2bbe4d84..6641415f 100644 --- a/subgraphs/arbitrum/subgraph.yaml +++ b/subgraphs/arbitrum/subgraph.yaml @@ -15,7 +15,7 @@ dataSources: name: TokenRecords-arbitrum network: arbitrum-one source: - address: "0x79daa21a44d1415306ec17c361e0090bdd4cfcbe" # COMP-USD feed, once per hour(-ish) + address: "0x5D041081725468Aa43e72ff0445Fde2Ad1aDE775" # FRAX-USD feed, once every 16 hours abi: ChainlinkAggregator startBlock: 10950000 # 2022-05-01 mapping: @@ -50,11 +50,7 @@ dataSources: file: abis/TreasureMining.json - name: ChainlinkAggregator file: abis/ChainlinkAggregator.json - blockHandlers: - - handler: handleBlock - filter: - kind: polling - # Every 8 hours - # 4 blocks per second * 60 seconds * 60 minutes * 8 hours - every: 115200 + eventHandlers: + - event: NewRound(indexed uint256,indexed address,uint256) + handler: handleEvent file: ./src/treasury/Assets.ts From cfe407094ac78c87fb185c1722f3597c4f6add8b Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Thu, 11 Jul 2024 21:49:30 +0400 Subject: [PATCH 14/20] Deployment bump --- subgraphs/arbitrum/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgraphs/arbitrum/config.json b/subgraphs/arbitrum/config.json index 37e81762..ea456db3 100644 --- a/subgraphs/arbitrum/config.json +++ b/subgraphs/arbitrum/config.json @@ -1,5 +1,5 @@ { - "id": "QmYSsMwPJPzaLELSYLWqaQ21Rz5VjMNrVh7SsUW4dcqGXu", + "id": "QmP2HQCcbes4pUpNGpEm1QhYXL46pmf9bTYJhTi5Xe3o71", "org": "olympusdao", "name": "protocol-metrics-arbitrum", "version": "1.7.5" From d7a035ede98d12602b16e1afd1920767ea581beb Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Tue, 16 Jul 2024 21:46:26 +0400 Subject: [PATCH 15/20] Fix indexing of protocol addresses by reducing code paths --- subgraphs/arbitrum/CHANGELOG.md | 3 ++- subgraphs/arbitrum/config.json | 2 +- subgraphs/arbitrum/src/contracts/JonesStaking.ts | 7 ++++--- subgraphs/arbitrum/src/contracts/TreasureMining.ts | 8 ++++---- subgraphs/arbitrum/src/treasury/OwnedLiquidity.ts | 8 ++++---- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/subgraphs/arbitrum/CHANGELOG.md b/subgraphs/arbitrum/CHANGELOG.md index 56c0d359..8d1ceb01 100644 --- a/subgraphs/arbitrum/CHANGELOG.md +++ b/subgraphs/arbitrum/CHANGELOG.md @@ -1,9 +1,10 @@ # Arbitrum Subgraph Changelog -## 1.7.5 (2024-07-XX) +## 1.7.6 (2024-07-XX) - Adds POL in Camelot - Change the Chainlink price feed used as a trigger in order to increase indexing speed +- Reduce code paths for determining protocol addresses ## 1.6.4 (2023-09-13) diff --git a/subgraphs/arbitrum/config.json b/subgraphs/arbitrum/config.json index ea456db3..861805b1 100644 --- a/subgraphs/arbitrum/config.json +++ b/subgraphs/arbitrum/config.json @@ -2,5 +2,5 @@ "id": "QmP2HQCcbes4pUpNGpEm1QhYXL46pmf9bTYJhTi5Xe3o71", "org": "olympusdao", "name": "protocol-metrics-arbitrum", - "version": "1.7.5" + "version": "1.7.6" } \ No newline at end of file diff --git a/subgraphs/arbitrum/src/contracts/JonesStaking.ts b/subgraphs/arbitrum/src/contracts/JonesStaking.ts index 6a8b278b..2afbb06f 100644 --- a/subgraphs/arbitrum/src/contracts/JonesStaking.ts +++ b/subgraphs/arbitrum/src/contracts/JonesStaking.ts @@ -9,12 +9,12 @@ import { getIsTokenLiquid, getTokenRecordValue, } from "../../../shared/src/utils/TokenRecordHelper"; -import { WALLET_ADDRESSES } from "../../../shared/src/Wallets"; import { JONESStaking } from "../../generated/TokenRecords-arbitrum/JONESStaking"; import { getPrice } from "../price/PriceLookup"; import { BLOCKCHAIN, ERC20_TOKENS_ARBITRUM, + getProtocolAddresses, JONES_STAKING, JONES_STAKING_POOL_IDS, JONES_WRITE_OFF_BLOCK, @@ -83,8 +83,9 @@ export const getStakedBalances = ( const records: TokenRecord[] = []; let price: BigDecimal | null = null; - for (let i = 0; i < WALLET_ADDRESSES.length; i++) { - const walletAddress = WALLET_ADDRESSES[i]; + const allWallets = getProtocolAddresses(); + for (let i = 0; i < allWallets.length; i++) { + const walletAddress = allWallets[i]; for (let j = 0; j < JONES_STAKING_POOL_IDS.length; j++) { const balance = getStakedBalance( tokenAddress, diff --git a/subgraphs/arbitrum/src/contracts/TreasureMining.ts b/subgraphs/arbitrum/src/contracts/TreasureMining.ts index 86daf170..099f4af5 100644 --- a/subgraphs/arbitrum/src/contracts/TreasureMining.ts +++ b/subgraphs/arbitrum/src/contracts/TreasureMining.ts @@ -4,10 +4,9 @@ import { TokenRecord } from "../../../shared/generated/schema"; import { toDecimal } from "../../../shared/src/utils/Decimals"; import { addressesEqual } from "../../../shared/src/utils/StringHelper"; import { createTokenRecord } from "../../../shared/src/utils/TokenRecordHelper"; -import { WALLET_ADDRESSES } from "../../../shared/src/Wallets"; import { TreasureMining } from "../../generated/TokenRecords-arbitrum/TreasureMining"; import { getPrice } from "../price/PriceLookup"; -import { BLOCKCHAIN, ERC20_MAGIC, ERC20_TOKENS_ARBITRUM, TREASURE_ATLAS_MINE } from "./Constants"; +import { BLOCKCHAIN, ERC20_MAGIC, ERC20_TOKENS_ARBITRUM, getProtocolAddresses, TREASURE_ATLAS_MINE } from "./Constants"; import { getContractName } from "./Contracts"; /** @@ -89,8 +88,9 @@ export const getStakedBalances = ( const contract = getStakingContract(block); - for (let i = 0; i < WALLET_ADDRESSES.length; i++) { - const walletAddress = WALLET_ADDRESSES[i]; + const allWallets = getProtocolAddresses(); + for (let i = 0; i < allWallets.length; i++) { + const walletAddress = allWallets[i]; const depositIds = getUserDepositIds(walletAddress, contract, block); for (let j = 0; j < depositIds.length; j++) { diff --git a/subgraphs/arbitrum/src/treasury/OwnedLiquidity.ts b/subgraphs/arbitrum/src/treasury/OwnedLiquidity.ts index 5b65a238..17b3ea38 100644 --- a/subgraphs/arbitrum/src/treasury/OwnedLiquidity.ts +++ b/subgraphs/arbitrum/src/treasury/OwnedLiquidity.ts @@ -7,8 +7,7 @@ import { createTokenRecord, getIsTokenLiquid, } from "../../../shared/src/utils/TokenRecordHelper"; -import { WALLET_ADDRESSES } from "../../../shared/src/Wallets"; -import { BLOCKCHAIN, ERC20_TOKENS_ARBITRUM, OHM_TOKENS } from "../contracts/Constants"; +import { BLOCKCHAIN, ERC20_TOKENS_ARBITRUM, getProtocolAddresses, OHM_TOKENS } from "../contracts/Constants"; import { getContractName } from "../contracts/Contracts"; import { getPriceRecursive, PRICE_HANDLERS } from "../price/PriceLookup"; @@ -51,8 +50,9 @@ function getOwnedLiquidityBalance( return records; } - for (let i = 0; i < WALLET_ADDRESSES.length; i++) { - const currentWalletAddress = WALLET_ADDRESSES[i]; + const allWallets = getProtocolAddresses(); + for (let i = 0; i < allWallets.length; i++) { + const currentWalletAddress = allWallets[i]; // Get the balance const balance = liquidityHandler.getBalance(currentWalletAddress, block); From 5d4f0b55c70e5b9b05bb9de6b01fceab6a12b283 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Tue, 16 Jul 2024 21:59:17 +0400 Subject: [PATCH 16/20] Add missing price lookup --- subgraphs/arbitrum/src/price/PriceLookup.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/subgraphs/arbitrum/src/price/PriceLookup.ts b/subgraphs/arbitrum/src/price/PriceLookup.ts index a6617d65..9f5db14c 100644 --- a/subgraphs/arbitrum/src/price/PriceLookup.ts +++ b/subgraphs/arbitrum/src/price/PriceLookup.ts @@ -21,6 +21,7 @@ import { LP_BALANCER_POOL_OHM_USDC, LP_BALANCER_POOL_WETH_OHM, LP_BALANCER_POOL_WETH_VESTA, + LP_CAMELOT_OHM_WETH, LP_UNISWAP_V2_GOHM_WETH, LP_UNISWAP_V2_JONES_WETH, LP_UNISWAP_V2_LQTY_WETH, @@ -43,6 +44,7 @@ export const PRICE_HANDLERS: PriceHandler[] = [ new PriceHandlerUniswapV2([ERC20_MAGIC, ERC20_WETH], LP_UNISWAP_V2_MAGIC_WETH, getContractName), new PriceHandlerUniswapV3([ERC20_USDC, ERC20_WETH], LP_UNISWAP_V3_WETH_USDC, getContractName), new PriceHandlerUniswapV3([ERC20_ARB, ERC20_WETH], LP_UNISWAP_V3_ARB_WETH, getContractName), + new PriceHandlerUniswapV2([ERC20_OHM, ERC20_WETH], LP_CAMELOT_OHM_WETH, getContractName), ]; /** From 5ecca99b0349e98fae4eb47c0b98b8ddb2440ee4 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Tue, 16 Jul 2024 21:59:54 +0400 Subject: [PATCH 17/20] Version bump --- subgraphs/arbitrum/CHANGELOG.md | 2 +- subgraphs/arbitrum/config.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/subgraphs/arbitrum/CHANGELOG.md b/subgraphs/arbitrum/CHANGELOG.md index 8d1ceb01..e4d19904 100644 --- a/subgraphs/arbitrum/CHANGELOG.md +++ b/subgraphs/arbitrum/CHANGELOG.md @@ -1,6 +1,6 @@ # Arbitrum Subgraph Changelog -## 1.7.6 (2024-07-XX) +## 1.7.8 (2024-07-16) - Adds POL in Camelot - Change the Chainlink price feed used as a trigger in order to increase indexing speed diff --git a/subgraphs/arbitrum/config.json b/subgraphs/arbitrum/config.json index 861805b1..eedee703 100644 --- a/subgraphs/arbitrum/config.json +++ b/subgraphs/arbitrum/config.json @@ -1,6 +1,6 @@ { - "id": "QmP2HQCcbes4pUpNGpEm1QhYXL46pmf9bTYJhTi5Xe3o71", + "id": "QmVvmsk8GA9PhGf6W8iXLJEiVnmUzLXmdwCN4TzBBgxEyd", "org": "olympusdao", "name": "protocol-metrics-arbitrum", - "version": "1.7.6" + "version": "1.7.8" } \ No newline at end of file From 203c96c1a178dcac4a1cb248504001267c9fd926 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Tue, 16 Jul 2024 22:50:52 +0400 Subject: [PATCH 18/20] Implement missing function --- subgraphs/shared/tests/price/PriceHandlerCustom.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/subgraphs/shared/tests/price/PriceHandlerCustom.ts b/subgraphs/shared/tests/price/PriceHandlerCustom.ts index d3fd67a5..2cd00e87 100644 --- a/subgraphs/shared/tests/price/PriceHandlerCustom.ts +++ b/subgraphs/shared/tests/price/PriceHandlerCustom.ts @@ -12,6 +12,10 @@ export class PriceHandlerCustom implements PriceHandler { this.returnValue = returnValue; } + exists(): boolean { + return true; + } + getId(): string { return "PriceHandlerCustom"; } From 3017ed2893f2f2569274a428db71b180ada94862 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Wed, 17 Jul 2024 21:45:24 +0400 Subject: [PATCH 19/20] Modify Uniswap V2 price handler to return 0 instead of reverting --- subgraphs/arbitrum/config.json | 4 ++-- .../shared/src/price/PriceHandlerUniswapV2.ts | 6 +++--- .../tests/price/PriceHandlerUniswapV2.test.ts | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/subgraphs/arbitrum/config.json b/subgraphs/arbitrum/config.json index eedee703..34417e68 100644 --- a/subgraphs/arbitrum/config.json +++ b/subgraphs/arbitrum/config.json @@ -1,6 +1,6 @@ { - "id": "QmVvmsk8GA9PhGf6W8iXLJEiVnmUzLXmdwCN4TzBBgxEyd", + "id": "QmNQfMN2GjnGYx2mGo92gAc7z47fMbTMRR9M1gGEUjLZHX", "org": "olympusdao", "name": "protocol-metrics-arbitrum", - "version": "1.7.8" + "version": "1.7.9" } \ No newline at end of file diff --git a/subgraphs/shared/src/price/PriceHandlerUniswapV2.ts b/subgraphs/shared/src/price/PriceHandlerUniswapV2.ts index 85ee8868..54861e08 100644 --- a/subgraphs/shared/src/price/PriceHandlerUniswapV2.ts +++ b/subgraphs/shared/src/price/PriceHandlerUniswapV2.ts @@ -211,7 +211,7 @@ export class PriceHandlerUniswapV2 implements PriceHandler { private getTokenReserves(tokenAddress: string, tokenIndex: number, block: BigInt): BigDecimal { const pair = this.getContract(block); if (!pair) { - throw new Error(`Unable to bind with UniswapV2 contract ${this.poolAddress} at block ${block.toString()}`); + return BigDecimal.zero(); } const reserves = pair.getReserves(); @@ -233,7 +233,7 @@ export class PriceHandlerUniswapV2 implements PriceHandler { private getTotalSupply(block: BigInt): BigDecimal { const pair = this.getContract(block); if (!pair) { - throw new Error(`Unable to bind with UniswapV2 contract ${this.poolAddress} at block ${block.toString()}`); + return BigDecimal.zero(); } return toDecimal(pair.totalSupply(), pair.decimals()); @@ -242,7 +242,7 @@ export class PriceHandlerUniswapV2 implements PriceHandler { getUnderlyingTokenBalance(walletAddress: string, tokenAddress: string, block: BigInt): BigDecimal { const pair = this.getContract(block); if (!pair) { - throw new Error(`Unable to bind with UniswapV2 contract ${this.poolAddress} at block ${block.toString()}`); + return BigDecimal.zero(); } const tokenIndex = this.getTokenIndex(tokenAddress, block); diff --git a/subgraphs/shared/tests/price/PriceHandlerUniswapV2.test.ts b/subgraphs/shared/tests/price/PriceHandlerUniswapV2.test.ts index e210c6ff..0af84a0d 100644 --- a/subgraphs/shared/tests/price/PriceHandlerUniswapV2.test.ts +++ b/subgraphs/shared/tests/price/PriceHandlerUniswapV2.test.ts @@ -292,4 +292,19 @@ describe("getUnderlyingTokenBalance", () => { const balance = handler.getUnderlyingTokenBalance(CROSS_CHAIN_ARBITRUM, TOKEN0, BLOCK); assert.stringEquals(expectedBalance.toString(), balance.toString()); }); + + test("returns 0 if the contract reverts", () => { + const contractLookup: ContractNameLookup = (tokenAddress: string): string => { + if (addressesEqual(tokenAddress, TOKEN0)) { + return "DAI"; + } + + return "OHM V2"; + }; + + const handler = new PriceHandlerUniswapV2([TOKEN0, TOKEN1], PAIR_ADDRESS, contractLookup); + + const balance = handler.getUnderlyingTokenBalance(CROSS_CHAIN_ARBITRUM, TOKEN0, BLOCK); + assert.stringEquals("0", balance.toString()); + }); }); From c0426e97d90badbf9518c6bd87431927308e0034 Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Wed, 17 Jul 2024 21:46:25 +0400 Subject: [PATCH 20/20] Update changelog --- subgraphs/arbitrum/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subgraphs/arbitrum/CHANGELOG.md b/subgraphs/arbitrum/CHANGELOG.md index e4d19904..a3e93315 100644 --- a/subgraphs/arbitrum/CHANGELOG.md +++ b/subgraphs/arbitrum/CHANGELOG.md @@ -1,10 +1,11 @@ # Arbitrum Subgraph Changelog -## 1.7.8 (2024-07-16) +## 1.7.9 (2024-07-17) - Adds POL in Camelot - Change the Chainlink price feed used as a trigger in order to increase indexing speed - Reduce code paths for determining protocol addresses +- Modify Uniswap V2 PriceHandler to return 0 if the contract reverts ## 1.6.4 (2023-09-13)