-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,6 +222,7 @@ | |
"rage-trade", | ||
"railgun", | ||
"redacted", | ||
"reflexer", | ||
"reserve", | ||
"ribbon-finance", | ||
"rocket-pool", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import type { Balance, BalancesContext, BorrowBalance, LendBalance } from '@lib/adapter' | ||
import type { Token } from '@lib/token' | ||
import request, { gql } from 'graphql-request' | ||
|
||
const WETH: Token = { | ||
chain: 'ethereum', | ||
address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', | ||
decimals: 18, | ||
symbol: 'WETH', | ||
} | ||
|
||
const RAI: Token = { | ||
chain: 'ethereum', | ||
address: '0x03ab458634910aad20ef5f1c8ee96f1d6ac54919', | ||
decimals: 18, | ||
symbol: 'RAI', | ||
} | ||
|
||
interface ReflexerLendBalancesParams extends LendBalance { | ||
proxy: `0x${string}` | ||
safe: { safeHandler: `0x${string}`; safeId: number } | ||
} | ||
|
||
interface ReflexerBorrowBalancesParams extends BorrowBalance { | ||
proxy: `0x${string}` | ||
safe: { safeHandler: `0x${string}`; safeId: number } | ||
} | ||
|
||
const url = 'https://api.thegraph.com/subgraphs/name/reflexer-labs/rai-mainnet' | ||
|
||
export async function getReflexerFarmBalancesWithProxies(ctx: BalancesContext): Promise<Balance[]> { | ||
const query = gql` | ||
query proxies { | ||
user(id: "${ctx.address}") { | ||
id | ||
proxies { | ||
id | ||
} | ||
safes { | ||
safeHandler | ||
safeId | ||
debt | ||
collateral | ||
} | ||
} | ||
} | ||
` | ||
|
||
const res: any = await request(url, query) | ||
|
||
const balances: Balance[] = res.user.safes.flatMap((safe: any) => { | ||
const { safeHandler, safeId, collateral, debt } = safe | ||
|
||
const lend: ReflexerLendBalancesParams = { | ||
chain: 'ethereum', | ||
address: WETH.address, | ||
proxy: res.user.proxies[0].id, | ||
safe: { safeHandler, safeId }, | ||
amount: BigInt(Math.round(collateral * Math.pow(10, WETH.decimals))), | ||
underlyings: undefined, | ||
rewards: undefined, | ||
category: 'lend', | ||
} | ||
|
||
const borrow: ReflexerBorrowBalancesParams = { | ||
chain: 'ethereum', | ||
address: RAI.address, | ||
proxy: res.user.proxies[0].id, | ||
safe: { safeHandler, safeId }, | ||
amount: BigInt(Math.round(debt * Math.pow(10, RAI.decimals))), | ||
underlyings: undefined, | ||
rewards: undefined, | ||
category: 'borrow', | ||
} | ||
|
||
return [lend, borrow] | ||
}) | ||
|
||
return balances | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { getReflexerFarmBalancesWithProxies } from '@adapters/reflexer/ethereum/farm' | ||
import { getReflexerStakeBalances } from '@adapters/reflexer/ethereum/stake' | ||
import type { BaseContext, Contract, GetBalancesHandler } from '@lib/adapter' | ||
import { resolveBalances } from '@lib/balance' | ||
|
||
const RAI: Contract = { | ||
chain: 'ethereum', | ||
address: '0x03ab458634910aad20ef5f1c8ee96f1d6ac54919', | ||
decimals: 18, | ||
symbol: 'RAI', | ||
} | ||
|
||
const FLX_ETH: Contract = { | ||
chain: 'ethereum', | ||
address: '0x69c6c08b91010c88c95775b6fd768e5b04efc106', | ||
token: '0xd6F3768E62Ef92a9798E5A8cEdD2b78907cEceF9', | ||
underlyings: ['0x6243d8CEA23066d098a15582d81a598b4e8391F4', '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'], | ||
} | ||
|
||
export const getContracts = async (_ctx: BaseContext) => { | ||
return { | ||
contracts: { FLX_ETH, RAI }, | ||
} | ||
} | ||
|
||
export const getBalances: GetBalancesHandler<typeof getContracts> = async (ctx, contracts) => { | ||
const balances = await resolveBalances<typeof getContracts>(ctx, contracts, { | ||
FLX_ETH: getReflexerStakeBalances, | ||
RAI: getReflexerFarmBalancesWithProxies, | ||
}) | ||
|
||
return { | ||
groups: [{ balances }], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { Balance, BalancesContext, Contract } from '@lib/adapter' | ||
import { call } from '@lib/call' | ||
import { getUnderlyingBalances } from '@lib/uniswap/v2/pair' | ||
|
||
const abi = { | ||
descendantBalanceOf: { | ||
inputs: [{ internalType: 'address', name: '', type: 'address' }], | ||
name: 'descendantBalanceOf', | ||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
} as const | ||
|
||
export async function getReflexerStakeBalances(ctx: BalancesContext, staker: Contract): Promise<Balance[]> { | ||
const userBalance = await call({ ctx, target: staker.address, params: [ctx.address], abi: abi.descendantBalanceOf }) | ||
|
||
return getUnderlyingBalances(ctx, [ | ||
{ | ||
...staker, | ||
address: staker.token!, | ||
amount: userBalance, | ||
underlyings: staker.underlyings as Contract[], | ||
rewards: undefined, | ||
category: 'stake', | ||
}, | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { Adapter } from '@lib/adapter' | ||
|
||
import * as ethereum from './ethereum' | ||
|
||
const adapter: Adapter = { | ||
id: 'reflexer', | ||
ethereum, | ||
} | ||
|
||
export default adapter |