@zebec-network/zebec-vault-sdk 3.0.0 → 3.1.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/artifacts/zebec_stream.d.ts +5 -0
- package/dist/artifacts/zebec_stream.json +5 -0
- package/dist/service.d.ts +27 -2
- package/dist/service.js +71 -5
- package/package.json +12 -12
package/dist/service.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Address, BN, Program, Provider } from "@coral-xyz/anchor";
|
|
2
2
|
import { AccountMeta, Connection, Keypair, PublicKey, Signer, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
-
import { TransactionPayload } from "@zebec-network/solana-common";
|
|
3
|
+
import { MultiTransactionPayload, TransactionPayload } from "@zebec-network/solana-common";
|
|
4
4
|
import { ZebecCardV2Idl, ZebecStreamIdl, ZebecVaultV1Idl } from "./artifacts";
|
|
5
5
|
import { RpcNetwork } from "./constants";
|
|
6
6
|
import { Numeric, ProposalAction, ProposalInfo, VaultInfo } from "./types";
|
|
@@ -103,8 +103,10 @@ export declare class ZebecVaultService {
|
|
|
103
103
|
}): Promise<TransactionPayload>;
|
|
104
104
|
swapAndCreateSilverCard(params: SwapAndCreateSilverCardParams): Promise<TransactionPayload>;
|
|
105
105
|
swapAndLoadCarbonCard(params: SwapAndLoadCarbonCardParams): Promise<TransactionPayload>;
|
|
106
|
-
|
|
106
|
+
createStreamFromVault(params: CreateStreamFromVaultParams): Promise<TransactionPayload>;
|
|
107
|
+
createMultipleStreamFromVault(params: createMultipleStreamFromVaultParams): Promise<MultiTransactionPayload>;
|
|
107
108
|
private _createTransactionPayload;
|
|
109
|
+
private _createMultiTransactionPayload;
|
|
108
110
|
getVaultInfoOfUser(user?: Address): Promise<VaultInfo | null>;
|
|
109
111
|
getAllVaultsInfo(): Promise<VaultInfo[]>;
|
|
110
112
|
getProposalsInfoOfVault(vault: Address): Promise<ProposalInfo[]>;
|
|
@@ -194,3 +196,26 @@ export type CreateStreamFromVaultParams = {
|
|
|
194
196
|
rateUpdatable: boolean;
|
|
195
197
|
streamMetadataKeypair?: Keypair;
|
|
196
198
|
};
|
|
199
|
+
export type createMultipleStreamFromVaultParams = {
|
|
200
|
+
sender: Address;
|
|
201
|
+
streamInfo: {
|
|
202
|
+
receiver: Address;
|
|
203
|
+
streamToken: Address;
|
|
204
|
+
amount: Numeric;
|
|
205
|
+
automaticWithdrawal: boolean;
|
|
206
|
+
cancelableByRecipient: boolean;
|
|
207
|
+
cancelableBySender: boolean;
|
|
208
|
+
cliffPercentage: Numeric;
|
|
209
|
+
duration: number;
|
|
210
|
+
isPausable: boolean;
|
|
211
|
+
startNow: boolean;
|
|
212
|
+
startTime: number;
|
|
213
|
+
autoWithdrawFrequency: number;
|
|
214
|
+
streamName: string;
|
|
215
|
+
transferableByRecipient: boolean;
|
|
216
|
+
transferableBySender: boolean;
|
|
217
|
+
canTopup: boolean;
|
|
218
|
+
rateUpdatable: boolean;
|
|
219
|
+
streamMetadataKeypair?: Keypair;
|
|
220
|
+
}[];
|
|
221
|
+
};
|
package/dist/service.js
CHANGED
|
@@ -559,7 +559,7 @@ class ZebecVaultService {
|
|
|
559
559
|
otherIxs.push(swapAndCreateSilverCardIx);
|
|
560
560
|
return this._createTransactionPayload(vaultOwner, otherIxs, [], addressLookupTableAccounts);
|
|
561
561
|
}
|
|
562
|
-
async
|
|
562
|
+
async createStreamFromVault(params) {
|
|
563
563
|
const vaultOwner = (0, anchor_1.translateAddress)(params.sender);
|
|
564
564
|
const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
|
|
565
565
|
const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
|
|
@@ -580,8 +580,8 @@ class ZebecVaultService {
|
|
|
580
580
|
const amount = new anchor_1.BN((0, bignumber_js_1.BigNumber)(params.amount).times(constants_1.TEN_BIGNUM.pow(streamTokenDecimals)).toFixed(0));
|
|
581
581
|
const cliffPercentage = new anchor_1.BN((0, core_utils_1.percentToBps)(params.cliffPercentage));
|
|
582
582
|
const STREAM_NAME_BUFFER_SIZE = 128;
|
|
583
|
-
const
|
|
584
|
-
|
|
583
|
+
const streamNameArray = new Uint8Array(STREAM_NAME_BUFFER_SIZE);
|
|
584
|
+
streamNameArray.set(anchor_1.utils.bytes.utf8.encode(params.streamName));
|
|
585
585
|
const ix = await this.getCreateStreamFromVaultInstruction(vaultOwner, vault, vaultSigner, vaultSignerAta, receiverVaultSigner, receiverVaultSignerAta, streamToken, streamMetadata, streamConfig, withdrawAccount, streamVault, streamVaultAta, this.streamProgramId, {
|
|
586
586
|
amount,
|
|
587
587
|
automaticWithdrawal: params.automaticWithdrawal,
|
|
@@ -596,12 +596,61 @@ class ZebecVaultService {
|
|
|
596
596
|
rateUpdatable: params.rateUpdatable,
|
|
597
597
|
startNow: params.startNow,
|
|
598
598
|
startTime: new anchor_1.BN(params.startTime),
|
|
599
|
-
streamName:
|
|
599
|
+
streamName: streamNameArray,
|
|
600
600
|
transferableByRecipient: params.transferableByRecipient,
|
|
601
601
|
transferableBySender: params.transferableBySender,
|
|
602
602
|
});
|
|
603
603
|
return this._createTransactionPayload(vaultOwner, [ix], [streamMetatdataKeypair]);
|
|
604
604
|
}
|
|
605
|
+
async createMultipleStreamFromVault(params) {
|
|
606
|
+
const vaultOwner = (0, anchor_1.translateAddress)(params.sender);
|
|
607
|
+
const [vault] = (0, pda_1.deriveUserVault)(vaultOwner, this.vaultV1ProgramId);
|
|
608
|
+
const [vaultSigner] = (0, pda_1.deriveVaultSigner)(vault, this.vaultV1ProgramId);
|
|
609
|
+
const transactionArtifacts = await Promise.all(params.streamInfo.map(async (info) => {
|
|
610
|
+
const receiver = (0, anchor_1.translateAddress)(info.receiver);
|
|
611
|
+
const [receiverVault] = (0, pda_1.deriveUserVault)(receiver, this.vaultV1ProgramId);
|
|
612
|
+
const [receiverVaultSigner] = (0, pda_1.deriveVaultSigner)(receiverVault, this.vaultV1ProgramId);
|
|
613
|
+
const streamToken = (0, anchor_1.translateAddress)(info.streamToken);
|
|
614
|
+
const vaultSignerAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, vaultSigner, true);
|
|
615
|
+
const receiverVaultSignerAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, receiverVaultSigner, true);
|
|
616
|
+
const [streamConfig] = (0, pda_1.deriveStreamConfigPda)(this.streamProgramId);
|
|
617
|
+
const streamConfigInfo = await this.streamProgram.account.streamConfig.fetch(streamConfig, this.connection.commitment);
|
|
618
|
+
const withdrawAccount = streamConfigInfo.withdrawAccount;
|
|
619
|
+
const streamMetatdataKeypair = info.streamMetadataKeypair ?? web3_js_1.Keypair.generate();
|
|
620
|
+
const streamMetadata = streamMetatdataKeypair.publicKey;
|
|
621
|
+
const [streamVault] = (0, pda_1.deriveStreamVaultPda)(streamMetadata, this.streamProgramId);
|
|
622
|
+
const streamVaultAta = (0, solana_common_1.getAssociatedTokenAddressSync)(streamToken, streamVault, true);
|
|
623
|
+
const streamTokenDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, streamToken);
|
|
624
|
+
const amount = new anchor_1.BN((0, bignumber_js_1.BigNumber)(info.amount).times(constants_1.TEN_BIGNUM.pow(streamTokenDecimals)).toFixed(0));
|
|
625
|
+
const cliffPercentage = new anchor_1.BN((0, core_utils_1.percentToBps)(info.cliffPercentage));
|
|
626
|
+
const STREAM_NAME_BUFFER_SIZE = 128;
|
|
627
|
+
const streamNameArray = new Uint8Array(STREAM_NAME_BUFFER_SIZE);
|
|
628
|
+
streamNameArray.set(anchor_1.utils.bytes.utf8.encode(info.streamName), 0);
|
|
629
|
+
const ix = await this.getCreateStreamFromVaultInstruction(vaultOwner, vault, vaultSigner, vaultSignerAta, receiverVaultSigner, receiverVaultSignerAta, streamToken, streamMetadata, streamConfig, withdrawAccount, streamVault, streamVaultAta, this.streamProgramId, {
|
|
630
|
+
amount,
|
|
631
|
+
automaticWithdrawal: info.automaticWithdrawal,
|
|
632
|
+
autoWithdrawFrequency: new anchor_1.BN(info.autoWithdrawFrequency),
|
|
633
|
+
cancelableByRecipient: info.cancelableByRecipient,
|
|
634
|
+
cancelableBySender: info.cancelableBySender,
|
|
635
|
+
canTopup: info.canTopup,
|
|
636
|
+
cliffPercentage,
|
|
637
|
+
duration: new anchor_1.BN(info.duration),
|
|
638
|
+
isPausable: info.isPausable,
|
|
639
|
+
numberOfWithdrawls: new anchor_1.BN(Math.floor(info.duration / info.autoWithdrawFrequency)),
|
|
640
|
+
rateUpdatable: info.rateUpdatable,
|
|
641
|
+
startNow: info.startNow,
|
|
642
|
+
startTime: new anchor_1.BN(info.startTime),
|
|
643
|
+
streamName: streamNameArray,
|
|
644
|
+
transferableByRecipient: info.transferableByRecipient,
|
|
645
|
+
transferableBySender: info.transferableBySender,
|
|
646
|
+
});
|
|
647
|
+
return {
|
|
648
|
+
instructions: [ix],
|
|
649
|
+
signers: [streamMetatdataKeypair],
|
|
650
|
+
};
|
|
651
|
+
}));
|
|
652
|
+
return this._createMultiTransactionPayload(vaultOwner, transactionArtifacts);
|
|
653
|
+
}
|
|
605
654
|
async _createTransactionPayload(payerKey, instructions, signers, addressLookupTableAccounts) {
|
|
606
655
|
const errorMap = new Map();
|
|
607
656
|
this.vaultV1Program.idl.errors.forEach((error) => errorMap.set(error.code, error.msg));
|
|
@@ -612,7 +661,24 @@ class ZebecVaultService {
|
|
|
612
661
|
return provider.wallet.signTransaction(tx);
|
|
613
662
|
};
|
|
614
663
|
}
|
|
615
|
-
return new solana_common_1.TransactionPayload(this.provider.connection, errorMap, instructions, payerKey, signers, addressLookupTableAccounts, signTransaction);
|
|
664
|
+
return new solana_common_1.TransactionPayload(this.provider.connection, errorMap, { instructions, feePayer: payerKey, signers, addressLookupTableAccounts }, signTransaction);
|
|
665
|
+
}
|
|
666
|
+
async _createMultiTransactionPayload(payerKey, transactionArtifacts) {
|
|
667
|
+
const errorMap = new Map();
|
|
668
|
+
this.vaultV1Program.idl.errors.forEach((error) => errorMap.set(error.code, error.msg));
|
|
669
|
+
let signAllTransactions = undefined;
|
|
670
|
+
const provider = this.provider;
|
|
671
|
+
if (provider instanceof anchor_1.AnchorProvider) {
|
|
672
|
+
signAllTransactions = async (txns) => {
|
|
673
|
+
return provider.wallet.signAllTransactions(txns);
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
const transactionData = transactionArtifacts.map((data) => ({
|
|
677
|
+
instructions: data.instructions,
|
|
678
|
+
feePayer: payerKey,
|
|
679
|
+
signers: data.signers,
|
|
680
|
+
}));
|
|
681
|
+
return new solana_common_1.MultiTransactionPayload(this.connection, errorMap, transactionData, signAllTransactions);
|
|
616
682
|
}
|
|
617
683
|
async getVaultInfoOfUser(user) {
|
|
618
684
|
user = user ? (0, anchor_1.translateAddress)(user) : this.provider.publicKey;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zebec-network/zebec-vault-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "An SDK for zebec vault solana program",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -26,25 +26,25 @@
|
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/mocha": "^10.0.10",
|
|
29
|
-
"@types/node": "^24.
|
|
30
|
-
"@zebec-network/zebec-card-v2-sdk": "^2.
|
|
31
|
-
"@zebec-network/zebec-stake-sdk": "^1.1.
|
|
32
|
-
"@zebec-network/zebec-stream-sdk": "^1.
|
|
33
|
-
"dotenv": "^17.2.
|
|
34
|
-
"mocha": "^11.
|
|
35
|
-
"prettier": "^3.
|
|
29
|
+
"@types/node": "^24.3.1",
|
|
30
|
+
"@zebec-network/zebec-card-v2-sdk": "^2.1.2",
|
|
31
|
+
"@zebec-network/zebec-stake-sdk": "^1.1.3",
|
|
32
|
+
"@zebec-network/zebec-stream-sdk": "^1.7.0",
|
|
33
|
+
"dotenv": "^17.2.2",
|
|
34
|
+
"mocha": "^11.7.2",
|
|
35
|
+
"prettier": "^3.6.2",
|
|
36
36
|
"rimraf": "^6.0.1",
|
|
37
37
|
"ts-mocha": "^11.1.0",
|
|
38
38
|
"ts-node": "^10.9.2",
|
|
39
|
-
"typescript": "^5.
|
|
39
|
+
"typescript": "^5.9.2"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@coral-xyz/anchor": "^0.31.1",
|
|
43
43
|
"@solana/web3.js": "^1.98.2",
|
|
44
44
|
"@types/bn.js": "^5.2.0",
|
|
45
|
-
"@zebec-network/core-utils": "^1.1.
|
|
46
|
-
"@zebec-network/solana-common": "^1.
|
|
47
|
-
"bignumber.js": "^9.3.
|
|
45
|
+
"@zebec-network/core-utils": "^1.1.1",
|
|
46
|
+
"@zebec-network/solana-common": "^2.1.1",
|
|
47
|
+
"bignumber.js": "^9.3.1",
|
|
48
48
|
"buffer": "^6.0.3"
|
|
49
49
|
}
|
|
50
50
|
}
|