@dolomite-exchange/zap-sdk 0.3.32 → 0.3.34
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/dist/__tests__/lib/estimators/GlvEstimator.test.d.ts +1 -0
- package/dist/__tests__/lib/estimators/GlvEstimator.test.js +112 -0
- package/dist/__tests__/lib/estimators/GlvEstimator.test.js.map +1 -0
- package/dist/src/abis/IERC20.json +185 -0
- package/dist/src/abis/IGlvReader.json +1388 -0
- package/dist/src/abis/IGlvRegistry.json +577 -0
- package/dist/src/abis/IGmxV2Reader.json +56 -0
- package/dist/src/abis/types/IGlvReader.d.ts +301 -0
- package/dist/src/abis/types/IGlvReader.js +3 -0
- package/dist/src/abis/types/IGlvReader.js.map +1 -0
- package/dist/src/abis/types/IGlvRegistry.d.ts +362 -0
- package/dist/src/abis/types/IGlvRegistry.js +3 -0
- package/dist/src/abis/types/IGlvRegistry.js.map +1 -0
- package/dist/src/abis/types/IGmxV2Reader.d.ts +15 -1
- package/dist/src/lib/Constants.d.ts +12 -1
- package/dist/src/lib/Constants.js +357 -277
- package/dist/src/lib/Constants.js.map +1 -1
- package/dist/src/lib/estimators/GlvEstimator.d.ts +19 -0
- package/dist/src/lib/estimators/GlvEstimator.js +264 -0
- package/dist/src/lib/estimators/GlvEstimator.js.map +1 -0
- package/dist/src/lib/estimators/GmxV2GmEstimator.d.ts +8 -3
- package/dist/src/lib/estimators/GmxV2GmEstimator.js +74 -64
- package/dist/src/lib/estimators/GmxV2GmEstimator.js.map +1 -1
- package/package.json +3 -3
- package/src/abis/IGlvReader.json +1388 -0
- package/src/abis/IGlvRegistry.json +577 -0
- package/src/abis/IGmxV2Reader.json +57 -1
- package/src/abis/types/IGlvReader.ts +900 -0
- package/src/abis/types/IGlvRegistry.ts +828 -0
- package/src/abis/types/IGmxV2Reader.ts +43 -0
- package/src/lib/Constants.ts +101 -7
- package/src/lib/estimators/GlvEstimator.ts +274 -0
- package/src/lib/estimators/GmxV2GmEstimator.ts +72 -61
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
43
|
+
var ethers_1 = require("ethers");
|
|
44
|
+
var utils_1 = require("ethers/lib/utils");
|
|
45
|
+
var src_1 = require("../../../src");
|
|
46
|
+
var GmxV2GmEstimator_1 = require("../../../src/lib/estimators/GmxV2GmEstimator");
|
|
47
|
+
var ArbitrumOneConstants_1 = require("../../helpers/ArbitrumOneConstants");
|
|
48
|
+
var GlvEstimator_1 = require("../../../src/lib/estimators/GlvEstimator");
|
|
49
|
+
var deployments_json_1 = __importDefault(require("@dolomite-exchange/modules-deployments/src/deploy/deployments.json"));
|
|
50
|
+
describe('GlvEstimator', function () {
|
|
51
|
+
var _a;
|
|
52
|
+
var network = src_1.Network.ARBITRUM_ONE;
|
|
53
|
+
var web3Provider = new ethers_1.ethers.providers.JsonRpcProvider(process.env.WEB3_PROVIDER_URL);
|
|
54
|
+
var gasMultiplier = new bignumber_js_1.default(3);
|
|
55
|
+
var gmxV2Estimator = new GmxV2GmEstimator_1.GmxV2GmEstimator(network, web3Provider, gasMultiplier);
|
|
56
|
+
var estimator = new GlvEstimator_1.GlvEstimator(network, web3Provider, gmxV2Estimator);
|
|
57
|
+
var marketsMap = (_a = {},
|
|
58
|
+
_a[ArbitrumOneConstants_1.WETH_MARKET.marketId.toFixed()] = ArbitrumOneConstants_1.WETH_MARKET,
|
|
59
|
+
_a[ArbitrumOneConstants_1.NATIVE_USDC_MARKET.marketId.toFixed()] = ArbitrumOneConstants_1.NATIVE_USDC_MARKET,
|
|
60
|
+
_a);
|
|
61
|
+
var config = {
|
|
62
|
+
gasPriceInWei: new bignumber_js_1.default('100000000'),
|
|
63
|
+
blockTag: 'latest',
|
|
64
|
+
filterOutZapsWithInsufficientOutput: false,
|
|
65
|
+
isLiquidation: false,
|
|
66
|
+
isVaporizable: false,
|
|
67
|
+
slippageTolerance: 0.003,
|
|
68
|
+
subAccountNumber: new bignumber_js_1.default('12321'),
|
|
69
|
+
disallowAggregator: false,
|
|
70
|
+
};
|
|
71
|
+
var glvEthIsolationModeAddress = deployments_json_1.default.GlvETHIsolationModeVaultFactory['42161'].address;
|
|
72
|
+
describe('#getUnwrappedAmount', function () {
|
|
73
|
+
it('should work normally', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
74
|
+
var glvAmountIn, ethAmount, usdcAmount;
|
|
75
|
+
return __generator(this, function (_a) {
|
|
76
|
+
switch (_a.label) {
|
|
77
|
+
case 0:
|
|
78
|
+
glvAmountIn = new bignumber_js_1.default((0, utils_1.parseEther)('100').toString());
|
|
79
|
+
return [4 /*yield*/, estimator.getUnwrappedAmount(glvEthIsolationModeAddress, glvAmountIn, ArbitrumOneConstants_1.WETH_MARKET.marketId, marketsMap, config)];
|
|
80
|
+
case 1:
|
|
81
|
+
ethAmount = _a.sent();
|
|
82
|
+
return [4 /*yield*/, estimator.getUnwrappedAmount(glvEthIsolationModeAddress, glvAmountIn, ArbitrumOneConstants_1.NATIVE_USDC_MARKET.marketId, marketsMap, config)];
|
|
83
|
+
case 2:
|
|
84
|
+
usdcAmount = _a.sent();
|
|
85
|
+
console.log('GLV unwrapped amounts [from ETH, from USDC]:', ethAmount.amountOut.toString(), usdcAmount.amountOut.toString());
|
|
86
|
+
return [2 /*return*/];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}); });
|
|
90
|
+
});
|
|
91
|
+
describe('#getWrappedAmount', function () {
|
|
92
|
+
it('should work normally', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
93
|
+
var ethAmountIn, usdcAmountIn, glvAmountOutFromEth, glvAmountOutFromUsdc;
|
|
94
|
+
return __generator(this, function (_a) {
|
|
95
|
+
switch (_a.label) {
|
|
96
|
+
case 0:
|
|
97
|
+
ethAmountIn = new bignumber_js_1.default((0, utils_1.parseEther)('0.1').toString());
|
|
98
|
+
usdcAmountIn = new bignumber_js_1.default('300000000');
|
|
99
|
+
return [4 /*yield*/, estimator.getWrappedAmount(glvEthIsolationModeAddress, ethAmountIn, ArbitrumOneConstants_1.WETH_MARKET.marketId, marketsMap, config)];
|
|
100
|
+
case 1:
|
|
101
|
+
glvAmountOutFromEth = _a.sent();
|
|
102
|
+
return [4 /*yield*/, estimator.getWrappedAmount(glvEthIsolationModeAddress, usdcAmountIn, ArbitrumOneConstants_1.NATIVE_USDC_MARKET.marketId, marketsMap, config)];
|
|
103
|
+
case 2:
|
|
104
|
+
glvAmountOutFromUsdc = _a.sent();
|
|
105
|
+
console.log('GLV wrapped amounts [from ETH, from USDC]:', glvAmountOutFromEth.amountOut.toString(), glvAmountOutFromUsdc.amountOut.toString());
|
|
106
|
+
return [2 /*return*/];
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}); });
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
//# sourceMappingURL=GlvEstimator.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GlvE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,CAAC,QAAQ,EAAE,EACxC,oBAAoB,CAAC,SAAS,CAAC,QAAQ,EAAE,CAC1C,CAAC;;;;aACH,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"anonymous": false,
|
|
4
|
+
"inputs": [
|
|
5
|
+
{
|
|
6
|
+
"indexed": true,
|
|
7
|
+
"internalType": "address",
|
|
8
|
+
"name": "owner",
|
|
9
|
+
"type": "address"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"indexed": true,
|
|
13
|
+
"internalType": "address",
|
|
14
|
+
"name": "spender",
|
|
15
|
+
"type": "address"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"indexed": false,
|
|
19
|
+
"internalType": "uint256",
|
|
20
|
+
"name": "value",
|
|
21
|
+
"type": "uint256"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"name": "Approval",
|
|
25
|
+
"type": "event"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"anonymous": false,
|
|
29
|
+
"inputs": [
|
|
30
|
+
{
|
|
31
|
+
"indexed": true,
|
|
32
|
+
"internalType": "address",
|
|
33
|
+
"name": "from",
|
|
34
|
+
"type": "address"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"indexed": true,
|
|
38
|
+
"internalType": "address",
|
|
39
|
+
"name": "to",
|
|
40
|
+
"type": "address"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"indexed": false,
|
|
44
|
+
"internalType": "uint256",
|
|
45
|
+
"name": "value",
|
|
46
|
+
"type": "uint256"
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"name": "Transfer",
|
|
50
|
+
"type": "event"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"inputs": [
|
|
54
|
+
{
|
|
55
|
+
"internalType": "address",
|
|
56
|
+
"name": "owner",
|
|
57
|
+
"type": "address"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"internalType": "address",
|
|
61
|
+
"name": "spender",
|
|
62
|
+
"type": "address"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"name": "allowance",
|
|
66
|
+
"outputs": [
|
|
67
|
+
{
|
|
68
|
+
"internalType": "uint256",
|
|
69
|
+
"name": "",
|
|
70
|
+
"type": "uint256"
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
"stateMutability": "view",
|
|
74
|
+
"type": "function"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"inputs": [
|
|
78
|
+
{
|
|
79
|
+
"internalType": "address",
|
|
80
|
+
"name": "spender",
|
|
81
|
+
"type": "address"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"internalType": "uint256",
|
|
85
|
+
"name": "amount",
|
|
86
|
+
"type": "uint256"
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"name": "approve",
|
|
90
|
+
"outputs": [
|
|
91
|
+
{
|
|
92
|
+
"internalType": "bool",
|
|
93
|
+
"name": "",
|
|
94
|
+
"type": "bool"
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
"stateMutability": "nonpayable",
|
|
98
|
+
"type": "function"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"inputs": [
|
|
102
|
+
{
|
|
103
|
+
"internalType": "address",
|
|
104
|
+
"name": "account",
|
|
105
|
+
"type": "address"
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
"name": "balanceOf",
|
|
109
|
+
"outputs": [
|
|
110
|
+
{
|
|
111
|
+
"internalType": "uint256",
|
|
112
|
+
"name": "",
|
|
113
|
+
"type": "uint256"
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"stateMutability": "view",
|
|
117
|
+
"type": "function"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"inputs": [],
|
|
121
|
+
"name": "totalSupply",
|
|
122
|
+
"outputs": [
|
|
123
|
+
{
|
|
124
|
+
"internalType": "uint256",
|
|
125
|
+
"name": "",
|
|
126
|
+
"type": "uint256"
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
"stateMutability": "view",
|
|
130
|
+
"type": "function"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"inputs": [
|
|
134
|
+
{
|
|
135
|
+
"internalType": "address",
|
|
136
|
+
"name": "to",
|
|
137
|
+
"type": "address"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"internalType": "uint256",
|
|
141
|
+
"name": "amount",
|
|
142
|
+
"type": "uint256"
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
"name": "transfer",
|
|
146
|
+
"outputs": [
|
|
147
|
+
{
|
|
148
|
+
"internalType": "bool",
|
|
149
|
+
"name": "",
|
|
150
|
+
"type": "bool"
|
|
151
|
+
}
|
|
152
|
+
],
|
|
153
|
+
"stateMutability": "nonpayable",
|
|
154
|
+
"type": "function"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"inputs": [
|
|
158
|
+
{
|
|
159
|
+
"internalType": "address",
|
|
160
|
+
"name": "from",
|
|
161
|
+
"type": "address"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"internalType": "address",
|
|
165
|
+
"name": "to",
|
|
166
|
+
"type": "address"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"internalType": "uint256",
|
|
170
|
+
"name": "amount",
|
|
171
|
+
"type": "uint256"
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
"name": "transferFrom",
|
|
175
|
+
"outputs": [
|
|
176
|
+
{
|
|
177
|
+
"internalType": "bool",
|
|
178
|
+
"name": "",
|
|
179
|
+
"type": "bool"
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
"stateMutability": "nonpayable",
|
|
183
|
+
"type": "function"
|
|
184
|
+
}
|
|
185
|
+
]
|