Skip to content

Commit

Permalink
Use production savings usdc addresses (#686)
Browse files Browse the repository at this point in the history
* Update base susdc block number

* Update susdc mainnet block number

* Update base tests

* Adjust mainnet base account tests

* Update savings withdraw tests on base

* Update savings withdraw mainnet tests

* Delete 4

* Update injected setup

* Update savings page test

* Add withdraw actions

* Add deposit to savings actions

* Update conversion fetching logic

* Add e2e tests
  • Loading branch information
oskarvu authored Mar 5, 2025
1 parent 7d0bce7 commit ae15266
Show file tree
Hide file tree
Showing 37 changed files with 554 additions and 182 deletions.
32 changes: 28 additions & 4 deletions packages/app/src/config/chain/configs/arbitrum.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { usdcVaultAddress } from '@/config/contracts-generated'
import { psm3SavingsMyEarningsQueryOptions } from '@/domain/savings-charts/my-earnings-query/psm3-savings'
import { arbitrumSusdsSavingsRateQueryOptions } from '@/domain/savings-charts/savings-rate-query/arbitrum'
import { susdsSsrAuthOracleConverterQueryOptions } from '@/domain/savings-converters/susdsSsrAuthOracleConverter'
import {
arbitrumSusdcSavingsRateQueryOptions,
arbitrumSusdsSavingsRateQueryOptions,
} from '@/domain/savings-charts/savings-rate-query/arbitrum'
import { ssrAuthOracleConverterQueryOptions } from '@/domain/savings-converters/ssrAuthOracleConverter'
import { TokenSymbol } from '@/domain/types/TokenSymbol'
import { assets } from '@/ui/assets'
import { CheckedAddress } from '@marsfoundation/common-universal'
import { arbitrum } from 'viem/chains'
import { USDC_ACCOUNT_ENABLED } from '../flags'
import { ChainConfigEntry } from '../types'
import { defineToken } from '../utils/defineToken'

Expand All @@ -14,6 +19,13 @@ const usdc = defineToken({
symbol: TokenSymbol('USDC'),
})

const susdc = defineToken({
address: CheckedAddress(usdcVaultAddress[arbitrum.id]),
oracleType: 'vault',
assetsDecimals: 6,
symbol: TokenSymbol('sUSDC'),
})

const usds = defineToken({
address: CheckedAddress('0x6491c05A82219b8D1479057361ff1654749b876b'),
oracleType: 'fixed-usd',
Expand Down Expand Up @@ -47,12 +59,24 @@ export const arbitrumConfig: ChainConfigEntry = {
savingsToken: susds.symbol,
underlyingToken: usds.symbol,
supportedStablecoins: [usds.symbol, usdc.symbol],
fetchConverterQuery: susdsSsrAuthOracleConverterQueryOptions,
fetchConverterQuery: ssrAuthOracleConverterQueryOptions,
savingsRateQueryOptions: arbitrumSusdsSavingsRateQueryOptions,
myEarningsQueryOptions: psm3SavingsMyEarningsQueryOptions,
},
...(USDC_ACCOUNT_ENABLED
? [
{
savingsToken: susdc.symbol,
underlyingToken: usdc.symbol,
supportedStablecoins: [usdc.symbol],
fetchConverterQuery: ssrAuthOracleConverterQueryOptions,
savingsRateQueryOptions: arbitrumSusdcSavingsRateQueryOptions,
myEarningsQueryOptions: undefined,
},
]
: []),
],
psmStables: [usds.symbol, usdc.symbol],
},
definedTokens: [usdc, usds, susds],
definedTokens: [usdc, usds, susds, susdc],
}
7 changes: 3 additions & 4 deletions packages/app/src/config/chain/configs/base.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { usdcVaultAddress } from '@/config/contracts-generated'
import { psm3SavingsMyEarningsQueryOptions } from '@/domain/savings-charts/my-earnings-query/psm3-savings'
import { baseSusdsSavingsRateQueryOptions } from '@/domain/savings-charts/savings-rate-query/base'
import { baseSavingsUsdcConverterQueryOptions } from '@/domain/savings-converters/baseSavingsConverter'
import { susdsSsrAuthOracleConverterQueryOptions } from '@/domain/savings-converters/susdsSsrAuthOracleConverter'
import { ssrAuthOracleConverterQueryOptions } from '@/domain/savings-converters/ssrAuthOracleConverter'
import { TokenSymbol } from '@/domain/types/TokenSymbol'
import { assets } from '@/ui/assets'
import { CheckedAddress } from '@marsfoundation/common-universal'
Expand Down Expand Up @@ -56,7 +55,7 @@ export const baseConfig: ChainConfigEntry = {
savingsToken: susds.symbol,
underlyingToken: usds.symbol,
supportedStablecoins: [usds.symbol, usdc.symbol],
fetchConverterQuery: susdsSsrAuthOracleConverterQueryOptions,
fetchConverterQuery: ssrAuthOracleConverterQueryOptions,
savingsRateQueryOptions: baseSusdsSavingsRateQueryOptions,
myEarningsQueryOptions: psm3SavingsMyEarningsQueryOptions,
},
Expand All @@ -66,7 +65,7 @@ export const baseConfig: ChainConfigEntry = {
savingsToken: susdc.symbol,
underlyingToken: usdc.symbol,
supportedStablecoins: [usdc.symbol],
fetchConverterQuery: baseSavingsUsdcConverterQueryOptions,
fetchConverterQuery: ssrAuthOracleConverterQueryOptions,
savingsRateQueryOptions: baseSusdsSavingsRateQueryOptions,
myEarningsQueryOptions: undefined,
},
Expand Down
17 changes: 10 additions & 7 deletions packages/app/src/config/contracts-generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5741,7 +5741,7 @@ export const uiPoolDataProviderConfig = {

/**
* - [__View Contract on Ethereum Etherscan__](https://etherscan.io/address/0x47ff5312c027aa733abdce6740c88d4a151e7901)
* - [__View Contract on Base Basescan__](https://basescan.org/address/0x62da45546a0f87b23941ffe5ca22f9d2a8fa7df3)
* - [__View Contract on Base Basescan__](https://basescan.org/address/0x3128a0F7f0ea68E7B7c9B00AFa7E41045828e858)
*/
export const usdcVaultAbi = [
{
Expand Down Expand Up @@ -6415,17 +6415,20 @@ export const usdcVaultAbi = [
] as const

/**
* - [__View Contract on Ethereum Etherscan__](https://etherscan.io/address/0x47ff5312c027aa733abdce6740c88d4a151e7901)
* - [__View Contract on Base Basescan__](https://basescan.org/address/0x62da45546a0f87b23941ffe5ca22f9d2a8fa7df3)
* - [__View Contract on Ethereum Etherscan__](https://etherscan.io/address/0xBc65ad17c5C0a2A4D159fa5a503f4992c7B545FE)
* - [__View Contract on Base Basescan__](https://basescan.org/address/0x3128a0F7f0ea68E7B7c9B00AFa7E41045828e858)
* - [__View Contract on Arbitrum One Arbiscan__](https://arbiscan.io/address/0x940098b108fB7D0a7E374f6eDED7760787464609)
*/
export const usdcVaultAddress = {
1: '0x29bd15f2c80f2807c29d2428aa835f2be1098a62',
8453: '0x62da45546a0f87b23941ffe5ca22f9d2a8fa7df3',
1: '0xBc65ad17c5C0a2A4D159fa5a503f4992c7B545FE',
8453: '0x3128a0F7f0ea68E7B7c9B00AFa7E41045828e858',
42161: '0x940098b108fB7D0a7E374f6eDED7760787464609',
} as const

/**
* - [__View Contract on Ethereum Etherscan__](https://etherscan.io/address/0x47ff5312c027aa733abdce6740c88d4a151e7901)
* - [__View Contract on Base Basescan__](https://basescan.org/address/0x62da45546a0f87b23941ffe5ca22f9d2a8fa7df3)
* - [__View Contract on Ethereum Etherscan__](https://etherscan.io/address/0xBc65ad17c5C0a2A4D159fa5a503f4992c7B545FE)
* - [__View Contract on Base Basescan__](https://basescan.org/address/0x3128a0F7f0ea68E7B7c9B00AFa7E41045828e858)
* - [__View Contract on Arbitrum One Arbiscan__](https://arbiscan.io/address/0x940098b108fB7D0a7E374f6eDED7760787464609)
*/
export const usdcVaultConfig = {
address: usdcVaultAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ export function arbitrumSusdsSavingsRateQueryOptions() {
select: ssrRateSelect,
})
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function arbitrumSusdcSavingsRateQueryOptions() {
return queryOptions({
...savingsRateQueryOptions(),
select: ssrRateSelect,
})
}
59 changes: 0 additions & 59 deletions packages/app/src/domain/savings-converters/baseSavingsConverter.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { readContract } from 'wagmi/actions'
import { PotSavingsConverter } from './PotSavingsConverter'
import { SavingsConverterQueryOptions, SavingsConverterQueryParams } from './types'

export function susdsSsrAuthOracleConverterQueryOptions({
export function ssrAuthOracleConverterQueryOptions({
wagmiConfig,
timestamp,
chainId,
}: SavingsConverterQueryParams): SavingsConverterQueryOptions {
return {
queryKey: ['base-savings-usds-info', { chainId }],
queryKey: ['ssr-auth-oracle-converter', { chainId }],
queryFn: async () => {
const { ssr, chi, rho } = await readContract(wagmiConfig, {
abi: ssrAuthOracleConfig.abi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function createDepositToSavingsActions(objective: DepositToSavingsObjecti

case 'usdc-to-susdc':
case 'base-usdc-to-susdc':
case 'arbitrum-usdc-to-susdc':
return [getApproveAction(getContractAddress(usdcVaultAddress, chainId)), depositAction]

case 'base-usdc-to-susds':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export function createDepositToSavingsActionConfig(
})

case 'usdc-to-susdc':
case 'base-usdc-to-susdc': {
case 'base-usdc-to-susdc':
case 'arbitrum-usdc-to-susdc': {
assert(
context.savingsAccounts,
'Savings account repository info is required for usdc deposit to savings action',
Expand Down Expand Up @@ -181,6 +182,7 @@ export function createDepositToSavingsActionConfig(
case 'usds-to-susds':
case 'usdc-to-susdc':
case 'base-usdc-to-susdc':
case 'arbitrum-usdc-to-susdc':
return [balancesQueryKeyPrefix, getAllowanceQueryKey(action.savingsToken.address)]

case 'base-usds-to-susds':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type SavingsDepositActionPath =
| 'base-usdc-to-susdc'
| 'arbitrum-usds-to-susds'
| 'arbitrum-usdc-to-susds'
| 'arbitrum-usdc-to-susdc'

export interface GetSavingsActionPathParams {
token: Token
Expand Down Expand Up @@ -60,6 +61,10 @@ export function getSavingsDepositActionPath({
if (token.symbol === usdc && savingsToken.symbol === susds) {
return 'arbitrum-usdc-to-susds'
}

if (token.symbol === usdc && savingsToken.symbol === susdc) {
return 'arbitrum-usdc-to-susdc'
}
}

if (token.symbol === usds && savingsToken.symbol === susds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export function createWithdrawFromSavingsActions(
case 'sdai-to-dai':
case 'susdc-to-usdc':
case 'base-susdc-to-usdc':
case 'arbitrum-susdc-to-usdc':
return [withdrawAction]

case 'sdai-to-usdc':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type SavingsWithdrawActionPath =
| 'base-susdc-to-usdc'
| 'arbitrum-susds-to-usds'
| 'arbitrum-susds-to-usdc'
| 'arbitrum-susdc-to-usdc'

export function getSavingsWithdrawActionPath({
token,
Expand Down Expand Up @@ -64,6 +65,10 @@ export function getSavingsWithdrawActionPath({
if (token.symbol === usdc && savingsToken.symbol === susds) {
return 'arbitrum-susds-to-usdc'
}

if (token.symbol === usdc && savingsToken.symbol === susdc) {
return 'arbitrum-susdc-to-usdc'
}
}

if (token.symbol === usds && savingsToken.symbol === susds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ export function createWithdrawFromSavingsActionConfig(
})
}

case 'base-susdc-to-usdc': {
case 'base-susdc-to-usdc':
case 'arbitrum-susdc-to-usdc': {
assert(context.savingsAccounts, 'Savings accounts repository is required for usdc vault withdrawal')
const { converter } = context.savingsAccounts.findOneBySavingsToken(savingsToken)

Expand Down Expand Up @@ -264,6 +265,7 @@ export function createWithdrawFromSavingsActionConfig(
case 'susds-to-usds':
case 'susdc-to-usdc':
case 'base-susdc-to-usdc':
case 'arbitrum-susdc-to-usdc':
return [balancesQueryKeyPrefix]
case 'sdai-to-sexy-dai':
return [balancesQueryKeyPrefix, getAllowanceQueryKey(CheckedAddress(savingsXDaiAdapterAddress[gnosis.id]))]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { psm3Address } from '@/config/contracts-generated'
import { SavingsDialogPageObject } from '@/features/dialogs/savings/common/e2e/SavingsDialog.PageObject'
import { SavingsPageObject } from '@/pages/Savings.PageObject'
import { ARBITRUM_SUSDC_ACTIVE_BLOCK_NUMBER, TOKENS_ON_FORK } from '@/test/e2e/constants'
import { TestContext, setup } from '@/test/e2e/setup'
import { test } from '@playwright/test'
import { arbitrum } from 'viem/chains'
import { depositValidationIssueToMessage } from '../../../logic/validation'

test.describe('Deposit USDC', () => {
let savingsPage: SavingsPageObject
let depositDialog: SavingsDialogPageObject
let testContext: TestContext

test.beforeEach(async ({ page }) => {
testContext = await setup(page, {
blockchain: {
chain: arbitrum,
blockNumber: ARBITRUM_SUSDC_ACTIVE_BLOCK_NUMBER,
},
initialPage: 'savings',
account: {
type: 'connected-random',
assetBalances: {
ETH: 1,
USDC: 10_000,
},
},
})

savingsPage = new SavingsPageObject(testContext)
await savingsPage.clickSavingsNavigationItemAction('USDC')
await savingsPage.clickDepositButtonAction('USDC')

depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' })
await depositDialog.fillAmountAction(10_000)
})

test('has correct action plan', async () => {
await depositDialog.actionsContainer.expectActions([
{ type: 'approve', asset: 'USDC' },
{ type: 'depositToSavings', asset: 'USDC', savingsAsset: 'sUSDC' },
])
})

test('displays transaction overview', async () => {
await depositDialog.expectNativeRouteTransactionOverview({
apy: {
value: '6.50%',
description: 'Earn ~650.00 USDC/year',
},
routeItems: [
{
tokenAmount: '10,000.00 USDC',
tokenUsdValue: '$10,000.00',
},
{
tokenAmount: '9,601.69 sUSDC',
tokenUsdValue: '$10,000.00',
},
],
outcome: '9,601.69 sUSDC',
outcomeUsd: '$10,000.00',
})
})

test('executes deposit', async () => {
await depositDialog.actionsContainer.acceptAllActionsAction(2)

await depositDialog.expectSuccessPage()
await depositDialog.clickBackToSavingsButton()

await savingsPage.expectSavingsAccountBalance({
balance: '9,601.69',
estimatedValue: '9,999.9999996',
})
await savingsPage.expectSupportedStablecoinBalance('USDC', '-')
})

test('fails validation if psm3 usds balance is too low', async ({ page }) => {
await testContext.testnetController.client.setErc20Balance(
TOKENS_ON_FORK[arbitrum.id].sUSDS.address,
psm3Address[arbitrum.id],
0n,
)
await testContext.testnetController.progressSimulation(5)
await page.reload()
await savingsPage.clickSavingsNavigationItemAction('USDC')

await savingsPage.clickDepositButtonAction('USDC')

depositDialog = new SavingsDialogPageObject({ testContext, type: 'deposit' })
await depositDialog.fillAmountAction(10_000)
await depositDialog.expectAssetInputError(depositValidationIssueToMessage['exceeds-psm3-balance'])
})
})
Loading

0 comments on commit ae15266

Please sign in to comment.