Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade gno version #1462

Merged
merged 11 commits into from
Dec 20, 2024
2 changes: 1 addition & 1 deletion .gnoversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9786fa366f922f04e1251ec6f1df6423b4fd2bf4
d69b5529e938f89b05b449fcd0a0bdcf7bcdc09e
6 changes: 3 additions & 3 deletions gno/r/launchpad_grc20/airdrop_grc20.gno
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func Claim(airdropID uint64, proofs []merkle.Node) {
panic("invalid proof")
}

airdrop.token.banker.Mint(caller, airdrop.amountPerAddr)
airdrop.token.privateLedger.Mint(caller, airdrop.amountPerAddr)

airdrop.alreadyClaimed.Set(caller.String(), true)
}
Expand All @@ -128,8 +128,8 @@ func (a *Airdrop) isOnGoing() bool {
func (a *Airdrop) ToJSON() *json.Node {
return json.ObjectNode("", map[string]*json.Node{
"id": json.StringNode("", ufmt.Sprintf("%d", uint64(a.id))),
"tokenName": json.StringNode("", a.token.banker.GetName()),
"tokenSymbol": json.StringNode("", a.token.banker.GetSymbol()),
"tokenName": json.StringNode("", a.token.GetName()),
"tokenSymbol": json.StringNode("", a.token.GetSymbol()),
"amountPerAddr": json.StringNode("", strconv.FormatUint(a.amountPerAddr, 10)),
"startTimestamp": json.StringNode("", strconv.FormatInt(a.startTimestamp, 10)),
"endTimestamp": json.StringNode("", strconv.FormatInt(a.endTimestamp, 10)),
Expand Down
36 changes: 18 additions & 18 deletions gno/r/launchpad_grc20/render.gno
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func renderTokenPage(res *mux.ResponseWriter, req *mux.Request) {
res.Write("## Last tokens created\n")

for _, token := range lastTokensCreated {
res.Write(ufmt.Sprintf("### Name: %s - Symbol: %s\n", token.banker.GetName(), token.banker.GetSymbol()))
res.Write(ufmt.Sprintf("#### Total Supply: %d %s\n", token.banker.TotalSupply(), token.banker.GetSymbol()))
res.Write(ufmt.Sprintf("#### Decimals: %d\n", token.banker.GetDecimals()))
res.Write(ufmt.Sprintf("### Name: %s - Symbol: %s\n", token.GetName(), token.GetSymbol()))
res.Write(ufmt.Sprintf("#### Total Supply: %d %s\n", token.TotalSupply(), token.GetSymbol()))
res.Write(ufmt.Sprintf("#### Decimals: %d\n", token.GetDecimals()))
res.Write(ufmt.Sprintf("#### Admin: %s\n\n", token.admin.Owner().String()))
res.Write(ufmt.Sprintf("> Link: [:token/%s](launchpad_grc20:token/%s)\n\n", token.banker.GetName(), token.banker.GetName()))
res.Write(ufmt.Sprintf("> Link: [:token/%s](launchpad_grc20:token/%s)\n\n", token.GetName(), token.GetName()))
}
}
renderFooter(res, "")
Expand All @@ -68,11 +68,11 @@ func renderTokenDetailPage(res *mux.ResponseWriter, req *mux.Request) {

res.Write("# 🪙 Token Details 🪙\n")

res.Write(ufmt.Sprintf("### Name: %s - Symbol: %s\n", token.banker.GetName(), token.banker.GetSymbol()))
res.Write(ufmt.Sprintf("#### Total Supply: %d %s\n", token.banker.TotalSupply(), token.banker.GetSymbol()))
res.Write(ufmt.Sprintf("#### Decimals: %d\n", token.banker.GetDecimals()))
res.Write(ufmt.Sprintf("### Name: %s - Symbol: %s\n", token.GetName(), token.GetSymbol()))
res.Write(ufmt.Sprintf("#### Total Supply: %d %s\n", token.TotalSupply(), token.GetSymbol()))
res.Write(ufmt.Sprintf("#### Decimals: %d\n", token.GetDecimals()))
res.Write(ufmt.Sprintf("#### Admin: %s\n\n", token.admin.Owner().String()))
res.Write(ufmt.Sprintf("#### Total Supply Cap (0 = unlimited): %d %s\n\n", token.totalSupplyCap, token.banker.GetSymbol()))
res.Write(ufmt.Sprintf("#### Total Supply Cap (0 = unlimited): %d %s\n\n", token.totalSupplyCap, token.GetSymbol()))

if token.allowMint {
res.Write("#### Mintable: true\n\n")
Expand Down Expand Up @@ -107,7 +107,7 @@ func renderTokenDetailPage(res *mux.ResponseWriter, req *mux.Request) {
sale := mustGetSale(uint64(id))
res.Write(ufmt.Sprintf("### Sale #%d\n", uint64(id)))
res.Write(ufmt.Sprintf("#### Price per token: %d $GNOT\n", sale.pricePerToken))
res.Write(ufmt.Sprintf("#### Limit per address: %d $%s\n", sale.limitPerAddr, token.banker.GetSymbol()))
res.Write(ufmt.Sprintf("#### Limit per address: %d $%s\n", sale.limitPerAddr, token.GetSymbol()))
res.Write(ufmt.Sprintf("#### Min goal: %d $GNOT\n", sale.minGoal))
res.Write(ufmt.Sprintf("#### Max goal: %d $GNOT\n", sale.maxGoal))
res.Write(ufmt.Sprintf("#### Already sold: %d $GNOT\n\n", sale.alreadySold))
Expand All @@ -120,10 +120,10 @@ func renderTokenBalancePage(res *mux.ResponseWriter, req *mux.Request) {
tokenName := req.GetVar("name")
address := req.GetVar("address")
token := mustGetToken(tokenName)
balance := token.banker.BalanceOf(std.Address(address))
balance := token.BalanceOf(std.Address(address))

res.Write("# 🪙 Token Balance 🪙\n")
res.Write(ufmt.Sprintf("### 📍 Address: %s\n ### 🏦 Balance: %d %s\n", address, balance, token.banker.GetSymbol()))
res.Write(ufmt.Sprintf("### 📍 Address: %s\n ### 🏦 Balance: %d %s\n", address, balance, token.GetSymbol()))
renderFooter(res, "../../../")
}

Expand All @@ -144,7 +144,7 @@ func renderAirdropPage(res *mux.ResponseWriter, req *mux.Request) {
}
airdrop := mustGetAirdrop(uint64(i))
res.Write(ufmt.Sprintf("### Airdrop #%d\n", i))
res.Write(ufmt.Sprintf("#### Token: %s\n", airdrop.token.banker.GetName()))
res.Write(ufmt.Sprintf("#### Token: %s\n", airdrop.token.GetName()))
if airdrop.isOnGoing() {
res.Write("#### Status: Ongoing\n")
} else {
Expand Down Expand Up @@ -175,7 +175,7 @@ func renderAirdropDetailPage(res *mux.ResponseWriter, req *mux.Request) {

res.Write(ufmt.Sprintf("# 🎁 Airdrop #%d Details 🎁\n", airdropID))

res.Write(ufmt.Sprintf("### Token: %s\n", airdrop.token.banker.GetName()))
res.Write(ufmt.Sprintf("### Token: %s\n", airdrop.token.GetName()))
if airdrop.isOnGoing() {
res.Write("### Status: Ongoing\n")
} else {
Expand Down Expand Up @@ -234,7 +234,7 @@ func renderSalePage(res *mux.ResponseWriter, req *mux.Request) {
}
sale := mustGetSale(uint64(i))
res.Write(ufmt.Sprintf("### Sale #%d\n", i))
res.Write(ufmt.Sprintf("#### Token: %s\n", sale.token.banker.GetName()))
res.Write(ufmt.Sprintf("#### Token: %s\n", sale.token.GetName()))
if sale.isOnGoing() {
res.Write("#### Status: Ongoing\n")
} else {
Expand All @@ -252,7 +252,7 @@ func renderSalePage(res *mux.ResponseWriter, req *mux.Request) {
res.Write("#### Sale is public\n")
}
res.Write(ufmt.Sprintf("#### Price per token: %d $GNOT\n", sale.pricePerToken))
res.Write(ufmt.Sprintf("#### Limit per address: %d $%s\n", sale.limitPerAddr, sale.token.banker.GetSymbol()))
res.Write(ufmt.Sprintf("#### Limit per address: %d $%s\n", sale.limitPerAddr, sale.token.GetSymbol()))
res.Write(ufmt.Sprintf("#### Min goal: %d $GNOT\n", sale.minGoal))
res.Write(ufmt.Sprintf("#### Max goal: %d $GNOT\n", sale.maxGoal))
res.Write(ufmt.Sprintf("#### Already sold: %d $GNOT\n\n", sale.alreadySold))
Expand All @@ -272,7 +272,7 @@ func renderSaleDetailPage(res *mux.ResponseWriter, req *mux.Request) {

res.Write(ufmt.Sprintf("# 🛒 Sale #%d Details 🛒\n", saleID))

res.Write(ufmt.Sprintf("### Token: %s\n", sale.token.banker.GetName()))
res.Write(ufmt.Sprintf("### Token: %s\n", sale.token.GetName()))
if sale.isOnGoing() {
res.Write("### Status: Ongoing\n")
} else {
Expand All @@ -290,7 +290,7 @@ func renderSaleDetailPage(res *mux.ResponseWriter, req *mux.Request) {
res.Write("### Sale is public\n")
}
res.Write(ufmt.Sprintf("### Price per token: %d $GNOT\n", sale.pricePerToken))
res.Write(ufmt.Sprintf("### Limit per address: %d $%s\n", sale.limitPerAddr, sale.token.banker.GetSymbol()))
res.Write(ufmt.Sprintf("### Limit per address: %d $%s\n", sale.limitPerAddr, sale.token.GetSymbol()))
res.Write(ufmt.Sprintf("### Min goal: %d $GNOT\n", sale.minGoal))
res.Write(ufmt.Sprintf("### Max goal: %d $GNOT\n", sale.maxGoal))
res.Write(ufmt.Sprintf("### Already sold: %d $GNOT\n\n", sale.alreadySold))
Expand All @@ -312,7 +312,7 @@ func renderSaleBalancePage(res *mux.ResponseWriter, req *mux.Request) {

res.Write("# 🛒 Sale Balance 🛒\n")
res.Write(ufmt.Sprintf("### 🛒 Sale ID: %d\n", saleID))
res.Write(ufmt.Sprintf("### 📍 Address: %s\n ### 🏦 Balance (Tokens from this sale only): %d %s\n", address, balance, sale.token.banker.GetSymbol()))
res.Write(ufmt.Sprintf("### 📍 Address: %s\n ### 🏦 Balance (Tokens from this sale only): %d %s\n", address, balance, sale.token.GetSymbol()))

res.Write("> ⚠️ *The tokens will be transfered or refunded after the sale ends depending if the sale reached the min goal or not* ⚠️\n")
renderFooter(res, "../../../")
Expand Down
10 changes: 5 additions & 5 deletions gno/r/launchpad_grc20/sale_grc20.gno
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func NewSale(tokenName, merkleRoot string, startTimestamp, endTimestamp int64, p

realmAddr := std.CurrentRealm().Addr()
if mintToken {
token.banker.Mint(realmAddr, maxGoal)
token.privateLedger.Mint(realmAddr, maxGoal)
} else {
err := token.banker.Transfer(owner, realmAddr, maxGoal)
err := token.privateLedger.Transfer(owner, realmAddr, maxGoal)
if err != nil {
panic("error while transferring tokens to the realm, " + err.Error())
}
Expand Down Expand Up @@ -152,7 +152,7 @@ func Finalize(saleID uint64) {
// If the min goal is not reached, refund all the buyers and send the tokens back to the owner
if sale.alreadySold < sale.minGoal {
sale.refundAllBuyers()
err := sale.token.banker.Transfer(realmAddr, sale.owner, sale.alreadySold)
err := sale.token.privateLedger.Transfer(realmAddr, sale.owner, sale.alreadySold)
if err != nil {
panic("error while transferring back tokens to the owner, " + err.Error())
}
Expand Down Expand Up @@ -259,7 +259,7 @@ func (s *Sale) payAllBuyers() {
s.buyers.Iterate("", "", func(key string, value interface{}) bool {
buyer := std.Address(key)
amount := value.(uint64)
err := s.token.banker.Transfer(realmAddr, buyer, amount)
err := s.token.privateLedger.Transfer(realmAddr, buyer, amount)
if err != nil {
panic("error while transferring tokens to the buyer, " + err.Error())
}
Expand All @@ -270,7 +270,7 @@ func (s *Sale) payAllBuyers() {
func (s *Sale) ToJSON() *json.Node {
return json.ObjectNode("", map[string]*json.Node{
"id": json.StringNode("", ufmt.Sprintf("%d", uint64(s.id))),
"tokenName": json.StringNode("", s.token.banker.GetName()),
"tokenName": json.StringNode("", s.token.GetName()),
"pricePerToken": json.StringNode("", strconv.FormatUint(s.pricePerToken, 10)),
"limitPerAddr": json.StringNode("", strconv.FormatUint(s.limitPerAddr, 10)),
"minGoal": json.StringNode("", strconv.FormatUint(s.minGoal, 10)),
Expand Down
39 changes: 20 additions & 19 deletions gno/r/launchpad_grc20/token_factory_grc20.gno
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
const LENGTH_LAST_TOKENS_CACHE = 10

type Token struct {
banker *grc20.Banker
privateLedger *grc20.PrivateLedger
token *grc20.Token
admin *ownable.Ownable
image string
totalSupplyCap uint64
Expand All @@ -24,7 +25,7 @@ type Token struct {
SalesIDs []seqid.ID
}

var _ grc20.Token = (*Token)(nil)
var _ grc20.Teller = (*Token)(nil)

var (
tokens *avl.Tree // name -> token
Expand Down Expand Up @@ -54,7 +55,7 @@ func NewToken(name, symbol, image string, decimals uint, initialSupply, totalSup
panic("decimals must be 18 or less")
}

banker := grc20.NewBanker(name, symbol, decimals)
token, banker := grc20.NewToken(name, symbol, decimals)

fee := initialSupply * 25 / 1000
netSupply := initialSupply - fee
Expand All @@ -66,7 +67,8 @@ func NewToken(name, symbol, image string, decimals uint, initialSupply, totalSup
}

inst := Token{
banker: banker,
token: token,
privateLedger: banker,
admin: ownable.NewWithAddress(admin),
image: image,
totalSupplyCap: totalSupplyCap,
Expand Down Expand Up @@ -99,7 +101,7 @@ func Mint(name string, to std.Address, amount uint64) {
}
}

checkErr(token.banker.Mint(to, amount))
checkErr(token.privateLedger.Mint(to, amount))
}

func Burn(name string, from std.Address, amount uint64) {
Expand All @@ -108,7 +110,7 @@ func Burn(name string, from std.Address, amount uint64) {
if !token.allowBurn {
panic("burning is not allowed")
}
checkErr(token.banker.Burn(from, amount))
checkErr(token.privateLedger.Burn(from, amount))
}

func TotalSupply(name string) uint64 {
Expand Down Expand Up @@ -141,33 +143,32 @@ func TransferFrom(name string, from, to std.Address, amount uint64) {
checkErr(token.TransferFrom(from, to, amount))
}

func (token Token) Token() grc20.Token { return token.banker.Token() }
func (token Token) GetName() string { return token.banker.GetName() }
func (token Token) GetSymbol() string { return token.banker.GetSymbol() }
func (token Token) GetDecimals() uint { return token.banker.GetDecimals() }
func (token Token) TotalSupply() uint64 { return token.Token().TotalSupply() }
func (token Token) BalanceOf(owner std.Address) uint64 { return token.Token().BalanceOf(owner) }
func (token Token) GetName() string { return token.token.GetName() }
func (token Token) GetSymbol() string { return token.token.GetSymbol() }
func (token Token) GetDecimals() uint { return token.token.GetDecimals() }
func (token Token) TotalSupply() uint64 { return token.token.TotalSupply() }
func (token Token) BalanceOf(owner std.Address) uint64 { return token.token.BalanceOf(owner) }
func (token Token) Transfer(to std.Address, amount uint64) error {
return token.Token().Transfer(to, amount)
return token.token.CallerTeller().Transfer(to, amount)
}

func (token Token) Allowance(owner, spender std.Address) uint64 {
return token.Token().Allowance(owner, spender)
return token.token.Allowance(owner, spender)
}

func (token Token) Approve(spender std.Address, amount uint64) error {
return token.Token().Approve(spender, amount)
return token.token.CallerTeller().Approve(spender, amount)
}

func (token Token) TransferFrom(from, to std.Address, amount uint64) error {
return token.Token().TransferFrom(from, to, amount)
return token.token.CallerTeller().TransferFrom(from, to, amount)
}

func (token Token) ToJSON() *json.Node {
return json.ObjectNode("", map[string]*json.Node{
"name": json.StringNode("", token.banker.GetName()),
"symbol": json.StringNode("", token.banker.GetSymbol()),
"decimals": json.StringNode("", strconv.FormatUint(uint64(token.banker.GetDecimals()), 10)),
"name": json.StringNode("", token.GetName()),
"symbol": json.StringNode("", token.GetSymbol()),
"decimals": json.StringNode("", strconv.FormatUint(uint64(token.GetDecimals()), 10)),
"admin": json.StringNode("", token.admin.Owner().String()),
"image": json.StringNode("", token.image),
"totalSupply": json.StringNode("", strconv.FormatInt(int64(token.TotalSupply()), 10)),
Expand Down
10 changes: 0 additions & 10 deletions gno/r/tori/gno.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
module gno.land/r/teritori/tori

require (
gno.land/p/demo/grc/grc20 v0.0.0-latest
gno.land/p/demo/json v0.0.0-latest
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/p/demo/users v0.0.0-latest
gno.land/p/teritori/dao_interfaces v0.0.0-latest
gno.land/p/teritori/jsonutil v0.0.0-latest
gno.land/r/demo/users v0.0.0-latest
)
23 changes: 13 additions & 10 deletions gno/r/tori/messages.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tori

import (
"std"
"strconv"
"strings"

Expand All @@ -10,17 +11,19 @@ import (
"gno.land/p/teritori/jsonutil"
)

// TODO: move this file in a generic package to administrate grc20s via daos

type ExecutableMessageMintTori struct {
dao_interfaces.ExecutableMessage

Recipient users.AddressOrName
Recipient std.Address
Amount uint64
}

var _ dao_interfaces.ExecutableMessage = &ExecutableMessageMintTori{}

func (msg ExecutableMessageMintTori) Type() string {
return "gno.land/r/teritori/tori.Mint"
return "gno.land/r/teritori/tori.MintTori"
}

func (msg *ExecutableMessageMintTori) String() string {
Expand All @@ -37,13 +40,13 @@ func (msg *ExecutableMessageMintTori) String() string {

func (msg *ExecutableMessageMintTori) FromJSON(ast *json.Node) {
obj := ast.MustObject()
msg.Recipient = jsonutil.MustAddressOrName(obj["recipient"])
msg.Recipient = jsonutil.MustAddress(obj["recipient"])
msg.Amount = jsonutil.MustUint64(obj["amount"])
}

func (msg *ExecutableMessageMintTori) ToJSON() *json.Node {
return json.ObjectNode("", map[string]*json.Node{
"recipient": jsonutil.AddressOrNameNode(msg.Recipient),
"recipient": jsonutil.AddressNode(msg.Recipient),
"amount": jsonutil.Uint64Node(msg.Amount),
})
}
Expand All @@ -60,7 +63,7 @@ func NewMintToriHandler() *MintToriHandler {

func (h *MintToriHandler) Execute(imsg dao_interfaces.ExecutableMessage) {
msg := imsg.(*ExecutableMessageMintTori)
Mint(msg.Recipient, msg.Amount)
Mint(users.AddressOrName(msg.Recipient), msg.Amount)
}

func (h MintToriHandler) Type() string {
Expand All @@ -81,7 +84,7 @@ type ExecutableMessageBurnTori struct {
var _ dao_interfaces.ExecutableMessage = &ExecutableMessageBurnTori{}

func (msg ExecutableMessageBurnTori) Type() string {
return "gno.land/r/teritori/tori.Burn"
return "gno.land/r/teritori/tori.BurnTori"
}

func (msg *ExecutableMessageBurnTori) String() string {
Expand Down Expand Up @@ -135,7 +138,7 @@ func (h *BurnToriHandler) Instantiate() dao_interfaces.ExecutableMessage {
type ExecutableMessageChangeAdmin struct {
dao_interfaces.ExecutableMessage

NewAdmin users.AddressOrName
NewAdmin std.Address
}

var _ dao_interfaces.ExecutableMessage = &ExecutableMessageChangeAdmin{}
Expand All @@ -154,12 +157,12 @@ func (msg *ExecutableMessageChangeAdmin) String() string {

func (msg *ExecutableMessageChangeAdmin) FromJSON(ast *json.Node) {
obj := ast.MustObject()
msg.NewAdmin = jsonutil.MustAddressOrName(obj["newAdmin"])
msg.NewAdmin = jsonutil.MustAddress(obj["newAdmin"])
}

func (msg *ExecutableMessageChangeAdmin) ToJSON() *json.Node {
return json.ObjectNode("", map[string]*json.Node{
"newAdmin": jsonutil.AddressOrNameNode(msg.NewAdmin),
"newAdmin": jsonutil.AddressNode(msg.NewAdmin),
})
}

Expand All @@ -175,7 +178,7 @@ func NewChangeAdminHandler() *ChangeAdminHandler {

func (h *ChangeAdminHandler) Execute(imsg dao_interfaces.ExecutableMessage) {
msg := imsg.(*ExecutableMessageChangeAdmin)
ChangeAdmin(msg.NewAdmin)
owner.TransferOwnership(msg.NewAdmin)
}

func (h ChangeAdminHandler) Type() string {
Expand Down
Loading
Loading