@reyaxyz/common 0.345.0 → 0.346.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.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/dist/trading-api-types.js.map +1 -1
  3. package/dist/transactions/executeTransaction.js +8 -123
  4. package/dist/transactions/executeTransaction.js.map +1 -1
  5. package/dist/types/trading-api-types.d.ts +103 -1
  6. package/dist/types/trading-api-types.d.ts.map +1 -1
  7. package/dist/types/transactions/executeTransaction.d.ts +2 -15
  8. package/dist/types/transactions/executeTransaction.d.ts.map +1 -1
  9. package/dist/types/utils/layerzero.d.ts +22 -0
  10. package/dist/types/utils/layerzero.d.ts.map +1 -0
  11. package/dist/types/utils/token/batch-token-getters.d.ts +0 -5
  12. package/dist/types/utils/token/batch-token-getters.d.ts.map +1 -1
  13. package/dist/types/utils/token/token-getters.d.ts +0 -2
  14. package/dist/types/utils/token/token-getters.d.ts.map +1 -1
  15. package/dist/utils/layerzero.js +31 -0
  16. package/dist/utils/layerzero.js.map +1 -0
  17. package/dist/utils/token/batch-token-getters.js +13 -64
  18. package/dist/utils/token/batch-token-getters.js.map +1 -1
  19. package/dist/utils/token/token-getters.js +1 -42
  20. package/dist/utils/token/token-getters.js.map +1 -1
  21. package/package.json +2 -2
  22. package/src/trading-api-types.ts +105 -1
  23. package/src/transactions/executeTransaction.ts +2 -130
  24. package/src/utils/layerzero.ts +66 -0
  25. package/src/utils/token/batch-token-getters.ts +0 -28
  26. package/src/utils/token/token-getters.ts +0 -29
  27. package/dist/types/utils/layerzero/index.d.ts +0 -3
  28. package/dist/types/utils/layerzero/index.d.ts.map +0 -1
  29. package/dist/types/utils/layerzero/oft-config.d.ts +0 -4
  30. package/dist/types/utils/layerzero/oft-config.d.ts.map +0 -1
  31. package/dist/types/utils/layerzero/types.d.ts +0 -23
  32. package/dist/types/utils/layerzero/types.d.ts.map +0 -1
  33. package/dist/utils/layerzero/index.js +0 -19
  34. package/dist/utils/layerzero/index.js.map +0 -1
  35. package/dist/utils/layerzero/oft-config.js +0 -29
  36. package/dist/utils/layerzero/oft-config.js.map +0 -1
  37. package/dist/utils/layerzero/types.js +0 -3
  38. package/dist/utils/layerzero/types.js.map +0 -1
  39. package/src/utils/layerzero/index.ts +0 -2
  40. package/src/utils/layerzero/oft-config.ts +0 -32
  41. package/src/utils/layerzero/types.ts +0 -25
@@ -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;AAK7D,MAAM,MAAM,sBAAsB,GAAG;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,iBAAiB,GAAG,WAAW,CAAC;CACxC,CAAC;AAEF,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,kBAAkB,8BAG5B,sBAAsB,KAAG,QAAQ,MAAM,CAiBzC,CAAC;AAEF,eAAO,MAAM,oBAAoB,2DAK9B,wBAAwB,KAAG,QAAQ,MAAM,CAiB3C,CAAC;AAEF,eAAO,MAAM,sBAAsB,2EAMhC,0BAA0B,KAAG,QAAQ,MAAM,CAoB7C,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,a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,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 = exports.getETHBalanceBatch = void 0;
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, rpcUrls_2, url, provider, token, currentBalance, error_2;
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, rpcUrls_2 = rpcUrls;
52
+ _i = 0, rpcUrls_1 = rpcUrls;
104
53
  _b.label = 1;
105
54
  case 1:
106
- if (!(_i < rpcUrls_2.length)) return [3 /*break*/, 6];
107
- url = rpcUrls_2[_i];
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
- error_2 = _b.sent();
119
- lastError = error_2;
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, rpcUrls_3, url, provider, token, currentBalance, error_3;
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, rpcUrls_3 = rpcUrls;
88
+ _i = 0, rpcUrls_2 = rpcUrls;
140
89
  _b.label = 1;
141
90
  case 1:
142
- if (!(_i < rpcUrls_3.length)) return [3 /*break*/, 6];
143
- url = rpcUrls_3[_i];
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
- error_3 = _b.sent();
155
- lastError = error_3;
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,kCAA8C;AAC9C,iCAAyD;AAsBlD,IAAM,kBAAkB,GAAG,UAAO,EAGhB;QAFvB,aAAa,mBAAA,EACb,KAAK,WAAA;;;;;;oBAEC,OAAO,GAAG,IAAA,iCAAuB,EAAC,KAAK,CAAC,CAAC;oBAC3C,SAAS,GAAG,IAAI,CAAC;wCAEV,GAAG;;;;;;oCAEJ,aAAW,IAAI,eAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;oCAC1B,qBAAM,IAAA,0BAAkB,EAAC;4CAC9C,OAAA,UAAQ,CAAC,UAAU,CAAC,eAAM,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;wCAArD,CAAqD,CACtD,EAAA;;oCAFK,cAAc,GAAG,SAEtB;mEACM,IAAA,eAAO,EAAC,EA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,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 { exponentialBackoff } from '../retry';\nimport { descale, getERC20TokenContract } from './utils';\n\nexport type GetETHBalanceBatchArgs = {\n walletAddress: string;\n chain: MoneyInOutChainId | ReyaChainId;\n};\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 getETHBalanceBatch = async ({\n walletAddress,\n chain,\n}: GetETHBalanceBatchArgs): 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 currentBalance = await exponentialBackoff(() =>\n provider.getBalance(ethers.getAddress(walletAddress)),\n );\n return descale(18)(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 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"]}
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;;;yBAA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ClE,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.getETHBalance = exports.getERC20Balance = exports.getERC20Allowance = void 0;
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":";;;;;;;;;;;;;;;;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,GAAG,OAAO,CAAC,QAAQ,CAAC;oBAClC,IAAI,CAAC,QAAQ;wBAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;oBAErC,qBAAM,IAAA,0BAAkB,EAAC;4BAC9C,OAAA,QAAQ,CAAC,UAAU,CAAC,eAAM,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;wBAArD,CAAqD,CACtD,EAAA;;oBAFK,cAAc,GAAG,SAEtB;oBAED,sBAAO,IAAA,eAAO,EAAC,EAAE,CAAC,CAAC,cAAc,CAAC,EAAC;;;;CACpC,CAAC;AAZW,QAAA,aAAa,iBAYxB","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\nexport const getERC20Balance = async ({\n tokenAddress,\n tokenDecimals,\n walletAddress,\n subject,\n}: GetERC20BalanceArgs): Promise<number> => {\n const token = getERC20TokenContract(tokenAddress, subject);\n\n const currentBalance = await exponentialBackoff(() =>\n token.balanceOf(walletAddress),\n );\n\n return descale(tokenDecimals)(currentBalance);\n};\n\nexport const getETHBalance = async ({\n walletAddress,\n subject,\n}: GetETHBalanceArgs): Promise<number> => {\n const provider = subject.provider;\n if (!provider) throw new Error(\"User's provider not found\");\n\n const currentBalance = await exponentialBackoff(() =>\n provider.getBalance(ethers.getAddress(walletAddress)),\n );\n\n return descale(18)(currentBalance);\n};\n"]}
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.345.0",
3
+ "version": "0.346.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": "a6136adcd8689769525a0ea1db5062702fbc5826"
48
+ "gitHead": "e58f32638c802226ae571812d910eae628be7cc1"
49
49
  }
@@ -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,
@@ -602,6 +602,12 @@ export type TradingApiSource = {
602
602
  address: string;
603
603
  }
604
604
  >;
605
+ 'collaterals/definitions': TradingApiEndpoint<
606
+ {
607
+ collaterals: CollateralDefinition[];
608
+ },
609
+ never
610
+ >;
605
611
  };
606
612
 
607
613
  export type Req<P = ParamsDictionary, ReqQuery = Query> = {
@@ -723,6 +729,104 @@ type ReplicationMessage =
723
729
  | GenericReplicationMessage<spot_execution_bust, 'spot_execution_busts'>
724
730
  | GenericReplicationMessage<Order, 'orders'>;
725
731
 
732
+ export type SocketDepositChainDetails = {
733
+ chainId: number;
734
+ chainName: string;
735
+ collateralAddress: Address;
736
+ collateralName: string;
737
+ collateralAddressInReyaPeriphery: Address;
738
+ vaultAddress: Address;
739
+ connectorAddress: Address;
740
+ msgGasLimit: string;
741
+ bridgeTime: number;
742
+ };
743
+
744
+ export type SocketWithdrawChainDetails = {
745
+ chainId: number;
746
+ chainName: string;
747
+ collateralAddress: Address;
748
+ collateralName: string;
749
+ collateralAddressInReyaCore: Address;
750
+ msgGasLimit: string;
751
+ bridgeFee: string;
752
+ bridgeTime: number;
753
+ };
754
+
755
+ export type LayerzeroDepositChainDetails = {
756
+ chainId: number;
757
+ chainName: string;
758
+ collateralAddress: Address;
759
+ collateralName: string;
760
+ collateralAddressInReyaPeriphery: Address;
761
+ dstEid: number;
762
+ extraOptions: string;
763
+ bridgeTime: number;
764
+ };
765
+
766
+ export type LayerzeroWithdrawChainDetails = {
767
+ chainId: number;
768
+ chainName: string;
769
+ collateralAddress: Address;
770
+ collateralName: string;
771
+ collateralAddressInReyaCore: Address;
772
+ dstEid: number;
773
+ bridgeFee: string;
774
+ bridgeTime: number;
775
+ };
776
+
777
+ export type SocketDepositInfo =
778
+ | { enabled: false }
779
+ | { enabled: true; chains: SocketDepositChainDetails[]; minAmount: number };
780
+
781
+ export type SocketWithdrawInfo =
782
+ | { enabled: false }
783
+ | { enabled: true; chains: SocketWithdrawChainDetails[]; minAmount: number };
784
+
785
+ export type LayerzeroDepositInfo =
786
+ | { enabled: false }
787
+ | {
788
+ enabled: true;
789
+ minAmount: number;
790
+ chains: LayerzeroDepositChainDetails[];
791
+ };
792
+
793
+ export type LayerzeroWithdrawInfo =
794
+ | { enabled: false }
795
+ | {
796
+ enabled: true;
797
+ minAmount: number;
798
+ chains: LayerzeroWithdrawChainDetails[];
799
+ };
800
+
801
+ export type TransferInfo = { enabled: boolean };
802
+
803
+ export type SpotInfo =
804
+ | { enabled: false }
805
+ | { enabled: true; spotMarketSymbol: string };
806
+
807
+ export type DisplayInfo = {
808
+ advertisedInSpot: boolean;
809
+ advertisedInPerp: boolean;
810
+ displayName: string;
811
+ displayDecimals: number;
812
+ };
813
+
814
+ export type CollateralDefinition = {
815
+ id: Uppercase<string>;
816
+ address: Address;
817
+ assetPairId: string;
818
+ priceHaircut: string;
819
+ liquidationDiscount: string;
820
+ decimals: number;
821
+ socketDepositInfo: SocketDepositInfo;
822
+ socketWithdrawInfo: SocketWithdrawInfo;
823
+ layerzeroDepositInfo: LayerzeroDepositInfo;
824
+ layerzeroWithdrawInfo: LayerzeroWithdrawInfo;
825
+ transferInfo: TransferInfo;
826
+ spotInfo: SpotInfo;
827
+ displayInfo: DisplayInfo;
828
+ };
829
+
726
830
  export type Replication = {
727
831
  [K in ReplicationMessage as `replication:${K['model']}`]: Extract<
728
832
  ReplicationMessage,
@@ -1,25 +1,10 @@
1
- import {
2
- ethers,
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
+ };