@streamflow/stream 4.1.0-beta.9 → 5.0.0
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.
- package/dist/aptos/types.d.ts +10 -0
- package/dist/aptos/types.js +7 -7
- package/dist/common/GenericStreamClient.d.ts +16 -11
- package/dist/common/GenericStreamClient.js +28 -35
- package/dist/common/contractUtils.d.ts +2 -0
- package/dist/common/contractUtils.js +21 -0
- package/dist/common/types.d.ts +2 -1
- package/dist/common/types.js +1 -0
- package/dist/evm/StreamClient.js +28 -8
- package/dist/evm/types.d.ts +10 -0
- package/dist/evm/types.js +7 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/solana/constants.d.ts +1 -0
- package/dist/solana/constants.js +3 -1
- package/dist/solana/instructionTypes.d.ts +10 -0
- package/dist/solana/layout.js +12 -0
- package/dist/solana/types.d.ts +15 -0
- package/dist/solana/types.js +7 -11
- package/dist/solana/utils.js +10 -0
- package/package.json +2 -2
package/dist/aptos/types.d.ts
CHANGED
|
@@ -83,6 +83,11 @@ export interface Stream {
|
|
|
83
83
|
canTopup: boolean;
|
|
84
84
|
name: string;
|
|
85
85
|
withdrawalFrequency: number;
|
|
86
|
+
closed: boolean;
|
|
87
|
+
currentPauseStart: number;
|
|
88
|
+
pauseCumulative: BN;
|
|
89
|
+
lastRateChangeTime: number;
|
|
90
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
86
91
|
unlocked(currentTimestamp: number): BN;
|
|
87
92
|
}
|
|
88
93
|
export declare class Contract implements Stream {
|
|
@@ -123,6 +128,11 @@ export declare class Contract implements Stream {
|
|
|
123
128
|
canTopup: boolean;
|
|
124
129
|
name: string;
|
|
125
130
|
withdrawalFrequency: number;
|
|
131
|
+
closed: boolean;
|
|
132
|
+
currentPauseStart: number;
|
|
133
|
+
pauseCumulative: BN;
|
|
134
|
+
lastRateChangeTime: number;
|
|
135
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
126
136
|
constructor(stream: StreamResource, tokenId: string);
|
|
127
137
|
unlocked(currentTimestamp: number): BN;
|
|
128
138
|
remaining(decimals: number): number;
|
package/dist/aptos/types.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Contract = void 0;
|
|
7
7
|
var bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
+
var contractUtils_1 = require("../common/contractUtils");
|
|
8
9
|
var utils_1 = require("../common/utils");
|
|
9
10
|
var Contract = /** @class */ (function () {
|
|
10
11
|
function Contract(stream, tokenId) {
|
|
@@ -46,15 +47,14 @@ var Contract = /** @class */ (function () {
|
|
|
46
47
|
var name = stream.meta.contract_name.replace("0x", "");
|
|
47
48
|
this.name = Buffer.from(name, "hex").toString("utf8");
|
|
48
49
|
this.withdrawalFrequency = parseInt(stream.meta.withdrawal_frequency);
|
|
50
|
+
this.closed = stream.closed;
|
|
51
|
+
this.currentPauseStart = parseInt(stream.current_pause_start);
|
|
52
|
+
this.pauseCumulative = new bn_js_1.default(stream.pause_cumulative);
|
|
53
|
+
this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
|
|
54
|
+
this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change);
|
|
49
55
|
}
|
|
50
56
|
Contract.prototype.unlocked = function (currentTimestamp) {
|
|
51
|
-
|
|
52
|
-
if (currentTimestamp < this.cliff)
|
|
53
|
-
return new bn_js_1.default(0);
|
|
54
|
-
if (currentTimestamp > this.end)
|
|
55
|
-
return deposited;
|
|
56
|
-
var streamed = this.cliffAmount.add(new bn_js_1.default(Math.floor((currentTimestamp - this.cliff) / this.period)).mul(this.amountPerPeriod));
|
|
57
|
-
return streamed.lt(deposited) ? streamed : deposited;
|
|
57
|
+
return (0, contractUtils_1.calculateUnlockedAmount)(this.depositedAmount, this.cliff, this.cliffAmount, this.end, currentTimestamp, this.lastRateChangeTime, this.period, this.amountPerPeriod, this.fundsUnlockedAtLastRateChange);
|
|
58
58
|
};
|
|
59
59
|
Contract.prototype.remaining = function (decimals) {
|
|
60
60
|
return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
@@ -28,35 +28,40 @@ export interface EvmStreamClientOptions {
|
|
|
28
28
|
cluster?: ICluster;
|
|
29
29
|
programId?: string;
|
|
30
30
|
}
|
|
31
|
-
declare type
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
declare type StreamClientOptions<T extends IChain> = T extends IChain.Solana ? SolanaStreamClientOptions : T extends IChain.Aptos ? AptosStreamClientOptions : EvmStreamClientOptions;
|
|
32
|
+
declare type StreamClientType<T extends IChain> = T extends IChain.Solana ? SolanaStreamClient : T extends IChain.Aptos ? AptosStreamClient : EvmStreamClient;
|
|
33
|
+
declare type ChainSpecificParams<T, SolanaExt, AptosExt> = T extends SolanaStreamClient ? SolanaExt : T extends AptosStreamClient ? AptosExt : undefined;
|
|
34
|
+
declare type CreateSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, ICreateStreamSolanaExt, ICreateStreamAptosExt>;
|
|
35
|
+
declare type TopupSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, ITopUpStreamSolanaExt, ITransactionAptosExt>;
|
|
36
|
+
declare type InteractSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, IInteractStreamSolanaExt, ITransactionAptosExt>;
|
|
37
|
+
export default class GenericStreamClient<T extends IChain> extends BaseStreamClient {
|
|
38
|
+
nativeStreamClient: StreamClientType<T>;
|
|
34
39
|
chain: IChain;
|
|
35
|
-
constructor(options:
|
|
40
|
+
constructor(options: StreamClientOptions<T>);
|
|
36
41
|
/**
|
|
37
42
|
* Creates a new stream/vesting contract.
|
|
38
43
|
*/
|
|
39
|
-
create(streamData: ICreateStreamData, chainSpecificParams
|
|
44
|
+
create(streamData: ICreateStreamData, chainSpecificParams?: CreateSpecificParams<T>): Promise<ICreateResult>;
|
|
40
45
|
/**
|
|
41
46
|
* Creates multiple stream/vesting contracts.
|
|
42
47
|
*/
|
|
43
|
-
createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams
|
|
48
|
+
createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams?: CreateSpecificParams<T>): Promise<IMultiTransactionResult>;
|
|
44
49
|
/**
|
|
45
50
|
* Attempts withdrawing from the specified stream.
|
|
46
51
|
*/
|
|
47
|
-
withdraw(withdrawData: IWithdrawData, chainSpecificParams
|
|
52
|
+
withdraw(withdrawData: IWithdrawData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
|
|
48
53
|
/**
|
|
49
54
|
* Attempts canceling the specified stream.
|
|
50
55
|
*/
|
|
51
|
-
cancel(cancelData: ICancelData, chainSpecificParams
|
|
56
|
+
cancel(cancelData: ICancelData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
|
|
52
57
|
/**
|
|
53
58
|
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
54
59
|
*/
|
|
55
|
-
transfer(transferData: ITransferData, chainSpecificParams
|
|
60
|
+
transfer(transferData: ITransferData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
|
|
56
61
|
/**
|
|
57
62
|
* Tops up stream account with specified amount.
|
|
58
63
|
*/
|
|
59
|
-
topup(topupData: ITopUpData, chainSpecificParams
|
|
64
|
+
topup(topupData: ITopUpData, chainSpecificParams?: TopupSpecificParams<T>): Promise<ITransactionResult>;
|
|
60
65
|
/**
|
|
61
66
|
* Fetch stream data by its id (address).
|
|
62
67
|
*/
|
|
@@ -68,6 +73,6 @@ export default class GenericStreamClient extends BaseStreamClient {
|
|
|
68
73
|
/**
|
|
69
74
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
70
75
|
*/
|
|
71
|
-
update(updateData: IUpdateData, chainSpecificParams
|
|
76
|
+
update(updateData: IUpdateData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
|
|
72
77
|
}
|
|
73
78
|
export {};
|
|
@@ -48,78 +48,72 @@ var GenericStreamClient = /** @class */ (function (_super) {
|
|
|
48
48
|
*/
|
|
49
49
|
GenericStreamClient.prototype.create = function (streamData, chainSpecificParams) {
|
|
50
50
|
if (this.nativeStreamClient instanceof StreamClient_1.default) {
|
|
51
|
-
|
|
52
|
-
return this.nativeStreamClient.create(streamData, params);
|
|
51
|
+
return this.nativeStreamClient.create(streamData, chainSpecificParams);
|
|
53
52
|
}
|
|
54
|
-
else {
|
|
55
|
-
|
|
56
|
-
return this.nativeStreamClient.create(streamData, params);
|
|
53
|
+
else if (this.nativeStreamClient instanceof StreamClient_2.default) {
|
|
54
|
+
return this.nativeStreamClient.create(streamData, chainSpecificParams);
|
|
57
55
|
}
|
|
56
|
+
return this.nativeStreamClient.create(streamData);
|
|
58
57
|
};
|
|
59
58
|
/**
|
|
60
59
|
* Creates multiple stream/vesting contracts.
|
|
61
60
|
*/
|
|
62
61
|
GenericStreamClient.prototype.createMultiple = function (multipleStreamData, chainSpecificParams) {
|
|
63
62
|
if (this.nativeStreamClient instanceof StreamClient_1.default) {
|
|
64
|
-
|
|
65
|
-
return this.nativeStreamClient.createMultiple(multipleStreamData, params);
|
|
63
|
+
return this.nativeStreamClient.createMultiple(multipleStreamData, chainSpecificParams);
|
|
66
64
|
}
|
|
67
|
-
else {
|
|
68
|
-
|
|
69
|
-
return this.nativeStreamClient.createMultiple(multipleStreamData, params);
|
|
65
|
+
else if (this.nativeStreamClient instanceof StreamClient_2.default) {
|
|
66
|
+
return this.nativeStreamClient.createMultiple(multipleStreamData, chainSpecificParams);
|
|
70
67
|
}
|
|
68
|
+
return this.nativeStreamClient.createMultiple(multipleStreamData);
|
|
71
69
|
};
|
|
72
70
|
/**
|
|
73
71
|
* Attempts withdrawing from the specified stream.
|
|
74
72
|
*/
|
|
75
73
|
GenericStreamClient.prototype.withdraw = function (withdrawData, chainSpecificParams) {
|
|
76
74
|
if (this.nativeStreamClient instanceof StreamClient_1.default) {
|
|
77
|
-
|
|
78
|
-
return this.nativeStreamClient.withdraw(withdrawData, params);
|
|
75
|
+
return this.nativeStreamClient.withdraw(withdrawData, chainSpecificParams);
|
|
79
76
|
}
|
|
80
|
-
else {
|
|
81
|
-
|
|
82
|
-
return this.nativeStreamClient.withdraw(withdrawData, params);
|
|
77
|
+
else if (this.nativeStreamClient instanceof StreamClient_2.default) {
|
|
78
|
+
return this.nativeStreamClient.withdraw(withdrawData, chainSpecificParams);
|
|
83
79
|
}
|
|
80
|
+
return this.nativeStreamClient.withdraw(withdrawData);
|
|
84
81
|
};
|
|
85
82
|
/**
|
|
86
83
|
* Attempts canceling the specified stream.
|
|
87
84
|
*/
|
|
88
85
|
GenericStreamClient.prototype.cancel = function (cancelData, chainSpecificParams) {
|
|
89
86
|
if (this.nativeStreamClient instanceof StreamClient_1.default) {
|
|
90
|
-
|
|
91
|
-
return this.nativeStreamClient.cancel(cancelData, params);
|
|
87
|
+
return this.nativeStreamClient.cancel(cancelData, chainSpecificParams);
|
|
92
88
|
}
|
|
93
|
-
else {
|
|
94
|
-
|
|
95
|
-
return this.nativeStreamClient.cancel(cancelData, params);
|
|
89
|
+
else if (this.nativeStreamClient instanceof StreamClient_2.default) {
|
|
90
|
+
return this.nativeStreamClient.cancel(cancelData, chainSpecificParams);
|
|
96
91
|
}
|
|
92
|
+
return this.nativeStreamClient.cancel(cancelData);
|
|
97
93
|
};
|
|
98
94
|
/**
|
|
99
95
|
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
100
96
|
*/
|
|
101
97
|
GenericStreamClient.prototype.transfer = function (transferData, chainSpecificParams) {
|
|
102
98
|
if (this.nativeStreamClient instanceof StreamClient_1.default) {
|
|
103
|
-
|
|
104
|
-
return this.nativeStreamClient.transfer(transferData, params);
|
|
99
|
+
return this.nativeStreamClient.transfer(transferData, chainSpecificParams);
|
|
105
100
|
}
|
|
106
|
-
else {
|
|
107
|
-
|
|
108
|
-
return this.nativeStreamClient.transfer(transferData, params);
|
|
101
|
+
else if (this.nativeStreamClient instanceof StreamClient_2.default) {
|
|
102
|
+
return this.nativeStreamClient.transfer(transferData, chainSpecificParams);
|
|
109
103
|
}
|
|
104
|
+
return this.nativeStreamClient.transfer(transferData);
|
|
110
105
|
};
|
|
111
106
|
/**
|
|
112
107
|
* Tops up stream account with specified amount.
|
|
113
108
|
*/
|
|
114
109
|
GenericStreamClient.prototype.topup = function (topupData, chainSpecificParams) {
|
|
115
110
|
if (this.nativeStreamClient instanceof StreamClient_1.default) {
|
|
116
|
-
|
|
117
|
-
return this.nativeStreamClient.topup(topupData, params);
|
|
111
|
+
return this.nativeStreamClient.topup(topupData, chainSpecificParams);
|
|
118
112
|
}
|
|
119
|
-
else {
|
|
120
|
-
|
|
121
|
-
return this.nativeStreamClient.topup(topupData, params);
|
|
113
|
+
else if (this.nativeStreamClient instanceof StreamClient_2.default) {
|
|
114
|
+
return this.nativeStreamClient.topup(topupData, chainSpecificParams);
|
|
122
115
|
}
|
|
116
|
+
return this.nativeStreamClient.topup(topupData);
|
|
123
117
|
};
|
|
124
118
|
/**
|
|
125
119
|
* Fetch stream data by its id (address).
|
|
@@ -138,13 +132,12 @@ var GenericStreamClient = /** @class */ (function (_super) {
|
|
|
138
132
|
*/
|
|
139
133
|
GenericStreamClient.prototype.update = function (updateData, chainSpecificParams) {
|
|
140
134
|
if (this.nativeStreamClient instanceof StreamClient_1.default) {
|
|
141
|
-
|
|
142
|
-
return this.nativeStreamClient.update(updateData, params);
|
|
135
|
+
return this.nativeStreamClient.update(updateData, chainSpecificParams);
|
|
143
136
|
}
|
|
144
|
-
else {
|
|
145
|
-
|
|
146
|
-
return this.nativeStreamClient.update(updateData, params);
|
|
137
|
+
else if (this.nativeStreamClient instanceof StreamClient_2.default) {
|
|
138
|
+
return this.nativeStreamClient.update(updateData, chainSpecificParams);
|
|
147
139
|
}
|
|
140
|
+
return this.nativeStreamClient.update(updateData);
|
|
148
141
|
};
|
|
149
142
|
return GenericStreamClient;
|
|
150
143
|
}(BaseStreamClient_1.BaseStreamClient));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.calculateUnlockedAmount = void 0;
|
|
7
|
+
var bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
+
var calculateUnlockedAmount = function (depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange) {
|
|
9
|
+
var deposited = depositedAmount;
|
|
10
|
+
if (currentTimestamp < cliff)
|
|
11
|
+
return new bn_js_1.default(0);
|
|
12
|
+
if (currentTimestamp > end)
|
|
13
|
+
return deposited;
|
|
14
|
+
var savedUnlockedFunds = lastRateChangeTime === 0 ? cliffAmount : fundsUnlockedAtLastRateChange;
|
|
15
|
+
var savedUnlockedFundsTime = lastRateChangeTime === 0 ? cliff : lastRateChangeTime;
|
|
16
|
+
var streamed = new bn_js_1.default(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period))
|
|
17
|
+
.mul(amountPerPeriod)
|
|
18
|
+
.add(savedUnlockedFunds);
|
|
19
|
+
return streamed.lt(deposited) ? streamed : deposited;
|
|
20
|
+
};
|
|
21
|
+
exports.calculateUnlockedAmount = calculateUnlockedAmount;
|
package/dist/common/types.d.ts
CHANGED
package/dist/common/types.js
CHANGED
package/dist/evm/StreamClient.js
CHANGED
|
@@ -133,7 +133,7 @@ var EvmStreamClient = /** @class */ (function (_super) {
|
|
|
133
133
|
}
|
|
134
134
|
EvmStreamClient.prototype.create = function (streamData) {
|
|
135
135
|
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
-
var multiParams, fees, args, result, confirmedTx, metadataId;
|
|
136
|
+
var multiParams, fees, args, sum, tokenContract, approvalTx, result, confirmedTx, metadataId;
|
|
137
137
|
var _a, _b;
|
|
138
138
|
return __generator(this, function (_c) {
|
|
139
139
|
switch (_c.label) {
|
|
@@ -145,13 +145,21 @@ var EvmStreamClient = /** @class */ (function (_super) {
|
|
|
145
145
|
return [4 /*yield*/, this.generateMultiPayloads(multiParams)];
|
|
146
146
|
case 2:
|
|
147
147
|
args = (_c.sent())[0];
|
|
148
|
-
|
|
148
|
+
sum = streamData.amount.mul(new bn_js_1.BN(constants_2.BASE_FEE)).div(new bn_js_1.BN(1000000));
|
|
149
|
+
tokenContract = new ethers_1.ethers.Contract(streamData.tokenId, ercAbi_1.default, this.signer);
|
|
150
|
+
return [4 /*yield*/, tokenContract.approve(this.programId, sum.toString())];
|
|
149
151
|
case 3:
|
|
152
|
+
approvalTx = _c.sent();
|
|
153
|
+
return [4 /*yield*/, approvalTx.wait()];
|
|
154
|
+
case 4:
|
|
155
|
+
_c.sent();
|
|
156
|
+
return [4 /*yield*/, (_b = this.writeContract).create.apply(_b, __spreadArray(__spreadArray([], __read(args), false), [{ value: fees.value }], false))];
|
|
157
|
+
case 5:
|
|
150
158
|
result = _c.sent();
|
|
151
159
|
return [4 /*yield*/, result.wait()];
|
|
152
|
-
case
|
|
160
|
+
case 6:
|
|
153
161
|
confirmedTx = _c.sent();
|
|
154
|
-
metadataId = this.formatMetadataId(confirmedTx.
|
|
162
|
+
metadataId = this.formatMetadataId(confirmedTx.events.find(function (item) { return item.event === "ContractCreated"; }).args[0]);
|
|
155
163
|
return [2 /*return*/, {
|
|
156
164
|
ixs: [],
|
|
157
165
|
txId: result.hash,
|
|
@@ -163,7 +171,7 @@ var EvmStreamClient = /** @class */ (function (_super) {
|
|
|
163
171
|
};
|
|
164
172
|
EvmStreamClient.prototype.createMultiple = function (multipleStreamData) {
|
|
165
173
|
return __awaiter(this, void 0, void 0, function () {
|
|
166
|
-
var fees, args, creationPromises, signatures, results, confirmations, successes, metadatas, metadataToRecipient, failures;
|
|
174
|
+
var fees, args, sum, tokenContract, approvalTx, creationPromises, signatures, results, confirmations, successes, metadatas, metadataToRecipient, failures;
|
|
167
175
|
var _a;
|
|
168
176
|
var _this = this;
|
|
169
177
|
return __generator(this, function (_b) {
|
|
@@ -174,16 +182,27 @@ var EvmStreamClient = /** @class */ (function (_super) {
|
|
|
174
182
|
return [4 /*yield*/, this.generateMultiPayloads(multipleStreamData)];
|
|
175
183
|
case 2:
|
|
176
184
|
args = _b.sent();
|
|
185
|
+
sum = multipleStreamData.recipients
|
|
186
|
+
.reduce(function (acc, v) { return acc.add(v.amount); }, new bn_js_1.BN(0))
|
|
187
|
+
.mul(new bn_js_1.BN(constants_2.BASE_FEE))
|
|
188
|
+
.div(new bn_js_1.BN(1000000));
|
|
189
|
+
tokenContract = new ethers_1.ethers.Contract(multipleStreamData.tokenId, ercAbi_1.default, this.signer);
|
|
190
|
+
return [4 /*yield*/, tokenContract.approve(this.programId, sum.toString())];
|
|
191
|
+
case 3:
|
|
192
|
+
approvalTx = _b.sent();
|
|
193
|
+
return [4 /*yield*/, approvalTx.wait()];
|
|
194
|
+
case 4:
|
|
195
|
+
_b.sent();
|
|
177
196
|
creationPromises = args.map(function (item) {
|
|
178
197
|
var _a;
|
|
179
198
|
return (_a = _this.writeContract).create.apply(_a, __spreadArray(__spreadArray([], __read(item), false), [{ value: fees.value }], false));
|
|
180
199
|
});
|
|
181
200
|
signatures = [];
|
|
182
201
|
return [4 /*yield*/, Promise.all(creationPromises)];
|
|
183
|
-
case
|
|
202
|
+
case 5:
|
|
184
203
|
results = _b.sent();
|
|
185
204
|
return [4 /*yield*/, Promise.allSettled(results.map(function (result) { return result.wait(); }))];
|
|
186
|
-
case
|
|
205
|
+
case 6:
|
|
187
206
|
confirmations = _b.sent();
|
|
188
207
|
successes = confirmations
|
|
189
208
|
.filter(function (el) { return el.status === "fulfilled"; })
|
|
@@ -191,7 +210,8 @@ var EvmStreamClient = /** @class */ (function (_super) {
|
|
|
191
210
|
signatures.push.apply(signatures, __spreadArray([], __read(successes.map(function (el) { return el.hash; })), false));
|
|
192
211
|
metadatas = confirmations.map(function (result) {
|
|
193
212
|
return result.status === "fulfilled"
|
|
194
|
-
? _this.formatMetadataId(result.value.
|
|
213
|
+
? _this.formatMetadataId(result.value.events.find(function (item) { return item.event === "ContractCreated"; })
|
|
214
|
+
.args[0])
|
|
195
215
|
: null;
|
|
196
216
|
});
|
|
197
217
|
metadataToRecipient = metadatas.reduce(function (acc, value, index) {
|
package/dist/evm/types.d.ts
CHANGED
|
@@ -80,6 +80,11 @@ export interface Stream {
|
|
|
80
80
|
canTopup: boolean;
|
|
81
81
|
name: string;
|
|
82
82
|
withdrawalFrequency: number;
|
|
83
|
+
closed: boolean;
|
|
84
|
+
currentPauseStart: number;
|
|
85
|
+
pauseCumulative: BN;
|
|
86
|
+
lastRateChangeTime: number;
|
|
87
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
83
88
|
unlocked(currentTimestamp: number, decimals: number): BN;
|
|
84
89
|
}
|
|
85
90
|
export declare class EvmContract implements Stream {
|
|
@@ -120,6 +125,11 @@ export declare class EvmContract implements Stream {
|
|
|
120
125
|
canTopup: boolean;
|
|
121
126
|
name: string;
|
|
122
127
|
withdrawalFrequency: number;
|
|
128
|
+
closed: boolean;
|
|
129
|
+
currentPauseStart: number;
|
|
130
|
+
pauseCumulative: BN;
|
|
131
|
+
lastRateChangeTime: number;
|
|
132
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
123
133
|
constructor(stream: StreamAbiResult);
|
|
124
134
|
unlocked(currentTimestamp: number): BN;
|
|
125
135
|
remaining(decimals: number): number;
|
package/dist/evm/types.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.EvmContract = void 0;
|
|
7
7
|
var bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
+
var contractUtils_1 = require("../common/contractUtils");
|
|
8
9
|
var utils_1 = require("../common/utils");
|
|
9
10
|
var EvmContract = /** @class */ (function () {
|
|
10
11
|
function EvmContract(stream) {
|
|
@@ -45,15 +46,14 @@ var EvmContract = /** @class */ (function () {
|
|
|
45
46
|
this.canTopup = stream.meta.can_topup;
|
|
46
47
|
this.name = stream.meta.contract_name;
|
|
47
48
|
this.withdrawalFrequency = stream.meta.withdrawal_frequency.toNumber();
|
|
49
|
+
this.closed = stream.closed;
|
|
50
|
+
this.currentPauseStart = stream.current_pause_start.toNumber();
|
|
51
|
+
this.pauseCumulative = new bn_js_1.default(stream.pause_cumulative.toString());
|
|
52
|
+
this.lastRateChangeTime = stream.last_rate_change_time.toNumber();
|
|
53
|
+
this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change.toString());
|
|
48
54
|
}
|
|
49
55
|
EvmContract.prototype.unlocked = function (currentTimestamp) {
|
|
50
|
-
|
|
51
|
-
if (currentTimestamp < this.cliff)
|
|
52
|
-
return new bn_js_1.default(0);
|
|
53
|
-
if (currentTimestamp > this.end)
|
|
54
|
-
return deposited;
|
|
55
|
-
var streamed = this.cliffAmount.add(new bn_js_1.default(Math.floor((currentTimestamp - this.cliff) / this.period)).mul(this.amountPerPeriod));
|
|
56
|
-
return streamed.lt(deposited) ? streamed : deposited;
|
|
56
|
+
return (0, contractUtils_1.calculateUnlockedAmount)(this.depositedAmount, this.cliff, this.cliffAmount, this.end, currentTimestamp, this.lastRateChangeTime, this.period, this.amountPerPeriod, this.fundsUnlockedAtLastRateChange);
|
|
57
57
|
};
|
|
58
58
|
EvmContract.prototype.remaining = function (decimals) {
|
|
59
59
|
return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * as StreamflowSolana from "./solana";
|
|
2
2
|
export * as StreamflowAptos from "./aptos";
|
|
3
|
+
export * as StreamflowEVM from "./evm";
|
|
3
4
|
export * as Types from "./common/types";
|
|
4
5
|
export * from "./common/utils";
|
|
5
6
|
export { default as GenericStreamClient } from "./common/GenericStreamClient";
|
package/dist/index.js
CHANGED
|
@@ -29,9 +29,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
29
29
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.GenericStreamClient = exports.Types = exports.StreamflowAptos = exports.StreamflowSolana = void 0;
|
|
32
|
+
exports.GenericStreamClient = exports.Types = exports.StreamflowEVM = exports.StreamflowAptos = exports.StreamflowSolana = void 0;
|
|
33
33
|
exports.StreamflowSolana = __importStar(require("./solana"));
|
|
34
34
|
exports.StreamflowAptos = __importStar(require("./aptos"));
|
|
35
|
+
exports.StreamflowEVM = __importStar(require("./evm"));
|
|
35
36
|
exports.Types = __importStar(require("./common/types"));
|
|
36
37
|
__exportStar(require("./common/utils"), exports);
|
|
37
38
|
var GenericStreamClient_1 = require("./common/GenericStreamClient");
|
|
@@ -2,6 +2,7 @@ import { PublicKey } from "@solana/web3.js";
|
|
|
2
2
|
export declare const TX_FINALITY_CONFIRMED = "confirmed";
|
|
3
3
|
export declare const STREAM_STRUCT_OFFSET_SENDER = 49;
|
|
4
4
|
export declare const STREAM_STRUCT_OFFSET_RECIPIENT = 113;
|
|
5
|
+
export declare const CREATE_PARAMS_PADDING = 126;
|
|
5
6
|
export declare const PROGRAM_ID: {
|
|
6
7
|
devnet: string;
|
|
7
8
|
mainnet: string;
|
package/dist/solana/constants.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.BASE_FEE = exports.AIRDROP_AMOUNT = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.STREAMFLOW_DEVNET_PROGRAM_ID = exports.STREAMFLOW_PROGRAM_ID = exports.PROGRAM_ID = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
|
|
4
|
+
exports.BASE_FEE = exports.AIRDROP_AMOUNT = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.STREAMFLOW_DEVNET_PROGRAM_ID = exports.STREAMFLOW_PROGRAM_ID = exports.PROGRAM_ID = exports.CREATE_PARAMS_PADDING = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
|
|
5
5
|
var web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
var types_1 = require("../common/types");
|
|
7
7
|
exports.TX_FINALITY_CONFIRMED = "confirmed";
|
|
8
8
|
exports.STREAM_STRUCT_OFFSET_SENDER = 49;
|
|
9
9
|
exports.STREAM_STRUCT_OFFSET_RECIPIENT = 113;
|
|
10
|
+
// Defined: https://github.com/streamflow-finance/protocol/blob/main/programs/protocol/src/state.rs#L25
|
|
11
|
+
exports.CREATE_PARAMS_PADDING = 126;
|
|
10
12
|
exports.PROGRAM_ID = (_a = {},
|
|
11
13
|
_a[types_1.ICluster.Devnet] = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
|
|
12
14
|
_a[types_1.ICluster.Mainnet] = "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m",
|
|
@@ -36,6 +36,16 @@ export interface IStreamLayout {
|
|
|
36
36
|
can_topup: number;
|
|
37
37
|
stream_name: Uint8Array;
|
|
38
38
|
withdraw_frequency: Uint8Array;
|
|
39
|
+
ghost: Uint8Array;
|
|
40
|
+
pausable: number;
|
|
41
|
+
can_update_rate: number;
|
|
42
|
+
create_params_padding_length: number;
|
|
43
|
+
create_params_padding: number[];
|
|
44
|
+
closed: number;
|
|
45
|
+
current_pause_start: Uint8Array;
|
|
46
|
+
pause_cumulative: Uint8Array;
|
|
47
|
+
last_rate_change_time: Uint8Array;
|
|
48
|
+
funds_unlocked_at_last_rate_change: Uint8Array;
|
|
39
49
|
}
|
|
40
50
|
export interface ICreateStreamLayout {
|
|
41
51
|
start_time: Uint8Array;
|
package/dist/solana/layout.js
CHANGED
|
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.topupStreamLayout = exports.encodeUpdateStream = exports.withdrawStreamLayout = exports.createUncheckedStreamLayout = exports.createStreamLayout = exports.streamLayout = void 0;
|
|
27
27
|
var BufferLayout = __importStar(require("@solana/buffer-layout"));
|
|
28
|
+
var constants_1 = require("./constants");
|
|
28
29
|
/**
|
|
29
30
|
* Stream layout
|
|
30
31
|
*/
|
|
@@ -66,6 +67,17 @@ exports.streamLayout = BufferLayout.struct([
|
|
|
66
67
|
BufferLayout.u8("can_topup"),
|
|
67
68
|
BufferLayout.blob(64, "stream_name"),
|
|
68
69
|
BufferLayout.blob(8, "withdraw_frequency"),
|
|
70
|
+
// Unused, kept for backward compatibility™
|
|
71
|
+
BufferLayout.blob(4, "ghost"),
|
|
72
|
+
BufferLayout.u8("pausable"),
|
|
73
|
+
BufferLayout.u8("can_update_rate"),
|
|
74
|
+
BufferLayout.blob(4, "create_stream_params_padding_length"),
|
|
75
|
+
BufferLayout.seq(BufferLayout.u8(), constants_1.CREATE_PARAMS_PADDING, "create_params_padding"),
|
|
76
|
+
BufferLayout.u8("closed"),
|
|
77
|
+
BufferLayout.blob(8, "current_pause_start"),
|
|
78
|
+
BufferLayout.blob(8, "pause_cumulative"),
|
|
79
|
+
BufferLayout.blob(8, "last_rate_change_time"),
|
|
80
|
+
BufferLayout.blob(8, "funds_unlocked_at_last_rate_change"),
|
|
69
81
|
]);
|
|
70
82
|
/**
|
|
71
83
|
* Create stream instruction layout
|
package/dist/solana/types.d.ts
CHANGED
|
@@ -171,6 +171,11 @@ export interface Stream {
|
|
|
171
171
|
canTopup: boolean;
|
|
172
172
|
name: string;
|
|
173
173
|
withdrawalFrequency: number;
|
|
174
|
+
closed: boolean;
|
|
175
|
+
currentPauseStart: number;
|
|
176
|
+
pauseCumulative: BN;
|
|
177
|
+
lastRateChangeTime: number;
|
|
178
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
174
179
|
unlocked(currentTimestamp: number): BN;
|
|
175
180
|
}
|
|
176
181
|
export declare class Contract implements Stream {
|
|
@@ -211,6 +216,11 @@ export declare class Contract implements Stream {
|
|
|
211
216
|
canTopup: boolean;
|
|
212
217
|
name: string;
|
|
213
218
|
withdrawalFrequency: number;
|
|
219
|
+
closed: boolean;
|
|
220
|
+
currentPauseStart: number;
|
|
221
|
+
pauseCumulative: BN;
|
|
222
|
+
lastRateChangeTime: number;
|
|
223
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
214
224
|
constructor(stream: DecodedStream);
|
|
215
225
|
unlocked(currentTimestamp: number): BN;
|
|
216
226
|
remaining(decimals: number): number;
|
|
@@ -253,6 +263,11 @@ export interface DecodedStream {
|
|
|
253
263
|
canTopup: boolean;
|
|
254
264
|
name: string;
|
|
255
265
|
withdrawFrequency: BN;
|
|
266
|
+
closed: boolean;
|
|
267
|
+
currentPauseStart: BN;
|
|
268
|
+
pauseCumulative: BN;
|
|
269
|
+
lastRateChangeTime: BN;
|
|
270
|
+
fundsUnlockedAtLastRateChange: BN;
|
|
256
271
|
}
|
|
257
272
|
export interface TransactionResponse {
|
|
258
273
|
tx: TransactionSignature;
|
package/dist/solana/types.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.TransferCancelOptions = exports.Contract = exports.Cluster = void 0;
|
|
7
|
-
var
|
|
4
|
+
var contractUtils_1 = require("../common/contractUtils");
|
|
8
5
|
var utils_1 = require("../common/utils");
|
|
9
6
|
var wallet_adapter_base_1 = require("@solana/wallet-adapter-base");
|
|
10
7
|
Object.defineProperty(exports, "Cluster", { enumerable: true, get: function () { return wallet_adapter_base_1.WalletAdapterNetwork; } });
|
|
@@ -48,15 +45,14 @@ var Contract = /** @class */ (function () {
|
|
|
48
45
|
this.canTopup = stream.canTopup;
|
|
49
46
|
this.name = stream.name;
|
|
50
47
|
this.withdrawalFrequency = stream.withdrawFrequency.toNumber();
|
|
48
|
+
this.closed = stream.closed;
|
|
49
|
+
this.currentPauseStart = stream.currentPauseStart.toNumber();
|
|
50
|
+
this.pauseCumulative = stream.pauseCumulative;
|
|
51
|
+
this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
|
|
52
|
+
this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
|
|
51
53
|
}
|
|
52
54
|
Contract.prototype.unlocked = function (currentTimestamp) {
|
|
53
|
-
|
|
54
|
-
if (currentTimestamp < this.cliff)
|
|
55
|
-
return new bn_js_1.default(0);
|
|
56
|
-
if (currentTimestamp > this.end)
|
|
57
|
-
return deposited;
|
|
58
|
-
var streamed = this.cliffAmount.add(new bn_js_1.default(Math.floor((currentTimestamp - this.cliff) / this.period)).mul(this.amountPerPeriod));
|
|
59
|
-
return streamed.lt(deposited) ? streamed : deposited;
|
|
55
|
+
return (0, contractUtils_1.calculateUnlockedAmount)(this.depositedAmount, this.cliff, this.cliffAmount, this.end, currentTimestamp, this.lastRateChangeTime, this.period, this.amountPerPeriod, this.fundsUnlockedAtLastRateChange);
|
|
60
56
|
};
|
|
61
57
|
Contract.prototype.remaining = function (decimals) {
|
|
62
58
|
return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
package/dist/solana/utils.js
CHANGED
|
@@ -98,6 +98,11 @@ var decodeStream = function (buf) {
|
|
|
98
98
|
canTopup: Boolean(raw.can_topup),
|
|
99
99
|
name: decoder.decode(raw.stream_name),
|
|
100
100
|
withdrawFrequency: new bn_js_1.default(raw.withdraw_frequency, LE),
|
|
101
|
+
closed: Boolean(raw.closed),
|
|
102
|
+
currentPauseStart: new bn_js_1.default(raw.current_pause_start, LE),
|
|
103
|
+
pauseCumulative: new bn_js_1.default(raw.pause_cumulative, LE),
|
|
104
|
+
lastRateChangeTime: new bn_js_1.default(raw.last_rate_change_time, LE),
|
|
105
|
+
fundsUnlockedAtLastRateChange: new bn_js_1.default(raw.funds_unlocked_at_last_rate_change, LE),
|
|
101
106
|
};
|
|
102
107
|
};
|
|
103
108
|
exports.decodeStream = decodeStream;
|
|
@@ -143,6 +148,11 @@ var formatDecodedStream = function (stream) {
|
|
|
143
148
|
canTopup: stream.canTopup,
|
|
144
149
|
name: stream.name,
|
|
145
150
|
withdrawalFrequency: stream.withdrawFrequency.toNumber(),
|
|
151
|
+
closed: stream.closed,
|
|
152
|
+
currentPauseStart: stream.currentPauseStart.toNumber(),
|
|
153
|
+
pauseCumulative: stream.pauseCumulative,
|
|
154
|
+
lastRateChangeTime: stream.lastRateChangeTime.toNumber(),
|
|
155
|
+
fundsUnlockedAtLastRateChange: stream.fundsUnlockedAtLastRateChange,
|
|
146
156
|
unlocked: function () {
|
|
147
157
|
return new bn_js_1.default(0);
|
|
148
158
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/stream",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "JavaScript SDK to interact with Streamflow protocol.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
@@ -40,4 +40,4 @@
|
|
|
40
40
|
"ethers": "5.7.2",
|
|
41
41
|
"js-sha256": "0.9.0"
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
}
|