@portal-hq/web 3.6.2-alpha → 3.7.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.
Files changed (45) hide show
  1. package/hypernative.d.ts +346 -0
  2. package/lib/commonjs/index.js +144 -2
  3. package/lib/commonjs/index.test.js +119 -2
  4. package/lib/commonjs/integrations/security/hypernative/index.js +101 -0
  5. package/lib/commonjs/integrations/security/hypernative/index.test.js +151 -0
  6. package/lib/commonjs/integrations/security/index.js +16 -0
  7. package/lib/commonjs/integrations/trading/zero-x/index.js +17 -4
  8. package/lib/commonjs/integrations/trading/zero-x/index.test.js +61 -15
  9. package/lib/commonjs/mpc/index.js +156 -5
  10. package/lib/commonjs/mpc/index.test.js +794 -5
  11. package/lib/commonjs/passkeys/index.js +394 -0
  12. package/lib/commonjs/passkeys/types.js +2 -0
  13. package/lib/commonjs/provider/index.js +5 -2
  14. package/lib/esm/index.js +144 -2
  15. package/lib/esm/index.test.js +119 -2
  16. package/lib/esm/integrations/security/hypernative/index.js +98 -0
  17. package/lib/esm/integrations/security/hypernative/index.test.js +146 -0
  18. package/lib/esm/integrations/security/index.js +10 -0
  19. package/lib/esm/integrations/trading/zero-x/index.js +17 -4
  20. package/lib/esm/integrations/trading/zero-x/index.test.js +62 -16
  21. package/lib/esm/mpc/index.js +156 -5
  22. package/lib/esm/mpc/index.test.js +795 -6
  23. package/lib/esm/passkeys/index.js +390 -0
  24. package/lib/esm/passkeys/types.js +1 -0
  25. package/lib/esm/provider/index.js +5 -2
  26. package/lifi-types.d.ts +1236 -0
  27. package/package.json +6 -3
  28. package/src/__mocks/constants.ts +422 -5
  29. package/src/__mocks/portal/mpc.ts +1 -0
  30. package/src/index.test.ts +179 -3
  31. package/src/index.ts +212 -4
  32. package/src/integrations/security/hypernative/index.test.ts +196 -0
  33. package/src/integrations/security/hypernative/index.ts +106 -0
  34. package/src/integrations/security/index.ts +14 -0
  35. package/src/integrations/trading/zero-x/index.test.ts +98 -19
  36. package/src/integrations/trading/zero-x/index.ts +29 -9
  37. package/src/mpc/index.test.ts +944 -7
  38. package/src/mpc/index.ts +200 -10
  39. package/src/passkeys/index.ts +536 -0
  40. package/src/passkeys/types.ts +78 -0
  41. package/src/provider/index.ts +5 -0
  42. package/tsconfig.json +7 -1
  43. package/types.d.ts +45 -12
  44. package/yieldxyz-types.d.ts +778 -0
  45. package/zero-x.d.ts +204 -0
@@ -7,10 +7,14 @@ import Mpc from '../../../mpc'
7
7
  import portalMock from '../../../__mocks/portal/portal'
8
8
  import {
9
9
  mockHost,
10
- mockQuoteArgs,
11
10
  mockSourcesRes,
12
- mockZeroXQuoteResponse,
11
+ mockZeroExQuoteV2Request,
12
+ mockZeroExQuoteV2Response,
13
+ mockZeroExOptions,
14
+ mockZeroExPriceRequest,
15
+ mockZeroExPriceResponse,
13
16
  } from '../../../__mocks/constants'
17
+ import type { ZeroExPriceResponse } from '../../../../zero-x'
14
18
 
15
19
  describe('ZeroX', () => {
16
20
  let zeroX: ZeroX
@@ -28,46 +32,121 @@ describe('ZeroX', () => {
28
32
  })
29
33
 
30
34
  describe('getQuote', () => {
31
- it('should correctly call mpc.getQuote', async () => {
35
+ it('should correctly call mpc.getSwapsQuoteV2 with args and options', async () => {
32
36
  const spy = jest
33
- .spyOn(mpc, 'getQuote')
34
- .mockResolvedValue(mockZeroXQuoteResponse)
37
+ .spyOn(mpc, 'getSwapsQuoteV2')
38
+ .mockResolvedValue(mockZeroExQuoteV2Response)
35
39
 
36
- const result = await zeroX.getQuote('test', mockQuoteArgs, 'eip155:1')
40
+ const result = await zeroX.getQuote(
41
+ mockZeroExQuoteV2Request,
42
+ mockZeroExOptions,
43
+ )
44
+
45
+ expect(spy).toHaveBeenCalledTimes(1)
46
+ expect(spy).toHaveBeenCalledWith(
47
+ mockZeroExQuoteV2Request,
48
+ mockZeroExOptions,
49
+ )
50
+ expect(result).toEqual(mockZeroExQuoteV2Response)
51
+ })
52
+
53
+ it('should correctly call mpc.getSwapsQuoteV2 without options', async () => {
54
+ const spy = jest
55
+ .spyOn(mpc, 'getSwapsQuoteV2')
56
+ .mockResolvedValue(mockZeroExQuoteV2Response)
57
+
58
+ const result = await zeroX.getQuote(mockZeroExQuoteV2Request)
37
59
 
38
60
  expect(spy).toHaveBeenCalledTimes(1)
39
- expect(spy).toHaveBeenCalledWith('test', mockQuoteArgs, 'eip155:1')
40
- expect(result).toEqual(mockZeroXQuoteResponse)
61
+ expect(spy).toHaveBeenCalledWith(mockZeroExQuoteV2Request, undefined)
62
+ expect(result).toEqual(mockZeroExQuoteV2Response)
41
63
  })
42
64
 
43
- it('should propagate errors from mpc.getQuote', async () => {
65
+ it('should propagate errors from mpc.getSwapsQuoteV2', async () => {
44
66
  const error = new Error('Test error')
45
- jest.spyOn(mpc, 'getQuote').mockRejectedValue(error)
67
+ jest.spyOn(mpc, 'getSwapsQuoteV2').mockRejectedValue(error)
46
68
 
47
- await expect(
48
- zeroX.getQuote('test', mockQuoteArgs, 'eip155:1'),
49
- ).rejects.toThrow('Test error')
69
+ await expect(zeroX.getQuote(mockZeroExQuoteV2Request)).rejects.toThrow(
70
+ 'Test error',
71
+ )
50
72
  })
51
73
  })
52
74
 
53
75
  describe('getSources', () => {
54
- it('should correctly call mpc.getSources', async () => {
76
+ it('should correctly call mpc.getSources with chainId and apiKey', async () => {
77
+ const spy = jest
78
+ .spyOn(mpc, 'getSwapsSourcesV2')
79
+ .mockResolvedValue(mockSourcesRes)
80
+
81
+ const result = await zeroX.getSources('eip155:1', {
82
+ zeroXApiKey: 'test-api-key',
83
+ })
84
+
85
+ console.log(`Result:`, result)
86
+ expect(spy).toHaveBeenCalledTimes(1)
87
+ expect(spy).toHaveBeenCalledWith(
88
+ { chainId: 'eip155:1' },
89
+ { zeroXApiKey: 'test-api-key' },
90
+ )
91
+ expect(result).toEqual(mockSourcesRes)
92
+ })
93
+
94
+ it('should correctly call mpc.getSources without apiKey', async () => {
55
95
  const spy = jest
56
- .spyOn(mpc, 'getSources')
96
+ .spyOn(mpc, 'getSwapsSourcesV2')
57
97
  .mockResolvedValue(mockSourcesRes)
58
98
 
59
- const result = await zeroX.getSources('test', 'eip155:1')
99
+ const result = await zeroX.getSources('eip155:1')
60
100
 
61
101
  expect(spy).toHaveBeenCalledTimes(1)
62
- expect(spy).toHaveBeenCalledWith('test', 'eip155:1')
102
+ expect(spy).toHaveBeenCalledWith({ chainId: 'eip155:1' }, undefined)
63
103
  expect(result).toEqual(mockSourcesRes)
64
104
  })
65
105
 
66
106
  it('should propagate errors from mpc.getSources', async () => {
67
107
  const error = new Error('Test error')
68
- jest.spyOn(mpc, 'getSources').mockRejectedValue(error)
108
+ jest.spyOn(mpc, 'getSwapsSourcesV2').mockRejectedValue(error)
109
+
110
+ await expect(zeroX.getSources('eip155:1')).rejects.toThrow('Test error')
111
+ })
112
+ })
113
+
114
+ describe('getPrice', () => {
115
+ it('should correctly call mpc.getSwapsPrice with args and options', async () => {
116
+ const spy = jest
117
+ .spyOn(mpc, 'getSwapsPrice')
118
+ .mockResolvedValue(mockZeroExPriceResponse as ZeroExPriceResponse)
119
+
120
+ const result = await zeroX.getPrice(
121
+ mockZeroExPriceRequest,
122
+ mockZeroExOptions,
123
+ )
124
+
125
+ expect(spy).toHaveBeenCalledTimes(1)
126
+ expect(spy).toHaveBeenCalledWith(
127
+ mockZeroExPriceRequest,
128
+ mockZeroExOptions,
129
+ )
130
+ expect(result).toEqual(mockZeroExPriceResponse)
131
+ })
132
+
133
+ it('should correctly call mpc.getSwapsPrice without options', async () => {
134
+ const spy = jest
135
+ .spyOn(mpc, 'getSwapsPrice')
136
+ .mockResolvedValue(mockZeroExPriceResponse as ZeroExPriceResponse)
137
+
138
+ const result = await zeroX.getPrice(mockZeroExPriceRequest)
139
+
140
+ expect(spy).toHaveBeenCalledTimes(1)
141
+ expect(spy).toHaveBeenCalledWith(mockZeroExPriceRequest, undefined)
142
+ expect(result).toEqual(mockZeroExPriceResponse)
143
+ })
144
+
145
+ it('should propagate errors from mpc.getSwapsPrice', async () => {
146
+ const error = new Error('Test error')
147
+ jest.spyOn(mpc, 'getSwapsPrice').mockRejectedValue(error)
69
148
 
70
- await expect(zeroX.getSources('test', 'eip155:1')).rejects.toThrow(
149
+ await expect(zeroX.getPrice(mockZeroExPriceRequest)).rejects.toThrow(
71
150
  'Test error',
72
151
  )
73
152
  })
@@ -1,5 +1,12 @@
1
1
  import Mpc from '../../../mpc'
2
- import { QuoteArgs, QuoteResponse } from '../../../../types'
2
+ import {
3
+ ZeroExOptions,
4
+ ZeroExPriceRequest,
5
+ ZeroExPriceResponse,
6
+ ZeroExQuoteRequest,
7
+ ZeroExQuoteResponse,
8
+ ZeroExSourcesResponse,
9
+ } from '../../../../zero-x'
3
10
 
4
11
  export default class ZeroX {
5
12
  private mpc: Mpc
@@ -17,11 +24,10 @@ export default class ZeroX {
17
24
  * @returns The quote response.
18
25
  */
19
26
  public async getQuote(
20
- apiKey: string,
21
- args: QuoteArgs,
22
- chainId: string,
23
- ): Promise<QuoteResponse> {
24
- return this.mpc?.getQuote(apiKey, args, chainId)
27
+ args: ZeroExQuoteRequest,
28
+ options?: ZeroExOptions,
29
+ ): Promise<ZeroExQuoteResponse> {
30
+ return this.mpc?.getSwapsQuoteV2(args, options)
25
31
  }
26
32
 
27
33
  /**
@@ -32,9 +38,23 @@ export default class ZeroX {
32
38
  * @returns The sources response.
33
39
  */
34
40
  public async getSources(
35
- apiKey: string,
36
41
  chainId: string,
37
- ): Promise<Record<string, string>> {
38
- return this.mpc?.getSources(apiKey, chainId)
42
+ options?: ZeroExOptions,
43
+ ): Promise<ZeroExSourcesResponse> {
44
+ return this.mpc?.getSwapsSourcesV2({ chainId }, options)
45
+ }
46
+
47
+ /**
48
+ * Get the price of a token from the Swaps API.
49
+ *
50
+ * @param args - The arguments for the price.
51
+ * @param options - The options for the price.
52
+ * @returns The price response.
53
+ */
54
+ public async getPrice(
55
+ args: ZeroExPriceRequest,
56
+ options?: ZeroExOptions,
57
+ ): Promise<ZeroExPriceResponse> {
58
+ return this.mpc?.getSwapsPrice(args, options)
39
59
  }
40
60
  }