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

GSW-530 feat: swap router #81

Merged
merged 35 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1fa681a
fix: Collect()
r3v4s Oct 25, 2023
8bc90a6
fix: CollectProtocol
r3v4s Oct 26, 2023
dccce64
test: multi-lp prepare
r3v4s Oct 26, 2023
44ae319
fix: logic test cases
r3v4s Oct 26, 2023
799e0ce
chore: rename grc20 token `gnos` to `gns`
r3v4s Oct 27, 2023
50167d2
fix: typo
r3v4s Oct 27, 2023
f775e3f
chore: more util functinos
r3v4s Oct 27, 2023
fd1268b
feat: router now finds maximum of 3 swap paths
r3v4s Oct 27, 2023
01ac880
feat: registered interface for position
r3v4s Oct 27, 2023
574ed1c
chore
r3v4s Oct 27, 2023
fec6afe
chore: rename
r3v4s Oct 27, 2023
f177e6c
chore: fourth token to test router
r3v4s Oct 31, 2023
5912fbe
chore: increase mint amount
r3v4s Oct 31, 2023
771a0ff
feat: Dryswap return bool instead of panic
r3v4s Oct 31, 2023
2251f59
fix: use pool's token pair, not parameter
r3v4s Oct 31, 2023
231cd5f
chore
r3v4s Oct 31, 2023
f4486f8
test:
r3v4s Oct 31, 2023
d2cec36
feat: router contract - entireSwapAmount
r3v4s Oct 31, 2023
68886f1
GSW-527 feat: find best swap paths
r3v4s Nov 2, 2023
919323a
GSW-528 feat: swap multi path with multi pools
r3v4s Nov 2, 2023
8c3fcb7
chore: remove dummy testcase
r3v4s Nov 3, 2023
649da4f
GSW-528 feat: swap multi path with multi pools
r3v4s Nov 3, 2023
dae2607
GSW-547 feat: estimate & swap singlePath when amountSpecified is nega…
r3v4s Nov 3, 2023
55e3f23
GSW-548 feat: estimate & swap multiPath when amountSpecified is negative
r3v4s Nov 6, 2023
92a7ef9
feat: swap multi path with multi pools
r3v4s Nov 6, 2023
0336b8f
chore: better error handling, remove unused codes
r3v4s Nov 6, 2023
8a4592c
GSW-57 feat: implement router getter for api
r3v4s Nov 6, 2023
6e8b46a
refactor: router contract handles pool router
r3v4s Nov 6, 2023
f802161
Update router/quotation.gno
r3v4s Nov 7, 2023
cf7f56f
Update router/getter_api.gno
r3v4s Nov 7, 2023
d318425
Update router/getter_api.gno
r3v4s Nov 7, 2023
8ce5675
Update router/getter_api.gno
r3v4s Nov 7, 2023
4fbe150
Update router/find_path.gno
r3v4s Nov 7, 2023
4775243
test: more detail getter_api test condition
r3v4s Nov 7, 2023
cb16f6a
refactor: use recursive
r3v4s Nov 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions _setup/bar/bar.gno
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,17 @@ func init() {
posAddr = std.DerivePkgAddr("gno.land/r/position")
)

bar.Mint(lp01, 50000000)
bar.Mint(lp02, 50000000)
bar.Mint(lp03, 50000000)
bar.Mint(tr01, 50000000)

bar.Approve(lp01, poolAddr, 50000000)
// bar.Approve(lp02, poolAddr, 50000000)
// bar.Approve(lp03, poolAddr, 50000000)
bar.Approve(tr01, poolAddr, 50000000)

// bar.Approve(lp01, lp01, 50000000)
// bar.Approve(lp02, lp02, 50000000)
// bar.Approve(lp03, lp03, 50000000)
// bar.Approve(tr01, tr01, 50000000)

// bar.Approve(poolAddr, registryAddr, 50000000)
bar.Mint(lp01, 50000000000)
bar.Mint(lp02, 50000000000)
bar.Mint(lp03, 50000000000)
bar.Mint(tr01, 50000000000)

bar.Approve(lp01, poolAddr, 50000000000)
bar.Approve(lp02, poolAddr, 50000000000)
bar.Approve(lp03, poolAddr, 50000000000)
bar.Approve(tr01, poolAddr, 50000000000)

// bar.Approve(poolAddr, registryAddr, 50000000000)
}

// method proxies as public functions.
Expand Down Expand Up @@ -117,7 +112,7 @@ func FaucetL() {
// FIXME: add limits?
// FIXME: add payment in gnot?
caller := std.PrevRealm().Addr()
bar.Mint(caller, 50000000000) // 50_000_000_000
bar.Mint(caller, 50000000000000) // 50_000_000_000
}

// administration.
Expand Down
29 changes: 12 additions & 17 deletions _setup/baz/baz.gno
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,17 @@ func init() {
posAddr = std.DerivePkgAddr("gno.land/r/position")
)

baz.Mint(lp01, 50000000)
baz.Mint(lp02, 50000000)
baz.Mint(lp03, 50000000)
baz.Mint(tr01, 50000000)

baz.Approve(lp01, poolAddr, 50000000)
// baz.Approve(lp02, poolAddr, 50000000)
// baz.Approve(lp03, poolAddr, 50000000)
baz.Approve(tr01, poolAddr, 50000000)

// baz.Approve(lp01, lp01, 50000000)
// baz.Approve(lp02, lp02, 50000000)
// baz.Approve(lp03, lp03, 50000000)
// baz.Approve(tr01, tr01, 50000000)

// baz.Approve(posAddr, poolAddr, 50000000)
baz.Mint(lp01, 50000000000)
baz.Mint(lp02, 50000000000)
baz.Mint(lp03, 50000000000)
baz.Mint(tr01, 50000000000)

baz.Approve(lp01, poolAddr, 50000000000)
baz.Approve(lp02, poolAddr, 50000000000)
baz.Approve(lp03, poolAddr, 50000000000)
baz.Approve(tr01, poolAddr, 50000000000)

baz.Approve(posAddr, poolAddr, 50000000000)
}

// method proxies as public functions.
Expand Down Expand Up @@ -121,7 +116,7 @@ func FaucetL() {
// FIXME: add payment in gnot?
// caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
baz.Mint(caller, 50000000000) // 50_000_000_000
baz.Mint(caller, 50000000000000) // 50_000_000_000
}

// administration.
Expand Down
27 changes: 11 additions & 16 deletions _setup/foo/foo.gno
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,17 @@ func init() {
posAddr = std.DerivePkgAddr("gno.land/r/position")
)

foo.Mint(lp01, 50000000)
foo.Mint(lp02, 50000000)
foo.Mint(lp03, 50000000)
foo.Mint(tr01, 50000000)

foo.Approve(lp01, poolAddr, 50000000)
// foo.Approve(lp02, poolAddr, 50000000)
// foo.Approve(lp03, poolAddr, 50000000)
foo.Approve(tr01, poolAddr, 50000000)

// foo.Approve(lp01, lp01, 50000000)
// foo.Approve(lp02, lp02, 50000000)
// foo.Approve(lp03, lp03, 50000000)
// foo.Approve(tr01, tr01, 50000000)

// foo.Approve(posAddr, poolAddr, 50000000)
foo.Mint(lp01, 50000000000)
foo.Mint(lp02, 50000000000)
foo.Mint(lp03, 50000000000)
foo.Mint(tr01, 50000000000)

foo.Approve(lp01, poolAddr, 50000000000)
foo.Approve(lp02, poolAddr, 50000000000)
foo.Approve(lp03, poolAddr, 50000000000)
foo.Approve(tr01, poolAddr, 50000000000)

// foo.Approve(posAddr, poolAddr, 50000000000)
}

// method proxies as public functions.
Expand Down
1 change: 0 additions & 1 deletion _setup/gnos/gno.mod

This file was deleted.

1 change: 1 addition & 0 deletions _setup/gns/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/gns
36 changes: 18 additions & 18 deletions _setup/gnos/gnos.gno → _setup/gns/gns.gno
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gnos
package gns

import (
"std"
Expand All @@ -10,21 +10,21 @@ import (
)

var (
gnos *grc20.AdminToken
gns *grc20.AdminToken
admin []string
)

func init() {
gnos = grc20.NewAdminToken("Gnoswap Shares", "GNOS", 4)
gns = grc20.NewAdminToken("Gnoswap Shares", "GNOS", 4)

// for swap > staker
var (
stakerAddr = std.Address("g13h5s9utqcwg3a655njen0p89txusjpfrs3vxp8")
poolAddr = std.Address("g1ee305k8yk0pjz443xpwtqdyep522f9g5r7d63w")
ira = std.Address("g1d9exzh6lta047h6lta047h6lta047h6l8ylkpa") // INTERNAL REWARD ACCOUNT
)
gnos.Mint(ira, 50000000000) // 50_000_000_000
gnos.Approve(ira, stakerAddr, 50000000000) // owner, spender, amount
gns.Mint(ira, 50000000000) // 50_000_000_000
gns.Approve(ira, stakerAddr, 50000000000) // owner, spender, amount

admin = append(admin, string(stakerAddr))
}
Expand All @@ -34,23 +34,23 @@ func init() {

// getters.
func GetGRC20() *grc20.AdminToken {
return gnos
return gns
}

func TotalSupply() uint64 {
return gnos.TotalSupply()
return gns.TotalSupply()
}

func BalanceOf(owner users.AddressOrName) uint64 {
balance, err := gnos.BalanceOf(owner.Resolve())
balance, err := gns.BalanceOf(owner.Resolve())
if err != nil {
panic(err)
}
return balance
}

func Allowance(owner, spender users.AddressOrName) uint64 {
allowance, err := gnos.Allowance(owner.Resolve(), spender.Resolve())
allowance, err := gns.Allowance(owner.Resolve(), spender.Resolve())
if err != nil {
panic(err)
}
Expand All @@ -62,7 +62,7 @@ func Allowance(owner, spender users.AddressOrName) uint64 {
func Transfer(to users.AddressOrName, amount uint64) {
// caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
err := gnos.Transfer(caller, to.Resolve(), amount)
err := gns.Transfer(caller, to.Resolve(), amount)
if err != nil {
panic(err.Error())
}
Expand All @@ -71,7 +71,7 @@ func Transfer(to users.AddressOrName, amount uint64) {
func Approve(spender users.AddressOrName, amount uint64) {
// caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
err := gnos.Approve(caller, spender.Resolve(), amount)
err := gns.Approve(caller, spender.Resolve(), amount)
if err != nil {
panic(err.Error())
}
Expand All @@ -80,7 +80,7 @@ func Approve(spender users.AddressOrName, amount uint64) {
func TransferFrom(from, to users.AddressOrName, amount uint64) {
// caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
err := gnos.TransferFrom(caller, from.Resolve(), to.Resolve(), amount)
err := gns.TransferFrom(caller, from.Resolve(), to.Resolve(), amount)
if err != nil {
panic(err.Error())
}
Expand All @@ -93,15 +93,15 @@ func Faucet() {
// FIXME: add payment in gnot?
// caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
gnos.Mint(caller, 1000*10000) // 1k
gns.Mint(caller, 1000*10000) // 1k
}

func FaucetL() {
// FIXME: add limits?
// FIXME: add payment in gnot?
// caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
gnos.Mint(caller, 50000000000) // 50_000_000_000
gns.Mint(caller, 50000000000) // 50_000_000_000
}

// administration.
Expand All @@ -110,14 +110,14 @@ func Mint(address users.AddressOrName, amount uint64) {
// caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
assertIsAdmin(caller)
gnos.Mint(address.Resolve(), amount)
gns.Mint(address.Resolve(), amount)
}

func Burn(address users.AddressOrName, amount uint64) {
// caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
assertIsAdmin(caller)
gnos.Burn(address.Resolve(), amount)
gns.Burn(address.Resolve(), amount)
}

func AppendAdmin(address users.AddressOrName) {
Expand Down Expand Up @@ -148,10 +148,10 @@ func Render(path string) string {

switch {
case path == "":
return gnos.RenderHome()
return gns.RenderHome()
case c == 2 && parts[0] == "balance":
owner := users.AddressOrName(parts[1])
balance, _ := gnos.BalanceOf(owner.Resolve())
balance, _ := gns.BalanceOf(owner.Resolve())
return ufmt.Sprintf("%d\n", balance)
default:
return "404\n"
Expand Down
2 changes: 1 addition & 1 deletion _setup/gnos/gnos_test.gno → _setup/gns/gns_test.gno
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gnos
package gns

import (
"std"
Expand Down
1 change: 1 addition & 0 deletions _setup/qux/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/qux
Loading