Skip to content

Commit

Permalink
adds fee event arg to all Started events
Browse files Browse the repository at this point in the history
adds support for old Started event signature
considers fees on the subgraph
reduces mapping code duplication by synthesizing a Crowdsale:Started event

add feeBp to crowdSale in subgraph

feebps can be int

Signed-off-by: stadolf <[email protected]>
  • Loading branch information
elmariachi111 committed Oct 27, 2023
1 parent f38c2c2 commit e46a02e
Show file tree
Hide file tree
Showing 10 changed files with 307 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/crowdsale/CrowdSale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ contract CrowdSale is ReentrancyGuard, Ownable {
*/
uint16 public currentFeeBp = 0;

event Started(uint256 indexed saleId, address indexed issuer, Sale sale, uint16 percentageFee);
event Started(uint256 indexed saleId, address indexed issuer, Sale sale, uint16 feeBp);
event Settled(uint256 indexed saleId, uint256 totalBids, uint256 surplus);
/// @notice emitted when participants of the sale claim their tokens
event Claimed(uint256 indexed saleId, address indexed claimer, uint256 claimed, uint256 refunded);
Expand Down
11 changes: 9 additions & 2 deletions src/crowdsale/LockingCrowdSale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract LockingCrowdSale is CrowdSale {

address immutable lockingTokenImplementation = address(new TimelockedToken());

event Started(uint256 indexed saleId, address indexed issuer, Sale sale, TimelockedToken lockingToken, uint256 lockingDuration);
event Started(uint256 indexed saleId, address indexed issuer, Sale sale, TimelockedToken lockingToken, uint256 lockingDuration, uint16 feeBp);
event LockingContractCreated(TimelockedToken indexed lockingContract, IERC20Metadata indexed underlyingToken);

/// @dev disable parent sale starting functions
Expand Down Expand Up @@ -71,7 +71,14 @@ contract LockingCrowdSale is CrowdSale {
}

function _afterSaleStarted(uint256 saleId) internal virtual override {
emit Started(saleId, msg.sender, _sales[saleId], lockingContracts[address(_sales[saleId].auctionToken)], salesLockingDuration[saleId]);
emit Started(
saleId,
msg.sender,
_sales[saleId],
lockingContracts[address(_sales[saleId].auctionToken)],
salesLockingDuration[saleId],
_saleInfo[saleId].feeBp
);
}

function _afterSaleSettled(uint256 saleId) internal override {
Expand Down
6 changes: 4 additions & 2 deletions src/crowdsale/StakedLockingCrowdSale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ contract StakedLockingCrowdSale is LockingCrowdSale {
StakingInfo staking,
TimelockedToken lockingToken,
uint256 lockingDuration,
uint256 stakingDuration
uint256 stakingDuration,
uint16 feeBp
);
event Staked(uint256 indexed saleId, address indexed bidder, uint256 stakedAmount, uint256 price);
event ClaimedStakes(uint256 indexed saleId, address indexed claimer, uint256 stakesClaimed, uint256 stakesRefunded);
Expand Down Expand Up @@ -139,7 +140,8 @@ contract StakedLockingCrowdSale is LockingCrowdSale {
salesStaking[saleId],
lockingContracts[address(_sales[saleId].auctionToken)],
salesLockingDuration[saleId],
stakingDuration
stakingDuration,
_saleInfo[saleId].feeBp
);
}

Expand Down
2 changes: 1 addition & 1 deletion subgraph/abis/CrowdSale.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
{
"indexed": false,
"internalType": "uint16",
"name": "percentageFee",
"name": "feeBp",
"type": "uint16"
}
],
Expand Down
117 changes: 116 additions & 1 deletion subgraph/abis/StakedLockingCrowdSale.json
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,12 @@
"internalType": "uint256",
"name": "stakingDuration",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint16",
"name": "feeBp",
"type": "uint16"
}
],
"name": "Started",
Expand Down Expand Up @@ -506,6 +512,12 @@
"internalType": "uint256",
"name": "lockingDuration",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint16",
"name": "feeBp",
"type": "uint16"
}
],
"name": "Started",
Expand Down Expand Up @@ -572,7 +584,7 @@
{
"indexed": false,
"internalType": "uint16",
"name": "percentageFee",
"name": "feeBp",
"type": "uint16"
}
],
Expand Down Expand Up @@ -1210,5 +1222,108 @@
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "uint256",
"name": "saleId",
"type": "uint256"
},
{
"indexed": true,
"internalType": "address",
"name": "issuer",
"type": "address"
},
{
"components": [
{
"internalType": "contract IERC20Metadata",
"name": "auctionToken",
"type": "address"
},
{
"internalType": "contract IERC20Metadata",
"name": "biddingToken",
"type": "address"
},
{
"internalType": "address",
"name": "beneficiary",
"type": "address"
},
{
"internalType": "uint256",
"name": "fundingGoal",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "salesAmount",
"type": "uint256"
},
{
"internalType": "uint64",
"name": "closingTime",
"type": "uint64"
},
{
"internalType": "contract IPermissioner",
"name": "permissioner",
"type": "address"
}
],
"indexed": false,
"internalType": "struct Sale",
"name": "sale",
"type": "tuple"
},
{
"components": [
{
"internalType": "contract IERC20Metadata",
"name": "stakedToken",
"type": "address"
},
{
"internalType": "contract TokenVesting",
"name": "stakesVestingContract",
"type": "address"
},
{
"internalType": "uint256",
"name": "wadFixedStakedPerBidPrice",
"type": "uint256"
}
],
"indexed": false,
"internalType": "struct StakingInfo",
"name": "staking",
"type": "tuple"
},
{
"indexed": false,
"internalType": "contract TimelockedToken",
"name": "lockingToken",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "lockingDuration",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "stakingDuration",
"type": "uint256"
}
],
"name": "Started",
"type": "event"
}
]
108 changes: 108 additions & 0 deletions subgraph/makeAbis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,111 @@ jq '. += [{

rm ./abis/_Tokenizer.json

# add the old StakedLockingCrowdSale's `Started` event to the abi so the subgraph can index them
#event Started(uint256 indexed saleId, address indexed issuer, Sale sale);

cat ../out/StakedLockingCrowdSale.sol/StakedLockingCrowdSale.json | jq .abi > ./abis/_StakedLockingCrowdSale.json
jq '. += [{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "uint256",
"name": "saleId",
"type": "uint256"
},
{
"indexed": true,
"internalType": "address",
"name": "issuer",
"type": "address"
},
{
"components": [
{
"internalType": "contract IERC20Metadata",
"name": "auctionToken",
"type": "address"
},
{
"internalType": "contract IERC20Metadata",
"name": "biddingToken",
"type": "address"
},
{
"internalType": "address",
"name": "beneficiary",
"type": "address"
},
{
"internalType": "uint256",
"name": "fundingGoal",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "salesAmount",
"type": "uint256"
},
{
"internalType": "uint64",
"name": "closingTime",
"type": "uint64"
},
{
"internalType": "contract IPermissioner",
"name": "permissioner",
"type": "address"
}
],
"indexed": false,
"internalType": "struct Sale",
"name": "sale",
"type": "tuple"
},
{
"components": [
{
"internalType": "contract IERC20Metadata",
"name": "stakedToken",
"type": "address"
},
{
"internalType": "contract TokenVesting",
"name": "stakesVestingContract",
"type": "address"
},
{
"internalType": "uint256",
"name": "wadFixedStakedPerBidPrice",
"type": "uint256"
}
],
"indexed": false,
"internalType": "struct StakingInfo",
"name": "staking",
"type": "tuple"
},
{
"indexed": false,
"internalType": "contract TimelockedToken",
"name": "lockingToken",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "lockingDuration",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "stakingDuration",
"type": "uint256"
}
],
"name": "Started",
"type": "event"
}]' ./abis/_StakedLockingCrowdSale.json > ./abis/StakedLockingCrowdSale.json
rm ./abis/_StakedLockingCrowdSale.json
1 change: 1 addition & 0 deletions subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ type CrowdSale @entity {
permissioner: Bytes! #a crowdsale can be configured with an individual permissioner
claimedAt: BigInt # the date when the auctioneer has claimed their return (depending on failed / settled sales)
contributions: [Contribution!] @derivedFrom(field: "crowdSale")
feeBp: Int # the percentage fee that will be cut from the crowdsale upon its success
type: SaleType!
}

Expand Down
1 change: 1 addition & 0 deletions subgraph/src/crowdSaleMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function handleStarted(event: StartedEvent): void {

crowdSale.ipt = ipt.id
crowdSale.issuer = event.params.issuer
crowdSale.feeBp = event.params.feeBp
crowdSale.beneficiary = event.params.sale.beneficiary
crowdSale.closingTime = event.params.sale.closingTime
crowdSale.createdAt = event.block.timestamp
Expand Down
Loading

0 comments on commit e46a02e

Please sign in to comment.