@cetusprotocol/aggregator-sdk 0.4.0 → 0.4.2

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.
Files changed (102) hide show
  1. package/README.md +19 -8
  2. package/dist/index.d.mts +14 -3
  3. package/dist/index.d.ts +14 -3
  4. package/dist/index.js +25 -27
  5. package/dist/index.mjs +26 -28
  6. package/package.json +1 -1
  7. package/dist/src/api.d.ts +0 -104
  8. package/dist/src/client.d.ts +0 -107
  9. package/dist/src/const.d.ts +0 -8
  10. package/dist/src/errors.d.ts +0 -40
  11. package/dist/src/index.d.ts +0 -9
  12. package/dist/src/math.d.ts +0 -6
  13. package/dist/src/transaction/afsui.d.ts +0 -10
  14. package/dist/src/transaction/aftermath.d.ts +0 -13
  15. package/dist/src/transaction/alphafi.d.ts +0 -7
  16. package/dist/src/transaction/bluefin.d.ts +0 -7
  17. package/dist/src/transaction/bluemove.d.ts +0 -7
  18. package/dist/src/transaction/cetus.d.ts +0 -15
  19. package/dist/src/transaction/deepbook_v2.d.ts +0 -14
  20. package/dist/src/transaction/deepbook_v3.d.ts +0 -12
  21. package/dist/src/transaction/flowx_v2.d.ts +0 -7
  22. package/dist/src/transaction/flowx_v3.d.ts +0 -8
  23. package/dist/src/transaction/haedal.d.ts +0 -6
  24. package/dist/src/transaction/haedal_pmm.d.ts +0 -7
  25. package/dist/src/transaction/index.d.ts +0 -10
  26. package/dist/src/transaction/kriya_v2.d.ts +0 -6
  27. package/dist/src/transaction/kriya_v3.d.ts +0 -7
  28. package/dist/src/transaction/metastable.d.ts +0 -8
  29. package/dist/src/transaction/obric.d.ts +0 -8
  30. package/dist/src/transaction/scallop.d.ts +0 -8
  31. package/dist/src/transaction/steamm.d.ts +0 -6
  32. package/dist/src/transaction/suilend.d.ts +0 -7
  33. package/dist/src/transaction/swap.d.ts +0 -4
  34. package/dist/src/transaction/turbos.d.ts +0 -7
  35. package/dist/src/transaction/volo.d.ts +0 -8
  36. package/dist/src/types/CoinAssist.d.ts +0 -122
  37. package/dist/src/types/sui.d.ts +0 -112
  38. package/dist/src/utils/api.d.ts +0 -1
  39. package/dist/src/utils/coin.d.ts +0 -11
  40. package/dist/src/utils/contracts.d.ts +0 -16
  41. package/dist/src/utils/index.d.ts +0 -5
  42. package/dist/src/utils/msafe.d.ts +0 -2
  43. package/dist/src/utils/transaction.d.ts +0 -3
  44. package/dist/tests/math.test.d.ts +0 -1
  45. package/dist/tests/router/metastable.test.d.ts +0 -2
  46. package/dist/tests/router/obric.test.d.ts +0 -2
  47. package/dist/tests/router/scallop.test.d.ts +0 -2
  48. package/dist/tests/router/steamm.test.d.ts +0 -2
  49. package/dist/tests/router.test.d.ts +0 -2
  50. package/dist/tests/test_data.test.d.ts +0 -18
  51. package/dist/tests/wallet.test.d.ts +0 -1
  52. package/example/package.json +0 -17
  53. package/example/swap.ts +0 -21
  54. package/example/tsconfig.json +0 -12
  55. package/jest.config.mjs +0 -13
  56. package/src/api.ts +0 -320
  57. package/src/client.ts +0 -1081
  58. package/src/const.ts +0 -15
  59. package/src/errors.ts +0 -77
  60. package/src/index.ts +0 -10
  61. package/src/math.ts +0 -66
  62. package/src/transaction/afsui.ts +0 -62
  63. package/src/transaction/aftermath.ts +0 -88
  64. package/src/transaction/alphafi.ts +0 -50
  65. package/src/transaction/bluefin.ts +0 -46
  66. package/src/transaction/bluemove.ts +0 -42
  67. package/src/transaction/cetus.ts +0 -118
  68. package/src/transaction/deepbook_v2.ts +0 -122
  69. package/src/transaction/deepbook_v3.ts +0 -60
  70. package/src/transaction/flowx_v2.ts +0 -42
  71. package/src/transaction/flowx_v3.ts +0 -52
  72. package/src/transaction/haedal.ts +0 -33
  73. package/src/transaction/haedal_pmm.ts +0 -80
  74. package/src/transaction/index.ts +0 -42
  75. package/src/transaction/kriya_v2.ts +0 -37
  76. package/src/transaction/kriya_v3.ts +0 -47
  77. package/src/transaction/metastable.ts +0 -141
  78. package/src/transaction/obric.ts +0 -90
  79. package/src/transaction/scallop.ts +0 -64
  80. package/src/transaction/steamm.ts +0 -77
  81. package/src/transaction/suilend.ts +0 -48
  82. package/src/transaction/swap.ts +0 -162
  83. package/src/transaction/turbos.ts +0 -56
  84. package/src/transaction/volo.ts +0 -53
  85. package/src/types/CoinAssist.ts +0 -217
  86. package/src/types/sui.ts +0 -148
  87. package/src/utils/api.ts +0 -6
  88. package/src/utils/coin.ts +0 -136
  89. package/src/utils/contracts.ts +0 -136
  90. package/src/utils/index.ts +0 -5
  91. package/src/utils/msafe.ts +0 -40
  92. package/src/utils/transaction.ts +0 -20
  93. package/tests/math.test.ts +0 -21
  94. package/tests/router/metastable.test.ts +0 -377
  95. package/tests/router/obric.test.ts +0 -197
  96. package/tests/router/scallop.test.ts +0 -127
  97. package/tests/router/steamm.test.ts +0 -124
  98. package/tests/router.test.ts +0 -373
  99. package/tests/test_data.test.ts +0 -28
  100. package/tests/wallet.test.ts +0 -21
  101. package/tsup.config.ts +0 -23
  102. package/version.mjs +0 -28
@@ -1,60 +0,0 @@
1
- import {
2
- Transaction,
3
- TransactionArgument,
4
- TransactionObjectArgument,
5
- } from "@mysten/sui/transactions"
6
- import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, getAggregatorV2ExtendPublishedAt, Path } from ".."
7
- import { mintZeroCoin } from "~/utils/coin"
8
-
9
- export type CetusFlashSwapResult = {
10
- targetCoin: TransactionObjectArgument
11
- flashReceipt: TransactionObjectArgument
12
- payAmount: TransactionArgument
13
- }
14
-
15
- export class DeepbookV3 implements Dex {
16
- private deepbookV3Config: string
17
-
18
- constructor(env: Env) {
19
- this.deepbookV3Config =
20
- env === Env.Mainnet
21
- ? "0xe4099d0cda04f3aa80028fac91a9b3dbe50d08f2ff42aa2c29473926e34ca48c"
22
- : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa"
23
- }
24
-
25
- async swap(
26
- client: AggregatorClient,
27
- txb: Transaction,
28
- path: Path,
29
- inputCoin: TransactionObjectArgument,
30
- packages?: Map<string, string>,
31
- deepbookv3DeepFee?: TransactionObjectArgument,
32
- ): Promise<TransactionObjectArgument> {
33
- const { direction, from, target } = path
34
- const [func, coinAType, coinBType] = direction
35
- ? ["swap_a2b", from, target]
36
- : ["swap_b2a", target, from]
37
-
38
- let deepFee
39
- if (deepbookv3DeepFee) {
40
- deepFee = deepbookv3DeepFee
41
- } else {
42
- deepFee = mintZeroCoin(txb, client.deepbookv3DeepFeeType())
43
- }
44
-
45
- const args = [
46
- txb.object(this.deepbookV3Config),
47
- txb.object(path.id),
48
- inputCoin,
49
- deepFee,
50
- txb.object(CLOCK_ADDRESS),
51
- ]
52
- const publishedAt = getAggregatorV2ExtendPublishedAt(client.publishedAtV2Extend(), packages)
53
- const res = txb.moveCall({
54
- target: `${publishedAt}::deepbookv3::${func}`,
55
- typeArguments: [coinAType, coinBType],
56
- arguments: args,
57
- }) as TransactionArgument
58
- return res
59
- }
60
- }
@@ -1,42 +0,0 @@
1
- import {
2
- Transaction,
3
- TransactionObjectArgument,
4
- } from "@mysten/sui/transactions"
5
- import { AggregatorClient, Dex, Env, getAggregatorV2PublishedAt, Path } from ".."
6
-
7
- export class FlowxV2 implements Dex {
8
- private container: string
9
-
10
- constructor(env: Env) {
11
- if (env !== Env.Mainnet) {
12
- throw new Error("Flowx only supported on mainnet")
13
- }
14
-
15
- this.container =
16
- "0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511"
17
- }
18
-
19
- async swap(
20
- client: AggregatorClient,
21
- txb: Transaction,
22
- path: Path,
23
- inputCoin: TransactionObjectArgument,
24
- packages?: Map<string, string>
25
- ): Promise<TransactionObjectArgument> {
26
- const { direction, from, target } = path
27
-
28
- const [func, coinAType, coinBType] = direction
29
- ? ["swap_a2b", from, target]
30
- : ["swap_b2a", target, from]
31
-
32
- const args = [txb.object(this.container), inputCoin]
33
- const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
34
- const res = txb.moveCall({
35
- target: `${publishedAt}::flowx_amm::${func}`,
36
- typeArguments: [coinAType, coinBType],
37
- arguments: args,
38
- }) as TransactionObjectArgument
39
-
40
- return res
41
- }
42
- }
@@ -1,52 +0,0 @@
1
- import {
2
- Transaction,
3
- TransactionObjectArgument,
4
- } from "@mysten/sui/transactions"
5
- import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, getAggregatorV2PublishedAt, Path } from ".."
6
-
7
- export class FlowxV3 implements Dex {
8
- private versioned: string
9
- private poolRegistry: string
10
-
11
- constructor(env: Env) {
12
- if (env !== Env.Mainnet) {
13
- throw new Error("Flowx clmm only supported on mainnet")
14
- }
15
-
16
- this.versioned =
17
- "0x67624a1533b5aff5d0dfcf5e598684350efd38134d2d245f475524c03a64e656"
18
- this.poolRegistry =
19
- "0x27565d24a4cd51127ac90e4074a841bbe356cca7bf5759ddc14a975be1632abc"
20
- }
21
-
22
- async swap(
23
- client: AggregatorClient,
24
- txb: Transaction,
25
- path: Path,
26
- inputCoin: TransactionObjectArgument,
27
- packages?: Map<string, string>
28
- ): Promise<TransactionObjectArgument> {
29
- const { direction, from, target } = path
30
-
31
- const [func, coinAType, coinBType] = direction
32
- ? ["swap_a2b", from, target]
33
- : ["swap_b2a", target, from]
34
-
35
- const args = [
36
- txb.object(this.poolRegistry),
37
- txb.pure.u64(path.feeRate * 1000000),
38
- inputCoin,
39
- txb.object(this.versioned),
40
- txb.object(CLOCK_ADDRESS),
41
- ]
42
-
43
- const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
44
- const res = txb.moveCall({
45
- target: `${publishedAt}::flowx_clmm::${func}`,
46
- typeArguments: [coinAType, coinBType],
47
- arguments: args,
48
- }) as TransactionObjectArgument
49
-
50
- return res
51
- }
52
- }
@@ -1,33 +0,0 @@
1
- import {
2
- Transaction,
3
- TransactionObjectArgument,
4
- } from "@mysten/sui/transactions"
5
- import { AggregatorClient, Dex, Env, getAggregatorV2PublishedAt, Path } from ".."
6
-
7
- export class Haedal implements Dex {
8
- constructor(env: Env) {
9
- if (env !== Env.Mainnet) {
10
- throw new Error("Haedal only supported on mainnet")
11
- }
12
- }
13
-
14
- async swap(
15
- client: AggregatorClient,
16
- txb: Transaction,
17
- path: Path,
18
- inputCoin: TransactionObjectArgument,
19
- packages?: Map<string, string>
20
- ): Promise<TransactionObjectArgument> {
21
- const { direction } = path
22
- const func = direction ? "swap_a2b" : "swap_b2a"
23
- const args = [txb.object(path.id), txb.object("0x5"), inputCoin]
24
- const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
25
- const res = txb.moveCall({
26
- target: `${publishedAt}::haedal::${func}`,
27
- typeArguments: [],
28
- arguments: args,
29
- }) as TransactionObjectArgument
30
-
31
- return res
32
- }
33
- }
@@ -1,80 +0,0 @@
1
- import {
2
- Transaction,
3
- TransactionArgument,
4
- TransactionObjectArgument,
5
- } from "@mysten/sui/transactions"
6
- import {
7
- AggregatorClient,
8
- CLOCK_ADDRESS,
9
- Dex,
10
- Env,
11
- getAggregatorV2ExtendPublishedAt,
12
- Path,
13
- } from ".."
14
-
15
- export class HaedalPmm implements Dex {
16
- private pythPriceIDs: Map<string, string>
17
-
18
- constructor(env: Env, pythPriceIDs: Map<string, string>) {
19
- if (env === Env.Testnet) {
20
- throw new Error("HaedalPmm is not supported on testnet")
21
- }
22
- this.pythPriceIDs = pythPriceIDs
23
- }
24
-
25
- async swap(
26
- client: AggregatorClient,
27
- txb: Transaction,
28
- path: Path,
29
- inputCoin: TransactionObjectArgument,
30
- packages?: Map<string, string>
31
- ): Promise<TransactionObjectArgument> {
32
- const { direction, from, target } = path
33
- const [func, coinAType, coinBType] = direction
34
- ? ["swap_a2b", from, target]
35
- : ["swap_b2a", target, from]
36
-
37
- let basePriceSeed: string
38
- let quotePriceSeed: string
39
-
40
- if (path.extendedDetails == null) {
41
- throw new Error("Extended details not supported haedal pmm")
42
- } else {
43
- if (
44
- !path.extendedDetails.haedalPmmBasePriceSeed ||
45
- !path.extendedDetails.haedalPmmQuotePriceSeed
46
- ) {
47
- throw new Error("Base price seed or quote price seed not supported")
48
- }
49
- basePriceSeed = path.extendedDetails.haedalPmmBasePriceSeed
50
- quotePriceSeed = path.extendedDetails.haedalPmmQuotePriceSeed
51
- }
52
-
53
- const basePriceInfoObjectId = this.pythPriceIDs.get(basePriceSeed)
54
- const quotePriceInfoObjectId = this.pythPriceIDs.get(quotePriceSeed)
55
-
56
- if (!basePriceInfoObjectId || !quotePriceInfoObjectId) {
57
- throw new Error(
58
- "Base price info object id or quote price info object id not found"
59
- )
60
- }
61
-
62
- const args = [
63
- txb.object(path.id),
64
- txb.object(basePriceInfoObjectId),
65
- txb.object(quotePriceInfoObjectId),
66
- inputCoin,
67
- txb.object(CLOCK_ADDRESS),
68
- ]
69
- const publishedAt = getAggregatorV2ExtendPublishedAt(
70
- client.publishedAtV2Extend(),
71
- packages
72
- )
73
- const res = txb.moveCall({
74
- target: `${publishedAt}::haedalpmm::${func}`,
75
- typeArguments: [coinAType, coinBType],
76
- arguments: args,
77
- }) as TransactionArgument
78
- return res
79
- }
80
- }
@@ -1,42 +0,0 @@
1
- import {
2
- Transaction,
3
- TransactionObjectArgument,
4
- } from "@mysten/sui/transactions"
5
- import { AggregatorClient, Path } from ".."
6
- import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils"
7
-
8
- export const CLOCK_ADDRESS = SUI_CLOCK_OBJECT_ID
9
-
10
- export const AGGREGATOR_V2 = "aggregator_v2"
11
- export const AGGREGATOR_V2_EXTEND = "aggregator_v2_extend"
12
-
13
- export function getAggregatorV2PublishedAt(
14
- aggregatorV2PublishedAt: string,
15
- packages?: Map<string, string> | Record<string, string>
16
- ) {
17
- if (packages instanceof Map) {
18
- return packages.get(AGGREGATOR_V2) ?? aggregatorV2PublishedAt
19
- }
20
- return aggregatorV2PublishedAt
21
- }
22
-
23
- export function getAggregatorV2ExtendPublishedAt(
24
- aggregatorV2ExtendPublishedAt: string,
25
- packages?: Map<string, string> | Record<string, string>
26
- ) {
27
- if (packages instanceof Map) {
28
- return packages.get(AGGREGATOR_V2_EXTEND) ?? aggregatorV2ExtendPublishedAt
29
- }
30
- return aggregatorV2ExtendPublishedAt
31
- }
32
-
33
- export interface Dex {
34
- swap(
35
- client: AggregatorClient,
36
- ptb: Transaction,
37
- path: Path,
38
- inputCoin: TransactionObjectArgument,
39
- packages?: Map<string, string>,
40
- deepbookv3DeepFee?: TransactionObjectArgument
41
- ): Promise<TransactionObjectArgument>
42
- }
@@ -1,37 +0,0 @@
1
- import {
2
- Transaction,
3
- TransactionObjectArgument,
4
- } from "@mysten/sui/transactions"
5
- import { AggregatorClient, Dex, Env, getAggregatorV2PublishedAt, Path } from ".."
6
-
7
- export class KriyaV2 implements Dex {
8
- constructor(env: Env) {
9
- if (env !== Env.Mainnet) {
10
- throw new Error("Kriya amm only supported on mainnet")
11
- }
12
- }
13
-
14
- async swap(
15
- client: AggregatorClient,
16
- txb: Transaction,
17
- path: Path,
18
- inputCoin: TransactionObjectArgument,
19
- packages?: Map<string, string>
20
- ): Promise<TransactionObjectArgument> {
21
- const { direction, from, target } = path
22
-
23
- const [func, coinAType, coinBType] = direction
24
- ? ["swap_a2b", from, target]
25
- : ["swap_b2a", target, from]
26
-
27
- const args = [txb.object(path.id), inputCoin]
28
- const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
29
- const res = txb.moveCall({
30
- target: `${publishedAt}::kriya_amm::${func}`,
31
- typeArguments: [coinAType, coinBType],
32
- arguments: args,
33
- }) as TransactionObjectArgument
34
-
35
- return res
36
- }
37
- }
@@ -1,47 +0,0 @@
1
- import {
2
- Transaction,
3
- TransactionObjectArgument,
4
- } from "@mysten/sui/transactions"
5
- import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, getAggregatorV2PublishedAt, Path } from ".."
6
-
7
- export class KriyaV3 implements Dex {
8
- private version: string
9
-
10
- constructor(env: Env) {
11
- if (env !== Env.Mainnet) {
12
- throw new Error("Kriya clmm only supported on mainnet")
13
- }
14
-
15
- this.version =
16
- "0xf5145a7ac345ca8736cf8c76047d00d6d378f30e81be6f6eb557184d9de93c78"
17
- }
18
-
19
- async swap(
20
- client: AggregatorClient,
21
- txb: Transaction,
22
- path: Path,
23
- inputCoin: TransactionObjectArgument,
24
- packages?: Map<string, string>
25
- ): Promise<TransactionObjectArgument> {
26
- const { direction, from, target } = path
27
-
28
- const [func, coinAType, coinBType] = direction
29
- ? ["swap_a2b", from, target]
30
- : ["swap_b2a", target, from]
31
-
32
- const args = [
33
- txb.object(path.id),
34
- inputCoin,
35
- txb.object(this.version),
36
- txb.object(CLOCK_ADDRESS),
37
- ]
38
- const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
39
- const res = txb.moveCall({
40
- target: `${publishedAt}::kriya_clmm::${func}`,
41
- typeArguments: [coinAType, coinBType],
42
- arguments: args,
43
- }) as TransactionObjectArgument
44
-
45
- return res
46
- }
47
- }
@@ -1,141 +0,0 @@
1
- import {
2
- Transaction,
3
- TransactionObjectArgument,
4
- } from "@mysten/sui/transactions"
5
- import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, getAggregatorV2ExtendPublishedAt, Path } from ".."
6
-
7
- const SUPER_SUI_TYPE = "0x790f258062909e3a0ffc78b3c53ac2f62d7084c3bab95644bdeb05add7250001::super_sui::SUPER_SUI"
8
- const MUSD_TYPE = "0xe44df51c0b21a27ab915fa1fe2ca610cd3eaa6d9666fe5e62b988bf7f0bd8722::musd::MUSD"
9
- const METH_TYPE = "0xccd628c2334c5ed33e6c47d6c21bb664f8b6307b2ac32c2462a61f69a31ebcee::meth::METH"
10
-
11
- export class Metastable implements Dex {
12
- private pythPriceIDs: Map<string, string>
13
- private versionID: string
14
-
15
- constructor(env: Env, pythPriceIDs: Map<string, string>) {
16
- if (env !== Env.Mainnet) {
17
- throw new Error("Metastable only supported on mainnet")
18
- }
19
- this.versionID = "0x4696559327b35ff2ab26904e7426a1646312e9c836d5c6cff6709a5ccc30915c"
20
- this.pythPriceIDs = pythPriceIDs
21
- }
22
-
23
- async swap(
24
- client: AggregatorClient,
25
- txb: Transaction,
26
- path: Path,
27
- inputCoin: TransactionObjectArgument,
28
- packages?: Map<string, string>
29
- ): Promise<TransactionObjectArgument> {
30
- const { direction, from, target } = path
31
-
32
- const [func, createCapFunc, coinType, metaCoinType] = direction
33
- ? ["swap_a2b", "create_deposit_cap", from, target]
34
- : ["swap_b2a", "create_withdraw_cap", target, from]
35
-
36
- let createExchangePkgId = "";
37
- let createDepositModule = "pyth";
38
- let metaSingletonId = "";
39
- if (path.extendedDetails == null) {
40
- throw new Error("Extended details not supported metastable")
41
- } else {
42
- if (
43
- !path.extendedDetails.metastableCreateCapPkgId ||
44
- !path.extendedDetails.metastableCreateCapModule ||
45
- !path.extendedDetails.metastableRegistryId ||
46
- !path.extendedDetails.metastableWhitelistedAppId
47
- ) {
48
- throw new Error("CreateCapPkgId or CreateCapModule or RegistryId or WhitelistedAppId or CreateCapAllTypeParams not supported")
49
- }
50
- createExchangePkgId = path.extendedDetails.metastableCreateCapPkgId
51
- createDepositModule = path.extendedDetails.metastableCreateCapModule
52
- metaSingletonId = path.extendedDetails.metastableWhitelistedAppId
53
- }
54
-
55
- const createDepositCapTypeArgs = [
56
- metaCoinType
57
- ]
58
- if (path.extendedDetails.metastableCreateCapAllTypeParams) {
59
- createDepositCapTypeArgs.push(coinType);
60
- }
61
-
62
- const depositArgs = [
63
- txb.object(metaSingletonId),
64
- txb.object(path.id),
65
- ]
66
-
67
- switch (metaCoinType) {
68
- case SUPER_SUI_TYPE: {
69
- if (!path.extendedDetails.metastableRegistryId) {
70
- throw new Error("Not found registry id for super sui")
71
- }
72
- depositArgs.push(txb.object(path.extendedDetails.metastableRegistryId));
73
- break;
74
- }
75
- case MUSD_TYPE: {
76
- if (path.extendedDetails.metastablePriceSeed != null) {
77
- const priceId = this.pythPriceIDs.get(path.extendedDetails.metastablePriceSeed)
78
- if (priceId == null) {
79
- throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastablePriceSeed)
80
- }
81
- depositArgs.push(txb.object(priceId));
82
- }
83
- if (path.extendedDetails.metastableETHPriceSeed != null) {
84
- const priceId = this.pythPriceIDs.get(path.extendedDetails.metastableETHPriceSeed)
85
- if (priceId == null) {
86
- throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastableETHPriceSeed)
87
- }
88
- depositArgs.push(txb.object(priceId));
89
- }
90
- depositArgs.push(txb.object(CLOCK_ADDRESS));
91
- break;
92
- }
93
- case METH_TYPE: {
94
- if (path.extendedDetails.metastablePriceSeed != null) {
95
- const priceId = this.pythPriceIDs.get(path.extendedDetails.metastablePriceSeed)
96
- if (priceId == null) {
97
- throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastablePriceSeed)
98
- }
99
- depositArgs.push(txb.object(priceId));
100
- }
101
- if (path.extendedDetails.metastableETHPriceSeed != null) {
102
- const priceId = this.pythPriceIDs.get(path.extendedDetails.metastableETHPriceSeed)
103
- if (priceId == null) {
104
- throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastableETHPriceSeed)
105
- }
106
- depositArgs.push(txb.object(priceId));
107
- }
108
- depositArgs.push(txb.object(CLOCK_ADDRESS));
109
- break;
110
- }
111
-
112
- default:
113
- throw new Error("Invalid Metacoin: " + metaCoinType);
114
- }
115
-
116
- const depositResult = txb.moveCall({
117
- target: `${createExchangePkgId}::${createDepositModule}::${createCapFunc}`,
118
- typeArguments: createDepositCapTypeArgs,
119
- arguments: depositArgs,
120
- }) as TransactionObjectArgument
121
-
122
- const swapArgs = [
123
- txb.object(path.id),
124
- txb.object(this.versionID),
125
- depositResult,
126
- inputCoin,
127
- ]
128
-
129
- const publishedAt = getAggregatorV2ExtendPublishedAt(client.publishedAtV2Extend(), packages)
130
- const res = txb.moveCall({
131
- target: `${publishedAt}::metastable::${func}`,
132
- typeArguments: [
133
- coinType,
134
- metaCoinType,
135
- ],
136
- arguments: swapArgs,
137
- }) as TransactionObjectArgument
138
-
139
- return res
140
- }
141
- }
@@ -1,90 +0,0 @@
1
- import {
2
- Transaction,
3
- TransactionArgument,
4
- TransactionObjectArgument,
5
- } from "@mysten/sui/transactions"
6
- import {
7
- AggregatorClient,
8
- CLOCK_ADDRESS,
9
- Dex,
10
- Env,
11
- getAggregatorV2ExtendPublishedAt,
12
- Path,
13
- } from ".."
14
-
15
- export class Obric implements Dex {
16
- private pythPriceIDs: Map<string, string>
17
- private pythStateObjectId: string
18
-
19
- constructor(env: Env, pythPriceIDs: Map<string, string>) {
20
- if (env === Env.Testnet) {
21
- throw new Error("Obric is not supported on testnet")
22
- }
23
- this.pythPriceIDs = pythPriceIDs
24
- this.pythStateObjectId = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"
25
- }
26
-
27
- async swap(
28
- client: AggregatorClient,
29
- txb: Transaction,
30
- path: Path,
31
- inputCoin: TransactionObjectArgument,
32
- packages?: Map<string, string>
33
- ): Promise<TransactionObjectArgument> {
34
- const { direction, from, target } = path
35
- const [func, coinAType, coinBType] = direction
36
- ? ["swap_a2b", from, target]
37
- : ["swap_b2a", target, from]
38
-
39
- let coinAPriceSeed
40
- let coinBPriceSeed
41
-
42
- let coinAPriceInfoObjectId
43
- let coinBPriceInfoObjectId
44
-
45
- if (path.extendedDetails == null) {
46
- throw new Error("Extended details not supported in obric")
47
- } else {
48
- if (
49
- path.extendedDetails.obricCoinAPriceSeed && path.extendedDetails.obricCoinBPriceSeed
50
- ) {
51
- coinAPriceSeed = path.extendedDetails.obricCoinAPriceSeed
52
- coinAPriceInfoObjectId = this.pythPriceIDs.get(coinAPriceSeed!)
53
- coinBPriceSeed = path.extendedDetails.obricCoinBPriceSeed
54
- coinBPriceInfoObjectId = this.pythPriceIDs.get(coinBPriceSeed!)
55
- } else {
56
- if (!path.extendedDetails.obricCoinAPriceId || !path.extendedDetails.obricCoinBPriceId) {
57
- throw new Error("Base price id or quote price id not supported")
58
- } else {
59
- coinAPriceInfoObjectId = path.extendedDetails.obricCoinAPriceId
60
- coinBPriceInfoObjectId = path.extendedDetails.obricCoinBPriceId
61
- }
62
- }
63
- }
64
-
65
- if (!coinAPriceInfoObjectId || !coinBPriceInfoObjectId) {
66
- throw new Error(
67
- "Base price info object id or quote price info object id not found"
68
- )
69
- }
70
-
71
- const args = [
72
- txb.object(path.id),
73
- inputCoin,
74
- txb.object(this.pythStateObjectId),
75
- txb.object(coinAPriceInfoObjectId),
76
- txb.object(coinBPriceInfoObjectId),
77
- txb.object(CLOCK_ADDRESS),
78
- ]
79
- const publishedAt = getAggregatorV2ExtendPublishedAt(
80
- client.publishedAtV2Extend(),
81
- packages
82
- )
83
- const res = txb.moveCall({
84
- target: `${publishedAt}::obric::${func}`,
85
- typeArguments: [coinAType, coinBType],
86
- arguments: args,
87
- }) as TransactionArgument
88
- return res
89
- }
90
- }
@@ -1,64 +0,0 @@
1
- import {
2
- Transaction,
3
- TransactionObjectArgument,
4
- } from "@mysten/sui/transactions"
5
- import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, getAggregatorV2ExtendPublishedAt, Path } from ".."
6
-
7
- export class Scallop implements Dex {
8
- private version: string
9
- private market: string
10
-
11
- constructor(env: Env) {
12
- if (env !== Env.Mainnet) {
13
- throw new Error("Scallop only supported on mainnet")
14
- }
15
-
16
- this.version = env === Env.Mainnet
17
- ? "0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7"
18
- : "0x0"
19
-
20
- this.market =
21
- env === Env.Mainnet
22
- ? "0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9"
23
- : "0x0"
24
- }
25
-
26
- async swap(
27
- client: AggregatorClient,
28
- txb: Transaction,
29
- path: Path,
30
- inputCoin: TransactionObjectArgument,
31
- packages?: Map<string, string>
32
- ): Promise<TransactionObjectArgument> {
33
- const { direction, from, target } = path
34
-
35
- // in scallop swap, the first coin type is always the common coin, the second coin type is always the special
36
- const [func, coinAType, coinBType] = direction
37
- ? ["swap_a2b", from, target]
38
- : ["swap_b2a", from, target]
39
-
40
- if (path.extendedDetails == null) {
41
- throw new Error("Extended details not supported")
42
- } else {
43
- if (path.extendedDetails.scallopScoinTreasury == null) {
44
- throw new Error("Scallop coin treasury not supported")
45
- }
46
- }
47
-
48
- const args = [
49
- txb.object(this.version),
50
- txb.object(this.market),
51
- txb.object(path.extendedDetails.scallopScoinTreasury),
52
- inputCoin,
53
- txb.object(CLOCK_ADDRESS),
54
- ]
55
- const publishedAt = getAggregatorV2ExtendPublishedAt(client.publishedAtV2Extend(), packages)
56
- const res = txb.moveCall({
57
- target: `${publishedAt}::scallop::${func}`,
58
- typeArguments: [coinAType, coinBType],
59
- arguments: args,
60
- }) as TransactionObjectArgument
61
-
62
- return res
63
- }
64
- }