@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.
Files changed (27) hide show
  1. package/dist/services/executeTransaction.js.map +1 -1
  2. package/dist/services/margin-accounts/account.js +6 -3
  3. package/dist/services/margin-accounts/account.js.map +1 -1
  4. package/dist/services/margin-accounts/deposit.js +13 -4
  5. package/dist/services/margin-accounts/deposit.js.map +1 -1
  6. package/dist/services/margin-accounts/types.js.map +1 -1
  7. package/dist/services/margin-accounts/withdraw.js +12 -4
  8. package/dist/services/margin-accounts/withdraw.js.map +1 -1
  9. package/dist/services/token/index.js +1 -0
  10. package/dist/services/token/index.js.map +1 -1
  11. package/dist/types/services/margin-accounts/account.d.ts +2 -2
  12. package/dist/types/services/margin-accounts/account.d.ts.map +1 -1
  13. package/dist/types/services/margin-accounts/deposit.d.ts +2 -2
  14. package/dist/types/services/margin-accounts/deposit.d.ts.map +1 -1
  15. package/dist/types/services/margin-accounts/types.d.ts +11 -9
  16. package/dist/types/services/margin-accounts/types.d.ts.map +1 -1
  17. package/dist/types/services/margin-accounts/withdraw.d.ts +2 -2
  18. package/dist/types/services/margin-accounts/withdraw.d.ts.map +1 -1
  19. package/dist/types/services/token/index.d.ts +1 -0
  20. package/dist/types/services/token/index.d.ts.map +1 -1
  21. package/package.json +2 -2
  22. package/src/services/executeTransaction.ts +1 -1
  23. package/src/services/margin-accounts/account.ts +8 -6
  24. package/src/services/margin-accounts/deposit.ts +18 -8
  25. package/src/services/margin-accounts/types.ts +14 -9
  26. package/src/services/margin-accounts/withdraw.ts +18 -8
  27. 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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,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 { 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(); // @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"]}
1
+ {"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["services/executeTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gDAAkD;AAClD,gEAAwD;AACxD,0CAAkD;AASlD,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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 { 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
- return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, params.chainId, consts_1.TransactionType.CREATE_ACCOUNT)];
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*/, result];
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;;;;;gBAGrB,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 { CreateAccountParams } from './types';\nimport { TransactionType } from '../../utils/consts';\n\nexport const createAccount = async (\n params: CreateAccountParams,\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"]}
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
- _a = (0, encode_1.encodeDeposit)(params.accountId, params.token, params.amount, params.marketId, params.exchangeId), data = _a.calldata, value = _a.value;
49
- return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, params.chainId, consts_1.TransactionType.DEPOSIT)];
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*/, result];
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;AAE9C,IAAM,OAAO,GAAG,UAAO,MAAqB;;;;;gBAE3C,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 { DepositParams } from './types';\nimport { encodeDeposit } from './encode';\nimport { executeTransaction } from '../executeTransaction';\nimport { TransactionType } from '../../utils/consts';\n\nexport const deposit = async (params: DepositParams): 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"]}
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 chainId: number;\n ownerAddress: string;\n};\n\nexport type DepositParams = {\n signer: Signer | JsonRpcSigner;\n chainId: number;\n accountId: number;\n token: string;\n amount: bigint;\n marketId: number;\n exchangeId: number;\n};\n\nexport type WithdrawParams = {\n signer: Signer | JsonRpcSigner;\n chainId: number;\n accountId: number;\n token: string;\n amount: bigint;\n marketId: number;\n exchangeId: number;\n};\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
- _a = (0, encode_1.encodeWithdraw)(params.accountId, params.token, params.amount, params.marketId, params.exchangeId), data = _a.calldata, value = _a.value;
49
- return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, params.chainId, consts_1.TransactionType.WITHDRAW)];
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*/, result];
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;AAE9C,IAAM,QAAQ,GAAG,UAAO,MAAsB;;;;;gBAE7C,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 { WithdrawParams } from './types';\nimport { encodeWithdraw } from './encode';\nimport { executeTransaction } from '../executeTransaction';\nimport { TransactionType } from '../../utils/consts';\n\nexport const withdraw = async (params: WithdrawParams): 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"]}
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<unknown>;
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;AAG9C,eAAO,MAAM,aAAa,WAChB,mBAAmB,KAC1B,QAAQ,OAAO,CAejB,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<unknown>;
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;AAKxC,eAAO,MAAM,OAAO,WAAkB,aAAa,KAAG,QAAQ,OAAO,CAmBpE,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: bigint;
13
- marketId: number;
14
- exchangeId: number;
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: bigint;
22
- marketId: number;
23
- exchangeId: number;
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,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AAa,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<unknown>;
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;AAKzC,eAAO,MAAM,QAAQ,WAAkB,cAAc,KAAG,QAAQ,OAAO,CAmBtE,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,4 +1,5 @@
1
1
  export * from './types';
2
2
  export * from './approve';
3
3
  export * from './getAllowance';
4
+ export * from './getBalance';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -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.5.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": "a0f4533458ea795570332768e5b2a49a5ec92afb"
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(); // @todo Check what was reasoning behind this since this function waits until transaction is minted
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<unknown> => {
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
- params.chainId,
19
+ chainId,
19
20
  TransactionType.CREATE_ACCOUNT,
20
21
  );
21
-
22
- return result;
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 (params: DepositParams): Promise<unknown> => {
7
- // @todo update type once we agree on the structure
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
- params.amount,
12
- params.marketId,
13
- params.exchangeId,
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
- params.chainId,
28
+ chainId,
21
29
  TransactionType.DEPOSIT,
22
30
  );
23
31
 
24
- return result;
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: bigint;
15
- marketId: number;
16
- exchangeId: number;
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: bigint;
25
- marketId: number;
26
- exchangeId: number;
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 (params: WithdrawParams): Promise<unknown> => {
7
- // @todo update type once we agree on the structure
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
- params.amount,
12
- params.marketId,
13
- params.exchangeId,
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
- params.chainId,
28
+ chainId,
21
29
  TransactionType.WITHDRAW,
22
30
  );
23
31
 
24
- return result;
32
+ return {
33
+ transactionHash: result?.hash || null,
34
+ };
25
35
  };
@@ -1,3 +1,4 @@
1
1
  export * from './types';
2
2
  export * from './approve';
3
3
  export * from './getAllowance';
4
+ export * from './getBalance';