Skip to content

Commit

Permalink
Get claimed bLUSD amount from NFT contract instead of logs
Browse files Browse the repository at this point in the history
  • Loading branch information
edmulraney committed Jan 18, 2023
1 parent a25a194 commit c755df4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1548,14 +1548,16 @@ This will start a hardhat mainnet forked RPC node at the block number configured
You'll need an Alchemy API key to create the fork.

```
ALCHEMY_API_KEY=enter_your_key_here yarn start-fork:rpc-node
ALCHEMY_API_KEY=enter_your_key_here yarn start-fork
```

```
yarn start-demo:dev-frontend
```

This spawns a modified version of dev-frontend that ignores MetaMask, and directly uses the local blockchain node. Every time the page is reloaded (at http://localhost:3000). Additionally, transactions are automatically signed, so you no longer need to accept wallet confirmations. This lets you play around with Liquity more freely.
This spawns a modified version of dev-frontend that automatically signs transactions so you don't need to interact with a browser wallet. It directly uses the local blockchain node. This lets you play around with Liquity more freely.

Make sure you configure your browser wallet to use the local fork RPC node: `http://localhost:8045`

When you no longer need the forked frontend mode, press Ctrl+C.

Expand Down
4 changes: 2 additions & 2 deletions hardhat.config.mainnet-fork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const config: HardhatUserConfig = {
hardhat: {
chainId: 1,
forking: {
url: `https://eth-mainnet.alchemyapi.io/v2/${alchemyApiKey}`,
blockNumber: 15767479
url: `https://eth-mainnet.g.alchemy.com/v2/${alchemyApiKey}`,
blockNumber: 16233419
},
accounts: [
{
Expand Down
24 changes: 4 additions & 20 deletions packages/dev-frontend/src/components/Bonds/context/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,6 @@ const cacheYearnVaultApys = async (): Promise<void> => {
}
};

const getClaimedBonds = async (
account: string,
chickenBondManager: ChickenBondManager
): Promise<ClaimedBonds> => {
const claimedBondsFilter = await chickenBondManager.filters.BondClaimed(account);
const events = await chickenBondManager.queryFilter(claimedBondsFilter);
const claimedBonds = events.reduce((accumulator, current) => {
const { bondId, bLusdAmount } = current.args;
return {
...accumulator,
[bondId.toNumber().toString()]: decimalify(bLusdAmount)
};
}, {});

return claimedBonds;
};

const getAccountBonds = async (
account: string,
bondNft: BondNFT,
Expand Down Expand Up @@ -280,7 +263,8 @@ const getAccountBonds = async (
startTimes: bondIds.map(bondId => bondNft.getBondStartTime(bondId)),
endTimes: bondIds.map(bondId => bondNft.getBondEndTime(bondId)),
statuses: bondIds.map(bondId => bondNft.getBondStatus(bondId)),
tokenUris: bondIds.map(bondId => bondNft.tokenURI(bondId))
tokenUris: bondIds.map(bondId => bondNft.tokenURI(bondId)),
claimedAmounts: bondIds.map(bondId => bondNft.getBondClaimedBLUSD(bondId))
};

const bondDeposits = await Promise.all(bondRequests.deposits);
Expand All @@ -289,7 +273,7 @@ const getAccountBonds = async (
const bondEndTimes = await Promise.all(bondRequests.endTimes);
const bondStatuses = await Promise.all(bondRequests.statuses);
const bondTokenUris = await Promise.all(bondRequests.tokenUris);
const claimedBonds = await getClaimedBonds(account, chickenBondManager);
const bondClaimedAmounts = await Promise.all(bondRequests.claimedAmounts);

const bonds = bondIds
.reduce<Bond[]>((accumulator, _, idx) => {
Expand Down Expand Up @@ -368,7 +352,7 @@ const getAccountBonds = async (
const rebondReturn = accrued.isZero ? 0 : getReturn(rebondAccrual, deposit, marketPrice);
const rebondRoi = rebondReturn / toFloat(deposit);
const rebondApr = rebondRoi * (365 / (bondAgeInDays + remainingRebondDays));
const claimedAmount = claimedBonds[id];
const claimedAmount = Decimal.from(numberify(bondClaimedAmounts[idx]));

return [
...accumulator,
Expand Down

0 comments on commit c755df4

Please sign in to comment.