@reyaxyz/sdk 0.8.1 → 0.9.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/dist/services/lp/encode.js.map +1 -1
- package/dist/services/lp/lp.js +2 -2
- package/dist/services/lp/lp.js.map +1 -1
- package/dist/services/margin-accounts/deposit.js +2 -2
- package/dist/services/margin-accounts/deposit.js.map +1 -1
- package/dist/services/margin-accounts/index.js +2 -0
- package/dist/services/margin-accounts/index.js.map +1 -1
- package/dist/services/margin-accounts/simulateDeposit.js +68 -0
- package/dist/services/margin-accounts/simulateDeposit.js.map +1 -0
- package/dist/services/margin-accounts/simulateWithdraw.js +68 -0
- package/dist/services/margin-accounts/simulateWithdraw.js.map +1 -0
- package/dist/services/margin-accounts/types.js.map +1 -1
- package/dist/services/margin-accounts/withdraw.js +2 -2
- package/dist/services/margin-accounts/withdraw.js.map +1 -1
- package/dist/types/services/lp/encode.d.ts +2 -2
- package/dist/types/services/margin-accounts/index.d.ts +2 -0
- package/dist/types/services/margin-accounts/index.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/simulateDeposit.d.ts +3 -0
- package/dist/types/services/margin-accounts/simulateDeposit.d.ts.map +1 -0
- package/dist/types/services/margin-accounts/simulateWithdraw.d.ts +3 -0
- package/dist/types/services/margin-accounts/simulateWithdraw.d.ts.map +1 -0
- package/dist/types/services/margin-accounts/types.d.ts +24 -2
- package/dist/types/services/margin-accounts/types.d.ts.map +1 -1
- package/dist/types/utils/lp.d.ts +1 -1
- package/dist/types/utils/lp.d.ts.map +1 -1
- package/dist/utils/lp.js +5 -4
- package/dist/utils/lp.js.map +1 -1
- package/package.json +2 -2
- package/src/services/lp/encode.ts +2 -2
- package/src/services/lp/lp.ts +2 -2
- package/src/services/margin-accounts/deposit.ts +2 -2
- package/src/services/margin-accounts/index.ts +2 -0
- package/src/services/margin-accounts/simulateDeposit.ts +30 -0
- package/src/services/margin-accounts/simulateWithdraw.ts +30 -0
- package/src/services/margin-accounts/types.ts +30 -2
- package/src/services/margin-accounts/withdraw.ts +2 -2
- package/src/utils/lp.ts +5 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.js","sourceRoot":"/","sources":["services/lp/encode.ts"],"names":[],"mappings":";;;AACA,iCAAmC;AAEnC,mBAAmB;AACnB,IAAM,mBAAmB,GAAG;IAC1B,2GAA2G;CAC5G,CAAC;AAEF,mBAAmB;AACnB,IAAM,kBAAkB,GAAG;IACzB,kGAAkG;CACnG,CAAC;AACK,IAAM,0BAA0B,GAAG,UACxC,MAAc,EACd,YAAoB,EACpB,MAAc,EACd,SAAiB;IAEjB,IAAM,iBAAiB,GAAG,cAAc,CAAC;IACzC,IAAM,UAAU,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAC7D,IAAM,SAAS,GAAG,IAAI,kBAAS,CAAC,mBAAmB,CAAC,CAAC;IACrD,IAAM,QAAQ,GAAG,SAAS,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;IAC7E,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AAC/D,CAAC,CAAC;AAXW,QAAA,0BAA0B,8BAWrC;AAEK,IAAM,yBAAyB,GAAG,UACvC,MAAc,EACd,YAAoB,EACpB,MAAc;IAEd,IAAM,iBAAiB,GAAG,iBAAiB,CAAC;IAC5C,IAAM,UAAU,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IAClD,IAAM,SAAS,GAAG,IAAI,kBAAS,CAAC,kBAAkB,CAAC,CAAC;IACpD,IAAM,QAAQ,GAAG,SAAS,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;IAC7E,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AAC/D,CAAC,CAAC;AAVW,QAAA,yBAAyB,6BAUpC","sourcesContent":["import { MethodParameters } from '../../utils/action';\nimport { Interface } from 'ethers';\n\n// @todo Update ABI\nconst provideLiquidityAbi = [\n 'function addLiquidity(uint128 poolId, address owner, uint256 amount, uint256 minShares) returns (uint256)',\n];\n\n// @todo Update ABI\nconst removeLiquidityabi = [\n 'function removeLiquidity(uint128 poolId, uint256 sharesAmount, uint256 minOut) returns (uint256)',\n];\nexport const encodeProvideLiquidityCall = (\n poolId: number,\n accountOwner: string,\n amount:
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"/","sources":["services/lp/encode.ts"],"names":[],"mappings":";;;AACA,iCAAmC;AAEnC,mBAAmB;AACnB,IAAM,mBAAmB,GAAG;IAC1B,2GAA2G;CAC5G,CAAC;AAEF,mBAAmB;AACnB,IAAM,kBAAkB,GAAG;IACzB,kGAAkG;CACnG,CAAC;AACK,IAAM,0BAA0B,GAAG,UACxC,MAAc,EACd,YAAoB,EACpB,MAAc,EACd,SAAiB;IAEjB,IAAM,iBAAiB,GAAG,cAAc,CAAC;IACzC,IAAM,UAAU,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAC7D,IAAM,SAAS,GAAG,IAAI,kBAAS,CAAC,mBAAmB,CAAC,CAAC;IACrD,IAAM,QAAQ,GAAG,SAAS,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;IAC7E,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AAC/D,CAAC,CAAC;AAXW,QAAA,0BAA0B,8BAWrC;AAEK,IAAM,yBAAyB,GAAG,UACvC,MAAc,EACd,YAAoB,EACpB,MAAc;IAEd,IAAM,iBAAiB,GAAG,iBAAiB,CAAC;IAC5C,IAAM,UAAU,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IAClD,IAAM,SAAS,GAAG,IAAI,kBAAS,CAAC,kBAAkB,CAAC,CAAC;IACpD,IAAM,QAAQ,GAAG,SAAS,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;IAC7E,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AAC/D,CAAC,CAAC;AAVW,QAAA,yBAAyB,6BAUpC","sourcesContent":["import { MethodParameters } from '../../utils/action';\nimport { Interface } from 'ethers';\n\n// @todo Update ABI\nconst provideLiquidityAbi = [\n 'function addLiquidity(uint128 poolId, address owner, uint256 amount, uint256 minShares) returns (uint256)',\n];\n\n// @todo Update ABI\nconst removeLiquidityabi = [\n 'function removeLiquidity(uint128 poolId, uint256 sharesAmount, uint256 minOut) returns (uint256)',\n];\nexport const encodeProvideLiquidityCall = (\n poolId: number,\n accountOwner: string,\n amount: bigint,\n minShares: number,\n): MethodParameters => {\n const functionSignature = 'addLiquidity';\n const parameters = [poolId, accountOwner, amount, minShares];\n const INTERFACE = new Interface(provideLiquidityAbi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return { calldata: calldata, value: BigInt(0).toString(10) };\n};\n\nexport const encodeRemoveLiquidityCall = (\n poolId: number,\n sharesAmount: bigint,\n minOut: number,\n): MethodParameters => {\n const functionSignature = 'removeLiquidity';\n const parameters = [poolId, sharesAmount, minOut];\n const INTERFACE = new Interface(removeLiquidityabi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return { calldata: calldata, value: BigInt(0).toString(10) };\n};\n"]}
|
package/dist/services/lp/lp.js
CHANGED
|
@@ -57,7 +57,7 @@ var provideLiquidity = function (params) { return __awaiter(void 0, void 0, void
|
|
|
57
57
|
if (params.amount === 0) {
|
|
58
58
|
throw new Error('LP amount can not be 0');
|
|
59
59
|
}
|
|
60
|
-
amount = (0, lp_1.expandLpAmount)(params.amount);
|
|
60
|
+
amount = (0, lp_1.expandLpAmount)(params.amount, 6);
|
|
61
61
|
_a = (0, encode_1.encodeProvideLiquidityCall)(params.poolId, ownerAddrees, amount, minShares), data = _a.calldata, value = _a.value;
|
|
62
62
|
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, chainId, consts_1.TransactionType.LP)];
|
|
63
63
|
case 3:
|
|
@@ -82,7 +82,7 @@ var removeLiquidity = function (params) { return __awaiter(void 0, void 0, void
|
|
|
82
82
|
throw new Error('Shares amount can not be 0');
|
|
83
83
|
}
|
|
84
84
|
minOut = (0, lp_1.calculateMinOutForLp)(params.sharesAmount);
|
|
85
|
-
amount = (0, lp_1.expandLpAmount)(params.sharesAmount);
|
|
85
|
+
amount = (0, lp_1.expandLpAmount)(params.sharesAmount, 30);
|
|
86
86
|
_a = (0, encode_1.encodeRemoveLiquidityCall)(params.poolId, amount, minOut), data = _a.calldata, value = _a.value;
|
|
87
87
|
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, chainId, consts_1.TransactionType.LP)];
|
|
88
88
|
case 2:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lp.js","sourceRoot":"/","sources":["services/lp/lp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA2D;AAC3D,mCAGkB;AAOlB,6CAAqD;AACrD,qCAIwB;AAEjB,IAAM,gBAAgB,GAAG,UAC9B,MAA8B;;;;;oBAET,qBAAM,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAA;;gBAA/C,YAAY,GAAG,SAAgC;gBAErC,qBAAM,CAAA,MAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,0CAAE,UAAU,EAAE,CAAA,EAAA;;gBAApD,OAAO,GAAG,SAA0C;gBACpD,OAAO,GAAG,MAAM,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;gBACnC,SAAS,GAAG,IAAA,4BAAuB,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAEzD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBACxB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;gBAC5C,CAAC;gBAEK,MAAM,GAAG,IAAA,mBAAc,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"lp.js","sourceRoot":"/","sources":["services/lp/lp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA2D;AAC3D,mCAGkB;AAOlB,6CAAqD;AACrD,qCAIwB;AAEjB,IAAM,gBAAgB,GAAG,UAC9B,MAA8B;;;;;oBAET,qBAAM,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAA;;gBAA/C,YAAY,GAAG,SAAgC;gBAErC,qBAAM,CAAA,MAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,0CAAE,UAAU,EAAE,CAAA,EAAA;;gBAApD,OAAO,GAAG,SAA0C;gBACpD,OAAO,GAAG,MAAM,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;gBACnC,SAAS,GAAG,IAAA,4BAAuB,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAEzD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBACxB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;gBAC5C,CAAC;gBAEK,MAAM,GAAG,IAAA,mBAAc,EAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;gBAE1C,KAA4B,IAAA,mCAA0B,EAC1D,MAAM,CAAC,MAAM,EACb,YAAY,EACZ,MAAM,EACN,SAAS,CACV,EALiB,IAAI,cAAA,EAAE,KAAK,WAAA,CAK3B;gBAEa,qBAAM,IAAA,uCAAkB,EACrC,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,OAAO,EACP,wBAAe,CAAC,EAAE,CACnB,EAAA;;gBANK,MAAM,GAAG,SAMd;gBAED,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,KAAI,IAAI;qBACtC,EAAC;;;KACH,CAAC;AAjCW,QAAA,gBAAgB,oBAiC3B;AAEK,IAAM,eAAe,GAAG,UAC7B,MAA6B;;;;;oBAEb,qBAAM,CAAA,MAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,0CAAE,UAAU,EAAE,CAAA,EAAA;;gBAApD,OAAO,GAAG,SAA0C;gBACpD,OAAO,GAAG,MAAM,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;gBAEzC,IAAI,MAAM,CAAC,YAAY,KAAK,CAAC,EAAE,CAAC;oBAC9B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;gBAChD,CAAC;gBAEK,MAAM,GAAG,IAAA,yBAAoB,EAAC,MAAM,CAAC,YAAY,CAAC,CAAC;gBAEnD,MAAM,GAAG,IAAA,mBAAc,EAAC,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;gBACjD,KAA4B,IAAA,kCAAyB,EACzD,MAAM,CAAC,MAAM,EACb,MAAM,EACN,MAAM,CACP,EAJiB,IAAI,cAAA,EAAE,KAAK,WAAA,CAI3B;gBAEa,qBAAM,IAAA,uCAAkB,EACrC,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,OAAO,EACP,wBAAe,CAAC,EAAE,CACnB,EAAA;;gBANK,MAAM,GAAG,SAMd;gBAED,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,KAAI,IAAI;qBACtC,EAAC;;;KACH,CAAC;AA9BW,QAAA,eAAe,mBA8B1B","sourcesContent":["import { executeTransaction } from '../executeTransaction';\nimport {\n encodeProvideLiquidityCall,\n encodeRemoveLiquidityCall,\n} from './encode';\nimport {\n ProvideLiquidityParams,\n ProvideLiquidityResult,\n RemoveLiquidityParams,\n RemoveLiquidityResult,\n} from './types';\nimport { TransactionType } from '../../utils/consts';\nimport {\n calculateMinOutForLp,\n calculateMinSharesForLp,\n expandLpAmount,\n} from '../../utils/lp';\n\nexport const provideLiquidity = async (\n params: ProvideLiquidityParams,\n): Promise<ProvideLiquidityResult> => {\n const ownerAddrees = await params.signer.getAddress();\n\n const network = await params.signer.provider?.getNetwork();\n const chainId = Number(network?.chainId);\n const minShares = calculateMinSharesForLp(params.amount);\n\n if (params.amount === 0) {\n throw new Error('LP amount can not be 0');\n }\n\n const amount = expandLpAmount(params.amount, 6);\n\n const { calldata: data, value } = encodeProvideLiquidityCall(\n params.poolId,\n ownerAddrees,\n amount,\n minShares,\n );\n\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n chainId,\n TransactionType.LP,\n );\n\n return {\n transactionHash: result?.hash || null,\n };\n};\n\nexport const removeLiquidity = async (\n params: RemoveLiquidityParams,\n): Promise<RemoveLiquidityResult> => {\n const network = await params.signer.provider?.getNetwork();\n const chainId = Number(network?.chainId);\n\n if (params.sharesAmount === 0) {\n throw new Error('Shares amount can not be 0');\n }\n\n const minOut = calculateMinOutForLp(params.sharesAmount);\n\n const amount = expandLpAmount(params.sharesAmount, 30); // shares have 30 decimals\n const { calldata: data, value } = encodeRemoveLiquidityCall(\n params.poolId,\n amount,\n minOut,\n );\n\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n chainId,\n TransactionType.LP,\n );\n\n return {\n transactionHash: result?.hash || null,\n };\n};\n"]}
|
|
@@ -47,11 +47,11 @@ var deposit = function (params) { return __awaiter(void 0, void 0, void 0, funct
|
|
|
47
47
|
return __generator(this, function (_c) {
|
|
48
48
|
switch (_c.label) {
|
|
49
49
|
case 0:
|
|
50
|
-
tokenDecimals = (0, common_1.getTokenDetails)(params.
|
|
50
|
+
tokenDecimals = (0, common_1.getTokenDetails)(params.tokenAddress).tokenDecimals;
|
|
51
51
|
amount = (0, common_1.scale)(tokenDecimals)(params.amount);
|
|
52
52
|
marketId = 0;
|
|
53
53
|
exchangeId = 0;
|
|
54
|
-
_a = (0, encode_1.encodeDeposit)(params.accountId, params.
|
|
54
|
+
_a = (0, encode_1.encodeDeposit)(params.accountId, params.tokenAddress, amount, marketId, exchangeId), data = _a.calldata, value = _a.value;
|
|
55
55
|
return [4 /*yield*/, ((_b = params.signer.provider) === null || _b === void 0 ? void 0 : _b.getNetwork())];
|
|
56
56
|
case 1:
|
|
57
57
|
network = _c.sent();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deposit.js","sourceRoot":"/","sources":["services/margin-accounts/deposit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAAyC;AACzC,4DAA2D;AAC3D,6CAAqD;AACrD,0CAAyD;AAElD,IAAM,OAAO,GAAG,UACrB,MAAqB;;;;;;gBAEb,aAAa,GAAK,IAAA,wBAAe,EAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"deposit.js","sourceRoot":"/","sources":["services/margin-accounts/deposit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAAyC;AACzC,4DAA2D;AAC3D,6CAAqD;AACrD,0CAAyD;AAElD,IAAM,OAAO,GAAG,UACrB,MAAqB;;;;;;gBAEb,aAAa,GAAK,IAAA,wBAAe,EAAC,MAAM,CAAC,YAAY,CAAC,cAAzC,CAA0C;gBACzD,MAAM,GAAG,IAAA,cAAK,EAAC,aAAa,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC7C,QAAQ,GAAG,CAAC,CAAC;gBACb,UAAU,GAAG,CAAC,CAAC;gBACf,KAA4B,IAAA,sBAAa,EAC7C,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,YAAY,EACnB,MAAM,EACN,QAAQ,EACR,UAAU,CACX,EANiB,IAAI,cAAA,EAAE,KAAK,WAAA,CAM3B;gBAEc,qBAAM,CAAA,MAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,0CAAE,UAAU,EAAE,CAAA,EAAA;;gBAApD,OAAO,GAAG,SAA0C;gBACpD,OAAO,GAAG,MAAM,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;gBAE1B,qBAAM,IAAA,uCAAkB,EACrC,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,OAAO,EACP,wBAAe,CAAC,OAAO,CACxB,EAAA;;gBANK,MAAM,GAAG,SAMd;gBAED,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,KAAI,IAAI;qBACtC,EAAC;;;KACH,CAAC;AA7BW,QAAA,OAAO,WA6BlB","sourcesContent":["import { DepositParams, DepositResult } from './types';\nimport { encodeDeposit } from './encode';\nimport { executeTransaction } from '../executeTransaction';\nimport { TransactionType } from '../../utils/consts';\nimport { getTokenDetails, scale } from '../token/common';\n\nexport const deposit = async (\n params: DepositParams,\n): Promise<DepositResult> => {\n const { tokenDecimals } = getTokenDetails(params.tokenAddress);\n const amount = scale(tokenDecimals)(params.amount);\n const marketId = 0;\n const exchangeId = 0;\n const { calldata: data, value } = encodeDeposit(\n params.accountId,\n params.tokenAddress,\n amount,\n marketId,\n exchangeId,\n );\n\n const network = await params.signer.provider?.getNetwork();\n const chainId = Number(network?.chainId);\n\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n chainId,\n TransactionType.DEPOSIT,\n );\n\n return {\n transactionHash: result?.hash || null,\n };\n};\n"]}
|
|
@@ -17,5 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./types"), exports);
|
|
18
18
|
__exportStar(require("./account"), exports);
|
|
19
19
|
__exportStar(require("./deposit"), exports);
|
|
20
|
+
__exportStar(require("./simulateDeposit"), exports);
|
|
21
|
+
__exportStar(require("./simulateWithdraw"), exports);
|
|
20
22
|
__exportStar(require("./withdraw"), exports);
|
|
21
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["services/margin-accounts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,4CAA0B;AAC1B,4CAA0B;AAC1B,6CAA2B","sourcesContent":["export * from './types';\nexport * from './account';\nexport * from './deposit';\nexport * from './withdraw';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["services/margin-accounts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,4CAA0B;AAC1B,4CAA0B;AAC1B,oDAAkC;AAClC,qDAAmC;AACnC,6CAA2B","sourcesContent":["export * from './types';\nexport * from './account';\nexport * from './deposit';\nexport * from './simulateDeposit';\nexport * from './simulateWithdraw';\nexport * from './withdraw';\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.simulateDeposit = void 0;
|
|
40
|
+
// The maximum is inclusive and the minimum is inclusive
|
|
41
|
+
function getRandomIntInclusive(min, max) {
|
|
42
|
+
min = Math.ceil(min);
|
|
43
|
+
max = Math.floor(max);
|
|
44
|
+
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
45
|
+
}
|
|
46
|
+
var randomSimulation = function () {
|
|
47
|
+
return {
|
|
48
|
+
bridgeGasFees: getRandomIntInclusive(1000, 100000),
|
|
49
|
+
marginRatio: getRandomIntInclusive(1, 100),
|
|
50
|
+
marginRatioHealth: 'danger',
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
var simulateDeposit = function (
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
55
|
+
params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
56
|
+
return __generator(this, function (_a) {
|
|
57
|
+
switch (_a.label) {
|
|
58
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve) {
|
|
59
|
+
setTimeout(function () {
|
|
60
|
+
resolve(randomSimulation());
|
|
61
|
+
}, Math.random() * 100 + 1000);
|
|
62
|
+
})];
|
|
63
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}); };
|
|
67
|
+
exports.simulateDeposit = simulateDeposit;
|
|
68
|
+
//# sourceMappingURL=simulateDeposit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulateDeposit.js","sourceRoot":"/","sources":["services/margin-accounts/simulateDeposit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,wDAAwD;AACxD,SAAS,qBAAqB,CAAC,GAAW,EAAE,GAAW;IACrD,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrB,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;AAC3D,CAAC;AAED,IAAM,gBAAgB,GAAG;IACvB,OAAO;QACL,aAAa,EAAE,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC;QAClD,WAAW,EAAE,qBAAqB,CAAC,CAAC,EAAE,GAAG,CAAC;QAC1C,iBAAiB,EAAE,QAAQ;KAC5B,CAAC;AACJ,CAAC,CAAC;AAEK,IAAM,eAAe,GAAG;AAC7B,6DAA6D;AAC7D,MAA6B;;;oBAEtB,qBAAM,IAAI,OAAO,CAAC,UAAC,OAAO;oBAC/B,UAAU,CACR;wBACE,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;oBAC9B,CAAC,EACD,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,IAAI,CAC3B,CAAC;gBACJ,CAAC,CAAC,EAAA;oBAPF,sBAAO,SAOL,EAAC;;;KACJ,CAAC;AAZW,QAAA,eAAe,mBAY1B","sourcesContent":["import { SimulateDepositParams, SimulateDepositResult } from './types';\n\n// The maximum is inclusive and the minimum is inclusive\nfunction getRandomIntInclusive(min: number, max: number) {\n min = Math.ceil(min);\n max = Math.floor(max);\n return Math.floor(Math.random() * (max - min + 1) + min);\n}\n\nconst randomSimulation = (): SimulateDepositResult => {\n return {\n bridgeGasFees: getRandomIntInclusive(1000, 100000),\n marginRatio: getRandomIntInclusive(1, 100),\n marginRatioHealth: 'danger',\n };\n};\n\nexport const simulateDeposit = async (\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n params: SimulateDepositParams,\n): Promise<SimulateDepositResult> => {\n return await new Promise((resolve) => {\n setTimeout(\n () => {\n resolve(randomSimulation());\n },\n Math.random() * 100 + 1000,\n );\n });\n};\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.simulateWithdraw = void 0;
|
|
40
|
+
// The maximum is inclusive and the minimum is inclusive
|
|
41
|
+
function getRandomIntInclusive(min, max) {
|
|
42
|
+
min = Math.ceil(min);
|
|
43
|
+
max = Math.floor(max);
|
|
44
|
+
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
45
|
+
}
|
|
46
|
+
var randomSimulation = function () {
|
|
47
|
+
return {
|
|
48
|
+
bridgeGasFees: getRandomIntInclusive(1000, 100000),
|
|
49
|
+
marginRatio: getRandomIntInclusive(1, 100),
|
|
50
|
+
marginRatioHealth: 'danger',
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
var simulateWithdraw = function (
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
55
|
+
params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
56
|
+
return __generator(this, function (_a) {
|
|
57
|
+
switch (_a.label) {
|
|
58
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve) {
|
|
59
|
+
setTimeout(function () {
|
|
60
|
+
resolve(randomSimulation());
|
|
61
|
+
}, Math.random() * 100 + 1000);
|
|
62
|
+
})];
|
|
63
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}); };
|
|
67
|
+
exports.simulateWithdraw = simulateWithdraw;
|
|
68
|
+
//# sourceMappingURL=simulateWithdraw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulateWithdraw.js","sourceRoot":"/","sources":["services/margin-accounts/simulateWithdraw.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,wDAAwD;AACxD,SAAS,qBAAqB,CAAC,GAAW,EAAE,GAAW;IACrD,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrB,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;AAC3D,CAAC;AAED,IAAM,gBAAgB,GAAG;IACvB,OAAO;QACL,aAAa,EAAE,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC;QAClD,WAAW,EAAE,qBAAqB,CAAC,CAAC,EAAE,GAAG,CAAC;QAC1C,iBAAiB,EAAE,QAAQ;KAC5B,CAAC;AACJ,CAAC,CAAC;AAEK,IAAM,gBAAgB,GAAG;AAC9B,6DAA6D;AAC7D,MAA8B;;;oBAEvB,qBAAM,IAAI,OAAO,CAAC,UAAC,OAAO;oBAC/B,UAAU,CACR;wBACE,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;oBAC9B,CAAC,EACD,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,IAAI,CAC3B,CAAC;gBACJ,CAAC,CAAC,EAAA;oBAPF,sBAAO,SAOL,EAAC;;;KACJ,CAAC;AAZW,QAAA,gBAAgB,oBAY3B","sourcesContent":["import { SimulateWithdrawParams, SimulateWithdrawResult } from './types';\n\n// The maximum is inclusive and the minimum is inclusive\nfunction getRandomIntInclusive(min: number, max: number) {\n min = Math.ceil(min);\n max = Math.floor(max);\n return Math.floor(Math.random() * (max - min + 1) + min);\n}\n\nconst randomSimulation = (): SimulateWithdrawResult => {\n return {\n bridgeGasFees: getRandomIntInclusive(1000, 100000),\n marginRatio: getRandomIntInclusive(1, 100),\n marginRatioHealth: 'danger',\n };\n};\n\nexport const simulateWithdraw = async (\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n params: SimulateWithdrawParams,\n): Promise<SimulateWithdrawResult> => {\n return await new Promise((resolve) => {\n setTimeout(\n () => {\n resolve(randomSimulation());\n },\n Math.random() * 100 + 1000,\n );\n });\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/margin-accounts/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\n\nexport type CreateAccountParams = {\n signer: Signer | JsonRpcSigner;\n ownerAddress: string;\n};\n\nexport type CreateAccountResult = {\n transactionHash: string | null;\n};\n\nexport type DepositParams = {\n signer: Signer | JsonRpcSigner;\n accountId: number;\n
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/margin-accounts/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\n\nexport type CreateAccountParams = {\n signer: Signer | JsonRpcSigner;\n ownerAddress: string;\n};\n\nexport type CreateAccountResult = {\n transactionHash: string | null;\n};\n\nexport type DepositParams = {\n signer: Signer | JsonRpcSigner;\n accountId: number;\n tokenAddress: string;\n amount: number;\n};\n\nexport type DepositResult = {\n transactionHash: string | null;\n};\n\nexport type WithdrawParams = {\n signer: Signer | JsonRpcSigner;\n accountId: number;\n tokenAddress: string;\n amount: number;\n};\n\nexport type WithdrawResult = {\n transactionHash: string | null;\n};\n\nexport type SimulateDepositResult = {\n bridgeGasFees: number;\n marginRatioHealth: 'danger' | 'healthy' | 'warning'; // MarginAccountEntity['marginRatioPercentage'];\n marginRatio: number; // MarginAccountEntity['marginRatioHealth'];\n};\n\n// TODO: Milan reevaluate these params\nexport type SimulateDepositParams = {\n signer: Signer | JsonRpcSigner;\n accountId: number;\n tokenAddress: string;\n amount: number;\n};\n\nexport type SimulateWithdrawResult = {\n bridgeGasFees: number;\n marginRatioHealth: 'danger' | 'healthy' | 'warning'; // MarginAccountEntity['marginRatioPercentage'];\n marginRatio: number; // MarginAccountEntity['marginRatioHealth'];\n};\n\n// TODO: Milan reevaluate these params\nexport type SimulateWithdrawParams = {\n signer: Signer | JsonRpcSigner;\n accountId: number;\n tokenAddress: string;\n amount: number;\n};\n"]}
|
|
@@ -47,11 +47,11 @@ var withdraw = function (params) { return __awaiter(void 0, void 0, void 0, func
|
|
|
47
47
|
return __generator(this, function (_c) {
|
|
48
48
|
switch (_c.label) {
|
|
49
49
|
case 0:
|
|
50
|
-
tokenDecimals = (0, common_1.getTokenDetails)(params.
|
|
50
|
+
tokenDecimals = (0, common_1.getTokenDetails)(params.tokenAddress).tokenDecimals;
|
|
51
51
|
amount = (0, common_1.scale)(tokenDecimals)(params.amount);
|
|
52
52
|
marketId = 0;
|
|
53
53
|
exchangeId = 0;
|
|
54
|
-
_a = (0, encode_1.encodeWithdraw)(params.accountId, params.
|
|
54
|
+
_a = (0, encode_1.encodeWithdraw)(params.accountId, params.tokenAddress, BigInt(amount), marketId, exchangeId), data = _a.calldata, value = _a.value;
|
|
55
55
|
return [4 /*yield*/, ((_b = params.signer.provider) === null || _b === void 0 ? void 0 : _b.getNetwork())];
|
|
56
56
|
case 1:
|
|
57
57
|
network = _c.sent();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdraw.js","sourceRoot":"/","sources":["services/margin-accounts/withdraw.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAA0C;AAC1C,4DAA2D;AAC3D,6CAAqD;AACrD,0CAAyD;AAElD,IAAM,QAAQ,GAAG,UACtB,MAAsB;;;;;;gBAEd,aAAa,GAAK,IAAA,wBAAe,EAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"withdraw.js","sourceRoot":"/","sources":["services/margin-accounts/withdraw.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAA0C;AAC1C,4DAA2D;AAC3D,6CAAqD;AACrD,0CAAyD;AAElD,IAAM,QAAQ,GAAG,UACtB,MAAsB;;;;;;gBAEd,aAAa,GAAK,IAAA,wBAAe,EAAC,MAAM,CAAC,YAAY,CAAC,cAAzC,CAA0C;gBACzD,MAAM,GAAG,IAAA,cAAK,EAAC,aAAa,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAE7C,QAAQ,GAAG,CAAC,CAAC;gBACb,UAAU,GAAG,CAAC,CAAC;gBACf,KAA4B,IAAA,uBAAc,EAC9C,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,YAAY,EACnB,MAAM,CAAC,MAAM,CAAC,EACd,QAAQ,EACR,UAAU,CACX,EANiB,IAAI,cAAA,EAAE,KAAK,WAAA,CAM3B;gBAEc,qBAAM,CAAA,MAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,0CAAE,UAAU,EAAE,CAAA,EAAA;;gBAApD,OAAO,GAAG,SAA0C;gBACpD,OAAO,GAAG,MAAM,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;gBAE1B,qBAAM,IAAA,uCAAkB,EACrC,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,OAAO,EACP,wBAAe,CAAC,QAAQ,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;AA9BW,QAAA,QAAQ,YA8BnB","sourcesContent":["import { WithdrawParams, WithdrawResult } from './types';\nimport { encodeWithdraw } from './encode';\nimport { executeTransaction } from '../executeTransaction';\nimport { TransactionType } from '../../utils/consts';\nimport { getTokenDetails, scale } from '../token/common';\n\nexport const withdraw = async (\n params: WithdrawParams,\n): Promise<WithdrawResult> => {\n const { tokenDecimals } = getTokenDetails(params.tokenAddress);\n const amount = scale(tokenDecimals)(params.amount);\n\n const marketId = 0;\n const exchangeId = 0;\n const { calldata: data, value } = encodeWithdraw(\n params.accountId,\n params.tokenAddress,\n BigInt(amount),\n marketId,\n exchangeId,\n );\n\n const network = await params.signer.provider?.getNetwork();\n const chainId = Number(network?.chainId);\n\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n chainId,\n TransactionType.WITHDRAW,\n );\n\n return {\n transactionHash: result?.hash || null,\n };\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { MethodParameters } from '../../utils/action';
|
|
2
|
-
export declare const encodeProvideLiquidityCall: (poolId: number, accountOwner: string, amount:
|
|
3
|
-
export declare const encodeRemoveLiquidityCall: (poolId: number, sharesAmount:
|
|
2
|
+
export declare const encodeProvideLiquidityCall: (poolId: number, accountOwner: string, amount: bigint, minShares: number) => MethodParameters;
|
|
3
|
+
export declare const encodeRemoveLiquidityCall: (poolId: number, sharesAmount: bigint, minOut: number) => MethodParameters;
|
|
4
4
|
//# sourceMappingURL=encode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/margin-accounts/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/margin-accounts/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulateDeposit.d.ts","sourceRoot":"/","sources":["services/margin-accounts/simulateDeposit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAiBvE,eAAO,MAAM,eAAe,WAElB,qBAAqB,KAC5B,QAAQ,qBAAqB,CAS/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulateWithdraw.d.ts","sourceRoot":"/","sources":["services/margin-accounts/simulateWithdraw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAiBzE,eAAO,MAAM,gBAAgB,WAEnB,sBAAsB,KAC7B,QAAQ,sBAAsB,CAShC,CAAC"}
|
|
@@ -9,7 +9,7 @@ export type CreateAccountResult = {
|
|
|
9
9
|
export type DepositParams = {
|
|
10
10
|
signer: Signer | JsonRpcSigner;
|
|
11
11
|
accountId: number;
|
|
12
|
-
|
|
12
|
+
tokenAddress: string;
|
|
13
13
|
amount: number;
|
|
14
14
|
};
|
|
15
15
|
export type DepositResult = {
|
|
@@ -18,10 +18,32 @@ export type DepositResult = {
|
|
|
18
18
|
export type WithdrawParams = {
|
|
19
19
|
signer: Signer | JsonRpcSigner;
|
|
20
20
|
accountId: number;
|
|
21
|
-
|
|
21
|
+
tokenAddress: string;
|
|
22
22
|
amount: number;
|
|
23
23
|
};
|
|
24
24
|
export type WithdrawResult = {
|
|
25
25
|
transactionHash: string | null;
|
|
26
26
|
};
|
|
27
|
+
export type SimulateDepositResult = {
|
|
28
|
+
bridgeGasFees: number;
|
|
29
|
+
marginRatioHealth: 'danger' | 'healthy' | 'warning';
|
|
30
|
+
marginRatio: number;
|
|
31
|
+
};
|
|
32
|
+
export type SimulateDepositParams = {
|
|
33
|
+
signer: Signer | JsonRpcSigner;
|
|
34
|
+
accountId: number;
|
|
35
|
+
tokenAddress: string;
|
|
36
|
+
amount: number;
|
|
37
|
+
};
|
|
38
|
+
export type SimulateWithdrawResult = {
|
|
39
|
+
bridgeGasFees: number;
|
|
40
|
+
marginRatioHealth: 'danger' | 'healthy' | 'warning';
|
|
41
|
+
marginRatio: number;
|
|
42
|
+
};
|
|
43
|
+
export type SimulateWithdrawParams = {
|
|
44
|
+
signer: Signer | JsonRpcSigner;
|
|
45
|
+
accountId: number;
|
|
46
|
+
tokenAddress: string;
|
|
47
|
+
amount: number;
|
|
48
|
+
};
|
|
27
49
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/margin-accounts/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE/C,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/margin-accounts/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE/C,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IACpD,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAGF,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IACpD,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAGF,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
|
package/dist/types/utils/lp.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function calculateMinSharesForLp(lpAmount: number): number;
|
|
2
2
|
export declare function calculateMinOutForLp(sharesAmount: number): number;
|
|
3
|
-
export declare function expandLpAmount(amount: number):
|
|
3
|
+
export declare function expandLpAmount(amount: number, decimals: number): bigint;
|
|
4
4
|
//# sourceMappingURL=lp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lp.d.ts","sourceRoot":"/","sources":["utils/lp.ts"],"names":[],"mappings":"AAEA,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOhE;AAED,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAOjE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"lp.d.ts","sourceRoot":"/","sources":["utils/lp.ts"],"names":[],"mappings":"AAEA,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOhE;AAED,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAOjE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOvE"}
|
package/dist/utils/lp.js
CHANGED
|
@@ -19,10 +19,11 @@ function calculateMinOutForLp(sharesAmount) {
|
|
|
19
19
|
return amount.minus(offset).times(1e6).toNumber(); // rUSD/USDC has 6 decimals, change if needed
|
|
20
20
|
}
|
|
21
21
|
exports.calculateMinOutForLp = calculateMinOutForLp;
|
|
22
|
-
function expandLpAmount(amount) {
|
|
23
|
-
var decimalFactor = (
|
|
24
|
-
var
|
|
25
|
-
|
|
22
|
+
function expandLpAmount(amount, decimals) {
|
|
23
|
+
var decimalFactor = BigInt(Math.pow(10, decimals));
|
|
24
|
+
var amountBigInt = BigInt(amount);
|
|
25
|
+
var amountDenormalised = amountBigInt * decimalFactor;
|
|
26
|
+
return amountDenormalised;
|
|
26
27
|
}
|
|
27
28
|
exports.expandLpAmount = expandLpAmount;
|
|
28
29
|
//# sourceMappingURL=lp.js.map
|
package/dist/utils/lp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lp.js","sourceRoot":"/","sources":["utils/lp.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqC;AAErC,SAAgB,uBAAuB,CAAC,QAAgB;IACtD,IAAM,MAAM,GAAG,IAAA,sBAAS,EAAC,QAAQ,CAAC,CAAC;IAEnC,2DAA2D;IAC3D,IAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,6CAA6C;AAClG,CAAC;AAPD,0DAOC;AAED,SAAgB,oBAAoB,CAAC,YAAoB;IACvD,IAAM,MAAM,GAAG,IAAA,sBAAS,EAAC,YAAY,CAAC,CAAC;IAEvC,6DAA6D;IAC7D,IAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,6CAA6C;AAClG,CAAC;AAPD,oDAOC;AAED,SAAgB,cAAc,CAAC,MAAc;
|
|
1
|
+
{"version":3,"file":"lp.js","sourceRoot":"/","sources":["utils/lp.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqC;AAErC,SAAgB,uBAAuB,CAAC,QAAgB;IACtD,IAAM,MAAM,GAAG,IAAA,sBAAS,EAAC,QAAQ,CAAC,CAAC;IAEnC,2DAA2D;IAC3D,IAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,6CAA6C;AAClG,CAAC;AAPD,0DAOC;AAED,SAAgB,oBAAoB,CAAC,YAAoB;IACvD,IAAM,MAAM,GAAG,IAAA,sBAAS,EAAC,YAAY,CAAC,CAAC;IAEvC,6DAA6D;IAC7D,IAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,6CAA6C;AAClG,CAAC;AAPD,oDAOC;AAED,SAAgB,cAAc,CAAC,MAAc,EAAE,QAAgB;IAC7D,IAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;IACrD,IAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAEpC,IAAM,kBAAkB,GAAG,YAAY,GAAG,aAAa,CAAC;IAExD,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAPD,wCAOC","sourcesContent":["import BigNumber from 'bignumber.js';\n\nexport function calculateMinSharesForLp(lpAmount: number): number {\n const amount = BigNumber(lpAmount);\n\n // Calculate 1% // @todo update this number once we have it\n const offset = amount.times(0.99);\n\n return amount.minus(offset).times(1e6).toNumber(); // rUSD/USDC has 6 decimals, change if needed\n}\n\nexport function calculateMinOutForLp(sharesAmount: number): number {\n const amount = BigNumber(sharesAmount);\n\n // Calculate 1% // @todo update once we have the exact number\n const offset = amount.times(0.99);\n\n return amount.minus(offset).times(1e6).toNumber(); // rUSD/USDC has 6 decimals, change if needed\n}\n\nexport function expandLpAmount(amount: number, decimals: number): bigint {\n const decimalFactor = BigInt(Math.pow(10, decimals));\n const amountBigInt = BigInt(amount);\n\n const amountDenormalised = amountBigInt * decimalFactor;\n\n return amountDenormalised;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"ethers": "6.9.0"
|
|
34
34
|
},
|
|
35
35
|
"packageManager": "pnpm@8.10.4",
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "9f2ff5ef64beccf41401f5805b3b1114865350c3"
|
|
37
37
|
}
|
|
@@ -13,7 +13,7 @@ const removeLiquidityabi = [
|
|
|
13
13
|
export const encodeProvideLiquidityCall = (
|
|
14
14
|
poolId: number,
|
|
15
15
|
accountOwner: string,
|
|
16
|
-
amount:
|
|
16
|
+
amount: bigint,
|
|
17
17
|
minShares: number,
|
|
18
18
|
): MethodParameters => {
|
|
19
19
|
const functionSignature = 'addLiquidity';
|
|
@@ -25,7 +25,7 @@ export const encodeProvideLiquidityCall = (
|
|
|
25
25
|
|
|
26
26
|
export const encodeRemoveLiquidityCall = (
|
|
27
27
|
poolId: number,
|
|
28
|
-
sharesAmount:
|
|
28
|
+
sharesAmount: bigint,
|
|
29
29
|
minOut: number,
|
|
30
30
|
): MethodParameters => {
|
|
31
31
|
const functionSignature = 'removeLiquidity';
|
package/src/services/lp/lp.ts
CHANGED
|
@@ -29,7 +29,7 @@ export const provideLiquidity = async (
|
|
|
29
29
|
throw new Error('LP amount can not be 0');
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const amount = expandLpAmount(params.amount);
|
|
32
|
+
const amount = expandLpAmount(params.amount, 6);
|
|
33
33
|
|
|
34
34
|
const { calldata: data, value } = encodeProvideLiquidityCall(
|
|
35
35
|
params.poolId,
|
|
@@ -63,7 +63,7 @@ export const removeLiquidity = async (
|
|
|
63
63
|
|
|
64
64
|
const minOut = calculateMinOutForLp(params.sharesAmount);
|
|
65
65
|
|
|
66
|
-
const amount = expandLpAmount(params.sharesAmount);
|
|
66
|
+
const amount = expandLpAmount(params.sharesAmount, 30); // shares have 30 decimals
|
|
67
67
|
const { calldata: data, value } = encodeRemoveLiquidityCall(
|
|
68
68
|
params.poolId,
|
|
69
69
|
amount,
|
|
@@ -7,13 +7,13 @@ import { getTokenDetails, scale } from '../token/common';
|
|
|
7
7
|
export const deposit = async (
|
|
8
8
|
params: DepositParams,
|
|
9
9
|
): Promise<DepositResult> => {
|
|
10
|
-
const { tokenDecimals } = getTokenDetails(params.
|
|
10
|
+
const { tokenDecimals } = getTokenDetails(params.tokenAddress);
|
|
11
11
|
const amount = scale(tokenDecimals)(params.amount);
|
|
12
12
|
const marketId = 0;
|
|
13
13
|
const exchangeId = 0;
|
|
14
14
|
const { calldata: data, value } = encodeDeposit(
|
|
15
15
|
params.accountId,
|
|
16
|
-
params.
|
|
16
|
+
params.tokenAddress,
|
|
17
17
|
amount,
|
|
18
18
|
marketId,
|
|
19
19
|
exchangeId,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SimulateDepositParams, SimulateDepositResult } from './types';
|
|
2
|
+
|
|
3
|
+
// The maximum is inclusive and the minimum is inclusive
|
|
4
|
+
function getRandomIntInclusive(min: number, max: number) {
|
|
5
|
+
min = Math.ceil(min);
|
|
6
|
+
max = Math.floor(max);
|
|
7
|
+
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const randomSimulation = (): SimulateDepositResult => {
|
|
11
|
+
return {
|
|
12
|
+
bridgeGasFees: getRandomIntInclusive(1000, 100000),
|
|
13
|
+
marginRatio: getRandomIntInclusive(1, 100),
|
|
14
|
+
marginRatioHealth: 'danger',
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const simulateDeposit = async (
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
20
|
+
params: SimulateDepositParams,
|
|
21
|
+
): Promise<SimulateDepositResult> => {
|
|
22
|
+
return await new Promise((resolve) => {
|
|
23
|
+
setTimeout(
|
|
24
|
+
() => {
|
|
25
|
+
resolve(randomSimulation());
|
|
26
|
+
},
|
|
27
|
+
Math.random() * 100 + 1000,
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SimulateWithdrawParams, SimulateWithdrawResult } from './types';
|
|
2
|
+
|
|
3
|
+
// The maximum is inclusive and the minimum is inclusive
|
|
4
|
+
function getRandomIntInclusive(min: number, max: number) {
|
|
5
|
+
min = Math.ceil(min);
|
|
6
|
+
max = Math.floor(max);
|
|
7
|
+
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const randomSimulation = (): SimulateWithdrawResult => {
|
|
11
|
+
return {
|
|
12
|
+
bridgeGasFees: getRandomIntInclusive(1000, 100000),
|
|
13
|
+
marginRatio: getRandomIntInclusive(1, 100),
|
|
14
|
+
marginRatioHealth: 'danger',
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const simulateWithdraw = async (
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
20
|
+
params: SimulateWithdrawParams,
|
|
21
|
+
): Promise<SimulateWithdrawResult> => {
|
|
22
|
+
return await new Promise((resolve) => {
|
|
23
|
+
setTimeout(
|
|
24
|
+
() => {
|
|
25
|
+
resolve(randomSimulation());
|
|
26
|
+
},
|
|
27
|
+
Math.random() * 100 + 1000,
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
@@ -12,7 +12,7 @@ export type CreateAccountResult = {
|
|
|
12
12
|
export type DepositParams = {
|
|
13
13
|
signer: Signer | JsonRpcSigner;
|
|
14
14
|
accountId: number;
|
|
15
|
-
|
|
15
|
+
tokenAddress: string;
|
|
16
16
|
amount: number;
|
|
17
17
|
};
|
|
18
18
|
|
|
@@ -23,10 +23,38 @@ export type DepositResult = {
|
|
|
23
23
|
export type WithdrawParams = {
|
|
24
24
|
signer: Signer | JsonRpcSigner;
|
|
25
25
|
accountId: number;
|
|
26
|
-
|
|
26
|
+
tokenAddress: string;
|
|
27
27
|
amount: number;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
export type WithdrawResult = {
|
|
31
31
|
transactionHash: string | null;
|
|
32
32
|
};
|
|
33
|
+
|
|
34
|
+
export type SimulateDepositResult = {
|
|
35
|
+
bridgeGasFees: number;
|
|
36
|
+
marginRatioHealth: 'danger' | 'healthy' | 'warning'; // MarginAccountEntity['marginRatioPercentage'];
|
|
37
|
+
marginRatio: number; // MarginAccountEntity['marginRatioHealth'];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// TODO: Milan reevaluate these params
|
|
41
|
+
export type SimulateDepositParams = {
|
|
42
|
+
signer: Signer | JsonRpcSigner;
|
|
43
|
+
accountId: number;
|
|
44
|
+
tokenAddress: string;
|
|
45
|
+
amount: number;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type SimulateWithdrawResult = {
|
|
49
|
+
bridgeGasFees: number;
|
|
50
|
+
marginRatioHealth: 'danger' | 'healthy' | 'warning'; // MarginAccountEntity['marginRatioPercentage'];
|
|
51
|
+
marginRatio: number; // MarginAccountEntity['marginRatioHealth'];
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// TODO: Milan reevaluate these params
|
|
55
|
+
export type SimulateWithdrawParams = {
|
|
56
|
+
signer: Signer | JsonRpcSigner;
|
|
57
|
+
accountId: number;
|
|
58
|
+
tokenAddress: string;
|
|
59
|
+
amount: number;
|
|
60
|
+
};
|
|
@@ -7,14 +7,14 @@ import { getTokenDetails, scale } from '../token/common';
|
|
|
7
7
|
export const withdraw = async (
|
|
8
8
|
params: WithdrawParams,
|
|
9
9
|
): Promise<WithdrawResult> => {
|
|
10
|
-
const { tokenDecimals } = getTokenDetails(params.
|
|
10
|
+
const { tokenDecimals } = getTokenDetails(params.tokenAddress);
|
|
11
11
|
const amount = scale(tokenDecimals)(params.amount);
|
|
12
12
|
|
|
13
13
|
const marketId = 0;
|
|
14
14
|
const exchangeId = 0;
|
|
15
15
|
const { calldata: data, value } = encodeWithdraw(
|
|
16
16
|
params.accountId,
|
|
17
|
-
params.
|
|
17
|
+
params.tokenAddress,
|
|
18
18
|
BigInt(amount),
|
|
19
19
|
marketId,
|
|
20
20
|
exchangeId,
|
package/src/utils/lp.ts
CHANGED
|
@@ -18,10 +18,11 @@ export function calculateMinOutForLp(sharesAmount: number): number {
|
|
|
18
18
|
return amount.minus(offset).times(1e6).toNumber(); // rUSD/USDC has 6 decimals, change if needed
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function expandLpAmount(amount: number
|
|
22
|
-
const decimalFactor =
|
|
21
|
+
export function expandLpAmount(amount: number, decimals: number): bigint {
|
|
22
|
+
const decimalFactor = BigInt(Math.pow(10, decimals));
|
|
23
|
+
const amountBigInt = BigInt(amount);
|
|
23
24
|
|
|
24
|
-
const amountDenormalised =
|
|
25
|
+
const amountDenormalised = amountBigInt * decimalFactor;
|
|
25
26
|
|
|
26
|
-
return
|
|
27
|
+
return amountDenormalised;
|
|
27
28
|
}
|