From 3a1127e7c48242bd06fa554443432ae9da6ce492 Mon Sep 17 00:00:00 2001 From: Eugene Mormul Date: Tue, 19 Dec 2023 17:13:24 +0200 Subject: [PATCH 1/7] feat: ethereum contracts --- src/adaptors/primex-finance/utils.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/adaptors/primex-finance/utils.js b/src/adaptors/primex-finance/utils.js index 8867d4bc6f..0e7186f870 100644 --- a/src/adaptors/primex-finance/utils.js +++ b/src/adaptors/primex-finance/utils.js @@ -51,6 +51,24 @@ const config = [ ['USDC.E']: 39.5, } }, + { + chain: 'Ethereum', + lensAddress: '0xBF7259d41af428642140C88a10db6921a383FCC1', + bucketsFactory: '0x7dE8607157124c894Ba9F18dd6138B5E8AAd5890', + positionManager: '0x99d63fEA4b3Ef6ca77941df3C5740dAd1586f0B8', + activityRewardDistributor: '0xA622b8DfC3B5Ec283CEefd37768F5B3b3E316730', + EPMX: "0xA533f744B179F2431f5395978e391107DC76e103", + EPMXPriceFeed: "0xF146a76F3Aa82D4cEa3eaB44932b7eE75737E11a", + EPMXPriceFeedDecimals: 8, + apyRewardBySymbol: { + ['WETH']: 24, + ['WBTC']: 2.4, + ['USDC']: 44.4, + ['USDT']: 43.2, + ['MATIC']: 21.6, + ['DAI']: 39.6, + } + }, ] const getPoolUrl = (address, chain) => `https://app.primex.finance/#/bucket-details/${address}?network=${CHAIN_IDS[chain]}`; From f545aa35eddd44671a9941fefe94fb65c54e9e12 Mon Sep 17 00:00:00 2001 From: 0xdi Date: Mon, 2 Dec 2024 16:52:12 +0100 Subject: [PATCH 2/7] update config --- src/adaptors/primex-finance/abi.js | 671 ++++++++++++++------------- src/adaptors/primex-finance/index.js | 19 +- src/adaptors/primex-finance/utils.js | 55 +-- 3 files changed, 353 insertions(+), 392 deletions(-) diff --git a/src/adaptors/primex-finance/abi.js b/src/adaptors/primex-finance/abi.js index a3e7d4e5c0..f4b7426685 100644 --- a/src/adaptors/primex-finance/abi.js +++ b/src/adaptors/primex-finance/abi.js @@ -1,536 +1,537 @@ const abi = { getAllBucketsFactory: { - "inputs": [ + inputs: [ { - "internalType": "address", - "name": "_bucketFactory", - "type": "address" + internalType: "address[]", + name: "_bucketFactories", + type: "address[]", }, { - "internalType": "address", - "name": "_user", - "type": "address" + internalType: "address", + name: "_user", + type: "address", }, { - "internalType": "address", - "name": "_positionManager", - "type": "address" + internalType: "address", + name: "_positionManager", + type: "address", }, { - "internalType": "bool", - "name": "_showDeprecated", - "type": "bool" - } + internalType: "bool", + name: "_showDeprecated", + type: "bool", + }, ], - "name": "getAllBucketsFactory", - "outputs": [ + name: "getAllBucketsFactory", + outputs: [ { - "components": [ + components: [ { - "internalType": "address", - "name": "bucketAddress", - "type": "address" + internalType: "address", + name: "bucketAddress", + type: "address", }, { - "internalType": "string", - "name": "name", - "type": "string" + internalType: "string", + name: "name", + type: "string", }, { - "components": [ + components: [ { - "internalType": "address", - "name": "tokenAddress", - "type": "address" + internalType: "address", + name: "tokenAddress", + type: "address", }, { - "internalType": "string", - "name": "symbol", - "type": "string" + internalType: "string", + name: "symbol", + type: "string", }, { - "internalType": "string", - "name": "name", - "type": "string" + internalType: "string", + name: "name", + type: "string", }, { - "internalType": "uint256", - "name": "decimals", - "type": "uint256" + internalType: "uint256", + name: "decimals", + type: "uint256", }, { - "internalType": "uint256", - "name": "balance", - "type": "uint256" - } + internalType: "uint256", + name: "balance", + type: "uint256", + }, ], - "internalType": "struct IPrimexLens.TokenMetadata", - "name": "asset", - "type": "tuple" + internalType: "struct IPrimexLens.TokenMetadata", + name: "asset", + type: "tuple", }, { - "internalType": "uint128", - "name": "bar", - "type": "uint128" + internalType: "uint128", + name: "bar", + type: "uint128", }, { - "internalType": "uint128", - "name": "lar", - "type": "uint128" + internalType: "uint128", + name: "lar", + type: "uint128", }, { - "internalType": "uint256", - "name": "supply", - "type": "uint256" + internalType: "uint256", + name: "supply", + type: "uint256", }, { - "internalType": "uint256", - "name": "demand", - "type": "uint256" + internalType: "uint256", + name: "demand", + type: "uint256", }, { - "internalType": "uint256", - "name": "availableLiquidity", - "type": "uint256" + internalType: "uint256", + name: "availableLiquidity", + type: "uint256", }, { - "internalType": "uint256", - "name": "utilizationRatio", - "type": "uint256" + internalType: "uint256", + name: "utilizationRatio", + type: "uint256", }, { - "components": [ + components: [ { - "components": [ + components: [ { - "internalType": "address", - "name": "tokenAddress", - "type": "address" + internalType: "address", + name: "tokenAddress", + type: "address", }, { - "internalType": "string", - "name": "symbol", - "type": "string" + internalType: "string", + name: "symbol", + type: "string", }, { - "internalType": "string", - "name": "name", - "type": "string" + internalType: "string", + name: "name", + type: "string", }, { - "internalType": "uint256", - "name": "decimals", - "type": "uint256" + internalType: "uint256", + name: "decimals", + type: "uint256", }, { - "internalType": "uint256", - "name": "balance", - "type": "uint256" - } + internalType: "uint256", + name: "balance", + type: "uint256", + }, ], - "internalType": "struct IPrimexLens.TokenMetadata", - "name": "asset", - "type": "tuple" + internalType: "struct IPrimexLens.TokenMetadata", + name: "asset", + type: "tuple", }, { - "components": [ + components: [ { - "internalType": "uint256", - "name": "id", - "type": "uint256" + internalType: "uint256", + name: "id", + type: "uint256", }, { - "internalType": "bool", - "name": "isSupported", - "type": "bool" + internalType: "bool", + name: "isSupported", + type: "bool", }, { - "internalType": "uint256", - "name": "pairPriceDrop", - "type": "uint256" + internalType: "uint256", + name: "pairPriceDrop", + type: "uint256", }, { - "internalType": "uint256", - "name": "maxLeverage", - "type": "uint256" - } + internalType: "uint256", + name: "maxLeverage", + type: "uint256", + }, ], - "internalType": "struct IPrimexLens.BucketTokenMetadata", - "name": "properties", - "type": "tuple" - } + internalType: "struct IPrimexLens.BucketTokenMetadata", + name: "properties", + type: "tuple", + }, ], - "internalType": "struct IPrimexLens.SupportedAsset[]", - "name": "supportedAssets", - "type": "tuple[]" + internalType: "struct IPrimexLens.SupportedAsset[]", + name: "supportedAssets", + type: "tuple[]", }, { - "components": [ + components: [ { - "internalType": "address", - "name": "tokenAddress", - "type": "address" + internalType: "address", + name: "tokenAddress", + type: "address", }, { - "internalType": "string", - "name": "symbol", - "type": "string" + internalType: "string", + name: "symbol", + type: "string", }, { - "internalType": "string", - "name": "name", - "type": "string" + internalType: "string", + name: "name", + type: "string", }, { - "internalType": "uint256", - "name": "decimals", - "type": "uint256" + internalType: "uint256", + name: "decimals", + type: "uint256", }, { - "internalType": "uint256", - "name": "balance", - "type": "uint256" - } + internalType: "uint256", + name: "balance", + type: "uint256", + }, ], - "internalType": "struct IPrimexLens.TokenMetadata", - "name": "pToken", - "type": "tuple" + internalType: "struct IPrimexLens.TokenMetadata", + name: "pToken", + type: "tuple", }, { - "components": [ + components: [ { - "internalType": "address", - "name": "tokenAddress", - "type": "address" + internalType: "address", + name: "tokenAddress", + type: "address", }, { - "internalType": "string", - "name": "symbol", - "type": "string" + internalType: "string", + name: "symbol", + type: "string", }, { - "internalType": "string", - "name": "name", - "type": "string" + internalType: "string", + name: "name", + type: "string", }, { - "internalType": "uint256", - "name": "decimals", - "type": "uint256" + internalType: "uint256", + name: "decimals", + type: "uint256", }, { - "internalType": "uint256", - "name": "balance", - "type": "uint256" - } + internalType: "uint256", + name: "balance", + type: "uint256", + }, ], - "internalType": "struct IPrimexLens.TokenMetadata", - "name": "debtToken", - "type": "tuple" + internalType: "struct IPrimexLens.TokenMetadata", + name: "debtToken", + type: "tuple", }, { - "internalType": "uint256", - "name": "feeBuffer", - "type": "uint256" + internalType: "uint256", + name: "feeBuffer", + type: "uint256", }, { - "internalType": "uint256", - "name": "withdrawalFeeRate", - "type": "uint256" + internalType: "uint256", + name: "withdrawalFeeRate", + type: "uint256", }, { - "components": [ + components: [ { - "internalType": "contract ILiquidityMiningRewardDistributor", - "name": "liquidityMiningRewardDistributor", - "type": "address" + internalType: "contract ILiquidityMiningRewardDistributor", + name: "liquidityMiningRewardDistributor", + type: "address", }, { - "internalType": "bool", - "name": "isBucketLaunched", - "type": "bool" + internalType: "bool", + name: "isBucketLaunched", + type: "bool", }, { - "internalType": "uint256", - "name": "accumulatingAmount", - "type": "uint256" + internalType: "uint256", + name: "accumulatingAmount", + type: "uint256", }, { - "internalType": "uint256", - "name": "deadlineTimestamp", - "type": "uint256" + internalType: "uint256", + name: "deadlineTimestamp", + type: "uint256", }, { - "internalType": "uint256", - "name": "stabilizationDuration", - "type": "uint256" + internalType: "uint256", + name: "stabilizationDuration", + type: "uint256", }, { - "internalType": "uint256", - "name": "stabilizationEndTimestamp", - "type": "uint256" + internalType: "uint256", + name: "stabilizationEndTimestamp", + type: "uint256", }, { - "internalType": "uint256", - "name": "maxAmountPerUser", - "type": "uint256" + internalType: "uint256", + name: "maxAmountPerUser", + type: "uint256", }, { - "internalType": "uint256", - "name": "maxDuration", - "type": "uint256" + internalType: "uint256", + name: "maxDuration", + type: "uint256", }, { - "internalType": "uint256", - "name": "maxStabilizationEndTimestamp", - "type": "uint256" - } + internalType: "uint256", + name: "maxStabilizationEndTimestamp", + type: "uint256", + }, ], - "internalType": "struct IBucketStorage.LiquidityMiningParams", - "name": "miningParams", - "type": "tuple" + internalType: "struct IBucketStorage.LiquidityMiningParams", + name: "miningParams", + type: "tuple", }, { - "components": [ + components: [ { - "internalType": "uint256", - "name": "amountInMining", - "type": "uint256" + internalType: "uint256", + name: "amountInMining", + type: "uint256", }, { - "internalType": "uint256", - "name": "currentPercent", - "type": "uint256" + internalType: "uint256", + name: "currentPercent", + type: "uint256", }, { - "components": [ + components: [ { - "internalType": "uint256", - "name": "minReward", - "type": "uint256" + internalType: "uint256", + name: "minReward", + type: "uint256", }, { - "internalType": "uint256", - "name": "maxReward", - "type": "uint256" + internalType: "uint256", + name: "maxReward", + type: "uint256", }, { - "internalType": "uint256", - "name": "extraReward", - "type": "uint256" - } + internalType: "uint256", + name: "extraReward", + type: "uint256", + }, ], - "internalType": "struct ILiquidityMiningRewardDistributor.RewardsInPMX", - "name": "rewardsInPMX", - "type": "tuple" - } + internalType: + "struct ILiquidityMiningRewardDistributor.RewardsInPMX", + name: "rewardsInPMX", + type: "tuple", + }, ], - "internalType": "struct IPrimexLens.LenderInfo", - "name": "lenderInfo", - "type": "tuple" + internalType: "struct IPrimexLens.LenderInfo", + name: "lenderInfo", + type: "tuple", }, { - "components": [ + components: [ { - "internalType": "uint256", - "name": "pmxAmount", - "type": "uint256" + internalType: "uint256", + name: "pmxAmount", + type: "uint256", }, { - "internalType": "uint256", - "name": "withdrawnRewards", - "type": "uint256" + internalType: "uint256", + name: "withdrawnRewards", + type: "uint256", }, { - "internalType": "uint256", - "name": "totalPoints", - "type": "uint256" - } + internalType: "uint256", + name: "totalPoints", + type: "uint256", + }, ], - "internalType": "struct IPrimexLens.LiquidityMiningBucketInfo", - "name": "lmBucketInfo", - "type": "tuple" + internalType: "struct IPrimexLens.LiquidityMiningBucketInfo", + name: "lmBucketInfo", + type: "tuple", }, { - "internalType": "uint128", - "name": "estimatedBar", - "type": "uint128" + internalType: "uint128", + name: "estimatedBar", + type: "uint128", }, { - "internalType": "uint128", - "name": "estimatedLar", - "type": "uint128" + internalType: "uint128", + name: "estimatedLar", + type: "uint128", }, { - "internalType": "bool", - "name": "isDeprecated", - "type": "bool" + internalType: "bool", + name: "isDeprecated", + type: "bool", }, { - "internalType": "bool", - "name": "isDelisted", - "type": "bool" + internalType: "bool", + name: "isDelisted", + type: "bool", }, { - "components": [ + components: [ { - "internalType": "uint256", - "name": "urOptimal", - "type": "uint256" + internalType: "uint256", + name: "urOptimal", + type: "uint256", }, { - "internalType": "uint256", - "name": "k0", - "type": "uint256" + internalType: "uint256", + name: "k0", + type: "uint256", }, { - "internalType": "uint256", - "name": "k1", - "type": "uint256" + internalType: "uint256", + name: "k1", + type: "uint256", }, { - "internalType": "uint256", - "name": "b0", - "type": "uint256" + internalType: "uint256", + name: "b0", + type: "uint256", }, { - "internalType": "int256", - "name": "b1", - "type": "int256" - } + internalType: "int256", + name: "b1", + type: "int256", + }, ], - "internalType": "struct IInterestRateStrategy.BarCalculationParams", - "name": "barCalcParams", - "type": "tuple" + internalType: "struct IInterestRateStrategy.BarCalculationParams", + name: "barCalcParams", + type: "tuple", }, { - "internalType": "uint256", - "name": "maxTotalDeposit", - "type": "uint256" - } + internalType: "uint256", + name: "maxTotalDeposit", + type: "uint256", + }, ], - "internalType": "struct IPrimexLens.BucketMetaData[]", - "name": "", - "type": "tuple[]" - } + internalType: "struct IPrimexLens.BucketMetaData[]", + name: "", + type: "tuple[]", + }, ], - "stateMutability": "view", - "type": "function" + stateMutability: "view", + type: "function", }, activityRewardDistributorBuckets: { - "inputs": [ + inputs: [ { - "internalType": "address", - "name": "", - "type": "address" + internalType: "address", + name: "", + type: "address", }, { - "internalType": "uint256", - "name": "", - "type": "uint256" - } + internalType: "uint256", + name: "", + type: "uint256", + }, ], - "name": "buckets", - "outputs": [ + name: "buckets", + outputs: [ { - "internalType": "uint256", - "name": "rewardIndex", - "type": "uint256" + internalType: "uint256", + name: "rewardIndex", + type: "uint256", }, { - "internalType": "uint256", - "name": "lastUpdatedTimestamp", - "type": "uint256" + internalType: "uint256", + name: "lastUpdatedTimestamp", + type: "uint256", }, { - "internalType": "uint256", - "name": "rewardPerToken", - "type": "uint256" + internalType: "uint256", + name: "rewardPerToken", + type: "uint256", }, { - "internalType": "uint256", - "name": "scaledTotalSupply", - "type": "uint256" + internalType: "uint256", + name: "scaledTotalSupply", + type: "uint256", }, { - "internalType": "bool", - "name": "isFinished", - "type": "bool" + internalType: "bool", + name: "isFinished", + type: "bool", }, { - "internalType": "uint256", - "name": "fixedReward", - "type": "uint256" + internalType: "uint256", + name: "fixedReward", + type: "uint256", }, { - "internalType": "uint256", - "name": "lastUpdatedRewardTimestamp", - "type": "uint256" + internalType: "uint256", + name: "lastUpdatedRewardTimestamp", + type: "uint256", }, { - "internalType": "uint256", - "name": "rewardPerDay", - "type": "uint256" + internalType: "uint256", + name: "rewardPerDay", + type: "uint256", }, { - "internalType": "uint256", - "name": "totalReward", - "type": "uint256" + internalType: "uint256", + name: "totalReward", + type: "uint256", }, { - "internalType": "uint256", - "name": "endTimestamp", - "type": "uint256" - } + internalType: "uint256", + name: "endTimestamp", + type: "uint256", + }, ], - "stateMutability": "view", - "type": "function" + stateMutability: "view", + type: "function", }, getChainlinkLatestRoundData: { - "inputs": [ + inputs: [ { - "internalType": "address[]", - "name": "_feeds", - "type": "address[]" - } + internalType: "address[]", + name: "_feeds", + type: "address[]", + }, ], - "name": "getChainlinkLatestRoundData", - "outputs": [ + name: "getChainlinkLatestRoundData", + outputs: [ { - "components": [ + components: [ { - "internalType": "uint80", - "name": "roundId", - "type": "uint80" + internalType: "uint80", + name: "roundId", + type: "uint80", }, { - "internalType": "int256", - "name": "answer", - "type": "int256" + internalType: "int256", + name: "answer", + type: "int256", }, { - "internalType": "uint256", - "name": "startedAt", - "type": "uint256" + internalType: "uint256", + name: "startedAt", + type: "uint256", }, { - "internalType": "uint256", - "name": "updatedAt", - "type": "uint256" + internalType: "uint256", + name: "updatedAt", + type: "uint256", }, { - "internalType": "uint80", - "name": "answeredInRound", - "type": "uint80" - } + internalType: "uint80", + name: "answeredInRound", + type: "uint80", + }, ], - "internalType": "struct IPrimexLens.RoundData[]", - "name": "", - "type": "tuple[]" - } + internalType: "struct IPrimexLens.RoundData[]", + name: "", + type: "tuple[]", + }, ], - "stateMutability": "view", - "type": "function" + stateMutability: "view", + type: "function", } } diff --git a/src/adaptors/primex-finance/index.js b/src/adaptors/primex-finance/index.js index 2f143a55a5..2e6b259ad2 100644 --- a/src/adaptors/primex-finance/index.js +++ b/src/adaptors/primex-finance/index.js @@ -5,22 +5,7 @@ const { CHAIN_IDS, DEAD_ADDRESS, ROLES, SECONDS_PER_YEAR, APY_REWARD_BONUS, conf const formatPool = async (bucket, config, EPMXPrice) => { const { bucketAddress, asset, supportedAssets, supply, demand, bar, lar, estimatedBar, estimatedLar, miningParams, name } = bucket; - const { chain, activityRewardDistributor, EPMX, USDCE, apyRewardBySymbol } = config - - const [rewardPerTokenLender, rewardPerTokenTrader] = (await Promise.all( - Object.values(ROLES).map((r) => { - return ( - sdk.api.abi.call({ - abi: abi.activityRewardDistributorBuckets, - target: activityRewardDistributor, - chain: chain.toLowerCase(), - params: [bucketAddress, r] - }) - ) - }) - )).map(v => { - return v.output.isFinished ? 0 : v.output.rewardPerToken - }) + const { chain, EPMX, USDCE, apyRewardBySymbol } = config const symbol = addressEq(asset.tokenAddress, USDCE) ? 'USDC.E' : asset.symbol const underlyingTokens = [asset.tokenAddress] @@ -91,7 +76,7 @@ const getPools = async (config) => { buckets .filter(({ miningParams }) => { const isMiningFailed = !miningParams.isBucketLaunched && miningParams.deadlineTimestamp * 1000 <= Date.now() - + return !isMiningFailed }) .map((b) => formatPool(b, config, EPMXPrice)) diff --git a/src/adaptors/primex-finance/utils.js b/src/adaptors/primex-finance/utils.js index 0e7186f870..2bffc6b301 100644 --- a/src/adaptors/primex-finance/utils.js +++ b/src/adaptors/primex-finance/utils.js @@ -7,8 +7,9 @@ const ROLES = { } const CHAIN_IDS = { + Ethereum: 'ethereum', + Arbitrum: 'arbitrum_one', Polygon: 'polygon_mainnet', - Arbitrum: 'arbitrum_one' }; const APY_REWARD_BONUS = 7; @@ -16,59 +17,33 @@ const APY_REWARD_BONUS = 7; const config = [ { chain: 'Polygon', - lensAddress: '0xCbaEc4b0683Ed6F2C2C318500962857768Fc1366', - bucketsFactory: '0x7E6915D307F434E4171cCee90e180f5021c60089', + lensAddress: '0xe84C7913dec4f1191F0b7ef7fb54c3E60DA2DF0B', + bucketsFactory: ['0x7E6915D307F434E4171cCee90e180f5021c60089', "0x9649CfDCfAa9c80907e63dD9Cb161cBA2033F3A0"], positionManager: '0x02bcaA4633E466d151b34112608f60A82a4F6035', - activityRewardDistributor: '0x156e2fC8e1906507412BEeEB6640Bf999a1Ea76b', USDCE: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", EPMX: "0xDc6D1bd104E1efa4A1bf0BBCf6E0BD093614E31A", EPMXPriceFeed: "0x103A9FF33c709405DF58f8f209C53f6B5c5eA2BE", EPMXPriceFeedDecimals: 8, - apyRewardBySymbol: { - ['WETH']: 18, - ['WBTC']: 1, - ['USDC.E']: 31, - ['USDT']: 20, - ['WMATIC']: 21, - } }, { chain: 'Arbitrum', - lensAddress: '0x3a5CAdB5eDF17876fD2518AEC3a4d804964aA89e', - bucketsFactory: '0x4e6f7372bCE4083c779c17B240A94dc2EA57AE67', + lensAddress: '0x9b3bdb43E43422d789FE4977d63Af76C3159F6C6', + bucketsFactory: ['0x4e6f7372bCE4083c779c17B240A94dc2EA57AE67', "0xB4d3A9f10D3D687FaF3b05b9aa3054856A1d7be8"], positionManager: '0x86890E30cE9E1e13Db5560BbEb435c55567Af1cd', - activityRewardDistributor: '0x38D94212AAe3f4aB3E4fE801d9021ab0aA371DaB', USDCE: "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8", EPMX: "0xA533f744B179F2431f5395978e391107DC76e103", EPMXPriceFeed: "0x053FB5b7c555FC0d9Bc49118023d6B6A4019168f", EPMXPriceFeedDecimals: 8, - apyRewardBySymbol: { - ['WETH']: 23.5, - ['WBTC']: 1.25, - ['USDC']: 39.5, - ['USDT']: 41, - ['ARB']: 1, - ['USDC.E']: 39.5, - } - }, - { - chain: 'Ethereum', - lensAddress: '0xBF7259d41af428642140C88a10db6921a383FCC1', - bucketsFactory: '0x7dE8607157124c894Ba9F18dd6138B5E8AAd5890', - positionManager: '0x99d63fEA4b3Ef6ca77941df3C5740dAd1586f0B8', - activityRewardDistributor: '0xA622b8DfC3B5Ec283CEefd37768F5B3b3E316730', - EPMX: "0xA533f744B179F2431f5395978e391107DC76e103", - EPMXPriceFeed: "0xF146a76F3Aa82D4cEa3eaB44932b7eE75737E11a", - EPMXPriceFeedDecimals: 8, - apyRewardBySymbol: { - ['WETH']: 24, - ['WBTC']: 2.4, - ['USDC']: 44.4, - ['USDT']: 43.2, - ['MATIC']: 21.6, - ['DAI']: 39.6, - } }, + // { + // chain: 'Ethereum', + // lensAddress: '0xa1690975FBd39dfCdCEf14726cF87662746E91d3', + // bucketsFactory: ['0x7dE8607157124c894Ba9F18dd6138B5E8AAd5890', "0x55120da310A0c5fd81Fd3bb8C177F6649bE30ACc"], + // positionManager: '0x99d63fEA4b3Ef6ca77941df3C5740dAd1586f0B8', + // EPMX: "0xA533f744B179F2431f5395978e391107DC76e103", + // EPMXPriceFeed: "0xF146a76F3Aa82D4cEa3eaB44932b7eE75737E11a", + // EPMXPriceFeedDecimals: 8, + // } ] const getPoolUrl = (address, chain) => `https://app.primex.finance/#/bucket-details/${address}?network=${CHAIN_IDS[chain]}`; From 66fde5aae6676a124370bf11816ad50ae10585e0 Mon Sep 17 00:00:00 2001 From: pavlo-tolok Date: Thu, 2 Jan 2025 12:42:22 +0100 Subject: [PATCH 3/7] FEAT(PRIM-6971):Updates of getAllBucketsFactory method call --- src/adaptors/primex-finance/abi.js | 626 ++++++++++++++------------- src/adaptors/primex-finance/index.js | 133 ++++-- src/adaptors/primex-finance/utils.js | 81 ++-- 3 files changed, 479 insertions(+), 361 deletions(-) diff --git a/src/adaptors/primex-finance/abi.js b/src/adaptors/primex-finance/abi.js index f4b7426685..78aa5c6039 100644 --- a/src/adaptors/primex-finance/abi.js +++ b/src/adaptors/primex-finance/abi.js @@ -2,537 +2,563 @@ const abi = { getAllBucketsFactory: { inputs: [ { - internalType: "address[]", - name: "_bucketFactories", - type: "address[]", + internalType: 'address[]', + name: '_bucketFactories', + type: 'address[]', }, { - internalType: "address", - name: "_user", - type: "address", + internalType: 'address', + name: '_user', + type: 'address', }, { - internalType: "address", - name: "_positionManager", - type: "address", + internalType: 'address', + name: '_positionManager', + type: 'address', }, { - internalType: "bool", - name: "_showDeprecated", - type: "bool", + internalType: 'bool', + name: '_showDeprecated', + type: 'bool', + }, + { + internalType: 'uint256', + name: '_cursor', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_count', + type: 'uint256', }, ], - name: "getAllBucketsFactory", + name: 'getAllBucketsFactory', outputs: [ { components: [ { - internalType: "address", - name: "bucketAddress", - type: "address", + internalType: 'address', + name: 'bucketAddress', + type: 'address', }, { - internalType: "string", - name: "name", - type: "string", + internalType: 'string', + name: 'name', + type: 'string', }, { components: [ { - internalType: "address", - name: "tokenAddress", - type: "address", + internalType: 'address', + name: 'tokenAddress', + type: 'address', }, { - internalType: "string", - name: "symbol", - type: "string", + internalType: 'string', + name: 'symbol', + type: 'string', }, { - internalType: "string", - name: "name", - type: "string", + internalType: 'string', + name: 'name', + type: 'string', }, { - internalType: "uint256", - name: "decimals", - type: "uint256", + internalType: 'uint256', + name: 'decimals', + type: 'uint256', }, { - internalType: "uint256", - name: "balance", - type: "uint256", + internalType: 'uint256', + name: 'balance', + type: 'uint256', }, ], - internalType: "struct IPrimexLens.TokenMetadata", - name: "asset", - type: "tuple", + internalType: 'struct IPrimexLens.TokenMetadata', + name: 'asset', + type: 'tuple', }, { - internalType: "uint128", - name: "bar", - type: "uint128", + internalType: 'uint128', + name: 'bar', + type: 'uint128', }, { - internalType: "uint128", - name: "lar", - type: "uint128", + internalType: 'uint128', + name: 'lar', + type: 'uint128', }, { - internalType: "uint256", - name: "supply", - type: "uint256", + internalType: 'uint256', + name: 'supply', + type: 'uint256', }, { - internalType: "uint256", - name: "demand", - type: "uint256", + internalType: 'uint256', + name: 'demand', + type: 'uint256', }, { - internalType: "uint256", - name: "availableLiquidity", - type: "uint256", + internalType: 'uint256', + name: 'availableLiquidity', + type: 'uint256', }, { - internalType: "uint256", - name: "utilizationRatio", - type: "uint256", + internalType: 'uint256', + name: 'utilizationRatio', + type: 'uint256', }, { components: [ { components: [ { - internalType: "address", - name: "tokenAddress", - type: "address", + internalType: 'address', + name: 'tokenAddress', + type: 'address', }, { - internalType: "string", - name: "symbol", - type: "string", + internalType: 'string', + name: 'symbol', + type: 'string', }, { - internalType: "string", - name: "name", - type: "string", + internalType: 'string', + name: 'name', + type: 'string', }, { - internalType: "uint256", - name: "decimals", - type: "uint256", + internalType: 'uint256', + name: 'decimals', + type: 'uint256', }, { - internalType: "uint256", - name: "balance", - type: "uint256", + internalType: 'uint256', + name: 'balance', + type: 'uint256', }, ], - internalType: "struct IPrimexLens.TokenMetadata", - name: "asset", - type: "tuple", + internalType: 'struct IPrimexLens.TokenMetadata', + name: 'asset', + type: 'tuple', }, { components: [ { - internalType: "uint256", - name: "id", - type: "uint256", + internalType: 'uint256', + name: 'id', + type: 'uint256', }, { - internalType: "bool", - name: "isSupported", - type: "bool", + internalType: 'bool', + name: 'isSupported', + type: 'bool', }, { - internalType: "uint256", - name: "pairPriceDrop", - type: "uint256", + internalType: 'uint256', + name: 'pairPriceDrop', + type: 'uint256', }, { - internalType: "uint256", - name: "maxLeverage", - type: "uint256", + internalType: 'uint256', + name: 'maxLeverage', + type: 'uint256', }, ], - internalType: "struct IPrimexLens.BucketTokenMetadata", - name: "properties", - type: "tuple", + internalType: 'struct IPrimexLens.BucketTokenMetadata', + name: 'properties', + type: 'tuple', }, ], - internalType: "struct IPrimexLens.SupportedAsset[]", - name: "supportedAssets", - type: "tuple[]", + internalType: 'struct IPrimexLens.SupportedAsset[]', + name: 'supportedAssets', + type: 'tuple[]', }, { components: [ { - internalType: "address", - name: "tokenAddress", - type: "address", + internalType: 'address', + name: 'tokenAddress', + type: 'address', }, { - internalType: "string", - name: "symbol", - type: "string", + internalType: 'string', + name: 'symbol', + type: 'string', }, { - internalType: "string", - name: "name", - type: "string", + internalType: 'string', + name: 'name', + type: 'string', }, { - internalType: "uint256", - name: "decimals", - type: "uint256", + internalType: 'uint256', + name: 'decimals', + type: 'uint256', }, { - internalType: "uint256", - name: "balance", - type: "uint256", + internalType: 'uint256', + name: 'balance', + type: 'uint256', }, ], - internalType: "struct IPrimexLens.TokenMetadata", - name: "pToken", - type: "tuple", + internalType: 'struct IPrimexLens.TokenMetadata', + name: 'pToken', + type: 'tuple', }, { components: [ { - internalType: "address", - name: "tokenAddress", - type: "address", + internalType: 'address', + name: 'tokenAddress', + type: 'address', }, { - internalType: "string", - name: "symbol", - type: "string", + internalType: 'string', + name: 'symbol', + type: 'string', }, { - internalType: "string", - name: "name", - type: "string", + internalType: 'string', + name: 'name', + type: 'string', }, { - internalType: "uint256", - name: "decimals", - type: "uint256", + internalType: 'uint256', + name: 'decimals', + type: 'uint256', }, { - internalType: "uint256", - name: "balance", - type: "uint256", + internalType: 'uint256', + name: 'balance', + type: 'uint256', }, ], - internalType: "struct IPrimexLens.TokenMetadata", - name: "debtToken", - type: "tuple", + internalType: 'struct IPrimexLens.TokenMetadata', + name: 'debtToken', + type: 'tuple', }, { - internalType: "uint256", - name: "feeBuffer", - type: "uint256", + internalType: 'uint256', + name: 'feeBuffer', + type: 'uint256', }, { - internalType: "uint256", - name: "withdrawalFeeRate", - type: "uint256", + internalType: 'uint256', + name: 'withdrawalFeeRate', + type: 'uint256', }, { components: [ { - internalType: "contract ILiquidityMiningRewardDistributor", - name: "liquidityMiningRewardDistributor", - type: "address", + internalType: 'contract ILiquidityMiningRewardDistributor', + name: 'liquidityMiningRewardDistributor', + type: 'address', }, { - internalType: "bool", - name: "isBucketLaunched", - type: "bool", + internalType: 'bool', + name: 'isBucketLaunched', + type: 'bool', }, { - internalType: "uint256", - name: "accumulatingAmount", - type: "uint256", + internalType: 'uint256', + name: 'accumulatingAmount', + type: 'uint256', }, { - internalType: "uint256", - name: "deadlineTimestamp", - type: "uint256", + internalType: 'uint256', + name: 'deadlineTimestamp', + type: 'uint256', }, { - internalType: "uint256", - name: "stabilizationDuration", - type: "uint256", + internalType: 'uint256', + name: 'stabilizationDuration', + type: 'uint256', }, { - internalType: "uint256", - name: "stabilizationEndTimestamp", - type: "uint256", + internalType: 'uint256', + name: 'stabilizationEndTimestamp', + type: 'uint256', }, { - internalType: "uint256", - name: "maxAmountPerUser", - type: "uint256", + internalType: 'uint256', + name: 'maxAmountPerUser', + type: 'uint256', }, { - internalType: "uint256", - name: "maxDuration", - type: "uint256", + internalType: 'uint256', + name: 'maxDuration', + type: 'uint256', }, { - internalType: "uint256", - name: "maxStabilizationEndTimestamp", - type: "uint256", + internalType: 'uint256', + name: 'maxStabilizationEndTimestamp', + type: 'uint256', }, ], - internalType: "struct IBucketStorage.LiquidityMiningParams", - name: "miningParams", - type: "tuple", + internalType: 'struct IBucketStorage.LiquidityMiningParams', + name: 'miningParams', + type: 'tuple', }, { components: [ { - internalType: "uint256", - name: "amountInMining", - type: "uint256", + internalType: 'uint256', + name: 'amountInMining', + type: 'uint256', }, { - internalType: "uint256", - name: "currentPercent", - type: "uint256", + internalType: 'uint256', + name: 'currentPercent', + type: 'uint256', }, { components: [ { - internalType: "uint256", - name: "minReward", - type: "uint256", + internalType: 'uint256', + name: 'minReward', + type: 'uint256', }, { - internalType: "uint256", - name: "maxReward", - type: "uint256", + internalType: 'uint256', + name: 'maxReward', + type: 'uint256', }, { - internalType: "uint256", - name: "extraReward", - type: "uint256", + internalType: 'uint256', + name: 'extraReward', + type: 'uint256', }, ], internalType: - "struct ILiquidityMiningRewardDistributor.RewardsInPMX", - name: "rewardsInPMX", - type: "tuple", + 'struct ILiquidityMiningRewardDistributor.RewardsInPMX', + name: 'rewardsInPMX', + type: 'tuple', }, ], - internalType: "struct IPrimexLens.LenderInfo", - name: "lenderInfo", - type: "tuple", + internalType: 'struct IPrimexLens.LenderInfo', + name: 'lenderInfo', + type: 'tuple', }, { components: [ { - internalType: "uint256", - name: "pmxAmount", - type: "uint256", + internalType: 'uint256', + name: 'pmxAmount', + type: 'uint256', }, { - internalType: "uint256", - name: "withdrawnRewards", - type: "uint256", + internalType: 'uint256', + name: 'withdrawnRewards', + type: 'uint256', }, { - internalType: "uint256", - name: "totalPoints", - type: "uint256", + internalType: 'uint256', + name: 'totalPoints', + type: 'uint256', }, ], - internalType: "struct IPrimexLens.LiquidityMiningBucketInfo", - name: "lmBucketInfo", - type: "tuple", + internalType: 'struct IPrimexLens.LiquidityMiningBucketInfo', + name: 'lmBucketInfo', + type: 'tuple', }, { - internalType: "uint128", - name: "estimatedBar", - type: "uint128", + internalType: 'uint128', + name: 'estimatedBar', + type: 'uint128', }, { - internalType: "uint128", - name: "estimatedLar", - type: "uint128", + internalType: 'uint128', + name: 'estimatedLar', + type: 'uint128', }, { - internalType: "bool", - name: "isDeprecated", - type: "bool", + internalType: 'bool', + name: 'isDeprecated', + type: 'bool', }, { - internalType: "bool", - name: "isDelisted", - type: "bool", + internalType: 'bool', + name: 'isDelisted', + type: 'bool', }, { components: [ { - internalType: "uint256", - name: "urOptimal", - type: "uint256", + internalType: 'uint256', + name: 'urOptimal', + type: 'uint256', }, { - internalType: "uint256", - name: "k0", - type: "uint256", + internalType: 'uint256', + name: 'k0', + type: 'uint256', }, { - internalType: "uint256", - name: "k1", - type: "uint256", + internalType: 'uint256', + name: 'k1', + type: 'uint256', }, { - internalType: "uint256", - name: "b0", - type: "uint256", + internalType: 'uint256', + name: 'b0', + type: 'uint256', }, { - internalType: "int256", - name: "b1", - type: "int256", + internalType: 'int256', + name: 'b1', + type: 'int256', }, ], - internalType: "struct IInterestRateStrategy.BarCalculationParams", - name: "barCalcParams", - type: "tuple", + internalType: 'struct IInterestRateStrategy.BarCalculationParams', + name: 'barCalcParams', + type: 'tuple', + }, + { + internalType: 'uint256', + name: 'maxTotalDeposit', + type: 'uint256', }, { - internalType: "uint256", - name: "maxTotalDeposit", - type: "uint256", + internalType: 'uint256', + name: 'liquidityIndex', + type: 'uint256', + }, + { + internalType: 'enum IPrimexDNSStorage.Status', + name: 'currentStatus', + type: 'uint8', }, ], - internalType: "struct IPrimexLens.BucketMetaData[]", - name: "", - type: "tuple[]", + internalType: 'struct IPrimexLensPart2.BucketMetaDataPart2[]', + name: '', + type: 'tuple[]', + }, + { + internalType: 'uint256', + name: '', + type: 'uint256', }, ], - stateMutability: "view", - type: "function", + + stateMutability: 'view', + type: 'function', }, activityRewardDistributorBuckets: { inputs: [ { - internalType: "address", - name: "", - type: "address", + internalType: 'address', + name: '', + type: 'address', }, { - internalType: "uint256", - name: "", - type: "uint256", + internalType: 'uint256', + name: '', + type: 'uint256', }, ], - name: "buckets", + name: 'buckets', outputs: [ { - internalType: "uint256", - name: "rewardIndex", - type: "uint256", + internalType: 'uint256', + name: 'rewardIndex', + type: 'uint256', }, { - internalType: "uint256", - name: "lastUpdatedTimestamp", - type: "uint256", + internalType: 'uint256', + name: 'lastUpdatedTimestamp', + type: 'uint256', }, { - internalType: "uint256", - name: "rewardPerToken", - type: "uint256", + internalType: 'uint256', + name: 'rewardPerToken', + type: 'uint256', }, { - internalType: "uint256", - name: "scaledTotalSupply", - type: "uint256", + internalType: 'uint256', + name: 'scaledTotalSupply', + type: 'uint256', }, { - internalType: "bool", - name: "isFinished", - type: "bool", + internalType: 'bool', + name: 'isFinished', + type: 'bool', }, { - internalType: "uint256", - name: "fixedReward", - type: "uint256", + internalType: 'uint256', + name: 'fixedReward', + type: 'uint256', }, { - internalType: "uint256", - name: "lastUpdatedRewardTimestamp", - type: "uint256", + internalType: 'uint256', + name: 'lastUpdatedRewardTimestamp', + type: 'uint256', }, { - internalType: "uint256", - name: "rewardPerDay", - type: "uint256", + internalType: 'uint256', + name: 'rewardPerDay', + type: 'uint256', }, { - internalType: "uint256", - name: "totalReward", - type: "uint256", + internalType: 'uint256', + name: 'totalReward', + type: 'uint256', }, { - internalType: "uint256", - name: "endTimestamp", - type: "uint256", + internalType: 'uint256', + name: 'endTimestamp', + type: 'uint256', }, ], - stateMutability: "view", - type: "function", + stateMutability: 'view', + type: 'function', }, getChainlinkLatestRoundData: { inputs: [ { - internalType: "address[]", - name: "_feeds", - type: "address[]", + internalType: 'address[]', + name: '_feeds', + type: 'address[]', }, ], - name: "getChainlinkLatestRoundData", + name: 'getChainlinkLatestRoundData', outputs: [ { components: [ { - internalType: "uint80", - name: "roundId", - type: "uint80", + internalType: 'uint80', + name: 'roundId', + type: 'uint80', }, { - internalType: "int256", - name: "answer", - type: "int256", + internalType: 'int256', + name: 'answer', + type: 'int256', }, { - internalType: "uint256", - name: "startedAt", - type: "uint256", + internalType: 'uint256', + name: 'startedAt', + type: 'uint256', }, { - internalType: "uint256", - name: "updatedAt", - type: "uint256", + internalType: 'uint256', + name: 'updatedAt', + type: 'uint256', }, { - internalType: "uint80", - name: "answeredInRound", - type: "uint80", + internalType: 'uint80', + name: 'answeredInRound', + type: 'uint80', }, ], - internalType: "struct IPrimexLens.RoundData[]", - name: "", - type: "tuple[]", + internalType: 'struct IPrimexLens.RoundData[]', + name: '', + type: 'tuple[]', }, ], - stateMutability: "view", - type: "function", - } -} + stateMutability: 'view', + type: 'function', + }, +}; -module.exports = { abi } \ No newline at end of file +module.exports = { abi }; diff --git a/src/adaptors/primex-finance/index.js b/src/adaptors/primex-finance/index.js index 49269c6f36..6e5b23c216 100644 --- a/src/adaptors/primex-finance/index.js +++ b/src/adaptors/primex-finance/index.js @@ -1,6 +1,7 @@ const sdk = require('@defillama/sdk'); const superagent = require('superagent'); const { abi } = require('./abi'); +const { ethers } = require('ethers'); const utils = require('../utils'); const { CHAIN_IDS, @@ -13,21 +14,37 @@ const { getPoolUrl, } = require('./utils'); -const formatPool = async (bucket, config, EPMXPrice) => { - const { bucketAddress, asset, supportedAssets, supply, demand, bar, lar, estimatedBar, estimatedLar, miningParams, name } = bucket; - const { chain, EPMX, USDCE, apyRewardBySymbol } = config - - const symbol = addressEq(asset.tokenAddress, USDCE) ? 'USDC.E' : asset.symbol; - const underlyingTokens = [asset.tokenAddress]; +const formatPool = async (bucket, config) => { + const { + bucketAddress, + asset, + supportedAssets, + supply, + demand, + bar, + lar, + estimatedBar, + estimatedLar, + miningParams, + name, + } = bucket[0]; + + const { chain, EPMX, USDCE, apyRewardBySymbol } = config; + + const symbol = addressEq(asset?.tokenAddress, USDCE) + ? 'USDC.E' + : asset?.symbol; + const underlyingTokens = [asset?.tokenAddress]; const priceKeys = underlyingTokens .map((t) => `${chain.toLowerCase()}:${t}`) .join(','); + const prices = ( await superagent.get(`https://coins.llama.fi/prices/current/${priceKeys}`) ).body.coins; - const assetPrice = prices[`${chain.toLowerCase()}:${asset.tokenAddress}`]; + const assetPrice = prices[`${chain.toLowerCase()}:${asset?.tokenAddress}`]; const totalSupplyUsd = (supply / 10 ** assetPrice?.decimals) * assetPrice?.price; const totalBorrowUsd = @@ -35,8 +52,8 @@ const formatPool = async (bucket, config, EPMXPrice) => { const tvlUsd = totalSupplyUsd - totalBorrowUsd; const isMiningPhase = - !miningParams.isBucketLaunched && - miningParams.deadlineTimestamp * 1000 > Date.now(); + !miningParams?.isBucketLaunched && + miningParams?.deadlineTimestamp * 1000 > Date.now(); const apyBaseCalculated = (Math.pow(1 + lar / 10 ** 27 / SECONDS_PER_YEAR, SECONDS_PER_YEAR) - 1) * @@ -47,13 +64,7 @@ const formatPool = async (bucket, config, EPMXPrice) => { (Math.pow(1 + bar / 10 ** 27 / SECONDS_PER_YEAR, SECONDS_PER_YEAR) - 1) * 100; const apyBaseBorrow = isMiningPhase ? 0 : apyBaseBorrowCalculated; - - // const apyRewardCalculated = (rewardPerTokenLender * 10 ** asset.decimals / 10 ** 18 * SECONDS_PER_YEAR * EPMXPrice / assetPrice.price / 10 ** 18) * 100; - // const apyReward = isMiningPhase ? apyRewardBySymbol[symbol] + APY_REWARD_BONUS : apyRewardCalculated const apyReward = isMiningPhase ? APY_REWARD_BONUS : 0; - - // const apyRewardBorrowCalculated = (rewardPerTokenTrader * 10 ** asset.decimals / 10 ** 18 * SECONDS_PER_YEAR * EPMXPrice / assetPrice.price / 10 ** 18) * 100; - // const apyRewardBorrow = isMiningPhase ? 0 : apyRewardBorrowCalculated const apyRewardBorrow = 0; return { @@ -85,33 +96,85 @@ const getPools = async (config) => { EPMXPriceFeedDecimals, } = config; - const buckets = ( - await sdk.api.abi.call({ - abi: abi.getAllBucketsFactory, - target: lensAddress, - chain: chain.toLowerCase(), - params: [bucketsFactory, DEAD_ADDRESS, positionManager, false], - }) - ).output; - - const EPMXPrice = - ( + if (chain === 'Ethereum') { + sdk.api.config.setProvider( + 'ethereum', + new ethers.providers.JsonRpcProvider( + 'https://lb.drpc.org/ogrpc?network=ethereum&dkey=AhjAIUax7EMFtu9ErxcXVpiWXqG_mFMR7oB-goai82vO' + ) + ); + } + + if (chain === 'Arbitrum') { + sdk.api.config.setProvider( + 'ethereum', + new ethers.providers.JsonRpcProvider( + 'https://lb.drpc.org/ogrpc?network=arbitrum&dkey=AhjAIUax7EMFtu9ErxcXVpgEW9szfIYR7qRQxqxINsn1' + ) + ); + } + + if (chain === 'Polygon') { + sdk.api.config.setProvider( + 'ethereum', + new ethers.providers.JsonRpcProvider( + 'https://lb.drpc.org/ogrpc?network=polygon&dkey=AhjAIUax7EMFtu9ErxcXVpinS0aAWWER7oTEFnomaLKw' + ) + ); + } + if (chain === 'Base') { + sdk.api.config.setProvider( + 'base', + new ethers.providers.JsonRpcProvider( + 'https://lb.drpc.org/ogrpc?network=base&dkey=AhjAIUax7EMFtu9ErxcXVpg7GmZNgi4R74QSKjW4AN0P' + ) + ); + } + + let bucketsArr = []; + let offset = 0; + const limit = 3; + + while (true) { + const result = ( await sdk.api.abi.call({ - abi: abi.getChainlinkLatestRoundData, + abi: abi.getAllBucketsFactory, target: lensAddress, chain: chain.toLowerCase(), - params: [[EPMXPriceFeed]], + params: [ + bucketsFactory, + DEAD_ADDRESS, + positionManager, + false, + offset, + limit, + ], }) - ).output[0].answer / - 10 ** EPMXPriceFeedDecimals; + ).output; + + if ( + (Array.isArray(result) && + Array.isArray(result[0]) && + result[0].length === 0) || + JSON.stringify(result) === JSON.stringify([[], '0']) + ) { + break; + } + + bucketsArr = bucketsArr.concat(result); + offset += limit; + } return await Promise.all( - buckets - .filter(({ miningParams }) => { - const isMiningFailed = !miningParams.isBucketLaunched && miningParams.deadlineTimestamp * 1000 <= Date.now() - return !isMiningFailed + bucketsArr + .filter((bucket) => { + const miningParams = bucket[0]?.miningParams; + const isMiningFailed = + !miningParams?.isBucketLaunched && + miningParams?.deadlineTimestamp * 1000 <= Date.now(); + return !isMiningFailed; }) - .map((b) => formatPool(b, config, EPMXPrice)) + .map((b) => formatPool(b, config)) ); }; diff --git a/src/adaptors/primex-finance/utils.js b/src/adaptors/primex-finance/utils.js index 2bffc6b301..6f62dc4db2 100644 --- a/src/adaptors/primex-finance/utils.js +++ b/src/adaptors/primex-finance/utils.js @@ -1,56 +1,85 @@ -const DEAD_ADDRESS = '0x000000000000000000000000000000000000dEaD' +const DEAD_ADDRESS = '0x000000000000000000000000000000000000dEaD'; const SECONDS_PER_YEAR = 31536000; const ROLES = { LENDER: 0, - TRADER: 1 -} + TRADER: 1, +}; const CHAIN_IDS = { Ethereum: 'ethereum', Arbitrum: 'arbitrum_one', Polygon: 'polygon_mainnet', + Base: 'base', }; const APY_REWARD_BONUS = 7; const config = [ + { + chain: 'Base', + lensAddress: '0x636177fa2629927500f0d7946b46d6275d2b01d2', + bucketsFactory: [ + '0xcf552c38a0ecb51982af28d4e475bef27ac2dd25', + '0x8e8792881227e8fee8a9e05a567a44d3fa04a7f0', + ], + positionManager: '0x01ed183275956dbd0064b789b778ca0921e695e9', + }, { chain: 'Polygon', - lensAddress: '0xe84C7913dec4f1191F0b7ef7fb54c3E60DA2DF0B', - bucketsFactory: ['0x7E6915D307F434E4171cCee90e180f5021c60089', "0x9649CfDCfAa9c80907e63dD9Cb161cBA2033F3A0"], + lensAddress: '0xfd5BB42E9B647d316c9c0356D368F09505D0F584', + bucketsFactory: [ + '0x7E6915D307F434E4171cCee90e180f5021c60089', + '0x9649CfDCfAa9c80907e63dD9Cb161cBA2033F3A0', + ], positionManager: '0x02bcaA4633E466d151b34112608f60A82a4F6035', - USDCE: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", - EPMX: "0xDc6D1bd104E1efa4A1bf0BBCf6E0BD093614E31A", - EPMXPriceFeed: "0x103A9FF33c709405DF58f8f209C53f6B5c5eA2BE", + USDCE: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', + EPMX: '0xDc6D1bd104E1efa4A1bf0BBCf6E0BD093614E31A', + EPMXPriceFeed: '0x103A9FF33c709405DF58f8f209C53f6B5c5eA2BE', EPMXPriceFeedDecimals: 8, }, { chain: 'Arbitrum', - lensAddress: '0x9b3bdb43E43422d789FE4977d63Af76C3159F6C6', - bucketsFactory: ['0x4e6f7372bCE4083c779c17B240A94dc2EA57AE67', "0xB4d3A9f10D3D687FaF3b05b9aa3054856A1d7be8"], + lensAddress: '0xa057c1464dD31B3Aacf72Ef3470E0dA9548e551f', + bucketsFactory: [ + '0x4e6f7372bCE4083c779c17B240A94dc2EA57AE67', + '0xB4d3A9f10D3D687FaF3b05b9aa3054856A1d7be8', + ], positionManager: '0x86890E30cE9E1e13Db5560BbEb435c55567Af1cd', - USDCE: "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8", - EPMX: "0xA533f744B179F2431f5395978e391107DC76e103", - EPMXPriceFeed: "0x053FB5b7c555FC0d9Bc49118023d6B6A4019168f", + USDCE: '0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8', + EPMX: '0xA533f744B179F2431f5395978e391107DC76e103', + EPMXPriceFeed: '0x053FB5b7c555FC0d9Bc49118023d6B6A4019168f', + EPMXPriceFeedDecimals: 8, + }, + { + chain: 'Ethereum', + lensAddress: '0xa5b9Fc7038d5e3b054249cf89A065b3Bb15D0d28', + bucketsFactory: [ + '0x7dE8607157124c894Ba9F18dd6138B5E8AAd5890', + '0x55120da310A0c5fd81Fd3bb8C177F6649bE30ACc', + ], + positionManager: '0x99d63fEA4b3Ef6ca77941df3C5740dAd1586f0B8', + EPMX: '0xA533f744B179F2431f5395978e391107DC76e103', + EPMXPriceFeed: '0xF146a76F3Aa82D4cEa3eaB44932b7eE75737E11a', EPMXPriceFeedDecimals: 8, }, - // { - // chain: 'Ethereum', - // lensAddress: '0xa1690975FBd39dfCdCEf14726cF87662746E91d3', - // bucketsFactory: ['0x7dE8607157124c894Ba9F18dd6138B5E8AAd5890', "0x55120da310A0c5fd81Fd3bb8C177F6649bE30ACc"], - // positionManager: '0x99d63fEA4b3Ef6ca77941df3C5740dAd1586f0B8', - // EPMX: "0xA533f744B179F2431f5395978e391107DC76e103", - // EPMXPriceFeed: "0xF146a76F3Aa82D4cEa3eaB44932b7eE75737E11a", - // EPMXPriceFeedDecimals: 8, - // } -] +]; -const getPoolUrl = (address, chain) => `https://app.primex.finance/#/bucket-details/${address}?network=${CHAIN_IDS[chain]}`; +const getPoolUrl = (address, chain) => + `https://app.primex.finance/#/bucket-details/${address}?network=${CHAIN_IDS[chain]}`; const addressEq = (addressA, addressB) => { if (!addressA || !addressB) return false; return addressA.toLowerCase() === addressB.toLowerCase(); -} +}; -module.exports = { DEAD_ADDRESS, SECONDS_PER_YEAR, ROLES, CHAIN_IDS, APY_REWARD_BONUS, config, getPoolUrl, addressEq } \ No newline at end of file +module.exports = { + DEAD_ADDRESS, + SECONDS_PER_YEAR, + ROLES, + CHAIN_IDS, + APY_REWARD_BONUS, + config, + getPoolUrl, + addressEq, +}; From f8151c2da516ec17cc7cf139ff62c85bb8e2c443 Mon Sep 17 00:00:00 2001 From: pavlo-tolok Date: Fri, 3 Jan 2025 12:06:33 +0100 Subject: [PATCH 4/7] FEAT/PRIM-6971:Add try catch --- src/adaptors/primex-finance/index.js | 56 +++++++++++++++------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/adaptors/primex-finance/index.js b/src/adaptors/primex-finance/index.js index 6e5b23c216..39ea407066 100644 --- a/src/adaptors/primex-finance/index.js +++ b/src/adaptors/primex-finance/index.js @@ -136,33 +136,37 @@ const getPools = async (config) => { const limit = 3; while (true) { - const result = ( - await sdk.api.abi.call({ - abi: abi.getAllBucketsFactory, - target: lensAddress, - chain: chain.toLowerCase(), - params: [ - bucketsFactory, - DEAD_ADDRESS, - positionManager, - false, - offset, - limit, - ], - }) - ).output; - - if ( - (Array.isArray(result) && - Array.isArray(result[0]) && - result[0].length === 0) || - JSON.stringify(result) === JSON.stringify([[], '0']) - ) { - break; + try { + const result = ( + await sdk.api.abi.call({ + abi: abi.getAllBucketsFactory, + target: lensAddress, + chain: chain.toLowerCase(), + params: [ + bucketsFactory, + DEAD_ADDRESS, + positionManager, + false, + offset, + limit, + ], + }) + ).output; + + if ( + (Array.isArray(result) && + Array.isArray(result[0]) && + result[0].length === 0) || + JSON.stringify(result) === JSON.stringify([[], '0']) + ) { + break; + } + + bucketsArr = bucketsArr.concat(result); + offset += limit; + } catch (error) { + console.error(error); } - - bucketsArr = bucketsArr.concat(result); - offset += limit; } return await Promise.all( From f8a759edf637825c10f16480502c2743c468b38a Mon Sep 17 00:00:00 2001 From: pavlo-tolok Date: Fri, 3 Jan 2025 12:09:42 +0100 Subject: [PATCH 5/7] FEAT/PRIM-6971:Add break --- src/adaptors/primex-finance/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/adaptors/primex-finance/index.js b/src/adaptors/primex-finance/index.js index 39ea407066..fa97752b44 100644 --- a/src/adaptors/primex-finance/index.js +++ b/src/adaptors/primex-finance/index.js @@ -166,6 +166,7 @@ const getPools = async (config) => { offset += limit; } catch (error) { console.error(error); + break } } From 4f32122f8a348e28d402a90c76c4e58b747b0590 Mon Sep 17 00:00:00 2001 From: pavlo-tolok Date: Fri, 3 Jan 2025 16:47:03 +0100 Subject: [PATCH 6/7] FEAT/PRIM-6971: Fix bugs --- src/adaptors/primex-finance/index.js | 45 +++++++--------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/src/adaptors/primex-finance/index.js b/src/adaptors/primex-finance/index.js index fa97752b44..1b2de03585 100644 --- a/src/adaptors/primex-finance/index.js +++ b/src/adaptors/primex-finance/index.js @@ -27,7 +27,7 @@ const formatPool = async (bucket, config) => { estimatedLar, miningParams, name, - } = bucket[0]; + } = bucket; const { chain, EPMX, USDCE, apyRewardBySymbol } = config; @@ -75,7 +75,6 @@ const formatPool = async (bucket, config) => { tvlUsd, apyBase, apyReward, - rewardTokens: [EPMX], underlyingTokens, url: getPoolUrl(bucketAddress, chain), apyBaseBorrow, @@ -91,42 +90,22 @@ const getPools = async (config) => { lensAddress, bucketsFactory, positionManager, - EPMX, - EPMXPriceFeed, - EPMXPriceFeedDecimals, } = config; if (chain === 'Ethereum') { sdk.api.config.setProvider( 'ethereum', new ethers.providers.JsonRpcProvider( - 'https://lb.drpc.org/ogrpc?network=ethereum&dkey=AhjAIUax7EMFtu9ErxcXVpiWXqG_mFMR7oB-goai82vO' + "https://lb.drpc.org/ogrpc?network=ethereum&dkey=AhjAIUax7EMFtu9ErxcXVpjOZcogyegR77I1IlZWwHzR" ) ); } - if (chain === 'Arbitrum') { - sdk.api.config.setProvider( - 'ethereum', - new ethers.providers.JsonRpcProvider( - 'https://lb.drpc.org/ogrpc?network=arbitrum&dkey=AhjAIUax7EMFtu9ErxcXVpgEW9szfIYR7qRQxqxINsn1' - ) - ); - } - - if (chain === 'Polygon') { - sdk.api.config.setProvider( - 'ethereum', - new ethers.providers.JsonRpcProvider( - 'https://lb.drpc.org/ogrpc?network=polygon&dkey=AhjAIUax7EMFtu9ErxcXVpinS0aAWWER7oTEFnomaLKw' - ) - ); - } if (chain === 'Base') { sdk.api.config.setProvider( 'base', new ethers.providers.JsonRpcProvider( - 'https://lb.drpc.org/ogrpc?network=base&dkey=AhjAIUax7EMFtu9ErxcXVpg7GmZNgi4R74QSKjW4AN0P' + 'https://lb.drpc.org/ogrpc?network=base&dkey=AhjAIUax7EMFtu9ErxcXVpjOZcogyegR77I1IlZWwHzR' ) ); } @@ -153,27 +132,25 @@ const getPools = async (config) => { }) ).output; - if ( - (Array.isArray(result) && - Array.isArray(result[0]) && - result[0].length === 0) || - JSON.stringify(result) === JSON.stringify([[], '0']) - ) { + if (result[0].length !== 0) { + bucketsArr = bucketsArr.concat(result[0]); + } + + if (result[1] === '0') { break; } - bucketsArr = bucketsArr.concat(result); offset += limit; } catch (error) { console.error(error); - break + break; } } - + return await Promise.all( bucketsArr .filter((bucket) => { - const miningParams = bucket[0]?.miningParams; + const miningParams = bucket.miningParams; const isMiningFailed = !miningParams?.isBucketLaunched && miningParams?.deadlineTimestamp * 1000 <= Date.now(); From 6e7557b3fcf47a26d000ed26ccf474dd369d8fbf Mon Sep 17 00:00:00 2001 From: pavlo-tolok Date: Sat, 4 Jan 2025 11:31:01 +0100 Subject: [PATCH 7/7] FEAT/PRIM-6971: Fix bugs v2 --- src/adaptors/primex-finance/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/adaptors/primex-finance/index.js b/src/adaptors/primex-finance/index.js index 1b2de03585..dc2b0d0d48 100644 --- a/src/adaptors/primex-finance/index.js +++ b/src/adaptors/primex-finance/index.js @@ -109,7 +109,6 @@ const getPools = async (config) => { ) ); } - let bucketsArr = []; let offset = 0; const limit = 3;