Skip to content

Commit be7f5b7

Browse files
authored
Merge pull request #1152 from lens-protocol/cesare/lens-540-add-referrals-in-paid-actions-and-rules
chore: support API changes
2 parents 5ac893c + c252576 commit be7f5b7

File tree

4 files changed

+156
-12
lines changed

4 files changed

+156
-12
lines changed

packages/client/src/actions/post.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertOk, nonNullable, uri } from '@lens-protocol/types';
1+
import { assertOk, nonNullable } from '@lens-protocol/types';
22

33
import { justPost } from '@lens-protocol/graphql';
44
import { textOnly } from '@lens-protocol/metadata';
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { type Post, justPost } from '@lens-protocol/graphql';
2+
import { textOnly } from '@lens-protocol/metadata';
3+
import { assertOk, bigDecimal, nonNullable } from '@lens-protocol/types';
4+
import { beforeAll, describe, it } from 'vitest';
5+
6+
import type { SessionClient } from '../clients';
7+
import { TEST_ACCOUNT, TEST_ERC20, TEST_SIGNER, loginAsAccountOwner, wallet } from '../test-utils';
8+
import { handleOperationWith } from '../viem';
9+
import { executeAccountAction, executePostAction } from './actions';
10+
import { fetchAccountBalances, wrapTokens } from './funds';
11+
import { findErc20Amount } from './helpers';
12+
import { post } from './post';
13+
import { fetchPost } from './posts';
14+
15+
describe('Given a Lens Account with some WGHO (or any other ERC20)', { timeout: 20000 }, () => {
16+
let sessionClient: SessionClient;
17+
18+
beforeAll(async () => {
19+
await loginAsAccountOwner().andTee((client) => {
20+
sessionClient = client;
21+
});
22+
23+
const balance = await fetchAccountBalances(sessionClient, {
24+
includeNative: false,
25+
tokens: [TEST_ERC20],
26+
}).andThen((balances) => findErc20Amount(TEST_ERC20, balances));
27+
assertOk(balance);
28+
29+
if (balance.value.value < '1') {
30+
const wrapped = await wrapTokens(sessionClient, {
31+
amount: bigDecimal(1),
32+
})
33+
.andThen(handleOperationWith(wallet))
34+
.andThen(sessionClient.waitForTransaction);
35+
36+
assertOk(wrapped);
37+
}
38+
});
39+
40+
describe('When executing the Tipping Account Action', () => {
41+
it('Then it should work as expected', async () => {
42+
const result = await executeAccountAction(sessionClient, {
43+
account: TEST_ACCOUNT,
44+
action: {
45+
tipping: {
46+
currency: TEST_ERC20,
47+
value: bigDecimal(1),
48+
referrals: [
49+
{
50+
address: TEST_SIGNER,
51+
percent: 10,
52+
},
53+
{
54+
address: TEST_SIGNER,
55+
percent: 90,
56+
},
57+
],
58+
},
59+
},
60+
})
61+
.andThen(handleOperationWith(wallet))
62+
.andThen(sessionClient.waitForTransaction);
63+
64+
assertOk(result);
65+
});
66+
});
67+
68+
describe('When executing the Tipping Post Action', () => {
69+
const content = `data:application/json,${JSON.stringify(textOnly({ content: 'Hello world!' }))}`;
70+
let anyPost: Post;
71+
72+
beforeAll(async () => {
73+
const result = await post(sessionClient, {
74+
contentUri: content,
75+
})
76+
.andThen(handleOperationWith(wallet))
77+
.andThen(sessionClient.waitForTransaction)
78+
.andThen((txHash) => fetchPost(sessionClient, { txHash }))
79+
.map(nonNullable)
80+
.map(justPost);
81+
assertOk(result);
82+
anyPost = result.value;
83+
});
84+
85+
it('Then it should work as expected', async () => {
86+
const result = await executePostAction(sessionClient, {
87+
post: anyPost.id,
88+
action: {
89+
tipping: {
90+
currency: TEST_ERC20,
91+
value: bigDecimal(1),
92+
referrals: [
93+
{
94+
address: TEST_SIGNER,
95+
percent: 10,
96+
},
97+
{
98+
address: TEST_SIGNER,
99+
percent: 90,
100+
},
101+
],
102+
},
103+
},
104+
})
105+
.andThen(handleOperationWith(wallet))
106+
.andThen(sessionClient.waitForTransaction);
107+
108+
assertOk(result);
109+
});
110+
});
111+
});

packages/graphql/schema.graphql

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ input AccountActionConfigInput @oneOf {
5353
}
5454

5555
input AccountActionExecuteInput @oneOf {
56-
tipping: AmountInput
56+
tipping: TippingAmountInput
5757
unknown: UnknownActionExecuteInput
5858
}
5959

@@ -1519,8 +1519,12 @@ type CreateNamespaceResponse {
15191519
}
15201520

15211521
input CreatePostRequest {
1522-
"""The feed to post to. If not provided, the global feed is used."""
1523-
feed: EvmAddress! = "0x31232Cb7dE0dce17949ffA58E9E38EEeB367C871"
1522+
"""
1523+
The feed to post to.
1524+
Defaults to the global feed for new posts, or the original post's feed for comments and
1525+
quotes.
1526+
"""
1527+
feed: EvmAddress
15241528

15251529
"""The URI of the post metadata."""
15261530
contentUri: URI!
@@ -5038,7 +5042,7 @@ input PostActionContractsRequest {
50385042

50395043
input PostActionExecuteInput @oneOf {
50405044
simpleCollect: SimpleCollectExecuteInput
5041-
tipping: AmountInput
5045+
tipping: TippingAmountInput
50425046
unknown: UnknownActionExecuteInput
50435047
}
50445048

@@ -5477,7 +5481,7 @@ enum PostVisibilityFilter {
54775481

54785482
input PostsExploreFilter {
54795483
"""Only return posts after this timestamp, defaults to 3 days ago."""
5480-
since: Int! = 1745315413
5484+
since: Int! = 1745759306
54815485

54825486
"""Metadata filters to apply to posts"""
54835487
metadata: PostMetadataFilter! = {mainContentFocus: null, tags: null, contentWarning: null}
@@ -5491,7 +5495,7 @@ input PostsExploreRequest {
54915495
cursor: Cursor
54925496

54935497
"""Filter for posts"""
5494-
filter: PostsExploreFilter! = {since: 1745315413, metadata: {mainContentFocus: null, tags: null, contentWarning: null}}
5498+
filter: PostsExploreFilter! = {since: 1745759306, metadata: {mainContentFocus: null, tags: null, contentWarning: null}}
54955499

54965500
"""
54975501
Shuffle the results, defaults to false. Causes performance issues so is ignored for now.
@@ -6244,6 +6248,12 @@ type SimpleCollectActionContract {
62446248

62456249
input SimpleCollectExecuteInput {
62466250
selected: AlwaysTrue!
6251+
6252+
"""
6253+
The list of referrers and their cut of the collect referral share.
6254+
This is calculated as a percentage of the referral share AFTER the
6255+
treasury fee is deducted.
6256+
"""
62476257
referrals: [ReferralCut!]
62486258
}
62496259

@@ -7276,6 +7286,28 @@ type TippingAccountActionExecuted {
72767286
executedAt: DateTime!
72777287
}
72787288

7289+
input TippingAmountInput {
7290+
"""
7291+
Token value in its main unit (e.g., 1.5 WGHO), NOT in the smallest fraction (e.g.,
7292+
wei).
7293+
"""
7294+
value: BigDecimal!
7295+
7296+
"""
7297+
The token address.
7298+
Currently, only ERC20 tokens are supported.
7299+
"""
7300+
currency: EvmAddress!
7301+
7302+
"""
7303+
The list of referrers and their cut of the referral share.
7304+
This is calculated as a percentage of the referral share AFTER the
7305+
treasury fee is deducted.
7306+
The tip referral share is capped at 20%.
7307+
"""
7308+
referrals: [ReferralCut!]
7309+
}
7310+
72797311
type TippingPostActionContract {
72807312
address: EvmAddress!
72817313
}

0 commit comments

Comments
 (0)