@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/types/sui.ts
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import type { TransactionArgument } from '@mysten/sui/transactions'
|
|
2
|
-
import Decimal from 'decimal.js'
|
|
3
|
-
import { TypesErrorCode } from '../errors'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Represents a SUI address, which is a string.
|
|
7
|
-
*/
|
|
8
|
-
export type SuiAddress = string
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Represents a SUI object identifier, which is a string.
|
|
12
|
-
*/
|
|
13
|
-
export type SuiObjectIdType = string
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Represents a BigNumber, which can be a Decimal.Value, number, or string.
|
|
17
|
-
*/
|
|
18
|
-
export type BigNumber = Decimal.Value | number | string
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Represents a SUI resource, which can be of any type.
|
|
23
|
-
*/
|
|
24
|
-
export type SuiResource = any
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Represents a Non-Fungible Token (NFT) with associated metadata.
|
|
28
|
-
*/
|
|
29
|
-
export type NFT = {
|
|
30
|
-
/**
|
|
31
|
-
* The address or identifier of the creator of the NFT.
|
|
32
|
-
*/
|
|
33
|
-
creator: string
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* A description providing additional information about the NFT.
|
|
37
|
-
*/
|
|
38
|
-
description: string
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The URL to the image representing the NFT visually.
|
|
42
|
-
*/
|
|
43
|
-
image_url: string
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* A link associated with the NFT, providing more details or interactions.
|
|
47
|
-
*/
|
|
48
|
-
link: string
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* The name or title of the NFT.
|
|
52
|
-
*/
|
|
53
|
-
name: string
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* The URL to the project or collection associated with the NFT.
|
|
57
|
-
*/
|
|
58
|
-
project_url: string
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Represents a SUI struct tag.
|
|
63
|
-
*/
|
|
64
|
-
export type SuiStructTag = {
|
|
65
|
-
/**
|
|
66
|
-
* The full address of the struct.
|
|
67
|
-
*/
|
|
68
|
-
full_address: string
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* The source address of the struct.
|
|
72
|
-
*/
|
|
73
|
-
source_address: string
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* The address of the struct.
|
|
77
|
-
*/
|
|
78
|
-
address: SuiAddress
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* The module to which the struct belongs.
|
|
82
|
-
*/
|
|
83
|
-
module: string
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* The name of the struct.
|
|
87
|
-
*/
|
|
88
|
-
name: string
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* An array of type arguments (SUI addresses) for the struct.
|
|
92
|
-
*/
|
|
93
|
-
type_arguments: SuiAddress[]
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Represents basic SUI data types.
|
|
98
|
-
*/
|
|
99
|
-
export type SuiBasicTypes = 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256'
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Represents a SUI transaction argument, which can be of various types.
|
|
103
|
-
*/
|
|
104
|
-
export type SuiTxArg = TransactionArgument | string | number | bigint | boolean
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Represents input types for SUI data.
|
|
108
|
-
*/
|
|
109
|
-
export type SuiInputTypes = 'object' | SuiBasicTypes
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Gets the default SUI input type based on the provided value.
|
|
113
|
-
* @param value - The value to determine the default input type for.
|
|
114
|
-
* @returns The default SUI input type.
|
|
115
|
-
* @throws Error if the type of the value is unknown.
|
|
116
|
-
*/
|
|
117
|
-
export const getDefaultSuiInputType = (value: any): SuiInputTypes => {
|
|
118
|
-
if (typeof value === 'string' && value.startsWith('0x')) {
|
|
119
|
-
return 'object'
|
|
120
|
-
}
|
|
121
|
-
if (typeof value === 'number' || typeof value === 'bigint') {
|
|
122
|
-
return 'u64'
|
|
123
|
-
}
|
|
124
|
-
if (typeof value === 'boolean') {
|
|
125
|
-
return 'bool'
|
|
126
|
-
}
|
|
127
|
-
throw new AggregateError(`Unknown type for value: ${value}`, TypesErrorCode.InvalidType)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Represents a coin asset with address, object ID, and balance information.
|
|
132
|
-
*/
|
|
133
|
-
export type CoinAsset = {
|
|
134
|
-
/**
|
|
135
|
-
* The address type of the coin asset.
|
|
136
|
-
*/
|
|
137
|
-
coinAddress: SuiAddress
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* The object identifier of the coin asset.
|
|
141
|
-
*/
|
|
142
|
-
coinObjectId: SuiObjectIdType
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* The balance amount of the coin asset.
|
|
146
|
-
*/
|
|
147
|
-
balance: bigint
|
|
148
|
-
}
|
package/src/utils/api.ts
DELETED
package/src/utils/coin.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { CoinAsset } from "../types/sui"
|
|
2
|
-
import { CoinUtils } from "../types/CoinAssist"
|
|
3
|
-
import { TransactionErrorCode } from "../errors"
|
|
4
|
-
import {
|
|
5
|
-
Transaction,
|
|
6
|
-
TransactionObjectArgument,
|
|
7
|
-
} from "@mysten/sui/transactions"
|
|
8
|
-
|
|
9
|
-
export function completionCoin(s: string): string {
|
|
10
|
-
const index = s.indexOf("::")
|
|
11
|
-
if (index === -1) {
|
|
12
|
-
return s
|
|
13
|
-
}
|
|
14
|
-
const prefix = s.substring(0, index)
|
|
15
|
-
const rest = s.substring(index)
|
|
16
|
-
if (!prefix.startsWith("0x")) {
|
|
17
|
-
return s
|
|
18
|
-
}
|
|
19
|
-
const hexStr = prefix.substring(2)
|
|
20
|
-
if (hexStr.length > 64) {
|
|
21
|
-
return s
|
|
22
|
-
}
|
|
23
|
-
const paddedHexStr = hexStr.padStart(64, "0")
|
|
24
|
-
return `0x${paddedHexStr}${rest}`
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function compareCoins(coinA: string, coinB: string): boolean {
|
|
28
|
-
coinA = completionCoin(coinA)
|
|
29
|
-
coinB = completionCoin(coinB)
|
|
30
|
-
const minLength = Math.min(coinA.length, coinB.length)
|
|
31
|
-
|
|
32
|
-
for (let i = 0; i < minLength; i++) {
|
|
33
|
-
if (coinA[i] > coinB[i]) {
|
|
34
|
-
return true
|
|
35
|
-
} else if (coinA[i] < coinB[i]) {
|
|
36
|
-
return false
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// If both strings are the same length and all characters are equal
|
|
41
|
-
return true // or coinB, they are equal
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function mintZeroCoin(
|
|
45
|
-
txb: Transaction,
|
|
46
|
-
coinType: string
|
|
47
|
-
): TransactionObjectArgument {
|
|
48
|
-
return txb.moveCall({
|
|
49
|
-
target: "0x2::coin::zero",
|
|
50
|
-
typeArguments: [coinType],
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export type BuildCoinResult = {
|
|
55
|
-
targetCoin: TransactionObjectArgument
|
|
56
|
-
isMintZeroCoin: boolean
|
|
57
|
-
targetCoinAmount: number
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function buildInputCoin(
|
|
61
|
-
txb: Transaction,
|
|
62
|
-
allCoins: CoinAsset[],
|
|
63
|
-
amount: bigint,
|
|
64
|
-
coinType: string,
|
|
65
|
-
): BuildCoinResult {
|
|
66
|
-
const usedCoinAsests = CoinUtils.getCoinAssets(coinType, allCoins)
|
|
67
|
-
if (amount === BigInt(0)) {
|
|
68
|
-
if (CoinUtils.isSuiCoin(coinType) || usedCoinAsests.length === 0 && !CoinUtils.isSuiCoin(coinType)) {
|
|
69
|
-
const zeroCoin = mintZeroCoin(txb, coinType)
|
|
70
|
-
return {
|
|
71
|
-
targetCoin: zeroCoin,
|
|
72
|
-
isMintZeroCoin: true,
|
|
73
|
-
targetCoinAmount: 0,
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
return {
|
|
77
|
-
targetCoin: txb.object(usedCoinAsests[0].coinObjectId),
|
|
78
|
-
isMintZeroCoin: false,
|
|
79
|
-
targetCoinAmount: Number(usedCoinAsests[0].balance.toString()),
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
let totalCoinBalance = CoinUtils.calculateTotalBalance(usedCoinAsests)
|
|
85
|
-
if (totalCoinBalance < amount) {
|
|
86
|
-
throw new AggregateError(
|
|
87
|
-
"Insufficient balance when build merge coin, coinType: " + coinType,
|
|
88
|
-
TransactionErrorCode.InsufficientBalance + coinType
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (CoinUtils.isSuiCoin(coinType)) {
|
|
93
|
-
const resultCoin = txb.splitCoins(txb.gas, [
|
|
94
|
-
txb.pure.u64(amount.toString()),
|
|
95
|
-
])
|
|
96
|
-
return {
|
|
97
|
-
targetCoin: resultCoin,
|
|
98
|
-
isMintZeroCoin: true,
|
|
99
|
-
targetCoinAmount: Number(amount.toString()),
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// sort used coin by amount, asc
|
|
104
|
-
let sortCoinAssets = CoinUtils.sortByBalance(usedCoinAsests)
|
|
105
|
-
|
|
106
|
-
// find first three coin if greater than amount
|
|
107
|
-
let totalThreeCoinBalance = sortCoinAssets
|
|
108
|
-
.slice(0, 3)
|
|
109
|
-
.reduce((acc, coin) => acc + coin.balance, BigInt(0))
|
|
110
|
-
if (totalThreeCoinBalance < BigInt(amount)) {
|
|
111
|
-
sortCoinAssets = CoinUtils.sortByBalanceDes(usedCoinAsests)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
let selectedCoinResult = CoinUtils.selectCoinObjectIdGreaterThanOrEqual(
|
|
115
|
-
sortCoinAssets,
|
|
116
|
-
amount
|
|
117
|
-
)
|
|
118
|
-
const [masterCoin, ...mergedCoin] = selectedCoinResult.objectArray
|
|
119
|
-
|
|
120
|
-
if (mergedCoin.length > 0) {
|
|
121
|
-
txb.mergeCoins(
|
|
122
|
-
masterCoin,
|
|
123
|
-
mergedCoin.map((coin) => txb.object(coin))
|
|
124
|
-
)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const targetCoin = txb.splitCoins(txb.object(masterCoin), [
|
|
128
|
-
txb.pure.u64(amount.toString()),
|
|
129
|
-
])
|
|
130
|
-
|
|
131
|
-
return {
|
|
132
|
-
targetCoin,
|
|
133
|
-
isMintZeroCoin: false,
|
|
134
|
-
targetCoinAmount: Number(amount.toString()),
|
|
135
|
-
}
|
|
136
|
-
}
|
package/src/utils/contracts.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { normalizeSuiObjectId } from '@mysten/sui/utils'
|
|
2
|
-
import type { SuiAddress, SuiStructTag } from '../types/sui'
|
|
3
|
-
import { CoinUtils, GAS_TYPE_ARG, GAS_TYPE_ARG_LONG } from '../types/CoinAssist'
|
|
4
|
-
|
|
5
|
-
const EQUAL = 0
|
|
6
|
-
const LESS_THAN = 1
|
|
7
|
-
const GREATER_THAN = 2
|
|
8
|
-
|
|
9
|
-
function cmp(a: number, b: number) {
|
|
10
|
-
if (a === b) {
|
|
11
|
-
return EQUAL
|
|
12
|
-
}
|
|
13
|
-
if (a < b) {
|
|
14
|
-
return LESS_THAN
|
|
15
|
-
}
|
|
16
|
-
return GREATER_THAN
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function compare(symbolX: string, symbolY: string) {
|
|
20
|
-
let i = 0
|
|
21
|
-
|
|
22
|
-
const len = symbolX.length <= symbolY.length ? symbolX.length : symbolY.length
|
|
23
|
-
|
|
24
|
-
const lenCmp = cmp(symbolX.length, symbolY.length)
|
|
25
|
-
while (i < len) {
|
|
26
|
-
const elemCmp = cmp(symbolX.charCodeAt(i), symbolY.charCodeAt(i))
|
|
27
|
-
i += 1
|
|
28
|
-
if (elemCmp !== 0) {
|
|
29
|
-
return elemCmp
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return lenCmp
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function isSortedSymbols(symbolX: string, symbolY: string) {
|
|
37
|
-
return compare(symbolX, symbolY) === LESS_THAN
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function composeType(address: string, generics: SuiAddress[]): SuiAddress
|
|
41
|
-
export function composeType(address: string, struct: string, generics?: SuiAddress[]): SuiAddress
|
|
42
|
-
export function composeType(address: string, module: string, struct: string, generics?: SuiAddress[]): SuiAddress
|
|
43
|
-
export function composeType(address: string, ...args: unknown[]): SuiAddress {
|
|
44
|
-
const generics: string[] = Array.isArray(args[args.length - 1]) ? (args.pop() as string[]) : []
|
|
45
|
-
const chains = [address, ...args].filter(Boolean)
|
|
46
|
-
|
|
47
|
-
let result: string = chains.join('::')
|
|
48
|
-
|
|
49
|
-
if (generics && generics.length) {
|
|
50
|
-
result += `<${generics.join(', ')}>`
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return result
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function extractAddressFromType(type: string) {
|
|
57
|
-
return type.split('::')[0]
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function extractStructTagFromType(type: string): SuiStructTag {
|
|
61
|
-
try {
|
|
62
|
-
let _type = type.replace(/\s/g, '')
|
|
63
|
-
|
|
64
|
-
const genericsString = _type.match(/(<.+>)$/)
|
|
65
|
-
const generics = genericsString?.[0]?.match(/(\w+::\w+::\w+)(?:<.*?>(?!>))?/g)
|
|
66
|
-
if (generics) {
|
|
67
|
-
_type = _type.slice(0, _type.indexOf('<'))
|
|
68
|
-
const tag = extractStructTagFromType(_type)
|
|
69
|
-
const structTag: SuiStructTag = {
|
|
70
|
-
...tag,
|
|
71
|
-
type_arguments: generics.map((item) => extractStructTagFromType(item).source_address),
|
|
72
|
-
}
|
|
73
|
-
structTag.type_arguments = structTag.type_arguments.map((item) => {
|
|
74
|
-
return CoinUtils.isSuiCoin(item) ? item : extractStructTagFromType(item).source_address
|
|
75
|
-
})
|
|
76
|
-
structTag.source_address = composeType(structTag.full_address, structTag.type_arguments)
|
|
77
|
-
return structTag
|
|
78
|
-
}
|
|
79
|
-
const parts = _type.split('::')
|
|
80
|
-
|
|
81
|
-
const isSuiCoin = _type === GAS_TYPE_ARG || _type === GAS_TYPE_ARG_LONG
|
|
82
|
-
|
|
83
|
-
const structTag: SuiStructTag = {
|
|
84
|
-
full_address: _type,
|
|
85
|
-
address: isSuiCoin ? '0x2' : normalizeSuiObjectId(parts[0]),
|
|
86
|
-
module: parts[1],
|
|
87
|
-
name: parts[2],
|
|
88
|
-
type_arguments: [],
|
|
89
|
-
source_address: '',
|
|
90
|
-
}
|
|
91
|
-
structTag.full_address = `${structTag.address}::${structTag.module}::${structTag.name}`
|
|
92
|
-
structTag.source_address = composeType(structTag.full_address, structTag.type_arguments)
|
|
93
|
-
return structTag
|
|
94
|
-
} catch (error) {
|
|
95
|
-
return {
|
|
96
|
-
full_address: type,
|
|
97
|
-
address: '',
|
|
98
|
-
module: '',
|
|
99
|
-
name: '',
|
|
100
|
-
type_arguments: [],
|
|
101
|
-
source_address: type,
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function normalizeCoinType(coinType: string): string {
|
|
107
|
-
return extractStructTagFromType(coinType).source_address
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function fixSuiObjectId(value: string): string {
|
|
111
|
-
if (value.toLowerCase().startsWith('0x')) {
|
|
112
|
-
return normalizeSuiObjectId(value)
|
|
113
|
-
}
|
|
114
|
-
return value
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Recursively traverses the given data object and patches any string values that represent Sui object IDs.
|
|
119
|
-
*
|
|
120
|
-
* @param {any} data - The data object to be patched.
|
|
121
|
-
*/
|
|
122
|
-
export function patchFixSuiObjectId(data: any) {
|
|
123
|
-
for (const key in data) {
|
|
124
|
-
const type = typeof data[key]
|
|
125
|
-
if (type === 'object') {
|
|
126
|
-
patchFixSuiObjectId(data[key])
|
|
127
|
-
} else if (type === 'string') {
|
|
128
|
-
const value = data[key]
|
|
129
|
-
data[key] = fixSuiObjectId(value)
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function createTarget(packageName: string, moduleName: string, functionName: string): `${string}::${string}::${string}` {
|
|
135
|
-
return `${packageName}::${moduleName}::${functionName}`
|
|
136
|
-
}
|
package/src/utils/index.ts
DELETED
package/src/utils/msafe.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import BN from 'bn.js'
|
|
3
|
-
import Decimal from "decimal.js"
|
|
4
|
-
|
|
5
|
-
export const dealWithFastRouterSwapParamsForMsafe = (data: any) => {
|
|
6
|
-
const result = {
|
|
7
|
-
...data,
|
|
8
|
-
amountIn: data?.amountIn?.toString(),
|
|
9
|
-
amountOut: data?.amountIn?.toString(),
|
|
10
|
-
routes: data?.routes?.map((item:any) => {
|
|
11
|
-
return {
|
|
12
|
-
...item,
|
|
13
|
-
amountIn: item?.amountIn?.toString(),
|
|
14
|
-
amountOut: item?.amountOut?.toString(),
|
|
15
|
-
initialPrice: item?.initialPrice?.toString()
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return result
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export const restituteMsafeFastRouterSwapParams = (data: any) => {
|
|
25
|
-
const result = {
|
|
26
|
-
...data,
|
|
27
|
-
amountIn: new BN(data?.amountIn),
|
|
28
|
-
amountOut: new BN(data?.amountIn),
|
|
29
|
-
routes: data?.routes?.map((item:any) => {
|
|
30
|
-
return {
|
|
31
|
-
...item,
|
|
32
|
-
amountIn: new BN(item?.amountIn),
|
|
33
|
-
amountOut: new BN(item?.amountOut),
|
|
34
|
-
initialPrice: new Decimal(item?.initialPrice?.toString())
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return result
|
|
40
|
-
}
|
package/src/utils/transaction.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Transaction } from "@mysten/sui/transactions"
|
|
2
|
-
|
|
3
|
-
export async function printTransaction(tx: Transaction, isPrint = true) {
|
|
4
|
-
console.log(`inputs`, tx.getData().inputs)
|
|
5
|
-
let i = 0
|
|
6
|
-
|
|
7
|
-
tx.getData().commands.forEach((item, index) => {
|
|
8
|
-
if (isPrint) {
|
|
9
|
-
console.log(`transaction ${index}: `, JSON.stringify(item, null, 2))
|
|
10
|
-
i++
|
|
11
|
-
}
|
|
12
|
-
})
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function checkInvalidSuiAddress(address: string): boolean {
|
|
16
|
-
if (!address.startsWith("0x") || address.length !== 66) {
|
|
17
|
-
return false
|
|
18
|
-
}
|
|
19
|
-
return true
|
|
20
|
-
}
|
package/tests/math.test.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import BN from "bn.js"
|
|
2
|
-
import { CalculateAmountLimit, sqrtPriceX64ToPrice } from "~/math"
|
|
3
|
-
|
|
4
|
-
describe("test math functions", () => {
|
|
5
|
-
test("test sqrt price x64 to price", () => {
|
|
6
|
-
const sqrtPriceStr = "1312674575678912631"
|
|
7
|
-
const decimalsA = 9
|
|
8
|
-
const decimalsB = 6
|
|
9
|
-
|
|
10
|
-
const price = sqrtPriceX64ToPrice(sqrtPriceStr, decimalsA, decimalsB)
|
|
11
|
-
console.log("price", price.toFixed(9))
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
test("calculate amount limit", () => {
|
|
15
|
-
const amount = new BN(80017351)
|
|
16
|
-
const byAmountIn = true
|
|
17
|
-
|
|
18
|
-
const amountLimit = CalculateAmountLimit(amount, byAmountIn, 0.01)
|
|
19
|
-
console.log("amount limit", amountLimit.toString())
|
|
20
|
-
})
|
|
21
|
-
})
|