@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.
- package/README.md +19 -8
- package/dist/index.d.mts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +25 -27
- package/dist/index.mjs +26 -28
- package/package.json +1 -1
- package/dist/src/api.d.ts +0 -104
- package/dist/src/client.d.ts +0 -107
- package/dist/src/const.d.ts +0 -8
- package/dist/src/errors.d.ts +0 -40
- package/dist/src/index.d.ts +0 -9
- package/dist/src/math.d.ts +0 -6
- package/dist/src/transaction/afsui.d.ts +0 -10
- package/dist/src/transaction/aftermath.d.ts +0 -13
- package/dist/src/transaction/alphafi.d.ts +0 -7
- package/dist/src/transaction/bluefin.d.ts +0 -7
- package/dist/src/transaction/bluemove.d.ts +0 -7
- package/dist/src/transaction/cetus.d.ts +0 -15
- package/dist/src/transaction/deepbook_v2.d.ts +0 -14
- package/dist/src/transaction/deepbook_v3.d.ts +0 -12
- package/dist/src/transaction/flowx_v2.d.ts +0 -7
- package/dist/src/transaction/flowx_v3.d.ts +0 -8
- package/dist/src/transaction/haedal.d.ts +0 -6
- package/dist/src/transaction/haedal_pmm.d.ts +0 -7
- package/dist/src/transaction/index.d.ts +0 -10
- package/dist/src/transaction/kriya_v2.d.ts +0 -6
- package/dist/src/transaction/kriya_v3.d.ts +0 -7
- package/dist/src/transaction/metastable.d.ts +0 -8
- package/dist/src/transaction/obric.d.ts +0 -8
- package/dist/src/transaction/scallop.d.ts +0 -8
- package/dist/src/transaction/steamm.d.ts +0 -6
- package/dist/src/transaction/suilend.d.ts +0 -7
- package/dist/src/transaction/swap.d.ts +0 -4
- package/dist/src/transaction/turbos.d.ts +0 -7
- package/dist/src/transaction/volo.d.ts +0 -8
- package/dist/src/types/CoinAssist.d.ts +0 -122
- package/dist/src/types/sui.d.ts +0 -112
- package/dist/src/utils/api.d.ts +0 -1
- package/dist/src/utils/coin.d.ts +0 -11
- package/dist/src/utils/contracts.d.ts +0 -16
- package/dist/src/utils/index.d.ts +0 -5
- package/dist/src/utils/msafe.d.ts +0 -2
- package/dist/src/utils/transaction.d.ts +0 -3
- package/dist/tests/math.test.d.ts +0 -1
- package/dist/tests/router/metastable.test.d.ts +0 -2
- package/dist/tests/router/obric.test.d.ts +0 -2
- package/dist/tests/router/scallop.test.d.ts +0 -2
- package/dist/tests/router/steamm.test.d.ts +0 -2
- package/dist/tests/router.test.d.ts +0 -2
- package/dist/tests/test_data.test.d.ts +0 -18
- package/dist/tests/wallet.test.d.ts +0 -1
- package/example/package.json +0 -17
- package/example/swap.ts +0 -21
- package/example/tsconfig.json +0 -12
- package/jest.config.mjs +0 -13
- package/src/api.ts +0 -320
- package/src/client.ts +0 -1081
- package/src/const.ts +0 -15
- package/src/errors.ts +0 -77
- package/src/index.ts +0 -10
- package/src/math.ts +0 -66
- package/src/transaction/afsui.ts +0 -62
- package/src/transaction/aftermath.ts +0 -88
- package/src/transaction/alphafi.ts +0 -50
- package/src/transaction/bluefin.ts +0 -46
- package/src/transaction/bluemove.ts +0 -42
- package/src/transaction/cetus.ts +0 -118
- package/src/transaction/deepbook_v2.ts +0 -122
- package/src/transaction/deepbook_v3.ts +0 -60
- package/src/transaction/flowx_v2.ts +0 -42
- package/src/transaction/flowx_v3.ts +0 -52
- package/src/transaction/haedal.ts +0 -33
- package/src/transaction/haedal_pmm.ts +0 -80
- package/src/transaction/index.ts +0 -42
- package/src/transaction/kriya_v2.ts +0 -37
- package/src/transaction/kriya_v3.ts +0 -47
- package/src/transaction/metastable.ts +0 -141
- package/src/transaction/obric.ts +0 -90
- package/src/transaction/scallop.ts +0 -64
- package/src/transaction/steamm.ts +0 -77
- package/src/transaction/suilend.ts +0 -48
- package/src/transaction/swap.ts +0 -162
- package/src/transaction/turbos.ts +0 -56
- package/src/transaction/volo.ts +0 -53
- package/src/types/CoinAssist.ts +0 -217
- package/src/types/sui.ts +0 -148
- package/src/utils/api.ts +0 -6
- package/src/utils/coin.ts +0 -136
- package/src/utils/contracts.ts +0 -136
- package/src/utils/index.ts +0 -5
- package/src/utils/msafe.ts +0 -40
- package/src/utils/transaction.ts +0 -20
- package/tests/math.test.ts +0 -21
- package/tests/router/metastable.test.ts +0 -377
- package/tests/router/obric.test.ts +0 -197
- package/tests/router/scallop.test.ts +0 -127
- package/tests/router/steamm.test.ts +0 -124
- package/tests/router.test.ts +0 -373
- package/tests/test_data.test.ts +0 -28
- package/tests/wallet.test.ts +0 -21
- package/tsup.config.ts +0 -23
- package/version.mjs +0 -28
package/src/const.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import BN from "bn.js"
|
|
2
|
-
|
|
3
|
-
export const ZERO = new BN(0)
|
|
4
|
-
|
|
5
|
-
export const ONE = new BN(1)
|
|
6
|
-
|
|
7
|
-
export const TWO = new BN(2)
|
|
8
|
-
|
|
9
|
-
export const U128 = TWO.pow(new BN(128))
|
|
10
|
-
|
|
11
|
-
export const U64_MAX_BN = new BN("18446744073709551615")
|
|
12
|
-
|
|
13
|
-
export const U64_MAX = "18446744073709551615"
|
|
14
|
-
|
|
15
|
-
export const TEN_POW_NINE = 1000000000
|
package/src/errors.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
export enum TypesErrorCode {
|
|
2
|
-
InvalidType = `InvalidType`,
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export enum ConfigErrorCode {
|
|
6
|
-
MissAggregatorPackage = `MissAggregatorPackage`,
|
|
7
|
-
MissGlobalConfig = `MissGlobalConfig`,
|
|
8
|
-
InvalidWallet = `InvalidWallet`,
|
|
9
|
-
SimulateError = `SimulateError`,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export enum TransactionErrorCode {
|
|
13
|
-
InsufficientBalance = `InsufficientBalance`,
|
|
14
|
-
SimulateEventError = `simulateEventError`,
|
|
15
|
-
CannotGetDecimals = `CannotGetDecimals`,
|
|
16
|
-
MissCoinA = `MissCoinA`,
|
|
17
|
-
MissCoinB = `MissCoinB`,
|
|
18
|
-
MissTurbosFeeType = `MissTurbosFeeType`,
|
|
19
|
-
MissAftermathLpSupplyType = `MissAftermathLpSupplyType`,
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type AggregatorErrorCode =
|
|
23
|
-
| TypesErrorCode
|
|
24
|
-
| ConfigErrorCode
|
|
25
|
-
| TransactionErrorCode
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* AggregatorError is a custom error class that extends the built-in Error class. It is used to represent errors that occur during aggregation operations.
|
|
29
|
-
* The key functionality of this code includes:
|
|
30
|
-
* - Defining the AggregatorError class that represents an error during aggregation. It includes a message property and an optional errorCode property.
|
|
31
|
-
* - Providing a static method isAggregatorErrorCode() that checks if a given error instance is an instance of AggregatorError and has a specific error code.
|
|
32
|
-
*/
|
|
33
|
-
export class AggregatorError extends Error {
|
|
34
|
-
override message: string
|
|
35
|
-
|
|
36
|
-
errorCode?: AggregatorErrorCode
|
|
37
|
-
|
|
38
|
-
constructor(message: string, errorCode?: AggregatorErrorCode) {
|
|
39
|
-
super(message)
|
|
40
|
-
this.message = message
|
|
41
|
-
this.errorCode = errorCode
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
static isAggregatorErrorCode(e: any, code: AggregatorErrorCode): boolean {
|
|
45
|
-
return e instanceof AggregatorError && e.errorCode === code
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export enum AggregatorServerErrorCode {
|
|
50
|
-
CalculateError = 10000,
|
|
51
|
-
NumberTooLarge = 10001,
|
|
52
|
-
NoRouter = 10002,
|
|
53
|
-
InsufficientLiquidity = 10003,
|
|
54
|
-
HoneyPot = 10004,
|
|
55
|
-
RateLimitExceeded = 10005,
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function getAggregatorServerErrorMessage(
|
|
59
|
-
code: AggregatorServerErrorCode
|
|
60
|
-
): string {
|
|
61
|
-
switch (code) {
|
|
62
|
-
case AggregatorServerErrorCode.CalculateError:
|
|
63
|
-
return "Calculate error"
|
|
64
|
-
case AggregatorServerErrorCode.NumberTooLarge:
|
|
65
|
-
return "Input number too large can not fit in target type"
|
|
66
|
-
case AggregatorServerErrorCode.NoRouter:
|
|
67
|
-
return "No router"
|
|
68
|
-
case AggregatorServerErrorCode.InsufficientLiquidity:
|
|
69
|
-
return "Insufficient Liquidity"
|
|
70
|
-
case AggregatorServerErrorCode.HoneyPot:
|
|
71
|
-
return "Target token is detected as a HoneyPot scam"
|
|
72
|
-
case AggregatorServerErrorCode.RateLimitExceeded:
|
|
73
|
-
return "Too many requests. Please try again later"
|
|
74
|
-
default:
|
|
75
|
-
return "Unknown error"
|
|
76
|
-
}
|
|
77
|
-
}
|
package/src/index.ts
DELETED
package/src/math.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// Calculate amount limit.
|
|
2
|
-
// If byAmountIn is true, the expectAmount means amountOut, otherwise means amountIn.
|
|
3
|
-
// `byAmountIn` means fixed amount in or out.
|
|
4
|
-
|
|
5
|
-
import BN from "bn.js"
|
|
6
|
-
import { TEN_POW_NINE, ZERO } from "./const"
|
|
7
|
-
import Decimal from "decimal.js"
|
|
8
|
-
|
|
9
|
-
// `slippage` is a percentage, for example, 0.01 means 1%.
|
|
10
|
-
export function CalculateAmountLimit(
|
|
11
|
-
expectAmount: BN,
|
|
12
|
-
byAmountIn: boolean,
|
|
13
|
-
slippage: number
|
|
14
|
-
): number {
|
|
15
|
-
let amountLimit = ZERO
|
|
16
|
-
if (byAmountIn) {
|
|
17
|
-
amountLimit = expectAmount
|
|
18
|
-
.mul(new BN(TEN_POW_NINE - slippage * TEN_POW_NINE))
|
|
19
|
-
.div(new BN(TEN_POW_NINE))
|
|
20
|
-
} else {
|
|
21
|
-
amountLimit = expectAmount
|
|
22
|
-
.mul(new BN(TEN_POW_NINE + slippage * TEN_POW_NINE))
|
|
23
|
-
.div(new BN(TEN_POW_NINE))
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return Number(amountLimit.toString())
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function CalculateAmountLimitBN(
|
|
30
|
-
expectAmount: BN,
|
|
31
|
-
byAmountIn: boolean,
|
|
32
|
-
slippage: number
|
|
33
|
-
): BN {
|
|
34
|
-
let amountLimit = ZERO
|
|
35
|
-
if (byAmountIn) {
|
|
36
|
-
amountLimit = expectAmount
|
|
37
|
-
.mul(new BN(TEN_POW_NINE - slippage * TEN_POW_NINE))
|
|
38
|
-
.div(new BN(TEN_POW_NINE))
|
|
39
|
-
} else {
|
|
40
|
-
amountLimit = expectAmount
|
|
41
|
-
.mul(new BN(TEN_POW_NINE + slippage * TEN_POW_NINE))
|
|
42
|
-
.div(new BN(TEN_POW_NINE))
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return amountLimit
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const MAX_SQER_PRICE_X64 = "79226673515401279992447579055"
|
|
49
|
-
const MIN_SQER_PRICE_X64 = "4295048016"
|
|
50
|
-
|
|
51
|
-
export function GetDefaultSqrtPriceLimit(a2b: boolean): BN {
|
|
52
|
-
if (a2b) {
|
|
53
|
-
return new BN(MIN_SQER_PRICE_X64)
|
|
54
|
-
} else {
|
|
55
|
-
return new BN(MAX_SQER_PRICE_X64)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function sqrtPriceX64ToPrice(
|
|
60
|
-
sqrtPriceStr: string,
|
|
61
|
-
decimalsA: number,
|
|
62
|
-
decimalsB: number
|
|
63
|
-
): Decimal {
|
|
64
|
-
const sqrtPriceX64 = new Decimal(sqrtPriceStr).mul(Decimal.pow(2, -64))
|
|
65
|
-
return sqrtPriceX64.pow(2).mul(Decimal.pow(10, decimalsA - decimalsB))
|
|
66
|
-
}
|
package/src/transaction/afsui.ts
DELETED
|
@@ -1,62 +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 Afsui implements Dex {
|
|
8
|
-
private stakedSuiVault: string
|
|
9
|
-
private safe: string
|
|
10
|
-
private referVault: string
|
|
11
|
-
private validator: string
|
|
12
|
-
|
|
13
|
-
constructor(env: Env) {
|
|
14
|
-
if (env !== Env.Mainnet) {
|
|
15
|
-
throw new Error("Afsui only supported on mainnet")
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
this.stakedSuiVault =
|
|
19
|
-
"0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d"
|
|
20
|
-
this.safe =
|
|
21
|
-
"0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610"
|
|
22
|
-
this.referVault =
|
|
23
|
-
"0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef"
|
|
24
|
-
this.validator =
|
|
25
|
-
"0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2"
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async swap(
|
|
29
|
-
client: AggregatorClient,
|
|
30
|
-
txb: Transaction,
|
|
31
|
-
path: Path,
|
|
32
|
-
inputCoin: TransactionObjectArgument,
|
|
33
|
-
packages?: Map<string, string>
|
|
34
|
-
): Promise<TransactionObjectArgument> {
|
|
35
|
-
const { direction } = path
|
|
36
|
-
|
|
37
|
-
if (!direction) {
|
|
38
|
-
throw new Error("Afsui not support b2a swap")
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const func = "swap_a2b"
|
|
42
|
-
|
|
43
|
-
const args = [
|
|
44
|
-
txb.object(this.stakedSuiVault),
|
|
45
|
-
txb.object(this.safe),
|
|
46
|
-
txb.object("0x5"),
|
|
47
|
-
txb.object(this.referVault),
|
|
48
|
-
txb.object(this.validator),
|
|
49
|
-
inputCoin,
|
|
50
|
-
]
|
|
51
|
-
|
|
52
|
-
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
|
|
53
|
-
|
|
54
|
-
const res = txb.moveCall({
|
|
55
|
-
target: `${publishedAt}::afsui::${func}`,
|
|
56
|
-
typeArguments: [],
|
|
57
|
-
arguments: args,
|
|
58
|
-
}) as TransactionObjectArgument
|
|
59
|
-
|
|
60
|
-
return res
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Transaction,
|
|
3
|
-
TransactionObjectArgument,
|
|
4
|
-
} from "@mysten/sui/transactions"
|
|
5
|
-
import { AggregatorClient, Dex, Env, getAggregatorV2PublishedAt, Path } from ".."
|
|
6
|
-
import BN from "bn.js"
|
|
7
|
-
|
|
8
|
-
export class Aftermath implements Dex {
|
|
9
|
-
private slippage: string
|
|
10
|
-
private poolRegistry: string
|
|
11
|
-
private protocolFeeVault: string
|
|
12
|
-
private treasury: string
|
|
13
|
-
private insuranceFund: string
|
|
14
|
-
private referrealVault: string
|
|
15
|
-
|
|
16
|
-
constructor(env: Env) {
|
|
17
|
-
if (env !== Env.Mainnet) {
|
|
18
|
-
throw new Error("Aftermath only supported on mainnet")
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
this.slippage = "900000000000000000"
|
|
22
|
-
this.poolRegistry =
|
|
23
|
-
"0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae"
|
|
24
|
-
this.protocolFeeVault =
|
|
25
|
-
"0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4"
|
|
26
|
-
this.treasury =
|
|
27
|
-
"0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce"
|
|
28
|
-
this.insuranceFund =
|
|
29
|
-
"0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b"
|
|
30
|
-
this.referrealVault =
|
|
31
|
-
"0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278"
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
amountLimit(exportAmountOut: string): string {
|
|
35
|
-
return new BN(exportAmountOut)
|
|
36
|
-
.mul(new BN(this.slippage))
|
|
37
|
-
.div(new BN("1000000000000000000"))
|
|
38
|
-
.toString()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async swap(
|
|
42
|
-
client: AggregatorClient,
|
|
43
|
-
txb: Transaction,
|
|
44
|
-
path: Path,
|
|
45
|
-
inputCoin: TransactionObjectArgument,
|
|
46
|
-
packages?: Map<string, string>
|
|
47
|
-
): Promise<TransactionObjectArgument> {
|
|
48
|
-
const { direction, from, target } = path
|
|
49
|
-
|
|
50
|
-
const [func, coinAType, coinBType] = direction
|
|
51
|
-
? ["swap_a2b", from, target]
|
|
52
|
-
: ["swap_b2a", target, from]
|
|
53
|
-
|
|
54
|
-
if (path.extendedDetails == null) {
|
|
55
|
-
throw new Error("Extended details not supported")
|
|
56
|
-
} else {
|
|
57
|
-
if (path.extendedDetails.aftermathLpSupplyType == null) {
|
|
58
|
-
throw new Error("LP supply type not supported")
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const args = [
|
|
63
|
-
txb.object(path.id),
|
|
64
|
-
txb.object(this.poolRegistry),
|
|
65
|
-
txb.object(this.protocolFeeVault),
|
|
66
|
-
txb.object(this.treasury),
|
|
67
|
-
txb.object(this.insuranceFund),
|
|
68
|
-
txb.object(this.referrealVault),
|
|
69
|
-
txb.pure.u64(this.amountLimit(path.amountOut)),
|
|
70
|
-
txb.pure.u64(this.slippage),
|
|
71
|
-
inputCoin,
|
|
72
|
-
]
|
|
73
|
-
|
|
74
|
-
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
|
|
75
|
-
|
|
76
|
-
const res = txb.moveCall({
|
|
77
|
-
target: `${publishedAt}::aftermath::${func}`,
|
|
78
|
-
typeArguments: [
|
|
79
|
-
coinAType,
|
|
80
|
-
coinBType,
|
|
81
|
-
path.extendedDetails.aftermathLpSupplyType,
|
|
82
|
-
],
|
|
83
|
-
arguments: args,
|
|
84
|
-
}) as TransactionObjectArgument
|
|
85
|
-
|
|
86
|
-
return res
|
|
87
|
-
}
|
|
88
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Transaction,
|
|
3
|
-
TransactionObjectArgument,
|
|
4
|
-
} from "@mysten/sui/transactions"
|
|
5
|
-
import { AggregatorClient, Dex, Env, getAggregatorV2ExtendPublishedAt, Path } from ".."
|
|
6
|
-
|
|
7
|
-
export class Alphafi implements Dex {
|
|
8
|
-
private sui_system_state: string
|
|
9
|
-
|
|
10
|
-
constructor(env: Env) {
|
|
11
|
-
if (env !== Env.Mainnet) {
|
|
12
|
-
throw new Error("Alphafi only supported on mainnet")
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
this.sui_system_state =
|
|
16
|
-
env === Env.Mainnet
|
|
17
|
-
? "0x0000000000000000000000000000000000000000000000000000000000000005"
|
|
18
|
-
: "0x0"
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async swap(
|
|
22
|
-
client: AggregatorClient,
|
|
23
|
-
txb: Transaction,
|
|
24
|
-
path: Path,
|
|
25
|
-
inputCoin: TransactionObjectArgument,
|
|
26
|
-
packages?: Map<string, string>
|
|
27
|
-
): Promise<TransactionObjectArgument> {
|
|
28
|
-
const { direction, from, target } = path
|
|
29
|
-
|
|
30
|
-
const [func, stCoinType] = direction
|
|
31
|
-
? ["swap_a2b", target]
|
|
32
|
-
: ["swap_b2a", from]
|
|
33
|
-
|
|
34
|
-
const args = [
|
|
35
|
-
txb.object(path.id),
|
|
36
|
-
txb.object(this.sui_system_state),
|
|
37
|
-
inputCoin,
|
|
38
|
-
]
|
|
39
|
-
|
|
40
|
-
const publishedAt = getAggregatorV2ExtendPublishedAt(client.publishedAtV2Extend(), packages)
|
|
41
|
-
|
|
42
|
-
const res = txb.moveCall({
|
|
43
|
-
target: `${publishedAt}::alphafi::${func}`,
|
|
44
|
-
typeArguments: [stCoinType],
|
|
45
|
-
arguments: args,
|
|
46
|
-
}) as TransactionObjectArgument
|
|
47
|
-
|
|
48
|
-
return res
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,46 +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
|
-
|
|
8
|
-
export class Bluefin implements Dex {
|
|
9
|
-
private globalConfig: string
|
|
10
|
-
|
|
11
|
-
constructor(env: Env) {
|
|
12
|
-
if (env !== Env.Mainnet) {
|
|
13
|
-
throw new Error("Bluefin only supported on mainnet")
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
this.globalConfig =
|
|
17
|
-
"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352"
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async swap(
|
|
21
|
-
client: AggregatorClient,
|
|
22
|
-
txb: Transaction,
|
|
23
|
-
path: Path,
|
|
24
|
-
inputCoin: TransactionObjectArgument,
|
|
25
|
-
packages?: Map<string, string>
|
|
26
|
-
): Promise<TransactionObjectArgument> {
|
|
27
|
-
const { direction, from, target } = path
|
|
28
|
-
const [func, coinAType, coinBType] = direction
|
|
29
|
-
? ["swap_a2b", from, target]
|
|
30
|
-
: ["swap_b2a", target, from]
|
|
31
|
-
const args = [
|
|
32
|
-
txb.object(this.globalConfig),
|
|
33
|
-
txb.object(path.id),
|
|
34
|
-
inputCoin,
|
|
35
|
-
txb.object(CLOCK_ADDRESS),
|
|
36
|
-
]
|
|
37
|
-
const publishedAt = getAggregatorV2ExtendPublishedAt(client.publishedAtV2Extend(), packages)
|
|
38
|
-
|
|
39
|
-
const res = txb.moveCall({
|
|
40
|
-
target: `${publishedAt}::bluefin::${func}`,
|
|
41
|
-
typeArguments: [coinAType, coinBType],
|
|
42
|
-
arguments: args,
|
|
43
|
-
}) as TransactionArgument
|
|
44
|
-
return res
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -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 Bluemove implements Dex {
|
|
8
|
-
private dexInfo: string
|
|
9
|
-
|
|
10
|
-
constructor(env: Env) {
|
|
11
|
-
if (env !== Env.Mainnet) {
|
|
12
|
-
throw new Error("Bluemove only supported on mainnet")
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
this.dexInfo =
|
|
16
|
-
"0x3f2d9f724f4a1ce5e71676448dc452be9a6243dac9c5b975a588c8c867066e92"
|
|
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.dexInfo), inputCoin]
|
|
33
|
-
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
|
|
34
|
-
const res = txb.moveCall({
|
|
35
|
-
target: `${publishedAt}::bluemove::${func}`,
|
|
36
|
-
typeArguments: [coinAType, coinBType],
|
|
37
|
-
arguments: args,
|
|
38
|
-
}) as TransactionObjectArgument
|
|
39
|
-
|
|
40
|
-
return res
|
|
41
|
-
}
|
|
42
|
-
}
|
package/src/transaction/cetus.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Transaction,
|
|
3
|
-
TransactionArgument,
|
|
4
|
-
TransactionObjectArgument,
|
|
5
|
-
} from "@mysten/sui/transactions"
|
|
6
|
-
import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, getAggregatorV2PublishedAt, Path } from ".."
|
|
7
|
-
|
|
8
|
-
export type CetusFlashSwapResult = {
|
|
9
|
-
targetCoin: TransactionObjectArgument
|
|
10
|
-
flashReceipt: TransactionObjectArgument
|
|
11
|
-
payAmount: TransactionArgument
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class Cetus implements Dex {
|
|
15
|
-
private globalConfig: string
|
|
16
|
-
private partner: string
|
|
17
|
-
|
|
18
|
-
constructor(env: Env, partner?: string) {
|
|
19
|
-
this.globalConfig =
|
|
20
|
-
env === Env.Mainnet
|
|
21
|
-
? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f"
|
|
22
|
-
: "0x9774e359588ead122af1c7e7f64e14ade261cfeecdb5d0eb4a5b3b4c8ab8bd3e"
|
|
23
|
-
|
|
24
|
-
this.partner =
|
|
25
|
-
partner ??
|
|
26
|
-
(env === Env.Mainnet
|
|
27
|
-
? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b"
|
|
28
|
-
: "0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5")
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
flash_swap(
|
|
32
|
-
client: AggregatorClient,
|
|
33
|
-
txb: Transaction,
|
|
34
|
-
path: Path,
|
|
35
|
-
by_amount_in: boolean,
|
|
36
|
-
packages?: Map<string, string>
|
|
37
|
-
): CetusFlashSwapResult {
|
|
38
|
-
const { direction, from, target } = path
|
|
39
|
-
const [func, coinAType, coinBType] = direction
|
|
40
|
-
? ["flash_swap_a2b", from, target]
|
|
41
|
-
: ["flash_swap_b2a", target, from]
|
|
42
|
-
let amount = by_amount_in ? path.amountIn : path.amountOut
|
|
43
|
-
const args = [
|
|
44
|
-
txb.object(this.globalConfig),
|
|
45
|
-
txb.object(path.id),
|
|
46
|
-
txb.object(this.partner),
|
|
47
|
-
txb.pure.u64(amount),
|
|
48
|
-
txb.pure.bool(by_amount_in),
|
|
49
|
-
txb.object(CLOCK_ADDRESS),
|
|
50
|
-
]
|
|
51
|
-
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
|
|
52
|
-
const res: TransactionObjectArgument[] = txb.moveCall({
|
|
53
|
-
target: `${publishedAt}::cetus::${func}`,
|
|
54
|
-
typeArguments: [coinAType, coinBType],
|
|
55
|
-
arguments: args,
|
|
56
|
-
})
|
|
57
|
-
return {
|
|
58
|
-
targetCoin: res[0],
|
|
59
|
-
flashReceipt: res[1],
|
|
60
|
-
payAmount: res[2],
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
repay_flash_swap(
|
|
65
|
-
client: AggregatorClient,
|
|
66
|
-
txb: Transaction,
|
|
67
|
-
path: Path,
|
|
68
|
-
inputCoin: TransactionObjectArgument,
|
|
69
|
-
receipt: TransactionArgument,
|
|
70
|
-
packages?: Map<string, string>
|
|
71
|
-
): TransactionObjectArgument {
|
|
72
|
-
const { direction, from, target } = path
|
|
73
|
-
const [func, coinAType, coinBType] = direction
|
|
74
|
-
? ["repay_flash_swap_a2b", from, target]
|
|
75
|
-
: ["repay_flash_swap_b2a", target, from]
|
|
76
|
-
const args = [
|
|
77
|
-
txb.object(this.globalConfig),
|
|
78
|
-
txb.object(path.id),
|
|
79
|
-
txb.object(this.partner),
|
|
80
|
-
inputCoin,
|
|
81
|
-
receipt,
|
|
82
|
-
]
|
|
83
|
-
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
|
|
84
|
-
const res = txb.moveCall({
|
|
85
|
-
target: `${publishedAt}::cetus::${func}`,
|
|
86
|
-
typeArguments: [coinAType, coinBType],
|
|
87
|
-
arguments: args,
|
|
88
|
-
})
|
|
89
|
-
return res[0] as TransactionObjectArgument
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async swap(
|
|
93
|
-
client: AggregatorClient,
|
|
94
|
-
txb: Transaction,
|
|
95
|
-
path: Path,
|
|
96
|
-
inputCoin: TransactionObjectArgument,
|
|
97
|
-
packages?: Map<string, string>
|
|
98
|
-
): Promise<TransactionObjectArgument> {
|
|
99
|
-
const { direction, from, target } = path
|
|
100
|
-
const [func, coinAType, coinBType] = direction
|
|
101
|
-
? ["swap_a2b", from, target]
|
|
102
|
-
: ["swap_b2a", target, from]
|
|
103
|
-
const args = [
|
|
104
|
-
txb.object(this.globalConfig),
|
|
105
|
-
txb.object(path.id),
|
|
106
|
-
txb.object(this.partner),
|
|
107
|
-
inputCoin,
|
|
108
|
-
txb.object(CLOCK_ADDRESS),
|
|
109
|
-
]
|
|
110
|
-
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
|
|
111
|
-
const res = txb.moveCall({
|
|
112
|
-
target: `${publishedAt}::cetus::${func}`,
|
|
113
|
-
typeArguments: [coinAType, coinBType],
|
|
114
|
-
arguments: args,
|
|
115
|
-
}) as TransactionArgument
|
|
116
|
-
return res
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Transaction,
|
|
3
|
-
TransactionObjectArgument,
|
|
4
|
-
} from "@mysten/sui/transactions"
|
|
5
|
-
import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, getAggregatorV2PublishedAt, Path } from ".."
|
|
6
|
-
import { SuiClient } from "@mysten/sui/client"
|
|
7
|
-
|
|
8
|
-
const DEEPBOOK_PACKAGE_ID =
|
|
9
|
-
"0x000000000000000000000000000000000000000000000000000000000000dee9"
|
|
10
|
-
|
|
11
|
-
type GetOrCreateAccountCapResult = {
|
|
12
|
-
accountCap: TransactionObjectArgument
|
|
13
|
-
isCreate: boolean
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class DeepbookV2 implements Dex {
|
|
17
|
-
constructor(env: Env) {
|
|
18
|
-
if (env !== Env.Mainnet) {
|
|
19
|
-
throw new Error("Aftermath only supported on mainnet")
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async getAccountCap(
|
|
24
|
-
client: SuiClient,
|
|
25
|
-
owner: string
|
|
26
|
-
): Promise<string | null> {
|
|
27
|
-
let limit = 50
|
|
28
|
-
let cursor = null
|
|
29
|
-
|
|
30
|
-
while (true) {
|
|
31
|
-
const ownedObjects: any = client.getOwnedObjects({
|
|
32
|
-
owner,
|
|
33
|
-
cursor,
|
|
34
|
-
limit,
|
|
35
|
-
filter: {
|
|
36
|
-
MoveModule: {
|
|
37
|
-
package: DEEPBOOK_PACKAGE_ID,
|
|
38
|
-
module: "custodian_v2",
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
if (ownedObjects != null && ownedObjects.data != null) {
|
|
44
|
-
if (ownedObjects.data.length !== 0) {
|
|
45
|
-
return ownedObjects.data[0].data.objectId
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (ownedObjects.data.length < 50) {
|
|
49
|
-
break
|
|
50
|
-
}
|
|
51
|
-
} else {
|
|
52
|
-
break
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return null
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async getOrCreateAccountCap(
|
|
60
|
-
txb: Transaction,
|
|
61
|
-
client: SuiClient,
|
|
62
|
-
owner: string
|
|
63
|
-
): Promise<GetOrCreateAccountCapResult> {
|
|
64
|
-
let accountCapStr = await this.getAccountCap(client, owner)
|
|
65
|
-
if (accountCapStr !== null) {
|
|
66
|
-
return {
|
|
67
|
-
accountCap: txb.object(accountCapStr),
|
|
68
|
-
isCreate: false,
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const accountCap = txb.moveCall({
|
|
73
|
-
target: `${DEEPBOOK_PACKAGE_ID}::clob_v2::create_account`,
|
|
74
|
-
typeArguments: [],
|
|
75
|
-
arguments: [],
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
accountCap,
|
|
80
|
-
isCreate: true,
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async swap(
|
|
85
|
-
client: AggregatorClient,
|
|
86
|
-
txb: Transaction,
|
|
87
|
-
path: Path,
|
|
88
|
-
inputCoin: TransactionObjectArgument,
|
|
89
|
-
packages?: Map<string, string>
|
|
90
|
-
): Promise<TransactionObjectArgument> {
|
|
91
|
-
const { direction, from, target } = path
|
|
92
|
-
|
|
93
|
-
const [func, coinAType, coinBType] = direction
|
|
94
|
-
? ["swap_a2b", from, target]
|
|
95
|
-
: ["swap_b2a", target, from]
|
|
96
|
-
|
|
97
|
-
const accountCapRes = await this.getOrCreateAccountCap(
|
|
98
|
-
txb,
|
|
99
|
-
client.client,
|
|
100
|
-
client.signer
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
const args = [
|
|
104
|
-
txb.object(path.id),
|
|
105
|
-
inputCoin,
|
|
106
|
-
accountCapRes.accountCap,
|
|
107
|
-
txb.object(CLOCK_ADDRESS),
|
|
108
|
-
]
|
|
109
|
-
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
|
|
110
|
-
const res = txb.moveCall({
|
|
111
|
-
target: `${publishedAt}::deepbook::${func}`,
|
|
112
|
-
typeArguments: [coinAType, coinBType],
|
|
113
|
-
arguments: args,
|
|
114
|
-
}) as TransactionObjectArgument
|
|
115
|
-
|
|
116
|
-
if (accountCapRes.isCreate) {
|
|
117
|
-
txb.transferObjects([accountCapRes.accountCap], client.signer)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return res
|
|
121
|
-
}
|
|
122
|
-
}
|