@clober/v2-sdk 0.0.1-b → 0.0.1-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/.graphclient/index.js +243 -0
- package/dist/cjs/.graphclient/index.js.map +1 -0
- package/dist/cjs/.graphclient/sources/clober-v2/introspectionSchema.js +14482 -0
- package/dist/cjs/.graphclient/sources/clober-v2/introspectionSchema.js.map +1 -0
- package/dist/cjs/.graphclient/sources/clober-v2/types.js +4 -0
- package/dist/cjs/.graphclient/sources/clober-v2/types.js.map +1 -0
- package/dist/cjs/abis/core/controller-abi.js +989 -0
- package/dist/cjs/abis/core/controller-abi.js.map +1 -0
- package/dist/cjs/abis/core/params-abi.js +62 -0
- package/dist/cjs/abis/core/params-abi.js.map +1 -0
- package/dist/cjs/apis/currency.js +87 -0
- package/dist/cjs/apis/currency.js.map +1 -0
- package/dist/cjs/apis/market.js +63 -0
- package/dist/cjs/apis/market.js.map +1 -0
- package/dist/cjs/apis/open-order.js +90 -0
- package/dist/cjs/apis/open-order.js.map +1 -0
- package/dist/cjs/approval.js +74 -0
- package/dist/cjs/approval.js.map +1 -0
- package/dist/cjs/call.js +545 -0
- package/dist/cjs/call.js.map +1 -0
- package/dist/cjs/constants/action.js +14 -0
- package/dist/cjs/constants/action.js.map +1 -0
- package/dist/cjs/constants/addresses.js +13 -0
- package/dist/cjs/constants/addresses.js.map +1 -0
- package/dist/cjs/constants/chain.js +13 -0
- package/dist/cjs/constants/chain.js.map +1 -0
- package/dist/cjs/constants/currency.js +12 -0
- package/dist/cjs/constants/currency.js.map +1 -0
- package/dist/cjs/constants/fee.js +7 -0
- package/dist/cjs/constants/fee.js.map +1 -0
- package/dist/cjs/constants/price.js +6 -0
- package/dist/cjs/constants/price.js.map +1 -0
- package/dist/cjs/constants/subgraph-url.js +8 -0
- package/dist/cjs/constants/subgraph-url.js.map +1 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/model/book.js +130 -0
- package/dist/cjs/model/book.js.map +1 -0
- package/dist/cjs/model/currency.js +3 -0
- package/dist/cjs/model/currency.js.map +1 -0
- package/dist/cjs/model/depth.js +3 -0
- package/dist/cjs/model/depth.js.map +1 -0
- package/dist/cjs/model/fee-policy.js +42 -0
- package/dist/cjs/model/fee-policy.js.map +1 -0
- package/dist/cjs/model/market.js +215 -0
- package/dist/cjs/model/market.js.map +1 -0
- package/dist/cjs/model/open-order.js +3 -0
- package/dist/cjs/model/open-order.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/signature.js +178 -0
- package/dist/cjs/signature.js.map +1 -0
- package/dist/cjs/tsconfig.build.tsbuildinfo +1 -0
- package/dist/cjs/type.js +6 -0
- package/dist/cjs/type.js.map +1 -0
- package/dist/cjs/utils/approval.js +46 -0
- package/dist/cjs/utils/approval.js.map +1 -0
- package/dist/cjs/utils/book-id.js +25 -0
- package/dist/cjs/utils/book-id.js.map +1 -0
- package/dist/cjs/utils/build-transaction.js +31 -0
- package/dist/cjs/utils/build-transaction.js.map +1 -0
- package/dist/cjs/utils/decimals.js +17 -0
- package/dist/cjs/utils/decimals.js.map +1 -0
- package/dist/cjs/utils/market.js +53 -0
- package/dist/cjs/utils/market.js.map +1 -0
- package/dist/cjs/utils/math.js +83 -0
- package/dist/cjs/utils/math.js.map +1 -0
- package/dist/cjs/utils/prices.js +22 -0
- package/dist/cjs/utils/prices.js.map +1 -0
- package/dist/cjs/utils/tick.js +106 -0
- package/dist/cjs/utils/tick.js.map +1 -0
- package/dist/cjs/utils/time.js +9 -0
- package/dist/cjs/utils/time.js.map +1 -0
- package/dist/cjs/utils/unit.js +38 -0
- package/dist/cjs/utils/unit.js.map +1 -0
- package/dist/cjs/view.js +185 -0
- package/dist/cjs/view.js.map +1 -0
- package/dist/esm/.graphclient/index.js +233 -0
- package/dist/esm/.graphclient/index.js.map +1 -0
- package/dist/esm/.graphclient/sources/clober-v2/introspectionSchema.js +14480 -0
- package/dist/esm/.graphclient/sources/clober-v2/introspectionSchema.js.map +1 -0
- package/dist/esm/.graphclient/sources/clober-v2/types.js +3 -0
- package/dist/esm/.graphclient/sources/clober-v2/types.js.map +1 -0
- package/dist/esm/abis/core/controller-abi.js +986 -0
- package/dist/esm/abis/core/controller-abi.js.map +1 -0
- package/dist/esm/abis/core/params-abi.js +59 -0
- package/dist/esm/abis/core/params-abi.js.map +1 -0
- package/dist/esm/apis/currency.js +83 -0
- package/dist/esm/apis/currency.js.map +1 -0
- package/dist/esm/apis/market.js +59 -0
- package/dist/esm/apis/market.js.map +1 -0
- package/dist/esm/apis/open-order.js +85 -0
- package/dist/esm/apis/open-order.js.map +1 -0
- package/dist/esm/approval.js +70 -0
- package/dist/esm/approval.js.map +1 -0
- package/dist/esm/call.js +535 -0
- package/dist/esm/call.js.map +1 -0
- package/dist/esm/constants/action.js +11 -0
- package/dist/esm/constants/action.js.map +1 -0
- package/dist/esm/constants/addresses.js +10 -0
- package/dist/esm/constants/addresses.js.map +1 -0
- package/dist/esm/constants/chain.js +10 -0
- package/dist/esm/constants/chain.js.map +1 -0
- package/dist/esm/constants/currency.js +9 -0
- package/dist/esm/constants/currency.js.map +1 -0
- package/dist/esm/constants/fee.js +4 -0
- package/dist/esm/constants/fee.js.map +1 -0
- package/dist/esm/constants/price.js +3 -0
- package/dist/esm/constants/price.js.map +1 -0
- package/dist/esm/constants/subgraph-url.js +5 -0
- package/dist/esm/constants/subgraph-url.js.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/model/book.js +126 -0
- package/dist/esm/model/book.js.map +1 -0
- package/dist/esm/model/currency.js +2 -0
- package/dist/esm/model/currency.js.map +1 -0
- package/dist/esm/model/depth.js +2 -0
- package/dist/esm/model/depth.js.map +1 -0
- package/dist/esm/model/fee-policy.js +38 -0
- package/dist/esm/model/fee-policy.js.map +1 -0
- package/dist/esm/model/market.js +211 -0
- package/dist/esm/model/market.js.map +1 -0
- package/dist/esm/model/open-order.js +2 -0
- package/dist/esm/model/open-order.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/signature.js +174 -0
- package/dist/esm/signature.js.map +1 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -0
- package/dist/esm/type.js +2 -0
- package/dist/esm/type.js.map +1 -0
- package/dist/esm/utils/approval.js +42 -0
- package/dist/esm/utils/approval.js.map +1 -0
- package/{src/utils/book-id.ts → dist/esm/utils/book-id.js} +9 -19
- package/dist/esm/utils/book-id.js.map +1 -0
- package/dist/esm/utils/build-transaction.js +27 -0
- package/dist/esm/utils/build-transaction.js.map +1 -0
- package/dist/esm/utils/decimals.js +12 -0
- package/dist/esm/utils/decimals.js.map +1 -0
- package/dist/esm/utils/market.js +49 -0
- package/dist/esm/utils/market.js.map +1 -0
- package/dist/esm/utils/math.js +78 -0
- package/dist/esm/utils/math.js.map +1 -0
- package/dist/esm/utils/prices.js +17 -0
- package/dist/esm/utils/prices.js.map +1 -0
- package/dist/esm/utils/tick.js +100 -0
- package/dist/esm/utils/tick.js.map +1 -0
- package/dist/esm/utils/time.js +5 -0
- package/dist/esm/utils/time.js.map +1 -0
- package/dist/esm/utils/unit.js +34 -0
- package/dist/esm/utils/unit.js.map +1 -0
- package/dist/esm/view.js +177 -0
- package/dist/esm/view.js.map +1 -0
- package/dist/types/.graphclient/index.d.ts +1281 -0
- package/dist/types/.graphclient/index.d.ts.map +1 -0
- package/dist/types/.graphclient/sources/clober-v2/introspectionSchema.d.ts +3 -0
- package/dist/types/.graphclient/sources/clober-v2/introspectionSchema.d.ts.map +1 -0
- package/dist/types/.graphclient/sources/clober-v2/types.d.ts +984 -0
- package/dist/types/.graphclient/sources/clober-v2/types.d.ts.map +1 -0
- package/dist/types/abis/core/controller-abi.d.ts +757 -0
- package/dist/types/abis/core/controller-abi.d.ts.map +1 -0
- package/dist/types/abis/core/params-abi.d.ts +21 -0
- package/dist/types/abis/core/params-abi.d.ts.map +1 -0
- package/dist/types/apis/currency.d.ts +4 -0
- package/dist/types/apis/currency.d.ts.map +1 -0
- package/dist/types/apis/market.d.ts +4 -0
- package/dist/types/apis/market.d.ts.map +1 -0
- package/dist/types/apis/open-order.d.ts +5 -0
- package/dist/types/apis/open-order.d.ts.map +1 -0
- package/dist/types/approval.d.ts +32 -0
- package/dist/types/approval.d.ts.map +1 -0
- package/dist/types/call.d.ts +234 -0
- package/dist/types/call.d.ts.map +1 -0
- package/dist/types/constants/action.d.ts +10 -0
- package/dist/types/constants/action.d.ts.map +1 -0
- package/dist/types/constants/addresses.d.ts +9 -0
- package/dist/types/constants/addresses.d.ts.map +1 -0
- package/dist/types/constants/chain.d.ts +9 -0
- package/dist/types/constants/chain.d.ts.map +1 -0
- package/dist/types/constants/currency.d.ts +8 -0
- package/dist/types/constants/currency.d.ts.map +1 -0
- package/dist/types/constants/fee.d.ts +4 -0
- package/dist/types/constants/fee.d.ts.map +1 -0
- package/dist/types/constants/price.d.ts +3 -0
- package/dist/types/constants/price.d.ts.map +1 -0
- package/dist/types/constants/subgraph-url.d.ts +5 -0
- package/dist/types/constants/subgraph-url.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/model/book.d.ts +31 -0
- package/dist/types/model/book.d.ts.map +1 -0
- package/dist/types/model/currency.d.ts +7 -0
- package/dist/types/model/currency.d.ts.map +1 -0
- package/dist/types/model/depth.d.ts +11 -0
- package/dist/types/model/depth.d.ts.map +1 -0
- package/dist/types/model/fee-policy.d.ts +15 -0
- package/dist/types/model/fee-policy.d.ts.map +1 -0
- package/dist/types/model/market.d.ts +44 -0
- package/dist/types/model/market.d.ts.map +1 -0
- package/dist/types/model/open-order.d.ts +28 -0
- package/dist/types/model/open-order.d.ts.map +1 -0
- package/dist/types/signature.d.ts +40 -0
- package/dist/types/signature.d.ts.map +1 -0
- package/dist/types/type.d.ts +34 -0
- package/dist/types/type.d.ts.map +1 -0
- package/dist/types/utils/approval.d.ts +3 -0
- package/dist/types/utils/approval.d.ts.map +1 -0
- package/dist/types/utils/book-id.d.ts +2 -0
- package/dist/types/utils/book-id.d.ts.map +1 -0
- package/dist/types/utils/build-transaction.d.ts +5 -0
- package/dist/types/utils/build-transaction.d.ts.map +1 -0
- package/dist/types/utils/decimals.d.ts +3 -0
- package/dist/types/utils/decimals.d.ts.map +1 -0
- package/dist/types/utils/market.d.ts +7 -0
- package/dist/types/utils/market.d.ts.map +1 -0
- package/dist/types/utils/math.d.ts +3 -0
- package/dist/types/utils/math.d.ts.map +1 -0
- package/dist/types/utils/prices.d.ts +3 -0
- package/dist/types/utils/prices.d.ts.map +1 -0
- package/dist/types/utils/tick.d.ts +4 -0
- package/dist/types/utils/tick.d.ts.map +1 -0
- package/dist/types/utils/time.d.ts +2 -0
- package/dist/types/utils/time.d.ts.map +1 -0
- package/dist/types/utils/unit.d.ts +4 -0
- package/dist/types/utils/unit.d.ts.map +1 -0
- package/dist/types/view.d.ts +129 -0
- package/dist/types/view.d.ts.map +1 -0
- package/package.json +14 -6
- package/.eslintignore +0 -1
- package/.eslintrc.yaml +0 -34
- package/.github/workflows/ci.yaml +0 -88
- package/.github/workflows/deployer.yaml +0 -19
- package/.nvmrc +0 -1
- package/.prettierignore +0 -6
- package/.prettierrc +0 -7
- package/src/.graphclient/index.ts +0 -1695
- package/src/.graphclient/schema.graphql +0 -1116
- package/src/.graphclient/sources/clober-v2/introspectionSchema.ts +0 -14481
- package/src/.graphclient/sources/clober-v2/schema.graphql +0 -1116
- package/src/.graphclient/sources/clober-v2/types.ts +0 -1133
- package/src/.graphclientrc.yml +0 -12
- package/src/abis/core/controller-abi.ts +0 -985
- package/src/abis/core/params-abi.ts +0 -59
- package/src/apis/currency.ts +0 -92
- package/src/apis/graphql/books.graphql +0 -25
- package/src/apis/graphql/open-order.graphql +0 -29
- package/src/apis/graphql/open-orders.graphql +0 -29
- package/src/apis/market.ts +0 -85
- package/src/apis/open-order.ts +0 -145
- package/src/approval.ts +0 -82
- package/src/call.ts +0 -705
- package/src/constants/action.ts +0 -9
- package/src/constants/addresses.ts +0 -17
- package/src/constants/chain.ts +0 -12
- package/src/constants/currency.ts +0 -15
- package/src/constants/fee.ts +0 -4
- package/src/constants/price.ts +0 -3
- package/src/constants/subgraph-url.ts +0 -8
- package/src/index.ts +0 -5
- package/src/model/book.ts +0 -166
- package/src/model/currency.ts +0 -6
- package/src/model/depth.ts +0 -11
- package/src/model/fee-policy.ts +0 -51
- package/src/model/market.ts +0 -320
- package/src/model/open-order.ts +0 -16
- package/src/signature.ts +0 -196
- package/src/type.ts +0 -38
- package/src/utils/approval.ts +0 -48
- package/src/utils/build-transaction.ts +0 -39
- package/src/utils/decimals.ts +0 -22
- package/src/utils/market.ts +0 -74
- package/src/utils/math.ts +0 -117
- package/src/utils/prices.ts +0 -29
- package/src/utils/tick.ts +0 -104
- package/src/utils/time.ts +0 -6
- package/src/utils/unit.ts +0 -43
- package/src/view.ts +0 -258
- package/test/book-id.test.ts +0 -101
- package/test/fee-policy.test.ts +0 -228
- package/test/get-expected-input.test.ts +0 -206
- package/test/get-expected-output.test.ts +0 -206
- package/test/limit-order.test.ts +0 -279
- package/test/market-order.test.ts +0 -245
- package/test/market.test.ts +0 -68
- package/test/math.test.ts +0 -91
- package/test/open-order.test.ts +0 -112
- package/test/open.test.ts +0 -15
- package/test/tick.test.ts +0 -230
- package/test/tsconfig.json +0 -12
- package/test/utils/chain.ts +0 -12
- package/test/utils/constants.ts +0 -25
- package/test/utils/currency.ts +0 -44
- package/test/utils/depth.ts +0 -148
- package/test/utils/test-chain.ts +0 -26
- package/test/vitest.config.ts +0 -15
- package/tsconfig.base.json +0 -37
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -9
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import { expect, test } from 'vitest'
|
|
2
|
-
import { marketOrder } from '@clober/v2-sdk'
|
|
3
|
-
|
|
4
|
-
import { cloberTestChain } from './utils/test-chain'
|
|
5
|
-
import { publicClient } from './utils/constants'
|
|
6
|
-
|
|
7
|
-
const IS_LOCAL = process.env.IS_LOCAL === 'true'
|
|
8
|
-
|
|
9
|
-
test.runIf(IS_LOCAL)('market order in not open market', async () => {
|
|
10
|
-
expect(
|
|
11
|
-
await marketOrder(
|
|
12
|
-
cloberTestChain.id,
|
|
13
|
-
'0x447ad4a108b5540c220f9f7e83723ac87c0f8fd8',
|
|
14
|
-
'0x447ad4a108b5540c220f9f7e83723ac87c0f8fd8',
|
|
15
|
-
'0x0000000000000000000000000000000000000000',
|
|
16
|
-
'10',
|
|
17
|
-
{ rpcUrl: publicClient.transport.url! },
|
|
18
|
-
).catch((e) => e.message),
|
|
19
|
-
).toEqual(`
|
|
20
|
-
import { openMarket } from '@clober/v2-sdk'
|
|
21
|
-
|
|
22
|
-
const transaction = await openMarket(
|
|
23
|
-
${cloberTestChain.id},
|
|
24
|
-
'0x447ad4a108b5540c220f9f7e83723ac87c0f8fd8',
|
|
25
|
-
'0x0000000000000000000000000000000000000000',
|
|
26
|
-
)
|
|
27
|
-
`)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
// test('market bid with unlimited slippage', async () => {
|
|
31
|
-
// const signature = await signERC20Permit(
|
|
32
|
-
// cloberTestChain.id,
|
|
33
|
-
// account,
|
|
34
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
35
|
-
// '100',
|
|
36
|
-
// { rpcUrl: publicClient.transport.url! },
|
|
37
|
-
// )
|
|
38
|
-
// const transaction = await marketOrder(
|
|
39
|
-
// cloberTestChain.id,
|
|
40
|
-
// account.address,
|
|
41
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
42
|
-
// '0x0000000000000000000000000000000000000000',
|
|
43
|
-
// '100',
|
|
44
|
-
// { signature, rpcUrl: publicClient.transport.url! },
|
|
45
|
-
// )
|
|
46
|
-
//
|
|
47
|
-
// const [beforeUSDCBalance, beforeETHBalance, beforeAskDepth] =
|
|
48
|
-
// await Promise.all([
|
|
49
|
-
// fetchTokenBalance(
|
|
50
|
-
// cloberTestChain.id,
|
|
51
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
52
|
-
// account.address,
|
|
53
|
-
// publicClient.transport.url!,
|
|
54
|
-
// ),
|
|
55
|
-
// publicClient.getBalance({
|
|
56
|
-
// address: account.address,
|
|
57
|
-
// }),
|
|
58
|
-
// fetchAskDepth(publicClient.transport.url!),
|
|
59
|
-
// ])
|
|
60
|
-
// expect(beforeAskDepth.length).toBeGreaterThan(0)
|
|
61
|
-
//
|
|
62
|
-
// await walletClient.sendTransaction({ ...transaction!, account })
|
|
63
|
-
//
|
|
64
|
-
// const [afterUSDCBalance, afterETHBalance, afterAskDepth] = await Promise.all([
|
|
65
|
-
// fetchTokenBalance(
|
|
66
|
-
// cloberTestChain.id,
|
|
67
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
68
|
-
// account.address,
|
|
69
|
-
// publicClient.transport.url!,
|
|
70
|
-
// ),
|
|
71
|
-
// publicClient.getBalance({
|
|
72
|
-
// address: account.address,
|
|
73
|
-
// }),
|
|
74
|
-
// fetchAskDepth(publicClient.transport.url!),
|
|
75
|
-
// ])
|
|
76
|
-
//
|
|
77
|
-
// expect(Number(beforeUSDCBalance)).toBeGreaterThan(Number(afterUSDCBalance))
|
|
78
|
-
// expect(Number(afterETHBalance)).toBeGreaterThan(Number(beforeETHBalance))
|
|
79
|
-
// expect(beforeAskDepth.length).toBeGreaterThan(afterAskDepth.length)
|
|
80
|
-
// expect(afterAskDepth.length).toBe(0)
|
|
81
|
-
// })
|
|
82
|
-
//
|
|
83
|
-
// test('market ask with unlimited slippage', async () => {
|
|
84
|
-
// const transaction = await marketOrder(
|
|
85
|
-
// cloberTestChain.id,
|
|
86
|
-
// account.address,
|
|
87
|
-
// '0x0000000000000000000000000000000000000000',
|
|
88
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
89
|
-
// '10',
|
|
90
|
-
// { rpcUrl: publicClient.transport.url! },
|
|
91
|
-
// )
|
|
92
|
-
//
|
|
93
|
-
// const [beforeUSDCBalance, beforeETHBalance, beforeBidDepth] =
|
|
94
|
-
// await Promise.all([
|
|
95
|
-
// fetchTokenBalance(
|
|
96
|
-
// cloberTestChain.id,
|
|
97
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
98
|
-
// account.address,
|
|
99
|
-
// publicClient.transport.url!,
|
|
100
|
-
// ),
|
|
101
|
-
// publicClient.getBalance({
|
|
102
|
-
// address: account.address,
|
|
103
|
-
// }),
|
|
104
|
-
// fetchBidDepth(publicClient.transport.url!),
|
|
105
|
-
// ])
|
|
106
|
-
// expect(beforeBidDepth.length).toBeGreaterThan(0)
|
|
107
|
-
//
|
|
108
|
-
// await walletClient.sendTransaction({ ...transaction!, account })
|
|
109
|
-
//
|
|
110
|
-
// const [afterUSDCBalance, afterETHBalance, afterBidDepth] = await Promise.all([
|
|
111
|
-
// fetchTokenBalance(
|
|
112
|
-
// cloberTestChain.id,
|
|
113
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
114
|
-
// account.address,
|
|
115
|
-
// publicClient.transport.url!,
|
|
116
|
-
// ),
|
|
117
|
-
// publicClient.getBalance({
|
|
118
|
-
// address: account.address,
|
|
119
|
-
// }),
|
|
120
|
-
// fetchBidDepth(publicClient.transport.url!),
|
|
121
|
-
// ])
|
|
122
|
-
//
|
|
123
|
-
// expect(Number(afterUSDCBalance)).toBeGreaterThan(Number(beforeUSDCBalance))
|
|
124
|
-
// expect(Number(beforeETHBalance)).toBeGreaterThan(Number(afterETHBalance))
|
|
125
|
-
// expect(beforeBidDepth.length).toBeGreaterThan(afterBidDepth.length)
|
|
126
|
-
// expect(afterBidDepth.length).toBe(0)
|
|
127
|
-
// })
|
|
128
|
-
//
|
|
129
|
-
// test('market bid with slippage tolerate', async () => {
|
|
130
|
-
// const market = await getMarket(
|
|
131
|
-
// cloberTestChain.id,
|
|
132
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
133
|
-
// '0x0000000000000000000000000000000000000000',
|
|
134
|
-
// { rpcUrl: publicClient.transport.url! },
|
|
135
|
-
// )
|
|
136
|
-
// const signature = await signERC20Permit(
|
|
137
|
-
// cloberTestChain.id,
|
|
138
|
-
// account,
|
|
139
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
140
|
-
// '1000000',
|
|
141
|
-
// { rpcUrl: publicClient.transport.url! },
|
|
142
|
-
// )
|
|
143
|
-
// const transaction = await marketOrder(
|
|
144
|
-
// cloberTestChain.id,
|
|
145
|
-
// account.address,
|
|
146
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
147
|
-
// '0x0000000000000000000000000000000000000000',
|
|
148
|
-
// '1000000',
|
|
149
|
-
// {
|
|
150
|
-
// signature,
|
|
151
|
-
// rpcUrl: publicClient.transport.url!,
|
|
152
|
-
// limitPrice: (market.asks[0]!.price + 1).toString(),
|
|
153
|
-
// },
|
|
154
|
-
// )
|
|
155
|
-
//
|
|
156
|
-
// const [beforeUSDCBalance, beforeETHBalance, beforeAskDepth] =
|
|
157
|
-
// await Promise.all([
|
|
158
|
-
// fetchTokenBalance(
|
|
159
|
-
// cloberTestChain.id,
|
|
160
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
161
|
-
// account.address,
|
|
162
|
-
// publicClient.transport.url!,
|
|
163
|
-
// ),
|
|
164
|
-
// publicClient.getBalance({
|
|
165
|
-
// address: account.address,
|
|
166
|
-
// }),
|
|
167
|
-
// fetchAskDepth(publicClient.transport.url!),
|
|
168
|
-
// ])
|
|
169
|
-
// expect(beforeAskDepth.length).toBeGreaterThan(1)
|
|
170
|
-
//
|
|
171
|
-
// await walletClient.sendTransaction({ ...transaction!, account })
|
|
172
|
-
//
|
|
173
|
-
// const [afterUSDCBalance, afterETHBalance, afterAskDepth] = await Promise.all([
|
|
174
|
-
// fetchTokenBalance(
|
|
175
|
-
// cloberTestChain.id,
|
|
176
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
177
|
-
// account.address,
|
|
178
|
-
// publicClient.transport.url!,
|
|
179
|
-
// ),
|
|
180
|
-
// publicClient.getBalance({
|
|
181
|
-
// address: account.address,
|
|
182
|
-
// }),
|
|
183
|
-
// fetchAskDepth(publicClient.transport.url!),
|
|
184
|
-
// ])
|
|
185
|
-
//
|
|
186
|
-
// expect(Number(beforeUSDCBalance)).toBeGreaterThan(Number(afterUSDCBalance))
|
|
187
|
-
// expect(Number(afterETHBalance)).toBeGreaterThan(Number(beforeETHBalance))
|
|
188
|
-
// expect(beforeAskDepth.length).toBeGreaterThan(afterAskDepth.length)
|
|
189
|
-
// expect(afterAskDepth.length).toBeGreaterThan(0)
|
|
190
|
-
// })
|
|
191
|
-
//
|
|
192
|
-
// test('market ask with slippage tolerate', async () => {
|
|
193
|
-
// const market = await getMarket(
|
|
194
|
-
// cloberTestChain.id,
|
|
195
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
196
|
-
// '0x0000000000000000000000000000000000000000',
|
|
197
|
-
// { rpcUrl: publicClient.transport.url! },
|
|
198
|
-
// )
|
|
199
|
-
// const transaction = await marketOrder(
|
|
200
|
-
// cloberTestChain.id,
|
|
201
|
-
// account.address,
|
|
202
|
-
// '0x0000000000000000000000000000000000000000',
|
|
203
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
204
|
-
// '10',
|
|
205
|
-
// {
|
|
206
|
-
// rpcUrl: publicClient.transport.url!,
|
|
207
|
-
// limitPrice: (market.bids[0]!.price - 1).toString(),
|
|
208
|
-
// },
|
|
209
|
-
// )
|
|
210
|
-
//
|
|
211
|
-
// const [beforeUSDCBalance, beforeETHBalance, beforeBidDepth] =
|
|
212
|
-
// await Promise.all([
|
|
213
|
-
// fetchTokenBalance(
|
|
214
|
-
// cloberTestChain.id,
|
|
215
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
216
|
-
// account.address,
|
|
217
|
-
// publicClient.transport.url!,
|
|
218
|
-
// ),
|
|
219
|
-
// publicClient.getBalance({
|
|
220
|
-
// address: account.address,
|
|
221
|
-
// }),
|
|
222
|
-
// fetchBidDepth(publicClient.transport.url!),
|
|
223
|
-
// ])
|
|
224
|
-
// expect(beforeBidDepth.length).toBeGreaterThan(1)
|
|
225
|
-
//
|
|
226
|
-
// await walletClient.sendTransaction({ ...transaction!, account })
|
|
227
|
-
//
|
|
228
|
-
// const [afterUSDCBalance, afterETHBalance, afterBidDepth] = await Promise.all([
|
|
229
|
-
// fetchTokenBalance(
|
|
230
|
-
// cloberTestChain.id,
|
|
231
|
-
// '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
232
|
-
// account.address,
|
|
233
|
-
// publicClient.transport.url!,
|
|
234
|
-
// ),
|
|
235
|
-
// publicClient.getBalance({
|
|
236
|
-
// address: account.address,
|
|
237
|
-
// }),
|
|
238
|
-
// fetchBidDepth(publicClient.transport.url!),
|
|
239
|
-
// ])
|
|
240
|
-
//
|
|
241
|
-
// expect(Number(afterUSDCBalance)).toBeGreaterThan(Number(beforeUSDCBalance))
|
|
242
|
-
// expect(Number(beforeETHBalance)).toBeGreaterThan(Number(afterETHBalance))
|
|
243
|
-
// expect(beforeBidDepth.length).toBeGreaterThan(afterBidDepth.length)
|
|
244
|
-
// expect(afterBidDepth.length).toBeGreaterThan(0)
|
|
245
|
-
// })
|
package/test/market.test.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { expect, test } from 'vitest'
|
|
2
|
-
import { arbitrumSepolia } from 'viem/chains'
|
|
3
|
-
import { getAddress } from 'viem'
|
|
4
|
-
import { getMarket } from '@clober/v2-sdk'
|
|
5
|
-
|
|
6
|
-
import { publicClient } from './utils/constants'
|
|
7
|
-
|
|
8
|
-
test('fetch open market', async () => {
|
|
9
|
-
const market = await getMarket(
|
|
10
|
-
arbitrumSepolia.id,
|
|
11
|
-
'0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
12
|
-
'0x0000000000000000000000000000000000000000',
|
|
13
|
-
{ rpcUrl: publicClient.transport.url! },
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
expect(market.makerFee).toEqual(-0.03)
|
|
17
|
-
expect(market.takerFee).toEqual(0.1)
|
|
18
|
-
|
|
19
|
-
expect(market.quote.address).toEqual(
|
|
20
|
-
getAddress('0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0'),
|
|
21
|
-
)
|
|
22
|
-
expect(market.quote.symbol).toEqual('MT')
|
|
23
|
-
expect(market.quote.name).toEqual('MockERC20')
|
|
24
|
-
expect(market.quote.decimals).toEqual(6)
|
|
25
|
-
|
|
26
|
-
expect(market.base.address).toEqual(
|
|
27
|
-
getAddress('0x0000000000000000000000000000000000000000'),
|
|
28
|
-
)
|
|
29
|
-
expect(market.base.symbol).toEqual('ETH')
|
|
30
|
-
expect(market.base.name).toEqual('Ethereum')
|
|
31
|
-
expect(market.base.decimals).toEqual(18)
|
|
32
|
-
|
|
33
|
-
expect(market.bidBookOpen).toEqual(true)
|
|
34
|
-
expect(market.askBookOpen).toEqual(true)
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
test('fetch empty market', async () => {
|
|
38
|
-
const market = await getMarket(
|
|
39
|
-
arbitrumSepolia.id,
|
|
40
|
-
'0x447ad4a108b5540c220f9f7e83723ac87c0f8fd8',
|
|
41
|
-
'0x0000000000000000000000000000000000000000',
|
|
42
|
-
{ rpcUrl: publicClient.transport.url! },
|
|
43
|
-
)
|
|
44
|
-
expect(market.bidBookOpen).toEqual(true)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
// @dev: this test will be fail when the market is open
|
|
48
|
-
test('fetch not open market', async () => {
|
|
49
|
-
const market = await getMarket(
|
|
50
|
-
arbitrumSepolia.id,
|
|
51
|
-
'0xf18Be2a91cF31Fc3f8D828b6c714e1806a75e0AA',
|
|
52
|
-
'0x0000000000000000000000000000000000000000',
|
|
53
|
-
{ rpcUrl: publicClient.transport.url! },
|
|
54
|
-
)
|
|
55
|
-
expect(market.bidBookOpen).toEqual(false)
|
|
56
|
-
expect(market.askBookOpen).toEqual(false)
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
test('fetch invalid market', async () => {
|
|
60
|
-
expect(
|
|
61
|
-
await getMarket(
|
|
62
|
-
arbitrumSepolia.id,
|
|
63
|
-
'0x0000000000000000000000000000000000000000',
|
|
64
|
-
'0x0000000000000000000000000000000000000000',
|
|
65
|
-
{ rpcUrl: publicClient.transport.url! },
|
|
66
|
-
).catch((e) => e.message),
|
|
67
|
-
).toEqual('Token0 and token1 must be different')
|
|
68
|
-
})
|
package/test/math.test.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { expect, test } from 'vitest'
|
|
2
|
-
import { getAddress } from 'viem'
|
|
3
|
-
|
|
4
|
-
import { lnWad } from '../src/utils/math'
|
|
5
|
-
|
|
6
|
-
import { publicClient } from './utils/constants'
|
|
7
|
-
|
|
8
|
-
const _abi = [
|
|
9
|
-
{
|
|
10
|
-
inputs: [
|
|
11
|
-
{
|
|
12
|
-
internalType: 'uint256',
|
|
13
|
-
name: 'a',
|
|
14
|
-
type: 'uint256',
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
internalType: 'uint256',
|
|
18
|
-
name: 'b',
|
|
19
|
-
type: 'uint256',
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
internalType: 'bool',
|
|
23
|
-
name: 'roundingUp',
|
|
24
|
-
type: 'bool',
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
name: 'divide',
|
|
28
|
-
outputs: [
|
|
29
|
-
{
|
|
30
|
-
internalType: 'uint256',
|
|
31
|
-
name: '',
|
|
32
|
-
type: 'uint256',
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
stateMutability: 'pure',
|
|
36
|
-
type: 'function',
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
inputs: [
|
|
40
|
-
{
|
|
41
|
-
internalType: 'int256',
|
|
42
|
-
name: 'x',
|
|
43
|
-
type: 'int256',
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
name: 'lnWad',
|
|
47
|
-
outputs: [
|
|
48
|
-
{
|
|
49
|
-
internalType: 'int256',
|
|
50
|
-
name: '',
|
|
51
|
-
type: 'int256',
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
stateMutability: 'pure',
|
|
55
|
-
type: 'function',
|
|
56
|
-
},
|
|
57
|
-
] as const
|
|
58
|
-
|
|
59
|
-
const MATH_WRAPPER_ADDRESS = '0x98d55f0AaEda3bad7815C8F3d8f8882e6B702D26'
|
|
60
|
-
|
|
61
|
-
const randomInteger = (start: number, end: number) => {
|
|
62
|
-
return Math.floor(Math.random() * (end - start + 1) + start)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const MIN_PRICE = 1350587n
|
|
66
|
-
const MAX_PRICE = 4647684107270898330752324302845848816923571339324334n
|
|
67
|
-
|
|
68
|
-
test('lnWad', async () => {
|
|
69
|
-
const randomValues = [
|
|
70
|
-
MIN_PRICE,
|
|
71
|
-
...Array.from({ length: 500 }, () =>
|
|
72
|
-
randomInteger(Number(MIN_PRICE + 1n), Number(MAX_PRICE - 1n)),
|
|
73
|
-
),
|
|
74
|
-
MAX_PRICE,
|
|
75
|
-
]
|
|
76
|
-
const actualValues = (
|
|
77
|
-
(await publicClient.multicall({
|
|
78
|
-
contracts: randomValues.map((value) => ({
|
|
79
|
-
address: getAddress(MATH_WRAPPER_ADDRESS),
|
|
80
|
-
abi: _abi,
|
|
81
|
-
functionName: 'lnWad',
|
|
82
|
-
args: [value],
|
|
83
|
-
})),
|
|
84
|
-
})) as { result: bigint }[]
|
|
85
|
-
).map(({ result }) => result)
|
|
86
|
-
|
|
87
|
-
const expectedValues = randomValues.map((priceIndex) =>
|
|
88
|
-
lnWad(BigInt(priceIndex)),
|
|
89
|
-
)
|
|
90
|
-
expect(expectedValues).toEqual(actualValues)
|
|
91
|
-
})
|
package/test/open-order.test.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { expect, test } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
getOpenOrders,
|
|
4
|
-
getOpenOrder,
|
|
5
|
-
claimOrders,
|
|
6
|
-
setApprovalOfOpenOrdersForAll,
|
|
7
|
-
cancelOrders,
|
|
8
|
-
} from '@clober/v2-sdk'
|
|
9
|
-
|
|
10
|
-
import { cloberTestChain } from './utils/test-chain'
|
|
11
|
-
import { account, publicClient, walletClient } from './utils/constants'
|
|
12
|
-
|
|
13
|
-
const IS_LOCAL = process.env.IS_LOCAL === 'true'
|
|
14
|
-
|
|
15
|
-
test.runIf(IS_LOCAL)('get open orders by user address', async () => {
|
|
16
|
-
const openOrders = await getOpenOrders(
|
|
17
|
-
cloberTestChain.id,
|
|
18
|
-
'0xf18Be2a91cF31Fc3f8D828b6c714e1806a75e0AA',
|
|
19
|
-
{
|
|
20
|
-
rpcUrl: publicClient.transport.url!,
|
|
21
|
-
},
|
|
22
|
-
)
|
|
23
|
-
expect(openOrders.length).toBeGreaterThan(0)
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
test.runIf(IS_LOCAL)('get undefined open orders', async () => {
|
|
27
|
-
expect(
|
|
28
|
-
await getOpenOrder(cloberTestChain.id, '200', {
|
|
29
|
-
rpcUrl: publicClient.transport.url!,
|
|
30
|
-
}).catch((e) => e.message),
|
|
31
|
-
).toEqual('Open order not found: 200')
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
test.runIf(IS_LOCAL)('claim all orders', async () => {
|
|
35
|
-
const openOrders = (
|
|
36
|
-
await getOpenOrders(cloberTestChain.id, account.address, {
|
|
37
|
-
rpcUrl: publicClient.transport.url!,
|
|
38
|
-
})
|
|
39
|
-
).slice(0, 5)
|
|
40
|
-
expect(
|
|
41
|
-
await claimOrders(
|
|
42
|
-
cloberTestChain.id,
|
|
43
|
-
account.address,
|
|
44
|
-
openOrders.map((order) => order.id),
|
|
45
|
-
{ rpcUrl: publicClient.transport.url! },
|
|
46
|
-
).catch((e) => e.message),
|
|
47
|
-
).toEqual(`
|
|
48
|
-
import { setApprovalOfOpenOrdersForAll } from '@clober/v2-sdk'
|
|
49
|
-
|
|
50
|
-
const hash = await setApprovalOfOpenOrdersForAll(
|
|
51
|
-
${cloberTestChain.id},
|
|
52
|
-
privateKeyToAccount('0x...')
|
|
53
|
-
)
|
|
54
|
-
`)
|
|
55
|
-
|
|
56
|
-
// be sure to approve before claim
|
|
57
|
-
await publicClient.waitForTransactionReceipt({
|
|
58
|
-
hash: (await setApprovalOfOpenOrdersForAll(cloberTestChain.id, account, {
|
|
59
|
-
rpcUrl: publicClient.transport.url!,
|
|
60
|
-
}))!,
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
const transaction = await claimOrders(
|
|
64
|
-
cloberTestChain.id,
|
|
65
|
-
account.address,
|
|
66
|
-
openOrders.map((order) => order.id),
|
|
67
|
-
{ rpcUrl: publicClient.transport.url! },
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
await walletClient.sendTransaction({ ...transaction, account })
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
test.runIf(IS_LOCAL)('cancel all orders', async () => {
|
|
74
|
-
const openOrders = (
|
|
75
|
-
await getOpenOrders(cloberTestChain.id, account.address, {
|
|
76
|
-
rpcUrl: publicClient.transport.url!,
|
|
77
|
-
})
|
|
78
|
-
)
|
|
79
|
-
.filter((order) => order.cancelable)
|
|
80
|
-
.slice(0, 5)
|
|
81
|
-
expect(
|
|
82
|
-
await cancelOrders(
|
|
83
|
-
cloberTestChain.id,
|
|
84
|
-
account.address,
|
|
85
|
-
openOrders.map((order) => order.id),
|
|
86
|
-
{ rpcUrl: publicClient.transport.url! },
|
|
87
|
-
).catch((e) => e.message),
|
|
88
|
-
).toEqual(`
|
|
89
|
-
import { setApprovalOfOpenOrdersForAll } from '@clober/v2-sdk'
|
|
90
|
-
|
|
91
|
-
const hash = await setApprovalOfOpenOrdersForAll(
|
|
92
|
-
${cloberTestChain.id},
|
|
93
|
-
privateKeyToAccount('0x...')
|
|
94
|
-
)
|
|
95
|
-
`)
|
|
96
|
-
|
|
97
|
-
// be sure to approve before cancel
|
|
98
|
-
await publicClient.waitForTransactionReceipt({
|
|
99
|
-
hash: (await setApprovalOfOpenOrdersForAll(cloberTestChain.id, account, {
|
|
100
|
-
rpcUrl: publicClient.transport.url!,
|
|
101
|
-
}))!,
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
const transaction = await cancelOrders(
|
|
105
|
-
cloberTestChain.id,
|
|
106
|
-
account.address,
|
|
107
|
-
openOrders.map((order) => order.id),
|
|
108
|
-
{ rpcUrl: publicClient.transport.url! },
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
await walletClient.sendTransaction({ ...transaction, account })
|
|
112
|
-
})
|
package/test/open.test.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { expect, test } from 'vitest'
|
|
2
|
-
import { openMarket } from '@clober/v2-sdk'
|
|
3
|
-
|
|
4
|
-
import { publicClient } from './utils/constants'
|
|
5
|
-
import { cloberTestChain } from './utils/test-chain'
|
|
6
|
-
|
|
7
|
-
test('try already open market', async () => {
|
|
8
|
-
const transaction = await openMarket(
|
|
9
|
-
cloberTestChain.id,
|
|
10
|
-
'0x0000000000000000000000000000000000000000',
|
|
11
|
-
'0x447ad4a108b5540c220f9f7e83723ac87c0f8fd8',
|
|
12
|
-
{ rpcUrl: publicClient.transport.url! },
|
|
13
|
-
)
|
|
14
|
-
expect(transaction).toBeUndefined()
|
|
15
|
-
})
|