@openocean.finance/openocean-sdk 0.1.72 → 0.1.73
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/api/index.js +136 -0
- package/lib/api/vo/RequestVo.js +401 -0
- package/lib/asset/abi/ERC20_abi.js +119 -0
- package/lib/asset/abi/aggregator.js +391 -0
- package/lib/config/Chains.js +508 -0
- package/lib/config/Wallets.js +81 -0
- package/lib/config/index.js +11 -0
- package/lib/index.js +20 -2
- package/lib/swapSdk/Approve.js +227 -0
- package/lib/swapSdk/ConnectWallet.js +311 -0
- package/lib/swapSdk/NotoMobile.js +141 -0
- package/lib/swapSdk/RequestVo.js +94 -0
- package/lib/swapSdk/Swap.js +739 -0
- package/lib/swapSdk/getAllowance.js +97 -0
- package/lib/swapSdk/getBalance.js +220 -0
- package/lib/swapSdk/index.js +277 -0
- package/lib/swapSdk/limitOrder.js +234 -0
- package/lib/swapSdk/qrcode.d.ts +6 -0
- package/lib/swapSdk/qrcode.js +969 -0
- package/lib/utils/ajx.js +150 -0
- package/lib/utils/index.js +91 -0
- package/lib/utils/limit-order-sdk/connector/private-key-provider.connector.d.ts +10 -0
- package/lib/utils/limit-order-sdk/connector/private-key-provider.connector.js +36 -0
- package/lib/utils/limit-order-sdk/connector/provider.connector.d.ts +1 -0
- package/lib/utils/limit-order-sdk/connector/provider.connector.js +2 -0
- package/lib/utils/limit-order-sdk/connector/web3-provider.connector.d.ts +9 -0
- package/lib/utils/limit-order-sdk/connector/web3-provider.connector.js +38 -0
- package/lib/utils/limit-order-sdk/erc20.facade.d.ts +7 -0
- package/lib/utils/limit-order-sdk/erc20.facade.js +19 -0
- package/lib/utils/limit-order-sdk/index.d.ts +1 -0
- package/lib/utils/limit-order-sdk/index.js +14 -0
- package/lib/utils/limit-order-sdk/limit-order-predicate.builder.d.ts +12 -0
- package/lib/utils/limit-order-sdk/limit-order-predicate.builder.js +60 -0
- package/lib/utils/limit-order-sdk/limit-order-protocol.const.d.ts +18 -0
- package/lib/utils/limit-order-sdk/limit-order-protocol.const.js +45 -0
- package/lib/utils/limit-order-sdk/limit-order-protocol.facade.d.ts +26 -0
- package/lib/utils/limit-order-sdk/limit-order-protocol.facade.js +180 -0
- package/lib/utils/limit-order-sdk/limit-order.builder.d.ts +101 -0
- package/lib/utils/limit-order-sdk/limit-order.builder.js +120 -0
- package/lib/utils/limit-order-sdk/model/abi.model.d.ts +1 -0
- package/lib/utils/limit-order-sdk/model/abi.model.js +2 -0
- package/lib/utils/limit-order-sdk/model/eip712.model.d.ts +1 -0
- package/lib/utils/limit-order-sdk/model/eip712.model.js +2 -0
- package/lib/utils/limit-order-sdk/model/limit-order-protocol.model.d.ts +3 -0
- package/lib/utils/limit-order-sdk/model/limit-order-protocol.model.js +38 -0
- package/lib/utils/limit-order-sdk/utils/get-rpc-code.d.ts +2 -0
- package/lib/utils/limit-order-sdk/utils/get-rpc-code.js +28 -0
- package/lib/utils/limit-order-sdk/utils/limit-order-rfq.const.d.ts +89 -0
- package/lib/utils/limit-order-sdk/utils/limit-order-rfq.const.js +140 -0
- package/lib/utils/limit-order-sdk/utils/limit-order-rfq.helpers.d.ts +10 -0
- package/lib/utils/limit-order-sdk/utils/limit-order-rfq.helpers.js +254 -0
- package/lib/utils/limit-order-sdk/utils/limit-order-rfq.model.d.ts +1 -0
- package/lib/utils/limit-order-sdk/utils/limit-order-rfq.model.js +2 -0
- package/lib/utils/limit-order-sdk/utils/limit-order-rfq.utils.d.ts +2 -0
- package/lib/utils/limit-order-sdk/utils/limit-order-rfq.utils.js +82 -0
- package/lib/utils/web3.js +9 -0
- package/package.json +2 -2
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
var _a, _b, _c;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.explorersUrls = exports.contractAddresses = exports.rpcUrls = exports.cancelOrderSchema = exports.fillOrderSchema = exports.createOrderSchema = exports.operationSchema = void 0;
|
|
14
|
+
var limit_order_protocol_model_1 = require("../model/limit-order-protocol.model");
|
|
15
|
+
var commonProperties = [
|
|
16
|
+
{
|
|
17
|
+
type: 'select',
|
|
18
|
+
name: 'chainId',
|
|
19
|
+
message: 'Select network',
|
|
20
|
+
choices: [
|
|
21
|
+
{ title: 'Ethereum', value: limit_order_protocol_model_1.ChainId.etherumMainnet },
|
|
22
|
+
{ title: 'BSC', value: limit_order_protocol_model_1.ChainId.binanceMainnet },
|
|
23
|
+
{ title: 'Polygon', value: limit_order_protocol_model_1.ChainId.polygonMainnet },
|
|
24
|
+
{ title: 'Optimism', value: limit_order_protocol_model_1.ChainId.optimismMainnet },
|
|
25
|
+
{ title: 'Arbitrum', value: limit_order_protocol_model_1.ChainId.arbitrumMainnet },
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: 'password',
|
|
30
|
+
name: 'privateKey',
|
|
31
|
+
message: 'Enter your private key',
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
exports.operationSchema = [
|
|
35
|
+
{
|
|
36
|
+
type: 'select',
|
|
37
|
+
name: 'operation',
|
|
38
|
+
choices: [
|
|
39
|
+
{ title: 'create', value: 'create' },
|
|
40
|
+
{ title: 'fill', value: 'fill' },
|
|
41
|
+
{ title: 'cancel', value: 'cancel' },
|
|
42
|
+
],
|
|
43
|
+
message: 'Choose operation for limit order RFQ: create, fill, cancel',
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
exports.createOrderSchema = __spreadArray(__spreadArray([], commonProperties, true), [
|
|
47
|
+
{
|
|
48
|
+
type: 'number',
|
|
49
|
+
name: 'orderId',
|
|
50
|
+
message: 'Limit order RFQ id',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: 'number',
|
|
54
|
+
name: 'expiresIn',
|
|
55
|
+
message: 'Expires in (seconds, for example: 300 - order will expired in 5 mins)',
|
|
56
|
+
initial: 300,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: 'text',
|
|
60
|
+
name: 'makerAssetAddress',
|
|
61
|
+
message: 'Maker asset address',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: 'text',
|
|
65
|
+
name: 'takerAssetAddress',
|
|
66
|
+
message: 'Taker asset address',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: 'text',
|
|
70
|
+
name: 'makerAmount',
|
|
71
|
+
message: 'Maker asset amount',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: 'text',
|
|
75
|
+
name: 'takerAmount',
|
|
76
|
+
message: 'Taker asset amount',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
type: 'text',
|
|
80
|
+
name: 'takerAddress',
|
|
81
|
+
message: 'Taker address (optional)',
|
|
82
|
+
},
|
|
83
|
+
], false);
|
|
84
|
+
exports.fillOrderSchema = __spreadArray(__spreadArray([], commonProperties, true), [
|
|
85
|
+
{
|
|
86
|
+
type: 'number',
|
|
87
|
+
name: 'gasPrice',
|
|
88
|
+
message: 'Gas price (GWEI)',
|
|
89
|
+
initial: 10,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
type: 'text',
|
|
93
|
+
name: 'order',
|
|
94
|
+
message: 'Limit order RFQ json',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
type: 'text',
|
|
98
|
+
name: 'makerAmount',
|
|
99
|
+
message: 'Maker asset fill amount (set 0 if you will use taker asset amount)',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
type: 'text',
|
|
103
|
+
name: 'takerAmount',
|
|
104
|
+
message: 'Taker asset amount (set 0 if has set maker asset amount)',
|
|
105
|
+
},
|
|
106
|
+
], false);
|
|
107
|
+
exports.cancelOrderSchema = __spreadArray(__spreadArray([], commonProperties, true), [
|
|
108
|
+
{
|
|
109
|
+
type: 'number',
|
|
110
|
+
name: 'gasPrice',
|
|
111
|
+
message: 'Gas price (GWEI)',
|
|
112
|
+
initial: 10,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
type: 'text',
|
|
116
|
+
name: 'orderInfo',
|
|
117
|
+
message: 'Order info',
|
|
118
|
+
},
|
|
119
|
+
], false);
|
|
120
|
+
exports.rpcUrls = (_a = {},
|
|
121
|
+
_a[limit_order_protocol_model_1.ChainId.etherumMainnet] = 'https://web3-node.1inch.io',
|
|
122
|
+
_a[limit_order_protocol_model_1.ChainId.binanceMainnet] = 'https://bsc-dataseed.binance.org',
|
|
123
|
+
_a[limit_order_protocol_model_1.ChainId.polygonMainnet] = 'https://bor-nodes.1inch.io',
|
|
124
|
+
_a[limit_order_protocol_model_1.ChainId.optimismMainnet] = 'https://optimism-nodes.1inch.io',
|
|
125
|
+
_a[limit_order_protocol_model_1.ChainId.arbitrumMainnet] = 'https://arbitrum-nodes.1inch.io',
|
|
126
|
+
_a);
|
|
127
|
+
exports.contractAddresses = (_b = {},
|
|
128
|
+
_b[limit_order_protocol_model_1.ChainId.etherumMainnet] = '0x119c71d3bbac22029622cbaec24854d3d32d2828',
|
|
129
|
+
_b[limit_order_protocol_model_1.ChainId.binanceMainnet] = '0x1e38eff998df9d3669e32f4ff400031385bf6362',
|
|
130
|
+
_b[limit_order_protocol_model_1.ChainId.polygonMainnet] = '0x94bc2a1c732bcad7343b25af48385fe76e08734f',
|
|
131
|
+
_b[limit_order_protocol_model_1.ChainId.optimismMainnet] = '0x11431a89893025d2a48dca4eddc396f8c8117187',
|
|
132
|
+
_b[limit_order_protocol_model_1.ChainId.arbitrumMainnet] = '0x7f069df72b7a39bce9806e3afaf579e54d8cf2b9',
|
|
133
|
+
_b);
|
|
134
|
+
exports.explorersUrls = (_c = {},
|
|
135
|
+
_c[limit_order_protocol_model_1.ChainId.etherumMainnet] = 'https://etherscan.io',
|
|
136
|
+
_c[limit_order_protocol_model_1.ChainId.binanceMainnet] = 'https://bscscan.com',
|
|
137
|
+
_c[limit_order_protocol_model_1.ChainId.polygonMainnet] = 'https://polygonscan.com',
|
|
138
|
+
_c[limit_order_protocol_model_1.ChainId.optimismMainnet] = 'https://optimistic.etherscan.io',
|
|
139
|
+
_c[limit_order_protocol_model_1.ChainId.arbitrumMainnet] = 'https://arbiscan.io',
|
|
140
|
+
_c);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export var __esModule: boolean;
|
|
3
|
+
export function createOrderOperation(isRunningWithArgv: any, params: any): any;
|
|
4
|
+
export function fillOrderOperation(isRunningWithArgv: any, params: any): any;
|
|
5
|
+
export function cancelOrderOperation(isRunningWithArgv: any, params: any): any;
|
|
6
|
+
export function createOrder(params: any): import("..").RFQOrder;
|
|
7
|
+
export function fillOrder(params: any, order: any): any;
|
|
8
|
+
export function cancelOrder(params: any): any;
|
|
9
|
+
export function sendSignedTransaction(web3: any, txConfig: any, privateKey: any): any;
|
|
10
|
+
export function gweiToWei(value: any): string;
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
4
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
5
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
6
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
7
|
+
function step(op) {
|
|
8
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
9
|
+
while (_) try {
|
|
10
|
+
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;
|
|
11
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
12
|
+
switch (op[0]) {
|
|
13
|
+
case 0: case 1: t = op; break;
|
|
14
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
15
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
16
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
17
|
+
default:
|
|
18
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
19
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
20
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
21
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
22
|
+
if (t[2]) _.ops.pop();
|
|
23
|
+
_.trys.pop(); continue;
|
|
24
|
+
}
|
|
25
|
+
op = body.call(thisArg, _);
|
|
26
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
27
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.gweiToWei = exports.sendSignedTransaction = exports.cancelOrder = exports.fillOrder = exports.createOrder = exports.cancelOrderOperation = exports.fillOrderOperation = exports.createOrderOperation = void 0;
|
|
32
|
+
var tslib_1 = require("tslib");
|
|
33
|
+
var prompts_1 = tslib_1.__importDefault(require("prompts"));
|
|
34
|
+
var kleur_1 = tslib_1.__importDefault(require("kleur"));
|
|
35
|
+
var web3_1 = tslib_1.__importDefault(require("web3"));
|
|
36
|
+
var limit_order_builder_1 = require("../limit-order.builder");
|
|
37
|
+
var limit_order_protocol_facade_1 = require("../limit-order-protocol.facade");
|
|
38
|
+
var limit_order_rfq_const_1 = require("./limit-order-rfq.const");
|
|
39
|
+
var private_key_provider_connector_1 = require("../connector/private-key-provider.connector");
|
|
40
|
+
function createOrderOperation(isRunningWithArgv, params) {
|
|
41
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
42
|
+
var creatingParams, _a, newOrder;
|
|
43
|
+
return __generator(this, function (_b) {
|
|
44
|
+
switch (_b.label) {
|
|
45
|
+
case 0:
|
|
46
|
+
_a = params;
|
|
47
|
+
if (_a) return [3 /*break*/, 2];
|
|
48
|
+
return [4 /*yield*/, prompts_1.default(limit_order_rfq_const_1.createOrderSchema)];
|
|
49
|
+
case 1:
|
|
50
|
+
_a = (_b.sent());
|
|
51
|
+
_b.label = 2;
|
|
52
|
+
case 2:
|
|
53
|
+
creatingParams = _a;
|
|
54
|
+
newOrder = createOrder(creatingParams);
|
|
55
|
+
if (isRunningWithArgv) {
|
|
56
|
+
console.log(JSON.stringify(newOrder));
|
|
57
|
+
return [2 /*return*/];
|
|
58
|
+
}
|
|
59
|
+
console.log(kleur_1.default.green().bold('New limit order RFQ: '));
|
|
60
|
+
console.log(kleur_1.default.white().underline(JSON.stringify(newOrder, null, 4)));
|
|
61
|
+
return [2 /*return*/];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.createOrderOperation = createOrderOperation;
|
|
67
|
+
function fillOrderOperation(isRunningWithArgv, params) {
|
|
68
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
69
|
+
var fillingParams, _a, orderForFill, txHash;
|
|
70
|
+
return __generator(this, function (_b) {
|
|
71
|
+
switch (_b.label) {
|
|
72
|
+
case 0:
|
|
73
|
+
_a = params;
|
|
74
|
+
if (_a) return [3 /*break*/, 2];
|
|
75
|
+
return [4 /*yield*/, prompts_1.default(limit_order_rfq_const_1.fillOrderSchema)];
|
|
76
|
+
case 1:
|
|
77
|
+
_a = (_b.sent());
|
|
78
|
+
_b.label = 2;
|
|
79
|
+
case 2:
|
|
80
|
+
fillingParams = _a;
|
|
81
|
+
orderForFill = JSON.parse(fillingParams.order);
|
|
82
|
+
console.log(kleur_1.default.green().bold('Order for filling: '));
|
|
83
|
+
console.log(kleur_1.default.white().underline(JSON.stringify(orderForFill, null, 4)));
|
|
84
|
+
return [4 /*yield*/, fillOrder(fillingParams, orderForFill)];
|
|
85
|
+
case 3:
|
|
86
|
+
txHash = _b.sent();
|
|
87
|
+
if (isRunningWithArgv) {
|
|
88
|
+
console.log(txHash);
|
|
89
|
+
return [2 /*return*/];
|
|
90
|
+
}
|
|
91
|
+
console.log(kleur_1.default.green().bold('Order filling transaction: '));
|
|
92
|
+
printTransactionLink(explorerTxLink(fillingParams.chainId, txHash));
|
|
93
|
+
return [2 /*return*/];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
exports.fillOrderOperation = fillOrderOperation;
|
|
99
|
+
function cancelOrderOperation(isRunningWithArgv, params) {
|
|
100
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
101
|
+
var cancelingParams, _a, cancelingTxHash;
|
|
102
|
+
return __generator(this, function (_b) {
|
|
103
|
+
switch (_b.label) {
|
|
104
|
+
case 0:
|
|
105
|
+
_a = params;
|
|
106
|
+
if (_a) return [3 /*break*/, 2];
|
|
107
|
+
return [4 /*yield*/, prompts_1.default(limit_order_rfq_const_1.cancelOrderSchema)];
|
|
108
|
+
case 1:
|
|
109
|
+
_a = (_b.sent());
|
|
110
|
+
_b.label = 2;
|
|
111
|
+
case 2:
|
|
112
|
+
cancelingParams = _a;
|
|
113
|
+
return [4 /*yield*/, cancelOrder(cancelingParams)];
|
|
114
|
+
case 3:
|
|
115
|
+
cancelingTxHash = _b.sent();
|
|
116
|
+
if (isRunningWithArgv) {
|
|
117
|
+
console.log(cancelingTxHash);
|
|
118
|
+
return [2 /*return*/];
|
|
119
|
+
}
|
|
120
|
+
console.log(kleur_1.default.green().bold('Order canceling transaction: '));
|
|
121
|
+
printTransactionLink(explorerTxLink(cancelingParams.chainId, cancelingTxHash));
|
|
122
|
+
return [2 /*return*/];
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
exports.cancelOrderOperation = cancelOrderOperation;
|
|
128
|
+
/* eslint-disable max-lines-per-function */
|
|
129
|
+
function createOrder(params) {
|
|
130
|
+
var contractAddress = limit_order_rfq_const_1.contractAddresses[params.chainId];
|
|
131
|
+
var web3 = new web3_1.default(limit_order_rfq_const_1.rpcUrls[params.chainId]);
|
|
132
|
+
var providerConnector = new private_key_provider_connector_1.PrivateKeyProviderConnector(params.privateKey, web3);
|
|
133
|
+
var walletAddress = web3.eth.accounts.privateKeyToAccount(params.privateKey).address;
|
|
134
|
+
var limitOrderBuilder = new limit_order_builder_1.LimitOrderBuilder(contractAddress, params.chainId, providerConnector);
|
|
135
|
+
return limitOrderBuilder.buildRFQOrder({
|
|
136
|
+
id: params.orderId,
|
|
137
|
+
expiresInTimestamp: Math.ceil(Date.now() / 1000) + params.expiresIn,
|
|
138
|
+
makerAddress: walletAddress,
|
|
139
|
+
makerAssetAddress: params.makerAssetAddress,
|
|
140
|
+
takerAssetAddress: params.takerAssetAddress,
|
|
141
|
+
makerAmount: params.makerAmount,
|
|
142
|
+
takerAmount: params.takerAmount,
|
|
143
|
+
takerAddress: params.takerAddress || undefined,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
exports.createOrder = createOrder;
|
|
147
|
+
/* eslint-enable max-lines-per-function */
|
|
148
|
+
/* eslint-disable max-lines-per-function */
|
|
149
|
+
function fillOrder(params, order) {
|
|
150
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
151
|
+
var contractAddress, web3, providerConnector, walletAddress, limitOrderBuilder, limitOrderProtocolFacade, typedData, signature, callData, txConfig, _a;
|
|
152
|
+
return __generator(this, function (_b) {
|
|
153
|
+
switch (_b.label) {
|
|
154
|
+
case 0:
|
|
155
|
+
contractAddress = limit_order_rfq_const_1.contractAddresses[params.chainId];
|
|
156
|
+
web3 = new web3_1.default(limit_order_rfq_const_1.rpcUrls[params.chainId]);
|
|
157
|
+
providerConnector = new private_key_provider_connector_1.PrivateKeyProviderConnector(params.privateKey, web3);
|
|
158
|
+
walletAddress = web3.eth.accounts.privateKeyToAccount(params.privateKey).address;
|
|
159
|
+
limitOrderBuilder = new limit_order_builder_1.LimitOrderBuilder(contractAddress, params.chainId, providerConnector);
|
|
160
|
+
limitOrderProtocolFacade = new limit_order_protocol_facade_1.LimitOrderProtocolFacade(contractAddress, providerConnector);
|
|
161
|
+
typedData = limitOrderBuilder.buildRFQOrderTypedData(order, params.domainName || undefined);
|
|
162
|
+
return [4 /*yield*/, limitOrderBuilder.buildOrderSignature(walletAddress, typedData)];
|
|
163
|
+
case 1:
|
|
164
|
+
signature = _b.sent();
|
|
165
|
+
callData = limitOrderProtocolFacade.fillRFQOrder(order, signature, params.makerAmount, params.takerAmount);
|
|
166
|
+
_a = {
|
|
167
|
+
to: contractAddress,
|
|
168
|
+
from: walletAddress,
|
|
169
|
+
data: callData,
|
|
170
|
+
value: '0',
|
|
171
|
+
gas: 120000,
|
|
172
|
+
gasPrice: gweiToWei(params.gasPrice)
|
|
173
|
+
};
|
|
174
|
+
return [4 /*yield*/, web3.eth.getTransactionCount(walletAddress)];
|
|
175
|
+
case 2:
|
|
176
|
+
txConfig = (_a.nonce = _b.sent(),
|
|
177
|
+
_a);
|
|
178
|
+
return [2 /*return*/, sendSignedTransaction(web3, txConfig, params.privateKey)];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
exports.fillOrder = fillOrder;
|
|
184
|
+
/* eslint-enable max-lines-per-function */
|
|
185
|
+
/* eslint-disable max-lines-per-function */
|
|
186
|
+
function cancelOrder(params) {
|
|
187
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
188
|
+
var contractAddress, web3, providerConnector, walletAddress, limitOrderProtocolFacade, callData, txConfig, _a;
|
|
189
|
+
return __generator(this, function (_b) {
|
|
190
|
+
switch (_b.label) {
|
|
191
|
+
case 0:
|
|
192
|
+
contractAddress = limit_order_rfq_const_1.contractAddresses[params.chainId];
|
|
193
|
+
web3 = new web3_1.default(new web3_1.default.providers.HttpProvider(limit_order_rfq_const_1.rpcUrls[params.chainId]));
|
|
194
|
+
providerConnector = new private_key_provider_connector_1.PrivateKeyProviderConnector(params.privateKey, web3);
|
|
195
|
+
walletAddress = web3.eth.accounts.privateKeyToAccount(params.privateKey).address;
|
|
196
|
+
limitOrderProtocolFacade = new limit_order_protocol_facade_1.LimitOrderProtocolFacade(contractAddress, providerConnector);
|
|
197
|
+
callData = limitOrderProtocolFacade.cancelRFQOrder(params.orderInfo);
|
|
198
|
+
_a = {
|
|
199
|
+
to: contractAddress,
|
|
200
|
+
from: walletAddress,
|
|
201
|
+
data: callData,
|
|
202
|
+
value: '0',
|
|
203
|
+
gas: 50000,
|
|
204
|
+
gasPrice: gweiToWei(params.gasPrice)
|
|
205
|
+
};
|
|
206
|
+
return [4 /*yield*/, web3.eth.getTransactionCount(walletAddress)];
|
|
207
|
+
case 1:
|
|
208
|
+
txConfig = (_a.nonce = _b.sent(),
|
|
209
|
+
_a);
|
|
210
|
+
return [2 /*return*/, sendSignedTransaction(web3, txConfig, params.privateKey)];
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
exports.cancelOrder = cancelOrder;
|
|
216
|
+
/* eslint-enable max-lines-per-function */
|
|
217
|
+
function sendSignedTransaction(web3, txConfig, privateKey) {
|
|
218
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
219
|
+
var sign;
|
|
220
|
+
return __generator(this, function (_a) {
|
|
221
|
+
switch (_a.label) {
|
|
222
|
+
case 0: return [4 /*yield*/, web3.eth.accounts.signTransaction(txConfig, privateKey)];
|
|
223
|
+
case 1:
|
|
224
|
+
sign = _a.sent();
|
|
225
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
226
|
+
web3.eth.sendSignedTransaction(sign.rawTransaction, function (error, hash) {
|
|
227
|
+
if (error) {
|
|
228
|
+
reject(error);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
resolve(hash);
|
|
232
|
+
});
|
|
233
|
+
})];
|
|
234
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
exports.sendSignedTransaction = sendSignedTransaction;
|
|
240
|
+
function explorerTxLink(chainId, txHash) {
|
|
241
|
+
var explorerUrl = limit_order_rfq_const_1.explorersUrls[chainId];
|
|
242
|
+
return "".concat(explorerUrl, "/tx/").concat(txHash);
|
|
243
|
+
}
|
|
244
|
+
function gweiToWei(value) {
|
|
245
|
+
return value + '000000000';
|
|
246
|
+
}
|
|
247
|
+
exports.gweiToWei = gweiToWei;
|
|
248
|
+
function printTransactionLink(text) {
|
|
249
|
+
console.log(kleur_1.default.white('************************************************'));
|
|
250
|
+
console.log(kleur_1.default.white(' '));
|
|
251
|
+
console.log(kleur_1.default.white().underline(text));
|
|
252
|
+
console.log(kleur_1.default.white(' '));
|
|
253
|
+
console.log(kleur_1.default.white('************************************************'));
|
|
254
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var __esModule: boolean;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
4
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
5
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
6
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
7
|
+
function step(op) {
|
|
8
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
9
|
+
while (_) try {
|
|
10
|
+
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;
|
|
11
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
12
|
+
switch (op[0]) {
|
|
13
|
+
case 0: case 1: t = op; break;
|
|
14
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
15
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
16
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
17
|
+
default:
|
|
18
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
19
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
20
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
21
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
22
|
+
if (t[2]) _.ops.pop();
|
|
23
|
+
_.trys.pop(); continue;
|
|
24
|
+
}
|
|
25
|
+
op = body.call(thisArg, _);
|
|
26
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
27
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
var tslib_1 = require("tslib");
|
|
32
|
+
var prompts_1 = tslib_1.__importDefault(require("prompts"));
|
|
33
|
+
var yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
34
|
+
var limit_order_rfq_const_1 = require("./limit-order-rfq.const");
|
|
35
|
+
var limit_order_rfq_helpers_1 = require("./limit-order-rfq.helpers");
|
|
36
|
+
var allSchemas = [
|
|
37
|
+
limit_order_rfq_const_1.cancelOrderSchema,
|
|
38
|
+
limit_order_rfq_const_1.createOrderSchema,
|
|
39
|
+
limit_order_rfq_const_1.fillOrderSchema,
|
|
40
|
+
limit_order_rfq_const_1.operationSchema,
|
|
41
|
+
];
|
|
42
|
+
(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
43
|
+
var argvKeys, isRunningWithArgv, operationResult, _a;
|
|
44
|
+
return __generator(this, function (_b) {
|
|
45
|
+
switch (_b.label) {
|
|
46
|
+
case 0:
|
|
47
|
+
argvKeys = Object.keys(yargs_1.default.argv);
|
|
48
|
+
isRunningWithArgv = allSchemas.some(function (schema) {
|
|
49
|
+
return schema
|
|
50
|
+
.map(function (i) { return i.name; })
|
|
51
|
+
.every(function (param) { return argvKeys.includes(param); });
|
|
52
|
+
});
|
|
53
|
+
prompts_1.default.override(yargs_1.default.argv);
|
|
54
|
+
return [4 /*yield*/, prompts_1.default(limit_order_rfq_const_1.operationSchema)];
|
|
55
|
+
case 1:
|
|
56
|
+
operationResult = (_b.sent());
|
|
57
|
+
_a = operationResult.operation;
|
|
58
|
+
switch (_a) {
|
|
59
|
+
case 'create': return [3 /*break*/, 2];
|
|
60
|
+
case 'fill': return [3 /*break*/, 4];
|
|
61
|
+
case 'cancel': return [3 /*break*/, 6];
|
|
62
|
+
}
|
|
63
|
+
return [3 /*break*/, 8];
|
|
64
|
+
case 2: return [4 /*yield*/, limit_order_rfq_helpers_1.createOrderOperation(isRunningWithArgv)];
|
|
65
|
+
case 3:
|
|
66
|
+
_b.sent();
|
|
67
|
+
return [3 /*break*/, 9];
|
|
68
|
+
case 4: return [4 /*yield*/, limit_order_rfq_helpers_1.fillOrderOperation(isRunningWithArgv)];
|
|
69
|
+
case 5:
|
|
70
|
+
_b.sent();
|
|
71
|
+
return [3 /*break*/, 9];
|
|
72
|
+
case 6: return [4 /*yield*/, limit_order_rfq_helpers_1.cancelOrderOperation(isRunningWithArgv)];
|
|
73
|
+
case 7:
|
|
74
|
+
_b.sent();
|
|
75
|
+
return [3 /*break*/, 9];
|
|
76
|
+
case 8:
|
|
77
|
+
console.log('Unknown operation: ', operationResult.operation);
|
|
78
|
+
return [3 /*break*/, 9];
|
|
79
|
+
case 9: return [2 /*return*/];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}); })();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Web3 = exports.web3 = void 0;
|
|
7
|
+
var web3_1 = __importDefault(require("web3"));
|
|
8
|
+
exports.Web3 = web3_1.default;
|
|
9
|
+
exports.web3 = new web3_1.default();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openocean.finance/openocean-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.73",
|
|
4
4
|
"description": "Openocean sdk",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@1inch/limit-order-protocol": "^2.0.4",
|
|
49
49
|
"@jup-ag/core": "^1.0.0-beta.27",
|
|
50
|
-
"@openocean.finance/wallet": "^0.4.
|
|
50
|
+
"@openocean.finance/wallet": "^0.4.31",
|
|
51
51
|
"@solana/buffer-layout": "^4.0.0",
|
|
52
52
|
"@walletconnect/web3-provider": "^1.7.8",
|
|
53
53
|
"bs58": "^4.0.1",
|