@streamflow/stream 7.5.3 → 8.0.0-alpha.p287.5172056

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.
Files changed (154) hide show
  1. package/dist/cjs/BaseStreamClient-CQOC8m8V.d.cts +542 -0
  2. package/dist/cjs/aptos/index.cjs +456 -0
  3. package/dist/cjs/aptos/index.cjs.map +1 -0
  4. package/dist/cjs/aptos/index.d.cts +14 -0
  5. package/dist/cjs/evm/index.cjs +1915 -0
  6. package/dist/cjs/evm/index.cjs.map +1 -0
  7. package/dist/cjs/evm/index.d.cts +13 -0
  8. package/dist/cjs/index-CYu6i--S.d.cts +136 -0
  9. package/dist/cjs/index-DUVcpIhD.d.cts +203 -0
  10. package/dist/cjs/index-b7Qo5mCj.d.cts +664 -0
  11. package/dist/cjs/index-fNLnPKzv.d.cts +213 -0
  12. package/dist/cjs/index.cjs +7189 -0
  13. package/dist/cjs/index.cjs.map +1 -0
  14. package/dist/cjs/index.d.cts +192 -0
  15. package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.cjs +4 -0
  16. package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.cjs.map +1 -0
  17. package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.d.cts +1234 -0
  18. package/dist/cjs/solana/index.cjs +3749 -0
  19. package/dist/cjs/solana/index.cjs.map +1 -0
  20. package/dist/cjs/solana/index.d.cts +17 -0
  21. package/dist/cjs/sui/index.cjs +1021 -0
  22. package/dist/cjs/sui/index.cjs.map +1 -0
  23. package/dist/cjs/sui/index.d.cts +13 -0
  24. package/dist/esm/BaseStreamClient-CQOC8m8V.d.ts +542 -0
  25. package/dist/esm/aptos/index.d.ts +14 -4
  26. package/dist/esm/aptos/index.js +443 -4
  27. package/dist/esm/aptos/index.js.map +1 -0
  28. package/dist/esm/evm/index.d.ts +13 -5
  29. package/dist/esm/evm/index.js +1902 -5
  30. package/dist/esm/evm/index.js.map +1 -0
  31. package/dist/esm/index-BEo0O2IG.d.ts +664 -0
  32. package/dist/esm/index-CWmb3-x9.d.ts +136 -0
  33. package/dist/esm/index-Cgv37xlG.d.ts +213 -0
  34. package/dist/esm/index-D6QYg8hn.d.ts +203 -0
  35. package/dist/esm/index.d.ts +192 -10
  36. package/dist/esm/index.js +7096 -10
  37. package/dist/esm/index.js.map +1 -0
  38. package/dist/esm/solana/descriptor/idl/streamflow_aligned_unlocks.json +917 -1368
  39. package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.d.ts +3 -1
  40. package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js +3 -1
  41. package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js.map +1 -0
  42. package/dist/esm/solana/index.d.ts +17 -7
  43. package/dist/esm/solana/index.js +3693 -7
  44. package/dist/esm/solana/index.js.map +1 -0
  45. package/dist/esm/sui/index.d.ts +13 -4
  46. package/dist/esm/sui/index.js +1011 -4
  47. package/dist/esm/sui/index.js.map +1 -0
  48. package/package.json +57 -27
  49. package/dist/cjs/__tests__/aptos/streamClient.spec.js +0 -111
  50. package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +0 -45
  51. package/dist/cjs/aptos/StreamClient.js +0 -226
  52. package/dist/cjs/aptos/constants.js +0 -27
  53. package/dist/cjs/aptos/index.js +0 -38
  54. package/dist/cjs/aptos/types.js +0 -69
  55. package/dist/cjs/aptos/utils.js +0 -34
  56. package/dist/cjs/aptos/wallet.js +0 -34
  57. package/dist/cjs/common/BaseStreamClient.js +0 -23
  58. package/dist/cjs/common/GenericStreamClient.js +0 -102
  59. package/dist/cjs/common/constants.js +0 -10
  60. package/dist/cjs/common/contractUtils.js +0 -77
  61. package/dist/cjs/common/types.js +0 -141
  62. package/dist/cjs/common/utils.js +0 -69
  63. package/dist/cjs/evm/StreamClient.js +0 -238
  64. package/dist/cjs/evm/abi.js +0 -1257
  65. package/dist/cjs/evm/constants.js +0 -38
  66. package/dist/cjs/evm/ercAbi.js +0 -224
  67. package/dist/cjs/evm/index.js +0 -40
  68. package/dist/cjs/evm/types.js +0 -66
  69. package/dist/cjs/evm/utils.js +0 -11
  70. package/dist/cjs/index.js +0 -43
  71. package/dist/cjs/solana/StreamClient.js +0 -1042
  72. package/dist/cjs/solana/constants.js +0 -95
  73. package/dist/cjs/solana/descriptor/idl/streamflow_aligned_unlocks.json +0 -1437
  74. package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.js +0 -2
  75. package/dist/cjs/solana/index.js +0 -40
  76. package/dist/cjs/solana/instructionTypes.js +0 -2
  77. package/dist/cjs/solana/instructions.js +0 -298
  78. package/dist/cjs/solana/layout.js +0 -182
  79. package/dist/cjs/solana/lib/derive-accounts.js +0 -17
  80. package/dist/cjs/solana/lib/utils.js +0 -127
  81. package/dist/cjs/solana/timelockIDL.js +0 -422
  82. package/dist/cjs/solana/types.js +0 -93
  83. package/dist/cjs/sui/StreamClient.js +0 -416
  84. package/dist/cjs/sui/constants.js +0 -42
  85. package/dist/cjs/sui/index.js +0 -37
  86. package/dist/cjs/sui/types.js +0 -68
  87. package/dist/cjs/sui/utils.js +0 -46
  88. package/dist/cjs/sui/wallet.js +0 -40
  89. package/dist/esm/__tests__/aptos/streamClient.spec.d.ts +0 -1
  90. package/dist/esm/__tests__/aptos/streamClient.spec.js +0 -106
  91. package/dist/esm/__tests__/common/GenericStreamClient.spec.d.ts +0 -1
  92. package/dist/esm/__tests__/common/GenericStreamClient.spec.js +0 -40
  93. package/dist/esm/aptos/StreamClient.d.ts +0 -53
  94. package/dist/esm/aptos/StreamClient.js +0 -226
  95. package/dist/esm/aptos/constants.d.ts +0 -8
  96. package/dist/esm/aptos/constants.js +0 -24
  97. package/dist/esm/aptos/types.d.ts +0 -109
  98. package/dist/esm/aptos/types.js +0 -105
  99. package/dist/esm/aptos/utils.d.ts +0 -7
  100. package/dist/esm/aptos/utils.js +0 -30
  101. package/dist/esm/aptos/wallet.d.ts +0 -9
  102. package/dist/esm/aptos/wallet.js +0 -33
  103. package/dist/esm/common/BaseStreamClient.d.ts +0 -22
  104. package/dist/esm/common/BaseStreamClient.js +0 -19
  105. package/dist/esm/common/GenericStreamClient.d.ts +0 -72
  106. package/dist/esm/common/GenericStreamClient.js +0 -101
  107. package/dist/esm/common/constants.d.ts +0 -4
  108. package/dist/esm/common/constants.js +0 -4
  109. package/dist/esm/common/contractUtils.d.ts +0 -63
  110. package/dist/esm/common/contractUtils.js +0 -61
  111. package/dist/esm/common/types.d.ts +0 -353
  112. package/dist/esm/common/types.js +0 -135
  113. package/dist/esm/common/utils.d.ts +0 -32
  114. package/dist/esm/common/utils.js +0 -59
  115. package/dist/esm/evm/StreamClient.d.ts +0 -32
  116. package/dist/esm/evm/StreamClient.js +0 -237
  117. package/dist/esm/evm/abi.d.ts +0 -111
  118. package/dist/esm/evm/abi.js +0 -1255
  119. package/dist/esm/evm/constants.d.ts +0 -20
  120. package/dist/esm/evm/constants.js +0 -35
  121. package/dist/esm/evm/ercAbi.d.ts +0 -39
  122. package/dist/esm/evm/ercAbi.js +0 -222
  123. package/dist/esm/evm/types.d.ts +0 -98
  124. package/dist/esm/evm/types.js +0 -102
  125. package/dist/esm/evm/utils.d.ts +0 -1
  126. package/dist/esm/evm/utils.js +0 -8
  127. package/dist/esm/solana/StreamClient.d.ts +0 -150
  128. package/dist/esm/solana/StreamClient.js +0 -1017
  129. package/dist/esm/solana/constants.d.ts +0 -70
  130. package/dist/esm/solana/constants.js +0 -92
  131. package/dist/esm/solana/instructionTypes.d.ts +0 -101
  132. package/dist/esm/solana/instructionTypes.js +0 -1
  133. package/dist/esm/solana/instructions.d.ts +0 -142
  134. package/dist/esm/solana/instructions.js +0 -265
  135. package/dist/esm/solana/layout.d.ts +0 -27
  136. package/dist/esm/solana/layout.js +0 -155
  137. package/dist/esm/solana/lib/derive-accounts.d.ts +0 -4
  138. package/dist/esm/solana/lib/derive-accounts.js +0 -11
  139. package/dist/esm/solana/lib/utils.d.ts +0 -22
  140. package/dist/esm/solana/lib/utils.js +0 -117
  141. package/dist/esm/solana/timelockIDL.d.ts +0 -22
  142. package/dist/esm/solana/timelockIDL.js +0 -420
  143. package/dist/esm/solana/types.d.ts +0 -180
  144. package/dist/esm/solana/types.js +0 -142
  145. package/dist/esm/sui/StreamClient.d.ts +0 -82
  146. package/dist/esm/sui/StreamClient.js +0 -417
  147. package/dist/esm/sui/constants.d.ts +0 -10
  148. package/dist/esm/sui/constants.js +0 -39
  149. package/dist/esm/sui/types.d.ts +0 -167
  150. package/dist/esm/sui/types.js +0 -104
  151. package/dist/esm/sui/utils.d.ts +0 -11
  152. package/dist/esm/sui/utils.js +0 -39
  153. package/dist/esm/sui/wallet.d.ts +0 -17
  154. package/dist/esm/sui/wallet.js +0 -38
@@ -1,142 +0,0 @@
1
- import { buildStreamType, calculateUnlockedAmount, decodeEndTime } from "../common/contractUtils.js";
2
- import { getNumberFromBN } from "../common/utils.js";
3
- import { ALIGNED_PRECISION_FACTOR_POW } from "./constants.js";
4
- export { IChain, ICluster, ContractError } from "@streamflow/common";
5
- export class Contract {
6
- magic;
7
- version;
8
- createdAt;
9
- withdrawnAmount;
10
- canceledAt;
11
- end;
12
- lastWithdrawnAt;
13
- sender;
14
- senderTokens;
15
- recipient;
16
- recipientTokens;
17
- mint;
18
- escrowTokens;
19
- streamflowTreasury;
20
- streamflowTreasuryTokens;
21
- streamflowFeeTotal;
22
- streamflowFeeWithdrawn;
23
- streamflowFeePercent;
24
- partnerFeeTotal;
25
- partnerFeeWithdrawn;
26
- partnerFeePercent;
27
- partner;
28
- partnerTokens;
29
- start;
30
- depositedAmount;
31
- period;
32
- amountPerPeriod;
33
- cliff;
34
- cliffAmount;
35
- cancelableBySender;
36
- cancelableByRecipient;
37
- automaticWithdrawal;
38
- transferableBySender;
39
- transferableByRecipient;
40
- canTopup;
41
- name;
42
- withdrawalFrequency;
43
- closed;
44
- currentPauseStart;
45
- pauseCumulative;
46
- lastRateChangeTime;
47
- fundsUnlockedAtLastRateChange;
48
- type;
49
- isAligned;
50
- constructor(stream) {
51
- this.magic = stream.magic.toNumber();
52
- this.version = stream.version.toNumber();
53
- this.createdAt = stream.createdAt.toNumber();
54
- this.withdrawnAmount = stream.withdrawnAmount;
55
- this.canceledAt = stream.canceledAt.toNumber();
56
- // for aligned contracts end time can be an invalid timeValue
57
- this.end = decodeEndTime(stream.end);
58
- this.lastWithdrawnAt = stream.lastWithdrawnAt.toNumber();
59
- this.sender = stream.sender.toBase58();
60
- this.senderTokens = stream.senderTokens.toBase58();
61
- this.recipient = stream.recipient.toBase58();
62
- this.recipientTokens = stream.recipientTokens.toBase58();
63
- this.mint = stream.mint.toBase58();
64
- this.escrowTokens = stream.escrowTokens.toBase58();
65
- this.streamflowTreasury = stream.streamflowTreasury.toBase58();
66
- this.streamflowTreasuryTokens = stream.streamflowTreasuryTokens.toBase58();
67
- this.streamflowFeeTotal = stream.streamflowFeeTotal;
68
- this.streamflowFeeWithdrawn = stream.streamflowFeeWithdrawn;
69
- this.streamflowFeePercent = stream.streamflowFeePercent.toNumber();
70
- this.partnerFeeTotal = stream.partnerFeeTotal;
71
- this.partnerFeeWithdrawn = stream.partnerFeeWithdrawn;
72
- this.partnerFeePercent = stream.partnerFeePercent.toNumber();
73
- this.partner = stream.partner.toBase58();
74
- this.partnerTokens = stream.partnerTokens?.toBase58();
75
- this.start = stream.start.toNumber();
76
- this.depositedAmount = stream.depositedAmount;
77
- this.period = stream.period.toNumber();
78
- this.amountPerPeriod = stream.amountPerPeriod;
79
- this.cliff = stream.cliff.toNumber();
80
- this.cliffAmount = stream.cliffAmount;
81
- this.cancelableBySender = stream.cancelableBySender;
82
- this.cancelableByRecipient = stream.cancelableByRecipient;
83
- this.automaticWithdrawal = stream.automaticWithdrawal;
84
- this.transferableBySender = stream.transferableBySender;
85
- this.transferableByRecipient = stream.transferableByRecipient;
86
- this.canTopup = stream.canTopup;
87
- this.name = stream.name;
88
- this.withdrawalFrequency = stream.withdrawFrequency.toNumber();
89
- this.closed = stream.closed;
90
- this.currentPauseStart = stream.currentPauseStart.toNumber();
91
- this.pauseCumulative = stream.pauseCumulative;
92
- this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
93
- this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
94
- this.type = buildStreamType(this);
95
- this.isAligned = false;
96
- }
97
- unlocked(currentTimestamp) {
98
- return calculateUnlockedAmount({
99
- ...this,
100
- currentTimestamp,
101
- });
102
- }
103
- remaining(decimals) {
104
- return getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
105
- }
106
- }
107
- export class AlignedContract extends Contract {
108
- minPrice;
109
- maxPrice;
110
- minPercentage;
111
- maxPercentage;
112
- tickSize;
113
- proxyAddress;
114
- priceOracle;
115
- oracleType;
116
- initialAmountPerPeriod;
117
- initialPrice;
118
- lastPrice;
119
- lastAmountUpdateTime;
120
- initialNetAmount;
121
- constructor(stream, alignedProxy) {
122
- super(stream);
123
- this.minPrice = getNumberFromBN(alignedProxy.minPrice, ALIGNED_PRECISION_FACTOR_POW);
124
- this.maxPrice = getNumberFromBN(alignedProxy.maxPrice, ALIGNED_PRECISION_FACTOR_POW);
125
- this.minPercentage = getNumberFromBN(alignedProxy.minPercentage, ALIGNED_PRECISION_FACTOR_POW);
126
- this.maxPercentage = getNumberFromBN(alignedProxy.maxPercentage, ALIGNED_PRECISION_FACTOR_POW);
127
- this.oracleType = (Object.keys(alignedProxy.priceOracleType).find((key) => !!key) || "none");
128
- this.tickSize = alignedProxy.tickSize.toNumber();
129
- this.priceOracle = this.oracleType === "none" ? undefined : alignedProxy.priceOracle.toBase58();
130
- this.sender = alignedProxy.sender.toBase58();
131
- this.canceledAt = alignedProxy.streamCanceledTime.toNumber();
132
- this.proxyAddress = stream.sender.toBase58();
133
- this.initialAmountPerPeriod = alignedProxy.initialAmountPerPeriod;
134
- this.initialPrice = getNumberFromBN(alignedProxy.initialPrice, ALIGNED_PRECISION_FACTOR_POW);
135
- this.lastPrice = getNumberFromBN(alignedProxy.lastPrice, ALIGNED_PRECISION_FACTOR_POW);
136
- this.lastAmountUpdateTime = alignedProxy.lastAmountUpdateTime.toNumber();
137
- this.initialNetAmount = alignedProxy.initialNetAmount;
138
- // need to call this again since minPrice and maxPrice are used in determining the type
139
- this.type = buildStreamType(this);
140
- this.isAligned = true;
141
- }
142
- }
@@ -1,82 +0,0 @@
1
- import { BaseStreamClient } from "../common/BaseStreamClient.js";
2
- import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetFeesData, IGetOneData, IFees, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData } from "../common/types.js";
3
- import { Contract, ICreateStreamSuiExt, ITransactionSuiExt, ISuiIdParameters } from "./types.js";
4
- export default class SuiStreamClient extends BaseStreamClient {
5
- private programId;
6
- private configId;
7
- private feeTableId;
8
- private client;
9
- constructor(clusterUrl: string, cluster?: ICluster, ids?: ISuiIdParameters);
10
- /**
11
- * Creates a new stream/vesting contract.
12
- */
13
- create(streamData: ICreateStreamData, { senderWallet }: ICreateStreamSuiExt): Promise<ICreateResult>;
14
- /**
15
- * Creates multiple stream/vesting contracts.
16
- * We don't chain transactions in one Block so that one failed transaction does not revert all others.
17
- */
18
- createMultiple(multipleStreamData: ICreateMultipleStreamData, { senderWallet }: ICreateStreamSuiExt): Promise<IMultiTransactionResult>;
19
- /**
20
- * Attempts withdrawing from the specified stream.
21
- */
22
- withdraw({ id, amount }: IWithdrawData, { senderWallet, tokenId }: ITransactionSuiExt): Promise<ITransactionResult>;
23
- /**
24
- * Attempts canceling the specified stream.
25
- */
26
- cancel(cancelData: ICancelData, { senderWallet, tokenId }: ITransactionSuiExt): Promise<ITransactionResult>;
27
- /**
28
- * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
29
- */
30
- transfer(transferData: ITransferData, { senderWallet, tokenId }: ITransactionSuiExt): Promise<ITransactionResult>;
31
- /**
32
- * Tops up stream account with specified amount.
33
- */
34
- topup(topupData: ITopUpData, { senderWallet, tokenId }: ITransactionSuiExt): Promise<ITransactionResult>;
35
- /**
36
- * Fetch stream data by its id (address).
37
- */
38
- getOne({ id }: IGetOneData): Promise<Contract>;
39
- get(): Promise<[string, Contract][]>;
40
- /**
41
- * Attempts updating the stream auto withdrawal params and amount per period
42
- */
43
- update(updateData: IUpdateData, { senderWallet, tokenId }: ITransactionSuiExt): Promise<ITransactionResult>;
44
- extractErrorCode(err: Error): string | null;
45
- getFees({ address }: IGetFeesData): Promise<IFees | null>;
46
- getDefaultStreamflowFee(): Promise<number>;
47
- /**
48
- * Returns StreamClient protocol program ID.
49
- */
50
- getProgramId(): string;
51
- /**
52
- * Utility function to generate Transaction Block to create streams
53
- */
54
- private generateCreateBlock;
55
- /**
56
- * Returns all coins owned by a Wallet
57
- * @param walletAddress wallet address
58
- * @param coinType coin type
59
- * @returns Array of Coin Structs
60
- */
61
- private getAllCoins;
62
- /**
63
- * Utility function to split Coin object and use splitted object for stream operations.
64
- * We do it like thid to mitigate risk of Transaction reverting in case Stream is created for Sui Coin object.
65
- * This way we can safely pass splitted Sui Coin object in Stream payload and use another object for gas/withdrawal fees.
66
- * @param tx current transanction block
67
- * @param amount minimal amount of coins requried
68
- * @param coinType coin type
69
- * @param coins array of owned coins of the same type
70
- * @param totalFee partner and treasury fees
71
- * @returns Coin Object to use in a Move Call
72
- */
73
- private splitCoinObjectForAmount;
74
- /**
75
- * Return previously splitted Coin Object to owner and merge it to to rebate storage fees
76
- * @param tx current transaction
77
- * @param coinType coin type
78
- * @param coinObject splitted object
79
- * @param coins array of objects used in
80
- */
81
- private returnSplittedCoinObject;
82
- }
@@ -1,417 +0,0 @@
1
- import { SuiClient } from "@mysten/sui/client";
2
- import { Transaction } from "@mysten/sui/transactions";
3
- import { SUI_CLOCK_OBJECT_ID, SUI_TYPE_ARG } from "@mysten/sui/utils";
4
- import { bcs } from "@mysten/sui/bcs";
5
- import { BaseStreamClient } from "../common/BaseStreamClient.js";
6
- import { ICluster, } from "../common/types.js";
7
- import { SUI_PROGRAM_IDS, SUI_FEE_TABLE_IDS, SUI_CONFIG_IDS } from "./constants.js";
8
- import { Contract, } from "./types.js";
9
- import { extractSuiErrorInfo, getTransactionBlock } from "./utils.js";
10
- import { SuiWalletWrapper } from "./wallet.js";
11
- import { calculateTotalAmountToDeposit } from "../common/utils.js";
12
- import { WITHDRAW_AVAILABLE_AMOUNT } from "../common/constants.js";
13
- export default class SuiStreamClient extends BaseStreamClient {
14
- programId;
15
- configId;
16
- feeTableId;
17
- client;
18
- constructor(clusterUrl, cluster = ICluster.Mainnet, ids) {
19
- super();
20
- this.programId = ids?.program ? ids.program : SUI_PROGRAM_IDS[cluster];
21
- this.configId = ids?.config ? ids.config : SUI_CONFIG_IDS[cluster];
22
- this.feeTableId = ids?.feeTable ? ids.feeTable : SUI_FEE_TABLE_IDS[cluster];
23
- this.client = new SuiClient({ url: clusterUrl });
24
- }
25
- /**
26
- * Creates a new stream/vesting contract.
27
- */
28
- async create(streamData, { senderWallet }) {
29
- const wallet = new SuiWalletWrapper(senderWallet, this.client);
30
- const totalFee = await this.getTotalFee({
31
- address: streamData.partner ?? wallet.address,
32
- });
33
- const [tx] = await this.generateCreateBlock(wallet.address, {
34
- ...streamData,
35
- recipients: [{ ...streamData }],
36
- }, totalFee);
37
- const { digest, events } = await wallet.signAndExecuteTransaction({
38
- transaction: tx,
39
- options: { showEvents: true },
40
- });
41
- return {
42
- ixs: [],
43
- txId: digest,
44
- metadataId: events[0].parsedJson.address,
45
- };
46
- }
47
- /**
48
- * Creates multiple stream/vesting contracts.
49
- * We don't chain transactions in one Block so that one failed transaction does not revert all others.
50
- */
51
- async createMultiple(multipleStreamData, { senderWallet }) {
52
- const wallet = new SuiWalletWrapper(senderWallet, this.client);
53
- const totalFee = await this.getTotalFee({
54
- address: multipleStreamData.partner ?? wallet.address,
55
- });
56
- const [tx, firstIndex] = await this.generateCreateBlock(wallet.address, multipleStreamData, totalFee);
57
- const txs = [];
58
- const metadatas = [];
59
- const metadataToRecipient = {};
60
- const errors = [];
61
- try {
62
- const executedTx = await wallet.signAndExecuteTransaction({
63
- transaction: tx,
64
- options: { showEffects: true, showEvents: true },
65
- });
66
- const digest = executedTx.digest;
67
- // effects may be string according to Sui Wallet standard, events won't even be returned
68
- // https://github.com/MystenLabs/ts-sdks/blob/main/packages/wallet-standard/src/features/suiSignAndExecuteTransaction.ts#L34
69
- const { events, effects } = !executedTx.effects || typeof executedTx.effects === "string"
70
- ? await getTransactionBlock(this.client, { digest, options: { showEvents: true, showEffects: true } })
71
- : executedTx;
72
- txs.push(digest);
73
- if (effects.status.status === "failure") {
74
- multipleStreamData.recipients.forEach((recipient) => {
75
- errors.push({
76
- error: effects.status.error ?? "Unknown error!",
77
- recipient: recipient.recipient,
78
- });
79
- });
80
- }
81
- else {
82
- multipleStreamData.recipients.forEach((recipient, index) => {
83
- const metadataId = events[index].parsedJson.address;
84
- metadatas.push(metadataId);
85
- metadataToRecipient[metadataId] = recipient;
86
- });
87
- }
88
- }
89
- catch (e) {
90
- const errorInfo = extractSuiErrorInfo(e.toString() ?? "Unknown error!");
91
- multipleStreamData.recipients.forEach((recipient, index) => {
92
- if (errorInfo.index === undefined ||
93
- errorInfo.index < index + firstIndex ||
94
- errorInfo.index >= multipleStreamData.recipients.length + firstIndex ||
95
- errorInfo.index === index + firstIndex) {
96
- errors.push({
97
- error: errorInfo.text,
98
- recipient: recipient.recipient,
99
- contractErrorCode: errorInfo.parsed?.name,
100
- });
101
- }
102
- });
103
- }
104
- return {
105
- txs,
106
- metadatas,
107
- metadataToRecipient,
108
- errors,
109
- };
110
- }
111
- /**
112
- * Attempts withdrawing from the specified stream.
113
- */
114
- async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, { senderWallet, tokenId }) {
115
- const wallet = new SuiWalletWrapper(senderWallet, this.client);
116
- const tx = new Transaction();
117
- tx.moveCall({
118
- target: `${this.programId}::protocol::withdraw`,
119
- typeArguments: [tokenId],
120
- arguments: [
121
- tx.object(id),
122
- tx.object(this.configId),
123
- tx.object(SUI_CLOCK_OBJECT_ID),
124
- tx.pure.u64(amount.toString()),
125
- ],
126
- });
127
- const { digest } = await wallet.signAndExecuteTransaction({
128
- transaction: tx,
129
- });
130
- return {
131
- ixs: [],
132
- txId: digest,
133
- };
134
- }
135
- /**
136
- * Attempts canceling the specified stream.
137
- */
138
- async cancel(cancelData, { senderWallet, tokenId }) {
139
- const wallet = new SuiWalletWrapper(senderWallet, this.client);
140
- const tx = new Transaction();
141
- tx.moveCall({
142
- target: `${this.programId}::protocol::cancel`,
143
- typeArguments: [tokenId],
144
- arguments: [tx.object(cancelData.id), tx.object(this.configId), tx.object(SUI_CLOCK_OBJECT_ID)],
145
- });
146
- const { digest } = await wallet.signAndExecuteTransaction({
147
- transaction: tx,
148
- });
149
- return {
150
- ixs: [],
151
- txId: digest,
152
- };
153
- }
154
- /**
155
- * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
156
- */
157
- async transfer(transferData, { senderWallet, tokenId }) {
158
- const wallet = new SuiWalletWrapper(senderWallet, this.client);
159
- const tx = new Transaction();
160
- tx.moveCall({
161
- target: `${this.programId}::protocol::transfer`,
162
- typeArguments: [tokenId],
163
- arguments: [tx.object(transferData.id), tx.pure.address(transferData.newRecipient)],
164
- });
165
- const { digest } = await wallet.signAndExecuteTransaction({
166
- transaction: tx,
167
- });
168
- return {
169
- ixs: [],
170
- txId: digest,
171
- };
172
- }
173
- /**
174
- * Tops up stream account with specified amount.
175
- */
176
- async topup(topupData, { senderWallet, tokenId }) {
177
- const wallet = new SuiWalletWrapper(senderWallet, this.client);
178
- const tx = new Transaction();
179
- const coins = await this.getAllCoins(wallet.address, tokenId);
180
- const stream = await this.getOne({ id: topupData.id });
181
- const totalFee = (stream.partnerFeePercent + stream.streamflowFeePercent) / 100;
182
- const coinObject = this.splitCoinObjectForAmount(tx, topupData.amount, tokenId, coins, totalFee);
183
- tx.moveCall({
184
- target: `${this.programId}::protocol::topup`,
185
- typeArguments: [tokenId],
186
- arguments: [
187
- tx.object(topupData.id),
188
- tx.object(this.configId),
189
- coinObject,
190
- tx.gas,
191
- tx.pure.u64(topupData.amount.toString()),
192
- ],
193
- });
194
- this.returnSplittedCoinObject(tx, tokenId, coins, coinObject);
195
- const { digest } = await wallet.signAndExecuteTransaction({
196
- transaction: tx,
197
- });
198
- return {
199
- ixs: [],
200
- txId: digest,
201
- };
202
- }
203
- /**
204
- * Fetch stream data by its id (address).
205
- */
206
- async getOne({ id }) {
207
- const response = await this.client.getObject({
208
- id,
209
- options: {
210
- showContent: true,
211
- },
212
- });
213
- if (!response.data) {
214
- throw new Error(`Contract with id ${id} could not be found!`);
215
- }
216
- const content = response.data.content;
217
- if (content.dataType !== "moveObject") {
218
- throw new Error(`Not a Move Object!`);
219
- }
220
- return new Contract(content.fields, "0x97e9a9fb1392e9785319f5512d0bfde6ecf7757b09c6de41cec89e798dd361f2::strmt::STRMT");
221
- }
222
- async get() {
223
- throw new Error("Get all method is not supported for Sui chain!");
224
- }
225
- /**
226
- * Attempts updating the stream auto withdrawal params and amount per period
227
- */
228
- async update(updateData, { senderWallet, tokenId }) {
229
- const wallet = new SuiWalletWrapper(senderWallet, this.client);
230
- const tx = new Transaction();
231
- tx.moveCall({
232
- target: `${this.programId}::protocol::update`,
233
- typeArguments: [tokenId],
234
- arguments: [
235
- tx.object(updateData.id),
236
- tx.object(this.configId),
237
- tx.object(SUI_CLOCK_OBJECT_ID),
238
- tx.gas,
239
- bcs
240
- .vector(bcs.bool())
241
- .serialize(updateData.enableAutomaticWithdrawal !== undefined ? [updateData.enableAutomaticWithdrawal] : []),
242
- bcs
243
- .vector(bcs.u64())
244
- .serialize(updateData.withdrawFrequency !== undefined ? [updateData.withdrawFrequency.toString()] : []),
245
- bcs
246
- .vector(bcs.u64())
247
- .serialize(updateData.amountPerPeriod !== undefined ? [updateData.amountPerPeriod.toString()] : []),
248
- ],
249
- });
250
- const { digest } = await wallet.signAndExecuteTransaction({
251
- transaction: tx,
252
- });
253
- return {
254
- ixs: [],
255
- txId: digest,
256
- };
257
- }
258
- extractErrorCode(err) {
259
- const errorInfo = extractSuiErrorInfo(err.toString() ?? "Unknown error!");
260
- return errorInfo?.parsed?.name || null;
261
- }
262
- async getFees({ address }) {
263
- const response = await this.client.getObject({
264
- id: this.feeTableId,
265
- options: {
266
- showContent: true,
267
- },
268
- });
269
- const content = response.data.content;
270
- if (content.dataType !== "moveObject") {
271
- throw new Error(`Not a Move Object!`);
272
- }
273
- const fields = content.fields;
274
- const fieldsResponse = await this.client.getDynamicFields({
275
- parentId: fields.values.fields.id.id,
276
- });
277
- const partnerDynamicField = fieldsResponse.data.filter((item) => item.name.value === address)[0];
278
- if (!partnerDynamicField) {
279
- return null;
280
- }
281
- const valueResponse = await this.client.getObject({
282
- id: partnerDynamicField.objectId,
283
- options: {
284
- showContent: true,
285
- },
286
- });
287
- const valueContent = valueResponse.data.content;
288
- if (valueContent.dataType !== "moveObject") {
289
- throw new Error(`Not a Move Object!`);
290
- }
291
- const valueFields = valueContent.fields.value.fields;
292
- return {
293
- streamflowFee: Number(valueFields.streamflow_fee) / 100,
294
- partnerFee: Number(valueFields.partner_fee) / 100,
295
- };
296
- }
297
- async getDefaultStreamflowFee() {
298
- const response = await this.client.getObject({
299
- id: this.configId,
300
- options: {
301
- showContent: true,
302
- },
303
- });
304
- const content = response.data.content;
305
- if (content.dataType !== "moveObject") {
306
- throw new Error(`Not a Move Object!`);
307
- }
308
- const fields = content.fields;
309
- return Number(fields.streamflow_fee) / 100;
310
- }
311
- /**
312
- * Returns StreamClient protocol program ID.
313
- */
314
- getProgramId() {
315
- return this.programId;
316
- }
317
- /**
318
- * Utility function to generate Transaction Block to create streams
319
- */
320
- async generateCreateBlock(walletAddress, multipleStreamData, totalFee) {
321
- let coins = await this.getAllCoins(walletAddress, multipleStreamData.tokenId);
322
- const totalAmount = multipleStreamData.recipients
323
- .map((recipiient) => recipiient.amount)
324
- .reduce((prev, current) => current.add(prev));
325
- const tx = new Transaction();
326
- const coinObject = this.splitCoinObjectForAmount(tx, totalAmount, multipleStreamData.tokenId, coins, totalFee);
327
- coins = [coins[0]];
328
- let firstIndex = null;
329
- multipleStreamData.recipients.forEach((recipient) => {
330
- const result = tx.moveCall({
331
- target: `${this.programId}::protocol::create`,
332
- typeArguments: [multipleStreamData.tokenId],
333
- arguments: [
334
- tx.object(this.configId),
335
- tx.object(this.feeTableId),
336
- tx.object(SUI_CLOCK_OBJECT_ID),
337
- coinObject,
338
- tx.gas,
339
- tx.pure.u64(recipient.amount.toString()),
340
- tx.pure.u64(multipleStreamData.period),
341
- tx.pure.u64(recipient.amountPerPeriod.toString()),
342
- tx.pure.u64(multipleStreamData.start),
343
- tx.pure.u64(recipient.cliffAmount.toString()),
344
- tx.pure.bool(multipleStreamData.cancelableBySender),
345
- tx.pure.bool(multipleStreamData.cancelableByRecipient),
346
- tx.pure.bool(multipleStreamData.transferableBySender),
347
- tx.pure.bool(multipleStreamData.transferableByRecipient),
348
- tx.pure.bool(multipleStreamData.canTopup),
349
- tx.pure.bool(!!multipleStreamData.canPause),
350
- tx.pure.bool(!!multipleStreamData.canUpdateRate),
351
- tx.pure.bool(!!multipleStreamData.automaticWithdrawal),
352
- tx.pure.u64(multipleStreamData.withdrawalFrequency || 0),
353
- tx.pure.string(recipient.name),
354
- tx.pure.address(recipient.recipient),
355
- tx.pure.address(multipleStreamData.partner || walletAddress),
356
- ],
357
- });
358
- if (result.$kind === "Result" && firstIndex === null) {
359
- firstIndex = result.Result;
360
- }
361
- });
362
- this.returnSplittedCoinObject(tx, multipleStreamData.tokenId, coins, coinObject);
363
- return [tx, firstIndex];
364
- }
365
- /**
366
- * Returns all coins owned by a Wallet
367
- * @param walletAddress wallet address
368
- * @param coinType coin type
369
- * @returns Array of Coin Structs
370
- */
371
- async getAllCoins(walletAddress, coinType) {
372
- let coinsResponse = await this.client.getCoins({
373
- owner: walletAddress,
374
- coinType: coinType,
375
- });
376
- const coins = coinsResponse.data;
377
- while (coinsResponse.hasNextPage) {
378
- coinsResponse = await this.client.getCoins({
379
- owner: walletAddress,
380
- coinType: coinType,
381
- cursor: coinsResponse.nextCursor,
382
- });
383
- coins.push(...coinsResponse.data);
384
- }
385
- return coins;
386
- }
387
- /**
388
- * Utility function to split Coin object and use splitted object for stream operations.
389
- * We do it like thid to mitigate risk of Transaction reverting in case Stream is created for Sui Coin object.
390
- * This way we can safely pass splitted Sui Coin object in Stream payload and use another object for gas/withdrawal fees.
391
- * @param tx current transanction block
392
- * @param amount minimal amount of coins requried
393
- * @param coinType coin type
394
- * @param coins array of owned coins of the same type
395
- * @param totalFee partner and treasury fees
396
- * @returns Coin Object to use in a Move Call
397
- */
398
- splitCoinObjectForAmount(tx, amount, coinType, coins, totalFee) {
399
- const coinObject = coinType === SUI_TYPE_ARG ? tx.gas : tx.object(coins[0].coinObjectId);
400
- if (coins.length > 1) {
401
- tx.mergeCoins(coinObject, coins.slice(1).map((item) => tx.object(item.coinObjectId)));
402
- }
403
- const totalAmount = calculateTotalAmountToDeposit(amount, totalFee);
404
- return tx.splitCoins(coinObject, [tx.pure.u64(totalAmount.toString())])[0];
405
- }
406
- /**
407
- * Return previously splitted Coin Object to owner and merge it to to rebate storage fees
408
- * @param tx current transaction
409
- * @param coinType coin type
410
- * @param coinObject splitted object
411
- * @param coins array of objects used in
412
- */
413
- returnSplittedCoinObject(tx, coinType, coins, coinObject) {
414
- const firstCoinObject = coinType === SUI_TYPE_ARG ? tx.gas : tx.object(coins[0].coinObjectId);
415
- tx.mergeCoins(firstCoinObject, [coinObject]);
416
- }
417
- }
@@ -1,10 +0,0 @@
1
- import { ICluster } from "../common/types.js";
2
- export declare const SUI_PROGRAM_IDS: Record<ICluster, string>;
3
- export declare const SUI_CONFIG_IDS: Record<ICluster, string>;
4
- export declare const SUI_FEE_TABLE_IDS: Record<ICluster, string>;
5
- export declare const SUI_ERROR_MATCH_REGEX: RegExp;
6
- export declare const SUI_MODULE_ERROR_MAP: {
7
- [key: string]: {
8
- [key: number]: string;
9
- };
10
- };