@portal-hq/web 3.6.0-alpha → 3.6.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/lib/commonjs/index.js +4 -2
- package/lib/commonjs/index.test.js +2 -2
- 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 +33 -3
- package/lib/commonjs/mpc/index.test.js +286 -4
- package/lib/commonjs/provider/index.js +5 -2
- package/lib/esm/index.js +4 -2
- package/lib/esm/index.test.js +2 -2
- 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 +33 -3
- package/lib/esm/mpc/index.test.js +287 -5
- package/lib/esm/provider/index.js +5 -2
- package/package.json +2 -3
- package/src/__mocks/constants.ts +206 -5
- package/src/index.test.ts +3 -3
- package/src/index.ts +4 -2
- 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 +341 -4
- package/src/mpc/index.ts +49 -4
- package/src/provider/index.ts +5 -0
- package/types.d.ts +3 -0
|
@@ -19,10 +19,10 @@ export default class ZeroX {
|
|
|
19
19
|
* @param chainId - The chain ID for the quote.
|
|
20
20
|
* @returns The quote response.
|
|
21
21
|
*/
|
|
22
|
-
getQuote(
|
|
22
|
+
getQuote(args, options) {
|
|
23
23
|
var _a;
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.
|
|
25
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSwapsQuoteV2(args, options);
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
@@ -32,10 +32,23 @@ export default class ZeroX {
|
|
|
32
32
|
* @param chainId - The chain ID for the sources.
|
|
33
33
|
* @returns The sources response.
|
|
34
34
|
*/
|
|
35
|
-
getSources(
|
|
35
|
+
getSources(chainId, options) {
|
|
36
36
|
var _a;
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.
|
|
38
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSwapsSourcesV2({ chainId }, options);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the price of a token from the Swaps API.
|
|
43
|
+
*
|
|
44
|
+
* @param args - The arguments for the price.
|
|
45
|
+
* @param options - The options for the price.
|
|
46
|
+
* @returns The price response.
|
|
47
|
+
*/
|
|
48
|
+
getPrice(args, options) {
|
|
49
|
+
var _a;
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSwapsPrice(args, options);
|
|
39
52
|
});
|
|
40
53
|
}
|
|
41
54
|
}
|
|
@@ -13,7 +13,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
13
13
|
import ZeroX from '.';
|
|
14
14
|
import Mpc from '../../../mpc';
|
|
15
15
|
import portalMock from '../../../__mocks/portal/portal';
|
|
16
|
-
import { mockHost,
|
|
16
|
+
import { mockHost, mockSourcesRes, mockZeroExQuoteV2Request, mockZeroExQuoteV2Response, mockZeroExOptions, mockZeroExPriceRequest, mockZeroExPriceResponse, } from '../../../__mocks/constants';
|
|
17
17
|
describe('ZeroX', () => {
|
|
18
18
|
let zeroX;
|
|
19
19
|
let mpc;
|
|
@@ -26,35 +26,81 @@ describe('ZeroX', () => {
|
|
|
26
26
|
zeroX = new ZeroX({ mpc });
|
|
27
27
|
});
|
|
28
28
|
describe('getQuote', () => {
|
|
29
|
-
it('should correctly call mpc.
|
|
29
|
+
it('should correctly call mpc.getSwapsQuoteV2 with args and options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
30
|
const spy = jest
|
|
31
|
-
.spyOn(mpc, '
|
|
32
|
-
.mockResolvedValue(
|
|
33
|
-
const result = yield zeroX.getQuote(
|
|
31
|
+
.spyOn(mpc, 'getSwapsQuoteV2')
|
|
32
|
+
.mockResolvedValue(mockZeroExQuoteV2Response);
|
|
33
|
+
const result = yield zeroX.getQuote(mockZeroExQuoteV2Request, mockZeroExOptions);
|
|
34
34
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
35
|
-
expect(spy).toHaveBeenCalledWith(
|
|
36
|
-
expect(result).toEqual(
|
|
35
|
+
expect(spy).toHaveBeenCalledWith(mockZeroExQuoteV2Request, mockZeroExOptions);
|
|
36
|
+
expect(result).toEqual(mockZeroExQuoteV2Response);
|
|
37
37
|
}));
|
|
38
|
-
it('should
|
|
38
|
+
it('should correctly call mpc.getSwapsQuoteV2 without options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const spy = jest
|
|
40
|
+
.spyOn(mpc, 'getSwapsQuoteV2')
|
|
41
|
+
.mockResolvedValue(mockZeroExQuoteV2Response);
|
|
42
|
+
const result = yield zeroX.getQuote(mockZeroExQuoteV2Request);
|
|
43
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
44
|
+
expect(spy).toHaveBeenCalledWith(mockZeroExQuoteV2Request, undefined);
|
|
45
|
+
expect(result).toEqual(mockZeroExQuoteV2Response);
|
|
46
|
+
}));
|
|
47
|
+
it('should propagate errors from mpc.getSwapsQuoteV2', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
48
|
const error = new Error('Test error');
|
|
40
|
-
jest.spyOn(mpc, '
|
|
41
|
-
yield expect(zeroX.getQuote(
|
|
49
|
+
jest.spyOn(mpc, 'getSwapsQuoteV2').mockRejectedValue(error);
|
|
50
|
+
yield expect(zeroX.getQuote(mockZeroExQuoteV2Request)).rejects.toThrow('Test error');
|
|
42
51
|
}));
|
|
43
52
|
});
|
|
44
53
|
describe('getSources', () => {
|
|
45
|
-
it('should correctly call mpc.getSources', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
it('should correctly call mpc.getSources with chainId and apiKey', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
55
|
const spy = jest
|
|
47
|
-
.spyOn(mpc, '
|
|
56
|
+
.spyOn(mpc, 'getSwapsSourcesV2')
|
|
48
57
|
.mockResolvedValue(mockSourcesRes);
|
|
49
|
-
const result = yield zeroX.getSources('
|
|
58
|
+
const result = yield zeroX.getSources('eip155:1', {
|
|
59
|
+
zeroXApiKey: 'test-api-key',
|
|
60
|
+
});
|
|
61
|
+
console.log(`Result:`, result);
|
|
50
62
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
51
|
-
expect(spy).toHaveBeenCalledWith(
|
|
63
|
+
expect(spy).toHaveBeenCalledWith({ chainId: 'eip155:1' }, { zeroXApiKey: 'test-api-key' });
|
|
64
|
+
expect(result).toEqual(mockSourcesRes);
|
|
65
|
+
}));
|
|
66
|
+
it('should correctly call mpc.getSources without apiKey', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
const spy = jest
|
|
68
|
+
.spyOn(mpc, 'getSwapsSourcesV2')
|
|
69
|
+
.mockResolvedValue(mockSourcesRes);
|
|
70
|
+
const result = yield zeroX.getSources('eip155:1');
|
|
71
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
72
|
+
expect(spy).toHaveBeenCalledWith({ chainId: 'eip155:1' }, undefined);
|
|
52
73
|
expect(result).toEqual(mockSourcesRes);
|
|
53
74
|
}));
|
|
54
75
|
it('should propagate errors from mpc.getSources', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
76
|
const error = new Error('Test error');
|
|
56
|
-
jest.spyOn(mpc, '
|
|
57
|
-
yield expect(zeroX.getSources('
|
|
77
|
+
jest.spyOn(mpc, 'getSwapsSourcesV2').mockRejectedValue(error);
|
|
78
|
+
yield expect(zeroX.getSources('eip155:1')).rejects.toThrow('Test error');
|
|
79
|
+
}));
|
|
80
|
+
});
|
|
81
|
+
describe('getPrice', () => {
|
|
82
|
+
it('should correctly call mpc.getSwapsPrice with args and options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const spy = jest
|
|
84
|
+
.spyOn(mpc, 'getSwapsPrice')
|
|
85
|
+
.mockResolvedValue(mockZeroExPriceResponse);
|
|
86
|
+
const result = yield zeroX.getPrice(mockZeroExPriceRequest, mockZeroExOptions);
|
|
87
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
88
|
+
expect(spy).toHaveBeenCalledWith(mockZeroExPriceRequest, mockZeroExOptions);
|
|
89
|
+
expect(result).toEqual(mockZeroExPriceResponse);
|
|
90
|
+
}));
|
|
91
|
+
it('should correctly call mpc.getSwapsPrice without options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
+
const spy = jest
|
|
93
|
+
.spyOn(mpc, 'getSwapsPrice')
|
|
94
|
+
.mockResolvedValue(mockZeroExPriceResponse);
|
|
95
|
+
const result = yield zeroX.getPrice(mockZeroExPriceRequest);
|
|
96
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
97
|
+
expect(spy).toHaveBeenCalledWith(mockZeroExPriceRequest, undefined);
|
|
98
|
+
expect(result).toEqual(mockZeroExPriceResponse);
|
|
99
|
+
}));
|
|
100
|
+
it('should propagate errors from mpc.getSwapsPrice', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
+
const error = new Error('Test error');
|
|
102
|
+
jest.spyOn(mpc, 'getSwapsPrice').mockRejectedValue(error);
|
|
103
|
+
yield expect(zeroX.getPrice(mockZeroExPriceRequest)).rejects.toThrow('Test error');
|
|
58
104
|
}));
|
|
59
105
|
});
|
|
60
106
|
});
|
package/lib/esm/mpc/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { PortalMpcError } from './errors';
|
|
11
11
|
import { BackupMethods, } from '../index';
|
|
12
|
-
const WEB_SDK_VERSION = '3.6.0
|
|
12
|
+
const WEB_SDK_VERSION = '3.6.0';
|
|
13
13
|
class Mpc {
|
|
14
14
|
get ready() {
|
|
15
15
|
return this._ready;
|
|
@@ -670,7 +670,7 @@ class Mpc {
|
|
|
670
670
|
});
|
|
671
671
|
});
|
|
672
672
|
}
|
|
673
|
-
getQuote(
|
|
673
|
+
getQuote(chainId, args, apiKey) {
|
|
674
674
|
return __awaiter(this, void 0, void 0, function* () {
|
|
675
675
|
return new Promise((resolve, reject) => {
|
|
676
676
|
const handleGetQuote = (event) => {
|
|
@@ -707,7 +707,7 @@ class Mpc {
|
|
|
707
707
|
});
|
|
708
708
|
});
|
|
709
709
|
}
|
|
710
|
-
getSources(
|
|
710
|
+
getSources(chainId, apiKey) {
|
|
711
711
|
return __awaiter(this, void 0, void 0, function* () {
|
|
712
712
|
return new Promise((resolve, reject) => {
|
|
713
713
|
const handleGetSources = (event) => {
|
|
@@ -1109,6 +1109,36 @@ class Mpc {
|
|
|
1109
1109
|
});
|
|
1110
1110
|
});
|
|
1111
1111
|
}
|
|
1112
|
+
getSwapsQuoteV2(data, options) {
|
|
1113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1114
|
+
return this.handleRequestToIframeAndPost({
|
|
1115
|
+
methodMessage: 'portal:swaps:getQuoteV2',
|
|
1116
|
+
errorMessage: 'portal:swaps:getQuoteV2Error',
|
|
1117
|
+
resultMessage: 'portal:swaps:getQuoteV2Result',
|
|
1118
|
+
data: Object.assign(Object.assign({}, data), { options }),
|
|
1119
|
+
});
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
getSwapsSourcesV2(data, options) {
|
|
1123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1124
|
+
return this.handleRequestToIframeAndPost({
|
|
1125
|
+
methodMessage: 'portal:swaps:getSourcesV2',
|
|
1126
|
+
errorMessage: 'portal:swaps:getSourcesV2Error',
|
|
1127
|
+
resultMessage: 'portal:swaps:getSourcesV2Result',
|
|
1128
|
+
data: Object.assign(Object.assign({}, data), { options }),
|
|
1129
|
+
});
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
getSwapsPrice(data, options) {
|
|
1133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1134
|
+
return this.handleRequestToIframeAndPost({
|
|
1135
|
+
methodMessage: 'portal:swaps:getPrice',
|
|
1136
|
+
errorMessage: 'portal:swaps:getPriceError',
|
|
1137
|
+
resultMessage: 'portal:swaps:getPriceResult',
|
|
1138
|
+
data: Object.assign(Object.assign({}, data), { options }),
|
|
1139
|
+
});
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1112
1142
|
/***************************
|
|
1113
1143
|
* Private Methods
|
|
1114
1144
|
***************************/
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { BackupMethods, MpcStatuses, PortalCurve } from '../index';
|
|
5
5
|
import Mpc from '.';
|
|
6
|
-
import { mockAddress, mockApikey, mockAssets, mockBackupConfig, mockBackupIds, mockBalances, mockBuiltTransaction, mockCipherText, mockClientResponse, mockEjectResult, mockEjectPrivateKeysResult, mockEvaluationResult, mockHost, mockNFTs, mockOrgBackupShares, mockQuoteArgs, mockRpcUrl, mockSharesOnDevice, mockSimulationResult, mockTransactionToEvaluate, mockTransactionToSimulate, mockYieldXyzGetYieldsRequest, mockYieldXyzGetYieldsResponse, mockYieldXyzEnterRequest, mockYieldXyzEnterResponse, mockYieldXyzExitRequest, mockYieldXyzExitResponse, mockYieldXyzGetBalancesRequest, mockYieldXyzGetBalancesResponse, mockYieldXyzGetHistoricalActionsRequest, mockYieldXyzGetHistoricalActionsResponse, mockYieldXyzManageYieldRequest, mockYieldXyzManageYieldResponse, mockYieldXyzTrackTransactionRequest, mockYieldXyzTrackTransactionResponse, mockYieldXyzGetTransactionResponse, mockLifiGetRoutesRequest, mockLifiGetRoutesResponse, mockLifiGetQuoteRequest, mockLifiGetQuoteResponse, mockLifiGetStatusRequest, mockLifiGetStatusResponse, mockLifiGetRouteStepRequest, mockLifiGetRouteStepResponse, } from '../__mocks/constants';
|
|
6
|
+
import { mockAddress, mockApikey, mockAssets, mockBackupConfig, mockBackupIds, mockBalances, mockBuiltTransaction, mockCipherText, mockClientResponse, mockEjectResult, mockEjectPrivateKeysResult, mockEvaluationResult, mockHost, mockNFTs, mockOrgBackupShares, mockQuoteArgs, mockRpcUrl, mockSharesOnDevice, mockSimulationResult, mockTransactionToEvaluate, mockTransactionToSimulate, mockYieldXyzGetYieldsRequest, mockYieldXyzGetYieldsResponse, mockYieldXyzEnterRequest, mockYieldXyzEnterResponse, mockYieldXyzExitRequest, mockYieldXyzExitResponse, mockYieldXyzGetBalancesRequest, mockYieldXyzGetBalancesResponse, mockYieldXyzGetHistoricalActionsRequest, mockYieldXyzGetHistoricalActionsResponse, mockYieldXyzManageYieldRequest, mockYieldXyzManageYieldResponse, mockYieldXyzTrackTransactionRequest, mockYieldXyzTrackTransactionResponse, mockYieldXyzGetTransactionResponse, mockLifiGetRoutesRequest, mockLifiGetRoutesResponse, mockLifiGetQuoteRequest, mockLifiGetQuoteResponse, mockLifiGetStatusRequest, mockLifiGetStatusResponse, mockLifiGetRouteStepRequest, mockLifiGetRouteStepResponse, mockZeroExQuoteV2Request, mockZeroExQuoteV2Response, mockZeroExSourcesV2Request, mockZeroExSourcesV2Response, mockZeroExPriceRequest, mockZeroExPriceResponse, mockZeroExOptions, } from '../__mocks/constants';
|
|
7
7
|
import portalMock from '../__mocks/portal/portal';
|
|
8
8
|
import { PortalMpcError } from './errors';
|
|
9
9
|
describe('Mpc', () => {
|
|
@@ -1246,7 +1246,7 @@ describe('Mpc', () => {
|
|
|
1246
1246
|
}));
|
|
1247
1247
|
});
|
|
1248
1248
|
mpc
|
|
1249
|
-
.getQuote(
|
|
1249
|
+
.getQuote('eip155:1', mockQuoteArgs, mockApikey)
|
|
1250
1250
|
.then((data) => {
|
|
1251
1251
|
expect(data).toEqual(res);
|
|
1252
1252
|
done();
|
|
@@ -1281,7 +1281,7 @@ describe('Mpc', () => {
|
|
|
1281
1281
|
}));
|
|
1282
1282
|
});
|
|
1283
1283
|
mpc
|
|
1284
|
-
.getQuote(
|
|
1284
|
+
.getQuote('eip155:1', mockQuoteArgs, mockApikey)
|
|
1285
1285
|
.then(() => {
|
|
1286
1286
|
expect(0).toEqual(1);
|
|
1287
1287
|
done();
|
|
@@ -1314,7 +1314,7 @@ describe('Mpc', () => {
|
|
|
1314
1314
|
}));
|
|
1315
1315
|
});
|
|
1316
1316
|
mpc
|
|
1317
|
-
.getSources(
|
|
1317
|
+
.getSources('eip155:1', mockApikey)
|
|
1318
1318
|
.then((data) => {
|
|
1319
1319
|
expect(data).toEqual(res);
|
|
1320
1320
|
done();
|
|
@@ -1345,7 +1345,7 @@ describe('Mpc', () => {
|
|
|
1345
1345
|
}));
|
|
1346
1346
|
});
|
|
1347
1347
|
mpc
|
|
1348
|
-
.getSources(
|
|
1348
|
+
.getSources('eip155:1', mockApikey)
|
|
1349
1349
|
.then(() => {
|
|
1350
1350
|
expect(0).toEqual(1);
|
|
1351
1351
|
done();
|
|
@@ -2493,4 +2493,286 @@ describe('Mpc', () => {
|
|
|
2493
2493
|
});
|
|
2494
2494
|
});
|
|
2495
2495
|
});
|
|
2496
|
+
describe('getSwapsQuoteV2', () => {
|
|
2497
|
+
const args = mockZeroExQuoteV2Request;
|
|
2498
|
+
const options = mockZeroExOptions;
|
|
2499
|
+
const res = mockZeroExQuoteV2Response;
|
|
2500
|
+
it('should successfully return the quote', (done) => {
|
|
2501
|
+
var _a;
|
|
2502
|
+
jest
|
|
2503
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2504
|
+
.mockImplementation((message, origin) => {
|
|
2505
|
+
const { type, data } = message;
|
|
2506
|
+
expect(type).toEqual('portal:swaps:getQuoteV2');
|
|
2507
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2508
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2509
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2510
|
+
origin: mockHostOrigin,
|
|
2511
|
+
data: {
|
|
2512
|
+
type: 'portal:swaps:getQuoteV2Result',
|
|
2513
|
+
data: res,
|
|
2514
|
+
},
|
|
2515
|
+
}));
|
|
2516
|
+
});
|
|
2517
|
+
mpc
|
|
2518
|
+
.getSwapsQuoteV2(args, options)
|
|
2519
|
+
.then((data) => {
|
|
2520
|
+
expect(data).toEqual(res);
|
|
2521
|
+
done();
|
|
2522
|
+
})
|
|
2523
|
+
.catch((_) => {
|
|
2524
|
+
expect(0).toEqual(1);
|
|
2525
|
+
done();
|
|
2526
|
+
});
|
|
2527
|
+
});
|
|
2528
|
+
it('should successfully return the quote without options', (done) => {
|
|
2529
|
+
var _a;
|
|
2530
|
+
jest
|
|
2531
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2532
|
+
.mockImplementation((message, origin) => {
|
|
2533
|
+
const { type, data } = message;
|
|
2534
|
+
expect(type).toEqual('portal:swaps:getQuoteV2');
|
|
2535
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options: undefined }));
|
|
2536
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2537
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2538
|
+
origin: mockHostOrigin,
|
|
2539
|
+
data: {
|
|
2540
|
+
type: 'portal:swaps:getQuoteV2Result',
|
|
2541
|
+
data: res,
|
|
2542
|
+
},
|
|
2543
|
+
}));
|
|
2544
|
+
});
|
|
2545
|
+
mpc
|
|
2546
|
+
.getSwapsQuoteV2(args)
|
|
2547
|
+
.then((data) => {
|
|
2548
|
+
expect(data).toEqual(res);
|
|
2549
|
+
done();
|
|
2550
|
+
})
|
|
2551
|
+
.catch((_) => {
|
|
2552
|
+
expect(0).toEqual(1);
|
|
2553
|
+
done();
|
|
2554
|
+
});
|
|
2555
|
+
});
|
|
2556
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2557
|
+
var _a;
|
|
2558
|
+
jest
|
|
2559
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2560
|
+
.mockImplementationOnce((message, origin) => {
|
|
2561
|
+
const { type, data } = message;
|
|
2562
|
+
expect(type).toEqual('portal:swaps:getQuoteV2');
|
|
2563
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2564
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2565
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2566
|
+
origin: mockHostOrigin,
|
|
2567
|
+
data: {
|
|
2568
|
+
type: 'portal:swaps:getQuoteV2Error',
|
|
2569
|
+
data: {
|
|
2570
|
+
code: 1,
|
|
2571
|
+
message: 'test',
|
|
2572
|
+
},
|
|
2573
|
+
},
|
|
2574
|
+
}));
|
|
2575
|
+
});
|
|
2576
|
+
mpc
|
|
2577
|
+
.getSwapsQuoteV2(args, options)
|
|
2578
|
+
.then(() => {
|
|
2579
|
+
expect(0).toEqual(1);
|
|
2580
|
+
done();
|
|
2581
|
+
})
|
|
2582
|
+
.catch((e) => {
|
|
2583
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2584
|
+
expect(e.message).toEqual('test');
|
|
2585
|
+
expect(e.code).toEqual(1);
|
|
2586
|
+
done();
|
|
2587
|
+
});
|
|
2588
|
+
});
|
|
2589
|
+
});
|
|
2590
|
+
describe('getSwapsSourcesV2', () => {
|
|
2591
|
+
const args = mockZeroExSourcesV2Request;
|
|
2592
|
+
const options = mockZeroExOptions;
|
|
2593
|
+
const res = mockZeroExSourcesV2Response;
|
|
2594
|
+
it('should successfully return the sources', (done) => {
|
|
2595
|
+
var _a;
|
|
2596
|
+
jest
|
|
2597
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2598
|
+
.mockImplementation((message, origin) => {
|
|
2599
|
+
const { type, data } = message;
|
|
2600
|
+
expect(type).toEqual('portal:swaps:getSourcesV2');
|
|
2601
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2602
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2603
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2604
|
+
origin: mockHostOrigin,
|
|
2605
|
+
data: {
|
|
2606
|
+
type: 'portal:swaps:getSourcesV2Result',
|
|
2607
|
+
data: res,
|
|
2608
|
+
},
|
|
2609
|
+
}));
|
|
2610
|
+
});
|
|
2611
|
+
mpc
|
|
2612
|
+
.getSwapsSourcesV2(args, options)
|
|
2613
|
+
.then((data) => {
|
|
2614
|
+
expect(data).toEqual(res);
|
|
2615
|
+
done();
|
|
2616
|
+
})
|
|
2617
|
+
.catch((_) => {
|
|
2618
|
+
expect(0).toEqual(1);
|
|
2619
|
+
done();
|
|
2620
|
+
});
|
|
2621
|
+
});
|
|
2622
|
+
it('should successfully return the sources without options', (done) => {
|
|
2623
|
+
var _a;
|
|
2624
|
+
jest
|
|
2625
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2626
|
+
.mockImplementation((message, origin) => {
|
|
2627
|
+
const { type, data } = message;
|
|
2628
|
+
expect(type).toEqual('portal:swaps:getSourcesV2');
|
|
2629
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options: undefined }));
|
|
2630
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2631
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2632
|
+
origin: mockHostOrigin,
|
|
2633
|
+
data: {
|
|
2634
|
+
type: 'portal:swaps:getSourcesV2Result',
|
|
2635
|
+
data: res,
|
|
2636
|
+
},
|
|
2637
|
+
}));
|
|
2638
|
+
});
|
|
2639
|
+
mpc
|
|
2640
|
+
.getSwapsSourcesV2(args)
|
|
2641
|
+
.then((data) => {
|
|
2642
|
+
expect(data).toEqual(res);
|
|
2643
|
+
done();
|
|
2644
|
+
})
|
|
2645
|
+
.catch((_) => {
|
|
2646
|
+
expect(0).toEqual(1);
|
|
2647
|
+
done();
|
|
2648
|
+
});
|
|
2649
|
+
});
|
|
2650
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2651
|
+
var _a;
|
|
2652
|
+
jest
|
|
2653
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2654
|
+
.mockImplementationOnce((message, origin) => {
|
|
2655
|
+
const { type, data } = message;
|
|
2656
|
+
expect(type).toEqual('portal:swaps:getSourcesV2');
|
|
2657
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2658
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2659
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2660
|
+
origin: mockHostOrigin,
|
|
2661
|
+
data: {
|
|
2662
|
+
type: 'portal:swaps:getSourcesV2Error',
|
|
2663
|
+
data: {
|
|
2664
|
+
code: 1,
|
|
2665
|
+
message: 'test',
|
|
2666
|
+
},
|
|
2667
|
+
},
|
|
2668
|
+
}));
|
|
2669
|
+
});
|
|
2670
|
+
mpc
|
|
2671
|
+
.getSwapsSourcesV2(args, options)
|
|
2672
|
+
.then(() => {
|
|
2673
|
+
expect(0).toEqual(1);
|
|
2674
|
+
done();
|
|
2675
|
+
})
|
|
2676
|
+
.catch((e) => {
|
|
2677
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2678
|
+
expect(e.message).toEqual('test');
|
|
2679
|
+
expect(e.code).toEqual(1);
|
|
2680
|
+
done();
|
|
2681
|
+
});
|
|
2682
|
+
});
|
|
2683
|
+
});
|
|
2684
|
+
describe('getSwapsPrice', () => {
|
|
2685
|
+
const args = mockZeroExPriceRequest;
|
|
2686
|
+
const options = mockZeroExOptions;
|
|
2687
|
+
const res = mockZeroExPriceResponse;
|
|
2688
|
+
it('should successfully return the price', (done) => {
|
|
2689
|
+
var _a;
|
|
2690
|
+
jest
|
|
2691
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2692
|
+
.mockImplementation((message, origin) => {
|
|
2693
|
+
const { type, data } = message;
|
|
2694
|
+
expect(type).toEqual('portal:swaps:getPrice');
|
|
2695
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2696
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2697
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2698
|
+
origin: mockHostOrigin,
|
|
2699
|
+
data: {
|
|
2700
|
+
type: 'portal:swaps:getPriceResult',
|
|
2701
|
+
data: res,
|
|
2702
|
+
},
|
|
2703
|
+
}));
|
|
2704
|
+
});
|
|
2705
|
+
mpc
|
|
2706
|
+
.getSwapsPrice(args, options)
|
|
2707
|
+
.then((data) => {
|
|
2708
|
+
expect(data).toEqual(res);
|
|
2709
|
+
done();
|
|
2710
|
+
})
|
|
2711
|
+
.catch((_) => {
|
|
2712
|
+
expect(0).toEqual(1);
|
|
2713
|
+
done();
|
|
2714
|
+
});
|
|
2715
|
+
});
|
|
2716
|
+
it('should successfully return the price without options', (done) => {
|
|
2717
|
+
var _a;
|
|
2718
|
+
jest
|
|
2719
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2720
|
+
.mockImplementation((message, origin) => {
|
|
2721
|
+
const { type, data } = message;
|
|
2722
|
+
expect(type).toEqual('portal:swaps:getPrice');
|
|
2723
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options: undefined }));
|
|
2724
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2725
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2726
|
+
origin: mockHostOrigin,
|
|
2727
|
+
data: {
|
|
2728
|
+
type: 'portal:swaps:getPriceResult',
|
|
2729
|
+
data: res,
|
|
2730
|
+
},
|
|
2731
|
+
}));
|
|
2732
|
+
});
|
|
2733
|
+
mpc
|
|
2734
|
+
.getSwapsPrice(args)
|
|
2735
|
+
.then((data) => {
|
|
2736
|
+
expect(data).toEqual(res);
|
|
2737
|
+
done();
|
|
2738
|
+
})
|
|
2739
|
+
.catch((_) => {
|
|
2740
|
+
expect(0).toEqual(1);
|
|
2741
|
+
done();
|
|
2742
|
+
});
|
|
2743
|
+
});
|
|
2744
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2745
|
+
var _a;
|
|
2746
|
+
jest
|
|
2747
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2748
|
+
.mockImplementationOnce((message, origin) => {
|
|
2749
|
+
const { type, data } = message;
|
|
2750
|
+
expect(type).toEqual('portal:swaps:getPrice');
|
|
2751
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2752
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2753
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2754
|
+
origin: mockHostOrigin,
|
|
2755
|
+
data: {
|
|
2756
|
+
type: 'portal:swaps:getPriceError',
|
|
2757
|
+
data: {
|
|
2758
|
+
code: 1,
|
|
2759
|
+
message: 'test',
|
|
2760
|
+
},
|
|
2761
|
+
},
|
|
2762
|
+
}));
|
|
2763
|
+
});
|
|
2764
|
+
mpc
|
|
2765
|
+
.getSwapsPrice(args, options)
|
|
2766
|
+
.then(() => {
|
|
2767
|
+
expect(0).toEqual(1);
|
|
2768
|
+
done();
|
|
2769
|
+
})
|
|
2770
|
+
.catch((e) => {
|
|
2771
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2772
|
+
expect(e.message).toEqual('test');
|
|
2773
|
+
expect(e.code).toEqual(1);
|
|
2774
|
+
done();
|
|
2775
|
+
});
|
|
2776
|
+
});
|
|
2777
|
+
});
|
|
2496
2778
|
});
|
|
@@ -257,7 +257,7 @@ class Provider {
|
|
|
257
257
|
* @param args The arguments of the request being made
|
|
258
258
|
* @returns Promise<any>
|
|
259
259
|
*/
|
|
260
|
-
request({ chainId: requestChainId, method, params, }) {
|
|
260
|
+
request({ chainId: requestChainId, method, params, sponsorGas, }) {
|
|
261
261
|
return __awaiter(this, void 0, void 0, function* () {
|
|
262
262
|
const isSignerMethod = signerMethods.includes(method);
|
|
263
263
|
const chainId = this.getCAIP2ChainId(requestChainId);
|
|
@@ -285,6 +285,7 @@ class Provider {
|
|
|
285
285
|
chainId,
|
|
286
286
|
method,
|
|
287
287
|
params,
|
|
288
|
+
sponsorGas,
|
|
288
289
|
});
|
|
289
290
|
if (transactionHash) {
|
|
290
291
|
this.emit('portal_signatureReceived', {
|
|
@@ -400,7 +401,7 @@ class Provider {
|
|
|
400
401
|
* @param args The arguments of the request being made
|
|
401
402
|
* @returns Promise<any>
|
|
402
403
|
*/
|
|
403
|
-
handleSigningRequest({ chainId, method, params, }) {
|
|
404
|
+
handleSigningRequest({ chainId, method, params, sponsorGas, }) {
|
|
404
405
|
return __awaiter(this, void 0, void 0, function* () {
|
|
405
406
|
const isApproved = passiveSignerMethods.includes(method)
|
|
406
407
|
? true
|
|
@@ -432,6 +433,7 @@ class Provider {
|
|
|
432
433
|
method,
|
|
433
434
|
params: this.buildParams(method, params),
|
|
434
435
|
rpcUrl: this.portal.getRpcUrl(chainId),
|
|
436
|
+
sponsorGas,
|
|
435
437
|
});
|
|
436
438
|
return result;
|
|
437
439
|
}
|
|
@@ -445,6 +447,7 @@ class Provider {
|
|
|
445
447
|
method,
|
|
446
448
|
params: this.buildParams(method, params),
|
|
447
449
|
rpcUrl: this.portal.getRpcUrl(chainId),
|
|
450
|
+
sponsorGas,
|
|
448
451
|
});
|
|
449
452
|
return result;
|
|
450
453
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Portal MPC Support for Web",
|
|
4
4
|
"author": "Portal Labs, Inc.",
|
|
5
5
|
"homepage": "https://portalhq.io/",
|
|
6
|
-
"version": "3.6.0
|
|
6
|
+
"version": "3.6.0",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"main": "lib/commonjs/index",
|
|
9
9
|
"module": "lib/esm/index",
|
|
@@ -49,6 +49,5 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@solana/web3.js": "^1.91.8"
|
|
52
|
-
}
|
|
53
|
-
"stableVersion": "3.5.2"
|
|
52
|
+
}
|
|
54
53
|
}
|