Skip to content

Commit d56c4d6

Browse files
authored
feat: bump distributor idls, support clawbackReques (#353)
* feat: bump distributor idls, support clawbackRequest
1 parent b18d604 commit d56c4d6

15 files changed

Lines changed: 2436 additions & 280 deletions

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"packages": [
33
"packages/*"
44
],
5-
"version": "11.4.0",
5+
"version": "12.0.0",
66
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
77
"command": {
88
"run": {

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@streamflow/common",
3-
"version": "11.4.0",
3+
"version": "12.0.0",
44
"description": "Common utilities and types used by streamflow packages.",
55
"homepage": "https://github.com/streamflow-finance/js-sdk/",
66
"type": "module",

packages/distributor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@streamflow/distributor",
3-
"version": "11.4.0",
3+
"version": "12.0.0",
44
"description": "JavaScript SDK to interact with Streamflow Airdrop protocol.",
55
"homepage": "https://github.com/streamflow-finance/js-sdk/",
66
"main": "./dist/cjs/index.cjs",

packages/distributor/solana/clients/BaseDistributorClient.ts

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ import type {
5555
IGetClaimData,
5656
IGetDistributors,
5757
IInteractExt,
58+
IRequestClawbackData,
5859
ISearchDistributors,
60+
IWithdrawClawbackRequestData,
5961
ClawbackAccounts,
6062
NewDistributorAccounts,
6163
Fees,
@@ -521,7 +523,7 @@ export default abstract class BaseDistributorClient {
521523
distributor: distributorPublicKey,
522524
from: distributor.tokenVault,
523525
to: distributor.clawbackReceiver,
524-
admin: extParams.invoker.publicKey,
526+
authority: extParams.invoker.publicKey,
525527
mint: distributor.mint,
526528
tokenProgram: tokenProgramId,
527529
};
@@ -557,6 +559,114 @@ export default abstract class BaseDistributorClient {
557559
return { ixs, txId: signature };
558560
}
559561

562+
/**
563+
* Requests delayed clawback by the configured fee partner authority.
564+
* Once the request is recorded on-chain, clawback can be executed after the
565+
* configured delay elapses.
566+
*/
567+
public async requestClawback(
568+
data: IRequestClawbackData,
569+
extParams: IInteractExt,
570+
): Promise<ITransactionResult> {
571+
const executionParams = this.unwrapExecutionParams(extParams);
572+
const invoker = executionParams.invoker.publicKey;
573+
invariant(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
574+
const ixs = await createAndEstimateTransaction(
575+
(params) => this.prepareRequestClawbackInstructions(data, params),
576+
executionParams,
577+
);
578+
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, invoker);
579+
const signature = await wrappedSignAndExecuteTransaction(
580+
this.connection,
581+
executionParams.invoker,
582+
tx,
583+
{
584+
hash,
585+
context,
586+
commitment: this.getCommitment(),
587+
},
588+
{ sendThrottler: this.sendThrottler, skipSimulation: executionParams.skipSimulation },
589+
);
590+
591+
return { ixs, txId: signature };
592+
}
593+
594+
public async prepareRequestClawbackInstructions(
595+
data: IRequestClawbackData,
596+
extParams: ITransactionExtResolved<IInteractExt>,
597+
): Promise<TransactionInstruction[]> {
598+
if (!extParams.invoker.publicKey) {
599+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
600+
}
601+
602+
const ixs: TransactionInstruction[] = prepareBaseInstructions(this.connection, extParams);
603+
604+
ixs.push(
605+
await this.merkleDistributorProgram.methods
606+
.requestClawback()
607+
.accounts({
608+
distributor: new PublicKey(data.id),
609+
authority: extParams.invoker.publicKey,
610+
})
611+
.instruction(),
612+
);
613+
614+
return ixs;
615+
}
616+
617+
/**
618+
* Withdraws a previously submitted clawback request, cancelling the delayed clawback flow.
619+
*/
620+
public async withdrawClawbackRequest(
621+
data: IWithdrawClawbackRequestData,
622+
extParams: IInteractExt,
623+
): Promise<ITransactionResult> {
624+
const executionParams = this.unwrapExecutionParams(extParams);
625+
const invoker = executionParams.invoker.publicKey;
626+
invariant(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
627+
const ixs = await createAndEstimateTransaction(
628+
(params) => this.prepareWithdrawClawbackRequestInstructions(data, params),
629+
executionParams,
630+
);
631+
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, invoker);
632+
const signature = await wrappedSignAndExecuteTransaction(
633+
this.connection,
634+
executionParams.invoker,
635+
tx,
636+
{
637+
hash,
638+
context,
639+
commitment: this.getCommitment(),
640+
},
641+
{ sendThrottler: this.sendThrottler, skipSimulation: executionParams.skipSimulation },
642+
);
643+
644+
return { ixs, txId: signature };
645+
}
646+
647+
public async prepareWithdrawClawbackRequestInstructions(
648+
data: IWithdrawClawbackRequestData,
649+
extParams: ITransactionExtResolved<IInteractExt>,
650+
): Promise<TransactionInstruction[]> {
651+
if (!extParams.invoker.publicKey) {
652+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
653+
}
654+
655+
const ixs: TransactionInstruction[] = prepareBaseInstructions(this.connection, extParams);
656+
657+
ixs.push(
658+
await this.merkleDistributorProgram.methods
659+
.withdrawClawbackRequest()
660+
.accounts({
661+
distributor: new PublicKey(data.id),
662+
authority: extParams.invoker.publicKey,
663+
})
664+
.instruction(),
665+
);
666+
667+
return ixs;
668+
}
669+
560670
public async getClaim(claimStatus: string | PublicKey): Promise<AnyClaimStatus | null> {
561671
return this.connection.getAccountInfo(pk(claimStatus)).then((account) => this.decodeClaimStatus(account));
562672
}

packages/distributor/solana/clients/SolanaAlignedDistributorClient.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default class SolanaAlignedDistributorClient extends BaseDistributorClien
8787
? new PublicKey(data.oracleAddress)
8888
: getTestOraclePda(this.alignedProxyProgram.programId, pk(mint), pk(admin));
8989

90-
return this.alignedProxyProgram.methods
90+
let builder = this.alignedProxyProgram.methods
9191
.newDistributor({
9292
claimsClosable: data.claimsClosableByAdmin,
9393
version: new BN(data.version),
@@ -109,12 +109,19 @@ export default class SolanaAlignedDistributorClient extends BaseDistributorClien
109109
tokenProgram,
110110
priceOracle: oracle,
111111
})
112-
.accountsPartial({ partnerOracle: this.partnerOracleProgramId, partnerOracleConfig: this.feeConfigPublicKey })
113-
.instruction();
112+
.accountsPartial({ partnerOracle: this.partnerOracleProgramId, partnerOracleConfig: this.feeConfigPublicKey });
113+
114+
if (data.partnerLink) {
115+
builder = builder.remainingAccounts([
116+
{ pubkey: new PublicKey(data.partnerLink.address), isSigner: data.partnerLink.isSigner, isWritable: false },
117+
]);
118+
}
119+
120+
return builder.instruction();
114121
}
115122

116123
protected async getClawbackInstruction(accounts: ClawbackAccounts): Promise<TransactionInstruction> {
117-
const { distributor, from, to, mint, tokenProgram, admin } = accounts;
124+
const { distributor, from, to, mint, tokenProgram, authority } = accounts;
118125
const alignedDistributorKey = getAlignedDistributorPda(
119126
this.alignedProxyProgram.programId,
120127
pk(accounts.distributor),
@@ -126,7 +133,7 @@ export default class SolanaAlignedDistributorClient extends BaseDistributorClien
126133
return this.alignedProxyProgram.methods
127134
.clawback()
128135
.accounts({
129-
admin,
136+
admin: authority,
130137
distributor,
131138
from,
132139
to,

packages/distributor/solana/clients/SolanaDistributorClient.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type TransactionInstruction } from "@solana/web3.js";
1+
import { PublicKey, type TransactionInstruction } from "@solana/web3.js";
22
import BN from "bn.js";
33

44
import { type ICreateDistributorData, type NewDistributorAccounts, type ClawbackAccounts } from "../types.js";
@@ -10,7 +10,7 @@ export default class SolanaDistributorClient extends BaseDistributorClient {
1010
accounts: Required<NewDistributorAccounts>,
1111
): Promise<TransactionInstruction> {
1212
this.validateDistributorArgs(data);
13-
return this.merkleDistributorProgram.methods
13+
let builder = this.merkleDistributorProgram.methods
1414
.newDistributor(
1515
new BN(data.version),
1616
data.root,
@@ -28,8 +28,15 @@ export default class SolanaDistributorClient extends BaseDistributorClient {
2828
data.claimsLimit ?? null,
2929
)
3030
.accounts(accounts)
31-
.accountsPartial({ partnerOracle: this.partnerOracleProgramId, partnerOracleConfig: this.feeConfigPublicKey })
32-
.instruction();
31+
.accountsPartial({ partnerOracle: this.partnerOracleProgramId, partnerOracleConfig: this.feeConfigPublicKey });
32+
33+
if (data.partnerLink) {
34+
builder = builder.remainingAccounts([
35+
{ pubkey: new PublicKey(data.partnerLink.address), isSigner: data.partnerLink.isSigner, isWritable: false },
36+
]);
37+
}
38+
39+
return builder.instruction();
3340
}
3441

3542
protected async getClawbackInstruction(accounts: ClawbackAccounts): Promise<TransactionInstruction> {

packages/distributor/solana/descriptor/aligned_distributor.ts

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type AlignedDistributor = {
88
"address": "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
99
"metadata": {
1010
"name": "alignedDistributor",
11-
"version": "2.0.0",
11+
"version": "1.9.0",
1212
"spec": "0.1.0",
1313
"description": "Proxy for merkle distributor that updates Vesting duration according to token market performance."
1414
},
@@ -160,9 +160,9 @@ export type AlignedDistributor = {
160160
{
161161
"name": "admin",
162162
"docs": [
163-
"Only Admin can trigger the clawback of funds",
163+
"Admin or anybody in case distributor has been clawed back (usually by clawback authority).",
164+
"Since receiver is set by the admin, it's generally safe to call clawback by anyone here if the merkle distributor has been clawed back",
164165
],
165-
"writable": true,
166166
"signer": true
167167
},
168168
{
@@ -1038,6 +1038,16 @@ export type AlignedDistributor = {
10381038
"name": "noFeesToClaim",
10391039
"msg": "No fees to claim"
10401040
},
1041+
{
1042+
"code": 6015,
1043+
"name": "durationNotUpdated",
1044+
"msg": "Update won't lead to any changes in unlock schedule"
1045+
},
1046+
{
1047+
"code": 6016,
1048+
"name": "clawbackAlreadyClaimed",
1049+
"msg": "Clawback already claimed"
1050+
},
10411051
],
10421052
"types": [
10431053
{
@@ -1525,14 +1535,56 @@ export type AlignedDistributor = {
15251535
"type": "u8"
15261536
},
15271537
{
1528-
"name": "buffer",
1538+
"name": "autoClaim",
15291539
"docs": [
1530-
"Buffer for additional fields",
1540+
"Whether Distributor supports auto-claim",
1541+
],
1542+
"type": "bool"
1543+
},
1544+
{
1545+
"name": "alignBuffer1",
1546+
"docs": [
1547+
"Extra buffer to keep alignment, may be reused",
15311548
],
15321549
"type": {
15331550
"array": [
15341551
"u8",
1535-
13,
1552+
4,
1553+
]
1554+
}
1555+
},
1556+
{
1557+
"name": "feePartner",
1558+
"docs": [
1559+
"Partner wallet whose fee schedule was applied, if different from the creator",
1560+
],
1561+
"type": "pubkey"
1562+
},
1563+
{
1564+
"name": "clawbackRequestTs",
1565+
"docs": [
1566+
"Timestamp when clawback was requested by the fee partner",
1567+
],
1568+
"type": "u64"
1569+
},
1570+
{
1571+
"name": "buffer1",
1572+
"docs": [
1573+
"Buffers for additional fields",
1574+
],
1575+
"type": {
1576+
"array": [
1577+
"u8",
1578+
32,
1579+
]
1580+
}
1581+
},
1582+
{
1583+
"name": "buffer2",
1584+
"type": {
1585+
"array": [
1586+
"u8",
1587+
32,
15361588
]
15371589
}
15381590
},

0 commit comments

Comments
 (0)