Skip to content

Commit

Permalink
Merge pull request #105 from gnoswap-labs/GSW-595-update-wugnot-comment
Browse files Browse the repository at this point in the history
GSW-595 chore: update wugnot
  • Loading branch information
notJoon authored Dec 1, 2023
2 parents b839698 + c371fd6 commit 575fe6f
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions _setup/wugnot/wugnot.gno
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// ** IMPORTANT **
/*
This realm is meant to be support swapping between GRC20 tokens and native coins.
It is not meant to be used as a standalone token.
User can not call transfer not transferFrom only gnoswap can.

All of admin related funcitons and Facuet() will be removed in the future.
*/

package wugnot

import (
Expand All @@ -14,19 +23,21 @@ import (
var (
wugnot *grc20.AdminToken
admin std.Address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5" // TODO: helper to change admin

poolAddr = std.DerivePkgAddr("gno.land/r/pool")
posAddr = std.DerivePkgAddr("gno.land/r/position")
routerAddr = std.DerivePkgAddr("gno.land/r/router")
)

func init() {
wugnot = grc20.NewAdminToken("WrappedUGNOT", "WUGNOT", 6)

// for swap
var (
lp01 = testutils.TestAddress("lp01") // Liquidity Provider 01
lp02 = testutils.TestAddress("lp02") // Liquidity Provider 02
lp03 = testutils.TestAddress("lp03") // Liquidity Provider 03
tr01 = testutils.TestAddress("tr01") // Trader 01
poolAddr = std.DerivePkgAddr("gno.land/r/pool")
posAddr = std.DerivePkgAddr("gno.land/r/position")
lp01 = testutils.TestAddress("lp01") // Liquidity Provider 01
lp02 = testutils.TestAddress("lp02") // Liquidity Provider 02
lp03 = testutils.TestAddress("lp03") // Liquidity Provider 03
tr01 = testutils.TestAddress("tr01") // Trader 01
)

wugnot.Approve(lp01, poolAddr, 50000000000)
Expand Down Expand Up @@ -124,43 +135,47 @@ func assertIsAdmin(address std.Address) {
// WRAP & UNWRAP
func Wrap(address users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
if !(caller == std.DerivePkgAddr("gno.land/r/pool") || caller == std.DerivePkgAddr("gno.land/r/position")) {
panic("only pool, position contract can wrap")
if !(caller == poolAddr || caller == posAddr || caller == routerAddr) {
panic("only pool, position, router contract can wrap")
}

wugnot.Mint(address.Resolve(), amount) // mint to user
// wugnot.Mint(std.PrevRealm().Addr(), amount) // mint to contract
}

func Unwrap(address users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
if !(caller == std.DerivePkgAddr("gno.land/r/pool") || caller == std.DerivePkgAddr("gno.land/r/position")) {
panic("only pool, position contract can unwrap")
if !(caller == poolAddr || caller == posAddr || caller == routerAddr) {
panic("only pool, position, router contract can unwrap")
}

wugnot.Burn(address.Resolve(), amount) // burn from user
// wugnot.Burn(std.PrevRealm().Addr(), amount) // burn from contract
}

func Transfer(to users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
if !(caller == poolAddr || caller == posAddr || caller == routerAddr) {
panic("only pool, position, router contract can transfer")
}
err := wugnot.Transfer(caller, to.Resolve(), amount)
if err != nil {
panic(err.Error())
}
}

func Approve(spender users.AddressOrName, amount uint64) {
func TransferFrom(from, to users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
err := wugnot.Approve(caller, spender.Resolve(), amount)
if !(caller == poolAddr || caller == posAddr || caller == routerAddr) {
panic("only pool, position, router contract can transferFrom")
}
err := wugnot.TransferFrom(caller, from.Resolve(), to.Resolve(), amount)
if err != nil {
panic(err.Error())
}
}

func TransferFrom(from, to users.AddressOrName, amount uint64) {
func Approve(spender users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
err := wugnot.TransferFrom(caller, from.Resolve(), to.Resolve(), amount)
err := wugnot.Approve(caller, spender.Resolve(), amount)
if err != nil {
panic(err.Error())
}
Expand Down

0 comments on commit 575fe6f

Please sign in to comment.