@streamflow/stream 7.5.3 → 8.0.0-alpha.p287.25d0c28
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/cjs/BaseStreamClient-CQOC8m8V.d.cts +542 -0
- package/dist/cjs/aptos/index.cjs +456 -0
- package/dist/cjs/aptos/index.cjs.map +1 -0
- package/dist/cjs/aptos/index.d.cts +14 -0
- package/dist/cjs/evm/index.cjs +1915 -0
- package/dist/cjs/evm/index.cjs.map +1 -0
- package/dist/cjs/evm/index.d.cts +13 -0
- package/dist/cjs/index-CYu6i--S.d.cts +136 -0
- package/dist/cjs/index-DUVcpIhD.d.cts +203 -0
- package/dist/cjs/index-b7Qo5mCj.d.cts +664 -0
- package/dist/cjs/index-fNLnPKzv.d.cts +213 -0
- package/dist/cjs/index.cjs +7189 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +192 -0
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.cjs +4 -0
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.cjs.map +1 -0
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.d.cts +1234 -0
- package/dist/cjs/solana/index.cjs +3749 -0
- package/dist/cjs/solana/index.cjs.map +1 -0
- package/dist/cjs/solana/index.d.cts +17 -0
- package/dist/cjs/sui/index.cjs +1021 -0
- package/dist/cjs/sui/index.cjs.map +1 -0
- package/dist/cjs/sui/index.d.cts +13 -0
- package/dist/esm/BaseStreamClient-CQOC8m8V.d.ts +542 -0
- package/dist/esm/aptos/index.d.ts +14 -4
- package/dist/esm/aptos/index.js +443 -4
- package/dist/esm/aptos/index.js.map +1 -0
- package/dist/esm/evm/index.d.ts +13 -5
- package/dist/esm/evm/index.js +1902 -5
- package/dist/esm/evm/index.js.map +1 -0
- package/dist/esm/index-BEo0O2IG.d.ts +664 -0
- package/dist/esm/index-CWmb3-x9.d.ts +136 -0
- package/dist/esm/index-Cgv37xlG.d.ts +213 -0
- package/dist/esm/index-D6QYg8hn.d.ts +203 -0
- package/dist/esm/index.d.ts +192 -10
- package/dist/esm/index.js +7096 -10
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/solana/descriptor/idl/streamflow_aligned_unlocks.json +917 -1368
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.d.ts +3 -1
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js +3 -1
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js.map +1 -0
- package/dist/esm/solana/index.d.ts +17 -7
- package/dist/esm/solana/index.js +3693 -7
- package/dist/esm/solana/index.js.map +1 -0
- package/dist/esm/sui/index.d.ts +13 -4
- package/dist/esm/sui/index.js +1011 -4
- package/dist/esm/sui/index.js.map +1 -0
- package/package.json +57 -27
- package/dist/cjs/__tests__/aptos/streamClient.spec.js +0 -111
- package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +0 -45
- package/dist/cjs/aptos/StreamClient.js +0 -226
- package/dist/cjs/aptos/constants.js +0 -27
- package/dist/cjs/aptos/index.js +0 -38
- package/dist/cjs/aptos/types.js +0 -69
- package/dist/cjs/aptos/utils.js +0 -34
- package/dist/cjs/aptos/wallet.js +0 -34
- package/dist/cjs/common/BaseStreamClient.js +0 -23
- package/dist/cjs/common/GenericStreamClient.js +0 -102
- package/dist/cjs/common/constants.js +0 -10
- package/dist/cjs/common/contractUtils.js +0 -77
- package/dist/cjs/common/types.js +0 -141
- package/dist/cjs/common/utils.js +0 -69
- package/dist/cjs/evm/StreamClient.js +0 -238
- package/dist/cjs/evm/abi.js +0 -1257
- package/dist/cjs/evm/constants.js +0 -38
- package/dist/cjs/evm/ercAbi.js +0 -224
- package/dist/cjs/evm/index.js +0 -40
- package/dist/cjs/evm/types.js +0 -66
- package/dist/cjs/evm/utils.js +0 -11
- package/dist/cjs/index.js +0 -43
- package/dist/cjs/solana/StreamClient.js +0 -1042
- package/dist/cjs/solana/constants.js +0 -95
- package/dist/cjs/solana/descriptor/idl/streamflow_aligned_unlocks.json +0 -1437
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.js +0 -2
- package/dist/cjs/solana/index.js +0 -40
- package/dist/cjs/solana/instructionTypes.js +0 -2
- package/dist/cjs/solana/instructions.js +0 -298
- package/dist/cjs/solana/layout.js +0 -182
- package/dist/cjs/solana/lib/derive-accounts.js +0 -17
- package/dist/cjs/solana/lib/utils.js +0 -127
- package/dist/cjs/solana/timelockIDL.js +0 -422
- package/dist/cjs/solana/types.js +0 -93
- package/dist/cjs/sui/StreamClient.js +0 -416
- package/dist/cjs/sui/constants.js +0 -42
- package/dist/cjs/sui/index.js +0 -37
- package/dist/cjs/sui/types.js +0 -68
- package/dist/cjs/sui/utils.js +0 -46
- package/dist/cjs/sui/wallet.js +0 -40
- package/dist/esm/__tests__/aptos/streamClient.spec.d.ts +0 -1
- package/dist/esm/__tests__/aptos/streamClient.spec.js +0 -106
- package/dist/esm/__tests__/common/GenericStreamClient.spec.d.ts +0 -1
- package/dist/esm/__tests__/common/GenericStreamClient.spec.js +0 -40
- package/dist/esm/aptos/StreamClient.d.ts +0 -53
- package/dist/esm/aptos/StreamClient.js +0 -226
- package/dist/esm/aptos/constants.d.ts +0 -8
- package/dist/esm/aptos/constants.js +0 -24
- package/dist/esm/aptos/types.d.ts +0 -109
- package/dist/esm/aptos/types.js +0 -105
- package/dist/esm/aptos/utils.d.ts +0 -7
- package/dist/esm/aptos/utils.js +0 -30
- package/dist/esm/aptos/wallet.d.ts +0 -9
- package/dist/esm/aptos/wallet.js +0 -33
- package/dist/esm/common/BaseStreamClient.d.ts +0 -22
- package/dist/esm/common/BaseStreamClient.js +0 -19
- package/dist/esm/common/GenericStreamClient.d.ts +0 -72
- package/dist/esm/common/GenericStreamClient.js +0 -101
- package/dist/esm/common/constants.d.ts +0 -4
- package/dist/esm/common/constants.js +0 -4
- package/dist/esm/common/contractUtils.d.ts +0 -63
- package/dist/esm/common/contractUtils.js +0 -61
- package/dist/esm/common/types.d.ts +0 -353
- package/dist/esm/common/types.js +0 -135
- package/dist/esm/common/utils.d.ts +0 -32
- package/dist/esm/common/utils.js +0 -59
- package/dist/esm/evm/StreamClient.d.ts +0 -32
- package/dist/esm/evm/StreamClient.js +0 -237
- package/dist/esm/evm/abi.d.ts +0 -111
- package/dist/esm/evm/abi.js +0 -1255
- package/dist/esm/evm/constants.d.ts +0 -20
- package/dist/esm/evm/constants.js +0 -35
- package/dist/esm/evm/ercAbi.d.ts +0 -39
- package/dist/esm/evm/ercAbi.js +0 -222
- package/dist/esm/evm/types.d.ts +0 -98
- package/dist/esm/evm/types.js +0 -102
- package/dist/esm/evm/utils.d.ts +0 -1
- package/dist/esm/evm/utils.js +0 -8
- package/dist/esm/solana/StreamClient.d.ts +0 -150
- package/dist/esm/solana/StreamClient.js +0 -1017
- package/dist/esm/solana/constants.d.ts +0 -70
- package/dist/esm/solana/constants.js +0 -92
- package/dist/esm/solana/instructionTypes.d.ts +0 -101
- package/dist/esm/solana/instructionTypes.js +0 -1
- package/dist/esm/solana/instructions.d.ts +0 -142
- package/dist/esm/solana/instructions.js +0 -265
- package/dist/esm/solana/layout.d.ts +0 -27
- package/dist/esm/solana/layout.js +0 -155
- package/dist/esm/solana/lib/derive-accounts.d.ts +0 -4
- package/dist/esm/solana/lib/derive-accounts.js +0 -11
- package/dist/esm/solana/lib/utils.d.ts +0 -22
- package/dist/esm/solana/lib/utils.js +0 -117
- package/dist/esm/solana/timelockIDL.d.ts +0 -22
- package/dist/esm/solana/timelockIDL.js +0 -420
- package/dist/esm/solana/types.d.ts +0 -180
- package/dist/esm/solana/types.js +0 -142
- package/dist/esm/sui/StreamClient.d.ts +0 -82
- package/dist/esm/sui/StreamClient.js +0 -417
- package/dist/esm/sui/constants.d.ts +0 -10
- package/dist/esm/sui/constants.js +0 -39
- package/dist/esm/sui/types.d.ts +0 -167
- package/dist/esm/sui/types.js +0 -104
- package/dist/esm/sui/utils.d.ts +0 -11
- package/dist/esm/sui/utils.js +0 -39
- package/dist/esm/sui/wallet.d.ts +0 -17
- package/dist/esm/sui/wallet.js +0 -38
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const aptos_1 = require("aptos");
|
|
4
|
-
const BaseStreamClient_js_1 = require("../common/BaseStreamClient.js");
|
|
5
|
-
const types_js_1 = require("../common/types.js");
|
|
6
|
-
const constants_js_1 = require("./constants.js");
|
|
7
|
-
const types_js_2 = require("./types.js");
|
|
8
|
-
const wallet_js_1 = require("./wallet.js");
|
|
9
|
-
const utils_js_1 = require("./utils.js");
|
|
10
|
-
const constants_js_2 = require("../common/constants.js");
|
|
11
|
-
class AptosStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
12
|
-
constructor(clusterUrl, cluster = types_js_1.ICluster.Mainnet, maxGas = "10000", programId) {
|
|
13
|
-
super();
|
|
14
|
-
this.programId = programId ? programId : constants_js_1.APTOS_PROGRAM_IDS[cluster];
|
|
15
|
-
this.maxGas = maxGas;
|
|
16
|
-
this.client = new aptos_1.AptosClient(clusterUrl);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Creates a new stream/vesting contract.
|
|
20
|
-
*/
|
|
21
|
-
async create(streamData, { senderWallet }) {
|
|
22
|
-
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
23
|
-
const [metadataId, payload] = this.generateMultiPayloads({
|
|
24
|
-
...streamData,
|
|
25
|
-
recipients: [{ ...streamData }],
|
|
26
|
-
}, wallet)[0];
|
|
27
|
-
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
28
|
-
return { ixs: [payload], txId: hash, metadataId };
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Creates multiple stream/vesting contracts.
|
|
32
|
-
*/
|
|
33
|
-
async createMultiple(multipleStreamData, { senderWallet }) {
|
|
34
|
-
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
35
|
-
const payloads = this.generateMultiPayloads(multipleStreamData, wallet);
|
|
36
|
-
const txs = [];
|
|
37
|
-
const metadatas = [];
|
|
38
|
-
const metadataToRecipient = {};
|
|
39
|
-
const errors = [];
|
|
40
|
-
for (let i = 0; i < payloads.length; i++) {
|
|
41
|
-
const [metadataId, payload] = payloads[i];
|
|
42
|
-
const recipient = multipleStreamData.recipients[i];
|
|
43
|
-
try {
|
|
44
|
-
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
45
|
-
txs.push(hash);
|
|
46
|
-
}
|
|
47
|
-
catch (e) {
|
|
48
|
-
errors.push({
|
|
49
|
-
error: e?.toString() ?? "Unknown error!",
|
|
50
|
-
recipient: recipient.recipient,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
finally {
|
|
54
|
-
metadatas.push(metadataId);
|
|
55
|
-
metadataToRecipient[metadataId] = recipient;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
txs,
|
|
60
|
-
metadatas,
|
|
61
|
-
metadataToRecipient,
|
|
62
|
-
errors,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Attempts withdrawing from the specified stream.
|
|
67
|
-
*/
|
|
68
|
-
async withdraw({ id, amount = constants_js_2.WITHDRAW_AVAILABLE_AMOUNT }, { senderWallet, tokenId }) {
|
|
69
|
-
const payload = {
|
|
70
|
-
type: "withdraw",
|
|
71
|
-
function: `${this.programId}::protocol::withdraw`,
|
|
72
|
-
type_arguments: [tokenId],
|
|
73
|
-
arguments: [id, amount.toString()],
|
|
74
|
-
};
|
|
75
|
-
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
76
|
-
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
77
|
-
return { ixs: [payload], txId: hash };
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Attempts canceling the specified stream.
|
|
81
|
-
*/
|
|
82
|
-
async cancel(cancelData, { senderWallet, tokenId }) {
|
|
83
|
-
const payload = {
|
|
84
|
-
type: "cancel",
|
|
85
|
-
function: `${this.programId}::protocol::cancel`,
|
|
86
|
-
type_arguments: [tokenId],
|
|
87
|
-
arguments: [cancelData.id],
|
|
88
|
-
};
|
|
89
|
-
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
90
|
-
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
91
|
-
return { ixs: [payload], txId: hash };
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
95
|
-
*/
|
|
96
|
-
async transfer(transferData, { senderWallet, tokenId }) {
|
|
97
|
-
const payload = {
|
|
98
|
-
type: "transfer",
|
|
99
|
-
function: `${this.programId}::protocol::transfer`,
|
|
100
|
-
type_arguments: [tokenId],
|
|
101
|
-
arguments: [transferData.id, transferData.newRecipient],
|
|
102
|
-
};
|
|
103
|
-
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
104
|
-
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
105
|
-
return { ixs: [payload], txId: hash };
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Tops up stream account with specified amount.
|
|
109
|
-
*/
|
|
110
|
-
async topup(topupData, { senderWallet, tokenId }) {
|
|
111
|
-
const payload = {
|
|
112
|
-
type: "topup",
|
|
113
|
-
function: `${this.programId}::protocol::topup`,
|
|
114
|
-
type_arguments: [tokenId],
|
|
115
|
-
arguments: [topupData.id, topupData.amount.toString()],
|
|
116
|
-
};
|
|
117
|
-
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
118
|
-
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
119
|
-
return { ixs: [payload], txId: hash };
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Fetch stream data by its id (address).
|
|
123
|
-
*/
|
|
124
|
-
async getOne({ id }) {
|
|
125
|
-
const contractResources = await this.client.getAccountResources(id);
|
|
126
|
-
const contract = contractResources.find((r) => r.type.includes("protocol::Contract"));
|
|
127
|
-
if (!contract) {
|
|
128
|
-
throw new Error(`Contract with id ${id} could not be found!`);
|
|
129
|
-
}
|
|
130
|
-
const tokenIdMatch = contract.type.match(/0x[0-9a-f]+::protocol::Contract<(.*)>/);
|
|
131
|
-
const tokenId = tokenIdMatch?.[1] ?? "";
|
|
132
|
-
const { data } = contract;
|
|
133
|
-
return new types_js_2.Contract(data, tokenId);
|
|
134
|
-
}
|
|
135
|
-
async get() {
|
|
136
|
-
throw new Error("Get all method is not supported for Aptos chain!");
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Attempts updating the stream auto withdrawal params and amount per period
|
|
140
|
-
*/
|
|
141
|
-
async update(updateData, { senderWallet, tokenId }) {
|
|
142
|
-
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
143
|
-
const payload = {
|
|
144
|
-
type: "update",
|
|
145
|
-
function: `${this.programId}::protocol::update`,
|
|
146
|
-
type_arguments: [tokenId],
|
|
147
|
-
arguments: [
|
|
148
|
-
updateData.id,
|
|
149
|
-
updateData.enableAutomaticWithdrawal ? [true] : [],
|
|
150
|
-
updateData.withdrawFrequency ? [updateData.withdrawFrequency.toString()] : [],
|
|
151
|
-
updateData.amountPerPeriod ? [updateData.amountPerPeriod.toString()] : [],
|
|
152
|
-
],
|
|
153
|
-
};
|
|
154
|
-
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
155
|
-
return { ixs: [payload], txId: hash };
|
|
156
|
-
}
|
|
157
|
-
async getFees({ address }) {
|
|
158
|
-
const resource = await this.client.getAccountResource(this.programId, `${this.programId}::fees::FeeTable`);
|
|
159
|
-
const data = resource.data;
|
|
160
|
-
const value = await this.client.getTableItem(data.values.handle, {
|
|
161
|
-
key_type: "address",
|
|
162
|
-
key: address,
|
|
163
|
-
value_type: "u64",
|
|
164
|
-
});
|
|
165
|
-
if (!value) {
|
|
166
|
-
return null;
|
|
167
|
-
}
|
|
168
|
-
return { streamflowFee: Number(value) / 100, partnerFee: 0 };
|
|
169
|
-
}
|
|
170
|
-
async getDefaultStreamflowFee() {
|
|
171
|
-
const resource = await this.client.getAccountResource(this.programId, `${this.programId}::admin::ConfigV2`);
|
|
172
|
-
return Number(resource.data.streamflow_fees) / 100;
|
|
173
|
-
}
|
|
174
|
-
extractErrorCode(err) {
|
|
175
|
-
return (0, utils_js_1.extractAptosErrorCode)(err.toString() ?? "Unknown error!");
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Returns StreamClient protocol program ID.
|
|
179
|
-
*/
|
|
180
|
-
getProgramId() {
|
|
181
|
-
return this.programId;
|
|
182
|
-
}
|
|
183
|
-
getMaxGas() {
|
|
184
|
-
return { max_gas_amount: this.maxGas };
|
|
185
|
-
}
|
|
186
|
-
// Utility function to prepare transaction payloads for multiple recipients.
|
|
187
|
-
generateMultiPayloads(multipleStreamData, wallet) {
|
|
188
|
-
return multipleStreamData.recipients.map((recipient) => {
|
|
189
|
-
const acc = new aptos_1.AptosAccount(); // Generate random address as seeds for deriving "escrow" account
|
|
190
|
-
const seeds = acc.address();
|
|
191
|
-
const encoder = new TextEncoder();
|
|
192
|
-
// A workaround to pass a String in seeds because different wallets seem
|
|
193
|
-
// to serialize vector<u8> differently and String should be safer that Uin8Array
|
|
194
|
-
const actualSeeds = encoder.encode(seeds.hex());
|
|
195
|
-
const metadataId = aptos_1.AptosAccount.getResourceAccountAddress(wallet.address, actualSeeds);
|
|
196
|
-
return [
|
|
197
|
-
metadataId.toString(),
|
|
198
|
-
{
|
|
199
|
-
type: "create",
|
|
200
|
-
function: `${this.programId}::protocol::create`,
|
|
201
|
-
type_arguments: [multipleStreamData.tokenId],
|
|
202
|
-
arguments: [
|
|
203
|
-
seeds.hex(),
|
|
204
|
-
recipient.amount.toString(),
|
|
205
|
-
multipleStreamData.period,
|
|
206
|
-
recipient.amountPerPeriod.toString(),
|
|
207
|
-
multipleStreamData.start,
|
|
208
|
-
recipient.cliffAmount.toString(),
|
|
209
|
-
multipleStreamData.cancelableBySender,
|
|
210
|
-
multipleStreamData.cancelableByRecipient,
|
|
211
|
-
multipleStreamData.transferableBySender,
|
|
212
|
-
multipleStreamData.transferableByRecipient,
|
|
213
|
-
multipleStreamData.canTopup,
|
|
214
|
-
multipleStreamData.canPause || false,
|
|
215
|
-
multipleStreamData.canUpdateRate || false,
|
|
216
|
-
multipleStreamData.automaticWithdrawal || false,
|
|
217
|
-
multipleStreamData.withdrawalFrequency || 0,
|
|
218
|
-
recipient.name,
|
|
219
|
-
recipient.recipient,
|
|
220
|
-
],
|
|
221
|
-
},
|
|
222
|
-
];
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
exports.default = AptosStreamClient;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.APTOS_MODULE_ERROR_MAP = exports.APTOS_ERROR_MATCH_REGEX = exports.APTOS_PROGRAM_IDS = void 0;
|
|
4
|
-
const types_js_1 = require("../common/types.js");
|
|
5
|
-
exports.APTOS_PROGRAM_IDS = {
|
|
6
|
-
[types_js_1.ICluster.Mainnet]: "0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0",
|
|
7
|
-
// TODO: Add a correct programID for Test net
|
|
8
|
-
[types_js_1.ICluster.Devnet]: "0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688",
|
|
9
|
-
[types_js_1.ICluster.Testnet]: "0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688",
|
|
10
|
-
[types_js_1.ICluster.Local]: "0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0",
|
|
11
|
-
};
|
|
12
|
-
exports.APTOS_ERROR_MATCH_REGEX = /Move abort in [a-z0-9]+::([^:]+): ([A-Z_]+)/;
|
|
13
|
-
exports.APTOS_MODULE_ERROR_MAP = {
|
|
14
|
-
protocol: {
|
|
15
|
-
1: types_js_1.ContractErrorCode.ECONTRACT_NOT_INIT,
|
|
16
|
-
2: types_js_1.ContractErrorCode.EBAD_AMOUNT,
|
|
17
|
-
3: types_js_1.ContractErrorCode.ENO_PERMISSIONS,
|
|
18
|
-
4: types_js_1.ContractErrorCode.EBADINPUT,
|
|
19
|
-
5: types_js_1.ContractErrorCode.ECLOSED,
|
|
20
|
-
6: types_js_1.ContractErrorCode.EBAD_INPUT_AMOUNT_PER_PERIOD,
|
|
21
|
-
8: types_js_1.ContractErrorCode.EBAD_INPUT_UPDATE_RATE,
|
|
22
|
-
9: types_js_1.ContractErrorCode.EBAD_INPUT_CLIFF_AMOUNT,
|
|
23
|
-
10: types_js_1.ContractErrorCode.EBAD_INPUT_PERIOD,
|
|
24
|
-
11: types_js_1.ContractErrorCode.EBAD_INPUT_START,
|
|
25
|
-
12: types_js_1.ContractErrorCode.ENO_RECIPIENT_COIN_ADDRESS,
|
|
26
|
-
},
|
|
27
|
-
};
|
package/dist/cjs/aptos/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
-
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod;
|
|
23
|
-
var result = {};
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
-
__setModuleDefault(result, mod);
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
-
};
|
|
31
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.constants = exports.AptosStreamClient = exports.default = void 0;
|
|
33
|
-
var StreamClient_js_1 = require("./StreamClient.js");
|
|
34
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(StreamClient_js_1).default; } });
|
|
35
|
-
Object.defineProperty(exports, "AptosStreamClient", { enumerable: true, get: function () { return __importDefault(StreamClient_js_1).default; } });
|
|
36
|
-
__exportStar(require("./utils.js"), exports);
|
|
37
|
-
__exportStar(require("./types.js"), exports);
|
|
38
|
-
exports.constants = __importStar(require("./constants.js"));
|
package/dist/cjs/aptos/types.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
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.Contract = void 0;
|
|
7
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
-
const buffer_1 = require("buffer");
|
|
9
|
-
const contractUtils_js_1 = require("../common/contractUtils.js");
|
|
10
|
-
const utils_js_1 = require("./utils.js");
|
|
11
|
-
const utils_js_2 = require("../common/utils.js");
|
|
12
|
-
class Contract {
|
|
13
|
-
constructor(stream, tokenId) {
|
|
14
|
-
this.magic = 0;
|
|
15
|
-
this.version = 0;
|
|
16
|
-
this.createdAt = parseInt(stream.created);
|
|
17
|
-
this.withdrawnAmount = new bn_js_1.default(stream.withdrawn);
|
|
18
|
-
this.canceledAt = parseInt(stream.canceled_at);
|
|
19
|
-
this.end = parseInt(stream.end);
|
|
20
|
-
this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
|
|
21
|
-
this.sender = (0, utils_js_1.normalizeAptosAddress)(stream.sender);
|
|
22
|
-
this.senderTokens = (0, utils_js_1.normalizeAptosAddress)(stream.sender);
|
|
23
|
-
this.recipient = (0, utils_js_1.normalizeAptosAddress)(stream.recipient);
|
|
24
|
-
this.recipientTokens = (0, utils_js_1.normalizeAptosAddress)(stream.recipient);
|
|
25
|
-
this.mint = tokenId;
|
|
26
|
-
this.escrowTokens = "";
|
|
27
|
-
this.streamflowTreasury = "";
|
|
28
|
-
this.streamflowTreasuryTokens = "";
|
|
29
|
-
this.streamflowFeeTotal = new bn_js_1.default(0);
|
|
30
|
-
this.streamflowFeeWithdrawn = new bn_js_1.default(0);
|
|
31
|
-
this.streamflowFeePercent = parseInt(stream.fees.streamflow_fee_percentage) / 10000;
|
|
32
|
-
this.partnerFeeTotal = new bn_js_1.default(0);
|
|
33
|
-
this.partnerFeeWithdrawn = new bn_js_1.default(0);
|
|
34
|
-
this.partnerFeePercent = 0;
|
|
35
|
-
this.partner = "";
|
|
36
|
-
this.partnerTokens = "";
|
|
37
|
-
this.start = parseInt(stream.start);
|
|
38
|
-
this.depositedAmount = new bn_js_1.default(stream.amount);
|
|
39
|
-
this.period = parseInt(stream.period);
|
|
40
|
-
this.amountPerPeriod = new bn_js_1.default(stream.amount_per_period);
|
|
41
|
-
this.cliff = parseInt(stream.start);
|
|
42
|
-
this.cliffAmount = new bn_js_1.default(stream.cliff_amount);
|
|
43
|
-
this.cancelableBySender = stream.meta.cancelable_by_sender;
|
|
44
|
-
this.cancelableByRecipient = stream.meta.cancelable_by_recipient;
|
|
45
|
-
this.automaticWithdrawal = stream.meta.automatic_withdrawal;
|
|
46
|
-
this.transferableBySender = stream.meta.transferable_by_sender;
|
|
47
|
-
this.transferableByRecipient = stream.meta.transferable_by_recipient;
|
|
48
|
-
this.canTopup = stream.meta.can_topup;
|
|
49
|
-
const name = stream.meta.contract_name.replace("0x", "");
|
|
50
|
-
this.name = buffer_1.Buffer.from(name, "hex").toString("utf8");
|
|
51
|
-
this.withdrawalFrequency = parseInt(stream.meta.withdrawal_frequency);
|
|
52
|
-
this.closed = stream.closed;
|
|
53
|
-
this.currentPauseStart = parseInt(stream.current_pause_start);
|
|
54
|
-
this.pauseCumulative = new bn_js_1.default(stream.pause_cumulative);
|
|
55
|
-
this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
|
|
56
|
-
this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change);
|
|
57
|
-
this.type = (0, contractUtils_js_1.buildStreamType)(this);
|
|
58
|
-
}
|
|
59
|
-
unlocked(currentTimestamp) {
|
|
60
|
-
return (0, contractUtils_js_1.calculateUnlockedAmount)({
|
|
61
|
-
...this,
|
|
62
|
-
currentTimestamp,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
remaining(decimals) {
|
|
66
|
-
return (0, utils_js_2.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
exports.Contract = Contract;
|
package/dist/cjs/aptos/utils.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractAptosErrorCode = extractAptosErrorCode;
|
|
4
|
-
exports.normalizeAptosAddress = normalizeAptosAddress;
|
|
5
|
-
const constants_js_1 = require("./constants.js");
|
|
6
|
-
function extractAptosErrorCode(errorText) {
|
|
7
|
-
const match = constants_js_1.APTOS_ERROR_MATCH_REGEX.exec(errorText);
|
|
8
|
-
if (!match) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
return match[2];
|
|
12
|
-
}
|
|
13
|
-
function isAddressSpecial(address) {
|
|
14
|
-
if (address.length === 3) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Aptos has inconsistencies in how it returns addresses.
|
|
21
|
-
* This method normalizes them to be 64+2(0x...) characters long, or leaves it as SPECIAL ADDRESS (0x0 - 0xf inclusive)
|
|
22
|
-
* Per this: https://github.com/aptos-labs/aptos-ts-sdk/blob/main/src/core/accountAddress.ts#L115
|
|
23
|
-
* */
|
|
24
|
-
function normalizeAptosAddress(address) {
|
|
25
|
-
if (isAddressSpecial(address)) {
|
|
26
|
-
return address;
|
|
27
|
-
}
|
|
28
|
-
const length = address.length;
|
|
29
|
-
if (length === 66 || length < 3) {
|
|
30
|
-
return address;
|
|
31
|
-
}
|
|
32
|
-
const missingZeros = 66 - length;
|
|
33
|
-
return address.slice(0, 2) + "0".repeat(missingZeros) + address.slice(2);
|
|
34
|
-
}
|
package/dist/cjs/aptos/wallet.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AptosWalletWrapper = void 0;
|
|
4
|
-
const aptos_1 = require("aptos");
|
|
5
|
-
class AptosWalletWrapper {
|
|
6
|
-
constructor(wallet, client) {
|
|
7
|
-
this.client = client;
|
|
8
|
-
this.wallet = wallet;
|
|
9
|
-
if (wallet instanceof aptos_1.AptosAccount) {
|
|
10
|
-
this.address = wallet.address();
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
this.address = wallet.account.address;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async signAndSubmitTransaction(input) {
|
|
17
|
-
if (this.wallet instanceof aptos_1.AptosAccount) {
|
|
18
|
-
const builder = new aptos_1.TransactionBuilderRemoteABI(this.client, {
|
|
19
|
-
sender: this.address,
|
|
20
|
-
});
|
|
21
|
-
const rawTxn = await builder.build(input.function, input.type_arguments, input.arguments);
|
|
22
|
-
const res = await this.client.simulateTransaction(this.wallet, rawTxn);
|
|
23
|
-
if (!res[0].success) {
|
|
24
|
-
throw new Error(`Transaction Simulation failed: ${JSON.stringify(res)}`);
|
|
25
|
-
}
|
|
26
|
-
const signedTx = await this.client.signTransaction(this.wallet, rawTxn);
|
|
27
|
-
const tx = await this.client.submitSignedBCSTransaction(signedTx);
|
|
28
|
-
await this.client.waitForTransaction(tx.hash);
|
|
29
|
-
return tx.hash;
|
|
30
|
-
}
|
|
31
|
-
return (await this.wallet.signAndSubmitTransaction(input)).hash;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.AptosWalletWrapper = AptosWalletWrapper;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseStreamClient = void 0;
|
|
4
|
-
class BaseStreamClient {
|
|
5
|
-
/**
|
|
6
|
-
* Returns total fee percent, streamflow fees + partner fees
|
|
7
|
-
* @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
|
|
8
|
-
* @param chainSpecificParams additional parameters required by chain client
|
|
9
|
-
* @returns fee as floating number, so if fee is 0.99%, it will return 0.99
|
|
10
|
-
*/
|
|
11
|
-
async getTotalFee(getFeesData, chainSpecificParams) {
|
|
12
|
-
const fees = await this.getFees(getFeesData, chainSpecificParams);
|
|
13
|
-
if (fees) {
|
|
14
|
-
return fees.partnerFee + fees.streamflowFee;
|
|
15
|
-
}
|
|
16
|
-
return this.getDefaultStreamflowFee(chainSpecificParams);
|
|
17
|
-
}
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
|
-
extractErrorCode(err) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.BaseStreamClient = BaseStreamClient;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const BaseStreamClient_js_1 = require("./BaseStreamClient.js");
|
|
4
|
-
const types_js_1 = require("./types.js");
|
|
5
|
-
const utils_js_1 = require("./utils.js");
|
|
6
|
-
const index_js_1 = require("../aptos/index.js");
|
|
7
|
-
const index_js_2 = require("../evm/index.js");
|
|
8
|
-
const index_js_3 = require("../solana/index.js");
|
|
9
|
-
const index_js_4 = require("../sui/index.js");
|
|
10
|
-
const constants_js_1 = require("./constants.js");
|
|
11
|
-
/** Generic Stream Client implementation that wrap Chain Client methods and enriches error messages if possible
|
|
12
|
-
* @property {StreamClientType} - Chain Client implementation
|
|
13
|
-
* @property {chain} - Chain
|
|
14
|
-
*/
|
|
15
|
-
class GenericStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
16
|
-
constructor(options) {
|
|
17
|
-
super();
|
|
18
|
-
this.chain = options.chain;
|
|
19
|
-
switch (options.chain) {
|
|
20
|
-
case types_js_1.IChain.Solana:
|
|
21
|
-
this.nativeStreamClient = new index_js_3.SolanaStreamClient(options);
|
|
22
|
-
break;
|
|
23
|
-
case types_js_1.IChain.Aptos:
|
|
24
|
-
this.nativeStreamClient = new index_js_1.AptosStreamClient(options.clusterUrl, options.cluster, options.maxGas, options.programId);
|
|
25
|
-
break;
|
|
26
|
-
case types_js_1.IChain.BNB:
|
|
27
|
-
case types_js_1.IChain.Ethereum:
|
|
28
|
-
case types_js_1.IChain.Polygon:
|
|
29
|
-
this.nativeStreamClient = new index_js_2.EvmStreamClient(options.clusterUrl, options.chain, options.signer, options.cluster, options.programId);
|
|
30
|
-
break;
|
|
31
|
-
case types_js_1.IChain.Sui:
|
|
32
|
-
this.nativeStreamClient = new index_js_4.SuiStreamClient(options.clusterUrl, options.cluster, options.ids);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Creates a new stream/vesting contract.
|
|
37
|
-
*/
|
|
38
|
-
create(streamData, chainSpecificParams) {
|
|
39
|
-
return (0, utils_js_1.handleContractError)(() => this.nativeStreamClient.create(streamData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Creates multiple stream/vesting contracts.
|
|
43
|
-
*/
|
|
44
|
-
createMultiple(multipleStreamData, chainSpecificParams) {
|
|
45
|
-
return (0, utils_js_1.handleContractError)(() => this.nativeStreamClient.createMultiple(multipleStreamData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Attempts withdrawing from the specified stream.
|
|
49
|
-
*/
|
|
50
|
-
withdraw({ id, amount = constants_js_1.WITHDRAW_AVAILABLE_AMOUNT }, chainSpecificParams) {
|
|
51
|
-
return (0, utils_js_1.handleContractError)(() => this.nativeStreamClient.withdraw({ id, amount }, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Attempts canceling the specified stream.
|
|
55
|
-
*/
|
|
56
|
-
cancel(cancelData, chainSpecificParams) {
|
|
57
|
-
return (0, utils_js_1.handleContractError)(() => this.nativeStreamClient.cancel(cancelData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
61
|
-
*/
|
|
62
|
-
transfer(transferData, chainSpecificParams) {
|
|
63
|
-
return (0, utils_js_1.handleContractError)(() => this.nativeStreamClient.transfer(transferData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Tops up stream account with specified amount.
|
|
67
|
-
*/
|
|
68
|
-
topup(topupData, chainSpecificParams) {
|
|
69
|
-
return (0, utils_js_1.handleContractError)(() => this.nativeStreamClient.topup(topupData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Fetch stream data by its id (address).
|
|
73
|
-
*/
|
|
74
|
-
getOne(getOneData) {
|
|
75
|
-
return this.nativeStreamClient.getOne(getOneData);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Fetch streams by sender or recipient address.
|
|
79
|
-
*/
|
|
80
|
-
get(getAllData) {
|
|
81
|
-
return this.nativeStreamClient.get(getAllData);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Attempts updating the stream auto withdrawal params and amount per period
|
|
85
|
-
*/
|
|
86
|
-
update(updateData, chainSpecificParams) {
|
|
87
|
-
return (0, utils_js_1.handleContractError)(() => this.nativeStreamClient.update(updateData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Returns streamflow and partner fees for the specific wallet in %
|
|
91
|
-
*/
|
|
92
|
-
getFees(getFeesData) {
|
|
93
|
-
return this.nativeStreamClient.getFees(getFeesData);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Returns default Streamflow Fee in %
|
|
97
|
-
*/
|
|
98
|
-
getDefaultStreamflowFee() {
|
|
99
|
-
return this.nativeStreamClient.getDefaultStreamflowFee();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.default = GenericStreamClient;
|
|
@@ -1,10 +0,0 @@
|
|
|
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.WITHDRAW_AVAILABLE_AMOUNT = exports.BASE_FEE = exports.MAX_SAFE_UNIX_TIME_VALUE = void 0;
|
|
7
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
-
exports.MAX_SAFE_UNIX_TIME_VALUE = 8640000000000;
|
|
9
|
-
exports.BASE_FEE = 1009900; // Buffer to include usual fees when calculating stream amount
|
|
10
|
-
exports.WITHDRAW_AVAILABLE_AMOUNT = new bn_js_1.default("18446744073709551615"); // Magical number to withdraw all available amount from a Contract
|
|
@@ -1,77 +0,0 @@
|
|
|
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.decodeEndTime = exports.buildStreamType = exports.isTokenLock = exports.isDynamicLock = exports.isCreateAlignedStreamData = exports.isAligned = exports.isVesting = exports.isPayment = exports.isCliffCloseToDepositedAmount = exports.calculateUnlockedAmount = void 0;
|
|
7
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
-
const types_js_1 = require("./types.js");
|
|
9
|
-
const constants_js_1 = require("./constants.js");
|
|
10
|
-
const calculateUnlockedAmount = ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }) => {
|
|
11
|
-
const deposited = depositedAmount;
|
|
12
|
-
if (currentTimestamp < cliff)
|
|
13
|
-
return new bn_js_1.default(0);
|
|
14
|
-
if (currentTimestamp > end)
|
|
15
|
-
return deposited;
|
|
16
|
-
const savedUnlockedFunds = lastRateChangeTime === 0 ? cliffAmount : fundsUnlockedAtLastRateChange;
|
|
17
|
-
const savedUnlockedFundsTime = lastRateChangeTime === 0 ? cliff : lastRateChangeTime;
|
|
18
|
-
const streamed = new bn_js_1.default(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period))
|
|
19
|
-
.mul(amountPerPeriod)
|
|
20
|
-
.add(savedUnlockedFunds);
|
|
21
|
-
return streamed.lt(deposited) ? streamed : deposited;
|
|
22
|
-
};
|
|
23
|
-
exports.calculateUnlockedAmount = calculateUnlockedAmount;
|
|
24
|
-
const isCliffCloseToDepositedAmount = (streamData) => {
|
|
25
|
-
return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new bn_js_1.default(1)));
|
|
26
|
-
};
|
|
27
|
-
exports.isCliffCloseToDepositedAmount = isCliffCloseToDepositedAmount;
|
|
28
|
-
const isPayment = (streamData) => {
|
|
29
|
-
return streamData.canTopup;
|
|
30
|
-
};
|
|
31
|
-
exports.isPayment = isPayment;
|
|
32
|
-
const isVesting = (streamData) => {
|
|
33
|
-
return (!streamData.canTopup &&
|
|
34
|
-
!(0, exports.isCliffCloseToDepositedAmount)(streamData) &&
|
|
35
|
-
!(0, exports.isDynamicLock)(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage));
|
|
36
|
-
};
|
|
37
|
-
exports.isVesting = isVesting;
|
|
38
|
-
const isAligned = (stream) => {
|
|
39
|
-
return "minPrice" in stream && "maxPrice" in stream && "minPercentage" in stream && "maxPercentage" in stream;
|
|
40
|
-
};
|
|
41
|
-
exports.isAligned = isAligned;
|
|
42
|
-
const isCreateAlignedStreamData = (obj) => {
|
|
43
|
-
return "minPrice" in obj && "maxPrice" in obj && "minPercentage" in obj && "maxPercentage" in obj;
|
|
44
|
-
};
|
|
45
|
-
exports.isCreateAlignedStreamData = isCreateAlignedStreamData;
|
|
46
|
-
const isDynamicLock = (minPrice, maxPrice, minPercentage, maxPercentage) => {
|
|
47
|
-
return (!!minPrice && !!maxPrice && minPrice > 0 && maxPrice - minPrice <= 1 && minPercentage === 0 && maxPercentage === 100);
|
|
48
|
-
};
|
|
49
|
-
exports.isDynamicLock = isDynamicLock;
|
|
50
|
-
const isTokenLock = (streamData) => {
|
|
51
|
-
return (!streamData.canTopup &&
|
|
52
|
-
!streamData.automaticWithdrawal &&
|
|
53
|
-
!streamData.cancelableBySender &&
|
|
54
|
-
!streamData.cancelableByRecipient &&
|
|
55
|
-
!streamData.transferableBySender &&
|
|
56
|
-
!streamData.transferableByRecipient &&
|
|
57
|
-
((0, exports.isCliffCloseToDepositedAmount)(streamData) ||
|
|
58
|
-
(0, exports.isDynamicLock)(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage)));
|
|
59
|
-
};
|
|
60
|
-
exports.isTokenLock = isTokenLock;
|
|
61
|
-
const buildStreamType = (streamData) => {
|
|
62
|
-
if ((0, exports.isVesting)(streamData)) {
|
|
63
|
-
return types_js_1.StreamType.Vesting;
|
|
64
|
-
}
|
|
65
|
-
if ((0, exports.isTokenLock)(streamData)) {
|
|
66
|
-
return types_js_1.StreamType.Lock;
|
|
67
|
-
}
|
|
68
|
-
return types_js_1.StreamType.Payment;
|
|
69
|
-
};
|
|
70
|
-
exports.buildStreamType = buildStreamType;
|
|
71
|
-
const decodeEndTime = (endTime) => {
|
|
72
|
-
if (endTime.gt(new bn_js_1.default(constants_js_1.MAX_SAFE_UNIX_TIME_VALUE))) {
|
|
73
|
-
return constants_js_1.MAX_SAFE_UNIX_TIME_VALUE;
|
|
74
|
-
}
|
|
75
|
-
return endTime.toNumber();
|
|
76
|
-
};
|
|
77
|
-
exports.decodeEndTime = decodeEndTime;
|