@celo/contractkit"wrappers/Exchange"ExchangeWrapper

Class: ExchangeWrapper

Contract that allows to exchange StableToken for GoldToken and vice versa using a Constant Product Market Maker Model

Hierarchy

ExchangeWrapper

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

+ new ExchangeWrapper(kit: ContractKit, contract: Exchange): ExchangeWrapper

Inherited from BaseWrapper.constructor

Defined in packages/sdk/contractkit/src/wrappers/BaseWrapper.ts:30

Parameters:

Name Type
kit ContractKit
contract Exchange

Returns: ExchangeWrapper

Properties

buy

buy: function = proxySend( this.kit, this.contract.methods.buy, tupleParser(valueToString, valueToString, identity) )

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:112

Sells sellAmount of sellToken in exchange for at least minBuyAmount of buyToken Requires the sellAmount to have been approved to the exchange

param The amount of sellToken the user is selling to the exchange

param The maximum amount of sellToken the user will sell for this transaction to succeed

param true if gold is the buy token

returns The amount of buyToken that was transfered

Type declaration:

▸ (buyAmount: BigNumber.Value, maxSellAmount: BigNumber.Value, buyGold: boolean): CeloTransactionObject‹string›

Parameters:

Name Type
buyAmount BigNumber.Value
maxSellAmount BigNumber.Value
buyGold boolean

buyDollar

buyDollar: (Anonymous function) = this.buyStable

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:226

Deprecated alias of buyStable. Buy amount of the stable token in exchange for at least minGoldAmount of CELO Requires the amount to have been approved to the exchange

deprecated use buyStable instead

param The amount of the stable token the user is selling to the exchange

param The maximum amount of CELO the user will pay for this transaction to succeed


eventTypes

eventTypes: EventsEnum‹T› = Object.keys(this.events).reduce>( (acc, key) => ({ ...acc, [key]: key }), {} as any )

Inherited from BaseWrapper.eventTypes

Defined in packages/sdk/contractkit/src/wrappers/BaseWrapper.ts:61


events

events: Exchange["events"] = this.contract.events

Inherited from BaseWrapper.events

Defined in packages/sdk/contractkit/src/wrappers/BaseWrapper.ts:59


exchange

exchange: function = proxySend( this.kit, this.contract.methods.exchange, tupleParser(valueToString, valueToString, identity) )

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:74

DEPRECATED: use function sell Exchanges sellAmount of sellToken in exchange for at least minBuyAmount of buyToken Requires the sellAmount to have been approved to the exchange

param The amount of sellToken the user is selling to the exchange

param The minimum amount of buyToken the user has to receive for this transaction to succeed

param true if gold is the sell token

returns The amount of buyToken that was transfered

Type declaration:

▸ (sellAmount: BigNumber.Value, minBuyAmount: BigNumber.Value, sellGold: boolean): CeloTransactionObject‹string›

Parameters:

Name Type
sellAmount BigNumber.Value
minBuyAmount BigNumber.Value
sellGold boolean

getBuyAndSellBuckets

getBuyAndSellBuckets: function = proxyCall( this.contract.methods.getBuyAndSellBuckets, undefined, (callRes: { 0: string; 1: string }) => [valueToBigNumber(callRes[0]), valueToBigNumber(callRes[1])] as [BigNumber, BigNumber] )

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:159

Returns the buy token and sell token bucket sizes, in order. The ratio of the two also represents the exchange rate between the two.

param true if gold is the sell token

returns

Type declaration:

▸ (sellGold: boolean): Promise‹[BigNumber, BigNumber]›

Parameters:

Name Type
sellGold boolean

getUsdExchangeRate

getUsdExchangeRate: (Anonymous function) = this.getStableExchangeRate

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:336

Deprecated alias of getStableExchangeRate. Returns the exchange rate for the stable token estimated at the buyAmount

deprecated Use getStableExchangeRate instead

param The amount of the stable token in wei to estimate the exchange rate at

returns The exchange rate (number of CELO received for one stable token)


lastBucketUpdate

lastBucketUpdate: function = proxyCall(this.contract.methods.lastBucketUpdate, undefined, valueToBigNumber)

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:62

Query last bucket update

returns The timestamp of the last time exchange buckets were updated.

Type declaration:

▸ (...args: InputArgs): Promise‹Output›

Parameters:

Name Type
...args InputArgs

methodIds

methodIds: Record‹keyof T["methods"], string› = Object.keys(this.contract.methods).reduce, string>>( (acc, method: Methods) => { const methodABI = this.contract.options.jsonInterface.find((item) => item.name === method)

  acc[method] =
    methodABI === undefined
      ? '0x'
      : this.kit.connection.getAbiCoder().encodeFunctionSignature(methodABI)

  return acc
},
{} as any

)

Inherited from BaseWrapper.methodIds

Defined in packages/sdk/contractkit/src/wrappers/BaseWrapper.ts:66


minimumReports

minimumReports: function = proxyCall(this.contract.methods.minimumReports, undefined, valueToBigNumber)

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:57

Query minimum reports parameter

returns The minimum number of fresh reports that need to be present in the oracle to update buckets commit to the gold bucket

Type declaration:

▸ (...args: InputArgs): Promise‹Output›

Parameters:

Name Type
...args InputArgs

quoteUsdBuy

quoteUsdBuy: (Anonymous function) = this.quoteStableBuy

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:267

Deprecated alias of quoteStableBuy. Returns the amount of CELO a user would need to exchange to receive buyAmount of the stable token.

deprecated Use quoteStableBuy instead

param The amount of the stable token the user would like to purchase.

returns The corresponding CELO amount.


quoteUsdSell

quoteUsdSell: (Anonymous function) = this.quoteStableSell

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:242

Deprecated alias of quoteStableSell. Returns the amount of CELO a user would get for sellAmount of the stable token

deprecated Use quoteStableSell instead

param The amount of the stable token the user is selling to the exchange

returns The corresponding CELO amount.


reserveFraction

reserveFraction: function = proxyCall( this.contract.methods.reserveFraction, undefined, fixidityValueToBigNumber )

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:40

Query reserve fraction parameter

returns Current fraction to commit to the gold bucket

Type declaration:

▸ (...args: InputArgs): Promise‹Output›

Parameters:

Name Type
...args InputArgs

sell

sell: function = proxySend( this.kit, this.contract.methods.sell, tupleParser(valueToString, valueToString, identity) )

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:93

Sells sellAmount of sellToken in exchange for at least minBuyAmount of buyToken Requires the sellAmount to have been approved to the exchange

param The amount of sellToken the user is selling to the exchange

param The minimum amount of buyToken the user has to receive for this transaction to succeed

param true if gold is the sell token

returns The amount of buyToken that was transfered

Type declaration:

▸ (sellAmount: BigNumber.Value, minBuyAmount: BigNumber.Value, sellGold: boolean): CeloTransactionObject‹string›

Parameters:

Name Type
sellAmount BigNumber.Value
minBuyAmount BigNumber.Value
sellGold boolean

sellDollar

sellDollar: (Anonymous function) = this.sellStable

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:195

Deprecated alias of sellStable. Sell amount of the stable token in exchange for at least minGoldAmount of CELO Requires the amount to have been approved to the exchange

deprecated use sellStable instead

param The amount of the stable token the user is selling to the exchange

param The minimum amount of CELO the user has to receive for this transaction to succeed


spread

spread: function = proxyCall(this.contract.methods.spread, undefined, fixidityValueToBigNumber)

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:35

Query spread parameter

returns Current spread charged on exchanges

Type declaration:

▸ (...args: InputArgs): Promise‹Output›

Parameters:

Name Type
...args InputArgs

updateFrequency

updateFrequency: function = proxyCall(this.contract.methods.updateFrequency, undefined, valueToBigNumber)

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:50

Query update frequency parameter

returns The time period that needs to elapse between bucket updates

Type declaration:

▸ (...args: InputArgs): Promise‹Output›

Parameters:

Name Type
...args InputArgs

Accessors

address

get address(): string

Inherited from BaseWrapper.address

Defined in packages/sdk/contractkit/src/wrappers/BaseWrapper.ts:35

Contract address

Returns: string

Methods

buyGold

buyGold(amount: BigNumber.Value, maxStableAmount: BigNumber.Value): CeloTransactionObject‹string›

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:204

Buy amount of CELO in exchange for at most maxStableAmount of the stable token Requires the amount to have been approved to the exchange

Parameters:

Name Type Description
amount BigNumber.Value The amount of CELO the user is buying from the exchange
maxStableAmount BigNumber.Value The maximum amount of the stable token the user will pay for this transaction to succeed

Returns: CeloTransactionObject‹string›


buyStable

buyStable(amount: BigNumber.Value, maxGoldAmount: BigNumber.Value): CeloTransactionObject‹string›

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:214

Buy amount of the stable token in exchange for at least minGoldAmount of CELO Requires the amount to have been approved to the exchange

Parameters:

Name Type Description
amount BigNumber.Value The amount of the stable token the user is selling to the exchange
maxGoldAmount BigNumber.Value The maximum amount of CELO the user will pay for this transaction to succeed

Returns: CeloTransactionObject‹string›


getBuyTokenAmount

getBuyTokenAmount(sellAmount: BigNumber.Value, sellGold: boolean): Promise‹BigNumber›

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:128

dev Returns the amount of buyToken a user would get for sellAmount of sellToken

Parameters:

Name Type Description
sellAmount BigNumber.Value The amount of sellToken the user is selling to the exchange
sellGold boolean true if gold is the sell token

Returns: Promise‹BigNumber›

The corresponding buyToken amount.


getConfig

getConfig(): Promise‹ExchangeConfig

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:281

dev Returns the current configuration of the exchange contract

Returns: Promise‹ExchangeConfig

ExchangeConfig object


getExchangeRate

getExchangeRate(buyAmount: BigNumber.Value, sellGold: boolean): Promise‹BigNumber›

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:317

Returns the exchange rate estimated at buyAmount.

Parameters:

Name Type Description
buyAmount BigNumber.Value The amount of buyToken in wei to estimate the exchange rate at
sellGold boolean true if gold is the sell token

Returns: Promise‹BigNumber›

The exchange rate (number of sellTokens received for one buyToken).


getGoldExchangeRate

getGoldExchangeRate(buyAmount: BigNumber.Value): Promise‹BigNumber‹››

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:343

Returns the exchange rate for CELO estimated at the buyAmount

Parameters:

Name Type Description
buyAmount BigNumber.Value The amount of CELO in wei to estimate the exchange rate at

Returns: Promise‹BigNumber‹››

The exchange rate (number of stable tokens received for one CELO)


getHumanReadableConfig

getHumanReadableConfig(): Promise‹object›

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:302

dev Returns human readable configuration of the exchange contract

Returns: Promise‹object›

ExchangeConfig object


getPastEvents

getPastEvents(event: Events‹Exchange›, options: PastEventOptions): Promise‹EventLog[]›

Inherited from BaseWrapper.getPastEvents

Defined in packages/sdk/contractkit/src/wrappers/BaseWrapper.ts:55

Contract getPastEvents

Parameters:

Name Type
event Events‹Exchange›
options PastEventOptions

Returns: Promise‹EventLog[]›


getSellTokenAmount

getSellTokenAmount(buyAmount: BigNumber.Value, sellGold: boolean): Promise‹BigNumber›

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:144

Returns the amount of sellToken a user would need to exchange to receive buyAmount of buyToken.

Parameters:

Name Type Description
buyAmount BigNumber.Value The amount of buyToken the user would like to purchase.
sellGold boolean true if gold is the sell token

Returns: Promise‹BigNumber›

The corresponding sellToken amount.


getStableExchangeRate

getStableExchangeRate(buyAmount: BigNumber.Value): Promise‹BigNumber‹››

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:327

Returns the exchange rate for the stable token estimated at the buyAmount

Parameters:

Name Type Description
buyAmount BigNumber.Value The amount of the stable token in wei to estimate the exchange rate at

Returns: Promise‹BigNumber‹››

The exchange rate (number of CELO received for one stable token)


quoteGoldBuy

quoteGoldBuy(buyAmount: BigNumber.Value): Promise‹BigNumber‹››

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:275

Returns the amount of the stable token a user would need to exchange to receive buyAmount of CELO.

Parameters:

Name Type Description
buyAmount BigNumber.Value The amount of CELO the user would like to purchase.

Returns: Promise‹BigNumber‹››

The corresponding stable token amount.


quoteGoldSell

quoteGoldSell(sellAmount: BigNumber.Value): Promise‹BigNumber‹››

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:249

Returns the amount of the stable token a user would get for sellAmount of CELO

Parameters:

Name Type Description
sellAmount BigNumber.Value The amount of CELO the user is selling to the exchange

Returns: Promise‹BigNumber‹››

The corresponding stable token amount.


quoteStableBuy

quoteStableBuy(buyAmount: BigNumber.Value): Promise‹BigNumber‹››

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:257

Returns the amount of CELO a user would need to exchange to receive buyAmount of the stable token.

Parameters:

Name Type Description
buyAmount BigNumber.Value The amount of the stable token the user would like to purchase.

Returns: Promise‹BigNumber‹››

The corresponding CELO amount.


quoteStableSell

quoteStableSell(sellAmount: BigNumber.Value): Promise‹BigNumber‹››

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:233

Returns the amount of CELO a user would get for sellAmount of the stable token

Parameters:

Name Type Description
sellAmount BigNumber.Value The amount of the stable token the user is selling to the exchange

Returns: Promise‹BigNumber‹››

The corresponding CELO amount.


sellGold

sellGold(amount: BigNumber.Value, minStableAmount: BigNumber.Value): CeloTransactionObject‹string›

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:173

Sell amount of CELO in exchange for at least minStableAmount of the stable token Requires the amount to have been approved to the exchange

Parameters:

Name Type Description
amount BigNumber.Value The amount of CELO the user is selling to the exchange
minStableAmount BigNumber.Value The minimum amount of the stable token the user has to receive for this transaction to succeed

Returns: CeloTransactionObject‹string›


sellStable

sellStable(amount: BigNumber.Value, minGoldAmount: BigNumber.Value): CeloTransactionObject‹string›

Defined in packages/sdk/contractkit/src/wrappers/Exchange.ts:183

Sell amount of the stable token in exchange for at least minGoldAmount of CELO Requires the amount to have been approved to the exchange

Parameters:

Name Type Description
amount BigNumber.Value The amount of the stable token the user is selling to the exchange
minGoldAmount BigNumber.Value The minimum amount of CELO the user has to receive for this transaction to succeed

Returns: CeloTransactionObject‹string›


version

version(): Promise‹NonNullable‹T["methods"] extends object ? ContractVersion<> : never››

Inherited from BaseWrapper.version

Defined in packages/sdk/contractkit/src/wrappers/BaseWrapper.ts:39

Returns: Promise‹NonNullable‹T["methods"] extends object ? ContractVersion<> : never››