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

Gains network fix #1320

Merged
merged 4 commits into from
Feb 29, 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
17 changes: 11 additions & 6 deletions src/adapters/gains-network/arbitrum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Token } from '@lib/token'

import { getGainsBalances } from '../common/farm'
import { getGainsLockerBalances } from '../common/locker'
import { getsgDAIBalances, getsgGNSBalances } from '../common/stake'
import { getGainsNetworkStakeBalance, getsgGNSBalance } from '../common/stake'

const DAI: Token = {
chain: 'arbitrum',
Expand All @@ -30,31 +30,36 @@ const locker: Contract = {
symbol: 'gNFT-DAI',
}

const sgDAI: Contract = {
const GNS_staking_v6: Contract = {
chain: 'arbitrum',
address: '0x6b8d3c08072a020ac065c467ce922e3a36d3f9d6',
token: '0x18c11fd286c5ec11c3b683caa813b77f5163a122',
rewards: [DAI],
}

const sGNS: Contract = {
chain: 'polygon',
chain: 'arbitrum',
address: '0x7edde7e5900633f698eab0dbc97de640fc5dc015',
token: '0x18c11FD286C5EC11c3b683Caa813B77f5163A122',
rewards: [
'0xda10009cbd5d07dd0cecc66161fc93d7c9000da1',
'0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
'0xaf88d065e77c8cc2239327c5edb3a432268e5831',
],
}

export const getContracts = () => {
return {
contracts: { gDAI, locker, sgDAI, sGNS },
contracts: { gDAI, locker, sGNS, GNS_staking_v6 },
}
}

export const getBalances: GetBalancesHandler<typeof getContracts> = async (ctx, contracts) => {
const balances = await resolveBalances<typeof getContracts>(ctx, contracts, {
gDAI: getGainsBalances,
locker: getGainsLockerBalances,
sgDAI: getsgDAIBalances,
sGNS: getsgGNSBalances,
GNS_staking_v6: getGainsNetworkStakeBalance,
sGNS: getsgGNSBalance,
})

return {
Expand Down
42 changes: 16 additions & 26 deletions src/adapters/gains-network/common/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,16 @@ const abi = {
stateMutability: 'view',
type: 'function',
},
} as const

const DAI: { [key: string]: Contract } = {
polygon: {
chain: 'polygon',
address: '0x8f3cf7ad23cd3cadbd9735aff958023239c6a063',
decimals: 18,
symbol: 'DAI',
},
arbitrum: {
chain: 'arbitrum',
address: '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1',
decimals: 18,
symbol: 'DAI',
pendingRewardTokens: {
inputs: [{ internalType: 'address', name: '_staker', type: 'address' }],
name: 'pendingRewardTokens',
outputs: [{ internalType: 'uint128[]', name: 'pendingTokens', type: 'uint128[]' }],
stateMutability: 'view',
type: 'function',
},
}
} as const

export async function getsgDAIBalances(ctx: BalancesContext, staker: Contract): Promise<Balance> {
export async function getGainsNetworkStakeBalance(ctx: BalancesContext, staker: Contract): Promise<Balance> {
const stakeBalance = await call({
ctx,
target: staker.address,
Expand All @@ -80,8 +72,8 @@ export async function getsgDAIBalances(ctx: BalancesContext, staker: Contract):
}
}

export async function getsgGNSBalances(ctx: BalancesContext, staker: Contract): Promise<Balance> {
const [stakeBalance, pendingRewards, pendingUnlockRewards] = await Promise.all([
export async function getsgGNSBalance(ctx: BalancesContext, staker: Contract): Promise<Balance> {
const [stakeBalance, pendingRewardTokens] = await Promise.all([
call({
ctx,
target: staker.address,
Expand All @@ -92,21 +84,19 @@ export async function getsgGNSBalances(ctx: BalancesContext, staker: Contract):
ctx,
target: staker.address,
params: [ctx.address],
abi: abi.pendingRewardDai,
}),
call({
ctx,
target: staker.address,
params: [ctx.address],
abi: abi.pendingRewardDaiFromUnlocks,
abi: abi.pendingRewardTokens,
}),
])

const rewards = (staker.rewards as Contract[]).map((reward, rewardIdx) => {
return { ...reward, amount: pendingRewardTokens[rewardIdx] }
})

return {
...staker,
amount: stakeBalance,
underlyings: undefined,
rewards: [{ ...DAI[ctx.chain], amount: pendingRewards + pendingUnlockRewards }],
rewards,
category: 'stake',
}
}
15 changes: 10 additions & 5 deletions src/adapters/gains-network/polygon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Token } from '@lib/token'

import { getGainsBalances } from '../common/farm'
import { getGainsLockerBalances } from '../common/locker'
import { getsgDAIBalances, getsgGNSBalances } from '../common/stake'
import { getGainsNetworkStakeBalance, getsgGNSBalance } from '../common/stake'

const DAI: Token = {
chain: 'polygon',
Expand All @@ -30,7 +30,7 @@ const locker: Contract = {
symbol: 'gNFT-DAI',
}

const sgDAI: Contract = {
const GNSStaking: Contract = {
chain: 'polygon',
address: '0xfb06a737f549eb2512eb6082a808fc7f16c0819d',
token: '0xe5417af564e4bfda1c483642db72007871397896',
Expand All @@ -41,20 +41,25 @@ const sGNS: Contract = {
chain: 'polygon',
address: '0x8c74b2256ffb6705f14ada8e86fbd654e0e2beca',
token: '0xE5417Af564e4bFDA1c483642db72007871397896',
rewards: [
'0x8f3cf7ad23cd3cadbd9735aff958023239c6a063',
'0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',
'0x3c499c542cef5e3811e1192ce70d8cc03d5c3359',
],
}

export const getContracts = () => {
return {
contracts: { gDAI, locker, sgDAI, sGNS },
contracts: { gDAI, locker, GNSStaking, sGNS },
}
}

export const getBalances: GetBalancesHandler<typeof getContracts> = async (ctx, contracts) => {
const balances = await resolveBalances<typeof getContracts>(ctx, contracts, {
gDAI: getGainsBalances,
locker: getGainsLockerBalances,
sgDAI: getsgDAIBalances,
sGNS: getsgGNSBalances,
GNSStaking: getGainsNetworkStakeBalance,
sGNS: getsgGNSBalance,
})

return {
Expand Down
Loading