bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 20쪽 중 18쪽
e in the following way.
```typescript
const config = {
networkId,
nodeUrl,
streamContractId,
multiSigFactoryContractId,
},
const actions = {
multiSigActions: new MultiSigActions(),
storageSpecAction: new StorageSpecActions(),
streamActions: new StreamActions(),
};
const multisigService = new ZebecMultiSigService(
signerId,
multisigAccountId,
actions
);
```
# Initialize Near Stream
Let's suppose this multisig requires two of its member to confirm a request and `multisigservices1` is an instance created for `member1` and `multisigservices2` is an instance created for `member2`. A native stream can be done in the following way.
```typescript
const params: InitStreamParams = {
canCancel: true,
canUpdate: true,
startTime: (nowInSec() + 15).toString(),
endTime: (nowInSec() + 20).toString(),
receiver: member2,
streamRate: NearAmount.parse("0.001").toString(),
};
const payload = await multisigservices1.initStream(params);
const result = await wallet.signAndTransactions(payload);
```
Then to confirm the request by another member you need to retrieve the requestId from the result which can be done in the following way.
```typescript
const successValue = (result[result.length - 1].status as FinalExecutionStatus).SuccessValue;
if (!successValue) throw new Error("successValue is missing");
const requestId = Number(Buffer.from(successValue, "base64").toString());
```
Then request can be confirmed by another member in the following way.
```typescript
const confirmPayload = await multiSigService2.confirm({ requestId: Number(requestId) });
const result = await wallet.signAndTransactions(payload);
```
# Initialize Token Stream
```typescript
const params: InitTokenStreamParams = {
canCancel: true,
canUpdate: true,
startTime: (nowInSec() + 1000).toString(),
endTime: (nowInSec() + 1300).toString(), // after 2 min
receiver: account2.accountId,
streamRate: FungibleTokenAmount.parse("0.1", 18).toString(),
tokenId: "dai.fakes.testnet",
};
const payload = await multiSigService1.initTokenStream(params);
const result = await wallet.signAndTransactions(payload);
```
Then to confirm the request by another member you need to retrieve the requestId from the result which can be done in the following way.
<pre class="language-typescript"><code class="lang-typescript"><strong>const successValue = (result[result.length - 1].status as FinalExecutionStatus).SuccessValue;
</strong>if (!successValue) throw new Error("successValue is missing");
const requestId = Number(Buffer.from(successValue, "base64").toString());
</code></pre>
Then request can be confirmed by another member in the following way.
```typescript
const confirmPayload = await multiSigService2.confirm({ requestId: Number(requestId) });
const result = await wallet.signAndTransactions(payload);
```
# Pause/Resume Stream
```typescript
const pauseParams: PauseStreamParams = {
streamId: "1",
};
const payoad = await multisigservices1.pause(pauseParams);
const result = await wallet.signAndTransactions(payload);
const successValue = (result[result.length - 1].status as FinalExecutionStatus).SuccessValue;
if (!successValue) throw new Error("successValue is missing");
const requestId = Number(Buffer.from(successValue, "base64").toString());
const confirmPayload = await multiSigService2.confirm({ requestId: Number(requestId) });
const result = await wallet.signAndTransactions(payload);
```
```typescript
const resumeParams: ResumeStreamParams = {
streamId,
};
const payload = await multisigservices1.resume(resumeParams);
const result = await wallet.signAndTransactions(payload);
const successValue = (result[result.length - 1].status as FinalExecutionStatus).SuccessValue;
if (!successValue) throw new Error("successValue is missing");
const requestId = Number(Buffer.from(successValue, "base64").toString());
const confirmPayload = await multiSigService2.confirm({ requestId: Number(requestId) });
const result = await wallet.signAndTransactions(payload);
```
# Withdraw Stream
```typescript
const withdrawParams: WithdrawStreamParams = {
streamId: "1",
};
const payload = await multisigservices1.withdraw(withdrawParams);
const result = await wallet.signAndTransactions(payload);
const successValue = (result[result.length - 1].status as FinalExecutionStatus).SuccessValue;
if (!successValue) throw new Error("successValue is missing");
const requestId = Number(Buffer.from(successValue, "base64").toString());
const confirmPayload = await multiSigService2.confirm({ requestId: Number(requestId) });
const result = await wallet.signAndTransactions(payload);
```
# Update Stream
```typescript
const updateParams : UpdateParams = {
endTime: ,
startTime,
streamId,
streamRate
}
const payload = await multisigService1.update(updateParams);
const result = await wallet.signAndTransactions(payload);
const successValue = (result[result.length - 1].status as FinalExecutionStatus).SuccessValue;
if (!successValue) throw new Error("successValue is missing");
const requestId = Number(Buffer.from(successValue, "base64").toString());
const confirmPayload = await multiSigService2.confirm({ requestId: Number(requestId) });
const result = await wallet.signAndTransactions(payload);
```
# Cancel Stream
```typescript
const cancelParams: CancelStreamParams = {
streamId
}
const payload = await multisigService1.cancel(cancelParams);
const result = await wallet.signAndTransactions(payload);
const successValue = (result[result.length - 1].status as FinalExecutionStatus).SuccessValue;
if (!successValue) throw new Error("successValue is missing");
const requestId = Number(Buffer.from(successValue, "base64").toString());
const confirmPayload = await multiSigService2.confirm({ requestId: Number(requestId) });
const result = await wallet.signAndTransactions(payload);
```
# Claim Stream
```typescript
const claimParams: ClaimBalanceParams = {
streamId: "1"
}
const payload = multisigService1.claim(claimParams);
const result = await wallet.signAndTransactions(payload);
const successValue = (result[result.length - 1].status as FinalExecutionStatus).SuccessValue;
if (!successValue) throw new Error("successValue is missing");
const requestId = Number(Buffer.from(successValue, "base64").toString());
const confirmPayload = await multiSigService2.confirm({ requestId: Number(requestId) });
const result = await wallet.signAndTransactions(payload);
```
# View methods
Mutisig contract provides some view methods which are given below.
* getRequest
```typescript
const result = await multisigservice.getRequest({ requestId: 0 });
```
* getRequestWithSigner
```typescript
const result = await multisigservice.getRequestWithSigner({ requestId: 0 });getRequestIdsList
```
* getRequestIdsList
```typescript
const result = await multisigservice.getRequestIdsList();
```
* getConfirmations
```typescript
const result = await multisigservice.getConfirmations({requestId: 0 });
```
* getNumOfConfirmations
```typescript
const result = await multisigservice.getNumOfConfirmations();
```
* getNumRequestsPerMember
```typescript
const member: MultiSigMemberWithAccountId = {
type: "Account";
accountId: "<account id>";
}
const result = await multisigservice.getNumRequestsPerMember();
```
* getRequestNonce
<pre class="language-typescript"><code class="lang-typescript"><strong>const result = await multisigservice.getRequestNonce();
</strong></code></pre>
# Zebec Evm Sdk
This SDK is organized into three main modules: `bulk-transfer`, `staking`, `stream` Each clients serves a specific purpose and provides functionalities related to its respective domain.
1. **`stream` Client:** This client is focused on financial streaming, which involves continuous and scheduled payments or allocations.
2. **`bulk-transfer` Client:** This client deals with scheduled bulk transfers of assets or tokens.
3. **`staking` Client:** This client is related to staking assets.
**Usage:** Developers can use this SDK to integrate and interact with various zebec functionalities in their applications. Depending on their needs, they can import and utilize specific modules from the SDK, such as bulk transfers, staking, streaming, or multisignature operations. The SDK provides pre-defined class, types and interfaces to facilitate seamless integration and interaction with these functionalities.
# Zebec Stream Client
ZebecStreamClient is a client library that provides an interface to interact with the Zebec Stream smart contract. It allows you to perform various operations such as initiating streams, withdrawing tokens, updating streams, and more.
### Installation
To use the ZebecStreamClient library, you need to have the `zebec-bnb-sdk` package installed in your project. You can install them using npm:
```shell
npm install @zebec-protocol/zebec-bnb-sdk
```
### Environment Setup
To Setup the environment checkout the .env.example at [https://github.com/Zebec-protocol/bnb-zebec-sdk](#environment-setup).
<table><thead><tr><th>Variables</th><th width="240.33333333333331">Description</th><th>Values</th></tr></thead><tbody><tr><td>CHAIN_ID</td><td>Chain Ids</td><td>56, 22222(Nautilus), 5, 97</td></tr><tr><td>SDK_ENV</td><td>Environment to work on : "production" or "test"</td><td>"production" if you are working on mainnet and "test" for testnets</td></tr></tbody></table>
### Test Code
The [test code ](https://github.com/Zebec-protocol/bnb-zebec-sdk/blob/main/test/integration/stream/stream.spec.ts)can also serve as a reference for how to use the `ZebecStreamClient` class in practice.
# Creating Clients
Import the necessary dependencies and create an instance of the `ZebecStreamClient` class:
```javascript
import { ZebecStreamClient } from "@zebec-protocol/zebec-bnb-sdk";
// Create an instance of ZebecStreamClient
const zebecClient = new ZebecStreamClient(signer);
```
#### Getting Signer Address
You can get the signer's address using the `getSignerAddress()` method:
```javascript
const signerAddress = await client.getSignerAddress();
console.log("Signer Address:", signerAddress);
```
# Whitelisting Tokens
Streaming is only allowed for tokens that have been added to the whitelist within the Zebec Core Contract. Use `whitelistToken()` method:
```javascript
const tokenAddresses = ["tokenA", "tokenB"];
await zebecClient.grantWhitelisterRole(sender.address);
await zebecClient.whitelistToken([tokenAddress]);
```
*Note: Only user who has whitlisterRole can whitelist a token. To grant whitelister role, use the `grantWhitelisterRole():`*
```javascript
//only contract owner can grant whitelister role
const zebecClientOwner = new ZebecStreamClient(contractOwner);
await zebecClientOwner.grantWhitelisterRole(whitelisterAddress);
```
To whitelist your token on the existing Zebec protocol, please reach out directly to the administrator. You can see the list of whitelisted tokens at:
{% content-ref url="/pages/8Th5CauHLiaHSl9oM6vr" %}
[Whitelisted Tokens on BSC and Nautilus](/zebec-network-archive/zebec-network-archive/zebec-evm-sdk/zebec-stream-client/whitelisted-tokens-on-bsc-and-nautilus)
{% endcontent-ref %}
# Deposit into Zebec Wallet
To deposit tokens into the zebec wallet, use the `depositToken()` method:
*Note: You can override the default sdk overrides using optional param called `overrides` in every client functions.*
```javascript
const tokenAddress = "0x1234567890abcdef";
const amount = "100";
const customOverrides = {
gasLimit: 25000000,
};
const receipt = await client.depositToken(
tokenAddress,
amount,
customOverrides
);
console.log("Deposit Token Receipt:", receipt);
```
# Withdraw from Zebec Wallet
To withdraw tokens from the zebec wallet, use the `withdrawToken()` method:
*Note: You can override the default sdk overrides using optional param called `overrides` in every client functions.*
```javascript
const tokenAddress = "0x1234567890abcdef";
const amount = "10";
const customOverrides = {
gasLimit: 25000000,
};
const receipt = await client.withdrawToken(
tokenAddress,
amount,
customOverrides
);
console.log("Withdraw Token Receipt:", receipt);
```
####
# Initiating a Stream
To initiate a stream, use the `initStream()` method:
```javascript
const streamName = "MyStream";
const amount = "100";
const tokenAddress = "0x1234567890abcdef..";
const receiver = "0xabcdef1234567890..";
const startTime = 1654320000;
const endTime = 1657008000;
const canCancel = true;
const canPause = true;
const customOverrides = {
gasLimit: 25000000,
};
const receipt = await zebecClient.initStream(
streamName,
amount,
tokenAddress,
receiver,
startTime,
endTime,
canCancel,
canPause,
customOverrides
);
console.log("Initiate Stream Receipt:", receipt);
```
# Pause/Resume/Cancel Stream
You can pause, resume, or cancel a stream using the respective methods:
```javascript
const streamBytes = "0xabcdef1234567890.."; // Stream ID
// Pause a stream
const pauseReceipt = await zebecClient.pauseStream(streamBytes);
console.log("Pause Stream Receipt:", pauseReceipt);
// Resume a stream
const resumeReceipt = await zebecClient.resumeStream(streamBytes);
console.log("Resume Stream Receipt:", resumeReceipt);
// Cancel a stream
const cancelReceipt = await zebecClient.cancelStream(streamBytes);
console.log("Cancel Stream Receipt:", cancelReceipt);
```
# Updating a Stream
To update a stream, use the `updateStream()` method:
```javascript
const streamName = "UpdatedStream";
const streamBytes = "0xabcdef1234567890.."; // Stream ID
const startTime = 1657008000;
const endTime = 1659696000;
const amount = "200";
const receipt = await zebecClient.updateStream(
streamName,
streamBytes,
tokenAddress,
startTime,
endTime,
amount
);
console.log("Update Stream Receipt:", receipt);
```
# Withdraw Streamed Tokens
To withdraw tokens from a stream by receiver, use the `withdrawStream()` method:
```javascript
const streamBytes = "0xabcdef1234567890.."; // Stream ID
const tokenAddress = "0x1234567890abcdef..";
const amount = "50";
const zebecWalletWithdrawal = false;
const receipt = await zebecReceiverClient.withdrawStream(
streamBytes,
tokenAddress,
amount,
zebecWalletWithdrawal
);
console.log("Withdraw Stream Receipt:", receipt);
```
# Getting Stream Details
To get the details of a stream, use the `getStreamDetails()` method:
```javascript
const streamBytes = await zebecClient.getLatestStreamBytes(sender.address); // gets the last stream bytes of "sender.address"
const streamDetails = await zebecClient.getStreamDetails(streamBytes);
console.log("Stream Details:", streamDetails);
```
For more details and methods, please refer to the source code or documentation of the`ZebecStreamClient` class.
The `getStreamDetails` function returns an object containing the following stream details:
* `receiver` (type: `string`): address of the receiver of the stream.
* `token` (type: `string`): address of the token being streamed
* `startTime` (type: `BigNumber`): The timestamp when the stream started.
* `endTime` (type: `BigNumber`): The timestamp when the stream is scheduled to end.
* `amounts` (type: `Core.AmountStructOutput`):
An object containing various amounts associated with the stream. It is a type with the following sub-properties:
* `streamAmount` (BigNumber): The total amount allocated to the stream.
* `releasedAmount` (BigNumber): The amount that has been released to the recipient.
* `unlockedAmount` (BigNumber): The amount that is currently unlocked and can be withdrawn.
* `pausedAmount` (BigNumber): The amount that is currently paused and cannot be withdrawn.
* `pausedTime` (type: `BigNumber`): The timestamp when the stream was paused, if it has been paused.
* `withdrawTime` (type: `BigNumber`): The timestamp when the stream was withdrawn, if it has been withdrawn.
* `originZebecWallet` (type: `string`): The wallet or address from which the stream originates.
* `canceled` (type: `boolean`): A boolean value indicating whether the stream has been canceled (`true`) or not (`false`).
* `paused` (type: `boolean`): A boolean value indicating whether the stream is currently paused (`true`) or not (`false`).
* `streamParam` (type: `number`): A numeric value representing a parameter of the stream.
# Whitelisted Tokens on BSC and Nautilus
#### BNB Smart Chain
| Token | Address |
| ----- | ------------------------------------------ |
| BNB | 0x0000000000000000000000000000000000000000 |
| wBNB | 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c |
| USDT | 0x55d398326f99059fF775485246999027B3197955 |
| USDC | 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d |
| ZBC | 0x37a56cdcD83Dce2868f721De58cB3830C44C6303 |
#### Nautilus
| Token Name | Token Address |
| ---------- | ------------------------------------------ |
| ZBC | 0x0000000000000000000000000000000000000000 |
| USDC | 0xB2723928400AE5778f6A3C69D7Ca9e90FC430180 |
| USDT | 0xBDa330Ea8F3005C421C8088e638fBB64fA71b9e0 |
# Zebec Bulk Client
The `ZebecBulkClient` is a TypeScript class designed to interact with Ethereum smart contracts for bulk transfers in the Zebec protocol.
### Overview
The `ZebecBulkClient` class is designed to interact with two key contracts in the Zebec protocol: `BulkTransfer` and `Core`. These contracts are used to manage bulk transfers of tokens. The class provides methods to perform actions such as initializing bulk transfers, updating bulk transfers, and withdrawing funds from bulk transfers.
### Test Code
The [test code](https://github.com/Zebec-protocol/bnb-zebec-sdk/tree/main/test/integration/bulk) can also serve as a reference for how to use the `ZebecBulkClient` class in practice.
# Bulk Instant Transfer
#### Initializing the Class
To initialize an instance of the `ZebecBulkClient` class, you need to provide a signer or provider and optionally specify contract addresses for `BulkTransfer` and `Core`. Here's an example of how to initialize the class:
```typescript
import { ethers } from "ethers";
import { ZebecBulkClient } from "@zebec-protocol/zebec-bnb-sdk";
// Initialize with a signer (e.g., MetaMask)
const signer = new ethers.Wallet("your-private-key");
const bulkClient = new ZebecBulkClient(signer);
```
1. **Initialize Bulk Instant**
```typescript
const bulkStreamName = "YourBulkStreamName";
const now = Math.floor(Date.now() / 1000);
const amounts = ["1", "2", "3"];
const tokenAddress = "0xTokenAddress";
const receivers = [receiver1.address, receiver2.address, receiver3.address];
const startTimes = [BigNumber.from(now + 100)]; // An array of start times. Length must be equal to recurring Frequency
const recurringFrequency = 1;
const overrides = {}; // Optional overrides
const bulkInstantTree = await bulkClient.getBulkInstantTransferRoot(
tokenAddress,
amounts,
receivers
);
const txnReceipt = await bulkClient.initBlulkInstantTransfer(
bulkStreamName,
bulkInstantTree.root,
startTimes,
recurringFrequency
);
console.log(txnReceipt);
```
`initBlulkInstantTransfer` method initializes a bulk stream with a bulk tree root, start times, and other parameters.
`getBulkInstantTransferRoot` function is designed to calculate and retrieve the Merkle tree root for a bulk instant transfer. This function is used to create a Merkle tree structure that represents a set of instant token transfers that will occur simultaneously.
2. **Update Bulk Transfer**
<pre class="language-typescript"><code class="lang-typescript">const bulkName = "Updated Bulk";
const bulkIndex = await receiver1Client.getLatestBulkCount(sender.address).toNumber(); // bulk index to update
const amounts = ["5", "7", "9"];
const tokenAddress = "0xNewTokenAddress";
const receivers = [receiver1.address, receiver2.address, receiver3.address];
const startTimes = [BigNumber.from(now + 600), BigNumber.from(now + 900)]; // An array of start times. Length must be equal to recurring Frequency
const recurringFrequency = 2;
const overrides = {}; // Optional overrides
<strong>bulkInstantTree = await bulkClient.updateBulkInstantTransferRoot(
</strong> tokenAddress,
amounts,
프로젝트로 돌아가기