@reyaxyz/sdk 0.106.0 → 0.106.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/config/index.js +35 -1
- package/dist/config/index.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/services/conditional-orders/grant-trade-permission/encode.js +69 -0
- package/dist/services/conditional-orders/grant-trade-permission/encode.js.map +1 -0
- package/dist/services/conditional-orders/grant-trade-permission/grantTradePermission.js +67 -0
- package/dist/services/conditional-orders/grant-trade-permission/grantTradePermission.js.map +1 -0
- package/dist/services/conditional-orders/grant-trade-permission/index.js +19 -0
- package/dist/services/conditional-orders/grant-trade-permission/index.js.map +1 -0
- package/dist/services/conditional-orders/grant-trade-permission/types.js +3 -0
- package/dist/services/conditional-orders/grant-trade-permission/types.js.map +1 -0
- package/dist/services/conditional-orders/index.js +18 -0
- package/dist/services/conditional-orders/index.js.map +1 -0
- package/dist/types/config/index.d.ts +5 -1
- package/dist/types/config/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/services/conditional-orders/grant-trade-permission/encode.d.ts +4 -0
- package/dist/types/services/conditional-orders/grant-trade-permission/encode.d.ts.map +1 -0
- package/dist/types/services/conditional-orders/grant-trade-permission/grantTradePermission.d.ts +3 -0
- package/dist/types/services/conditional-orders/grant-trade-permission/grantTradePermission.d.ts.map +1 -0
- package/dist/types/services/conditional-orders/grant-trade-permission/index.d.ts +3 -0
- package/dist/types/services/conditional-orders/grant-trade-permission/index.d.ts.map +1 -0
- package/dist/types/services/conditional-orders/grant-trade-permission/types.d.ts +11 -0
- package/dist/types/services/conditional-orders/grant-trade-permission/types.d.ts.map +1 -0
- package/dist/types/services/conditional-orders/index.d.ts +2 -0
- package/dist/types/services/conditional-orders/index.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/config/index.ts +40 -0
- package/src/index.ts +1 -0
- package/src/services/conditional-orders/grant-trade-permission/encode.ts +45 -0
- package/src/services/conditional-orders/grant-trade-permission/grantTradePermission.ts +38 -0
- package/src/services/conditional-orders/grant-trade-permission/index.ts +2 -0
- package/src/services/conditional-orders/grant-trade-permission/types.ts +12 -0
- package/src/services/conditional-orders/index.ts +1 -0
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
package/dist/config/index.js
CHANGED
|
@@ -51,7 +51,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.getAlphaTermsModuleClient = exports.getTransactionModuleClient = exports.configureSDK = exports.getSdkEnvironment = exports.AlphaTermsModule = exports.TransactionModule = void 0;
|
|
54
|
+
exports.getApiInteractionsModule = exports.getAlphaTermsModuleClient = exports.getTransactionModuleClient = exports.configureSDK = exports.getSdkEnvironment = exports.ApiInteractionsModule = exports.AlphaTermsModule = exports.TransactionModule = void 0;
|
|
55
55
|
var common_1 = require("@reyaxyz/common");
|
|
56
56
|
var TransactionModule = /** @class */ (function (_super) {
|
|
57
57
|
__extends(TransactionModule, _super);
|
|
@@ -110,9 +110,36 @@ var AlphaTermsModule = /** @class */ (function (_super) {
|
|
|
110
110
|
return AlphaTermsModule;
|
|
111
111
|
}(common_1.RestClient));
|
|
112
112
|
exports.AlphaTermsModule = AlphaTermsModule;
|
|
113
|
+
var ApiInteractionsModule = /** @class */ (function (_super) {
|
|
114
|
+
__extends(ApiInteractionsModule, _super);
|
|
115
|
+
function ApiInteractionsModule() {
|
|
116
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
117
|
+
}
|
|
118
|
+
ApiInteractionsModule.prototype.createSLOrder = function (accountId, marketId, isLong, stopPrice, signerWallet, nonce, signature) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
120
|
+
var uri;
|
|
121
|
+
return __generator(this, function (_a) {
|
|
122
|
+
uri = "/api/conditional-orders/sl/create-order";
|
|
123
|
+
return [2 /*return*/, this.post(uri, {}, {
|
|
124
|
+
accountId: accountId,
|
|
125
|
+
marketId: marketId,
|
|
126
|
+
isLong: isLong,
|
|
127
|
+
stopPrice: stopPrice,
|
|
128
|
+
signerWallet: signerWallet,
|
|
129
|
+
nonce: nonce,
|
|
130
|
+
signature: signature,
|
|
131
|
+
status: common_1.StopLossOrderStatus.NEW,
|
|
132
|
+
})];
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
return ApiInteractionsModule;
|
|
137
|
+
}(common_1.RestClient));
|
|
138
|
+
exports.ApiInteractionsModule = ApiInteractionsModule;
|
|
113
139
|
// Internal state
|
|
114
140
|
var transactionModule = new TransactionModule(common_1.API_CLIENT_CONFIGS['test'].apiEndpoint);
|
|
115
141
|
var alphaTermsModule = new AlphaTermsModule(common_1.API_CLIENT_CONFIGS['test'].apiEndpoint);
|
|
142
|
+
var apiInteractionsModule = new ApiInteractionsModule(common_1.API_CLIENT_CONFIGS['test'].apiEndpoint);
|
|
116
143
|
var sdkEnv = 'test';
|
|
117
144
|
var getSdkEnvironment = function () {
|
|
118
145
|
return sdkEnv;
|
|
@@ -124,6 +151,7 @@ var configureSDK = function (environment) {
|
|
|
124
151
|
sdkEnv = environment;
|
|
125
152
|
transactionModule = new TransactionModule(config.apiEndpoint);
|
|
126
153
|
alphaTermsModule = new AlphaTermsModule(config.apiEndpoint);
|
|
154
|
+
apiInteractionsModule = new ApiInteractionsModule(config.apiEndpoint);
|
|
127
155
|
};
|
|
128
156
|
exports.configureSDK = configureSDK;
|
|
129
157
|
var getTransactionModuleClient = function () {
|
|
@@ -138,4 +166,10 @@ var getAlphaTermsModuleClient = function () {
|
|
|
138
166
|
return alphaTermsModule;
|
|
139
167
|
};
|
|
140
168
|
exports.getAlphaTermsModuleClient = getAlphaTermsModuleClient;
|
|
169
|
+
var getApiInteractionsModule = function () {
|
|
170
|
+
if (!apiInteractionsModule)
|
|
171
|
+
throw new Error('SDK is not configured! Call configureSDK()');
|
|
172
|
+
return apiInteractionsModule;
|
|
173
|
+
};
|
|
174
|
+
exports.getApiInteractionsModule = getApiInteractionsModule;
|
|
141
175
|
//# sourceMappingURL=index.js.map
|
package/dist/config/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n Address,\n API_CLIENT_CONFIGS,\n RestClient,\n ServiceConfig,\n TransactionExecutionMetadata,\n TransactionExecutionOutput,\n StopLossOrderStatus,\n StopLossOrder,\n} from '@reyaxyz/common';\n\nexport type TxData = {\n to: string;\n data: string;\n};\n\ntype AlphaTermsData = {\n walletAddress: Address;\n link: string;\n};\n\nexport class TransactionModule extends RestClient {\n async executeTransaction(\n txData: TxData,\n contractAddress: string,\n metadata: TransactionExecutionMetadata,\n ) {\n const uri = `/api/transaction-gelato/executeGelato`;\n // const uri = `/api/transaction/execute`; //switch between Gelato and internal relayer\n return this.post<TransactionExecutionOutput>(\n uri,\n {},\n {\n txData: txData,\n contractAddress,\n metadata,\n },\n );\n }\n\n async pushPendingTransaction(\n marginAccountId: number,\n transactionHash: string,\n sourceChainId: number,\n amount: number,\n assetId: string,\n type: string,\n ) {\n const uri = `/api/accounts/${marginAccountId}/push-pending-transaction`;\n return this.post<{ successful: boolean }>(\n uri,\n {},\n {\n tx_hash: transactionHash,\n source_chain_id: sourceChainId,\n amount,\n asset_id: assetId,\n type: type,\n },\n );\n }\n}\n\nexport class AlphaTermsModule extends RestClient {\n async registerAlphaSignature(params: AlphaTermsData): Promise<void> {\n // Build formData object.\n const formData = new FormData();\n formData.append('walletAddress', params.walletAddress);\n formData.append('signedLink', params.link);\n\n const uri = '/api/tos/alpha-signatures';\n return this.post(uri, undefined, formData, undefined);\n }\n}\n\nexport class ApiInteractionsModule extends RestClient {\n async createSLOrder(\n accountId: number,\n marketId: number,\n isLong: boolean,\n stopPrice: number,\n signerWallet: string,\n nonce: number,\n signature: string,\n ) {\n const uri = `/api/conditional-orders/sl/create-order`;\n return this.post<StopLossOrder>(\n uri,\n {},\n {\n accountId: accountId,\n marketId: marketId,\n isLong: isLong,\n stopPrice: stopPrice,\n signerWallet: signerWallet,\n nonce: nonce,\n signature: signature,\n status: StopLossOrderStatus.NEW,\n },\n );\n }\n}\n\n// Internal state\nlet transactionModule: TransactionModule = new TransactionModule(\n API_CLIENT_CONFIGS['test'].apiEndpoint,\n);\nlet alphaTermsModule: AlphaTermsModule = new AlphaTermsModule(\n API_CLIENT_CONFIGS['test'].apiEndpoint,\n);\nlet apiInteractionsModule: ApiInteractionsModule = new ApiInteractionsModule(\n API_CLIENT_CONFIGS['test'].apiEndpoint,\n);\n\nlet sdkEnv: ServiceConfig['environment'] = 'test';\n\nexport const getSdkEnvironment = (): ServiceConfig['environment'] => {\n return sdkEnv;\n};\n// Function to configure the SDK\nexport const configureSDK = (\n environment: ServiceConfig['environment'],\n): void => {\n const config = API_CLIENT_CONFIGS[environment] || API_CLIENT_CONFIGS['test'];\n sdkEnv = environment;\n transactionModule = new TransactionModule(config.apiEndpoint);\n alphaTermsModule = new AlphaTermsModule(config.apiEndpoint);\n apiInteractionsModule = new ApiInteractionsModule(config.apiEndpoint);\n};\n\nexport const getTransactionModuleClient = (): TransactionModule => {\n if (!transactionModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return transactionModule;\n};\n\nexport const getAlphaTermsModuleClient = (): AlphaTermsModule => {\n if (!alphaTermsModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return alphaTermsModule;\n};\n\nexport const getApiInteractionsModule = (): ApiInteractionsModule => {\n if (!apiInteractionsModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return apiInteractionsModule;\n};\n"]}
|
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ __exportStar(require("./services/lp"), exports);
|
|
|
19
19
|
__exportStar(require("./services/margin-accounts"), exports);
|
|
20
20
|
__exportStar(require("./services/money-flows"), exports);
|
|
21
21
|
__exportStar(require("./services/orders"), exports);
|
|
22
|
+
__exportStar(require("./services/conditional-orders"), exports);
|
|
22
23
|
__exportStar(require("./services/isolated-order"), exports);
|
|
23
24
|
__exportStar(require("./services/token"), exports);
|
|
24
25
|
var config_1 = require("./config");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,6DAA2C;AAC3C,yDAAuC;AACvC,oDAAkC;AAClC,4DAA0C;AAC1C,mDAAiC;AACjC,mCAAwC;AAA/B,sGAAA,YAAY,OAAA","sourcesContent":["export * from './services/lp';\nexport * from './services/margin-accounts';\nexport * from './services/money-flows';\nexport * from './services/orders';\nexport * from './services/isolated-order';\nexport * from './services/token';\nexport { configureSDK } from './config';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,6DAA2C;AAC3C,yDAAuC;AACvC,oDAAkC;AAClC,gEAA8C;AAC9C,4DAA0C;AAC1C,mDAAiC;AACjC,mCAAwC;AAA/B,sGAAA,YAAY,OAAA","sourcesContent":["export * from './services/lp';\nexport * from './services/margin-accounts';\nexport * from './services/money-flows';\nexport * from './services/orders';\nexport * from './services/conditional-orders';\nexport * from './services/isolated-order';\nexport * from './services/token';\nexport { configureSDK } from './config';\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
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.encodeGrantTradePermission = void 0;
|
|
40
|
+
var common_1 = require("@reyaxyz/common");
|
|
41
|
+
var common_2 = require("@reyaxyz/common");
|
|
42
|
+
var common_3 = require("@reyaxyz/common");
|
|
43
|
+
var ethers_1 = require("ethers");
|
|
44
|
+
var encodeGrantTradePermission = function (signer, chainId, coreSigNonce, accountId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
45
|
+
var permission, user, eip712Signature, value, functionSignature, parameters, INTERFACE, calldata;
|
|
46
|
+
return __generator(this, function (_a) {
|
|
47
|
+
switch (_a.label) {
|
|
48
|
+
case 0:
|
|
49
|
+
permission = (0, common_2.getPermission)(common_2.CoreAccountPermissionTypes.MATCH_ORDER);
|
|
50
|
+
user = (0, common_2.getAddress)(chainId, common_2.ContractType.CONDITIONAL_ORDERS_PROXY);
|
|
51
|
+
return [4 /*yield*/, (0, common_2.signGrantPermission)(signer, chainId, accountId, permission, user, coreSigNonce + 1, (0, common_2.getCurrentTimestampInSeconds)() + common_3.CORE_DEADLINE_IN_SECONDS)];
|
|
52
|
+
case 1:
|
|
53
|
+
eip712Signature = _a.sent();
|
|
54
|
+
value = BigInt(0);
|
|
55
|
+
functionSignature = 'grantAccountPermissionBySig';
|
|
56
|
+
parameters = [
|
|
57
|
+
{ accountId: accountId, permission: permission, user: user, sig: eip712Signature },
|
|
58
|
+
];
|
|
59
|
+
INTERFACE = new ethers_1.Interface(common_1.CoreAbi);
|
|
60
|
+
calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);
|
|
61
|
+
return [2 /*return*/, {
|
|
62
|
+
calldata: calldata,
|
|
63
|
+
value: BigInt(value).toString(10),
|
|
64
|
+
}];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}); };
|
|
68
|
+
exports.encodeGrantTradePermission = encodeGrantTradePermission;
|
|
69
|
+
//# sourceMappingURL=encode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/encode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAmE;AACnE,0CAOyB;AACzB,0CAA2D;AAC3D,iCAA2C;AAEpC,IAAM,0BAA0B,GAAG,UACxC,MAAc,EACd,OAAe,EACf,YAAoB,EACpB,SAAiB;;;;;gBAEX,UAAU,GAAG,IAAA,sBAAa,EAAC,mCAA0B,CAAC,WAAW,CAAC,CAAC;gBACnE,IAAI,GAAG,IAAA,mBAAU,EAAC,OAAO,EAAE,qBAAY,CAAC,wBAAwB,CAAC,CAAC;gBAEhD,qBAAM,IAAA,4BAAmB,EAC/C,MAAM,EACN,OAAO,EACP,SAAS,EACT,UAAU,EACV,IAAI,EACJ,YAAY,GAAG,CAAC,EAChB,IAAA,qCAA4B,GAAE,GAAG,iCAAwB,CAC1D,EAAA;;gBARK,eAAe,GAAG,SAQvB;gBAEK,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;gBAElB,iBAAiB,GAAG,6BAA6B,CAAC;gBAClD,UAAU,GAAG;oBACjB,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,YAAA,EAAE,IAAI,MAAA,EAAE,GAAG,EAAE,eAAe,EAAE;iBACjE,CAAC;gBAEI,SAAS,GAAG,IAAI,kBAAS,CAAC,gBAAG,CAAC,CAAC;gBAC/B,QAAQ,GAAG,SAAS,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;gBAC7E,sBAAO;wBACL,QAAQ,EAAE,QAAQ;wBAClB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;qBAClC,EAAC;;;KACH,CAAC;AAhCW,QAAA,0BAA0B,8BAgCrC","sourcesContent":["import { MethodParameters, CoreAbi as abi } from '@reyaxyz/common';\nimport {\n getCurrentTimestampInSeconds,\n ContractType,\n getAddress,\n CoreAccountPermissionTypes,\n getPermission,\n signGrantPermission,\n} from '@reyaxyz/common';\nimport { CORE_DEADLINE_IN_SECONDS } from '@reyaxyz/common';\nimport { Interface, Signer } from 'ethers';\n\nexport const encodeGrantTradePermission = async (\n signer: Signer,\n chainId: number,\n coreSigNonce: number,\n accountId: number,\n): Promise<MethodParameters> => {\n const permission = getPermission(CoreAccountPermissionTypes.MATCH_ORDER);\n const user = getAddress(chainId, ContractType.CONDITIONAL_ORDERS_PROXY);\n\n const eip712Signature = await signGrantPermission(\n signer,\n chainId,\n accountId,\n permission,\n user,\n coreSigNonce + 1,\n getCurrentTimestampInSeconds() + CORE_DEADLINE_IN_SECONDS,\n );\n\n const value = BigInt(0);\n\n const functionSignature = 'grantAccountPermissionBySig';\n const parameters = [\n { accountId: accountId, permission, user, sig: eip712Signature },\n ];\n\n const INTERFACE = new Interface(abi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return {\n calldata: calldata,\n value: BigInt(value).toString(10),\n };\n};\n"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
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.grantTradePermission = void 0;
|
|
40
|
+
var encode_1 = require("./encode");
|
|
41
|
+
var signAndBroadcastTransaction_1 = require("../../signAndBroadcastTransaction");
|
|
42
|
+
var common_1 = require("@reyaxyz/common");
|
|
43
|
+
var common_2 = require("@reyaxyz/common");
|
|
44
|
+
var config_1 = require("../../../config");
|
|
45
|
+
var grantTradePermission = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
+
var env, chainId, _a, data, value, result;
|
|
47
|
+
return __generator(this, function (_b) {
|
|
48
|
+
switch (_b.label) {
|
|
49
|
+
case 0:
|
|
50
|
+
env = (0, config_1.getSdkEnvironment)();
|
|
51
|
+
chainId = (0, common_1.getReyaNetwork)(env === 'production' ? 'production' : 'test');
|
|
52
|
+
return [4 /*yield*/, (0, encode_1.encodeGrantTradePermission)(params.signer, chainId, params.owner.coreSigNonce, params.accountId)];
|
|
53
|
+
case 1:
|
|
54
|
+
_a = _b.sent(), data = _a.calldata, value = _a.value;
|
|
55
|
+
return [4 /*yield*/, (0, signAndBroadcastTransaction_1.signAndBroadcastTransaction)(params.signer, data, value, chainId, common_2.ContractType.CORE_PROXY, {
|
|
56
|
+
accountId: params.accountId,
|
|
57
|
+
})];
|
|
58
|
+
case 2:
|
|
59
|
+
result = _b.sent();
|
|
60
|
+
return [2 /*return*/, {
|
|
61
|
+
transactionHash: (result === null || result === void 0 ? void 0 : result.txHash) || null,
|
|
62
|
+
}];
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}); };
|
|
66
|
+
exports.grantTradePermission = grantTradePermission;
|
|
67
|
+
//# sourceMappingURL=grantTradePermission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grantTradePermission.js","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/grantTradePermission.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,mCAAsD;AACtD,iFAAgF;AAChF,0CAAiD;AACjD,0CAA+C;AAC/C,0CAAoD;AAE7C,IAAM,oBAAoB,GAAG,UAClC,MAAkC;;;;;gBAE5B,GAAG,GAAG,IAAA,0BAAiB,GAAE,CAAC;gBAC1B,OAAO,GAAG,IAAA,uBAAc,EAAC,GAAG,KAAK,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;gBAE3C,qBAAM,IAAA,mCAA0B,EAChE,MAAM,CAAC,MAAM,EACb,OAAO,EACP,MAAM,CAAC,KAAK,CAAC,YAAY,EACzB,MAAM,CAAC,SAAS,CACjB,EAAA;;gBALK,KAA4B,SAKjC,EALiB,IAAI,cAAA,EAAE,KAAK,WAAA;gBAOd,qBAAM,IAAA,yDAA2B,EAC9C,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,OAAO,EACP,qBAAY,CAAC,UAAU,EACvB;wBACE,SAAS,EAAE,MAAM,CAAC,SAAS;qBAC5B,CACF,EAAA;;gBATK,MAAM,GAAG,SASd;gBAED,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,KAAI,IAAI;qBACxC,EAAC;;;KACH,CAAC;AA3BW,QAAA,oBAAoB,wBA2B/B","sourcesContent":["import {\n GrantTradePermissionParams,\n GrantTradePermissionResult,\n} from './types';\nimport { encodeGrantTradePermission } from './encode';\nimport { signAndBroadcastTransaction } from '../../signAndBroadcastTransaction';\nimport { getReyaNetwork } from '@reyaxyz/common';\nimport { ContractType } from '@reyaxyz/common';\nimport { getSdkEnvironment } from '../../../config';\n\nexport const grantTradePermission = async (\n params: GrantTradePermissionParams,\n): Promise<GrantTradePermissionResult> => {\n const env = getSdkEnvironment();\n const chainId = getReyaNetwork(env === 'production' ? 'production' : 'test');\n\n const { calldata: data, value } = await encodeGrantTradePermission(\n params.signer,\n chainId,\n params.owner.coreSigNonce,\n params.accountId,\n );\n\n const result = await signAndBroadcastTransaction(\n params.signer,\n data,\n value,\n chainId,\n ContractType.CORE_PROXY,\n {\n accountId: params.accountId,\n },\n );\n\n return {\n transactionHash: result?.txHash || null,\n };\n};\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./grantTradePermission"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,yDAAuC","sourcesContent":["export * from './types';\nexport * from './grantTradePermission';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/types.ts"],"names":[],"mappings":"","sourcesContent":["import { OwnerMetadataEntity } from '@reyaxyz/common';\nimport { JsonRpcSigner, Signer } from 'ethers';\n\nexport type GrantTradePermissionParams = {\n signer: Signer | JsonRpcSigner;\n owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;\n accountId: number;\n};\n\nexport type GrantTradePermissionResult = {\n transactionHash: string | null;\n};\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./grant-trade-permission"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["services/conditional-orders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC","sourcesContent":["export * from './grant-trade-permission';\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, RestClient, ServiceConfig, TransactionExecutionMetadata, TransactionExecutionOutput } from '@reyaxyz/common';
|
|
1
|
+
import { Address, RestClient, ServiceConfig, TransactionExecutionMetadata, TransactionExecutionOutput, StopLossOrder } from '@reyaxyz/common';
|
|
2
2
|
export type TxData = {
|
|
3
3
|
to: string;
|
|
4
4
|
data: string;
|
|
@@ -16,9 +16,13 @@ export declare class TransactionModule extends RestClient {
|
|
|
16
16
|
export declare class AlphaTermsModule extends RestClient {
|
|
17
17
|
registerAlphaSignature(params: AlphaTermsData): Promise<void>;
|
|
18
18
|
}
|
|
19
|
+
export declare class ApiInteractionsModule extends RestClient {
|
|
20
|
+
createSLOrder(accountId: number, marketId: number, isLong: boolean, stopPrice: number, signerWallet: string, nonce: number, signature: string): Promise<StopLossOrder>;
|
|
21
|
+
}
|
|
19
22
|
export declare const getSdkEnvironment: () => ServiceConfig['environment'];
|
|
20
23
|
export declare const configureSDK: (environment: ServiceConfig['environment']) => void;
|
|
21
24
|
export declare const getTransactionModuleClient: () => TransactionModule;
|
|
22
25
|
export declare const getAlphaTermsModuleClient: () => AlphaTermsModule;
|
|
26
|
+
export declare const getApiInteractionsModule: () => ApiInteractionsModule;
|
|
23
27
|
export {};
|
|
24
28
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,UAAU,EACV,aAAa,EACb,4BAA4B,EAC5B,0BAA0B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,UAAU,EACV,aAAa,EACb,4BAA4B,EAC5B,0BAA0B,EAE1B,aAAa,EACd,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,MAAM,GAAG;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qBAAa,iBAAkB,SAAQ,UAAU;IACzC,kBAAkB,CACtB,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,4BAA4B;IAelC,sBAAsB,CAC1B,eAAe,EAAE,MAAM,EACvB,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM;oBAGmB,OAAO;;CAYzC;AAED,qBAAa,gBAAiB,SAAQ,UAAU;IACxC,sBAAsB,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CASpE;AAED,qBAAa,qBAAsB,SAAQ,UAAU;IAC7C,aAAa,CACjB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM;CAkBpB;AAeD,eAAO,MAAM,iBAAiB,QAAO,aAAa,CAAC,aAAa,CAE/D,CAAC;AAEF,eAAO,MAAM,YAAY,gBACV,aAAa,CAAC,aAAa,CAAC,KACxC,IAMF,CAAC;AAEF,eAAO,MAAM,0BAA0B,QAAO,iBAI7C,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAAO,gBAI5C,CAAC;AAEF,eAAO,MAAM,wBAAwB,QAAO,qBAI3C,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './services/lp';
|
|
|
2
2
|
export * from './services/margin-accounts';
|
|
3
3
|
export * from './services/money-flows';
|
|
4
4
|
export * from './services/orders';
|
|
5
|
+
export * from './services/conditional-orders';
|
|
5
6
|
export * from './services/isolated-order';
|
|
6
7
|
export * from './services/token';
|
|
7
8
|
export { configureSDK } from './config';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MethodParameters } from '@reyaxyz/common';
|
|
2
|
+
import { Signer } from 'ethers';
|
|
3
|
+
export declare const encodeGrantTradePermission: (signer: Signer, chainId: number, coreSigNonce: number, accountId: number) => Promise<MethodParameters>;
|
|
4
|
+
//# sourceMappingURL=encode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAkB,MAAM,iBAAiB,CAAC;AAUnE,OAAO,EAAa,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE3C,eAAO,MAAM,0BAA0B,WAC7B,MAAM,WACL,MAAM,gBACD,MAAM,aACT,MAAM,KAChB,QAAQ,gBAAgB,CA2B1B,CAAC"}
|
package/dist/types/services/conditional-orders/grant-trade-permission/grantTradePermission.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grantTradePermission.d.ts","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/grantTradePermission.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC3B,MAAM,SAAS,CAAC;AAOjB,eAAO,MAAM,oBAAoB,WACvB,0BAA0B,KACjC,QAAQ,0BAA0B,CAyBpC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OwnerMetadataEntity } from '@reyaxyz/common';
|
|
2
|
+
import { JsonRpcSigner, Signer } from 'ethers';
|
|
3
|
+
export type GrantTradePermissionParams = {
|
|
4
|
+
signer: Signer | JsonRpcSigner;
|
|
5
|
+
owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
|
|
6
|
+
accountId: number;
|
|
7
|
+
};
|
|
8
|
+
export type GrantTradePermissionResult = {
|
|
9
|
+
transactionHash: string | null;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/conditional-orders/grant-trade-permission/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE/C,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;IACjD,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/conditional-orders/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/sdk",
|
|
3
|
-
"version": "0.106.
|
|
3
|
+
"version": "0.106.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@reyaxyz/common": "0.
|
|
32
|
+
"@reyaxyz/common": "0.155.1",
|
|
33
33
|
"bignumber.js": "^9.1.2",
|
|
34
34
|
"ethers": "6.9.0"
|
|
35
35
|
},
|
|
36
36
|
"packageManager": "pnpm@8.3.1",
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "e2d795903d65a29bf2d214b0224c2ec10fda767a"
|
|
38
38
|
}
|
package/src/config/index.ts
CHANGED
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
ServiceConfig,
|
|
6
6
|
TransactionExecutionMetadata,
|
|
7
7
|
TransactionExecutionOutput,
|
|
8
|
+
StopLossOrderStatus,
|
|
9
|
+
StopLossOrder,
|
|
8
10
|
} from '@reyaxyz/common';
|
|
9
11
|
|
|
10
12
|
export type TxData = {
|
|
@@ -71,6 +73,34 @@ export class AlphaTermsModule extends RestClient {
|
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
export class ApiInteractionsModule extends RestClient {
|
|
77
|
+
async createSLOrder(
|
|
78
|
+
accountId: number,
|
|
79
|
+
marketId: number,
|
|
80
|
+
isLong: boolean,
|
|
81
|
+
stopPrice: number,
|
|
82
|
+
signerWallet: string,
|
|
83
|
+
nonce: number,
|
|
84
|
+
signature: string,
|
|
85
|
+
) {
|
|
86
|
+
const uri = `/api/conditional-orders/sl/create-order`;
|
|
87
|
+
return this.post<StopLossOrder>(
|
|
88
|
+
uri,
|
|
89
|
+
{},
|
|
90
|
+
{
|
|
91
|
+
accountId: accountId,
|
|
92
|
+
marketId: marketId,
|
|
93
|
+
isLong: isLong,
|
|
94
|
+
stopPrice: stopPrice,
|
|
95
|
+
signerWallet: signerWallet,
|
|
96
|
+
nonce: nonce,
|
|
97
|
+
signature: signature,
|
|
98
|
+
status: StopLossOrderStatus.NEW,
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
74
104
|
// Internal state
|
|
75
105
|
let transactionModule: TransactionModule = new TransactionModule(
|
|
76
106
|
API_CLIENT_CONFIGS['test'].apiEndpoint,
|
|
@@ -78,6 +108,9 @@ let transactionModule: TransactionModule = new TransactionModule(
|
|
|
78
108
|
let alphaTermsModule: AlphaTermsModule = new AlphaTermsModule(
|
|
79
109
|
API_CLIENT_CONFIGS['test'].apiEndpoint,
|
|
80
110
|
);
|
|
111
|
+
let apiInteractionsModule: ApiInteractionsModule = new ApiInteractionsModule(
|
|
112
|
+
API_CLIENT_CONFIGS['test'].apiEndpoint,
|
|
113
|
+
);
|
|
81
114
|
|
|
82
115
|
let sdkEnv: ServiceConfig['environment'] = 'test';
|
|
83
116
|
|
|
@@ -92,6 +125,7 @@ export const configureSDK = (
|
|
|
92
125
|
sdkEnv = environment;
|
|
93
126
|
transactionModule = new TransactionModule(config.apiEndpoint);
|
|
94
127
|
alphaTermsModule = new AlphaTermsModule(config.apiEndpoint);
|
|
128
|
+
apiInteractionsModule = new ApiInteractionsModule(config.apiEndpoint);
|
|
95
129
|
};
|
|
96
130
|
|
|
97
131
|
export const getTransactionModuleClient = (): TransactionModule => {
|
|
@@ -105,3 +139,9 @@ export const getAlphaTermsModuleClient = (): AlphaTermsModule => {
|
|
|
105
139
|
throw new Error('SDK is not configured! Call configureSDK()');
|
|
106
140
|
return alphaTermsModule;
|
|
107
141
|
};
|
|
142
|
+
|
|
143
|
+
export const getApiInteractionsModule = (): ApiInteractionsModule => {
|
|
144
|
+
if (!apiInteractionsModule)
|
|
145
|
+
throw new Error('SDK is not configured! Call configureSDK()');
|
|
146
|
+
return apiInteractionsModule;
|
|
147
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './services/lp';
|
|
|
2
2
|
export * from './services/margin-accounts';
|
|
3
3
|
export * from './services/money-flows';
|
|
4
4
|
export * from './services/orders';
|
|
5
|
+
export * from './services/conditional-orders';
|
|
5
6
|
export * from './services/isolated-order';
|
|
6
7
|
export * from './services/token';
|
|
7
8
|
export { configureSDK } from './config';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { MethodParameters, CoreAbi as abi } from '@reyaxyz/common';
|
|
2
|
+
import {
|
|
3
|
+
getCurrentTimestampInSeconds,
|
|
4
|
+
ContractType,
|
|
5
|
+
getAddress,
|
|
6
|
+
CoreAccountPermissionTypes,
|
|
7
|
+
getPermission,
|
|
8
|
+
signGrantPermission,
|
|
9
|
+
} from '@reyaxyz/common';
|
|
10
|
+
import { CORE_DEADLINE_IN_SECONDS } from '@reyaxyz/common';
|
|
11
|
+
import { Interface, Signer } from 'ethers';
|
|
12
|
+
|
|
13
|
+
export const encodeGrantTradePermission = async (
|
|
14
|
+
signer: Signer,
|
|
15
|
+
chainId: number,
|
|
16
|
+
coreSigNonce: number,
|
|
17
|
+
accountId: number,
|
|
18
|
+
): Promise<MethodParameters> => {
|
|
19
|
+
const permission = getPermission(CoreAccountPermissionTypes.MATCH_ORDER);
|
|
20
|
+
const user = getAddress(chainId, ContractType.CONDITIONAL_ORDERS_PROXY);
|
|
21
|
+
|
|
22
|
+
const eip712Signature = await signGrantPermission(
|
|
23
|
+
signer,
|
|
24
|
+
chainId,
|
|
25
|
+
accountId,
|
|
26
|
+
permission,
|
|
27
|
+
user,
|
|
28
|
+
coreSigNonce + 1,
|
|
29
|
+
getCurrentTimestampInSeconds() + CORE_DEADLINE_IN_SECONDS,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const value = BigInt(0);
|
|
33
|
+
|
|
34
|
+
const functionSignature = 'grantAccountPermissionBySig';
|
|
35
|
+
const parameters = [
|
|
36
|
+
{ accountId: accountId, permission, user, sig: eip712Signature },
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
const INTERFACE = new Interface(abi);
|
|
40
|
+
const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);
|
|
41
|
+
return {
|
|
42
|
+
calldata: calldata,
|
|
43
|
+
value: BigInt(value).toString(10),
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GrantTradePermissionParams,
|
|
3
|
+
GrantTradePermissionResult,
|
|
4
|
+
} from './types';
|
|
5
|
+
import { encodeGrantTradePermission } from './encode';
|
|
6
|
+
import { signAndBroadcastTransaction } from '../../signAndBroadcastTransaction';
|
|
7
|
+
import { getReyaNetwork } from '@reyaxyz/common';
|
|
8
|
+
import { ContractType } from '@reyaxyz/common';
|
|
9
|
+
import { getSdkEnvironment } from '../../../config';
|
|
10
|
+
|
|
11
|
+
export const grantTradePermission = async (
|
|
12
|
+
params: GrantTradePermissionParams,
|
|
13
|
+
): Promise<GrantTradePermissionResult> => {
|
|
14
|
+
const env = getSdkEnvironment();
|
|
15
|
+
const chainId = getReyaNetwork(env === 'production' ? 'production' : 'test');
|
|
16
|
+
|
|
17
|
+
const { calldata: data, value } = await encodeGrantTradePermission(
|
|
18
|
+
params.signer,
|
|
19
|
+
chainId,
|
|
20
|
+
params.owner.coreSigNonce,
|
|
21
|
+
params.accountId,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const result = await signAndBroadcastTransaction(
|
|
25
|
+
params.signer,
|
|
26
|
+
data,
|
|
27
|
+
value,
|
|
28
|
+
chainId,
|
|
29
|
+
ContractType.CORE_PROXY,
|
|
30
|
+
{
|
|
31
|
+
accountId: params.accountId,
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
transactionHash: result?.txHash || null,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OwnerMetadataEntity } from '@reyaxyz/common';
|
|
2
|
+
import { JsonRpcSigner, Signer } from 'ethers';
|
|
3
|
+
|
|
4
|
+
export type GrantTradePermissionParams = {
|
|
5
|
+
signer: Signer | JsonRpcSigner;
|
|
6
|
+
owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
|
|
7
|
+
accountId: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type GrantTradePermissionResult = {
|
|
11
|
+
transactionHash: string | null;
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './grant-trade-permission';
|