@rabby-wallet/rabby-action 0.1.12 → 0.1.13-beta.0

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.
@@ -0,0 +1,9 @@
1
+ import { FetchActionRequiredData } from '../../types';
2
+ export declare const fetchDataAddLiquidity: FetchActionRequiredData<{
3
+ receiver: string;
4
+ exchange_rate: string;
5
+ min_exchange_rate: string;
6
+ max_exchange_rate: string;
7
+ token0: any;
8
+ token1: any;
9
+ }>;
@@ -0,0 +1,67 @@
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
+ import BigNumber from 'bignumber.js';
13
+ export const fetchDataAddLiquidity = (options, likeAction) => __awaiter(void 0, void 0, void 0, function* () {
14
+ const { actionData, apiProvider, sender, walletProvider, chainId } = options;
15
+ const action = likeAction || actionData.addLiquidity;
16
+ if (!action || options.type === 'text') {
17
+ return {};
18
+ }
19
+ const { receiver, exchange_rate, token0, token1 } = action;
20
+ const fair_exchange_rate = new BigNumber(token0.price).div(token1.price);
21
+ const diff = +new BigNumber(exchange_rate)
22
+ .minus(fair_exchange_rate)
23
+ .abs()
24
+ .div(fair_exchange_rate)
25
+ .times(100)
26
+ .toFixed(4);
27
+ const receiverInWallet = yield walletProvider.hasAddress(receiver);
28
+ const id = options.type === 'transaction'
29
+ ? options.tx.to
30
+ : options.actionData.contractId;
31
+ if (!id) {
32
+ return {};
33
+ }
34
+ const result = {
35
+ id,
36
+ protocol: null,
37
+ bornAt: 0,
38
+ rank: null,
39
+ sender,
40
+ receiverInWallet,
41
+ hasInteraction: false,
42
+ receiver,
43
+ poolRate: exchange_rate,
44
+ token0,
45
+ token1,
46
+ marketRate: fair_exchange_rate.toFixed(),
47
+ diff,
48
+ };
49
+ const queue = new PQueue();
50
+ queue.add(() => __awaiter(void 0, void 0, void 0, function* () {
51
+ const contractInfo = yield apiProvider.getContractInfo(id, chainId);
52
+ if (!contractInfo) {
53
+ result.rank = null;
54
+ }
55
+ else {
56
+ result.rank = contractInfo.credit.rank_at;
57
+ result.bornAt = contractInfo.create_at;
58
+ result.protocol = contractInfo.protocol;
59
+ }
60
+ }));
61
+ queue.add(() => __awaiter(void 0, void 0, void 0, function* () {
62
+ const hasInteraction = yield apiProvider.hasInteraction(sender, chainId, id);
63
+ result.hasInteraction = hasInteraction.has_interaction;
64
+ }));
65
+ yield waitQueueFinished(queue);
66
+ return result;
67
+ });
@@ -0,0 +1,2 @@
1
+ import { FormatSecurityEngineContext } from '../../types';
2
+ export declare const formatSecurityEngineAddLiquidity: FormatSecurityEngineContext;
@@ -0,0 +1,23 @@
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 formatSecurityEngineAddLiquidity = (options) => __awaiter(void 0, void 0, void 0, function* () {
11
+ var _a;
12
+ const { actionData, requireData, chainId } = options;
13
+ if (!actionData.addLiquidity || !chainId) {
14
+ return {};
15
+ }
16
+ const data = requireData;
17
+ return {
18
+ addLiquidity: {
19
+ receiverMatch: ((_a = data.receiver) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === data.sender.toLowerCase(),
20
+ diff: data.diff,
21
+ },
22
+ };
23
+ });
@@ -0,0 +1,2 @@
1
+ import { ParseAction } from '../../types';
2
+ export declare const parseActionAddLiquidity: ParseAction;
@@ -0,0 +1,17 @@
1
+ export const parseActionAddLiquidity = (options) => {
2
+ const { data } = options;
3
+ if ((data === null || data === void 0 ? void 0 : data.type) !== 'add_liquidity') {
4
+ return {};
5
+ }
6
+ const { receiver, exchange_rate, min_exchange_rate, max_exchange_rate, token0, token1, } = data.data;
7
+ return {
8
+ addLiquidity: {
9
+ receiver,
10
+ exchange_rate,
11
+ min_exchange_rate,
12
+ max_exchange_rate,
13
+ token0,
14
+ token1,
15
+ },
16
+ };
17
+ };
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { fetchDataDeployContract } from './actions/deployContract/fetchData';
11
11
  import { fetchDataSend } from './actions/send/fetchData';
12
12
  import { fetchDataSendNFT } from './actions/sendNFT/fetchData';
13
+ import { fetchDataAddLiquidity } from './actions/addLiquidity/fetchData';
13
14
  import { fetchDataSwap } from './actions/swap/fetchData';
14
15
  import { fetchDataCrossToken } from './actions/crossToken/fetchData';
15
16
  import { fetchDataCrossSwapToken } from './actions/crossSwapToken/fetchData';
@@ -87,6 +88,7 @@ export const fetchActionRequiredData = (options) => __awaiter(void 0, void 0, vo
87
88
  fetchDataCoboSafeModificationRole(options),
88
89
  fetchDataCoboSafeModificationTokenApproval(options),
89
90
  fetchDataRevokePermit(options),
91
+ fetchDataAddLiquidity(options),
90
92
  ]);
91
93
  return result.reduce((acc, val) => (Object.assign(Object.assign({}, acc), val)), {});
92
94
  });
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { formatSecurityEngineApproveNFT } from './actions/approveNFT/formatSecurityEngine';
11
11
  import { formatSecurityEngineApproveNFTCollection } from './actions/approveNFTCollection/formatSecurityEngine';
12
+ import { formatSecurityEngineAddLiquidity } from './actions/addLiquidity/formatSecurityEngine';
12
13
  import { formatSecurityEngineApproveToken } from './actions/approveToken/formatSecurityEngine';
13
14
  import { formatSecurityEngineAssetOrder } from './actions/assetOrder/formatSecurityEngine';
14
15
  import { formatSecurityEngineCancelTx } from './actions/cancelTx/formatSecurityEngine';
@@ -90,6 +91,7 @@ export const formatSecurityEngineContext = (options) => __awaiter(void 0, void 0
90
91
  formatSecurityEngineCoboSafeModificationRole(options),
91
92
  formatSecurityEngineCoboSafeModificationTokenApproval(options),
92
93
  formatSecurityEngineRevokePermit(options),
94
+ formatSecurityEngineAddLiquidity(options),
93
95
  ]);
94
96
  return result.reduce((acc, val) => (Object.assign(Object.assign({}, acc), val)), {});
95
97
  });
@@ -1,6 +1,7 @@
1
1
  import { parseActionSwapLimitPay } from './actions/swapLimitPay/parseAction';
2
2
  import { parseActionMultiSwap } from './actions/multiSwap/parseAction';
3
3
  import { parseActionTransferOwner } from './actions/transferOwner/parseAction';
4
+ import { parseActionAddLiquidity } from './actions/addLiquidity/parseAction';
4
5
  import { parseActionSend } from './actions/send/parseAction';
5
6
  import { parseActionApproveNFT } from './actions/approveNFT/parseAction';
6
7
  import { parseActionApproveNFTCollection } from './actions/approveNFTCollection/parseAction';
@@ -42,19 +43,19 @@ import { parseTextAction } from './utils/parseTextAction';
42
43
  export function parseAction(options) {
43
44
  const result = [];
44
45
  if (options.type === 'transaction') {
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));
46
+ 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), parseActionAddLiquidity(options));
46
47
  }
47
48
  if (options.type === 'typed_data') {
48
49
  result.push(
49
50
  // 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
+ 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), parseTypedDataAction(parseActionAddLiquidity)(options),
51
52
  // typed data actions
52
53
  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));
53
54
  }
54
55
  if (options.type === 'text') {
55
56
  result.push(
56
57
  // 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
+ 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), parseTextAction(parseActionAddLiquidity)(options),
58
59
  // text actions
59
60
  parseTextAction(parseActionCreateKey)(options), parseTextAction(parseActionVerifyAddress)(options));
60
61
  }
@@ -159,4 +159,22 @@ export interface SwapTokenOrderRequireData extends ContractRequireData {
159
159
  export type BatchApproveTokenRequireData = Omit<ApproveTokenRequireData, 'token'> & {
160
160
  tokens: TokenItem[];
161
161
  };
162
- export type ActionRequireData = SwapRequireData | ApproveTokenRequireData | SendRequireData | ApproveNFTRequireData | RevokeNFTRequireData | ContractCallRequireData | Record<string, any> | ContractCallRequireData | CancelTxRequireData | WrapTokenRequireData | PushMultiSigRequireData | AssetOrderRequireData | BatchRevokePermit2RequireData | SwapTokenOrderRequireData | ContractRequireData | MultiSigRequireData | BatchApproveTokenRequireData | null;
162
+ export interface AddLiquidityRequireData {
163
+ id: string;
164
+ protocol: {
165
+ name: string;
166
+ logo_url: string;
167
+ } | null;
168
+ bornAt: number;
169
+ rank: number | null;
170
+ receiverInWallet: boolean;
171
+ hasInteraction: boolean;
172
+ sender: string;
173
+ receiver: string;
174
+ poolRate: string;
175
+ token0: TokenItem;
176
+ token1: TokenItem;
177
+ marketRate: string;
178
+ diff: number;
179
+ }
180
+ export type ActionRequireData = SwapRequireData | ApproveTokenRequireData | SendRequireData | ApproveNFTRequireData | RevokeNFTRequireData | ContractCallRequireData | Record<string, any> | ContractCallRequireData | CancelTxRequireData | WrapTokenRequireData | PushMultiSigRequireData | AssetOrderRequireData | BatchRevokePermit2RequireData | SwapTokenOrderRequireData | ContractRequireData | MultiSigRequireData | BatchApproveTokenRequireData | AddLiquidityRequireData | null;
@@ -108,6 +108,14 @@ export type ParsedTransactionActionData = {
108
108
  receiver?: string;
109
109
  from: string;
110
110
  };
111
+ addLiquidity?: {
112
+ receiver: string;
113
+ exchange_rate: string;
114
+ min_exchange_rate: string;
115
+ max_exchange_rate: string;
116
+ token0: TokenItem;
117
+ token1: TokenItem;
118
+ };
111
119
  };
112
120
  export type ParsedTypedDataActionData = ParsedTransactionActionData & {
113
121
  chainId?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/rabby-action",
3
- "version": "0.1.12",
3
+ "version": "0.1.13-beta.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [