@streamflow/stream 7.4.11 → 7.4.13
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/common/contractUtils.js +10 -3
- package/dist/cjs/solana/StreamClient.js +7 -3
- package/dist/cjs/solana/types.js +3 -0
- package/dist/esm/common/contractUtils.d.ts +13 -0
- package/dist/esm/common/contractUtils.js +8 -2
- package/dist/esm/solana/StreamClient.js +7 -3
- package/dist/esm/solana/types.js +3 -0
- package/package.json +19 -14
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.decodeEndTime = exports.buildStreamType = exports.isTokenLock = exports.isCreateAlignedStreamData = exports.isAligned = exports.isVesting = exports.isPayment = exports.isCliffCloseToDepositedAmount = exports.calculateUnlockedAmount = void 0;
|
|
6
|
+
exports.decodeEndTime = exports.buildStreamType = exports.isTokenLock = exports.isDynamicLock = exports.isCreateAlignedStreamData = exports.isAligned = exports.isVesting = exports.isPayment = exports.isCliffCloseToDepositedAmount = exports.calculateUnlockedAmount = void 0;
|
|
7
7
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
8
|
const types_js_1 = require("./types.js");
|
|
9
9
|
const constants_js_1 = require("./constants.js");
|
|
@@ -30,7 +30,9 @@ const isPayment = (streamData) => {
|
|
|
30
30
|
};
|
|
31
31
|
exports.isPayment = isPayment;
|
|
32
32
|
const isVesting = (streamData) => {
|
|
33
|
-
return !streamData.canTopup &&
|
|
33
|
+
return (!streamData.canTopup &&
|
|
34
|
+
!(0, exports.isCliffCloseToDepositedAmount)(streamData) &&
|
|
35
|
+
!(0, exports.isDynamicLock)(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage));
|
|
34
36
|
};
|
|
35
37
|
exports.isVesting = isVesting;
|
|
36
38
|
const isAligned = (stream) => {
|
|
@@ -41,6 +43,10 @@ const isCreateAlignedStreamData = (obj) => {
|
|
|
41
43
|
return "minPrice" in obj && "maxPrice" in obj && "minPercentage" in obj && "maxPercentage" in obj;
|
|
42
44
|
};
|
|
43
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;
|
|
44
50
|
const isTokenLock = (streamData) => {
|
|
45
51
|
return (!streamData.canTopup &&
|
|
46
52
|
!streamData.automaticWithdrawal &&
|
|
@@ -48,7 +54,8 @@ const isTokenLock = (streamData) => {
|
|
|
48
54
|
!streamData.cancelableByRecipient &&
|
|
49
55
|
!streamData.transferableBySender &&
|
|
50
56
|
!streamData.transferableByRecipient &&
|
|
51
|
-
(0, exports.isCliffCloseToDepositedAmount)(streamData)
|
|
57
|
+
((0, exports.isCliffCloseToDepositedAmount)(streamData) ||
|
|
58
|
+
(0, exports.isDynamicLock)(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage)));
|
|
52
59
|
};
|
|
53
60
|
exports.isTokenLock = isTokenLock;
|
|
54
61
|
const buildStreamType = (streamData) => {
|
|
@@ -49,6 +49,7 @@ const streamflow_aligned_unlocks_json_1 = __importDefault(require("./descriptor/
|
|
|
49
49
|
const derive_accounts_js_1 = require("./lib/derive-accounts.js");
|
|
50
50
|
const contractUtils_js_1 = require("../common/contractUtils.js");
|
|
51
51
|
const METADATA_ACC_SIZE = 1104;
|
|
52
|
+
const ALIGNED_METADATA_ACC_SIZE = 320;
|
|
52
53
|
class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
53
54
|
/**
|
|
54
55
|
* Create Stream instance
|
|
@@ -842,6 +843,9 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
842
843
|
bytes: sender,
|
|
843
844
|
},
|
|
844
845
|
},
|
|
846
|
+
{
|
|
847
|
+
dataSize: ALIGNED_METADATA_ACC_SIZE,
|
|
848
|
+
},
|
|
845
849
|
]);
|
|
846
850
|
const streamPubKeys = alignedOutgoingProgramAccounts.map((account) => account.account.stream);
|
|
847
851
|
const streamAccounts = await this.connection.getMultipleAccountsInfo(streamPubKeys, constants_js_1.TX_FINALITY_CONFIRMED);
|
|
@@ -857,11 +861,11 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
857
861
|
const streams = {};
|
|
858
862
|
const alignedStreamsPubKeys = Object.keys(streamRecord);
|
|
859
863
|
const alignedProxyPDAs = alignedStreamsPubKeys.map((streamPubKey) => (0, derive_accounts_js_1.deriveContractPDA)(this.alignedProxyProgram.programId, new web3_js_1.PublicKey(streamPubKey)));
|
|
860
|
-
const alignedProxyAccounts = await this.
|
|
864
|
+
const alignedProxyAccounts = await this.connection.getMultipleAccountsInfo(alignedProxyPDAs);
|
|
861
865
|
alignedProxyAccounts.forEach((account, index) => {
|
|
862
|
-
if (account) {
|
|
866
|
+
if (account && account.data.length === ALIGNED_METADATA_ACC_SIZE) {
|
|
863
867
|
const alignedData = streamRecord[alignedStreamsPubKeys[index]];
|
|
864
|
-
streams[alignedStreamsPubKeys[index]] = new types_js_1.AlignedContract(alignedData, account);
|
|
868
|
+
streams[alignedStreamsPubKeys[index]] = new types_js_1.AlignedContract(alignedData, this.alignedProxyProgram.account.contract.coder.accounts.decode("contract", account.data));
|
|
865
869
|
}
|
|
866
870
|
});
|
|
867
871
|
return streams;
|
package/dist/cjs/solana/types.js
CHANGED
|
@@ -80,6 +80,9 @@ class AlignedContract extends Contract {
|
|
|
80
80
|
this.sender = alignedProxy.sender.toBase58();
|
|
81
81
|
this.canceledAt = alignedProxy.streamCanceledTime.toNumber();
|
|
82
82
|
this.proxyAddress = stream.sender.toBase58();
|
|
83
|
+
// need to call this again since minPrice and maxPrice are used in determining the type
|
|
84
|
+
this.type = (0, contractUtils_js_1.buildStreamType)(this);
|
|
85
|
+
this.isAligned = true;
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
exports.AlignedContract = AlignedContract;
|
|
@@ -23,9 +23,14 @@ export declare const isVesting: (streamData: {
|
|
|
23
23
|
canTopup: boolean;
|
|
24
24
|
depositedAmount: BN;
|
|
25
25
|
cliffAmount: BN;
|
|
26
|
+
minPrice?: number;
|
|
27
|
+
maxPrice?: number;
|
|
28
|
+
minPercentage?: number;
|
|
29
|
+
maxPercentage?: number;
|
|
26
30
|
}) => boolean;
|
|
27
31
|
export declare const isAligned: (stream: Stream) => stream is AlignedStream;
|
|
28
32
|
export declare const isCreateAlignedStreamData: (obj: ICreateStreamData) => obj is ICreateAlignedStreamData;
|
|
33
|
+
export declare const isDynamicLock: (minPrice?: number, maxPrice?: number, minPercentage?: number, maxPercentage?: number) => boolean;
|
|
29
34
|
export declare const isTokenLock: (streamData: {
|
|
30
35
|
canTopup: boolean;
|
|
31
36
|
automaticWithdrawal: boolean;
|
|
@@ -35,6 +40,10 @@ export declare const isTokenLock: (streamData: {
|
|
|
35
40
|
transferableByRecipient: boolean;
|
|
36
41
|
depositedAmount: BN;
|
|
37
42
|
cliffAmount: BN;
|
|
43
|
+
minPrice?: number;
|
|
44
|
+
maxPrice?: number;
|
|
45
|
+
minPercentage?: number;
|
|
46
|
+
maxPercentage?: number;
|
|
38
47
|
}) => boolean;
|
|
39
48
|
export declare const buildStreamType: (streamData: {
|
|
40
49
|
canTopup: boolean;
|
|
@@ -45,6 +54,10 @@ export declare const buildStreamType: (streamData: {
|
|
|
45
54
|
transferableByRecipient: boolean;
|
|
46
55
|
depositedAmount: BN;
|
|
47
56
|
cliffAmount: BN;
|
|
57
|
+
minPrice?: number;
|
|
58
|
+
maxPrice?: number;
|
|
59
|
+
minPercentage?: number;
|
|
60
|
+
maxPercentage?: number;
|
|
48
61
|
}) => StreamType;
|
|
49
62
|
export declare const decodeEndTime: (endTime: BN) => number;
|
|
50
63
|
export {};
|
|
@@ -21,7 +21,9 @@ export const isPayment = (streamData) => {
|
|
|
21
21
|
return streamData.canTopup;
|
|
22
22
|
};
|
|
23
23
|
export const isVesting = (streamData) => {
|
|
24
|
-
return !streamData.canTopup &&
|
|
24
|
+
return (!streamData.canTopup &&
|
|
25
|
+
!isCliffCloseToDepositedAmount(streamData) &&
|
|
26
|
+
!isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage));
|
|
25
27
|
};
|
|
26
28
|
export const isAligned = (stream) => {
|
|
27
29
|
return "minPrice" in stream && "maxPrice" in stream && "minPercentage" in stream && "maxPercentage" in stream;
|
|
@@ -29,6 +31,9 @@ export const isAligned = (stream) => {
|
|
|
29
31
|
export const isCreateAlignedStreamData = (obj) => {
|
|
30
32
|
return "minPrice" in obj && "maxPrice" in obj && "minPercentage" in obj && "maxPercentage" in obj;
|
|
31
33
|
};
|
|
34
|
+
export const isDynamicLock = (minPrice, maxPrice, minPercentage, maxPercentage) => {
|
|
35
|
+
return (!!minPrice && !!maxPrice && minPrice > 0 && maxPrice - minPrice <= 1 && minPercentage === 0 && maxPercentage === 100);
|
|
36
|
+
};
|
|
32
37
|
export const isTokenLock = (streamData) => {
|
|
33
38
|
return (!streamData.canTopup &&
|
|
34
39
|
!streamData.automaticWithdrawal &&
|
|
@@ -36,7 +41,8 @@ export const isTokenLock = (streamData) => {
|
|
|
36
41
|
!streamData.cancelableByRecipient &&
|
|
37
42
|
!streamData.transferableBySender &&
|
|
38
43
|
!streamData.transferableByRecipient &&
|
|
39
|
-
isCliffCloseToDepositedAmount(streamData)
|
|
44
|
+
(isCliffCloseToDepositedAmount(streamData) ||
|
|
45
|
+
isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage)));
|
|
40
46
|
};
|
|
41
47
|
export const buildStreamType = (streamData) => {
|
|
42
48
|
if (isVesting(streamData)) {
|
|
@@ -20,6 +20,7 @@ import StreamflowAlignedUnlocksIDL from "./descriptor/idl/streamflow_aligned_unl
|
|
|
20
20
|
import { deriveContractPDA, deriveEscrowPDA, deriveTestOraclePDA } from "./lib/derive-accounts.js";
|
|
21
21
|
import { isCreateAlignedStreamData } from "../common/contractUtils.js";
|
|
22
22
|
const METADATA_ACC_SIZE = 1104;
|
|
23
|
+
const ALIGNED_METADATA_ACC_SIZE = 320;
|
|
23
24
|
export class SolanaStreamClient extends BaseStreamClient {
|
|
24
25
|
connection;
|
|
25
26
|
programId;
|
|
@@ -818,6 +819,9 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
818
819
|
bytes: sender,
|
|
819
820
|
},
|
|
820
821
|
},
|
|
822
|
+
{
|
|
823
|
+
dataSize: ALIGNED_METADATA_ACC_SIZE,
|
|
824
|
+
},
|
|
821
825
|
]);
|
|
822
826
|
const streamPubKeys = alignedOutgoingProgramAccounts.map((account) => account.account.stream);
|
|
823
827
|
const streamAccounts = await this.connection.getMultipleAccountsInfo(streamPubKeys, TX_FINALITY_CONFIRMED);
|
|
@@ -833,11 +837,11 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
833
837
|
const streams = {};
|
|
834
838
|
const alignedStreamsPubKeys = Object.keys(streamRecord);
|
|
835
839
|
const alignedProxyPDAs = alignedStreamsPubKeys.map((streamPubKey) => deriveContractPDA(this.alignedProxyProgram.programId, new PublicKey(streamPubKey)));
|
|
836
|
-
const alignedProxyAccounts = await this.
|
|
840
|
+
const alignedProxyAccounts = await this.connection.getMultipleAccountsInfo(alignedProxyPDAs);
|
|
837
841
|
alignedProxyAccounts.forEach((account, index) => {
|
|
838
|
-
if (account) {
|
|
842
|
+
if (account && account.data.length === ALIGNED_METADATA_ACC_SIZE) {
|
|
839
843
|
const alignedData = streamRecord[alignedStreamsPubKeys[index]];
|
|
840
|
-
streams[alignedStreamsPubKeys[index]] = new AlignedContract(alignedData, account);
|
|
844
|
+
streams[alignedStreamsPubKeys[index]] = new AlignedContract(alignedData, this.alignedProxyProgram.account.contract.coder.accounts.decode("contract", account.data));
|
|
841
845
|
}
|
|
842
846
|
});
|
|
843
847
|
return streams;
|
package/dist/esm/solana/types.js
CHANGED
|
@@ -125,5 +125,8 @@ export class AlignedContract extends Contract {
|
|
|
125
125
|
this.sender = alignedProxy.sender.toBase58();
|
|
126
126
|
this.canceledAt = alignedProxy.streamCanceledTime.toNumber();
|
|
127
127
|
this.proxyAddress = stream.sender.toBase58();
|
|
128
|
+
// need to call this again since minPrice and maxPrice are used in determining the type
|
|
129
|
+
this.type = buildStreamType(this);
|
|
130
|
+
this.isAligned = true;
|
|
128
131
|
}
|
|
129
132
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/stream",
|
|
3
|
-
"version": "7.4.
|
|
3
|
+
"version": "7.4.13",
|
|
4
4
|
"description": "JavaScript SDK to interact with Streamflow protocol.",
|
|
5
5
|
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
6
6
|
"main": "./dist/esm/index.js",
|
|
@@ -8,29 +8,34 @@
|
|
|
8
8
|
"type": "module",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
+
"types": "./dist/esm/index.d.ts",
|
|
11
12
|
"import": "./dist/esm/index.js",
|
|
12
|
-
"require": "./dist/cjs/index.js"
|
|
13
|
-
"types": "./dist/esm/index.d.ts"
|
|
13
|
+
"require": "./dist/cjs/index.js"
|
|
14
14
|
},
|
|
15
15
|
"./aptos": {
|
|
16
|
+
"types": "./dist/esm/aptos/index.d.ts",
|
|
16
17
|
"import": "./dist/esm/aptos/index.js",
|
|
17
|
-
"require": "./dist/cjs/aptos/index.js"
|
|
18
|
-
"types": "./dist/esm/aptos/index.d.ts"
|
|
18
|
+
"require": "./dist/cjs/aptos/index.js"
|
|
19
19
|
},
|
|
20
20
|
"./evm": {
|
|
21
|
+
"types": "./dist/esm/evm/index.d.ts",
|
|
21
22
|
"import": "./dist/esm/evm/index.js",
|
|
22
|
-
"require": "./dist/cjs/evm/index.js"
|
|
23
|
-
|
|
23
|
+
"require": "./dist/cjs/evm/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./solana/idl/*": {
|
|
26
|
+
"types": "./dist/esm/solana/descriptor/*",
|
|
27
|
+
"import": "./dist/esm/solana/descriptor/*",
|
|
28
|
+
"require": "./dist/cjs/solana/descriptor/*"
|
|
24
29
|
},
|
|
25
30
|
"./solana": {
|
|
31
|
+
"types": "./dist/esm/solana/index.d.ts",
|
|
26
32
|
"import": "./dist/esm/solana/index.js",
|
|
27
|
-
"require": "./dist/cjs/solana/index.js"
|
|
28
|
-
"types": "./dist/esm/solana/index.d.ts"
|
|
33
|
+
"require": "./dist/cjs/solana/index.js"
|
|
29
34
|
},
|
|
30
35
|
"./sui": {
|
|
36
|
+
"types": "./dist/esm/sui/index.d.ts",
|
|
31
37
|
"import": "./dist/esm/sui/index.js",
|
|
32
|
-
"require": "./dist/cjs/sui/index.js"
|
|
33
|
-
"types": "./dist/esm/sui/index.d.ts"
|
|
38
|
+
"require": "./dist/cjs/sui/index.js"
|
|
34
39
|
}
|
|
35
40
|
},
|
|
36
41
|
"scripts": {
|
|
@@ -42,9 +47,9 @@
|
|
|
42
47
|
"lint": "eslint --fix .",
|
|
43
48
|
"prepublishOnly": "pnpm run lint && pnpm run test run && pnpm run build"
|
|
44
49
|
},
|
|
45
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "1fdd4be9210a469bac52e97f969b679774a9aefd",
|
|
46
51
|
"devDependencies": {
|
|
47
|
-
"@streamflow/eslint-config": "7.4.
|
|
52
|
+
"@streamflow/eslint-config": "7.4.13",
|
|
48
53
|
"@types/bn.js": "5.1.1",
|
|
49
54
|
"@types/ethereum-checksum-address": "^0.0.0",
|
|
50
55
|
"date-fns": "2.28.0",
|
|
@@ -59,7 +64,7 @@
|
|
|
59
64
|
"@solana/spl-token": "0.4.9",
|
|
60
65
|
"@solana/wallet-adapter-base": "0.9.19",
|
|
61
66
|
"@solana/web3.js": "1.95.4",
|
|
62
|
-
"@streamflow/common": "7.4.
|
|
67
|
+
"@streamflow/common": "7.4.13",
|
|
63
68
|
"@suiet/wallet-kit": "^0.3.3",
|
|
64
69
|
"aptos": "1.21.0",
|
|
65
70
|
"bn.js": "5.2.1",
|