Including Weekly Dev: 24/05/21–30/05/21

May Summary

Let's take a moment to take stock, before looking forward to June.

By now you will likely be aware that 2 May 2021 saw an exploit of Spartan Protocol’s smart contracts, resulting in more than USD $40M of $SPARTA, $BNB and other assets being drained from several V1 Liquidity Pools (based on token prices at the time of exploit).

With the help of the community and the gracious assistance of PeckShield, the transactions were fully analysed, and the issue identified.

Since then, several changes have been deployed to mainnet, both related and unrelated to the exploit.

Once a full review and analysis of the specific calcLiquidityShare vector was completed, an update to the Utils contract was deployed to ensure that repeated attempts using the same vector were no longer possible.

A new base token (SPARTA V2) has been deployed onto mainnet with the primary goals of:

  • Removing components related to the original ‘Burn For SPARTA’ TGE
  • Create a deflationary aspect to assist with inflation resulting from the FallenSpartans compensation
  • Upgrade the transfer() function to ensure best practice (removal of tx.origin)

At the same time, a dApp was built to assist the Shield Wall in performing the below tasks

  • Upgrading their V1 Tokens to V2 Tokens
  • Claiming the SPARTA side of the liquidity that was drained in the May 2 exploit (FallenSpartans compensation)

In the weeks following the release of the upgrade DApp, there have been over 850 users upgrade to version 2 of the Token Contract.

BSCSCAN.com Screenshot 23 MAY 21: https://bscscan.com/token/0x3910db0600ea925f63c36ddb1351ab6e2c6eb102

SpartanProtocol dApp V2 has also been deployed to #BinanceSmartChain testnet for the wider community to test and log issues on GitHub. The more community members that get involved the better opportunity for improvement.

The feeBurn function for SPARTA transfers has been in effect since the token upgrade with the goal of causing deflationary pressure over time; with minimal transactions so far we have already seen over 9,000 SPARTA burnt permanently from the supply.

Looking Forwards to June

The community contributors that have been working on the UI integration have not been impacted and have, in fact, doubled their efforts - so June will likely see a reduction in activity in the Spartan Protocol dApp, and a greater focus on the critical CodeArena reviews & community testing tasks.

Spartan Protocol GitBook

This will be an ongoing focus for the wider community to contribute towards.

Spartan Socials

And perhaps most impressively, considering the circumstances, it is important to mention the support seen between community members, who took the time to support each other during and after the exploit.

Spartan Socials — Twitter

Top Impressions:

Top Engagement:

Top Community Mention:

SpartanSocials — Medium

SpartanSocials — Telegram

Contributor’s Focus

Phase 1 — SPARTA V2 (Token) — Completed!

Affected Users Snapshot

Deploy New $SPARTA v2 BASE Token

Deploy Upgrade dApp

  • The above-weighted claims (from the snapshot) are plugged in for affected users to claim via the bridge dApp
  • Implement deflationary mechanisms (burn SPARTA on each transfer)

Phase 2 — Spartan Protocol V2 (Protocol) — In Progress

SPARTA V2 (Token)

  • Work with DEXs & aggregators to ensure the new SPARTA token address is added to their lists (1inch, PancakeSwap etc)
  • Work with token-tracking information websites to ensure new token info is added and verified (BSCscan, CoinGecko, CoinMarketCap etc)

SpartanContracts

  • Put the contracts through a code review process on CodeArena
  • Continue the code review process within the community

DAppV2

  • Add in simple DAO for Bond+Mint allocations
  • Test bond process from start to finish via UI (propose bond allocation, vote it in, finalise it, and then proceed to bond assets and test the weight from that in the DAOVault, and other proposals)

Community Forum

  • Setup categories & get the community contributing good questions about DAO proposals & mechanics of AMMs so that they can be padded out into longer-form go-to guides to post in the channels

Phase 3 — Deploy & Iterate

  • Enable Bond allocations to replenish TVL into the V2 pools
  • Deploy Lending to testnet
  • March onwards with our original goals of building the decentralised, yield-generating, solo staking, leveraged synthetics and derivatives + lending protocol on Binance Smart Chain

GitHub Activity — SpartanContractsV2

contracts/BondVault.sol

  • Bond members weight now contributes to DAO proposals (greater advantage to future Bond+Mint participants)
  • Bond member’s locked LPs now contribute to their DAOVault harvest weight (greater advantage to future Bond+Mint participants)
  • Pending SPARTA that has been unlocked and allocated via DAO proposals will now be held in the DAO address
  • The Bond/BondVault refactor along with the SPARTAv2 token has resulted in the removal of a Bond contract; only BondVault (Simplified; reduce code scope)

contracts/Dao.sol

  • depositLPForMember() — msg.sender changed to member arg. Added in BondVault weight to the check for the forced harvest()
  • calcReward() — added BondVault member’s weight to the DaoVault calculation (and vice versa with the totalWeight used in the calc)
  • Added functions to handle the Bond-SPARTA allocations held in the DAO contract. ie. burn remaining allocation, or move it to a new DAO address
  • Added functions to handle Bond-enabled assets. ie. List or de-list bond assets.
  • Added functions to handle end-users performing bond actions. ie. bond, calc and claim
  • Reverted SPARTA Bond-allocation back to 2.5M per proposal
  • Removed some additional redundant functions
  • countVotes() — now uses BondVault member weight included in the calculation of weight in a proposal. Same with all the functions that check for minority and majority and quorum etc

contracts/DaoVault.sol

  • Change public functions to external

contracts/Pool.sol

  • Emit a MintSynth event
  • burnSynth() — use UTILS.calSwapOutput() instead of UTILS.calcSwapValueInBase()
  • Emit a BurnSynth even

contracts/Reserve.sol

contracts/Router.sol

  • zapLiquidity() — added in the transfer ‘fromToken’ for the swap
  • addLiquiditySingleForMember() — allow asym-add directly into the pools (reduce gas for user)
  • removeLiquidityExact() — handle BNB/WBNB
  • swapSynthToAsset() — handle feeBurn

contracts/Synth.sol

  • mintSynth() — refactor; amount handed in as arg
  • realise() — added ‘realise’ function to cut back the LP unit collateral if it is greater than the debt (funnel more revenue into the underlying pools for LPers to benefit instead of the un-owned Synth contract)

contracts/Utils.sol

  • Cleanup case and brackets in calcLiquidityUnitsAsym()

contracts/synthFactory.sol

contracts/synthVault.sol

  • harvestSingle() — _member changed to msg.sender throughout & the new SYNTH.realise() function is now called on harvest
  • withdraw() — _member changes to msg.sender throughout

Automated Tests

  • Tests added to suite new functions added (ie. SYNTH.realise())

GitHub Activity — SpartanDAppV2

ABIs

  • Update all the testnet ABIs to match the newly testnet-deployed V2 contracts

src/Providers.js

  • Removed utilsMath store; it’s not something we need
  • Removed utilsPricing store; it’s not something we need

src/components/AssetSelect/AssetSelect.js

  • Add getWalletType() to detect if a wallet is MetaMask or TrustWallet to handle their unique watchAsset functions (Show MetaMask or TrustWallet icons next to assets dynamically to add the custom tokens to your respective wallet, previously this always just showed MetaMask)
  • Icon has also been fixed in regards to the added watchAsset. Metamask will now use the relevant tokenIcon from the DApp
TrustWallet vs MetaMask dynamic watchAsset() handling

src/components/DataManager/DataManager.js

  • Removed actions that are no longer relevant (ie. getCuratedPools and getBondSpartaRemaining)
  • Added action: bondGlobalDetails() to the initial global loop

src/components/Share/SharePool.js

  • Update the usage of window.location
  • Handle the asset type being shown (icon/symbol shown based on selected assetType)

src/components/Supply/Supply.js

  • Burn & bond distribution numbers added as const for the tokenomics calculations (these numbers are now final and won't change, so do not need to dynamically call for updated counts)
  • Bond added as a const too for v2. However, we can convert this into a simple call to count the completed DAO proposals of type: “GET_SPARTA” and multiply it by 2.5M *OR* call all ‘Transfer’ events from BASE to DAO who’s amount is 2.5M SPARTA.
  • Hide distro-breakdown on Testnet; only really relevant on Mainnet
  • Show V1 circulating vs V2 to visually show the progress of the token upgrade

src/components/WalletSelect/WalletSelect.js

  • checkWallets() — refactor out repeat checks and set fallback to ‘injected’ for mobile wallets so we get better UX for mobile users (try to auto-connect first-time mobile users to the wallet that is relevant to their browser)
  • Add getWalletType() to detect if a wallet is MetaMask or TrustWallet to handle their unique watchAsset functions (Show MetaMask or TrustWallet icons next to assets dynamically to add the custom tokens to your respective wallet, previously this always just showed MetaMask)
  • Icon has also been fixed in regards to the added watchAsset. Metamask will now use the relevant tokenIcon from the DApp
  • Detect if the device is Apple/iOS; if so; show a button before connecting the wallet to enable the in-app DApp browser in TrustWallet
  • WalletConnect disabled throughout; not a priority right now but will revisit later and get the bridge setup so wallets can ‘write’ instead of only ‘read’

src/store/bond/actions.js

  • Any DAO contract functions relevant to BOND will be located here even though they are in a different contract; makes sense from a common-sense perspective; but not from a search-via-contract perspective. The former seems to suit most contributors

src/store/dao/actions.js

src/store/pool/actions.js

  • Remove all curatedArray refs (handled in poolDetails now without needing an extra loop)

src/store/router/actions.js

  • Updated functions to suit changes in the new V2 contracts

src/store/sparta/actions.js

  • Culled some old functions

src/store/synth/actions.js

src/store/utils/actions.js

  • Also deleted the utilsMath & utilsPricing stores

src/utils/web3.js

  • Handle SPARTAv2 throughout as the base asset

src/utils/web3Contracts.js

src/utils/web3Utils.js

src/views/pages/Pools/LiqAdd.js

  • Handle feeBurn in all transaction estimates/outputs

src/views/pages/Pools/LiqBond.js

  • Handle feeBurn in all transaction estimates/outputs (needs further testing for 100% accuracy this week)

src/views/pages/Pools/LiqRemove.js

  • Handle feeBurn in all transaction estimates/outputs (needs further testing for 100% accuracy this week)
  • Added approval component for LPs now that they require approval

src/views/pages/Pools/Overview.js

src/views/pages/Swap/Swap.js

  • Handle feeBurn in all transaction estimates/outputs (needs further testing for 100% accuracy this week)
  • Large refactor especially with synth handling
  • Handle params for ‘assetType’
  • Made variables in some sections more human-readable
  • Added approval component for LPs and Synths now that they require approval

src/views/pages/Synths/Overview.js

  • Handle SPARTAv2 throughout as the base asset
  • Handle feeBurn in all transaction estimates/outputs (continued testing is taking place)
  • Added approval component for synths now that they require approval
  • Refactor calculations for outputs and each step between
  • Renamed some variables to be more human-readable

src/views/pages/Upgrade/Upgrade.js

src/views/pages/Vault/Components/DaoDepositModal.js

  • Added approval component for LPs now that they require approval

src/views/pages/Vault/Components/SynthDepositModal.js

  • Added approval component for synths now that they require approval

src/views/pages/Vault/DaoVault.js

src/views/pages/Vault/SynthVaultItem.js

  • Add in synthVault deposit modal

Deleted Throughout

GitHub Activity — SpartanSite

Styles

  • Adjusted margins and padding throughout

Footer

index.html

Project Information

Official Links

Community Contribution

Recently, community members have been graciously funnelling in to contribute to explainer articles, ideas and even $SPARTA donations to support the growth of the platform.

Engage with the community and contributors

Community Bounty Wallet

Incentivized liquidity and synthetic asset generation for Binance Smart Chain. https://SpartanProtocol.org