The top question we get from experienced asset managers and investors is how Basket handles rebalancing. While this is possible by buying the old Basket and selling a different quantity of the new Basket, it may be expensive since the Supplier has to double up in inventory to effectuate the transfer.
Since most rebalances only change a small subset of the tokens in the basket, we should be able to do a swap via that minimizes the amount of inventory utilized by the Supplier. The challenge is in doing so efficiently, i.e. minimizing the gas cost for a rebalance, especially for Baskets with a larger number of tokens.
Summary
This introduces a BasketDelta smart contract which intermediates a rebalance from one Basket to another. Also, it introduces a PermittedDeltas whitelist to validate BasketDelta contracts so that a new rebalance function in the Basket contract can be safely called without excess looping.
The Supplier injects the new tokens into BasketDelta. After a rebalance, the Supplier gets backs the excess tokens from the old Basket.
Definitions
b[t]: token t in Basket b
b[t:q]: quantity of token t in Basket b
b0: the prior Basket token in a series
b1: the new, rebalanced Baske token in the series
d1: a BasketDelta token with the following property: for each t in b1, r1 * b0[t:q] + d1[t:q] >= b1[t:q].
r1: a fixed ratio defined in the d1 token that represents the quantity of b0 tokens exchanged for one b1 token. r1 should always be less than one, because (1 - r1) * b0 are the tokens in b0 swapped for the new ones in d1.
d1[t]: the new tokens in d1[t]
How it works
BasketDelta
A special class that faciltates rebalances of Baskets. Like Basket tokens, BasketDelta tokens can be minted. However, when a BasketDelta token is consumed in a rebalance, it is automatically debundled. May also have an escrow function.
PermittedDeltas
PermittedDeltas is a whitelist in the BasketRegistry contract that defines a permitted BasketDelta for each (b0, b1) pair. To add a d1 token to the whitelist, someone needs to call a function that checks that the d1 token is valid, i.e. the property defined in d1 holds. This function may need to conduct a few loops and thus may be expensive, but once it is called, the presence of d1 in the whitelist prevents the need for redundant looping in each rebalance.
rebalance(address b1, address d1)
A function on the Basket contract. It does the following:
Checks the PermittedDeltas whitelist to verify that address d1 exists for the (b0, b1) pair, whereb0` is the current Basket contract. If true, this means that the rebalance can be safely done in one loop.
Checks msg.sender has a non-zero balance of b0.
Checks d1 balance is sufficient.
For each token t in b1, transfer r1 * b0[t:q] to b1, and transfer 1 - r1 * b0[t:q] to the owner of d1.
Transfer the tokens in d1[t] to b1.
Mint a b1 token belonging to the caller of the rebalance function.
Motivation
The top question we get from experienced asset managers and investors is how Basket handles rebalancing. While this is possible by buying the old Basket and selling a different quantity of the new Basket, it may be expensive since the Supplier has to double up in inventory to effectuate the transfer.
Since most rebalances only change a small subset of the tokens in the basket, we should be able to do a swap via that minimizes the amount of inventory utilized by the Supplier. The challenge is in doing so efficiently, i.e. minimizing the gas cost for a rebalance, especially for Baskets with a larger number of tokens.
Summary
This introduces a
BasketDelta
smart contract which intermediates a rebalance from one Basket to another. Also, it introduces aPermittedDeltas
whitelist to validateBasketDelta
contracts so that a newrebalance
function in the Basket contract can be safely called without excess looping.The Supplier injects the new tokens into
BasketDelta
. After a rebalance, the Supplier gets backs the excess tokens from the old Basket.Definitions
b[t]
: tokent
in Basketb
b[t:q]
: quantity of tokent
in Basketb
b0
: the prior Basket token in a seriesb1
: the new, rebalanced Baske token in the seriesd1
: a BasketDelta token with the following property: for eacht
inb1
,r1 * b0[t:q]
+d1[t:q]
>=b1[t:q]
.r1
: a fixed ratio defined in thed1
token that represents the quantity ofb0
tokens exchanged for oneb1
token.r1
should always be less than one, because(1 - r1) * b0
are the tokens inb0
swapped for the new ones ind1
.d1[t]
: the new tokens ind1[t]
How it works
BasketDelta
A special class that faciltates rebalances of Baskets. Like Basket tokens, BasketDelta tokens can be minted. However, when a BasketDelta token is consumed in a rebalance, it is automatically debundled. May also have an escrow function.
PermittedDeltas
PermittedDeltas is a whitelist in the
BasketRegistry
contract that defines a permittedBasketDelta
for each (b0
,b1
) pair. To add ad1
token to the whitelist, someone needs to call a function that checks that thed1
token is valid, i.e. the property defined ind1
holds. This function may need to conduct a few loops and thus may be expensive, but once it is called, the presence ofd1
in the whitelist prevents the need for redundant looping in each rebalance.rebalance(address
b1
, addressd1
)A function on the Basket contract. It does the following:
PermittedDeltas
whitelist to verify that addressd1
exists for the (b0
, b1) pair, where
b0` is the current Basket contract. If true, this means that the rebalance can be safely done in one loop.msg.sender
has a non-zero balance ofb0
.d1
balance is sufficient.t
inb1
, transferr1 * b0[t:q]
tob1
, and transfer1 - r1 * b0[t:q]
to the owner ofd1
.d1[t]
tob1
.b1
token belonging to the caller of therebalance
function.Example
To come.