Skip to content

Commit 65db5d7

Browse files
committed
feat: support fee partner, cancel request
1 parent d56c4d6 commit 65db5d7

13 files changed

Lines changed: 1093 additions & 6 deletions

File tree

packages/stream/__tests__/solana/streamClient.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ describe("SolanaStreamClient Transaction Builders", async () => {
404404
oldMetadata: PublicKey.default,
405405
payer: PublicKey.default,
406406
bump: 0,
407+
feePartner: PublicKey.default,
408+
cancelRequestTime: new BN(0),
407409
});
408410

409411
const setupTransferHookMint = () => {

packages/stream/solana/StreamClient.ts

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ import {
7373
type IMultiTransactionResult,
7474
type IPrepareCreateStreamExt,
7575
type IPrepareStreamExt, type IPrepareTopUpstreamExt,
76+
type IRequestCancelData,
7677
type ISearchStreams,
7778
type ITopUpData,
7879
type ITopUpStreamExt,
7980
type ITransactionExtWithInstructions,
8081
type ITransactionResult,
8182
type ITransferData,
8283
type IUpdateData,
84+
type IWithdrawCancelRequestData,
8385
type IWithdrawData,
8486
type MetadataRecipientHashMap,
8587
type OracleType,
@@ -122,9 +124,11 @@ import {
122124
createStreamV2Instruction,
123125
createUncheckedStreamInstruction,
124126
createUncheckedStreamV2Instruction,
127+
requestCancelStreamInstruction,
125128
topupStreamInstruction,
126129
transferStreamInstruction,
127130
updateStreamInstruction,
131+
withdrawCancelRequestInstruction,
128132
withdrawStreamInstruction,
129133
} from "./instructions.js";
130134
import type { IPartnerLayout } from "./instructionTypes.js";
@@ -1468,6 +1472,114 @@ export class SolanaStreamClient {
14681472
return ixs;
14691473
}
14701474

1475+
/**
1476+
* Requests cancellation of a stream by the fee partner authority.
1477+
* @param {IRequestCancelData} data - Request cancel parameters including stream ID
1478+
* @param {IInteractStreamExt} extParams - Transaction configuration including invoker wallet and compute settings
1479+
* @returns Transaction result
1480+
*/
1481+
public async requestCancel(
1482+
data: IRequestCancelData,
1483+
extParams: IInteractStreamExt,
1484+
): Promise<ITransactionResult> {
1485+
const ixs = await this.prepareRequestCancelInstructions(data, extParams);
1486+
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
1487+
const signature = await signAndExecuteTransaction(
1488+
this.connection,
1489+
extParams.invoker,
1490+
tx,
1491+
{
1492+
hash,
1493+
context,
1494+
commitment: this.getCommitment(),
1495+
},
1496+
this.schedulingParams,
1497+
);
1498+
1499+
return { ixs, txId: signature };
1500+
}
1501+
1502+
/**
1503+
* Creates Transaction Instructions for request_cancel
1504+
* @param {IRequestCancelData} data - Request cancel parameters including stream ID
1505+
* @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet and compute settings
1506+
* @returns Transaction instructions
1507+
*/
1508+
public async prepareRequestCancelInstructions(
1509+
{ id }: IRequestCancelData,
1510+
{ invoker, computePrice, computeLimit }: IPrepareStreamExt,
1511+
): Promise<TransactionInstruction[]> {
1512+
assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
1513+
1514+
const ixs: TransactionInstruction[] = prepareBaseInstructions(this.connection, {
1515+
computePrice,
1516+
computeLimit,
1517+
});
1518+
1519+
ixs.push(
1520+
await requestCancelStreamInstruction(this.programId, {
1521+
authority: invoker.publicKey,
1522+
metadata: new PublicKey(id),
1523+
}),
1524+
);
1525+
1526+
return ixs;
1527+
}
1528+
1529+
/**
1530+
* Withdraws a previously submitted cancel request.
1531+
* @param {IWithdrawCancelRequestData} data - Withdraw cancel request parameters including stream ID
1532+
* @param {IInteractStreamExt} extParams - Transaction configuration including invoker wallet and compute settings
1533+
* @returns Transaction result
1534+
*/
1535+
public async withdrawCancelRequest(
1536+
data: IWithdrawCancelRequestData,
1537+
extParams: IInteractStreamExt,
1538+
): Promise<ITransactionResult> {
1539+
const ixs = await this.prepareWithdrawCancelRequestInstructions(data, extParams);
1540+
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
1541+
const signature = await signAndExecuteTransaction(
1542+
this.connection,
1543+
extParams.invoker,
1544+
tx,
1545+
{
1546+
hash,
1547+
context,
1548+
commitment: this.getCommitment(),
1549+
},
1550+
this.schedulingParams,
1551+
);
1552+
1553+
return { ixs, txId: signature };
1554+
}
1555+
1556+
/**
1557+
* Creates Transaction Instructions for withdraw_cancel_request
1558+
* @param {IWithdrawCancelRequestData} data - Withdraw cancel request parameters including stream ID
1559+
* @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet and compute settings
1560+
* @returns Transaction instructions
1561+
*/
1562+
public async prepareWithdrawCancelRequestInstructions(
1563+
{ id }: IWithdrawCancelRequestData,
1564+
{ invoker, computePrice, computeLimit }: IPrepareStreamExt,
1565+
): Promise<TransactionInstruction[]> {
1566+
assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
1567+
1568+
const ixs: TransactionInstruction[] = prepareBaseInstructions(this.connection, {
1569+
computePrice,
1570+
computeLimit,
1571+
});
1572+
1573+
ixs.push(
1574+
await withdrawCancelRequestInstruction(this.programId, {
1575+
authority: invoker.publicKey,
1576+
metadata: new PublicKey(id),
1577+
}),
1578+
);
1579+
1580+
return ixs;
1581+
}
1582+
14711583
/**
14721584
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
14731585
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.

packages/stream/solana/api-public/transform.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ async function toDecodedStream(schema: ContractSchema): Promise<DecodedStream> {
8787
oldMetadata: PublicKey.default,
8888
payer,
8989
bump: schema.bump ? schema.bump : 0,
90+
feePartner: partner,
91+
cancelRequestTime: toBN(isoToUnix(schema.cancelRequestDt)),
9092
};
9193
}
9294

packages/stream/solana/api-public/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export interface ContractSchema {
7474
nonce: number | null;
7575
payer: string | null;
7676
bump: number | null;
77+
feePartner: string | null,
78+
cancelRequestDt: string | null;
7779
dynamicContract: DynamicContractSchema | null;
7880
}
7981

packages/stream/solana/descriptor/idl/streamflow.json

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"address": "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m",
33
"metadata": {
44
"name": "streamflow",
5-
"version": "0.4.0",
5+
"version": "0.6.0",
66
"spec": "0.1.0",
77
"description": "Created with Anchor"
88
},
@@ -94,6 +94,10 @@
9494
{
9595
"name": "metadata",
9696
"writable": true
97+
},
98+
{
99+
"name": "partner",
100+
"writable": true
97101
}
98102
],
99103
"args": []
@@ -1122,6 +1126,30 @@
11221126
],
11231127
"args": []
11241128
},
1129+
{
1130+
"name": "request_cancel",
1131+
"discriminator": [
1132+
244,
1133+
78,
1134+
42,
1135+
227,
1136+
165,
1137+
174,
1138+
94,
1139+
167
1140+
],
1141+
"accounts": [
1142+
{
1143+
"name": "authority",
1144+
"signer": true
1145+
},
1146+
{
1147+
"name": "metadata",
1148+
"writable": true
1149+
}
1150+
],
1151+
"args": []
1152+
},
11251153
{
11261154
"name": "topup",
11271155
"discriminator": [
@@ -1435,6 +1463,30 @@
14351463
"type": "u64"
14361464
}
14371465
]
1466+
},
1467+
{
1468+
"name": "withdraw_cancel_request",
1469+
"discriminator": [
1470+
91,
1471+
137,
1472+
171,
1473+
103,
1474+
142,
1475+
205,
1476+
96,
1477+
75
1478+
],
1479+
"accounts": [
1480+
{
1481+
"name": "authority",
1482+
"signer": true
1483+
},
1484+
{
1485+
"name": "metadata",
1486+
"writable": true
1487+
}
1488+
],
1489+
"args": []
14381490
}
14391491
]
14401492
}

0 commit comments

Comments
 (0)