@lifi/sdk-provider-sui 4.0.1-alpha.0 → 4.0.1
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/CHANGELOG.md +25 -0
- package/README.md +88 -5
- package/dist/esm/SuiProvider.d.ts +7 -2
- package/dist/esm/SuiProvider.d.ts.map +1 -0
- package/dist/esm/SuiProvider.js +32 -32
- package/dist/esm/SuiProvider.js.map +1 -1
- package/dist/esm/actions/getSuiBalance.d.ts +7 -2
- package/dist/esm/actions/getSuiBalance.d.ts.map +1 -0
- package/dist/esm/actions/getSuiBalance.js +40 -47
- package/dist/esm/actions/getSuiBalance.js.map +1 -1
- package/dist/esm/actions/getSuiNSAddress.d.ts +7 -1
- package/dist/esm/actions/getSuiNSAddress.d.ts.map +1 -0
- package/dist/esm/actions/getSuiNSAddress.js +24 -27
- package/dist/esm/actions/getSuiNSAddress.js.map +1 -1
- package/dist/esm/actions/resolveSuiAddress.d.ts +5 -1
- package/dist/esm/actions/resolveSuiAddress.d.ts.map +1 -0
- package/dist/esm/actions/resolveSuiAddress.js +7 -3
- package/dist/esm/actions/resolveSuiAddress.js.map +1 -1
- package/dist/esm/client/suiClient.d.ts +13 -8
- package/dist/esm/client/suiClient.d.ts.map +1 -0
- package/dist/esm/client/suiClient.js +32 -33
- package/dist/esm/client/suiClient.js.map +1 -1
- package/dist/esm/core/SuiStepExecutor.d.ts +16 -0
- package/dist/esm/core/SuiStepExecutor.d.ts.map +1 -0
- package/dist/esm/core/SuiStepExecutor.js +44 -0
- package/dist/esm/core/SuiStepExecutor.js.map +1 -0
- package/dist/esm/core/tasks/SuiSignAndExecuteTask.d.ts +10 -0
- package/dist/esm/core/tasks/SuiSignAndExecuteTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/SuiSignAndExecuteTask.js +26 -0
- package/dist/esm/core/tasks/SuiSignAndExecuteTask.js.map +1 -0
- package/dist/esm/core/tasks/SuiWaitForTransactionTask.d.ts +10 -0
- package/dist/esm/core/tasks/SuiWaitForTransactionTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/SuiWaitForTransactionTask.js +26 -0
- package/dist/esm/core/tasks/SuiWaitForTransactionTask.js.map +1 -0
- package/dist/esm/errors/parseSuiErrors.d.ts +7 -2
- package/dist/esm/errors/parseSuiErrors.d.ts.map +1 -0
- package/dist/esm/errors/parseSuiErrors.js +17 -27
- package/dist/esm/errors/parseSuiErrors.js.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +3 -4
- package/dist/esm/package.json +1 -1
- package/dist/esm/types.d.ts +27 -11
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +9 -5
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/version.d.ts +6 -2
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +6 -2
- package/dist/esm/version.js.map +1 -1
- package/package.json +9 -9
- package/src/SuiProvider.ts +22 -6
- package/src/actions/getSuiBalance.ts +10 -10
- package/src/actions/getSuiNSAddress.ts +6 -3
- package/src/client/suiClient.ts +6 -6
- package/src/core/SuiStepExecutor.ts +93 -0
- package/src/core/tasks/SuiSignAndExecuteTask.ts +68 -0
- package/src/core/tasks/SuiWaitForTransactionTask.ts +67 -0
- package/src/types.ts +20 -3
- package/src/version.ts +1 -1
- package/dist/cjs/SuiProvider.d.ts +0 -2
- package/dist/cjs/SuiProvider.js +0 -37
- package/dist/cjs/SuiProvider.js.map +0 -1
- package/dist/cjs/SuiStepExecutor.d.ts +0 -8
- package/dist/cjs/SuiStepExecutor.js +0 -109
- package/dist/cjs/SuiStepExecutor.js.map +0 -1
- package/dist/cjs/actions/getSuiBalance.d.ts +0 -2
- package/dist/cjs/actions/getSuiBalance.js +0 -54
- package/dist/cjs/actions/getSuiBalance.js.map +0 -1
- package/dist/cjs/actions/getSuiNSAddress.d.ts +0 -1
- package/dist/cjs/actions/getSuiNSAddress.js +0 -32
- package/dist/cjs/actions/getSuiNSAddress.js.map +0 -1
- package/dist/cjs/actions/resolveSuiAddress.d.ts +0 -1
- package/dist/cjs/actions/resolveSuiAddress.js +0 -8
- package/dist/cjs/actions/resolveSuiAddress.js.map +0 -1
- package/dist/cjs/client/suiClient.d.ts +0 -3
- package/dist/cjs/client/suiClient.js +0 -30
- package/dist/cjs/client/suiClient.js.map +0 -1
- package/dist/cjs/errors/parseSuiErrors.d.ts +0 -2
- package/dist/cjs/errors/parseSuiErrors.js +0 -35
- package/dist/cjs/errors/parseSuiErrors.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -3
- package/dist/cjs/index.js +0 -8
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/types.d.ts +0 -14
- package/dist/cjs/types.js +0 -11
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/version.d.ts +0 -2
- package/dist/cjs/version.js +0 -6
- package/dist/cjs/version.js.map +0 -1
- package/dist/esm/SuiStepExecutor.d.ts +0 -8
- package/dist/esm/SuiStepExecutor.js +0 -110
- package/dist/esm/SuiStepExecutor.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/types/SuiProvider.d.ts +0 -3
- package/dist/types/SuiProvider.d.ts.map +0 -1
- package/dist/types/SuiStepExecutor.d.ts +0 -9
- package/dist/types/SuiStepExecutor.d.ts.map +0 -1
- package/dist/types/actions/getSuiBalance.d.ts +0 -3
- package/dist/types/actions/getSuiBalance.d.ts.map +0 -1
- package/dist/types/actions/getSuiNSAddress.d.ts +0 -2
- package/dist/types/actions/getSuiNSAddress.d.ts.map +0 -1
- package/dist/types/actions/resolveSuiAddress.d.ts +0 -2
- package/dist/types/actions/resolveSuiAddress.d.ts.map +0 -1
- package/dist/types/client/suiClient.d.ts +0 -10
- package/dist/types/client/suiClient.d.ts.map +0 -1
- package/dist/types/errors/parseSuiErrors.d.ts +0 -3
- package/dist/types/errors/parseSuiErrors.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/types.d.ts +0 -15
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/version.d.ts +0 -3
- package/dist/types/version.d.ts.map +0 -1
- package/src/SuiStepExecutor.ts +0 -191
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseStepExecutor,
|
|
3
|
+
CheckBalanceTask,
|
|
4
|
+
type ExecutionAction,
|
|
5
|
+
LiFiErrorCode,
|
|
6
|
+
type LiFiStepExtended,
|
|
7
|
+
PrepareTransactionTask,
|
|
8
|
+
type SDKError,
|
|
9
|
+
type StepExecutorBaseContext,
|
|
10
|
+
TaskPipeline,
|
|
11
|
+
TransactionError,
|
|
12
|
+
WaitForTransactionStatusTask,
|
|
13
|
+
} from '@lifi/sdk'
|
|
14
|
+
import type { ClientWithCoreApi } from '@mysten/sui/client'
|
|
15
|
+
import type { Signer } from '@mysten/sui/cryptography'
|
|
16
|
+
import { parseSuiErrors } from '../errors/parseSuiErrors.js'
|
|
17
|
+
import type {
|
|
18
|
+
SuiStepExecutorContext,
|
|
19
|
+
SuiStepExecutorOptions,
|
|
20
|
+
} from '../types.js'
|
|
21
|
+
import { SuiSignAndExecuteTask } from './tasks/SuiSignAndExecuteTask.js'
|
|
22
|
+
import { SuiWaitForTransactionTask } from './tasks/SuiWaitForTransactionTask.js'
|
|
23
|
+
|
|
24
|
+
export class SuiStepExecutor extends BaseStepExecutor {
|
|
25
|
+
private client: ClientWithCoreApi
|
|
26
|
+
private signer: Signer
|
|
27
|
+
|
|
28
|
+
constructor(options: SuiStepExecutorOptions) {
|
|
29
|
+
super(options)
|
|
30
|
+
this.client = options.client
|
|
31
|
+
this.signer = options.signer
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
checkWallet = (step: LiFiStepExtended): void => {
|
|
35
|
+
// Prevent execution of the quote by wallet different from the one which requested the quote
|
|
36
|
+
const address = this.signer.toSuiAddress()
|
|
37
|
+
if (address !== step.action.fromAddress) {
|
|
38
|
+
throw new TransactionError(
|
|
39
|
+
LiFiErrorCode.WalletChangedDuringExecution,
|
|
40
|
+
'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
override parseErrors = (
|
|
46
|
+
error: Error,
|
|
47
|
+
step?: LiFiStepExtended,
|
|
48
|
+
action?: ExecutionAction
|
|
49
|
+
): Promise<SDKError> => parseSuiErrors(error, step, action)
|
|
50
|
+
|
|
51
|
+
override createContext = async (
|
|
52
|
+
baseContext: StepExecutorBaseContext
|
|
53
|
+
): Promise<SuiStepExecutorContext> => {
|
|
54
|
+
return {
|
|
55
|
+
...baseContext,
|
|
56
|
+
suiClient: this.client,
|
|
57
|
+
signer: this.signer,
|
|
58
|
+
checkWallet: this.checkWallet,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
override createPipeline = (context: SuiStepExecutorContext): TaskPipeline => {
|
|
63
|
+
const { step, isBridgeExecution } = context
|
|
64
|
+
|
|
65
|
+
const tasks = [
|
|
66
|
+
new CheckBalanceTask(),
|
|
67
|
+
new PrepareTransactionTask(),
|
|
68
|
+
new SuiSignAndExecuteTask(),
|
|
69
|
+
new SuiWaitForTransactionTask(),
|
|
70
|
+
new WaitForTransactionStatusTask(
|
|
71
|
+
isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'
|
|
72
|
+
),
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
const swapOrBridgeAction = this.statusManager.findAction(
|
|
76
|
+
step,
|
|
77
|
+
isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
const taskName =
|
|
81
|
+
swapOrBridgeAction?.txHash && swapOrBridgeAction?.status === 'DONE'
|
|
82
|
+
? WaitForTransactionStatusTask.name
|
|
83
|
+
: CheckBalanceTask.name
|
|
84
|
+
|
|
85
|
+
const firstTaskIndex = tasks.findIndex(
|
|
86
|
+
(task) => task.constructor.name === taskName
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
const tasksToRun = tasks.slice(firstTaskIndex)
|
|
90
|
+
|
|
91
|
+
return new TaskPipeline(tasksToRun)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseStepExecutionTask,
|
|
3
|
+
getTransactionRequestData,
|
|
4
|
+
LiFiErrorCode,
|
|
5
|
+
type TaskResult,
|
|
6
|
+
TransactionError,
|
|
7
|
+
} from '@lifi/sdk'
|
|
8
|
+
import { Transaction } from '@mysten/sui/transactions'
|
|
9
|
+
import type { SuiStepExecutorContext } from '../../types.js'
|
|
10
|
+
|
|
11
|
+
export class SuiSignAndExecuteTask extends BaseStepExecutionTask {
|
|
12
|
+
async run(context: SuiStepExecutorContext): Promise<TaskResult> {
|
|
13
|
+
const {
|
|
14
|
+
step,
|
|
15
|
+
suiClient,
|
|
16
|
+
signer,
|
|
17
|
+
statusManager,
|
|
18
|
+
executionOptions,
|
|
19
|
+
isBridgeExecution,
|
|
20
|
+
checkWallet,
|
|
21
|
+
} = context
|
|
22
|
+
|
|
23
|
+
const action = statusManager.findAction(
|
|
24
|
+
step,
|
|
25
|
+
isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
if (!action) {
|
|
29
|
+
throw new TransactionError(
|
|
30
|
+
LiFiErrorCode.TransactionUnprepared,
|
|
31
|
+
'Unable to prepare transaction. Action not found.'
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const transactionRequestData = await getTransactionRequestData(
|
|
36
|
+
step,
|
|
37
|
+
executionOptions
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
checkWallet(step)
|
|
41
|
+
|
|
42
|
+
// We give users 2 minutes to sign the transaction
|
|
43
|
+
const {
|
|
44
|
+
$kind,
|
|
45
|
+
FailedTransaction,
|
|
46
|
+
Transaction: TransactionResult,
|
|
47
|
+
} = await suiClient.core.signAndExecuteTransaction({
|
|
48
|
+
signer,
|
|
49
|
+
transaction: Transaction.from(transactionRequestData),
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
statusManager.updateAction(step, action.type, 'PENDING', {
|
|
53
|
+
signedAt: Date.now(),
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
if ($kind !== 'Transaction' || !TransactionResult) {
|
|
57
|
+
throw new TransactionError(
|
|
58
|
+
LiFiErrorCode.TransactionFailed,
|
|
59
|
+
`Transaction failed: ${FailedTransaction?.status.error ?? `Unexpected transaction result: ${$kind}`}`
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
status: 'COMPLETED',
|
|
65
|
+
context: { signedTransaction: TransactionResult },
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseStepExecutionTask,
|
|
3
|
+
LiFiErrorCode,
|
|
4
|
+
type TaskResult,
|
|
5
|
+
TransactionError,
|
|
6
|
+
} from '@lifi/sdk'
|
|
7
|
+
import { callSuiWithRetry } from '../../client/suiClient.js'
|
|
8
|
+
import type { SuiStepExecutorContext } from '../../types.js'
|
|
9
|
+
|
|
10
|
+
export class SuiWaitForTransactionTask extends BaseStepExecutionTask {
|
|
11
|
+
async run(context: SuiStepExecutorContext): Promise<TaskResult> {
|
|
12
|
+
const {
|
|
13
|
+
client,
|
|
14
|
+
step,
|
|
15
|
+
statusManager,
|
|
16
|
+
fromChain,
|
|
17
|
+
isBridgeExecution,
|
|
18
|
+
signedTransaction,
|
|
19
|
+
} = context
|
|
20
|
+
|
|
21
|
+
if (!signedTransaction) {
|
|
22
|
+
throw new TransactionError(
|
|
23
|
+
LiFiErrorCode.TransactionUnprepared,
|
|
24
|
+
'Unable to prepare transaction. Signed transaction is not found.'
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const action = statusManager.findAction(
|
|
29
|
+
step,
|
|
30
|
+
isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
|
|
31
|
+
)
|
|
32
|
+
if (!action) {
|
|
33
|
+
throw new TransactionError(
|
|
34
|
+
LiFiErrorCode.TransactionUnprepared,
|
|
35
|
+
'Unable to prepare transaction. Action not found.'
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const result = await callSuiWithRetry(client, (client) =>
|
|
40
|
+
client.waitForTransaction({
|
|
41
|
+
digest: signedTransaction.digest,
|
|
42
|
+
options: {
|
|
43
|
+
showEffects: true,
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if (result.effects?.status.status !== 'success') {
|
|
49
|
+
throw new TransactionError(
|
|
50
|
+
LiFiErrorCode.TransactionFailed,
|
|
51
|
+
`Transaction failed: ${result.effects?.status.error}`
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Transaction has been confirmed and we can update the action
|
|
56
|
+
statusManager.updateAction(step, action.type, 'PENDING', {
|
|
57
|
+
txHash: result.digest,
|
|
58
|
+
txLink: `${fromChain.metamask.blockExplorerUrls[0]}txblock/${result.digest}`,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
if (isBridgeExecution) {
|
|
62
|
+
statusManager.updateAction(step, action.type, 'DONE')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return { status: 'COMPLETED' }
|
|
66
|
+
}
|
|
67
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ChainType,
|
|
3
|
+
type LiFiStepExtended,
|
|
3
4
|
type SDKProvider,
|
|
5
|
+
type StepExecutorContext,
|
|
4
6
|
type StepExecutorOptions,
|
|
5
7
|
} from '@lifi/sdk'
|
|
6
|
-
import type {
|
|
8
|
+
import type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client'
|
|
9
|
+
import type { Signer } from '@mysten/sui/cryptography'
|
|
7
10
|
|
|
8
11
|
export interface SuiProviderOptions {
|
|
9
|
-
|
|
12
|
+
getClient?: () => Promise<ClientWithCoreApi>
|
|
13
|
+
getSigner?: () => Promise<Signer>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface SuiTaskContext {
|
|
17
|
+
signedTransaction?: SuiClientTypes.Transaction
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SuiStepExecutorContext
|
|
21
|
+
extends StepExecutorContext,
|
|
22
|
+
SuiTaskContext {
|
|
23
|
+
suiClient: ClientWithCoreApi
|
|
24
|
+
signer: Signer
|
|
25
|
+
checkWallet: (step: LiFiStepExtended) => void
|
|
10
26
|
}
|
|
11
27
|
|
|
12
28
|
export interface SuiSDKProvider extends SDKProvider {
|
|
@@ -20,7 +36,8 @@ export function isSuiProvider(
|
|
|
20
36
|
}
|
|
21
37
|
|
|
22
38
|
export interface SuiStepExecutorOptions extends StepExecutorOptions {
|
|
23
|
-
|
|
39
|
+
client: ClientWithCoreApi
|
|
40
|
+
signer: Signer
|
|
24
41
|
}
|
|
25
42
|
|
|
26
43
|
export const SuiTokenShortAddress = '0x2::sui::SUI'
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk-provider-sui'
|
|
2
|
-
export const version = '4.0.1
|
|
2
|
+
export const version = '4.0.1'
|
package/dist/cjs/SuiProvider.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SuiProvider = SuiProvider;
|
|
4
|
-
const sdk_1 = require("@lifi/sdk");
|
|
5
|
-
const utils_1 = require("@mysten/sui/utils");
|
|
6
|
-
const getSuiBalance_js_1 = require("./actions/getSuiBalance.js");
|
|
7
|
-
const resolveSuiAddress_js_1 = require("./actions/resolveSuiAddress.js");
|
|
8
|
-
const SuiStepExecutor_js_1 = require("./SuiStepExecutor.js");
|
|
9
|
-
function SuiProvider(options) {
|
|
10
|
-
const _options = options ?? {};
|
|
11
|
-
return {
|
|
12
|
-
get type() {
|
|
13
|
-
return sdk_1.ChainType.MVM;
|
|
14
|
-
},
|
|
15
|
-
isAddress: utils_1.isValidSuiAddress,
|
|
16
|
-
resolveAddress: resolveSuiAddress_js_1.resolveSuiAddress,
|
|
17
|
-
getBalance: getSuiBalance_js_1.getSuiBalance,
|
|
18
|
-
async getStepExecutor(options) {
|
|
19
|
-
if (!_options.getWallet) {
|
|
20
|
-
throw new Error('getWallet is not provided.');
|
|
21
|
-
}
|
|
22
|
-
const wallet = await _options.getWallet();
|
|
23
|
-
const executor = new SuiStepExecutor_js_1.SuiStepExecutor({
|
|
24
|
-
wallet,
|
|
25
|
-
routeId: options.routeId,
|
|
26
|
-
executionOptions: {
|
|
27
|
-
...options.executionOptions,
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
return executor;
|
|
31
|
-
},
|
|
32
|
-
setOptions(options) {
|
|
33
|
-
Object.assign(_options, options);
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=SuiProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SuiProvider.js","sourceRoot":"","sources":["../../src/SuiProvider.ts"],"names":[],"mappings":";;AAOA,kCAgCC;AAvCD,mCAA+D;AAC/D,6CAAqD;AACrD,iEAA0D;AAC1D,yEAAkE;AAClE,6DAAsD;AAGtD,SAAgB,WAAW,CAAC,OAA4B;IACtD,MAAM,QAAQ,GAAuB,OAAO,IAAI,EAAE,CAAA;IAClD,OAAO;QACL,IAAI,IAAI;YACN,OAAO,eAAS,CAAC,GAAG,CAAA;QACtB,CAAC;QACD,SAAS,EAAE,yBAAiB;QAC5B,cAAc,EAAE,wCAAiB;QACjC,UAAU,EAAE,gCAAa;QACzB,KAAK,CAAC,eAAe,CACnB,OAA4B;YAE5B,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;YAC/C,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,SAAS,EAAE,CAAA;YAEzC,MAAM,QAAQ,GAAG,IAAI,oCAAe,CAAC;gBACnC,MAAM;gBACN,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,gBAAgB,EAAE;oBAChB,GAAG,OAAO,CAAC,gBAAgB;iBAC5B;aACF,CAAC,CAAA;YAEF,OAAO,QAAQ,CAAA;QACjB,CAAC;QACD,UAAU,CAAC,OAA2B;YACpC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;QAClC,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BaseStepExecutor, type LiFiStepExtended, type SDKClient } from '@lifi/sdk';
|
|
2
|
-
import type { SuiStepExecutorOptions } from './types.js';
|
|
3
|
-
export declare class SuiStepExecutor extends BaseStepExecutor {
|
|
4
|
-
private wallet;
|
|
5
|
-
constructor(options: SuiStepExecutorOptions);
|
|
6
|
-
checkWallet: (step: LiFiStepExtended) => void;
|
|
7
|
-
executeStep: (client: SDKClient, step: LiFiStepExtended) => Promise<LiFiStepExtended>;
|
|
8
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SuiStepExecutor = void 0;
|
|
4
|
-
const sdk_1 = require("@lifi/sdk");
|
|
5
|
-
const wallet_standard_1 = require("@mysten/wallet-standard");
|
|
6
|
-
const suiClient_js_1 = require("./client/suiClient.js");
|
|
7
|
-
const parseSuiErrors_js_1 = require("./errors/parseSuiErrors.js");
|
|
8
|
-
class SuiStepExecutor extends sdk_1.BaseStepExecutor {
|
|
9
|
-
wallet;
|
|
10
|
-
constructor(options) {
|
|
11
|
-
super(options);
|
|
12
|
-
this.wallet = options.wallet;
|
|
13
|
-
}
|
|
14
|
-
checkWallet = (step) => {
|
|
15
|
-
if (!this.wallet.accounts?.some?.((account) => account.address === step.action.fromAddress)) {
|
|
16
|
-
throw new sdk_1.TransactionError(sdk_1.LiFiErrorCode.WalletChangedDuringExecution, 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.');
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
executeStep = async (client, step) => {
|
|
20
|
-
step.execution = this.statusManager.initExecutionObject(step);
|
|
21
|
-
const fromChain = await client.getChainById(step.action.fromChainId);
|
|
22
|
-
const toChain = await client.getChainById(step.action.toChainId);
|
|
23
|
-
const isBridgeExecution = fromChain.id !== toChain.id;
|
|
24
|
-
const currentActionType = isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP';
|
|
25
|
-
let action = this.statusManager.findOrCreateAction({
|
|
26
|
-
step,
|
|
27
|
-
type: currentActionType,
|
|
28
|
-
chainId: fromChain.id,
|
|
29
|
-
});
|
|
30
|
-
if (action.status !== 'DONE') {
|
|
31
|
-
try {
|
|
32
|
-
action = this.statusManager.updateAction(step, action.type, 'STARTED');
|
|
33
|
-
await (0, sdk_1.checkBalance)(client, step.action.fromAddress, step);
|
|
34
|
-
if (!step.transactionRequest) {
|
|
35
|
-
const { execution, ...stepBase } = step;
|
|
36
|
-
const updatedStep = await (0, sdk_1.getStepTransaction)(client, stepBase);
|
|
37
|
-
const comparedStep = await (0, sdk_1.stepComparison)(this.statusManager, step, updatedStep, this.allowUserInteraction, this.executionOptions);
|
|
38
|
-
Object.assign(step, {
|
|
39
|
-
...comparedStep,
|
|
40
|
-
execution: step.execution,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
if (!step.transactionRequest?.data) {
|
|
44
|
-
throw new sdk_1.TransactionError(sdk_1.LiFiErrorCode.TransactionUnprepared, 'Unable to prepare transaction.');
|
|
45
|
-
}
|
|
46
|
-
action = this.statusManager.updateAction(step, action.type, 'ACTION_REQUIRED');
|
|
47
|
-
if (!this.allowUserInteraction) {
|
|
48
|
-
return step;
|
|
49
|
-
}
|
|
50
|
-
let transactionRequest = {
|
|
51
|
-
data: step.transactionRequest.data,
|
|
52
|
-
};
|
|
53
|
-
if (this.executionOptions?.updateTransactionRequestHook) {
|
|
54
|
-
const customizedTransactionRequest = await this.executionOptions.updateTransactionRequestHook({
|
|
55
|
-
requestType: 'transaction',
|
|
56
|
-
...transactionRequest,
|
|
57
|
-
});
|
|
58
|
-
transactionRequest = {
|
|
59
|
-
...transactionRequest,
|
|
60
|
-
...customizedTransactionRequest,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
const transactionRequestData = transactionRequest.data;
|
|
64
|
-
if (!transactionRequestData) {
|
|
65
|
-
throw new sdk_1.TransactionError(sdk_1.LiFiErrorCode.TransactionUnprepared, 'Unable to prepare transaction.');
|
|
66
|
-
}
|
|
67
|
-
this.checkWallet(step);
|
|
68
|
-
const signedTx = await (0, wallet_standard_1.signAndExecuteTransaction)(this.wallet, {
|
|
69
|
-
account: this.wallet.accounts.find((account) => account.address === step.action.fromAddress),
|
|
70
|
-
chain: 'sui:mainnet',
|
|
71
|
-
transaction: {
|
|
72
|
-
toJSON: async () => transactionRequestData,
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
action = this.statusManager.updateAction(step, action.type, 'PENDING');
|
|
76
|
-
const result = await (0, suiClient_js_1.callSuiWithRetry)(client, (client) => client.waitForTransaction({
|
|
77
|
-
digest: signedTx.digest,
|
|
78
|
-
options: {
|
|
79
|
-
showEffects: true,
|
|
80
|
-
},
|
|
81
|
-
}));
|
|
82
|
-
if (result.effects?.status.status !== 'success') {
|
|
83
|
-
throw new sdk_1.TransactionError(sdk_1.LiFiErrorCode.TransactionFailed, `Transaction failed: ${result.effects?.status.error}`);
|
|
84
|
-
}
|
|
85
|
-
action = this.statusManager.updateAction(step, action.type, 'PENDING', {
|
|
86
|
-
txHash: result.digest,
|
|
87
|
-
txLink: `${fromChain.metamask.blockExplorerUrls[0]}txblock/${result.digest}`,
|
|
88
|
-
});
|
|
89
|
-
if (isBridgeExecution) {
|
|
90
|
-
action = this.statusManager.updateAction(step, action.type, 'DONE');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
catch (e) {
|
|
94
|
-
const error = await (0, parseSuiErrors_js_1.parseSuiErrors)(e, step, action);
|
|
95
|
-
action = this.statusManager.updateAction(step, action.type, 'FAILED', {
|
|
96
|
-
error: {
|
|
97
|
-
message: error.cause.message,
|
|
98
|
-
code: error.code,
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
throw error;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
await (0, sdk_1.waitForDestinationChainTransaction)(client, step, action, fromChain, toChain, this.statusManager);
|
|
105
|
-
return step;
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
exports.SuiStepExecutor = SuiStepExecutor;
|
|
109
|
-
//# sourceMappingURL=SuiStepExecutor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SuiStepExecutor.js","sourceRoot":"","sources":["../../src/SuiStepExecutor.ts"],"names":[],"mappings":";;;AAAA,mCAWkB;AAClB,6DAGgC;AAChC,wDAAwD;AACxD,kEAA2D;AAG3D,MAAa,eAAgB,SAAQ,sBAAgB;IAC3C,MAAM,CAA4B;IAE1C,YAAY,OAA+B;QACzC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;IAC9B,CAAC;IAED,WAAW,GAAG,CAAC,IAAsB,EAAE,EAAE;QAEvC,IACE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,CAC3B,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,MAAM,CAAC,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AAM,CAAC,MAAM,EAAE;iBAC7E,CAAC,CAAA;gBAEF,IAAI,iBAAiB,EAAE,CAAC;oBACtB,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;gBACrE,CAAC;YACH,CAAC;YAAC,OAAO,CAAM,EAAE,CAAC;gBAChB,MAAM,KAAK,GAAG,MAAM,IAAA,kCAAc,EAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;gBACnD,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE;oBACpE,KAAK,EAAE;wBACL,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;wBAC5B,IAAI,EAAE,KAAK,CAAC,IAAI;qBACjB;iBACF,CAAC,CAAA;gBACF,MAAM,KAAK,CAAA;YACb,CAAC;QACH,CAAC;QAED,MAAM,IAAA,wCAAkC,EACtC,MAAM,EACN,IAAI,EACJ,MAAM,EACN,SAAS,EACT,OAAO,EACP,IAAI,CAAC,aAAa,CACnB,CAAA;QAED,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;CACF;AA1KD,0CA0KC"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSuiBalance = getSuiBalance;
|
|
4
|
-
const sdk_1 = require("@lifi/sdk");
|
|
5
|
-
const suiClient_js_1 = require("../client/suiClient.js");
|
|
6
|
-
const types_js_1 = require("../types.js");
|
|
7
|
-
async function getSuiBalance(client, walletAddress, tokens) {
|
|
8
|
-
if (tokens.length === 0) {
|
|
9
|
-
return [];
|
|
10
|
-
}
|
|
11
|
-
const { chainId } = tokens[0];
|
|
12
|
-
for (const token of tokens) {
|
|
13
|
-
if (token.chainId !== chainId) {
|
|
14
|
-
console.warn('Requested tokens have to be on the same chain.');
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return getSuiBalanceDefault(client, chainId, tokens, walletAddress);
|
|
18
|
-
}
|
|
19
|
-
const getSuiBalanceDefault = async (client, _chainId, tokens, walletAddress) => {
|
|
20
|
-
const [coins, checkpoint] = await Promise.allSettled([
|
|
21
|
-
(0, sdk_1.withDedupe)(() => (0, suiClient_js_1.callSuiWithRetry)(client, (client) => client.getAllBalances({
|
|
22
|
-
owner: walletAddress,
|
|
23
|
-
})), { id: `${getSuiBalanceDefault.name}.getAllBalances` }),
|
|
24
|
-
(0, sdk_1.withDedupe)(() => (0, suiClient_js_1.callSuiWithRetry)(client, (client) => client.getLatestCheckpointSequenceNumber()), { id: `${getSuiBalanceDefault.name}.getLatestCheckpointSequenceNumber` }),
|
|
25
|
-
]);
|
|
26
|
-
const coinsResult = coins.status === 'fulfilled' ? coins.value : [];
|
|
27
|
-
const blockNumber = checkpoint.status === 'fulfilled' ? BigInt(checkpoint.value) : 0n;
|
|
28
|
-
const walletTokenAmounts = coinsResult.reduce((tokenAmounts, coin) => {
|
|
29
|
-
const amount = BigInt(coin.totalBalance);
|
|
30
|
-
if (amount > 0n) {
|
|
31
|
-
tokenAmounts[coin.coinType] = amount;
|
|
32
|
-
}
|
|
33
|
-
return tokenAmounts;
|
|
34
|
-
}, {});
|
|
35
|
-
const suiTokenBalance = coinsResult.find((coin) => coin.coinType === types_js_1.SuiTokenShortAddress);
|
|
36
|
-
if (suiTokenBalance?.totalBalance) {
|
|
37
|
-
walletTokenAmounts[types_js_1.SuiTokenLongAddress] = BigInt(suiTokenBalance.totalBalance);
|
|
38
|
-
}
|
|
39
|
-
const tokenAmounts = tokens.map((token) => {
|
|
40
|
-
if (walletTokenAmounts[token.address]) {
|
|
41
|
-
return {
|
|
42
|
-
...token,
|
|
43
|
-
amount: walletTokenAmounts[token.address],
|
|
44
|
-
blockNumber,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
...token,
|
|
49
|
-
blockNumber,
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
return tokenAmounts;
|
|
53
|
-
};
|
|
54
|
-
//# sourceMappingURL=getSuiBalance.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getSuiBalance.js","sourceRoot":"","sources":["../../../src/actions/getSuiBalance.ts"],"names":[],"mappings":";;AASA,sCAiBC;AA1BD,mCAKkB;AAClB,yDAAyD;AACzD,0CAAuE;AAEhE,KAAK,UAAU,aAAa,CACjC,MAAiB,EACjB,aAAqB,EACrB,MAAe;IAEf,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;IAC7B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,KAAK,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;YAC9B,OAAO,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAA;QAChE,CAAC;IACH,CAAC;IAED,OAAO,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,CAAA;AACrE,CAAC;AAED,MAAM,oBAAoB,GAAG,KAAK,EAChC,MAAiB,EACjB,QAAgB,EAChB,MAAe,EACf,aAAqB,EACG,EAAE;IAC1B,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC;QACnD,IAAA,gBAAU,EACR,GAAG,EAAE,CACH,IAAA,+BAAgB,EAAC,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAClC,MAAM,CAAC,cAAc,CAAC;YACpB,KAAK,EAAE,aAAa;SACrB,CAAC,CACH,EACH,EAAE,EAAE,EAAE,GAAG,oBAAoB,CAAC,IAAI,iBAAiB,EAAE,CACtD;QACD,IAAA,gBAAU,EACR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kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC;gBACzC,WAAW;aACZ,CAAA;QACH,CAAC;QACD,OAAO;YACL,GAAG,KAAK;YACR,WAAW;SACZ,CAAA;IACH,CAAC,CAAC,CAAA;IACF,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getSuiNSAddress(name: string, rpcUrl?: string): Promise<string | undefined>;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSuiNSAddress = getSuiNSAddress;
|
|
4
|
-
const client_1 = require("@mysten/sui/client");
|
|
5
|
-
const SNS_REGISTRY_ID = '0x6e0ddefc0ad3ed64f53f5f91b7023077b2f7c131d7e6d5e0d1a0e4e6f1a2c3b4';
|
|
6
|
-
async function getSuiNSAddress(name, rpcUrl) {
|
|
7
|
-
const client = new client_1.SuiClient({
|
|
8
|
-
url: rpcUrl || 'https://fullnode.mainnet.sui.io:443',
|
|
9
|
-
});
|
|
10
|
-
try {
|
|
11
|
-
const result = await client.getObject({
|
|
12
|
-
id: SNS_REGISTRY_ID,
|
|
13
|
-
options: {
|
|
14
|
-
showContent: true,
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
if (!result.data?.content) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const registry = result.data.content;
|
|
21
|
-
const nameRecord = registry.fields.records.find((record) => record.fields.name === name);
|
|
22
|
-
if (!nameRecord) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
return nameRecord.fields.address;
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
console.error('Error resolving SuiNS address:', error);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=getSuiNSAddress.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getSuiNSAddress.js","sourceRoot":"","sources":["../../../src/actions/getSuiNSAddress.ts"],"names":[],"mappings":";;AAKA,0CAkCC;AAvCD,+CAA8C;AAE9C,MAAM,eAAe,GACnB,oEAAoE,CAAA;AAE/D,KAAK,UAAU,eAAe,CACnC,IAAY,EACZ,MAAe;IAEf,MAAM,MAAM,GAAG,IAAI,kBAAS,CAAC;QAC3B,GAAG,EAAE,MAAM,IAAI,qCAAqC;KACrD,CAAC,CAAA;IAEF,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC;YACpC,EAAE,EAAE,eAAe;YACnB,OAAO,EAAE;gBACP,WAAW,EAAE,IAAI;aAClB;SACF,CAAC,CAAA;QAEF,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC;YAC1B,OAAM;QACR,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,OAAc,CAAA;QAC3C,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAC7C,CAAC,MAAW,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CAC7C,CAAA;QAED,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAM;QACR,CAAC;QAED,OAAO,UAAU,CAAC,MAAM,CAAC,OAAO,CAAA;IAClC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAA;QACtD,OAAM;IACR,CAAC;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function resolveSuiAddress(name: string): Promise<string | undefined>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveSuiAddress = resolveSuiAddress;
|
|
4
|
-
const getSuiNSAddress_js_1 = require("./getSuiNSAddress.js");
|
|
5
|
-
async function resolveSuiAddress(name) {
|
|
6
|
-
return await (0, getSuiNSAddress_js_1.getSuiNSAddress)(name);
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=resolveSuiAddress.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolveSuiAddress.js","sourceRoot":"","sources":["../../../src/actions/resolveSuiAddress.ts"],"names":[],"mappings":";;AAEA,8CAIC;AAND,6DAAsD;AAE/C,KAAK,UAAU,iBAAiB,CACrC,IAAY;IAEZ,OAAO,MAAM,IAAA,oCAAe,EAAC,IAAI,CAAC,CAAA;AACpC,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.callSuiWithRetry = callSuiWithRetry;
|
|
4
|
-
const sdk_1 = require("@lifi/sdk");
|
|
5
|
-
const client_1 = require("@mysten/sui/client");
|
|
6
|
-
const clients = new Map();
|
|
7
|
-
const ensureClients = async (client) => {
|
|
8
|
-
const rpcUrls = await client.getRpcUrlsByChainId(sdk_1.ChainId.SUI);
|
|
9
|
-
for (const rpcUrl of rpcUrls) {
|
|
10
|
-
if (!clients.get(rpcUrl)) {
|
|
11
|
-
const client = new client_1.SuiClient({ url: rpcUrl });
|
|
12
|
-
clients.set(rpcUrl, client);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
async function callSuiWithRetry(client, fn) {
|
|
17
|
-
await ensureClients(client);
|
|
18
|
-
let lastError = null;
|
|
19
|
-
for (const client of clients.values()) {
|
|
20
|
-
try {
|
|
21
|
-
const result = await fn(client);
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
lastError = error;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
throw lastError;
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=suiClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"suiClient.js","sourceRoot":"","sources":["../../../src/client/suiClient.ts"],"names":[],"mappings":";;AAyBA,4CAiBC;AA1CD,mCAAmD;AACnD,+CAA8C;AAE9C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAqB,CAAA;AAM5C,MAAM,aAAa,GAAG,KAAK,EAAE,MAAiB,EAAiB,EAAE;IAC/D,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,aAAO,CAAC,GAAG,CAAC,CAAA;IAC7D,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACzB,MAAM,MAAM,GAAG,IAAI,kBAAS,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAA;YAC7C,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAC7B,CAAC;IACH,CAAC;AACH,CAAC,CAAA;AAQM,KAAK,UAAU,gBAAgB,CACpC,MAAiB,EACjB,EAAqC;IAGrC,MAAM,aAAa,CAAC,MAAM,CAAC,CAAA;IAC3B,IAAI,SAAS,GAAQ,IAAI,CAAA;IACzB,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;QACtC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,CAAA;YAC/B,OAAO,MAAM,CAAA;QACf,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,SAAS,GAAG,KAAK,CAAA;QACnB,CAAC;IACH,CAAC;IAED,MAAM,SAAS,CAAA;AACjB,CAAC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseSuiErrors = void 0;
|
|
4
|
-
const sdk_1 = require("@lifi/sdk");
|
|
5
|
-
const parseSuiErrors = async (e, step, action) => {
|
|
6
|
-
if (e instanceof sdk_1.SDKError) {
|
|
7
|
-
e.step = e.step ?? step;
|
|
8
|
-
e.action = e.action ?? action;
|
|
9
|
-
return e;
|
|
10
|
-
}
|
|
11
|
-
const baseError = handleSpecificErrors(e);
|
|
12
|
-
return new sdk_1.SDKError(baseError, step, action);
|
|
13
|
-
};
|
|
14
|
-
exports.parseSuiErrors = parseSuiErrors;
|
|
15
|
-
const handleSpecificErrors = (e) => {
|
|
16
|
-
const isRejection = typeof e === 'string'
|
|
17
|
-
? e.toLowerCase().includes('reject')
|
|
18
|
-
: e.message?.toLowerCase().includes('reject');
|
|
19
|
-
if (isRejection) {
|
|
20
|
-
return new sdk_1.TransactionError(sdk_1.LiFiErrorCode.SignatureRejected, e.message, e);
|
|
21
|
-
}
|
|
22
|
-
if (e.message?.toLowerCase().includes('transaction') &&
|
|
23
|
-
(e.message?.toLowerCase().includes('failed') ||
|
|
24
|
-
e.message?.toLowerCase().includes('error'))) {
|
|
25
|
-
return new sdk_1.TransactionError(sdk_1.LiFiErrorCode.TransactionFailed, e.message, e);
|
|
26
|
-
}
|
|
27
|
-
if (e.message?.includes('simulate') || e.message?.includes('simulation')) {
|
|
28
|
-
return new sdk_1.TransactionError(sdk_1.LiFiErrorCode.TransactionSimulationFailed, e.message, e);
|
|
29
|
-
}
|
|
30
|
-
if (e instanceof sdk_1.BaseError) {
|
|
31
|
-
return e;
|
|
32
|
-
}
|
|
33
|
-
return new sdk_1.UnknownError(e.message || sdk_1.ErrorMessage.UnknownError, e);
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=parseSuiErrors.js.map
|