@airgap/optimism 0.13.45-beta.2 → 0.13.45-beta.3
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 +6 -6
- package/v1/client/info/OptimismInfoClient.d.ts +1 -1
- package/v1/client/node/HttpOptimismNodeClient.js +24 -90
- package/v1/client/node/HttpOptimismNodeClient.js.map +1 -1
- package/v1/index.js +4 -4
- package/v1/index.js.map +1 -1
- package/v1/module/OptimismModule.js +71 -161
- package/v1/module/OptimismModule.js.map +1 -1
- package/v1/module.js +2 -3
- package/v1/module.js.map +1 -1
- package/v1/protocol/OptimismBaseProtocol.js +154 -352
- package/v1/protocol/OptimismBaseProtocol.js.map +1 -1
- package/v1/protocol/OptimismProtocol.js +27 -54
- package/v1/protocol/OptimismProtocol.js.map +1 -1
- package/v1/protocol/erc20/ERC20Token.js +63 -169
- package/v1/protocol/erc20/ERC20Token.js.map +1 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +30 -30
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
- package/v1/serializer/v3/serializer-companion.js +73 -152
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/serializer/v3/validators/transaction-validator.js +3 -23
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
- package/v1/types/crypto.d.ts +1 -1
- package/v1/types/transaction.d.ts +3 -3
- package/v1/utils/protocol.js +30 -19
- package/v1/utils/protocol.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@airgap/optimism",
|
|
3
|
-
"version": "0.13.45-beta.
|
|
3
|
+
"version": "0.13.45-beta.3",
|
|
4
4
|
"description": "The @airgap/optimism is an Optimism implementation of the ICoinProtocol interface from @airgap/coinlib-core.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"airgap",
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
},
|
|
32
32
|
"author": "Papers AG <contact@papers.ch> (https://papers.ch)",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@airgap/coinlib-core": "^0.13.45-beta.
|
|
35
|
-
"@airgap/crypto": "^0.13.45-beta.
|
|
36
|
-
"@airgap/ethereum": "^0.13.45-beta.
|
|
37
|
-
"@airgap/module-kit": "^0.13.45-beta.
|
|
38
|
-
"@airgap/serializer": "^0.13.45-beta.
|
|
34
|
+
"@airgap/coinlib-core": "^0.13.45-beta.3",
|
|
35
|
+
"@airgap/crypto": "^0.13.45-beta.3",
|
|
36
|
+
"@airgap/ethereum": "^0.13.45-beta.3",
|
|
37
|
+
"@airgap/module-kit": "^0.13.45-beta.3",
|
|
38
|
+
"@airgap/serializer": "^0.13.45-beta.3",
|
|
39
39
|
"@ethereumjs/tx": "3.4.0"
|
|
40
40
|
},
|
|
41
41
|
"nyc": {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { EthereumInfoClient } from '@airgap/ethereum/v1';
|
|
2
|
-
export
|
|
2
|
+
export type OptimismInfoClient = EthereumInfoClient;
|
|
@@ -1,69 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (_) try {
|
|
33
|
-
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;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
4
|
};
|
|
56
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
6
|
exports.HttpOptimismNodeClient = void 0;
|
|
58
7
|
// tslint:disable: max-classes-per-file
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
8
|
+
const bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
9
|
+
const v1_1 = require("@airgap/ethereum/v1");
|
|
10
|
+
const tx_1 = require("@ethereumjs/tx");
|
|
11
|
+
class OptimismRPCDataGetL1Fee extends v1_1.EthereumRPCData {
|
|
12
|
+
static { this.methodName = 'getL1Fee'; }
|
|
13
|
+
constructor(tx) {
|
|
14
|
+
super(`${OptimismRPCDataGetL1Fee.methodName}(bytes)`);
|
|
15
|
+
this.bytes =
|
|
67
16
|
tx.ethereumType === 'raw'
|
|
68
17
|
? tx_1.Transaction.fromTxData({
|
|
69
18
|
nonce: tx.nonce,
|
|
@@ -74,41 +23,26 @@ var OptimismRPCDataGetL1Fee = /** @class */ (function (_super) {
|
|
|
74
23
|
data: tx.data
|
|
75
24
|
}).serialize()
|
|
76
25
|
: Buffer.from(tx.serialized, 'hex');
|
|
77
|
-
return _this;
|
|
78
26
|
}
|
|
79
|
-
|
|
80
|
-
|
|
27
|
+
abiEncoded() {
|
|
28
|
+
let bytesLength = v1_1.EthereumUtils.toHex(this.bytes.length);
|
|
81
29
|
if (bytesLength.startsWith('0x')) {
|
|
82
30
|
bytesLength = bytesLength.slice(2);
|
|
83
31
|
}
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
32
|
+
return super.abiEncoded() + v1_1.EthereumRPCData.addLeadingZeroPadding(bytesLength + this.bytes.toString('hex'), 256);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
class HttpOptimismNodeClient extends v1_1.HttpEthereumNodeClient {
|
|
36
|
+
constructor(baseURL, headers) {
|
|
37
|
+
super(baseURL, headers);
|
|
38
|
+
}
|
|
39
|
+
async getL1Fee(contractAddress, tx) {
|
|
40
|
+
const data = new OptimismRPCDataGetL1Fee(tx);
|
|
41
|
+
const body = new v1_1.EthereumRPCBody('eth_call', [{ to: contractAddress, data: data.abiEncoded() }, v1_1.EthereumRPCBody.blockLatest]);
|
|
42
|
+
const response = await this.send(body);
|
|
43
|
+
const fee = new bignumber_1.default(response.result);
|
|
44
|
+
return fee.isNaN() ? new bignumber_1.default(0) : fee;
|
|
93
45
|
}
|
|
94
|
-
|
|
95
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
96
|
-
var data, body, response, fee;
|
|
97
|
-
return __generator(this, function (_a) {
|
|
98
|
-
switch (_a.label) {
|
|
99
|
-
case 0:
|
|
100
|
-
data = new OptimismRPCDataGetL1Fee(tx);
|
|
101
|
-
body = new v1_1.EthereumRPCBody('eth_call', [{ to: contractAddress, data: data.abiEncoded() }, v1_1.EthereumRPCBody.blockLatest]);
|
|
102
|
-
return [4 /*yield*/, this.send(body)];
|
|
103
|
-
case 1:
|
|
104
|
-
response = _a.sent();
|
|
105
|
-
fee = new bignumber_1.default(response.result);
|
|
106
|
-
return [2 /*return*/, fee.isNaN() ? new bignumber_1.default(0) : fee];
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
return HttpOptimismNodeClient;
|
|
112
|
-
}(v1_1.HttpEthereumNodeClient));
|
|
46
|
+
}
|
|
113
47
|
exports.HttpOptimismNodeClient = HttpOptimismNodeClient;
|
|
114
48
|
//# sourceMappingURL=HttpOptimismNodeClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpOptimismNodeClient.js","sourceRoot":"","sources":["../../../../src/v1/client/node/HttpOptimismNodeClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HttpOptimismNodeClient.js","sourceRoot":"","sources":["../../../../src/v1/client/node/HttpOptimismNodeClient.ts"],"names":[],"mappings":";;;;;;AAAA,uCAAuC;AACvC,mHAA0F;AAC1F,4CAA0I;AAC1I,uCAA4C;AAI5C,MAAM,uBAAwB,SAAQ,oBAAe;aACrC,eAAU,GAAW,UAAU,CAAA;IAG7C,YAAY,EAA+B;QACzC,KAAK,CAAC,GAAG,uBAAuB,CAAC,UAAU,SAAS,CAAC,CAAA;QACrD,IAAI,CAAC,KAAK;YACR,EAAE,CAAC,YAAY,KAAK,KAAK;gBACvB,CAAC,CAAC,gBAAW,CAAC,UAAU,CAAC;oBACrB,KAAK,EAAE,EAAE,CAAC,KAAK;oBACf,QAAQ,EAAE,EAAE,CAAC,QAAQ;oBACrB,QAAQ,EAAE,EAAE,CAAC,QAAQ;oBACrB,EAAE,EAAE,EAAE,CAAC,EAAE;oBACT,KAAK,EAAE,EAAE,CAAC,KAAK;oBACf,IAAI,EAAE,EAAE,CAAC,IAAI;iBACd,CAAC,CAAC,SAAS,EAAE;gBAChB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC,CA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ule", { value: true });
|
|
3
3
|
exports.isOptimismERC20Token = exports.isOptimismProtocol = exports.isAnyOptimismProtocol = exports.createERC20Token = exports.createOptimismProtocol = exports.OptimismModule = void 0;
|
|
4
|
-
|
|
4
|
+
const OptimismModule_1 = require("./module/OptimismModule");
|
|
5
5
|
Object.defineProperty(exports, "OptimismModule", { enumerable: true, get: function () { return OptimismModule_1.OptimismModule; } });
|
|
6
|
-
|
|
6
|
+
const ERC20Token_1 = require("./protocol/erc20/ERC20Token");
|
|
7
7
|
Object.defineProperty(exports, "createERC20Token", { enumerable: true, get: function () { return ERC20Token_1.createERC20Token; } });
|
|
8
|
-
|
|
8
|
+
const OptimismProtocol_1 = require("./protocol/OptimismProtocol");
|
|
9
9
|
Object.defineProperty(exports, "createOptimismProtocol", { enumerable: true, get: function () { return OptimismProtocol_1.createOptimismProtocol; } });
|
|
10
|
-
|
|
10
|
+
const protocol_1 = require("./utils/protocol");
|
|
11
11
|
Object.defineProperty(exports, "isAnyOptimismProtocol", { enumerable: true, get: function () { return protocol_1.isAnyOptimismProtocol; } });
|
|
12
12
|
Object.defineProperty(exports, "isOptimismERC20Token", { enumerable: true, get: function () { return protocol_1.isOptimismERC20Token; } });
|
|
13
13
|
Object.defineProperty(exports, "isOptimismProtocol", { enumerable: true, get: function () { return protocol_1.isOptimismProtocol; } });
|
package/v1/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/v1/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/v1/index.ts"],"names":[],"mappings":";;;AAAA,4DAAwD;AAgB/C,+FAhBA,+BAAc,OAgBA;AAfvB,4DAA0E;AAmBX,iGAnBtD,6BAAgB,OAmBsD;AAlB/E,kEAAsF;AAkB3D,uGAlBlB,yCAAsB,OAkBkB;AARjD,+CAAkG;AAyBzF,sGAzBA,gCAAqB,OAyBA;AAAsB,qGAzBpB,+BAAoB,OAyBoB;AAAxC,mGAzBsB,6BAAkB,OAyBtB"}
|
|
@@ -1,182 +1,92 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
3
|
exports.OptimismModule = void 0;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var networkRegistry = new module_kit_1.ModuleNetworkRegistry({
|
|
4
|
+
const coinlib_core_1 = require("@airgap/coinlib-core");
|
|
5
|
+
const errors_1 = require("@airgap/coinlib-core/errors");
|
|
6
|
+
const v1_1 = require("@airgap/ethereum/v1");
|
|
7
|
+
const module_kit_1 = require("@airgap/module-kit");
|
|
8
|
+
const module_1 = require("../module");
|
|
9
|
+
const ERC20Token_1 = require("../protocol/erc20/ERC20Token");
|
|
10
|
+
const OptimismProtocol_1 = require("../protocol/OptimismProtocol");
|
|
11
|
+
const serializer_companion_1 = require("../serializer/v3/serializer-companion");
|
|
12
|
+
const ERC20Tokens_1 = require("./ERC20Tokens");
|
|
13
|
+
class OptimismModule {
|
|
14
|
+
constructor() {
|
|
15
|
+
const networkRegistry = new module_kit_1.ModuleNetworkRegistry({
|
|
64
16
|
supportedNetworks: [OptimismProtocol_1.OPTIMISM_MAINNET_PROTOCOL_NETWORK]
|
|
65
17
|
});
|
|
66
|
-
|
|
18
|
+
const erc20NetworkRegistry = new module_kit_1.ModuleNetworkRegistry({
|
|
67
19
|
supportedNetworks: [ERC20Token_1.OPTIMISM_ERC20_MAINNET_PROTOCOL_NETWORK]
|
|
68
20
|
});
|
|
69
|
-
this.networkRegistries =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
21
|
+
this.networkRegistries = {
|
|
22
|
+
[coinlib_core_1.MainProtocolSymbols.OPTIMISM]: networkRegistry,
|
|
23
|
+
...ERC20Tokens_1.erc20TokensIdentifiers.reduce((obj, next) => Object.assign(obj, { [next]: erc20NetworkRegistry }), {})
|
|
24
|
+
};
|
|
73
25
|
this.supportedProtocols = (0, module_kit_1.createSupportedProtocols)(this.networkRegistries);
|
|
74
26
|
}
|
|
75
|
-
|
|
76
|
-
return
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
var _a;
|
|
97
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
-
var network;
|
|
99
|
-
return __generator(this, function (_b) {
|
|
100
|
-
network = typeof networkOrId === 'object' ? networkOrId : (_a = this.networkRegistries[identifier]) === null || _a === void 0 ? void 0 : _a.findNetwork(networkOrId);
|
|
101
|
-
if (network === undefined) {
|
|
102
|
-
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.OPTIMISM, 'Block Explorer network type not supported.');
|
|
103
|
-
}
|
|
104
|
-
return [2 /*return*/, new v1_1.EtherscanBlockExplorer(network.blockExplorerUrl)];
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
OptimismModule.prototype.createV3SerializerCompanion = function () {
|
|
109
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
110
|
-
return __generator(this, function (_a) {
|
|
111
|
-
return [2 /*return*/, new serializer_companion_1.OptimismV3SerializerCompanion()];
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
OptimismModule.prototype.createProtocol = function (identifier, network) {
|
|
27
|
+
async createOfflineProtocol(identifier) {
|
|
28
|
+
return this.createProtocol(identifier);
|
|
29
|
+
}
|
|
30
|
+
async createOnlineProtocol(identifier, networkOrId) {
|
|
31
|
+
const network = typeof networkOrId === 'object' ? networkOrId : this.networkRegistries[identifier]?.findNetwork(networkOrId);
|
|
32
|
+
if (network === undefined) {
|
|
33
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.OPTIMISM, 'Protocol network type not supported.');
|
|
34
|
+
}
|
|
35
|
+
return this.createProtocol(identifier, network);
|
|
36
|
+
}
|
|
37
|
+
async createBlockExplorer(identifier, networkOrId) {
|
|
38
|
+
const network = typeof networkOrId === 'object' ? networkOrId : this.networkRegistries[identifier]?.findNetwork(networkOrId);
|
|
39
|
+
if (network === undefined) {
|
|
40
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.OPTIMISM, 'Block Explorer network type not supported.');
|
|
41
|
+
}
|
|
42
|
+
return new v1_1.EtherscanBlockExplorer(network.blockExplorerUrl);
|
|
43
|
+
}
|
|
44
|
+
async createV3SerializerCompanion() {
|
|
45
|
+
return new serializer_companion_1.OptimismV3SerializerCompanion();
|
|
46
|
+
}
|
|
47
|
+
createProtocol(identifier, network) {
|
|
116
48
|
if (identifier === coinlib_core_1.MainProtocolSymbols.OPTIMISM) {
|
|
117
|
-
return (0, OptimismProtocol_1.createOptimismProtocol)({ network
|
|
49
|
+
return (0, OptimismProtocol_1.createOptimismProtocol)({ network });
|
|
118
50
|
}
|
|
119
51
|
if (ERC20Tokens_1.erc20Tokens[identifier] !== undefined) {
|
|
120
|
-
|
|
52
|
+
const tokenMetadata = ERC20Tokens_1.erc20Tokens[identifier];
|
|
121
53
|
return (0, ERC20Token_1.createERC20Token)(tokenMetadata);
|
|
122
54
|
}
|
|
123
|
-
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.OPTIMISM,
|
|
124
|
-
}
|
|
55
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.OPTIMISM, `Protocol ${identifier} not supported.`);
|
|
56
|
+
}
|
|
125
57
|
// ProtocolSerializer
|
|
126
|
-
|
|
127
|
-
return
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
};
|
|
154
|
-
OptimismModule.prototype.serializeProtocol = function (protocol, type) {
|
|
155
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
156
|
-
var _a, metadata, serializedProtocol;
|
|
157
|
-
return __generator(this, function (_b) {
|
|
158
|
-
switch (_b.label) {
|
|
159
|
-
case 0:
|
|
160
|
-
if (!(0, module_1.isOptimismERC20Token)(protocol)) return [3 /*break*/, 2];
|
|
161
|
-
return [4 /*yield*/, Promise.all([
|
|
162
|
-
protocol.getMetadata(),
|
|
163
|
-
(0, ERC20Token_1.serializeERC20Token)(protocol)
|
|
164
|
-
])];
|
|
165
|
-
case 1:
|
|
166
|
-
_a = _b.sent(), metadata = _a[0], serializedProtocol = _a[1];
|
|
167
|
-
return [2 /*return*/, __assign({ type: type, identifier: metadata.identifier }, serializedProtocol)];
|
|
168
|
-
case 2: return [2 /*return*/, undefined];
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
};
|
|
173
|
-
OptimismModule.prototype.deserializeProtocol = function (serialized) {
|
|
58
|
+
async serializeOfflineProtocol(protocol) {
|
|
59
|
+
return this.serializeProtocol(protocol, 'offline');
|
|
60
|
+
}
|
|
61
|
+
async deserializeOfflineProtocol(serialized) {
|
|
62
|
+
return this.deserializeProtocol(serialized);
|
|
63
|
+
}
|
|
64
|
+
async serializeOnlineProtocol(protocol) {
|
|
65
|
+
return this.serializeProtocol(protocol, 'online');
|
|
66
|
+
}
|
|
67
|
+
async deserializeOnlineProtocol(serialized) {
|
|
68
|
+
return this.deserializeProtocol(serialized);
|
|
69
|
+
}
|
|
70
|
+
async serializeProtocol(protocol, type) {
|
|
71
|
+
if ((0, module_1.isOptimismERC20Token)(protocol)) {
|
|
72
|
+
const [metadata, serializedProtocol] = await Promise.all([
|
|
73
|
+
protocol.getMetadata(),
|
|
74
|
+
(0, ERC20Token_1.serializeERC20Token)(protocol)
|
|
75
|
+
]);
|
|
76
|
+
return {
|
|
77
|
+
type,
|
|
78
|
+
identifier: metadata.identifier,
|
|
79
|
+
...serializedProtocol
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
deserializeProtocol(serialized) {
|
|
174
85
|
if (serialized.identifier.startsWith(coinlib_core_1.SubProtocolSymbols.OPTIMISM_ERC20) && (0, ERC20Token_1.isSerializedERC20Token)(serialized)) {
|
|
175
86
|
return (0, ERC20Token_1.deserializeERC20Token)(serialized);
|
|
176
87
|
}
|
|
177
88
|
return undefined;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
}());
|
|
89
|
+
}
|
|
90
|
+
}
|
|
181
91
|
exports.OptimismModule = OptimismModule;
|
|
182
92
|
//# sourceMappingURL=OptimismModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptimismModule.js","sourceRoot":"","sources":["../../../src/v1/module/OptimismModule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OptimismModule.js","sourceRoot":"","sources":["../../../src/v1/module/OptimismModule.ts"],"names":[],"mappings":";;;AAAA,uDAAsF;AACtF,wDAAqE;AACrE,4CAAgF;AAChF,mDAgB2B;AAE3B,sCAAgD;AAChD,6DAMqC;AACrC,mEAAwG;AACxG,gFAAqF;AAGrF,+CAAmE;AAEnE,MAAa,cAAc;IAIzB;QACE,MAAM,eAAe,GAA0B,IAAI,kCAAqB,CAAC;YACvE,iBAAiB,EAAE,CAAC,oDAAiC,CAAC;SACvD,CAAC,CAAA;QACF,MAAM,oBAAoB,GAA0B,IAAI,kCAAqB,CAAC;YAC5E,iBAAiB,EAAE,CAAC,oDAAuC,CAAC;SAC7D,CAAC,CAAA;QAEF,IAAI,CAAC,iBAAiB,GAAG;YACvB,CAAC,kCAAmB,CAAC,QAAQ,CAAC,EAAE,eAAe;YAC/C,GAAG,oCAAsB,CAAC,MAAM,CAC9B,CAAC,GAA0C,EAAE,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,oBAAoB,EAAE,CAAC,EAClH,EAAE,CACH;SACF,CAAA;QACD,IAAI,CAAC,kBAAkB,GAAG,IAAA,qCAAwB,EAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;IAC5E,CAAC;IAEM,KAAK,CAAC,qBAAqB,CAAC,UAAkB;QACnD,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU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UAAU,CAAC,EAAE,CAAC;YAC9G,OAAO,IAAA,kCAAqB,EAAC,UAAU,CAAC,CAAA;QAC1C,CAAC;QAED,OAAO,SAAS,CAAA;IAClB,CAAC;CACF;AA5HD,wCA4HC"}
|
package/v1/module.js
CHANGED
|
@@ -14,11 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.create =
|
|
18
|
-
|
|
17
|
+
exports.create = create;
|
|
18
|
+
const OptimismModule_1 = require("./module/OptimismModule");
|
|
19
19
|
__exportStar(require("./index"), exports);
|
|
20
20
|
function create() {
|
|
21
21
|
return new OptimismModule_1.OptimismModule();
|
|
22
22
|
}
|
|
23
|
-
exports.create = create;
|
|
24
23
|
//# sourceMappingURL=module.js.map
|
package/v1/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/v1/module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/v1/module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAKA,wBAEC;AAND,4DAAwD;AAExD,0CAAuB;AAEvB,SAAgB,MAAM;IACpB,OAAO,IAAI,+BAAc,EAAE,CAAA;AAC7B,CAAC"}
|