-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add tests * chore: format * feat: tests * chore: lint * feat: token list export * Version Packages * chore: format * feat: getKandelSteps without kandel address * Version Packages * chore: format * feat: SmartKandel address for blast * chore: version package * chore: format * feat: add tests * chore: format * feat: tests * chore: lint * test: Update distribution test in kandel library. * feat: Add deployment of SmartKandel Seeder contract in global setup. * chore: format * test: Ensure distribution and logs tests are passing. * chore: format * chore: Add default gasreq to kandel. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: maxencerb <[email protected]>
- Loading branch information
1 parent
41490ef
commit 185dadb
Showing
18 changed files
with
457 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@mangrovedao/mgv": patch | ||
--- | ||
|
||
Add default gasreq to kandel |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { parseUnits } from 'viem' | ||
import { describe, expect, inject, it } from 'vitest' | ||
import { BA } from './enums.js' | ||
import { | ||
amounts, | ||
amountsToHumanPrice, | ||
humanPriceToRawPrice, | ||
rawPriceToHumanPrice, | ||
rpcOfferToHumanOffer, | ||
} from './human-readable.js' | ||
import { tickFromVolumes } from './tick.js' | ||
|
||
const { wethUSDC } = inject('markets') | ||
const { USDC, WETH } = inject('tokens') | ||
|
||
// price is quote/base | ||
// USDC is 6 decimals | ||
// DAI and WETH are 18 decimals | ||
|
||
describe('human readable', () => { | ||
it('rawPriceToHumanPrice', () => { | ||
const humanPrice = 3000 | ||
const rawPrice = (3000 * 1e6) / 1e18 | ||
const price = rawPriceToHumanPrice(rawPrice, wethUSDC) | ||
expect(price).toBe(humanPrice) | ||
}) | ||
|
||
it('humanPriceToRawPrice', () => { | ||
const humanPrice = 3000 | ||
const rawPrice = (3000 * 1e6) / 1e18 | ||
const price = humanPriceToRawPrice(humanPrice, wethUSDC) | ||
expect(price).toBe(rawPrice) | ||
}) | ||
|
||
it('amountsToHumanPrice', () => { | ||
const amountUSDC = parseUnits('3000', USDC.decimals) | ||
const amountWETH = parseUnits('1', WETH.decimals) | ||
const price = amountsToHumanPrice( | ||
{ baseAmount: amountWETH, quoteAmount: amountUSDC }, | ||
wethUSDC, | ||
) | ||
expect(price).toBe(3000) | ||
}) | ||
|
||
it('amounts', () => { | ||
const humanPrice = 3000 | ||
const baseAmount = parseUnits('1', WETH.decimals) | ||
const quoteAmount = parseUnits('3000', USDC.decimals) | ||
|
||
expect( | ||
amounts({ baseAmount, quoteAmount }, wethUSDC), | ||
'Wrong human price', | ||
).toEqual(expect.objectContaining({ baseAmount, quoteAmount, humanPrice })) | ||
|
||
expect( | ||
amounts({ humanPrice, baseAmount }, wethUSDC).quoteAmount, | ||
'Wrong quote amount', | ||
).toApproximateEqual(quoteAmount, 0.0001) | ||
|
||
expect( | ||
amounts({ humanPrice, quoteAmount }, wethUSDC).baseAmount, | ||
'Wrong base amount', | ||
).toApproximateEqual(baseAmount, 0.0001) | ||
}) | ||
|
||
it('rpcOfferToHumanOffer', () => { | ||
const baseAmount = parseUnits('1', WETH.decimals) | ||
const quoteAmount = parseUnits('3000', USDC.decimals) | ||
const tickBid = tickFromVolumes( | ||
baseAmount, | ||
quoteAmount, | ||
wethUSDC.tickSpacing, | ||
) | ||
const tickAsk = tickFromVolumes( | ||
quoteAmount, | ||
baseAmount, | ||
wethUSDC.tickSpacing, | ||
) | ||
const humanPrice = 3000 | ||
const offerBid = rpcOfferToHumanOffer({ | ||
gives: quoteAmount, | ||
tick: tickBid, | ||
ba: BA.bids, | ||
baseDecimals: WETH.decimals, | ||
quoteDecimals: USDC.decimals, | ||
}) | ||
|
||
expect(offerBid.price).toApproximateEqual(humanPrice, 0.0001) | ||
expect(offerBid.total).toApproximateEqual(3000, 0.0001) | ||
expect(offerBid.volume).toApproximateEqual(1, 0.0001) | ||
expect(offerBid.ba).toBe(BA.bids) | ||
|
||
const offerAsk = rpcOfferToHumanOffer({ | ||
gives: baseAmount, | ||
tick: tickAsk, | ||
ba: BA.asks, | ||
baseDecimals: WETH.decimals, | ||
quoteDecimals: USDC.decimals, | ||
}) | ||
|
||
expect(offerAsk.price).toApproximateEqual(humanPrice, 0.0001) | ||
expect(offerAsk.total).toApproximateEqual(3000, 0.0001) | ||
expect(offerAsk.volume).toApproximateEqual(1, 0.0001) | ||
expect(offerAsk.ba).toBe(BA.asks) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { parseAbi } from 'viem' | ||
import { expect, it } from 'vitest' | ||
import { describe, inject } from 'vitest' | ||
import { getClient } from '~test/src/client.js' | ||
import { createGeometricDistribution } from './distribution.js' | ||
import { getKandelPositionRawParams } from './params.js' | ||
|
||
const { kandelLib, smartKandelSeeder } = inject('kandel') | ||
const { routerProxyFactory, mangrove } = inject('mangrove') | ||
const { wethUSDC } = inject('markets') | ||
|
||
const client = getClient() | ||
|
||
const kandelLibAbi = parseAbi([ | ||
'struct DistributionOffer {uint index;int tick;uint gives;}', | ||
'struct Distribution {DistributionOffer[] asks;DistributionOffer[] bids;}', | ||
'function createGeometricDistribution(uint from,uint to,int baseQuoteTickIndex0,uint _baseQuoteTickOffset,uint firstAskIndex,uint bidGives,uint askGives,uint pricePoints,uint stepSize) external pure returns (Distribution memory distribution)', | ||
]) | ||
|
||
describe('distribution', () => { | ||
it('checks kandel deployment', async () => { | ||
const [factory, mgv] = await client.multicall({ | ||
contracts: [ | ||
{ | ||
address: smartKandelSeeder, | ||
abi: parseAbi(['function PROXY_FACTORY() view returns (address)']), | ||
functionName: 'PROXY_FACTORY', | ||
}, | ||
{ | ||
address: smartKandelSeeder, | ||
abi: parseAbi(['function MGV() view returns (address)']), | ||
functionName: 'MGV', | ||
}, | ||
], | ||
}) | ||
expect(factory.status).toEqual('success') | ||
expect(factory.result).toAddressEqual(routerProxyFactory) | ||
expect(mgv.status).toEqual('success') | ||
expect(mgv.result).toAddressEqual(mangrove) | ||
}) | ||
|
||
it('checks kandel distribution', async () => { | ||
const params = getKandelPositionRawParams({ | ||
minPrice: 2500, | ||
midPrice: 3000, | ||
maxPrice: 3500, | ||
pricePoints: 10n, | ||
market: wethUSDC, | ||
}) | ||
|
||
const distrib = createGeometricDistribution({ | ||
...params, | ||
stepSize: 1n, | ||
market: wethUSDC, | ||
bidGives: 1n, | ||
askGives: 1n, | ||
}) | ||
|
||
const fromChain = await client.readContract({ | ||
address: kandelLib, | ||
abi: kandelLibAbi, | ||
functionName: 'createGeometricDistribution', | ||
args: [ | ||
0n, | ||
10n, | ||
params.baseQuoteTickIndex0, | ||
params.baseQuoteTickOffset, | ||
params.firstAskIndex, | ||
1n, | ||
1n, | ||
params.pricePoints, | ||
1n, | ||
], | ||
}) | ||
|
||
expect(distrib.asks.length).toEqual(fromChain.asks.length) | ||
expect(distrib.bids.length).toEqual(fromChain.bids.length) | ||
|
||
for (let i = 0; i < distrib.asks.length; i++) { | ||
expect(distrib.asks[i].gives).toEqual(fromChain.asks[i].gives) | ||
expect(distrib.asks[i].tick).toEqual(fromChain.asks[i].tick) | ||
expect(distrib.asks[i].index).toEqual(fromChain.asks[i].index) | ||
} | ||
for (let i = 0; i < distrib.bids.length; i++) { | ||
expect(distrib.bids[i].gives).toEqual(fromChain.bids[i].gives) | ||
expect(distrib.bids[i].tick).toEqual(fromChain.bids[i].tick) | ||
expect(distrib.bids[i].index).toEqual(fromChain.bids[i].index) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { isAddress } from 'viem' | ||
import { describe, expect, inject, it } from 'vitest' | ||
import { simulateSow } from '~mgv/actions/kandel/sow.js' | ||
import { getClient } from '~test/src/client.js' | ||
import { hash } from '../ol-key.js' | ||
import { getKandelsFromLogs } from './logs.js' | ||
|
||
const { smartKandelSeeder } = inject('kandel') | ||
const { wethUSDC } = inject('markets') | ||
const client = getClient() | ||
|
||
describe('Kandel logs', () => { | ||
it('get smart kandel from logs', async () => { | ||
const { request } = await simulateSow(client, wethUSDC, smartKandelSeeder) | ||
const tx = await client.writeContract(request) | ||
const receipt = await client.waitForTransactionReceipt({ | ||
hash: tx, | ||
}) | ||
const result = getKandelsFromLogs(receipt.logs) | ||
expect(result.length).toEqual(1) | ||
expect(result[0].type).toEqual('SmartKandel') | ||
expect(result[0].owner).toAddressEqual(client.account.address) | ||
expect(result[0].baseQuoteOlKeyHash).toEqual( | ||
hash({ | ||
outbound_tkn: wethUSDC.base.address, | ||
inbound_tkn: wethUSDC.quote.address, | ||
tickSpacing: wethUSDC.tickSpacing, | ||
}), | ||
) | ||
expect(isAddress(result[0].address)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { describe, expect, inject, it } from 'vitest' | ||
import { | ||
humanPriceToRawPrice, | ||
rawPriceToHumanPrice, | ||
} from '../human-readable.js' | ||
import { priceFromTick, tickFromPrice } from '../tick.js' | ||
import { getKandelPositionRawParams } from './params.js' | ||
|
||
const { wethUSDC } = inject('markets') | ||
|
||
describe('kandel params', () => { | ||
it('kandel position raw params', () => { | ||
const params = getKandelPositionRawParams({ | ||
minPrice: 2500, | ||
midPrice: 3000, | ||
maxPrice: 3500, | ||
pricePoints: 10n, | ||
market: wethUSDC, | ||
}) | ||
|
||
expect(params.pricePoints).toBe(10n) | ||
expect(params.firstAskIndex).toBe(5n) | ||
|
||
const baseQuoteTickIndex0 = tickFromPrice( | ||
humanPriceToRawPrice(2500, wethUSDC), | ||
wethUSDC.tickSpacing, | ||
) | ||
expect(params.baseQuoteTickIndex0).toBe(baseQuoteTickIndex0) | ||
expect(params.baseQuoteTickOffset % wethUSDC.tickSpacing).toBe(0n) | ||
|
||
const endTick = | ||
params.baseQuoteTickIndex0 + | ||
params.baseQuoteTickOffset * (params.pricePoints - 1n) | ||
const endPrice = rawPriceToHumanPrice(priceFromTick(endTick), wethUSDC) | ||
expect(endPrice).toApproximateEqual(3500) | ||
}) | ||
}) |
Oops, something went wrong.