@reyaxyz/sdk 0.1.1 → 0.2.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/executeTransaction.js +9 -7
- package/dist/services/executeTransaction.js.map +1 -1
- package/dist/services/lp/lp.js +3 -2
- package/dist/services/lp/lp.js.map +1 -1
- package/dist/services/margin-accounts/account.js +2 -1
- package/dist/services/margin-accounts/account.js.map +1 -1
- package/dist/services/margin-accounts/deposit.js +2 -1
- package/dist/services/margin-accounts/deposit.js.map +1 -1
- package/dist/services/margin-accounts/withdraw.js +2 -1
- package/dist/services/margin-accounts/withdraw.js.map +1 -1
- package/dist/services/orders/order.js +2 -1
- package/dist/services/orders/order.js.map +1 -1
- package/dist/types/services/executeTransaction.d.ts +3 -2
- package/dist/types/services/executeTransaction.d.ts.map +1 -1
- package/dist/types/services/lp/lp.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/account.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/deposit.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/withdraw.d.ts.map +1 -1
- package/dist/types/services/orders/order.d.ts.map +1 -1
- package/dist/types/utils/consts.d.ts +8 -0
- package/dist/types/utils/consts.d.ts.map +1 -0
- package/dist/utils/consts.js +12 -0
- package/dist/utils/consts.js.map +1 -0
- package/package.json +2 -2
- package/src/services/executeTransaction.ts +15 -3
- package/src/services/lp/lp.ts +3 -0
- package/src/services/margin-accounts/account.ts +2 -0
- package/src/services/margin-accounts/deposit.ts +2 -0
- package/src/services/margin-accounts/withdraw.ts +2 -0
- package/src/services/orders/order.ts +2 -0
- package/src/utils/consts.ts +7 -0
|
@@ -49,17 +49,19 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
50
|
exports.executeTransaction = exports.estimateGas = void 0;
|
|
51
51
|
var txHelpers_1 = require("../utils/txHelpers");
|
|
52
|
-
|
|
52
|
+
var contractAddresses_1 = require("../utils/contractAddresses");
|
|
53
|
+
var consts_1 = require("../utils/consts");
|
|
54
|
+
function estimateGas(signer, data, value, chainId, transactionType) {
|
|
53
55
|
return __awaiter(this, void 0, void 0, function () {
|
|
54
56
|
var accountAddress, contractAddress, tx, gasLimit, gasEstimate, error_1;
|
|
55
57
|
return __generator(this, function (_a) {
|
|
56
58
|
switch (_a.label) {
|
|
57
|
-
case 0:
|
|
58
|
-
console.log(chainId); // @todo remove chainId if obsolete
|
|
59
|
-
return [4 /*yield*/, signer.getAddress()];
|
|
59
|
+
case 0: return [4 /*yield*/, signer.getAddress()];
|
|
60
60
|
case 1:
|
|
61
61
|
accountAddress = _a.sent();
|
|
62
|
-
contractAddress =
|
|
62
|
+
contractAddress = transactionType === consts_1.TransactionType.LP
|
|
63
|
+
? (0, contractAddresses_1.getAddress)(chainId, 'passive_pool_proxy')
|
|
64
|
+
: (0, contractAddresses_1.getAddress)(chainId, 'core_proxy');
|
|
63
65
|
tx = __assign({ from: accountAddress, to: contractAddress, data: data }, (value && value !== '0' ? { value: value } : {}));
|
|
64
66
|
_a.label = 2;
|
|
65
67
|
case 2:
|
|
@@ -79,12 +81,12 @@ function estimateGas(signer, data, value, chainId) {
|
|
|
79
81
|
});
|
|
80
82
|
}
|
|
81
83
|
exports.estimateGas = estimateGas;
|
|
82
|
-
function executeTransaction(signer, data, value, chainId) {
|
|
84
|
+
function executeTransaction(signer, data, value, chainId, transactionType) {
|
|
83
85
|
return __awaiter(this, void 0, void 0, function () {
|
|
84
86
|
var txData, txResponse, txReceipt, error_2;
|
|
85
87
|
return __generator(this, function (_a) {
|
|
86
88
|
switch (_a.label) {
|
|
87
|
-
case 0: return [4 /*yield*/, estimateGas(signer, data, value, chainId)];
|
|
89
|
+
case 0: return [4 /*yield*/, estimateGas(signer, data, value, chainId, transactionType)];
|
|
88
90
|
case 1:
|
|
89
91
|
txData = _a.sent();
|
|
90
92
|
_a.label = 2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["services/executeTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gDAAkD;AASlD,SAAsB,WAAW,CAC/B,MAAc,EACd,IAAY,EACZ,KAAa,EACb,OAAe
|
|
1
|
+
{"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["services/executeTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gDAAkD;AAClD,gEAAwD;AACxD,0CAAkD;AASlD,SAAsB,WAAW,CAC/B,MAAc,EACd,IAAY,EACZ,KAAa,EACb,OAAe,EACf,eAAgC;;;;;wBAET,qBAAM,MAAM,CAAC,UAAU,EAAE,EAAA;;oBAA1C,cAAc,GAAG,SAAyB;oBAC1C,eAAe,GACnB,eAAe,KAAK,wBAAe,CAAC,EAAE;wBACpC,CAAC,CAAC,IAAA,8BAAU,EAAC,OAAO,EAAE,oBAAoB,CAAC;wBAC3C,CAAC,CAAC,IAAA,8BAAU,EAAC,OAAO,EAAE,YAAY,CAAC,CAAC;oBAClC,EAAE,cACN,IAAI,EAAE,cAAc,EACpB,EAAE,EAAE,eAAe,EACnB,IAAI,MAAA,IACD,CAAC,KAAK,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACpD,CAAC;;;;oBAKoB,qBAAM,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,EAAA;;oBAA1C,WAAW,GAAG,SAA4B;oBAChD,QAAQ,GAAG,IAAA,wBAAY,EAAC,WAAW,CAAC,CAAC;;;;oBAErC,OAAO,CAAC,IAAI,CAAC,OAAK,CAAC,CAAC;oBACpB,MAAM,IAAI,KAAK,CAAC,OAAe,CAAC,CAAC;wBAEnC,4CAAY,EAAE,KAAE,QAAQ,UAAA,KAAG;;;;CAC5B;AA7BD,kCA6BC;AAED,SAAsB,kBAAkB,CACtC,MAAc,EACd,IAAY,EACZ,KAAa,EACb,OAAe,EACf,eAAgC;;;;;wBAEjB,qBAAM,WAAW,CAC9B,MAAM,EACN,IAAI,EACJ,KAAK,EACL,OAAO,EACP,eAAe,CAChB,EAAA;;oBANK,MAAM,GAAG,SAMd;;;;oBAEoB,qBAAM,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,EAAA;;oBAAjD,UAAU,GAAG,SAAoC;oBACrC,qBAAM,UAAU,CAAC,IAAI,EAAE,EAAA;;oBAAnC,SAAS,GAAG,SAAuB;oBACzC,sBAAO,SAAS,EAAC;;;oBAEjB,OAAO,CAAC,IAAI,CAAC,OAAK,CAAC,CAAC;oBACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;;;;;CAElD;AAtBD,gDAsBC","sourcesContent":["import { Signer } from 'ethers';\nimport { getGasBuffer } from '../utils/txHelpers';\nimport { getAddress } from '../utils/contractAddresses';\nimport { TransactionType } from '../utils/consts';\n\nexport type Transaction = {\n from: string;\n to: string;\n data: string;\n value?: string;\n};\n\nexport async function estimateGas(\n signer: Signer,\n data: string,\n value: string,\n chainId: number,\n transactionType: TransactionType,\n): Promise<Transaction & { gasLimit: bigint }> {\n const accountAddress = await signer.getAddress();\n const contractAddress =\n transactionType === TransactionType.LP\n ? getAddress(chainId, 'passive_pool_proxy')\n : getAddress(chainId, 'core_proxy');\n const tx = {\n from: accountAddress,\n to: contractAddress,\n data,\n ...(value && value !== '0' ? { value: value } : {}),\n };\n\n let gasLimit: bigint;\n\n try {\n const gasEstimate = await signer.estimateGas(tx);\n gasLimit = getGasBuffer(gasEstimate);\n } catch (error) {\n console.warn(error);\n throw new Error(error as string);\n }\n return { ...tx, gasLimit };\n}\n\nexport async function executeTransaction(\n signer: Signer,\n data: string,\n value: string,\n chainId: number,\n transactionType: TransactionType,\n) {\n const txData = await estimateGas(\n signer,\n data,\n value,\n chainId,\n transactionType,\n );\n try {\n const txResponse = await signer.sendTransaction(txData);\n const txReceipt = await txResponse.wait(); // @todo Check what was reasoning behind this since this function waits until transaction is minted\n return txReceipt;\n } catch (error) {\n console.warn(error);\n throw new Error('Transaction Execution Error');\n }\n}\n"]}
|
package/dist/services/lp/lp.js
CHANGED
|
@@ -39,13 +39,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.removeLiquidity = exports.provideLiquidity = void 0;
|
|
40
40
|
var executeTransaction_1 = require("../executeTransaction");
|
|
41
41
|
var encode_1 = require("./encode");
|
|
42
|
+
var consts_1 = require("../../utils/consts");
|
|
42
43
|
var provideLiquidity = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
44
|
var _a, data, value, result;
|
|
44
45
|
return __generator(this, function (_b) {
|
|
45
46
|
switch (_b.label) {
|
|
46
47
|
case 0:
|
|
47
48
|
_a = (0, encode_1.encodeProvideLiquidityCall)(params.poolId, params.owner, params.amount, params.minShares), data = _a.calldata, value = _a.value;
|
|
48
|
-
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, params.chainId)];
|
|
49
|
+
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, params.chainId, consts_1.TransactionType.LP)];
|
|
49
50
|
case 1:
|
|
50
51
|
result = _b.sent();
|
|
51
52
|
return [2 /*return*/, result];
|
|
@@ -59,7 +60,7 @@ var removeLiquidity = function (params) { return __awaiter(void 0, void 0, void
|
|
|
59
60
|
switch (_b.label) {
|
|
60
61
|
case 0:
|
|
61
62
|
_a = (0, encode_1.encodeRemoveLiquidityCall)(params.poolId, params.sharesAmount, params.minOut), data = _a.calldata, value = _a.value;
|
|
62
|
-
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, params.chainId)];
|
|
63
|
+
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, params.chainId, consts_1.TransactionType.LP)];
|
|
63
64
|
case 1:
|
|
64
65
|
result = _b.sent();
|
|
65
66
|
return [2 /*return*/, result];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lp.js","sourceRoot":"/","sources":["services/lp/lp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA2D;AAC3D,mCAGkB;
|
|
1
|
+
{"version":3,"file":"lp.js","sourceRoot":"/","sources":["services/lp/lp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA2D;AAC3D,mCAGkB;AAElB,6CAAqD;AAE9C,IAAM,gBAAgB,GAAG,UAC9B,MAA4B;;;;;gBAGtB,KAA4B,IAAA,mCAA0B,EAC1D,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,SAAS,CACjB,EALiB,IAAI,cAAA,EAAE,KAAK,WAAA,CAK3B;gBAEa,qBAAM,IAAA,uCAAkB,EACrC,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,MAAM,CAAC,OAAO,EACd,wBAAe,CAAC,EAAE,CACnB,EAAA;;gBANK,MAAM,GAAG,SAMd;gBAED,sBAAO,MAAM,EAAC;;;KACf,CAAC;AApBW,QAAA,gBAAgB,oBAoB3B;AAEK,IAAM,eAAe,GAAG,UAC7B,MAA2B;;;;;gBAGrB,KAA4B,IAAA,kCAAyB,EACzD,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,YAAY,EACnB,MAAM,CAAC,MAAM,CACd,EAJiB,IAAI,cAAA,EAAE,KAAK,WAAA,CAI3B;gBAEa,qBAAM,IAAA,uCAAkB,EACrC,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,MAAM,CAAC,OAAO,EACd,wBAAe,CAAC,EAAE,CACnB,EAAA;;gBANK,MAAM,GAAG,SAMd;gBAED,sBAAO,MAAM,EAAC;;;KACf,CAAC;AAnBW,QAAA,eAAe,mBAmB1B","sourcesContent":["import { executeTransaction } from '../executeTransaction';\nimport {\n encodeProvideLiquidityCall,\n encodeRemoveLiquidityCall,\n} from './encode';\nimport { ProvideLiquidityArgs, RemoveLiquidityArgs } from './types';\nimport { TransactionType } from '../../utils/consts';\n\nexport const provideLiquidity = async (\n params: ProvideLiquidityArgs,\n): Promise<unknown> => {\n // @todo update type once we agree on the structure\n const { calldata: data, value } = encodeProvideLiquidityCall(\n params.poolId,\n params.owner,\n params.amount,\n params.minShares,\n );\n\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n params.chainId,\n TransactionType.LP,\n );\n\n return result;\n};\n\nexport const removeLiquidity = async (\n params: RemoveLiquidityArgs,\n): Promise<unknown> => {\n // @todo update type once we agree on the structure\n const { calldata: data, value } = encodeRemoveLiquidityCall(\n params.poolId,\n params.sharesAmount,\n params.minOut,\n );\n\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n params.chainId,\n TransactionType.LP,\n );\n\n return result;\n};\n"]}
|
|
@@ -39,13 +39,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.createAccount = void 0;
|
|
40
40
|
var executeTransaction_1 = require("../executeTransaction");
|
|
41
41
|
var encode_1 = require("./encode");
|
|
42
|
+
var consts_1 = require("../../utils/consts");
|
|
42
43
|
var createAccount = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
44
|
var _a, data, value, result;
|
|
44
45
|
return __generator(this, function (_b) {
|
|
45
46
|
switch (_b.label) {
|
|
46
47
|
case 0:
|
|
47
48
|
_a = (0, encode_1.encodeCreateAccountCall)(params.ownerAddress), data = _a.calldata, value = _a.value;
|
|
48
|
-
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, params.chainId)];
|
|
49
|
+
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, params.chainId, consts_1.TransactionType.CREATE_ACCOUNT)];
|
|
49
50
|
case 1:
|
|
50
51
|
result = _b.sent();
|
|
51
52
|
return [2 /*return*/, result];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"/","sources":["services/margin-accounts/account.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA2D;AAC3D,mCAAmD;
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"/","sources":["services/margin-accounts/account.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA2D;AAC3D,mCAAmD;AAEnD,6CAAqD;AAE9C,IAAM,aAAa,GAAG,UAC3B,MAAyB;;;;;gBAGnB,KAA4B,IAAA,gCAAuB,EACvD,MAAM,CAAC,YAAY,CACpB,EAFiB,IAAI,cAAA,EAAE,KAAK,WAAA,CAE3B;gBAEa,qBAAM,IAAA,uCAAkB,EACrC,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,MAAM,CAAC,OAAO,EACd,wBAAe,CAAC,cAAc,CAC/B,EAAA;;gBANK,MAAM,GAAG,SAMd;gBAED,sBAAO,MAAM,EAAC;;;KACf,CAAC;AAjBW,QAAA,aAAa,iBAiBxB","sourcesContent":["import { executeTransaction } from '../executeTransaction';\nimport { encodeCreateAccountCall } from './encode';\nimport { CreateAccountArgs } from './types';\nimport { TransactionType } from '../../utils/consts';\n\nexport const createAccount = async (\n params: CreateAccountArgs,\n): Promise<unknown> => {\n // @todo update type once we agree on the structure\n const { calldata: data, value } = encodeCreateAccountCall(\n params.ownerAddress,\n );\n\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n params.chainId,\n TransactionType.CREATE_ACCOUNT,\n );\n\n return result;\n};\n"]}
|
|
@@ -39,13 +39,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.deposit = void 0;
|
|
40
40
|
var encode_1 = require("./encode");
|
|
41
41
|
var executeTransaction_1 = require("../executeTransaction");
|
|
42
|
+
var consts_1 = require("../../utils/consts");
|
|
42
43
|
var deposit = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
44
|
var _a, data, value, result;
|
|
44
45
|
return __generator(this, function (_b) {
|
|
45
46
|
switch (_b.label) {
|
|
46
47
|
case 0:
|
|
47
48
|
_a = (0, encode_1.encodeDeposit)(params.accountId, params.token, params.amount, params.marketId, params.exchangeId), data = _a.calldata, value = _a.value;
|
|
48
|
-
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, params.chainId)];
|
|
49
|
+
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, params.chainId, consts_1.TransactionType.DEPOSIT)];
|
|
49
50
|
case 1:
|
|
50
51
|
result = _b.sent();
|
|
51
52
|
return [2 /*return*/, result];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deposit.js","sourceRoot":"/","sources":["services/margin-accounts/deposit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAAyC;AACzC,4DAA2D;
|
|
1
|
+
{"version":3,"file":"deposit.js","sourceRoot":"/","sources":["services/margin-accounts/deposit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAAyC;AACzC,4DAA2D;AAC3D,6CAAqD;AAE9C,IAAM,OAAO,GAAG,UAAO,MAAmB;;;;;gBAEzC,KAA4B,IAAA,sBAAa,EAC7C,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,UAAU,CAClB,EANiB,IAAI,cAAA,EAAE,KAAK,WAAA,CAM3B;gBAEa,qBAAM,IAAA,uCAAkB,EACrC,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,MAAM,CAAC,OAAO,EACd,wBAAe,CAAC,OAAO,CACxB,EAAA;;gBANK,MAAM,GAAG,SAMd;gBAED,sBAAO,MAAM,EAAC;;;KACf,CAAC;AAnBW,QAAA,OAAO,WAmBlB","sourcesContent":["import { DepositArgs } from './types';\nimport { encodeDeposit } from './encode';\nimport { executeTransaction } from '../executeTransaction';\nimport { TransactionType } from '../../utils/consts';\n\nexport const deposit = async (params: DepositArgs): Promise<unknown> => {\n // @todo update type once we agree on the structure\n const { calldata: data, value } = encodeDeposit(\n params.accountId,\n params.token,\n params.amount,\n params.marketId,\n params.exchangeId,\n );\n\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n params.chainId,\n TransactionType.DEPOSIT,\n );\n\n return result;\n};\n"]}
|
|
@@ -39,13 +39,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.withdraw = void 0;
|
|
40
40
|
var encode_1 = require("./encode");
|
|
41
41
|
var executeTransaction_1 = require("../executeTransaction");
|
|
42
|
+
var consts_1 = require("../../utils/consts");
|
|
42
43
|
var withdraw = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
44
|
var _a, data, value, result;
|
|
44
45
|
return __generator(this, function (_b) {
|
|
45
46
|
switch (_b.label) {
|
|
46
47
|
case 0:
|
|
47
48
|
_a = (0, encode_1.encodeWithdraw)(params.accountId, params.token, params.amount, params.marketId, params.exchangeId), data = _a.calldata, value = _a.value;
|
|
48
|
-
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, params.chainId)];
|
|
49
|
+
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, params.chainId, consts_1.TransactionType.WITHDRAW)];
|
|
49
50
|
case 1:
|
|
50
51
|
result = _b.sent();
|
|
51
52
|
return [2 /*return*/, result];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdraw.js","sourceRoot":"/","sources":["services/margin-accounts/withdraw.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAA0C;AAC1C,4DAA2D;
|
|
1
|
+
{"version":3,"file":"withdraw.js","sourceRoot":"/","sources":["services/margin-accounts/withdraw.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAA0C;AAC1C,4DAA2D;AAC3D,6CAAqD;AAE9C,IAAM,QAAQ,GAAG,UAAO,MAAoB;;;;;gBAE3C,KAA4B,IAAA,uBAAc,EAC9C,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,UAAU,CAClB,EANiB,IAAI,cAAA,EAAE,KAAK,WAAA,CAM3B;gBAEa,qBAAM,IAAA,uCAAkB,EACrC,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,MAAM,CAAC,OAAO,EACd,wBAAe,CAAC,QAAQ,CACzB,EAAA;;gBANK,MAAM,GAAG,SAMd;gBAED,sBAAO,MAAM,EAAC;;;KACf,CAAC;AAnBW,QAAA,QAAQ,YAmBnB","sourcesContent":["import { WithdrawArgs } from './types';\nimport { encodeWithdraw } from './encode';\nimport { executeTransaction } from '../executeTransaction';\nimport { TransactionType } from '../../utils/consts';\n\nexport const withdraw = async (params: WithdrawArgs): Promise<unknown> => {\n // @todo update type once we agree on the structure\n const { calldata: data, value } = encodeWithdraw(\n params.accountId,\n params.token,\n params.amount,\n params.marketId,\n params.exchangeId,\n );\n\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n params.chainId,\n TransactionType.WITHDRAW,\n );\n\n return result;\n};\n"]}
|
|
@@ -39,13 +39,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.matchOrder = void 0;
|
|
40
40
|
var encode_1 = require("./encode");
|
|
41
41
|
var executeTransaction_1 = require("../executeTransaction");
|
|
42
|
+
var consts_1 = require("../../utils/consts");
|
|
42
43
|
var matchOrder = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
44
|
var _a, data, value, result;
|
|
44
45
|
return __generator(this, function (_b) {
|
|
45
46
|
switch (_b.label) {
|
|
46
47
|
case 0:
|
|
47
48
|
_a = (0, encode_1.encodeMatchOrder)(params.accountId, params.orderBase, params.orderPriceLimit, params.counterpartyAccountIds, params.marketId, params.exchangeId), data = _a.calldata, value = _a.value;
|
|
48
|
-
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, params.chainId)];
|
|
49
|
+
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, params.chainId, consts_1.TransactionType.TRADE)];
|
|
49
50
|
case 1:
|
|
50
51
|
result = _b.sent();
|
|
51
52
|
return [2 /*return*/, result];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.js","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAA4C;AAC5C,4DAA2D;
|
|
1
|
+
{"version":3,"file":"order.js","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAA4C;AAC5C,4DAA2D;AAC3D,6CAAqD;AAE9C,IAAM,UAAU,GAAG,UAAO,MAAsB;;;;;gBAE/C,KAA4B,IAAA,yBAAgB,EAChD,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,eAAe,EACtB,MAAM,CAAC,sBAAsB,EAC7B,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,UAAU,CAClB,EAPiB,IAAI,cAAA,EAAE,KAAK,WAAA,CAO3B;gBAEa,qBAAM,IAAA,uCAAkB,EACrC,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,MAAM,CAAC,OAAO,EACd,wBAAe,CAAC,KAAK,CACtB,EAAA;;gBANK,MAAM,GAAG,SAMd;gBAED,sBAAO,MAAM,EAAC;;;KACf,CAAC;AApBW,QAAA,UAAU,cAoBrB","sourcesContent":["import { MatchOrderArgs } from './types';\nimport { encodeMatchOrder } from './encode';\nimport { executeTransaction } from '../executeTransaction';\nimport { TransactionType } from '../../utils/consts';\n\nexport const matchOrder = async (params: MatchOrderArgs): Promise<unknown> => {\n // @todo update type once we agree on the structure\n const { calldata: data, value } = encodeMatchOrder(\n params.accountId,\n params.orderBase,\n params.orderPriceLimit,\n params.counterpartyAccountIds,\n params.marketId,\n params.exchangeId,\n );\n\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n params.chainId,\n TransactionType.TRADE,\n );\n\n return result;\n};\n"]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Signer } from 'ethers';
|
|
2
|
+
import { TransactionType } from '../utils/consts';
|
|
2
3
|
export type Transaction = {
|
|
3
4
|
from: string;
|
|
4
5
|
to: string;
|
|
5
6
|
data: string;
|
|
6
7
|
value?: string;
|
|
7
8
|
};
|
|
8
|
-
export declare function estimateGas(signer: Signer, data: string, value: string, chainId: number): Promise<Transaction & {
|
|
9
|
+
export declare function estimateGas(signer: Signer, data: string, value: string, chainId: number, transactionType: TransactionType): Promise<Transaction & {
|
|
9
10
|
gasLimit: bigint;
|
|
10
11
|
}>;
|
|
11
|
-
export declare function executeTransaction(signer: Signer, data: string, value: string, chainId: number): Promise<import("ethers").TransactionReceipt | null>;
|
|
12
|
+
export declare function executeTransaction(signer: Signer, data: string, value: string, chainId: number, transactionType: TransactionType): Promise<import("ethers").TransactionReceipt | null>;
|
|
12
13
|
//# sourceMappingURL=executeTransaction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeTransaction.d.ts","sourceRoot":"/","sources":["services/executeTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"executeTransaction.d.ts","sourceRoot":"/","sources":["services/executeTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,WAAW,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAuB7C;AAED,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,eAAe,uDAiBjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lp.d.ts","sourceRoot":"/","sources":["services/lp/lp.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"lp.d.ts","sourceRoot":"/","sources":["services/lp/lp.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAGpE,eAAO,MAAM,gBAAgB,WACnB,oBAAoB,KAC3B,QAAQ,OAAO,CAkBjB,CAAC;AAEF,eAAO,MAAM,eAAe,WAClB,mBAAmB,KAC1B,QAAQ,OAAO,CAiBjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.d.ts","sourceRoot":"/","sources":["services/margin-accounts/account.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"/","sources":["services/margin-accounts/account.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAG5C,eAAO,MAAM,aAAa,WAChB,iBAAiB,KACxB,QAAQ,OAAO,CAejB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deposit.d.ts","sourceRoot":"/","sources":["services/margin-accounts/deposit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"deposit.d.ts","sourceRoot":"/","sources":["services/margin-accounts/deposit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAKtC,eAAO,MAAM,OAAO,WAAkB,WAAW,KAAG,QAAQ,OAAO,CAmBlE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdraw.d.ts","sourceRoot":"/","sources":["services/margin-accounts/withdraw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"withdraw.d.ts","sourceRoot":"/","sources":["services/margin-accounts/withdraw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAKvC,eAAO,MAAM,QAAQ,WAAkB,YAAY,KAAG,QAAQ,OAAO,CAmBpE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.d.ts","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"order.d.ts","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAKzC,eAAO,MAAM,UAAU,WAAkB,cAAc,KAAG,QAAQ,OAAO,CAoBxE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"/","sources":["utils/consts.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe;IACzB,cAAc,IAAA;IACd,OAAO,IAAA;IACP,QAAQ,IAAA;IACR,EAAE,IAAA;IACF,KAAK,IAAA;CACN"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionType = void 0;
|
|
4
|
+
var TransactionType;
|
|
5
|
+
(function (TransactionType) {
|
|
6
|
+
TransactionType[TransactionType["CREATE_ACCOUNT"] = 0] = "CREATE_ACCOUNT";
|
|
7
|
+
TransactionType[TransactionType["DEPOSIT"] = 1] = "DEPOSIT";
|
|
8
|
+
TransactionType[TransactionType["WITHDRAW"] = 2] = "WITHDRAW";
|
|
9
|
+
TransactionType[TransactionType["LP"] = 3] = "LP";
|
|
10
|
+
TransactionType[TransactionType["TRADE"] = 4] = "TRADE";
|
|
11
|
+
})(TransactionType || (exports.TransactionType = TransactionType = {}));
|
|
12
|
+
//# sourceMappingURL=consts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"/","sources":["utils/consts.ts"],"names":[],"mappings":";;;AAAA,IAAY,eAMX;AAND,WAAY,eAAe;IACzB,yEAAc,CAAA;IACd,2DAAO,CAAA;IACP,6DAAQ,CAAA;IACR,iDAAE,CAAA;IACF,uDAAK,CAAA;AACP,CAAC,EANW,eAAe,+BAAf,eAAe,QAM1B","sourcesContent":["export enum TransactionType {\n CREATE_ACCOUNT,\n DEPOSIT,\n WITHDRAW,\n LP,\n TRADE,\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"ethers": "6.9.0"
|
|
33
33
|
},
|
|
34
34
|
"packageManager": "pnpm@8.10.4",
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "0cd4bd2ca7ec708fcf7ef2198aa7abdc4dbbc83c"
|
|
36
36
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Signer } from 'ethers';
|
|
2
2
|
import { getGasBuffer } from '../utils/txHelpers';
|
|
3
|
+
import { getAddress } from '../utils/contractAddresses';
|
|
4
|
+
import { TransactionType } from '../utils/consts';
|
|
3
5
|
|
|
4
6
|
export type Transaction = {
|
|
5
7
|
from: string;
|
|
@@ -13,10 +15,13 @@ export async function estimateGas(
|
|
|
13
15
|
data: string,
|
|
14
16
|
value: string,
|
|
15
17
|
chainId: number,
|
|
18
|
+
transactionType: TransactionType,
|
|
16
19
|
): Promise<Transaction & { gasLimit: bigint }> {
|
|
17
|
-
console.log(chainId); // @todo remove chainId if obsolete
|
|
18
20
|
const accountAddress = await signer.getAddress();
|
|
19
|
-
const contractAddress =
|
|
21
|
+
const contractAddress =
|
|
22
|
+
transactionType === TransactionType.LP
|
|
23
|
+
? getAddress(chainId, 'passive_pool_proxy')
|
|
24
|
+
: getAddress(chainId, 'core_proxy');
|
|
20
25
|
const tx = {
|
|
21
26
|
from: accountAddress,
|
|
22
27
|
to: contractAddress,
|
|
@@ -41,8 +46,15 @@ export async function executeTransaction(
|
|
|
41
46
|
data: string,
|
|
42
47
|
value: string,
|
|
43
48
|
chainId: number,
|
|
49
|
+
transactionType: TransactionType,
|
|
44
50
|
) {
|
|
45
|
-
const txData = await estimateGas(
|
|
51
|
+
const txData = await estimateGas(
|
|
52
|
+
signer,
|
|
53
|
+
data,
|
|
54
|
+
value,
|
|
55
|
+
chainId,
|
|
56
|
+
transactionType,
|
|
57
|
+
);
|
|
46
58
|
try {
|
|
47
59
|
const txResponse = await signer.sendTransaction(txData);
|
|
48
60
|
const txReceipt = await txResponse.wait(); // @todo Check what was reasoning behind this since this function waits until transaction is minted
|
package/src/services/lp/lp.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
encodeRemoveLiquidityCall,
|
|
5
5
|
} from './encode';
|
|
6
6
|
import { ProvideLiquidityArgs, RemoveLiquidityArgs } from './types';
|
|
7
|
+
import { TransactionType } from '../../utils/consts';
|
|
7
8
|
|
|
8
9
|
export const provideLiquidity = async (
|
|
9
10
|
params: ProvideLiquidityArgs,
|
|
@@ -21,6 +22,7 @@ export const provideLiquidity = async (
|
|
|
21
22
|
data,
|
|
22
23
|
value,
|
|
23
24
|
params.chainId,
|
|
25
|
+
TransactionType.LP,
|
|
24
26
|
);
|
|
25
27
|
|
|
26
28
|
return result;
|
|
@@ -41,6 +43,7 @@ export const removeLiquidity = async (
|
|
|
41
43
|
data,
|
|
42
44
|
value,
|
|
43
45
|
params.chainId,
|
|
46
|
+
TransactionType.LP,
|
|
44
47
|
);
|
|
45
48
|
|
|
46
49
|
return result;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { executeTransaction } from '../executeTransaction';
|
|
2
2
|
import { encodeCreateAccountCall } from './encode';
|
|
3
3
|
import { CreateAccountArgs } from './types';
|
|
4
|
+
import { TransactionType } from '../../utils/consts';
|
|
4
5
|
|
|
5
6
|
export const createAccount = async (
|
|
6
7
|
params: CreateAccountArgs,
|
|
@@ -15,6 +16,7 @@ export const createAccount = async (
|
|
|
15
16
|
data,
|
|
16
17
|
value,
|
|
17
18
|
params.chainId,
|
|
19
|
+
TransactionType.CREATE_ACCOUNT,
|
|
18
20
|
);
|
|
19
21
|
|
|
20
22
|
return result;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DepositArgs } from './types';
|
|
2
2
|
import { encodeDeposit } from './encode';
|
|
3
3
|
import { executeTransaction } from '../executeTransaction';
|
|
4
|
+
import { TransactionType } from '../../utils/consts';
|
|
4
5
|
|
|
5
6
|
export const deposit = async (params: DepositArgs): Promise<unknown> => {
|
|
6
7
|
// @todo update type once we agree on the structure
|
|
@@ -17,6 +18,7 @@ export const deposit = async (params: DepositArgs): Promise<unknown> => {
|
|
|
17
18
|
data,
|
|
18
19
|
value,
|
|
19
20
|
params.chainId,
|
|
21
|
+
TransactionType.DEPOSIT,
|
|
20
22
|
);
|
|
21
23
|
|
|
22
24
|
return result;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WithdrawArgs } from './types';
|
|
2
2
|
import { encodeWithdraw } from './encode';
|
|
3
3
|
import { executeTransaction } from '../executeTransaction';
|
|
4
|
+
import { TransactionType } from '../../utils/consts';
|
|
4
5
|
|
|
5
6
|
export const withdraw = async (params: WithdrawArgs): Promise<unknown> => {
|
|
6
7
|
// @todo update type once we agree on the structure
|
|
@@ -17,6 +18,7 @@ export const withdraw = async (params: WithdrawArgs): Promise<unknown> => {
|
|
|
17
18
|
data,
|
|
18
19
|
value,
|
|
19
20
|
params.chainId,
|
|
21
|
+
TransactionType.WITHDRAW,
|
|
20
22
|
);
|
|
21
23
|
|
|
22
24
|
return result;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MatchOrderArgs } from './types';
|
|
2
2
|
import { encodeMatchOrder } from './encode';
|
|
3
3
|
import { executeTransaction } from '../executeTransaction';
|
|
4
|
+
import { TransactionType } from '../../utils/consts';
|
|
4
5
|
|
|
5
6
|
export const matchOrder = async (params: MatchOrderArgs): Promise<unknown> => {
|
|
6
7
|
// @todo update type once we agree on the structure
|
|
@@ -18,6 +19,7 @@ export const matchOrder = async (params: MatchOrderArgs): Promise<unknown> => {
|
|
|
18
19
|
data,
|
|
19
20
|
value,
|
|
20
21
|
params.chainId,
|
|
22
|
+
TransactionType.TRADE,
|
|
21
23
|
);
|
|
22
24
|
|
|
23
25
|
return result;
|