@rabby-wallet/rabby-action 0.1.0 → 0.1.1-beta.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.
Files changed (75) hide show
  1. package/dist/actions/approveNFT/fetchData.js +0 -3
  2. package/dist/actions/approveNFT/formatSecurityEngine.js +0 -3
  3. package/dist/actions/approveNFTCollection/fetchData.js +0 -3
  4. package/dist/actions/approveNFTCollection/formatSecurityEngine.js +0 -3
  5. package/dist/actions/approveNFTCollection/parseAction.d.ts +1 -1
  6. package/dist/actions/approveToken/formatSecurityEngine.js +0 -3
  7. package/dist/actions/approveToken/parseAction.d.ts +1 -1
  8. package/dist/actions/assetOrder/fetchData.js +1 -0
  9. package/dist/actions/assetOrder/formatSecurityEngine.js +0 -3
  10. package/dist/actions/assetOrder/parseAction.d.ts +1 -1
  11. package/dist/actions/cancelTx/fetchData.js +1 -4
  12. package/dist/actions/cancelTx/parseAction.d.ts +1 -1
  13. package/dist/actions/cancelTx/parseAction.js +2 -2
  14. package/dist/actions/common/formatSecurityEngine.js +2 -5
  15. package/dist/actions/common/parseAction.js +1 -1
  16. package/dist/actions/contractCall/formatSecurityEngine.js +0 -3
  17. package/dist/actions/crossSwapToken/fetchData.js +0 -3
  18. package/dist/actions/crossSwapToken/formatSecurityEngine.js +0 -3
  19. package/dist/actions/crossSwapToken/parseAction.d.ts +1 -1
  20. package/dist/actions/crossToken/fetchData.js +0 -3
  21. package/dist/actions/crossToken/parseAction.d.ts +1 -1
  22. package/dist/actions/deployContract/parseAction.d.ts +1 -1
  23. package/dist/actions/multiSwap/fetchData.d.ts +2 -0
  24. package/dist/actions/multiSwap/fetchData.js +16 -0
  25. package/dist/actions/multiSwap/formatSecurityEngine.d.ts +2 -0
  26. package/dist/actions/multiSwap/formatSecurityEngine.js +25 -0
  27. package/dist/actions/multiSwap/parseAction.d.ts +2 -0
  28. package/dist/actions/multiSwap/parseAction.js +14 -0
  29. package/dist/actions/permit2BatchRevokeToken/fetchData.js +0 -3
  30. package/dist/actions/permit2BatchRevokeToken/parseAction.d.ts +1 -1
  31. package/dist/actions/pushMultiSig/fetchData.js +0 -3
  32. package/dist/actions/pushMultiSig/parseAction.d.ts +1 -1
  33. package/dist/actions/revokeNFT/fetchData.js +0 -3
  34. package/dist/actions/revokeNFT/parseAction.d.ts +1 -1
  35. package/dist/actions/revokeNFTCollection/parseAction.d.ts +1 -1
  36. package/dist/actions/revokePermit2/fetchData.js +0 -3
  37. package/dist/actions/revokePermit2/parseAction.d.ts +1 -1
  38. package/dist/actions/revokeToken/fetchData.js +0 -3
  39. package/dist/actions/revokeToken/formatSecurityEngine.js +1 -4
  40. package/dist/actions/revokeToken/parseAction.d.ts +1 -1
  41. package/dist/actions/send/formatSecurityEngine.js +0 -3
  42. package/dist/actions/sendNFT/fetchData.js +0 -3
  43. package/dist/actions/sendNFT/formatSecurityEngine.js +0 -3
  44. package/dist/actions/sendNFT/parseAction.d.ts +1 -1
  45. package/dist/actions/swap/fetchData.js +9 -3
  46. package/dist/actions/swap/formatSecurityEngine.js +0 -3
  47. package/dist/actions/swap/parseAction.d.ts +1 -1
  48. package/dist/actions/swap/parseAction.js +6 -6
  49. package/dist/actions/swapLimitPay/fetchData.d.ts +2 -0
  50. package/dist/actions/swapLimitPay/fetchData.js +16 -0
  51. package/dist/actions/swapLimitPay/formatSecurityEngine.d.ts +2 -0
  52. package/dist/actions/swapLimitPay/formatSecurityEngine.js +25 -0
  53. package/dist/actions/swapLimitPay/parseAction.d.ts +2 -0
  54. package/dist/actions/swapLimitPay/parseAction.js +14 -0
  55. package/dist/actions/transferOwner/fetchData.d.ts +2 -0
  56. package/dist/actions/transferOwner/fetchData.js +82 -0
  57. package/dist/actions/transferOwner/formatSecurityEngine.d.ts +2 -0
  58. package/dist/actions/transferOwner/formatSecurityEngine.js +22 -0
  59. package/dist/actions/transferOwner/parseAction.d.ts +2 -0
  60. package/dist/actions/transferOwner/parseAction.js +14 -0
  61. package/dist/actions/unwrapToken/fetchData.js +0 -3
  62. package/dist/actions/unwrapToken/formatSecurityEngine.js +0 -3
  63. package/dist/actions/unwrapToken/parseAction.d.ts +1 -1
  64. package/dist/actions/wrapToken/fetchData.js +0 -3
  65. package/dist/actions/wrapToken/formatSecurityEngine.js +0 -3
  66. package/dist/actions/wrapToken/parseAction.d.ts +1 -1
  67. package/dist/fetchActionRequiredData.js +11 -1
  68. package/dist/formatSecurityEngineContext.js +7 -1
  69. package/dist/parseAction.js +17 -3
  70. package/dist/types/actionRequireData.d.ts +3 -0
  71. package/dist/types/fetchActionRequiredData.d.ts +6 -4
  72. package/dist/types/formatSecurityEngineContext.d.ts +13 -19
  73. package/dist/types/parseAction.d.ts +9 -2
  74. package/dist/types/parsedActionData.d.ts +20 -5
  75. package/package.json +3 -3
@@ -10,9 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import PQueue from 'p-queue';
11
11
  import { waitQueueFinished } from '../../utils/waitQueueFinished';
12
12
  export const fetchDataApproveNFT = (options, likeAction) => __awaiter(void 0, void 0, void 0, function* () {
13
- if (options.type !== 'transaction') {
14
- return {};
15
- }
16
13
  const queue = new PQueue();
17
14
  const { sender, apiProvider, chainId, actionData } = options;
18
15
  const action = likeAction || actionData.approveNFT;
@@ -8,9 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export const formatSecurityEngineApproveNFT = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
- if (options.type !== 'transaction' && options.type !== 'typed_data') {
12
- return {};
13
- }
14
11
  const { actionData, requireData, chainId, provider } = options;
15
12
  if (!actionData.approveNFT || !chainId) {
16
13
  return {};
@@ -9,9 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { fetchDataApproveNFT } from '../approveNFT/fetchData';
11
11
  export const fetchDataApproveNFTCollection = (options) => __awaiter(void 0, void 0, void 0, function* () {
12
- if (options.type !== 'transaction') {
13
- return {};
14
- }
15
12
  if (!options.actionData.approveNFTCollection) {
16
13
  return {};
17
14
  }
@@ -8,9 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export const formatSecurityEngineApproveNFTCollection = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
- if (options.type !== 'transaction') {
12
- return {};
13
- }
14
11
  const { actionData, requireData, chainId, provider } = options;
15
12
  if (!actionData.approveNFTCollection || !chainId) {
16
13
  return {};
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionApproveNFTCollection: ParseAction<'transaction'>;
2
+ export declare const parseActionApproveNFTCollection: ParseAction;
@@ -8,9 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export const formatSecurityEngineApproveToken = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
- if (options.type !== 'transaction') {
12
- return {};
13
- }
14
11
  const { actionData, requireData, chainId, provider } = options;
15
12
  if (!actionData.approveToken || !chainId) {
16
13
  return {};
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionApproveToken: ParseAction<'transaction'>;
2
+ export declare const parseActionApproveToken: ParseAction;
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { fetchDataCommon } from '../common/fetchData';
11
+ // TODO: text action not supported
11
12
  export const fetchDataAssetOrder = (options) => __awaiter(void 0, void 0, void 0, function* () {
12
13
  let action;
13
14
  if (options.type === 'transaction' && options.actionData.assetOrder) {
@@ -8,9 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export const formatSecurityEngineAssetOrder = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
- if (options.type !== 'transaction' && options.type !== 'typed_data') {
12
- return {};
13
- }
14
11
  const { actionData, requireData, chainId, provider } = options;
15
12
  if (!actionData.assetOrder) {
16
13
  return {};
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionAssetOrder: ParseAction<'transaction' | 'typed_data'>;
2
+ export declare const parseActionAssetOrder: ParseAction;
@@ -8,9 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export const fetchDataCancelTx = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
- if (options.type !== 'transaction') {
12
- return {};
13
- }
14
11
  const { walletProvider, actionData, chainId, sender } = options;
15
12
  if (!actionData.cancelTx) {
16
13
  return {};
@@ -18,7 +15,7 @@ export const fetchDataCancelTx = (options) => __awaiter(void 0, void 0, void 0,
18
15
  const chain = walletProvider.findChain({
19
16
  serverId: chainId,
20
17
  });
21
- if (chain) {
18
+ if (chain && actionData.cancelTx.nonce !== undefined) {
22
19
  const pendingTxs = yield walletProvider.getPendingTxsByNonce(sender, chain.id, Number(actionData.cancelTx.nonce));
23
20
  return {
24
21
  pendingTxs,
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionCancelTx: ParseAction<'transaction'>;
2
+ export declare const parseActionCancelTx: ParseAction;
@@ -1,11 +1,11 @@
1
1
  export const parseActionCancelTx = (options) => {
2
- const { tx, data } = options;
2
+ const { data } = options;
3
3
  if ((data === null || data === void 0 ? void 0 : data.type) !== 'cancel_tx') {
4
4
  return {};
5
5
  }
6
6
  return {
7
7
  cancelTx: {
8
- nonce: tx.nonce,
8
+ nonce: options.type === 'transaction' ? options.tx.nonce : undefined,
9
9
  },
10
10
  };
11
11
  };
@@ -8,14 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export const formatSecurityEngineCommon = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
- if (options.type === 'text') {
12
- return {};
13
- }
11
+ var _a;
14
12
  if (!options.actionData.common) {
15
13
  return {};
16
14
  }
17
15
  return {
18
- common: Object.assign(Object.assign({}, options.actionData.common), { receiverInWallet: options.requireData
19
- .receiverInWallet }),
16
+ common: Object.assign(Object.assign({}, options.actionData.common), { receiverInWallet: (_a = options.requireData) === null || _a === void 0 ? void 0 : _a.receiverInWallet }),
20
17
  };
21
18
  });
@@ -4,7 +4,7 @@ export const parseActionCommon = (options) => {
4
4
  return {};
5
5
  }
6
6
  const from = options.type === 'transaction'
7
- ? options.tx.from
7
+ ? options.sender
8
8
  : options.type === 'text'
9
9
  ? undefined
10
10
  : options.sender;
@@ -8,9 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export const formatSecurityEngineContractCall = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
- if (options.type !== 'transaction' && options.type !== 'typed_data') {
12
- return {};
13
- }
14
11
  const { actionData, requireData, chainId, provider } = options;
15
12
  if (!actionData.contractCall || !chainId) {
16
13
  return {};
@@ -9,9 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { fetchDataSwap } from '../swap/fetchData';
11
11
  export const fetchDataCrossSwapToken = (options) => __awaiter(void 0, void 0, void 0, function* () {
12
- if (options.type !== 'transaction') {
13
- return {};
14
- }
15
12
  if (!options.actionData.crossSwapToken) {
16
13
  return {};
17
14
  }
@@ -8,9 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export const formatSecurityEngineCrossSwapToken = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
- if (options.type !== 'transaction') {
12
- return {};
13
- }
14
11
  const { actionData, requireData, chainId, provider } = options;
15
12
  if (!actionData.crossSwapToken) {
16
13
  return {};
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionCrossSwapToken: ParseAction<'transaction'>;
2
+ export declare const parseActionCrossSwapToken: ParseAction;
@@ -9,9 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { fetchDataSwap } from '../swap/fetchData';
11
11
  export const fetchDataCrossToken = (options) => __awaiter(void 0, void 0, void 0, function* () {
12
- if (options.type !== 'transaction') {
13
- return {};
14
- }
15
12
  if (!options.actionData.crossToken) {
16
13
  return {};
17
14
  }
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionCrossToken: ParseAction<'transaction'>;
2
+ export declare const parseActionCrossToken: ParseAction;
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionDeployContract: ParseAction<'transaction'>;
2
+ export declare const parseActionDeployContract: ParseAction;
@@ -0,0 +1,2 @@
1
+ import { FetchActionRequiredData } from '../../types';
2
+ export declare const fetchDataMultiSwap: FetchActionRequiredData;
@@ -0,0 +1,16 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { fetchDataSwap } from '../swap/fetchData';
11
+ export const fetchDataMultiSwap = (options) => __awaiter(void 0, void 0, void 0, function* () {
12
+ if (!options.actionData.multiSwap) {
13
+ return {};
14
+ }
15
+ return fetchDataSwap(options, options.actionData.multiSwap);
16
+ });
@@ -0,0 +1,2 @@
1
+ import { FormatSecurityEngineContext } from '../../types';
2
+ export declare const formatSecurityEngineMultiSwap: FormatSecurityEngineContext;
@@ -0,0 +1,25 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export const formatSecurityEngineMultiSwap = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
+ const { actionData, requireData, chainId } = options;
12
+ if (!actionData.multiSwap) {
13
+ return {};
14
+ }
15
+ const { receiver } = actionData.multiSwap;
16
+ const data = requireData;
17
+ return {
18
+ multiSwap: {
19
+ from: data.sender,
20
+ receiver: receiver || '',
21
+ chainId,
22
+ id: data.id,
23
+ },
24
+ };
25
+ });
@@ -0,0 +1,2 @@
1
+ import { ParseAction } from '../../types';
2
+ export declare const parseActionMultiSwap: ParseAction;
@@ -0,0 +1,14 @@
1
+ export const parseActionMultiSwap = (options) => {
2
+ const { data } = options;
3
+ if ((data === null || data === void 0 ? void 0 : data.type) !== 'multi_swap_token') {
4
+ return {};
5
+ }
6
+ const { pay_token_list: payTokenList, receive_token_list: receiveTokenList, receiver, } = data.data;
7
+ return {
8
+ multiSwap: {
9
+ payTokenList,
10
+ receiveTokenList,
11
+ receiver,
12
+ },
13
+ };
14
+ };
@@ -9,9 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { fetchDataApproveToken } from '../approveToken/fetchData';
11
11
  export const fetchDataPermit2BatchRevokeToken = (options) => __awaiter(void 0, void 0, void 0, function* () {
12
- if (options.type !== 'transaction') {
13
- return {};
14
- }
15
12
  const { actionData } = options;
16
13
  const action = actionData.permit2BatchRevokeToken;
17
14
  if (!action) {
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionPermit2BatchRevokeToken: ParseAction<'transaction'>;
2
+ export declare const parseActionPermit2BatchRevokeToken: ParseAction;
@@ -8,9 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export const fetchDataPushMultiSig = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
- if (options.type !== 'transaction') {
12
- return {};
13
- }
14
11
  const { apiProvider, actionData } = options;
15
12
  if (!actionData.pushMultiSig) {
16
13
  return {};
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionPushMultiSig: ParseAction<'transaction'>;
2
+ export declare const parseActionPushMultiSig: ParseAction;
@@ -9,9 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { fetchDataApproveNFT } from '../approveNFT/fetchData';
11
11
  export const fetchDataRevokeNFT = (options) => __awaiter(void 0, void 0, void 0, function* () {
12
- if (options.type !== 'transaction') {
13
- return {};
14
- }
15
12
  if (!options.actionData.revokeNFT) {
16
13
  return {};
17
14
  }
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionRevokeNFT: ParseAction<'transaction'>;
2
+ export declare const parseActionRevokeNFT: ParseAction;
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionRevokeNFTCollection: ParseAction<'transaction'>;
2
+ export declare const parseActionRevokeNFTCollection: ParseAction;
@@ -9,9 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { fetchDataApproveToken } from '../approveToken/fetchData';
11
11
  export const fetchDataRevokePermit2 = (options) => __awaiter(void 0, void 0, void 0, function* () {
12
- if (options.type !== 'transaction') {
13
- return {};
14
- }
15
12
  if (!options.actionData.revokePermit2) {
16
13
  return {};
17
14
  }
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionRevokePermit2: ParseAction<'transaction'>;
2
+ export declare const parseActionRevokePermit2: ParseAction;
@@ -9,9 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { fetchDataApproveToken } from '../approveToken/fetchData';
11
11
  export const fetchDataRevokeToken = (options) => __awaiter(void 0, void 0, void 0, function* () {
12
- if (options.type !== 'transaction') {
13
- return {};
14
- }
15
12
  if (!options.actionData.revokeToken) {
16
13
  return {};
17
14
  }
@@ -8,9 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export const formatSecurityEngineRevokeToken = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
- if (options.type !== 'transaction') {
12
- return {};
13
- }
14
11
  const { actionData, requireData, chainId, provider } = options;
15
12
  if (!actionData.revokeToken) {
16
13
  return {};
@@ -18,7 +15,7 @@ export const formatSecurityEngineRevokeToken = (options) => __awaiter(void 0, vo
18
15
  const { gasUsed } = actionData.revokeToken;
19
16
  return {
20
17
  revokeApprove: {
21
- gasUsed,
18
+ gasUsed: gasUsed || 0,
22
19
  chainId,
23
20
  },
24
21
  };
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionRevokeToken: ParseAction<'transaction'>;
2
+ export declare const parseActionRevokeToken: ParseAction;
@@ -8,9 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export const formatSecurityEngineSend = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
- if (options.type !== 'transaction' && options.type !== 'typed_data') {
12
- return {};
13
- }
14
11
  const { actionData, requireData, chainId, provider } = options;
15
12
  if (!actionData.send || !chainId) {
16
13
  return {};
@@ -9,9 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { fetchDataSend } from '../send/fetchData';
11
11
  export const fetchDataSendNFT = (options) => __awaiter(void 0, void 0, void 0, function* () {
12
- if (options.type !== 'transaction') {
13
- return {};
14
- }
15
12
  const sendNFT = options.actionData.sendNFT;
16
13
  if (!sendNFT) {
17
14
  return {};
@@ -8,9 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export const formatSecurityEngineSendNFT = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
- if (options.type !== 'transaction') {
12
- return {};
13
- }
14
11
  const { actionData, requireData, chainId, provider } = options;
15
12
  if (!actionData.sendNFT || !chainId) {
16
13
  return {};
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionSendNFT: ParseAction<'transaction'>;
2
+ export declare const parseActionSendNFT: ParseAction;
@@ -9,19 +9,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import PQueue from 'p-queue';
11
11
  import { waitQueueFinished } from '../../utils/waitQueueFinished';
12
+ // TODO: text
12
13
  export const fetchDataSwap = (options, likeSwapAction) => __awaiter(void 0, void 0, void 0, function* () {
13
- if (options.type !== 'transaction') {
14
+ if (options.type === 'text') {
14
15
  return {};
15
16
  }
16
17
  const queue = new PQueue();
17
- const { actionData, walletProvider, tx, sender, apiProvider, chainId } = options;
18
+ const { actionData, walletProvider, sender, apiProvider, chainId } = options;
18
19
  const swapAction = likeSwapAction || actionData.swap;
19
20
  if (!swapAction) {
20
21
  return {};
21
22
  }
22
23
  const { receiver } = swapAction;
23
24
  const receiverInWallet = yield walletProvider.hasAddress(receiver);
24
- const id = tx.to;
25
+ const id = options.type === 'transaction'
26
+ ? options.tx.to
27
+ : options.actionData.contractId;
28
+ if (!id) {
29
+ return {};
30
+ }
25
31
  const result = {
26
32
  id,
27
33
  protocol: null,
@@ -8,9 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export const formatSecurityEngineSwap = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
- if (options.type !== 'transaction') {
12
- return {};
13
- }
14
11
  const { actionData, requireData, chainId, provider } = options;
15
12
  if (!actionData.swap || !chainId) {
16
13
  return {};
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionSwap: ParseAction<'transaction'>;
2
+ export declare const parseActionSwap: ParseAction;
@@ -3,21 +3,21 @@ import { calcSlippageTolerance } from '../../utils/calcSlippageTolerance';
3
3
  import { calcUSDValueChange } from '../../utils/calcUSDValueChange';
4
4
  import { isSameAddress } from '../../utils/isSameAddress';
5
5
  export const parseActionSwap = (options) => {
6
- const { data, balanceChange, preExecVersion, tx } = options;
6
+ const { data, balanceChange, preExecVersion, sender } = options;
7
7
  if ((data === null || data === void 0 ? void 0 : data.type) !== 'swap_token') {
8
8
  return {};
9
9
  }
10
10
  const { pay_token: payToken, receive_token: receiveToken, receiver, } = data.data;
11
- const balanceChangeSuccess = balanceChange.success;
11
+ const balanceChangeSuccess = balanceChange === null || balanceChange === void 0 ? void 0 : balanceChange.success;
12
12
  const supportBalanceChange = preExecVersion !== 'v0';
13
- const actualReceiveToken = balanceChange.receive_token_list.find((token) => isSameAddress(token.id, receiveToken.id));
13
+ const actualReceiveToken = balanceChange === null || balanceChange === void 0 ? void 0 : balanceChange.receive_token_list.find((token) => isSameAddress(token.id, receiveToken.id));
14
14
  const receiveTokenAmount = actualReceiveToken ? actualReceiveToken.amount : 0;
15
15
  const slippageTolerance = balanceChangeSuccess && supportBalanceChange
16
16
  ? calcSlippageTolerance(actualReceiveToken ? actualReceiveToken.raw_amount || '0' : '0', receiveToken.min_raw_amount || '0')
17
17
  : null;
18
18
  const receiveTokenUsdValue = new BigNumber(receiveTokenAmount).times(receiveToken.price);
19
19
  const payTokenUsdValue = new BigNumber(payToken.amount).times(payToken.price);
20
- const hasReceiver = !isSameAddress(receiver, tx.from);
20
+ const hasReceiver = !isSameAddress(receiver, sender);
21
21
  const usdValueDiff = hasReceiver || !balanceChangeSuccess || !supportBalanceChange
22
22
  ? null
23
23
  : receiveTokenUsdValue.minus(payTokenUsdValue).toFixed();
@@ -35,8 +35,8 @@ export const parseActionSwap = (options) => {
35
35
  usdValueDiff,
36
36
  usdValuePercentage,
37
37
  balanceChange: {
38
- success: balanceChangeSuccess,
39
- support: supportBalanceChange,
38
+ success: !!balanceChangeSuccess,
39
+ support: !!supportBalanceChange,
40
40
  },
41
41
  },
42
42
  };
@@ -0,0 +1,2 @@
1
+ import { FetchActionRequiredData } from '../../types';
2
+ export declare const fetchDataSwapLimitPay: FetchActionRequiredData;
@@ -0,0 +1,16 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { fetchDataSwap } from '../swap/fetchData';
11
+ export const fetchDataSwapLimitPay = (options) => __awaiter(void 0, void 0, void 0, function* () {
12
+ if (!options.actionData.swapLimitPay) {
13
+ return {};
14
+ }
15
+ return fetchDataSwap(options, options.actionData.swapLimitPay);
16
+ });
@@ -0,0 +1,2 @@
1
+ import { FormatSecurityEngineContext } from '../../types';
2
+ export declare const formatSecurityEngineSwapLimitPay: FormatSecurityEngineContext;
@@ -0,0 +1,25 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export const formatSecurityEngineSwapLimitPay = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
+ const { actionData, requireData, chainId } = options;
12
+ if (!actionData.swapLimitPay) {
13
+ return {};
14
+ }
15
+ const { receiver } = actionData.swapLimitPay;
16
+ const data = requireData;
17
+ return {
18
+ multiSwap: {
19
+ from: data.sender,
20
+ receiver: receiver || '',
21
+ chainId,
22
+ id: data.id,
23
+ },
24
+ };
25
+ });
@@ -0,0 +1,2 @@
1
+ import { ParseAction } from '../../types';
2
+ export declare const parseActionSwapLimitPay: ParseAction;
@@ -0,0 +1,14 @@
1
+ export const parseActionSwapLimitPay = (options) => {
2
+ const { data } = options;
3
+ if ((data === null || data === void 0 ? void 0 : data.type) !== 'swap_token_limit_pay') {
4
+ return {};
5
+ }
6
+ const { pay_token: payToken, receive_token: receiveToken, receiver, } = data.data;
7
+ return {
8
+ swapLimitPay: {
9
+ payToken,
10
+ receiveToken,
11
+ receiver,
12
+ },
13
+ };
14
+ };
@@ -0,0 +1,2 @@
1
+ import { FetchActionRequiredData } from '../../types';
2
+ export declare const fetchDataTransferOwner: FetchActionRequiredData;
@@ -0,0 +1,82 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import PQueue from 'p-queue';
11
+ import { waitQueueFinished } from '../../utils/waitQueueFinished';
12
+ export const fetchDataTransferOwner = (options) => __awaiter(void 0, void 0, void 0, function* () {
13
+ var _a;
14
+ if (!options.actionData.transferOwner) {
15
+ return {};
16
+ }
17
+ const queue = new PQueue();
18
+ const { actionData, walletProvider, apiProvider, chainId, sender } = options;
19
+ const addr = (_a = actionData.transferOwner) === null || _a === void 0 ? void 0 : _a.to;
20
+ const result = {
21
+ receiver: null,
22
+ };
23
+ if (addr) {
24
+ const chain = walletProvider.findChain({
25
+ serverId: chainId,
26
+ });
27
+ const receiverData = {
28
+ address: addr,
29
+ chain: chain,
30
+ eoa: null,
31
+ cex: null,
32
+ contract: null,
33
+ usd_value: 0,
34
+ hasTransfer: false,
35
+ isTokenContract: false,
36
+ name: null,
37
+ onTransferWhitelist: false,
38
+ };
39
+ queue.add(() => __awaiter(void 0, void 0, void 0, function* () {
40
+ const { has_transfer } = yield apiProvider.hasTransfer(chainId, sender, addr);
41
+ receiverData.hasTransfer = has_transfer;
42
+ }));
43
+ queue.add(() => __awaiter(void 0, void 0, void 0, function* () {
44
+ var _a;
45
+ const { desc } = yield apiProvider.addrDesc(addr);
46
+ if ((_a = desc.cex) === null || _a === void 0 ? void 0 : _a.id) {
47
+ receiverData.cex = {
48
+ id: desc.cex.id,
49
+ logo: desc.cex.logo_url,
50
+ name: desc.cex.name,
51
+ bornAt: desc.born_at,
52
+ isDeposit: desc.cex.is_deposit,
53
+ };
54
+ }
55
+ if (desc.contract && Object.keys(desc.contract).length > 0) {
56
+ receiverData.contract = desc.contract;
57
+ }
58
+ if (!receiverData.cex && !receiverData.contract) {
59
+ receiverData.eoa = {
60
+ id: addr,
61
+ bornAt: desc.born_at,
62
+ };
63
+ }
64
+ receiverData.usd_value = desc.usd_value;
65
+ receiverData.name = desc.name;
66
+ }));
67
+ queue.add(() => __awaiter(void 0, void 0, void 0, function* () {
68
+ if (addr) {
69
+ const { is_token } = yield apiProvider.isTokenContract(chainId, addr);
70
+ receiverData.isTokenContract = is_token;
71
+ }
72
+ if (walletProvider.ALIAS_ADDRESS[addr.toLowerCase()]) {
73
+ receiverData.name = walletProvider.ALIAS_ADDRESS[addr.toLowerCase()];
74
+ }
75
+ const whitelist = yield walletProvider.getWhitelist();
76
+ receiverData.onTransferWhitelist = whitelist.includes(addr.toLowerCase());
77
+ }));
78
+ yield waitQueueFinished(queue);
79
+ result.receiver = receiverData;
80
+ }
81
+ return result;
82
+ });
@@ -0,0 +1,2 @@
1
+ import { FormatSecurityEngineContext } from '../../types';
2
+ export declare const formatSecurityEngineTransferOwner: FormatSecurityEngineContext;
@@ -0,0 +1,22 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export const formatSecurityEngineTransferOwner = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
+ var _a;
12
+ const { actionData, requireData, chainId, provider } = options;
13
+ if (!actionData.transferOwner || !chainId) {
14
+ return {};
15
+ }
16
+ const data = requireData;
17
+ return {
18
+ transferOwner: {
19
+ receiverInWhitelist: !!((_a = data.receiver) === null || _a === void 0 ? void 0 : _a.onTransferWhitelist),
20
+ },
21
+ };
22
+ });
@@ -0,0 +1,2 @@
1
+ import { ParseAction } from '../../types';
2
+ export declare const parseActionTransferOwner: ParseAction;
@@ -0,0 +1,14 @@
1
+ export const parseActionTransferOwner = (options) => {
2
+ const { data } = options;
3
+ if ((data === null || data === void 0 ? void 0 : data.type) !== 'transfer_ownership') {
4
+ return {};
5
+ }
6
+ const { description, from_addr, to_addr } = data.data;
7
+ return {
8
+ transferOwner: {
9
+ description,
10
+ from: from_addr,
11
+ to: to_addr,
12
+ },
13
+ };
14
+ };
@@ -9,9 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { fetchDataSwap } from '../swap/fetchData';
11
11
  export const fetchDataUnwrapToken = (options) => __awaiter(void 0, void 0, void 0, function* () {
12
- if (options.type !== 'transaction') {
13
- return {};
14
- }
15
12
  if (!options.actionData.unWrapToken) {
16
13
  return {};
17
14
  }
@@ -8,9 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export const formatSecurityEngineUnwrapToken = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
- if (options.type !== 'transaction') {
12
- return {};
13
- }
14
11
  const { actionData, requireData, chainId, provider } = options;
15
12
  if (!actionData.unWrapToken || !chainId) {
16
13
  return {};
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionUnwrapToken: ParseAction<'transaction'>;
2
+ export declare const parseActionUnwrapToken: ParseAction;
@@ -9,9 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { fetchDataSwap } from '../swap/fetchData';
11
11
  export const fetchDataWrapToken = (options) => __awaiter(void 0, void 0, void 0, function* () {
12
- if (options.type !== 'transaction') {
13
- return {};
14
- }
15
12
  if (!options.actionData.wrapToken) {
16
13
  return {};
17
14
  }
@@ -8,9 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export const formatSecurityEngineWrapToken = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
- if (options.type !== 'transaction') {
12
- return {};
13
- }
14
11
  const { actionData, requireData, chainId, provider } = options;
15
12
  if (!actionData.wrapToken || !chainId) {
16
13
  return {};
@@ -1,2 +1,2 @@
1
1
  import { ParseAction } from '../../types';
2
- export declare const parseActionWrapToken: ParseAction<'transaction'>;
2
+ export declare const parseActionWrapToken: ParseAction;
@@ -43,8 +43,14 @@ import { fetchDataSellNFT } from './actions/sellNFT/fetchData';
43
43
  import { fetchDataSignMultiSig } from './actions/signMultiSig/fetchData';
44
44
  import { fetchDataSwapTokenOrder } from './actions/swapTokenOrder/fetchData';
45
45
  import { fetchDataVerifyAddress } from './actions/verifyAddress/fetchData';
46
+ import { fetchDataTransferOwner } from './actions/transferOwner/fetchData';
47
+ import { fetchDataMultiSwap } from './actions/multiSwap/fetchData';
48
+ import { fetchDataSwapLimitPay } from './actions/swapLimitPay/fetchData';
46
49
  export const fetchActionRequiredData = (options) => __awaiter(void 0, void 0, void 0, function* () {
47
50
  const result = yield Promise.all([
51
+ fetchDataTransferOwner(options),
52
+ fetchDataMultiSwap(options),
53
+ fetchDataSwapLimitPay(options),
48
54
  fetchDataApproveNFT(options),
49
55
  fetchDataApproveNFTCollection(options),
50
56
  fetchDataApproveToken(options),
@@ -83,5 +89,9 @@ export const fetchActionRequiredData = (options) => __awaiter(void 0, void 0, vo
83
89
  fetchDataCoboSafeModificationTokenApproval(options),
84
90
  fetchDataRevokePermit(options),
85
91
  ]);
86
- return result.reduce((acc, val) => (Object.assign(Object.assign({}, acc), val)), {});
92
+ const requireData = result.reduce((acc, val) => (Object.assign(Object.assign({}, acc), val)), {});
93
+ if (requireData && Object.keys(requireData).length === 0) {
94
+ return null;
95
+ }
96
+ return requireData;
87
97
  });
@@ -43,11 +43,17 @@ import { formatSecurityEngineSellNFT } from './actions/sellNFT/formatSecurityEng
43
43
  import { formatSecurityEngineSignMultiSig } from './actions/signMultiSig/formatSecurityEngine';
44
44
  import { formatSecurityEngineSwapTokenOrder } from './actions/swapTokenOrder/formatSecurityEngine';
45
45
  import { formatSecurityEngineVerifyAddress } from './actions/verifyAddress/formatSecurityEngine';
46
+ import { formatSecurityEngineTransferOwner } from './actions/transferOwner/formatSecurityEngine';
47
+ import { formatSecurityEngineMultiSwap } from './actions/multiSwap/formatSecurityEngine';
48
+ import { formatSecurityEngineSwapLimitPay } from './actions/swapLimitPay/formatSecurityEngine';
46
49
  export const formatSecurityEngineContext = (options) => __awaiter(void 0, void 0, void 0, function* () {
47
- if (options.type !== 'text' && options.isTestnet) {
50
+ if (options.isTestnet) {
48
51
  return {};
49
52
  }
50
53
  const result = yield Promise.all([
54
+ formatSecurityEngineTransferOwner(options),
55
+ formatSecurityEngineMultiSwap(options),
56
+ formatSecurityEngineSwapLimitPay(options),
51
57
  formatSecurityEngineApproveNFT(options),
52
58
  formatSecurityEngineApproveNFTCollection(options),
53
59
  formatSecurityEngineApproveToken(options),
@@ -1,3 +1,6 @@
1
+ import { parseActionSwapLimitPay } from './actions/swapLimitPay/parseAction';
2
+ import { parseActionMultiSwap } from './actions/multiSwap/parseAction';
3
+ import { parseActionTransferOwner } from './actions/transferOwner/parseAction';
1
4
  import { parseActionSend } from './actions/send/parseAction';
2
5
  import { parseActionApproveNFT } from './actions/approveNFT/parseAction';
3
6
  import { parseActionApproveNFTCollection } from './actions/approveNFTCollection/parseAction';
@@ -39,13 +42,21 @@ import { parseTextAction } from './utils/parseTextAction';
39
42
  export function parseAction(options) {
40
43
  const result = [];
41
44
  if (options.type === 'transaction') {
42
- result.push(parseActionApproveNFT(options), parseActionApproveNFTCollection(options), parseActionApproveToken(options), parseActionAssetOrder(options), parseActionCancelTx(options), parseActionCommon(options), parseActionCrossSwapToken(options), parseActionCrossToken(options), parseActionDeployContract(options), parseActionPushMultiSig(options), parseActionRevokeNFT(options), parseActionRevokeNFTCollection(options), parseActionRevokePermit2(options), parseActionRevokeToken(options), parseActionSend(options), parseActionSendNFT(options), parseActionSwap(options), parseActionUnwrapToken(options), parseActionWrapToken(options), parseActionPermit2BatchRevokeToken(options));
45
+ result.push(parseActionApproveNFT(options), parseActionApproveNFTCollection(options), parseActionApproveToken(options), parseActionAssetOrder(options), parseActionCancelTx(options), parseActionCommon(options), parseActionCrossSwapToken(options), parseActionCrossToken(options), parseActionDeployContract(options), parseActionPushMultiSig(options), parseActionRevokeNFT(options), parseActionRevokeNFTCollection(options), parseActionRevokePermit2(options), parseActionRevokeToken(options), parseActionSend(options), parseActionSendNFT(options), parseActionSwap(options), parseActionUnwrapToken(options), parseActionWrapToken(options), parseActionPermit2BatchRevokeToken(options), parseActionTransferOwner(options), parseActionSwapLimitPay(options), parseActionMultiSwap(options));
43
46
  }
44
47
  if (options.type === 'typed_data') {
45
- result.push(parseTypedDataAction(parseActionCommon)(options), parseTypedDataAction(parseActionAssetOrder)(options), parseTypedDataAction(parseActionSend)(options), parseTypedDataAction(parseActionApproveNFT)(options), parseTypedDataAction(parseActionCreateKey)(options), parseTypedDataAction(parseActionVerifyAddress)(options), parseTypedDataAction(parseActionSellNFT)(options), parseTypedDataAction(parseActionBatchSellNFT)(options), parseTypedDataAction(parseActionSignMultiSig)(options), parseTypedDataAction(parseActionBuyNFT)(options), parseTypedDataAction(parseActionPermit)(options), parseTypedDataAction(parseActionPermit2)(options), parseTypedDataAction(parseActionBatchPermit2)(options), parseTypedDataAction(parseActionSwapTokenOrder)(options), parseTypedDataAction(parseActionCoboSafeCreate)(options), parseTypedDataAction(parseActionCoboSafeModificationDelegatedAddress)(options), parseTypedDataAction(parseActionCoboSafeModificationRole)(options), parseTypedDataAction(parseActionCoboSafeModificationTokenApproval)(options), parseTypedDataAction(parseActionRevokePermit)(options));
48
+ result.push(
49
+ // tx actions
50
+ parseTypedDataAction(parseActionCommon)(options), parseTypedDataAction(parseActionAssetOrder)(options), parseTypedDataAction(parseActionSend)(options), parseTypedDataAction(parseActionApproveNFT)(options), parseTypedDataAction(parseActionApproveNFTCollection)(options), parseTypedDataAction(parseActionApproveToken)(options), parseTypedDataAction(parseActionCancelTx)(options), parseTypedDataAction(parseActionCrossSwapToken)(options), parseTypedDataAction(parseActionCrossToken)(options), parseTypedDataAction(parseActionDeployContract)(options), parseTypedDataAction(parseActionPushMultiSig)(options), parseTypedDataAction(parseActionRevokeNFT)(options), parseTypedDataAction(parseActionRevokeNFTCollection)(options), parseTypedDataAction(parseActionRevokePermit2)(options), parseTypedDataAction(parseActionRevokeToken)(options), parseTypedDataAction(parseActionSendNFT)(options), parseTypedDataAction(parseActionSwap)(options), parseTypedDataAction(parseActionUnwrapToken)(options), parseTypedDataAction(parseActionWrapToken)(options), parseTypedDataAction(parseActionPermit2BatchRevokeToken)(options), parseTypedDataAction(parseActionTransferOwner)(options), parseTypedDataAction(parseActionSwapLimitPay)(options), parseTypedDataAction(parseActionMultiSwap)(options),
51
+ // typed data actions
52
+ parseTypedDataAction(parseActionCreateKey)(options), parseTypedDataAction(parseActionVerifyAddress)(options), parseTypedDataAction(parseActionSellNFT)(options), parseTypedDataAction(parseActionBatchSellNFT)(options), parseTypedDataAction(parseActionSignMultiSig)(options), parseTypedDataAction(parseActionBuyNFT)(options), parseTypedDataAction(parseActionPermit)(options), parseTypedDataAction(parseActionPermit2)(options), parseTypedDataAction(parseActionBatchPermit2)(options), parseTypedDataAction(parseActionSwapTokenOrder)(options), parseTypedDataAction(parseActionCoboSafeCreate)(options), parseTypedDataAction(parseActionCoboSafeModificationDelegatedAddress)(options), parseTypedDataAction(parseActionCoboSafeModificationRole)(options), parseTypedDataAction(parseActionCoboSafeModificationTokenApproval)(options), parseTypedDataAction(parseActionRevokePermit)(options));
46
53
  }
47
54
  if (options.type === 'text') {
48
- result.push(parseTextAction(parseActionCommon)(options), parseTextAction(parseActionCreateKey)(options), parseTextAction(parseActionVerifyAddress)(options));
55
+ result.push(
56
+ // tx actions
57
+ parseTextAction(parseActionCommon)(options), parseTextAction(parseActionAssetOrder)(options), parseTextAction(parseActionSend)(options), parseTextAction(parseActionApproveNFT)(options), parseTextAction(parseActionApproveNFTCollection)(options), parseTextAction(parseActionApproveToken)(options), parseTextAction(parseActionCancelTx)(options), parseTextAction(parseActionCrossSwapToken)(options), parseTextAction(parseActionCrossToken)(options), parseTextAction(parseActionDeployContract)(options), parseTextAction(parseActionPushMultiSig)(options), parseTextAction(parseActionRevokeNFT)(options), parseTextAction(parseActionRevokeNFTCollection)(options), parseTextAction(parseActionRevokePermit2)(options), parseTextAction(parseActionRevokeToken)(options), parseTextAction(parseActionSendNFT)(options), parseTextAction(parseActionSwap)(options), parseTextAction(parseActionUnwrapToken)(options), parseTextAction(parseActionWrapToken)(options), parseTextAction(parseActionPermit2BatchRevokeToken)(options),
58
+ // text actions
59
+ parseTextAction(parseActionCreateKey)(options), parseTextAction(parseActionVerifyAddress)(options));
49
60
  }
50
61
  const action = result.reduce((acc, val) => (Object.assign(Object.assign({}, acc), val)), {});
51
62
  // filter out typedData or text keys
@@ -60,6 +71,9 @@ export function parseAction(options) {
60
71
  else if (options.type === 'transaction') {
61
72
  return parseActionContractCall(options);
62
73
  }
74
+ else if (options.type === 'text') {
75
+ return parseTextAction(parseActionContractCall)(options);
76
+ }
63
77
  return {};
64
78
  }
65
79
  return action;
@@ -130,6 +130,9 @@ export interface ReceiverData {
130
130
  hasReceiverPrivateKeyInWallet?: boolean;
131
131
  rank?: number;
132
132
  }
133
+ export interface TransferOwnerRequireData {
134
+ receiver: ReceiverData | null;
135
+ }
133
136
  export interface ContractRequireData {
134
137
  id: string;
135
138
  protocol: {
@@ -3,22 +3,24 @@ import { ParsedActionData } from './parsedActionData';
3
3
  import { OpenApiService } from '@rabby-wallet/rabby-api';
4
4
  import { WalletProvider } from './walletProvider';
5
5
  import { ActionRequireData } from './actionRequireData';
6
- type BaseFetchActionRequiredDataParameters<T extends 'typed_data' | 'transaction' | undefined> = {
6
+ type BaseFetchActionRequiredDataParameters<T extends 'typed_data' | 'transaction' | 'text' | undefined> = {
7
7
  actionData: ParsedActionData<T>;
8
8
  sender: string;
9
9
  walletProvider: WalletProvider;
10
10
  apiProvider: OpenApiService;
11
+ chainId: string;
11
12
  };
12
13
  export type FetchTransactionRequiredDataParameters = BaseFetchActionRequiredDataParameters<'transaction'> & {
13
14
  type: 'transaction';
14
15
  contractCall?: ParseTxResponse['contract_call'] | null;
15
- chainId: string;
16
16
  tx: Tx;
17
17
  };
18
18
  export type FetchTypedDataRequiredDataParameters = BaseFetchActionRequiredDataParameters<'typed_data'> & {
19
19
  type: 'typed_data';
20
- chainId?: string;
21
20
  };
22
- export type FetchActionRequiredDataParameters = FetchTransactionRequiredDataParameters | FetchTypedDataRequiredDataParameters;
21
+ export type FetchTextRequiredDataParameters = BaseFetchActionRequiredDataParameters<'text'> & {
22
+ type: 'text';
23
+ };
24
+ export type FetchActionRequiredDataParameters = FetchTransactionRequiredDataParameters | FetchTypedDataRequiredDataParameters | FetchTextRequiredDataParameters;
23
25
  export type FetchActionRequiredData<T = undefined> = (options: FetchActionRequiredDataParameters, likeAction?: T) => Promise<ActionRequireData>;
24
26
  export {};
@@ -1,12 +1,10 @@
1
1
  import { ContextActionData } from '@rabby-wallet/rabby-security-engine/dist/rules';
2
2
  import { ActionRequireData } from './actionRequireData';
3
3
  import { ParsedActionData } from './parsedActionData';
4
- export type FormatSecurityEngineContextParameters = {
5
- type: 'transaction';
6
- actionData: ParsedActionData<'transaction'>;
7
- requireData: ActionRequireData;
4
+ type BaseFormatSecurityEngineContextParameters = {
8
5
  isTestnet: boolean;
9
- chainId?: string;
6
+ chainId: string;
7
+ requireData: ActionRequireData;
10
8
  provider: {
11
9
  getTimeSpan: (time: number) => {
12
10
  d: number;
@@ -16,25 +14,21 @@ export type FormatSecurityEngineContextParameters = {
16
14
  };
17
15
  hasAddress: (address: string) => Promise<boolean>;
18
16
  };
19
- } | {
17
+ };
18
+ export type FormatTransactionSecurityEngineContextParameters = BaseFormatSecurityEngineContextParameters & {
19
+ type: 'transaction';
20
+ actionData: ParsedActionData<'transaction'>;
21
+ };
22
+ export type FormatTypedDataSecurityEngineContextParameters = BaseFormatSecurityEngineContextParameters & {
20
23
  type: 'typed_data';
21
24
  actionData: ParsedActionData<'typed_data'>;
22
- requireData?: ActionRequireData;
23
- isTestnet: boolean;
24
- chainId?: string;
25
25
  origin: string;
26
- provider: {
27
- getTimeSpan: (time: number) => {
28
- d: number;
29
- h: number;
30
- m: number;
31
- s: number;
32
- };
33
- hasAddress: (address: string) => Promise<boolean>;
34
- };
35
- } | {
26
+ };
27
+ export type FormatTextSecurityEngineContextParameters = BaseFormatSecurityEngineContextParameters & {
36
28
  type: 'text';
37
29
  actionData: ParsedActionData<'text'>;
38
30
  origin: string;
39
31
  };
32
+ export type FormatSecurityEngineContextParameters = FormatTransactionSecurityEngineContextParameters | FormatTypedDataSecurityEngineContextParameters | FormatTextSecurityEngineContextParameters;
40
33
  export type FormatSecurityEngineContext = (options: FormatSecurityEngineContextParameters) => Promise<ContextActionData>;
34
+ export {};
@@ -1,10 +1,11 @@
1
- import { ParseTxResponse, ExplainTxResponse, Tx, ParseTypedDataResponse, ParseTextResponse } from '@rabby-wallet/rabby-api/dist/types';
1
+ import { ParseTxResponse, ExplainTxResponse, ParseTypedDataResponse, ParseTextResponse, Tx } from '@rabby-wallet/rabby-api/dist/types';
2
2
  import { ParsedActionData } from './parsedActionData';
3
3
  export type ParseTransactionActionParameters = {
4
4
  type: 'transaction';
5
5
  data: ParseTxResponse['action'];
6
- balanceChange: ExplainTxResponse['balance_change'];
6
+ sender: string;
7
7
  tx: Tx;
8
+ balanceChange: ExplainTxResponse['balance_change'];
8
9
  preExecVersion: 'v0' | 'v1' | 'v2';
9
10
  gasUsed: number;
10
11
  };
@@ -13,12 +14,18 @@ export type ParseTypedDataActionParameters = {
13
14
  data: ParseTypedDataResponse['action'];
14
15
  typedData: null | Record<string, any>;
15
16
  sender: string;
17
+ balanceChange?: ExplainTxResponse['balance_change'];
18
+ preExecVersion?: 'v0' | 'v1' | 'v2';
19
+ gasUsed?: number;
16
20
  };
17
21
  export type ParseTextActionParameters = {
18
22
  type: 'text';
19
23
  data: ParseTextResponse['action'];
20
24
  text: string;
21
25
  sender: string;
26
+ balanceChange?: ExplainTxResponse['balance_change'];
27
+ preExecVersion?: 'v0' | 'v1' | 'v2';
28
+ gasUsed?: number;
22
29
  };
23
30
  export type ParseActionParameters = ParseTransactionActionParameters | ParseTypedDataActionParameters | ParseTextActionParameters;
24
31
  export type ActionType = ParseActionParameters['type'];
@@ -1,4 +1,4 @@
1
- import { TokenItem, NFTItem, RevokeTokenApproveAction, PushMultiSigAction, ApproveNFTAction, BatchSellNFTOrderAction, BuyNFTOrderAction, CreateCoboSafeAction, CreateKeyAction, SellNFTOrderAction, SendAction, SignMultiSigActions, SubmitDelegatedAddressModificationAction, SubmitSafeRoleModificationAction, SubmitTokenApprovalModificationAction, VerifyAddressAction, BatchPermit2Action, Permit2Action, PermitAction, RevokeNFTAction, SendNFTAction, ApproveAction, ApproveNFTCollectionAction, RevokeNFTCollectionAction, RevokePermit2Action } from '@rabby-wallet/rabby-api/dist/types';
1
+ import { TokenItem, NFTItem, RevokeTokenApproveAction, PushMultiSigAction, ApproveNFTAction, BatchSellNFTOrderAction, BuyNFTOrderAction, CreateCoboSafeAction, CreateKeyAction, SellNFTOrderAction, SendAction, SignMultiSigActions, SubmitDelegatedAddressModificationAction, SubmitSafeRoleModificationAction, SubmitTokenApprovalModificationAction, VerifyAddressAction, BatchPermit2Action, Permit2Action, PermitAction, RevokeNFTAction, SendNFTAction, ApproveAction, ApproveNFTCollectionAction, RevokeNFTCollectionAction, RevokePermit2Action, MaxPayTokenItem } from '@rabby-wallet/rabby-api/dist/types';
2
2
  import { ActionType } from './parseAction';
3
3
  export interface ReceiveTokenItem extends TokenItem {
4
4
  min_amount: number;
@@ -14,6 +14,21 @@ interface BatchPermit2ActionData extends BatchPermit2Action {
14
14
  sig_expire_at: number | undefined;
15
15
  }
16
16
  export type ParsedTransactionActionData = {
17
+ swapLimitPay?: {
18
+ payToken: MaxPayTokenItem;
19
+ receiveToken: TokenItem;
20
+ receiver: string;
21
+ };
22
+ multiSwap?: {
23
+ payTokenList: TokenItem[];
24
+ receiveTokenList: ReceiveTokenItem[];
25
+ receiver: string;
26
+ };
27
+ transferOwner?: {
28
+ description: string;
29
+ from: string;
30
+ to: string;
31
+ };
17
32
  swap?: {
18
33
  payToken: TokenItem;
19
34
  receiveToken: ReceiveTokenItem;
@@ -49,7 +64,7 @@ export type ParsedTransactionActionData = {
49
64
  revokeToken?: {
50
65
  spender: string;
51
66
  token: TokenItem;
52
- gasUsed: number;
67
+ gasUsed?: number;
53
68
  };
54
69
  revokePermit2?: RevokePermit2Action;
55
70
  wrapToken?: {
@@ -66,7 +81,7 @@ export type ParsedTransactionActionData = {
66
81
  };
67
82
  deployContract?: Record<string, never>;
68
83
  cancelTx?: {
69
- nonce: string;
84
+ nonce?: string;
70
85
  };
71
86
  pushMultiSig?: PushMultiSigAction;
72
87
  permit2BatchRevokeToken?: {
@@ -94,7 +109,7 @@ export type ParsedTransactionActionData = {
94
109
  from: string;
95
110
  };
96
111
  };
97
- export type ParsedTypedDataActionData = {
112
+ export type ParsedTypedDataActionData = ParsedTransactionActionData & {
98
113
  chainId?: string;
99
114
  brand?: {
100
115
  logo_url: string;
@@ -146,7 +161,7 @@ export type ParsedTypedDataActionData = {
146
161
  from: string;
147
162
  };
148
163
  };
149
- export type ParsedTextActionData = {
164
+ export type ParsedTextActionData = ParsedTransactionActionData & {
150
165
  sender: string;
151
166
  createKey?: CreateKeyAction;
152
167
  verifyAddress?: VerifyAddressAction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/rabby-action",
3
- "version": "0.1.0",
3
+ "version": "0.1.1-beta.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -15,8 +15,8 @@
15
15
  "devDependencies": {
16
16
  "@babel/preset-env": "^7.19.1",
17
17
  "@debank/common": "^0.3.60",
18
- "@rabby-wallet/rabby-api": "^0.7.26",
19
- "@rabby-wallet/rabby-security-engine": "^2.0.5",
18
+ "@rabby-wallet/rabby-api": "0.7.28",
19
+ "@rabby-wallet/rabby-security-engine": "2.0.7-beta",
20
20
  "@types/jest": "^29.0.3",
21
21
  "@types/lodash": "^4.14.185",
22
22
  "@types/node": "^18.7.18",