@reyaxyz/sdk 0.8.2 → 0.10.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/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/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.map +1 -1
- package/dist/utils/lp.js +3 -4
- package/dist/utils/lp.js.map +1 -1
- package/package.json +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 +3 -6
|
@@ -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 +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"}
|
|
@@ -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,EAAE,QAAQ,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,CAIvE"}
|
package/dist/utils/lp.js
CHANGED
|
@@ -20,10 +20,9 @@ function calculateMinOutForLp(sharesAmount) {
|
|
|
20
20
|
}
|
|
21
21
|
exports.calculateMinOutForLp = calculateMinOutForLp;
|
|
22
22
|
function expandLpAmount(amount, decimals) {
|
|
23
|
-
var decimalFactor =
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
return amountDenormalised;
|
|
23
|
+
var decimalFactor = (0, bignumber_js_1.default)(10).pow(decimals);
|
|
24
|
+
var amountBigNumber = (0, bignumber_js_1.default)(amount);
|
|
25
|
+
return BigInt(amountBigNumber.times(decimalFactor).toFixed());
|
|
27
26
|
}
|
|
28
27
|
exports.expandLpAmount = expandLpAmount;
|
|
29
28
|
//# 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,EAAE,QAAgB;IAC7D,IAAM,aAAa,GAAG,
|
|
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,IAAA,sBAAS,EAAC,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAClD,IAAM,eAAe,GAAG,IAAA,sBAAS,EAAC,MAAM,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;AAChE,CAAC;AAJD,wCAIC","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 = BigNumber(10).pow(decimals);\n const amountBigNumber = BigNumber(amount);\n return BigInt(amountBigNumber.times(decimalFactor).toFixed());\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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": "6ab1baec6a0030c523d665ff96553100b0c12b01"
|
|
37
37
|
}
|
|
@@ -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
|
@@ -19,10 +19,7 @@ export function calculateMinOutForLp(sharesAmount: number): number {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function expandLpAmount(amount: number, decimals: number): bigint {
|
|
22
|
-
const decimalFactor =
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const amountDenormalised = amountBigInt * decimalFactor;
|
|
26
|
-
|
|
27
|
-
return amountDenormalised;
|
|
22
|
+
const decimalFactor = BigNumber(10).pow(decimals);
|
|
23
|
+
const amountBigNumber = BigNumber(amount);
|
|
24
|
+
return BigInt(amountBigNumber.times(decimalFactor).toFixed());
|
|
28
25
|
}
|