@primuslabs/fund-js-sdk 0.1.5 → 0.1.6

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/index.d.mts CHANGED
@@ -34,10 +34,11 @@ declare global {
34
34
  //
35
35
  // ERC20_TYPE = 0;
36
36
  // NATIVE_TYPE = 1;
37
- type TokenType = 0 | 1
38
- type TokenInfo =
39
- | { tokenType: 0; tokenAddress: string }
40
- | { tokenType: 1; tokenAddress?: string };
37
+ // ERC721_TYPE = 2;
38
+ type TokenType = 0 | 1 | 2
39
+ type TokenInfo = { tokenType: 0; tokenAddress: string }
40
+ | { tokenType: 1; tokenAddress?: string }
41
+ | { tokenType: 2; tokenAddress: string };
41
42
 
42
43
  type RecipientBaseInfo = {
43
44
  socialPlatform: string;// The name of the social platform.
package/dist/index.d.ts CHANGED
@@ -34,10 +34,11 @@ declare global {
34
34
  //
35
35
  // ERC20_TYPE = 0;
36
36
  // NATIVE_TYPE = 1;
37
- type TokenType = 0 | 1
38
- type TokenInfo =
39
- | { tokenType: 0; tokenAddress: string }
40
- | { tokenType: 1; tokenAddress?: string };
37
+ // ERC721_TYPE = 2;
38
+ type TokenType = 0 | 1 | 2
39
+ type TokenInfo = { tokenType: 0; tokenAddress: string }
40
+ | { tokenType: 1; tokenAddress?: string }
41
+ | { tokenType: 2; tokenAddress: string };
41
42
 
42
43
  type RecipientBaseInfo = {
43
44
  socialPlatform: string;// The name of the social platform.
package/dist/index.js CHANGED
@@ -154,15 +154,15 @@ var Contract = class {
154
154
  if (error?.code === "ACTION_REJECTED" || isUserRejected) {
155
155
  return reject("user rejected transaction");
156
156
  }
157
+ const isNoPendingWithdrawals = hasErrorFlagFn(curErrorStrArr, ["no pending withdrawals"]);
158
+ if (isNoPendingWithdrawals) {
159
+ return reject("no pending withdrawals");
160
+ }
157
161
  const insufficientBalanceErrStrArr = ["insufficient balance", "unpredictable_gas_limit"];
158
162
  const isInsufficientBalance = hasErrorFlagFn(curErrorStrArr, insufficientBalanceErrStrArr);
159
163
  if (isInsufficientBalance) {
160
164
  return reject("insufficient balance");
161
165
  }
162
- const isNoPendingWithdrawals = hasErrorFlagFn(curErrorStrArr, ["no pending withdrawals"]);
163
- if (isNoPendingWithdrawals) {
164
- return reject("no pending withdrawals");
165
- }
166
166
  return reject(error);
167
167
  }
168
168
  });
@@ -1157,6 +1157,190 @@ var erc20Abi_default = [
1157
1157
  }
1158
1158
  ];
1159
1159
 
1160
+ // src/config/erc721Abi.json
1161
+ var erc721Abi_default = [
1162
+ {
1163
+ type: "function",
1164
+ name: "supportsInterface",
1165
+ stateMutability: "view",
1166
+ inputs: [
1167
+ { internalType: "bytes4", name: "interfaceId", type: "bytes4" }
1168
+ ],
1169
+ outputs: [{ internalType: "bool", name: "", type: "bool" }]
1170
+ },
1171
+ {
1172
+ type: "function",
1173
+ name: "balanceOf",
1174
+ stateMutability: "view",
1175
+ inputs: [
1176
+ { internalType: "address", name: "owner", type: "address" }
1177
+ ],
1178
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }]
1179
+ },
1180
+ {
1181
+ type: "function",
1182
+ name: "ownerOf",
1183
+ stateMutability: "view",
1184
+ inputs: [
1185
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1186
+ ],
1187
+ outputs: [{ internalType: "address", name: "", type: "address" }]
1188
+ },
1189
+ {
1190
+ type: "function",
1191
+ name: "tokenURI",
1192
+ stateMutability: "view",
1193
+ inputs: [
1194
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1195
+ ],
1196
+ outputs: [{ internalType: "string", name: "", type: "string" }]
1197
+ },
1198
+ {
1199
+ type: "function",
1200
+ name: "approve",
1201
+ stateMutability: "nonpayable",
1202
+ inputs: [
1203
+ { internalType: "address", name: "to", type: "address" },
1204
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1205
+ ],
1206
+ outputs: []
1207
+ },
1208
+ {
1209
+ type: "function",
1210
+ name: "getApproved",
1211
+ stateMutability: "view",
1212
+ inputs: [
1213
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1214
+ ],
1215
+ outputs: [{ internalType: "address", name: "", type: "address" }]
1216
+ },
1217
+ {
1218
+ type: "function",
1219
+ name: "setApprovalForAll",
1220
+ stateMutability: "nonpayable",
1221
+ inputs: [
1222
+ { internalType: "address", name: "operator", type: "address" },
1223
+ { internalType: "bool", name: "approved", type: "bool" }
1224
+ ],
1225
+ outputs: []
1226
+ },
1227
+ {
1228
+ type: "function",
1229
+ name: "isApprovedForAll",
1230
+ stateMutability: "view",
1231
+ inputs: [
1232
+ { internalType: "address", name: "owner", type: "address" },
1233
+ { internalType: "address", name: "operator", type: "address" }
1234
+ ],
1235
+ outputs: [{ internalType: "bool", name: "", type: "bool" }]
1236
+ },
1237
+ {
1238
+ type: "function",
1239
+ name: "transferFrom",
1240
+ stateMutability: "nonpayable",
1241
+ inputs: [
1242
+ { internalType: "address", name: "from", type: "address" },
1243
+ { internalType: "address", name: "to", type: "address" },
1244
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1245
+ ],
1246
+ outputs: []
1247
+ },
1248
+ {
1249
+ type: "function",
1250
+ name: "safeTransferFrom",
1251
+ stateMutability: "nonpayable",
1252
+ inputs: [
1253
+ { internalType: "address", name: "from", type: "address" },
1254
+ { internalType: "address", name: "to", type: "address" },
1255
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1256
+ ],
1257
+ outputs: []
1258
+ },
1259
+ {
1260
+ type: "function",
1261
+ name: "name",
1262
+ stateMutability: "view",
1263
+ inputs: [],
1264
+ outputs: [{ internalType: "string", name: "", type: "string" }]
1265
+ },
1266
+ {
1267
+ type: "function",
1268
+ name: "symbol",
1269
+ stateMutability: "view",
1270
+ inputs: [],
1271
+ outputs: [{ internalType: "string", name: "", type: "string" }]
1272
+ }
1273
+ ];
1274
+
1275
+ // src/classes/Erc721Contract.ts
1276
+ var Erc721Contract = class {
1277
+ contractInstance;
1278
+ constructor(provider, address) {
1279
+ if (!provider || !address) {
1280
+ throw new Error("provider, address are required");
1281
+ }
1282
+ this.contractInstance = new Contract_default(provider, address, erc721Abi_default);
1283
+ }
1284
+ async approve(address, tokenId) {
1285
+ return new Promise(async (resolve, reject) => {
1286
+ try {
1287
+ const approver = await this.contractInstance.callMethod("getApproved", [tokenId]);
1288
+ if (approver === address) {
1289
+ console.log(`Already approved:: ${approver}`);
1290
+ resolve("Approved");
1291
+ } else {
1292
+ await this.contractInstance.sendTransaction("approve", [address, tokenId]);
1293
+ console.log(`Approved`);
1294
+ resolve("Approved");
1295
+ }
1296
+ } catch (error) {
1297
+ console.error("Approval failed:", error);
1298
+ return reject(error);
1299
+ }
1300
+ });
1301
+ }
1302
+ // ownerAddress: string,
1303
+ async setApprovalForAll(operatorAddress) {
1304
+ return new Promise(async (resolve, reject) => {
1305
+ try {
1306
+ await this.contractInstance.sendTransaction("setApprovalForAll", [operatorAddress, true]);
1307
+ console.log(`Approved`);
1308
+ resolve("Approved");
1309
+ } catch (error) {
1310
+ console.error("Approval failed:", error);
1311
+ return reject(error);
1312
+ }
1313
+ });
1314
+ }
1315
+ async fetchMetaData(nftContractAddress, tokenId) {
1316
+ return new Promise(async (resolve, reject) => {
1317
+ try {
1318
+ let url = await this.contractInstance.callMethod("tokenURI", [tokenId]);
1319
+ if (url.startsWith("ipfs://")) {
1320
+ url = url.replace("ipfs://", "https://ipfs.io/ipfs/");
1321
+ }
1322
+ const res = await fetch(url);
1323
+ if (!res.ok) {
1324
+ return reject(`Failed to fetch metadata from ${url}`);
1325
+ }
1326
+ let metadata = await res.json();
1327
+ if (metadata.image && metadata.image.startsWith("ipfs://")) {
1328
+ metadata.image = metadata.image.replace(
1329
+ "ipfs://",
1330
+ "https://ipfs.io/ipfs/"
1331
+ );
1332
+ }
1333
+ metadata.address = nftContractAddress;
1334
+ metadata.tokenId = tokenId;
1335
+ return resolve(metadata);
1336
+ } catch (error) {
1337
+ return reject(error);
1338
+ }
1339
+ });
1340
+ }
1341
+ };
1342
+ var Erc721Contract_default = Erc721Contract;
1343
+
1160
1344
  // src/classes/Fund.ts
1161
1345
  var { parseUnits, formatUnits } = import_ethers2.ethers.utils;
1162
1346
  var Fund = class {
@@ -1220,18 +1404,22 @@ var Fund = class {
1220
1404
  const web3Provider = new import_ethers2.ethers.providers.Web3Provider(this.provider);
1221
1405
  const erc20Contract = new import_ethers2.ethers.Contract(tokenInfo.tokenAddress, erc20Abi_default, web3Provider);
1222
1406
  decimals = await erc20Contract.decimals();
1407
+ } else if (tokenInfo.tokenType === 2) {
1408
+ decimals = 0;
1409
+ const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenInfo.tokenAddress);
1410
+ await erc721ContractInstance.approve(this.fundContract.address, recipientInfo.nftIds[0]);
1223
1411
  }
1224
1412
  const tokenAmount = parseUnits(recipientInfo.tokenAmount.toString(), decimals);
1225
1413
  const newFundRecipientInfo = {
1226
1414
  idSource: recipientInfo.socialPlatform,
1227
1415
  id: recipientInfo.userIdentifier,
1228
1416
  amount: tokenAmount,
1229
- nftIds: []
1417
+ nftIds: recipientInfo.nftIds
1230
1418
  };
1231
- if (tokenInfo.tokenType === 0) {
1232
- params = [tokenInfo, newFundRecipientInfo];
1233
- } else {
1419
+ if (tokenInfo.tokenType === 1) {
1234
1420
  params = [tokenInfo, newFundRecipientInfo, { value: tokenAmount }];
1421
+ } else {
1422
+ params = [tokenInfo, newFundRecipientInfo];
1235
1423
  }
1236
1424
  const result = await this.fundContract.sendTransaction("tip", params);
1237
1425
  resolve(result);
@@ -1267,6 +1455,10 @@ var Fund = class {
1267
1455
  const web3Provider = new import_ethers2.ethers.providers.Web3Provider(this.provider);
1268
1456
  const erc20Contract = new import_ethers2.ethers.Contract(tokenInfo.tokenAddress, erc20Abi_default, web3Provider);
1269
1457
  decimals = await erc20Contract.decimals();
1458
+ } else if (tokenInfo.tokenType === 2) {
1459
+ decimals = 0;
1460
+ const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenInfo.tokenAddress);
1461
+ await erc721ContractInstance.setApprovalForAll(this.fundContract.address);
1270
1462
  }
1271
1463
  let totalFormatAmount = recipientInfoList.reduce((acc, cur) => acc.add(parseUnits(cur.tokenAmount.toString(), decimals)), import_ethers2.ethers.BigNumber.from(0));
1272
1464
  const newRecipientInfoList = recipientInfoList.map((i) => {
@@ -1275,13 +1467,13 @@ var Fund = class {
1275
1467
  idSource: i.socialPlatform,
1276
1468
  id: i.userIdentifier,
1277
1469
  amount: formatAmount,
1278
- nftIds: []
1470
+ nftIds: i.nftIds
1279
1471
  };
1280
1472
  });
1281
- if (tokenInfo.tokenType === 0) {
1282
- params = [tokenInfo, newRecipientInfoList];
1283
- } else {
1473
+ if (tokenInfo.tokenType === 1) {
1284
1474
  params = [tokenInfo, newRecipientInfoList, { value: totalFormatAmount }];
1475
+ } else {
1476
+ params = [tokenInfo, newRecipientInfoList];
1285
1477
  }
1286
1478
  const result = await this.fundContract.sendTransaction("tipBatch", params);
1287
1479
  return resolve(result);
@@ -1424,9 +1616,11 @@ var Fund = class {
1424
1616
  console.log("fundRecords", fundRecords);
1425
1617
  let formatRecords = [];
1426
1618
  for (const record of fundRecords) {
1427
- const { tipper, timestamp, tipToken: [tokenType, tokenAddress], amount } = record;
1619
+ const { tipper, timestamp, tipToken: [tokenType, tokenAddress], amount, nftIds } = record;
1428
1620
  let decimals = 18;
1429
1621
  let symbol = "";
1622
+ let tokenId = null;
1623
+ let nftInfo = null;
1430
1624
  if (tokenType === 0) {
1431
1625
  let formatProvider;
1432
1626
  if (this.provider instanceof import_ethers2.ethers.providers.JsonRpcProvider) {
@@ -1439,6 +1633,11 @@ var Fund = class {
1439
1633
  symbol = await erc20Contract.symbol();
1440
1634
  } else if (tokenType === 1) {
1441
1635
  symbol = NATIVETOKENS[this.chainId];
1636
+ } else if (tokenType === 2) {
1637
+ decimals = 0;
1638
+ tokenId = parseInt(nftIds[0]);
1639
+ const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenAddress);
1640
+ nftInfo = await erc721ContractInstance.fetchMetaData(tokenAddress, tokenId);
1442
1641
  }
1443
1642
  let fundToken = {
1444
1643
  tokenType,
@@ -1450,11 +1649,14 @@ var Fund = class {
1450
1649
  if (tokenType === 0) {
1451
1650
  fundToken.tokenAddress = tokenAddress;
1452
1651
  }
1652
+ if (tokenType === 2) {
1653
+ Object.assign(fundToken, nftInfo ?? {});
1654
+ }
1453
1655
  formatRecords.push({
1454
1656
  funder: tipper,
1455
1657
  fundToken,
1456
1658
  amount: formatUnits(amount, decimals),
1457
- timestamp: timestamp.toNumber() * 1e3
1659
+ timestamp: timestamp.toNumber()
1458
1660
  });
1459
1661
  }
1460
1662
  console.log("formatRecords", formatRecords);
@@ -1506,7 +1708,7 @@ var PrimusFund = class {
1506
1708
  formatUserIdentifier = i.userIdentifier.slice(1);
1507
1709
  }
1508
1710
  return {
1509
- nftIds: [],
1711
+ nftIds: i.nftIds ?? [],
1510
1712
  socialPlatform: formatSocialPlatform,
1511
1713
  userIdentifier: formatUserIdentifier,
1512
1714
  tokenAmount: i.tokenAmount
package/dist/index.mjs CHANGED
@@ -130,15 +130,15 @@ var Contract = class {
130
130
  if (error?.code === "ACTION_REJECTED" || isUserRejected) {
131
131
  return reject("user rejected transaction");
132
132
  }
133
+ const isNoPendingWithdrawals = hasErrorFlagFn(curErrorStrArr, ["no pending withdrawals"]);
134
+ if (isNoPendingWithdrawals) {
135
+ return reject("no pending withdrawals");
136
+ }
133
137
  const insufficientBalanceErrStrArr = ["insufficient balance", "unpredictable_gas_limit"];
134
138
  const isInsufficientBalance = hasErrorFlagFn(curErrorStrArr, insufficientBalanceErrStrArr);
135
139
  if (isInsufficientBalance) {
136
140
  return reject("insufficient balance");
137
141
  }
138
- const isNoPendingWithdrawals = hasErrorFlagFn(curErrorStrArr, ["no pending withdrawals"]);
139
- if (isNoPendingWithdrawals) {
140
- return reject("no pending withdrawals");
141
- }
142
142
  return reject(error);
143
143
  }
144
144
  });
@@ -1133,6 +1133,190 @@ var erc20Abi_default = [
1133
1133
  }
1134
1134
  ];
1135
1135
 
1136
+ // src/config/erc721Abi.json
1137
+ var erc721Abi_default = [
1138
+ {
1139
+ type: "function",
1140
+ name: "supportsInterface",
1141
+ stateMutability: "view",
1142
+ inputs: [
1143
+ { internalType: "bytes4", name: "interfaceId", type: "bytes4" }
1144
+ ],
1145
+ outputs: [{ internalType: "bool", name: "", type: "bool" }]
1146
+ },
1147
+ {
1148
+ type: "function",
1149
+ name: "balanceOf",
1150
+ stateMutability: "view",
1151
+ inputs: [
1152
+ { internalType: "address", name: "owner", type: "address" }
1153
+ ],
1154
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }]
1155
+ },
1156
+ {
1157
+ type: "function",
1158
+ name: "ownerOf",
1159
+ stateMutability: "view",
1160
+ inputs: [
1161
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1162
+ ],
1163
+ outputs: [{ internalType: "address", name: "", type: "address" }]
1164
+ },
1165
+ {
1166
+ type: "function",
1167
+ name: "tokenURI",
1168
+ stateMutability: "view",
1169
+ inputs: [
1170
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1171
+ ],
1172
+ outputs: [{ internalType: "string", name: "", type: "string" }]
1173
+ },
1174
+ {
1175
+ type: "function",
1176
+ name: "approve",
1177
+ stateMutability: "nonpayable",
1178
+ inputs: [
1179
+ { internalType: "address", name: "to", type: "address" },
1180
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1181
+ ],
1182
+ outputs: []
1183
+ },
1184
+ {
1185
+ type: "function",
1186
+ name: "getApproved",
1187
+ stateMutability: "view",
1188
+ inputs: [
1189
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1190
+ ],
1191
+ outputs: [{ internalType: "address", name: "", type: "address" }]
1192
+ },
1193
+ {
1194
+ type: "function",
1195
+ name: "setApprovalForAll",
1196
+ stateMutability: "nonpayable",
1197
+ inputs: [
1198
+ { internalType: "address", name: "operator", type: "address" },
1199
+ { internalType: "bool", name: "approved", type: "bool" }
1200
+ ],
1201
+ outputs: []
1202
+ },
1203
+ {
1204
+ type: "function",
1205
+ name: "isApprovedForAll",
1206
+ stateMutability: "view",
1207
+ inputs: [
1208
+ { internalType: "address", name: "owner", type: "address" },
1209
+ { internalType: "address", name: "operator", type: "address" }
1210
+ ],
1211
+ outputs: [{ internalType: "bool", name: "", type: "bool" }]
1212
+ },
1213
+ {
1214
+ type: "function",
1215
+ name: "transferFrom",
1216
+ stateMutability: "nonpayable",
1217
+ inputs: [
1218
+ { internalType: "address", name: "from", type: "address" },
1219
+ { internalType: "address", name: "to", type: "address" },
1220
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1221
+ ],
1222
+ outputs: []
1223
+ },
1224
+ {
1225
+ type: "function",
1226
+ name: "safeTransferFrom",
1227
+ stateMutability: "nonpayable",
1228
+ inputs: [
1229
+ { internalType: "address", name: "from", type: "address" },
1230
+ { internalType: "address", name: "to", type: "address" },
1231
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1232
+ ],
1233
+ outputs: []
1234
+ },
1235
+ {
1236
+ type: "function",
1237
+ name: "name",
1238
+ stateMutability: "view",
1239
+ inputs: [],
1240
+ outputs: [{ internalType: "string", name: "", type: "string" }]
1241
+ },
1242
+ {
1243
+ type: "function",
1244
+ name: "symbol",
1245
+ stateMutability: "view",
1246
+ inputs: [],
1247
+ outputs: [{ internalType: "string", name: "", type: "string" }]
1248
+ }
1249
+ ];
1250
+
1251
+ // src/classes/Erc721Contract.ts
1252
+ var Erc721Contract = class {
1253
+ contractInstance;
1254
+ constructor(provider, address) {
1255
+ if (!provider || !address) {
1256
+ throw new Error("provider, address are required");
1257
+ }
1258
+ this.contractInstance = new Contract_default(provider, address, erc721Abi_default);
1259
+ }
1260
+ async approve(address, tokenId) {
1261
+ return new Promise(async (resolve, reject) => {
1262
+ try {
1263
+ const approver = await this.contractInstance.callMethod("getApproved", [tokenId]);
1264
+ if (approver === address) {
1265
+ console.log(`Already approved:: ${approver}`);
1266
+ resolve("Approved");
1267
+ } else {
1268
+ await this.contractInstance.sendTransaction("approve", [address, tokenId]);
1269
+ console.log(`Approved`);
1270
+ resolve("Approved");
1271
+ }
1272
+ } catch (error) {
1273
+ console.error("Approval failed:", error);
1274
+ return reject(error);
1275
+ }
1276
+ });
1277
+ }
1278
+ // ownerAddress: string,
1279
+ async setApprovalForAll(operatorAddress) {
1280
+ return new Promise(async (resolve, reject) => {
1281
+ try {
1282
+ await this.contractInstance.sendTransaction("setApprovalForAll", [operatorAddress, true]);
1283
+ console.log(`Approved`);
1284
+ resolve("Approved");
1285
+ } catch (error) {
1286
+ console.error("Approval failed:", error);
1287
+ return reject(error);
1288
+ }
1289
+ });
1290
+ }
1291
+ async fetchMetaData(nftContractAddress, tokenId) {
1292
+ return new Promise(async (resolve, reject) => {
1293
+ try {
1294
+ let url = await this.contractInstance.callMethod("tokenURI", [tokenId]);
1295
+ if (url.startsWith("ipfs://")) {
1296
+ url = url.replace("ipfs://", "https://ipfs.io/ipfs/");
1297
+ }
1298
+ const res = await fetch(url);
1299
+ if (!res.ok) {
1300
+ return reject(`Failed to fetch metadata from ${url}`);
1301
+ }
1302
+ let metadata = await res.json();
1303
+ if (metadata.image && metadata.image.startsWith("ipfs://")) {
1304
+ metadata.image = metadata.image.replace(
1305
+ "ipfs://",
1306
+ "https://ipfs.io/ipfs/"
1307
+ );
1308
+ }
1309
+ metadata.address = nftContractAddress;
1310
+ metadata.tokenId = tokenId;
1311
+ return resolve(metadata);
1312
+ } catch (error) {
1313
+ return reject(error);
1314
+ }
1315
+ });
1316
+ }
1317
+ };
1318
+ var Erc721Contract_default = Erc721Contract;
1319
+
1136
1320
  // src/classes/Fund.ts
1137
1321
  var { parseUnits, formatUnits } = ethers2.utils;
1138
1322
  var Fund = class {
@@ -1196,18 +1380,22 @@ var Fund = class {
1196
1380
  const web3Provider = new ethers2.providers.Web3Provider(this.provider);
1197
1381
  const erc20Contract = new ethers2.Contract(tokenInfo.tokenAddress, erc20Abi_default, web3Provider);
1198
1382
  decimals = await erc20Contract.decimals();
1383
+ } else if (tokenInfo.tokenType === 2) {
1384
+ decimals = 0;
1385
+ const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenInfo.tokenAddress);
1386
+ await erc721ContractInstance.approve(this.fundContract.address, recipientInfo.nftIds[0]);
1199
1387
  }
1200
1388
  const tokenAmount = parseUnits(recipientInfo.tokenAmount.toString(), decimals);
1201
1389
  const newFundRecipientInfo = {
1202
1390
  idSource: recipientInfo.socialPlatform,
1203
1391
  id: recipientInfo.userIdentifier,
1204
1392
  amount: tokenAmount,
1205
- nftIds: []
1393
+ nftIds: recipientInfo.nftIds
1206
1394
  };
1207
- if (tokenInfo.tokenType === 0) {
1208
- params = [tokenInfo, newFundRecipientInfo];
1209
- } else {
1395
+ if (tokenInfo.tokenType === 1) {
1210
1396
  params = [tokenInfo, newFundRecipientInfo, { value: tokenAmount }];
1397
+ } else {
1398
+ params = [tokenInfo, newFundRecipientInfo];
1211
1399
  }
1212
1400
  const result = await this.fundContract.sendTransaction("tip", params);
1213
1401
  resolve(result);
@@ -1243,6 +1431,10 @@ var Fund = class {
1243
1431
  const web3Provider = new ethers2.providers.Web3Provider(this.provider);
1244
1432
  const erc20Contract = new ethers2.Contract(tokenInfo.tokenAddress, erc20Abi_default, web3Provider);
1245
1433
  decimals = await erc20Contract.decimals();
1434
+ } else if (tokenInfo.tokenType === 2) {
1435
+ decimals = 0;
1436
+ const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenInfo.tokenAddress);
1437
+ await erc721ContractInstance.setApprovalForAll(this.fundContract.address);
1246
1438
  }
1247
1439
  let totalFormatAmount = recipientInfoList.reduce((acc, cur) => acc.add(parseUnits(cur.tokenAmount.toString(), decimals)), ethers2.BigNumber.from(0));
1248
1440
  const newRecipientInfoList = recipientInfoList.map((i) => {
@@ -1251,13 +1443,13 @@ var Fund = class {
1251
1443
  idSource: i.socialPlatform,
1252
1444
  id: i.userIdentifier,
1253
1445
  amount: formatAmount,
1254
- nftIds: []
1446
+ nftIds: i.nftIds
1255
1447
  };
1256
1448
  });
1257
- if (tokenInfo.tokenType === 0) {
1258
- params = [tokenInfo, newRecipientInfoList];
1259
- } else {
1449
+ if (tokenInfo.tokenType === 1) {
1260
1450
  params = [tokenInfo, newRecipientInfoList, { value: totalFormatAmount }];
1451
+ } else {
1452
+ params = [tokenInfo, newRecipientInfoList];
1261
1453
  }
1262
1454
  const result = await this.fundContract.sendTransaction("tipBatch", params);
1263
1455
  return resolve(result);
@@ -1400,9 +1592,11 @@ var Fund = class {
1400
1592
  console.log("fundRecords", fundRecords);
1401
1593
  let formatRecords = [];
1402
1594
  for (const record of fundRecords) {
1403
- const { tipper, timestamp, tipToken: [tokenType, tokenAddress], amount } = record;
1595
+ const { tipper, timestamp, tipToken: [tokenType, tokenAddress], amount, nftIds } = record;
1404
1596
  let decimals = 18;
1405
1597
  let symbol = "";
1598
+ let tokenId = null;
1599
+ let nftInfo = null;
1406
1600
  if (tokenType === 0) {
1407
1601
  let formatProvider;
1408
1602
  if (this.provider instanceof ethers2.providers.JsonRpcProvider) {
@@ -1415,6 +1609,11 @@ var Fund = class {
1415
1609
  symbol = await erc20Contract.symbol();
1416
1610
  } else if (tokenType === 1) {
1417
1611
  symbol = NATIVETOKENS[this.chainId];
1612
+ } else if (tokenType === 2) {
1613
+ decimals = 0;
1614
+ tokenId = parseInt(nftIds[0]);
1615
+ const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenAddress);
1616
+ nftInfo = await erc721ContractInstance.fetchMetaData(tokenAddress, tokenId);
1418
1617
  }
1419
1618
  let fundToken = {
1420
1619
  tokenType,
@@ -1426,11 +1625,14 @@ var Fund = class {
1426
1625
  if (tokenType === 0) {
1427
1626
  fundToken.tokenAddress = tokenAddress;
1428
1627
  }
1628
+ if (tokenType === 2) {
1629
+ Object.assign(fundToken, nftInfo ?? {});
1630
+ }
1429
1631
  formatRecords.push({
1430
1632
  funder: tipper,
1431
1633
  fundToken,
1432
1634
  amount: formatUnits(amount, decimals),
1433
- timestamp: timestamp.toNumber() * 1e3
1635
+ timestamp: timestamp.toNumber()
1434
1636
  });
1435
1637
  }
1436
1638
  console.log("formatRecords", formatRecords);
@@ -1482,7 +1684,7 @@ var PrimusFund = class {
1482
1684
  formatUserIdentifier = i.userIdentifier.slice(1);
1483
1685
  }
1484
1686
  return {
1485
- nftIds: [],
1687
+ nftIds: i.nftIds ?? [],
1486
1688
  socialPlatform: formatSocialPlatform,
1487
1689
  userIdentifier: formatUserIdentifier,
1488
1690
  tokenAmount: i.tokenAmount
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primuslabs/fund-js-sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "author": "Primus Labs <dev@primuslabs.org>",
5
5
  "description": "Primus fund js sdk",
6
6
  "repository": {