Switcheo / zilswap-sdk

Zilswap Typescript SDK
https://docs.zilswap.org
MIT License
18 stars 14 forks source link

Add ZILO functionality #18

Closed stevenkhong closed 3 years ago

stevenkhong commented 3 years ago

Add Zilo implementation which enables maintaining multiple Zilo instances at the same time.

Significant changes to original SDK:

  1. zilswap.zilliqa is now readonly instead of private readonly
  2. zilswap.callContract is now a public function
  3. zilswap.approveTokenTransferIfRequired takes in a third variable for spender contract hash
  4. zilswap.zilos added as a map of registered Zilo instances
  5. zilswap.registerZilo added as entry function to creating new Zilo instances
  6. zilswap.deregisterZilo added as exit function to tear down Zilo instances
  7. zilswap.subscribeToAppChanges updated to tear down previous subscription on entry, and subscribe to additional registered Zilo contracts.

TODOs:

  1. Documentation on Zilo class
  2. Update tests
const zilswap = new Zilswap(Network.TestNet, provider)
await zilswap.initialize()
const zilo = await zilswap.registerZilo(ZILO_ADDRESS, ziloStateObserver)

const ziloState = zilo.getZiloState()

if (ziloState.state === ILOState.Active) {
   const amount = new BigNumber(1).shiftedBy(ZIL_DECIMALS).toString(10)
   const tx = await zilo.contribute(amount)

   console.log("distribute TX sent", tx.hash)
} else {
   console.log("ZILO not yet active")
}

// removed
zilswap.deregisterZilo(ZILO_ADDRESS)