@relayprotocol/relay-sdk 5.2.2 → 5.2.3
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/_cjs/src/utils/prepareBatchTransaction.js +26 -20
- package/_cjs/src/utils/prepareBatchTransaction.js.map +1 -1
- package/_cjs/src/version.js +1 -1
- package/_cjs/tsconfig.build.tsbuildinfo +1 -1
- package/_esm/src/utils/prepareBatchTransaction.js +49 -21
- package/_esm/src/utils/prepareBatchTransaction.js.map +1 -1
- package/_esm/src/version.js +1 -1
- package/_esm/tsconfig.build.tsbuildinfo +1 -1
- package/_types/src/utils/prepareBatchTransaction.d.ts +22 -0
- package/_types/src/utils/prepareBatchTransaction.d.ts.map +1 -1
- package/_types/src/version.d.ts +1 -1
- package/_types/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,30 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true when the step sequence can be collapsed into a single atomic
|
|
3
|
+
* batch transaction.
|
|
4
|
+
*
|
|
5
|
+
* Supported shapes:
|
|
6
|
+
* [approve, swap | deposit] // standard 2-step flow
|
|
7
|
+
* [approve, approve, swap | deposit] // zero-reset flow (e.g. USDT on Ethereum)
|
|
8
|
+
* [approve, ..., approve, swap | deposit] // N leading approvals + terminal
|
|
9
|
+
*
|
|
10
|
+
* Every item in every step must be incomplete — any already-executed item
|
|
11
|
+
* means we're in the middle of a partial run and should not re-batch.
|
|
12
|
+
*/
|
|
1
13
|
export function canBatchTransactions(steps) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
if (!steps || steps.length < 2)
|
|
15
|
+
return false;
|
|
16
|
+
const terminalStep = steps[steps.length - 1];
|
|
17
|
+
const prefixSteps = steps.slice(0, -1);
|
|
18
|
+
const terminalIsSwapOrDeposit = terminalStep?.id === 'swap' || terminalStep?.id === 'deposit';
|
|
19
|
+
if (!terminalIsSwapOrDeposit)
|
|
20
|
+
return false;
|
|
21
|
+
const prefixAllApprovals = prefixSteps.every((step) => step?.id === 'approve');
|
|
22
|
+
if (!prefixAllApprovals)
|
|
23
|
+
return false;
|
|
24
|
+
const allStepsHaveIncomplete = steps.every((step) => step?.items?.some((item) => item.status === 'incomplete'));
|
|
25
|
+
return allStepsHaveIncomplete;
|
|
10
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Flattens N approval steps + terminal (swap|deposit) step into a single
|
|
29
|
+
* batched step whose items will be submitted together via EIP-5792
|
|
30
|
+
* `wallet_sendCalls`.
|
|
31
|
+
*
|
|
32
|
+
* The first item stays `incomplete` so the executeSteps iterator picks it as
|
|
33
|
+
* the active step item; all subsequent items are pre-marked `complete` so the
|
|
34
|
+
* iterator doesn't try to execute them again as separate transactions after
|
|
35
|
+
* the batch lands.
|
|
36
|
+
*/
|
|
11
37
|
export function prepareBatchTransaction(steps) {
|
|
12
|
-
const
|
|
38
|
+
const terminalStep = steps[steps.length - 1];
|
|
39
|
+
const terminalId = terminalStep?.id; // deposit or swap
|
|
40
|
+
const allItems = steps.flatMap((step) => step.items || []);
|
|
41
|
+
const batchedItems = allItems.map((item, index) => {
|
|
42
|
+
if (index === 0)
|
|
43
|
+
return item;
|
|
44
|
+
// mark non-leading items as complete so we only fire the batch once
|
|
45
|
+
item.status = 'complete';
|
|
46
|
+
item.progressState = 'complete';
|
|
47
|
+
return item;
|
|
48
|
+
});
|
|
13
49
|
const batchedStep = {
|
|
14
|
-
id: `approve-and-${
|
|
50
|
+
id: `approve-and-${terminalId}`,
|
|
15
51
|
action: 'Confirm transaction in your wallet',
|
|
16
|
-
description: `Batching approval and ${
|
|
52
|
+
description: `Batching approval and ${terminalId} transactions`,
|
|
17
53
|
kind: 'transaction',
|
|
18
|
-
items:
|
|
19
|
-
|
|
20
|
-
...(steps[1].items || []).map((item) => {
|
|
21
|
-
// mark the second step as complete
|
|
22
|
-
item.status = 'complete';
|
|
23
|
-
item.progressState = 'complete';
|
|
24
|
-
return item;
|
|
25
|
-
})
|
|
26
|
-
],
|
|
27
|
-
requestId: steps[1].requestId ?? steps[0].requestId
|
|
54
|
+
items: batchedItems,
|
|
55
|
+
requestId: terminalStep?.requestId ?? steps[0]?.requestId
|
|
28
56
|
};
|
|
29
57
|
return batchedStep;
|
|
30
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareBatchTransaction.js","sourceRoot":"","sources":["../../../src/utils/prepareBatchTransaction.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,oBAAoB,CAAC,KAAuB;IAC1D,
|
|
1
|
+
{"version":3,"file":"prepareBatchTransaction.js","sourceRoot":"","sources":["../../../src/utils/prepareBatchTransaction.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAuB;IAC1D,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAA;IAE5C,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAC5C,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAEtC,MAAM,uBAAuB,GAC3B,YAAY,EAAE,EAAE,KAAK,MAAM,IAAI,YAAY,EAAE,EAAE,KAAK,SAAS,CAAA;IAC/D,IAAI,CAAC,uBAAuB;QAAE,OAAO,KAAK,CAAA;IAE1C,MAAM,kBAAkB,GAAG,WAAW,CAAC,KAAK,CAC1C,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,KAAK,SAAS,CACjC,CAAA;IACD,IAAI,CAAC,kBAAkB;QAAE,OAAO,KAAK,CAAA;IAErC,MAAM,sBAAsB,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAClD,I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