From 84247dbb6fd94b5c4661398eb0a84baa7aaf663f Mon Sep 17 00:00:00 2001 From: gmbronco <83549293+gmbronco@users.noreply.github.com> Date: Mon, 3 Feb 2025 09:59:07 +0100 Subject: [PATCH] sUSDs - base (#1553) --- .changeset/popular-actors-notice.md | 5 +++ config/base.ts | 4 ++ .../apr-data-sources/yb-apr-handlers/index.ts | 1 + .../yb-apr-handlers/sources/index.ts | 1 + .../sources/susds-apr-handler.ts | 44 +++++++++++++++++++ 5 files changed, 55 insertions(+) create mode 100644 .changeset/popular-actors-notice.md create mode 100644 modules/pool/lib/apr-data-sources/yb-apr-handlers/sources/susds-apr-handler.ts diff --git a/.changeset/popular-actors-notice.md b/.changeset/popular-actors-notice.md new file mode 100644 index 000000000..c7df7c37b --- /dev/null +++ b/.changeset/popular-actors-notice.md @@ -0,0 +1,5 @@ +--- +'backend': patch +--- + +sUSDs - base diff --git a/config/base.ts b/config/base.ts index 6ca854395..c804c9612 100644 --- a/config/base.ts +++ b/config/base.ts @@ -67,6 +67,10 @@ export default { }, }, ybAprConfig: { + susds: { + oracle: '0x65d946e533748a998b1f0e430803e39a6388f7a1', + token: '0x5875eee11cf8398102fdad704c9e96607675467a', + }, morpho: { tokens: {}, }, diff --git a/modules/pool/lib/apr-data-sources/yb-apr-handlers/index.ts b/modules/pool/lib/apr-data-sources/yb-apr-handlers/index.ts index 10d054294..2ed87d305 100644 --- a/modules/pool/lib/apr-data-sources/yb-apr-handlers/index.ts +++ b/modules/pool/lib/apr-data-sources/yb-apr-handlers/index.ts @@ -31,6 +31,7 @@ const sourceToHandler = { sftmx: sources.SftmxAprHandler, sts: sources.StsAprHandler, silo: sources.SiloAprHandler, + susds: sources.SUSDSAprHandler, }; export class YbAprHandlers { diff --git a/modules/pool/lib/apr-data-sources/yb-apr-handlers/sources/index.ts b/modules/pool/lib/apr-data-sources/yb-apr-handlers/sources/index.ts index 6cf86e915..3c23024e8 100644 --- a/modules/pool/lib/apr-data-sources/yb-apr-handlers/sources/index.ts +++ b/modules/pool/lib/apr-data-sources/yb-apr-handlers/sources/index.ts @@ -20,6 +20,7 @@ export * from './teth'; export * from './morpho-apr-handler'; export * from './morpho-token-apr-handler'; export * from './usdl-apr-handler'; +export * from './susds-apr-handler'; // These need a refactor, because they depend on the network context export * from './sftmx-apr-handler'; export * from './sts-apr-handler'; diff --git a/modules/pool/lib/apr-data-sources/yb-apr-handlers/sources/susds-apr-handler.ts b/modules/pool/lib/apr-data-sources/yb-apr-handlers/sources/susds-apr-handler.ts new file mode 100644 index 000000000..83dcf2934 --- /dev/null +++ b/modules/pool/lib/apr-data-sources/yb-apr-handlers/sources/susds-apr-handler.ts @@ -0,0 +1,44 @@ +import { AprHandler } from '../types'; +import config from '../../../../../../config'; +import { createPublicClient, http, parseAbiItem } from 'viem'; +import { base } from 'viem/chains'; + +const client = createPublicClient({ + chain: base, + transport: http(config.BASE.rpcUrl), +}); + +const ssrOracle = '0x65d946e533748a998b1f0e430803e39a6388f7a1'; + +export class SUSDSAprHandler implements AprHandler { + group = 'MAKER'; + private oracle: string; + private token: string; + + constructor({ oracle, token }: { oracle: string; token: string }) { + this.oracle = oracle; + this.token = token; + } + + async getAprs() { + const aprs: { [p: string]: { apr: number; isIbYield: boolean; group: string } } = {}; + try { + const apr = await client.readContract({ + abi: [parseAbiItem('function getAPR() view returns (uint256)')], + address: this.oracle as `0x${string}`, + functionName: 'getAPR', + }); + + const tokenApr = Number(apr) * 10 ** -27; + + aprs[this.token] = { + apr: tokenApr, + isIbYield: false, + group: this.group, + }; + } catch (error) { + console.error(`sUSDS APR Failed for token ${this.token}: `, error); + } + return aprs; + } +}