@reyaxyz/sdk 0.150.0 → 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/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/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 +20 -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 +2 -2
- package/src/services/margin-accounts-v2/index.ts +1 -0
- package/src/services/margin-accounts-v2/types.ts +24 -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
|
|
|
@@ -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\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 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":"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"}
|
|
@@ -113,6 +113,26 @@ export type Erc20ApproveParamsV2 = {
|
|
|
113
113
|
export type Erc20ApproveResultV2 = {
|
|
114
114
|
transactionHash: string | null;
|
|
115
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
|
+
};
|
|
116
136
|
export type Erc20GetAllowanceParamsV2 = {
|
|
117
137
|
signer: Signer | JsonRpcSigner;
|
|
118
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,MA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AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,iBAAiB,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"
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"ethers": "6.9.0"
|
|
39
39
|
},
|
|
40
40
|
"packageManager": "pnpm@8.3.1",
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "dadf97097450e2424736c3657bf05cee4f2b3921"
|
|
42
42
|
}
|
|
@@ -139,6 +139,30 @@ export type Erc20ApproveResultV2 = {
|
|
|
139
139
|
transactionHash: string | null;
|
|
140
140
|
};
|
|
141
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
|
+
|
|
142
166
|
export type Erc20GetAllowanceParamsV2 = {
|
|
143
167
|
signer: Signer | JsonRpcSigner;
|
|
144
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
|
+
};
|