Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: token-gated support for Publication Metadata v3 and Lens API v2 #514

Merged
merged 10 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/funny-radios-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@lens-protocol/client": minor
"@lens-protocol/gated-content": patch
---

**feat:** token-gated support for LIP-2 metadata spec
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"packages/prettier-config",
"packages/react-web",
"packages/react",
"packages/sdk-gated",
"packages/shared-kernel",
"packages/storage",
"packages/tsconfig",
Expand Down
4 changes: 2 additions & 2 deletions examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dependencies": {
"@bundlr-network/client": "^0.11.9",
"@lens-protocol/client": "workspace:*",
"@lens-protocol/metadata": "0.1.0-alpha.25",
"@lens-protocol/metadata": "0.1.0-alpha.29",
"dotenv": "^16.0.3",
"ethers": "^5.7.2",
"uuid": "^9.0.0",
Expand All @@ -33,7 +33,7 @@
"@types/uuid": "^9.0.0",
"prettier": "^2.8.4",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
"typescript": "^4.9.5"
},
"prettier": "@lens-protocol/prettier-config"
}
3 changes: 1 addition & 2 deletions examples/node/scripts/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ async function main() {
const accessTokenResult = await client.authentication.getAccessToken();
const accessToken = accessTokenResult.unwrap();

const profileIdResult = await client.authentication.getProfileId();
const profileId = profileIdResult.unwrap();
const profileId = await client.authentication.getProfileId();

console.log(`Is LensClient authenticated? `, await client.authentication.isAuthenticated());
console.log(`Authenticated profileId: `, profileId);
Expand Down
3 changes: 2 additions & 1 deletion examples/node/scripts/follow/createFollowTypedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ async function main() {
}

console.log(
`Transaction to follow was successfully broadcasted with txId ${followBroadcastResultValue.txId}`,
`Transaction to follow was successfully broadcasted with txId`,
followBroadcastResultValue.txId,
);

// wait for follow to be indexed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ async function main() {
}

console.log(
`Profile follow module sucessfully set and successfully broadcasted with txId ${followBroadcastResultValue.txId}`,
`Profile follow module successfully set and successfully broadcasted with txId`,
followBroadcastResultValue.txId,
);

// wait for follow to be indexed
Expand Down
9 changes: 5 additions & 4 deletions examples/node/scripts/follow/createUnfollowTypedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ async function main() {
}

console.log(
`Transaction to follow ${profileToUnfollowId} was successfully broadcasted with txId ${followBroadcastResultValue.txId}`,
`Transaction to follow ${profileToUnfollowId} was successfully broadcasted with txId`,
followBroadcastResultValue.txId,
);

// wait for follow to be indexed
Expand All @@ -49,9 +50,9 @@ async function main() {
});

console.log(`Just followed profile`, {
id: justFollowedProfile.id,
handle: justFollowedProfile.handle,
isFollowedByMe: justFollowedProfile.operations.isFollowedByMe,
id: justFollowedProfile?.id,
handle: justFollowedProfile?.handle,
isFollowedByMe: justFollowedProfile?.operations.isFollowedByMe,
});
}

Expand Down
19 changes: 11 additions & 8 deletions examples/node/scripts/misc/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ async function main() {
console.log(`Fetching page for cursor: ${pagination.pageInfo.next}`);

const nextPage = await pagination.next();
publications.push(...nextPage.items);

console.log(
`Next page:`,
nextPage.items.map((i) => ({
id: i.id,
})),
);

if (nextPage) {
publications.push(...nextPage.items);

console.log(
`Next page:`,
nextPage.items.map((i) => ({
id: i.id,
})),
);
}
}

console.log(
Expand Down
3 changes: 2 additions & 1 deletion examples/node/scripts/profile/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ async function main() {
}

console.log(
`Transaction to create a new profile with handle "${handle}" was successfully broadcasted with txId ${profileCreateResult.txId}`,
`Transaction to create a new profile with handle "${handle}" was successfully broadcasted with txId`,
profileCreateResult.txId,
);

console.log(`Waiting for the transaction to be indexed...`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function main() {

await client.transaction.waitUntilComplete({ forTxId: broadcastResultValue.txId });

console.log(`Transaction was successfully broadcasted with txId ${broadcastResultValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, broadcastResultValue.txId);
}

main();
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ async function main() {
const wallet = setupWallet();
const client = await getAuthenticatedClientFromEthersWallet(wallet);

const profileIdResult = await client.authentication.getProfileId();
const profileId = profileIdResult.unwrap();
const profileId = await client.authentication.getProfileId();

const typedDataResult = await client.profile.createChangeProfileManagersTypedData({
approveLensManager: true,
Expand Down Expand Up @@ -43,7 +42,7 @@ async function main() {
}

console.log(
`Successfully changed profile manager for profile ${profileId} with: `,
`Successfully changed profile manager for profile ${String(profileId)} with: `,
onchainRelayResult,
);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/node/scripts/profile/createLinkHandleTypedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function main() {

await client.transaction.waitUntilComplete({ forTxId: broadcastResultValue.txId });

console.log(`Transaction was successfully broadcasted with txId ${broadcastResultValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, broadcastResultValue.txId);
}

main();
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function main() {
// or wait till transaction is indexed
await client.transaction.waitUntilComplete({ forTxId: broadcastResultValue.txId });

console.log(`Transaction was successfully broadcasted with txId ${broadcastResultValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, broadcastResultValue.txId);
}

main();
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function main() {

await client.transaction.waitUntilComplete({ forTxId: broadcastResultValue.txId });

console.log(`Transaction was successfully broadcasted with txId ${broadcastResultValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, broadcastResultValue.txId);
}

main();
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function main() {

await client.transaction.waitUntilComplete({ forTxId: broadcastResultValue.txId });

console.log(`Transaction was successfully broadcasted with txId ${broadcastResultValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, broadcastResultValue.txId);
}

main();
6 changes: 3 additions & 3 deletions examples/node/scripts/profile/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ async function main() {
forProfileId: '0x01',
});

console.log(`Profile fetched by id: `, { id: profileById.id, handle: profileById.handle });
console.log(`Profile fetched by id: `, { id: profileById?.id, handle: profileById?.handle });

// by handle
const profileByHandle = await client.profile.fetch({
forHandle: 'test/@firstprofile',
});

console.log(`Profile fetched by handle: `, {
id: profileByHandle.id,
handle: profileByHandle.handle,
id: profileByHandle?.id,
handle: profileByHandle?.handle,
});
}

Expand Down
4 changes: 2 additions & 2 deletions examples/node/scripts/profile/interests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ async function main() {
});

// fetch all interests
const { interests } = await client.profile.fetch({
const profile = await client.profile.fetch({
forProfileId: profileId,
});

console.log(`Profile interests`, interests);
console.log(`Profile interests`, profile?.interests);

// remove interests
await client.profile.removeInterests({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
forProfileId: profileId,
});

if (profile.lensManager) {
if (profile?.lensManager) {
console.log('Profile manager is enabled');
} else {
console.log('Profile manager is disabled');
Expand Down
6 changes: 3 additions & 3 deletions examples/node/scripts/profile/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ async function main() {
);

console.log(`Result: `, {
id: result.id,
handle: result.handle,
stats: result.stats,
id: result?.id,
handle: result?.handle,
stats: result?.stats,
});
}

Expand Down
2 changes: 1 addition & 1 deletion examples/node/scripts/publication/actions/actOn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function main() {
return;
}

console.log(`Transaction was successfully broadcasted with txId ${resultValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, resultValue.txId);

// wait in a loop
console.log(`Waiting for the transaction to be indexed...`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function main() {
return;
}

console.log(`Transaction was successfully broadcasted with txId ${broadcastValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, broadcastValue.txId);

// wait in a loop
console.log(`Waiting for the transaction to be indexed...`);
Expand Down
2 changes: 1 addition & 1 deletion examples/node/scripts/publication/commentOnchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function main() {
return;
}

console.log(`Transaction was successfully broadcasted with txId ${resultValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, resultValue.txId);

// wait in a loop
console.log(`Waiting for the transaction to be indexed...`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function main() {
return;
}

console.log(`Transaction was successfully broadcasted with txId ${broadcastValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, broadcastValue.txId);

// wait in a loop
console.log(`Waiting for the transaction to be indexed...`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function main() {
return;
}

console.log(`Transaction was successfully broadcasted with txId ${broadcastValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, broadcastValue.txId);

// wait in a loop
console.log(`Waiting for the transaction to be indexed...`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function main() {
return;
}

console.log(`Transaction was successfully broadcasted with txId ${broadcastValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, broadcastValue.txId);

// wait in a loop
console.log(`Waiting for the transaction to be indexed...`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function main() {
return;
}

console.log(`Transaction was successfully broadcasted with txId ${broadcastValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, broadcastValue.txId);

// wait in a loop
console.log(`Waiting for the transaction to be indexed...`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function main() {
return;
}

console.log(`Transaction was successfully broadcasted with txId ${broadcastValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, broadcastValue.txId);

// wait in a loop
console.log(`Waiting for the transaction to be indexed...`);
Expand Down
2 changes: 1 addition & 1 deletion examples/node/scripts/publication/legacyCollect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function main() {
return;
}

console.log(`Transaction was successfully broadcasted with txId ${resultValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, resultValue.txId);

// wait in a loop
console.log(`Waiting for the transaction to be indexed...`);
Expand Down
2 changes: 1 addition & 1 deletion examples/node/scripts/publication/mirrorOnchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function main() {
return;
}

console.log(`Transaction was successfully broadcasted with txId ${resultValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, resultValue.txId);

// wait in a loop
console.log(`Waiting for the transaction to be indexed...`);
Expand Down
2 changes: 1 addition & 1 deletion examples/node/scripts/publication/postOnchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function main() {
return;
}

console.log(`Transaction was successfully broadcasted with txId ${resultValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, resultValue.txId);

// wait in a loop
console.log(`Waiting for the transaction to be indexed...`);
Expand Down
2 changes: 1 addition & 1 deletion examples/node/scripts/publication/quoteOnchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function main() {
return;
}

console.log(`Transaction was successfully broadcasted with txId ${resultValue.txId}`);
console.log(`Transaction was successfully broadcasted with txId`, resultValue.txId);

// wait in a loop
console.log(`Waiting for the transaction to be indexed...`);
Expand Down
4 changes: 2 additions & 2 deletions examples/node/scripts/publication/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ async function main() {
forId: '0x04-0x0b',
});

if (isMirrorPublication(result)) {
if (result && isMirrorPublication(result)) {
throw new Error(`Stats are not available for mirrors`);
}

console.log(`Stats for the publication: `, result.stats);
console.log(`Stats for the publication: `, result?.stats);
}

main();
2 changes: 1 addition & 1 deletion examples/node/scripts/publication/validateMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async function main() {
});

if (!result.valid) {
throw new Error(`Metadata is not valid because of ${result.reason}`);
throw new Error(`Metadata is not valid because of ${String(result.reason)}`);
}

console.log(`Result: `, result);
Expand Down
4 changes: 2 additions & 2 deletions examples/node/scripts/shared/getAuthenticatedClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LensClient, development } from '@lens-protocol/client';
import { Wallet } from 'ethers';
import { Wallet, constants } from 'ethers';
import { WalletClient } from 'viem';

import { getOwnedProfileId } from './getOwnedProfileId';
Expand All @@ -26,7 +26,7 @@ export async function getAuthenticatedClientFromViemWalletClient(walletClient: W
const client = new LensClient({
environment: development,
});
const address = walletClient.account.address;
const address = walletClient.account?.address ?? constants.AddressZero;
const profileId = await getOwnedProfileId(client, address);

const { id, text } = await client.authentication.generateChallenge({
Expand Down
4 changes: 3 additions & 1 deletion examples/node/scripts/shared/uploadWithBundlr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export async function uploadWithBundlr(data: { [key: string]: unknown }): Promis
const atomicBalance = await bundlr.getLoadedBalance();
const balance = bundlr.utils.fromAtomic(atomicBalance);

console.log(`Bundlr balance for wallet ${bundlr.address} is ${balance.toString()} MUMBAI MATIC`);
console.log(
`Bundlr balance for wallet ${String(bundlr.address)} is ${balance.toString()} MUMBAI MATIC`,
);

// fund bundlr balance if empty
if (balance.eq(0)) {
Expand Down
Loading
Loading