This commit is contained in:
Richa-iitr 2022-10-27 15:04:23 +05:30
parent 5f94d4bd88
commit e79e9c4841
6 changed files with 3995 additions and 70 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
node_modules
generated
build

View File

@ -1,9 +1,21 @@
[ [
{ {
"inputs": [ "inputs": [
{ "internalType": "address", "name": "_logic", "type": "address" }, {
{ "internalType": "address", "name": "admin_", "type": "address" }, "internalType": "address",
{ "internalType": "bytes", "name": "_data", "type": "bytes" } "name": "_logic",
"type": "address"
},
{
"internalType": "address",
"name": "admin_",
"type": "address"
},
{
"internalType": "bytes",
"name": "_data",
"type": "bytes"
}
], ],
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "constructor" "type": "constructor"
@ -53,19 +65,30 @@
"name": "Upgraded", "name": "Upgraded",
"type": "event" "type": "event"
}, },
{ "stateMutability": "payable", "type": "fallback" }, {
"stateMutability": "payable",
"type": "fallback"
},
{ {
"inputs": [], "inputs": [],
"name": "admin", "name": "admin",
"outputs": [ "outputs": [
{ "internalType": "address", "name": "admin_", "type": "address" } {
"internalType": "address",
"name": "admin_",
"type": "address"
}
], ],
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function" "type": "function"
}, },
{ {
"inputs": [ "inputs": [
{ "internalType": "address", "name": "newAdmin", "type": "address" } {
"internalType": "address",
"name": "newAdmin",
"type": "address"
}
], ],
"name": "changeAdmin", "name": "changeAdmin",
"outputs": [], "outputs": [],
@ -105,12 +128,402 @@
"name": "newImplementation", "name": "newImplementation",
"type": "address" "type": "address"
}, },
{ "internalType": "bytes", "name": "data", "type": "bytes" } {
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
], ],
"name": "upgradeToAndCall", "name": "upgradeToAndCall",
"outputs": [], "outputs": [],
"stateMutability": "payable", "stateMutability": "payable",
"type": "function" "type": "function"
}, },
{ "stateMutability": "payable", "type": "receive" } {
"stateMutability": "payable",
"type": "receive"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "account",
"type": "address"
},
{
"indexed": true,
"internalType": "uint256",
"name": "route",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address[]",
"name": "tokens",
"type": "address[]"
},
{
"indexed": false,
"internalType": "uint256[]",
"name": "amounts",
"type": "uint256[]"
}
],
"name": "LogFlashloan",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "oldOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "updateOwnerLog",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "account",
"type": "address"
},
{
"indexed": true,
"internalType": "bool",
"name": "isWhitelisted_",
"type": "bool"
}
],
"name": "updateWhitelistLog",
"type": "event"
},
{
"inputs": [],
"name": "InstaFeeBPS",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address[]",
"name": "_cTokens",
"type": "address[]"
}
],
"name": "addTokenToCToken",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_route",
"type": "uint256"
},
{
"internalType": "address",
"name": "account_",
"type": "address"
}
],
"name": "calculateFeeBPS",
"outputs": [
{
"internalType": "uint256",
"name": "BPS_",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address[]",
"name": "_assets",
"type": "address[]"
},
{
"internalType": "uint256[]",
"name": "_amounts",
"type": "uint256[]"
},
{
"internalType": "uint256[]",
"name": "_premiums",
"type": "uint256[]"
},
{
"internalType": "address",
"name": "_initiator",
"type": "address"
},
{
"internalType": "bytes",
"name": "_data",
"type": "bytes"
}
],
"name": "executeOperation",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address[]",
"name": "_tokens",
"type": "address[]"
},
{
"internalType": "uint256[]",
"name": "_amounts",
"type": "uint256[]"
},
{
"internalType": "uint256",
"name": "_route",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "_data",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "",
"type": "bytes"
}
],
"name": "flashLoan",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "getRoutes",
"outputs": [
{
"internalType": "uint16[]",
"name": "routes_",
"type": "uint16[]"
}
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner_",
"type": "address"
}
],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "isWhitelisted",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_initiator",
"type": "address"
},
{
"internalType": "address",
"name": "",
"type": "address"
},
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_fee",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "_data",
"type": "bytes"
}
],
"name": "onFlashLoan",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "contract IERC20[]",
"name": "",
"type": "address[]"
},
{
"internalType": "uint256[]",
"name": "_amounts",
"type": "uint256[]"
},
{
"internalType": "uint256[]",
"name": "_fees",
"type": "uint256[]"
},
{
"internalType": "bytes",
"name": "_data",
"type": "bytes"
}
],
"name": "receiveFlashLoan",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "tokenToCToken",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address[]",
"name": "_tokens",
"type": "address[]"
}
],
"name": "transferFeeToTreasury",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner_",
"type": "address"
}
],
"name": "updateOwner",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account_",
"type": "address"
},
{
"internalType": "bool",
"name": "whitelist_",
"type": "bool"
}
],
"name": "updateWhitelist",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"stateMutability": "payable",
"type": "receive"
}
] ]

View File

@ -1,6 +1,8 @@
type ExampleEntity @entity { type FeeData @entity {
# user + '#' + token address
id: ID! id: ID!
count: BigInt! user: Bytes!
previousAdmin: Bytes! # address token: Bytes!
newAdmin: Bytes! # address flaFee: Int!
routeFee: Int!
} }

View File

@ -1,55 +1,113 @@
import { BigInt } from "@graphprotocol/graph-ts" import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { import {
ExecuteOperationCall,
FLA, FLA,
AdminChanged, OnFlashLoanCall,
BeaconUpgraded, ReceiveFlashLoanCall,
Upgraded } from "../generated/FLA/FLA";
} from "../generated/FLA/FLA" import { FeeData } from "../generated/schema";
import { ExampleEntity } from "../generated/schema"
export function handleAdminChanged(event: AdminChanged): void { // const DAI = new Address(0x6b175474e89094c44da98b954eedeac495271d0f);
// Entities can be loaded from the store using a string ID; this ID export function handleExecuteOperation(call: ExecuteOperationCall): void {
// needs to be unique across all entities of the same type // let assets = call.inputs._assets;
let entity = ExampleEntity.load(event.transaction.from.toHex()) // let amounts = call.inputs._amounts;
// let user = call.inputs._initiator;
let fees = call.inputs._premiums;
let length = fees.length;
let data_ = call.inputs._data;
// Entities only exist after they have been saved to the store; let decoded = ethereum.decode("(uint256,address[],uint256[],address,bytes)", data_)?.toTuple();
// `null` checks allow to create entities on demand if (decoded != undefined) {
if (!entity) { let tokens = decoded[1].toArray();
entity = new ExampleEntity(event.transaction.from.toHex()) let amounts = decoded[2].toArray();
let user = decoded[3].toAddress();
// Entity fields can be set using simple assignments for (let i = 0; i < length; i++) {
entity.count = BigInt.fromI32(0) let id = user.toHexString() + "#" + tokens[i].toAddress().toHexString();
let data = createOrLoadFeeData(id);
data.user = user;
data.token = tokens[i].toAddress();
let instaAmt_ = amounts[i]
.toBigInt()
.times(BigInt.fromI32(5))
.div(BigInt.fromI32(1e4));
if (instaAmt_ > fees[i]) {
data.flaFee += instaAmt_.minus(fees[i]).toI32();
}
data.routeFee += fees[i].toI32();
data.save();
}
} }
// BigInt and BigDecimal math are supported
entity.count = entity.count + BigInt.fromI32(1)
// Entity fields can be set based on event parameters
entity.previousAdmin = event.params.previousAdmin
entity.newAdmin = event.params.newAdmin
// Entities can be written to the store with `.save()`
entity.save()
// Note: If a handler doesn't require existing field values, it is faster
// _not_ to load the entity from the store. Instead, create it fresh with
// `new Entity(...)`, set the fields that should be updated and save the
// entity back to the store. Fields that were not set or unset remain
// unchanged, allowing for partial updates to be applied.
// It is also possible to access smart contracts from mappings. For
// example, the contract that has emitted the event can be connected to
// with:
//
// let contract = Contract.bind(event.address)
//
// The following functions can then be called on this contract to access
// state variables and other data:
//
// - contract.admin(...)
// - contract.implementation(...)
} }
export function handleBeaconUpgraded(event: BeaconUpgraded): void {} export function handleOnFlashloan(call: OnFlashLoanCall): void {
// let amount = call.inputs._amount;
let fee = call.inputs._fee;
let data_ = call.inputs._data;
let decoded = ethereum.decode("(uint256,address[],uint256[],address,bytes)", data_)?.toTuple();
if (decoded != undefined) {
let tokens = decoded[1].toArray();
let amounts = decoded[2].toArray();
let user = decoded[3].toAddress();
export function handleUpgraded(event: Upgraded): void {} for (let i = 0; i < tokens.length; i++) {
let id = user.toHexString() + "#" + tokens[i].toAddress().toHexString();
let data = createOrLoadFeeData(id);
data.user = user;
data.token = tokens[i].toAddress();
let instaAmt_ = amounts[i]
.toBigInt()
.times(BigInt.fromI32(5))
.div(BigInt.fromI32(1e4));
if (instaAmt_ > fee) {
data.flaFee += instaAmt_.minus(fee).toI32();
}
data.routeFee += fee.toI32();
data.save();
}
}
}
export function handleReceiveFlashloan(call: ReceiveFlashLoanCall): void {
let fees = call.inputs._fees;
let length = fees.length;
let data_ = call.inputs._data;
let decoded = ethereum.decode("(uint256,address[],uint256[],address,bytes)", data_)?.toTuple();
if (decoded != undefined) {
let tokens = decoded[1].toArray();
let amounts = decoded[2].toArray();
let user = decoded[3].toAddress();
for (let i = 0; i < length; i++) {
let id = user.toHexString() + "#" + tokens[i].toAddress().toHexString();
let data = createOrLoadFeeData(id);
data.user = user;
data.token = tokens[i].toAddress();
let instaAmt_ = amounts[i]
.toBigInt()
.times(BigInt.fromI32(5))
.div(BigInt.fromI32(1e4));
if (instaAmt_ > fees[i]) {
data.flaFee += instaAmt_.minus(fees[i]).toI32();
}
data.routeFee += fees[i].toI32();
data.save();
}
}
}
export function createOrLoadFeeData(id: string): FeeData {
let data = FeeData.load(id);
if (data == null) {
data = new FeeData(id);
data.user = new Address(0);
data.token = new Address(0);
data.flaFee = 0;
data.routeFee = 0;
}
return data;
}

View File

@ -1,4 +1,4 @@
specVersion: 0.0.1 specVersion: 0.0.4
schema: schema:
file: ./schema.graphql file: ./schema.graphql
dataSources: dataSources:
@ -10,20 +10,18 @@ dataSources:
abi: FLA abi: FLA
mapping: mapping:
kind: ethereum/events kind: ethereum/events
apiVersion: 0.0.5 apiVersion: 0.0.6
language: wasm/assemblyscript language: wasm/assemblyscript
entities: entities:
- AdminChanged - FeeData
- BeaconUpgraded
- Upgraded
abis: abis:
- name: FLA - name: FLA
file: ./abis/FLA.json file: ./abis/FLA.json
eventHandlers: callHandlers:
- event: AdminChanged(address,address) - function: executeOperation(address[],uint256[],uint256[],address,bytes)
handler: handleAdminChanged handler: handleExecuteOperation
- event: BeaconUpgraded(indexed address) - function: onFlashLoan(address,address,uint256,uint256,bytes)
handler: handleBeaconUpgraded handler: handleOnFlashloan
- event: Upgraded(indexed address) - function: receiveFlashLoan(address[],uint256[],uint256[],bytes)
handler: handleUpgraded handler: handleReceiveFlashloan
file: ./src/fla.ts file: ./src/fla.ts

3451
yarn.lock Normal file

File diff suppressed because it is too large Load Diff