curvance
v3.1.10
Published
A SDK to explore the curvance protocol efficently & easily.
Downloads
5,244
Readme
Features
- Efficient RPC Usage: Preloads all market data with minimal calls.
- Typed Contracts: Uses ethers.js for safe, typed blockchain interactions.
- Price Feeds: Integrates Redstone for on-chain price updates.
- Decimal Support: Handles BigInt and floating-point math with decimal.js.
- Flexible Providers: Works with multiple providers:
ethers.Wallet- For CLI/Local wallet connectionsethers.JsonRpcSigner- For browser interactionsethers.JsonRpcProvider- For a user configured RPCnull- We setup a JsonRpcProvider if we configured one for you
- Property conversions: For example getting a users asset balance can optionally be returned in USD or token amount
- Contract addresses: Use this package to pull in curvance contracts & have the latest contract addresses (especially useful on testnet)
Dependencies:
- Redstone: Used to attach price updates in a multicall for some actions.
- Decimals: Any floating point path being done with BigInt is done with Decimals.
- ethers.js: All signers passed into the protocol are using ether.js typed signers.
Notes:
- All values are returned in either BigInt or Decimals
- We use alchemy chain prefixing for exaple:
eth-mainnetorarb-sepoliato represents chains
❯ Install
$ npm install --save curvance❯ Usage
Grab general information
This is very RPC efficient as it uses 1-3 RPC call's to setup all the data you need. This is the main way to use the SDK as ALL the data is pre-setup for you. All you need to do is traverse the markets.
const { markets, reader, faucet } = await setupChain("monad-testnet", wallet);You can then explore the data pretty easily like so:
let count = 0;
console.log(`Market summaries in USD:`);
for(const market of markets) {
console.log(`[${count}] tvl: ${market.tvl.toFixed(18)} | totalDebt: ${market.totalDebt.toFixed(18)} | totalCollateral: ${market.totalCollateral.toFixed(18)}`);
for(const token of market.tokens) {
console.log(`\tToken: ${token.symbol} | Price: ${token.getPrice()} | Amount: ${token.getTvl(false)}`);
}
count++;
}Grab individaul classes
const test_1 = new ERC20(signer, `0x123`);
await test_1.approve(someGuy, BigInt(50e18));Some of these classes use preloaded cache to prevent RPC calls for example
const test_1 = new ERC20(signer, `0x123`);
console.log(test_1.name); // Attempts to use cache for name, so this returns undefined
const name = await test_1.fetchName();
console.log(name); // My Test Token
console.log(test_1.name); // My Test TokenNote: Protocol reader will populate things like test_1.name for underlying assets from the first preload RPC call and wont need to be fetched.
Helpers
getContractAddresses- Grab the contracts addresses for a given chainAdaptorTypes- Adaptor identifier enumsWAD- WAD amountWAD_DECIMAL- WAD amount as Decimal.js typecontractSetup- Used to initialize contract & attach typescript interfacehandleTransactionWithOracles- Depending on what adaptor is being used to execute the function we choose to run a multi-call that will write-price on-chain with the given function -- but only if the adaptor is the type of adaptor that requires this (pull oracle)
const contracts = getContractAddresses('monad-testnet');
console.log(contracts.ProtocolReader);