@reyaxyz/sdk 0.149.22 → 0.151.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/services/margin-accounts-v2/deposit/lz/lzBridgeAndDepositMA.js +8 -0
- package/dist/services/margin-accounts-v2/deposit/lz/lzBridgeAndDepositMA.js.map +1 -1
- package/dist/services/margin-accounts-v2/deposit/socket/socketBridgeAndDepositMA.js +31 -4
- package/dist/services/margin-accounts-v2/deposit/socket/socketBridgeAndDepositMA.js.map +1 -1
- package/dist/services/margin-accounts-v2/index.js +1 -0
- package/dist/services/margin-accounts-v2/index.js.map +1 -1
- package/dist/services/margin-accounts-v2/types.js.map +1 -1
- package/dist/services/margin-accounts-v2/weth/consts.js +35 -0
- package/dist/services/margin-accounts-v2/weth/consts.js.map +1 -0
- package/dist/services/margin-accounts-v2/weth/index.js +11 -0
- package/dist/services/margin-accounts-v2/weth/index.js.map +1 -0
- package/dist/services/margin-accounts-v2/weth/unwrap.weth.js +68 -0
- package/dist/services/margin-accounts-v2/weth/unwrap.weth.js.map +1 -0
- package/dist/services/margin-accounts-v2/weth/wrap.weth.js +65 -0
- package/dist/services/margin-accounts-v2/weth/wrap.weth.js.map +1 -0
- package/dist/types/services/margin-accounts-v2/deposit/lz/lzBridgeAndDepositMA.d.ts.map +1 -1
- package/dist/types/services/margin-accounts-v2/deposit/socket/socketBridgeAndDepositMA.d.ts.map +1 -1
- package/dist/types/services/margin-accounts-v2/index.d.ts +1 -0
- package/dist/types/services/margin-accounts-v2/index.d.ts.map +1 -1
- package/dist/types/services/margin-accounts-v2/types.d.ts +36 -0
- package/dist/types/services/margin-accounts-v2/types.d.ts.map +1 -1
- package/dist/types/services/margin-accounts-v2/weth/consts.d.ts +7 -0
- package/dist/types/services/margin-accounts-v2/weth/consts.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/weth/index.d.ts +4 -0
- package/dist/types/services/margin-accounts-v2/weth/index.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/weth/unwrap.weth.d.ts +3 -0
- package/dist/types/services/margin-accounts-v2/weth/unwrap.weth.d.ts.map +1 -0
- package/dist/types/services/margin-accounts-v2/weth/wrap.weth.d.ts +3 -0
- package/dist/types/services/margin-accounts-v2/weth/wrap.weth.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/services/margin-accounts-v2/deposit/lz/lzBridgeAndDepositMA.ts +8 -0
- package/src/services/margin-accounts-v2/deposit/socket/socketBridgeAndDepositMA.ts +51 -0
- package/src/services/margin-accounts-v2/index.ts +1 -0
- package/src/services/margin-accounts-v2/types.ts +38 -0
- package/src/services/margin-accounts-v2/weth/consts.ts +34 -0
- package/src/services/margin-accounts-v2/weth/index.ts +3 -0
- package/src/services/margin-accounts-v2/weth/unwrap.weth.ts +35 -0
- package/src/services/margin-accounts-v2/weth/wrap.weth.ts +32 -0
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
|
@@ -81,6 +81,14 @@ var lzBridgeAndDepositMAV2 = function (params) { return __awaiter(void 0, void 0
|
|
|
81
81
|
return [4 /*yield*/, (0, common_1.executeTransaction)(params.signer, calldata, params.bridgeFee.nativeFee, params.chainId, params.collateralAddress)];
|
|
82
82
|
case 3:
|
|
83
83
|
result = _a.sent();
|
|
84
|
+
// No pending row is recorded here on purpose. LayerZero carries only REYA
|
|
85
|
+
// deposits, and nothing resolves a LayerZero message's status, so a pending
|
|
86
|
+
// row would never leave `pending`.
|
|
87
|
+
//
|
|
88
|
+
// The consequence is that LayerZero deposits do not appear on
|
|
89
|
+
// /v2/wallet/{address}/deposits at all -- that channel is fed solely by this
|
|
90
|
+
// table. Supporting them means teaching resolveBridgeTransactionStatus to
|
|
91
|
+
// query the LayerZero Scan API, and recording a row here once it can.
|
|
84
92
|
return [2 /*return*/, {
|
|
85
93
|
transactionHash: (result === null || result === void 0 ? void 0 : result.hash) || null,
|
|
86
94
|
}];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lzBridgeAndDepositMA.js","sourceRoot":"/","sources":["services/margin-accounts-v2/deposit/lz/lzBridgeAndDepositMA.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAKyB;AACzB,iCAAmC;AAKnC,qDAAgE;AAChE,+DAA8D;AAE9D,IAAM,WAAW,GAAG,UAClB,MAAoC;;;;;gBAE9B,MAAM,GAAG,IAAA,gBAAO,EAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC3C,qBAAM,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAA;;gBAAhD,aAAa,GAAG,SAAgC;gBAEhD,UAAU,GAAG,IAAA,wCAA+B,EAAC;oBACjD,MAAM,QAAA;oBACN,gCAAgC,EAAE,MAAM,CAAC,gCAAgC;oBACzE,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,YAAY,EAAE,MAAM,CAAC,YAAY;oBACjC,eAAe,EAAE,IAAA,6BAAmB,GAAE;oBACtC,eAAe,EAAE,MAAM,CAAC,eAAe;iBACxC,CAAC,CAAC;gBAEG,SAAS,GAAG,IAAI,kBAAS,CAAC,eAAM,CAAC,CAAC;gBAClC,QAAQ,GAAG,SAAS,CAAC,kBAAkB,CAAC,MAAM,EAAE;oBACpD,UAAU;oBACV,MAAM,CAAC,SAAS;oBAChB,aAAa;iBACd,CAAC,CAAC;gBAEH,sBAAO,QAAQ,EAAC;;;KACjB,CAAC;AAEK,IAAM,sBAAsB,GAAG,UACpC,MAAoC;;;;oBAEpC,qBAAM,IAAA,2BAAY,EAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,EAAA;;gBAAjD,SAAiD,CAAC;g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AAU;oBACV,MAAM,CAAC,SAAS;oBAChB,aAAa;iBACd,CAAC,CAAC;gBAEH,sBAAO,QAAQ,EAAC;;;KACjB,CAAC;AAEK,IAAM,sBAAsB,GAAG,UACpC,MAAoC;;;;oBAEpC,qBAAM,IAAA,2BAAY,EAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,EAAA;;gBAAjD,SAAiD,CAAC;gBACjC,qBAAM,WAAW,CAAC,MAAM,CAAC,EAAA;;gBAApC,QAAQ,GAAG,SAAyB;gBAE3B,qBAAM,IAAA,2BAAkB,EACrC,MAAM,CAAC,MAAM,EACb,QAAQ,EACR,MAAM,CAAC,SAAS,CAAC,SAAS,EAC1B,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,iBAAiB,CACzB,EAAA;;gBANK,MAAM,GAAG,SAMd;gBAED,0EAA0E;gBAC1E,4EAA4E;gBAC5E,mCAAmC;gBACnC,EAAE;gBACF,8DAA8D;gBAC9D,6EAA6E;gBAC7E,0EAA0E;gBAC1E,sEAAsE;gBACtE,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,KAAI,IAAI;qBACtC,EAAC;;;KACH,CAAC;AAzBW,QAAA,sBAAsB,0BAyBjC","sourcesContent":["import {\n buildOFTSendParamsToDepositInMA,\n executeTransaction,\n OFTAbi,\n scaleV2,\n} from '@reyaxyz/common';\nimport { Interface } from 'ethers';\nimport {\n LzBridgeAndDepositMAParamsV2,\n LzBridgeAndDepositMAResultV2,\n} from '../../types';\nimport { getPeripheryAddress } from '../../../../utils/network';\nimport { checkChainId } from '../../../../utils/checkChainId';\n\nconst getCalldata = async (\n params: LzBridgeAndDepositMAParamsV2,\n): Promise<string> => {\n const amount = scaleV2(params.collateralDecimals)(params.amount);\n const refundAddress = await params.signer.getAddress();\n\n const sendParams = buildOFTSendParamsToDepositInMA({\n amount,\n collateralAddressInReyaPeriphery: params.collateralAddressInReyaPeriphery,\n dstEid: params.dstEid,\n extraOptions: params.extraOptions,\n receiverAddress: getPeripheryAddress(),\n marginAccountId: params.marginAccountId,\n });\n\n const INTERFACE = new Interface(OFTAbi);\n const calldata = INTERFACE.encodeFunctionData('send', [\n sendParams,\n params.bridgeFee,\n refundAddress,\n ]);\n\n return calldata;\n};\n\nexport const lzBridgeAndDepositMAV2 = async (\n params: LzBridgeAndDepositMAParamsV2,\n): Promise<LzBridgeAndDepositMAResultV2> => {\n await checkChainId(params.signer, params.chainId);\n const calldata = await getCalldata(params);\n\n const result = await executeTransaction(\n params.signer,\n calldata,\n params.bridgeFee.nativeFee,\n params.chainId,\n params.collateralAddress,\n );\n\n // No pending row is recorded here on purpose. LayerZero carries only REYA\n // deposits, and nothing resolves a LayerZero message's status, so a pending\n // row would never leave `pending`.\n //\n // The consequence is that LayerZero deposits do not appear on\n // /v2/wallet/{address}/deposits at all -- that channel is fed solely by this\n // table. Supporting them means teaching resolveBridgeTransactionStatus to\n // query the LayerZero Scan API, and recording a row here once it can.\n return {\n transactionHash: result?.hash || null,\n };\n};\n"]}
|
|
@@ -41,6 +41,7 @@ var ethers_1 = require("ethers");
|
|
|
41
41
|
var common_1 = require("@reyaxyz/common");
|
|
42
42
|
var network_1 = require("../../../../utils/network");
|
|
43
43
|
var checkChainId_1 = require("../../../../utils/checkChainId");
|
|
44
|
+
var config_1 = require("../../../../config");
|
|
44
45
|
var getCalldata = function (params) {
|
|
45
46
|
var amount = (0, common_1.scaleV2)(params.collateralDecimals)(params.amount);
|
|
46
47
|
var PERIPHERY_INTERFACE = new ethers_1.Interface(common_1.PeripheryAbi);
|
|
@@ -62,7 +63,7 @@ var getCalldata = function (params) {
|
|
|
62
63
|
return calldata;
|
|
63
64
|
};
|
|
64
65
|
var socketBridgeAndDepositMAV2 = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
65
|
-
var calldata, result;
|
|
66
|
+
var calldata, result, persistedPendingTransaction, reyaChainId, peripheryTokenInfo, coreTokenInfo, error_1;
|
|
66
67
|
return __generator(this, function (_a) {
|
|
67
68
|
switch (_a.label) {
|
|
68
69
|
case 0: return [4 /*yield*/, (0, checkChainId_1.checkChainId)(params.signer, params.chainId)];
|
|
@@ -72,9 +73,35 @@ var socketBridgeAndDepositMAV2 = function (params) { return __awaiter(void 0, vo
|
|
|
72
73
|
return [4 /*yield*/, (0, common_1.executeTransaction)(params.signer, calldata, params.bridgeFee, params.chainId, params.vaultAddress)];
|
|
73
74
|
case 2:
|
|
74
75
|
result = _a.sent();
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
persistedPendingTransaction = {
|
|
77
|
+
status: false,
|
|
78
|
+
reason: 'Deposit transaction was not broadcast',
|
|
79
|
+
};
|
|
80
|
+
if (!(result === null || result === void 0 ? void 0 : result.hash)) return [3 /*break*/, 6];
|
|
81
|
+
_a.label = 3;
|
|
82
|
+
case 3:
|
|
83
|
+
_a.trys.push([3, 5, , 6]);
|
|
84
|
+
reyaChainId = (0, common_1.getReyaNetworkFromMoneyInOutChainId)(params.chainId);
|
|
85
|
+
peripheryTokenInfo = (0, common_1.getTokenInfoByAddress)(params.collateralAddressInReyaPeriphery, reyaChainId);
|
|
86
|
+
coreTokenInfo = peripheryTokenInfo.isRUSDUnderlying
|
|
87
|
+
? (0, common_1.getTokenInfoByName)('RUSD', reyaChainId)
|
|
88
|
+
: peripheryTokenInfo;
|
|
89
|
+
return [4 /*yield*/, (0, config_1.getTransactionModuleClient)().pushPendingTransaction(params.accountId, result.hash, params.chainId, params.amount, coreTokenInfo.address, 'deposit')];
|
|
90
|
+
case 4:
|
|
91
|
+
_a.sent();
|
|
92
|
+
persistedPendingTransaction = { status: true };
|
|
93
|
+
return [3 /*break*/, 6];
|
|
94
|
+
case 5:
|
|
95
|
+
error_1 = _a.sent();
|
|
96
|
+
persistedPendingTransaction = {
|
|
97
|
+
status: false,
|
|
98
|
+
reason: error_1 instanceof Error ? error_1.message : String(error_1),
|
|
99
|
+
};
|
|
100
|
+
return [3 /*break*/, 6];
|
|
101
|
+
case 6: return [2 /*return*/, {
|
|
102
|
+
transactionHash: (result === null || result === void 0 ? void 0 : result.hash) || null,
|
|
103
|
+
persistedPendingTransaction: persistedPendingTransaction,
|
|
104
|
+
}];
|
|
78
105
|
}
|
|
79
106
|
});
|
|
80
107
|
}); };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socketBridgeAndDepositMA.js","sourceRoot":"/","sources":["services/margin-accounts-v2/deposit/socket/socketBridgeAndDepositMA.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,
|
|
1
|
+
{"version":3,"file":"socketBridgeAndDepositMA.js","sourceRoot":"/","sources":["services/margin-accounts-v2/deposit/socket/socketBridgeAndDepositMA.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,0CASyB;AAMzB,qDAAgE;AAChE,+DAA8D;AAC9D,6CAAgE;AAEhE,IAAM,WAAW,GAAG,UAAC,MAAwC;IAC3D,IAAM,MAAM,GAAG,IAAA,gBAAO,EAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEjE,IAAM,mBAAmB,GAAG,IAAI,kBAAS,CAAC,qBAAY,CAAC,CAAC;IACxD,IAAM,MAAM,GAAG;QACb,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,KAAK,EAAE,MAAM,CAAC,gCAAgC;KAC/C,CAAC;IACF,IAAM,iBAAiB,GAAG,mBAAmB,CAAC,kBAAkB,CAC9D,sCAAsC,EACtC,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,IAAM,eAAe,GAAG,IAAI,kBAAS,CAAC,mCAAQ,CAAC,CAAC;IAChD,IAAM,UAAU,GAAG;QACjB,IAAA,6BAAmB,GAAE;QACrB,MAAM;QACN,MAAM,CAAC,WAAW;QAClB,MAAM,CA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gBAEF,2BAA2B,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;;;;gBAE/C,2BAA2B,GAAG;oBAC5B,MAAM,EAAE,KAAK;oBACb,MAAM,EAAE,OAAK,YAAY,KAAK,CAAC,CAAC,CAAC,OAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAK,CAAC;iBAC/D,CAAC;;oBAIN,sBAAO;oBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,KAAI,IAAI;oBACrC,2BAA2B,6BAAA;iBAC5B,EAAC;;;KACH,CAAC;AA9DW,QAAA,0BAA0B,8BA8DrC","sourcesContent":["import { Interface } from 'ethers';\nimport {\n PeripheryAbi,\n Socket_VaultWithPayloadAbi as VaultAbi,\n executeTransaction,\n scaleV2,\n getReyaNetworkFromMoneyInOutChainId,\n getTokenInfoByAddress,\n getTokenInfoByName,\n MoneyInOutChainId,\n} from '@reyaxyz/common';\nimport {\n SocketBridgeAndDepositMAParamsV2,\n SocketBridgeAndDepositMAResultV2,\n PendingTransactionPersistence,\n} from '../../types';\nimport { getPeripheryAddress } from '../../../../utils/network';\nimport { checkChainId } from '../../../../utils/checkChainId';\nimport { getTransactionModuleClient } from '../../../../config';\n\nconst getCalldata = (params: SocketBridgeAndDepositMAParamsV2): string => {\n const amount = scaleV2(params.collateralDecimals)(params.amount);\n\n const PERIPHERY_INTERFACE = new Interface(PeripheryAbi);\n const inputs = {\n accountId: params.accountId,\n token: params.collateralAddressInReyaPeriphery,\n };\n const peripheryCalldata = PERIPHERY_INTERFACE.encodeFunctionData(\n 'depositExistingMA((uint128,address))',\n [inputs],\n );\n\n const VAULT_INTERFACE = new Interface(VaultAbi);\n const parameters = [\n getPeripheryAddress(),\n amount,\n params.msgGasLimit,\n params.connectorAddress,\n peripheryCalldata,\n '0x',\n ];\n const calldata = VAULT_INTERFACE.encodeFunctionData('bridge', parameters);\n\n return calldata;\n};\n\nexport const socketBridgeAndDepositMAV2 = async (\n params: SocketBridgeAndDepositMAParamsV2,\n): Promise<SocketBridgeAndDepositMAResultV2> => {\n await checkChainId(params.signer, params.chainId);\n const calldata = getCalldata(params);\n\n const result = await executeTransaction(\n params.signer,\n calldata,\n params.bridgeFee,\n params.chainId,\n params.vaultAddress,\n );\n\n let persistedPendingTransaction: PendingTransactionPersistence = {\n status: false,\n reason: 'Deposit transaction was not broadcast',\n };\n\n if (result?.hash) {\n // Record the deposit as pending so it can be surfaced while the bridge\n // delivers. Best-effort: the deposit is already on-chain by now, so a\n // failure here must never surface to the caller as a throw -- it is\n // returned instead, for the caller to report.\n try {\n const reyaChainId = getReyaNetworkFromMoneyInOutChainId(\n params.chainId as MoneyInOutChainId,\n );\n\n // `asset_id` is a foreign key onto the Reya-side Asset row, which is the\n // *core* token -- rUSD-underlying collateral (e.g. USDC) lands in the\n // margin account as RUSD. Mirrors the v1 bridgeAndDepositExistingMA path.\n const peripheryTokenInfo = getTokenInfoByAddress(\n params.collateralAddressInReyaPeriphery,\n reyaChainId,\n );\n const coreTokenInfo = peripheryTokenInfo.isRUSDUnderlying\n ? getTokenInfoByName('RUSD', reyaChainId)\n : peripheryTokenInfo;\n\n await getTransactionModuleClient().pushPendingTransaction(\n params.accountId,\n result.hash,\n params.chainId,\n params.amount,\n coreTokenInfo.address,\n 'deposit',\n );\n\n persistedPendingTransaction = { status: true };\n } catch (error) {\n persistedPendingTransaction = {\n status: false,\n reason: error instanceof Error ? error.message : String(error),\n };\n }\n }\n\n return {\n transactionHash: result?.hash || null,\n persistedPendingTransaction,\n };\n};\n"]}
|
|
@@ -20,4 +20,5 @@ __exportStar(require("./deposit"), exports);
|
|
|
20
20
|
__exportStar(require("./transferMarginBetweenAccounts"), exports);
|
|
21
21
|
__exportStar(require("./withdraw"), exports);
|
|
22
22
|
__exportStar(require("./erc20"), exports);
|
|
23
|
+
__exportStar(require("./weth"), exports);
|
|
23
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["services/margin-accounts-v2/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,kDAAgC;AAChC,4CAA0B;AAC1B,kEAAgD;AAChD,6CAA2B;AAC3B,0CAAwB","sourcesContent":["export * from './types';\nexport * from './createAccount';\nexport * from './deposit';\nexport * from './transferMarginBetweenAccounts';\nexport * from './withdraw';\nexport * from './erc20';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["services/margin-accounts-v2/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,kDAAgC;AAChC,4CAA0B;AAC1B,kEAAgD;AAChD,6CAA2B;AAC3B,0CAAwB;AACxB,yCAAuB","sourcesContent":["export * from './types';\nexport * from './createAccount';\nexport * from './deposit';\nexport * from './transferMarginBetweenAccounts';\nexport * from './withdraw';\nexport * from './erc20';\nexport * from './weth';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/margin-accounts-v2/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport { Address, OFTMessagingFee } from '@reyaxyz/common';\n\nexport type CreateAccountParamsV2 = {\n ownerAddress: string;\n name: string;\n};\n\nexport type CreateAccountResultV2 = {\n transactionHash: string | null;\n accountId: number | null;\n};\n\nexport type TransferMAParamsV2 = {\n collateralAddress: Address;\n collateralDecimals: number;\n signer: Signer | JsonRpcSigner;\n coreSigNonce: number;\n fromMarginAccountId: number;\n toMarginAccountId: number;\n amount: number;\n};\n\nexport type TransferMAResultV2 = {\n transactionHash: string | null;\n coreSigNonce: number | null;\n};\n\nexport type SocketBridgeAndDepositMAParamsV2 = {\n collateralAddressInReyaPeriphery: Address;\n collateralDecimals: number;\n chainId: number;\n bridgeFee: string;\n vaultAddress: Address;\n connectorAddress: Address;\n msgGasLimit: string;\n signer: Signer | JsonRpcSigner;\n accountId: number;\n amount: number;\n};\n\nexport type SocketBridgeAndDepositMAResultV2 = {\n transactionHash: string | null;\n};\n\nexport type LzBridgeAndDepositMAParamsV2 = {\n collateralAddress: Address;\n collateralDecimals: number;\n collateralAddressInReyaPeriphery: Address;\n chainId: number;\n dstEid: number;\n bridgeFee: OFTMessagingFee;\n extraOptions: string;\n signer: Signer | JsonRpcSigner;\n marginAccountId: number;\n amount: number;\n};\n\nexport type LzBridgeAndDepositMAResultV2 = {\n transactionHash: string | null;\n};\n\nexport type EstimateFeeLzBridgeAndDepositMAParamsV2 = Pick<\n LzBridgeAndDepositMAParamsV2,\n | 'collateralAddress'\n | 'collateralDecimals'\n | 'collateralAddressInReyaPeriphery'\n | 'chainId'\n | 'dstEid'\n | 'extraOptions'\n> & {\n signer: Signer | JsonRpcSigner;\n};\n\nexport type EstimateFeeSocketBridgeAndDepositMAParamsV2 = Pick<\n SocketBridgeAndDepositMAParamsV2,\n 'vaultAddress' | 'connectorAddress' | 'msgGasLimit' | 'chainId'\n> & {\n signer: Signer | JsonRpcSigner;\n};\n\nexport type WithdrawMAAndSocketBridgeParamsV2 = {\n collateralAddressInReyaCore: Address;\n collateralDecimals: number;\n destinationChainId: number;\n msgGasLimit: string;\n signer: Signer | JsonRpcSigner;\n coreSigNonce: number;\n marginAccountId: number;\n amount: number;\n receiverAddress: Address;\n};\n\nexport type WithdrawMAAndSocketBridgeResultV2 = {\n transactionHash: string | null;\n coreSigNonce: number | null;\n};\n\nexport type WithdrawMAAndLzBridgeParamsV2 = {\n collateralAddressInReyaCore: Address;\n collateralDecimals: number;\n dstEid: number;\n signer: Signer | JsonRpcSigner;\n coreSigNonce: number;\n marginAccountId: number;\n amount: number;\n receiverAddress: Address;\n};\n\nexport type WithdrawMAAndLzBridgeResultV2 = {\n transactionHash: string | null;\n coreSigNonce: number | null;\n};\n\nexport type Erc20ApproveParamsV2 = {\n collateralAddress: Address;\n collateralDecimals: number;\n spenderAddress: Address;\n chainId: number;\n signer: Signer | JsonRpcSigner;\n amount: number;\n};\n\nexport type Erc20ApproveResultV2 = {\n transactionHash: string | null;\n};\n\nexport type Erc20GetAllowanceParamsV2 = {\n signer: Signer | JsonRpcSigner;\n collateralAddress: Address;\n collateralDecimals: number;\n walletAddress: Address;\n spenderAddress: Address;\n chainId: number;\n};\n\nexport type Erc20GetAllowanceResultV2 = {\n allowance: number;\n};\n\nexport type Erc20GetBalanceParamsV2 = {\n signer: Signer | JsonRpcSigner;\n collateralAddress: Address;\n collateralDecimals: number;\n chainId: number;\n walletAddress: Address;\n};\n\nexport type Erc20GetBalanceResultV2 = {\n balance: number;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/margin-accounts-v2/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport { Address, OFTMessagingFee } from '@reyaxyz/common';\n\nexport type CreateAccountParamsV2 = {\n ownerAddress: string;\n name: string;\n};\n\nexport type CreateAccountResultV2 = {\n transactionHash: string | null;\n accountId: number | null;\n};\n\nexport type TransferMAParamsV2 = {\n collateralAddress: Address;\n collateralDecimals: number;\n signer: Signer | JsonRpcSigner;\n coreSigNonce: number;\n fromMarginAccountId: number;\n toMarginAccountId: number;\n amount: number;\n};\n\nexport type TransferMAResultV2 = {\n transactionHash: string | null;\n coreSigNonce: number | null;\n};\n\nexport type SocketBridgeAndDepositMAParamsV2 = {\n collateralAddressInReyaPeriphery: Address;\n collateralDecimals: number;\n chainId: number;\n bridgeFee: string;\n vaultAddress: Address;\n connectorAddress: Address;\n msgGasLimit: string;\n signer: Signer | JsonRpcSigner;\n accountId: number;\n amount: number;\n};\n\n/**\n * Whether the pending row was registered with the API.\n *\n * Recording it is best-effort -- the deposit is already on-chain by then, so a\n * failure never fails the deposit -- but the caller is the one with error\n * reporting wired up, so the outcome is returned rather than swallowed. A\n * `false` here means the deposit will not appear as pending until the bridge\n * delivers and the indexer picks it up.\n */\nexport type PendingTransactionPersistence =\n | { status: true }\n | { status: false; reason: string };\n\nexport type SocketBridgeAndDepositMAResultV2 = {\n transactionHash: string | null;\n persistedPendingTransaction: PendingTransactionPersistence;\n};\n\nexport type LzBridgeAndDepositMAParamsV2 = {\n collateralAddress: Address;\n collateralDecimals: number;\n collateralAddressInReyaPeriphery: Address;\n chainId: number;\n dstEid: number;\n bridgeFee: OFTMessagingFee;\n extraOptions: string;\n signer: Signer | JsonRpcSigner;\n marginAccountId: number;\n amount: number;\n};\n\nexport type LzBridgeAndDepositMAResultV2 = {\n transactionHash: string | null;\n};\n\nexport type EstimateFeeLzBridgeAndDepositMAParamsV2 = Pick<\n LzBridgeAndDepositMAParamsV2,\n | 'collateralAddress'\n | 'collateralDecimals'\n | 'collateralAddressInReyaPeriphery'\n | 'chainId'\n | 'dstEid'\n | 'extraOptions'\n> & {\n signer: Signer | JsonRpcSigner;\n};\n\nexport type EstimateFeeSocketBridgeAndDepositMAParamsV2 = Pick<\n SocketBridgeAndDepositMAParamsV2,\n 'vaultAddress' | 'connectorAddress' | 'msgGasLimit' | 'chainId'\n> & {\n signer: Signer | JsonRpcSigner;\n};\n\nexport type WithdrawMAAndSocketBridgeParamsV2 = {\n collateralAddressInReyaCore: Address;\n collateralDecimals: number;\n destinationChainId: number;\n msgGasLimit: string;\n signer: Signer | JsonRpcSigner;\n coreSigNonce: number;\n marginAccountId: number;\n amount: number;\n receiverAddress: Address;\n};\n\nexport type WithdrawMAAndSocketBridgeResultV2 = {\n transactionHash: string | null;\n coreSigNonce: number | null;\n};\n\nexport type WithdrawMAAndLzBridgeParamsV2 = {\n collateralAddressInReyaCore: Address;\n collateralDecimals: number;\n dstEid: number;\n signer: Signer | JsonRpcSigner;\n coreSigNonce: number;\n marginAccountId: number;\n amount: number;\n receiverAddress: Address;\n};\n\nexport type WithdrawMAAndLzBridgeResultV2 = {\n transactionHash: string | null;\n coreSigNonce: number | null;\n};\n\nexport type Erc20ApproveParamsV2 = {\n collateralAddress: Address;\n collateralDecimals: number;\n spenderAddress: Address;\n chainId: number;\n signer: Signer | JsonRpcSigner;\n amount: number;\n};\n\nexport type Erc20ApproveResultV2 = {\n transactionHash: string | null;\n};\n\nexport type WrapEthParamsV2 = {\n signer: Signer | JsonRpcSigner;\n collateralAddress: Address;\n collateralDecimals: number;\n chainId: number;\n amount: number;\n};\n\nexport type WrapEthResultV2 = {\n transactionHash: string | null;\n};\n\nexport type UnwrapEthParamsV2 = {\n signer: Signer | JsonRpcSigner;\n collateralAddress: Address;\n collateralDecimals: number;\n chainId: number;\n amount: number;\n};\n\nexport type UnwrapEthResultV2 = {\n transactionHash: string | null;\n};\n\nexport type Erc20GetAllowanceParamsV2 = {\n signer: Signer | JsonRpcSigner;\n collateralAddress: Address;\n collateralDecimals: number;\n walletAddress: Address;\n spenderAddress: Address;\n chainId: number;\n};\n\nexport type Erc20GetAllowanceResultV2 = {\n allowance: number;\n};\n\nexport type Erc20GetBalanceParamsV2 = {\n signer: Signer | JsonRpcSigner;\n collateralAddress: Address;\n collateralDecimals: number;\n chainId: number;\n walletAddress: Address;\n};\n\nexport type Erc20GetBalanceResultV2 = {\n balance: number;\n};\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertPositiveAmount = exports.assertWrappableChain = exports.isWrappableChain = exports.WETH9_CHAIN_IDS = exports.WETH9_INTERFACE = void 0;
|
|
4
|
+
var ethers_1 = require("ethers");
|
|
5
|
+
var common_1 = require("@reyaxyz/common");
|
|
6
|
+
exports.WETH9_INTERFACE = new ethers_1.Interface([
|
|
7
|
+
'function deposit() external payable',
|
|
8
|
+
'function withdraw(uint256 wad) external',
|
|
9
|
+
]);
|
|
10
|
+
// Only chains whose `WETH` is a genuine WETH9. Most are not — Polygon's is a
|
|
11
|
+
// bridged UChildERC20, the Sepolia entries are test ERC20s, and the Reya chains'
|
|
12
|
+
// is the Socket-bridged representation — and wrapping is payable, so calling one
|
|
13
|
+
// of those sends native ETH somewhere unrecoverable. Verify `deposit()` on-chain
|
|
14
|
+
// before adding a chain here.
|
|
15
|
+
exports.WETH9_CHAIN_IDS = [
|
|
16
|
+
common_1.MoneyInOutChainId.ethereumMainnet,
|
|
17
|
+
common_1.MoneyInOutChainId.arbitrumOne,
|
|
18
|
+
];
|
|
19
|
+
var isWrappableChain = function (chainId) {
|
|
20
|
+
return exports.WETH9_CHAIN_IDS.includes(chainId);
|
|
21
|
+
};
|
|
22
|
+
exports.isWrappableChain = isWrappableChain;
|
|
23
|
+
var assertWrappableChain = function (chainId) {
|
|
24
|
+
if (!(0, exports.isWrappableChain)(chainId)) {
|
|
25
|
+
throw new Error("ETH wrap/unwrap is not supported on chain ".concat(chainId, " \u2014 its WETH is not a WETH9 contract"));
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.assertWrappableChain = assertWrappableChain;
|
|
29
|
+
var assertPositiveAmount = function (amount, action) {
|
|
30
|
+
if (amount <= BigInt(0)) {
|
|
31
|
+
throw new Error("Cannot ".concat(action, " a zero or negative amount"));
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.assertPositiveAmount = assertPositiveAmount;
|
|
35
|
+
//# sourceMappingURL=consts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"/","sources":["services/margin-accounts-v2/weth/consts.ts"],"names":[],"mappings":";;;AAAA,iCAAmC;AACnC,0CAAoD;AAEvC,QAAA,eAAe,GAAG,IAAI,kBAAS,CAAC;IAC3C,qCAAqC;IACrC,yCAAyC;CAC1C,CAAC,CAAC;AAEH,6EAA6E;AAC7E,iFAAiF;AACjF,iFAAiF;AACjF,iFAAiF;AACjF,8BAA8B;AACjB,QAAA,eAAe,GAAsB;IAChD,0BAAiB,CAAC,eAAe;IACjC,0BAAiB,CAAC,WAAW;CAC9B,CAAC;AAEK,IAAM,gBAAgB,GAAG,UAAC,OAAe;IAC9C,OAAA,uBAAe,CAAC,QAAQ,CAAC,OAAO,CAAC;AAAjC,CAAiC,CAAC;AADvB,QAAA,gBAAgB,oBACO;AAE7B,IAAM,oBAAoB,GAAG,UAAC,OAAe;IAClD,IAAI,CAAC,IAAA,wBAAgB,EAAC,OAAO,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CACb,oDAA6C,OAAO,6CAAqC,CAC1F,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AANW,QAAA,oBAAoB,wBAM/B;AAEK,IAAM,oBAAoB,GAAG,UAAC,MAAc,EAAE,MAAc;IACjE,IAAI,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,iBAAU,MAAM,+BAA4B,CAAC,CAAC;IAChE,CAAC;AACH,CAAC,CAAC;AAJW,QAAA,oBAAoB,wBAI/B","sourcesContent":["import { Interface } from 'ethers';\nimport { MoneyInOutChainId } from '@reyaxyz/common';\n\nexport const WETH9_INTERFACE = new Interface([\n 'function deposit() external payable',\n 'function withdraw(uint256 wad) external',\n]);\n\n// Only chains whose `WETH` is a genuine WETH9. Most are not — Polygon's is a\n// bridged UChildERC20, the Sepolia entries are test ERC20s, and the Reya chains'\n// is the Socket-bridged representation — and wrapping is payable, so calling one\n// of those sends native ETH somewhere unrecoverable. Verify `deposit()` on-chain\n// before adding a chain here.\nexport const WETH9_CHAIN_IDS: readonly number[] = [\n MoneyInOutChainId.ethereumMainnet,\n MoneyInOutChainId.arbitrumOne,\n];\n\nexport const isWrappableChain = (chainId: number): boolean =>\n WETH9_CHAIN_IDS.includes(chainId);\n\nexport const assertWrappableChain = (chainId: number): void => {\n if (!isWrappableChain(chainId)) {\n throw new Error(\n `ETH wrap/unwrap is not supported on chain ${chainId} — its WETH is not a WETH9 contract`,\n );\n }\n};\n\nexport const assertPositiveAmount = (amount: bigint, action: string): void => {\n if (amount <= BigInt(0)) {\n throw new Error(`Cannot ${action} a zero or negative amount`);\n }\n};\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WETH9_CHAIN_IDS = exports.isWrappableChain = exports.unwrapEthV2 = exports.wrapEthV2 = void 0;
|
|
4
|
+
var wrap_weth_1 = require("./wrap.weth");
|
|
5
|
+
Object.defineProperty(exports, "wrapEthV2", { enumerable: true, get: function () { return wrap_weth_1.wrapEthV2; } });
|
|
6
|
+
var unwrap_weth_1 = require("./unwrap.weth");
|
|
7
|
+
Object.defineProperty(exports, "unwrapEthV2", { enumerable: true, get: function () { return unwrap_weth_1.unwrapEthV2; } });
|
|
8
|
+
var consts_1 = require("./consts");
|
|
9
|
+
Object.defineProperty(exports, "isWrappableChain", { enumerable: true, get: function () { return consts_1.isWrappableChain; } });
|
|
10
|
+
Object.defineProperty(exports, "WETH9_CHAIN_IDS", { enumerable: true, get: function () { return consts_1.WETH9_CHAIN_IDS; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["services/margin-accounts-v2/weth/index.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,mCAA6D;AAApD,0GAAA,gBAAgB,OAAA;AAAE,yGAAA,eAAe,OAAA","sourcesContent":["export { wrapEthV2 } from './wrap.weth';\nexport { unwrapEthV2 } from './unwrap.weth';\nexport { isWrappableChain, WETH9_CHAIN_IDS } from './consts';\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.unwrapEthV2 = void 0;
|
|
40
|
+
var common_1 = require("@reyaxyz/common");
|
|
41
|
+
var checkChainId_1 = require("../../../utils/checkChainId");
|
|
42
|
+
var consts_1 = require("./consts");
|
|
43
|
+
// `amount` is a JS number, which at 18 decimals cannot address individual wei,
|
|
44
|
+
// so unwrapping a full balance must round down — a balance read back as a number
|
|
45
|
+
// can scale to marginally more than is held, which reverts.
|
|
46
|
+
var unwrapEthV2 = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
47
|
+
var amount, calldata, result;
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
switch (_a.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
(0, consts_1.assertWrappableChain)(params.chainId);
|
|
52
|
+
return [4 /*yield*/, (0, checkChainId_1.checkChainId)(params.signer, params.chainId)];
|
|
53
|
+
case 1:
|
|
54
|
+
_a.sent();
|
|
55
|
+
amount = (0, common_1.scaleV2)(params.collateralDecimals)(params.amount);
|
|
56
|
+
(0, consts_1.assertPositiveAmount)(amount, 'unwrap');
|
|
57
|
+
calldata = consts_1.WETH9_INTERFACE.encodeFunctionData('withdraw', [amount]);
|
|
58
|
+
return [4 /*yield*/, (0, common_1.executeTransaction)(params.signer, calldata, '0', params.chainId, params.collateralAddress)];
|
|
59
|
+
case 2:
|
|
60
|
+
result = _a.sent();
|
|
61
|
+
return [2 /*return*/, {
|
|
62
|
+
transactionHash: (result === null || result === void 0 ? void 0 : result.hash) || null,
|
|
63
|
+
}];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}); };
|
|
67
|
+
exports.unwrapEthV2 = unwrapEthV2;
|
|
68
|
+
//# sourceMappingURL=unwrap.weth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unwrap.weth.js","sourceRoot":"/","sources":["services/margin-accounts-v2/weth/unwrap.weth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAA8D;AAC9D,4DAA2D;AAE3D,mCAIkB;AAElB,+EAA+E;AAC/E,iFAAiF;AACjF,4DAA4D;AACrD,IAAM,WAAW,GAAG,UACzB,MAAyB;;;;;gBAEzB,IAAA,6BAAoB,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBACrC,qBAAM,IAAA,2BAAY,EAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,EAAA;;gBAAjD,SAAiD,CAAC;gBAE5C,MAAM,GAAG,IAAA,gBAAO,EAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBACjE,IAAA,6BAAoB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;gBAEjC,QAAQ,GAAG,wBAAe,CAAC,kBAAkB,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;gBAE3D,qBAAM,IAAA,2BAAkB,EACrC,MAAM,CAAC,MAAM,EACb,QAAQ,EACR,GAAG,EACH,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,iBAAiB,CACzB,EAAA;;gBANK,MAAM,GAAG,SAMd;gBAED,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,KAAI,IAAI;qBACtC,EAAC;;;KACH,CAAC;AAtBW,QAAA,WAAW,eAsBtB","sourcesContent":["import { executeTransaction, scaleV2 } from '@reyaxyz/common';\nimport { checkChainId } from '../../../utils/checkChainId';\nimport { UnwrapEthParamsV2, UnwrapEthResultV2 } from '../types';\nimport {\n assertPositiveAmount,\n assertWrappableChain,\n WETH9_INTERFACE,\n} from './consts';\n\n// `amount` is a JS number, which at 18 decimals cannot address individual wei,\n// so unwrapping a full balance must round down — a balance read back as a number\n// can scale to marginally more than is held, which reverts.\nexport const unwrapEthV2 = async (\n params: UnwrapEthParamsV2,\n): Promise<UnwrapEthResultV2> => {\n assertWrappableChain(params.chainId);\n await checkChainId(params.signer, params.chainId);\n\n const amount = scaleV2(params.collateralDecimals)(params.amount);\n assertPositiveAmount(amount, 'unwrap');\n\n const calldata = WETH9_INTERFACE.encodeFunctionData('withdraw', [amount]);\n\n const result = await executeTransaction(\n params.signer,\n calldata,\n '0',\n params.chainId,\n params.collateralAddress,\n );\n\n return {\n transactionHash: result?.hash || null,\n };\n};\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.wrapEthV2 = void 0;
|
|
40
|
+
var common_1 = require("@reyaxyz/common");
|
|
41
|
+
var checkChainId_1 = require("../../../utils/checkChainId");
|
|
42
|
+
var consts_1 = require("./consts");
|
|
43
|
+
var wrapEthV2 = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
44
|
+
var amount, calldata, result;
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
switch (_a.label) {
|
|
47
|
+
case 0:
|
|
48
|
+
(0, consts_1.assertWrappableChain)(params.chainId);
|
|
49
|
+
return [4 /*yield*/, (0, checkChainId_1.checkChainId)(params.signer, params.chainId)];
|
|
50
|
+
case 1:
|
|
51
|
+
_a.sent();
|
|
52
|
+
amount = (0, common_1.scaleV2)(params.collateralDecimals)(params.amount);
|
|
53
|
+
(0, consts_1.assertPositiveAmount)(amount, 'wrap');
|
|
54
|
+
calldata = consts_1.WETH9_INTERFACE.encodeFunctionData('deposit', []);
|
|
55
|
+
return [4 /*yield*/, (0, common_1.executeTransaction)(params.signer, calldata, amount.toString(), params.chainId, params.collateralAddress)];
|
|
56
|
+
case 2:
|
|
57
|
+
result = _a.sent();
|
|
58
|
+
return [2 /*return*/, {
|
|
59
|
+
transactionHash: (result === null || result === void 0 ? void 0 : result.hash) || null,
|
|
60
|
+
}];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}); };
|
|
64
|
+
exports.wrapEthV2 = wrapEthV2;
|
|
65
|
+
//# sourceMappingURL=wrap.weth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap.weth.js","sourceRoot":"/","sources":["services/margin-accounts-v2/weth/wrap.weth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAA8D;AAC9D,4DAA2D;AAE3D,mCAIkB;AAEX,IAAM,SAAS,GAAG,UACvB,MAAuB;;;;;gBAEvB,IAAA,6BAAoB,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBACrC,qBAAM,IAAA,2BAAY,EAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,EAAA;;gBAAjD,SAAiD,CAAC;gBAE5C,MAAM,GAAG,IAAA,gBAAO,EAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBACjE,IAAA,6BAAoB,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAE/B,QAAQ,GAAG,wBAAe,CAAC,kBAAkB,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;gBAEpD,qBAAM,IAAA,2BAAkB,EACrC,MAAM,CAAC,MAAM,EACb,QAAQ,EACR,MAAM,CAAC,QAAQ,EAAE,EACjB,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,iBAAiB,CACzB,EAAA;;gBANK,MAAM,GAAG,SAMd;gBAED,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,KAAI,IAAI;qBACtC,EAAC;;;KACH,CAAC;AAtBW,QAAA,SAAS,aAsBpB","sourcesContent":["import { executeTransaction, scaleV2 } from '@reyaxyz/common';\nimport { checkChainId } from '../../../utils/checkChainId';\nimport { WrapEthParamsV2, WrapEthResultV2 } from '../types';\nimport {\n assertPositiveAmount,\n assertWrappableChain,\n WETH9_INTERFACE,\n} from './consts';\n\nexport const wrapEthV2 = async (\n params: WrapEthParamsV2,\n): Promise<WrapEthResultV2> => {\n assertWrappableChain(params.chainId);\n await checkChainId(params.signer, params.chainId);\n\n const amount = scaleV2(params.collateralDecimals)(params.amount);\n assertPositiveAmount(amount, 'wrap');\n\n const calldata = WETH9_INTERFACE.encodeFunctionData('deposit', []);\n\n const result = await executeTransaction(\n params.signer,\n calldata,\n amount.toString(),\n params.chainId,\n params.collateralAddress,\n );\n\n return {\n transactionHash: result?.hash || null,\n };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lzBridgeAndDepositMA.d.ts","sourceRoot":"/","sources":["services/margin-accounts-v2/deposit/lz/lzBridgeAndDepositMA.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC7B,MAAM,aAAa,CAAC;AA6BrB,eAAO,MAAM,sBAAsB,WACzB,4BAA4B,KACnC,QAAQ,4BAA4B,
|
|
1
|
+
{"version":3,"file":"lzBridgeAndDepositMA.d.ts","sourceRoot":"/","sources":["services/margin-accounts-v2/deposit/lz/lzBridgeAndDepositMA.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC7B,MAAM,aAAa,CAAC;AA6BrB,eAAO,MAAM,sBAAsB,WACzB,4BAA4B,KACnC,QAAQ,4BAA4B,CAuBtC,CAAC"}
|
package/dist/types/services/margin-accounts-v2/deposit/socket/socketBridgeAndDepositMA.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socketBridgeAndDepositMA.d.ts","sourceRoot":"/","sources":["services/margin-accounts-v2/deposit/socket/socketBridgeAndDepositMA.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"socketBridgeAndDepositMA.d.ts","sourceRoot":"/","sources":["services/margin-accounts-v2/deposit/socket/socketBridgeAndDepositMA.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,gCAAgC,EAChC,gCAAgC,EAEjC,MAAM,aAAa,CAAC;AAgCrB,eAAO,MAAM,0BAA0B,WAC7B,gCAAgC,KACvC,QAAQ,gCAAgC,CA4D1C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/margin-accounts-v2/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,iCAAiC,CAAC;AAChD,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/margin-accounts-v2/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,iCAAiC,CAAC;AAChD,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
|
|
@@ -33,8 +33,24 @@ export type SocketBridgeAndDepositMAParamsV2 = {
|
|
|
33
33
|
accountId: number;
|
|
34
34
|
amount: number;
|
|
35
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* Whether the pending row was registered with the API.
|
|
38
|
+
*
|
|
39
|
+
* Recording it is best-effort -- the deposit is already on-chain by then, so a
|
|
40
|
+
* failure never fails the deposit -- but the caller is the one with error
|
|
41
|
+
* reporting wired up, so the outcome is returned rather than swallowed. A
|
|
42
|
+
* `false` here means the deposit will not appear as pending until the bridge
|
|
43
|
+
* delivers and the indexer picks it up.
|
|
44
|
+
*/
|
|
45
|
+
export type PendingTransactionPersistence = {
|
|
46
|
+
status: true;
|
|
47
|
+
} | {
|
|
48
|
+
status: false;
|
|
49
|
+
reason: string;
|
|
50
|
+
};
|
|
36
51
|
export type SocketBridgeAndDepositMAResultV2 = {
|
|
37
52
|
transactionHash: string | null;
|
|
53
|
+
persistedPendingTransaction: PendingTransactionPersistence;
|
|
38
54
|
};
|
|
39
55
|
export type LzBridgeAndDepositMAParamsV2 = {
|
|
40
56
|
collateralAddress: Address;
|
|
@@ -97,6 +113,26 @@ export type Erc20ApproveParamsV2 = {
|
|
|
97
113
|
export type Erc20ApproveResultV2 = {
|
|
98
114
|
transactionHash: string | null;
|
|
99
115
|
};
|
|
116
|
+
export type WrapEthParamsV2 = {
|
|
117
|
+
signer: Signer | JsonRpcSigner;
|
|
118
|
+
collateralAddress: Address;
|
|
119
|
+
collateralDecimals: number;
|
|
120
|
+
chainId: number;
|
|
121
|
+
amount: number;
|
|
122
|
+
};
|
|
123
|
+
export type WrapEthResultV2 = {
|
|
124
|
+
transactionHash: string | null;
|
|
125
|
+
};
|
|
126
|
+
export type UnwrapEthParamsV2 = {
|
|
127
|
+
signer: Signer | JsonRpcSigner;
|
|
128
|
+
collateralAddress: Address;
|
|
129
|
+
collateralDecimals: number;
|
|
130
|
+
chainId: number;
|
|
131
|
+
amount: number;
|
|
132
|
+
};
|
|
133
|
+
export type UnwrapEthResultV2 = {
|
|
134
|
+
transactionHash: string | null;
|
|
135
|
+
};
|
|
100
136
|
export type Erc20GetAllowanceParamsV2 = {
|
|
101
137
|
signer: Signer | JsonRpcSigner;
|
|
102
138
|
collateralAddress: Address;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/margin-accounts-v2/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE3D,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,gCAAgC,EAAE,OAAO,CAAC;IAC1C,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,MA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EAAE,OAAO,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Interface } from 'ethers';
|
|
2
|
+
export declare const WETH9_INTERFACE: Interface;
|
|
3
|
+
export declare const WETH9_CHAIN_IDS: readonly number[];
|
|
4
|
+
export declare const isWrappableChain: (chainId: number) => boolean;
|
|
5
|
+
export declare const assertWrappableChain: (chainId: number) => void;
|
|
6
|
+
export declare const assertPositiveAmount: (amount: bigint, action: string) => void;
|
|
7
|
+
//# sourceMappingURL=consts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"/","sources":["services/margin-accounts-v2/weth/consts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGnC,eAAO,MAAM,eAAe,WAG1B,CAAC;AAOH,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAG5C,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAAa,MAAM,KAAG,OAChB,CAAC;AAEpC,eAAO,MAAM,oBAAoB,YAAa,MAAM,KAAG,IAMtD,CAAC;AAEF,eAAO,MAAM,oBAAoB,WAAY,MAAM,UAAU,MAAM,KAAG,IAIrE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/margin-accounts-v2/weth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unwrap.weth.d.ts","sourceRoot":"/","sources":["services/margin-accounts-v2/weth/unwrap.weth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAUhE,eAAO,MAAM,WAAW,WACd,iBAAiB,KACxB,QAAQ,iBAAiB,CAoB3B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap.weth.d.ts","sourceRoot":"/","sources":["services/margin-accounts-v2/weth/wrap.weth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAO5D,eAAO,MAAM,SAAS,WACZ,eAAe,KACtB,QAAQ,eAAe,CAoBzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.151.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@reyaxyz/api-v2-sdk": "0.308.0",
|
|
35
|
-
"@reyaxyz/common": "0.
|
|
35
|
+
"@reyaxyz/common": "0.360.0",
|
|
36
36
|
"axios": "1.6.2",
|
|
37
37
|
"bignumber.js": "9.1.2",
|
|
38
38
|
"ethers": "6.9.0"
|
|
39
39
|
},
|
|
40
40
|
"packageManager": "pnpm@8.3.1",
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "dadf97097450e2424736c3657bf05cee4f2b3921"
|
|
42
42
|
}
|
|
@@ -51,6 +51,14 @@ export const lzBridgeAndDepositMAV2 = async (
|
|
|
51
51
|
params.collateralAddress,
|
|
52
52
|
);
|
|
53
53
|
|
|
54
|
+
// No pending row is recorded here on purpose. LayerZero carries only REYA
|
|
55
|
+
// deposits, and nothing resolves a LayerZero message's status, so a pending
|
|
56
|
+
// row would never leave `pending`.
|
|
57
|
+
//
|
|
58
|
+
// The consequence is that LayerZero deposits do not appear on
|
|
59
|
+
// /v2/wallet/{address}/deposits at all -- that channel is fed solely by this
|
|
60
|
+
// table. Supporting them means teaching resolveBridgeTransactionStatus to
|
|
61
|
+
// query the LayerZero Scan API, and recording a row here once it can.
|
|
54
62
|
return {
|
|
55
63
|
transactionHash: result?.hash || null,
|
|
56
64
|
};
|
|
@@ -4,13 +4,19 @@ import {
|
|
|
4
4
|
Socket_VaultWithPayloadAbi as VaultAbi,
|
|
5
5
|
executeTransaction,
|
|
6
6
|
scaleV2,
|
|
7
|
+
getReyaNetworkFromMoneyInOutChainId,
|
|
8
|
+
getTokenInfoByAddress,
|
|
9
|
+
getTokenInfoByName,
|
|
10
|
+
MoneyInOutChainId,
|
|
7
11
|
} from '@reyaxyz/common';
|
|
8
12
|
import {
|
|
9
13
|
SocketBridgeAndDepositMAParamsV2,
|
|
10
14
|
SocketBridgeAndDepositMAResultV2,
|
|
15
|
+
PendingTransactionPersistence,
|
|
11
16
|
} from '../../types';
|
|
12
17
|
import { getPeripheryAddress } from '../../../../utils/network';
|
|
13
18
|
import { checkChainId } from '../../../../utils/checkChainId';
|
|
19
|
+
import { getTransactionModuleClient } from '../../../../config';
|
|
14
20
|
|
|
15
21
|
const getCalldata = (params: SocketBridgeAndDepositMAParamsV2): string => {
|
|
16
22
|
const amount = scaleV2(params.collateralDecimals)(params.amount);
|
|
@@ -53,7 +59,52 @@ export const socketBridgeAndDepositMAV2 = async (
|
|
|
53
59
|
params.vaultAddress,
|
|
54
60
|
);
|
|
55
61
|
|
|
62
|
+
let persistedPendingTransaction: PendingTransactionPersistence = {
|
|
63
|
+
status: false,
|
|
64
|
+
reason: 'Deposit transaction was not broadcast',
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
if (result?.hash) {
|
|
68
|
+
// Record the deposit as pending so it can be surfaced while the bridge
|
|
69
|
+
// delivers. Best-effort: the deposit is already on-chain by now, so a
|
|
70
|
+
// failure here must never surface to the caller as a throw -- it is
|
|
71
|
+
// returned instead, for the caller to report.
|
|
72
|
+
try {
|
|
73
|
+
const reyaChainId = getReyaNetworkFromMoneyInOutChainId(
|
|
74
|
+
params.chainId as MoneyInOutChainId,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// `asset_id` is a foreign key onto the Reya-side Asset row, which is the
|
|
78
|
+
// *core* token -- rUSD-underlying collateral (e.g. USDC) lands in the
|
|
79
|
+
// margin account as RUSD. Mirrors the v1 bridgeAndDepositExistingMA path.
|
|
80
|
+
const peripheryTokenInfo = getTokenInfoByAddress(
|
|
81
|
+
params.collateralAddressInReyaPeriphery,
|
|
82
|
+
reyaChainId,
|
|
83
|
+
);
|
|
84
|
+
const coreTokenInfo = peripheryTokenInfo.isRUSDUnderlying
|
|
85
|
+
? getTokenInfoByName('RUSD', reyaChainId)
|
|
86
|
+
: peripheryTokenInfo;
|
|
87
|
+
|
|
88
|
+
await getTransactionModuleClient().pushPendingTransaction(
|
|
89
|
+
params.accountId,
|
|
90
|
+
result.hash,
|
|
91
|
+
params.chainId,
|
|
92
|
+
params.amount,
|
|
93
|
+
coreTokenInfo.address,
|
|
94
|
+
'deposit',
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
persistedPendingTransaction = { status: true };
|
|
98
|
+
} catch (error) {
|
|
99
|
+
persistedPendingTransaction = {
|
|
100
|
+
status: false,
|
|
101
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
56
106
|
return {
|
|
57
107
|
transactionHash: result?.hash || null,
|
|
108
|
+
persistedPendingTransaction,
|
|
58
109
|
};
|
|
59
110
|
};
|
|
@@ -39,8 +39,22 @@ export type SocketBridgeAndDepositMAParamsV2 = {
|
|
|
39
39
|
amount: number;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Whether the pending row was registered with the API.
|
|
44
|
+
*
|
|
45
|
+
* Recording it is best-effort -- the deposit is already on-chain by then, so a
|
|
46
|
+
* failure never fails the deposit -- but the caller is the one with error
|
|
47
|
+
* reporting wired up, so the outcome is returned rather than swallowed. A
|
|
48
|
+
* `false` here means the deposit will not appear as pending until the bridge
|
|
49
|
+
* delivers and the indexer picks it up.
|
|
50
|
+
*/
|
|
51
|
+
export type PendingTransactionPersistence =
|
|
52
|
+
| { status: true }
|
|
53
|
+
| { status: false; reason: string };
|
|
54
|
+
|
|
42
55
|
export type SocketBridgeAndDepositMAResultV2 = {
|
|
43
56
|
transactionHash: string | null;
|
|
57
|
+
persistedPendingTransaction: PendingTransactionPersistence;
|
|
44
58
|
};
|
|
45
59
|
|
|
46
60
|
export type LzBridgeAndDepositMAParamsV2 = {
|
|
@@ -125,6 +139,30 @@ export type Erc20ApproveResultV2 = {
|
|
|
125
139
|
transactionHash: string | null;
|
|
126
140
|
};
|
|
127
141
|
|
|
142
|
+
export type WrapEthParamsV2 = {
|
|
143
|
+
signer: Signer | JsonRpcSigner;
|
|
144
|
+
collateralAddress: Address;
|
|
145
|
+
collateralDecimals: number;
|
|
146
|
+
chainId: number;
|
|
147
|
+
amount: number;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export type WrapEthResultV2 = {
|
|
151
|
+
transactionHash: string | null;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export type UnwrapEthParamsV2 = {
|
|
155
|
+
signer: Signer | JsonRpcSigner;
|
|
156
|
+
collateralAddress: Address;
|
|
157
|
+
collateralDecimals: number;
|
|
158
|
+
chainId: number;
|
|
159
|
+
amount: number;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export type UnwrapEthResultV2 = {
|
|
163
|
+
transactionHash: string | null;
|
|
164
|
+
};
|
|
165
|
+
|
|
128
166
|
export type Erc20GetAllowanceParamsV2 = {
|
|
129
167
|
signer: Signer | JsonRpcSigner;
|
|
130
168
|
collateralAddress: Address;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Interface } from 'ethers';
|
|
2
|
+
import { MoneyInOutChainId } from '@reyaxyz/common';
|
|
3
|
+
|
|
4
|
+
export const WETH9_INTERFACE = new Interface([
|
|
5
|
+
'function deposit() external payable',
|
|
6
|
+
'function withdraw(uint256 wad) external',
|
|
7
|
+
]);
|
|
8
|
+
|
|
9
|
+
// Only chains whose `WETH` is a genuine WETH9. Most are not — Polygon's is a
|
|
10
|
+
// bridged UChildERC20, the Sepolia entries are test ERC20s, and the Reya chains'
|
|
11
|
+
// is the Socket-bridged representation — and wrapping is payable, so calling one
|
|
12
|
+
// of those sends native ETH somewhere unrecoverable. Verify `deposit()` on-chain
|
|
13
|
+
// before adding a chain here.
|
|
14
|
+
export const WETH9_CHAIN_IDS: readonly number[] = [
|
|
15
|
+
MoneyInOutChainId.ethereumMainnet,
|
|
16
|
+
MoneyInOutChainId.arbitrumOne,
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
export const isWrappableChain = (chainId: number): boolean =>
|
|
20
|
+
WETH9_CHAIN_IDS.includes(chainId);
|
|
21
|
+
|
|
22
|
+
export const assertWrappableChain = (chainId: number): void => {
|
|
23
|
+
if (!isWrappableChain(chainId)) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`ETH wrap/unwrap is not supported on chain ${chainId} — its WETH is not a WETH9 contract`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const assertPositiveAmount = (amount: bigint, action: string): void => {
|
|
31
|
+
if (amount <= BigInt(0)) {
|
|
32
|
+
throw new Error(`Cannot ${action} a zero or negative amount`);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { executeTransaction, scaleV2 } from '@reyaxyz/common';
|
|
2
|
+
import { checkChainId } from '../../../utils/checkChainId';
|
|
3
|
+
import { UnwrapEthParamsV2, UnwrapEthResultV2 } from '../types';
|
|
4
|
+
import {
|
|
5
|
+
assertPositiveAmount,
|
|
6
|
+
assertWrappableChain,
|
|
7
|
+
WETH9_INTERFACE,
|
|
8
|
+
} from './consts';
|
|
9
|
+
|
|
10
|
+
// `amount` is a JS number, which at 18 decimals cannot address individual wei,
|
|
11
|
+
// so unwrapping a full balance must round down — a balance read back as a number
|
|
12
|
+
// can scale to marginally more than is held, which reverts.
|
|
13
|
+
export const unwrapEthV2 = async (
|
|
14
|
+
params: UnwrapEthParamsV2,
|
|
15
|
+
): Promise<UnwrapEthResultV2> => {
|
|
16
|
+
assertWrappableChain(params.chainId);
|
|
17
|
+
await checkChainId(params.signer, params.chainId);
|
|
18
|
+
|
|
19
|
+
const amount = scaleV2(params.collateralDecimals)(params.amount);
|
|
20
|
+
assertPositiveAmount(amount, 'unwrap');
|
|
21
|
+
|
|
22
|
+
const calldata = WETH9_INTERFACE.encodeFunctionData('withdraw', [amount]);
|
|
23
|
+
|
|
24
|
+
const result = await executeTransaction(
|
|
25
|
+
params.signer,
|
|
26
|
+
calldata,
|
|
27
|
+
'0',
|
|
28
|
+
params.chainId,
|
|
29
|
+
params.collateralAddress,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
transactionHash: result?.hash || null,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { executeTransaction, scaleV2 } from '@reyaxyz/common';
|
|
2
|
+
import { checkChainId } from '../../../utils/checkChainId';
|
|
3
|
+
import { WrapEthParamsV2, WrapEthResultV2 } from '../types';
|
|
4
|
+
import {
|
|
5
|
+
assertPositiveAmount,
|
|
6
|
+
assertWrappableChain,
|
|
7
|
+
WETH9_INTERFACE,
|
|
8
|
+
} from './consts';
|
|
9
|
+
|
|
10
|
+
export const wrapEthV2 = async (
|
|
11
|
+
params: WrapEthParamsV2,
|
|
12
|
+
): Promise<WrapEthResultV2> => {
|
|
13
|
+
assertWrappableChain(params.chainId);
|
|
14
|
+
await checkChainId(params.signer, params.chainId);
|
|
15
|
+
|
|
16
|
+
const amount = scaleV2(params.collateralDecimals)(params.amount);
|
|
17
|
+
assertPositiveAmount(amount, 'wrap');
|
|
18
|
+
|
|
19
|
+
const calldata = WETH9_INTERFACE.encodeFunctionData('deposit', []);
|
|
20
|
+
|
|
21
|
+
const result = await executeTransaction(
|
|
22
|
+
params.signer,
|
|
23
|
+
calldata,
|
|
24
|
+
amount.toString(),
|
|
25
|
+
params.chainId,
|
|
26
|
+
params.collateralAddress,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
transactionHash: result?.hash || null,
|
|
31
|
+
};
|
|
32
|
+
};
|