From a0cd04421b2a22c4c7de22e7403e56debaecb2a9 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 7 Mar 2024 15:38:33 +0800 Subject: [PATCH 1/4] feat: monroeprotocol --- projects/monroeprotocol/index.js | 67 ++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 projects/monroeprotocol/index.js diff --git a/projects/monroeprotocol/index.js b/projects/monroeprotocol/index.js new file mode 100644 index 000000000000..972b1b81b5ef --- /dev/null +++ b/projects/monroeprotocol/index.js @@ -0,0 +1,67 @@ +const ADDRESSES = require('../helper/coreAssets.json') +const { sumTokensExport } = require("../helper/unwrapLPs"); +const { getLogs } = require('../helper/cache/getLogs') + +// Controllers[chain] +const CONTROLLERS = { + manta: "0xCc396B83Baba70c85FBB8f44B64e7e43aE810232", +} + + +async function tvl(_, _1, _2, { api }) { + const logs = await getLogs({ + api, + target: CONTROLLERS[api.chain], + eventAbi: "event CreatedSynth(address newSynth, string name, address oracle)", + onlyArgs: true, + fromBlock: 1548740 + }); + const synthAddresses = logs.map(log => log.newSynth); + + const vaultLength = await api.call({ + abi: "uint:getVaultsLength", + target: CONTROLLERS[api.chain] + }) + + let tokens = await Promise.all(synthAddresses.map( async (synth) => { + let mintVaults = await Promise.all([...new Array(vaultLength)].map(async(_, vaultIndex) => {return await + api.call({ + abi: "function mintVaults(uint vaultId) view returns (address)", + target: synth, + params: vaultIndex + }) + })) + let collateralAmounts = await Promise.all( + mintVaults.map(async vaultAddress => { + let collateralAddress = await api.call({ + abi: "function collateralAsset() view returns (address)", + target: vaultAddress + }) + let amount = await api.call({ + abi: "function balanceOf(address user) view returns (uint)", + target: collateralAddress, + params: vaultAddress + }) + return [collateralAddress, amount] + }) + ) + return collateralAmounts + })) + for (let synthCollateralAmounts of tokens){ + for(let collateralAmounts of synthCollateralAmounts){ + api.add(collateralAmounts[0], collateralAmounts[1]) + } + } +} + + + +module.exports = { + methodology: + "Adds up the total value locked as collateral in Monroe vaults", + start: 1709510400, // Monday, March 4, 2024 00:00 GMT +}; + +Object.keys(CONTROLLERS).forEach((chain) => { + module.exports[chain] = { tvl }; +}); From 511fe1066d2b9167d7a3624c74425856b246126c Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sat, 16 Mar 2024 10:45:48 +0800 Subject: [PATCH 2/4] feat: Monroe prod --- projects/monroeprotocol/index.js | 60 ++++++++++---------------------- 1 file changed, 19 insertions(+), 41 deletions(-) diff --git a/projects/monroeprotocol/index.js b/projects/monroeprotocol/index.js index 972b1b81b5ef..f2dede29892f 100644 --- a/projects/monroeprotocol/index.js +++ b/projects/monroeprotocol/index.js @@ -1,57 +1,35 @@ -const ADDRESSES = require('../helper/coreAssets.json') -const { sumTokensExport } = require("../helper/unwrapLPs"); +const { createIncrementArray } = require("../helper/utils"); const { getLogs } = require('../helper/cache/getLogs') // Controllers[chain] const CONTROLLERS = { - manta: "0xCc396B83Baba70c85FBB8f44B64e7e43aE810232", + manta: "0xb2E609ef662889a32452598F0131863035974878", } async function tvl(_, _1, _2, { api }) { - const logs = await getLogs({ - api, - target: CONTROLLERS[api.chain], + const logs = await getLogs({ + api, + target: CONTROLLERS[api.chain], eventAbi: "event CreatedSynth(address newSynth, string name, address oracle)", onlyArgs: true, fromBlock: 1548740 }); const synthAddresses = logs.map(log => log.newSynth); - - const vaultLength = await api.call({ - abi: "uint:getVaultsLength", - target: CONTROLLERS[api.chain] - }) - let tokens = await Promise.all(synthAddresses.map( async (synth) => { - let mintVaults = await Promise.all([...new Array(vaultLength)].map(async(_, vaultIndex) => {return await - api.call({ - abi: "function mintVaults(uint vaultId) view returns (address)", - target: synth, - params: vaultIndex - }) - })) - let collateralAmounts = await Promise.all( - mintVaults.map(async vaultAddress => { - let collateralAddress = await api.call({ - abi: "function collateralAsset() view returns (address)", - target: vaultAddress - }) - let amount = await api.call({ - abi: "function balanceOf(address user) view returns (uint)", - target: collateralAddress, - params: vaultAddress - }) - return [collateralAddress, amount] - }) - ) - return collateralAmounts + const vaultLength = await api.call({ abi: "uint:getVaultsLength", target: CONTROLLERS[api.chain] }) + const vaultCalls = createIncrementArray(vaultLength) + + const owners = [] + const tokens = [] + await Promise.all(synthAddresses.map(async (synth) => { + const vaults = await api.multiCall({ abi: "function mintVaults(uint vaultId) view returns (address)", calls: vaultCalls, target: synth}) + const _tokens = await api.multiCall({ abi: 'address:collateralAsset', calls: vaults}) + tokens.push(..._tokens) + owners.push(...vaults) })) - for (let synthCollateralAmounts of tokens){ - for(let collateralAmounts of synthCollateralAmounts){ - api.add(collateralAmounts[0], collateralAmounts[1]) - } - } + + return api.sumTokens({ tokensAndOwners2: [tokens, owners]}) } @@ -59,9 +37,9 @@ async function tvl(_, _1, _2, { api }) { module.exports = { methodology: "Adds up the total value locked as collateral in Monroe vaults", - start: 1709510400, // Monday, March 4, 2024 00:00 GMT + start: 1710288000, // Monday, March 4, 2024 00:00 GMT }; Object.keys(CONTROLLERS).forEach((chain) => { module.exports[chain] = { tvl }; -}); +}); \ No newline at end of file From 1a45ab7a5a2c6ebe77e2d7afed363c615b8bbd9f Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 26 Apr 2024 11:56:30 +0800 Subject: [PATCH 3/4] MonroeProtocol: new chains deployments --- projects/monroeprotocol/index.js | 42 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/projects/monroeprotocol/index.js b/projects/monroeprotocol/index.js index c8db34e5d7fb..ae9ce664015e 100644 --- a/projects/monroeprotocol/index.js +++ b/projects/monroeprotocol/index.js @@ -1,33 +1,33 @@ const { createIncrementArray } = require("../helper/utils"); const { getLogs } = require('../helper/cache/getLogs') -// Controllers[chain] -const CONTROLLERS = { - manta: "0xb2E609ef662889a32452598F0131863035974878", -} +const CHAINS = ["ethereum", "manta", "avax", "iotex"] +// Where possible contracts are deployed using deterministic addresses +const DEFAULT_ADDRESSES = { + controller: "0xb2E609ef662889a32452598F0131863035974878", + monusd: "0xDf3d57c3480951958Cef19905E4cf7FC1bA9ad42" +} +const SPECIAL_ADDRESSES = { + zklink: { + controller: "0xD620b0613568406F427a6f5d4ecA301870a1A3d5", + monusd: "0x051baaA86328Fc7F522431932B8010F66f260A6a" + } +} async function tvl(api) { - const logs = await getLogs({ - api, - target: CONTROLLERS[api.chain], - eventAbi: "event CreatedSynth(address newSynth, string name, address oracle)", - onlyArgs: true, - fromBlock: 1548740 - }); - const synthAddresses = logs.map(log => log.newSynth); - - const vaultLength = await api.call({ abi: "uint:getVaultsLength", target: CONTROLLERS[api.chain] }) + const addresses = SPECIAL_ADDRESSES.hasOwnProperty(api.chain) ? SPECIAL_ADDRESSES[api.chain] : DEFAULT_ADDRESSES + const vaultLength = await api.call({ abi: "uint:getVaultsLength", target: addresses.controller }) const vaultCalls = createIncrementArray(vaultLength) const owners = [] const tokens = [] - await Promise.all(synthAddresses.map(async (synth) => { - const vaults = await api.multiCall({ abi: "function mintVaults(uint vaultId) view returns (address)", calls: vaultCalls, target: synth}) - const _tokens = await api.multiCall({ abi: 'address:collateralAsset', calls: vaults}) - tokens.push(..._tokens) - owners.push(...vaults) - })) + + const vaults = await api.multiCall({ abi: "function mintVaults(uint vaultId) view returns (address)", calls: vaultCalls, target: addresses.monusd}) + const _tokens = await api.multiCall({ abi: 'address:collateralAsset', calls: vaults}) + tokens.push(..._tokens) + owners.push(...vaults) + return api.sumTokens({ tokensAndOwners2: [tokens, owners]}) } @@ -39,6 +39,6 @@ module.exports = { start: 1710288000, // March 13, 2024 00:00 GMT }; -Object.keys(CONTROLLERS).forEach((chain) => { +CHAINS.forEach((chain) => { module.exports[chain] = { tvl }; }); \ No newline at end of file From fab5c9924688019316c8b42844870d17d0b7e190 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Mon, 29 Jul 2024 12:55:08 +0800 Subject: [PATCH 4/4] feat: Monroe v2 --- projects/monroeprotocol/index.js | 46 +++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/projects/monroeprotocol/index.js b/projects/monroeprotocol/index.js index ae9ce664015e..576470c15386 100644 --- a/projects/monroeprotocol/index.js +++ b/projects/monroeprotocol/index.js @@ -1,34 +1,51 @@ const { createIncrementArray } = require("../helper/utils"); const { getLogs } = require('../helper/cache/getLogs') -const CHAINS = ["ethereum", "manta", "avax", "iotex"] +const V1_CHAINS = ["ethereum", "manta", "avax"] +const V2_CHAINS = ["manta", "avax"] +const CHAINS = [...new Set([...V2_CHAINS,...V1_CHAINS])] // Where possible contracts are deployed using deterministic addresses -const DEFAULT_ADDRESSES = { +const V1_ADDRESSES = { controller: "0xb2E609ef662889a32452598F0131863035974878", monusd: "0xDf3d57c3480951958Cef19905E4cf7FC1bA9ad42" } -const SPECIAL_ADDRESSES = { +const V1_SPECIAL_ADDRESSES = { zklink: { controller: "0xD620b0613568406F427a6f5d4ecA301870a1A3d5", monusd: "0x051baaA86328Fc7F522431932B8010F66f260A6a" } } +// V2 +const roeUSD = "0xF88DF111343BffE7a2d89FB770d77A264d53f043" -async function tvl(api) { - const addresses = SPECIAL_ADDRESSES.hasOwnProperty(api.chain) ? SPECIAL_ADDRESSES[api.chain] : DEFAULT_ADDRESSES - const vaultLength = await api.call({ abi: "uint:getVaultsLength", target: addresses.controller }) - const vaultCalls = createIncrementArray(vaultLength) +async function tvl(api) { const owners = [] const tokens = [] + + // V1 + if (V1_CHAINS.indexOf(api.chain) > -1){ + const addresses = V1_SPECIAL_ADDRESSES.hasOwnProperty(api.chain) ? V1_SPECIAL_ADDRESSES[api.chain] : V1_ADDRESSES + const vaultLength = await api.call({ abi: "uint:getVaultsLength", target: addresses.controller }) + const vaultCalls = createIncrementArray(vaultLength) - const vaults = await api.multiCall({ abi: "function mintVaults(uint vaultId) view returns (address)", calls: vaultCalls, target: addresses.monusd}) - const _tokens = await api.multiCall({ abi: 'address:collateralAsset', calls: vaults}) - tokens.push(..._tokens) - owners.push(...vaults) - - + const vaults = await api.multiCall({ abi: "function mintVaults(uint vaultId) view returns (address)", calls: vaultCalls, target: addresses.monusd}) + const _tokens = await api.multiCall({ abi: 'address:collateralAsset', calls: vaults}) + tokens.push(..._tokens) + owners.push(...vaults) + } + + // V2 + if (V2_CHAINS.indexOf(api.chain) > -1) { + const vaultLengthV2 = await api.call({ abi: "uint:getVaultsLength", target: roeUSD }) + const vaultCallsV2 = createIncrementArray(vaultLengthV2) + const vaultsV2 = await api.multiCall({ abi: "function vaults(uint vaultId) view returns (address)", calls: vaultCallsV2, target: roeUSD}) + const _tokensV2 = await api.multiCall({ abi: 'address:collateralAsset', calls: vaultsV2}) + tokens.push(..._tokensV2) + owners.push(...vaultsV2) + } + return api.sumTokens({ tokensAndOwners2: [tokens, owners]}) } @@ -37,6 +54,9 @@ module.exports = { methodology: "Adds up the total value locked as collateral in Monroe vaults", start: 1710288000, // March 13, 2024 00:00 GMT + hallmarks: [ + [1722000000, "V2 Launch"] + ], }; CHAINS.forEach((chain) => {