@raac/rpc 1.1.0-beta.16 → 1.1.0-beta.18

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.
@@ -111,6 +111,11 @@ const openVaultPosition_1 = __importDefault(require("./pools/lendingPool/openVau
111
111
  const getAdapterAddress_1 = require("./pools/lendingPool/getAdapterAddress");
112
112
  const getAdapterAddress_2 = require("./pools/rwaVault/getAdapterAddress");
113
113
  const getAdapters_2 = __importDefault(require("./pools/rwaVault/getAdapters"));
114
+ const getNFTApproval_1 = __importDefault(require("./nfts/getNFTApproval"));
115
+ const getApprovalForAll_1 = __importDefault(require("./nfts/getApprovalForAll"));
116
+ const setApprovalForAll_1 = __importDefault(require("./nfts/setApprovalForAll"));
117
+ const approveNFT_1 = __importDefault(require("./nfts/approveNFT"));
118
+ const vaultOpened_1 = __importDefault(require("./pools/lendingPool/vaultOpened"));
114
119
  class RPCLibrary {
115
120
  signer;
116
121
  isConnected;
@@ -165,6 +170,10 @@ class RPCLibrary {
165
170
  getAllTokens: getAllTokens_1.default,
166
171
  getTokenURI: getTokenURI_1.default,
167
172
  getTotalPropertiesCount: getTotalPropertiesCount_1.default,
173
+ getNFTApproval: getNFTApproval_1.default,
174
+ getApprovedForAll: getApprovalForAll_1.default,
175
+ setApprovalForAll: setApprovalForAll_1.default,
176
+ approveNFT: approveNFT_1.default,
168
177
  };
169
178
  this.contracts = {
170
179
  housePrices: {
@@ -224,6 +233,7 @@ class RPCLibrary {
224
233
  openVaultPosition: openVaultPosition_1.default,
225
234
  getAdapterAddress: getAdapterAddress_1.getAdapterAddress,
226
235
  getAdapterAddressOnly: getAdapterAddress_1.getAdapterAddressOnly,
236
+ vaultOpened: vaultOpened_1.default,
227
237
  },
228
238
  // RWA Vault
229
239
  rwaVault: {
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ethers_1 = require("ethers");
4
+ const contracts_1 = require("../utils/contracts");
5
+ const artifacts_1 = require("../utils/artifacts");
6
+ async function approveNFT(chainId, nftContractName, approvedAddress, tokenId, signer) {
7
+ if (!signer) {
8
+ throw new Error("Wallet not connected");
9
+ }
10
+ try {
11
+ const nftAddress = (0, contracts_1.getContractAddress)(chainId, nftContractName);
12
+ const nftABI = (0, artifacts_1.getABI)(nftContractName);
13
+ const nftContract = new ethers_1.ethers.Contract(nftAddress, nftABI, signer);
14
+ console.log(`Approving NFT ${nftContractName} token ID ${tokenId} for ${approvedAddress}`);
15
+ const tx = await nftContract.approve(approvedAddress, tokenId);
16
+ const receipt = await tx.wait();
17
+ console.log(`Approved NFT ${nftContractName} token ID ${tokenId} for ${approvedAddress} successfully:`, receipt?.hash);
18
+ return receipt;
19
+ }
20
+ catch (error) {
21
+ console.error(`Error approving NFT ${nftContractName}:`, error);
22
+ throw new Error(`Failed to approve NFT ${nftContractName}: ${error.message}`);
23
+ }
24
+ }
25
+ exports.default = approveNFT;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ethers_1 = require("ethers");
4
+ const contracts_1 = require("../utils/contracts");
5
+ const artifacts_1 = require("../utils/artifacts");
6
+ /**
7
+ * Check if an address is approved for all tokens of an NFT contract (operator approval)
8
+ * @param chainId - The chain ID
9
+ * @param nftContractName - The NFT contract name from configs
10
+ * @param owner - The owner address
11
+ * @param operator - The operator address to check
12
+ * @param provider - The provider to use for the contract call
13
+ * @returns Boolean indicating if the operator is approved for all
14
+ */
15
+ async function getApprovedForAll(chainId, nftContractName, owner, operator, provider) {
16
+ if (!provider) {
17
+ throw new Error("Wallet not connected");
18
+ }
19
+ try {
20
+ const nftAddress = (0, contracts_1.getContractAddress)(chainId, nftContractName);
21
+ const nftABI = (0, artifacts_1.getABI)(nftContractName);
22
+ const nftContract = new ethers_1.ethers.Contract(nftAddress, nftABI, provider);
23
+ const isApproved = await nftContract.isApprovedForAll(owner, operator);
24
+ console.log(`NFT ${nftContractName}: ${operator} is ${isApproved ? 'approved' : 'not approved'} for all tokens of ${owner}`);
25
+ return isApproved;
26
+ }
27
+ catch (error) {
28
+ console.error(`Error checking NFT approval for all for ${nftContractName}:`, error);
29
+ throw new Error(`Failed to check NFT approval for all for ${nftContractName}: ${error.message}`);
30
+ }
31
+ }
32
+ exports.default = getApprovedForAll;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ethers_1 = require("ethers");
4
+ const contracts_1 = require("../utils/contracts");
5
+ const artifacts_1 = require("../utils/artifacts");
6
+ /**
7
+ * Check if an NFT token is approved for a specific address
8
+ * @param chainId - The chain ID
9
+ * @param nftContractName - The NFT contract name from configs
10
+ * @param tokenId - The token ID to check
11
+ * @param checkAddress - The address to check if it's approved
12
+ * @param provider - The provider to use for the contract call
13
+ * @returns Boolean indicating if the address is approved for the token
14
+ */
15
+ async function getNFTApproval(chainId, nftContractName, tokenId, checkAddress, provider) {
16
+ if (!provider) {
17
+ throw new Error("Wallet not connected");
18
+ }
19
+ try {
20
+ const nftAddress = (0, contracts_1.getContractAddress)(chainId, nftContractName);
21
+ const nftABI = (0, artifacts_1.getABI)(nftContractName);
22
+ const nftContract = new ethers_1.ethers.Contract(nftAddress, nftABI, provider);
23
+ const approvedAddress = await nftContract.getApproved(tokenId);
24
+ const isApproved = approvedAddress.toLowerCase() === checkAddress.toLowerCase();
25
+ console.log(`NFT ${nftContractName} token ID ${tokenId} is ${isApproved ? 'approved' : 'not approved'} for ${checkAddress}`);
26
+ return isApproved;
27
+ }
28
+ catch (error) {
29
+ console.error(`Error checking NFT approval for ${nftContractName}:`, error);
30
+ throw new Error(`Failed to check NFT approval for ${nftContractName}: ${error.message}`);
31
+ }
32
+ }
33
+ exports.default = getNFTApproval;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ethers_1 = require("ethers");
4
+ const contracts_1 = require("../utils/contracts");
5
+ const artifacts_1 = require("../utils/artifacts");
6
+ /**
7
+ * Set approval for all tokens of an NFT contract (operator approval)
8
+ * @param chainId - The chain ID
9
+ * @param nftContractName - The NFT contract name from configs
10
+ * @param operator - The operator address to approve/disapprove
11
+ * @param approved - Boolean indicating whether to approve or disapprove
12
+ * @param signer - The signer to use for the transaction
13
+ * @returns Transaction receipt
14
+ */
15
+ async function setApprovalForAll(chainId, nftContractName, operator, approved, signer) {
16
+ if (!signer) {
17
+ throw new Error("Wallet not connected");
18
+ }
19
+ try {
20
+ const nftAddress = (0, contracts_1.getContractAddress)(chainId, nftContractName);
21
+ const nftABI = (0, artifacts_1.getABI)(nftContractName);
22
+ const nftContract = new ethers_1.ethers.Contract(nftAddress, nftABI, signer);
23
+ console.log(`${approved ? 'Approving' : 'Revoking approval for'} all NFTs ${nftContractName} for operator ${operator}`);
24
+ const tx = await nftContract.setApprovalForAll(operator, approved);
25
+ const receipt = await tx.wait();
26
+ console.log(`${approved ? 'Approved' : 'Revoked approval for'} all NFTs ${nftContractName} for operator ${operator} successfully:`, receipt?.hash);
27
+ return receipt;
28
+ }
29
+ catch (error) {
30
+ console.error(`Error setting approval for all NFTs ${nftContractName}:`, error);
31
+ throw new Error(`Failed to set approval for all NFTs ${nftContractName}: ${error.message}`);
32
+ }
33
+ }
34
+ exports.default = setApprovalForAll;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const _helpers_1 = require("./_helpers");
4
+ /**
5
+ * @description Check if the vault position is opened for a given address in the lending pool
6
+ * @param chainId - The chain ID
7
+ * @param address - The user address to check
8
+ * @param provider - The provider to use for the blockchain call
9
+ * @returns Promise<boolean> - True if vault position is opened, false otherwise
10
+ */
11
+ async function vaultOpened(chainId, address, provider) {
12
+ try {
13
+ const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, provider);
14
+ const isVaultOpened = await lendingPoolContract.vaultOpened(address);
15
+ return isVaultOpened;
16
+ }
17
+ catch (error) {
18
+ console.error("Error in vaultOpened:", error);
19
+ throw error;
20
+ }
21
+ }
22
+ exports.default = vaultOpened;
@@ -16,9 +16,12 @@ async function withdrawFromLendingPool(chainId, amount, signer) {
16
16
  if (userBalance < parseFloat(amount)) {
17
17
  throw new Error(`Insufficient rToken balance. Available: ${ethers_1.ethers.formatEther(userBalance)}, Requested: ${ethers_1.ethers.formatEther(amount)}`);
18
18
  }
19
- const approveTx = await rTokenContract.approve(await lendingPoolContract.getAddress(), amountInWei);
20
- await approveTx.wait();
21
- console.log(`Approved LendingPool to spend ${amount} rToken`);
19
+ // const approveTx = await rTokenContract.approve(
20
+ // await lendingPoolContract.getAddress(),
21
+ // amountInWei
22
+ // );
23
+ // await approveTx.wait();
24
+ // console.log(`Approved LendingPool to spend ${amount} rToken`);
22
25
  // const withdraw = await lendingPoolContract.withdraw(amountInWei.toString(), {
23
26
  // maxFeePerGas,
24
27
  // nonce: await signer.getNonce()
@@ -86,6 +86,11 @@ import openVaultPosition from "./pools/lendingPool/openVaultPosition";
86
86
  import { getAdapterAddress as getLendingPoolAdapterAddress, getAdapterAddressOnly as getLendingPoolAdapterAddressOnly } from "./pools/lendingPool/getAdapterAddress";
87
87
  import { getAdapterAddress as getRWAVaultAdapterAddress, getAdapterAddressOnly as getRWAVaultAdapterAddressOnly } from "./pools/rwaVault/getAdapterAddress";
88
88
  import getRWAVaultAdapters from "./pools/rwaVault/getAdapters";
89
+ import getNFTApproval from "./nfts/getNFTApproval";
90
+ import getApprovedForAll from "./nfts/getApprovalForAll";
91
+ import setApprovalForAll from "./nfts/setApprovalForAll";
92
+ import approveNFT from "./nfts/approveNFT";
93
+ import vaultOpened from "./pools/lendingPool/vaultOpened";
89
94
  declare class RPCLibrary {
90
95
  signer: Signer | null;
91
96
  isConnected: boolean;
@@ -121,6 +126,10 @@ declare class RPCLibrary {
121
126
  getAllTokens: typeof getAllTokens;
122
127
  getTokenURI: typeof getTokenURI;
123
128
  getTotalPropertiesCount: typeof getTotalPropertiesCount;
129
+ getNFTApproval: typeof getNFTApproval;
130
+ getApprovedForAll: typeof getApprovedForAll;
131
+ setApprovalForAll: typeof setApprovalForAll;
132
+ approveNFT: typeof approveNFT;
124
133
  };
125
134
  contracts: {
126
135
  housePrices: {
@@ -177,6 +186,7 @@ declare class RPCLibrary {
177
186
  openVaultPosition: typeof openVaultPosition;
178
187
  getAdapterAddress: typeof getLendingPoolAdapterAddress;
179
188
  getAdapterAddressOnly: typeof getLendingPoolAdapterAddressOnly;
189
+ vaultOpened: typeof vaultOpened;
180
190
  };
181
191
  rwaVault: {
182
192
  depositToRWAVault: typeof depositToRWAVault;
@@ -0,0 +1,9 @@
1
+ import { ethers, Signer } from "ethers";
2
+ import { ChainId } from "../configs/chains/index";
3
+ import { configs } from "../configs/chains";
4
+ type NftContractNames = {
5
+ [K in keyof typeof configs]: keyof (typeof configs)[K]['nfts'];
6
+ }[keyof typeof configs];
7
+ declare function approveNFT(chainId: ChainId, nftContractName: NftContractNames, approvedAddress: string, tokenId: string, signer: Signer): Promise<ethers.ContractTransactionReceipt>;
8
+ export default approveNFT;
9
+ export type { NftContractNames };
@@ -0,0 +1,14 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../configs/chains/index";
3
+ import { NftContractNames } from "./approveNFT";
4
+ /**
5
+ * Check if an address is approved for all tokens of an NFT contract (operator approval)
6
+ * @param chainId - The chain ID
7
+ * @param nftContractName - The NFT contract name from configs
8
+ * @param owner - The owner address
9
+ * @param operator - The operator address to check
10
+ * @param provider - The provider to use for the contract call
11
+ * @returns Boolean indicating if the operator is approved for all
12
+ */
13
+ declare function getApprovedForAll(chainId: ChainId, nftContractName: NftContractNames, owner: string, operator: string, provider: Provider): Promise<boolean>;
14
+ export default getApprovedForAll;
@@ -0,0 +1,14 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../configs/chains/index";
3
+ import { NftContractNames } from "./approveNFT";
4
+ /**
5
+ * Check if an NFT token is approved for a specific address
6
+ * @param chainId - The chain ID
7
+ * @param nftContractName - The NFT contract name from configs
8
+ * @param tokenId - The token ID to check
9
+ * @param checkAddress - The address to check if it's approved
10
+ * @param provider - The provider to use for the contract call
11
+ * @returns Boolean indicating if the address is approved for the token
12
+ */
13
+ declare function getNFTApproval(chainId: ChainId, nftContractName: NftContractNames, tokenId: string, checkAddress: string, provider: Provider): Promise<boolean>;
14
+ export default getNFTApproval;
@@ -0,0 +1,14 @@
1
+ import { ethers, Signer } from "ethers";
2
+ import { ChainId } from "../configs/chains/index";
3
+ import { NftContractNames } from "./approveNFT";
4
+ /**
5
+ * Set approval for all tokens of an NFT contract (operator approval)
6
+ * @param chainId - The chain ID
7
+ * @param nftContractName - The NFT contract name from configs
8
+ * @param operator - The operator address to approve/disapprove
9
+ * @param approved - Boolean indicating whether to approve or disapprove
10
+ * @param signer - The signer to use for the transaction
11
+ * @returns Transaction receipt
12
+ */
13
+ declare function setApprovalForAll(chainId: ChainId, nftContractName: NftContractNames, operator: string, approved: boolean, signer: Signer): Promise<ethers.ContractTransactionReceipt>;
14
+ export default setApprovalForAll;
@@ -0,0 +1,11 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../../configs/chains";
3
+ /**
4
+ * @description Check if the vault position is opened for a given address in the lending pool
5
+ * @param chainId - The chain ID
6
+ * @param address - The user address to check
7
+ * @param provider - The provider to use for the blockchain call
8
+ * @returns Promise<boolean> - True if vault position is opened, false otherwise
9
+ */
10
+ declare function vaultOpened(chainId: ChainId, address: string, provider: Provider): Promise<boolean>;
11
+ export default vaultOpened;
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raac/rpc",
3
- "version": "1.1.0-beta.16",
3
+ "version": "1.1.0-beta.18",
4
4
  "description": "RPC Library for RAAC ",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",