@reyaxyz/sdk 0.41.0 → 0.42.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.
@@ -14,17 +14,6 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
17
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
18
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
19
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -71,12 +60,11 @@ var TransactionModule = /** @class */ (function (_super) {
71
60
  }
72
61
  TransactionModule.prototype.executeTransaction = function (txData, contractType, metadata) {
73
62
  return __awaiter(this, void 0, void 0, function () {
74
- var tx, uri;
63
+ var uri;
75
64
  return __generator(this, function (_a) {
76
- tx = __assign(__assign({}, txData), { gasLimit: String(txData.gasLimit), maxPriorityFeePerGas: String(txData.maxPriorityFeePerGas), maxFeePerGas: String(txData.maxFeePerGas) });
77
65
  uri = "/api/transaction/execute";
78
66
  return [2 /*return*/, this.post(uri, {}, {
79
- txData: tx,
67
+ txData: txData,
80
68
  contractType: contractType,
81
69
  metadata: metadata,
82
70
  })];
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAgF;AAehF;IAAuC,qCAAU;IAAjD;;IAwBA,CAAC;IAvBO,8CAAkB,GAAxB,UACE,MAAc,EACd,YAAoB,EACpB,QAAsC;;;;gBAGhC,EAAE,yBACH,MAAM,KACT,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EACjC,oBAAoB,EAAE,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,EACzD,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,GAC1C,CAAC;gBACI,GAAG,GAAG,0BAA0B,CAAC;gBACvC,sBAAO,IAAI,CAAC,IAAI,CACd,GAAG,EACH,EAAE,EACF;wBACE,MAAM,EAAE,EAAE;wBACV,YAAY,cAAA;wBACZ,QAAQ,UAAA;qBACT,CACF,EAAC;;;KACH;IACH,wBAAC;AAAD,CAAC,AAxBD,CAAuC,mBAAU,GAwBhD;AAxBY,8CAAiB;AA0B9B,iBAAiB;AACjB,IAAI,iBAAiB,GAAsB,IAAI,iBAAiB,CAC9D,2BAAkB,CAAC,MAAM,CAAC,CAAC,WAAW,CACvC,CAAC;AAEF,gCAAgC;AACzB,IAAM,YAAY,GAAG,UAC1B,WAAyC;IAEzC,IAAM,MAAM,GAAG,2BAAkB,CAAC,WAAW,CAAC,IAAI,2BAAkB,CAAC,MAAM,CAAC,CAAC;IAC7E,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAChE,CAAC,CAAC;AALW,QAAA,YAAY,gBAKvB;AAEK,IAAM,0BAA0B,GAAG;IACxC,IAAI,CAAC,iBAAiB;QACpB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAJW,QAAA,0BAA0B,8BAIrC","sourcesContent":["import { API_CLIENT_CONFIGS, RestClient, ServiceConfig } from '@reyaxyz/common';\n\nexport type BroadcastTransactionMetadata = {\n accountName?: string;\n};\n\nexport type TxData = {\n from: string;\n to: string;\n data: string;\n value?: string;\n gasLimit: bigint;\n maxPriorityFeePerGas?: bigint;\n maxFeePerGas?: bigint;\n};\nexport class TransactionModule extends RestClient {\n async executeTransaction(\n txData: TxData,\n contractType: string,\n metadata: BroadcastTransactionMetadata,\n ) {\n // convert from big number\n const tx = {\n ...txData,\n gasLimit: String(txData.gasLimit),\n maxPriorityFeePerGas: String(txData.maxPriorityFeePerGas),\n maxFeePerGas: String(txData.maxFeePerGas),\n };\n const uri = `/api/transaction/execute`;\n return this.post<{ txHash: string }>(\n uri,\n {},\n {\n txData: tx,\n contractType,\n metadata,\n },\n );\n }\n}\n\n// Internal state\nlet transactionModule: TransactionModule = new TransactionModule(\n API_CLIENT_CONFIGS['test'].apiEndpoint,\n);\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 transactionModule = new TransactionModule(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"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAgF;AAUhF;IAAuC,qCAAU;IAAjD;;IAiBA,CAAC;IAhBO,8CAAkB,GAAxB,UACE,MAAc,EACd,YAAoB,EACpB,QAAsC;;;;gBAEhC,GAAG,GAAG,0BAA0B,CAAC;gBACvC,sBAAO,IAAI,CAAC,IAAI,CACd,GAAG,EACH,EAAE,EACF;wBACE,MAAM,EAAE,MAAM;wBACd,YAAY,cAAA;wBACZ,QAAQ,UAAA;qBACT,CACF,EAAC;;;KACH;IACH,wBAAC;AAAD,CAAC,AAjBD,CAAuC,mBAAU,GAiBhD;AAjBY,8CAAiB;AAmB9B,iBAAiB;AACjB,IAAI,iBAAiB,GAAsB,IAAI,iBAAiB,CAC9D,2BAAkB,CAAC,MAAM,CAAC,CAAC,WAAW,CACvC,CAAC;AAEF,gCAAgC;AACzB,IAAM,YAAY,GAAG,UAC1B,WAAyC;IAEzC,IAAM,MAAM,GAAG,2BAAkB,CAAC,WAAW,CAAC,IAAI,2BAAkB,CAAC,MAAM,CAAC,CAAC;IAC7E,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAChE,CAAC,CAAC;AALW,QAAA,YAAY,gBAKvB;AAEK,IAAM,0BAA0B,GAAG;IACxC,IAAI,CAAC,iBAAiB;QACpB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAJW,QAAA,0BAA0B,8BAIrC","sourcesContent":["import { API_CLIENT_CONFIGS, RestClient, ServiceConfig } from '@reyaxyz/common';\n\nexport type BroadcastTransactionMetadata = {\n accountName?: string;\n};\n\nexport type TxData = {\n to: string;\n data: string;\n};\nexport class TransactionModule extends RestClient {\n async executeTransaction(\n txData: TxData,\n contractType: string,\n metadata: BroadcastTransactionMetadata,\n ) {\n const uri = `/api/transaction/execute`;\n return this.post<{ txHash: string }>(\n uri,\n {},\n {\n txData: txData,\n contractType,\n metadata,\n },\n );\n }\n}\n\n// Internal state\nlet transactionModule: TransactionModule = new TransactionModule(\n API_CLIENT_CONFIGS['test'].apiEndpoint,\n);\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 transactionModule = new TransactionModule(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"]}
@@ -17,7 +17,7 @@ var encodeSingleWithdraw = function (token, amount, multiAction) {
17
17
  };
18
18
  exports.encodeSingleWithdraw = encodeSingleWithdraw;
19
19
  var encodeSingleTransferMargin = function (toMarginAccountId, token, amount, multiAction) {
20
- multiAction.newAction((0, routerCommands_1.getCommand)(routerCommands_1.CommandType.TRANSFER_MARGIN_ACCOUNT, [toMarginAccountId, token, amount], 0, 0));
20
+ multiAction.newAction((0, routerCommands_1.getCommand)(routerCommands_1.CommandType.TRANSFER_MARGIN_ACCOUNT, [[toMarginAccountId, token, amount]], 0, 0));
21
21
  };
22
22
  exports.encodeSingleTransferMargin = encodeSingleTransferMargin;
23
23
  var encodeSingleTrade = function (counterpartyAccountIds, orderBase, orderPriceLimit, marketId, exchangeId, multiAction) {
@@ -1 +1 @@
1
- {"version":3,"file":"encode.js","sourceRoot":"/","sources":["services/encode.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,0DAAkE;AAClE,iCAA6C;AAC7C,qEAAmD;AACnD,gBAAgB;AAChB,wGAAwG;AACxG,KAAK;AACE,IAAM,mBAAmB,GAAG,UACjC,KAAa,EACb,MAAc,EACd,WAAwB;IAExB,WAAW,CAAC,SAAS,CAAC,IAAA,2BAAU,EAAC,4BAAW,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAChF,CAAC,CAAC;AANW,QAAA,mBAAmB,uBAM9B;AAEK,IAAM,oBAAoB,GAAG,UAClC,KAAa,EACb,MAAc,EACd,WAAwB;IAExB,WAAW,CAAC,SAAS,CACnB,IAAA,2BAAU,EAAC,4BAAW,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CACxD,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,oBAAoB,wBAQ/B;AAEK,IAAM,0BAA0B,GAAG,UACxC,iBAAyB,EACzB,KAAa,EACb,MAAc,EACd,WAAwB;IAExB,WAAW,CAAC,SAAS,CACnB,IAAA,2BAAU,EACR,4BAAW,CAAC,uBAAuB,EACnC,CAAC,iBAAiB,EAAE,KAAK,EAAE,MAAM,CAAC,EAClC,CAAC,EACD,CAAC,CACF,CACF,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,0BAA0B,8BAcrC;AAEK,IAAM,iBAAiB,GAAG,UAC/B,sBAAgC,EAChC,SAAiB,EACjB,eAAuB,EACvB,QAAgB,EAChB,UAAkB,EAClB,WAAwB;IAExB,wGAAwG;IACxG,IAAM,gBAAgB,GAAG,iBAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,CACxD,CAAC,QAAQ,EAAE,SAAS,CAAC,EACrB,CAAC,SAAS,EAAE,eAAe,CAAC,CAC7B,CAAC;IAEF,WAAW,CAAC,SAAS,CACnB,IAAA,2BAAU,EACR,4BAAW,CAAC,WAAW,EACvB,CAAC,sBAAsB,EAAE,gBAAgB,CAAC,EAC1C,QAAQ,EACR,UAAU,CACX,CACF,CAAC;AACJ,CAAC,CAAC;AAtBW,QAAA,iBAAiB,qBAsB5B;AAEK,IAAM,gBAAgB,GAAG,UAC9B,WAAwB,EACxB,SAAiB,EACjB,mBAA2B;IAE3B,IAAM,iBAAiB,GAAG,SAAS,CAAC;IACpC,IAAM,UAAU,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAErD,IAAM,SAAS,GAAG,IAAI,kBAAS,CAAC,0BAAG,CAAC,CAAC;IACrC,IAAM,QAAQ,GAAG,SAAS,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;IAC7E,OAAO;QACL,QAAQ,EAAE,QAAQ;QAClB,KAAK,EAAE,MAAM,CAAC,mBAAmB,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;KAChD,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,gBAAgB,oBAc3B","sourcesContent":["//////////////////// ENCODE SINGLE ////////////////////\n\nimport { MethodParameters, MultiAction } from '../utils/action';\nimport { CommandType, getCommand } from '../utils/routerCommands';\nimport { AbiCoder, Interface } from 'ethers';\nimport { abi } from '../abis/ExecutionModule.json';\n// const abi = [\n// 'function coreExecute(uint128 poolId, uint128 accountId, Command[] commands, EIP712Signature sig)',\n// ];\nexport const encodeSingleDeposit = (\n token: string,\n amount: bigint,\n multiAction: MultiAction,\n): void => {\n multiAction.newAction(getCommand(CommandType.DEPOSIT, [token, amount], 0, 0));\n};\n\nexport const encodeSingleWithdraw = (\n token: string,\n amount: bigint,\n multiAction: MultiAction,\n): void => {\n multiAction.newAction(\n getCommand(CommandType.WITHDRAW, [token, amount], 0, 0),\n );\n};\n\nexport const encodeSingleTransferMargin = (\n toMarginAccountId: number,\n token: string,\n amount: bigint,\n multiAction: MultiAction,\n): void => {\n multiAction.newAction(\n getCommand(\n CommandType.TRANSFER_MARGIN_ACCOUNT,\n [toMarginAccountId, token, amount],\n 0,\n 0,\n ),\n );\n};\n\nexport const encodeSingleTrade = (\n counterpartyAccountIds: number[],\n orderBase: bigint,\n orderPriceLimit: bigint,\n marketId: number,\n exchangeId: number,\n multiAction: MultiAction,\n): void => {\n // (int256 orderBase, UD60x18 orderPriceLimit) = abi.decode(matchOrderInputs.inputs, (int256, UD60x18));\n const encodedBasePrice = AbiCoder.defaultAbiCoder().encode(\n ['int256', 'uint256'],\n [orderBase, orderPriceLimit],\n );\n\n multiAction.newAction(\n getCommand(\n CommandType.MATCH_ORDER,\n [counterpartyAccountIds, encodedBasePrice],\n marketId,\n exchangeId,\n ),\n );\n};\n\nexport const encodeRouterCall = (\n multiAction: MultiAction,\n accountId: number,\n nativeCurrencyValue: bigint,\n): MethodParameters => {\n const functionSignature = 'execute';\n const parameters = [accountId, multiAction.commands];\n\n const INTERFACE = new Interface(abi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return {\n calldata: calldata,\n value: BigInt(nativeCurrencyValue).toString(10),\n };\n};\n"]}
1
+ {"version":3,"file":"encode.js","sourceRoot":"/","sources":["services/encode.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,0DAAkE;AAClE,iCAA6C;AAC7C,qEAAmD;AACnD,gBAAgB;AAChB,wGAAwG;AACxG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;AACJ,CAAC,CAAC;AAtBW,QAAA,iBAAiB,qBAsB5B;AAEK,IAAM,gBAAgB,GAAG,UAC9B,WAAwB,EACxB,SAAiB,EACjB,mBAA2B;IAE3B,IAAM,iBAAiB,GAAG,SAAS,CAAC;IACpC,IAAM,UAAU,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAErD,IAAM,SAAS,GAAG,IAAI,kBAAS,CAAC,0BAAG,CAAC,CAAC;IACrC,IAAM,QAAQ,GAAG,SAAS,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;IAC7E,OAAO;QACL,QAAQ,EAAE,QAAQ;QAClB,KAAK,EAAE,MAAM,CAAC,mBAAmB,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;KAChD,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,gBAAgB,oBAc3B","sourcesContent":["//////////////////// ENCODE SINGLE ////////////////////\n\nimport { MethodParameters, MultiAction } from '../utils/action';\nimport { CommandType, getCommand } from '../utils/routerCommands';\nimport { AbiCoder, Interface } from 'ethers';\nimport { abi } from '../abis/ExecutionModule.json';\n// const abi = [\n// 'function coreExecute(uint128 poolId, uint128 accountId, Command[] commands, EIP712Signature sig)',\n// ];\nexport const encodeSingleDeposit = (\n token: string,\n amount: bigint,\n multiAction: MultiAction,\n): void => {\n multiAction.newAction(getCommand(CommandType.DEPOSIT, [token, amount], 0, 0));\n};\n\nexport const encodeSingleWithdraw = (\n token: string,\n amount: bigint,\n multiAction: MultiAction,\n): void => {\n multiAction.newAction(\n getCommand(CommandType.WITHDRAW, [token, amount], 0, 0),\n );\n};\n\nexport const encodeSingleTransferMargin = (\n toMarginAccountId: number,\n token: string,\n amount: bigint,\n multiAction: MultiAction,\n): void => {\n multiAction.newAction(\n getCommand(\n CommandType.TRANSFER_MARGIN_ACCOUNT,\n [[toMarginAccountId, token, amount]],\n 0,\n 0,\n ),\n );\n};\n\nexport const encodeSingleTrade = (\n counterpartyAccountIds: number[],\n orderBase: bigint,\n orderPriceLimit: bigint,\n marketId: number,\n exchangeId: number,\n multiAction: MultiAction,\n): void => {\n // (int256 orderBase, UD60x18 orderPriceLimit) = abi.decode(matchOrderInputs.inputs, (int256, UD60x18));\n const encodedBasePrice = AbiCoder.defaultAbiCoder().encode(\n ['int256', 'uint256'],\n [orderBase, orderPriceLimit],\n );\n\n multiAction.newAction(\n getCommand(\n CommandType.MATCH_ORDER,\n [counterpartyAccountIds, encodedBasePrice],\n marketId,\n exchangeId,\n ),\n );\n};\n\nexport const encodeRouterCall = (\n multiAction: MultiAction,\n accountId: number,\n nativeCurrencyValue: bigint,\n): MethodParameters => {\n const functionSignature = 'execute';\n const parameters = [accountId, multiAction.commands];\n\n const INTERFACE = new Interface(abi);\n const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);\n return {\n calldata: calldata,\n value: BigInt(nativeCurrencyValue).toString(10),\n };\n};\n"]}
@@ -120,25 +120,26 @@ function executeTransaction(signer, data, value, chainId, targetContract) {
120
120
  exports.executeTransaction = executeTransaction;
121
121
  function signAndBroadcastTransaction(signer, data, value, chainId, targetContract, metadata) {
122
122
  return __awaiter(this, void 0, void 0, function () {
123
- var txData, transactionModuleClient, txHash, error_3;
123
+ var contractAddress, transactionModuleClient, txHash, error_3;
124
124
  return __generator(this, function (_a) {
125
125
  switch (_a.label) {
126
- case 0: return [4 /*yield*/, estimateGas(signer, data, value, chainId, targetContract)];
126
+ case 0:
127
+ contractAddress = Object.values(contractAddresses_1.ContractType).includes(targetContract)
128
+ ? (0, contractAddresses_1.getAddress)(chainId, targetContract)
129
+ : targetContract;
130
+ _a.label = 1;
127
131
  case 1:
128
- txData = _a.sent();
129
- _a.label = 2;
130
- case 2:
131
- _a.trys.push([2, 4, , 5]);
132
+ _a.trys.push([1, 3, , 4]);
132
133
  transactionModuleClient = (0, config_1.getTransactionModuleClient)();
133
- return [4 /*yield*/, transactionModuleClient.executeTransaction(txData, targetContract, metadata)];
134
- case 3:
134
+ return [4 /*yield*/, transactionModuleClient.executeTransaction({ to: contractAddress, data: data }, targetContract, metadata)];
135
+ case 2:
135
136
  txHash = (_a.sent()).txHash;
136
137
  return [2 /*return*/, { hash: txHash }];
137
- case 4:
138
+ case 3:
138
139
  error_3 = _a.sent();
139
140
  console.warn(error_3);
140
141
  throw new Error('Transaction Execution Error');
141
- case 5: return [2 /*return*/];
142
+ case 4: return [2 /*return*/];
142
143
  }
143
144
  });
144
145
  });
@@ -1 +1 @@
1
- {"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["services/executeTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gEAAsE;AACtE,gDAAkD;AAClD,oCAGmB;AACnB,0CAA8C;AAS9C,SAAsB,WAAW,CAC/B,MAA8B,EAC9B,IAAY,EACZ,KAAa,EACb,OAAe,EACf,cAAqC;;;;;wBAQd,qBAAM,MAAM,CAAC,UAAU,EAAE,EAAA;;oBAA1C,cAAc,GAAG,SAAyB;oBAE1C,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,gCAAY,CAAC,CAAC,QAAQ,CAC1D,cAA8B,CAC/B;wBACC,CAAC,CAAC,IAAA,8BAAU,EAAC,OAAO,EAAE,cAA8B,CAAC;wBACrD,CAAC,CAAC,cAAc,CAAC;oBACb,EAAE,cACN,IAAI,EAAE,cAAc,EACpB,EAAE,EAAE,eAAe,EACnB,IAAI,MAAA,IACD,CAAC,KAAK,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACpD,CAAC;oBAEE,QAAQ,GAAW,MAAM,CAAC,SAAS,CAAC,CAAC;;;;oBAGnB,qBAAM,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,EAAA;;oBAA1C,WAAW,GAAG,SAA4B;oBAChD,QAAQ,GAAG,IAAA,wBAAY,EAAC,W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AAA;;oBANK,MAAM,GAAG,SAMd;;;;oBAEO,uBAAuB,GAAG,IAAA,mCAA0B,GAAE,CAAC;oBAC1C,qBAAM,uBAAuB,CAAC,kBAAkB,CACjE,MAAM,EACN,cAAc,EACd,QAAQ,CACT,EAAA;;oBAJO,MAAM,GAAK,CAAA,SAIlB,CAAA,OAJa;oBAKd,sBAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAC;;;oBAExB,OAAO,CAAC,IAAI,CAAC,OAAK,CAAC,CAAC;oBACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;;;;;CAElD;AA3BD,kEA2BC","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport { ContractType, getAddress } from '../utils/contractAddresses';\nimport { getGasBuffer } from '../utils/txHelpers';\nimport {\n BroadcastTransactionMetadata,\n getTransactionModuleClient,\n} from '../config';\nimport { ReyaChainId } from '@reyaxyz/common';\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 targetContract: ContractType | string,\n): Promise<\n Transaction & {\n gasLimit: bigint;\n maxPriorityFeePerGas?: bigint;\n maxFeePerGas?: bigint;\n }\n> {\n const accountAddress = await signer.getAddress();\n\n const contractAddress = Object.values(ContractType).includes(\n targetContract as ContractType,\n )\n ? getAddress(chainId, targetContract as ContractType)\n : targetContract;\n const tx = {\n from: accountAddress, // @todo Update with relayer address\n to: contractAddress,\n data,\n ...(value && value !== '0' ? { value: value } : {}),\n };\n\n let gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit if fails to get estimate\n\n try {\n const gasEstimate = await signer.estimateGas(tx);\n gasLimit = getGasBuffer(gasEstimate);\n } catch (error) {\n // sentry error & thorw\n console.warn(error);\n throw new Error('Error executing transaction'); // @todo introduce error parsing\n }\n\n if (Object.values(ReyaChainId).includes(chainId as ReyaChainId)) {\n const maxPriorityFeePerGas: bigint = BigInt('0');\n const maxFeePerGas: bigint = BigInt('0');\n return { ...tx, gasLimit, maxPriorityFeePerGas, maxFeePerGas };\n }\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 targetContract: ContractType | string,\n) {\n const txData = await estimateGas(\n signer,\n data,\n value,\n chainId,\n targetContract,\n );\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\nexport async function signAndBroadcastTransaction(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n metadata: BroadcastTransactionMetadata,\n): Promise<{ hash: string }> {\n const txData = await estimateGas(\n signer,\n data,\n value,\n chainId,\n targetContract,\n );\n try {\n const transactionModuleClient = getTransactionModuleClient();\n const { txHash } = await transactionModuleClient.executeTransaction(\n txData,\n targetContract,\n metadata,\n );\n return { hash: txHash };\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,gEAAsE;AACtE,gDAAkD;AAClD,oCAGmB;AACnB,0CAA8C;AAS9C,SAAsB,WAAW,CAC/B,MAA8B,EAC9B,IAAY,EACZ,KAAa,EACb,OAAe,EACf,cAAqC;;;;;wBAQd,qBAAM,MAAM,CAAC,UAAU,EAAE,EAAA;;oBAA1C,cAAc,GAAG,SAAyB;oBAE1C,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,gCAAY,CAAC,CAAC,QAAQ,CAC1D,cAA8B,CAC/B;wBACC,CAAC,CAAC,IAAA,8BAAU,EAAC,OAAO,EAAE,cAA8B,CAAC;wBACrD,CAAC,CAAC,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AAU,CAAC,IAAI,EAAE,EAAA;;oBAAnC,SAAS,GAAG,SAAuB;oBACzC,sBAAO,SAAS,EAAC;;;oBAEjB,OAAO,CAAC,IAAI,CAAC,OAAK,CAAC,CAAC;oBACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;;;;;CAElD;AAvBD,gDAuBC;AAED,SAAsB,2BAA2B,CAC/C,MAA8B,EAC9B,IAAY,EACZ,KAAa,EACb,OAAe,EACf,cAAqC,EACrC,QAAsC;;;;;;oBAEhC,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,gCAAY,CAAC,CAAC,QAAQ,CAC1D,cAA8B,CAC/B;wBACC,CAAC,CAAC,IAAA,8BAAU,EAAC,OAAO,EAAE,cAA8B,CAAC;wBACrD,CAAC,CAAC,cAAc,CAAC;;;;oBAEX,uBAAuB,GAAG,IAAA,mCAA0B,GAAE,CAAC;oBAC1C,qBAAM,uBAAuB,CAAC,kBAAkB,CACjE,EAAE,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,EAAE,EACnC,cAAc,EACd,QAAQ,CACT,EAAA;;oBAJO,MAAM,GAAK,CAAA,SAIlB,CAAA,OAJa;oBAKd,sBAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAC;;;oBAExB,OAAO,CAAC,IAAI,CAAC,OAAK,CAAC,CAAC;oBACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;;;;;CAElD;AAzBD,kEAyBC","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport { ContractType, getAddress } from '../utils/contractAddresses';\nimport { getGasBuffer } from '../utils/txHelpers';\nimport {\n BroadcastTransactionMetadata,\n getTransactionModuleClient,\n} from '../config';\nimport { ReyaChainId } from '@reyaxyz/common';\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 targetContract: ContractType | string,\n): Promise<\n Transaction & {\n gasLimit: bigint;\n maxPriorityFeePerGas?: bigint;\n maxFeePerGas?: bigint;\n }\n> {\n const accountAddress = await signer.getAddress();\n\n const contractAddress = Object.values(ContractType).includes(\n targetContract as ContractType,\n )\n ? getAddress(chainId, targetContract as ContractType)\n : targetContract;\n const tx = {\n from: accountAddress, // @todo Update with relayer address\n to: contractAddress,\n data,\n ...(value && value !== '0' ? { value: value } : {}),\n };\n\n let gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit if fails to get estimate\n\n try {\n const gasEstimate = await signer.estimateGas(tx);\n gasLimit = getGasBuffer(gasEstimate);\n } catch (error) {\n // sentry error & thorw\n console.warn(error);\n throw new Error('Error executing transaction'); // @todo introduce error parsing\n }\n\n if (Object.values(ReyaChainId).includes(chainId as ReyaChainId)) {\n const maxPriorityFeePerGas: bigint = BigInt('0');\n const maxFeePerGas: bigint = BigInt('0');\n return { ...tx, gasLimit, maxPriorityFeePerGas, maxFeePerGas };\n }\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 targetContract: ContractType | string,\n) {\n const txData = await estimateGas(\n signer,\n data,\n value,\n chainId,\n targetContract,\n );\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\nexport async function signAndBroadcastTransaction(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n metadata: BroadcastTransactionMetadata,\n): Promise<{ hash: string }> {\n const contractAddress = Object.values(ContractType).includes(\n targetContract as ContractType,\n )\n ? getAddress(chainId, targetContract as ContractType)\n : targetContract;\n try {\n const transactionModuleClient = getTransactionModuleClient();\n const { txHash } = await transactionModuleClient.executeTransaction(\n { to: contractAddress, data: data },\n targetContract,\n metadata,\n );\n return { hash: txHash };\n } catch (error) {\n console.warn(error);\n throw new Error('Transaction Execution Error');\n }\n}\n"]}
@@ -41,6 +41,7 @@ var common_1 = require("@reyaxyz/common");
41
41
  var contractAddresses_1 = require("../../utils/contractAddresses");
42
42
  var executeTransaction_1 = require("../executeTransaction");
43
43
  var encode_1 = require("./encode");
44
+ var common_2 = require("@reyaxyz/common");
44
45
  var bridgeAndDepositPassivePool = function (params) { return __awaiter(void 0, void 0, void 0, function () {
45
46
  var network, moneyInOutChainId, tokenInfo, amount, socketConnectors, peripheryAddress, _a, data, value, result;
46
47
  var _b;
@@ -51,6 +52,9 @@ var bridgeAndDepositPassivePool = function (params) { return __awaiter(void 0, v
51
52
  network = _c.sent();
52
53
  moneyInOutChainId = Number(network === null || network === void 0 ? void 0 : network.chainId);
53
54
  tokenInfo = (0, common_1.getTokenInfoByAddress)(params.pool.tokenAddress);
55
+ if (tokenInfo.name === 'RUSD') {
56
+ tokenInfo = (0, common_2.getTokenInfoByName)('USDC', moneyInOutChainId);
57
+ }
54
58
  amount = (0, common_1.scale)(tokenInfo.decimals)(params.amount);
55
59
  socketConnectors = (0, common_1.getSocketConnectors)({
56
60
  moneyInOutChainId: moneyInOutChainId,
@@ -1 +1 @@
1
- {"version":3,"file":"bridgeAndDepositPassivePool.js","sourceRoot":"/","sources":["services/lp/bridgeAndDepositPassivePool.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAQyB;AACzB,mEAAyE;AACzE,4DAA2D;AAC3D,mCAA6D;AAMtD,IAAM,2BAA2B,GAAG,UACzC,MAAyC;;;;;oBAEzB,qBAAM,CAAA,MAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,0CAAE,UAAU,EAAE,CAAA,EAAA;;gBAApD,OAAO,GAAG,SAA0C;gBACpD,iBAAiB,GAAsB,MAAM,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;gBAEhE,SAAS,GAAG,IAAA,8BAAqB,EAAC,M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InfoByAddress,\n getReyaNetworkFromMoneyInOutChainId,\n} from '@reyaxyz/common';\nimport { ContractType, getAddress } from '../../utils/contractAddresses';\nimport { executeTransaction } from '../executeTransaction';\nimport { encodeBridgeAndDepositPassivePool } from './encode';\nimport {\n BridgeAndDepositPassivePoolParams,\n BridgeAndDepositPassivePoolResult,\n} from './types';\n\nexport const bridgeAndDepositPassivePool = async (\n params: BridgeAndDepositPassivePoolParams,\n): Promise<BridgeAndDepositPassivePoolResult> => {\n const network = await params.signer.provider?.getNetwork();\n const moneyInOutChainId: MoneyInOutChainId = Number(network?.chainId);\n\n const tokenInfo = getTokenInfoByAddress(params.pool.tokenAddress);\n const amount = scale(tokenInfo.decimals)(params.amount);\n\n const socketConnectors = getSocketConnectors({\n moneyInOutChainId: moneyInOutChainId,\n tokenName: tokenInfo.name,\n });\n\n const peripheryAddress = getAddress(\n getReyaNetworkFromMoneyInOutChainId(moneyInOutChainId),\n ContractType.PERIPHERY_PROXY,\n );\n\n const { calldata: data, value } = encodeBridgeAndDepositPassivePool(\n peripheryAddress,\n BigInt('10000000'),\n socketConnectors.deposit,\n getSocketDepositFeesAsBigInt({\n moneyInOutChainId: moneyInOutChainId,\n }),\n params.pool.id,\n params.ownerAddress,\n amount,\n BigInt(0),\n BigInt('10000000'),\n socketConnectors.withdraw,\n );\n\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n moneyInOutChainId,\n getSocketVault({\n moneyInOutChainId: moneyInOutChainId,\n tokenName: tokenInfo.name,\n }),\n );\n\n return {\n transactionHash: result?.hash || null,\n };\n};\n"]}
1
+ {"version":3,"file":"bridgeAndDepositPassivePool.js","sourceRoot":"/","sources":["services/lp/bridgeAndDepositPassivePool.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAQyB;AACzB,mEAAyE;AACzE,4DAA2D;AAC3D,mCAA6D;AAK7D,0CAAqD;AAE9C,IAAM,2BAA2B,GAAG,UACzC,MAAyC;;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AK,EACL,iBAAiB,EACjB,IAAA,uBAAc,EAAC;wBACb,iBAAiB,EAAE,iBAAiB;wBACpC,SAAS,EAAE,SAAS,CAAC,IAAI;qBAC1B,CAAC,CACH,EAAA;;gBATK,MAAM,GAAG,SASd;gBAED,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,KAAI,IAAI;qBACtC,EAAC;;;KACH,CAAC;AArDW,QAAA,2BAA2B,+BAqDtC","sourcesContent":["import {\n getSocketDepositFeesAsBigInt,\n getSocketVault,\n scale,\n MoneyInOutChainId,\n getSocketConnectors,\n getTokenInfoByAddress,\n getReyaNetworkFromMoneyInOutChainId,\n} from '@reyaxyz/common';\nimport { ContractType, getAddress } from '../../utils/contractAddresses';\nimport { executeTransaction } from '../executeTransaction';\nimport { encodeBridgeAndDepositPassivePool } from './encode';\nimport {\n BridgeAndDepositPassivePoolParams,\n BridgeAndDepositPassivePoolResult,\n} from './types';\nimport { getTokenInfoByName } from '@reyaxyz/common';\n\nexport const bridgeAndDepositPassivePool = async (\n params: BridgeAndDepositPassivePoolParams,\n): Promise<BridgeAndDepositPassivePoolResult> => {\n const network = await params.signer.provider?.getNetwork();\n const moneyInOutChainId: MoneyInOutChainId = Number(network?.chainId);\n\n // todo: to be removed once lp form in offchain/UI is fixed\n let tokenInfo = getTokenInfoByAddress(params.pool.tokenAddress);\n if (tokenInfo.name === 'RUSD') {\n tokenInfo = getTokenInfoByName('USDC', moneyInOutChainId);\n }\n\n const amount = scale(tokenInfo.decimals)(params.amount);\n\n const socketConnectors = getSocketConnectors({\n moneyInOutChainId: moneyInOutChainId,\n tokenName: tokenInfo.name,\n });\n\n const peripheryAddress = getAddress(\n getReyaNetworkFromMoneyInOutChainId(moneyInOutChainId),\n ContractType.PERIPHERY_PROXY,\n );\n\n const { calldata: data, value } = encodeBridgeAndDepositPassivePool(\n peripheryAddress,\n BigInt('10000000'),\n socketConnectors.deposit,\n getSocketDepositFeesAsBigInt({\n moneyInOutChainId: moneyInOutChainId,\n }),\n params.pool.id,\n params.ownerAddress,\n amount,\n BigInt(0),\n BigInt('10000000'),\n socketConnectors.withdraw,\n );\n\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n moneyInOutChainId,\n getSocketVault({\n moneyInOutChainId: moneyInOutChainId,\n tokenName: tokenInfo.name,\n }),\n );\n\n return {\n transactionHash: result?.hash || null,\n };\n};\n"]}
@@ -40,20 +40,22 @@ exports.approveTokenSpending = void 0;
40
40
  var types_1 = require("./types");
41
41
  var common_1 = require("@reyaxyz/common");
42
42
  var contractAddresses_1 = require("../../utils/contractAddresses");
43
+ var common_2 = require("@reyaxyz/common");
43
44
  var approveTokenSpending = function (params) { return __awaiter(void 0, void 0, void 0, function () {
44
- var underLyingTokenAddress, network, chainId, tokenContract, tokenInfo, contractProxyAddress, maxUint256Bn, approvalTransaction, error_1, _a, error_2;
45
+ var network, chainId, tokenInfo, tokenContract, contractProxyAddress, maxUint256Bn, approvalTransaction, error_1, _a, error_2;
45
46
  var _b;
46
47
  var _c;
47
48
  return __generator(this, function (_d) {
48
49
  switch (_d.label) {
49
- case 0:
50
- underLyingTokenAddress = params.tokenAddress;
51
- return [4 /*yield*/, ((_c = params.signer.provider) === null || _c === void 0 ? void 0 : _c.getNetwork())];
50
+ case 0: return [4 /*yield*/, ((_c = params.signer.provider) === null || _c === void 0 ? void 0 : _c.getNetwork())];
52
51
  case 1:
53
52
  network = _d.sent();
54
53
  chainId = Number(network === null || network === void 0 ? void 0 : network.chainId);
55
- tokenContract = (0, common_1.getERC20TokenContract)(underLyingTokenAddress, params.signer);
56
- tokenInfo = (0, common_1.getTokenInfoByAddress)(underLyingTokenAddress);
54
+ tokenInfo = (0, common_1.getTokenInfoByAddress)(params.tokenAddress);
55
+ if (types_1.ApprovalType.BRIDGE && tokenInfo.name === 'RUSD') {
56
+ tokenInfo = (0, common_2.getTokenInfoByName)('USDC', chainId);
57
+ }
58
+ tokenContract = (0, common_1.getERC20TokenContract)(tokenInfo.address, params.signer);
57
59
  switch (params.type) {
58
60
  case types_1.ApprovalType.DEPOSIT:
59
61
  contractProxyAddress = (0, contractAddresses_1.getAddress)(chainId, contractAddresses_1.ContractType.CORE_PROXY);
@@ -64,7 +66,7 @@ var approveTokenSpending = function (params) { return __awaiter(void 0, void 0,
64
66
  case types_1.ApprovalType.BRIDGE:
65
67
  contractProxyAddress = (0, common_1.getSocketVault)({
66
68
  moneyInOutChainId: chainId,
67
- tokenName: tokenInfo.name === 'RUSD' ? 'USDC' : tokenInfo.name,
69
+ tokenName: tokenInfo.name,
68
70
  });
69
71
  break;
70
72
  default:
@@ -97,7 +99,7 @@ var approveTokenSpending = function (params) { return __awaiter(void 0, void 0,
97
99
  _b = {};
98
100
  return [4 /*yield*/, params.signer.getAddress()];
99
101
  case 7: return [4 /*yield*/, _a.apply(void 0, [(_b.walletAddress = _d.sent(),
100
- _b.tokenAddress = underLyingTokenAddress,
102
+ _b.tokenAddress = tokenInfo.address,
101
103
  _b.spenderAddress = contractProxyAddress,
102
104
  _b.subject = params.signer,
103
105
  _b)])];
@@ -1 +1 @@
1
- {"version":3,"file":"approve.js","sourceRoot":"/","sources":["services/token/approve.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA2D;AAC3D,0CAMyB;AACzB,mEAAyE;AAElE,IAAM,oBAAoB,GAAG,UAClC,MAA0B;;;;;;;gBAEpB,sBAAsB,GAAG,MAAM,CAAC,YAAY,CAAC;gBAEnC,qBAAM,CAAA,MAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,0CAAE,UAAU,EAAE,CAAA,EAAA;;gBAApD,OAAO,GAAG,SAA0C;gBACpD,OAAO,GAAG,MAAM,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;gBAEnC,aAAa,GAAG,IAAA,8BAAqB,EACzC,sBAAsB,EACtB,MAAM,CAAC,MAAM,CACd,CAAC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,KAAA,0BAAiB,CAAA;;gBACb,qBAAM,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAA;oBAD1C,qBAAM,mBACX,gBAAa,GAAE,SAAgC;wBAC/C,eAAY,GAAE,sBAAsB;wBACpC,iBAAc,GAAE,oBAAoB;wBACpC,UAAO,GAAE,MAAM,CAAC,MAAM;6BACtB,EAAA;oBALF,sBAAO,SAKL,EAAC;;;gBAEH,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;;qBAG5C,sBAAO,CAAC,EAAC;;;KACV,CAAC;AAnEW,QAAA,oBAAoB,wBAmE/B","sourcesContent":["import { ApprovalType, ApproveTokenParams } from './types';\nimport {\n getERC20Allowance,\n getERC20TokenContract,\n getSocketVault,\n GetSocketVaultParams,\n getTokenInfoByAddress,\n} from '@reyaxyz/common';\nimport { ContractType, getAddress } from '../../utils/contractAddresses';\n\nexport const approveTokenSpending = async (\n params: ApproveTokenParams,\n): Promise<number> => {\n const underLyingTokenAddress = params.tokenAddress;\n\n const network = await params.signer.provider?.getNetwork();\n const chainId = Number(network?.chainId);\n\n const tokenContract = getERC20TokenContract(\n underLyingTokenAddress,\n params.signer,\n );\n\n const tokenInfo = getTokenInfoByAddress(underLyingTokenAddress);\n\n let contractProxyAddress;\n switch (params.type) {\n case ApprovalType.DEPOSIT:\n contractProxyAddress = getAddress(chainId, ContractType.CORE_PROXY);\n break;\n case ApprovalType.LP:\n contractProxyAddress = getAddress(\n chainId,\n ContractType.PASSIVE_POOL_PROXY,\n );\n break;\n case ApprovalType.BRIDGE:\n contractProxyAddress = getSocketVault({\n moneyInOutChainId: chainId,\n tokenName: tokenInfo.name === 'RUSD' ? 'USDC' : tokenInfo.name,\n } as GetSocketVaultParams);\n break;\n default:\n throw new Error('Unexpected approval type in approveTokenSpending');\n }\n\n // @todo validate if maxAllowance should be passed from UI\n const maxUint256Bn = BigInt(\n '115792089237316195423570985008687907853269984665640564039457584007913129639935',\n );\n\n const approvalTransaction = await tokenContract\n .approve(contractProxyAddress, maxUint256Bn)\n .catch((error) => {\n console.warn('Transaction Confirmation Error');\n console.error(error);\n throw new Error('Transaction Confirmation Error');\n });\n try {\n await approvalTransaction.wait();\n } catch (error) {\n console.warn('Token approval failed');\n throw new Error('Token approval failed');\n }\n\n try {\n return await getERC20Allowance({\n walletAddress: await params.signer.getAddress(),\n tokenAddress: underLyingTokenAddress,\n spenderAddress: contractProxyAddress,\n subject: params.signer,\n });\n } catch (error) {\n console.warn('Fetching allowance failed');\n }\n\n return 0;\n};\n"]}
1
+ {"version":3,"file":"approve.js","sourceRoot":"/","sources":["services/token/approve.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA2D;AAC3D,0CAMyB;AACzB,mEAAyE;AACzE,0CAAqD;AAE9C,IAAM,oBAAoB,GAAG,UAClC,MAA0B;;;;;;oBAEV,qBAAM,CAAA,MAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,0CAAE,UAAU,EAAE,CAAA,EAAA;;gBAApD,OAAO,GAAG,SAA0C;gBACpD,OAAO,GAAG,MAAM,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;gBAGrC,SAAS,GAAG,IAAA,8BAAqB,EAAC,MAAM,CAAC,YAAY,CAAC,CAAC;gBAC3D,IAAI,oBAAY,CAAC,MAAM,IAAI,SAAS,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;oBACrD,SAAS,GAAG,IAAA,2BAAkB,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAClD,CAAC;gBAEK,aAAa,GAAG,IAAA,8BAAqB,EAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;gBAG9E,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;oBACpB,KAAK,oBAAY,CAAC,OAAO;wBACvB,oBAAoB,GAAG,IAAA,8BAAU,EAAC,OAAO,EAAE,gCAAY,CAAC,UA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AAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;;qBAG5C,sBAAO,CAAC,EAAC;;;KACV,CAAC;AAlEW,QAAA,oBAAoB,wBAkE/B","sourcesContent":["import { ApprovalType, ApproveTokenParams } from './types';\nimport {\n getERC20Allowance,\n getERC20TokenContract,\n getSocketVault,\n GetSocketVaultParams,\n getTokenInfoByAddress,\n} from '@reyaxyz/common';\nimport { ContractType, getAddress } from '../../utils/contractAddresses';\nimport { getTokenInfoByName } from '@reyaxyz/common';\n\nexport const approveTokenSpending = async (\n params: ApproveTokenParams,\n): Promise<number> => {\n const network = await params.signer.provider?.getNetwork();\n const chainId = Number(network?.chainId);\n\n // todo: to be removed once lp form in offchain/UI is fixed\n let tokenInfo = getTokenInfoByAddress(params.tokenAddress);\n if (ApprovalType.BRIDGE && tokenInfo.name === 'RUSD') {\n tokenInfo = getTokenInfoByName('USDC', chainId);\n }\n\n const tokenContract = getERC20TokenContract(tokenInfo.address, params.signer);\n\n let contractProxyAddress;\n switch (params.type) {\n case ApprovalType.DEPOSIT:\n contractProxyAddress = getAddress(chainId, ContractType.CORE_PROXY);\n break;\n case ApprovalType.LP:\n contractProxyAddress = getAddress(\n chainId,\n ContractType.PASSIVE_POOL_PROXY,\n );\n break;\n case ApprovalType.BRIDGE:\n contractProxyAddress = getSocketVault({\n moneyInOutChainId: chainId,\n tokenName: tokenInfo.name,\n } as GetSocketVaultParams);\n break;\n default:\n throw new Error('Unexpected approval type in approveTokenSpending');\n }\n\n // @todo validate if maxAllowance should be passed from UI\n const maxUint256Bn = BigInt(\n '115792089237316195423570985008687907853269984665640564039457584007913129639935',\n );\n\n const approvalTransaction = await tokenContract\n .approve(contractProxyAddress, maxUint256Bn)\n .catch((error) => {\n console.warn('Transaction Confirmation Error');\n console.error(error);\n throw new Error('Transaction Confirmation Error');\n });\n try {\n await approvalTransaction.wait();\n } catch (error) {\n console.warn('Token approval failed');\n throw new Error('Token approval failed');\n }\n\n try {\n return await getERC20Allowance({\n walletAddress: await params.signer.getAddress(),\n tokenAddress: tokenInfo.address,\n spenderAddress: contractProxyAddress,\n subject: params.signer,\n });\n } catch (error) {\n console.warn('Fetching allowance failed');\n }\n\n return 0;\n};\n"]}
@@ -40,18 +40,20 @@ exports.getAllowance = void 0;
40
40
  var types_1 = require("./types");
41
41
  var common_1 = require("@reyaxyz/common");
42
42
  var contractAddresses_1 = require("../../utils/contractAddresses");
43
+ var common_2 = require("@reyaxyz/common");
43
44
  var getAllowance = function (params) { return __awaiter(void 0, void 0, void 0, function () {
44
- var underLyingTokenAddress, network, chainId, tokenInfo, contractProxyAddress, walletAddress, allowance;
45
+ var network, chainId, tokenInfo, contractProxyAddress, walletAddress, allowance;
45
46
  var _a;
46
47
  return __generator(this, function (_b) {
47
48
  switch (_b.label) {
48
- case 0:
49
- underLyingTokenAddress = params.tokenAddress;
50
- return [4 /*yield*/, ((_a = params.signer.provider) === null || _a === void 0 ? void 0 : _a.getNetwork())];
49
+ case 0: return [4 /*yield*/, ((_a = params.signer.provider) === null || _a === void 0 ? void 0 : _a.getNetwork())];
51
50
  case 1:
52
51
  network = _b.sent();
53
52
  chainId = Number(network === null || network === void 0 ? void 0 : network.chainId);
54
- tokenInfo = (0, common_1.getTokenInfoByAddress)(underLyingTokenAddress);
53
+ tokenInfo = (0, common_1.getTokenInfoByAddress)(params.tokenAddress);
54
+ if (types_1.ApprovalType.BRIDGE && tokenInfo.name === 'RUSD') {
55
+ tokenInfo = (0, common_2.getTokenInfoByName)('USDC', chainId);
56
+ }
55
57
  switch (params.type) {
56
58
  case types_1.ApprovalType.DEPOSIT:
57
59
  contractProxyAddress = (0, contractAddresses_1.getAddress)(chainId, contractAddresses_1.ContractType.CORE_PROXY);
@@ -62,7 +64,7 @@ var getAllowance = function (params) { return __awaiter(void 0, void 0, void 0,
62
64
  case types_1.ApprovalType.BRIDGE:
63
65
  contractProxyAddress = (0, common_1.getSocketVault)({
64
66
  moneyInOutChainId: chainId,
65
- tokenName: tokenInfo.name === 'RUSD' ? 'USDC' : tokenInfo.name,
67
+ tokenName: tokenInfo.name,
66
68
  });
67
69
  break;
68
70
  default:
@@ -73,7 +75,7 @@ var getAllowance = function (params) { return __awaiter(void 0, void 0, void 0,
73
75
  walletAddress = _b.sent();
74
76
  return [4 /*yield*/, (0, common_1.getERC20Allowance)({
75
77
  walletAddress: walletAddress,
76
- tokenAddress: underLyingTokenAddress,
78
+ tokenAddress: tokenInfo.address,
77
79
  spenderAddress: contractProxyAddress,
78
80
  subject: params.signer,
79
81
  })];
@@ -1 +1 @@
1
- {"version":3,"file":"getAllowance.js","sourceRoot":"/","sources":["services/token/getAllowance.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA2D;AAC3D,0CAKyB;AACzB,mEAAyE;AAElE,IAAM,YAAY,GAAG,UAC1B,MAA0B;;;;;;gBAEpB,sBAAsB,GAAG,MAAM,CAAC,YAAY,CAAC;gBAEnC,qBAAM,CAAA,MAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,0CAAE,UAAU,EAAE,CAAA,EAAA;;gBAApD,OAAO,GAAG,SAA0C;gBACpD,OAAO,GAAG,MAAM,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;gBAEnC,SAAS,GAAG,IAAA,8BAAqB,EAAC,sBAAsB,CAAC,CAAC;gBAGhE,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;oBACpB,KAAK,oBAAY,CAAC,OAAO;wBACvB,oBAAoB,GAAG,IAAA,8BAAU,EAAC,OAAO,EAAE,gCAAY,CAAC,UAAU,CAAC,CAAC;wBACpE,MAAM;oBACR,KAAK,oBAAY,CAAC,EAAE;wBAClB,oBAAoB,GAAG,IAAA,8BAAU,EAC/B,OAAO,EACP,gCAAY,CAAC,kBAAkB,CAChC,CAAC;wBACF,MAAM;oBACR,KAAK,oBAAY,CAAC,MAAM;wBACtB,oBAAoB,GAAG,IAAA,uBAAc,EAAC;4BACpC,iBAAiB,EAAE,OAAO;4BAC1B,SAAS,EAAE,SAAS,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI;yBACvC,CAAC,CAAC;wBAC3B,MAAM;oBACR;wBACE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;gBAChE,CAAC;gBAE6B,qBAAM,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAA;;gBAAxD,aAAa,GAAW,SAAgC;gBAE5C,qBAAM,IAAA,0BAAiB,EAAC;wBACxC,aAAa,eAAA;wBACb,YAAY,EAAE,sBAAsB;wBACpC,cAAc,EAAE,oBAAoB;wBACpC,OAAO,EAAE,MAAM,CAAC,MAAM;qBACvB,CAAC,EAAA;;gBALI,SAAS,GAAG,SAKhB;gBAEF,sBAAO,SAAS,EAAC;;;KAClB,CAAC;AAzCW,QAAA,YAAY,gBAyCvB","sourcesContent":["import { ApprovalType, GetAllowanceParams } from './types';\nimport {\n GetSocketVaultParams,\n getERC20Allowance,\n getSocketVault,\n getTokenInfoByAddress,\n} from '@reyaxyz/common';\nimport { ContractType, getAddress } from '../../utils/contractAddresses';\n\nexport const getAllowance = async (\n params: GetAllowanceParams,\n): Promise<number> => {\n const underLyingTokenAddress = params.tokenAddress;\n\n const network = await params.signer.provider?.getNetwork();\n const chainId = Number(network?.chainId);\n\n const tokenInfo = getTokenInfoByAddress(underLyingTokenAddress);\n\n let contractProxyAddress;\n switch (params.type) {\n case ApprovalType.DEPOSIT:\n contractProxyAddress = getAddress(chainId, ContractType.CORE_PROXY);\n break;\n case ApprovalType.LP:\n contractProxyAddress = getAddress(\n chainId,\n ContractType.PASSIVE_POOL_PROXY,\n );\n break;\n case ApprovalType.BRIDGE:\n contractProxyAddress = getSocketVault({\n moneyInOutChainId: chainId,\n tokenName: tokenInfo.name === 'RUSD' ? 'USDC' : tokenInfo.name,\n } as GetSocketVaultParams);\n break;\n default:\n throw new Error('Unexpected approval type in getAllowance');\n }\n\n const walletAddress: string = await params.signer.getAddress();\n\n const allowance = await getERC20Allowance({\n walletAddress,\n tokenAddress: underLyingTokenAddress,\n spenderAddress: contractProxyAddress,\n subject: params.signer,\n });\n\n return allowance;\n};\n"]}
1
+ {"version":3,"file":"getAllowance.js","sourceRoot":"/","sources":["services/token/getAllowance.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA2D;AAC3D,0CAKyB;AACzB,mEAAyE;AACzE,0CAAqD;AAE9C,IAAM,YAAY,GAAG,UAC1B,MAA0B;;;;;oBAEV,qBAAM,CAAA,MAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,0CAAE,UAAU,EAAE,CAAA,EAAA;;gBAApD,OAAO,GAAG,SAA0C;gBACpD,OAAO,GAAG,MAAM,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;gBAGrC,SAAS,GAAG,IAAA,8BAAqB,EAAC,MAAM,CAAC,YAAY,CAAC,CAAC;gBAC3D,IAAI,oBAAY,CAAC,MAAM,IAAI,SAAS,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;oBACrD,SAAS,GAAG,IAAA,2BAAkB,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAClD,CAAC;gBAGD,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;oBACpB,KAAK,oBAAY,CAAC,OAAO;wBACvB,oBAAoB,GAAG,IAAA,8BAAU,EAAC,OAAO,EAAE,gCAAY,CAAC,UAAU,CAAC,CAAC;wBACpE,MAAM;oBACR,KAAK,oBAAY,CAAC,EAAE;wBAClB,oBAAoB,GAAG,IAAA,8BAAU,EAC/B,OAAO,EACP,gCAAY,CAAC,kBAAkB,CAChC,CAAC;wBACF,MAAM;oBACR,KAAK,oBAAY,CAAC,MAAM;wBACtB,oBAAoB,GAAG,IAAA,uBAAc,EAAC;4BACpC,iBAAiB,EAAE,OAAO;4BAC1B,SAAS,EAAE,SAAS,CAAC,IAAI;yBACF,CAAC,CAAC;wBAC3B,MAAM;oBACR;wBACE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;gBAChE,CAAC;gBAE6B,qBAAM,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAA;;gBAAxD,aAAa,GAAW,SAAgC;gBAE5C,qBAAM,IAAA,0BAAiB,EAAC;wBACxC,aAAa,eAAA;wBACb,YAAY,EAAE,SAAS,CAAC,OAAO;wBAC/B,cAAc,EAAE,oBAAoB;wBACpC,OAAO,EAAE,MAAM,CAAC,MAAM;qBACvB,CAAC,EAAA;;gBALI,SAAS,GAAG,SAKhB;gBAEF,sBAAO,SAAS,EAAC;;;KAClB,CAAC;AA3CW,QAAA,YAAY,gBA2CvB","sourcesContent":["import { ApprovalType, GetAllowanceParams } from './types';\nimport {\n GetSocketVaultParams,\n getERC20Allowance,\n getSocketVault,\n getTokenInfoByAddress,\n} from '@reyaxyz/common';\nimport { ContractType, getAddress } from '../../utils/contractAddresses';\nimport { getTokenInfoByName } from '@reyaxyz/common';\n\nexport const getAllowance = async (\n params: GetAllowanceParams,\n): Promise<number> => {\n const network = await params.signer.provider?.getNetwork();\n const chainId = Number(network?.chainId);\n\n // todo: to be removed once lp form in offchain/UI is fixed\n let tokenInfo = getTokenInfoByAddress(params.tokenAddress);\n if (ApprovalType.BRIDGE && tokenInfo.name === 'RUSD') {\n tokenInfo = getTokenInfoByName('USDC', chainId);\n }\n\n let contractProxyAddress;\n switch (params.type) {\n case ApprovalType.DEPOSIT:\n contractProxyAddress = getAddress(chainId, ContractType.CORE_PROXY);\n break;\n case ApprovalType.LP:\n contractProxyAddress = getAddress(\n chainId,\n ContractType.PASSIVE_POOL_PROXY,\n );\n break;\n case ApprovalType.BRIDGE:\n contractProxyAddress = getSocketVault({\n moneyInOutChainId: chainId,\n tokenName: tokenInfo.name,\n } as GetSocketVaultParams);\n break;\n default:\n throw new Error('Unexpected approval type in getAllowance');\n }\n\n const walletAddress: string = await params.signer.getAddress();\n\n const allowance = await getERC20Allowance({\n walletAddress,\n tokenAddress: tokenInfo.address,\n spenderAddress: contractProxyAddress,\n subject: params.signer,\n });\n\n return allowance;\n};\n"]}
@@ -3,13 +3,8 @@ export type BroadcastTransactionMetadata = {
3
3
  accountName?: string;
4
4
  };
5
5
  export type TxData = {
6
- from: string;
7
6
  to: string;
8
7
  data: string;
9
- value?: string;
10
- gasLimit: bigint;
11
- maxPriorityFeePerGas?: bigint;
12
- maxFeePerGas?: bigint;
13
8
  };
14
9
  export declare class TransactionModule extends RestClient {
15
10
  executeTransaction(txData: TxData, contractType: string, metadata: BroadcastTransactionMetadata): Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhF,MAAM,MAAM,4BAA4B,GAAG;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AACF,qBAAa,iBAAkB,SAAQ,UAAU;IACzC,kBAAkB,CACtB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,4BAA4B;gBAUX,MAAM;;CAUpC;AAQD,eAAO,MAAM,YAAY,gBACV,aAAa,CAAC,aAAa,CAAC,KACxC,IAGF,CAAC;AAEF,eAAO,MAAM,0BAA0B,QAAO,iBAI7C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhF,MAAM,MAAM,4BAA4B,GAAG;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AACF,qBAAa,iBAAkB,SAAQ,UAAU;IACzC,kBAAkB,CACtB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,4BAA4B;gBAGX,MAAM;;CAUpC;AAQD,eAAO,MAAM,YAAY,gBACV,aAAa,CAAC,aAAa,CAAC,KACxC,IAGF,CAAC;AAEF,eAAO,MAAM,0BAA0B,QAAO,iBAI7C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"executeTransaction.d.ts","sourceRoot":"/","sources":["services/executeTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAc,MAAM,4BAA4B,CAAC;AAEtE,OAAO,EACL,4BAA4B,EAE7B,MAAM,WAAW,CAAC;AAGnB,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,YAAY,GAAG,MAAM,GACpC,OAAO,CACR,WAAW,GAAG;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9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AAkB,CACtC,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,YAAY,GAAG,MAAM,uDAkBtC;AAED,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,YAAY,GAAG,MAAM,EACrC,QAAQ,EAAE,4BAA4B,GACrC,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAkB3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"bridgeAndDepositPassivePool.d.ts","sourceRoot":"/","sources":["services/lp/bridgeAndDepositPassivePool.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,iCAAiC,EACjC,iCAAiC,EAClC,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,2BAA2B,WAC9B,iCAAiC,KACxC,QAAQ,iCAAiC,CA8C3C,CAAC"}
1
+ {"version":3,"file":"bridgeAndDepositPassivePool.d.ts","sourceRoot":"/","sources":["services/lp/bridgeAndDepositPassivePool.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,iCAAiC,EACjC,iCAAiC,EAClC,MAAM,SAAS,CAAC;AAGjB,eAAO,MAAM,2BAA2B,WAC9B,iCAAiC,KACxC,QAAQ,iCAAiC,CAmD3C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"approve.d.ts","sourceRoot":"/","sources":["services/token/approve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAU3D,eAAO,MAAM,oBAAoB,WACvB,kBAAkB,KACzB,QAAQ,MAAM,CAiEhB,CAAC"}
1
+ {"version":3,"file":"approve.d.ts","sourceRoot":"/","sources":["services/token/approve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAW3D,eAAO,MAAM,oBAAoB,WACvB,kBAAkB,KACzB,QAAQ,MAAM,CAgEhB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getAllowance.d.ts","sourceRoot":"/","sources":["services/token/getAllowance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAS3D,eAAO,MAAM,YAAY,WACf,kBAAkB,KACzB,QAAQ,MAAM,CAuChB,CAAC"}
1
+ {"version":3,"file":"getAllowance.d.ts","sourceRoot":"/","sources":["services/token/getAllowance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAU3D,eAAO,MAAM,YAAY,WACf,kBAAkB,KACzB,QAAQ,MAAM,CAyChB,CAAC"}
@@ -23,7 +23,7 @@ var ABI_DEFINITION = (_a = {},
23
23
  _a[CommandType.MATCH_ORDER] = ['uint128[]', 'bytes'],
24
24
  _a[CommandType.PROPAGATE_CACHE_FLOW] = [],
25
25
  _a[CommandType.DUTCH_LIQUIDATION] = [],
26
- _a[CommandType.TRANSFER_MARGIN_ACCOUNT] = [],
26
+ _a[CommandType.TRANSFER_MARGIN_ACCOUNT] = ['tuple(uint128,address,uint256)'],
27
27
  _a);
28
28
  function createCommand(type, parameters, marketId, exchangeId) {
29
29
  var encodedInput = ethers_1.AbiCoder.defaultAbiCoder().encode(ABI_DEFINITION[type], parameters);
@@ -1 +1 @@
1
- {"version":3,"file":"routerCommands.js","sourceRoot":"/","sources":["utils/routerCommands.ts"],"names":[],"mappings":";;;;AAAA,iCAAkC;AAGlC;;;;GAIG;AACH,IAAY,WAOX;AAPD,WAAY,WAAW;IACrB,mDAAO,CAAA;IACP,qDAAQ,CAAA;IACR,uEAAiB,CAAA;IACjB,2DAAW,CAAA;IACX,6EAAoB,CAAA;IACpB,mFAAuB,CAAA;AACzB,CAAC,EAPW,WAAW,2BAAX,WAAW,QAOtB;AAED,IAAM,cAAc;IAClB,GAAC,WAAW,CAAC,OAAO,IAAG,CAAC,SAAS,EAAE,SAAS,CAAC;IAC7C,GAAC,WAAW,CAAC,QAAQ,IAAG,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9C,GAAC,WAAW,CAAC,WAAW,IAAG,CAAC,WAAW,EAAE,OAAO,CAAC;IACjD,GAAC,WAAW,CAAC,oBAAoB,IAAG,EAAE;IACtC,GAAC,WAAW,CAAC,iBAAiB,IAAG,EAAE;IACnC,GAAC,WAAW,CAAC,uBAAuB,IAAG,EAAE;OAC1C,CAAC;AASF,SAAgB,aAAa,CAC3B,IAAiB,EACjB,UAAqB,EACrB,QAAgB,EAChB,UAAkB;IAElB,IAAM,YAAY,GAAG,iBAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,CACpD,cAAc,CAAC,IAAI,CAAC,EACpB,UAAU,CACX,CAAC;IACF,OAAO,EAAE,IAAI,MAAA,EAAE,YAAY,cAAA,EAAE,QAAQ,UAAA,EAAE,UAAU,YAAA,EAAE,CAAC;AACtD,CAAC;AAXD,sCAWC;AAED,SAAgB,UAAU,CACxB,IAAiB,EACjB,UAAqB,EACrB,QAAgB,EAChB,UAAkB;IAElB,IAAM,OAAO,GAAG,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IACtE,OAAO;QACL,OAAO,EAAE;YACP,WAAW,EAAE,OAAO,CAAC,IAAI;YACzB,MAAM,EAAE,OAAO,CAAC,YAAY;YAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B;KACF,CAAC;AACJ,CAAC;AAfD,gCAeC","sourcesContent":["import { AbiCoder } from 'ethers';\nimport { SingleAction } from './action';\n\n/**\n * CommandTypes\n * @description Flags that modify a command's execution\n * @enum {number}\n */\nexport enum CommandType {\n DEPOSIT,\n WITHDRAW,\n DUTCH_LIQUIDATION,\n MATCH_ORDER,\n PROPAGATE_CACHE_FLOW,\n TRANSFER_MARGIN_ACCOUNT,\n}\n\nconst ABI_DEFINITION: { [key in CommandType]: string[] } = {\n [CommandType.DEPOSIT]: ['address', 'uint256'],\n [CommandType.WITHDRAW]: ['address', 'uint256'],\n [CommandType.MATCH_ORDER]: ['uint128[]', 'bytes'],\n [CommandType.PROPAGATE_CACHE_FLOW]: [], // @todo Check if correct\n [CommandType.DUTCH_LIQUIDATION]: [], // @todo update once needed\n [CommandType.TRANSFER_MARGIN_ACCOUNT]: [], // @todo update once needed\n};\n\nexport type RouterCommand = {\n type: CommandType;\n encodedInput: string;\n marketId: number;\n exchangeId: number;\n};\n\nexport function createCommand(\n type: CommandType,\n parameters: unknown[],\n marketId: number,\n exchangeId: number,\n): RouterCommand {\n const encodedInput = AbiCoder.defaultAbiCoder().encode(\n ABI_DEFINITION[type],\n parameters,\n );\n return { type, encodedInput, marketId, exchangeId };\n}\n\nexport function getCommand(\n type: CommandType,\n parameters: unknown[],\n marketId: number,\n exchangeId: number,\n): SingleAction {\n const command = createCommand(type, parameters, marketId, exchangeId);\n return {\n command: {\n commandType: command.type,\n inputs: command.encodedInput,\n marketId: command.marketId,\n exchangeId: command.exchangeId,\n },\n };\n}\n"]}
1
+ {"version":3,"file":"routerCommands.js","sourceRoot":"/","sources":["utils/routerCommands.ts"],"names":[],"mappings":";;;;AAAA,iCAAkC;AAGlC;;;;GAIG;AACH,IAAY,WAOX;AAPD,WAAY,WAAW;IACrB,mDAAO,CAAA;IACP,qDAAQ,CAAA;IACR,uEAAiB,CAAA;IACjB,2DAAW,CAAA;IACX,6EAAoB,CAAA;IACpB,mFAAuB,CAAA;AACzB,CAAC,EAPW,WAAW,2BAAX,WAAW,QAOtB;AAED,IAAM,cAAc;IAClB,GAAC,WAAW,CAAC,OAAO,IAAG,CAAC,SAAS,EAAE,SAAS,CAAC;IAC7C,GAAC,WAAW,CAAC,QAAQ,IAAG,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9C,GAAC,WAAW,CAAC,WAAW,IAAG,CAAC,WAAW,EAAE,OAAO,CAAC;IACjD,GAAC,WAAW,CAAC,oBAAoB,IAAG,EAAE;IACtC,GAAC,WAAW,CAAC,iBAAiB,IAAG,EAAE;IACnC,GAAC,WAAW,CAAC,uBAAuB,IAAG,CAAC,gCAAgC,CAAC;OAC1E,CAAC;AASF,SAAgB,aAAa,CAC3B,IAAiB,EACjB,UAAqB,EACrB,QAAgB,EAChB,UAAkB;IAElB,IAAM,YAAY,GAAG,iBAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,CACpD,cAAc,CAAC,IAAI,CAAC,EACpB,UAAU,CACX,CAAC;IACF,OAAO,EAAE,IAAI,MAAA,EAAE,YAAY,cAAA,EAAE,QAAQ,UAAA,EAAE,UAAU,YAAA,EAAE,CAAC;AACtD,CAAC;AAXD,sCAWC;AAED,SAAgB,UAAU,CACxB,IAAiB,EACjB,UAAqB,EACrB,QAAgB,EAChB,UAAkB;IAElB,IAAM,OAAO,GAAG,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IACtE,OAAO;QACL,OAAO,EAAE;YACP,WAAW,EAAE,OAAO,CAAC,IAAI;YACzB,MAAM,EAAE,OAAO,CAAC,YAAY;YAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B;KACF,CAAC;AACJ,CAAC;AAfD,gCAeC","sourcesContent":["import { AbiCoder } from 'ethers';\nimport { SingleAction } from './action';\n\n/**\n * CommandTypes\n * @description Flags that modify a command's execution\n * @enum {number}\n */\nexport enum CommandType {\n DEPOSIT,\n WITHDRAW,\n DUTCH_LIQUIDATION,\n MATCH_ORDER,\n PROPAGATE_CACHE_FLOW,\n TRANSFER_MARGIN_ACCOUNT,\n}\n\nconst ABI_DEFINITION: { [key in CommandType]: string[] } = {\n [CommandType.DEPOSIT]: ['address', 'uint256'],\n [CommandType.WITHDRAW]: ['address', 'uint256'],\n [CommandType.MATCH_ORDER]: ['uint128[]', 'bytes'],\n [CommandType.PROPAGATE_CACHE_FLOW]: [], // @todo Check if correct\n [CommandType.DUTCH_LIQUIDATION]: [], // @todo update once needed\n [CommandType.TRANSFER_MARGIN_ACCOUNT]: ['tuple(uint128,address,uint256)'], // @todo update once needed\n};\n\nexport type RouterCommand = {\n type: CommandType;\n encodedInput: string;\n marketId: number;\n exchangeId: number;\n};\n\nexport function createCommand(\n type: CommandType,\n parameters: unknown[],\n marketId: number,\n exchangeId: number,\n): RouterCommand {\n const encodedInput = AbiCoder.defaultAbiCoder().encode(\n ABI_DEFINITION[type],\n parameters,\n );\n return { type, encodedInput, marketId, exchangeId };\n}\n\nexport function getCommand(\n type: CommandType,\n parameters: unknown[],\n marketId: number,\n exchangeId: number,\n): SingleAction {\n const command = createCommand(type, parameters, marketId, exchangeId);\n return {\n command: {\n commandType: command.type,\n inputs: command.encodedInput,\n marketId: command.marketId,\n exchangeId: command.exchangeId,\n },\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/sdk",
3
- "version": "0.41.0",
3
+ "version": "0.42.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "scripts": {
17
17
  "prebuild": "rm -rf node_modules && rm -rf dist",
18
- "build": "tsc -p tsconfig.build.json",
18
+ "build": "rm -rf dist && tsc -p tsconfig.build.json",
19
19
  "ts:check-types": "npx tsc --noEmit",
20
20
  "ts:circular-check": "dpdm --no-output --no-tree --no-warning --exit-code circular:1 -T src/index.ts",
21
21
  "ts:check": "pnpm ts:check-types && pnpm ts:circular-check",
@@ -29,10 +29,10 @@
29
29
  "generate:coverage-badges": "npx istanbul-badges-readme --silent"
30
30
  },
31
31
  "dependencies": {
32
- "@reyaxyz/common": "0.49.0",
32
+ "@reyaxyz/common": "0.49.1",
33
33
  "bignumber.js": "^9.1.2",
34
34
  "ethers": "6.9.0"
35
35
  },
36
36
  "packageManager": "pnpm@8.10.4",
37
- "gitHead": "33916d67f37134f5c53d55c95753bb7ea13d4e58"
37
+ "gitHead": "89a27e4a2c7e29c5f99496218fa8f57c141da7d0"
38
38
  }
@@ -5,13 +5,8 @@ export type BroadcastTransactionMetadata = {
5
5
  };
6
6
 
7
7
  export type TxData = {
8
- from: string;
9
8
  to: string;
10
9
  data: string;
11
- value?: string;
12
- gasLimit: bigint;
13
- maxPriorityFeePerGas?: bigint;
14
- maxFeePerGas?: bigint;
15
10
  };
16
11
  export class TransactionModule extends RestClient {
17
12
  async executeTransaction(
@@ -19,19 +14,12 @@ export class TransactionModule extends RestClient {
19
14
  contractType: string,
20
15
  metadata: BroadcastTransactionMetadata,
21
16
  ) {
22
- // convert from big number
23
- const tx = {
24
- ...txData,
25
- gasLimit: String(txData.gasLimit),
26
- maxPriorityFeePerGas: String(txData.maxPriorityFeePerGas),
27
- maxFeePerGas: String(txData.maxFeePerGas),
28
- };
29
17
  const uri = `/api/transaction/execute`;
30
18
  return this.post<{ txHash: string }>(
31
19
  uri,
32
20
  {},
33
21
  {
34
- txData: tx,
22
+ txData: txData,
35
23
  contractType,
36
24
  metadata,
37
25
  },
@@ -34,7 +34,7 @@ export const encodeSingleTransferMargin = (
34
34
  multiAction.newAction(
35
35
  getCommand(
36
36
  CommandType.TRANSFER_MARGIN_ACCOUNT,
37
- [toMarginAccountId, token, amount],
37
+ [[toMarginAccountId, token, amount]],
38
38
  0,
39
39
  0,
40
40
  ),
@@ -94,17 +94,15 @@ export async function signAndBroadcastTransaction(
94
94
  targetContract: ContractType | string,
95
95
  metadata: BroadcastTransactionMetadata,
96
96
  ): Promise<{ hash: string }> {
97
- const txData = await estimateGas(
98
- signer,
99
- data,
100
- value,
101
- chainId,
102
- targetContract,
103
- );
97
+ const contractAddress = Object.values(ContractType).includes(
98
+ targetContract as ContractType,
99
+ )
100
+ ? getAddress(chainId, targetContract as ContractType)
101
+ : targetContract;
104
102
  try {
105
103
  const transactionModuleClient = getTransactionModuleClient();
106
104
  const { txHash } = await transactionModuleClient.executeTransaction(
107
- txData,
105
+ { to: contractAddress, data: data },
108
106
  targetContract,
109
107
  metadata,
110
108
  );
@@ -14,6 +14,7 @@ import {
14
14
  BridgeAndDepositPassivePoolParams,
15
15
  BridgeAndDepositPassivePoolResult,
16
16
  } from './types';
17
+ import { getTokenInfoByName } from '@reyaxyz/common';
17
18
 
18
19
  export const bridgeAndDepositPassivePool = async (
19
20
  params: BridgeAndDepositPassivePoolParams,
@@ -21,7 +22,12 @@ export const bridgeAndDepositPassivePool = async (
21
22
  const network = await params.signer.provider?.getNetwork();
22
23
  const moneyInOutChainId: MoneyInOutChainId = Number(network?.chainId);
23
24
 
24
- const tokenInfo = getTokenInfoByAddress(params.pool.tokenAddress);
25
+ // todo: to be removed once lp form in offchain/UI is fixed
26
+ let tokenInfo = getTokenInfoByAddress(params.pool.tokenAddress);
27
+ if (tokenInfo.name === 'RUSD') {
28
+ tokenInfo = getTokenInfoByName('USDC', moneyInOutChainId);
29
+ }
30
+
25
31
  const amount = scale(tokenInfo.decimals)(params.amount);
26
32
 
27
33
  const socketConnectors = getSocketConnectors({
@@ -7,21 +7,21 @@ import {
7
7
  getTokenInfoByAddress,
8
8
  } from '@reyaxyz/common';
9
9
  import { ContractType, getAddress } from '../../utils/contractAddresses';
10
+ import { getTokenInfoByName } from '@reyaxyz/common';
10
11
 
11
12
  export const approveTokenSpending = async (
12
13
  params: ApproveTokenParams,
13
14
  ): Promise<number> => {
14
- const underLyingTokenAddress = params.tokenAddress;
15
-
16
15
  const network = await params.signer.provider?.getNetwork();
17
16
  const chainId = Number(network?.chainId);
18
17
 
19
- const tokenContract = getERC20TokenContract(
20
- underLyingTokenAddress,
21
- params.signer,
22
- );
18
+ // todo: to be removed once lp form in offchain/UI is fixed
19
+ let tokenInfo = getTokenInfoByAddress(params.tokenAddress);
20
+ if (ApprovalType.BRIDGE && tokenInfo.name === 'RUSD') {
21
+ tokenInfo = getTokenInfoByName('USDC', chainId);
22
+ }
23
23
 
24
- const tokenInfo = getTokenInfoByAddress(underLyingTokenAddress);
24
+ const tokenContract = getERC20TokenContract(tokenInfo.address, params.signer);
25
25
 
26
26
  let contractProxyAddress;
27
27
  switch (params.type) {
@@ -37,7 +37,7 @@ export const approveTokenSpending = async (
37
37
  case ApprovalType.BRIDGE:
38
38
  contractProxyAddress = getSocketVault({
39
39
  moneyInOutChainId: chainId,
40
- tokenName: tokenInfo.name === 'RUSD' ? 'USDC' : tokenInfo.name,
40
+ tokenName: tokenInfo.name,
41
41
  } as GetSocketVaultParams);
42
42
  break;
43
43
  default:
@@ -66,7 +66,7 @@ export const approveTokenSpending = async (
66
66
  try {
67
67
  return await getERC20Allowance({
68
68
  walletAddress: await params.signer.getAddress(),
69
- tokenAddress: underLyingTokenAddress,
69
+ tokenAddress: tokenInfo.address,
70
70
  spenderAddress: contractProxyAddress,
71
71
  subject: params.signer,
72
72
  });
@@ -6,16 +6,19 @@ import {
6
6
  getTokenInfoByAddress,
7
7
  } from '@reyaxyz/common';
8
8
  import { ContractType, getAddress } from '../../utils/contractAddresses';
9
+ import { getTokenInfoByName } from '@reyaxyz/common';
9
10
 
10
11
  export const getAllowance = async (
11
12
  params: GetAllowanceParams,
12
13
  ): Promise<number> => {
13
- const underLyingTokenAddress = params.tokenAddress;
14
-
15
14
  const network = await params.signer.provider?.getNetwork();
16
15
  const chainId = Number(network?.chainId);
17
16
 
18
- const tokenInfo = getTokenInfoByAddress(underLyingTokenAddress);
17
+ // todo: to be removed once lp form in offchain/UI is fixed
18
+ let tokenInfo = getTokenInfoByAddress(params.tokenAddress);
19
+ if (ApprovalType.BRIDGE && tokenInfo.name === 'RUSD') {
20
+ tokenInfo = getTokenInfoByName('USDC', chainId);
21
+ }
19
22
 
20
23
  let contractProxyAddress;
21
24
  switch (params.type) {
@@ -31,7 +34,7 @@ export const getAllowance = async (
31
34
  case ApprovalType.BRIDGE:
32
35
  contractProxyAddress = getSocketVault({
33
36
  moneyInOutChainId: chainId,
34
- tokenName: tokenInfo.name === 'RUSD' ? 'USDC' : tokenInfo.name,
37
+ tokenName: tokenInfo.name,
35
38
  } as GetSocketVaultParams);
36
39
  break;
37
40
  default:
@@ -42,7 +45,7 @@ export const getAllowance = async (
42
45
 
43
46
  const allowance = await getERC20Allowance({
44
47
  walletAddress,
45
- tokenAddress: underLyingTokenAddress,
48
+ tokenAddress: tokenInfo.address,
46
49
  spenderAddress: contractProxyAddress,
47
50
  subject: params.signer,
48
51
  });
@@ -21,7 +21,7 @@ const ABI_DEFINITION: { [key in CommandType]: string[] } = {
21
21
  [CommandType.MATCH_ORDER]: ['uint128[]', 'bytes'],
22
22
  [CommandType.PROPAGATE_CACHE_FLOW]: [], // @todo Check if correct
23
23
  [CommandType.DUTCH_LIQUIDATION]: [], // @todo update once needed
24
- [CommandType.TRANSFER_MARGIN_ACCOUNT]: [], // @todo update once needed
24
+ [CommandType.TRANSFER_MARGIN_ACCOUNT]: ['tuple(uint128,address,uint256)'], // @todo update once needed
25
25
  };
26
26
 
27
27
  export type RouterCommand = {