@raac/rpc 1.1.0-beta.15 → 1.1.0-beta.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/RPCLibrary.js +8 -0
- package/dist/nfts/approveNFT.js +25 -0
- package/dist/nfts/getApprovalForAll.js +32 -0
- package/dist/nfts/getNFTApproval.js +33 -0
- package/dist/nfts/setApprovalForAll.js +34 -0
- package/dist/pools/lendingPool/withdrawFromLendingPool.js +6 -3
- package/dist/types/RPCLibrary.d.ts +8 -0
- package/dist/types/nfts/approveNFT.d.ts +9 -0
- package/dist/types/nfts/getApprovalForAll.d.ts +14 -0
- package/dist/types/nfts/getNFTApproval.d.ts +14 -0
- package/dist/types/nfts/setApprovalForAll.d.ts +14 -0
- package/dist/types/wallet/assets/approveNFT.d.ts +0 -0
- package/dist/wallet/assets/approveNFT.js +0 -0
- package/package.json +1 -1
package/dist/RPCLibrary.js
CHANGED
|
@@ -111,6 +111,10 @@ 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"));
|
|
114
118
|
class RPCLibrary {
|
|
115
119
|
signer;
|
|
116
120
|
isConnected;
|
|
@@ -165,6 +169,10 @@ class RPCLibrary {
|
|
|
165
169
|
getAllTokens: getAllTokens_1.default,
|
|
166
170
|
getTokenURI: getTokenURI_1.default,
|
|
167
171
|
getTotalPropertiesCount: getTotalPropertiesCount_1.default,
|
|
172
|
+
getNFTApproval: getNFTApproval_1.default,
|
|
173
|
+
getApprovedForAll: getApprovalForAll_1.default,
|
|
174
|
+
setApprovalForAll: setApprovalForAll_1.default,
|
|
175
|
+
approveNFT: approveNFT_1.default,
|
|
168
176
|
};
|
|
169
177
|
this.contracts = {
|
|
170
178
|
housePrices: {
|
|
@@ -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;
|
|
@@ -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(
|
|
20
|
-
await
|
|
21
|
-
|
|
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,10 @@ 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";
|
|
89
93
|
declare class RPCLibrary {
|
|
90
94
|
signer: Signer | null;
|
|
91
95
|
isConnected: boolean;
|
|
@@ -121,6 +125,10 @@ declare class RPCLibrary {
|
|
|
121
125
|
getAllTokens: typeof getAllTokens;
|
|
122
126
|
getTokenURI: typeof getTokenURI;
|
|
123
127
|
getTotalPropertiesCount: typeof getTotalPropertiesCount;
|
|
128
|
+
getNFTApproval: typeof getNFTApproval;
|
|
129
|
+
getApprovedForAll: typeof getApprovedForAll;
|
|
130
|
+
setApprovalForAll: typeof setApprovalForAll;
|
|
131
|
+
approveNFT: typeof approveNFT;
|
|
124
132
|
};
|
|
125
133
|
contracts: {
|
|
126
134
|
housePrices: {
|
|
@@ -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 | string>;
|
|
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;
|
|
File without changes
|
|
File without changes
|