-
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
7 changed files
with
158 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
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,30 @@ | ||
import { getKarakStakeBalances } from '@adapters/karak/common/balance' | ||
import { getKarakTokens } from '@adapters/karak/common/contract' | ||
import type { AdapterConfig, BaseContext, Contract, GetBalancesHandler } from '@lib/adapter' | ||
import { resolveBalances } from '@lib/balance' | ||
|
||
const supervisor: Contract = { | ||
chain: 'arbitrum', | ||
address: '0x399f22ae52a18382a67542b3de9bed52b7b9a4ad', | ||
} | ||
|
||
export const getContracts = async (ctx: BaseContext) => { | ||
const staker = await getKarakTokens(ctx, supervisor) | ||
return { | ||
contracts: { staker }, | ||
} | ||
} | ||
|
||
export const getBalances: GetBalancesHandler<typeof getContracts> = async (ctx, contracts) => { | ||
const balances = await resolveBalances<typeof getContracts>(ctx, contracts, { | ||
staker: getKarakStakeBalances, | ||
}) | ||
|
||
return { | ||
groups: [{ balances }], | ||
} | ||
} | ||
|
||
export const config: AdapterConfig = { | ||
startDate: 1712620800, | ||
} |
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,47 @@ | ||
import type { Balance, BalancesContext, Contract } from '@lib/adapter' | ||
import { call } from '@lib/call' | ||
import type { Category } from '@lib/category' | ||
import { isNotNullish } from '@lib/type' | ||
|
||
const abi = { | ||
getDeposits: { | ||
inputs: [{ internalType: 'address', name: 'staker', type: 'address' }], | ||
name: 'getDeposits', | ||
outputs: [ | ||
{ internalType: 'contract IVault[]', name: 'vaults', type: 'address[]' }, | ||
{ internalType: 'contract IERC20[]', name: 'tokens', type: 'address[]' }, | ||
{ internalType: 'uint256[]', name: 'assets', type: 'uint256[]' }, | ||
{ internalType: 'uint256[]', name: 'shares', type: 'uint256[]' }, | ||
], | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
} as const | ||
|
||
export async function getKarakStakeBalances(ctx: BalancesContext, staker: Contract): Promise<Balance[]> { | ||
const underlyings = staker.underlyings as Contract[] | ||
if (!underlyings) return [] | ||
|
||
const [_vaults, tokens, assets, _shares] = await call({ | ||
ctx, | ||
target: staker.address, | ||
params: [ctx.address], | ||
abi: abi.getDeposits, | ||
}) | ||
|
||
return tokens | ||
.map((token, index) => { | ||
const amount = assets[index] | ||
const underlying = underlyings.find((underlying) => underlying.address.toLowerCase() === token.toLowerCase()) | ||
if (!underlying) return null | ||
|
||
return { | ||
...underlying, | ||
amount, | ||
underlyings: undefined, | ||
rewards: undefined, | ||
category: 'stake' as Category, | ||
} | ||
}) | ||
.filter(isNotNullish) | ||
} |
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,36 @@ | ||
import type { BaseContext, Contract } from '@lib/adapter' | ||
import { mapSuccessFilter } from '@lib/array' | ||
import { call } from '@lib/call' | ||
import { multicall } from '@lib/multicall' | ||
|
||
const abi = { | ||
depositToken: { | ||
inputs: [], | ||
name: 'depositToken', | ||
outputs: [{ internalType: 'contract IERC20', name: '', type: 'address' }], | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
asset: { | ||
inputs: [], | ||
name: 'asset', | ||
outputs: [{ internalType: 'address', name: '', type: 'address' }], | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
getVaults: { | ||
inputs: [], | ||
name: 'getVaults', | ||
outputs: [{ internalType: 'contract IVault[]', name: '', type: 'address[]' }], | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
} as const | ||
|
||
export async function getKarakTokens(ctx: BaseContext, supervisor: Contract): Promise<Contract> { | ||
const vaults = await call({ ctx, target: supervisor.address, abi: abi.getVaults }) | ||
const tokens = await multicall({ ctx, calls: vaults.map((vault) => ({ target: vault })), abi: abi.depositToken }) | ||
|
||
const underlyings = mapSuccessFilter(tokens, (res) => res.output) | ||
return { ...supervisor, underlyings } | ||
} |
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,30 @@ | ||
import { getKarakStakeBalances } from '@adapters/karak/common/balance' | ||
import { getKarakTokens } from '@adapters/karak/common/contract' | ||
import type { AdapterConfig, BaseContext, Contract, GetBalancesHandler } from '@lib/adapter' | ||
import { resolveBalances } from '@lib/balance' | ||
|
||
const supervisor: Contract = { | ||
chain: 'ethereum', | ||
address: '0x54e44dbb92dba848ace27f44c0cb4268981ef1cc', | ||
} | ||
|
||
export const getContracts = async (ctx: BaseContext) => { | ||
const staker = await getKarakTokens(ctx, supervisor) | ||
return { | ||
contracts: { staker }, | ||
} | ||
} | ||
|
||
export const getBalances: GetBalancesHandler<typeof getContracts> = async (ctx, contracts) => { | ||
const balances = await resolveBalances<typeof getContracts>(ctx, contracts, { | ||
staker: getKarakStakeBalances, | ||
}) | ||
|
||
return { | ||
groups: [{ balances }], | ||
} | ||
} | ||
|
||
export const config: AdapterConfig = { | ||
startDate: 1712620800, | ||
} |
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,12 @@ | ||
import type { Adapter } from '@lib/adapter' | ||
|
||
import * as ethereum from './ethereum' | ||
import * as arbitrum from './arbitrum' | ||
|
||
const adapter: Adapter = { | ||
id: 'karak', | ||
ethereum: ethereum, | ||
arbitrum: arbitrum, | ||
} | ||
|
||
export default adapter |