@rango-dev/queue-manager-rango-preset 0.61.2-next.3 → 0.61.2-next.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/checkPrerequisites/checkPrerequisites.d.ts +5 -0
- package/dist/actions/checkPrerequisites/checkPrerequisites.d.ts.map +1 -0
- package/dist/actions/checkPrerequisites/index.d.ts +2 -0
- package/dist/actions/checkPrerequisites/index.d.ts.map +1 -0
- package/dist/actions/checkPrerequisites/utils.d.ts +21 -0
- package/dist/actions/checkPrerequisites/utils.d.ts.map +1 -0
- package/dist/actions/checkStellarTrustline/checkStellarTrustline.d.ts +5 -0
- package/dist/actions/checkStellarTrustline/checkStellarTrustline.d.ts.map +1 -0
- package/dist/actions/checkStellarTrustline/constants.d.ts +2 -0
- package/dist/actions/checkStellarTrustline/constants.d.ts.map +1 -0
- package/dist/actions/checkStellarTrustline/index.d.ts +3 -0
- package/dist/actions/checkStellarTrustline/index.d.ts.map +1 -0
- package/dist/actions/checkStellarTrustline/types.d.ts +9 -0
- package/dist/actions/checkStellarTrustline/types.d.ts.map +1 -0
- package/dist/actions/checkStellarTrustline/utils.d.ts +26 -0
- package/dist/actions/checkStellarTrustline/utils.d.ts.map +1 -0
- package/dist/actions/checkXrplTrustline/checkXrplTrustline.d.ts.map +1 -1
- package/dist/actions/checkXrplTrustline/constants.d.ts +2 -0
- package/dist/actions/checkXrplTrustline/constants.d.ts.map +1 -0
- package/dist/actions/checkXrplTrustline/index.d.ts +1 -1
- package/dist/actions/checkXrplTrustline/index.d.ts.map +1 -1
- package/dist/actions/checkXrplTrustline/utils.d.ts +20 -7
- package/dist/actions/checkXrplTrustline/utils.d.ts.map +1 -1
- package/dist/actions/checkXrplTrustlineTransactionStatus/checkXrplTrustlineTransactionStatus.d.ts +5 -0
- package/dist/actions/checkXrplTrustlineTransactionStatus/checkXrplTrustlineTransactionStatus.d.ts.map +1 -0
- package/dist/actions/checkXrplTrustlineTransactionStatus/constants.d.ts +3 -0
- package/dist/actions/checkXrplTrustlineTransactionStatus/constants.d.ts.map +1 -0
- package/dist/actions/checkXrplTrustlineTransactionStatus/index.d.ts +2 -0
- package/dist/actions/checkXrplTrustlineTransactionStatus/index.d.ts.map +1 -0
- package/dist/actions/executeStellarTransaction/executeStellarTransaction.d.ts +4 -0
- package/dist/actions/executeStellarTransaction/executeStellarTransaction.d.ts.map +1 -0
- package/dist/actions/executeStellarTransaction/helpers.d.ts +7 -0
- package/dist/actions/executeStellarTransaction/helpers.d.ts.map +1 -0
- package/dist/actions/executeStellarTransaction/index.d.ts +2 -0
- package/dist/actions/executeStellarTransaction/index.d.ts.map +1 -0
- package/dist/actions/executeXrplTransaction/executeXrplTransaction.d.ts.map +1 -1
- package/dist/actions/executeXrplTransaction/helpers.d.ts +5 -0
- package/dist/actions/executeXrplTransaction/helpers.d.ts.map +1 -1
- package/dist/actions/scheduleNextStep.d.ts.map +1 -1
- package/dist/helpers.d.ts +2 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/queue-manager-rango-preset.build.json +1 -1
- package/dist/queueDef.d.ts.map +1 -1
- package/dist/types.d.ts +5 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/actions/checkPrerequisites/checkPrerequisites.ts +113 -0
- package/src/actions/checkPrerequisites/index.ts +1 -0
- package/src/actions/checkPrerequisites/utils.ts +124 -0
- package/src/actions/checkStellarTrustline/checkStellarTrustline.ts +237 -0
- package/src/actions/checkStellarTrustline/constants.ts +1 -0
- package/src/actions/checkStellarTrustline/index.ts +6 -0
- package/src/actions/checkStellarTrustline/types.ts +9 -0
- package/src/actions/checkStellarTrustline/utils.ts +200 -0
- package/src/actions/checkXrplTrustline/checkXrplTrustline.ts +147 -97
- package/src/actions/checkXrplTrustline/constants.ts +1 -0
- package/src/actions/checkXrplTrustline/index.ts +2 -1
- package/src/actions/checkXrplTrustline/utils.ts +134 -59
- package/src/actions/checkXrplTrustlineTransactionStatus/checkXrplTrustlineTransactionStatus.ts +145 -0
- package/src/actions/checkXrplTrustlineTransactionStatus/constants.ts +2 -0
- package/src/actions/checkXrplTrustlineTransactionStatus/index.ts +1 -0
- package/src/actions/executeStellarTransaction/executeStellarTransaction.ts +168 -0
- package/src/actions/executeStellarTransaction/helpers.ts +43 -0
- package/src/actions/executeStellarTransaction/index.ts +1 -0
- package/src/actions/executeXrplTransaction/executeXrplTransaction.ts +79 -47
- package/src/actions/executeXrplTransaction/helpers.ts +46 -0
- package/src/actions/scheduleNextStep.ts +2 -6
- package/src/helpers.ts +29 -0
- package/src/queueDef.ts +10 -1
- package/src/types.ts +8 -1
- package/dist/actions/executeXrplTransaction/constants.d.ts +0 -2
- package/dist/actions/executeXrplTransaction/constants.d.ts.map +0 -1
- package/src/actions/executeXrplTransaction/constants.ts +0 -1
package/src/actions/checkXrplTrustlineTransactionStatus/checkXrplTrustlineTransactionStatus.ts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { SwapQueueContext, SwapStorage } from '../../types';
|
|
2
|
+
import type { NextTransactionStateError } from '../common/produceNextStateForTransaction';
|
|
3
|
+
import type { ExecuterActions } from '@rango-dev/queue-manager-core';
|
|
4
|
+
import type { TrustSet, TxResponse } from 'xrpl';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
isXrplChangeTrustLinePrerequisiteResult,
|
|
8
|
+
XRPL_CHANGE_TRUSTLINE_TYPE,
|
|
9
|
+
type XrplChangeTrustLinePrerequisiteResult,
|
|
10
|
+
} from 'rango-types';
|
|
11
|
+
import { Err } from 'ts-results';
|
|
12
|
+
import { Client } from 'xrpl';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
delay,
|
|
16
|
+
getCurrentStep,
|
|
17
|
+
updateStorageWithPrerequisiteResult,
|
|
18
|
+
} from '../../helpers';
|
|
19
|
+
import { SwapActionTypes } from '../../types';
|
|
20
|
+
import { onNextStateError } from '../common/produceNextStateForTransaction';
|
|
21
|
+
|
|
22
|
+
import {
|
|
23
|
+
INTERVAL_FOR_CHECK_XRPL_TRUSTLINE_TRANSACTION_STATUS,
|
|
24
|
+
XRPL_PUBLIC_SERVER,
|
|
25
|
+
} from './constants';
|
|
26
|
+
|
|
27
|
+
export async function checkXrplTrustLineTransactionStatus(
|
|
28
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>
|
|
29
|
+
): Promise<void> {
|
|
30
|
+
const { failed, getStorage, retry, next, schedule } = actions;
|
|
31
|
+
|
|
32
|
+
const swap = getStorage().swapDetails;
|
|
33
|
+
const currentStep = getCurrentStep(swap)!;
|
|
34
|
+
|
|
35
|
+
const onFinish = () => {
|
|
36
|
+
if (actions.context.resetClaimedBy) {
|
|
37
|
+
actions.context.resetClaimedBy();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const onSuccessfulFinish = () => {
|
|
42
|
+
schedule(SwapActionTypes.CHECK_PREREQUISITES);
|
|
43
|
+
next();
|
|
44
|
+
onFinish();
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const handleErr = (err: Err<NextTransactionStateError>) => {
|
|
48
|
+
onNextStateError(actions, err.val);
|
|
49
|
+
failed();
|
|
50
|
+
onFinish();
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const retryAfterDelay = async () => {
|
|
54
|
+
await delay(INTERVAL_FOR_CHECK_XRPL_TRUSTLINE_TRANSACTION_STATUS);
|
|
55
|
+
retry();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
*
|
|
60
|
+
* 1. Ensure a pending XRPL_CHANGE_TRUSTLINE prerequisite result is available.
|
|
61
|
+
*
|
|
62
|
+
*/
|
|
63
|
+
let pendingXrplChangeTrustLinePrerequisiteResult: XrplChangeTrustLinePrerequisiteResult | null =
|
|
64
|
+
null;
|
|
65
|
+
|
|
66
|
+
for (const prerequisiteResult of currentStep.prerequisiteResults) {
|
|
67
|
+
if (
|
|
68
|
+
isXrplChangeTrustLinePrerequisiteResult(prerequisiteResult) &&
|
|
69
|
+
prerequisiteResult.status === 'pending'
|
|
70
|
+
) {
|
|
71
|
+
pendingXrplChangeTrustLinePrerequisiteResult = prerequisiteResult;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!pendingXrplChangeTrustLinePrerequisiteResult) {
|
|
77
|
+
onSuccessfulFinish();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const client = new Client(XRPL_PUBLIC_SERVER);
|
|
83
|
+
await client.connect();
|
|
84
|
+
|
|
85
|
+
const response: TxResponse<TrustSet> = await client.request({
|
|
86
|
+
command: 'tx',
|
|
87
|
+
transaction:
|
|
88
|
+
pendingXrplChangeTrustLinePrerequisiteResult.data
|
|
89
|
+
.executedTransactionHash,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (!response.result.validated) {
|
|
93
|
+
// If data is not final, we need to retry
|
|
94
|
+
await retryAfterDelay();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// If data is final, we can update the prerequisite status
|
|
99
|
+
if (
|
|
100
|
+
typeof response.result.meta !== 'string' && // `response.result.meta` should not be of type "string" because `binary` filed is not set in tx request
|
|
101
|
+
response.result.meta?.TransactionResult === 'tesSUCCESS' // https://xrpl.org/docs/references/protocol/transactions/transaction-results
|
|
102
|
+
) {
|
|
103
|
+
const prerequisiteResult: XrplChangeTrustLinePrerequisiteResult = {
|
|
104
|
+
prerequisiteIndex:
|
|
105
|
+
pendingXrplChangeTrustLinePrerequisiteResult.prerequisiteIndex,
|
|
106
|
+
prerequisiteType: XRPL_CHANGE_TRUSTLINE_TYPE,
|
|
107
|
+
status: 'success',
|
|
108
|
+
data: {
|
|
109
|
+
executedTransactionHash:
|
|
110
|
+
pendingXrplChangeTrustLinePrerequisiteResult.data
|
|
111
|
+
.executedTransactionHash,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
updateStorageWithPrerequisiteResult(actions, prerequisiteResult);
|
|
116
|
+
onSuccessfulFinish();
|
|
117
|
+
} else {
|
|
118
|
+
const prerequisiteResult: XrplChangeTrustLinePrerequisiteResult = {
|
|
119
|
+
prerequisiteIndex:
|
|
120
|
+
pendingXrplChangeTrustLinePrerequisiteResult.prerequisiteIndex,
|
|
121
|
+
prerequisiteType: XRPL_CHANGE_TRUSTLINE_TYPE,
|
|
122
|
+
status: 'failed',
|
|
123
|
+
data: {
|
|
124
|
+
executedTransactionHash:
|
|
125
|
+
pendingXrplChangeTrustLinePrerequisiteResult.data
|
|
126
|
+
.executedTransactionHash,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
updateStorageWithPrerequisiteResult(actions, prerequisiteResult);
|
|
131
|
+
handleErr(
|
|
132
|
+
new Err({
|
|
133
|
+
nextStatus: 'failed',
|
|
134
|
+
nextStepStatus: 'failed',
|
|
135
|
+
message:
|
|
136
|
+
'Unexpected Error: xrpl change trustline transaction failed!',
|
|
137
|
+
details: undefined,
|
|
138
|
+
errorCode: 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
139
|
+
})
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
} catch {
|
|
143
|
+
await retryAfterDelay();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { checkXrplTrustLineTransactionStatus } from './checkXrplTrustlineTransactionStatus';
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SwapActionTypes,
|
|
3
|
+
SwapQueueContext,
|
|
4
|
+
SwapStorage,
|
|
5
|
+
} from '../../types';
|
|
6
|
+
import type { NextTransactionStateError } from '../common/produceNextStateForTransaction';
|
|
7
|
+
import type { ExecuterActions } from '@rango-dev/queue-manager-core';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
type GenericSigner,
|
|
11
|
+
type StellarTransaction,
|
|
12
|
+
TransactionType,
|
|
13
|
+
} from 'rango-types';
|
|
14
|
+
import { Err } from 'ts-results';
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
getCurrentStep,
|
|
18
|
+
getCurrentStepTx,
|
|
19
|
+
handleRejectedSign,
|
|
20
|
+
handleSuccessfulSign,
|
|
21
|
+
} from '../../helpers';
|
|
22
|
+
import { getCurrentAddressOf } from '../../shared';
|
|
23
|
+
import {
|
|
24
|
+
ensureRequiredStellarWalletIsConnected,
|
|
25
|
+
ensureStellarNamespaceExists,
|
|
26
|
+
getStellarWalletFromSwap,
|
|
27
|
+
} from '../checkStellarTrustline';
|
|
28
|
+
import {
|
|
29
|
+
onNextStateError,
|
|
30
|
+
onNextStateOk,
|
|
31
|
+
produceNextStateForTransaction,
|
|
32
|
+
} from '../common/produceNextStateForTransaction';
|
|
33
|
+
import { requestBlockQueue } from '../common/utils';
|
|
34
|
+
|
|
35
|
+
import { ensureStellarTransactionIsValid } from './helpers';
|
|
36
|
+
|
|
37
|
+
export async function executeStellarTransaction(
|
|
38
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>
|
|
39
|
+
): Promise<void> {
|
|
40
|
+
const { failed, getStorage, context } = actions;
|
|
41
|
+
const { meta, getSigners } = context;
|
|
42
|
+
|
|
43
|
+
const onFinish = () => {
|
|
44
|
+
if (actions.context.resetClaimedBy) {
|
|
45
|
+
actions.context.resetClaimedBy();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const handleErr = (err: Err<NextTransactionStateError>) => {
|
|
50
|
+
onNextStateError(actions, err.val);
|
|
51
|
+
failed();
|
|
52
|
+
onFinish();
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
*
|
|
57
|
+
* 1. Ensure transaction is available.
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
60
|
+
const swap = getStorage().swapDetails;
|
|
61
|
+
const currentStep = getCurrentStep(swap)!;
|
|
62
|
+
const currentTransactionFromStorage = getCurrentStepTx(currentStep);
|
|
63
|
+
|
|
64
|
+
const transaction = await ensureStellarTransactionIsValid(
|
|
65
|
+
currentTransactionFromStorage
|
|
66
|
+
);
|
|
67
|
+
if (transaction.err) {
|
|
68
|
+
handleErr(transaction);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/*
|
|
73
|
+
*
|
|
74
|
+
* 2. Ensure wallet is connected with a correct address.
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
const stellarWallet = getStellarWalletFromSwap(swap);
|
|
78
|
+
if (!stellarWallet) {
|
|
79
|
+
handleErr(
|
|
80
|
+
new Err({
|
|
81
|
+
nextStatus: 'failed',
|
|
82
|
+
nextStepStatus: 'failed',
|
|
83
|
+
message: 'Unexpected Error: Stellar wallet was not found in the swap!',
|
|
84
|
+
details: undefined,
|
|
85
|
+
errorCode: 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const namespace = await ensureStellarNamespaceExists(
|
|
92
|
+
context,
|
|
93
|
+
stellarWallet.type
|
|
94
|
+
);
|
|
95
|
+
if (namespace.err) {
|
|
96
|
+
handleErr(namespace);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const ensureRequiredStellarWalletIsConnectedResult =
|
|
101
|
+
await ensureRequiredStellarWalletIsConnected(actions, stellarWallet);
|
|
102
|
+
|
|
103
|
+
if (ensureRequiredStellarWalletIsConnectedResult.err) {
|
|
104
|
+
requestBlockQueue(
|
|
105
|
+
actions,
|
|
106
|
+
ensureRequiredStellarWalletIsConnectedResult.val
|
|
107
|
+
);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const walletAddress = getCurrentAddressOf(swap, currentStep);
|
|
112
|
+
|
|
113
|
+
/*
|
|
114
|
+
* Checking the current transaction state to determine the next step.
|
|
115
|
+
* It will either be Err, indicating process should stop, or Ok, indicating process should continue.
|
|
116
|
+
*/
|
|
117
|
+
const nextStateResult = produceNextStateForTransaction(actions);
|
|
118
|
+
|
|
119
|
+
if (nextStateResult.err) {
|
|
120
|
+
handleErr(nextStateResult);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// On success, we should update Swap object and also call notifier
|
|
125
|
+
onNextStateOk(actions, nextStateResult.val);
|
|
126
|
+
|
|
127
|
+
/*
|
|
128
|
+
*
|
|
129
|
+
* 3. Execute transaction
|
|
130
|
+
*
|
|
131
|
+
*/
|
|
132
|
+
const chainId = meta.blockchains['Stellar']?.chainId;
|
|
133
|
+
let signer: GenericSigner<StellarTransaction>;
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
const walletSigners = await getSigners(stellarWallet.type);
|
|
137
|
+
signer = walletSigners.getSigner(TransactionType.STELLAR);
|
|
138
|
+
} catch {
|
|
139
|
+
handleErr(
|
|
140
|
+
new Err({
|
|
141
|
+
nextStatus: 'failed',
|
|
142
|
+
nextStepStatus: 'failed',
|
|
143
|
+
message:
|
|
144
|
+
'Unexpected Error: Failed to load the signer. Please refresh the page and try again.',
|
|
145
|
+
details: undefined,
|
|
146
|
+
errorCode: 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
const result = await signer.signAndSendTx(
|
|
154
|
+
transaction.val,
|
|
155
|
+
walletAddress,
|
|
156
|
+
chainId
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
handleSuccessfulSign(actions, {
|
|
160
|
+
isApproval: false,
|
|
161
|
+
})(result);
|
|
162
|
+
} catch (e) {
|
|
163
|
+
handleRejectedSign(actions)(e);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// this works as `finally` for the iterator.
|
|
167
|
+
onFinish();
|
|
168
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { NextTransactionStateError } from '../common/produceNextStateForTransaction';
|
|
2
|
+
import type { Transaction } from 'rango-sdk';
|
|
3
|
+
import type { StellarTransaction } from 'rango-types';
|
|
4
|
+
import type { Result } from 'ts-results';
|
|
5
|
+
|
|
6
|
+
import { isStellarTransaction } from 'rango-types';
|
|
7
|
+
import { Err, Ok } from 'ts-results';
|
|
8
|
+
|
|
9
|
+
// Extracting currency and account from the following format (it's a convention on rango's backend): currency-accountAddress
|
|
10
|
+
export function extractFromSymbolAddress(
|
|
11
|
+
symbolAddress: string
|
|
12
|
+
): [string, string | undefined] {
|
|
13
|
+
const [currency, account] = symbolAddress.split('-');
|
|
14
|
+
|
|
15
|
+
return [currency, account];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function ensureStellarTransactionIsValid(
|
|
19
|
+
tx: Transaction | null
|
|
20
|
+
): Promise<Result<StellarTransaction, NextTransactionStateError>> {
|
|
21
|
+
if (!tx) {
|
|
22
|
+
return new Err({
|
|
23
|
+
nextStatus: 'failed',
|
|
24
|
+
nextStepStatus: 'failed',
|
|
25
|
+
message: 'Unexpected Error: tx is null!',
|
|
26
|
+
details: undefined,
|
|
27
|
+
errorCode: 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!isStellarTransaction(tx)) {
|
|
32
|
+
return new Err({
|
|
33
|
+
nextStatus: 'failed',
|
|
34
|
+
nextStepStatus: 'failed',
|
|
35
|
+
message:
|
|
36
|
+
"Unexpected Error: Expected Stellar transaction but it doesn't match with the structure.",
|
|
37
|
+
details: undefined,
|
|
38
|
+
errorCode: 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return Ok(tx);
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { executeStellarTransaction } from './executeStellarTransaction.js';
|
|
@@ -5,8 +5,13 @@ import type {
|
|
|
5
5
|
} from '../../types';
|
|
6
6
|
import type { NextTransactionStateError } from '../common/produceNextStateForTransaction';
|
|
7
7
|
import type { ExecuterActions } from '@rango-dev/queue-manager-core';
|
|
8
|
-
|
|
9
|
-
import
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
type GenericSigner,
|
|
11
|
+
TransactionType,
|
|
12
|
+
type XrplTransaction,
|
|
13
|
+
} from 'rango-types';
|
|
14
|
+
import { Err } from 'ts-results';
|
|
10
15
|
|
|
11
16
|
import {
|
|
12
17
|
getCurrentStep,
|
|
@@ -14,12 +19,12 @@ import {
|
|
|
14
19
|
handleRejectedSign,
|
|
15
20
|
handleSuccessfulSign,
|
|
16
21
|
} from '../../helpers';
|
|
17
|
-
import { getCurrentAddressOf
|
|
22
|
+
import { getCurrentAddressOf } from '../../shared';
|
|
18
23
|
import {
|
|
24
|
+
ensureRequiredXrplWalletIsConnected,
|
|
19
25
|
ensureXrplNamespaceExists,
|
|
20
|
-
|
|
26
|
+
getXrplWalletFromSwap,
|
|
21
27
|
} from '../checkXrplTrustline';
|
|
22
|
-
import { checkEnvironmentBeforeExecuteTransaction } from '../common/checkEnvironmentBeforeExecuteTransaction';
|
|
23
28
|
import {
|
|
24
29
|
onNextStateError,
|
|
25
30
|
onNextStateOk,
|
|
@@ -27,30 +32,14 @@ import {
|
|
|
27
32
|
} from '../common/produceNextStateForTransaction';
|
|
28
33
|
import { requestBlockQueue } from '../common/utils';
|
|
29
34
|
|
|
35
|
+
import { ensureXrplTransactionIsValid } from './helpers';
|
|
36
|
+
|
|
30
37
|
export async function executeXrplTransaction(
|
|
31
38
|
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>
|
|
32
39
|
): Promise<void> {
|
|
33
|
-
/*
|
|
34
|
-
*
|
|
35
|
-
* 1. Ensure wallet is connected with a correct address.
|
|
36
|
-
*
|
|
37
|
-
*/
|
|
38
|
-
const checkResult = await checkEnvironmentBeforeExecuteTransaction(actions);
|
|
39
|
-
if (checkResult.err) {
|
|
40
|
-
requestBlockQueue(actions, checkResult.val);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
40
|
const { failed, getStorage, context } = actions;
|
|
45
41
|
const { meta, getSigners } = context;
|
|
46
42
|
|
|
47
|
-
const swap = getStorage().swapDetails;
|
|
48
|
-
const currentStep = getCurrentStep(swap)!;
|
|
49
|
-
const currentTransactionFromStorage = getCurrentStepTx(currentStep);
|
|
50
|
-
|
|
51
|
-
const sourceWallet = getRelatedWallet(swap, currentStep);
|
|
52
|
-
const walletAddress = getCurrentAddressOf(swap, currentStep);
|
|
53
|
-
|
|
54
43
|
const onFinish = () => {
|
|
55
44
|
if (actions.context.resetClaimedBy) {
|
|
56
45
|
actions.context.resetClaimedBy();
|
|
@@ -64,52 +53,95 @@ export async function executeXrplTransaction(
|
|
|
64
53
|
};
|
|
65
54
|
|
|
66
55
|
/*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
56
|
+
*
|
|
57
|
+
* 1. Ensure transaction is available.
|
|
58
|
+
*
|
|
69
59
|
*/
|
|
70
|
-
const
|
|
60
|
+
const swap = getStorage().swapDetails;
|
|
61
|
+
const currentStep = getCurrentStep(swap)!;
|
|
62
|
+
const currentTransactionFromStorage = getCurrentStepTx(currentStep);
|
|
71
63
|
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
const transaction = await ensureXrplTransactionIsValid(
|
|
65
|
+
currentTransactionFromStorage
|
|
66
|
+
);
|
|
67
|
+
if (transaction.err) {
|
|
68
|
+
handleErr(transaction);
|
|
74
69
|
return;
|
|
75
70
|
}
|
|
76
71
|
|
|
77
|
-
// On success, we should update Swap object and also call notifier
|
|
78
|
-
onNextStateOk(actions, nextStateResult.val);
|
|
79
|
-
|
|
80
72
|
/*
|
|
81
73
|
*
|
|
82
|
-
* 2. Ensure
|
|
74
|
+
* 2. Ensure wallet is connected with a correct address.
|
|
83
75
|
*
|
|
84
76
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
|
|
77
|
+
|
|
78
|
+
const xrplWallet = getXrplWalletFromSwap(swap);
|
|
79
|
+
if (!xrplWallet) {
|
|
80
|
+
handleErr(
|
|
81
|
+
new Err({
|
|
82
|
+
nextStatus: 'failed',
|
|
83
|
+
nextStepStatus: 'failed',
|
|
84
|
+
message: 'Unexpected Error: Stellar wallet was not found in the swap!',
|
|
85
|
+
details: undefined,
|
|
86
|
+
errorCode: 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
87
|
+
})
|
|
88
|
+
);
|
|
90
89
|
return;
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
const namespace = await ensureXrplNamespaceExists(
|
|
94
|
-
context,
|
|
95
|
-
sourceWallet.walletType
|
|
96
|
-
);
|
|
92
|
+
const namespace = await ensureXrplNamespaceExists(context, xrplWallet.type);
|
|
97
93
|
if (namespace.err) {
|
|
98
94
|
handleErr(namespace);
|
|
99
95
|
return;
|
|
100
96
|
}
|
|
101
97
|
|
|
98
|
+
const ensureRequiredXrplWalletIsConnectedResult =
|
|
99
|
+
await ensureRequiredXrplWalletIsConnected(actions, xrplWallet);
|
|
100
|
+
|
|
101
|
+
if (ensureRequiredXrplWalletIsConnectedResult.err) {
|
|
102
|
+
requestBlockQueue(actions, ensureRequiredXrplWalletIsConnectedResult.val);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const walletAddress = getCurrentAddressOf(swap, currentStep);
|
|
107
|
+
|
|
108
|
+
/*
|
|
109
|
+
* Checking the current transaction state to determine the next step.
|
|
110
|
+
* It will either be Err, indicating process should stop, or Ok, indicating process should continue.
|
|
111
|
+
*/
|
|
112
|
+
const nextStateResult = produceNextStateForTransaction(actions);
|
|
113
|
+
|
|
114
|
+
if (nextStateResult.err) {
|
|
115
|
+
handleErr(nextStateResult);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// On success, we should update Swap object and also call notifier
|
|
120
|
+
onNextStateOk(actions, nextStateResult.val);
|
|
121
|
+
|
|
102
122
|
/*
|
|
103
123
|
*
|
|
104
124
|
* 3. Execute transaction
|
|
105
125
|
*
|
|
106
126
|
*/
|
|
107
|
-
const chainId = meta.blockchains[
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
127
|
+
const chainId = meta.blockchains['XRPL']?.chainId;
|
|
128
|
+
let signer: GenericSigner<XrplTransaction>;
|
|
129
|
+
try {
|
|
130
|
+
const walletSigners = await getSigners(xrplWallet.type);
|
|
131
|
+
signer = walletSigners.getSigner(TransactionType.XRPL);
|
|
132
|
+
} catch {
|
|
133
|
+
handleErr(
|
|
134
|
+
new Err({
|
|
135
|
+
nextStatus: 'failed',
|
|
136
|
+
nextStepStatus: 'failed',
|
|
137
|
+
message:
|
|
138
|
+
'Unexpected Error: Failed to load the signer. Please refresh the page and try again.',
|
|
139
|
+
details: undefined,
|
|
140
|
+
errorCode: 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
141
|
+
})
|
|
142
|
+
);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
113
145
|
|
|
114
146
|
try {
|
|
115
147
|
const result = await signer.signAndSendTx(
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import type { NextTransactionStateError } from '../common/produceNextStateForTransaction';
|
|
2
|
+
import type { Transaction } from 'rango-sdk';
|
|
3
|
+
import type { XrplTransaction } from 'rango-types';
|
|
4
|
+
import type { Result } from 'ts-results';
|
|
5
|
+
|
|
6
|
+
import { isXrplTransaction } from 'rango-types';
|
|
7
|
+
import { Err, Ok } from 'ts-results';
|
|
8
|
+
|
|
1
9
|
// Extracting currency and account from the following format (it's a convention on rango's backend): currency-accountAddress
|
|
2
10
|
export function extractFromSymbolAddress(
|
|
3
11
|
symbolAddress: string
|
|
@@ -6,3 +14,41 @@ export function extractFromSymbolAddress(
|
|
|
6
14
|
|
|
7
15
|
return [currency, account];
|
|
8
16
|
}
|
|
17
|
+
|
|
18
|
+
export async function ensureXrplTransactionIsValid(
|
|
19
|
+
tx: Transaction | null
|
|
20
|
+
): Promise<Result<XrplTransaction, NextTransactionStateError>> {
|
|
21
|
+
if (!tx) {
|
|
22
|
+
return new Err({
|
|
23
|
+
nextStatus: 'failed',
|
|
24
|
+
nextStepStatus: 'failed',
|
|
25
|
+
message: 'Unexpected Error: tx is null!',
|
|
26
|
+
details: undefined,
|
|
27
|
+
errorCode: 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!isXrplTransaction(tx)) {
|
|
32
|
+
return new Err({
|
|
33
|
+
nextStatus: 'failed',
|
|
34
|
+
nextStepStatus: 'failed',
|
|
35
|
+
message:
|
|
36
|
+
"Unexpected Error: Expected XRPL transaction but it doesn't match with the structure.",
|
|
37
|
+
details: undefined,
|
|
38
|
+
errorCode: 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (tx.data.TransactionType !== 'Payment') {
|
|
43
|
+
return new Err({
|
|
44
|
+
nextStatus: 'failed',
|
|
45
|
+
nextStepStatus: 'failed',
|
|
46
|
+
message:
|
|
47
|
+
'Unexpected Error: Only XRPL transactions with payment type are supported',
|
|
48
|
+
details: undefined,
|
|
49
|
+
errorCode: 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return Ok(tx);
|
|
54
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SwapQueueContext, SwapStorage } from '../types';
|
|
2
2
|
import type { ExecuterActions } from '@rango-dev/queue-manager-core';
|
|
3
3
|
|
|
4
|
-
import { type PendingSwapStep
|
|
4
|
+
import { type PendingSwapStep } from 'rango-types';
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
getCurrentStep,
|
|
@@ -38,11 +38,7 @@ export function scheduleNextStep({
|
|
|
38
38
|
|
|
39
39
|
if (!!currentStep && !isFailed) {
|
|
40
40
|
if (isTxAlreadyCreated(swap, currentStep)) {
|
|
41
|
-
|
|
42
|
-
schedule(SwapActionTypes.CHECK_XRPL_TRUSTLINE);
|
|
43
|
-
} else {
|
|
44
|
-
schedule(SwapActionTypes.EXECUTE_TRANSACTION);
|
|
45
|
-
}
|
|
41
|
+
schedule(SwapActionTypes.CHECK_PREREQUISITES);
|
|
46
42
|
return next();
|
|
47
43
|
}
|
|
48
44
|
|
package/src/helpers.ts
CHANGED
|
@@ -39,6 +39,7 @@ import type {
|
|
|
39
39
|
PendingSwapStep,
|
|
40
40
|
SignerErrorCode,
|
|
41
41
|
StepStatus,
|
|
42
|
+
SwapStepStatus,
|
|
42
43
|
} from 'rango-types';
|
|
43
44
|
|
|
44
45
|
import { warn } from '@rango-dev/logging-core';
|
|
@@ -55,6 +56,7 @@ import {
|
|
|
55
56
|
TransactionType,
|
|
56
57
|
} from 'rango-types';
|
|
57
58
|
|
|
59
|
+
import { matchesPrerequisiteKey } from './actions/checkPrerequisites/utils';
|
|
58
60
|
import {
|
|
59
61
|
DEFAULT_ERROR_CODE,
|
|
60
62
|
ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK,
|
|
@@ -170,6 +172,7 @@ export const getCurrentStepTx = (
|
|
|
170
172
|
transferTransaction,
|
|
171
173
|
starknetApprovalTransaction,
|
|
172
174
|
starknetTransaction,
|
|
175
|
+
stellarTransaction,
|
|
173
176
|
tronApprovalTransaction,
|
|
174
177
|
tronTransaction,
|
|
175
178
|
tonTransaction,
|
|
@@ -184,6 +187,7 @@ export const getCurrentStepTx = (
|
|
|
184
187
|
transferTransaction ||
|
|
185
188
|
starknetApprovalTransaction ||
|
|
186
189
|
starknetTransaction ||
|
|
190
|
+
stellarTransaction ||
|
|
187
191
|
tronApprovalTransaction ||
|
|
188
192
|
tronTransaction ||
|
|
189
193
|
tonTransaction ||
|
|
@@ -784,6 +788,7 @@ export const isTxAlreadyCreated = (
|
|
|
784
788
|
swap.wallets[step.solanaTransaction?.blockChain || ''] ||
|
|
785
789
|
swap.wallets[step.tonTransaction?.blockChain || ''] ||
|
|
786
790
|
swap.wallets[step.suiTransaction?.blockChain || ''] ||
|
|
791
|
+
swap.wallets[step.stellarTransaction?.blockChain || ''] ||
|
|
787
792
|
swap.wallets[step.xrplTransaction?.blockChain || ''] ||
|
|
788
793
|
step.transferTransaction?.fromWalletAddress ||
|
|
789
794
|
null;
|
|
@@ -1067,6 +1072,30 @@ export function isRequiredWalletConnected(
|
|
|
1067
1072
|
return { ok: matched, reason: 'account_miss_match' };
|
|
1068
1073
|
}
|
|
1069
1074
|
|
|
1075
|
+
export function updateStorageWithPrerequisiteResult(
|
|
1076
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>,
|
|
1077
|
+
prerequisiteResult: SwapStepStatus['prerequisiteResults'][number]
|
|
1078
|
+
) {
|
|
1079
|
+
const { getStorage, setStorage } = actions;
|
|
1080
|
+
const swap = getStorage().swapDetails;
|
|
1081
|
+
const currentStep = getCurrentStep(swap)!;
|
|
1082
|
+
|
|
1083
|
+
const index = currentStep.prerequisiteResults.findIndex((existing) =>
|
|
1084
|
+
matchesPrerequisiteKey(existing, prerequisiteResult)
|
|
1085
|
+
);
|
|
1086
|
+
|
|
1087
|
+
if (index >= 0) {
|
|
1088
|
+
currentStep.prerequisiteResults[index] = prerequisiteResult;
|
|
1089
|
+
} else {
|
|
1090
|
+
currentStep.prerequisiteResults.push(prerequisiteResult);
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
setStorage({
|
|
1094
|
+
...getStorage(),
|
|
1095
|
+
swapDetails: swap,
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1070
1099
|
export function updateStorageOnSuccessfulSign(
|
|
1071
1100
|
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>,
|
|
1072
1101
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|