Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Adding vesting contracts #13

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
106 changes: 106 additions & 0 deletions abis/ERC20VestingFactory.json

Large diffs are not rendered by default.

292 changes: 292 additions & 0 deletions abis/TokenVesting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "TokenVesting",
"sourceName": "openzeppelin-solidity/contracts/drafts/TokenVesting.sol",
"abi": [
{
"inputs": [
{
"internalType": "address",
"name": "beneficiary",
"type": "address"
},
{
"internalType": "uint256",
"name": "start",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "cliffDuration",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "duration",
"type": "uint256"
},
{
"internalType": "bool",
"name": "revocable",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "token",
"type": "address"
}
],
"name": "TokenVestingRevoked",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "token",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "TokensReleased",
"type": "event"
},
{
"constant": true,
"inputs": [],
"name": "beneficiary",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "cliff",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "duration",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "isOwner",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "contract IERC20",
"name": "token",
"type": "address"
}
],
"name": "release",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "address",
"name": "token",
"type": "address"
}
],
"name": "released",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "revocable",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "contract IERC20",
"name": "token",
"type": "address"
}
],
"name": "revoke",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "address",
"name": "token",
"type": "address"
}
],
"name": "revoked",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "start",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
]
}

40 changes: 40 additions & 0 deletions src/mappings/ERC20VestingFactory/mapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { TokenVesting, VestingFactory } from '../../types/schema';
import {
ERC20VestingFactory,
VestingCreated,
} from '../../types/templates/ERC20VestingFactory/ERC20VestingFactory';
import { TokenVesting as TokenVestingContract } from '../../types/templates/TokenVesting/TokenVesting';

export function handleVestingCreated(event: VestingCreated): void {
const tokenVestingAddress = event.params.vestingContractAddress;

// create vestingFactory with ownerAddress + token
const vestingFactory = new VestingFactory(event.address.toHexString());
let vestingFactoryContract = ERC20VestingFactory.bind(event.address);

vestingFactory.token = vestingFactoryContract.erc20Token().toHexString();
vestingFactory.owner = vestingFactoryContract.vestingOwner().toHexString();

let tokenVestingContract = TokenVestingContract.bind(tokenVestingAddress);

let tokenVesting = new TokenVesting(tokenVestingAddress.toHex());

tokenVesting.beneficiary = tokenVestingContract.beneficiary().toString();
tokenVesting.cliff = tokenVestingContract.cliff();
tokenVesting.start = tokenVestingContract.start();
tokenVesting.duration = tokenVestingContract.duration();
tokenVesting.revocable = tokenVestingContract.revocable();
tokenVesting.released = tokenVestingContract.released(
vestingFactoryContract.erc20Token()
);
tokenVesting.revoked = tokenVestingContract.revoked(
vestingFactoryContract.erc20Token()
);
tokenVesting.owner = vestingFactory.owner;
tokenVesting.token = vestingFactory.token;

vestingFactory.save();

tokenVesting.save();
}

6 changes: 6 additions & 0 deletions src/mappings/ERC20VestingFactory/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type VestingFactory @entity {
id: ID!
token: String!
owner: String!
}

10 changes: 10 additions & 0 deletions src/mappings/ERC20VestingFactory/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
abis:
- ERC20VestingFactory
entities:
- VestingFactory
eventHandlers:
- event: VestingCreated(address)
handler: handleVestingCreated
callHandlers:
-

29 changes: 29 additions & 0 deletions src/mappings/TokenVesting/mapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { TokenVesting } from '../../types/schema';
import {
TokensReleased,
TokenVestingRevoked,
} from '../../types/templates/TokenVesting/TokenVesting';

export function handleTokensReleased(event: TokensReleased): void {
let tokenVesting = TokenVesting.load(event.address.toHexString());

if (!tokenVesting) return;

tokenVesting.released = event.params.amount;

tokenVesting.save();
}

export function handleTokenVestingRevoked(event: TokenVestingRevoked): void {
let tokenVesting = TokenVesting.load(event.address.toHexString());

if (!tokenVesting) return;

// why does the contract have this line? there can be more than one token inside the same vesting contract?
// _revoked[address(token)] = true;

tokenVesting.revoked = true;

tokenVesting.save();
}

13 changes: 13 additions & 0 deletions src/mappings/TokenVesting/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type TokenVesting @entity {
id: ID!
owner: String!
token: String!
beneficiary: String!
cliff: BigInt!
start: BigInt!
duration: BigInt!
revocable: Boolean!
released: BigInt!
revoked: Boolean!
}

Loading