@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
package/lib/commonjs/index.js
CHANGED
|
@@ -361,6 +361,7 @@ class Portal {
|
|
|
361
361
|
chainId,
|
|
362
362
|
method: 'eth_sendTransaction',
|
|
363
363
|
params: [buildTxResponse.transaction],
|
|
364
|
+
sponsorGas: params.sponsorGas,
|
|
364
365
|
});
|
|
365
366
|
break;
|
|
366
367
|
}
|
|
@@ -369,6 +370,7 @@ class Portal {
|
|
|
369
370
|
chainId,
|
|
370
371
|
method: 'sol_signAndSendTransaction',
|
|
371
372
|
params: [buildTxResponse.transaction],
|
|
373
|
+
sponsorGas: params.sponsorGas,
|
|
372
374
|
});
|
|
373
375
|
break;
|
|
374
376
|
}
|
|
@@ -711,7 +713,7 @@ class Portal {
|
|
|
711
713
|
getQuote(apiKey, args, chainId) {
|
|
712
714
|
var _a;
|
|
713
715
|
return __awaiter(this, void 0, void 0, function* () {
|
|
714
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getQuote(
|
|
716
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getQuote(chainId, args, apiKey);
|
|
715
717
|
});
|
|
716
718
|
}
|
|
717
719
|
/**
|
|
@@ -720,7 +722,7 @@ class Portal {
|
|
|
720
722
|
getSources(apiKey, chainId) {
|
|
721
723
|
var _a;
|
|
722
724
|
return __awaiter(this, void 0, void 0, function* () {
|
|
723
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSources(
|
|
725
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSources(chainId, apiKey);
|
|
724
726
|
});
|
|
725
727
|
}
|
|
726
728
|
/*******************************
|
|
@@ -565,14 +565,14 @@ describe('Portal', () => {
|
|
|
565
565
|
it('should correctly call mpc.getQuote', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
566
566
|
yield portal.getQuote('test', constants_1.mockQuoteArgs, 'eip155:1');
|
|
567
567
|
expect(portal.mpc.getQuote).toHaveBeenCalledTimes(1);
|
|
568
|
-
expect(portal.mpc.getQuote).toHaveBeenCalledWith('
|
|
568
|
+
expect(portal.mpc.getQuote).toHaveBeenCalledWith('eip155:1', constants_1.mockQuoteArgs, 'test');
|
|
569
569
|
}));
|
|
570
570
|
});
|
|
571
571
|
describe('getSources', () => {
|
|
572
572
|
it('should correctly call mpc.getSources', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
573
573
|
yield portal.getSources('test', 'eip155:1');
|
|
574
574
|
expect(portal.mpc.getSources).toHaveBeenCalledTimes(1);
|
|
575
|
-
expect(portal.mpc.getSources).toHaveBeenCalledWith('
|
|
575
|
+
expect(portal.mpc.getSources).toHaveBeenCalledWith('eip155:1', 'test');
|
|
576
576
|
}));
|
|
577
577
|
});
|
|
578
578
|
describe('storedClientBackupShare', () => {
|
|
@@ -21,10 +21,10 @@ class ZeroX {
|
|
|
21
21
|
* @param chainId - The chain ID for the quote.
|
|
22
22
|
* @returns The quote response.
|
|
23
23
|
*/
|
|
24
|
-
getQuote(
|
|
24
|
+
getQuote(args, options) {
|
|
25
25
|
var _a;
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.
|
|
27
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSwapsQuoteV2(args, options);
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
@@ -34,10 +34,23 @@ class ZeroX {
|
|
|
34
34
|
* @param chainId - The chain ID for the sources.
|
|
35
35
|
* @returns The sources response.
|
|
36
36
|
*/
|
|
37
|
-
getSources(
|
|
37
|
+
getSources(chainId, options) {
|
|
38
38
|
var _a;
|
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.
|
|
40
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSwapsSourcesV2({ chainId }, options);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get the price of a token from the Swaps API.
|
|
45
|
+
*
|
|
46
|
+
* @param args - The arguments for the price.
|
|
47
|
+
* @param options - The options for the price.
|
|
48
|
+
* @returns The price response.
|
|
49
|
+
*/
|
|
50
|
+
getPrice(args, options) {
|
|
51
|
+
var _a;
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSwapsPrice(args, options);
|
|
41
54
|
});
|
|
42
55
|
}
|
|
43
56
|
}
|
|
@@ -31,35 +31,81 @@ describe('ZeroX', () => {
|
|
|
31
31
|
zeroX = new _1.default({ mpc });
|
|
32
32
|
});
|
|
33
33
|
describe('getQuote', () => {
|
|
34
|
-
it('should correctly call mpc.
|
|
34
|
+
it('should correctly call mpc.getSwapsQuoteV2 with args and options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
35
|
const spy = jest
|
|
36
|
-
.spyOn(mpc, '
|
|
37
|
-
.mockResolvedValue(constants_1.
|
|
38
|
-
const result = yield zeroX.getQuote(
|
|
36
|
+
.spyOn(mpc, 'getSwapsQuoteV2')
|
|
37
|
+
.mockResolvedValue(constants_1.mockZeroExQuoteV2Response);
|
|
38
|
+
const result = yield zeroX.getQuote(constants_1.mockZeroExQuoteV2Request, constants_1.mockZeroExOptions);
|
|
39
39
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
40
|
-
expect(spy).toHaveBeenCalledWith(
|
|
41
|
-
expect(result).toEqual(constants_1.
|
|
40
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockZeroExQuoteV2Request, constants_1.mockZeroExOptions);
|
|
41
|
+
expect(result).toEqual(constants_1.mockZeroExQuoteV2Response);
|
|
42
42
|
}));
|
|
43
|
-
it('should
|
|
43
|
+
it('should correctly call mpc.getSwapsQuoteV2 without options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
const spy = jest
|
|
45
|
+
.spyOn(mpc, 'getSwapsQuoteV2')
|
|
46
|
+
.mockResolvedValue(constants_1.mockZeroExQuoteV2Response);
|
|
47
|
+
const result = yield zeroX.getQuote(constants_1.mockZeroExQuoteV2Request);
|
|
48
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
49
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockZeroExQuoteV2Request, undefined);
|
|
50
|
+
expect(result).toEqual(constants_1.mockZeroExQuoteV2Response);
|
|
51
|
+
}));
|
|
52
|
+
it('should propagate errors from mpc.getSwapsQuoteV2', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
53
|
const error = new Error('Test error');
|
|
45
|
-
jest.spyOn(mpc, '
|
|
46
|
-
yield expect(zeroX.getQuote(
|
|
54
|
+
jest.spyOn(mpc, 'getSwapsQuoteV2').mockRejectedValue(error);
|
|
55
|
+
yield expect(zeroX.getQuote(constants_1.mockZeroExQuoteV2Request)).rejects.toThrow('Test error');
|
|
47
56
|
}));
|
|
48
57
|
});
|
|
49
58
|
describe('getSources', () => {
|
|
50
|
-
it('should correctly call mpc.getSources', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
it('should correctly call mpc.getSources with chainId and apiKey', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
60
|
const spy = jest
|
|
52
|
-
.spyOn(mpc, '
|
|
61
|
+
.spyOn(mpc, 'getSwapsSourcesV2')
|
|
53
62
|
.mockResolvedValue(constants_1.mockSourcesRes);
|
|
54
|
-
const result = yield zeroX.getSources('
|
|
63
|
+
const result = yield zeroX.getSources('eip155:1', {
|
|
64
|
+
zeroXApiKey: 'test-api-key',
|
|
65
|
+
});
|
|
66
|
+
console.log(`Result:`, result);
|
|
55
67
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
56
|
-
expect(spy).toHaveBeenCalledWith(
|
|
68
|
+
expect(spy).toHaveBeenCalledWith({ chainId: 'eip155:1' }, { zeroXApiKey: 'test-api-key' });
|
|
69
|
+
expect(result).toEqual(constants_1.mockSourcesRes);
|
|
70
|
+
}));
|
|
71
|
+
it('should correctly call mpc.getSources without apiKey', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
const spy = jest
|
|
73
|
+
.spyOn(mpc, 'getSwapsSourcesV2')
|
|
74
|
+
.mockResolvedValue(constants_1.mockSourcesRes);
|
|
75
|
+
const result = yield zeroX.getSources('eip155:1');
|
|
76
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
77
|
+
expect(spy).toHaveBeenCalledWith({ chainId: 'eip155:1' }, undefined);
|
|
57
78
|
expect(result).toEqual(constants_1.mockSourcesRes);
|
|
58
79
|
}));
|
|
59
80
|
it('should propagate errors from mpc.getSources', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
81
|
const error = new Error('Test error');
|
|
61
|
-
jest.spyOn(mpc, '
|
|
62
|
-
yield expect(zeroX.getSources('
|
|
82
|
+
jest.spyOn(mpc, 'getSwapsSourcesV2').mockRejectedValue(error);
|
|
83
|
+
yield expect(zeroX.getSources('eip155:1')).rejects.toThrow('Test error');
|
|
84
|
+
}));
|
|
85
|
+
});
|
|
86
|
+
describe('getPrice', () => {
|
|
87
|
+
it('should correctly call mpc.getSwapsPrice with args and options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
+
const spy = jest
|
|
89
|
+
.spyOn(mpc, 'getSwapsPrice')
|
|
90
|
+
.mockResolvedValue(constants_1.mockZeroExPriceResponse);
|
|
91
|
+
const result = yield zeroX.getPrice(constants_1.mockZeroExPriceRequest, constants_1.mockZeroExOptions);
|
|
92
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
93
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockZeroExPriceRequest, constants_1.mockZeroExOptions);
|
|
94
|
+
expect(result).toEqual(constants_1.mockZeroExPriceResponse);
|
|
95
|
+
}));
|
|
96
|
+
it('should correctly call mpc.getSwapsPrice without options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
const spy = jest
|
|
98
|
+
.spyOn(mpc, 'getSwapsPrice')
|
|
99
|
+
.mockResolvedValue(constants_1.mockZeroExPriceResponse);
|
|
100
|
+
const result = yield zeroX.getPrice(constants_1.mockZeroExPriceRequest);
|
|
101
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
102
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockZeroExPriceRequest, undefined);
|
|
103
|
+
expect(result).toEqual(constants_1.mockZeroExPriceResponse);
|
|
104
|
+
}));
|
|
105
|
+
it('should propagate errors from mpc.getSwapsPrice', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
+
const error = new Error('Test error');
|
|
107
|
+
jest.spyOn(mpc, 'getSwapsPrice').mockRejectedValue(error);
|
|
108
|
+
yield expect(zeroX.getPrice(constants_1.mockZeroExPriceRequest)).rejects.toThrow('Test error');
|
|
63
109
|
}));
|
|
64
110
|
});
|
|
65
111
|
});
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.MpcErrorCodes = exports.MpcError = void 0;
|
|
13
13
|
const errors_1 = require("./errors");
|
|
14
14
|
const index_1 = require("../index");
|
|
15
|
-
const WEB_SDK_VERSION = '3.6.0
|
|
15
|
+
const WEB_SDK_VERSION = '3.6.0';
|
|
16
16
|
class Mpc {
|
|
17
17
|
get ready() {
|
|
18
18
|
return this._ready;
|
|
@@ -673,7 +673,7 @@ class Mpc {
|
|
|
673
673
|
});
|
|
674
674
|
});
|
|
675
675
|
}
|
|
676
|
-
getQuote(
|
|
676
|
+
getQuote(chainId, args, apiKey) {
|
|
677
677
|
return __awaiter(this, void 0, void 0, function* () {
|
|
678
678
|
return new Promise((resolve, reject) => {
|
|
679
679
|
const handleGetQuote = (event) => {
|
|
@@ -710,7 +710,7 @@ class Mpc {
|
|
|
710
710
|
});
|
|
711
711
|
});
|
|
712
712
|
}
|
|
713
|
-
getSources(
|
|
713
|
+
getSources(chainId, apiKey) {
|
|
714
714
|
return __awaiter(this, void 0, void 0, function* () {
|
|
715
715
|
return new Promise((resolve, reject) => {
|
|
716
716
|
const handleGetSources = (event) => {
|
|
@@ -1112,6 +1112,36 @@ class Mpc {
|
|
|
1112
1112
|
});
|
|
1113
1113
|
});
|
|
1114
1114
|
}
|
|
1115
|
+
getSwapsQuoteV2(data, options) {
|
|
1116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1117
|
+
return this.handleRequestToIframeAndPost({
|
|
1118
|
+
methodMessage: 'portal:swaps:getQuoteV2',
|
|
1119
|
+
errorMessage: 'portal:swaps:getQuoteV2Error',
|
|
1120
|
+
resultMessage: 'portal:swaps:getQuoteV2Result',
|
|
1121
|
+
data: Object.assign(Object.assign({}, data), { options }),
|
|
1122
|
+
});
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
getSwapsSourcesV2(data, options) {
|
|
1126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1127
|
+
return this.handleRequestToIframeAndPost({
|
|
1128
|
+
methodMessage: 'portal:swaps:getSourcesV2',
|
|
1129
|
+
errorMessage: 'portal:swaps:getSourcesV2Error',
|
|
1130
|
+
resultMessage: 'portal:swaps:getSourcesV2Result',
|
|
1131
|
+
data: Object.assign(Object.assign({}, data), { options }),
|
|
1132
|
+
});
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
getSwapsPrice(data, options) {
|
|
1136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1137
|
+
return this.handleRequestToIframeAndPost({
|
|
1138
|
+
methodMessage: 'portal:swaps:getPrice',
|
|
1139
|
+
errorMessage: 'portal:swaps:getPriceError',
|
|
1140
|
+
resultMessage: 'portal:swaps:getPriceResult',
|
|
1141
|
+
data: Object.assign(Object.assign({}, data), { options }),
|
|
1142
|
+
});
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1115
1145
|
/***************************
|
|
1116
1146
|
* Private Methods
|
|
1117
1147
|
***************************/
|
|
@@ -1251,7 +1251,7 @@ describe('Mpc', () => {
|
|
|
1251
1251
|
}));
|
|
1252
1252
|
});
|
|
1253
1253
|
mpc
|
|
1254
|
-
.getQuote(
|
|
1254
|
+
.getQuote('eip155:1', constants_1.mockQuoteArgs, constants_1.mockApikey)
|
|
1255
1255
|
.then((data) => {
|
|
1256
1256
|
expect(data).toEqual(res);
|
|
1257
1257
|
done();
|
|
@@ -1286,7 +1286,7 @@ describe('Mpc', () => {
|
|
|
1286
1286
|
}));
|
|
1287
1287
|
});
|
|
1288
1288
|
mpc
|
|
1289
|
-
.getQuote(
|
|
1289
|
+
.getQuote('eip155:1', constants_1.mockQuoteArgs, constants_1.mockApikey)
|
|
1290
1290
|
.then(() => {
|
|
1291
1291
|
expect(0).toEqual(1);
|
|
1292
1292
|
done();
|
|
@@ -1319,7 +1319,7 @@ describe('Mpc', () => {
|
|
|
1319
1319
|
}));
|
|
1320
1320
|
});
|
|
1321
1321
|
mpc
|
|
1322
|
-
.getSources(
|
|
1322
|
+
.getSources('eip155:1', constants_1.mockApikey)
|
|
1323
1323
|
.then((data) => {
|
|
1324
1324
|
expect(data).toEqual(res);
|
|
1325
1325
|
done();
|
|
@@ -1350,7 +1350,7 @@ describe('Mpc', () => {
|
|
|
1350
1350
|
}));
|
|
1351
1351
|
});
|
|
1352
1352
|
mpc
|
|
1353
|
-
.getSources(
|
|
1353
|
+
.getSources('eip155:1', constants_1.mockApikey)
|
|
1354
1354
|
.then(() => {
|
|
1355
1355
|
expect(0).toEqual(1);
|
|
1356
1356
|
done();
|
|
@@ -2498,4 +2498,286 @@ describe('Mpc', () => {
|
|
|
2498
2498
|
});
|
|
2499
2499
|
});
|
|
2500
2500
|
});
|
|
2501
|
+
describe('getSwapsQuoteV2', () => {
|
|
2502
|
+
const args = constants_1.mockZeroExQuoteV2Request;
|
|
2503
|
+
const options = constants_1.mockZeroExOptions;
|
|
2504
|
+
const res = constants_1.mockZeroExQuoteV2Response;
|
|
2505
|
+
it('should successfully return the quote', (done) => {
|
|
2506
|
+
var _a;
|
|
2507
|
+
jest
|
|
2508
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2509
|
+
.mockImplementation((message, origin) => {
|
|
2510
|
+
const { type, data } = message;
|
|
2511
|
+
expect(type).toEqual('portal:swaps:getQuoteV2');
|
|
2512
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2513
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2514
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2515
|
+
origin: mockHostOrigin,
|
|
2516
|
+
data: {
|
|
2517
|
+
type: 'portal:swaps:getQuoteV2Result',
|
|
2518
|
+
data: res,
|
|
2519
|
+
},
|
|
2520
|
+
}));
|
|
2521
|
+
});
|
|
2522
|
+
mpc
|
|
2523
|
+
.getSwapsQuoteV2(args, options)
|
|
2524
|
+
.then((data) => {
|
|
2525
|
+
expect(data).toEqual(res);
|
|
2526
|
+
done();
|
|
2527
|
+
})
|
|
2528
|
+
.catch((_) => {
|
|
2529
|
+
expect(0).toEqual(1);
|
|
2530
|
+
done();
|
|
2531
|
+
});
|
|
2532
|
+
});
|
|
2533
|
+
it('should successfully return the quote without options', (done) => {
|
|
2534
|
+
var _a;
|
|
2535
|
+
jest
|
|
2536
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2537
|
+
.mockImplementation((message, origin) => {
|
|
2538
|
+
const { type, data } = message;
|
|
2539
|
+
expect(type).toEqual('portal:swaps:getQuoteV2');
|
|
2540
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options: undefined }));
|
|
2541
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2542
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2543
|
+
origin: mockHostOrigin,
|
|
2544
|
+
data: {
|
|
2545
|
+
type: 'portal:swaps:getQuoteV2Result',
|
|
2546
|
+
data: res,
|
|
2547
|
+
},
|
|
2548
|
+
}));
|
|
2549
|
+
});
|
|
2550
|
+
mpc
|
|
2551
|
+
.getSwapsQuoteV2(args)
|
|
2552
|
+
.then((data) => {
|
|
2553
|
+
expect(data).toEqual(res);
|
|
2554
|
+
done();
|
|
2555
|
+
})
|
|
2556
|
+
.catch((_) => {
|
|
2557
|
+
expect(0).toEqual(1);
|
|
2558
|
+
done();
|
|
2559
|
+
});
|
|
2560
|
+
});
|
|
2561
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2562
|
+
var _a;
|
|
2563
|
+
jest
|
|
2564
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2565
|
+
.mockImplementationOnce((message, origin) => {
|
|
2566
|
+
const { type, data } = message;
|
|
2567
|
+
expect(type).toEqual('portal:swaps:getQuoteV2');
|
|
2568
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2569
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2570
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2571
|
+
origin: mockHostOrigin,
|
|
2572
|
+
data: {
|
|
2573
|
+
type: 'portal:swaps:getQuoteV2Error',
|
|
2574
|
+
data: {
|
|
2575
|
+
code: 1,
|
|
2576
|
+
message: 'test',
|
|
2577
|
+
},
|
|
2578
|
+
},
|
|
2579
|
+
}));
|
|
2580
|
+
});
|
|
2581
|
+
mpc
|
|
2582
|
+
.getSwapsQuoteV2(args, options)
|
|
2583
|
+
.then(() => {
|
|
2584
|
+
expect(0).toEqual(1);
|
|
2585
|
+
done();
|
|
2586
|
+
})
|
|
2587
|
+
.catch((e) => {
|
|
2588
|
+
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
2589
|
+
expect(e.message).toEqual('test');
|
|
2590
|
+
expect(e.code).toEqual(1);
|
|
2591
|
+
done();
|
|
2592
|
+
});
|
|
2593
|
+
});
|
|
2594
|
+
});
|
|
2595
|
+
describe('getSwapsSourcesV2', () => {
|
|
2596
|
+
const args = constants_1.mockZeroExSourcesV2Request;
|
|
2597
|
+
const options = constants_1.mockZeroExOptions;
|
|
2598
|
+
const res = constants_1.mockZeroExSourcesV2Response;
|
|
2599
|
+
it('should successfully return the sources', (done) => {
|
|
2600
|
+
var _a;
|
|
2601
|
+
jest
|
|
2602
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2603
|
+
.mockImplementation((message, origin) => {
|
|
2604
|
+
const { type, data } = message;
|
|
2605
|
+
expect(type).toEqual('portal:swaps:getSourcesV2');
|
|
2606
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2607
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2608
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2609
|
+
origin: mockHostOrigin,
|
|
2610
|
+
data: {
|
|
2611
|
+
type: 'portal:swaps:getSourcesV2Result',
|
|
2612
|
+
data: res,
|
|
2613
|
+
},
|
|
2614
|
+
}));
|
|
2615
|
+
});
|
|
2616
|
+
mpc
|
|
2617
|
+
.getSwapsSourcesV2(args, options)
|
|
2618
|
+
.then((data) => {
|
|
2619
|
+
expect(data).toEqual(res);
|
|
2620
|
+
done();
|
|
2621
|
+
})
|
|
2622
|
+
.catch((_) => {
|
|
2623
|
+
expect(0).toEqual(1);
|
|
2624
|
+
done();
|
|
2625
|
+
});
|
|
2626
|
+
});
|
|
2627
|
+
it('should successfully return the sources without options', (done) => {
|
|
2628
|
+
var _a;
|
|
2629
|
+
jest
|
|
2630
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2631
|
+
.mockImplementation((message, origin) => {
|
|
2632
|
+
const { type, data } = message;
|
|
2633
|
+
expect(type).toEqual('portal:swaps:getSourcesV2');
|
|
2634
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options: undefined }));
|
|
2635
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2636
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2637
|
+
origin: mockHostOrigin,
|
|
2638
|
+
data: {
|
|
2639
|
+
type: 'portal:swaps:getSourcesV2Result',
|
|
2640
|
+
data: res,
|
|
2641
|
+
},
|
|
2642
|
+
}));
|
|
2643
|
+
});
|
|
2644
|
+
mpc
|
|
2645
|
+
.getSwapsSourcesV2(args)
|
|
2646
|
+
.then((data) => {
|
|
2647
|
+
expect(data).toEqual(res);
|
|
2648
|
+
done();
|
|
2649
|
+
})
|
|
2650
|
+
.catch((_) => {
|
|
2651
|
+
expect(0).toEqual(1);
|
|
2652
|
+
done();
|
|
2653
|
+
});
|
|
2654
|
+
});
|
|
2655
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2656
|
+
var _a;
|
|
2657
|
+
jest
|
|
2658
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2659
|
+
.mockImplementationOnce((message, origin) => {
|
|
2660
|
+
const { type, data } = message;
|
|
2661
|
+
expect(type).toEqual('portal:swaps:getSourcesV2');
|
|
2662
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2663
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2664
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2665
|
+
origin: mockHostOrigin,
|
|
2666
|
+
data: {
|
|
2667
|
+
type: 'portal:swaps:getSourcesV2Error',
|
|
2668
|
+
data: {
|
|
2669
|
+
code: 1,
|
|
2670
|
+
message: 'test',
|
|
2671
|
+
},
|
|
2672
|
+
},
|
|
2673
|
+
}));
|
|
2674
|
+
});
|
|
2675
|
+
mpc
|
|
2676
|
+
.getSwapsSourcesV2(args, options)
|
|
2677
|
+
.then(() => {
|
|
2678
|
+
expect(0).toEqual(1);
|
|
2679
|
+
done();
|
|
2680
|
+
})
|
|
2681
|
+
.catch((e) => {
|
|
2682
|
+
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
2683
|
+
expect(e.message).toEqual('test');
|
|
2684
|
+
expect(e.code).toEqual(1);
|
|
2685
|
+
done();
|
|
2686
|
+
});
|
|
2687
|
+
});
|
|
2688
|
+
});
|
|
2689
|
+
describe('getSwapsPrice', () => {
|
|
2690
|
+
const args = constants_1.mockZeroExPriceRequest;
|
|
2691
|
+
const options = constants_1.mockZeroExOptions;
|
|
2692
|
+
const res = constants_1.mockZeroExPriceResponse;
|
|
2693
|
+
it('should successfully return the price', (done) => {
|
|
2694
|
+
var _a;
|
|
2695
|
+
jest
|
|
2696
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2697
|
+
.mockImplementation((message, origin) => {
|
|
2698
|
+
const { type, data } = message;
|
|
2699
|
+
expect(type).toEqual('portal:swaps:getPrice');
|
|
2700
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2701
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2702
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2703
|
+
origin: mockHostOrigin,
|
|
2704
|
+
data: {
|
|
2705
|
+
type: 'portal:swaps:getPriceResult',
|
|
2706
|
+
data: res,
|
|
2707
|
+
},
|
|
2708
|
+
}));
|
|
2709
|
+
});
|
|
2710
|
+
mpc
|
|
2711
|
+
.getSwapsPrice(args, options)
|
|
2712
|
+
.then((data) => {
|
|
2713
|
+
expect(data).toEqual(res);
|
|
2714
|
+
done();
|
|
2715
|
+
})
|
|
2716
|
+
.catch((_) => {
|
|
2717
|
+
expect(0).toEqual(1);
|
|
2718
|
+
done();
|
|
2719
|
+
});
|
|
2720
|
+
});
|
|
2721
|
+
it('should successfully return the price without options', (done) => {
|
|
2722
|
+
var _a;
|
|
2723
|
+
jest
|
|
2724
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2725
|
+
.mockImplementation((message, origin) => {
|
|
2726
|
+
const { type, data } = message;
|
|
2727
|
+
expect(type).toEqual('portal:swaps:getPrice');
|
|
2728
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options: undefined }));
|
|
2729
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2730
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2731
|
+
origin: mockHostOrigin,
|
|
2732
|
+
data: {
|
|
2733
|
+
type: 'portal:swaps:getPriceResult',
|
|
2734
|
+
data: res,
|
|
2735
|
+
},
|
|
2736
|
+
}));
|
|
2737
|
+
});
|
|
2738
|
+
mpc
|
|
2739
|
+
.getSwapsPrice(args)
|
|
2740
|
+
.then((data) => {
|
|
2741
|
+
expect(data).toEqual(res);
|
|
2742
|
+
done();
|
|
2743
|
+
})
|
|
2744
|
+
.catch((_) => {
|
|
2745
|
+
expect(0).toEqual(1);
|
|
2746
|
+
done();
|
|
2747
|
+
});
|
|
2748
|
+
});
|
|
2749
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2750
|
+
var _a;
|
|
2751
|
+
jest
|
|
2752
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2753
|
+
.mockImplementationOnce((message, origin) => {
|
|
2754
|
+
const { type, data } = message;
|
|
2755
|
+
expect(type).toEqual('portal:swaps:getPrice');
|
|
2756
|
+
expect(data).toEqual(Object.assign(Object.assign({}, args), { options }));
|
|
2757
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2758
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2759
|
+
origin: mockHostOrigin,
|
|
2760
|
+
data: {
|
|
2761
|
+
type: 'portal:swaps:getPriceError',
|
|
2762
|
+
data: {
|
|
2763
|
+
code: 1,
|
|
2764
|
+
message: 'test',
|
|
2765
|
+
},
|
|
2766
|
+
},
|
|
2767
|
+
}));
|
|
2768
|
+
});
|
|
2769
|
+
mpc
|
|
2770
|
+
.getSwapsPrice(args, options)
|
|
2771
|
+
.then(() => {
|
|
2772
|
+
expect(0).toEqual(1);
|
|
2773
|
+
done();
|
|
2774
|
+
})
|
|
2775
|
+
.catch((e) => {
|
|
2776
|
+
expect(e).toBeInstanceOf(errors_1.PortalMpcError);
|
|
2777
|
+
expect(e.message).toEqual('test');
|
|
2778
|
+
expect(e.code).toEqual(1);
|
|
2779
|
+
done();
|
|
2780
|
+
});
|
|
2781
|
+
});
|
|
2782
|
+
});
|
|
2501
2783
|
});
|
|
@@ -260,7 +260,7 @@ class Provider {
|
|
|
260
260
|
* @param args The arguments of the request being made
|
|
261
261
|
* @returns Promise<any>
|
|
262
262
|
*/
|
|
263
|
-
request({ chainId: requestChainId, method, params, }) {
|
|
263
|
+
request({ chainId: requestChainId, method, params, sponsorGas, }) {
|
|
264
264
|
return __awaiter(this, void 0, void 0, function* () {
|
|
265
265
|
const isSignerMethod = signerMethods.includes(method);
|
|
266
266
|
const chainId = this.getCAIP2ChainId(requestChainId);
|
|
@@ -288,6 +288,7 @@ class Provider {
|
|
|
288
288
|
chainId,
|
|
289
289
|
method,
|
|
290
290
|
params,
|
|
291
|
+
sponsorGas,
|
|
291
292
|
});
|
|
292
293
|
if (transactionHash) {
|
|
293
294
|
this.emit('portal_signatureReceived', {
|
|
@@ -403,7 +404,7 @@ class Provider {
|
|
|
403
404
|
* @param args The arguments of the request being made
|
|
404
405
|
* @returns Promise<any>
|
|
405
406
|
*/
|
|
406
|
-
handleSigningRequest({ chainId, method, params, }) {
|
|
407
|
+
handleSigningRequest({ chainId, method, params, sponsorGas, }) {
|
|
407
408
|
return __awaiter(this, void 0, void 0, function* () {
|
|
408
409
|
const isApproved = passiveSignerMethods.includes(method)
|
|
409
410
|
? true
|
|
@@ -435,6 +436,7 @@ class Provider {
|
|
|
435
436
|
method,
|
|
436
437
|
params: this.buildParams(method, params),
|
|
437
438
|
rpcUrl: this.portal.getRpcUrl(chainId),
|
|
439
|
+
sponsorGas,
|
|
438
440
|
});
|
|
439
441
|
return result;
|
|
440
442
|
}
|
|
@@ -448,6 +450,7 @@ class Provider {
|
|
|
448
450
|
method,
|
|
449
451
|
params: this.buildParams(method, params),
|
|
450
452
|
rpcUrl: this.portal.getRpcUrl(chainId),
|
|
453
|
+
sponsorGas,
|
|
451
454
|
});
|
|
452
455
|
return result;
|
|
453
456
|
}
|
package/lib/esm/index.js
CHANGED
|
@@ -332,6 +332,7 @@ class Portal {
|
|
|
332
332
|
chainId,
|
|
333
333
|
method: 'eth_sendTransaction',
|
|
334
334
|
params: [buildTxResponse.transaction],
|
|
335
|
+
sponsorGas: params.sponsorGas,
|
|
335
336
|
});
|
|
336
337
|
break;
|
|
337
338
|
}
|
|
@@ -340,6 +341,7 @@ class Portal {
|
|
|
340
341
|
chainId,
|
|
341
342
|
method: 'sol_signAndSendTransaction',
|
|
342
343
|
params: [buildTxResponse.transaction],
|
|
344
|
+
sponsorGas: params.sponsorGas,
|
|
343
345
|
});
|
|
344
346
|
break;
|
|
345
347
|
}
|
|
@@ -682,7 +684,7 @@ class Portal {
|
|
|
682
684
|
getQuote(apiKey, args, chainId) {
|
|
683
685
|
var _a;
|
|
684
686
|
return __awaiter(this, void 0, void 0, function* () {
|
|
685
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getQuote(
|
|
687
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getQuote(chainId, args, apiKey);
|
|
686
688
|
});
|
|
687
689
|
}
|
|
688
690
|
/**
|
|
@@ -691,7 +693,7 @@ class Portal {
|
|
|
691
693
|
getSources(apiKey, chainId) {
|
|
692
694
|
var _a;
|
|
693
695
|
return __awaiter(this, void 0, void 0, function* () {
|
|
694
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSources(
|
|
696
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSources(chainId, apiKey);
|
|
695
697
|
});
|
|
696
698
|
}
|
|
697
699
|
/*******************************
|
package/lib/esm/index.test.js
CHANGED
|
@@ -537,14 +537,14 @@ describe('Portal', () => {
|
|
|
537
537
|
it('should correctly call mpc.getQuote', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
538
538
|
yield portal.getQuote('test', mockQuoteArgs, 'eip155:1');
|
|
539
539
|
expect(portal.mpc.getQuote).toHaveBeenCalledTimes(1);
|
|
540
|
-
expect(portal.mpc.getQuote).toHaveBeenCalledWith('
|
|
540
|
+
expect(portal.mpc.getQuote).toHaveBeenCalledWith('eip155:1', mockQuoteArgs, 'test');
|
|
541
541
|
}));
|
|
542
542
|
});
|
|
543
543
|
describe('getSources', () => {
|
|
544
544
|
it('should correctly call mpc.getSources', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
545
545
|
yield portal.getSources('test', 'eip155:1');
|
|
546
546
|
expect(portal.mpc.getSources).toHaveBeenCalledTimes(1);
|
|
547
|
-
expect(portal.mpc.getSources).toHaveBeenCalledWith('
|
|
547
|
+
expect(portal.mpc.getSources).toHaveBeenCalledWith('eip155:1', 'test');
|
|
548
548
|
}));
|
|
549
549
|
});
|
|
550
550
|
describe('storedClientBackupShare', () => {
|