@airgap/optimism 0.13.15-beta.12 → 0.13.16-beta.1
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/package.json +7 -6
- package/v1/client/info/OptimismInfoClient.d.ts +2 -0
- package/v1/client/info/OptimismInfoClient.js +3 -0
- package/v1/client/info/OptimismInfoClient.js.map +1 -0
- package/v1/client/node/AirGapNodeClient.d.ts +21 -0
- package/v1/client/node/AirGapNodeClient.js +161 -0
- package/v1/client/node/AirGapNodeClient.js.map +1 -0
- package/v1/client/node/OptimismNodeClient.d.ts +5 -0
- package/v1/client/node/OptimismNodeClient.js +28 -0
- package/v1/client/node/OptimismNodeClient.js.map +1 -0
- package/v1/module/ERC20Tokens.js +82 -1
- package/v1/module/ERC20Tokens.js.map +1 -1
- package/v1/module/OptimismModule.js +4 -3
- package/v1/module/OptimismModule.js.map +1 -1
- package/v1/protocol/OptimismBaseProtocol.d.ts +55 -0
- package/v1/protocol/OptimismBaseProtocol.js +340 -0
- package/v1/protocol/OptimismBaseProtocol.js.map +1 -0
- package/v1/protocol/OptimismProtocol.d.ts +3 -3
- package/v1/protocol/OptimismProtocol.js +21 -16
- package/v1/protocol/OptimismProtocol.js.map +1 -1
- package/v1/protocol/erc20/ERC20Token.d.ts +9 -0
- package/v1/protocol/erc20/ERC20Token.js +131 -0
- package/v1/protocol/erc20/ERC20Token.js.map +1 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +37 -4
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-optimism.d.ts +14 -2
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-optimism.json +4 -1
- package/v1/serializer/v3/serializer-companion.d.ts +1 -1
- package/v1/serializer/v3/serializer-companion.js +11 -11
- package/v1/types/crypto.d.ts +2 -0
- package/v1/types/crypto.js +3 -0
- package/v1/types/crypto.js.map +1 -0
- package/v1/types/protocol.d.ts +2 -4
- package/v1/types/transaction.d.ts +8 -2
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.OptimismBaseProtocolImpl = void 0;
|
|
54
|
+
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
55
|
+
var v1_1 = require("@airgap/ethereum/v1");
|
|
56
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
57
|
+
// Implementation
|
|
58
|
+
var OptimismBaseProtocolImpl = /** @class */ (function () {
|
|
59
|
+
function OptimismBaseProtocolImpl(ethereumProtocol, nodeClient, infoClient, options) {
|
|
60
|
+
this.ethereumProtocol = ethereumProtocol;
|
|
61
|
+
this.nodeClient = nodeClient;
|
|
62
|
+
this.infoClient = infoClient;
|
|
63
|
+
this.options = options;
|
|
64
|
+
this.units = this.ethereumProtocol.units;
|
|
65
|
+
this.feeUnits = this.ethereumProtocol.feeUnits;
|
|
66
|
+
}
|
|
67
|
+
OptimismBaseProtocolImpl.prototype.getMetadata = function () {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
69
|
+
return __generator(this, function (_a) {
|
|
70
|
+
return [2 /*return*/, this.ethereumProtocol.getMetadata()];
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
OptimismBaseProtocolImpl.prototype.getAddressFromPublicKey = function (publicKey) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
+
return __generator(this, function (_a) {
|
|
77
|
+
return [2 /*return*/, this.ethereumProtocol.getAddressFromPublicKey(publicKey)];
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
OptimismBaseProtocolImpl.prototype.deriveFromExtendedPublicKey = function (extendedPublicKey, visibilityIndex, addressIndex) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
+
return __generator(this, function (_a) {
|
|
84
|
+
return [2 /*return*/, this.ethereumProtocol.deriveFromExtendedPublicKey(extendedPublicKey, visibilityIndex, addressIndex)];
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
OptimismBaseProtocolImpl.prototype.getDetailsFromTransaction = function (transaction, publicKey) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
+
var ethereumDetails, l1DataFee, l1DataFeePerTransaction;
|
|
91
|
+
var _this = this;
|
|
92
|
+
return __generator(this, function (_a) {
|
|
93
|
+
switch (_a.label) {
|
|
94
|
+
case 0: return [4 /*yield*/, this.ethereumProtocol.getDetailsFromTransaction(transaction, publicKey)];
|
|
95
|
+
case 1:
|
|
96
|
+
ethereumDetails = _a.sent();
|
|
97
|
+
l1DataFee = transaction.type === 'signed' ? transaction.l1DataFee : transaction.ethereumType === 'raw' ? transaction.l1DataFee : undefined;
|
|
98
|
+
if (l1DataFee === undefined) {
|
|
99
|
+
return [2 /*return*/, ethereumDetails];
|
|
100
|
+
}
|
|
101
|
+
l1DataFeePerTransaction = new bignumber_1.default(l1DataFee).div(ethereumDetails.length);
|
|
102
|
+
return [2 /*return*/, ethereumDetails.map(function (details) {
|
|
103
|
+
var feeBlockchain = (0, module_kit_1.newAmount)(details.fee).blockchain(_this.feeUnits);
|
|
104
|
+
return __assign(__assign({}, details), { fee: (0, module_kit_1.newAmount)(l1DataFeePerTransaction.plus(feeBlockchain.value), 'blockchain') });
|
|
105
|
+
})];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
OptimismBaseProtocolImpl.prototype.verifyMessageWithPublicKey = function (message, signature, publicKey) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
+
return __generator(this, function (_a) {
|
|
113
|
+
return [2 /*return*/, this.ethereumProtocol.verifyMessageWithPublicKey(message, signature, publicKey)];
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
OptimismBaseProtocolImpl.prototype.encryptAsymmetricWithPublicKey = function (payload, publicKey) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
+
return __generator(this, function (_a) {
|
|
120
|
+
return [2 /*return*/, this.ethereumProtocol.encryptAsymmetricWithPublicKey(payload, publicKey)];
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
// Offline
|
|
125
|
+
OptimismBaseProtocolImpl.prototype.getCryptoConfiguration = function () {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
127
|
+
return __generator(this, function (_a) {
|
|
128
|
+
return [2 /*return*/, this.ethereumProtocol.getCryptoConfiguration()];
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
OptimismBaseProtocolImpl.prototype.getKeyPairFromDerivative = function (derivative) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
+
return __generator(this, function (_a) {
|
|
135
|
+
return [2 /*return*/, this.ethereumProtocol.getKeyPairFromDerivative(derivative)];
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
OptimismBaseProtocolImpl.prototype.getExtendedKeyPairFromDerivative = function (derivative) {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
141
|
+
return __generator(this, function (_a) {
|
|
142
|
+
return [2 /*return*/, this.ethereumProtocol.getExtendedKeyPairFromDerivative(derivative)];
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
OptimismBaseProtocolImpl.prototype.deriveFromExtendedSecretKey = function (extendedSecretKey, visibilityIndex, addressIndex) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
+
return __generator(this, function (_a) {
|
|
149
|
+
return [2 /*return*/, this.ethereumProtocol.deriveFromExtendedSecretKey(extendedSecretKey, visibilityIndex, addressIndex)];
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
OptimismBaseProtocolImpl.prototype.signTransactionWithSecretKey = function (transaction, secretKey) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
+
var ethereumTransaction;
|
|
156
|
+
return __generator(this, function (_a) {
|
|
157
|
+
switch (_a.label) {
|
|
158
|
+
case 0: return [4 /*yield*/, this.ethereumProtocol.signTransactionWithSecretKey(transaction, secretKey)];
|
|
159
|
+
case 1:
|
|
160
|
+
ethereumTransaction = _a.sent();
|
|
161
|
+
return [2 /*return*/, transaction.ethereumType === 'raw'
|
|
162
|
+
? (0, module_kit_1.newSignedTransaction)(__assign(__assign({}, ethereumTransaction), { l1DataFee: transaction.l1DataFee }))
|
|
163
|
+
: ethereumTransaction];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
OptimismBaseProtocolImpl.prototype.signMessageWithKeyPair = function (message, keyPair) {
|
|
169
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
170
|
+
return __generator(this, function (_a) {
|
|
171
|
+
return [2 /*return*/, this.ethereumProtocol.signMessageWithKeyPair(message, keyPair)];
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
OptimismBaseProtocolImpl.prototype.decryptAsymmetricWithKeyPair = function (payload, keyPair) {
|
|
176
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
177
|
+
return __generator(this, function (_a) {
|
|
178
|
+
return [2 /*return*/, this.ethereumProtocol.decryptAsymmetricWithKeyPair(payload, keyPair)];
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
OptimismBaseProtocolImpl.prototype.encryptAESWithSecretKey = function (payload, secretKey) {
|
|
183
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
184
|
+
return __generator(this, function (_a) {
|
|
185
|
+
return [2 /*return*/, this.ethereumProtocol.encryptAESWithSecretKey(payload, secretKey)];
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
OptimismBaseProtocolImpl.prototype.decryptAESWithSecretKey = function (payload, secretKey) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
191
|
+
return __generator(this, function (_a) {
|
|
192
|
+
return [2 /*return*/, this.ethereumProtocol.decryptAESWithSecretKey(payload, secretKey)];
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
// Online
|
|
197
|
+
OptimismBaseProtocolImpl.prototype.getNetwork = function () {
|
|
198
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
199
|
+
return __generator(this, function (_a) {
|
|
200
|
+
return [2 /*return*/, this.ethereumProtocol.getNetwork()];
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
OptimismBaseProtocolImpl.prototype.getTransactionsForPublicKey = function (publicKey, limit, cursor) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
206
|
+
return __generator(this, function (_a) {
|
|
207
|
+
return [2 /*return*/, this.ethereumProtocol.getTransactionsForPublicKey(publicKey, limit, cursor)];
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
OptimismBaseProtocolImpl.prototype.getTransactionsForAddress = function (address, limit, cursor) {
|
|
212
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
213
|
+
return __generator(this, function (_a) {
|
|
214
|
+
return [2 /*return*/, this.ethereumProtocol.getTransactionsForAddress(address, limit, cursor)];
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
OptimismBaseProtocolImpl.prototype.getTransactionsForAddresses = function (addresses, limit, cursor) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
220
|
+
return __generator(this, function (_a) {
|
|
221
|
+
return [2 /*return*/, this.ethereumProtocol.getTransactionsForAddresses(addresses, limit, cursor)];
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
OptimismBaseProtocolImpl.prototype.getTransactionStatus = function (transactionIds) {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
227
|
+
return __generator(this, function (_a) {
|
|
228
|
+
return [2 /*return*/, this.ethereumProtocol.getTransactionStatus(transactionIds)];
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
OptimismBaseProtocolImpl.prototype.getBalanceOfPublicKey = function (publicKey) {
|
|
233
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
234
|
+
return __generator(this, function (_a) {
|
|
235
|
+
return [2 /*return*/, this.ethereumProtocol.getBalanceOfPublicKey(publicKey)];
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
OptimismBaseProtocolImpl.prototype.getBalanceOfAddress = function (address) {
|
|
240
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
241
|
+
return __generator(this, function (_a) {
|
|
242
|
+
return [2 /*return*/, this.ethereumProtocol.getBalanceOfAddress(address)];
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
OptimismBaseProtocolImpl.prototype.getBalanceOfAddresses = function (addresses) {
|
|
247
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
248
|
+
return __generator(this, function (_a) {
|
|
249
|
+
return [2 /*return*/, this.ethereumProtocol.getBalanceOfAddresses(addresses)];
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
OptimismBaseProtocolImpl.prototype.getTransactionMaxAmountWithPublicKey = function (publicKey, to, configuration) {
|
|
254
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
255
|
+
var _a, metadata, ethereumMaxAmount, maxAmountBlockchain, maxAmountPerRecipient, ethereumTransaction, l1Fee;
|
|
256
|
+
return __generator(this, function (_b) {
|
|
257
|
+
switch (_b.label) {
|
|
258
|
+
case 0: return [4 /*yield*/, Promise.all([
|
|
259
|
+
this.getMetadata(),
|
|
260
|
+
this.ethereumProtocol.getTransactionMaxAmountWithPublicKey(publicKey, to, configuration)
|
|
261
|
+
])];
|
|
262
|
+
case 1:
|
|
263
|
+
_a = _b.sent(), metadata = _a[0], ethereumMaxAmount = _a[1];
|
|
264
|
+
maxAmountBlockchain = new bignumber_1.default((0, module_kit_1.newAmount)(ethereumMaxAmount).blockchain(metadata.units).value);
|
|
265
|
+
maxAmountPerRecipient = maxAmountBlockchain.div(to.length);
|
|
266
|
+
return [4 /*yield*/, this.ethereumProtocol.prepareTransactionWithPublicKey(publicKey, to.map(function (recipient) { return ({
|
|
267
|
+
to: recipient,
|
|
268
|
+
amount: (0, module_kit_1.newAmount)(maxAmountPerRecipient, 'blockchain')
|
|
269
|
+
}); }), configuration)];
|
|
270
|
+
case 2:
|
|
271
|
+
ethereumTransaction = _b.sent();
|
|
272
|
+
return [4 /*yield*/, this.nodeClient.getL1Fee(this.options.network.gasPriceOracleAddress, ethereumTransaction)];
|
|
273
|
+
case 3:
|
|
274
|
+
l1Fee = _b.sent();
|
|
275
|
+
if (maxAmountBlockchain.lte(l1Fee)) {
|
|
276
|
+
return [2 /*return*/, (0, module_kit_1.newAmount)(0, 'blockchain')];
|
|
277
|
+
}
|
|
278
|
+
return [2 /*return*/, (0, module_kit_1.newAmount)(maxAmountBlockchain.minus(l1Fee), 'blockchain')];
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
OptimismBaseProtocolImpl.prototype.getTransactionFeeWithPublicKey = function (publicKey, details) {
|
|
284
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
285
|
+
var l2Fee, ethereumTransaction, l1Fee;
|
|
286
|
+
return __generator(this, function (_a) {
|
|
287
|
+
switch (_a.label) {
|
|
288
|
+
case 0: return [4 /*yield*/, this.ethereumProtocol.getTransactionFeeWithPublicKey(publicKey, details)];
|
|
289
|
+
case 1:
|
|
290
|
+
l2Fee = _a.sent();
|
|
291
|
+
return [4 /*yield*/, this.ethereumProtocol.prepareTransactionWithPublicKey(publicKey, details, { fee: l2Fee.medium })];
|
|
292
|
+
case 2:
|
|
293
|
+
ethereumTransaction = _a.sent();
|
|
294
|
+
return [4 /*yield*/, this.nodeClient.getL1Fee(this.options.network.gasPriceOracleAddress, ethereumTransaction)];
|
|
295
|
+
case 3:
|
|
296
|
+
l1Fee = _a.sent();
|
|
297
|
+
return [2 /*return*/, {
|
|
298
|
+
low: (0, module_kit_1.newAmount)(l1Fee.plus((0, module_kit_1.newAmount)(l2Fee.low).blockchain(this.feeUnits).value), 'blockchain'),
|
|
299
|
+
medium: (0, module_kit_1.newAmount)(l1Fee.plus((0, module_kit_1.newAmount)(l2Fee.medium).blockchain(this.feeUnits).value), 'blockchain'),
|
|
300
|
+
high: (0, module_kit_1.newAmount)(l1Fee.plus((0, module_kit_1.newAmount)(l2Fee.high).blockchain(this.feeUnits).value), 'blockchain')
|
|
301
|
+
}];
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
};
|
|
306
|
+
OptimismBaseProtocolImpl.prototype.prepareTransactionWithPublicKey = function (publicKey, details, configuration) {
|
|
307
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
308
|
+
var ethereumTransaction, l1Gas, gasLimit, gasPrice, totalGas, l2Gas, newGasPrice;
|
|
309
|
+
return __generator(this, function (_a) {
|
|
310
|
+
switch (_a.label) {
|
|
311
|
+
case 0: return [4 /*yield*/, this.ethereumProtocol.prepareTransactionWithPublicKey(publicKey, details, configuration)];
|
|
312
|
+
case 1:
|
|
313
|
+
ethereumTransaction = _a.sent();
|
|
314
|
+
if (ethereumTransaction.ethereumType === 'typed') {
|
|
315
|
+
return [2 /*return*/, ethereumTransaction];
|
|
316
|
+
}
|
|
317
|
+
return [4 /*yield*/, this.nodeClient.getL1Fee(this.options.network.gasPriceOracleAddress, ethereumTransaction)];
|
|
318
|
+
case 2:
|
|
319
|
+
l1Gas = _a.sent();
|
|
320
|
+
gasLimit = v1_1.EthereumUtils.hexToNumber(ethereumTransaction.gasLimit);
|
|
321
|
+
gasPrice = v1_1.EthereumUtils.hexToNumber(ethereumTransaction.gasPrice);
|
|
322
|
+
totalGas = gasPrice.times(gasLimit);
|
|
323
|
+
l2Gas = totalGas.minus(l1Gas).abs();
|
|
324
|
+
newGasPrice = l2Gas.div(gasLimit).integerValue(bignumber_1.default.ROUND_CEIL);
|
|
325
|
+
return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)(__assign(__assign({}, ethereumTransaction), { gasPrice: v1_1.EthereumUtils.toHex(newGasPrice.toFixed()), l1DataFee: l1Gas.toFixed() }))];
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
};
|
|
330
|
+
OptimismBaseProtocolImpl.prototype.broadcastTransaction = function (transaction) {
|
|
331
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
332
|
+
return __generator(this, function (_a) {
|
|
333
|
+
return [2 /*return*/, this.ethereumProtocol.broadcastTransaction(transaction)];
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
};
|
|
337
|
+
return OptimismBaseProtocolImpl;
|
|
338
|
+
}());
|
|
339
|
+
exports.OptimismBaseProtocolImpl = OptimismBaseProtocolImpl;
|
|
340
|
+
//# sourceMappingURL=OptimismBaseProtocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OptimismBaseProtocol.js","sourceRoot":"","sources":["../../../src/v1/protocol/OptimismBaseProtocol.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iHAA0F;AAC1F,0CAA4F;AAC5F,iDAwB2B;AAmC3B,iBAAiB;AAEjB;IAOE,kCACqB,gBAAmC,EACnC,UAA8B,EAC9B,UAA8B,EAC9B,OAAgC;QAHhC,qBAAgB,GAAhB,gBAAgB,CAAmB;QACnC,eAAU,GAAV,UAAU,CAAoB;QAC9B,eAAU,GAAV,UAAU,CAAoB;QAC9B,YAAO,GAAP,OAAO,CAAyB;QAEnD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAA;QACxC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAA;IAChD,CAAC;IAOY,8CAAW,GAAxB;;;gBACE,sBAAO,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,EAAA;;;KAC3C;IAEY,0DAAuB,GAApC,UAAqC,SAAwC;;;gBAC3E,sBAAO,IAAI,CAAC,gBAAgB,CAAC,uBAAuB,CAAC,SAAS,CAAC,EAAA;;;KAChE;IAEY,8DAA2B,GAAxC,UACE,iBAAoC,EACpC,eAAuB,EACvB,YAAoB;;;gBAEpB,sBAAO,IAAI,CAAC,gBAAg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/module-kit';
|
|
3
|
-
import { OptimismProtocolNetwork, OptimismProtocolOptions
|
|
4
|
-
|
|
2
|
+
import { OptimismProtocolNetwork, OptimismProtocolOptions } from '../types/protocol';
|
|
3
|
+
import { OptimismBaseProtocol } from './OptimismBaseProtocol';
|
|
4
|
+
export interface OptimismProtocol extends OptimismBaseProtocol {
|
|
5
5
|
}
|
|
6
6
|
export declare function createOptimismProtocol(options?: RecursivePartial<OptimismProtocolOptions>): OptimismProtocol;
|
|
7
7
|
export declare const OPTIMISM_MAINNET_PROTOCOL_NETWORK: OptimismProtocolNetwork;
|
|
@@ -29,29 +29,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.createOptimismProtocolOptions = exports.OPTIMISM_MAINNET_PROTOCOL_NETWORK = exports.createOptimismProtocol = void 0;
|
|
30
30
|
var coinlib_core_1 = require("@airgap/coinlib-core");
|
|
31
31
|
var v1_1 = require("@airgap/ethereum/v1");
|
|
32
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
33
|
+
var AirGapNodeClient_1 = require("../client/node/AirGapNodeClient");
|
|
34
|
+
var OptimismBaseProtocol_1 = require("./OptimismBaseProtocol");
|
|
32
35
|
// Implementation
|
|
33
36
|
var OptimismProtocolImpl = /** @class */ (function (_super) {
|
|
34
37
|
__extends(OptimismProtocolImpl, _super);
|
|
35
38
|
function OptimismProtocolImpl(options) {
|
|
36
39
|
var completeOptions = createOptimismProtocolOptions(options.network);
|
|
37
|
-
var nodeClient = new
|
|
40
|
+
var nodeClient = new AirGapNodeClient_1.AirGapNodeClient(completeOptions.network.rpcUrl);
|
|
38
41
|
var infoClient = new v1_1.EtherscanInfoClient(completeOptions.network.blockExplorerApi, completeOptions.network.blockExplorerApiKey);
|
|
39
|
-
|
|
42
|
+
var baseProtocolOptions = {
|
|
40
43
|
network: completeOptions.network,
|
|
41
|
-
contractAddress: completeOptions.network.contractAddress,
|
|
42
|
-
name: 'Optimism',
|
|
43
44
|
identifier: coinlib_core_1.MainProtocolSymbols.OPTIMISM,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
name: 'Optimism',
|
|
46
|
+
units: v1_1.DEFAULT_ETHEREUM_UNITS_METADATA,
|
|
47
|
+
mainUnit: 'ETH',
|
|
48
|
+
// The layer 2 gas price is normally 0.001 gwei, but it increases when experiencing heavy congestion
|
|
49
|
+
feeDefaults: {
|
|
50
|
+
low: (0, module_kit_1.newAmount)(15.75 /* 21000 GAS * 0.00075 GWEI */, 'GWEI').blockchain(v1_1.DEFAULT_ETHEREUM_UNITS_METADATA),
|
|
51
|
+
medium: (0, module_kit_1.newAmount)(22.05 /* 21000 GAS * 0.00105 GWEI */, 'GWEI').blockchain(v1_1.DEFAULT_ETHEREUM_UNITS_METADATA),
|
|
52
|
+
high: (0, module_kit_1.newAmount)(44.1 /* 21000 GAS * 0.0021 GWEI */, 'GWEI').blockchain(v1_1.DEFAULT_ETHEREUM_UNITS_METADATA)
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var ethereumProtocol = new v1_1.EthereumBaseProtocolImpl(nodeClient, infoClient, baseProtocolOptions);
|
|
56
|
+
return _super.call(this, ethereumProtocol, nodeClient, infoClient, completeOptions) || this;
|
|
52
57
|
}
|
|
53
58
|
return OptimismProtocolImpl;
|
|
54
|
-
}(
|
|
59
|
+
}(OptimismBaseProtocol_1.OptimismBaseProtocolImpl));
|
|
55
60
|
// Factory
|
|
56
61
|
function createOptimismProtocol(options) {
|
|
57
62
|
if (options === void 0) { options = {}; }
|
|
@@ -61,11 +66,11 @@ exports.createOptimismProtocol = createOptimismProtocol;
|
|
|
61
66
|
exports.OPTIMISM_MAINNET_PROTOCOL_NETWORK = {
|
|
62
67
|
name: 'Mainnet',
|
|
63
68
|
type: 'mainnet',
|
|
64
|
-
rpcUrl: 'https://mainnet.
|
|
69
|
+
rpcUrl: 'https://opt-mainnet.g.alchemy.com/v2/fVtiJ6xrTqHg0fvaCYyIfF8S5p_7vnr4',
|
|
65
70
|
chainId: 10,
|
|
66
|
-
contractAddress: '0x4200000000000000000000000000000000000042',
|
|
67
71
|
blockExplorerApi: 'https://api-optimistic.etherscan.io',
|
|
68
|
-
blockExplorerApiKey: 'WQC6EZP3IZU2I1JHVTREI3V3E8K4GYGPN8'
|
|
72
|
+
blockExplorerApiKey: 'WQC6EZP3IZU2I1JHVTREI3V3E8K4GYGPN8',
|
|
73
|
+
gasPriceOracleAddress: '0x420000000000000000000000000000000000000F'
|
|
69
74
|
};
|
|
70
75
|
var DEFAULT_OPTIMISM_PROTOCOL_NETWORK = exports.OPTIMISM_MAINNET_PROTOCOL_NETWORK;
|
|
71
76
|
function createOptimismProtocolOptions(network) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptimismProtocol.js","sourceRoot":"","sources":["../../../src/v1/protocol/OptimismProtocol.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA0D;AAC1D,
|
|
1
|
+
{"version":3,"file":"OptimismProtocol.js","sourceRoot":"","sources":["../../../src/v1/protocol/OptimismProtocol.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA0D;AAC1D,0CAM4B;AAC5B,iDAAgE;AAEhE,oEAAkE;AAGlE,+DAAuF;AAMvF,iBAAiB;AAEjB;IAAmC,wCAAwB;IACzD,8BAAY,OAAkD;QAC5D,IAAM,eAAe,GAAG,6BAA6B,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAEtE,IAAM,UAAU,GAAG,IAAI,mCAAgB,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QACvE,IAAM,UAAU,GAAG,IAAI,wBAAmB,CAAC,eAAe,CAAC,OAAO,CAAC,gBAAgB,EAAE,eAAe,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;QAEjI,IAAM,mB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,EAAA,YAA8C;IAC1F,OAAO;QACL,OAAO,wBAAO,iCAAiC,GAAK,OAAO,CAAE;KAC9D,CAAA;AACH,CAAC;AAJD,sEAIC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ERC20TokenMetadata, ERC20TokenOptions, EthereumProtocolNetwork } from '@airgap/ethereum/v1';
|
|
2
|
+
import { AirGapInterface, RecursivePartial } from '@airgap/module-kit';
|
|
3
|
+
import { OptimismProtocolNetwork, OptimismProtocolOptions } from '../../types/protocol';
|
|
4
|
+
import { OptimismBaseProtocol } from '../OptimismBaseProtocol';
|
|
5
|
+
export interface ERC20Token extends AirGapInterface<OptimismBaseProtocol<string>, 'SingleTokenSubProtocol'> {
|
|
6
|
+
}
|
|
7
|
+
export declare function createERC20Token(metadata: ERC20TokenMetadata, options?: RecursivePartial<OptimismProtocolOptions>): ERC20Token;
|
|
8
|
+
export declare const OPTIMISM_ERC20_MAINNET_PROTOCOL_NETWORK: OptimismProtocolNetwork;
|
|
9
|
+
export declare function createERC20TokenOptions(metadata: ERC20TokenMetadata, network?: Partial<EthereumProtocolNetwork>): ERC20TokenOptions<OptimismProtocolNetwork>;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Factory
|
|
3
|
+
var __extends = (this && this.__extends) || (function () {
|
|
4
|
+
var extendStatics = function (d, b) {
|
|
5
|
+
extendStatics = Object.setPrototypeOf ||
|
|
6
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
7
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
8
|
+
return extendStatics(d, b);
|
|
9
|
+
};
|
|
10
|
+
return function (d, b) {
|
|
11
|
+
if (typeof b !== "function" && b !== null)
|
|
12
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
13
|
+
extendStatics(d, b);
|
|
14
|
+
function __() { this.constructor = d; }
|
|
15
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
16
|
+
};
|
|
17
|
+
})();
|
|
18
|
+
var __assign = (this && this.__assign) || function () {
|
|
19
|
+
__assign = Object.assign || function(t) {
|
|
20
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
21
|
+
s = arguments[i];
|
|
22
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
23
|
+
t[p] = s[p];
|
|
24
|
+
}
|
|
25
|
+
return t;
|
|
26
|
+
};
|
|
27
|
+
return __assign.apply(this, arguments);
|
|
28
|
+
};
|
|
29
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
30
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
31
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
32
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
33
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
34
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
35
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
39
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
40
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
41
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
42
|
+
function step(op) {
|
|
43
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
44
|
+
while (_) try {
|
|
45
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
46
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
47
|
+
switch (op[0]) {
|
|
48
|
+
case 0: case 1: t = op; break;
|
|
49
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
50
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
51
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
52
|
+
default:
|
|
53
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
54
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
55
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
56
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
57
|
+
if (t[2]) _.ops.pop();
|
|
58
|
+
_.trys.pop(); continue;
|
|
59
|
+
}
|
|
60
|
+
op = body.call(thisArg, _);
|
|
61
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
62
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
|
+
exports.createERC20TokenOptions = exports.OPTIMISM_ERC20_MAINNET_PROTOCOL_NETWORK = exports.createERC20Token = void 0;
|
|
67
|
+
var coinlib_core_1 = require("@airgap/coinlib-core");
|
|
68
|
+
var v1_1 = require("@airgap/ethereum/v1");
|
|
69
|
+
var AirGapNodeClient_1 = require("../../client/node/AirGapNodeClient");
|
|
70
|
+
var OptimismBaseProtocol_1 = require("../OptimismBaseProtocol");
|
|
71
|
+
var OptimismProtocol_1 = require("../OptimismProtocol");
|
|
72
|
+
// Implementation
|
|
73
|
+
var ERC20TokenImpl = /** @class */ (function (_super) {
|
|
74
|
+
__extends(ERC20TokenImpl, _super);
|
|
75
|
+
function ERC20TokenImpl(options) {
|
|
76
|
+
var nodeClient = new AirGapNodeClient_1.AirGapNodeClient(options.network.rpcUrl);
|
|
77
|
+
var infoClient = new v1_1.EtherscanInfoClient(options.network.blockExplorerApi, options.network.blockExplorerApiKey);
|
|
78
|
+
var ethereumProtocol = new v1_1.ERC20TokenImpl(nodeClient, infoClient, options);
|
|
79
|
+
return _super.call(this, ethereumProtocol, nodeClient, infoClient, options) || this;
|
|
80
|
+
}
|
|
81
|
+
ERC20TokenImpl.prototype.getType = function () {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
+
return __generator(this, function (_a) {
|
|
84
|
+
return [2 /*return*/, this.ethereumProtocol.getType()];
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
ERC20TokenImpl.prototype.mainProtocol = function () {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
+
return __generator(this, function (_a) {
|
|
91
|
+
return [2 /*return*/, this.ethereumProtocol.mainProtocol()];
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
ERC20TokenImpl.prototype.getContractAddress = function () {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
return [2 /*return*/, this.ethereumProtocol.getContractAddress()];
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
return ERC20TokenImpl;
|
|
103
|
+
}(OptimismBaseProtocol_1.OptimismBaseProtocolImpl));
|
|
104
|
+
function createERC20Token(metadata, options) {
|
|
105
|
+
if (options === void 0) { options = {}; }
|
|
106
|
+
var completeOptions = createERC20TokenOptions(metadata, options.network);
|
|
107
|
+
return new ERC20TokenImpl(completeOptions);
|
|
108
|
+
}
|
|
109
|
+
exports.createERC20Token = createERC20Token;
|
|
110
|
+
exports.OPTIMISM_ERC20_MAINNET_PROTOCOL_NETWORK = OptimismProtocol_1.OPTIMISM_MAINNET_PROTOCOL_NETWORK;
|
|
111
|
+
var DEFAULT_ERC20_PROTOCOL_NETWORK = exports.OPTIMISM_ERC20_MAINNET_PROTOCOL_NETWORK;
|
|
112
|
+
function createERC20TokenOptions(metadata, network) {
|
|
113
|
+
var _a;
|
|
114
|
+
if (network === void 0) { network = {}; }
|
|
115
|
+
return {
|
|
116
|
+
network: __assign(__assign({}, DEFAULT_ERC20_PROTOCOL_NETWORK), network),
|
|
117
|
+
name: metadata.name,
|
|
118
|
+
identifier: metadata.identifier,
|
|
119
|
+
mainIdentifier: coinlib_core_1.MainProtocolSymbols.OPTIMISM,
|
|
120
|
+
contractAddress: metadata.contractAddress,
|
|
121
|
+
units: (_a = {},
|
|
122
|
+
_a[metadata.symbol] = {
|
|
123
|
+
symbol: { value: metadata.symbol, market: metadata.marketSymbol },
|
|
124
|
+
decimals: metadata.decimals
|
|
125
|
+
},
|
|
126
|
+
_a),
|
|
127
|
+
mainUnit: metadata.symbol
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
exports.createERC20TokenOptions = createERC20TokenOptions;
|
|
131
|
+
//# sourceMappingURL=ERC20Token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ERC20Token.js","sourceRoot":"","sources":["../../../../src/v1/protocol/erc20/ERC20Token.ts"],"names":[],"mappings":";AAAA,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEV,qDAA0D;AAC1D,0CAM4B;AAG5B,uEAAqE;AAErE,gEAAwF;AACxF,wDAAuE;AAMvE,iBAAiB;AAEjB;IAA6B,kCAAiF;IAC5G,wBAAY,OAAmD;QAC7D,IAAM,UAAU,GAAG,IAAI,mCAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAC/D,IAAM,UAAU,GAAG,IAAI,wBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC,gBAAgB,EAAE,OAAO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