SIP-66: Reduce gas of SNX transfers for non-stakers

Author
StatusImplemented
TypeGovernance
ImplementorTBD
ReleaseTBD
Discussions-To<https://discordapp.com/invite/AEdUHzt>
Created2020-06-30

Simple Summary

Reduce gas of SNX transfers for non stakers.

Abstract

When an account has no debt, then reduce gas requirement of SNX transfers by not checking any stale rates.

Motivation

Prior to SIP-48, transfers of SNX would initially check for any debt and if none, skip checking the total size of the debt pool. SIP-48 inadventently undid this, meaning that SNX transfers for non-stakers caused much higher gas limits than necessary.

Checking the total size of the debt pool involves looping over every synth in Synthetix (currently 40-odd), calculating their USD value (totalSupply * rate), which is very gas intensive (~500k gas).

Specification

Overview

Add a check in Synthetix.transfer and Synthetix.transferFrom to only check Issuer.transferableSynthetixAndAnyRateIsStale when there is debt for the account.

Rationale

Put the check back into the functions that are impacted.

Note that with this change, SNX transfers will be allowed for accounts with no debt even when the SNX or any synth rates are stale.

Technical Specification

In both transfer and transferFrom, perform an initial check for SynthetixState.issuanceData() and if no debt ownership, then proceed with a regular transfer.

Test Cases

  • Given a user has SNX
    • and they have not issued any debt
      • and the rate of SNX or any synth is stale
        • when they transfer any amount of their SNX
          • it succeeds
      • and no synth rate nor SNX is stale
        • when they transfer any amount of their SNX
          • it succeeds
    • and they have issued debt
      • and the rate of SNX or any synth is stale
        • when they transfer any amount of their SNX
          • it fails
      • and no synth rate nor SNX is stale
        • when they transfer any amount of their SNX
          • it succeeds

Configurable Values (Via SCCP)

Please list all values configurable via SCCP under this implementation.

Copyright and related rights waived via CC0.