Class: Core
Core class for managing connections and intent transactions in the SDK.
This class provides methods to connect using any EVM provider, onboard users, send gasless intent transactions, and view user balances from our smart contracts.
Methods
getStakeBalance()
getStakeBalance(
chainId
,tokenAddress
,amount
,stakeProtocol
?):Promise
<false
|ReceiptTokensBalance
>
Parameters
Parameter | Type | Default value |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Returns
Promise
<false
| ReceiptTokensBalance
>
Defined in
core.ts:827
Initialize and Onboard User
connect()
connect(
signer
,env
):Promise
<OperationResult
<boolean
>>
Connects to the blockchain using the provided signer. Call the connect function to initialize the sdk environment.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
|
|
| The signer to connect with. |
|
| The environment to connect to (default is |
Returns
Promise
<OperationResult
<boolean
>>
A promise that resolves to the operation result.
Example
const sdkCore = new Core();
// you can generate your own signer using providers like Metamask, Web3Auth, etc instead of directly using private key
const signer: ethers.Signer = new ethers.Wallet(pk, provider);
const connection = sdkCore.connect(signer);
if (connection.success)
console.log("SDK initialized successfully");
else
console.log("Error in initializing sdk");
Defined in
core.ts:52
onboard()
onboard(
vmType
,token_address
?,amount
?):Promise
<OperationResult
<UserOnboardResult
>>
Onboards a user to the system based on the specified virtual machine (VM) type.
This function handles the onboarding process for both EVM and SVM environments. For EVM, it directly calls the onboarding function for EVM. For SVM, it requires a token address which will be deposited later by the user in the vault and an amount, converts the token address from hex to base58, and then calls the onboarding function for SVM.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
|
| The type of virtual machine to onboard the user to. This can be either | |
|
|
| The address of the token to be used for onboarding in SVM. This token should be used to make an initial deposit for the user as well This parameter is required if |
|
|
| The amount of tokens to be used for onboarding in SVM. This parameter is required if |
Returns
Promise
<OperationResult
<UserOnboardResult
>>
A promise that resolves to an operation result containing the onboarding result for the user, including success status and any relevant data.
Throws
Throws an error if the user address is not found, if the token address or amount is required but not provided, or if an invalid VM type is specified.
Example
const onboardResult = await sdkCore.onboard(VMType.SVM, "0xTokenAddress", 1000);
if (onboardResult.success) {
console.log(`Onboarding successful! Data: ${JSON.stringify(onboardResult.data)}`);
} else {
console.error(`Onboarding failed: ${onboardResult.error}`);
}
Defined in
core.ts:147
sendFaucetDepositRequest()
sendFaucetDepositRequest():
Promise
<any
>
Sends our faucet deposit request for the user. Currently only available for Arbitrum Sepolia. The connected user deposit address (smart account address) will be funded with testnet USDT and USDC tokens and then deposited on its behalf to the Vault on Arbitrum sepolia.
Returns
Promise
<any
>
A promise that resolves to the result of the faucet deposit request.
Defined in
core.ts:197
Price Feed
assetPricesFeed()
assetPricesFeed(
onData
):Promise
<undefined
|WebSocket
>
Subscribes to real-time asset price updates via WebSocket connection.
Parameters
Parameter | Type | Description |
---|---|---|
| ( | Callback function that will be called whenever new price data is received. The callback receives the price data as its parameter. |
Returns
Promise
<undefined
| WebSocket
>
A WebSocket client instance that can be used to close the connection when needed.
Example
const sdk = new Core();
// Subscribe to price updates
const wsClient = sdk.assetPricesFeed((priceData) => {
console.log('New price update:', priceData);
});
// To stop receiving updates later:
if (wsClient) {
wsClient.close();
}
The prices of EVM tokens are expressed in $, USDC And the prices of SVM tokens are in $ Example price feed data: For every minute interval, you will get two feeds from this function. The first response is data fetched from Jupiter for Solana ecosystem tokens and second is a list of tokens in EVM
{
prices: {
'0x069b8857feab8184fb687f634618c035dac439dc1aeb3b5598a0f00000000001': 1.000214,
'0x40968e32205218d09372d017b366fae0972a3d6c243e6b4b2d10e678f87bf6f4': 0.824362,
'0x937b4268a58d839dffa3d14554a8729c09da3217a3ca5cf993aa1c8bc5106293': 0.375308,
'0xc52c124b605922e084980ccd34a7da05be38319fa125d886d3fc30d3f01d8f34': 1.161847,
'0xdaaffb46de173f2b17c07a25f597779bf37aa39d7bbfaefc46e26bfd5b2ad9d0': 1.75391,
'0x841b27e917d53b1733a74a12586783164af5ba5c0a1b59586f7e7dc2d95ba4c7': 2.65976712,
So11111111111111111111111111111111111111112: 203.1348895
}
}
{
prices: {
'0x55cD83934d81EF36fb5e0da6C47c4A9a1DE2DF0F': 0.7878581831805177,
'0xD9ce99d10a5C175166058369E38BBFad8a11615C': 0.2372134402048717,
'0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2': 3440.321244105436,
'0xb4d99977f4a90BCbB8a86256d305F7945237Dc4a': 1,
'0xA8f9F1c3Ea7AFBb00bd06FaF1e5aE38a62B0D3dF': 99441.60709347912,
'0xA5942391C8866D3c74282Eaf7f8F06Bd882F83DA': 0.9988440760687899,
'0x77F6a7215B27688Ab4a660EDbfB1DC88aFa2Dd68': 0.6655491979869123,
'0xbc9863C01C8FFd12f4f7154FD68915faC198309D': 5.425320073169899,
'0xF86062ffd991CE1f8c5786Db3560ED0B9c920321': 0.48218508126430304
}
}
Defined in
core.ts:1085
getLatestPriceFeed()
getLatestPriceFeed():
Promise
<any
>
Retrieves the latest price feed data from the price feed service.
This function sends a GET request to the price feed API to obtain the most recent price information for various assets. It returns the data received from the API response, which typically includes price details for different tokens.
Returns
Promise
<any
>
A promise that resolves to the latest price feed data, which may include: - Prices of various tokens in the specified format. - Timestamps or other relevant metadata associated with the price data.
Throws
Throws an error if there is an issue with the API request or if the response is not successful.
Example
try {
const latestPrices = await sdkCore.getLatestPriceFeed();
console.log("Latest Price Feed:", latestPrices);
} catch (error) {
console.error("Failed to fetch latest price feed:", error);
}
Example response
const result = {
feeds: {
solana: {
prices: { Object containing price details },
source: 'jup',
timestamp: 1740186298,
supported_chains: [ Array of supported chains ]
},
ethereum: {
prices: { Object containing price details },
source: 'one_inch',
timestamp: 1740186288,
supported_chains: [ Array of supported chains ]
}
}
};
Defined in
core.ts:1237
getQuote()
getQuote(
quoteRequest
):Promise
<any
>
Retrieves a quote for a token swap via a api connection.
Parameters
Parameter | Type | Description |
---|---|---|
| The request object containing the parameters for the quote. This should include details such as the tokens involved and the amount to be swapped. |
Returns
Promise
<any
>
A promise that resolves to an object containing the quote details, including: - from_chain
: The chain from which the tokens are being sent. - to_chain
: The chain to which the tokens are being sent. - from_token
: The address of the token being sent. - to_token
: The address of the token being received. - from_amount
: The amount of the token being sent. - to_amount
: The estimated amount of the token being received. - timestamp
: The time at which the quote was generated.
Throws
Throws an error if there is an issue establishing the WebSocket connection, sending the request, or processing the response.
Example
const quoteRequest = {
from_chain: 'ethereum',
to_chain: 'ethereum',
from_token: '0xA8f9F1c3Ea7AFBb00bd06FaF1e5aE38a62B0D3dF',
to_token: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
from_amount: '1.0'
};
try {
const quote = await sdkCore.getQuote(quoteRequest);
console.log("Quote received:", quote);
} catch (error) {
console.error("Failed to fetch quote:", error);
}
// Example response
const result = {
amount: '19166468',
fee_data: {
destination_cost: 191097310629.00003,
provider_fee: {
flat_fee: 15000000,
provider: 'DeBridge',
solver_fee: 1,
variable_fee: 7999
},
source_cost: 5809201355889915
}
};
Defined in
core.ts:1171
Sending Intents
sendStakeIntent()
sendStakeIntent(
stakeAction
,amount
,tokenAddress
,stakeProtocol
,timeoutTimestampInSeconds
):Promise
<OperationResult
<String
|IntentTransactionResponse
>>
Sends a gasless Stake intent transaction to our L3.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
|
|
| Enum StakeActionEnum, Either DEPOSIT or WITHDRAW |
|
|
| Amount to deposit in a stake or withdraw |
|
|
| Token address to deposit or withdraw |
|
|
| Enum StakeProtocolEnum, either LIDO, AAVE, SOLANALST |
|
|
|
Returns
Promise
<OperationResult
<String
| IntentTransactionResponse
>>
A promise that resolves to the operation result.
Defined in
core.ts:391
sendTransactIntent()
sendTransactIntent(
tokenIn
,amountIn
,tokenOut
,amountOut
,receiverAddress
,sourceChainId
,destinationChainId
,timeoutTimestampInSeconds
?):Promise
<OperationResult
<String
|IntentTransactionResponse
>>
Sends a gasless transact intent transaction.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The input token address. |
|
| The amount of input tokens. |
|
| The output token address. |
|
| The amount of output tokens. |
|
| The address of the receiver or null. |
|
| The source chain ID. |
|
| The destination chain ID. |
|
| Optional timeout timestamp in seconds. |
Returns
Promise
<OperationResult
<String
| IntentTransactionResponse
>>
A promise that resolves to the operation result.
Examples
Transfering tokens from a source chain to a destination chain or an EOA address. Keeping source chain and destination chain different will create a Cross chain transact intent If source chain and destination chain are same, a local transfer intent will be placed and balances would be updated in the protocol.
Note: The function takes a receiver address as parameter. This parameter can be passed as a null
value too. If the receiverAddress
is null, the protocol considers this as a Swap transaction where the resulting tokens will be deposited in the destination vault, and balances will be updated corresponding to the current user's address in the protocol. If an address value is given to the receiverAddress
, the protocol will send the resulting tokens to that address, this can be an EOA or another contract.
If doing a local transfer from the vault to an EOA, and the tokenOut
doesn't exist on the destionation chain, the intent will fail.
const sdkCore = new Core();
// you can generate your own signer using providers like Metamask, Web3Auth, etc instead of directly using private key
const signer: ethers.Signer = new ethers.Wallet(pk, provider);
const connectedVault = await sdkCore.connect(signer);
const payload = await sdkCore.sendTransactIntent(
"0x750b8C791080d89e2E9d0620C4CB4982CAEf9217", // USDT on arbitrum sepolia
5000000000000000000,
"0xac8Ee2E2eFe0f8C81B2cd4ea3C2ADFE9dDf46a0B", // USDC on optimism sepolia
4000000000000000000,
0x5B5D1D5C5C5D1D5C5C5D1D5C5C5D1D5C5C5D1D5C,
421614, // source arbitrum sepolia
11155420 // destination optimism sepolia
);
Successful response
{
"operation": "Send Transact Intent",
"success": true,
"data": {
"intent_id": "1",
"status": true,
"transaction_hash": "0x..."
},
"remark": "SUCCESS"
}
Failed response
{
"operation": "Send Transact Intent",
"success": false,
"data": {
"intent_id": null,
"status": false,
"transaction_hash": "0x..."
},
"remark": "FAIL"
}
Defined in
core.ts:289
User Balance
getUserBalance()
getUserBalance(
tokenAddress
):Promise
<OperationResult
<string
>>
Retrieves the user's balance for a specific token in the user deposit smart contract.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The address of the token. |
Returns
Promise
<OperationResult
<string
>>
A promise that resolves to the user's balance.
Defined in
core.ts:810
getVaultBalance()
getVaultBalance():
Promise
<OperationResult
<VaultBalanceResponse
>>
Retrieves the user's Vault and locked balance in each of the vaults where it exists. A user has 2 balances, Vault and locked.
- Vault balance is the one present in the vaults using which the user can place further intents swap or transfer. This includes the locked balances as well.
- Locked balance are the balances out of the Vault balances, on which the intents are already placed and are in processing.
A user cannot place an intent on the balance greater than (Vault_balance - locked_balance)
Returns
Promise
<OperationResult
<VaultBalanceResponse
>>
A promise that resolves to the user's vault balance.
Example
Successful response
{
operation: 'Get Vault balance',
success: true,
data: {
vault: [
{
chainId: 4294967295,
tokenAddress: '0xc52c124b605922e084980ccd34a7da05be38319fa125d886d3fc30d3f01d8f34',
amount: 1008989000n
},
{
chainId: 421614,
tokenAddress: '0x750b8C791080d89e2E9d0620C4CB4982CAEf9217',
amount: 10282233720368546756080n
},
{
chainId: 11155420,
tokenAddress: '0xac8Ee2E2eFe0f8C81B2cd4ea3C2ADFE9dDf46a0B',
amount: 5003000000000001000000n
},
],
locked: []
},
remark: 'Operation completed successfully',
error: undefined
}
Defined in
core.ts:738
unbondingBalance()
unbondingBalance(
userAddress
):Promise
<OperationResult
<WithdrawalBalanceStatus
>>
Retrieves the unbonding balance for a user based on their address.
This function fetches the user's request IDs from the indexer API and retrieves the corresponding unbonding orders from the intent processor contract. It then checks the withdrawal status for each order and compiles the results into a structured format.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The address of the user for whom the unbonding balance is being retrieved. |
Returns
Promise
<OperationResult
<WithdrawalBalanceStatus
>>
A promise that resolves to an object containing the unbonding balance status for each protocol, including details such as token address, intent ID, order ID, amount, and whether the withdrawal is finalized or claimed.
Throws
Throws an error if there is an issue fetching the request IDs or retrieving the withdrawal status from the contract.
Example
const userAddress = "0xUserAddress"; // Replace with the actual user address
try {
const unbondingStatus = await sdkCore.unbondingBalance(userAddress);
console.log("Unbonding Balance Status:", unbondingStatus);
} catch (error) {
console.error("Failed to fetch unbonding balance:", error);
}
Response
result {
'0': [
{
token_address: '0x0000000000000000000000003f1c547b21f65e10480de3ad8e19faac46c95034',
intentId: 44n,
orderId: 50n,
amount: 998n,
isFinalized: true,
isClaimed: false
},
{
token_address: '0x0000000000000000000000003f1c547b21f65e10480de3ad8e19faac46c95034',
intentId: 45n,
orderId: 51n,
amount: 998n,
isFinalized: true,
isClaimed: false
}
]
}
Defined in
core.ts:1684
Utility
calculateFee()
calculateFee(
amount_in
):Promise
<BigInt
>
Calculates the fee amount based on the input amount and the fee basis points for processing an intent.
This function retrieves the fee basis points from the intent processor contract and calculates the fee by multiplying the input amount by the fee basis points
Parameters
Parameter | Type | Description |
---|---|---|
|
| The amount for which the fee needs to be calculated. This should be a BigNumberish type, which can represent various numeric formats. |
Returns
Promise
<BigInt
>
A promise that resolves to the calculated fee amount as a BigInt.
Throws
Throws an error if there is an issue retrieving the fee basis points or calculating the fee amount.
Example
const fee = await sdkCore.calculateFee(1000000); // Calculate fee for 1,000,000 units
console.log(`Calculated fee: ${fee}`);
Defined in
core.ts:1269
depositFundInVault()
depositFundInVault(
tokenAddress
):Promise
<OperationResult
<String
|DepositTransactionResponse
>>
Deposits funds into the vault smart contracts and the updated balance is reflected.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The address of the token to deposit. |
Returns
Promise
<OperationResult
<String
| DepositTransactionResponse
>>
A promise that resolves to the operation result.
Defined in
core.ts:494
depositFundInVaultSVM()
depositFundInVaultSVM(
token_address
,amount
):Promise
<OperationResult
<String
|DepositTransactionResponse
>>
Deposits funds into the Solana vault.
This function constructs a meta-transaction request to transfer a specified amount of tokens to the vault on the Solana blockchain.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The address of the token mint in hex on the Solana blockchain to be sent in the Vault. |
|
| The amount of tokens to deposit. |
Returns
Promise
<OperationResult
<String
| DepositTransactionResponse
>>
A promise that resolves to an operation result indicating the success or failure of the deposit operation, including the transaction hash if successful.
Throws
Throws an error if there is an issue during the transaction or if the deposit fails.
Example
const result = await sdkCore.depositFundInVaultSVM("0xTokenMintAddress", 1000);
if (result.success) {
console.log(`Deposit successful! Transaction hash: ${result.data}`);
} else {
console.error(`Deposit failed: ${result.error}`);
}
Defined in
core.ts:572
directTopupFundsInVault()
directTopupFundsInVault(
tokenType
,amount
,user_address
?,tokenAddress
?):Promise
<OperationResult
<String
>>
Directly tops up funds in the vault by depositing tokens from the user's account. Presently for EVM vaults. This function is not gasless
This function interacts with the vault contract on the current active chain to deposit a specified amount of tokens from the user's account into the vault.
Parameters
Parameter | Type | Description |
---|---|---|
| Type of token to deposit ERC20 or Native | |
|
| The amount of tokens to deposit. This should be a BigNumberish type, which can represent various numeric formats. |
|
| The address of the user to deposit tokens for in the vault. |
|
| The address of the token to be deposited into the vault. |
Returns
Promise
<OperationResult
<String
>>
A promise that resolves to an operation result indicating the success or failure of the top-up operation, including the transaction hash if successful.
Throws
Throws an error if there is an issue during the transaction or if the deposit fails.
Example
const result = await sdkCore.directTopupFundsInVault(TokenType.ERC20, 1000, "0xTokenAddress");
if (result.success) {
console.log(`Top-up successful! Transaction hash: ${result.data}`);
} else {
console.error(`Top-up failed: ${result.error}`);
}
Defined in
core.ts:640
getTransactionCost()
getTransactionCost(
from_chain
,to_chain
,from_amount
,to_amount
):Promise
<any
>
Retrieves the estimated transaction cost for executing the intent.
This function sends a request to a gas calculator API to obtain the estimated costs associated with a transaction from one blockchain to another. It returns the source, destination, and total costs in gwei.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The chain ID from which the transaction is initiated. |
|
| The chain ID to which the transaction is directed. |
|
| The amount of tokens being sent from the source chain. |
|
| The amount of tokens expected to be received on the destination chain. |
Returns
Promise
<any
>
A promise that resolves to an object containing the transaction costs, including: - source_cost
: The estimated cost of the transaction on the source chain (in gwei). - destination_cost
: The estimated cost of the transaction on the destination chain (in gwei). - total_cost
: The total estimated cost of the transaction (in gwei).
Throws
Throws an error if there is an issue with the API request or if the response is not successful.
Example
const fromChainId = 1; // Ethereum mainnet
const toChainId = 137; // Polygon mainnet
const fromAmount = "1.0"; // Amount being sent
const toAmount = "0.9"; // Amount expected to be received
try {
const transactionCost = await sdkCore.getTransactionCost(fromChainId, toChainId, fromAmount, toAmount);
console.log("Transaction Cost:", transactionCost);
} catch (error) {
console.error("Failed to fetch transaction cost:", error);
}
// Example response
const result = {
source_cost: 220.01013975, // Cost in gwei
destination_cost: 11412906.74419764, // Cost in gwei
total_cost: 11413126.75433739 // Total cost in gwei
};
Defined in
core.ts:1323
getUserDepositContractAddress()
getUserDepositContractAddress(
vmType
,token_address
?):Promise
<OperationResult
<String
|DepositContractResponse
>>
Retrieves the user's deposit contract address, also referred to as the user's smart account, which holds the user balance prior to sending them to the vault contract.
This function checks the user's address and retrieves the deposit contract address based on the specified virtual machine (VM) type. It determines whether the deposit address is deployed on-chain and returns the relevant information.
Parameters
Parameter | Type | Description |
---|---|---|
| The type of virtual machine (VM) to use (EVM or SVM). | |
|
| The address of the token (required for SVM). |
Returns
Promise
<OperationResult
<String
| DepositContractResponse
>>
A promise that resolves to an object containing the user's deposit contract address and its deployment status. The structure of the response is as follows:
- `operation`: A string indicating the operation performed.
- `success`: A boolean indicating whether the operation was successful.
- `data`: An object containing:
- `depositAddress`: The address of the user's deposit contract.
- `deployed`: A boolean flag indicating if the deposit address is deployed on-chain.
- `remark`: A string providing additional information about the operation.
Throws
Throws an error if there is an issue retrieving the user address, if the VM type is invalid, or if the required parameters are missing.
Example
const vmType = VMType.EVM; // or VMType.SVM
const tokenAddress = "0xTokenAddress"; // Required for SVM
try {
const depositInfo = await sdkCore.getUserDepositContractAddress(vmType, tokenAddress);
console.log("Deposit Contract Address Info:", depositInfo);
} catch (error) {
console.error("Failed to fetch deposit contract address:", error);
}
// Example response
const result = {
operation: "Get Deposit Contract address",
success: true,
data: {
depositAddress: "0x123...",
deployed: false
},
remark: "SUCCESS"
};
Defined in
core.ts:950