diff --git a/adapters/rollie/src/abi/Erc20.ts b/adapters/rollie/src/abi/Erc20.ts new file mode 100644 index 0000000..e57ff45 --- /dev/null +++ b/adapters/rollie/src/abi/Erc20.ts @@ -0,0 +1,124 @@ +const Erc20Abi = [{ + "inputs": [{"internalType": "address", "name": "to", "type": "address"}, { + "internalType": "uint256", + "name": "initSupply", + "type": "uint256" + }], "stateMutability": "nonpayable", "type": "constructor" +}, { + "anonymous": false, + "inputs": [{"indexed": true, "internalType": "address", "name": "owner", "type": "address"}, { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, {"indexed": false, "internalType": "uint256", "name": "value", "type": "uint256"}], + "name": "Approval", + "type": "event" +}, { + "anonymous": false, + "inputs": [{"indexed": true, "internalType": "address", "name": "from", "type": "address"}, { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, {"indexed": false, "internalType": "uint256", "name": "value", "type": "uint256"}], + "name": "Transfer", + "type": "event" +}, { + "inputs": [{"internalType": "address", "name": "owner", "type": "address"}, { + "internalType": "address", + "name": "spender", + "type": "address" + }], + "name": "allowance", + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [{"internalType": "address", "name": "spender", "type": "address"}, { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }], + "name": "approve", + "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{"internalType": "address", "name": "account", "type": "address"}], + "name": "balanceOf", + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [{"internalType": "uint256", "name": "amount", "type": "uint256"}], + "name": "burn", + "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [], + "name": "decimals", + "outputs": [{"internalType": "uint8", "name": "", "type": "uint8"}], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [{"internalType": "address", "name": "spender", "type": "address"}, { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + }], + "name": "decreaseAllowance", + "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{"internalType": "address", "name": "spender", "type": "address"}, { + "internalType": "uint256", + "name": "addedValue", + "type": "uint256" + }], + "name": "increaseAllowance", + "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [], + "name": "name", + "outputs": [{"internalType": "string", "name": "", "type": "string"}], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [], + "name": "symbol", + "outputs": [{"internalType": "string", "name": "", "type": "string"}], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [], + "name": "totalSupply", + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "stateMutability": "view", + "type": "function" +}, { + "inputs": [{"internalType": "address", "name": "to", "type": "address"}, { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }], + "name": "transfer", + "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], + "stateMutability": "nonpayable", + "type": "function" +}, { + "inputs": [{"internalType": "address", "name": "from", "type": "address"}, { + "internalType": "address", + "name": "to", + "type": "address" + }, {"internalType": "uint256", "name": "amount", "type": "uint256"}], + "name": "transferFrom", + "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], + "stateMutability": "nonpayable", + "type": "function" +}] +export default Erc20Abi; diff --git a/adapters/rollie/src/index.ts b/adapters/rollie/src/index.ts index f4f191e..74c57e4 100644 --- a/adapters/rollie/src/index.ts +++ b/adapters/rollie/src/index.ts @@ -10,20 +10,18 @@ import { write } from 'fast-csv'; import { pipeline as streamPipeline } from 'stream'; import * as converter from "json-2-csv"; -console.log("converter", converter) - import TradingVaultABI from "./abi/TradingVault"; -import {containsNodeError} from "viem/utils"; import {resolve} from "path"; -import convert from "lodash/fp/convert"; +import Erc20Abi from "./abi/Erc20"; const PairInfoAddress = "0xA852CE8B0BF3Bcd9191D6140a4627E7823c84848"; -const TradingVaultAddress = "0xA79E00e68549e91e5f0c27048F453b3D87ef6E3D" +const TradingVaultAddress = "0xA79E00e68549e91e5f0c27048F453b3D87ef6E3D"; +const USDCAddress = "0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4"; const SubgrapnUrl = "https://api.studio.thegraph.com/query/76203/rollie-finance/0.0.2"; const RPCs = [ + "https://scroll.drpc.org", "https://scroll.blockpi.network/v1/rpc/public", "https://scroll-mainnet.chainstacklabs.com", - "https://scroll.drpc.org" ]; const USDC_DECIMALS = 6; const RLP_DECIMALS = 6; @@ -93,6 +91,11 @@ const TradingVaultContract = { address: TradingVaultAddress as Address, } +const USDCContract = { + abi: Erc20Abi as any, + address: USDCAddress as Address, +} + interface Pair { funding_rate: { long: string, @@ -189,6 +192,7 @@ interface User { closeCount: string amountGainRate: string staked: string, + user_balance_usdc: string, } async function getAllUser(lastRequest: User[], page: number = 0, block: BlockData): Promise { @@ -213,12 +217,18 @@ async function getAllUser(lastRequest: User[], page: number = 0, block: BlockDat const allUsers = [...lastRequest, ...users] console.log("Finish load users ..."); // get all staked value - const calls = allUsers.map((item: User) => { - return { + const calls: any[] = []; + allUsers.forEach((item: User) => { + calls.push({ ...TradingVaultContract, functionName: "balanceOf", args: [item.id], - } + }) + calls.push({ + ...USDCContract, + functionName: "balanceOf", + args: [item.id], + }) }) calls.push({ ...TradingVaultContract, @@ -235,12 +245,17 @@ async function getAllUser(lastRequest: User[], page: number = 0, block: BlockDat const pps = result[result.length - 1]; return allUsers.map((item, index) => { const staked = formatUnits( - (result[index] * pps ) / (10n ** BigInt(PPS_DECIMALS)), + (result[index * 2] * pps ) / (10n ** BigInt(PPS_DECIMALS)), RLP_DECIMALS ); + const user_balance_usdc = formatUnits( + (result[index * 2 + 1]) , + USDC_DECIMALS + ) return { ...item, staked, + user_balance_usdc } }); } @@ -294,6 +309,7 @@ interface Result { protocol_fees_usd: number; users_fees_usd: number; etl_timestamp: number; + user_balance_usdc: string; } // const endTime = Math.ceil(Date.now() / 1000); @@ -419,6 +435,7 @@ function generateUserData(user: User, openOrders: OpenOrder[], closedOrders: Clo open_longs_usd: pairData.open_longs, protocol_fees_usd: pairData.protocol_fees, users_fees_usd: pairData.users_fees, + user_balance_usdc: user.user_balance_usdc, } }) }