@reyaxyz/sdk 0.5.0 → 0.7.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.map +1 -1
- package/dist/services/margin-accounts/account.js +6 -3
- package/dist/services/margin-accounts/account.js.map +1 -1
- package/dist/services/margin-accounts/deposit.js +13 -4
- package/dist/services/margin-accounts/deposit.js.map +1 -1
- package/dist/services/margin-accounts/types.js.map +1 -1
- package/dist/services/margin-accounts/withdraw.js +12 -4
- package/dist/services/margin-accounts/withdraw.js.map +1 -1
- package/dist/services/token/index.js +1 -0
- package/dist/services/token/index.js.map +1 -1
- package/dist/types/services/margin-accounts/account.d.ts +2 -2
- package/dist/types/services/margin-accounts/account.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/deposit.d.ts +2 -2
- package/dist/types/services/margin-accounts/deposit.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/types.d.ts +11 -9
- package/dist/types/services/margin-accounts/types.d.ts.map +1 -1
- package/dist/types/services/margin-accounts/withdraw.d.ts +2 -2
- package/dist/types/services/margin-accounts/withdraw.d.ts.map +1 -1
- package/dist/types/services/token/index.d.ts +1 -0
- package/dist/types/services/token/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/services/executeTransaction.ts +1 -1
- package/src/services/margin-accounts/account.ts +8 -6
- package/src/services/margin-accounts/deposit.ts +18 -8
- package/src/services/margin-accounts/types.ts +14 -9
- package/src/services/margin-accounts/withdraw.ts +18 -8
- package/src/services/token/index.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["services/executeTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gDAAkD;AAClD,gEAAwD;AACxD,0CAAkD;AASlD,SAAsB,WAAW,CAC/B,MAA8B,EAC9B,IAAY,EACZ,KAAa,EACb,OAAe,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AAC,OAAK,CAAC,CAAC;oBACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;;;;;CAElD;AAtBD,gDAsBC","sourcesContent":["import { JsonRpcSigner, 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 | JsonRpcSigner,\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 | JsonRpcSigner,\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()
|
|
1
|
+
{"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["services/executeTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gDAAkD;AAClD,gEAAwD;AACxD,0CAAkD;AASlD,SAAsB,WAAW,CAC/B,MAA8B,EAC9B,IAAY,EACZ,KAAa,EACb,OAAe,EACf,eAAgC;;;;;wBAET,qBAAM,MAAM,CAAC,UAAU,EAAE,EAAA;;oBAA1C,cAAc,GAAG,SAAyB;oBAC1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AsBC","sourcesContent":["import { JsonRpcSigner, 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 | JsonRpcSigner,\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 | JsonRpcSigner,\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();\n return txReceipt;\n } catch (error) {\n console.warn(error);\n throw new Error('Transaction Execution Error');\n }\n}\n"]}
|
|
@@ -41,15 +41,18 @@ var executeTransaction_1 = require("../executeTransaction");
|
|
|
41
41
|
var encode_1 = require("./encode");
|
|
42
42
|
var consts_1 = require("../../utils/consts");
|
|
43
43
|
var createAccount = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
44
|
-
var _a, data, value, result;
|
|
44
|
+
var _a, data, value, chainId, result;
|
|
45
45
|
return __generator(this, function (_b) {
|
|
46
46
|
switch (_b.label) {
|
|
47
47
|
case 0:
|
|
48
48
|
_a = (0, encode_1.encodeCreateAccountCall)(params.ownerAddress), data = _a.calldata, value = _a.value;
|
|
49
|
-
|
|
49
|
+
chainId = 80001;
|
|
50
|
+
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, chainId, consts_1.TransactionType.CREATE_ACCOUNT)];
|
|
50
51
|
case 1:
|
|
51
52
|
result = _b.sent();
|
|
52
|
-
return [2 /*return*/,
|
|
53
|
+
return [2 /*return*/, {
|
|
54
|
+
transactionHash: (result === null || result === void 0 ? void 0 : result.hash) || null,
|
|
55
|
+
}];
|
|
53
56
|
}
|
|
54
57
|
});
|
|
55
58
|
}); };
|
|
@@ -1 +1 @@
|
|
|
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,MAA2B;;;;;
|
|
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,MAA2B;;;;;gBAErB,KAA4B,IAAA,gCAAuB,EACvD,MAAM,CAAC,YAAY,CACpB,EAFiB,IAAI,cAAA,EAAE,KAAK,WAAA,CAE3B;gBAGI,OAAO,GAAG,KAAK,CAAC;gBACP,qBAAM,IAAA,uCAAkB,EACrC,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,OAAO,EACP,wBAAe,CAAC,cAAc,CAC/B,EAAA;;gBANK,MAAM,GAAG,SAMd;gBACD,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,KAAI,IAAI;qBACtC,EAAC;;;KACH,CAAC;AAnBW,QAAA,aAAa,iBAmBxB","sourcesContent":["import { executeTransaction } from '../executeTransaction';\nimport { encodeCreateAccountCall } from './encode';\nimport { CreateAccountParams, CreateAccountResult } from './types';\nimport { TransactionType } from '../../utils/consts';\n\nexport const createAccount = async (\n params: CreateAccountParams,\n): Promise<CreateAccountResult> => {\n const { calldata: data, value } = encodeCreateAccountCall(\n params.ownerAddress,\n );\n\n // @todo update it\n const chainId = 80001;\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n chainId,\n TransactionType.CREATE_ACCOUNT,\n );\n return {\n transactionHash: result?.hash || null,\n };\n};\n"]}
|
|
@@ -40,16 +40,25 @@ exports.deposit = void 0;
|
|
|
40
40
|
var encode_1 = require("./encode");
|
|
41
41
|
var executeTransaction_1 = require("../executeTransaction");
|
|
42
42
|
var consts_1 = require("../../utils/consts");
|
|
43
|
+
var common_1 = require("../token/common");
|
|
43
44
|
var deposit = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
44
|
-
var _a, data, value, result;
|
|
45
|
+
var tokenDecimals, amount, marketId, exchangeId, _a, data, value, chainId, result;
|
|
45
46
|
return __generator(this, function (_b) {
|
|
46
47
|
switch (_b.label) {
|
|
47
48
|
case 0:
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
tokenDecimals = (0, common_1.getTokenDetails)(params.token).tokenDecimals;
|
|
50
|
+
amount = (0, common_1.scale)(tokenDecimals)(params.amount);
|
|
51
|
+
marketId = 0;
|
|
52
|
+
exchangeId = 0;
|
|
53
|
+
console.log(amount);
|
|
54
|
+
_a = (0, encode_1.encodeDeposit)(params.accountId, params.token, amount, marketId, exchangeId), data = _a.calldata, value = _a.value;
|
|
55
|
+
chainId = 80001;
|
|
56
|
+
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, chainId, consts_1.TransactionType.DEPOSIT)];
|
|
50
57
|
case 1:
|
|
51
58
|
result = _b.sent();
|
|
52
|
-
return [2 /*return*/,
|
|
59
|
+
return [2 /*return*/, {
|
|
60
|
+
transactionHash: (result === null || result === void 0 ? void 0 : result.hash) || null,
|
|
61
|
+
}];
|
|
53
62
|
}
|
|
54
63
|
});
|
|
55
64
|
}); };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deposit.js","sourceRoot":"/","sources":["services/margin-accounts/deposit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAAyC;AACzC,4DAA2D;AAC3D,6CAAqD;
|
|
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,KAAK,CAAC,cAAlC,CAAmC;gBAClD,MAAM,GAAG,IAAA,cAAK,EAAC,aAAa,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC7C,QAAQ,GAAG,CAAC,CAAC;gBACb,UAAU,GAAG,CAAC,CAAC;gBACrB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBACd,KAA4B,IAAA,sBAAa,EAC7C,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,KAAK,EACZ,MAAM,EACN,QAAQ,EACR,UAAU,CACX,EANiB,IAAI,cAAA,EAAE,KAAK,WAAA,CAM3B;gBAEI,OAAO,GAAG,KAAK,CAAC;gBACP,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;AA5BW,QAAA,OAAO,WA4BlB","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.token);\n const amount = scale(tokenDecimals)(params.amount);\n const marketId = 0;\n const exchangeId = 0;\n console.log(amount);\n const { calldata: data, value } = encodeDeposit(\n params.accountId,\n params.token,\n amount,\n marketId,\n exchangeId,\n );\n\n const chainId = 80001;\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"]}
|
|
@@ -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
|
|
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 token: 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 token: string;\n amount: number;\n};\n\nexport type WithdrawResult = {\n transactionHash: string | null;\n};\n"]}
|
|
@@ -40,16 +40,24 @@ exports.withdraw = void 0;
|
|
|
40
40
|
var encode_1 = require("./encode");
|
|
41
41
|
var executeTransaction_1 = require("../executeTransaction");
|
|
42
42
|
var consts_1 = require("../../utils/consts");
|
|
43
|
+
var common_1 = require("../token/common");
|
|
43
44
|
var withdraw = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
44
|
-
var _a, data, value, result;
|
|
45
|
+
var tokenDecimals, amount, marketId, exchangeId, _a, data, value, chainId, result;
|
|
45
46
|
return __generator(this, function (_b) {
|
|
46
47
|
switch (_b.label) {
|
|
47
48
|
case 0:
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
tokenDecimals = (0, common_1.getTokenDetails)(params.token).tokenDecimals;
|
|
50
|
+
amount = (0, common_1.scale)(tokenDecimals)(params.amount);
|
|
51
|
+
marketId = 0;
|
|
52
|
+
exchangeId = 0;
|
|
53
|
+
_a = (0, encode_1.encodeWithdraw)(params.accountId, params.token, BigInt(amount), marketId, exchangeId), data = _a.calldata, value = _a.value;
|
|
54
|
+
chainId = 80001;
|
|
55
|
+
return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, chainId, consts_1.TransactionType.WITHDRAW)];
|
|
50
56
|
case 1:
|
|
51
57
|
result = _b.sent();
|
|
52
|
-
return [2 /*return*/,
|
|
58
|
+
return [2 /*return*/, {
|
|
59
|
+
transactionHash: (result === null || result === void 0 ? void 0 : result.hash) || null,
|
|
60
|
+
}];
|
|
53
61
|
}
|
|
54
62
|
});
|
|
55
63
|
}); };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdraw.js","sourceRoot":"/","sources":["services/margin-accounts/withdraw.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAA0C;AAC1C,4DAA2D;AAC3D,6CAAqD;
|
|
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,KAAK,CAAC,cAAlC,CAAmC;gBAClD,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,KAAK,EACZ,MAAM,CAAC,MAAM,CAAC,EACd,QAAQ,EACR,UAAU,CACX,EANiB,IAAI,cAAA,EAAE,KAAK,WAAA,CAM3B;gBAEI,OAAO,GAAG,KAAK,CAAC;gBACP,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;AA5BW,QAAA,QAAQ,YA4BnB","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.token);\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.token,\n BigInt(amount),\n marketId,\n exchangeId,\n );\n\n const chainId = 80001;\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"]}
|
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./types"), exports);
|
|
18
18
|
__exportStar(require("./approve"), exports);
|
|
19
19
|
__exportStar(require("./getAllowance"), exports);
|
|
20
|
+
__exportStar(require("./getBalance"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["services/token/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,4CAA0B;AAC1B,iDAA+B","sourcesContent":["export * from './types';\nexport * from './approve';\nexport * from './getAllowance';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["services/token/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,4CAA0B;AAC1B,iDAA+B;AAC/B,+CAA6B","sourcesContent":["export * from './types';\nexport * from './approve';\nexport * from './getAllowance';\nexport * from './getBalance';\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { CreateAccountParams } from './types';
|
|
2
|
-
export declare const createAccount: (params: CreateAccountParams) => Promise<
|
|
1
|
+
import { CreateAccountParams, CreateAccountResult } from './types';
|
|
2
|
+
export declare const createAccount: (params: CreateAccountParams) => Promise<CreateAccountResult>;
|
|
3
3
|
//# sourceMappingURL=account.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.d.ts","sourceRoot":"/","sources":["services/margin-accounts/account.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"/","sources":["services/margin-accounts/account.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAGnE,eAAO,MAAM,aAAa,WAChB,mBAAmB,KAC1B,QAAQ,mBAAmB,CAiB7B,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DepositParams } from './types';
|
|
2
|
-
export declare const deposit: (params: DepositParams) => Promise<
|
|
1
|
+
import { DepositParams, DepositResult } from './types';
|
|
2
|
+
export declare const deposit: (params: DepositParams) => Promise<DepositResult>;
|
|
3
3
|
//# sourceMappingURL=deposit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deposit.d.ts","sourceRoot":"/","sources":["services/margin-accounts/deposit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"deposit.d.ts","sourceRoot":"/","sources":["services/margin-accounts/deposit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAMvD,eAAO,MAAM,OAAO,WACV,aAAa,KACpB,QAAQ,aAAa,CA0BvB,CAAC"}
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import { JsonRpcSigner, Signer } from 'ethers';
|
|
2
2
|
export type CreateAccountParams = {
|
|
3
3
|
signer: Signer | JsonRpcSigner;
|
|
4
|
-
chainId: number;
|
|
5
4
|
ownerAddress: string;
|
|
6
5
|
};
|
|
6
|
+
export type CreateAccountResult = {
|
|
7
|
+
transactionHash: string | null;
|
|
8
|
+
};
|
|
7
9
|
export type DepositParams = {
|
|
8
10
|
signer: Signer | JsonRpcSigner;
|
|
9
|
-
chainId: number;
|
|
10
11
|
accountId: number;
|
|
11
12
|
token: string;
|
|
12
|
-
amount:
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
amount: number;
|
|
14
|
+
};
|
|
15
|
+
export type DepositResult = {
|
|
16
|
+
transactionHash: string | null;
|
|
15
17
|
};
|
|
16
18
|
export type WithdrawParams = {
|
|
17
19
|
signer: Signer | JsonRpcSigner;
|
|
18
|
-
chainId: number;
|
|
19
20
|
accountId: number;
|
|
20
21
|
token: string;
|
|
21
|
-
amount:
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
amount: number;
|
|
23
|
+
};
|
|
24
|
+
export type WithdrawResult = {
|
|
25
|
+
transactionHash: string | null;
|
|
24
26
|
};
|
|
25
27
|
//# 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,
|
|
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,KAAK,EAAE,MAAM,CAAC;IACd,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,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { WithdrawParams } from './types';
|
|
2
|
-
export declare const withdraw: (params: WithdrawParams) => Promise<
|
|
1
|
+
import { WithdrawParams, WithdrawResult } from './types';
|
|
2
|
+
export declare const withdraw: (params: WithdrawParams) => Promise<WithdrawResult>;
|
|
3
3
|
//# sourceMappingURL=withdraw.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdraw.d.ts","sourceRoot":"/","sources":["services/margin-accounts/withdraw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"withdraw.d.ts","sourceRoot":"/","sources":["services/margin-accounts/withdraw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAMzD,eAAO,MAAM,QAAQ,WACX,cAAc,KACrB,QAAQ,cAAc,CA0BxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/token/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/token/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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": "c949888ceea20a14fb1ffbe8e4406f6554d5b7f7"
|
|
37
37
|
}
|
|
@@ -57,7 +57,7 @@ export async function executeTransaction(
|
|
|
57
57
|
);
|
|
58
58
|
try {
|
|
59
59
|
const txResponse = await signer.sendTransaction(txData);
|
|
60
|
-
const txReceipt = await txResponse.wait();
|
|
60
|
+
const txReceipt = await txResponse.wait();
|
|
61
61
|
return txReceipt;
|
|
62
62
|
} catch (error) {
|
|
63
63
|
console.warn(error);
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
import { executeTransaction } from '../executeTransaction';
|
|
2
2
|
import { encodeCreateAccountCall } from './encode';
|
|
3
|
-
import { CreateAccountParams } from './types';
|
|
3
|
+
import { CreateAccountParams, CreateAccountResult } from './types';
|
|
4
4
|
import { TransactionType } from '../../utils/consts';
|
|
5
5
|
|
|
6
6
|
export const createAccount = async (
|
|
7
7
|
params: CreateAccountParams,
|
|
8
|
-
): Promise<
|
|
9
|
-
// @todo update type once we agree on the structure
|
|
8
|
+
): Promise<CreateAccountResult> => {
|
|
10
9
|
const { calldata: data, value } = encodeCreateAccountCall(
|
|
11
10
|
params.ownerAddress,
|
|
12
11
|
);
|
|
13
12
|
|
|
13
|
+
// @todo update it
|
|
14
|
+
const chainId = 80001;
|
|
14
15
|
const result = await executeTransaction(
|
|
15
16
|
params.signer,
|
|
16
17
|
data,
|
|
17
18
|
value,
|
|
18
|
-
|
|
19
|
+
chainId,
|
|
19
20
|
TransactionType.CREATE_ACCOUNT,
|
|
20
21
|
);
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
return {
|
|
23
|
+
transactionHash: result?.hash || null,
|
|
24
|
+
};
|
|
23
25
|
};
|
|
@@ -1,25 +1,35 @@
|
|
|
1
|
-
import { DepositParams } from './types';
|
|
1
|
+
import { DepositParams, DepositResult } from './types';
|
|
2
2
|
import { encodeDeposit } from './encode';
|
|
3
3
|
import { executeTransaction } from '../executeTransaction';
|
|
4
4
|
import { TransactionType } from '../../utils/consts';
|
|
5
|
+
import { getTokenDetails, scale } from '../token/common';
|
|
5
6
|
|
|
6
|
-
export const deposit = async (
|
|
7
|
-
|
|
7
|
+
export const deposit = async (
|
|
8
|
+
params: DepositParams,
|
|
9
|
+
): Promise<DepositResult> => {
|
|
10
|
+
const { tokenDecimals } = getTokenDetails(params.token);
|
|
11
|
+
const amount = scale(tokenDecimals)(params.amount);
|
|
12
|
+
const marketId = 0;
|
|
13
|
+
const exchangeId = 0;
|
|
14
|
+
console.log(amount);
|
|
8
15
|
const { calldata: data, value } = encodeDeposit(
|
|
9
16
|
params.accountId,
|
|
10
17
|
params.token,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
amount,
|
|
19
|
+
marketId,
|
|
20
|
+
exchangeId,
|
|
14
21
|
);
|
|
15
22
|
|
|
23
|
+
const chainId = 80001;
|
|
16
24
|
const result = await executeTransaction(
|
|
17
25
|
params.signer,
|
|
18
26
|
data,
|
|
19
27
|
value,
|
|
20
|
-
|
|
28
|
+
chainId,
|
|
21
29
|
TransactionType.DEPOSIT,
|
|
22
30
|
);
|
|
23
31
|
|
|
24
|
-
return
|
|
32
|
+
return {
|
|
33
|
+
transactionHash: result?.hash || null,
|
|
34
|
+
};
|
|
25
35
|
};
|
|
@@ -2,26 +2,31 @@ import { JsonRpcSigner, Signer } from 'ethers';
|
|
|
2
2
|
|
|
3
3
|
export type CreateAccountParams = {
|
|
4
4
|
signer: Signer | JsonRpcSigner;
|
|
5
|
-
chainId: number;
|
|
6
5
|
ownerAddress: string;
|
|
7
6
|
};
|
|
8
7
|
|
|
8
|
+
export type CreateAccountResult = {
|
|
9
|
+
transactionHash: string | null;
|
|
10
|
+
};
|
|
11
|
+
|
|
9
12
|
export type DepositParams = {
|
|
10
13
|
signer: Signer | JsonRpcSigner;
|
|
11
|
-
chainId: number;
|
|
12
14
|
accountId: number;
|
|
13
15
|
token: string;
|
|
14
|
-
amount:
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
amount: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type DepositResult = {
|
|
20
|
+
transactionHash: string | null;
|
|
17
21
|
};
|
|
18
22
|
|
|
19
23
|
export type WithdrawParams = {
|
|
20
24
|
signer: Signer | JsonRpcSigner;
|
|
21
|
-
chainId: number;
|
|
22
25
|
accountId: number;
|
|
23
26
|
token: string;
|
|
24
|
-
amount:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
amount: number;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type WithdrawResult = {
|
|
31
|
+
transactionHash: string | null;
|
|
27
32
|
};
|
|
@@ -1,25 +1,35 @@
|
|
|
1
|
-
import { WithdrawParams } from './types';
|
|
1
|
+
import { WithdrawParams, WithdrawResult } from './types';
|
|
2
2
|
import { encodeWithdraw } from './encode';
|
|
3
3
|
import { executeTransaction } from '../executeTransaction';
|
|
4
4
|
import { TransactionType } from '../../utils/consts';
|
|
5
|
+
import { getTokenDetails, scale } from '../token/common';
|
|
5
6
|
|
|
6
|
-
export const withdraw = async (
|
|
7
|
-
|
|
7
|
+
export const withdraw = async (
|
|
8
|
+
params: WithdrawParams,
|
|
9
|
+
): Promise<WithdrawResult> => {
|
|
10
|
+
const { tokenDecimals } = getTokenDetails(params.token);
|
|
11
|
+
const amount = scale(tokenDecimals)(params.amount);
|
|
12
|
+
|
|
13
|
+
const marketId = 0;
|
|
14
|
+
const exchangeId = 0;
|
|
8
15
|
const { calldata: data, value } = encodeWithdraw(
|
|
9
16
|
params.accountId,
|
|
10
17
|
params.token,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
BigInt(amount),
|
|
19
|
+
marketId,
|
|
20
|
+
exchangeId,
|
|
14
21
|
);
|
|
15
22
|
|
|
23
|
+
const chainId = 80001;
|
|
16
24
|
const result = await executeTransaction(
|
|
17
25
|
params.signer,
|
|
18
26
|
data,
|
|
19
27
|
value,
|
|
20
|
-
|
|
28
|
+
chainId,
|
|
21
29
|
TransactionType.WITHDRAW,
|
|
22
30
|
);
|
|
23
31
|
|
|
24
|
-
return
|
|
32
|
+
return {
|
|
33
|
+
transactionHash: result?.hash || null,
|
|
34
|
+
};
|
|
25
35
|
};
|