Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update rollie: add user usdc balance data (user_balance_usdc) #17

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions adapters/rollie/src/abi/Erc20.ts
Original file line number Diff line number Diff line change
@@ -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;
37 changes: 27 additions & 10 deletions adapters/rollie/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<User[]> {
Expand All @@ -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,
Expand All @@ -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
}
});
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
}
})
}
Expand Down
Loading