Swivel
A TypeScript wrapper for the Swivel smart contract.
Overview
The Swivel contract wrapper allows a user to sign orders; initiate, exit, and cancel orders; as well as split, combine, and redeem their tokens.
An order is a struct of the following shape:
Order
Creating a Swivel instance
The snippet below illustrates how you can create a Swivel instance and what information you need to do so.
Properties
address
Holds the current contract address used by the Swivel instance.
Signature
Getters
NAME
Allows a user to get the Swivel domain name for EIP-712 signing.
Signature
Returns
A promise that resolves with the domain name if the contract call succeeds and rejects otherwise.
VERSION
Allows a user to get the Swivel domain version for EIP-712 signing.
Signature
Returns
A promise that resolves with the domain version if the contract call succeeds and rejects otherwise.
domain
Allows a user to get the Swivel domain for EIP-712 signing.
Signature
Returns
A promise that resolves with the domain if the contract call succeeds and rejects otherwise.
marketPlace
Allows a user to get the associated MarketPlace contract address.
Signature
Returns
A promise that resolves with the MarketPlace contract's address if the contract call succeeds and rejects otherwise.
Methods
constructor
Creates an instance of the Swivel smart contract wrapper.
After creating an instance of the Swivel contract it can be used to sign offline orders, however it cannot yet interact with the deployed Swivel smart contract on chain. You need to additionally invoke the
at()
method of the Swivel instance to connect the instance with the contract on chain.
Even though chain-id and contract address are optional parameters for the Swivel constructor,
signOrder()
requires these parameters to be set. If you want to use the Swivel instance to sign offline orders, you must provide the paramaters.
Signature
Parameters
v
Vendor
A vendor instance (ethers.js or web3.js vendor) to use.
i
number
The chain-id for the deployed Swivel smart contract.
c
string
The address of the deployed Swivel smart contract.
Example
at
Connects a Swivel instance to a deployed Swivel smart contract on chain.
Signature
Parameters
a
string
The address of the deployed Swivel smart contract.
o
TxOptions
Optional transaction options to override ethers.js' default transaction options.
Returns
The connected Swivel instance.
Example
signOrder
Allows a user to sign an offline order using EIP-712.
Signature
Parameters
o
Order
An order object to sign.
Returns
A promise that resolves with the 132 byte ECDSA signature of the order.
Example
cancelled
Allows a user to check if an order was cancelled.
Signature
Parameters
k
string
The key of the order to check.
Returns
A promise that resolves with true
or false
if the contract call succeeds and rejects otherwise.
filled
Allows a user to retrieve an order's filled volume.
Signature
Parameters
k
string
The key of the order to check.
Returns
A promise that resolves with the orders filled volume if the contract call succeeds and rejects otherwise.
initiate
Allows a user to fill part or all of any number of orders by initiating a fixed-yield (zcToken) or amplified-yield (nToken) position.
Splits an array of bytes32
signatures into R,S,V, and calls the initiate method on the Swivel.sol contract.
Signature
Parameters
o
Order[]
An array of order objects to be filled.
a
uint256[]
An array of uint256
amounts. The amount filled with each o[i] order submitted.
s
string[]
An array of 132 byte ECDSA signatures associated with each o[i] order submitted.
Returns
A promise that resolves with a TxResponse
if the contract call succeeds and rejects otherwise.
Example
exit
Allows a user to fill part or all of any number of orders by exiting/selling off a zcToken or nToken position.
Splits an array of bytes32
signatures into R,S,V, and calls the exit method on the Swivel.sol contract.
Signature
Parameters
o
Order[]
An array of order objects to be filled.
a
uint256[]
An array of uint256
amounts. The amount filled with each o[i] order submitted.
s
string[]
An array of 132 byte ECDSA signatures associated with each o[i] order submitted.
Returns
A promise that resolves with a TxResponse
if the contract call succeeds and rejects otherwise.
cancel
Allows a user to cancel their order.
Splits a bytes32
signature into R,S,V, and calls the cancel method on the Swivel Brokerage contract. Can only be called by the order's maker.
Signature
Parameters
o
Order
An order object to be cancelled.
s
string
The full 132 byte ECDSA signature associated with the order.
Returns
A promise that resolves with a TxResponse
if the contract call succeeds and rejects otherwise.
splitUnderlying
Allows a user to split their underlying tokens into zcTokens and nTokens.
Signature
Parameters
u
string
The address of the underlying token contract.
m
uint256
The market's maturity.
a
uint256
The amount of underlying to split.
Returns
A promise that resolves with a TxResponse
if the contract call succeeds and rejects otherwise.
splitUnderlying
Allows a user to combine an equal amount of their zcTokens and nTokens into underlying.
Signature
Parameters
u
string
The address of the underlying token contract.
m
uint256
The market's maturity.
a
uint256
The amount of zcTokens/nTokens to combine.
Returns
A promise that resolves with a TxResponse
if the contract call succeeds and rejects otherwise.
redeemZcToken
Allows a user to redeem their zcTokens at maturity.
Signature
Parameters
u
string
The address of the underlying token contract.
m
uint256
The market's maturity.
a
uint256
The amount of zcTokens to redeem.
Returns
A promise that resolves with a TxResponse
if the contract call succeeds and rejects otherwise.
redeemZcToken
Allows a user to redeem the interest generated by their nTokens.
Signature
Parameters
u
string
The address of the underlying token contract.
m
uint256
The market's maturity.
Returns
A promise that resolves with a TxResponse
if the contract call succeeds and rejects otherwise.
Last updated