Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
*.graphql
*.md
*.yml

##TODO: To remove and format this folder in an other PR
src/**
Comment on lines -4 to -6
Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove TODO ✅

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@
"dependencies": {
"@iexec/poco": "^5.5.0"
}
}
}
40 changes: 20 additions & 20 deletions src/Modules/IexecCategoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@
* limitations under the License. *
******************************************************************************/

import { BigInt } from "@graphprotocol/graph-ts";
import { BigInt } from '@graphprotocol/graph-ts';

import { CreateCategory as CreateCategoryEvent } from "../../generated/Core/IexecInterfaceToken";
import { CreateCategory as CreateCategoryEvent } from '../../generated/Core/IexecInterfaceToken';

import { Category } from "../../generated/schema";
import { Category } from '../../generated/schema';

import { fetchProtocol } from "../utils";
import { fetchProtocol } from '../utils';

export function handleCreateCategory(event: CreateCategoryEvent): void {
// categories may be redefined by the administrator
let category = Category.load(event.params.catid.toString());

if (category == null) {
category = new Category(event.params.catid.toString());

let protocol = fetchProtocol();
protocol.categoriesCount = protocol.categoriesCount.plus(BigInt.fromI32(1));
protocol.save();
}

category.name = event.params.name;
category.description = event.params.description;
category.workClockTimeRef = event.params.workClockTimeRef;
category.timestamp = event.block.timestamp;
category.save();
// categories may be redefined by the administrator
let category = Category.load(event.params.catid.toString());

if (category == null) {
category = new Category(event.params.catid.toString());

let protocol = fetchProtocol();
protocol.categoriesCount = protocol.categoriesCount.plus(BigInt.fromI32(1));
protocol.save();
}

category.name = event.params.name;
category.description = event.params.description;
category.workClockTimeRef = event.params.workClockTimeRef;
category.timestamp = event.block.timestamp;
category.save();
}
170 changes: 85 additions & 85 deletions src/Modules/IexecERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,106 +15,106 @@
******************************************************************************/

import {
Transfer as TransferEvent,
Reward as RewardEvent,
Seize as SeizeEvent,
Lock as LockEvent,
Unlock as UnlockEvent,
} from "../../generated/Core/IexecInterfaceToken";
Lock as LockEvent,
Reward as RewardEvent,
Seize as SeizeEvent,
Transfer as TransferEvent,
Unlock as UnlockEvent,
} from '../../generated/Core/IexecInterfaceToken';

import { Transfer, Reward, Seize, Lock, Unlock } from "../../generated/schema";
import { Lock, Reward, Seize, Transfer, Unlock } from '../../generated/schema';

import {
ADDRESS_ZERO,
createEventID,
fetchAccount,
fetchProtocol,
logTransaction,
toRLC,
} from "../utils";
ADDRESS_ZERO,
createEventID,
fetchAccount,
fetchProtocol,
logTransaction,
toRLC,
} from '../utils';

export function handleTransfer(event: TransferEvent): void {
let protocol = fetchProtocol();
let value = toRLC(event.params.value);
let from = fetchAccount(event.params.from.toHex());
let to = fetchAccount(event.params.to.toHex());
if (from.id == ADDRESS_ZERO) {
protocol.tvl = protocol.tvl.plus(value);
} else {
from.balance = from.balance.minus(value);
}
if (to.id == ADDRESS_ZERO) {
protocol.tvl = protocol.tvl.minus(value);
} else {
to.balance = to.balance.plus(value);
}
protocol.save();
from.save();
to.save();

let transferEvent = new Transfer(createEventID(event));
transferEvent.transaction = logTransaction(event).id;
transferEvent.timestamp = event.block.timestamp;
transferEvent.from = from.id;
transferEvent.to = to.id;
transferEvent.value = value;
transferEvent.save();
let protocol = fetchProtocol();
let value = toRLC(event.params.value);
let from = fetchAccount(event.params.from.toHex());
let to = fetchAccount(event.params.to.toHex());
if (from.id == ADDRESS_ZERO) {
protocol.tvl = protocol.tvl.plus(value);
} else {
from.balance = from.balance.minus(value);
}
if (to.id == ADDRESS_ZERO) {
protocol.tvl = protocol.tvl.minus(value);
} else {
to.balance = to.balance.plus(value);
}
protocol.save();
from.save();
to.save();

let transferEvent = new Transfer(createEventID(event));
transferEvent.transaction = logTransaction(event).id;
transferEvent.timestamp = event.block.timestamp;
transferEvent.from = from.id;
transferEvent.to = to.id;
transferEvent.value = value;
transferEvent.save();
}

export function handleReward(event: RewardEvent): void {
let value = toRLC(event.params.amount);

let op = new Reward(createEventID(event));
op.transaction = logTransaction(event).id;
op.timestamp = event.block.timestamp;
op.account = event.params.owner.toHex();
op.value = value;
op.task = event.params.ref.toHex();
op.save();
let value = toRLC(event.params.amount);

let op = new Reward(createEventID(event));
op.transaction = logTransaction(event).id;
op.timestamp = event.block.timestamp;
op.account = event.params.owner.toHex();
op.value = value;
op.task = event.params.ref.toHex();
op.save();
}

export function handleSeize(event: SeizeEvent): void {
let value = toRLC(event.params.amount);

let account = fetchAccount(event.params.owner.toHex());
account.frozen = account.frozen.minus(value);
account.save();

let op = new Seize(createEventID(event));
op.transaction = logTransaction(event).id;
op.timestamp = event.block.timestamp;
op.account = event.params.owner.toHex();
op.value = value;
op.task = event.params.ref.toHex();
op.save();
let value = toRLC(event.params.amount);

let account = fetchAccount(event.params.owner.toHex());
account.frozen = account.frozen.minus(value);
account.save();

let op = new Seize(createEventID(event));
op.transaction = logTransaction(event).id;
op.timestamp = event.block.timestamp;
op.account = event.params.owner.toHex();
op.value = value;
op.task = event.params.ref.toHex();
op.save();
}

export function handleLock(event: LockEvent): void {
let value = toRLC(event.params.amount);

let account = fetchAccount(event.params.owner.toHex());
account.frozen = account.frozen.plus(value);
account.save();

let op = new Lock(createEventID(event));
op.transaction = logTransaction(event).id;
op.timestamp = event.block.timestamp;
op.account = event.params.owner.toHex();
op.value = value;
op.save();
let value = toRLC(event.params.amount);

let account = fetchAccount(event.params.owner.toHex());
account.frozen = account.frozen.plus(value);
account.save();

let op = new Lock(createEventID(event));
op.transaction = logTransaction(event).id;
op.timestamp = event.block.timestamp;
op.account = event.params.owner.toHex();
op.value = value;
op.save();
}

export function handleUnlock(event: UnlockEvent): void {
let value = toRLC(event.params.amount);

let account = fetchAccount(event.params.owner.toHex());
account.frozen = account.frozen.minus(value);
account.save();

let op = new Unlock(createEventID(event));
op.transaction = logTransaction(event).id;
op.timestamp = event.block.timestamp;
op.account = event.params.owner.toHex();
op.value = value;
op.save();
let value = toRLC(event.params.amount);

let account = fetchAccount(event.params.owner.toHex());
account.frozen = account.frozen.minus(value);
account.save();

let op = new Unlock(createEventID(event));
op.transaction = logTransaction(event).id;
op.timestamp = event.block.timestamp;
op.account = event.params.owner.toHex();
op.value = value;
op.save();
}
78 changes: 39 additions & 39 deletions src/Registries/Appregistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,54 @@
* limitations under the License. *
******************************************************************************/

import { BigInt } from "@graphprotocol/graph-ts";
import { BigInt } from '@graphprotocol/graph-ts';

import { App as AppContract } from "../../generated/AppRegistry/App";
import { App as AppContract } from '../../generated/AppRegistry/App';

import { Transfer as TransferEvent } from "../../generated/AppRegistry/AppRegistry";
import { Transfer as TransferEvent } from '../../generated/AppRegistry/AppRegistry';

import { App, AppTransfer } from "../../generated/schema";
import { App, AppTransfer } from '../../generated/schema';

import {
createEventID,
fetchAccount,
fetchProtocol,
logTransaction,
intToAddress,
ADDRESS_ZERO,
} from "../utils";
ADDRESS_ZERO,
createEventID,
fetchAccount,
fetchProtocol,
intToAddress,
logTransaction,
} from '../utils';

export function handleTransferApp(ev: TransferEvent): void {
let contract = AppContract.bind(intToAddress(ev.params.tokenId));
let contract = AppContract.bind(intToAddress(ev.params.tokenId));

let from = fetchAccount(ev.params.from.toHex());
let to = fetchAccount(ev.params.to.toHex());
from.save();
to.save();
let from = fetchAccount(ev.params.from.toHex());
let to = fetchAccount(ev.params.to.toHex());
from.save();
to.save();

let app = new App(contract._address.toHex());
app.owner = contract.owner().toHex();
app.name = contract.m_appName();
app.type = contract.m_appType();
app.multiaddr = contract.m_appMultiaddr();
app.checksum = contract.m_appChecksum();
app.mrenclave = contract.m_appMREnclave();
app.timestamp = ev.block.timestamp;
app.usageCount = BigInt.zero();
app.lastUsageTimestamp = BigInt.zero();
app.save();
let app = new App(contract._address.toHex());
app.owner = contract.owner().toHex();
app.name = contract.m_appName();
app.type = contract.m_appType();
app.multiaddr = contract.m_appMultiaddr();
app.checksum = contract.m_appChecksum();
app.mrenclave = contract.m_appMREnclave();
app.timestamp = ev.block.timestamp;
app.usageCount = BigInt.zero();
app.lastUsageTimestamp = BigInt.zero();
app.save();

let transfer = new AppTransfer(createEventID(ev));
transfer.transaction = logTransaction(ev).id;
transfer.timestamp = app.timestamp;
transfer.app = app.id;
transfer.from = from.id;
transfer.to = to.id;
transfer.save();
let transfer = new AppTransfer(createEventID(ev));
transfer.transaction = logTransaction(ev).id;
transfer.timestamp = app.timestamp;
transfer.app = app.id;
transfer.from = from.id;
transfer.to = to.id;
transfer.save();

if (from.id == ADDRESS_ZERO) {
let protocol = fetchProtocol();
protocol.appsCount = protocol.appsCount.plus(BigInt.fromI32(1));
protocol.save();
}
if (from.id == ADDRESS_ZERO) {
let protocol = fetchProtocol();
protocol.appsCount = protocol.appsCount.plus(BigInt.fromI32(1));
protocol.save();
}
}
Loading
Loading