@metamask/bridge-controller 33.0.1 → 34.0.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/CHANGELOG.md +24 -1
- package/dist/bridge-controller.cjs.map +1 -1
- package/dist/bridge-controller.d.cts.map +1 -1
- package/dist/bridge-controller.d.mts.map +1 -1
- package/dist/bridge-controller.mjs.map +1 -1
- package/dist/index.cjs +6 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/selectors.cjs +13 -4
- package/dist/selectors.cjs.map +1 -1
- package/dist/selectors.d.cts +13100 -124
- package/dist/selectors.d.cts.map +1 -1
- package/dist/selectors.d.mts +13100 -124
- package/dist/selectors.d.mts.map +1 -1
- package/dist/selectors.mjs +14 -5
- package/dist/selectors.mjs.map +1 -1
- package/dist/types.cjs +1 -12
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +35 -113
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +35 -113
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +0 -11
- package/dist/types.mjs.map +1 -1
- package/dist/utils/feature-flags.d.cts +2 -2
- package/dist/utils/feature-flags.d.mts +2 -2
- package/dist/utils/fetch.cjs +1 -0
- package/dist/utils/fetch.cjs.map +1 -1
- package/dist/utils/fetch.d.cts.map +1 -1
- package/dist/utils/fetch.d.mts.map +1 -1
- package/dist/utils/fetch.mjs +1 -0
- package/dist/utils/fetch.mjs.map +1 -1
- package/dist/utils/quote.cjs +58 -19
- package/dist/utils/quote.cjs.map +1 -1
- package/dist/utils/quote.d.cts +7 -2
- package/dist/utils/quote.d.cts.map +1 -1
- package/dist/utils/quote.d.mts +7 -2
- package/dist/utils/quote.d.mts.map +1 -1
- package/dist/utils/quote.mjs +57 -19
- package/dist/utils/quote.mjs.map +1 -1
- package/dist/utils/validators.cjs +134 -73
- package/dist/utils/validators.cjs.map +1 -1
- package/dist/utils/validators.d.cts +1922 -4
- package/dist/utils/validators.d.cts.map +1 -1
- package/dist/utils/validators.d.mts +1922 -4
- package/dist/utils/validators.d.mts.map +1 -1
- package/dist/utils/validators.mjs +132 -71
- package/dist/utils/validators.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1,99 +1,160 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateQuoteResponse = exports.validateSwapsTokenObject = exports.validateFeatureFlagsResponse = exports.truthyString = void 0;
|
|
3
|
+
exports.validateQuoteResponse = exports.QuoteResponseSchema = exports.TxDataSchema = exports.QuoteSchema = exports.StepSchema = exports.ProtocolSchema = exports.FeeDataSchema = exports.validateSwapsTokenObject = exports.validateFeatureFlagsResponse = exports.PlatformConfigSchema = exports.ChainConfigurationSchema = exports.BridgeAssetSchema = exports.truthyString = exports.ActionTypes = exports.FeeType = void 0;
|
|
4
4
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
5
5
|
const superstruct_1 = require("@metamask/superstruct");
|
|
6
6
|
const utils_1 = require("@metamask/utils");
|
|
7
|
-
|
|
7
|
+
var FeeType;
|
|
8
|
+
(function (FeeType) {
|
|
9
|
+
FeeType["METABRIDGE"] = "metabridge";
|
|
10
|
+
FeeType["REFUEL"] = "refuel";
|
|
11
|
+
FeeType["TX_FEE"] = "txFee";
|
|
12
|
+
})(FeeType || (exports.FeeType = FeeType = {}));
|
|
13
|
+
var ActionTypes;
|
|
14
|
+
(function (ActionTypes) {
|
|
15
|
+
ActionTypes["BRIDGE"] = "bridge";
|
|
16
|
+
ActionTypes["SWAP"] = "swap";
|
|
17
|
+
ActionTypes["REFUEL"] = "refuel";
|
|
18
|
+
})(ActionTypes || (exports.ActionTypes = ActionTypes = {}));
|
|
8
19
|
const HexAddressSchema = (0, superstruct_1.define)('HexAddress', (v) => (0, controller_utils_1.isValidHexAddress)(v, { allowNonPrefixed: false }));
|
|
9
20
|
const HexStringSchema = (0, superstruct_1.define)('HexString', (v) => (0, utils_1.isStrictHexString)(v));
|
|
10
21
|
const truthyString = (s) => Boolean(s?.length);
|
|
11
22
|
exports.truthyString = truthyString;
|
|
12
|
-
const TruthyDigitStringSchema = (0, superstruct_1.
|
|
23
|
+
const TruthyDigitStringSchema = (0, superstruct_1.pattern)((0, superstruct_1.string)(), /^\d+$/u);
|
|
13
24
|
const ChainIdSchema = (0, superstruct_1.number)();
|
|
14
|
-
|
|
25
|
+
exports.BridgeAssetSchema = (0, superstruct_1.type)({
|
|
26
|
+
/**
|
|
27
|
+
* The chainId of the token
|
|
28
|
+
*/
|
|
15
29
|
chainId: ChainIdSchema,
|
|
30
|
+
/**
|
|
31
|
+
* An address that the metaswap-api recognizes as the default token
|
|
32
|
+
*/
|
|
16
33
|
address: (0, superstruct_1.string)(),
|
|
17
|
-
|
|
34
|
+
/**
|
|
35
|
+
* The assetId of the token
|
|
36
|
+
*/
|
|
37
|
+
assetId: utils_1.CaipAssetTypeStruct,
|
|
38
|
+
/**
|
|
39
|
+
* The symbol of token object
|
|
40
|
+
*/
|
|
18
41
|
symbol: (0, superstruct_1.string)(),
|
|
42
|
+
/**
|
|
43
|
+
* The name for the network
|
|
44
|
+
*/
|
|
19
45
|
name: (0, superstruct_1.string)(),
|
|
20
46
|
decimals: (0, superstruct_1.number)(),
|
|
21
|
-
|
|
22
|
-
|
|
47
|
+
/**
|
|
48
|
+
* URL for token icon
|
|
49
|
+
*/
|
|
50
|
+
icon: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.string)())),
|
|
51
|
+
/**
|
|
52
|
+
* URL for token icon
|
|
53
|
+
*/
|
|
54
|
+
iconUrl: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.string)())),
|
|
55
|
+
});
|
|
56
|
+
exports.ChainConfigurationSchema = (0, superstruct_1.type)({
|
|
57
|
+
isActiveSrc: (0, superstruct_1.boolean)(),
|
|
58
|
+
isActiveDest: (0, superstruct_1.boolean)(),
|
|
59
|
+
refreshRate: (0, superstruct_1.optional)((0, superstruct_1.number)()),
|
|
60
|
+
topAssets: (0, superstruct_1.optional)((0, superstruct_1.array)((0, superstruct_1.string)())),
|
|
61
|
+
isUnifiedUIEnabled: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
|
|
62
|
+
isSnapConfirmationEnabled: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* This is the schema for the feature flags response from the RemoteFeatureFlagController
|
|
66
|
+
*/
|
|
67
|
+
exports.PlatformConfigSchema = (0, superstruct_1.type)({
|
|
68
|
+
minimumVersion: (0, superstruct_1.string)(),
|
|
69
|
+
refreshRate: (0, superstruct_1.number)(),
|
|
70
|
+
maxRefreshCount: (0, superstruct_1.number)(),
|
|
71
|
+
support: (0, superstruct_1.boolean)(),
|
|
72
|
+
chains: (0, superstruct_1.record)((0, superstruct_1.string)(), exports.ChainConfigurationSchema),
|
|
23
73
|
});
|
|
24
74
|
const validateFeatureFlagsResponse = (data) => {
|
|
25
|
-
|
|
26
|
-
isActiveSrc: (0, superstruct_1.boolean)(),
|
|
27
|
-
isActiveDest: (0, superstruct_1.boolean)(),
|
|
28
|
-
refreshRate: (0, superstruct_1.optional)((0, superstruct_1.number)()),
|
|
29
|
-
topAssets: (0, superstruct_1.optional)((0, superstruct_1.array)((0, superstruct_1.string)())),
|
|
30
|
-
isUnifiedUIEnabled: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
|
|
31
|
-
});
|
|
32
|
-
const PlatformConfigSchema = (0, superstruct_1.type)({
|
|
33
|
-
minimumVersion: (0, superstruct_1.string)(),
|
|
34
|
-
refreshRate: (0, superstruct_1.number)(),
|
|
35
|
-
maxRefreshCount: (0, superstruct_1.number)(),
|
|
36
|
-
support: (0, superstruct_1.boolean)(),
|
|
37
|
-
chains: (0, superstruct_1.record)((0, superstruct_1.string)(), ChainConfigurationSchema),
|
|
38
|
-
});
|
|
39
|
-
// Create schema for FeatureFlagResponse
|
|
40
|
-
return (0, superstruct_1.is)(data, PlatformConfigSchema);
|
|
75
|
+
return (0, superstruct_1.is)(data, exports.PlatformConfigSchema);
|
|
41
76
|
};
|
|
42
77
|
exports.validateFeatureFlagsResponse = validateFeatureFlagsResponse;
|
|
43
78
|
const validateSwapsTokenObject = (data) => {
|
|
44
|
-
return (0, superstruct_1.is)(data, BridgeAssetSchema);
|
|
79
|
+
return (0, superstruct_1.is)(data, exports.BridgeAssetSchema);
|
|
45
80
|
};
|
|
46
81
|
exports.validateSwapsTokenObject = validateSwapsTokenObject;
|
|
82
|
+
exports.FeeDataSchema = (0, superstruct_1.type)({
|
|
83
|
+
amount: TruthyDigitStringSchema,
|
|
84
|
+
asset: exports.BridgeAssetSchema,
|
|
85
|
+
});
|
|
86
|
+
exports.ProtocolSchema = (0, superstruct_1.type)({
|
|
87
|
+
name: (0, superstruct_1.string)(),
|
|
88
|
+
displayName: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
89
|
+
icon: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
90
|
+
});
|
|
91
|
+
exports.StepSchema = (0, superstruct_1.type)({
|
|
92
|
+
action: (0, superstruct_1.enums)(Object.values(ActionTypes)),
|
|
93
|
+
srcChainId: ChainIdSchema,
|
|
94
|
+
destChainId: (0, superstruct_1.optional)(ChainIdSchema),
|
|
95
|
+
srcAsset: exports.BridgeAssetSchema,
|
|
96
|
+
destAsset: exports.BridgeAssetSchema,
|
|
97
|
+
srcAmount: (0, superstruct_1.string)(),
|
|
98
|
+
destAmount: (0, superstruct_1.string)(),
|
|
99
|
+
protocol: exports.ProtocolSchema,
|
|
100
|
+
});
|
|
101
|
+
const RefuelDataSchema = exports.StepSchema;
|
|
102
|
+
exports.QuoteSchema = (0, superstruct_1.type)({
|
|
103
|
+
requestId: (0, superstruct_1.string)(),
|
|
104
|
+
srcChainId: ChainIdSchema,
|
|
105
|
+
srcAsset: exports.BridgeAssetSchema,
|
|
106
|
+
/**
|
|
107
|
+
* The amount sent, in atomic amount: amount sent - fees
|
|
108
|
+
* Some tokens have a fee of 0, so sometimes it's equal to amount sent
|
|
109
|
+
*/
|
|
110
|
+
srcTokenAmount: (0, superstruct_1.string)(),
|
|
111
|
+
destChainId: ChainIdSchema,
|
|
112
|
+
destAsset: exports.BridgeAssetSchema,
|
|
113
|
+
/**
|
|
114
|
+
* The amount received, in atomic amount
|
|
115
|
+
*/
|
|
116
|
+
destTokenAmount: (0, superstruct_1.string)(),
|
|
117
|
+
feeData: (0, superstruct_1.type)({
|
|
118
|
+
[FeeType.METABRIDGE]: exports.FeeDataSchema,
|
|
119
|
+
/**
|
|
120
|
+
* This is the fee for the swap transaction taken from either the
|
|
121
|
+
* src or dest token if the quote has gas fees included or "gasless"
|
|
122
|
+
*/
|
|
123
|
+
[FeeType.TX_FEE]: (0, superstruct_1.optional)((0, superstruct_1.intersection)([
|
|
124
|
+
exports.FeeDataSchema,
|
|
125
|
+
(0, superstruct_1.type)({
|
|
126
|
+
maxFeePerGas: (0, superstruct_1.string)(),
|
|
127
|
+
maxPriorityFeePerGas: (0, superstruct_1.string)(),
|
|
128
|
+
}),
|
|
129
|
+
])),
|
|
130
|
+
}),
|
|
131
|
+
gasIncluded: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
|
|
132
|
+
bridgeId: (0, superstruct_1.string)(),
|
|
133
|
+
bridges: (0, superstruct_1.array)((0, superstruct_1.string)()),
|
|
134
|
+
steps: (0, superstruct_1.array)(exports.StepSchema),
|
|
135
|
+
refuel: (0, superstruct_1.optional)(RefuelDataSchema),
|
|
136
|
+
priceData: (0, superstruct_1.optional)((0, superstruct_1.type)({
|
|
137
|
+
totalFromAmountUsd: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
138
|
+
totalToAmountUsd: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
139
|
+
priceImpact: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
140
|
+
})),
|
|
141
|
+
});
|
|
142
|
+
exports.TxDataSchema = (0, superstruct_1.type)({
|
|
143
|
+
chainId: (0, superstruct_1.number)(),
|
|
144
|
+
to: HexAddressSchema,
|
|
145
|
+
from: HexAddressSchema,
|
|
146
|
+
value: HexStringSchema,
|
|
147
|
+
data: HexStringSchema,
|
|
148
|
+
gasLimit: (0, superstruct_1.nullable)((0, superstruct_1.number)()),
|
|
149
|
+
});
|
|
150
|
+
exports.QuoteResponseSchema = (0, superstruct_1.type)({
|
|
151
|
+
quote: exports.QuoteSchema,
|
|
152
|
+
estimatedProcessingTimeInSeconds: (0, superstruct_1.number)(),
|
|
153
|
+
approval: (0, superstruct_1.optional)(exports.TxDataSchema),
|
|
154
|
+
trade: (0, superstruct_1.union)([exports.TxDataSchema, (0, superstruct_1.string)()]),
|
|
155
|
+
});
|
|
47
156
|
const validateQuoteResponse = (data) => {
|
|
48
|
-
|
|
49
|
-
amount: TruthyDigitStringSchema,
|
|
50
|
-
asset: BridgeAssetSchema,
|
|
51
|
-
});
|
|
52
|
-
const ProtocolSchema = (0, superstruct_1.type)({
|
|
53
|
-
name: (0, superstruct_1.string)(),
|
|
54
|
-
displayName: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
55
|
-
icon: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
56
|
-
});
|
|
57
|
-
const StepSchema = (0, superstruct_1.type)({
|
|
58
|
-
action: (0, superstruct_1.enums)(Object.values(types_1.ActionTypes)),
|
|
59
|
-
srcChainId: ChainIdSchema,
|
|
60
|
-
destChainId: (0, superstruct_1.optional)(ChainIdSchema),
|
|
61
|
-
srcAsset: BridgeAssetSchema,
|
|
62
|
-
destAsset: BridgeAssetSchema,
|
|
63
|
-
srcAmount: (0, superstruct_1.string)(),
|
|
64
|
-
destAmount: (0, superstruct_1.string)(),
|
|
65
|
-
protocol: ProtocolSchema,
|
|
66
|
-
});
|
|
67
|
-
const RefuelDataSchema = StepSchema;
|
|
68
|
-
const QuoteSchema = (0, superstruct_1.type)({
|
|
69
|
-
requestId: (0, superstruct_1.string)(),
|
|
70
|
-
srcChainId: ChainIdSchema,
|
|
71
|
-
srcAsset: BridgeAssetSchema,
|
|
72
|
-
srcTokenAmount: (0, superstruct_1.string)(),
|
|
73
|
-
destChainId: ChainIdSchema,
|
|
74
|
-
destAsset: BridgeAssetSchema,
|
|
75
|
-
destTokenAmount: (0, superstruct_1.string)(),
|
|
76
|
-
feeData: (0, superstruct_1.record)((0, superstruct_1.enums)(Object.values(types_1.FeeType)), FeeDataSchema),
|
|
77
|
-
bridgeId: (0, superstruct_1.string)(),
|
|
78
|
-
bridges: (0, superstruct_1.array)((0, superstruct_1.string)()),
|
|
79
|
-
steps: (0, superstruct_1.array)(StepSchema),
|
|
80
|
-
refuel: (0, superstruct_1.optional)(RefuelDataSchema),
|
|
81
|
-
});
|
|
82
|
-
const TxDataSchema = (0, superstruct_1.type)({
|
|
83
|
-
chainId: (0, superstruct_1.number)(),
|
|
84
|
-
to: HexAddressSchema,
|
|
85
|
-
from: HexAddressSchema,
|
|
86
|
-
value: HexStringSchema,
|
|
87
|
-
data: HexStringSchema,
|
|
88
|
-
gasLimit: (0, superstruct_1.nullable)((0, superstruct_1.number)()),
|
|
89
|
-
});
|
|
90
|
-
const QuoteResponseSchema = (0, superstruct_1.type)({
|
|
91
|
-
quote: QuoteSchema,
|
|
92
|
-
approval: (0, superstruct_1.optional)(TxDataSchema),
|
|
93
|
-
trade: (0, superstruct_1.union)([TxDataSchema, (0, superstruct_1.string)()]),
|
|
94
|
-
estimatedProcessingTimeInSeconds: (0, superstruct_1.number)(),
|
|
95
|
-
});
|
|
96
|
-
(0, superstruct_1.assert)(data, QuoteResponseSchema);
|
|
157
|
+
(0, superstruct_1.assert)(data, exports.QuoteResponseSchema);
|
|
97
158
|
return true;
|
|
98
159
|
};
|
|
99
160
|
exports.validateQuoteResponse = validateQuoteResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.cjs","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":";;;AAAA,iEAA+D;
|
|
1
|
+
{"version":3,"file":"validators.cjs","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":";;;AAAA,iEAA+D;AAE/D,uDAgB+B;AAC/B,2CAAyE;AAEzE,IAAY,OAIX;AAJD,WAAY,OAAO;IACjB,oCAAyB,CAAA;IACzB,4BAAiB,CAAA;IACjB,2BAAgB,CAAA;AAClB,CAAC,EAJW,OAAO,uBAAP,OAAO,QAIlB;AAED,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,4BAAa,CAAA;IACb,gCAAiB,CAAA;AACnB,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB;AAED,MAAM,gBAAgB,GAAG,IAAA,oBAAM,EAAS,YAAY,EAAE,CAAC,CAAU,EAAE,EAAE,CACnE,IAAA,oCAAiB,EAAC,CAAW,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,CAC5D,CAAC;AAEF,MAAM,eAAe,GAAG,IAAA,oBAAM,EAAS,WAAW,EAAE,CAAC,CAAU,EAAE,EAAE,CACjE,IAAA,yBAAiB,EAAC,CAAW,CAAC,CAC/B,CAAC;AAEK,MAAM,YAAY,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAAjD,QAAA,YAAY,gBAAqC;AAC9D,MAAM,uBAAuB,GAAG,IAAA,qBAAO,EAAC,IAAA,oBAAM,GAAE,EAAE,QAAQ,CAAC,CAAC;AAE5D,MAAM,aAAa,GAAG,IAAA,oBAAM,GAAE,CAAC;AAElB,QAAA,iBAAiB,GAAG,IAAA,kBAAI,EAAC;IACpC;;OAEG;IACH,OAAO,EAAE,aAAa;IACtB;;OAEG;IACH,OAAO,EAAE,I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AG,IAAA,kBAAI,EAAC;IACtC,KAAK,EAAE,mBAAW;IAClB,gCAAgC,EAAE,IAAA,oBAAM,GAAE;IAC1C,QAAQ,EAAE,IAAA,sBAAQ,EAAC,oBAAY,CAAC;IAChC,KAAK,EAAE,IAAA,mBAAK,EAAC,CAAC,oBAAY,EAAE,IAAA,oBAAM,GAAE,CAAC,CAAC;CACvC,CAAC,CAAC;AAEI,MAAM,qBAAqB,GAAG,CACnC,IAAa,EAC8B,EAAE;IAC7C,IAAA,oBAAM,EAAC,IAAI,EAAE,2BAAmB,CAAC,CAAC;IAClC,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AALW,QAAA,qBAAqB,yBAKhC","sourcesContent":["import { isValidHexAddress } from '@metamask/controller-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n string,\n boolean,\n number,\n type,\n is,\n record,\n array,\n nullable,\n optional,\n enums,\n define,\n union,\n assert,\n pattern,\n intersection,\n} from '@metamask/superstruct';\nimport { CaipAssetTypeStruct, isStrictHexString } from '@metamask/utils';\n\nexport enum FeeType {\n METABRIDGE = 'metabridge',\n REFUEL = 'refuel',\n TX_FEE = 'txFee',\n}\n\nexport enum ActionTypes {\n BRIDGE = 'bridge',\n SWAP = 'swap',\n REFUEL = 'refuel',\n}\n\nconst HexAddressSchema = define<string>('HexAddress', (v: unknown) =>\n isValidHexAddress(v as string, { allowNonPrefixed: false }),\n);\n\nconst HexStringSchema = define<string>('HexString', (v: unknown) =>\n isStrictHexString(v as string),\n);\n\nexport const truthyString = (s: string) => Boolean(s?.length);\nconst TruthyDigitStringSchema = pattern(string(), /^\\d+$/u);\n\nconst ChainIdSchema = number();\n\nexport const BridgeAssetSchema = type({\n /**\n * The chainId of the token\n */\n chainId: ChainIdSchema,\n /**\n * An address that the metaswap-api recognizes as the default token\n */\n address: string(),\n /**\n * The assetId of the token\n */\n assetId: CaipAssetTypeStruct,\n /**\n * The symbol of token object\n */\n symbol: string(),\n /**\n * The name for the network\n */\n name: string(),\n decimals: number(),\n /**\n * URL for token icon\n */\n icon: optional(nullable(string())),\n /**\n * URL for token icon\n */\n iconUrl: optional(nullable(string())),\n});\n\nexport const ChainConfigurationSchema = type({\n isActiveSrc: boolean(),\n isActiveDest: boolean(),\n refreshRate: optional(number()),\n topAssets: optional(array(string())),\n isUnifiedUIEnabled: optional(boolean()),\n isSnapConfirmationEnabled: optional(boolean()),\n});\n\n/**\n * This is the schema for the feature flags response from the RemoteFeatureFlagController\n */\nexport const PlatformConfigSchema = type({\n minimumVersion: string(),\n refreshRate: number(),\n maxRefreshCount: number(),\n support: boolean(),\n chains: record(string(), ChainConfigurationSchema),\n});\n\nexport const validateFeatureFlagsResponse = (\n data: unknown,\n): data is Infer<typeof PlatformConfigSchema> => {\n return is(data, PlatformConfigSchema);\n};\n\nexport const validateSwapsTokenObject = (\n data: unknown,\n): data is Infer<typeof BridgeAssetSchema> => {\n return is(data, BridgeAssetSchema);\n};\n\nexport const FeeDataSchema = type({\n amount: TruthyDigitStringSchema,\n asset: BridgeAssetSchema,\n});\n\nexport const ProtocolSchema = type({\n name: string(),\n displayName: optional(string()),\n icon: optional(string()),\n});\n\nexport const StepSchema = type({\n action: enums(Object.values(ActionTypes)),\n srcChainId: ChainIdSchema,\n destChainId: optional(ChainIdSchema),\n srcAsset: BridgeAssetSchema,\n destAsset: BridgeAssetSchema,\n srcAmount: string(),\n destAmount: string(),\n protocol: ProtocolSchema,\n});\n\nconst RefuelDataSchema = StepSchema;\n\nexport const QuoteSchema = type({\n requestId: string(),\n srcChainId: ChainIdSchema,\n srcAsset: BridgeAssetSchema,\n /**\n * The amount sent, in atomic amount: amount sent - fees\n * Some tokens have a fee of 0, so sometimes it's equal to amount sent\n */\n srcTokenAmount: string(),\n destChainId: ChainIdSchema,\n destAsset: BridgeAssetSchema,\n /**\n * The amount received, in atomic amount\n */\n destTokenAmount: string(),\n feeData: type({\n [FeeType.METABRIDGE]: FeeDataSchema,\n /**\n * This is the fee for the swap transaction taken from either the\n * src or dest token if the quote has gas fees included or \"gasless\"\n */\n [FeeType.TX_FEE]: optional(\n intersection([\n FeeDataSchema,\n type({\n maxFeePerGas: string(),\n maxPriorityFeePerGas: string(),\n }),\n ]),\n ),\n }),\n gasIncluded: optional(boolean()),\n bridgeId: string(),\n bridges: array(string()),\n steps: array(StepSchema),\n refuel: optional(RefuelDataSchema),\n priceData: optional(\n type({\n totalFromAmountUsd: optional(string()),\n totalToAmountUsd: optional(string()),\n priceImpact: optional(string()),\n }),\n ),\n});\n\nexport const TxDataSchema = type({\n chainId: number(),\n to: HexAddressSchema,\n from: HexAddressSchema,\n value: HexStringSchema,\n data: HexStringSchema,\n gasLimit: nullable(number()),\n});\n\nexport const QuoteResponseSchema = type({\n quote: QuoteSchema,\n estimatedProcessingTimeInSeconds: number(),\n approval: optional(TxDataSchema),\n trade: union([TxDataSchema, string()]),\n});\n\nexport const validateQuoteResponse = (\n data: unknown,\n): data is Infer<typeof QuoteResponseSchema> => {\n assert(data, QuoteResponseSchema);\n return true;\n};\n"]}
|