@allianceblock/abridge-sdk

1.2.5 • Public • Published

RouterSDK

constructor

Initializes the RouterSDK

constructor(signerOrProvider, optionalParams)
- signerOrProvider - JsonRpcSigner (userWallet) | JsonRpcProvider
- optionalParams:
    - routerABI: RouterContractABI 
    - erc20ABI: ERC20Permit 
    - routerAddress: address
    - validators: array
    - threshold: number
    - validatorTargetVersion: string
    - blackListedTokens: array
      i.e. [{chainId: 1, tokenAddress: '0x123qwe'}]

setParams(optionalParams)

Checks if some of the optional parameters are given and sets them, if there is a missing optional parameter a default value is used

setValidator(url)

Set validatorUrl

getRandomProperty(obj)

This method receives an object and returns a random property from it

async send(targetChainId, tokenAddress, amount, receiver, feeTokenAddress, bridgedTokenIsNativeToken)

Send transaction. The nativeToken is retrieved and based on the chainId of the nativeToken, one of the following methods in the Router contract are called:

- lock 
- burnAndTransfer
- burn

Please Note: The feeTokenAddress needs to be passed if not native fee (ALBT/WALBT) is chosen. Please Note: If we want to bridge nativeCurrency, we need to pass bridgedTokenIsNativeToken Returns unsigned lock/burnAndTransfer/burn transaction which should be signed.

- targetChainId: string - ID of the target chain  
- tokenAddress: string - Address of the deployed token
- amount: number - Amount of token to be send
- receiver - Recipient wallet address 
- feeTokenAddress - Address of the fee token
- bridgedTokenIsNativeToken - Boolean (in case that we are bridging native currency)

async sendWithPermit(targetChainId, tokenAddress, amount, receiver, v, r, s, deadline, feeTokenAddress, bridgedTokenIsNativeToken)

Send transaction with Permit enabled. The nativeToken is retrieved and based on the chainId of the nativeToken, one of the following methods in the Router contract are called: Returns unsigned lockWithPermit/burnWithPermit transaction Please Note: The feeTokenAddress needs to be passed if not native fee (ALBT/WALBT) is chosen. Please Note: If we want to bridge nativeCurrency, we need to pass bridgedTokenIsNativeToken

- targetChainId: string - ID of the target chain  
- tokenAddress: string - Address of the deployed token
- amount: number - Amount of token to be send
- receiver - Recipient wallet address 
- v: number
- r: any
- s: string
- deadline: number - Milliseconds
- feeTokenAddress - Address of the fee token
- bridgedTokenIsNativeToken - Boolean (in case that we are bridging native currency)

v, r, s represent one signature with different formatting

async claim(transfer)

Mints wrapped token or unlocks the native one Returns unsigned claim transaction

- transfer: info needed claim the transaction

async balanceOf(tokenAddress, userAddress)

Returns the amount of token with this tokenAddress of the user ({ balance, tokenDecimals })

- tokenAddress: string - Address of the deployed token
- userAddress: string - User wallet address 

async allowance(tokenAddress, userAddress)

Returns the maximum approved amount of a token Returns ({ balance, tokenDecimals })

- tokenAddress: string - Address of the deployed token
- userAddress: string - User wallet address 

async isTokenApproved(tokenAddress, userAddress, bridgedTokenIsNativeTokenOrNonDefaultFee, threshold)

Checks if the token has been approved Returns boolean

- tokenAddress: string - Address of the deployed token
- userAddress: string - User wallet address
- bridgedTokenIsNativeTokenOrNonDefaultFee - Boolean
- (optional) threshold: number

async approve(tokenAddress, amount, bridgedTokenIsNativeTokenOrNonDefaultFee)

Approve amount of token Returns unsigned transaction

- tokenAddress: string - Address of the deployed token
- amount: number - Amount of token to be approved
- bridgedTokenIsNativeTokenOrNonDefaultFee - Boolean

async approveMaxInt(tokenAddress, bridgedTokenIsNativeTokenOrNonDefaultFee)

Calls approve with ethers.constants.MaxUint256 amount Returns unsigned transaction

- tokenAddress: string - Address of the deployed token
- bridgedTokenIsNativeTokenOrNonDefaultFee - Boolean

async getServiceFee()

Returns the amount of service fee in WEI

async getExternalFee()

Returns the amount of external fee in WEI

async getClaims(userAddress, targetChainId, page)

Returns all the transactions for userAddress held in the specified chain If page is not specified, all claims are returned. The header returns two additional params:

x-total-count: Number of total results
x-total-pages: Number of all pages
- userAddress: string - User wallet address
- targetChainId: string - ID of the target chain  
- page [optional] Get the claims per page and return the requested page

async getValidatorVersion()

Returns the version of the current validator that is attached to.

async getWrappedTokens(chainId)

Returns all the wrapped tokens from the specified chainId

- chainId: string - ID of the chain  

async isClaimed(transfer)

Returns the claimed status of the transfer

- transfer - single transfer object

async getTokenName(tokenAddress)

Returns the token name by given token address

- tokenAddress: string - Address of the deployed token

async getTokenSymbol(tokenAddress)

Returns the token symbol by given token address

- tokenAddress: string - Address of the deployed token

async getTokenDecimals(tokenAddress)

Returns the token decimals by given token address

- tokenAddress: string - Address of the deployed token

async getTokenDetails(tokenAddress)

Returns the token name, symbol and decimals by given token address

- tokenAddress: string - Address of the deployed token

async getProxyFee(tokenAddress)

Returns the fee amount for the chosen token

- tokenAddress: string - Address of the token

async getWrappedTokenDetails(nativeTokenAddress, nativeChainId)

Returns the address, name, symbol and decimals of the wrapped token

- nativeTokenAddress: string - Address of the deployed native token
- nativeChainId: string - ID of the source chain

async getNativeTokenByWrappedAddress(wrappedTokenAddress)

Returns the native token

- wrappedTokenAddress: string - Address of the deployed wrapped token

async getALBTToken()

Returns the address, name, symbol and decimals of the ALBT token used for token FEE into the different networks

fixSignatures(signatures)

Formats the given signatures and returns the fixed ones

- signatures: signature[] - Signatures list of the validators

/@allianceblock/abridge-sdk/

    Package Sidebar

    Install

    npm i @allianceblock/abridge-sdk

    Weekly Downloads

    1

    Version

    1.2.5

    License

    GPL-3.0-or-later

    Unpacked Size

    215 kB

    Total Files

    14

    Last publish

    Collaborators

    • mr_onadasky
    • jornf
    • mrsfusion
    • lopezgonzalo
    • lucas-marc
    • rafael-ab
    • jucaffet
    • jcaffet
    • defimati