@avalabs/bridge-unified 0.0.0-fix-dual-export-20240111234556 → 0.0.0-fix-address-comparison-20240119104940

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avalabs/bridge-unified",
3
- "version": "0.0.0-fix-dual-export-20240111234556",
3
+ "version": "0.0.0-fix-address-comparison-20240119104940",
4
4
  "main": "dist/index.cjs",
5
5
  "module": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "ts-jest": "29.1.1",
18
18
  "tsup": "7.2.0",
19
19
  "@internal/tsup-config": "0.0.1",
20
- "eslint-config-custom": "0.0.0-fix-dual-export-20240111234556"
20
+ "eslint-config-custom": "0.1.0"
21
21
  },
22
22
  "scripts": {
23
23
  "build": "tsup",
@@ -135,7 +135,7 @@ export const trackSourceTx = async (config: BridgeConfig, params: TrackingParams
135
135
  * Get the `TransferTokens` event's log entry from the receipt
136
136
  */
137
137
  const transferEventLog = txReceipt.logs.find((log) => {
138
- if (log.address === sourceChainData.tokenRouterAddress) {
138
+ if (log.address.toLowerCase() === sourceChainData.tokenRouterAddress.toLowerCase()) {
139
139
  const event = decodeEventLog({
140
140
  abi: TOKEN_ROUTER_ABI,
141
141
  ...log,
@@ -6,6 +6,7 @@ import {
6
6
  BridgeType,
7
7
  ErrorReason,
8
8
  type Signer,
9
+ BridgeSignatureReason,
9
10
  } from '../../../types';
10
11
  import { getClientForChain } from '../../../utils/client';
11
12
  import { BRIDGE_ASSET } from '../__mocks__/asset.mock';
@@ -49,6 +50,7 @@ describe('CCTP transferAsset', () => {
49
50
  const targetClientMock = {
50
51
  getBlockNumber: jest.fn(),
51
52
  };
53
+ const onStepChangeSpy = jest.fn();
52
54
 
53
55
  const getTransferParams = (props?: Partial<TransferParams>) =>
54
56
  ({
@@ -59,6 +61,7 @@ describe('CCTP transferAsset', () => {
59
61
  targetChain: TARGET_CHAIN,
60
62
  sourceProvider: sourceProviderMock,
61
63
  targetProvider: targetProviderMock,
64
+ onStepChange: onStepChangeSpy,
62
65
  ...(props ?? {}),
63
66
  }) as TransferParams;
64
67
 
@@ -182,6 +185,18 @@ describe('CCTP transferAsset', () => {
182
185
  hash: approvalTxHash,
183
186
  pollingInterval: 1_000,
184
187
  });
188
+
189
+ expect(onStepChangeSpy).toHaveBeenCalledTimes(2);
190
+ expect(onStepChangeSpy).toHaveBeenNthCalledWith(1, {
191
+ currentSignature: 1,
192
+ requiredSignatures: 2,
193
+ currentSignatureReason: BridgeSignatureReason.AllowanceApproval,
194
+ });
195
+ expect(onStepChangeSpy).toHaveBeenNthCalledWith(2, {
196
+ currentSignature: 2,
197
+ requiredSignatures: 2,
198
+ currentSignatureReason: BridgeSignatureReason.TokensTransfer,
199
+ });
185
200
  });
186
201
 
187
202
  it('works without provided signer', async () => {
@@ -255,6 +270,18 @@ describe('CCTP transferAsset', () => {
255
270
  hash: approvalTxHash,
256
271
  pollingInterval: 1_000,
257
272
  });
273
+
274
+ expect(onStepChangeSpy).toHaveBeenCalledTimes(2);
275
+ expect(onStepChangeSpy).toHaveBeenNthCalledWith(1, {
276
+ currentSignature: 1,
277
+ requiredSignatures: 2,
278
+ currentSignatureReason: BridgeSignatureReason.AllowanceApproval,
279
+ });
280
+ expect(onStepChangeSpy).toHaveBeenNthCalledWith(2, {
281
+ currentSignature: 2,
282
+ requiredSignatures: 2,
283
+ currentSignatureReason: BridgeSignatureReason.TokensTransfer,
284
+ });
258
285
  });
259
286
  });
260
287
 
@@ -327,6 +354,13 @@ describe('CCTP transferAsset', () => {
327
354
  expect(sourceClientMock.sendRawTransaction).toHaveBeenCalledWith({
328
355
  serializedTransaction: bridgeSignedHex,
329
356
  });
357
+
358
+ expect(onStepChangeSpy).toHaveBeenCalledTimes(1);
359
+ expect(onStepChangeSpy).toHaveBeenNthCalledWith(1, {
360
+ currentSignature: 1,
361
+ requiredSignatures: 1,
362
+ currentSignatureReason: BridgeSignatureReason.TokensTransfer,
363
+ });
330
364
  });
331
365
 
332
366
  it('works without provided signer', async () => {
@@ -383,6 +417,13 @@ describe('CCTP transferAsset', () => {
383
417
 
384
418
  expect(sourceClientMock.writeContract).toHaveBeenCalledTimes(1);
385
419
  expect(sourceClientMock.writeContract).toHaveBeenCalledWith(bridgeTxRequest);
420
+
421
+ expect(onStepChangeSpy).toHaveBeenCalledTimes(1);
422
+ expect(onStepChangeSpy).toHaveBeenNthCalledWith(1, {
423
+ currentSignature: 1,
424
+ requiredSignatures: 1,
425
+ currentSignatureReason: BridgeSignatureReason.TokensTransfer,
426
+ });
386
427
  });
387
428
  });
388
429
  });
@@ -6,6 +6,7 @@ import {
6
6
  type TransferParams,
7
7
  type Hex,
8
8
  type BridgeTransfer,
9
+ BridgeSignatureReason,
9
10
  } from '../../../types';
10
11
  import { getClientForChain } from '../../../utils/client';
11
12
  import { ERC20_ABI } from '../abis/erc20';
@@ -22,6 +23,7 @@ const approveAndTransfer = async (bridge: BridgeService, params: TransferParams)
22
23
  fromAddress,
23
24
  toAddress: maybeToAddress,
24
25
  sourceProvider,
26
+ onStepChange,
25
27
  sign,
26
28
  } = params;
27
29
  const toAddress = maybeToAddress ?? fromAddress;
@@ -43,7 +45,16 @@ const approveAndTransfer = async (bridge: BridgeService, params: TransferParams)
43
45
  args: [fromAddress, sourceChainData.tokenRouterAddress],
44
46
  });
45
47
 
46
- if (allowance < amount) {
48
+ const isAllowanceApprovalRequired = allowance < amount;
49
+ const requiredSignatures = isAllowanceApprovalRequired ? 2 : 1; // if approval is required, we'll need 2 signatures
50
+
51
+ if (isAllowanceApprovalRequired) {
52
+ onStepChange?.({
53
+ currentSignature: 1,
54
+ currentSignatureReason: BridgeSignatureReason.AllowanceApproval,
55
+ requiredSignatures,
56
+ });
57
+
47
58
  if (sign) {
48
59
  const data = encodeFunctionData({
49
60
  abi: ERC20_ABI,
@@ -75,6 +86,12 @@ const approveAndTransfer = async (bridge: BridgeService, params: TransferParams)
75
86
  }
76
87
  }
77
88
 
89
+ onStepChange?.({
90
+ currentSignature: isAllowanceApprovalRequired ? 2 : 1,
91
+ currentSignatureReason: BridgeSignatureReason.TokensTransfer,
92
+ requiredSignatures,
93
+ });
94
+
78
95
  if (sign) {
79
96
  const data = encodeFunctionData({
80
97
  abi: TOKEN_ROUTER_ABI,
@@ -18,6 +18,17 @@ export type FeeParams = {
18
18
  provider?: Provider;
19
19
  };
20
20
 
21
+ export enum BridgeSignatureReason {
22
+ AllowanceApproval = 'allowance-approval',
23
+ TokensTransfer = 'tokens-transfer',
24
+ }
25
+
26
+ export type BridgeStepDetails = {
27
+ currentSignature: number;
28
+ requiredSignatures: number;
29
+ currentSignatureReason: BridgeSignatureReason;
30
+ };
31
+
21
32
  export type TransferParams = {
22
33
  asset: BridgeAsset;
23
34
  amount: bigint;
@@ -27,6 +38,7 @@ export type TransferParams = {
27
38
  targetChain: Chain;
28
39
  sourceProvider?: Provider;
29
40
  targetProvider?: Provider;
41
+ onStepChange?: (stepDetails: BridgeStepDetails) => void;
30
42
  sign?: Signer;
31
43
  };
32
44