Skip to content

Commit

Permalink
docs: add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fedorovdg committed Mar 2, 2025
1 parent 9d9c087 commit 72a7cee
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
File renamed without changes.
54 changes: 54 additions & 0 deletions test/selfLiquidateCrvUSD.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { assert } from "chai";
import { crvusd } from "../src/crvusd";
import { getLlamma, LlammaTemplate } from "../src/llammas";

const LLAMMAS = ['sfrxeth'];

const selfLiquidationTest = (id: string) => {
describe(`${id} self-liquidation test`, function () {
let llamma: LlammaTemplate;

before(async function () {
llamma = getLlamma(id);
const maxDebt = await llamma.createLoanMaxRecv(0.3, 10);
await llamma.createLoan(0.3, maxDebt, 10);
await llamma.swap(0, 1, Number(maxDebt) * 10, 0.05);
});

it('Self-liquidations', async function () {
const initialBalances = await llamma.wallet.balances();
const initialState = await llamma.userState();
const initialTokensToLiquidate = await llamma.tokensToLiquidate();

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

await llamma.selfLiquidate(0.1);

const balances = await llamma.wallet.balances();
const state = await llamma.userState();

const tokensToLiquidate = await llamma.tokensToLiquidate();
assert.equal(Number(tokensToLiquidate), 0, 'tokens to liquidate');
assert.equal(Number(balances.collateral), Number(initialBalances.collateral) + Number(initialState.collateral), 'wallet collateral');
assert.approximately(Number(balances.stablecoin), Number(initialBalances.stablecoin) - Number(initialTokensToLiquidate), 1e-4, 'wallet stablecoin');
assert.equal(Number(state.collateral), 0, 'state callateral');
assert.equal(Number(state.stablecoin), 0, 'state stablecoin');
assert.equal(Number(state.debt), 0, 'state debt');
});
})
}

describe('Self-liquidation test', async function () {
this.timeout(120000);

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

for (const llammaId of LLAMMAS) {
selfLiquidationTest(llammaId);
}
})
56 changes: 56 additions & 0 deletions test/swapCrvUSD.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { assert } from "chai";
import { crvusd } from "../src/crvusd";
import { getLlamma, LlammaTemplate } from "../src/llammas";
import { BN } from "../src/utils";

const LLAMMAS = ['sfrxeth'];

const swapTest = (id: string) => {
let llamma: LlammaTemplate;
let maxDebt: string;

before(async function () {
llamma = getLlamma(id);
maxDebt = await llamma.createLoanMaxRecv(0.3, 10);
await llamma.createLoan(0.3, maxDebt, 10)
});

after(async function () {
await llamma.fullRepay();
});


describe(`${id} llamma swap test`, function () {
for (let i = 0; i < 2; i++) {
for (let j = 0; j < 2; j++) {
if (i === j) continue;

it(`${i} --> ${j}`, async function () {
const initialBalances = await llamma.wallet.balances();
const swapAmount = i === 0 ? Number(maxDebt) / 10 : 0.003;
const expected = Number(await llamma.swapExpected(i, j, swapAmount));

await llamma.swap(i, j, swapAmount, 0.05);

const balances = await llamma.wallet.balances();
const out = Number(Object.values(balances)[j]) - Number(Object.values(initialBalances)[j]);

assert.deepStrictEqual(BN(Object.values(balances)[i]).toString(), BN(Object.values(initialBalances)[i]).minus(BN(swapAmount)).toString(), 'in');
assert.isAtMost(Math.abs(out - expected) / expected, 5 * 1e-3, 'out');
});
}
}
});
}

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

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

for (const llammaId of LLAMMAS) {
swapTest(llammaId);
}
})

0 comments on commit 72a7cee

Please sign in to comment.