import { type PublicClient, type Transport } from 'viem'; import { gnosis } from 'viem/chains'; import { Amount } from '../currencies/currency-amount.js'; import type { Token } from '../currencies/token.js'; import { sDAI } from '../currencies/common-tokens.js'; export type GnosisChainPublicClient = PublicClient; /** * The address of the SDAI rate provider on the Gnosis chain. */ export const SDAI_RATE_PROVIDER = '0x89C80A4540A00b5270347E02e2E144c71da2EceD' as const; export const GNOSIS_CHAIN_SDAI_ADAPTER_ADDRESS = '0xd499b51fcfc66bd31248ef4b28d656d67e591a94' as const; export const GNOSIS_CHAIN_SDAI_ADAPTER_ABI = [ { inputs: [ { internalType: 'address', name: 'interestReceiver_', type: 'address', }, { internalType: 'address payable', name: 'sDAI_', type: 'address' }, ], stateMutability: 'nonpayable', type: 'constructor', }, { inputs: [ { internalType: 'uint256', name: 'assets', type: 'uint256' }, { internalType: 'address', name: 'receiver', type: 'address' }, ], name: 'deposit', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'nonpayable', type: 'function', }, { inputs: [ { internalType: 'address', name: 'receiver', type: 'address', }, ], name: 'depositXDAI', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'payable', type: 'function', }, { inputs: [], name: 'interestReceiver', outputs: [ { internalType: 'contract IBridgeInterestReceiver', name: '', type: 'address', }, ], stateMutability: 'view', type: 'function', }, { inputs: [ { internalType: 'uint256', name: 'shares', type: 'uint256' }, { internalType: 'address', name: 'receiver', type: 'address' }, ], name: 'mint', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'nonpayable', type: 'function', }, { inputs: [ { internalType: 'uint256', name: 'shares', type: 'uint256' }, { internalType: 'address', name: 'receiver', type: 'address' }, ], name: 'redeem', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'nonpayable', type: 'function', }, { inputs: [ { internalType: 'address', name: 'receiver', type: 'address', }, ], name: 'redeemAll', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'nonpayable', type: 'function', }, { inputs: [ { internalType: 'address', name: 'receiver', type: 'address', }, ], name: 'redeemAllXDAI', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'payable', type: 'function', }, { inputs: [ { internalType: 'uint256', name: 'shares', type: 'uint256' }, { internalType: 'address', name: 'receiver', type: 'address' }, ], name: 'redeemXDAI', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'payable', type: 'function', }, { inputs: [], name: 'sDAI', outputs: [ { internalType: 'contract SavingsXDai', name: '', type: 'address', }, ], stateMutability: 'view', type: 'function', }, { inputs: [], name: 'vaultAPY', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'view', type: 'function', }, { inputs: [ { internalType: 'uint256', name: 'assets', type: 'uint256' }, { internalType: 'address', name: 'receiver', type: 'address' }, ], name: 'withdraw', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'nonpayable', type: 'function', }, { inputs: [ { internalType: 'uint256', name: 'assets', type: 'uint256' }, { internalType: 'address', name: 'receiver', type: 'address' }, ], name: 'withdrawXDAI', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'payable', type: 'function', }, { inputs: [], name: 'wxdai', outputs: [ { internalType: 'contract IWXDAI', name: '', type: 'address', }, ], stateMutability: 'view', type: 'function', }, { stateMutability: 'payable', type: 'receive' }, ] as const; export const SDAI_RATE_PROVIDER_ABI = [ { inputs: [ { internalType: 'contract IERC4626', name: '_erc4626', type: 'address', }, ], stateMutability: 'nonpayable', type: 'constructor', }, { inputs: [], name: 'baseDecimals', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'view', type: 'function', }, { inputs: [], name: 'erc4626', outputs: [{ internalType: 'contract IERC4626', name: '', type: 'address' }], stateMutability: 'view', type: 'function', }, { inputs: [], name: 'getRate', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'view', type: 'function', }, ] as const; // Get sDAI rate from its rate provider export async function getSdaiRate({ client }: { client: GnosisChainPublicClient }): Promise> { const rateRaw = await client.readContract({ address: SDAI_RATE_PROVIDER, abi: SDAI_RATE_PROVIDER_ABI, functionName: 'getRate', }); const returnValue = Amount.fromRawAmount(sDAI[gnosis.id], rateRaw); return returnValue; }