bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 20쪽 중 16쪽
"Shittal street, Bharatpur - 10, Chitwan";
const recipient = Recipient.create(
participantId,
firstName,
lastName,
emailAddress,
mobilePhone,
language,
city,
state,
postalCode,
countryCode,
address1,
);
const amount = "150.55";
const quote = await service.fetchQuote(amount);
const [depositResponse, buyCardResponse, apiResponse] = await service.purchaseCard({
amount,
recipient,
quote,
});
console.log("Deposit Transaction Hash:", depositResponse.hash);
console.log("Purchase Transaction Hash:", buyCardResponse.hash);
console.log("Zebec Server Response:", apiResponse.data);
```
For Bittensor Network:
```javascript
const participantId = "JohnChamling";
const firstName = "John";
const lastName = "Chamling";
const emailAddress = "user@example.com";
const mobilePhone = "+91 012345678";
const language = "en-US";
const city = "Bharatpur";
const state = "Bagmati";
const postalCode = "44200";
const countryCode: CountryCode = "NPL";
const address1 = "Shittal street, Bharatpur - 10, Chitwan";
const recipient = Recipient.create(
participantId,
firstName,
lastName,
emailAddress,
mobilePhone,
language,
city,
state,
postalCode,
countryCode,
address1,
);
const amount = "150.55"; // Amount in USD
const quote = await service.fetchQuote(amount);
const [depositResponse, apiResponse] = await service.purchaseCard({
walletAddress: signer.address || "<wallet_address>",
amount,
recipient,
quote,
});
console.log(
`Deposit response: \n BlockHash: ${depositResponse.blockHash} \n TransactionHash: ${depositResponse.txHash}`,
);
console.log("Zebec Server Response:", apiResponse.data);
```
# Configuration Parameters
#### ZebecCardService
To create an instance of `ZebecCardService`, you need:
* **signer**: An instance of `ethers.Signer`.
* **chainId**: The ID of the blockchain (see list of supported chains below).
* **apiConfig**: Object containing `apiKey` and `encryptionKey`.
* **sdkConfig (optional)**: SDK-specific settings, such as:
* `sandbox`: Boolean, set to `true` for testnets.
#### ZebecCardTAOService
To create an instance of `ZebecCardTAOService`, you need:
* **signer**: An instance of `Keyring` or `Signer`.
* **apiConfig**: Object containing `apiKey` and `encryptionKey`.
* **sdkConfig (optional)**: SDK-specific settings, such as:
* `sandbox`: Boolean, set to `true` for testnets.
#### EVM Supported Chains
| Chain | Chain ID |
| ------------------- | ------------------------------- |
| Ethereum | Mainnet (1), Sepolia (11155111) |
| Binance Smart Chain | Mainnet (56), Testnet (97) |
| Base | Mainnet (8453) |
# Recipient Fields
To create a valid `Recipient` instance, provide the following details:
* **participantId** (alphanumeric string): Unique identifier for the buyer end user. 1-20 chars.
* **firstName**, **lastName** (string): Participant's full name.
* **emailAddress** (string): Contact email. 1-80 chars
* **mobilePhone** (string): Mobile number with country code.
* **language** (string): Language code (e.g., `"en-US"`).
* **city**, **state**, **postalCode** (string): Location details.
* **countryCode** (CountryCode enum): ISO 3166-1 alpha-3 country code.
* **address1** (string): Street address. (max 50 chars)
---
[Next Page](https://docs.zebec.io/llms-full.txt/1)
# Responses
The `purchaseCard` method returns three responses:
1. **depositResponse**: Transaction response for token deposit.
2. **buyCardResponse**: Transaction response for card purchase. (EVM only)
3. **apiResponse**: API response from Zebec's backend with additional transaction metadata.
# Environment Variables
* **API\_KEY**: Your Zebec API Key.
* **ENCRYPTION\_KEY**: Your Zebec encryption key for secure data handling.
# Supported Countries
| Country | Code |
| -------------------------------- | ---- |
| Algeria | DZA |
| Angola | AGO |
| Argentina | ARG |
| Australia | AUS |
| Austria | AUT |
| Belgium | BEL |
| Bolivia (Plurinational State of) | BOL |
| Brazil | BRA |
| Cameroon | CMR |
| Canada | CAN |
| Chile | CHL |
| Costa Rica | CRI |
| Cyprus | CYP |
| Czechia | CZE |
| Denmark | DNK |
| Ecuador | ECU |
| Egypt | EGY |
| El Salvador | SLV |
| Estonia | EST |
| Finland | FIN |
| France | FRA |
| Georgia | GEO |
| Germany | DEU |
| Ghana | GHA |
| Greece | GRC |
| Guatemala | GTM |
| Honduras | HND |
| Hungary | HUN |
| Iceland | ISL |
| Ireland | IRL |
| Italy | ITA |
| Jamaica | JAM |
| Japan | JPN |
| Jordan | JOR |
| Kenya | KEN |
| Korea, Republic of Korea | KOR |
| Kuwait | KWT |
| Lithuania | LTU |
| Luxembourg | LUX |
| Malawi | MWI |
| Malaysia | MYS |
| Malta | MLT |
| Mexico | MEX |
| Morocco | MAR |
| Mozambique | MOZ |
| Nepal | NPL |
| Netherlands | NLD |
| New Zealand | NZL |
| Nigeria | NGA |
| Norway | NOR |
| Oman | OMN |
| Pakistan | PAK |
| Papua New Guinea | PNG |
| Paraguay | PRY |
| Peru | PER |
| Philippines | PHL |
| Poland | POL |
| Portugal | PRT |
| Puerto Rico | PRI |
| Qatar | QAT |
| Romania | ROU |
| Saudi Arabia | SAU |
| Singapore | SGP |
| Slovakia | SVK |
| Slovenia | SVN |
| Spain | ESP |
| Sweden | SWE |
| Taiwan | TWN |
| Thailand | THA |
| Trinidad and Tobago | TTO |
| Tunisia | TUN |
| Turkey | TUR |
| United Kingdom | GBR |
| United States | USA |
| Uruguay | URY |
| Vanuatu | VUT |
| Zambia | ZMB |
# Zebec Bridge
Development kit for x-chain Zebec Bridge Contracts
This is the sdk for zebec bridge contracts which lets use bridge your transactions from multiple chains to solana via wormhole to utilize the features of zebec streaming and multisig streaming protocol in solana.
This sdk is built on top of [wormhole-sdk](https://www.npmjs.com/package/@certusone/wormhole-sdk) package and requires you to install it to utilize this sdk. Since zebec protocol utilizes the solana's fast transaction processing ability for its streaming services, despite of the transaction payload being originated from various foreign chains that zebec supports or will be supporting in future, the target of the payload for execution will always be in solana.
| Folders/Files | Description |
| -------------- | --------------------------------------------------------------------------------------------------- |
| evm | Contains evm contract and client factory classes needed to interact with Zebec Evm bridge contract |
| solana | Contains solana contract factory and client classes to interact with Zebec Solana bridge contract |
| portalTransfer | Contains all the functions for operation of token transfer from EVM chains to Solana and vice versa |
| utils | Contains all the necessary constants, and other utility functions. |
| parser | Contains necessary methods and types for parsing wormhole vaa payloads. |
This sdk provides you apis to interact with Zebec's stream services such as:
* Vault interaction: Deposit and Withdraw
* Streaming actions: Initialize, update, pause, resume, cancel, withdrawStreamed
as well as some other apis such as:
* RegisterUser
* CreateTokenAccounts
* GetTargetAsset
* TransferEvm
* GetIsRelayCompleted
# Creating clients
Currently, there are two clients:
1. Evm Bridge client
2. Solana Bridge client
Evm bridge client instances can be created in following way:
```typescript
const sourceChain = CHAIN_ID_BSC;
const targetChain = CHAIN_ID_SOLANA;
const ethClient = new ZebecEthBridgeClient(
BSC_ZEBEC_BRIDGE_ADDRESS,
signer,
sourceChain
);
```
Solana bridge client instances can be created in following way:
```typescript
const connection = new Connection(SOLANA_HOST);
const wallet = new anchor.Wallet(keypair);
const achorProvider = new anchor.AnchorProvider(
connection,
wallet,
AnchorProvider.defaultOptions()
);
const wormholeConfig = {
coreBridgeProgram: new PublicKey(SOL_BRIDGE_ADDRESS),
tokenBridgeProgram: new PublicKey(SOL_TOKEN_BRIDGE_ADDRESS),
};
const FEE_RECEIVER = "<solana pubkey>"
const zebecInstructions = new ZebecInstructions(anchorProvider);
const bridgeProgram = ZebecSolBridge__factory.getProgram(new PublicKey(SOL_ZEBEC_BRIDGE_ADDRESS), anchorProvider);
const bridgeTransactions = new ZebecBridgeTransactions(bridgeProgram);
const solanaClient = new ZebecSolBridgeClient(
anchorProvider,
bridgeProgram,
bridgeTransactions,
zebecInstructions,
wormholeConfig,
FEE_RECEIVER,
);
```
Here, `FEE_RECEIVER` is solana pubkey address which receives fee for provider streaming services. If you're using this sdk for providing stream service to other, then you must have initialzed before streaming.
# Initialize Proxy Account
Every foreign chain user requires a solana account for their identity in solana chain to make any transactions. The associated token accounts that the user possesses in solana is also created from this account. The zebec bridge program in solana provides creating a solana account for users in foreign chain user for each chain that acts as a proxy account for evm user and signs transactions on behalf of user's demand in invoking solana programs. Proxy account is derived from seed of the 32 bytes wormhole's standard address buffer derived from their native address and wormhole chain id.
*Seed: \[32 byte sender address, chain id]*
*Program Id: Solana Zebec bridge program Id*
A solana proxy account can be created in following way.
```typescript
const newUser = "<evm address>"
// sends payload to initialize solana accounts
const receipt = await ethClient.registerUser(newUser);
```
After this, Zebec evm bridge contract sends payloads to wormhole which will be signed by the validators called guardians which when signed by minimum required number of validators can be retrieved from wormhole rpc hosts. This should be posted in solana wormhole bridge. The signed vaa can be obtained in following way.
```typescript
const sequence = parseSequenceFromLogEth(receipt, getBridgeAddressForChain(sourceChain));
const zebecEmitterAddress = getEmitterAddressEth(BSC_ZEBEC_BRIDGE_ADDRESS);
const { vaaBytes } = await getSignedVAAWithRetry(
WORMHOLE_RPC_HOSTS,
sourceChain,
zebecEmitterAddress,
sequence
);
```
Zebec provides specialized zebec bridge spy relayer for relaying the message passed by its evm bridge contracts to solana bridge program as well however, that doesn't imply that they cannot be relayed manually. The sdk provides required client interfaces, factory classes and utililities for this. The spy relayer uses same sdk to relay the incomming payloads to solana.
```typescript
const payerAddress = wallet.publicKey.toString();
const bridgeAddress = getBridgeAddressForChain(targetChain);
const vaaBuf = Buffer.from(vaaBytes);
setDefaultWasm("node"); // use bundler for browser
// posting vaa in solana
await postVaaSolanaWithRetry(
connection,
wallet.signTransaction,
bridgeAddress,
payerAddress,
vaaBuf,
MAX_VAA_UPLOAD_RETRIES_SOLANA,
);
```
Then you parse payload information from vaa and call method in Zebec Solana bridge program to initialize account.
```typescript
const parsedVaa = parse_vaa(vaaBytes);
const parsedPayload = parseZebecPayload(Buffer.from(parsedVaa.payload));
// this initializes proxy account
const result = await solanaClient.initiallizePda(
vaaBytes,
<InitializeProxyAccountPayload>parsedPayload
);
```
One thing you might have noticed is the payload is type cast in method params. This is because the `parseZebecPayload` function return a union type `ParsedZebecPayload` type which is a union type for all parsed payload types.
# Initialize Token Account
Creating a token account from Solana Proxy Account for each x-chain users.
For any tokens to migrate from evm chain to solana chain a user must have an existing token account in solana chain. This is becuase, every token has separate associated token account and a user may own many token account. An associated token account address is derived from the token mint address, user wallet address and token program id.
You can create a token account in following way.
```typescript
const owner = "0x91845D534744Ef350695CF98393d23acC9639024";
const tokenAddress = "<evm token address>"
const sourceChain = CHAIN_ID_BSC;
const targetChain = CHAIN_ID_SOLANA;
const tokenAddrInSolana = await getTargetAsset(
signer,
tokenAddress,
sourceChain,
targetChain
)
const proxyAccount = ZebecSolBridgeClient.getProxyUserKey(
tryNativeToUint8Array(owner, sourceChain),
sourceChain,
SOL_ZEBEC_BRIDGE_ADDRESS
);
const ethClient = new ZebecEthBridgeClient(BSC_ZEBEC_BRIDGE_ADDRESS, signer, sourceChain);
const receipt = await ethClient.createTokenAccount(owner, tokenAddrInSolana);
```
Now you can find signed Vaa bytes of your payload sent to wormhole.
```typescript
const sequence = parseSequenceFromLogEth(receipt, getBridgeAddressForChain(sourceChain));
const zebecEmitterAddress = getEmitterAddressEth(BSC_ZEBEC_BRIDGE_ADDRESS);
const { vaaBytes } = await getSignedVAAWithRetry(WORMHOLE_RPC_HOSTS, sourceChain, zebecEmitterAddress, sequence);
```
Rest of work is performed by the relayer. If you want to manually relay the payloads to solana, you can accomplish it in following way.
```typescript
const payerAddress = wallet.publicKey.toString();
const bridgeAddress = getBridgeAddressForChain(targetChain);
const vaaBuf = Buffer.from(vaaBytes);
setDefaultWasm("node"); // use bundler for browser
// posting vaa in solana
await postVaaSolanaWithRetry(
connection,
wallet.signTransaction,
bridgeAddress,
payerAddress,
vaaBuf,
MAX_VAA_UPLOAD_RETRIES_SOLANA,
);
```
Then you parse payload information from vaa and call method in Zebec Solana bridge program to initialize token account in solana.
```typescript
const { parse_vaa } = await importCoreWasm();
const parsedVaa = parse_vaa(vaaBytes);
const parsedPayload = parseZebecPayload(Buffer.from(parsedVaa.payload));
const result = await solanaClient.initiallizePdaTokenAccount(
vaaBytes,
<InitializeTokenAccountPayload>parsedPayload,
);
```
# Deposit
To deposit token native to source evm chain, you must be attest the token beforehand in solana chain. If the token is already an attested token imported from solana to the source evm chain, you can proceed for depositing to zebec vault.
Deposit process in completed in two step:
1. [Token Transfer](/zebec-network-archive/zebec-network-archive/bridge-sdk/deposit/token-transfer): Migrate evm token to Proxy Account in solana through token portal
2. [Deposit](/zebec-network-archive/zebec-network-archive/bridge-sdk/deposit/deposit-to-zebec): Deposit token from Proxy Account to Zebec Vault.
# Token Transfer
Migrate token via Token Portal from evm to solana
Token transfer can be done in following way.
```typescript
const depositor = signer.address;
const sourceChain = CHAIN_ID_BSC;
const depositorAddrInSolana = ZebecSolBridgeClient.getProxyUserKey(
depositor,
sourceChain,
SOL_ZEBEC_BRIDGE_ADDRESS
);
const tokenAddress = "<evm address of token>";
// use ui value for amount
const amount = "1";
// this may vary depending upon the token being transfered
const relayFee = "0.1";
// transfer from evm to solana
const transferReceipt = await transferEvm(
signer,
tokenAddress,
sourceChain,
amount,
targetChain,
proxyAccount.toString(),
relayFee,
);
```
*Note: The solana proxy address that is derived from the user's evm address must be initialized beforehand. To initialize see initialize proxy account part.*
After this, it takes some time for your token to reach solana chain. During this time, a vaa is created which is then verified and signed by the wormhole validators called guardians. You can obtain the vaa in following way.
```typescript
const sequence = parseSequenceFromLogEth(transferReceipt, getBridgeAddressForChain(sourceChain));
const transferEmitterAddress = getEmitterAddressEth(getTokenBridgeAddressForChain(sourceChain));
const { vaaBytes } = await getSignedVAAWithRetry(
WORMHOLE_RPC_HOSTS,
sourceChain,
transferEmitterAddress,
sequence,
);
```
The vaa then can be used to posted on solana chain and redeem the token transferred. Zebec provides specialized token bridge relayer supporting certain tokens as well that automatically relay your tokens using small amount of fee so this part may be *optional*. However, if you want to manually relay you can accomplish it in following way.
```typescript
const payerAddress = wallet.publicKey.toString();
const bridgeAddress = getBridgeAddressForChain(targetChain);
const vaaBuf = Buffer.from(vaaBytes);
setDefaultWasm("node"); // use bundler for browser
// posting vaa in solana
await postVaaSolanaWithRetry(
connection,
wallet.signTransaction,
bridgeAddress,
payerAddress,
vaaBuf,
MAX_VAA_UPLOAD_RETRIES_SOLANA,
);
// redeeming token
const unsignedTransaction = await redeemOnSolana(
connection,
bridgeAddress,
tokenBridgeAddress,
payerAddress,
vaaBytes,
);
unsignedTransaction.partialSign(keypair);
const txid = await connection.sendRawTransaction(unsignedTransaction.serialize());
await connection.confirmTransaction(txid);
```
If vaa is supposed to be relayed and token is redeemed by a relayer, in that case you can check and wait for token to be redeemed by the relayer in following way.
```typescript
let success = false;
let retry = 0;
while(!success) {
success = await getIsTransferCompletedSolana(tokenBridgeAddress, transferVaa, connection);
await new Promise((r) => setTimeout(r, 5000));
if (retry > 13) throw new Error("Transfer failed!");
retry++;
}
console.log("transfer successful");
```
# Deposit to Zebec
Deposit from solana account to zebec vaults
Depositing token from proxy accounts to zebec vault can be done in following way. You first need to pass message to solana chain using evm bridge contracts for deposit tokens.
```typescript
const tokenAddress = "0xea0Fbe70025ac7Cab1F5f06976dA76Ac85C045d9";
const tokenAddressSol = await getTargetAsset(signer, tokenAddress, sourceChain, targetChain);
// deposit same amoutn of token that you migrated from bsc to solana
const receipt = await ethClient.deposit(amount, depositor, tokenAddrInSolana);
```
Then the vaa can be obtained after this and which'll be posted in solana chain.
```typescript
const sequence = parseSequenceFromLogEth(receipt, getBridgeAddressForChain(sourceChain));
const emitterAddress = getEmitterAddressEth(BSC_ZEBEC_BRIDGE_ADDRESS);
const { vaaBytes } = await getSignedVAAWithRetry(
WORMHOLE_RPC_HOSTS,
sourceChain,
emitterAddress,
sequence,
);
```
Now post this signed vaa to wormhole solana core bridge program, parse the payloads from vaa and send the parsed data to solana zebec bridge program. Posting vaa and calling solana bridge (also called as proxy) program. This is optional because it's handled by zebec's specialized relayer.
```typescript
const payerAddress = wallet.publicKey.toString();
const bridgeAddress = getBridgeAddressForChain(targetChain);
const vaaBuf = Buffer.from(vaaBytes);
setDefaultWasm("node"); // use bundler for browser
// posting vaa in solana
await postVaaSolanaWithRetry(
connection,
wallet.signTransaction,
bridgeAddress,
payerAddress,
vaaBuf,
MAX_VAA_UPLOAD_RETRIES_SOLANA,
);
const { parse_vaa } = await importCoreWasm();
const parsedVaa = await parse_vaa(vaaBytes);
const payload = parseZebecPayload(Buffer.from(parsedVaa.payload));
const depositResult = await solClient.depositToken(depositVaa, depositPayload);
```
# Withdraw Deposited
withdraw assets deposited by sender
If you want to withdraw your assets you deposited. You have to keep in mind that your assets is being transferred from one chain to another. Withdraw comprises of two parts:
1. [Withdraw](/zebec-network-archive/zebec-network-archive/bridge-sdk/withdraw-deposited/withdraw-from-zebec) from Zebec accounts (vaults) to your solana wallet account (proxy accounts).
2. [Token migration](/zebec-network-archive/zebec-network-archive/bridge-sdk/withdraw-deposited/token-transfer) from Solana to EVM chain.
# Withdraw From Zebec
Withdraw from vault to proxy accounts
At first, you have to withdraw your assets from the Zebec. To withdraw you can do as follows.
```typescript
const withdrawer = signer.address
const withdrawerAddrIn프로젝트로 돌아가기