From 28c27cb7d41232423632f1dd825a82736dc72185 Mon Sep 17 00:00:00 2001 From: philbow61 <80156619+philbow61@users.noreply.github.com> Date: Tue, 5 Nov 2024 16:00:41 +0100 Subject: [PATCH] feat: add cCOP to reserve Site (#121) --- public/assets/tokens/cCOP.svg | 261 ++++++++++++++++++++++++++++++++++ src/contract-addresses.ts | 2 + src/hooks/useStableTokens.ts | 1 + src/providers/Celo.ts | 13 ++ src/service/Data.ts | 1 + src/service/stables.ts | 31 ++++ 6 files changed, 309 insertions(+) create mode 100644 public/assets/tokens/cCOP.svg diff --git a/public/assets/tokens/cCOP.svg b/public/assets/tokens/cCOP.svg new file mode 100644 index 0000000..3e00294 --- /dev/null +++ b/public/assets/tokens/cCOP.svg @@ -0,0 +1,261 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/contract-addresses.ts b/src/contract-addresses.ts index 32c60a0..589ee7d 100644 --- a/src/contract-addresses.ts +++ b/src/contract-addresses.ts @@ -59,3 +59,5 @@ export const USDT_CELO_NATIVE_ADDRESS = export const CKES_ADDRESS = "0x456a3D042C0DbD3db53D5489e98dFb038553B0d0"; export const PUSO_ADDRESS = "0x105d4A9306D2E55a71d2Eb95B81553AE1dC20d7B"; + +export const CCOP_Address = "0x8A567e2aE79CA692Bd748aB832081C45de4041eA"; diff --git a/src/hooks/useStableTokens.ts b/src/hooks/useStableTokens.ts index fe2be8c..8cd036c 100644 --- a/src/hooks/useStableTokens.ts +++ b/src/hooks/useStableTokens.ts @@ -26,6 +26,7 @@ export const useStableTokens = () => { { ...initialOtherToken, token: "eXOF" }, { ...initialOtherToken, token: "cKES" }, { ...initialOtherToken, token: "PUSO" }, + { ...initialOtherToken, token: "cCOP" }, ], }, }, diff --git a/src/providers/Celo.ts b/src/providers/Celo.ts index 2b7d66c..14c2f81 100644 --- a/src/providers/Celo.ts +++ b/src/providers/Celo.ts @@ -7,6 +7,7 @@ import { ERC20_ABI } from "src/constants/abis"; import { CKES_ADDRESS, CUSD_ADDRESS, + CCOP_Address, EUROC_AXELAR_ADDRESS, EXOF_ADDRESS, PUSO_ADDRESS, @@ -52,6 +53,8 @@ const provider = new JsonRpcProvider(process.env.CELO_NODE_RPC_URL); const eXOFContract = new Contract(EXOF_ADDRESS, ERC20_ABI, provider); const cKESContract = new Contract(CKES_ADDRESS, ERC20_ABI, provider); const PUSOContract = new Contract(PUSO_ADDRESS, ERC20_ABI, provider); +const cCOPContract = new Contract(CCOP_Address, ERC20_ABI, provider); + export async function getFrozenBalance(): Promise { try { const [reserve, nativeToken] = await Promise.all([ @@ -303,6 +306,16 @@ export async function getPUSOSupply(): Promise { } } +export async function getCCOPSupply(): Promise { + try { + let cCOPSupply = (await cCOPContract.totalSupply()).toString(); + cCOPSupply = formatNumber(new BigNumber(cCOPSupply)); + return providerOk(cCOPSupply, Providers.celoNode); + } catch (error) { + return providerError(error, Providers.celoNode); + } +} + export const WEI_PER = 1_000_000_000_000_000_000; function formatNumber(value: BigNumber, decimals = 18) { diff --git a/src/service/Data.ts b/src/service/Data.ts index 83d08e1..dae1347 100644 --- a/src/service/Data.ts +++ b/src/service/Data.ts @@ -20,6 +20,7 @@ export type Tokens = | "cKES" | "eXOF" | "PUSO" + | "cCOP" | "USDGLO" | Token | StableToken; diff --git a/src/service/stables.ts b/src/service/stables.ts index c7027d0..df34f99 100644 --- a/src/service/stables.ts +++ b/src/service/stables.ts @@ -8,6 +8,7 @@ import { getEXOFSupply, getMultisigCUSD, getPUSOSupply, + getCCOPSupply, } from "src/providers/Celo"; import { TokenModel } from "src/service/Data"; import { getOrSave } from "src/service/cache"; @@ -46,6 +47,10 @@ async function PUSOSupply() { return getOrSave("PUSOSupply", () => getPUSOSupply(), 5 * SECOND); } +async function cCOPSupply() { + return getOrSave("cCOPSupply", () => getCCOPSupply(), 5 * SECOND); +} + interface Circulation { units: ProviderResult; symbol: StableToken; @@ -123,6 +128,7 @@ export default async function stables(): Promise { tokens.push(await getEXOFData()); tokens.push(await getCKESData()); tokens.push(await getPUSOData()); + tokens.push(await getCCOPData()); return tokens; } @@ -203,3 +209,28 @@ export async function getPUSOData(): Promise { } return pusoData; } + +export async function getCCOPData(): Promise { + const ccopData: TokenModel = { + token: "cCOP", + units: null, + value: null, + updated: null, + hasError: false, + } as TokenModel; + + try { + const result: ProviderResult = await cCOPSupply(); + if (result.hasError) { + ccopData.hasError = true; + return ccopData; + } else if (result.hasError == false) { + ccopData.units = result.value; + ccopData.value = result.value * (await fiatPrices()).value["COP"]; + ccopData.updated = result.time; + } + } catch { + ccopData.hasError = true; + } + return ccopData; +}