@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.
- package/hypernative.d.ts +346 -0
- package/lib/commonjs/index.js +144 -2
- package/lib/commonjs/index.test.js +119 -2
- package/lib/commonjs/integrations/security/hypernative/index.js +101 -0
- package/lib/commonjs/integrations/security/hypernative/index.test.js +151 -0
- package/lib/commonjs/integrations/security/index.js +16 -0
- package/lib/commonjs/integrations/trading/zero-x/index.js +17 -4
- package/lib/commonjs/integrations/trading/zero-x/index.test.js +61 -15
- package/lib/commonjs/mpc/index.js +156 -5
- package/lib/commonjs/mpc/index.test.js +794 -5
- package/lib/commonjs/passkeys/index.js +394 -0
- package/lib/commonjs/passkeys/types.js +2 -0
- package/lib/commonjs/provider/index.js +5 -2
- package/lib/esm/index.js +144 -2
- package/lib/esm/index.test.js +119 -2
- package/lib/esm/integrations/security/hypernative/index.js +98 -0
- package/lib/esm/integrations/security/hypernative/index.test.js +146 -0
- package/lib/esm/integrations/security/index.js +10 -0
- package/lib/esm/integrations/trading/zero-x/index.js +17 -4
- package/lib/esm/integrations/trading/zero-x/index.test.js +62 -16
- package/lib/esm/mpc/index.js +156 -5
- package/lib/esm/mpc/index.test.js +795 -6
- package/lib/esm/passkeys/index.js +390 -0
- package/lib/esm/passkeys/types.js +1 -0
- package/lib/esm/provider/index.js +5 -2
- package/lifi-types.d.ts +1236 -0
- package/package.json +6 -3
- package/src/__mocks/constants.ts +422 -5
- package/src/__mocks/portal/mpc.ts +1 -0
- package/src/index.test.ts +179 -3
- package/src/index.ts +212 -4
- package/src/integrations/security/hypernative/index.test.ts +196 -0
- package/src/integrations/security/hypernative/index.ts +106 -0
- package/src/integrations/security/index.ts +14 -0
- package/src/integrations/trading/zero-x/index.test.ts +98 -19
- package/src/integrations/trading/zero-x/index.ts +29 -9
- package/src/mpc/index.test.ts +944 -7
- package/src/mpc/index.ts +200 -10
- package/src/passkeys/index.ts +536 -0
- package/src/passkeys/types.ts +78 -0
- package/src/provider/index.ts +5 -0
- package/tsconfig.json +7 -1
- package/types.d.ts +45 -12
- package/yieldxyz-types.d.ts +778 -0
- 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
|
-
|
|
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.
|
|
35
|
+
it('should correctly call mpc.getSwapsQuoteV2 with args and options', async () => {
|
|
32
36
|
const spy = jest
|
|
33
|
-
.spyOn(mpc, '
|
|
34
|
-
.mockResolvedValue(
|
|
37
|
+
.spyOn(mpc, 'getSwapsQuoteV2')
|
|
38
|
+
.mockResolvedValue(mockZeroExQuoteV2Response)
|
|
35
39
|
|
|
36
|
-
const result = await zeroX.getQuote(
|
|
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(
|
|
40
|
-
expect(result).toEqual(
|
|
61
|
+
expect(spy).toHaveBeenCalledWith(mockZeroExQuoteV2Request, undefined)
|
|
62
|
+
expect(result).toEqual(mockZeroExQuoteV2Response)
|
|
41
63
|
})
|
|
42
64
|
|
|
43
|
-
it('should propagate errors from mpc.
|
|
65
|
+
it('should propagate errors from mpc.getSwapsQuoteV2', async () => {
|
|
44
66
|
const error = new Error('Test error')
|
|
45
|
-
jest.spyOn(mpc, '
|
|
67
|
+
jest.spyOn(mpc, 'getSwapsQuoteV2').mockRejectedValue(error)
|
|
46
68
|
|
|
47
|
-
await expect(
|
|
48
|
-
|
|
49
|
-
)
|
|
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, '
|
|
96
|
+
.spyOn(mpc, 'getSwapsSourcesV2')
|
|
57
97
|
.mockResolvedValue(mockSourcesRes)
|
|
58
98
|
|
|
59
|
-
const result = await zeroX.getSources('
|
|
99
|
+
const result = await zeroX.getSources('eip155:1')
|
|
60
100
|
|
|
61
101
|
expect(spy).toHaveBeenCalledTimes(1)
|
|
62
|
-
expect(spy).toHaveBeenCalledWith(
|
|
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, '
|
|
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.
|
|
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 {
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
38
|
-
|
|
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
|
}
|