From f771be983de6a6679ca02a9707438c20a6b55e8a Mon Sep 17 00:00:00 2001 From: Corantin Date: Sun, 26 Mar 2023 20:26:49 -0400 Subject: [PATCH 1/5] Push --- .../react-app/src/services/quest.service.ts | 2 +- .../quest-subgraph/abis/Quest.2.json | 274 ++++++++ .../subgraphs/quest-subgraph/abis/Quest.json | 158 +++++ .../generated/QuestFactory-Quest/Quest.ts | 411 +++++++++++ .../generated/QuestFactoryV2-Quest/Quest.ts | 645 ++++++++++++++++++ .../quest-subgraph/generated/schema.ts | 86 +++ .../src/mappings/quest-factory.2.ts | 47 +- .../src/mappings/quest-factory.ts | 39 +- .../quest-subgraph/src/schema.graphql | 9 + .../src/templates/questFactory.2.yaml | 25 + .../src/templates/questFactory.yaml | 19 + .../subgraphs/quest-subgraph/subgraph.yaml | 56 +- 12 files changed, 1752 insertions(+), 19 deletions(-) create mode 100644 packages/subgraphs/quest-subgraph/abis/Quest.2.json create mode 100644 packages/subgraphs/quest-subgraph/abis/Quest.json create mode 100644 packages/subgraphs/quest-subgraph/generated/QuestFactory-Quest/Quest.ts create mode 100644 packages/subgraphs/quest-subgraph/generated/QuestFactoryV2-Quest/Quest.ts diff --git a/packages/react-app/src/services/quest.service.ts b/packages/react-app/src/services/quest.service.ts index 7c9abdc5..34357bc2 100644 --- a/packages/react-app/src/services/quest.service.ts +++ b/packages/react-app/src/services/quest.service.ts @@ -112,7 +112,7 @@ async function mapQuest(questEntity: any, claimCountMap: Map) { quest.description = formatIpfsMarkdownLink(quest.detailsRefIpfs, 'See description'); } - if (quest?.maxPlayers !== undefined) { + if (quest?.features.playableQuest) { quest.players = await getQuestContract(quest).getPlayers(); } diff --git a/packages/subgraphs/quest-subgraph/abis/Quest.2.json b/packages/subgraphs/quest-subgraph/abis/Quest.2.json new file mode 100644 index 00000000..c238afe5 --- /dev/null +++ b/packages/subgraphs/quest-subgraph/abis/Quest.2.json @@ -0,0 +1,274 @@ +[ + { + "inputs": [ + { "internalType": "string", "name": "_questTitle", "type": "string" }, + { + "internalType": "bytes", + "name": "_questDetailsRef", + "type": "bytes" + }, + { + "internalType": "contract IERC20", + "name": "_rewardToken", + "type": "address" + }, + { "internalType": "uint256", "name": "_expireTime", "type": "uint256" }, + { + "internalType": "address", + "name": "_aragonGovernAddress", + "type": "address" + }, + { + "internalType": "address payable", + "name": "_fundsRecoveryAddress", + "type": "address" + }, + { + "components": [ + { + "internalType": "contract IERC20", + "name": "token", + "type": "address" + }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct Models.Deposit", + "name": "_createDeposit", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "contract IERC20", + "name": "token", + "type": "address" + }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct Models.Deposit", + "name": "_playDeposit", + "type": "tuple" + }, + { + "internalType": "address", + "name": "_questCreator", + "type": "address" + }, + { "internalType": "uint32", "name": "_maxPlayers", "type": "uint32" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "bytes", + "name": "evidence", + "type": "bytes" + }, + { + "indexed": false, + "internalType": "address", + "name": "player", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "QuestClaimed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "player", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + } + ], + "name": "QuestPlayed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "player", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + } + ], + "name": "QuestUnplayed", + "type": "event" + }, + { + "inputs": [], + "name": "aragonGovernAddress", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "executer", "type": "address" }], + "name": "canExecute", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes", "name": "_evidence", "type": "bytes" }, + { "internalType": "address", "name": "_player", "type": "address" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" }, + { "internalType": "bool", "name": "_claimAll", "type": "bool" } + ], + "name": "claim", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "name": "claims", + "outputs": [ + { "internalType": "bytes", "name": "evidence", "type": "bytes" }, + { "internalType": "address", "name": "player", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "createDeposit", + "outputs": [ + { + "internalType": "contract IERC20", + "name": "token", + "type": "address" + }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "expireTime", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "fundsRecoveryAddress", + "outputs": [{ "internalType": "address payable", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getPlayers", + "outputs": [{ "internalType": "address[]", "name": "", "type": "address[]" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "isCreateDepositReleased", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "maxPlayers", + "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "_player", "type": "address" }], + "name": "play", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "playDeposit", + "outputs": [ + { + "internalType": "contract IERC20", + "name": "token", + "type": "address" + }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "questCreator", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "questDetailsRef", + "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "questTitle", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "recoverFundsAndDeposit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "rewardToken", + "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "_player", "type": "address" }], + "name": "unplay", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] \ No newline at end of file diff --git a/packages/subgraphs/quest-subgraph/abis/Quest.json b/packages/subgraphs/quest-subgraph/abis/Quest.json new file mode 100644 index 00000000..1c18d9fb --- /dev/null +++ b/packages/subgraphs/quest-subgraph/abis/Quest.json @@ -0,0 +1,158 @@ +[ + { + "type": "constructor", + "stateMutability": "nonpayable", + "inputs": [ + { "type": "string", "name": "_questTitle", "internalType": "string" }, + { "type": "bytes", "name": "_questDetailsRef", "internalType": "bytes" }, + { + "type": "address", + "name": "_rewardToken", + "internalType": "contract IERC20" + }, + { "type": "uint256", "name": "_expireTime", "internalType": "uint256" }, + { + "type": "address", + "name": "_aragonGovernAddress", + "internalType": "address" + }, + { + "type": "address", + "name": "_fundsRecoveryAddress", + "internalType": "address payable" + }, + { + "type": "address", + "name": "_depositToken", + "internalType": "contract IERC20" + }, + { + "type": "uint256", + "name": "_depositAmount", + "internalType": "uint256" + }, + { "type": "address", "name": "_questCreator", "internalType": "address" } + ] + }, + { + "type": "event", + "name": "QuestClaimed", + "inputs": [ + { + "type": "bytes", + "name": "evidence", + "internalType": "bytes", + "indexed": false + }, + { + "type": "address", + "name": "player", + "internalType": "address", + "indexed": false + }, + { + "type": "uint256", + "name": "amount", + "internalType": "uint256", + "indexed": false + } + ], + "anonymous": false + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [{ "type": "address", "name": "", "internalType": "address" }], + "name": "aragonGovernAddress", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "claim", + "inputs": [ + { "type": "bytes", "name": "_evidence", "internalType": "bytes" }, + { "type": "address", "name": "_player", "internalType": "address" }, + { "type": "uint256", "name": "_amount", "internalType": "uint256" }, + { "type": "bool", "name": "_claimAll", "internalType": "bool" } + ] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { "type": "bytes", "name": "evidence", "internalType": "bytes" }, + { "type": "address", "name": "player", "internalType": "address" }, + { "type": "uint256", "name": "amount", "internalType": "uint256" } + ], + "name": "claims", + "inputs": [{ "type": "uint256", "name": "", "internalType": "uint256" }] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { "type": "address", "name": "token", "internalType": "contract IERC20" }, + { "type": "uint256", "name": "amount", "internalType": "uint256" } + ], + "name": "deposit", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [{ "type": "uint256", "name": "", "internalType": "uint256" }], + "name": "expireTime", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [{ "type": "address", "name": "", "internalType": "address payable" }], + "name": "fundsRecoveryAddress", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [{ "type": "bool", "name": "", "internalType": "bool" }], + "name": "isDepositReleased", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [{ "type": "address", "name": "", "internalType": "address" }], + "name": "questCreator", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [{ "type": "bytes", "name": "", "internalType": "bytes" }], + "name": "questDetailsRef", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [{ "type": "string", "name": "", "internalType": "string" }], + "name": "questTitle", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "recoverFundsAndDeposit", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [{ "type": "address", "name": "", "internalType": "contract IERC20" }], + "name": "rewardToken", + "inputs": [] + } +] \ No newline at end of file diff --git a/packages/subgraphs/quest-subgraph/generated/QuestFactory-Quest/Quest.ts b/packages/subgraphs/quest-subgraph/generated/QuestFactory-Quest/Quest.ts new file mode 100644 index 00000000..4aeaf6af --- /dev/null +++ b/packages/subgraphs/quest-subgraph/generated/QuestFactory-Quest/Quest.ts @@ -0,0 +1,411 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + ethereum, + JSONValue, + TypedMap, + Entity, + Bytes, + Address, + BigInt +} from "@graphprotocol/graph-ts"; + +export class QuestClaimed extends ethereum.Event { + get params(): QuestClaimed__Params { + return new QuestClaimed__Params(this); + } +} + +export class QuestClaimed__Params { + _event: QuestClaimed; + + constructor(event: QuestClaimed) { + this._event = event; + } + + get evidence(): Bytes { + return this._event.parameters[0].value.toBytes(); + } + + get player(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get amount(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class Quest__claimsResult { + value0: Bytes; + value1: Address; + value2: BigInt; + + constructor(value0: Bytes, value1: Address, value2: BigInt) { + this.value0 = value0; + this.value1 = value1; + this.value2 = value2; + } + + toMap(): TypedMap { + let map = new TypedMap(); + map.set("value0", ethereum.Value.fromBytes(this.value0)); + map.set("value1", ethereum.Value.fromAddress(this.value1)); + map.set("value2", ethereum.Value.fromUnsignedBigInt(this.value2)); + return map; + } +} + +export class Quest__depositResult { + value0: Address; + value1: BigInt; + + constructor(value0: Address, value1: BigInt) { + this.value0 = value0; + this.value1 = value1; + } + + toMap(): TypedMap { + let map = new TypedMap(); + map.set("value0", ethereum.Value.fromAddress(this.value0)); + map.set("value1", ethereum.Value.fromUnsignedBigInt(this.value1)); + return map; + } +} + +export class Quest extends ethereum.SmartContract { + static bind(address: Address): Quest { + return new Quest("Quest", address); + } + + aragonGovernAddress(): Address { + let result = super.call( + "aragonGovernAddress", + "aragonGovernAddress():(address)", + [] + ); + + return result[0].toAddress(); + } + + try_aragonGovernAddress(): ethereum.CallResult
{ + let result = super.tryCall( + "aragonGovernAddress", + "aragonGovernAddress():(address)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + claims(param0: BigInt): Quest__claimsResult { + let result = super.call( + "claims", + "claims(uint256):(bytes,address,uint256)", + [ethereum.Value.fromUnsignedBigInt(param0)] + ); + + return new Quest__claimsResult( + result[0].toBytes(), + result[1].toAddress(), + result[2].toBigInt() + ); + } + + try_claims(param0: BigInt): ethereum.CallResult { + let result = super.tryCall( + "claims", + "claims(uint256):(bytes,address,uint256)", + [ethereum.Value.fromUnsignedBigInt(param0)] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue( + new Quest__claimsResult( + value[0].toBytes(), + value[1].toAddress(), + value[2].toBigInt() + ) + ); + } + + deposit(): Quest__depositResult { + let result = super.call("deposit", "deposit():(address,uint256)", []); + + return new Quest__depositResult( + result[0].toAddress(), + result[1].toBigInt() + ); + } + + try_deposit(): ethereum.CallResult { + let result = super.tryCall("deposit", "deposit():(address,uint256)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue( + new Quest__depositResult(value[0].toAddress(), value[1].toBigInt()) + ); + } + + expireTime(): BigInt { + let result = super.call("expireTime", "expireTime():(uint256)", []); + + return result[0].toBigInt(); + } + + try_expireTime(): ethereum.CallResult { + let result = super.tryCall("expireTime", "expireTime():(uint256)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + fundsRecoveryAddress(): Address { + let result = super.call( + "fundsRecoveryAddress", + "fundsRecoveryAddress():(address)", + [] + ); + + return result[0].toAddress(); + } + + try_fundsRecoveryAddress(): ethereum.CallResult
{ + let result = super.tryCall( + "fundsRecoveryAddress", + "fundsRecoveryAddress():(address)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + isDepositReleased(): boolean { + let result = super.call( + "isDepositReleased", + "isDepositReleased():(bool)", + [] + ); + + return result[0].toBoolean(); + } + + try_isDepositReleased(): ethereum.CallResult { + let result = super.tryCall( + "isDepositReleased", + "isDepositReleased():(bool)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + questCreator(): Address { + let result = super.call("questCreator", "questCreator():(address)", []); + + return result[0].toAddress(); + } + + try_questCreator(): ethereum.CallResult
{ + let result = super.tryCall("questCreator", "questCreator():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + questDetailsRef(): Bytes { + let result = super.call("questDetailsRef", "questDetailsRef():(bytes)", []); + + return result[0].toBytes(); + } + + try_questDetailsRef(): ethereum.CallResult { + let result = super.tryCall( + "questDetailsRef", + "questDetailsRef():(bytes)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBytes()); + } + + questTitle(): string { + let result = super.call("questTitle", "questTitle():(string)", []); + + return result[0].toString(); + } + + try_questTitle(): ethereum.CallResult { + let result = super.tryCall("questTitle", "questTitle():(string)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toString()); + } + + rewardToken(): Address { + let result = super.call("rewardToken", "rewardToken():(address)", []); + + return result[0].toAddress(); + } + + try_rewardToken(): ethereum.CallResult
{ + let result = super.tryCall("rewardToken", "rewardToken():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let 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; + } + + get _questTitle(): string { + return this._call.inputValues[0].value.toString(); + } + + get _questDetailsRef(): Bytes { + return this._call.inputValues[1].value.toBytes(); + } + + get _rewardToken(): Address { + return this._call.inputValues[2].value.toAddress(); + } + + get _expireTime(): BigInt { + return this._call.inputValues[3].value.toBigInt(); + } + + get _aragonGovernAddress(): Address { + return this._call.inputValues[4].value.toAddress(); + } + + get _fundsRecoveryAddress(): Address { + return this._call.inputValues[5].value.toAddress(); + } + + get _depositToken(): Address { + return this._call.inputValues[6].value.toAddress(); + } + + get _depositAmount(): BigInt { + return this._call.inputValues[7].value.toBigInt(); + } + + get _questCreator(): Address { + return this._call.inputValues[8].value.toAddress(); + } +} + +export class ConstructorCall__Outputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } +} + +export class ClaimCall extends ethereum.Call { + get inputs(): ClaimCall__Inputs { + return new ClaimCall__Inputs(this); + } + + get outputs(): ClaimCall__Outputs { + return new ClaimCall__Outputs(this); + } +} + +export class ClaimCall__Inputs { + _call: ClaimCall; + + constructor(call: ClaimCall) { + this._call = call; + } + + get _evidence(): Bytes { + return this._call.inputValues[0].value.toBytes(); + } + + get _player(): Address { + return this._call.inputValues[1].value.toAddress(); + } + + get _amount(): BigInt { + return this._call.inputValues[2].value.toBigInt(); + } + + get _claimAll(): boolean { + return this._call.inputValues[3].value.toBoolean(); + } +} + +export class ClaimCall__Outputs { + _call: ClaimCall; + + constructor(call: ClaimCall) { + this._call = call; + } +} + +export class RecoverFundsAndDepositCall extends ethereum.Call { + get inputs(): RecoverFundsAndDepositCall__Inputs { + return new RecoverFundsAndDepositCall__Inputs(this); + } + + get outputs(): RecoverFundsAndDepositCall__Outputs { + return new RecoverFundsAndDepositCall__Outputs(this); + } +} + +export class RecoverFundsAndDepositCall__Inputs { + _call: RecoverFundsAndDepositCall; + + constructor(call: RecoverFundsAndDepositCall) { + this._call = call; + } +} + +export class RecoverFundsAndDepositCall__Outputs { + _call: RecoverFundsAndDepositCall; + + constructor(call: RecoverFundsAndDepositCall) { + this._call = call; + } +} diff --git a/packages/subgraphs/quest-subgraph/generated/QuestFactoryV2-Quest/Quest.ts b/packages/subgraphs/quest-subgraph/generated/QuestFactoryV2-Quest/Quest.ts new file mode 100644 index 00000000..c9a1336b --- /dev/null +++ b/packages/subgraphs/quest-subgraph/generated/QuestFactoryV2-Quest/Quest.ts @@ -0,0 +1,645 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + ethereum, + JSONValue, + TypedMap, + Entity, + Bytes, + Address, + BigInt +} from "@graphprotocol/graph-ts"; + +export class QuestClaimed extends ethereum.Event { + get params(): QuestClaimed__Params { + return new QuestClaimed__Params(this); + } +} + +export class QuestClaimed__Params { + _event: QuestClaimed; + + constructor(event: QuestClaimed) { + this._event = event; + } + + get evidence(): Bytes { + return this._event.parameters[0].value.toBytes(); + } + + get player(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get amount(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class QuestPlayed extends ethereum.Event { + get params(): QuestPlayed__Params { + return new QuestPlayed__Params(this); + } +} + +export class QuestPlayed__Params { + _event: QuestPlayed; + + constructor(event: QuestPlayed) { + this._event = event; + } + + get player(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get timestamp(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } +} + +export class QuestUnplayed extends ethereum.Event { + get params(): QuestUnplayed__Params { + return new QuestUnplayed__Params(this); + } +} + +export class QuestUnplayed__Params { + _event: QuestUnplayed; + + constructor(event: QuestUnplayed) { + this._event = event; + } + + get player(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get timestamp(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } +} + +export class Quest__claimsResult { + value0: Bytes; + value1: Address; + value2: BigInt; + + constructor(value0: Bytes, value1: Address, value2: BigInt) { + this.value0 = value0; + this.value1 = value1; + this.value2 = value2; + } + + toMap(): TypedMap { + let map = new TypedMap(); + map.set("value0", ethereum.Value.fromBytes(this.value0)); + map.set("value1", ethereum.Value.fromAddress(this.value1)); + map.set("value2", ethereum.Value.fromUnsignedBigInt(this.value2)); + return map; + } +} + +export class Quest__createDepositResult { + value0: Address; + value1: BigInt; + + constructor(value0: Address, value1: BigInt) { + this.value0 = value0; + this.value1 = value1; + } + + toMap(): TypedMap { + let map = new TypedMap(); + map.set("value0", ethereum.Value.fromAddress(this.value0)); + map.set("value1", ethereum.Value.fromUnsignedBigInt(this.value1)); + return map; + } +} + +export class Quest__playDepositResult { + value0: Address; + value1: BigInt; + + constructor(value0: Address, value1: BigInt) { + this.value0 = value0; + this.value1 = value1; + } + + toMap(): TypedMap { + let map = new TypedMap(); + map.set("value0", ethereum.Value.fromAddress(this.value0)); + map.set("value1", ethereum.Value.fromUnsignedBigInt(this.value1)); + return map; + } +} + +export class Quest extends ethereum.SmartContract { + static bind(address: Address): Quest { + return new Quest("Quest", address); + } + + aragonGovernAddress(): Address { + let result = super.call( + "aragonGovernAddress", + "aragonGovernAddress():(address)", + [] + ); + + return result[0].toAddress(); + } + + try_aragonGovernAddress(): ethereum.CallResult
{ + let result = super.tryCall( + "aragonGovernAddress", + "aragonGovernAddress():(address)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + canExecute(executer: Address): boolean { + let result = super.call("canExecute", "canExecute(address):(bool)", [ + ethereum.Value.fromAddress(executer) + ]); + + return result[0].toBoolean(); + } + + try_canExecute(executer: Address): ethereum.CallResult { + let result = super.tryCall("canExecute", "canExecute(address):(bool)", [ + ethereum.Value.fromAddress(executer) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + claims(param0: BigInt): Quest__claimsResult { + let result = super.call( + "claims", + "claims(uint256):(bytes,address,uint256)", + [ethereum.Value.fromUnsignedBigInt(param0)] + ); + + return new Quest__claimsResult( + result[0].toBytes(), + result[1].toAddress(), + result[2].toBigInt() + ); + } + + try_claims(param0: BigInt): ethereum.CallResult { + let result = super.tryCall( + "claims", + "claims(uint256):(bytes,address,uint256)", + [ethereum.Value.fromUnsignedBigInt(param0)] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue( + new Quest__claimsResult( + value[0].toBytes(), + value[1].toAddress(), + value[2].toBigInt() + ) + ); + } + + createDeposit(): Quest__createDepositResult { + let result = super.call( + "createDeposit", + "createDeposit():(address,uint256)", + [] + ); + + return new Quest__createDepositResult( + result[0].toAddress(), + result[1].toBigInt() + ); + } + + try_createDeposit(): ethereum.CallResult { + let result = super.tryCall( + "createDeposit", + "createDeposit():(address,uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue( + new Quest__createDepositResult(value[0].toAddress(), value[1].toBigInt()) + ); + } + + expireTime(): BigInt { + let result = super.call("expireTime", "expireTime():(uint256)", []); + + return result[0].toBigInt(); + } + + try_expireTime(): ethereum.CallResult { + let result = super.tryCall("expireTime", "expireTime():(uint256)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + fundsRecoveryAddress(): Address { + let result = super.call( + "fundsRecoveryAddress", + "fundsRecoveryAddress():(address)", + [] + ); + + return result[0].toAddress(); + } + + try_fundsRecoveryAddress(): ethereum.CallResult
{ + let result = super.tryCall( + "fundsRecoveryAddress", + "fundsRecoveryAddress():(address)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + getPlayers(): Array
{ + let result = super.call("getPlayers", "getPlayers():(address[])", []); + + return result[0].toAddressArray(); + } + + try_getPlayers(): ethereum.CallResult> { + let result = super.tryCall("getPlayers", "getPlayers():(address[])", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddressArray()); + } + + isCreateDepositReleased(): boolean { + let result = super.call( + "isCreateDepositReleased", + "isCreateDepositReleased():(bool)", + [] + ); + + return result[0].toBoolean(); + } + + try_isCreateDepositReleased(): ethereum.CallResult { + let result = super.tryCall( + "isCreateDepositReleased", + "isCreateDepositReleased():(bool)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + maxPlayers(): BigInt { + let result = super.call("maxPlayers", "maxPlayers():(uint32)", []); + + return result[0].toBigInt(); + } + + try_maxPlayers(): ethereum.CallResult { + let result = super.tryCall("maxPlayers", "maxPlayers():(uint32)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + playDeposit(): Quest__playDepositResult { + let result = super.call( + "playDeposit", + "playDeposit():(address,uint256)", + [] + ); + + return new Quest__playDepositResult( + result[0].toAddress(), + result[1].toBigInt() + ); + } + + try_playDeposit(): ethereum.CallResult { + let result = super.tryCall( + "playDeposit", + "playDeposit():(address,uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue( + new Quest__playDepositResult(value[0].toAddress(), value[1].toBigInt()) + ); + } + + questCreator(): Address { + let result = super.call("questCreator", "questCreator():(address)", []); + + return result[0].toAddress(); + } + + try_questCreator(): ethereum.CallResult
{ + let result = super.tryCall("questCreator", "questCreator():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + questDetailsRef(): Bytes { + let result = super.call("questDetailsRef", "questDetailsRef():(bytes)", []); + + return result[0].toBytes(); + } + + try_questDetailsRef(): ethereum.CallResult { + let result = super.tryCall( + "questDetailsRef", + "questDetailsRef():(bytes)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBytes()); + } + + questTitle(): string { + let result = super.call("questTitle", "questTitle():(string)", []); + + return result[0].toString(); + } + + try_questTitle(): ethereum.CallResult { + let result = super.tryCall("questTitle", "questTitle():(string)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toString()); + } + + rewardToken(): Address { + let result = super.call("rewardToken", "rewardToken():(address)", []); + + return result[0].toAddress(); + } + + try_rewardToken(): ethereum.CallResult
{ + let result = super.tryCall("rewardToken", "rewardToken():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let 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; + } + + get _questTitle(): string { + return this._call.inputValues[0].value.toString(); + } + + get _questDetailsRef(): Bytes { + return this._call.inputValues[1].value.toBytes(); + } + + get _rewardToken(): Address { + return this._call.inputValues[2].value.toAddress(); + } + + get _expireTime(): BigInt { + return this._call.inputValues[3].value.toBigInt(); + } + + get _aragonGovernAddress(): Address { + return this._call.inputValues[4].value.toAddress(); + } + + get _fundsRecoveryAddress(): Address { + return this._call.inputValues[5].value.toAddress(); + } + + get _createDeposit(): ConstructorCall_createDepositStruct { + return changetype( + this._call.inputValues[6].value.toTuple() + ); + } + + get _playDeposit(): ConstructorCall_playDepositStruct { + return changetype( + this._call.inputValues[7].value.toTuple() + ); + } + + get _questCreator(): Address { + return this._call.inputValues[8].value.toAddress(); + } + + get _maxPlayers(): BigInt { + return this._call.inputValues[9].value.toBigInt(); + } +} + +export class ConstructorCall__Outputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } +} + +export class ConstructorCall_createDepositStruct extends ethereum.Tuple { + get token(): Address { + return this[0].toAddress(); + } + + get amount(): BigInt { + return this[1].toBigInt(); + } +} + +export class ConstructorCall_playDepositStruct extends ethereum.Tuple { + get token(): Address { + return this[0].toAddress(); + } + + get amount(): BigInt { + return this[1].toBigInt(); + } +} + +export class ClaimCall extends ethereum.Call { + get inputs(): ClaimCall__Inputs { + return new ClaimCall__Inputs(this); + } + + get outputs(): ClaimCall__Outputs { + return new ClaimCall__Outputs(this); + } +} + +export class ClaimCall__Inputs { + _call: ClaimCall; + + constructor(call: ClaimCall) { + this._call = call; + } + + get _evidence(): Bytes { + return this._call.inputValues[0].value.toBytes(); + } + + get _player(): Address { + return this._call.inputValues[1].value.toAddress(); + } + + get _amount(): BigInt { + return this._call.inputValues[2].value.toBigInt(); + } + + get _claimAll(): boolean { + return this._call.inputValues[3].value.toBoolean(); + } +} + +export class ClaimCall__Outputs { + _call: ClaimCall; + + constructor(call: ClaimCall) { + this._call = call; + } +} + +export class PlayCall extends ethereum.Call { + get inputs(): PlayCall__Inputs { + return new PlayCall__Inputs(this); + } + + get outputs(): PlayCall__Outputs { + return new PlayCall__Outputs(this); + } +} + +export class PlayCall__Inputs { + _call: PlayCall; + + constructor(call: PlayCall) { + this._call = call; + } + + get _player(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class PlayCall__Outputs { + _call: PlayCall; + + constructor(call: PlayCall) { + this._call = call; + } +} + +export class RecoverFundsAndDepositCall extends ethereum.Call { + get inputs(): RecoverFundsAndDepositCall__Inputs { + return new RecoverFundsAndDepositCall__Inputs(this); + } + + get outputs(): RecoverFundsAndDepositCall__Outputs { + return new RecoverFundsAndDepositCall__Outputs(this); + } +} + +export class RecoverFundsAndDepositCall__Inputs { + _call: RecoverFundsAndDepositCall; + + constructor(call: RecoverFundsAndDepositCall) { + this._call = call; + } +} + +export class RecoverFundsAndDepositCall__Outputs { + _call: RecoverFundsAndDepositCall; + + constructor(call: RecoverFundsAndDepositCall) { + this._call = call; + } +} + +export class UnplayCall extends ethereum.Call { + get inputs(): UnplayCall__Inputs { + return new UnplayCall__Inputs(this); + } + + get outputs(): UnplayCall__Outputs { + return new UnplayCall__Outputs(this); + } +} + +export class UnplayCall__Inputs { + _call: UnplayCall; + + constructor(call: UnplayCall) { + this._call = call; + } + + get _player(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class UnplayCall__Outputs { + _call: UnplayCall; + + constructor(call: UnplayCall) { + this._call = call; + } +} diff --git a/packages/subgraphs/quest-subgraph/generated/schema.ts b/packages/subgraphs/quest-subgraph/generated/schema.ts index f3a9d3cc..f7251236 100644 --- a/packages/subgraphs/quest-subgraph/generated/schema.ts +++ b/packages/subgraphs/quest-subgraph/generated/schema.ts @@ -29,6 +29,7 @@ export class QuestEntity extends Entity { this.set("questCreateDepositAmount", Value.fromBigInt(BigInt.zero())); this.set("questPlayDepositToken", Value.fromBytes(Bytes.empty())); this.set("questPlayDepositAmount", Value.fromBigInt(BigInt.zero())); + this.set("questPlayers", Value.fromStringArray(new Array(0))); } save(): void { @@ -224,6 +225,15 @@ export class QuestEntity extends Entity { set questPlayDepositAmount(value: BigInt) { this.set("questPlayDepositAmount", Value.fromBigInt(value)); } + + get questPlayers(): Array { + let value = this.get("questPlayers"); + return value!.toStringArray(); + } + + set questPlayers(value: Array) { + this.set("questPlayers", Value.fromStringArray(value)); + } } export class CreateDepositEntity extends Entity { @@ -357,3 +367,79 @@ export class PlayDepositEntity extends Entity { this.set("depositAmount", Value.fromBigInt(value)); } } + +export class QuestClaimEntity extends Entity { + constructor(id: string) { + super(); + this.set("id", Value.fromString(id)); + + this.set("questAddress", Value.fromString("")); + this.set("amount", Value.fromBigInt(BigInt.zero())); + this.set("evidenceIpfsHash", Value.fromBytes(Bytes.empty())); + this.set("player", Value.fromString("")); + } + + save(): void { + let id = this.get("id"); + assert(id != null, "Cannot save QuestClaimEntity entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.STRING, + "Cannot save QuestClaimEntity entity with non-string ID. " + + 'Considering using .toHex() to convert the "id" to a string.' + ); + store.set("QuestClaimEntity", id.toString(), this); + } + } + + static load(id: string): QuestClaimEntity | null { + return changetype( + store.get("QuestClaimEntity", id) + ); + } + + get id(): string { + let value = this.get("id"); + return value!.toString(); + } + + set id(value: string) { + this.set("id", Value.fromString(value)); + } + + get questAddress(): string { + let value = this.get("questAddress"); + return value!.toString(); + } + + set questAddress(value: string) { + this.set("questAddress", Value.fromString(value)); + } + + get amount(): BigInt { + let value = this.get("amount"); + return value!.toBigInt(); + } + + set amount(value: BigInt) { + this.set("amount", Value.fromBigInt(value)); + } + + get evidenceIpfsHash(): Bytes { + let value = this.get("evidenceIpfsHash"); + return value!.toBytes(); + } + + set evidenceIpfsHash(value: Bytes) { + this.set("evidenceIpfsHash", Value.fromBytes(value)); + } + + get player(): string { + let value = this.get("player"); + return value!.toString(); + } + + set player(value: string) { + this.set("player", Value.fromString(value)); + } +} diff --git a/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.2.ts b/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.2.ts index e85822d1..9b2c3037 100644 --- a/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.2.ts +++ b/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.2.ts @@ -3,12 +3,19 @@ import { PlayDepositChanged, CreateDepositChanged, } from "../../generated/QuestFactoryV2/QuestFactory"; + +import { + QuestPlayed, + QuestClaimed, + QuestUnplayed, +} from "../../generated/QuestFactoryV2-Quest/Quest"; import { CreateDepositEntity, PlayDepositEntity, + QuestClaimEntity, QuestEntity, } from "../../generated/schema"; -import { Bytes, ipfs } from "@graphprotocol/graph-ts"; +import { Bytes, ethereum, ipfs } from "@graphprotocol/graph-ts"; import { json } from "@graphprotocol/graph-ts"; export function handleCreateDepositChanged(event: CreateDepositChanged): void { @@ -51,6 +58,7 @@ export function handleQuestCreated(event: QuestCreated): void { questEntity.questPlayDepositAmount = event.params.playDepositAmount; questEntity.questCreator = event.params.creator; questEntity.questMaxPlayers = event.params.maxPlayers; + questEntity.questPlayers = []; if (!event.params.questDetailsRef) { questEntity.questDescription = ""; @@ -89,3 +97,40 @@ export function handleQuestCreated(event: QuestCreated): void { questEntity.save(); } + +export function handleQuestPlayed(event: QuestPlayed): void { + const hexAddress = event.params._event.address.toHex(); + let questEntity = QuestEntity.load(hexAddress); + + if (!questEntity) { + throw new Error("Quest entity not found with " + hexAddress); + } + + questEntity.questPlayers.push(event.params.player.toHexString()); + questEntity.save(); +} + +export function handleQuestUnplayed(event: QuestUnplayed): void { + const hexAddress = event.params._event.address.toHex(); + let questEntity = QuestEntity.load(hexAddress); + + if (!questEntity) { + throw new Error("Quest entity not found with " + hexAddress); + } + const indexToBeRemoved = questEntity.questPlayers.indexOf( + event.params.player.toHexString() + ); + questEntity.questPlayers.splice(indexToBeRemoved, 1); + questEntity.save(); +} + +export function handleQuestClaimed(event: QuestClaimed): void { + const questClaimEntity = new QuestClaimEntity( + event.params._event.transaction.hash.toHex() + ); + questClaimEntity.questAddress = event.params._event.address.toHexString(); + questClaimEntity.amount = event.params.amount; + questClaimEntity.evidenceIpfsHash = event.params.evidence; + questClaimEntity.player = event.params.player.toHexString(); + questClaimEntity.save(); +} diff --git a/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.ts b/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.ts index dac2d0dd..e8ff5678 100644 --- a/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.ts +++ b/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.ts @@ -1,10 +1,15 @@ import { QuestCreated, DepositChanged, -} from '../../generated/QuestFactory/QuestFactory'; -import { CreateDepositEntity, QuestEntity } from '../../generated/schema'; -import { Bytes, ipfs } from '@graphprotocol/graph-ts'; -import { json } from '@graphprotocol/graph-ts'; +} from "../../generated/QuestFactory/QuestFactory"; +import { + CreateDepositEntity, + QuestClaimEntity, + QuestEntity, +} from "../../generated/schema"; +import { Bytes, ipfs } from "@graphprotocol/graph-ts"; +import { json } from "@graphprotocol/graph-ts"; +import { QuestClaimed } from "../../generated/QuestFactory-Quest/Quest"; export function handleDepositChanged(event: DepositChanged): void { let depositEntity = new CreateDepositEntity( `Create_${event.params.timestamp.toString()}_${event.params.token.toHex()}_${event.params.amount.toHex()}` @@ -31,9 +36,10 @@ export function handleQuestCreated(event: QuestCreated): void { questEntity.questCreateDepositAmount = event.params.depositAmount; questEntity.questCreator = event.params.creator; questEntity.questMaxPlayers = null; + questEntity.questPlayers = []; if (!event.params.questDetailsRef) { - questEntity.questDescription = ''; + questEntity.questDescription = ""; } else { // Fetching quest description with IPFS let questDataBytes: Bytes | null = null; @@ -47,25 +53,36 @@ export function handleQuestCreated(event: QuestCreated): void { let jsonResult = json.try_fromBytes(questDataBytes); if (jsonResult.isOk) { let jsonObject = jsonResult.value.toObject(); - let communicationLink = jsonObject.get('communicationLink'); - let questDescription = jsonObject.get('description'); + let communicationLink = jsonObject.get("communicationLink"); + let questDescription = jsonObject.get("description"); questEntity.questCommunicationLink = communicationLink ? communicationLink.toString() - : ''; + : ""; questEntity.questDescription = questDescription ? questDescription.toString() - : ''; + : ""; } else { let description = questDataBytes.toString(); questEntity.questDescription = description ? description.toString() - : ''; + : ""; } } else { // Continue with empty description - questEntity.questDescription = ''; + questEntity.questDescription = ""; } } questEntity.save(); } + +export function handleQuestClaimed(event: QuestClaimed): void { + const questClaimEntity = new QuestClaimEntity( + event.params._event.transaction.hash.toHex() + ); + questClaimEntity.questAddress = event.params._event.address.toHexString(); + questClaimEntity.amount = event.params.amount; + questClaimEntity.evidenceIpfsHash = event.params.evidence; + questClaimEntity.player = event.params.player.toHexString(); + questClaimEntity.save(); +} diff --git a/packages/subgraphs/quest-subgraph/src/schema.graphql b/packages/subgraphs/quest-subgraph/src/schema.graphql index f1ea1dd6..961ba119 100644 --- a/packages/subgraphs/quest-subgraph/src/schema.graphql +++ b/packages/subgraphs/quest-subgraph/src/schema.graphql @@ -33,6 +33,7 @@ type QuestEntity @entity(immutable: true) { questCreateDepositAmount: BigInt! questPlayDepositToken: Bytes! questPlayDepositAmount: BigInt! + questPlayers: [String!]! } type CreateDepositEntity @entity(immutable: true) { @@ -48,3 +49,11 @@ type PlayDepositEntity @entity(immutable: true) { depositToken: Bytes! depositAmount: BigInt! } + +type QuestClaimEntity @entity(immutable: true) { + id: ID! + questAddress: String! + amount: BigInt! + evidenceIpfsHash: Bytes! + player: String! +} diff --git a/packages/subgraphs/quest-subgraph/src/templates/questFactory.2.yaml b/packages/subgraphs/quest-subgraph/src/templates/questFactory.2.yaml index 9f4fa183..e9cdc4b1 100644 --- a/packages/subgraphs/quest-subgraph/src/templates/questFactory.2.yaml +++ b/packages/subgraphs/quest-subgraph/src/templates/questFactory.2.yaml @@ -21,4 +21,29 @@ handler: handleCreateDepositChanged - event: PlayDepositChanged(uint256,address,uint256) handler: handlePlayDepositChanged + file: ./src/mappings/quest-factory.2.ts + - kind: ethereum/contract + name: {{name}}-Quest + network: {{network}} + source: + abi: Quest + startBlock: {{startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - QuestClaimedV2 + - QuestPlayed + - QuestUnplayed + abis: + - name: Quest + file: ./abis/Quest.2.json + eventHandlers: + - event: QuestClaimed(bytes,address,uint256) + handler: handleQuestClaimed + - event: QuestPlayed(address,uint256) + handler: handleQuestPlayed + - event: QuestUnplayed(address,uint256) + handler: handleQuestUnplayed file: ./src/mappings/quest-factory.2.ts \ No newline at end of file diff --git a/packages/subgraphs/quest-subgraph/src/templates/questFactory.yaml b/packages/subgraphs/quest-subgraph/src/templates/questFactory.yaml index bce3275b..9f69f7b3 100644 --- a/packages/subgraphs/quest-subgraph/src/templates/questFactory.yaml +++ b/packages/subgraphs/quest-subgraph/src/templates/questFactory.yaml @@ -19,4 +19,23 @@ handler: handleQuestCreated - event: DepositChanged(uint256,address,uint256) handler: handleDepositChanged + file: ./src/mappings/quest-factory.ts + - kind: ethereum/contract + name: {{name}}-Quest + network: {{network}} + source: + abi: Quest + startBlock: {{startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - QuestClaimed + abis: + - name: Quest + file: ./abis/Quest.json + eventHandlers: + - event: QuestClaimed(bytes,address,uint256) + handler: handleQuestClaimed file: ./src/mappings/quest-factory.ts \ No newline at end of file diff --git a/packages/subgraphs/quest-subgraph/subgraph.yaml b/packages/subgraphs/quest-subgraph/subgraph.yaml index de299aa7..2c3a4ef9 100644 --- a/packages/subgraphs/quest-subgraph/subgraph.yaml +++ b/packages/subgraphs/quest-subgraph/subgraph.yaml @@ -8,11 +8,11 @@ schema: dataSources: - kind: ethereum/contract name: QuestFactory - network: xdai + network: goerli source: - address: "0x5Be5286FEFE6a44f394b551B6AC9255D42e974fe" + address: "0x4DfE6C03132BD14D95b87803e232AcA352a715b4" abi: QuestFactory - startBlock: 22777803 + startBlock: 7543619 mapping: kind: ethereum/events apiVersion: 0.0.6 @@ -28,13 +28,32 @@ dataSources: - event: DepositChanged(uint256,address,uint256) handler: handleDepositChanged file: ./src/mappings/quest-factory.ts + - kind: ethereum/contract + name: QuestFactory-Quest + network: goerli + source: + abi: Quest + startBlock: 7543619 + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - QuestClaimed + abis: + - name: Quest + file: ./abis/Quest.json + eventHandlers: + - event: QuestClaimed(bytes,address,uint256) + handler: handleQuestClaimed + file: ./src/mappings/quest-factory.ts - kind: ethereum/contract name: QuestFactoryV2 - network: xdai + network: goerli source: - address: "0x2fc3f4A630cD6962A22033436Fd63D93B180c076" + address: "0xa6FEAF5CA07b6F367CF39a840F5A7E41d0AE613D" abi: QuestFactory - startBlock: 25750107 + startBlock: 8240344 mapping: kind: ethereum/events apiVersion: 0.0.6 @@ -52,3 +71,28 @@ dataSources: - event: PlayDepositChanged(uint256,address,uint256) handler: handlePlayDepositChanged file: ./src/mappings/quest-factory.2.ts + - kind: ethereum/contract + name: QuestFactoryV2-Quest + network: goerli + source: + abi: Quest + startBlock: 8240344 + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - QuestClaimedV2 + - QuestPlayed + - QuestUnplayed + abis: + - name: Quest + file: ./abis/Quest.2.json + eventHandlers: + - event: QuestClaimed(bytes,address,uint256) + handler: handleQuestClaimed + - event: QuestPlayed(address,uint256) + handler: handleQuestPlayed + - event: QuestUnplayed(address,uint256) + handler: handleQuestUnplayed + file: ./src/mappings/quest-factory.2.ts From 532570a9451c67fcc6a4a00a3082d76827599190 Mon Sep 17 00:00:00 2001 From: Corantin Date: Mon, 27 Mar 2023 11:58:03 -0400 Subject: [PATCH 2/5] Push fix --- .../src/mappings/quest-factory.2.ts | 36 ++++++++++++------- .../src/mappings/quest-factory.ts | 1 + .../quest-subgraph/src/schema.graphql | 2 +- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.2.ts b/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.2.ts index 9b2c3037..3028998a 100644 --- a/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.2.ts +++ b/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.2.ts @@ -15,8 +15,7 @@ import { QuestClaimEntity, QuestEntity, } from "../../generated/schema"; -import { Bytes, ethereum, ipfs } from "@graphprotocol/graph-ts"; -import { json } from "@graphprotocol/graph-ts"; +import { Bytes, ipfs, json, log } from "@graphprotocol/graph-ts"; export function handleCreateDepositChanged(event: CreateDepositChanged): void { let depositEntity = new CreateDepositEntity( @@ -99,28 +98,39 @@ export function handleQuestCreated(event: QuestCreated): void { } export function handleQuestPlayed(event: QuestPlayed): void { - const hexAddress = event.params._event.address.toHex(); - let questEntity = QuestEntity.load(hexAddress); + const questAddress = event.address.toHex(); + let questEntity = QuestEntity.load(questAddress); if (!questEntity) { - throw new Error("Quest entity not found with " + hexAddress); + log.error("Quest entity not found with address: {}", [questAddress]); + return; } - - questEntity.questPlayers.push(event.params.player.toHexString()); + let questPlayers = questEntity.questPlayers; + questPlayers.push(event.params.player.toHexString()); + questEntity.questPlayers = questPlayers; questEntity.save(); } export function handleQuestUnplayed(event: QuestUnplayed): void { - const hexAddress = event.params._event.address.toHex(); - let questEntity = QuestEntity.load(hexAddress); - + const questAddress = event.address.toHex(); + let questEntity = QuestEntity.load(questAddress); if (!questEntity) { - throw new Error("Quest entity not found with " + hexAddress); + log.error("Quest entity not found with address: {}", [questAddress]); + return; } + let questPlayers = questEntity.questPlayers; const indexToBeRemoved = questEntity.questPlayers.indexOf( event.params.player.toHexString() ); - questEntity.questPlayers.splice(indexToBeRemoved, 1); + if (indexToBeRemoved === -1) { + log.error("Player not found in quest {} players list: {}", [ + questAddress, + event.params.player.toHexString(), + ]); + return; + } + questPlayers.splice(indexToBeRemoved, 1); + questEntity.questPlayers = questPlayers; questEntity.save(); } @@ -128,7 +138,7 @@ export function handleQuestClaimed(event: QuestClaimed): void { const questClaimEntity = new QuestClaimEntity( event.params._event.transaction.hash.toHex() ); - questClaimEntity.questAddress = event.params._event.address.toHexString(); + questClaimEntity.questAddress = event.address.toHexString(); questClaimEntity.amount = event.params.amount; questClaimEntity.evidenceIpfsHash = event.params.evidence; questClaimEntity.player = event.params.player.toHexString(); diff --git a/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.ts b/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.ts index e8ff5678..80847c63 100644 --- a/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.ts +++ b/packages/subgraphs/quest-subgraph/src/mappings/quest-factory.ts @@ -10,6 +10,7 @@ import { import { Bytes, ipfs } from "@graphprotocol/graph-ts"; import { json } from "@graphprotocol/graph-ts"; import { QuestClaimed } from "../../generated/QuestFactory-Quest/Quest"; + export function handleDepositChanged(event: DepositChanged): void { let depositEntity = new CreateDepositEntity( `Create_${event.params.timestamp.toString()}_${event.params.token.toHex()}_${event.params.amount.toHex()}` diff --git a/packages/subgraphs/quest-subgraph/src/schema.graphql b/packages/subgraphs/quest-subgraph/src/schema.graphql index 961ba119..ac318c1f 100644 --- a/packages/subgraphs/quest-subgraph/src/schema.graphql +++ b/packages/subgraphs/quest-subgraph/src/schema.graphql @@ -15,7 +15,7 @@ type _Schema_ ] ) -type QuestEntity @entity(immutable: true) { +type QuestEntity @entity(immutable: false) { id: ID! version: Int! questAddress: String! From 567eecedc7b3a08a1e3ed3ba12af8e227e9928c9 Mon Sep 17 00:00:00 2001 From: Corantin Date: Mon, 27 Mar 2023 12:02:20 -0400 Subject: [PATCH 3/5] Fetch players from subgraph instead --- packages/react-app/src/queries/quests.query.ts | 2 ++ packages/react-app/src/services/quest.service.ts | 6 +----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/react-app/src/queries/quests.query.ts b/packages/react-app/src/queries/quests.query.ts index 42e1fbaf..67f179c5 100644 --- a/packages/react-app/src/queries/quests.query.ts +++ b/packages/react-app/src/queries/quests.query.ts @@ -27,6 +27,7 @@ const QuestEntityQuery = gql` questCreator questFundsRecoveryAddress questMaxPlayers + questPlayers } } `; @@ -74,6 +75,7 @@ const QuestEntitiesQuery = (payload: any) => gql` questCreator questFundsRecoveryAddress questMaxPlayers + questPlayers } } `; diff --git a/packages/react-app/src/services/quest.service.ts b/packages/react-app/src/services/quest.service.ts index 34357bc2..659c3181 100644 --- a/packages/react-app/src/services/quest.service.ts +++ b/packages/react-app/src/services/quest.service.ts @@ -97,7 +97,7 @@ async function mapQuest(questEntity: any, claimCountMap: Map) { maxPlayers: questEntity.questMaxPlayers ? +questEntity.questMaxPlayers : undefined, // If null put undefined unlimited: questEntity.questMaxPlayers ? +questEntity.questMaxPlayers === 0 : undefined, status: QuestStatus.Active, - players: [], + players: questEntity.questPlayers ?? [], governAddress: toChecksumAddress(questEntity.questGovernAddress), version: questEntity.version, features: {}, @@ -112,10 +112,6 @@ async function mapQuest(questEntity: any, claimCountMap: Map) { quest.description = formatIpfsMarkdownLink(quest.detailsRefIpfs, 'See description'); } - if (quest?.features.playableQuest) { - quest.players = await getQuestContract(quest).getPlayers(); - } - return quest; } catch (error) { Logger.exception(error, `Failed to map quest :\n${JSON.stringify(questEntity)}`); From e381ecb96aae36fd8e4dfafecd017adb34710ee7 Mon Sep 17 00:00:00 2001 From: KevinMansour <77366744+KevinMansour@users.noreply.github.com> Date: Thu, 20 Apr 2023 21:14:29 -0400 Subject: [PATCH 4/5] filter played and unplayed --- packages/react-app/src/components/filter.tsx | 24 ++++++++++++++++++- .../src/enums/quest-play-status.enum.ts | 5 ++++ packages/react-app/src/models/filter.model.ts | 2 ++ .../react-app/src/services/quest.service.ts | 10 +++++++- 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 packages/react-app/src/enums/quest-play-status.enum.ts diff --git a/packages/react-app/src/components/filter.tsx b/packages/react-app/src/components/filter.tsx index 8773e3e2..0d0db484 100644 --- a/packages/react-app/src/components/filter.tsx +++ b/packages/react-app/src/components/filter.tsx @@ -5,6 +5,7 @@ import { QuestStatus } from 'src/enums/quest-status.enum'; import { ThemeInterface } from 'src/styles/theme'; import { GUpx } from 'src/utils/style.util'; import styled, { css } from 'styled-components'; +import { QuestPlayStatus } from 'src/enums/quest-play-status.enum'; import { DEFAULT_FILTER } from '../constants'; import DateFieldInput from './field-input/date-field-input'; import { FieldInput } from './field-input/field-input'; @@ -79,7 +80,11 @@ type Props = { }; const QuestStatusOptions = [QuestStatus.Active, QuestStatus.Expired, QuestStatus.All]; - +const QuestPlayStatusOptions = [ + QuestPlayStatus.All, + QuestPlayStatus.Played, + QuestPlayStatus.Unplayed, +]; export function Filter({ compact }: Props) { const { filter, setFilter, toggleFilter } = useFilterContext(); const theme = useTheme(); @@ -152,6 +157,23 @@ export function Filter({ compact }: Props) { compact={compact} /> + + + setFilter({ ...filter, playStatus: QuestPlayStatusOptions[i] }) + } + wide + compact={compact} + /> +