@0xknwn/starknet-test-helpers / SwapRouter
Class: SwapRouter
Defined in: sdks/__tests__/helpers/src/swap_router.ts:56
Represents a Swap contract.
Extends
Contract
Indexable
[key
: string
]: any
Constructors
new SwapRouter()
new SwapRouter(
address
,account
):SwapRouter
Defined in: sdks/__tests__/helpers/src/swap_router.ts:62
Creates an instance of the Counter contract.
Parameters
address
string
The address of the contract.
account
Account
The account used to interact with the contract.
Returns
Overrides
Contract.constructor
Properties
abi
abi:
Abi
Defined in: node_modules/starknet/dist/index.d.ts:4722
Inherited from
Contract.abi
address
address:
string
Defined in: node_modules/starknet/dist/index.d.ts:4723
Inherited from
Contract.address
callStatic
readonly
callStatic:object
Defined in: node_modules/starknet/dist/index.d.ts:4733
Index Signature
[name
: string
]: AsyncContractFunction
<any
>
Inherited from
Contract.callStatic
deployTransactionHash?
optional
deployTransactionHash:string
Defined in: node_modules/starknet/dist/index.d.ts:4725
Inherited from
Contract.deployTransactionHash
estimateFee
readonly
estimateFee:object
Defined in: node_modules/starknet/dist/index.d.ts:4739
Index Signature
[name
: string
]: ContractFunction
Inherited from
Contract.estimateFee
events
protected
readonly
events:AbiEvents
Defined in: node_modules/starknet/dist/index.d.ts:4729
Inherited from
Contract.events
functions
readonly
functions:object
Defined in: node_modules/starknet/dist/index.d.ts:4730
Index Signature
[name
: string
]: AsyncContractFunction
<any
>
Inherited from
Contract.functions
populateTransaction
readonly
populateTransaction:object
Defined in: node_modules/starknet/dist/index.d.ts:4736
Index Signature
[name
: string
]: ContractFunction
Inherited from
Contract.populateTransaction
providerOrAccount
providerOrAccount:
ProviderInterface
|AccountInterface
Defined in: node_modules/starknet/dist/index.d.ts:4724
Inherited from
Contract.providerOrAccount
structs
protected
readonly
structs:object
Defined in: node_modules/starknet/dist/index.d.ts:4726
Index Signature
[name
: string
]: AbiStruct
Inherited from
Contract.structs
Methods
attach()
attach(
address
):void
Defined in: node_modules/starknet/dist/index.d.ts:4752
Saves the address of the contract deployed on network that will be used for interaction
Parameters
address
string
address of the contract
Returns
void
Inherited from
Contract.attach
call()
call(
method
,args
?,options
?):Promise
<Result
>
Defined in: node_modules/starknet/dist/index.d.ts:4755
Calls a method on a contract
Parameters
method
string
name of the method
args?
ArgsOrCalldata
Array of the arguments for the call
options?
CallOptions
optional blockIdentifier
Returns
Promise
<Result
>
Result of the call as an array with key value pars
Inherited from
Contract.call
connect()
connect(
providerOrAccount
):void
Defined in: node_modules/starknet/dist/index.d.ts:4753
Attaches to new Provider or Account
Parameters
providerOrAccount
new Provider or Account to attach to
ProviderInterface
| AccountInterface
Returns
void
Inherited from
Contract.connect
deployed()
deployed():
Promise
<Contract
>
Defined in: node_modules/starknet/dist/index.d.ts:4754
Resolves when contract is deployed on the network or when no deployment transaction is found
Returns
Promise
<Contract
>
Promise that resolves when contract is deployed on the network or when no deployment transaction is found
Throws
When deployment fails
Inherited from
Contract.deployed
estimate()
estimate(
method
,args
?):Promise
<EstimateFeeResponse
>
Defined in: node_modules/starknet/dist/index.d.ts:4757
Estimates a method on a contract
Parameters
method
string
name of the method
args?
ArgsOrCalldata
Array of the arguments for the call or Calldata
Returns
Promise
<EstimateFeeResponse
>
Inherited from
Contract.estimate
faucet()
faucet(
amount
):Promise
<GetTransactionReceiptResponse
>
Defined in: sdks/__tests__/helpers/src/swap_router.ts:71
Sends a request to the faucet to receive a specified amount of Token A.
Parameters
amount
Uint256
The amount of tokens to request from the faucet.
Returns
Promise
<GetTransactionReceiptResponse
>
A promise that resolves to the transaction receipt once the transfer is complete.
get_conversion_rate()
get_conversion_rate():
Promise
<bigint
>
Defined in: sdks/__tests__/helpers/src/swap_router.ts:115
Retrieves the conversion rate.
Returns
Promise
<bigint
>
A promise that resolves to a bigint representing the conversion rate.
getVersion()
getVersion():
Promise
<ContractVersion
>
Defined in: node_modules/starknet/dist/index.d.ts:4761
Retrieves the version of the contract (cairo version & compiler version)
Returns
Promise
<ContractVersion
>
Inherited from
Contract.getVersion
invoke()
invoke(
method
,args
?,options
?):Promise
<{transaction_hash
:string
; }>
Defined in: node_modules/starknet/dist/index.d.ts:4756
Invokes a method on a contract
Parameters
method
string
name of the method
args?
ArgsOrCalldata
Array of the arguments for the invoke or Calldata
options?
InvokeOptions
Returns
Promise
<{ transaction_hash
: string
; }>
Add Transaction Response
Inherited from
Contract.invoke
isCairo1()
isCairo1():
boolean
Defined in: node_modules/starknet/dist/index.d.ts:4760
tells if the contract comes from a Cairo 1 contract
Returns
boolean
TRUE if the contract comes from a Cairo1 contract
Example
const isCairo1: boolean = myContract.isCairo1();
Inherited from
Contract.isCairo1
parseEvents()
parseEvents(
receipt
):ParsedEvents
Defined in: node_modules/starknet/dist/index.d.ts:4759
Parse contract events of a GetTransactionReceiptResponse received from waitForTransaction. Based on contract's abi
Parameters
receipt
GetTransactionReceiptResponse
transaction receipt
Returns
ParsedEvents
Events parsed
Inherited from
Contract.parseEvents
populate()
populate(
method
,args
?):Call
Defined in: node_modules/starknet/dist/index.d.ts:4758
Calls a method on a contract
Parameters
method
string
name of the method
args?
RawArgs
Array of the arguments for the call or Calldata
Returns
Call
Invocation object
Inherited from
Contract.populate
set_conversion_rate()
set_conversion_rate(
rate
):Promise
<GetTransactionReceiptResponse
>
Defined in: sdks/__tests__/helpers/src/swap_router.ts:102
Sets the conversion rate for the swap router.
Parameters
rate
string
The conversion rate to be set.
Returns
Promise
<GetTransactionReceiptResponse
>
A promise that resolves to the transaction receipt once the conversion rate is set.
set_tokens()
set_tokens(
tokenAAddress
,tokenBAddress
):Promise
<GetTransactionReceiptResponse
>
Defined in: sdks/__tests__/helpers/src/swap_router.ts:87
Sets the token addresses for tokenA and tokenB.
Parameters
tokenAAddress
string
The address of tokenA.
tokenBAddress
string
The address of tokenB.
Returns
Promise
<GetTransactionReceiptResponse
>
A promise that resolves to the transaction receipt once the transaction is confirmed.
swap()
swap(
tokenAAddress
,amount
):Promise
<GetTransactionReceiptResponse
>
Defined in: sdks/__tests__/helpers/src/swap_router.ts:125
Swaps a specified amount of a token for another token.
Parameters
tokenAAddress
string
The address of the token to be swapped.
amount
Uint256
The amount of the token to be swapped.
Returns
Promise
<GetTransactionReceiptResponse
>
A promise that resolves to the transaction receipt once the swap is completed.
swap_maximum_at()
swap_maximum_at(
tokenAAddress
,rate
,amount
):Promise
<GetTransactionReceiptResponse
>
Defined in: sdks/__tests__/helpers/src/swap_router.ts:178
Swaps the maximum amount of tokens at a given rate.
Parameters
tokenAAddress
string
The address of the token A.
rate
string
The rate at which to swap the tokens.
amount
Uint256
The amount of tokens to swap.
Returns
Promise
<GetTransactionReceiptResponse
>
A promise that resolves to the transaction receipt of the swap.
swap_minimum_at()
swap_minimum_at(
tokenAAddress
,rate
,amount
):Promise
<GetTransactionReceiptResponse
>
Defined in: sdks/__tests__/helpers/src/swap_router.ts:152
Executes a swap with a minimum rate and amount.
Parameters
tokenAAddress
string
The address of the token A.
rate
string
The rate of the swap.
amount
Uint256
The amount to swap.
Returns
Promise
<GetTransactionReceiptResponse
>
A promise that resolves to the transaction receipt of the swap.
typedv2()
typedv2<
TAbi
>(tAbi
):TypedContractV2
<TAbi
>
Defined in: node_modules/starknet/dist/index.d.ts:4762
Returns a typed instance of ContractV2 based on the supplied ABI.
Type Parameters
• TAbi extends Abi
Parameters
tAbi
TAbi
The ABI (Abstract Binary Interface) of the ContractV2.
Returns
TypedContractV2
<TAbi
>
- A typed instance of ContractV2.
Inherited from
Contract.typedv2