Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/stableswap-stackingDAO.clar
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
(x-amount-fees-lps-scaled (/ (* x-amount-scaled swap-fee-lps) u10000))
(x-amount-fees-stacking-dao-scaled (/ (* x-amount-scaled swap-fee-stacking-dao) u10000))
(x-amount-fees-bitflow-scaled (/ (* x-amount-scaled swap-fee-bitflow) u10000))
(x-amount-total-fees-scaled (/ (* x-amount total-swap-fee) u10000))
(x-amount-total-fees-scaled (/ (* x-amount-scaled total-swap-fee) u10000))
(updated-x-amount-scaled (- x-amount-scaled x-amount-total-fees-scaled))
(updated-x-balance-scaled (+ current-balance-x-scaled updated-x-amount-scaled))
(new-y-scaled (get-y updated-x-balance-scaled current-balance-y-scaled updated-x-amount-scaled (* (get amplification-coefficient pair-data) number-of-tokens)))
Expand Down
52 changes: 51 additions & 1 deletion tests/stableswap-stackingDAO_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,56 @@ Clarinet.test({
},
});

// Test get-dy for a pair where x and y token decimals differ
Clarinet.test({
name: "Ensure get-dy matches swap output for mixed-decimal pairs",
async fn(chain: Chain, accounts: Map<string, Account>) {
const deployer = accounts.get("deployer")!;
const yToken = `${deployer.address}.susdt-token`;
const lpToken = `${deployer.address}.usda-susdt-lp-token`;
const stableswapStackingDao = `${deployer.address}.stableswap-stackingDAO`;
const initialX = 1000000000;
const initialY = 100000000000;
const xAmount = 10000000;

chain.mineBlock([
Tx.contractCall("susdt-token", "mint", [types.uint(200000000000), types.principal(deployer.address)], deployer.address),
Tx.contractCall("usda-susdt-lp-token", "set-supply-controller", [types.principal(stableswapStackingDao)], deployer.address),
]);

const createPair = chain.mineBlock([
Tx.contractCall("stableswap-stackingDAO", "create-pair", [
types.principal(yToken),
types.principal(lpToken),
types.uint(100),
types.ascii("test-susdt"),
types.uint(initialX),
types.uint(initialY),
], deployer.address),
]);
createPair.receipts[0].result.expectOk();

const quote = chain.callReadOnlyFn("stableswap-stackingDAO", "get-dy", [
types.principal(yToken),
types.principal(lpToken),
types.uint(xAmount),
], deployer.address);

const block = chain.mineBlock([
Tx.contractCall("stableswap-stackingDAO", "swap-x-for-y", [
types.principal(yToken),
types.principal(lpToken),
types.uint(xAmount),
types.uint(0),
], deployer.address),
]);

const quotedDy = quote.result.expectOk();
const swappedDy = block.receipts[0].result.expectOk();
assertEquals(swappedDy, quotedDy);
},
});


// Test swap x for y
Clarinet.test({
Expand Down Expand Up @@ -1606,4 +1656,4 @@ Clarinet.test({
block.receipts[0].result.expectErr()
console.log(JSON.stringify(block.receipts));
},
});
});