@reyaxyz/common 0.345.0 → 0.347.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/trading-api-types.js.map +1 -1
- package/dist/transactions/executeTransaction.js +8 -123
- package/dist/transactions/executeTransaction.js.map +1 -1
- package/dist/types/trading-api-types.d.ts +104 -1
- package/dist/types/trading-api-types.d.ts.map +1 -1
- package/dist/types/transactions/executeTransaction.d.ts +2 -15
- package/dist/types/transactions/executeTransaction.d.ts.map +1 -1
- package/dist/types/utils/layerzero.d.ts +22 -0
- package/dist/types/utils/layerzero.d.ts.map +1 -0
- package/dist/types/utils/token/batch-token-getters.d.ts +0 -5
- package/dist/types/utils/token/batch-token-getters.d.ts.map +1 -1
- package/dist/types/utils/token/token-getters.d.ts +0 -2
- package/dist/types/utils/token/token-getters.d.ts.map +1 -1
- package/dist/utils/layerzero.js +31 -0
- package/dist/utils/layerzero.js.map +1 -0
- package/dist/utils/token/batch-token-getters.js +13 -64
- package/dist/utils/token/batch-token-getters.js.map +1 -1
- package/dist/utils/token/token-getters.js +1 -42
- package/dist/utils/token/token-getters.js.map +1 -1
- package/package.json +2 -2
- package/src/trading-api-types.ts +106 -1
- package/src/transactions/executeTransaction.ts +2 -130
- package/src/utils/layerzero.ts +66 -0
- package/src/utils/token/batch-token-getters.ts +0 -28
- package/src/utils/token/token-getters.ts +0 -29
- package/dist/types/utils/layerzero/index.d.ts +0 -3
- package/dist/types/utils/layerzero/index.d.ts.map +0 -1
- package/dist/types/utils/layerzero/oft-config.d.ts +0 -4
- package/dist/types/utils/layerzero/oft-config.d.ts.map +0 -1
- package/dist/types/utils/layerzero/types.d.ts +0 -23
- package/dist/types/utils/layerzero/types.d.ts.map +0 -1
- package/dist/utils/layerzero/index.js +0 -19
- package/dist/utils/layerzero/index.js.map +0 -1
- package/dist/utils/layerzero/oft-config.js +0 -29
- package/dist/utils/layerzero/oft-config.js.map +0 -1
- package/dist/utils/layerzero/types.js +0 -3
- package/dist/utils/layerzero/types.js.map +0 -1
- package/src/utils/layerzero/index.ts +0 -2
- package/src/utils/layerzero/oft-config.ts +0 -32
- package/src/utils/layerzero/types.ts +0 -25
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { MoneyInOutChainId, ReyaChainId } from '../../types';
|
|
2
|
-
export type GetETHBalanceBatchArgs = {
|
|
3
|
-
walletAddress: string;
|
|
4
|
-
chain: MoneyInOutChainId | ReyaChainId;
|
|
5
|
-
};
|
|
6
2
|
export type GetERC20BalanceBatchArgs = {
|
|
7
3
|
tokenAddress: string;
|
|
8
4
|
tokenDecimals: number;
|
|
@@ -16,7 +12,6 @@ export type GetERC20AllowanceBatchArgs = {
|
|
|
16
12
|
spenderAddress: string;
|
|
17
13
|
chain: MoneyInOutChainId | ReyaChainId;
|
|
18
14
|
};
|
|
19
|
-
export declare const getETHBalanceBatch: ({ walletAddress, chain, }: GetETHBalanceBatchArgs) => Promise<number>;
|
|
20
15
|
export declare const getERC20BalanceBatch: ({ tokenAddress, tokenDecimals, walletAddress, chain, }: GetERC20BalanceBatchArgs) => Promise<number>;
|
|
21
16
|
export declare const getERC20AllowanceBatch: ({ tokenAddress, tokenDecimals, walletAddress, spenderAddress, chain, }: GetERC20AllowanceBatchArgs) => Promise<number>;
|
|
22
17
|
//# sourceMappingURL=batch-token-getters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-token-getters.d.ts","sourceRoot":"/","sources":["utils/token/batch-token-getters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"batch-token-getters.d.ts","sourceRoot":"/","sources":["utils/token/batch-token-getters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI7D,MAAM,MAAM,wBAAwB,GAAG;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,iBAAiB,GAAG,WAAW,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,iBAAiB,GAAG,WAAW,CAAC;CACxC,CAAC;AAEF,eAAO,MAAM,oBAAoB,2DAK9B,wBAAwB,KAAG,QAAQ,MAAM,CAiB3C,CAAC;AAEF,eAAO,MAAM,sBAAsB,2EAMhC,0BAA0B,KAAG,QAAQ,MAAM,CAoB7C,CAAC"}
|
|
@@ -18,6 +18,4 @@ export type GetERC20AllowanceArgs = {
|
|
|
18
18
|
subject: ethers.Signer;
|
|
19
19
|
};
|
|
20
20
|
export declare const getERC20Allowance: ({ walletAddress, tokenAddress, tokenDecimals, spenderAddress, subject, }: GetERC20AllowanceArgs) => Promise<number>;
|
|
21
|
-
export declare const getERC20Balance: ({ tokenAddress, tokenDecimals, walletAddress, subject, }: GetERC20BalanceArgs) => Promise<number>;
|
|
22
|
-
export declare const getETHBalance: ({ walletAddress, subject, }: GetETHBalanceArgs) => Promise<number>;
|
|
23
21
|
//# sourceMappingURL=token-getters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-getters.d.ts","sourceRoot":"/","sources":["utils/token/token-getters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,MAAM,MAAM,mBAAmB,GAAG;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,iBAAiB,6EAM3B,qBAAqB,KAAG,QAAQ,MAAM,CAUxC,CAAC
|
|
1
|
+
{"version":3,"file":"token-getters.d.ts","sourceRoot":"/","sources":["utils/token/token-getters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,MAAM,MAAM,mBAAmB,GAAG;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,iBAAiB,6EAM3B,qBAAqB,KAAG,QAAQ,MAAM,CAUxC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildOFTSendParamsToDepositInMA = void 0;
|
|
4
|
+
var ethers_1 = require("ethers");
|
|
5
|
+
var LzComposerOperationType;
|
|
6
|
+
(function (LzComposerOperationType) {
|
|
7
|
+
LzComposerOperationType[LzComposerOperationType["NONE"] = 0] = "NONE";
|
|
8
|
+
LzComposerOperationType[LzComposerOperationType["DEPOSIT_SPOT_ACCOUNT"] = 1] = "DEPOSIT_SPOT_ACCOUNT";
|
|
9
|
+
LzComposerOperationType[LzComposerOperationType["DEPOSIT_ACCOUNT"] = 2] = "DEPOSIT_ACCOUNT";
|
|
10
|
+
})(LzComposerOperationType || (LzComposerOperationType = {}));
|
|
11
|
+
var buildComposeMsg = function (accountId, collateralAddressInReyaPeriphery) {
|
|
12
|
+
var opType = LzComposerOperationType.DEPOSIT_ACCOUNT;
|
|
13
|
+
var opData = ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['uint128', 'address'], [accountId, collateralAddressInReyaPeriphery]);
|
|
14
|
+
var composeMsg = ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['uint8', 'bytes'], [opType, opData]);
|
|
15
|
+
return composeMsg;
|
|
16
|
+
};
|
|
17
|
+
var buildOFTSendParamsToDepositInMA = function (params) {
|
|
18
|
+
var receiverBytes32 = ethers_1.ethers.zeroPadValue(params.receiverAddress, 32);
|
|
19
|
+
var composeMsg = buildComposeMsg(params.marginAccountId, params.collateralAddressInReyaPeriphery);
|
|
20
|
+
return {
|
|
21
|
+
dstEid: params.dstEid,
|
|
22
|
+
to: receiverBytes32,
|
|
23
|
+
amountLD: params.amount,
|
|
24
|
+
minAmountLD: params.amount,
|
|
25
|
+
extraOptions: params.extraOptions,
|
|
26
|
+
composeMsg: composeMsg,
|
|
27
|
+
oftCmd: '0x',
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
exports.buildOFTSendParamsToDepositInMA = buildOFTSendParamsToDepositInMA;
|
|
31
|
+
//# sourceMappingURL=layerzero.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layerzero.js","sourceRoot":"/","sources":["utils/layerzero.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAOhC,IAAK,uBAIJ;AAJD,WAAK,uBAAuB;IAC1B,qEAAQ,CAAA;IACR,qGAAwB,CAAA;IACxB,2FAAmB,CAAA;AACrB,CAAC,EAJI,uBAAuB,KAAvB,uBAAuB,QAI3B;AAYD,IAAM,eAAe,GAAG,UACtB,SAAiB,EACjB,gCAAwC;IAExC,IAAM,MAAM,GAAG,uBAAuB,CAAC,eAAe,CAAC;IACvD,IAAM,MAAM,GAAG,eAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,CACrD,CAAC,SAAS,EAAE,SAAS,CAAC,EACtB,CAAC,SAAS,EAAE,gCAAgC,CAAC,CAC9C,CAAC;IAEF,IAAM,UAAU,GAAG,eAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,CACzD,CAAC,OAAO,EAAE,OAAO,CAAC,EAClB,CAAC,MAAM,EAAE,MAAM,CAAC,CACjB,CAAC;IAEF,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEK,IAAM,+BAA+B,GAAG,UAAC,MAO/C;IACC,IAAM,eAAe,GAAG,eAAM,CAAC,YAAY,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;IAExE,IAAM,UAAU,GAAG,eAAe,CAChC,MAAM,CAAC,eAAe,EACtB,MAAM,CAAC,gCAAgC,CACxC,CAAC;IAEF,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,EAAE,EAAE,eAAe;QACnB,QAAQ,EAAE,MAAM,CAAC,MAAM;QACvB,WAAW,EAAE,MAAM,CAAC,MAAM;QAC1B,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,UAAU,YAAA;QACV,MAAM,EAAE,IAAI;KACb,CAAC;AACJ,CAAC,CAAC;AAxBW,QAAA,+BAA+B,mCAwB1C","sourcesContent":["import { ethers } from 'ethers';\n\nexport type OFTMessagingFee = {\n nativeFee: string;\n lzTokenFee: string;\n};\n\nenum LzComposerOperationType {\n NONE = 0,\n DEPOSIT_SPOT_ACCOUNT = 1,\n DEPOSIT_ACCOUNT = 2,\n}\n\nexport type OFTSendParams = {\n dstEid: number;\n to: string;\n amountLD: bigint;\n minAmountLD: bigint;\n extraOptions: string;\n composeMsg: string;\n oftCmd: string;\n};\n\nconst buildComposeMsg = (\n accountId: number,\n collateralAddressInReyaPeriphery: string,\n) => {\n const opType = LzComposerOperationType.DEPOSIT_ACCOUNT;\n const opData = ethers.AbiCoder.defaultAbiCoder().encode(\n ['uint128', 'address'],\n [accountId, collateralAddressInReyaPeriphery],\n );\n\n const composeMsg = ethers.AbiCoder.defaultAbiCoder().encode(\n ['uint8', 'bytes'],\n [opType, opData],\n );\n\n return composeMsg;\n};\n\nexport const buildOFTSendParamsToDepositInMA = (params: {\n amount: bigint;\n collateralAddressInReyaPeriphery: string;\n dstEid: number;\n extraOptions: string;\n receiverAddress: string;\n marginAccountId: number;\n}): OFTSendParams => {\n const receiverBytes32 = ethers.zeroPadValue(params.receiverAddress, 32);\n\n const composeMsg = buildComposeMsg(\n params.marginAccountId,\n params.collateralAddressInReyaPeriphery,\n );\n\n return {\n dstEid: params.dstEid,\n to: receiverBytes32,\n amountLD: params.amount,\n minAmountLD: params.amount,\n extraOptions: params.extraOptions,\n composeMsg,\n oftCmd: '0x',\n };\n};\n"]}
|
|
@@ -36,75 +36,24 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.getERC20AllowanceBatch = exports.getERC20BalanceBatch =
|
|
39
|
+
exports.getERC20AllowanceBatch = exports.getERC20BalanceBatch = void 0;
|
|
40
40
|
var ethers_1 = require("ethers");
|
|
41
41
|
var network_1 = require("../network");
|
|
42
|
-
var retry_1 = require("../retry");
|
|
43
42
|
var utils_1 = require("./utils");
|
|
44
|
-
var getETHBalanceBatch = function (_a) {
|
|
45
|
-
var walletAddress = _a.walletAddress, chain = _a.chain;
|
|
46
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
47
|
-
var rpcUrls, lastError, _loop_1, _i, rpcUrls_1, url, state_1;
|
|
48
|
-
return __generator(this, function (_b) {
|
|
49
|
-
switch (_b.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
rpcUrls = (0, network_1.getPublicRpcUrlsOrThrow)(chain);
|
|
52
|
-
lastError = null;
|
|
53
|
-
_loop_1 = function (url) {
|
|
54
|
-
var provider_1, currentBalance, error_1;
|
|
55
|
-
return __generator(this, function (_c) {
|
|
56
|
-
switch (_c.label) {
|
|
57
|
-
case 0:
|
|
58
|
-
_c.trys.push([0, 2, , 3]);
|
|
59
|
-
provider_1 = new ethers_1.ethers.JsonRpcProvider(url);
|
|
60
|
-
return [4 /*yield*/, (0, retry_1.exponentialBackoff)(function () {
|
|
61
|
-
return provider_1.getBalance(ethers_1.ethers.getAddress(walletAddress));
|
|
62
|
-
})];
|
|
63
|
-
case 1:
|
|
64
|
-
currentBalance = _c.sent();
|
|
65
|
-
return [2 /*return*/, { value: (0, utils_1.descale)(18)(currentBalance) }];
|
|
66
|
-
case 2:
|
|
67
|
-
error_1 = _c.sent();
|
|
68
|
-
lastError = error_1;
|
|
69
|
-
return [3 /*break*/, 3];
|
|
70
|
-
case 3: return [2 /*return*/];
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
_i = 0, rpcUrls_1 = rpcUrls;
|
|
75
|
-
_b.label = 1;
|
|
76
|
-
case 1:
|
|
77
|
-
if (!(_i < rpcUrls_1.length)) return [3 /*break*/, 4];
|
|
78
|
-
url = rpcUrls_1[_i];
|
|
79
|
-
return [5 /*yield**/, _loop_1(url)];
|
|
80
|
-
case 2:
|
|
81
|
-
state_1 = _b.sent();
|
|
82
|
-
if (typeof state_1 === "object")
|
|
83
|
-
return [2 /*return*/, state_1.value];
|
|
84
|
-
_b.label = 3;
|
|
85
|
-
case 3:
|
|
86
|
-
_i++;
|
|
87
|
-
return [3 /*break*/, 1];
|
|
88
|
-
case 4: throw new Error('All RPC URLs failed; last error: ' + lastError);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
exports.getETHBalanceBatch = getETHBalanceBatch;
|
|
94
43
|
var getERC20BalanceBatch = function (_a) {
|
|
95
44
|
var tokenAddress = _a.tokenAddress, tokenDecimals = _a.tokenDecimals, walletAddress = _a.walletAddress, chain = _a.chain;
|
|
96
45
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
97
|
-
var rpcUrls, lastError, _i,
|
|
46
|
+
var rpcUrls, lastError, _i, rpcUrls_1, url, provider, token, currentBalance, error_1;
|
|
98
47
|
return __generator(this, function (_b) {
|
|
99
48
|
switch (_b.label) {
|
|
100
49
|
case 0:
|
|
101
50
|
rpcUrls = (0, network_1.getPublicRpcUrlsOrThrow)(chain);
|
|
102
51
|
lastError = null;
|
|
103
|
-
_i = 0,
|
|
52
|
+
_i = 0, rpcUrls_1 = rpcUrls;
|
|
104
53
|
_b.label = 1;
|
|
105
54
|
case 1:
|
|
106
|
-
if (!(_i <
|
|
107
|
-
url =
|
|
55
|
+
if (!(_i < rpcUrls_1.length)) return [3 /*break*/, 6];
|
|
56
|
+
url = rpcUrls_1[_i];
|
|
108
57
|
_b.label = 2;
|
|
109
58
|
case 2:
|
|
110
59
|
_b.trys.push([2, 4, , 5]);
|
|
@@ -115,8 +64,8 @@ var getERC20BalanceBatch = function (_a) {
|
|
|
115
64
|
currentBalance = _b.sent();
|
|
116
65
|
return [2 /*return*/, (0, utils_1.descale)(tokenDecimals)(currentBalance)];
|
|
117
66
|
case 4:
|
|
118
|
-
|
|
119
|
-
lastError =
|
|
67
|
+
error_1 = _b.sent();
|
|
68
|
+
lastError = error_1;
|
|
120
69
|
return [3 /*break*/, 5];
|
|
121
70
|
case 5:
|
|
122
71
|
_i++;
|
|
@@ -130,17 +79,17 @@ exports.getERC20BalanceBatch = getERC20BalanceBatch;
|
|
|
130
79
|
var getERC20AllowanceBatch = function (_a) {
|
|
131
80
|
var tokenAddress = _a.tokenAddress, tokenDecimals = _a.tokenDecimals, walletAddress = _a.walletAddress, spenderAddress = _a.spenderAddress, chain = _a.chain;
|
|
132
81
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
133
|
-
var rpcUrls, lastError, _i,
|
|
82
|
+
var rpcUrls, lastError, _i, rpcUrls_2, url, provider, token, currentBalance, error_2;
|
|
134
83
|
return __generator(this, function (_b) {
|
|
135
84
|
switch (_b.label) {
|
|
136
85
|
case 0:
|
|
137
86
|
rpcUrls = (0, network_1.getPublicRpcUrlsOrThrow)(chain);
|
|
138
87
|
lastError = null;
|
|
139
|
-
_i = 0,
|
|
88
|
+
_i = 0, rpcUrls_2 = rpcUrls;
|
|
140
89
|
_b.label = 1;
|
|
141
90
|
case 1:
|
|
142
|
-
if (!(_i <
|
|
143
|
-
url =
|
|
91
|
+
if (!(_i < rpcUrls_2.length)) return [3 /*break*/, 6];
|
|
92
|
+
url = rpcUrls_2[_i];
|
|
144
93
|
_b.label = 2;
|
|
145
94
|
case 2:
|
|
146
95
|
_b.trys.push([2, 4, , 5]);
|
|
@@ -151,8 +100,8 @@ var getERC20AllowanceBatch = function (_a) {
|
|
|
151
100
|
currentBalance = _b.sent();
|
|
152
101
|
return [2 /*return*/, (0, utils_1.descale)(tokenDecimals)(currentBalance)];
|
|
153
102
|
case 4:
|
|
154
|
-
|
|
155
|
-
lastError =
|
|
103
|
+
error_2 = _b.sent();
|
|
104
|
+
lastError = error_2;
|
|
156
105
|
return [3 /*break*/, 5];
|
|
157
106
|
case 5:
|
|
158
107
|
_i++;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-token-getters.js","sourceRoot":"/","sources":["utils/token/batch-token-getters.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAgC;AAEhC,sCAAqD;AACrD,
|
|
1
|
+
{"version":3,"file":"batch-token-getters.js","sourceRoot":"/","sources":["utils/token/batch-token-getters.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAgC;AAEhC,sCAAqD;AACrD,iCAAyD;AAiBlD,IAAM,oBAAoB,GAAG,UAAO,EAKhB;QAJzB,YAAY,kBAAA,EACZ,aAAa,mBAAA,EACb,aAAa,mBAAA,EACb,KAAK,WAAA;;;;;;oBAEC,OAAO,GAAG,IAAA,iCAAuB,EAAC,KAAK,CAAC,CAAC;oBAC3C,SAAS,GAAG,IAAI,CAAC;0BAEI,EAAP,mBAAO;;;yBAAP,CAAA,qBAAO,CAAA;oBAAd,GAAG;;;;oBAEJ,QAAQ,GAAG,IAAI,eAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;oBAC3C,KAAK,GAAG,IAAA,6BAAqB,EAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;oBACrC,qBAAM,KAAK,CAAC,SAAS,CAAC,aAAa,CAAC,EAAA;;oBAArD,cAAc,GAAG,SAAoC;oBAE3D,sBAAO,IAAA,eAAO,EAAC,aAAa,CAAC,CAAC,cAAc,CAAC,EAAC;;;oBAE9C,SAAS,GAAG,OAAK,CAAC;;;oBARJ,IAAO,CAAA;;wBAYzB,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,SAAS,CAAC,CAAC;;;;CAClE,CAAC;AAtBW,QAAA,oBAAoB,wBAsB/B;AAEK,IAAM,sBAAsB,GAAG,UAAO,EAMhB;QAL3B,YAAY,kBAAA,EACZ,aAAa,mBAAA,EACb,aAAa,mBAAA,EACb,cAAc,oBAAA,EACd,KAAK,WAAA;;;;;;oBAEC,OAAO,GAAG,IAAA,iCAAuB,EAAC,KAAK,CAAC,CAAC;oBAC3C,SAAS,GAAG,IAAI,CAAC;0BAEI,EAAP,mBAAO;;;yBAAP,CAAA,qBAAO,CAAA;oBAAd,GAAG;;;;oBAEJ,QAAQ,GAAG,IAAI,eAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;oBAC3C,KAAK,GAAG,IAAA,6BAAqB,EAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;oBACrC,qBAAM,KAAK,CAAC,SAAS,CAC1C,aAAa,EACb,cAAc,CACf,EAAA;;oBAHK,cAAc,GAAG,SAGtB;oBAED,sBAAO,IAAA,eAAO,EAAC,aAAa,CAAC,CAAC,cAAc,CAAC,EAAC;;;oBAE9C,SAAS,GAAG,OAAK,CAAC;;;oBAXJ,IAAO,CAAA;;wBAezB,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,SAAS,CAAC,CAAC;;;;CAClE,CAAC;AA1BW,QAAA,sBAAsB,0BA0BjC","sourcesContent":["import { ethers } from 'ethers';\nimport { MoneyInOutChainId, ReyaChainId } from '../../types';\nimport { getPublicRpcUrlsOrThrow } from '../network';\nimport { descale, getERC20TokenContract } from './utils';\n\nexport type GetERC20BalanceBatchArgs = {\n tokenAddress: string;\n tokenDecimals: number;\n walletAddress: string;\n chain: MoneyInOutChainId | ReyaChainId;\n};\n\nexport type GetERC20AllowanceBatchArgs = {\n tokenAddress: string;\n tokenDecimals: number;\n walletAddress: string;\n spenderAddress: string;\n chain: MoneyInOutChainId | ReyaChainId;\n};\n\nexport const getERC20BalanceBatch = async ({\n tokenAddress,\n tokenDecimals,\n walletAddress,\n chain,\n}: GetERC20BalanceBatchArgs): Promise<number> => {\n const rpcUrls = getPublicRpcUrlsOrThrow(chain);\n let lastError = null;\n\n for (const url of rpcUrls) {\n try {\n const provider = new ethers.JsonRpcProvider(url);\n const token = getERC20TokenContract(tokenAddress, provider);\n const currentBalance = await token.balanceOf(walletAddress);\n\n return descale(tokenDecimals)(currentBalance);\n } catch (error) {\n lastError = error;\n }\n }\n\n throw new Error('All RPC URLs failed; last error: ' + lastError);\n};\n\nexport const getERC20AllowanceBatch = async ({\n tokenAddress,\n tokenDecimals,\n walletAddress,\n spenderAddress,\n chain,\n}: GetERC20AllowanceBatchArgs): Promise<number> => {\n const rpcUrls = getPublicRpcUrlsOrThrow(chain);\n let lastError = null;\n\n for (const url of rpcUrls) {\n try {\n const provider = new ethers.JsonRpcProvider(url);\n const token = getERC20TokenContract(tokenAddress, provider);\n const currentBalance = await token.allowance(\n walletAddress,\n spenderAddress,\n );\n\n return descale(tokenDecimals)(currentBalance);\n } catch (error) {\n lastError = error;\n }\n }\n\n throw new Error('All RPC URLs failed; last error: ' + lastError);\n};\n"]}
|
|
@@ -36,8 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
40
|
-
var ethers_1 = require("ethers");
|
|
39
|
+
exports.getERC20Allowance = void 0;
|
|
41
40
|
var retry_1 = require("../retry");
|
|
42
41
|
var utils_1 = require("./utils");
|
|
43
42
|
var getERC20Allowance = function (_a) {
|
|
@@ -61,44 +60,4 @@ var getERC20Allowance = function (_a) {
|
|
|
61
60
|
});
|
|
62
61
|
};
|
|
63
62
|
exports.getERC20Allowance = getERC20Allowance;
|
|
64
|
-
var getERC20Balance = function (_a) {
|
|
65
|
-
var tokenAddress = _a.tokenAddress, tokenDecimals = _a.tokenDecimals, walletAddress = _a.walletAddress, subject = _a.subject;
|
|
66
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
67
|
-
var token, currentBalance;
|
|
68
|
-
return __generator(this, function (_b) {
|
|
69
|
-
switch (_b.label) {
|
|
70
|
-
case 0:
|
|
71
|
-
token = (0, utils_1.getERC20TokenContract)(tokenAddress, subject);
|
|
72
|
-
return [4 /*yield*/, (0, retry_1.exponentialBackoff)(function () {
|
|
73
|
-
return token.balanceOf(walletAddress);
|
|
74
|
-
})];
|
|
75
|
-
case 1:
|
|
76
|
-
currentBalance = _b.sent();
|
|
77
|
-
return [2 /*return*/, (0, utils_1.descale)(tokenDecimals)(currentBalance)];
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
exports.getERC20Balance = getERC20Balance;
|
|
83
|
-
var getETHBalance = function (_a) {
|
|
84
|
-
var walletAddress = _a.walletAddress, subject = _a.subject;
|
|
85
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
86
|
-
var provider, currentBalance;
|
|
87
|
-
return __generator(this, function (_b) {
|
|
88
|
-
switch (_b.label) {
|
|
89
|
-
case 0:
|
|
90
|
-
provider = subject.provider;
|
|
91
|
-
if (!provider)
|
|
92
|
-
throw new Error("User's provider not found");
|
|
93
|
-
return [4 /*yield*/, (0, retry_1.exponentialBackoff)(function () {
|
|
94
|
-
return provider.getBalance(ethers_1.ethers.getAddress(walletAddress));
|
|
95
|
-
})];
|
|
96
|
-
case 1:
|
|
97
|
-
currentBalance = _b.sent();
|
|
98
|
-
return [2 /*return*/, (0, utils_1.descale)(18)(currentBalance)];
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
exports.getETHBalance = getETHBalance;
|
|
104
63
|
//# sourceMappingURL=token-getters.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-getters.js","sourceRoot":"/","sources":["utils/token/token-getters.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"token-getters.js","sourceRoot":"/","sources":["utils/token/token-getters.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kCAA8C;AAE9C,iCAAgE;AAsBzD,IAAM,iBAAiB,GAAG,UAAO,EAMhB;QALtB,aAAa,mBAAA,EACb,YAAY,kBAAA,EACZ,aAAa,mBAAA,EACb,cAAc,oBAAA,EACd,OAAO,aAAA;;;;;;oBAED,aAAa,GAAG,IAAA,6BAAqB,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;oBAEjD,qBAAM,IAAA,0BAAkB,EAAC;4BACzC,OAAA,aAAa,CAAC,SAAS,CAAC,aAAa,EAAE,cAAc,CAAC;wBAAtD,CAAsD,CACvD,EAAA;;oBAFK,SAAS,GAAG,SAEjB;oBAED,sBAAO,MAAM,CAAC,SAAS,CAAC,GAAG,IAAA,aAAK,EAAC,aAAa,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC;4BACtE,CAAC,CAAC,MAAM,CAAC,gBAAgB;4BACzB,CAAC,CAAC,IAAA,eAAO,EAAC,aAAa,CAAC,CAAC,SAAS,CAAC,EAAC;;;;CACvC,CAAC;AAhBW,QAAA,iBAAiB,qBAgB5B","sourcesContent":["import { ethers } from 'ethers';\nimport { exponentialBackoff } from '../retry';\nimport { LpPoolEntity } from '../../types';\nimport { getERC20TokenContract, scale, descale } from './utils';\n\nexport type GetERC20BalanceArgs = {\n tokenAddress: string;\n tokenDecimals: number;\n walletAddress: string;\n subject: ethers.Signer | ethers.Provider;\n};\n\nexport type GetETHBalanceArgs = {\n walletAddress: string;\n subject: ethers.Signer | ethers.Provider;\n};\n\nexport type GetERC20AllowanceArgs = {\n walletAddress: string;\n tokenAddress: LpPoolEntity['tokenAddress'];\n tokenDecimals: number;\n spenderAddress: string;\n subject: ethers.Signer;\n};\n\nexport const getERC20Allowance = async ({\n walletAddress,\n tokenAddress,\n tokenDecimals,\n spenderAddress,\n subject,\n}: GetERC20AllowanceArgs): Promise<number> => {\n const tokenContract = getERC20TokenContract(tokenAddress, subject);\n\n const allowance = await exponentialBackoff(() =>\n tokenContract.allowance(walletAddress, spenderAddress),\n );\n\n return BigInt(allowance) > scale(tokenDecimals)(Number.MAX_SAFE_INTEGER)\n ? Number.MAX_SAFE_INTEGER\n : descale(tokenDecimals)(allowance);\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.347.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
46
46
|
},
|
|
47
47
|
"packageManager": "pnpm@8.3.1",
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "e49d3e00d9af49fc29dac0ec48c4965ef585f947"
|
|
49
49
|
}
|
package/src/trading-api-types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ParamsDictionary, Query } from 'express-serve-static-core';
|
|
2
|
-
import { AssetPair, CollateralPrice, MarketPrice } from './types';
|
|
2
|
+
import { Address, AssetPair, CollateralPrice, MarketPrice } from './types';
|
|
3
3
|
import {
|
|
4
4
|
AddressParam,
|
|
5
5
|
ApiEndpoint,
|
|
@@ -532,6 +532,7 @@ export type TradingApiSource = {
|
|
|
532
532
|
{
|
|
533
533
|
og_discount: Decimal;
|
|
534
534
|
vltz_discount: Decimal;
|
|
535
|
+
spread_discount: Decimal;
|
|
535
536
|
referee_discount: Decimal;
|
|
536
537
|
referrer_rebate: Decimal;
|
|
537
538
|
affiliate_referrer_rebate: Decimal;
|
|
@@ -602,6 +603,12 @@ export type TradingApiSource = {
|
|
|
602
603
|
address: string;
|
|
603
604
|
}
|
|
604
605
|
>;
|
|
606
|
+
'collaterals/definitions': TradingApiEndpoint<
|
|
607
|
+
{
|
|
608
|
+
collaterals: CollateralDefinition[];
|
|
609
|
+
},
|
|
610
|
+
never
|
|
611
|
+
>;
|
|
605
612
|
};
|
|
606
613
|
|
|
607
614
|
export type Req<P = ParamsDictionary, ReqQuery = Query> = {
|
|
@@ -723,6 +730,104 @@ type ReplicationMessage =
|
|
|
723
730
|
| GenericReplicationMessage<spot_execution_bust, 'spot_execution_busts'>
|
|
724
731
|
| GenericReplicationMessage<Order, 'orders'>;
|
|
725
732
|
|
|
733
|
+
export type SocketDepositChainDetails = {
|
|
734
|
+
chainId: number;
|
|
735
|
+
chainName: string;
|
|
736
|
+
collateralAddress: Address;
|
|
737
|
+
collateralName: string;
|
|
738
|
+
collateralAddressInReyaPeriphery: Address;
|
|
739
|
+
vaultAddress: Address;
|
|
740
|
+
connectorAddress: Address;
|
|
741
|
+
msgGasLimit: string;
|
|
742
|
+
bridgeTime: number;
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
export type SocketWithdrawChainDetails = {
|
|
746
|
+
chainId: number;
|
|
747
|
+
chainName: string;
|
|
748
|
+
collateralAddress: Address;
|
|
749
|
+
collateralName: string;
|
|
750
|
+
collateralAddressInReyaCore: Address;
|
|
751
|
+
msgGasLimit: string;
|
|
752
|
+
bridgeFee: string;
|
|
753
|
+
bridgeTime: number;
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
export type LayerzeroDepositChainDetails = {
|
|
757
|
+
chainId: number;
|
|
758
|
+
chainName: string;
|
|
759
|
+
collateralAddress: Address;
|
|
760
|
+
collateralName: string;
|
|
761
|
+
collateralAddressInReyaPeriphery: Address;
|
|
762
|
+
dstEid: number;
|
|
763
|
+
extraOptions: string;
|
|
764
|
+
bridgeTime: number;
|
|
765
|
+
};
|
|
766
|
+
|
|
767
|
+
export type LayerzeroWithdrawChainDetails = {
|
|
768
|
+
chainId: number;
|
|
769
|
+
chainName: string;
|
|
770
|
+
collateralAddress: Address;
|
|
771
|
+
collateralName: string;
|
|
772
|
+
collateralAddressInReyaCore: Address;
|
|
773
|
+
dstEid: number;
|
|
774
|
+
bridgeFee: string;
|
|
775
|
+
bridgeTime: number;
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
export type SocketDepositInfo =
|
|
779
|
+
| { enabled: false }
|
|
780
|
+
| { enabled: true; chains: SocketDepositChainDetails[]; minAmount: number };
|
|
781
|
+
|
|
782
|
+
export type SocketWithdrawInfo =
|
|
783
|
+
| { enabled: false }
|
|
784
|
+
| { enabled: true; chains: SocketWithdrawChainDetails[]; minAmount: number };
|
|
785
|
+
|
|
786
|
+
export type LayerzeroDepositInfo =
|
|
787
|
+
| { enabled: false }
|
|
788
|
+
| {
|
|
789
|
+
enabled: true;
|
|
790
|
+
minAmount: number;
|
|
791
|
+
chains: LayerzeroDepositChainDetails[];
|
|
792
|
+
};
|
|
793
|
+
|
|
794
|
+
export type LayerzeroWithdrawInfo =
|
|
795
|
+
| { enabled: false }
|
|
796
|
+
| {
|
|
797
|
+
enabled: true;
|
|
798
|
+
minAmount: number;
|
|
799
|
+
chains: LayerzeroWithdrawChainDetails[];
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
export type TransferInfo = { enabled: boolean };
|
|
803
|
+
|
|
804
|
+
export type SpotInfo =
|
|
805
|
+
| { enabled: false }
|
|
806
|
+
| { enabled: true; spotMarketSymbol: string };
|
|
807
|
+
|
|
808
|
+
export type DisplayInfo = {
|
|
809
|
+
advertisedInSpot: boolean;
|
|
810
|
+
advertisedInPerp: boolean;
|
|
811
|
+
displayName: string;
|
|
812
|
+
displayDecimals: number;
|
|
813
|
+
};
|
|
814
|
+
|
|
815
|
+
export type CollateralDefinition = {
|
|
816
|
+
id: Uppercase<string>;
|
|
817
|
+
address: Address;
|
|
818
|
+
assetPairId: string;
|
|
819
|
+
priceHaircut: string;
|
|
820
|
+
liquidationDiscount: string;
|
|
821
|
+
decimals: number;
|
|
822
|
+
socketDepositInfo: SocketDepositInfo;
|
|
823
|
+
socketWithdrawInfo: SocketWithdrawInfo;
|
|
824
|
+
layerzeroDepositInfo: LayerzeroDepositInfo;
|
|
825
|
+
layerzeroWithdrawInfo: LayerzeroWithdrawInfo;
|
|
826
|
+
transferInfo: TransferInfo;
|
|
827
|
+
spotInfo: SpotInfo;
|
|
828
|
+
displayInfo: DisplayInfo;
|
|
829
|
+
};
|
|
830
|
+
|
|
726
831
|
export type Replication = {
|
|
727
832
|
[K in ReplicationMessage as `replication:${K['model']}`]: Extract<
|
|
728
833
|
ReplicationMessage,
|
|
@@ -1,25 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
JsonRpcProvider,
|
|
4
|
-
JsonRpcSigner,
|
|
5
|
-
Network,
|
|
6
|
-
Signer,
|
|
7
|
-
} from 'ethers';
|
|
8
|
-
import { MoneyInOutChainId, ReyaChainId } from '../types';
|
|
1
|
+
import { JsonRpcSigner, Signer } from 'ethers';
|
|
2
|
+
import { ReyaChainId } from '../types';
|
|
9
3
|
import { ContractType, getAddress } from './contractAddresses';
|
|
10
4
|
import { abi } from './abis/Errors.json';
|
|
11
5
|
import { ErrorDecoder } from 'ethers-decode-error';
|
|
12
6
|
import type { DecodedError } from 'ethers-decode-error';
|
|
13
7
|
import { getGasBuffer } from './txHelpers';
|
|
14
|
-
import { getPublicRpcUrlsOrThrow } from '../utils';
|
|
15
|
-
import { Interface } from 'ethers';
|
|
16
|
-
|
|
17
|
-
const reyaChainIdRPCMapper: { [key: number]: string } = {
|
|
18
|
-
[ReyaChainId.reyaNetwork]:
|
|
19
|
-
'https://rpc.reya.network/263e76b89da84d478fd2b6e8783a1cfe',
|
|
20
|
-
[ReyaChainId.reyaCronos]:
|
|
21
|
-
'https://rpc.reya-cronos.gelato.digital/263e76b89da84d478fd2b6e8783a1cfe',
|
|
22
|
-
};
|
|
23
8
|
|
|
24
9
|
export type Transaction = {
|
|
25
10
|
from: string;
|
|
@@ -29,108 +14,6 @@ export type Transaction = {
|
|
|
29
14
|
};
|
|
30
15
|
const errorDecoder = ErrorDecoder.create([abi]);
|
|
31
16
|
|
|
32
|
-
export async function estimateGas(
|
|
33
|
-
signer: Signer | JsonRpcSigner,
|
|
34
|
-
data: string,
|
|
35
|
-
value: string,
|
|
36
|
-
chainId: number,
|
|
37
|
-
targetContract: ContractType | string,
|
|
38
|
-
): Promise<
|
|
39
|
-
Transaction & {
|
|
40
|
-
gasLimit: bigint;
|
|
41
|
-
maxPriorityFeePerGas?: bigint;
|
|
42
|
-
maxFeePerGas?: bigint;
|
|
43
|
-
}
|
|
44
|
-
> {
|
|
45
|
-
const accountAddress = await signer.getAddress();
|
|
46
|
-
|
|
47
|
-
return estimateGasGivenAddress(
|
|
48
|
-
accountAddress,
|
|
49
|
-
data,
|
|
50
|
-
value,
|
|
51
|
-
chainId,
|
|
52
|
-
targetContract,
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// TODO: deprecate this when /executeGelato is gone
|
|
57
|
-
export async function estimateGasGivenAddress(
|
|
58
|
-
accountAddress: string,
|
|
59
|
-
data: string,
|
|
60
|
-
value: string,
|
|
61
|
-
chainId: number,
|
|
62
|
-
targetContract: ContractType | string,
|
|
63
|
-
): Promise<
|
|
64
|
-
Transaction & {
|
|
65
|
-
gasLimit: bigint;
|
|
66
|
-
maxPriorityFeePerGas?: bigint;
|
|
67
|
-
maxFeePerGas?: bigint;
|
|
68
|
-
}
|
|
69
|
-
> {
|
|
70
|
-
const contractAddress = Object.values(ContractType).includes(
|
|
71
|
-
targetContract as ContractType,
|
|
72
|
-
)
|
|
73
|
-
? getAddress(chainId, targetContract as ContractType)
|
|
74
|
-
: targetContract;
|
|
75
|
-
|
|
76
|
-
const tx = {
|
|
77
|
-
from: accountAddress, // @todo Update with relayer address
|
|
78
|
-
to: contractAddress,
|
|
79
|
-
data,
|
|
80
|
-
...(value && value !== '0' ? { value: value } : {}),
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit if fails to get estimate
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
const network = new Network('Reya', chainId);
|
|
87
|
-
const provider = new JsonRpcProvider(
|
|
88
|
-
reyaChainIdRPCMapper[chainId],
|
|
89
|
-
network,
|
|
90
|
-
{
|
|
91
|
-
staticNetwork: network,
|
|
92
|
-
pollingInterval: 50,
|
|
93
|
-
},
|
|
94
|
-
);
|
|
95
|
-
await provider.call(tx);
|
|
96
|
-
} catch (error) {
|
|
97
|
-
const decodedError = await errorDecoder.decode(error);
|
|
98
|
-
const reason = customReasonMapper(decodedError);
|
|
99
|
-
console.error(
|
|
100
|
-
`Error simulating transaction account address ${accountAddress} reason ${decodedError?.name} ${decodedError} ${error}`,
|
|
101
|
-
);
|
|
102
|
-
throw new Error(reason);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (Object.values(ReyaChainId).includes(chainId as ReyaChainId)) {
|
|
106
|
-
const maxPriorityFeePerGas: bigint = BigInt('0');
|
|
107
|
-
const maxFeePerGas: bigint = BigInt('100000000');
|
|
108
|
-
return { ...tx, gasLimit, maxPriorityFeePerGas, maxFeePerGas };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return { ...tx, gasLimit };
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export async function estimateGasFromTxAndChainId(
|
|
115
|
-
chainId: ReyaChainId | MoneyInOutChainId,
|
|
116
|
-
tx: ethers.TransactionRequest,
|
|
117
|
-
): Promise<bigint> {
|
|
118
|
-
const rpcUrls = getPublicRpcUrlsOrThrow(chainId);
|
|
119
|
-
let lastError = null;
|
|
120
|
-
|
|
121
|
-
for (const url of rpcUrls) {
|
|
122
|
-
try {
|
|
123
|
-
const provider = new ethers.JsonRpcProvider(url);
|
|
124
|
-
const estimation = await provider.estimateGas(tx);
|
|
125
|
-
return addGasBuffer(estimation);
|
|
126
|
-
} catch (error) {
|
|
127
|
-
lastError = error;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
throw new Error('All RPC URLs failed; last error: ' + lastError);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
17
|
async function estimateGasExternalChains(
|
|
135
18
|
signer: Signer | JsonRpcSigner,
|
|
136
19
|
data: string,
|
|
@@ -224,14 +107,3 @@ const customReasonMapper = ({ name, reason }: DecodedError): string => {
|
|
|
224
107
|
return reason ?? 'Error executing transaction';
|
|
225
108
|
}
|
|
226
109
|
};
|
|
227
|
-
|
|
228
|
-
function addGasBuffer(estimation: bigint): bigint {
|
|
229
|
-
return (estimation * BigInt(120)) / BigInt(100);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export async function decodeErrorBytes(returnData: string): Promise<string> {
|
|
233
|
-
const INTERFACE = new Interface(abi);
|
|
234
|
-
const decodedError = INTERFACE.parseError(returnData);
|
|
235
|
-
console.log(decodedError);
|
|
236
|
-
return `${decodedError?.name}: ${decodedError?.args}` || 'Error not found';
|
|
237
|
-
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
|
|
3
|
+
export type OFTMessagingFee = {
|
|
4
|
+
nativeFee: string;
|
|
5
|
+
lzTokenFee: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
enum LzComposerOperationType {
|
|
9
|
+
NONE = 0,
|
|
10
|
+
DEPOSIT_SPOT_ACCOUNT = 1,
|
|
11
|
+
DEPOSIT_ACCOUNT = 2,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type OFTSendParams = {
|
|
15
|
+
dstEid: number;
|
|
16
|
+
to: string;
|
|
17
|
+
amountLD: bigint;
|
|
18
|
+
minAmountLD: bigint;
|
|
19
|
+
extraOptions: string;
|
|
20
|
+
composeMsg: string;
|
|
21
|
+
oftCmd: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const buildComposeMsg = (
|
|
25
|
+
accountId: number,
|
|
26
|
+
collateralAddressInReyaPeriphery: string,
|
|
27
|
+
) => {
|
|
28
|
+
const opType = LzComposerOperationType.DEPOSIT_ACCOUNT;
|
|
29
|
+
const opData = ethers.AbiCoder.defaultAbiCoder().encode(
|
|
30
|
+
['uint128', 'address'],
|
|
31
|
+
[accountId, collateralAddressInReyaPeriphery],
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const composeMsg = ethers.AbiCoder.defaultAbiCoder().encode(
|
|
35
|
+
['uint8', 'bytes'],
|
|
36
|
+
[opType, opData],
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return composeMsg;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const buildOFTSendParamsToDepositInMA = (params: {
|
|
43
|
+
amount: bigint;
|
|
44
|
+
collateralAddressInReyaPeriphery: string;
|
|
45
|
+
dstEid: number;
|
|
46
|
+
extraOptions: string;
|
|
47
|
+
receiverAddress: string;
|
|
48
|
+
marginAccountId: number;
|
|
49
|
+
}): OFTSendParams => {
|
|
50
|
+
const receiverBytes32 = ethers.zeroPadValue(params.receiverAddress, 32);
|
|
51
|
+
|
|
52
|
+
const composeMsg = buildComposeMsg(
|
|
53
|
+
params.marginAccountId,
|
|
54
|
+
params.collateralAddressInReyaPeriphery,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
dstEid: params.dstEid,
|
|
59
|
+
to: receiverBytes32,
|
|
60
|
+
amountLD: params.amount,
|
|
61
|
+
minAmountLD: params.amount,
|
|
62
|
+
extraOptions: params.extraOptions,
|
|
63
|
+
composeMsg,
|
|
64
|
+
oftCmd: '0x',
|
|
65
|
+
};
|
|
66
|
+
};
|