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

Add rari-fuse strategy [rari-fuse] #714

Merged
merged 39 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
09dab71
Copy erc20-balance-of/ and rename to rari-fuse/
MantisClone Jul 16, 2022
2974cd4
Fix tests
MantisClone Jul 16, 2022
afe9f16
Call `FusePoolLens.getPoolUsersWithData(poolAddress, absMaxHealth)`
MantisClone Jul 16, 2022
02c674d
Update examples and schema
MantisClone Jul 16, 2022
1686efe
Use MaxUint256 because BigNumber.from(2**256-1) causes overflow error
MantisClone Jul 16, 2022
68e2883
Add fusePoolLensImplementation
MantisClone Jul 16, 2022
b723bf5
Revert "Add fusePoolLensImplementation"
MantisClone Jul 16, 2022
8f94ff4
Try using getAllBorrowers and getPoolAssetWithData
MantisClone Jul 16, 2022
28b11a9
Try calling getPoolAssetsWithData
MantisClone Jul 16, 2022
4a00efa
Both getPoolUsersWithData and getPoolAssetsWithData revert when called
MantisClone Jul 16, 2022
f207e9a
Add cTokenAddress (the market address) to parameters list
MantisClone Jul 16, 2022
a56b5a4
Strip out code related to getPoolUsersWithData and getPoolAssetsWithData
MantisClone Jul 16, 2022
76df2a1
Try using cToken.balanceOfUnderlying(address owner)
MantisClone Jul 16, 2022
bda81be
Use balanceOf, remove unneded parameters
MantisClone Jul 17, 2022
d77c988
yarn lint
MantisClone Jul 17, 2022
cd5fd1c
Update README
MantisClone Jul 17, 2022
e6a9296
Update README for readability
MantisClone Jul 17, 2022
2bef301
Rename underlyingTokenDecimals back to decimals
MantisClone Jul 17, 2022
9a20c06
Add more addresses to the examples.json
MantisClone Jul 17, 2022
656a891
Update README for readability
MantisClone Jul 17, 2022
6505b1a
Merge branch 'snapshot-labs:master' into rari-fuse
MantisClone Jul 18, 2022
f79afb6
Rename cToken to fToken
MantisClone Jul 18, 2022
0d51dc0
Change parameters to `token` and `fToken`
MantisClone Jul 18, 2022
21130df
Add functions for calculating underlying token balance, console logging
MantisClone Jul 18, 2022
6ef9099
Update schema example
MantisClone Jul 18, 2022
19d9c4a
Remove unncessary comma
MantisClone Jul 18, 2022
4d3e188
More changes to examples.json
MantisClone Jul 18, 2022
a7f5f69
Attempt to fix errors
MantisClone Jul 18, 2022
cfc7f18
Trying to fix
MantisClone Jul 18, 2022
3b0b7da
Update examples to use checksummed addresses
MantisClone Jul 18, 2022
eac9dea
Fixed! Now I can see the console logs.
MantisClone Jul 18, 2022
73c949f
Add error if token param != fToken.underlying()
MantisClone Jul 18, 2022
1c07f37
Add code from Rari Docs
MantisClone Jul 18, 2022
d6d64f4
Finish implementing index.js
MantisClone Jul 19, 2022
d7bebe6
It's not working. Add console logging
MantisClone Jul 19, 2022
e1a65ef
Adjust logic so div is last operation
MantisClone Jul 19, 2022
3562501
Rename base to divisor
MantisClone Jul 19, 2022
e3ff1f7
Remove console logging
MantisClone Jul 19, 2022
9e48cb8
Add additional addresses to examples.json
MantisClone Jul 19, 2022
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
4 changes: 3 additions & 1 deletion src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ import * as solvVoucherClaimable from './solv-voucher-claimable';
import * as h2o from './h2o';
import * as dopamine from './dopamine';
import * as lrcL2SubgraphBalanceOf from './lrc-l2-subgraph-balance-of';
import * as rariFuse from './rari-fuse';

const strategies = {
'forta-shares': fortaShares,
Expand Down Expand Up @@ -671,7 +672,8 @@ const strategies = {
apeswap,
h2o,
dopamine,
'lrc-l2-subgraph-balance-of': lrcL2SubgraphBalanceOf
'lrc-l2-subgraph-balance-of': lrcL2SubgraphBalanceOf,
'rari-fuse': rariFuse
};

Object.keys(strategies).forEach(function (strategyName) {
Expand Down
22 changes: 22 additions & 0 deletions src/strategies/rari-fuse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# rari-fuse

Returns the voter's underlying collateral balances in a given Rari Fuse market (fToken).

Here is an example of parameters:

- `symbol` - (**Optional**, `string`) Symbol of the underlying ERC20 token
- `token` - (**Required**, `string`) Address of the underlying token.
- `fToken` - (**Required**, `string`) Address of the fToken (Rari Fuse market)

```json
{
"symbol": "BANK",
"token": "0x2d94AA3e47d9D5024503Ca8491fcE9A2fB4DA198",
"fToken": "0x250316B3E46600417654b13bEa68b5f64D61E609"
}
```

## Reference

For details about exchange rate between fTokens and underlying tokens, see
https://docs.rari.capital/fuse/#interpreting-exchange-rates
22 changes: 22 additions & 0 deletions src/strategies/rari-fuse/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"name": "Example query",
"strategy": {
"name": "rari-fuse",
"params": {
"symbol": "BANK",
"token": "0x2d94AA3e47d9D5024503Ca8491fcE9A2fB4DA198",
"fToken": "0x250316B3E46600417654b13bEa68b5f64D61E609"
}
},
"network": "1",
"addresses": [
"0x3839AcF1ee7699D1F46b1BE840D8aD8317FDf757",
"0x0cf861f96378dbd5194d74cbe6b0424fafaed940",
"0x0f1d41cc51e97dc9d0cad80dc681777eed3675e3",
"0xb6ac0341fcf3fb507a8208d34a97f13779e1393d",
"0x173ff4db38c3fcde0584f8ea7930c44969a29ba4"
],
"snapshot": 14482171
}
]
62 changes: 62 additions & 0 deletions src/strategies/rari-fuse/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { BigNumber } from '@ethersproject/bignumber';
import { formatUnits } from '@ethersproject/units';
import { Multicaller } from '../../utils';

export const author = 'MantisClone';
export const version = '0.1.0';

const abi = [
'function underlying() public view returns (address)',
'function decimals() public view returns (uint8)',
'function exchangeRateStored() public view returns (uint256)',
'function balanceOf(address owner) external returns (uint256)'
];

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
): Promise<Record<string, number>> {
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest';

const multi = new Multicaller(network, provider, abi, { blockTag });
multi.call('underlying', options.fToken, 'underlying', []);
multi.call('tokenDecimals', options.token, 'decimals', []);
multi.call('fTokenDecimals', options.fToken, 'decimals', []);
multi.call('exchangeRate', options.fToken, 'exchangeRateStored', []);
addresses.forEach((address) =>
multi.call(`fTokenBalances.${address}`, options.fToken, 'balanceOf', [
address
])
);
const result = await multi.execute();

const underlying: string = result.underlying;
const tokenDecimals: BigNumber = result.tokenDecimals;
const fTokenDecimals: BigNumber = result.fTokenDecimals;
const exchangeRate: BigNumber = result.exchangeRate;
const fTokenBalances: Record<string, BigNumber> = result.fTokenBalances;

if (options.token !== underlying) {
throw new Error(
`token parameter doesn't match fToken.underlying(). token=${options.token}, underlying=${underlying}`
);
}

const mantissa: BigNumber = BigNumber.from(18)
.add(tokenDecimals)
.sub(fTokenDecimals);
const divisor: BigNumber = BigNumber.from(10).pow(mantissa);

return Object.fromEntries(
Object.entries(fTokenBalances).map(([address, balance]) => [
address,
parseFloat(
formatUnits(balance.mul(exchangeRate).div(divisor), fTokenDecimals)
)
])
);
}
36 changes: 36 additions & 0 deletions src/strategies/rari-fuse/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/Strategy",
"definitions": {
"Strategy": {
"title": "Strategy",
"type": "object",
"properties": {
"symbol": {
"type": "string",
"title": "symbol",
"examples": ["e.g. BANK"],
"maxLength": 16
},
"token": {
"type": "string",
"title": "token",
"examples": ["e.g. 0x2d94AA3e47d9D5024503Ca8491fcE9A2fB4DA198"],
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
},
"fToken": {
"type": "string",
"title": "fToken",
"examples": ["e.g. 0x250316B3E46600417654b13bEa68b5f64D61E609"],
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
}
},
"required": ["token", "fToken"],
"additionalProperties": false
}
}
}