LogoLogo
Swivel v2.0.0
Swivel v2.0.0
  • Swivel Finance Documentation
  • Litepaper
    • zcTokens
      • Exiting/Selling zcTokens
      • Secondary AMM's
    • nTokens
      • Exiting/Selling nTokens
    • AMM vs. Orderbook
  • Swivel Exchange
    • Testnet Setup
    • Exchange Functions
      • Fixed-Yield Lending
      • Purchasing nTokens
      • Selling zcTokens
      • Selling nTokens
      • Splitting/Combining Tokens
      • Redeeming Tokens/Interest
    • Maturity
    • Liquidity Incentives
    • Minimums, Rate Limits & Fees
    • Retroactive Distribution
    • How to Claim SWIV Tokens
  • Developers
    • Exchange API
      • GET
        • Orderbook
        • Get Order
        • OHCLV (Candles)
        • Get Effective Price (Preview Market Order)
        • Get Order History
        • Get Last Trade Info
        • Get Markets
      • POST
        • Order
    • Swivel.js
      • API
        • Swivel
        • MarketPlace
        • VaultTracker
    • Swivel.py
      • swivel
        • swivel.abstracts
          • swivel.abstracts.deployed
          • swivel.abstracts.market_place
          • swivel.abstracts.swivel
          • swivel.abstracts.vault_tracker
        • swivel.contracts
          • swivel.contracts.market_place
          • swivel.contracts.swivel
          • swivel.contracts.vault_tracker
        • swivel.vendors
          • swivel.vendors.signer
          • swivel.vendors.w3
    • Scrivel (Python Examples)
    • Contracts Overview
      • Contracts
        • Swivel
        • MarketPlace
        • VaultTracker
    • Ubiquitous Language V2
      • Shared Language
      • UI Language
      • Technical Language
      • Compound Language
      • Finance Terms
  • Community & Media
  • Other Resources
    • Institutions
      • Rate Profile Optimization
        • Instruments and Participants
        • Market Opportunities and Pricing
        • Counterparty Risk Management
        • Benefits and drawbacks of standardization
        • User Needs
          • Corporate Treasury and Funding
          • Institutional Investors and Asset Managers
          • Speculators and Proprietary Trading Functions
          • Brokers and Market Makers
          • Liquidity Management, Funding and Resource Management
          • Risk Management and Insurance
          • Smaller Institutions and Individuals
      • Swivel for Enterprise
        • Overview
        • How Swivel works
        • Flexible Order Book
        • Future Developments
      • Delegated Credit
        • Challenges of Delegated Credit
          • Credit Pools
          • Intermediating Trust in Credit Delegation
Powered by GitBook
On this page
  • Overview
  • Market
  • Creating a MarketPlace instance
  • Properties
  • address
  • Getters
  • admin
  • swivel
  • paused
  • Methods
  • constructor
  • at
  • markets
  • matureMarket
  • transferVaultNotional
  1. Developers
  2. Swivel.js
  3. API

MarketPlace

A TypeScript wrapper for the MarketPlace smart contract.

Overview

The MarketPlace contract wrapper allows a user to fetch market information from the MarketPlace smart contract, mature a market or transfer their vault notional.

Market information is returned in a struct of the following shape:

Market

interface Market {
    cTokenAddr: string;
    zcTokenAddr: string;
    vaultAddr: string;
    maturityRate: string;
}

Creating a MarketPlace instance

The snippet below illustrates how you can create a MarketPlace instance and what information you need to do so.

import { EthersVendor, MarketPlace } from '@swivel-finance/swivel-js';
import { ethers } from 'ethers';

// you need the address of the deployed MarketPlace contract
const marketPlaceAddress = '0x998689650D4d55822b4bDd4B7DB5F596bf6b3570';

// create an ethers provider and signer,...
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();

// ...create a Vendor for the MarketPlace contract,
const vendor = new EthersVendor(provider, signer);

// ...and use the vendor to instantiate the MarketPlace contract
const marketPlace = new MarketPlace(vendor).at(marketPlaceAddress);

Properties

address

Holds the current contract address used by the MarketPlace instance.

Signature

address?: string;

Getters

admin

Allows a user to get the admin address of this MarketPlace.

Signature

admin (): Promise<string>;

Returns

A promise that resolves with the admin address if the contract call succeeds and rejects otherwise.

swivel

Allows a user to get the Swivel contract address associated with this MarketPlace.

Signature

swivel (): Promise<string>;

Returns

A promise that resolves with the Swivel contract's address if the contract call succeeds and rejects otherwise.

paused

Allows a user to check if this MarketPlace has been paused.

Signature

paused (): Promise<boolean>;

Returns

A promise that resolves with true or false if the contract call succeeds and rejects otherwise.

Methods

constructor

Creates an instance of the MarketPlace smart contract wrapper.

Signature

constructor (v: Vendor): MarketPlace;

Parameters

Paramater
Type
Description

v

Vendor

A vendor instance (ethers.js or web3.js vendor) to use.

at

Connects a MarketPlace instance to a deployed MarketPlace smart contract on chain.

Signature

at (a: string, o?: TxOptions): MarketPlace;

Parameters

Paramater
Type
Description

a

string

The address of the deployed MarketPlace smart contract.

o

TxOptions

Optional transaction options to override ethers.js' default transaction options.

Returns

The connected MarketPlace instance.

markets

Allows a user to retrieve market information from the MarketPlace.

Signature

markets (u: string, m: uint256): Promise<Market>;

Parameters

Paramater
Type
Description

u

string

The address of the market's underlying token.

m

uint256

The market's maturity.

Returns

A promise that resolves with a Market if the contract call succeeds and rejects otherwise.

Example

Fetch the market information from one of Swivel's markets from the MarketPlace contract.

// you will need the underlying token address and maturity of a market
const underlying = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
const maturity = '1648177200';

// assuming you already created a MarketPlace instance (as shown above)
// use the underlying and maturity to retrieve the market information
const market = await marketPlace.markets(underlying, maturity);

// you now have access to the market's cTokenAddress, zcTokenAdress, 
// vaultAddress and maturityRate, e.g.:
const cTokenAddress = market.cTokenAddress;
const maturityRate = market.maturityRate;

matureMarket

Allows a user to mature a market in the MarketPlace.

Signature

matureMarket (u: string, m: uint256): Promise<TxResponse>;

Parameters

Paramater
Type
Description

u

string

The address of the market's underlying token.

m

uint256

The market's maturity.

Returns

A promise that resolves with a TxResonse if the contract call succeeds and rejects otherwise.

transferVaultNotional

Allows a user to transfer the their notional from a market in the MarketPlace.

Signature

transferVaultNotional (u: string, m: uint256, t: string, a: uint256): Promise<TxResponse>;

Parameters

Paramater
Type
Description

u

string

The address of the market's underlying token.

m

uint256

The market's maturity.

t

string

The target address to which to transfer the notional.

a

uint256

The amount of notional to transfer.

Returns

A promise that resolves with a TxResonse if the contract call succeeds and rejects otherwise.

PreviousSwivelNextVaultTracker

Last updated 2 years ago

A market is identified my its underlying token address and its maturity. You can use the to fetch the available markets (underlying/maturity pairs).

Swivel Exchange API