From 09dab7118cdbf550909802f474e4b5b86280f2fa Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sat, 16 Jul 2022 09:06:31 -0400 Subject: [PATCH 01/38] Copy erc20-balance-of/ and rename to rari-fuse/ --- src/strategies/rari-fuse/README.md | 13 ++++++++++ src/strategies/rari-fuse/examples.json | 35 ++++++++++++++++++++++++++ src/strategies/rari-fuse/index.ts | 34 +++++++++++++++++++++++++ src/strategies/rari-fuse/schema.json | 33 ++++++++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 src/strategies/rari-fuse/README.md create mode 100644 src/strategies/rari-fuse/examples.json create mode 100644 src/strategies/rari-fuse/index.ts create mode 100644 src/strategies/rari-fuse/schema.json diff --git a/src/strategies/rari-fuse/README.md b/src/strategies/rari-fuse/README.md new file mode 100644 index 000000000..e0af42a1b --- /dev/null +++ b/src/strategies/rari-fuse/README.md @@ -0,0 +1,13 @@ +# erc20-balance-of + +This is the most common strategy, it returns the balances of the voters for a specific ERC20 token. + +Here is an example of parameters: + +```json +{ + "address": "0x6b175474e89094c44da98b954eedeac495271d0f", + "symbol": "DAI", + "decimals": 18 +} +``` diff --git a/src/strategies/rari-fuse/examples.json b/src/strategies/rari-fuse/examples.json new file mode 100644 index 000000000..91c907bdd --- /dev/null +++ b/src/strategies/rari-fuse/examples.json @@ -0,0 +1,35 @@ +[ + { + "name": "Example query", + "strategy": { + "name": "erc20-balance-of", + "params": { + "address": "0x6b175474e89094c44da98b954eedeac495271d0f", + "symbol": "DAI", + "decimals": 18 + } + }, + "network": "1", + "addresses": [ + "0xa478c2975ab1ea89e8196811f51a7b7ade33eb11", + "0xeF8305E140ac520225DAf050e2f71d5fBcC543e7", + "0x1E1A51E25f2816335cA436D65e9Af7694BE232ad", + "0x1F717Ce8ff07597ee7c408b5623dF40AaAf1787C", + "0x1c7a9275F2BD5a260A9c31069F77d53473b8ae2e", + "0x1d5E65a087eBc3d03a294412E46CE5D6882969f4", + "0x1f254336E5c46639A851b9CfC165697150a6c327", + "0x2ec3F80BeDA63Ede96BA20375032CDD3aAfb3030", + "0x4AcBcA6BE2f8D2540bBF4CA77E45dA0A4a095Fa2", + "0x4F3D348a6D09837Ae7961B1E0cEe2cc118cec777", + "0x6D7f23A509E212Ba7773EC1b2505d1A134f54fbe", + "0x07a1f6fc89223c5ebD4e4ddaE89Ac97629856A0f", + "0x8d5F05270da470e015b67Ab5042BDbE2D2FEFB48", + "0x8d07D225a769b7Af3A923481E1FdF49180e6A265", + "0x8f60501dE5b9b01F9EAf1214dbE1924aA97F7fd0", + "0x9B8e8dD9151260c21CB6D7cc59067cd8DF306D58", + "0x17ea92D6FfbAA1c7F6B117c1E9D0c88ABdc8b84C", + "0x38C0039247A31F3939baE65e953612125cB88268" + ], + "snapshot": 11437846 + } +] diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts new file mode 100644 index 000000000..ead8f5514 --- /dev/null +++ b/src/strategies/rari-fuse/index.ts @@ -0,0 +1,34 @@ +import { BigNumberish } from '@ethersproject/bignumber'; +import { formatUnits } from '@ethersproject/units'; +import { Multicaller } from '../../utils'; + +export const author = 'bonustrack'; +export const version = '0.1.1'; + +const abi = [ + 'function balanceOf(address account) external view returns (uint256)' +]; + +export async function strategy( + space, + network, + provider, + addresses, + options, + snapshot +): Promise> { + const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; + + const multi = new Multicaller(network, provider, abi, { blockTag }); + addresses.forEach((address) => + multi.call(address, options.address, 'balanceOf', [address]) + ); + const result: Record = await multi.execute(); + + return Object.fromEntries( + Object.entries(result).map(([address, balance]) => [ + address, + parseFloat(formatUnits(balance, options.decimals)) + ]) + ); +} diff --git a/src/strategies/rari-fuse/schema.json b/src/strategies/rari-fuse/schema.json new file mode 100644 index 000000000..2113da8b8 --- /dev/null +++ b/src/strategies/rari-fuse/schema.json @@ -0,0 +1,33 @@ +{ + "$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. UNI"], + "maxLength": 16 + }, + "address": { + "type": "string", + "title": "Contract address", + "examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"], + "pattern": "^0x[a-fA-F0-9]{40}$", + "minLength": 42, + "maxLength": 42 + }, + "decimals": { + "type": "number", + "title": "Decimals", + "examples": ["e.g. 18"] + } + }, + "required": ["address", "decimals"], + "additionalProperties": false + } + } +} From 2974cd4b5070d490b0d3a04ad966a84fe4244fcf Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sat, 16 Jul 2022 09:45:03 -0400 Subject: [PATCH 02/38] Fix tests --- src/strategies/index.ts | 4 +++- src/strategies/rari-fuse/examples.json | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/strategies/index.ts b/src/strategies/index.ts index 8e2cbb25a..87640ac90 100644 --- a/src/strategies/index.ts +++ b/src/strategies/index.ts @@ -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, @@ -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) { diff --git a/src/strategies/rari-fuse/examples.json b/src/strategies/rari-fuse/examples.json index 91c907bdd..84019bdbf 100644 --- a/src/strategies/rari-fuse/examples.json +++ b/src/strategies/rari-fuse/examples.json @@ -2,7 +2,7 @@ { "name": "Example query", "strategy": { - "name": "erc20-balance-of", + "name": "rari-fuse", "params": { "address": "0x6b175474e89094c44da98b954eedeac495271d0f", "symbol": "DAI", From afe9f16db6facdfe3eb26e4a2c40b2ad32c571fd Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sat, 16 Jul 2022 09:49:43 -0400 Subject: [PATCH 03/38] Call `FusePoolLens.getPoolUsersWithData(poolAddress, absMaxHealth)` --- src/strategies/rari-fuse/index.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index ead8f5514..6a51c202d 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -2,11 +2,15 @@ import { BigNumberish } from '@ethersproject/bignumber'; import { formatUnits } from '@ethersproject/units'; import { Multicaller } from '../../utils'; -export const author = 'bonustrack'; -export const version = '0.1.1'; +export const author = 'MantisClone'; +export const version = '0.1.0'; + +const fusePoolLens = '0x6Dc585Ad66A10214Ef0502492B0CC02F0e836eec' + +const absMaxHealth = 2**256 - 1 // Absolute max health factor, show all users const abi = [ - 'function balanceOf(address account) external view returns (uint256)' + 'function getPoolUsersWithData(address comptroller,uint256 maxHealth) returns (FusePoolUser[], uint256, uint256)' ]; export async function strategy( @@ -20,11 +24,15 @@ export async function strategy( const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; const multi = new Multicaller(network, provider, abi, { blockTag }); - addresses.forEach((address) => - multi.call(address, options.address, 'balanceOf', [address]) + addresses.forEach((voterAddress) => + multi.call('poolUsersWithData', fusePoolLens, 'getPoolUsersWithData', [options.poolAddress, absMaxHealth]) ); const result: Record = await multi.execute(); + const poolUsersWithData = result.poolUsersWithData; + + console.log(`poolUsersWithData = ${poolUsersWithData}`); + return Object.fromEntries( Object.entries(result).map(([address, balance]) => [ address, From 02c674d01ee43b5c1a281c8d992a1abd32b140ac Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sat, 16 Jul 2022 10:14:46 -0400 Subject: [PATCH 04/38] Update examples and schema --- src/strategies/rari-fuse/examples.json | 28 ++++++-------------------- src/strategies/rari-fuse/schema.json | 28 +++++++++++++++++--------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/strategies/rari-fuse/examples.json b/src/strategies/rari-fuse/examples.json index 84019bdbf..9ba655f2e 100644 --- a/src/strategies/rari-fuse/examples.json +++ b/src/strategies/rari-fuse/examples.json @@ -4,32 +4,16 @@ "strategy": { "name": "rari-fuse", "params": { - "address": "0x6b175474e89094c44da98b954eedeac495271d0f", - "symbol": "DAI", - "decimals": 18 + "symbol": "BANK", + "decimals": 18, + "tokenAddress": "0x2d94AA3e47d9D5024503Ca8491fcE9A2fB4DA198", + "poolAddress": "0x3eE001bA561Af4478E5BBc510324f970aF7DBcDF" } }, "network": "1", "addresses": [ - "0xa478c2975ab1ea89e8196811f51a7b7ade33eb11", - "0xeF8305E140ac520225DAf050e2f71d5fBcC543e7", - "0x1E1A51E25f2816335cA436D65e9Af7694BE232ad", - "0x1F717Ce8ff07597ee7c408b5623dF40AaAf1787C", - "0x1c7a9275F2BD5a260A9c31069F77d53473b8ae2e", - "0x1d5E65a087eBc3d03a294412E46CE5D6882969f4", - "0x1f254336E5c46639A851b9CfC165697150a6c327", - "0x2ec3F80BeDA63Ede96BA20375032CDD3aAfb3030", - "0x4AcBcA6BE2f8D2540bBF4CA77E45dA0A4a095Fa2", - "0x4F3D348a6D09837Ae7961B1E0cEe2cc118cec777", - "0x6D7f23A509E212Ba7773EC1b2505d1A134f54fbe", - "0x07a1f6fc89223c5ebD4e4ddaE89Ac97629856A0f", - "0x8d5F05270da470e015b67Ab5042BDbE2D2FEFB48", - "0x8d07D225a769b7Af3A923481E1FdF49180e6A265", - "0x8f60501dE5b9b01F9EAf1214dbE1924aA97F7fd0", - "0x9B8e8dD9151260c21CB6D7cc59067cd8DF306D58", - "0x17ea92D6FfbAA1c7F6B117c1E9D0c88ABdc8b84C", - "0x38C0039247A31F3939baE65e953612125cB88268" + "0x0cf861f96378dbd5194d74cbe6b0424fafaed940" ], - "snapshot": 11437846 + "snapshot": 14609590 } ] diff --git a/src/strategies/rari-fuse/schema.json b/src/strategies/rari-fuse/schema.json index 2113da8b8..252df4252 100644 --- a/src/strategies/rari-fuse/schema.json +++ b/src/strategies/rari-fuse/schema.json @@ -8,25 +8,33 @@ "properties": { "symbol": { "type": "string", - "title": "Symbol", - "examples": ["e.g. UNI"], + "title": "symbol", + "examples": ["e.g. BANK"], "maxLength": 16 }, - "address": { + "decimals": { + "type": "number", + "title": "decimals", + "examples": ["e.g. 18"] + }, + "tokenAddress": { "type": "string", - "title": "Contract address", - "examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"], + "title": "tokenAddress", + "examples": ["e.g. 0x2d94AA3e47d9D5024503Ca8491fcE9A2fB4DA198"], "pattern": "^0x[a-fA-F0-9]{40}$", "minLength": 42, "maxLength": 42 }, - "decimals": { - "type": "number", - "title": "Decimals", - "examples": ["e.g. 18"] + "poolAddress": { + "type": "string", + "title": "poolAddress", + "examples": ["e.g. 0x472D0B0DDFE0BC02C27928b8BcbD67E65D07d48a"], + "pattern": "^0x[a-fA-F0-9]{40}$", + "minLength": 42, + "maxLength": 42 } }, - "required": ["address", "decimals"], + "required": ["decimals", "tokenAddress", "poolAddress"], "additionalProperties": false } } From 1686efe888def7501cf2593fc5c86d3ba6080a53 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sat, 16 Jul 2022 10:33:40 -0400 Subject: [PATCH 05/38] Use MaxUint256 because BigNumber.from(2**256-1) causes overflow error --- src/strategies/rari-fuse/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 6a51c202d..8a78cb95f 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -1,5 +1,6 @@ import { BigNumberish } from '@ethersproject/bignumber'; import { formatUnits } from '@ethersproject/units'; +import { MaxUint256 } from '@ethersproject/constants'; import { Multicaller } from '../../utils'; export const author = 'MantisClone'; @@ -7,7 +8,7 @@ export const version = '0.1.0'; const fusePoolLens = '0x6Dc585Ad66A10214Ef0502492B0CC02F0e836eec' -const absMaxHealth = 2**256 - 1 // Absolute max health factor, show all users +const absMaxHealth = MaxUint256 // show all users const abi = [ 'function getPoolUsersWithData(address comptroller,uint256 maxHealth) returns (FusePoolUser[], uint256, uint256)' From 68e28830fbc286599e3d9693dc416a92eea2b4d4 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sat, 16 Jul 2022 16:03:37 -0400 Subject: [PATCH 06/38] Add fusePoolLensImplementation --- src/strategies/rari-fuse/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 8a78cb95f..712a20288 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -7,6 +7,7 @@ export const author = 'MantisClone'; export const version = '0.1.0'; const fusePoolLens = '0x6Dc585Ad66A10214Ef0502492B0CC02F0e836eec' +const fusePoolLensImplementation = '0x6bcc070637a6eb4a13df47b906e4017530fd125d' const absMaxHealth = MaxUint256 // show all users From b723bf5ccd8e521977555484b909d1bc3df34900 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sat, 16 Jul 2022 16:37:36 -0400 Subject: [PATCH 07/38] Revert "Add fusePoolLensImplementation" This reverts commit 68e28830fbc286599e3d9693dc416a92eea2b4d4. --- src/strategies/rari-fuse/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 712a20288..8a78cb95f 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -7,7 +7,6 @@ export const author = 'MantisClone'; export const version = '0.1.0'; const fusePoolLens = '0x6Dc585Ad66A10214Ef0502492B0CC02F0e836eec' -const fusePoolLensImplementation = '0x6bcc070637a6eb4a13df47b906e4017530fd125d' const absMaxHealth = MaxUint256 // show all users From 8f94ff43c8bff881f14bc826ec586a97d388edea Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sat, 16 Jul 2022 17:13:27 -0400 Subject: [PATCH 08/38] Try using getAllBorrowers and getPoolAssetWithData - Hardcode return values to 1 - Comment out unused code --- src/strategies/rari-fuse/index.ts | 38 ++++++++++++++++++------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 8a78cb95f..01f482f5e 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -1,17 +1,19 @@ -import { BigNumberish } from '@ethersproject/bignumber'; -import { formatUnits } from '@ethersproject/units'; -import { MaxUint256 } from '@ethersproject/constants'; +// import { BigNumberish } from '@ethersproject/bignumber'; +// import { formatUnits } from '@ethersproject/units'; +// import { MaxUint256 } from '@ethersproject/constants'; import { Multicaller } from '../../utils'; export const author = 'MantisClone'; export const version = '0.1.0'; -const fusePoolLens = '0x6Dc585Ad66A10214Ef0502492B0CC02F0e836eec' +// const fusePoolLens = '0x6Dc585Ad66A10214Ef0502492B0CC02F0e836eec' -const absMaxHealth = MaxUint256 // show all users +// const absMaxHealth = MaxUint256 // show all users const abi = [ - 'function getPoolUsersWithData(address comptroller,uint256 maxHealth) returns (FusePoolUser[], uint256, uint256)' + // 'function getPoolUsersWithData(address comptroller,uint256 maxHealth) returns (FusePoolUser[], uint256, uint256)', + 'function getAllBorrowers() external view returns (address[] memory)', + 'function getPoolAssetsWithData(address comptroller) returns (FusePoolAsset[])' ]; export async function strategy( @@ -25,19 +27,23 @@ export async function strategy( const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; const multi = new Multicaller(network, provider, abi, { blockTag }); - addresses.forEach((voterAddress) => - multi.call('poolUsersWithData', fusePoolLens, 'getPoolUsersWithData', [options.poolAddress, absMaxHealth]) - ); - const result: Record = await multi.execute(); + multi.call('poolUsers', options.poolAddress, 'getAllBorrowers', []) + // addresses.forEach((voterAddress) => + // multi.call('poolUsersWithData', fusePoolLens, 'getPoolUsersWithData', [options.poolAddress, absMaxHealth]) + // ); + const result = await multi.execute(); - const poolUsersWithData = result.poolUsersWithData; + const poolUsers = result.poolUsers; + // const poolUsersWithData = result.poolUsersWithData; - console.log(`poolUsersWithData = ${poolUsersWithData}`); + console.log(`poolUsers = ${poolUsers}`) + // console.log(`poolUsersWithData = ${poolUsersWithData}`); return Object.fromEntries( - Object.entries(result).map(([address, balance]) => [ - address, - parseFloat(formatUnits(balance, options.decimals)) - ]) + result.users.map((u) => [u.id, 1]) + // Object.entries(result).map(([address, balance]) => [ + // address, + // parseFloat(formatUnits(balance, options.decimals)) + // ]) ); } From 28b11a9c45df97abca7eae18396190739b9c18b6 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sat, 16 Jul 2022 17:47:35 -0400 Subject: [PATCH 09/38] Try calling getPoolAssetsWithData --- src/strategies/rari-fuse/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 01f482f5e..17a033536 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -6,7 +6,7 @@ import { Multicaller } from '../../utils'; export const author = 'MantisClone'; export const version = '0.1.0'; -// const fusePoolLens = '0x6Dc585Ad66A10214Ef0502492B0CC02F0e836eec' +const fusePoolLens = '0x6Dc585Ad66A10214Ef0502492B0CC02F0e836eec' // const absMaxHealth = MaxUint256 // show all users @@ -28,9 +28,9 @@ export async function strategy( const multi = new Multicaller(network, provider, abi, { blockTag }); multi.call('poolUsers', options.poolAddress, 'getAllBorrowers', []) - // addresses.forEach((voterAddress) => - // multi.call('poolUsersWithData', fusePoolLens, 'getPoolUsersWithData', [options.poolAddress, absMaxHealth]) - // ); + addresses.forEach((voterAddress) => + multi.call('poolAssetsWithData', fusePoolLens, 'getPoolAssetsWithData', [options.poolAddress]) + ); const result = await multi.execute(); const poolUsers = result.poolUsers; From 4a00efa8c1d46d6bba56c32b44d31d0ab2ceef83 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sat, 16 Jul 2022 17:49:58 -0400 Subject: [PATCH 10/38] Both getPoolUsersWithData and getPoolAssetsWithData revert when called - Comment them out for now. --- src/strategies/rari-fuse/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 17a033536..7d293b3aa 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -12,8 +12,8 @@ const fusePoolLens = '0x6Dc585Ad66A10214Ef0502492B0CC02F0e836eec' const abi = [ // 'function getPoolUsersWithData(address comptroller,uint256 maxHealth) returns (FusePoolUser[], uint256, uint256)', + // 'function getPoolAssetsWithData(address comptroller) returns (FusePoolAsset[])' 'function getAllBorrowers() external view returns (address[] memory)', - 'function getPoolAssetsWithData(address comptroller) returns (FusePoolAsset[])' ]; export async function strategy( @@ -34,10 +34,8 @@ export async function strategy( const result = await multi.execute(); const poolUsers = result.poolUsers; - // const poolUsersWithData = result.poolUsersWithData; console.log(`poolUsers = ${poolUsers}`) - // console.log(`poolUsersWithData = ${poolUsersWithData}`); return Object.fromEntries( result.users.map((u) => [u.id, 1]) From f207e9a0c79f051de3cf20421b37711444cd4e24 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sat, 16 Jul 2022 17:50:58 -0400 Subject: [PATCH 11/38] Add cTokenAddress (the market address) to parameters list - The Rari Fuse app links to this address. I think there's one cToken for each distinct collateral type within a fuse pool. The example address given is for the BANK cToken. --- src/strategies/rari-fuse/examples.json | 1 + src/strategies/rari-fuse/schema.json | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/strategies/rari-fuse/examples.json b/src/strategies/rari-fuse/examples.json index 9ba655f2e..35428ea2b 100644 --- a/src/strategies/rari-fuse/examples.json +++ b/src/strategies/rari-fuse/examples.json @@ -7,6 +7,7 @@ "symbol": "BANK", "decimals": 18, "tokenAddress": "0x2d94AA3e47d9D5024503Ca8491fcE9A2fB4DA198", + "cTokenAddress": "0x250316B3E46600417654b13bEa68b5f64D61E609", "poolAddress": "0x3eE001bA561Af4478E5BBc510324f970aF7DBcDF" } }, diff --git a/src/strategies/rari-fuse/schema.json b/src/strategies/rari-fuse/schema.json index 252df4252..c5b2c19ee 100644 --- a/src/strategies/rari-fuse/schema.json +++ b/src/strategies/rari-fuse/schema.json @@ -25,10 +25,18 @@ "minLength": 42, "maxLength": 42 }, + "cTokenAddress": { + "type": "string", + "title": "cTokenAddress", + "examples": ["e.g. 0x250316B3E46600417654b13bEa68b5f64D61E609"], + "pattern": "^0x[a-fA-F0-9]{40}$", + "minLength": 42, + "maxLength": 42 + }, "poolAddress": { "type": "string", "title": "poolAddress", - "examples": ["e.g. 0x472D0B0DDFE0BC02C27928b8BcbD67E65D07d48a"], + "examples": ["e.g. 0x3eE001bA561Af4478E5BBc510324f970aF7DBcDF"], "pattern": "^0x[a-fA-F0-9]{40}$", "minLength": 42, "maxLength": 42 From a56b5a4b6f65c8da9074db8410baf11da6169a0a Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sat, 16 Jul 2022 17:59:17 -0400 Subject: [PATCH 12/38] Strip out code related to getPoolUsersWithData and getPoolAssetsWithData --- src/strategies/rari-fuse/index.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 7d293b3aa..2d033b059 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -1,6 +1,5 @@ // import { BigNumberish } from '@ethersproject/bignumber'; // import { formatUnits } from '@ethersproject/units'; -// import { MaxUint256 } from '@ethersproject/constants'; import { Multicaller } from '../../utils'; export const author = 'MantisClone'; @@ -8,11 +7,7 @@ export const version = '0.1.0'; const fusePoolLens = '0x6Dc585Ad66A10214Ef0502492B0CC02F0e836eec' -// const absMaxHealth = MaxUint256 // show all users - const abi = [ - // 'function getPoolUsersWithData(address comptroller,uint256 maxHealth) returns (FusePoolUser[], uint256, uint256)', - // 'function getPoolAssetsWithData(address comptroller) returns (FusePoolAsset[])' 'function getAllBorrowers() external view returns (address[] memory)', ]; From 76df2a17b1a753afd2e7500fe1175f8803aecd65 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sat, 16 Jul 2022 18:44:31 -0400 Subject: [PATCH 13/38] Try using cToken.balanceOfUnderlying(address owner) --- src/strategies/rari-fuse/index.ts | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 2d033b059..1d2cd81e8 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -1,14 +1,12 @@ -// import { BigNumberish } from '@ethersproject/bignumber'; -// import { formatUnits } from '@ethersproject/units'; +import { BigNumberish } from '@ethersproject/bignumber'; +import { formatUnits } from '@ethersproject/units'; import { Multicaller } from '../../utils'; export const author = 'MantisClone'; export const version = '0.1.0'; -const fusePoolLens = '0x6Dc585Ad66A10214Ef0502492B0CC02F0e836eec' - const abi = [ - 'function getAllBorrowers() external view returns (address[] memory)', + 'function balanceOfUnderlying(address owner) external returns (uint256);', ]; export async function strategy( @@ -22,21 +20,15 @@ export async function strategy( const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; const multi = new Multicaller(network, provider, abi, { blockTag }); - multi.call('poolUsers', options.poolAddress, 'getAllBorrowers', []) addresses.forEach((voterAddress) => - multi.call('poolAssetsWithData', fusePoolLens, 'getPoolAssetsWithData', [options.poolAddress]) + multi.call('underlyingBalance', options.cTokenAddress, 'balanceOfUnderlying', [voterAddress]) ); - const result = await multi.execute(); - - const poolUsers = result.poolUsers; - - console.log(`poolUsers = ${poolUsers}`) + const result: Record = await multi.execute(); return Object.fromEntries( - result.users.map((u) => [u.id, 1]) - // Object.entries(result).map(([address, balance]) => [ - // address, - // parseFloat(formatUnits(balance, options.decimals)) - // ]) + Object.entries(result).map(([address, balance]) => [ + address, + parseFloat(formatUnits(balance, options.decimals)) + ]) ); } From bda81be1fc8b7c2429bdd47700a1c914a82df111 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sun, 17 Jul 2022 07:30:58 -0400 Subject: [PATCH 14/38] Use balanceOf, remove unneded parameters --- src/strategies/rari-fuse/examples.json | 8 +++----- src/strategies/rari-fuse/index.ts | 8 ++++---- src/strategies/rari-fuse/schema.json | 22 +++------------------- 3 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/strategies/rari-fuse/examples.json b/src/strategies/rari-fuse/examples.json index 35428ea2b..1e09cb428 100644 --- a/src/strategies/rari-fuse/examples.json +++ b/src/strategies/rari-fuse/examples.json @@ -5,16 +5,14 @@ "name": "rari-fuse", "params": { "symbol": "BANK", - "decimals": 18, - "tokenAddress": "0x2d94AA3e47d9D5024503Ca8491fcE9A2fB4DA198", - "cTokenAddress": "0x250316B3E46600417654b13bEa68b5f64D61E609", - "poolAddress": "0x3eE001bA561Af4478E5BBc510324f970aF7DBcDF" + "underlyingTokenDecimals": 18, + "cTokenAddress": "0x250316B3E46600417654b13bEa68b5f64D61E609" } }, "network": "1", "addresses": [ "0x0cf861f96378dbd5194d74cbe6b0424fafaed940" ], - "snapshot": 14609590 + "snapshot": 14609591 } ] diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 1d2cd81e8..a11087f90 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -6,7 +6,7 @@ export const author = 'MantisClone'; export const version = '0.1.0'; const abi = [ - 'function balanceOfUnderlying(address owner) external returns (uint256);', + 'function balanceOf(address owner) external returns (uint256)' ]; export async function strategy( @@ -20,15 +20,15 @@ export async function strategy( const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; const multi = new Multicaller(network, provider, abi, { blockTag }); - addresses.forEach((voterAddress) => - multi.call('underlyingBalance', options.cTokenAddress, 'balanceOfUnderlying', [voterAddress]) + addresses.forEach((address) => + multi.call(address, options.cTokenAddress, 'balanceOf', [address]) ); const result: Record = await multi.execute(); return Object.fromEntries( Object.entries(result).map(([address, balance]) => [ address, - parseFloat(formatUnits(balance, options.decimals)) + parseFloat(formatUnits(balance, options.underlyingTokenDecimals)) ]) ); } diff --git a/src/strategies/rari-fuse/schema.json b/src/strategies/rari-fuse/schema.json index c5b2c19ee..d3d8f0f39 100644 --- a/src/strategies/rari-fuse/schema.json +++ b/src/strategies/rari-fuse/schema.json @@ -12,19 +12,11 @@ "examples": ["e.g. BANK"], "maxLength": 16 }, - "decimals": { + "underlyingTokenDecimals": { "type": "number", - "title": "decimals", + "title": "underlyingTokenDecimals", "examples": ["e.g. 18"] }, - "tokenAddress": { - "type": "string", - "title": "tokenAddress", - "examples": ["e.g. 0x2d94AA3e47d9D5024503Ca8491fcE9A2fB4DA198"], - "pattern": "^0x[a-fA-F0-9]{40}$", - "minLength": 42, - "maxLength": 42 - }, "cTokenAddress": { "type": "string", "title": "cTokenAddress", @@ -32,17 +24,9 @@ "pattern": "^0x[a-fA-F0-9]{40}$", "minLength": 42, "maxLength": 42 - }, - "poolAddress": { - "type": "string", - "title": "poolAddress", - "examples": ["e.g. 0x3eE001bA561Af4478E5BBc510324f970aF7DBcDF"], - "pattern": "^0x[a-fA-F0-9]{40}$", - "minLength": 42, - "maxLength": 42 } }, - "required": ["decimals", "tokenAddress", "poolAddress"], + "required": ["decimals", "cTokenAddress"], "additionalProperties": false } } From d77c9886f4f6558bb12ad62608028ece2221a8b8 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sun, 17 Jul 2022 07:33:26 -0400 Subject: [PATCH 15/38] yarn lint --- src/strategies/rari-fuse/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index a11087f90..3d241f603 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -5,9 +5,7 @@ import { Multicaller } from '../../utils'; export const author = 'MantisClone'; export const version = '0.1.0'; -const abi = [ - 'function balanceOf(address owner) external returns (uint256)' -]; +const abi = ['function balanceOf(address owner) external returns (uint256)']; export async function strategy( space, From cd5fd1caf84dff4ee02aec8d88ae33917ce64878 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sun, 17 Jul 2022 07:38:57 -0400 Subject: [PATCH 16/38] Update README --- src/strategies/rari-fuse/README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/strategies/rari-fuse/README.md b/src/strategies/rari-fuse/README.md index e0af42a1b..2e669f23a 100644 --- a/src/strategies/rari-fuse/README.md +++ b/src/strategies/rari-fuse/README.md @@ -1,13 +1,17 @@ -# erc20-balance-of +# rari-fuse -This is the most common strategy, it returns the balances of the voters for a specific ERC20 token. +Returns the balances of the voters for a given cToken (market) in Rari Fuse. Here is an example of parameters: +- `symbol` - (**Optional**, `string`) Symbol of the underlying ERC20 token +- `decimals` - (**Required**, `number`) Decimal precision of the underlying ERC20 token +- `cTokenAddress` - (**Required**, `string`) Address of the cToken (aka. market) in Rari Fuse + ```json { - "address": "0x6b175474e89094c44da98b954eedeac495271d0f", - "symbol": "DAI", - "decimals": 18 + "symbol": "BANK", + "decimals": 18, + "cTokenAddress": "0x250316B3E46600417654b13bEa68b5f64D61E609" } ``` From e6a92969fa53d7ba25803122821d44283ff82e06 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sun, 17 Jul 2022 08:00:04 -0400 Subject: [PATCH 17/38] Update README for readability --- src/strategies/rari-fuse/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/strategies/rari-fuse/README.md b/src/strategies/rari-fuse/README.md index 2e669f23a..653df126b 100644 --- a/src/strategies/rari-fuse/README.md +++ b/src/strategies/rari-fuse/README.md @@ -1,6 +1,6 @@ # rari-fuse -Returns the balances of the voters for a given cToken (market) in Rari Fuse. +Returns the voter's underlying collateral balances for a given Rari Fuse market (cToken). Here is an example of parameters: From 2bef30135e2990933ce5a73c3b90697cf3f94588 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sun, 17 Jul 2022 08:01:00 -0400 Subject: [PATCH 18/38] Rename underlyingTokenDecimals back to decimals --- src/strategies/rari-fuse/examples.json | 2 +- src/strategies/rari-fuse/index.ts | 2 +- src/strategies/rari-fuse/schema.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/strategies/rari-fuse/examples.json b/src/strategies/rari-fuse/examples.json index 1e09cb428..538758d15 100644 --- a/src/strategies/rari-fuse/examples.json +++ b/src/strategies/rari-fuse/examples.json @@ -5,7 +5,7 @@ "name": "rari-fuse", "params": { "symbol": "BANK", - "underlyingTokenDecimals": 18, + "decimals": 18, "cTokenAddress": "0x250316B3E46600417654b13bEa68b5f64D61E609" } }, diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 3d241f603..1fc63df02 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -26,7 +26,7 @@ export async function strategy( return Object.fromEntries( Object.entries(result).map(([address, balance]) => [ address, - parseFloat(formatUnits(balance, options.underlyingTokenDecimals)) + parseFloat(formatUnits(balance, options.decimals)) ]) ); } diff --git a/src/strategies/rari-fuse/schema.json b/src/strategies/rari-fuse/schema.json index d3d8f0f39..010764839 100644 --- a/src/strategies/rari-fuse/schema.json +++ b/src/strategies/rari-fuse/schema.json @@ -12,9 +12,9 @@ "examples": ["e.g. BANK"], "maxLength": 16 }, - "underlyingTokenDecimals": { + "decimals": { "type": "number", - "title": "underlyingTokenDecimals", + "title": "decimals", "examples": ["e.g. 18"] }, "cTokenAddress": { From 9a20c06b56d3890d294ed107058e9003de6533bf Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sun, 17 Jul 2022 08:06:03 -0400 Subject: [PATCH 19/38] Add more addresses to the examples.json --- src/strategies/rari-fuse/examples.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/strategies/rari-fuse/examples.json b/src/strategies/rari-fuse/examples.json index 538758d15..3d7dbcc75 100644 --- a/src/strategies/rari-fuse/examples.json +++ b/src/strategies/rari-fuse/examples.json @@ -11,7 +11,10 @@ }, "network": "1", "addresses": [ - "0x0cf861f96378dbd5194d74cbe6b0424fafaed940" + "0x0cf861f96378dbd5194d74cbe6b0424fafaed940", + "0x0f1d41cc51e97dc9d0cad80dc681777eed3675e3", + "0xb6ac0341fcf3fb507a8208d34a97f13779e1393d", + "0x173ff4db38c3fcde0584f8ea7930c44969a29ba4" ], "snapshot": 14609591 } From 656a891b976c6b169b7e98d759492b75ca267111 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Sun, 17 Jul 2022 08:08:25 -0400 Subject: [PATCH 20/38] Update README for readability --- src/strategies/rari-fuse/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/strategies/rari-fuse/README.md b/src/strategies/rari-fuse/README.md index 653df126b..357d17bd3 100644 --- a/src/strategies/rari-fuse/README.md +++ b/src/strategies/rari-fuse/README.md @@ -1,6 +1,6 @@ # rari-fuse -Returns the voter's underlying collateral balances for a given Rari Fuse market (cToken). +Returns the voter's underlying collateral balances in a given Rari Fuse market (cToken). Here is an example of parameters: From f79afb69a1682037d54702efdd6ddac5b4dc4c18 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 17:11:11 -0400 Subject: [PATCH 21/38] Rename cToken to fToken --- src/strategies/rari-fuse/README.md | 6 +++--- src/strategies/rari-fuse/examples.json | 2 +- src/strategies/rari-fuse/index.ts | 2 +- src/strategies/rari-fuse/schema.json | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/strategies/rari-fuse/README.md b/src/strategies/rari-fuse/README.md index 357d17bd3..64f58f6bb 100644 --- a/src/strategies/rari-fuse/README.md +++ b/src/strategies/rari-fuse/README.md @@ -1,17 +1,17 @@ # rari-fuse -Returns the voter's underlying collateral balances in a given Rari Fuse market (cToken). +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 - `decimals` - (**Required**, `number`) Decimal precision of the underlying ERC20 token -- `cTokenAddress` - (**Required**, `string`) Address of the cToken (aka. market) in Rari Fuse +- `fTokenAddress` - (**Required**, `string`) Address of the fToken (aka. market) in Rari Fuse ```json { "symbol": "BANK", "decimals": 18, - "cTokenAddress": "0x250316B3E46600417654b13bEa68b5f64D61E609" + "fTokenAddress": "0x250316B3E46600417654b13bEa68b5f64D61E609" } ``` diff --git a/src/strategies/rari-fuse/examples.json b/src/strategies/rari-fuse/examples.json index 3d7dbcc75..b8179757c 100644 --- a/src/strategies/rari-fuse/examples.json +++ b/src/strategies/rari-fuse/examples.json @@ -6,7 +6,7 @@ "params": { "symbol": "BANK", "decimals": 18, - "cTokenAddress": "0x250316B3E46600417654b13bEa68b5f64D61E609" + "fTokenAddress": "0x250316B3E46600417654b13bEa68b5f64D61E609" } }, "network": "1", diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 1fc63df02..4e71249fe 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -19,7 +19,7 @@ export async function strategy( const multi = new Multicaller(network, provider, abi, { blockTag }); addresses.forEach((address) => - multi.call(address, options.cTokenAddress, 'balanceOf', [address]) + multi.call(address, options.fTokenAddress, 'balanceOf', [address]) ); const result: Record = await multi.execute(); diff --git a/src/strategies/rari-fuse/schema.json b/src/strategies/rari-fuse/schema.json index 010764839..514db8f80 100644 --- a/src/strategies/rari-fuse/schema.json +++ b/src/strategies/rari-fuse/schema.json @@ -17,16 +17,16 @@ "title": "decimals", "examples": ["e.g. 18"] }, - "cTokenAddress": { + "fTokenAddress": { "type": "string", - "title": "cTokenAddress", + "title": "fTokenAddress", "examples": ["e.g. 0x250316B3E46600417654b13bEa68b5f64D61E609"], "pattern": "^0x[a-fA-F0-9]{40}$", "minLength": 42, "maxLength": 42 } }, - "required": ["decimals", "cTokenAddress"], + "required": ["decimals", "fTokenAddress"], "additionalProperties": false } } From 0d51dc0b0b2f0ef41a9e819c899b8eb6bc08a419 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 18:23:32 -0400 Subject: [PATCH 22/38] Change parameters to `token` and `fToken` --- src/strategies/rari-fuse/README.md | 13 +++++++++---- src/strategies/rari-fuse/schema.json | 17 ++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/strategies/rari-fuse/README.md b/src/strategies/rari-fuse/README.md index 64f58f6bb..5e5a70b1c 100644 --- a/src/strategies/rari-fuse/README.md +++ b/src/strategies/rari-fuse/README.md @@ -5,13 +5,18 @@ Returns the voter's underlying collateral balances in a given Rari Fuse market ( Here is an example of parameters: - `symbol` - (**Optional**, `string`) Symbol of the underlying ERC20 token -- `decimals` - (**Required**, `number`) Decimal precision of the underlying ERC20 token -- `fTokenAddress` - (**Required**, `string`) Address of the fToken (aka. market) in Rari Fuse +- `token` - (**Required**, `string`) Address of the underlying token. +- `fToken` - (**Required**, `string`) Address of the fToken (Rari Fuse market) ```json { "symbol": "BANK", - "decimals": 18, - "fTokenAddress": "0x250316B3E46600417654b13bEa68b5f64D61E609" + "token": "0x2d94AA3e47d9D5024503Ca8491fcE9A2fB4DA198", + "fToken": "0x250316B3E46600417654b13bEa68b5f64D61E609" } ``` + +## Reference + +For details about exchange rate between fTokens and underlying tokens, see +https://docs.rari.capital/fuse/#interpreting-exchange-rates diff --git a/src/strategies/rari-fuse/schema.json b/src/strategies/rari-fuse/schema.json index 514db8f80..7cd89447c 100644 --- a/src/strategies/rari-fuse/schema.json +++ b/src/strategies/rari-fuse/schema.json @@ -12,21 +12,24 @@ "examples": ["e.g. BANK"], "maxLength": 16 }, - "decimals": { - "type": "number", - "title": "decimals", - "examples": ["e.g. 18"] + "token": { + "type": "string", + "title": "token", + "examples": ["e.g. 0x250316B3E46600417654b13bEa68b5f64D61E609"], + "pattern": "^0x[a-fA-F0-9]{40}$", + "minLength": 42, + "maxLength": 42 }, - "fTokenAddress": { + "fToken": { "type": "string", - "title": "fTokenAddress", + "title": "fToken", "examples": ["e.g. 0x250316B3E46600417654b13bEa68b5f64D61E609"], "pattern": "^0x[a-fA-F0-9]{40}$", "minLength": 42, "maxLength": 42 } }, - "required": ["decimals", "fTokenAddress"], + "required": ["token", "fToken"], "additionalProperties": false } } From 21130df97c07dffe37126043211a02340fa8d0f8 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 18:24:11 -0400 Subject: [PATCH 23/38] Add functions for calculating underlying token balance, console logging --- src/strategies/rari-fuse/index.ts | 38 ++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 4e71249fe..97d660cff 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -1,11 +1,17 @@ -import { BigNumberish } from '@ethersproject/bignumber'; -import { formatUnits } from '@ethersproject/units'; +import { BigNumber } from '@ethersproject/bignumber'; +// import { BigNumber, BigNumberish } 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 balanceOf(address owner) external returns (uint256)']; +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, @@ -18,15 +24,35 @@ export async function strategy( 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.fTokenAddress, 'exchangeRateStored', []); addresses.forEach((address) => - multi.call(address, options.fTokenAddress, 'balanceOf', [address]) + multi.call(`fTokenBalances.${address}`, options.fTokenAddress, 'balanceOf', [address]) ); - const result: Record = await multi.execute(); + 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 = result.fTokenBalances; + + console.log(`underlying = ${underlying}`); + console.log(`tokenDecimals = ${tokenDecimals}`); + console.log(`fTokenDecimals = ${fTokenDecimals}`); + console.log(`exchangeRate = ${exchangeRate}`); + console.log(`fTokenBalances = ${fTokenBalances}`); return Object.fromEntries( Object.entries(result).map(([address, balance]) => [ address, - parseFloat(formatUnits(balance, options.decimals)) + 1 ]) + // Object.entries(result).map(([address, balance]) => [ + // address, + // parseFloat(formatUnits(balance, options.decimals)) + // ]) ); } From 6ef90994fda299e0a97211c379c3eb1a0676dc08 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 18:28:28 -0400 Subject: [PATCH 24/38] Update schema example --- src/strategies/rari-fuse/schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/strategies/rari-fuse/schema.json b/src/strategies/rari-fuse/schema.json index 7cd89447c..71e3fecc6 100644 --- a/src/strategies/rari-fuse/schema.json +++ b/src/strategies/rari-fuse/schema.json @@ -15,7 +15,7 @@ "token": { "type": "string", "title": "token", - "examples": ["e.g. 0x250316B3E46600417654b13bEa68b5f64D61E609"], + "examples": ["e.g. 0x2d94AA3e47d9D5024503Ca8491fcE9A2fB4DA198"], "pattern": "^0x[a-fA-F0-9]{40}$", "minLength": 42, "maxLength": 42 From 19d9c4a4802d593b135ffa65f10b86e9d713efd4 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 18:28:59 -0400 Subject: [PATCH 25/38] Remove unncessary comma --- src/strategies/rari-fuse/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 97d660cff..8938d5429 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -10,7 +10,7 @@ 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)', + 'function balanceOf(address owner) external returns (uint256)' ]; export async function strategy( From 4d3e18830dd10f6033927a7ee0047643dbdd5be5 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 18:39:45 -0400 Subject: [PATCH 26/38] More changes to examples.json --- src/strategies/rari-fuse/examples.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/strategies/rari-fuse/examples.json b/src/strategies/rari-fuse/examples.json index b8179757c..02f1412dd 100644 --- a/src/strategies/rari-fuse/examples.json +++ b/src/strategies/rari-fuse/examples.json @@ -5,17 +5,18 @@ "name": "rari-fuse", "params": { "symbol": "BANK", - "decimals": 18, - "fTokenAddress": "0x250316B3E46600417654b13bEa68b5f64D61E609" + "token": "0x2d94AA3e47d9D5024503Ca8491fcE9A2fB4DA198", + "fToken": "0x250316B3E46600417654b13bEa68b5f64D61E609" } }, "network": "1", "addresses": [ + "0x3839acf1ee7699d1f46b1be840d8ad8317fdf757", "0x0cf861f96378dbd5194d74cbe6b0424fafaed940", "0x0f1d41cc51e97dc9d0cad80dc681777eed3675e3", "0xb6ac0341fcf3fb507a8208d34a97f13779e1393d", "0x173ff4db38c3fcde0584f8ea7930c44969a29ba4" ], - "snapshot": 14609591 + "snapshot": 14482171 } ] From a7f5f69b68973852e2fe6bc8cac56e48c182819d Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 18:40:05 -0400 Subject: [PATCH 27/38] Attempt to fix errors --- src/strategies/rari-fuse/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 8938d5429..ca30b40c1 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -46,7 +46,7 @@ export async function strategy( console.log(`fTokenBalances = ${fTokenBalances}`); return Object.fromEntries( - Object.entries(result).map(([address, balance]) => [ + Object.entries(fTokenBalances).map(([address, balance]) => [ address, 1 ]) From cfc7f18b9c870b0d484b34eae3687d7771f58114 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 18:53:23 -0400 Subject: [PATCH 28/38] Trying to fix --- src/strategies/rari-fuse/index.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index ca30b40c1..1e641e004 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -1,6 +1,5 @@ -import { BigNumber } from '@ethersproject/bignumber'; -// import { BigNumber, BigNumberish } from '@ethersproject/bignumber'; -// import { formatUnits } from '@ethersproject/units'; +import { BigNumber, BigNumberish } from '@ethersproject/bignumber'; +import { formatUnits } from '@ethersproject/units'; import { Multicaller } from '../../utils'; export const author = 'MantisClone'; @@ -37,7 +36,7 @@ export async function strategy( const tokenDecimals: BigNumber = result.tokenDecimals; const fTokenDecimals: BigNumber = result.fTokenDecimals; const exchangeRate: BigNumber = result.exchangeRate; - const fTokenBalances: Record = result.fTokenBalances; + const fTokenBalances: Record = result.fTokenBalances; console.log(`underlying = ${underlying}`); console.log(`tokenDecimals = ${tokenDecimals}`); @@ -48,11 +47,7 @@ export async function strategy( return Object.fromEntries( Object.entries(fTokenBalances).map(([address, balance]) => [ address, - 1 + parseFloat(formatUnits(balance, fTokenDecimals)) ]) - // Object.entries(result).map(([address, balance]) => [ - // address, - // parseFloat(formatUnits(balance, options.decimals)) - // ]) ); } From 3b0b7da6567d137af82335fcfb9fd036ca58c720 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 18:56:00 -0400 Subject: [PATCH 29/38] Update examples to use checksummed addresses --- src/strategies/rari-fuse/examples.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/strategies/rari-fuse/examples.json b/src/strategies/rari-fuse/examples.json index 02f1412dd..d0c4831e4 100644 --- a/src/strategies/rari-fuse/examples.json +++ b/src/strategies/rari-fuse/examples.json @@ -11,11 +11,7 @@ }, "network": "1", "addresses": [ - "0x3839acf1ee7699d1f46b1be840d8ad8317fdf757", - "0x0cf861f96378dbd5194d74cbe6b0424fafaed940", - "0x0f1d41cc51e97dc9d0cad80dc681777eed3675e3", - "0xb6ac0341fcf3fb507a8208d34a97f13779e1393d", - "0x173ff4db38c3fcde0584f8ea7930c44969a29ba4" + "0x3839AcF1ee7699D1F46b1BE840D8aD8317FDf757" ], "snapshot": 14482171 } From eac9dea123a9ec539850e240f1e6995bc41d58c1 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 19:00:31 -0400 Subject: [PATCH 30/38] Fixed! Now I can see the console logs. --- src/strategies/rari-fuse/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 1e641e004..529d6a7cb 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -26,9 +26,9 @@ export async function strategy( multi.call('underlying', options.fToken, 'underlying', []); multi.call('tokenDecimals', options.token, 'decimals', []); multi.call('fTokenDecimals', options.fToken, 'decimals', []); - multi.call('exchangeRate', options.fTokenAddress, 'exchangeRateStored', []); + multi.call('exchangeRate', options.fToken, 'exchangeRateStored', []); addresses.forEach((address) => - multi.call(`fTokenBalances.${address}`, options.fTokenAddress, 'balanceOf', [address]) + multi.call(`fTokenBalances.${address}`, options.fToken, 'balanceOf', [address]) ); const result = await multi.execute(); From 73c949fb2bc58f578e52b196e47e077f5a228a22 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 19:00:55 -0400 Subject: [PATCH 31/38] Add error if token param != fToken.underlying() --- src/strategies/rari-fuse/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 529d6a7cb..685c9e120 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -44,6 +44,12 @@ export async function strategy( console.log(`exchangeRate = ${exchangeRate}`); console.log(`fTokenBalances = ${fTokenBalances}`); + if (options.token !== underlying) { + throw new Error( + `token parameter doesn't match fToken.underlying(). token=${options.token}, underlying=${underlying}` + ); + } + return Object.fromEntries( Object.entries(fTokenBalances).map(([address, balance]) => [ address, From 1c07f37fd9f92ff5ec1b031dc829cf1eaa5e0524 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 19:37:58 -0400 Subject: [PATCH 32/38] Add code from Rari Docs --- src/strategies/rari-fuse/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 685c9e120..83bd95949 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -42,7 +42,6 @@ export async function strategy( console.log(`tokenDecimals = ${tokenDecimals}`); console.log(`fTokenDecimals = ${fTokenDecimals}`); console.log(`exchangeRate = ${exchangeRate}`); - console.log(`fTokenBalances = ${fTokenBalances}`); if (options.token !== underlying) { throw new Error( @@ -50,6 +49,9 @@ export async function strategy( ); } + const mantissa = BigNumber.from(18).add(tokenDecimals.sub(fTokenDecimals)); + const onefTokenInUnderlying = exchangeRate.div(BigNumber.from(10).pow(mantissa)); + return Object.fromEntries( Object.entries(fTokenBalances).map(([address, balance]) => [ address, From d6d64f4634d7b77cf408f2c2726c725939f6de2a Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 20:03:45 -0400 Subject: [PATCH 33/38] Finish implementing index.js --- src/strategies/rari-fuse/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 83bd95949..9def4b0a1 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -1,4 +1,4 @@ -import { BigNumber, BigNumberish } from '@ethersproject/bignumber'; +import { BigNumber } from '@ethersproject/bignumber'; import { formatUnits } from '@ethersproject/units'; import { Multicaller } from '../../utils'; @@ -36,7 +36,7 @@ export async function strategy( const tokenDecimals: BigNumber = result.tokenDecimals; const fTokenDecimals: BigNumber = result.fTokenDecimals; const exchangeRate: BigNumber = result.exchangeRate; - const fTokenBalances: Record = result.fTokenBalances; + const fTokenBalances: Record = result.fTokenBalances; console.log(`underlying = ${underlying}`); console.log(`tokenDecimals = ${tokenDecimals}`); @@ -49,13 +49,13 @@ export async function strategy( ); } - const mantissa = BigNumber.from(18).add(tokenDecimals.sub(fTokenDecimals)); - const onefTokenInUnderlying = exchangeRate.div(BigNumber.from(10).pow(mantissa)); + const mantissa: BigNumber = BigNumber.from(18).add(tokenDecimals).sub(fTokenDecimals); + const onefTokenInUnderlying: BigNumber = exchangeRate.div(BigNumber.from(10).pow(mantissa)); return Object.fromEntries( Object.entries(fTokenBalances).map(([address, balance]) => [ address, - parseFloat(formatUnits(balance, fTokenDecimals)) + parseFloat(formatUnits(balance.mul(onefTokenInUnderlying), fTokenDecimals)) ]) ); } From d7bebe6b51765ee5d38d0abbf3f90b38d30fdc75 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 20:05:51 -0400 Subject: [PATCH 34/38] It's not working. Add console logging --- src/strategies/rari-fuse/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 9def4b0a1..bc456f063 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -52,6 +52,9 @@ export async function strategy( const mantissa: BigNumber = BigNumber.from(18).add(tokenDecimals).sub(fTokenDecimals); const onefTokenInUnderlying: BigNumber = exchangeRate.div(BigNumber.from(10).pow(mantissa)); + console.log(`mantissa = ${mantissa}`) + console.log(`onefTokenInUnderlying = ${onefTokenInUnderlying}`) + return Object.fromEntries( Object.entries(fTokenBalances).map(([address, balance]) => [ address, From e1a65ef84ef6af6b76bc3d9188622ade9808f15a Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 20:14:26 -0400 Subject: [PATCH 35/38] Adjust logic so div is last operation --- src/strategies/rari-fuse/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index bc456f063..dcc7d6949 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -50,15 +50,15 @@ export async function strategy( } const mantissa: BigNumber = BigNumber.from(18).add(tokenDecimals).sub(fTokenDecimals); - const onefTokenInUnderlying: BigNumber = exchangeRate.div(BigNumber.from(10).pow(mantissa)); + const base: BigNumber = BigNumber.from(10).pow(mantissa); console.log(`mantissa = ${mantissa}`) - console.log(`onefTokenInUnderlying = ${onefTokenInUnderlying}`) + console.log(`base = ${base}`) return Object.fromEntries( Object.entries(fTokenBalances).map(([address, balance]) => [ address, - parseFloat(formatUnits(balance.mul(onefTokenInUnderlying), fTokenDecimals)) + parseFloat(formatUnits(balance.mul(exchangeRate).div(base), fTokenDecimals)) ]) ); } From 3562501c985874d225c8d727fd2a5ec90cbf1ed5 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 20:20:42 -0400 Subject: [PATCH 36/38] Rename base to divisor --- src/strategies/rari-fuse/index.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index dcc7d6949..801fb9b9e 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -28,7 +28,9 @@ export async function strategy( multi.call('fTokenDecimals', options.fToken, 'decimals', []); multi.call('exchangeRate', options.fToken, 'exchangeRateStored', []); addresses.forEach((address) => - multi.call(`fTokenBalances.${address}`, options.fToken, 'balanceOf', [address]) + multi.call(`fTokenBalances.${address}`, options.fToken, 'balanceOf', [ + address + ]) ); const result = await multi.execute(); @@ -49,16 +51,20 @@ export async function strategy( ); } - const mantissa: BigNumber = BigNumber.from(18).add(tokenDecimals).sub(fTokenDecimals); - const base: BigNumber = BigNumber.from(10).pow(mantissa); + const mantissa: BigNumber = BigNumber.from(18) + .add(tokenDecimals) + .sub(fTokenDecimals); + const divisor: BigNumber = BigNumber.from(10).pow(mantissa); - console.log(`mantissa = ${mantissa}`) - console.log(`base = ${base}`) + console.log(`mantissa = ${mantissa}`); + console.log(`divisor = ${divisor}`); return Object.fromEntries( Object.entries(fTokenBalances).map(([address, balance]) => [ address, - parseFloat(formatUnits(balance.mul(exchangeRate).div(base), fTokenDecimals)) + parseFloat( + formatUnits(balance.mul(exchangeRate).div(divisor), fTokenDecimals) + ) ]) ); } From e3ff1f799325727d40102f42e53daf2b6dd541f9 Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 20:21:38 -0400 Subject: [PATCH 37/38] Remove console logging --- src/strategies/rari-fuse/index.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/strategies/rari-fuse/index.ts b/src/strategies/rari-fuse/index.ts index 801fb9b9e..8979152e9 100644 --- a/src/strategies/rari-fuse/index.ts +++ b/src/strategies/rari-fuse/index.ts @@ -40,11 +40,6 @@ export async function strategy( const exchangeRate: BigNumber = result.exchangeRate; const fTokenBalances: Record = result.fTokenBalances; - console.log(`underlying = ${underlying}`); - console.log(`tokenDecimals = ${tokenDecimals}`); - console.log(`fTokenDecimals = ${fTokenDecimals}`); - console.log(`exchangeRate = ${exchangeRate}`); - if (options.token !== underlying) { throw new Error( `token parameter doesn't match fToken.underlying(). token=${options.token}, underlying=${underlying}` @@ -56,9 +51,6 @@ export async function strategy( .sub(fTokenDecimals); const divisor: BigNumber = BigNumber.from(10).pow(mantissa); - console.log(`mantissa = ${mantissa}`); - console.log(`divisor = ${divisor}`); - return Object.fromEntries( Object.entries(fTokenBalances).map(([address, balance]) => [ address, From 9e48cb8e341aa74f1eb577b15dc6e28f2a3342ec Mon Sep 17 00:00:00 2001 From: MantisClone Date: Mon, 18 Jul 2022 20:24:37 -0400 Subject: [PATCH 38/38] Add additional addresses to examples.json --- src/strategies/rari-fuse/examples.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/strategies/rari-fuse/examples.json b/src/strategies/rari-fuse/examples.json index d0c4831e4..a733c48b6 100644 --- a/src/strategies/rari-fuse/examples.json +++ b/src/strategies/rari-fuse/examples.json @@ -11,7 +11,11 @@ }, "network": "1", "addresses": [ - "0x3839AcF1ee7699D1F46b1BE840D8aD8317FDf757" + "0x3839AcF1ee7699D1F46b1BE840D8aD8317FDf757", + "0x0cf861f96378dbd5194d74cbe6b0424fafaed940", + "0x0f1d41cc51e97dc9d0cad80dc681777eed3675e3", + "0xb6ac0341fcf3fb507a8208d34a97f13779e1393d", + "0x173ff4db38c3fcde0584f8ea7930c44969a29ba4" ], "snapshot": 14482171 }