Skip to content

Commit

Permalink
feat: add Compound external read functions
Browse files Browse the repository at this point in the history
  • Loading branch information
iherger committed Oct 3, 2023
1 parent d53a66b commit 13dbb27
Showing 1 changed file with 201 additions and 10 deletions.
211 changes: 201 additions & 10 deletions packages/sdk/src/internal/Extensions/IntegrationAdapters/CompoundV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,132 @@ export function redeemDecode(encoded: Hex): RedeemArgs {
// EXTERNAL CONTRACT METHODS
//--------------------------------------------------------------------------------------------

const exchangeRateStoredAbi = {
constant: true,
inputs: [],
name: "exchangeRateStored",
outputs: [{ name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function",
} as const;
const cTokenAbi = [
{
inputs: [],
name: "borrowRatePerBlock",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "supplyRatePerBlock",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "totalSupply",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "totalBorrows",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "exchangeRateStored",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
{
inputs: [{ internalType: "address", name: "owner", type: "address" }],
name: "balanceOf",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
] as const;

const compoundComptrollerAbi = [
{
constant: true,
inputs: [{ internalType: "address", name: "", type: "address" }],
name: "compSupplySpeeds",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [{ internalType: "address", name: "", type: "address" }],
name: "compBorrowSpeeds",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [{ internalType: "address", name: "", type: "address" }],
name: "markets",
outputs: [
{ internalType: "bool", name: "isListed", type: "bool" },
{ internalType: "uint256", name: "collateralFactorMantissa", type: "uint256" },
{ internalType: "bool", name: "isComped", type: "bool" },
],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [],
name: "_mintGuardianPaused",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
payable: false,
stateMutability: "view",
type: "function",
},
] as const;

export function getBorrowRatePerBlock(
client: PublicClient,
args: Viem.ContractCallParameters<{
cToken: Address;
}>,
) {
return Viem.readContract(client, args, {
abi: cTokenAbi,
functionName: "borrowRatePerBlock",
address: args.cToken,
});
}

export function getTotalSupply(
client: PublicClient,
args: Viem.ContractCallParameters<{
cToken: Address;
}>,
) {
return Viem.readContract(client, args, {
abi: cTokenAbi,
functionName: "totalSupply",
address: args.cToken,
});
}

export function getTotalBorrows(
client: PublicClient,
args: Viem.ContractCallParameters<{
cToken: Address;
}>,
) {
return Viem.readContract(client, args, {
abi: cTokenAbi,
functionName: "totalBorrows",
address: args.cToken,
});
}

export function getExchangeRateStored(
client: PublicClient,
Expand All @@ -103,8 +220,82 @@ export function getExchangeRateStored(
}>,
) {
return Viem.readContract(client, args, {
abi: [exchangeRateStoredAbi],
abi: cTokenAbi,
functionName: "exchangeRateStored",
address: args.cToken,
});
}

export function getBalanceOf(
client: PublicClient,
args: Viem.ContractCallParameters<{
cToken: Address;
account: Address;
}>,
) {
return Viem.readContract(client, args, {
abi: cTokenAbi,
functionName: "balanceOf",
address: args.cToken,
args: [args.account],
});
}

export function getCompSupplySpeeds(
client: PublicClient,
args: Viem.ContractCallParameters<{
compoundComptroller: Address;
cToken: Address;
}>,
) {
return Viem.readContract(client, args, {
abi: compoundComptrollerAbi,
functionName: "compSupplySpeeds",
address: args.compoundComptroller,
args: [args.cToken],
});
}

export function getCompBorrowSpeeds(
client: PublicClient,
args: Viem.ContractCallParameters<{
compoundComptroller: Address;
cToken: Address;
}>,
) {
return Viem.readContract(client, args, {
abi: compoundComptrollerAbi,
functionName: "compBorrowSpeeds",
address: args.compoundComptroller,
args: [args.cToken],
});
}

export function getMarkets(
client: PublicClient,
args: Viem.ContractCallParameters<{
compoundComptroller: Address;
cToken: Address;
}>,
) {
return Viem.readContract(client, args, {
abi: compoundComptrollerAbi,
functionName: "markets",
address: args.compoundComptroller,
args: [args.cToken],
});
}

export function getMintGuardianPaused(
client: PublicClient,
args: Viem.ContractCallParameters<{
compoundComptroller: Address;
cToken: Address;
}>,
) {
return Viem.readContract(client, args, {
abi: compoundComptrollerAbi,
functionName: "_mintGuardianPaused",
address: args.compoundComptroller,
});
}

0 comments on commit 13dbb27

Please sign in to comment.