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(
userAddress
,chainId
,tokenAddress
,amount
,stakeProtocol
?):Promise
<false
|ReceiptTokensBalance
>
Parameters
Parameter | Type | Default value |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns
Promise
<false
| ReceiptTokensBalance
>
Defined in
core.ts:953
manageLaunchPadLiquidityIntent()
manageLaunchPadLiquidityIntent(
liquidity_params
):Promise
<OperationResult
<String
|IntentTransactionResponse
>>
Parameters
Parameter | Type |
---|---|
|
Returns
Promise
<OperationResult
<String
| IntentTransactionResponse
>>
Defined in
core.ts:394
sendLaunchPadSwapIntent()
sendLaunchPadSwapIntent(
tokenIn
,amountIn
,tokenOut
,amountOut
,poolAddress
,chainId
,timeoutTimestampInSeconds
?):Promise
<OperationResult
<String
|IntentTransactionResponse
>>
Parameters
Parameter | Type |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns
Promise
<OperationResult
<String
| IntentTransactionResponse
>>
Defined in
core.ts:341
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
Price Feed
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:1277
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:1211
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 | 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 |
|
| Optional, set to default to 5 mins from current timestamp |
Returns
Promise
<OperationResult
<String
| IntentTransactionResponse
>>
A promise that resolves to the operation result.
Defined in
core.ts:487
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. Defaults to 5 mins from current timestamp |
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,
11155420
);
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:266
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:936
getVaultBalance()
getVaultBalance(
user_address
?):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)
Parameters
Parameter | Type |
---|---|
|
|
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:864
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:1764
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:1309
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:591
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:669
directTopupFundsInVault()
directTopupFundsInVault(
tokenType
,amount
,user_address
?,tokenAddress
?):Promise
<OperationResult
<String
|DepositTransactionResponse
>>
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
| DepositTransactionResponse
>>
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:756
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:1076