Skip to content

Commit

Permalink
feat: add cCOP to reserve Site (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
philbow61 authored Nov 5, 2024
1 parent be09ec1 commit 28c27cb
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 0 deletions.
261 changes: 261 additions & 0 deletions public/assets/tokens/cCOP.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/contract-addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
1 change: 1 addition & 0 deletions src/hooks/useStableTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const useStableTokens = () => {
{ ...initialOtherToken, token: "eXOF" },
{ ...initialOtherToken, token: "cKES" },
{ ...initialOtherToken, token: "PUSO" },
{ ...initialOtherToken, token: "cCOP" },
],
},
},
Expand Down
13 changes: 13 additions & 0 deletions src/providers/Celo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<ProviderResult> {
try {
const [reserve, nativeToken] = await Promise.all([
Expand Down Expand Up @@ -303,6 +306,16 @@ export async function getPUSOSupply(): Promise<ProviderResult> {
}
}

export async function getCCOPSupply(): Promise<ProviderResult> {
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) {
Expand Down
1 change: 1 addition & 0 deletions src/service/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type Tokens =
| "cKES"
| "eXOF"
| "PUSO"
| "cCOP"
| "USDGLO"
| Token
| StableToken;
Expand Down
31 changes: 31 additions & 0 deletions src/service/stables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<number>;
symbol: StableToken;
Expand Down Expand Up @@ -123,6 +128,7 @@ export default async function stables(): Promise<TokenModel[]> {
tokens.push(await getEXOFData());
tokens.push(await getCKESData());
tokens.push(await getPUSOData());
tokens.push(await getCCOPData());
return tokens;
}

Expand Down Expand Up @@ -203,3 +209,28 @@ export async function getPUSOData(): Promise<TokenModel> {
}
return pusoData;
}

export async function getCCOPData(): Promise<TokenModel> {
const ccopData: TokenModel = {
token: "cCOP",
units: null,
value: null,
updated: null,
hasError: false,
} as TokenModel;

try {
const result: ProviderResult<number> = 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;
}

0 comments on commit 28c27cb

Please sign in to comment.