Skip to content

Commit

Permalink
Merge pull request #16 from curvefi/leverage-sfrxeth2-tbtc
Browse files Browse the repository at this point in the history
Leverage: sfrxeth2, tbtc
  • Loading branch information
Macket authored Sep 25, 2023
2 parents 139c5df + 5a27775 commit d4c6ac6
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@curvefi/stablecoin-api",
"version": "1.3.7",
"version": "1.4.0",
"description": "JavaScript library for Curve Stablecoin",
"main": "lib/index.js",
"author": "Macket",
Expand Down
32 changes: 30 additions & 2 deletions src/constants/llammas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const LLAMMAS: IDict<ILlamma> = lowerCaseLlammasAddresses({
monetary_policy_address: '0x1E7d3bf98d3f8D8CE193236c3e0eC4b00e32DaaE',
collateral_address: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
leverage_zap: '0x293436d4e4a15FBc6cCC400c14a01735E5FC74fd',
collateral_symbol: 'wsteth',
collateral_symbol: 'wstETH',
collateral_decimals: 18,
min_bands: 4,
max_bands: 50,
Expand All @@ -39,7 +39,7 @@ export const LLAMMAS: IDict<ILlamma> = lowerCaseLlammasAddresses({
collateral_address: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
leverage_zap: '0xA2518b71ee64E910741f5Cf480b19E8e402de4d7',
health_calculator_zap: "0xCF61Ee62b136e3553fB545bd8fEc11fb7f830d6A",
collateral_symbol: 'wbtc',
collateral_symbol: 'WBTC',
collateral_decimals: 8,
min_bands: 4,
max_bands: 50,
Expand All @@ -61,4 +61,32 @@ export const LLAMMAS: IDict<ILlamma> = lowerCaseLlammasAddresses({
A: 100,
monetary_policy_abi: MonetaryPolicy2ABI,
},
sfrxeth2: {
amm_address: '0xfa96ad0a9e64261db86950e2da362f5572c5c6fd',
controller_address: '0xec0820efafc41d8943ee8de495fc9ba8495b15cf',
monetary_policy_address: '0x1e7d3bf98d3f8d8ce193236c3e0ec4b00e32daae',
collateral_address: '0xac3e018457b222d93114458476f3e3416abbe38f',
leverage_zap: '0x43eCFfe6c6C1b9F24AeB5C180E659c2a6FCe11Bc',
collateral_symbol: 'sfrxETH',
collateral_decimals: 18,
min_bands: 4,
max_bands: 50,
default_bands: 10,
A: 100,
monetary_policy_abi: MonetaryPolicy2ABI,
},
tbtc: {
amm_address: '0xf9bd9da2427a50908c4c6d1599d8e62837c2bcb0',
controller_address: '0x1c91da0223c763d2e0173243eadaa0a2ea47e704',
monetary_policy_address: '0xb8687d7dc9d8fa32fabde63e19b2dbc9bb8b2138',
collateral_address: '0x18084fba666a33d37592fa2633fd49a74dd93a88',
leverage_zap: '0xD79964C70Cb06224FdA4c48387B53E9819bcB71c',
collateral_symbol: 'tBTC',
collateral_decimals: 18,
min_bands: 4,
max_bands: 50,
default_bands: 10,
A: 100,
monetary_policy_abi: MonetaryPolicy2ABI,
},
});
2 changes: 1 addition & 1 deletion src/crvusd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class Crvusd implements Icrvusd {
this.setContract(monetary_policy_address, MonetaryPolicy2ABI);
const _llammaId: string = is_eth ? "eth" : collateral_symbol.toLowerCase();
let llammaId = _llammaId
let j = 1;
let j = 2;
while (llammaId in this.constants.LLAMMAS) llammaId = _llammaId + j++;
this.constants.LLAMMAS[llammaId] = {
amm_address: amms[i],
Expand Down
44 changes: 40 additions & 4 deletions test/general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getLlamma, LlammaTemplate } from "../src/llammas";
import { BN } from "../src/utils";


const LLAMMAS = ['sfrxeth', 'wsteth', 'wbtc', 'eth'];
const LLAMMAS = ['sfrxeth', 'wsteth', 'wbtc', 'eth', 'sfrxeth2', 'tbtc'];

const generalTest = (id: string) => {
describe(`${id} llamma general test`, function () {
Expand Down Expand Up @@ -191,17 +191,53 @@ const generalTest = (id: string) => {
const state = await llamma.userState();


assert.equal(Number(balances.collateral), Number(initialBalances.collateral) + Number(initialState.collateral), 'wallet collateral');
assert.approximately(Number(balances.stablecoin), Number(initialBalances.stablecoin) - Number(initialState.debt), 1e-4, 'wallet stablecoin');
assert.approximately(Number(balances.collateral), Number(initialBalances.collateral) + Number(initialState.collateral), 10**(-llamma.collateralDecimals), 'wallet collateral');
assert.approximately(Number(balances.stablecoin), Number(initialBalances.stablecoin) - Number(initialState.debt), 1e-3, 'wallet stablecoin');
assert.equal(Number(state.collateral), 0, 'state collateral');
assert.equal(Number(state.stablecoin), 0, 'state stablecoin');
assert.equal(Number(state.debt), 0, 'state debt');
});

it('Leverage', async function () {
const initialBalances = await llamma.wallet.balances();
const initialState = await llamma.userState();

assert.equal(Number(initialState.collateral), 0);
assert.equal(Number(initialState.stablecoin), 0);
assert.equal(Number(initialState.debt), 0);
assert.isAbove(Number(initialBalances.collateral), 0);

const collateralAmount = 0.5;
const N = 10;
const maxRecv = await llamma.leverage.createLoanMaxRecv(collateralAmount, N);
const debtAmount = (Number(maxRecv.maxBorrowable) / 2).toFixed(18);
const createLoanPrices = await llamma.leverage.createLoanPrices(collateralAmount, debtAmount, N);
const createLoanFullHealth = await llamma.leverage.createLoanHealth(collateralAmount, debtAmount, N);
const createLoanHealth = await llamma.leverage.createLoanHealth(collateralAmount, debtAmount, N, false);
const { collateral } = await llamma.leverage.createLoanCollateral(collateralAmount, debtAmount);

await llamma.leverage.createLoan(collateralAmount, debtAmount, N);

const balances = await llamma.wallet.balances();
const state = await llamma.userState();
const userPrices = await llamma.userPrices();
const fullHealth = await llamma.userHealth();
const health = await llamma.userHealth(false);

assert.approximately(Number(createLoanPrices[0]), Number(userPrices[0]), 1e-2, 'price 0');
assert.approximately(Number(createLoanPrices[1]), Number(userPrices[1]), 1e-2, 'price 1');
assert.approximately(Number(createLoanFullHealth), Number(fullHealth), 0.1, 'full health');
assert.approximately(Number(createLoanHealth), Number(health), 1e-4, 'health');
assert.equal(Number(balances.collateral), Number(initialBalances.collateral) - Number(collateralAmount), 'wallet collateral');
assert.equal(Number(balances.stablecoin), Number(initialBalances.stablecoin), 'wallet stablecoin');
assert.approximately(Number(state.collateral), Number(collateral), 1e-7, 'state collateral');
assert.equal(Number(state.debt), Number(debtAmount), 'state debt');
});
})
}

describe('General test', async function () {
this.timeout(120000);
this.timeout(240000);

before(async function () {
await crvusd.init('JsonRpc', {},{ gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0 });
Expand Down

0 comments on commit d4c6ac6

Please sign in to comment.