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-1014 feat: check incentive active status from chain time #208

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test.prepare:

cp -r "$(PWD)/_deploy/p/demo/gnoswap" ".test/examples/gno.land/p/demo" # gnoswap base package

cp -r "$(PWD)/_deploy/r/gnoswap" ".test/examples/gno.land/r/gnoswap" # gnoswap base realm
cp -r "$(PWD)/_deploy/r/demo/gnoswap" ".test/examples/gno.land/r/demo/gnoswap" # gnoswap base realm

cp -r "$(PWD)/gov" "$(PWD)/pool" "$(PWD)/position" "$(PWD)/router" "$(PWD)/staker" ".test/examples/gno.land/r/demo" # gnoswap realm

Expand Down
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,49 @@ To run unit tests, follow these steps:
### Set Up Gnoswap Contracts in Gno Core

1. Clone the `gnoswap` contracts repository:

```
$ cd $WORKDIR
$ git clone https://github.com/gnoswap-labs/gnoswap.git
$ cd gnoswap
```

2. Copy the `gnoswap` contracts into the Gno core:

```
# copy grc20 tokens
$ cp -R __local/grc20_tokens/* $WORK_DIR/gno/examples/gno.land/r/demo
$ cp -R _deploy/r/demo/* $WORK_DIR/gno/examples/gno.land/r/demo

# copy gnoswap base packages ( includes uint256, int256 and bit of pool calculation )
$ cp -R _deploy/p/demo/gnoswap $WORK_DIR/gno/examples/gno.land/p/demo

# copy gnoswap base realms ( includes common logic, variables and consts )
$ cp -R _deploy/r/gnoswap $WORK_DIR/gno/examples/gno.land/r/gnoswap

# copy gnoswap realms
$ cp -R gov pool position router staker $WORK_DIR/gno/examples/gno.land/r/demo
```

3. Move all test cases into its own directory:

```
# Governance
$ cd $WORKDIR/gno/examples/gno.land/r/demo/gov
$ mv _TEST_/* .

# Pool
$ cd $WORKDIR/gno/examples/gno.land/r/demo/pool
$ mv _TEST_/* .

# Position
$ cd $WORKDIR/gno/examples/gno.land/r/demo/position
$ mv _TEST_/* .

# Router
$ cd $WORKDIR/gno/examples/gno.land/r/demo/router
$ mv _TEST_/* .

# Staker
$ cd $WORKDIR/gno/examples/gno.land/r/demo/staker
$ mv _TEST_/* .
Expand All @@ -87,10 +90,12 @@ $ gno test -root-dir $WORKDIR/gno-for-swap -verbose=true $WORKDIR/gno/examples/g
The contracts can be tested using [testscript](https://github.com/gnolang/gno/blob/d54ca62749f79a6992da520e1659ba0dbbdd980b/gno.land/pkg/integration/doc.go)

### Change Admin Address
1. Open `$WORKDIR/gno/examples/gno.land/r/gnoswap/consts/consts.gno`

1. Open `$WORKDIR/gno/examples/gno.land/r/demo/gnoswap/consts/consts.gno`
2. Change `GNOSWAP_ADMIN`, `FEE_COLLECTOR` to `g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5`

### Testing

```
$ cd $WORKDIR/gnoswap
$ cp __local/test/gnoswap.txtar $WORKDIR/gno/gno.land/cmd/gnoland/testdata/
Expand All @@ -100,14 +105,11 @@ $ go test -v . -run Testdata/gnoswap
```

## WARNING
> [!WARNING]
> To deploy `pool` contract, `9781838` gas is required which is close to the [block gas limit](https://github.com/gnolang/gno/blob/831bb6f92e1a2217242169dab1f4fd1f87e5eaa0/tm2/pkg/bft/types/params.go#L26-L27).

> [!WARNING] To deploy `pool` contract, `9781838` gas is required which is close to the [block gas limit](https://github.com/gnolang/gno/blob/831bb6f92e1a2217242169dab1f4fd1f87e5eaa0/tm2/pkg/bft/types/params.go#L26-L27).
>
> So, when changing the `pool` contract, make sure to test it on actual network before making PR.


> [!WARNING]
> To deploy `uint256` contract, `9731522` gas is required which is close to the [block gas limit](https://github.com/gnolang/gno/blob/831bb6f92e1a2217242169dab1f4fd1f87e5eaa0/tm2/pkg/bft/types/params.go#L26-L27).
> [!WARNING] To deploy `uint256` contract, `9731522` gas is required which is close to the [block gas limit](https://github.com/gnolang/gno/blob/831bb6f92e1a2217242169dab1f4fd1f87e5eaa0/tm2/pkg/bft/types/params.go#L26-L27).
>
> So, when changing the `uint256` contract, make sure to test it on actual network before making PR.

4 changes: 2 additions & 2 deletions __local/test/gnoswap.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ loadpkg gno.land/r/demo/users
loadpkg gno.land/r/demo/wugnot
loadpkg gno.land/r/demo/foo20

loadpkg gno.land/r/gnoswap/consts
loadpkg gno.land/r/gnoswap/common
loadpkg gno.land/r/demo/gnoswap/consts
loadpkg gno.land/r/demo/gnoswap/common

loadpkg gno.land/r/demo/gns
loadpkg gno.land/r/demo/gnft
Expand Down
16 changes: 8 additions & 8 deletions __local/test/test_data.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ ADDR_WUGNOT := g1pf6dv9fjk3rn0m4jjcne306ga4he3mzmupfjl6
MAX_UINT64 := 18446744073709551615
TX_EXPIRE := 9999999999

NOW := $(shell date +%s)
INCENTIVE_START := $(shell expr $(NOW) + 360) # GIVE ENOUGH TIME TO EXECUTE PREVIOUS TXS
INCENTIVE_END := $(shell expr $(NOW) + 360 + 7776000) # 7776000 SECONDS = 90 DAY
# INCENTIVE_START
# TOMORROW_MIDNIGHT := $(shell date +%s) # DEV
TOMORROW_MIDNIGHT := $(shell (gdate -ud 'tomorrow 00:00:00' +%s))
INCENTIVE_END := $(shell expr $(TOMORROW_MIDNIGHT) + 7776000) # 7776000 SECONDS = 90 DAY


MAKEFILE := $(shell realpath $(firstword $(MAKEFILE_LIST)))

# GNOLAND_RPC_URL ?= localhost:26657
GNOLAND_RPC_URL ?= localhost:26657 # 36657 for gnodev, 26657 for gnoland
GNOLAND_RPC_URL ?= localhost:26657
CHAINID ?= dev
ROOT_DIR:=$(shell dirname $(MAKEFILE))/../../

Expand Down Expand Up @@ -151,12 +151,12 @@ deploy-package-pool:
# deploy common realms
deploy-consts:
$(info ************ deploy consts ************)
@echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_deploy/r/gnoswap/consts -pkgpath gno.land/r/gnoswap/consts -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 10000000 -memo "" gnoswap_admin > /dev/null
@echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_deploy/r/demo/gnoswap/consts -pkgpath gno.land/r/demo/gnoswap/consts -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 10000000 -memo "" gnoswap_admin > /dev/null
@echo

deploy-common:
$(info ************ deploy common ************)
@echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_deploy/r/gnoswap/common -pkgpath gno.land/r/gnoswap/common -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 10000000 -memo "" gnoswap_admin > /dev/null
@echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_deploy/r/demo/gnoswap/common -pkgpath gno.land/r/demo/gnoswap/common -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 10000000 -memo "" gnoswap_admin > /dev/null
@echo

# deploy gnoswap realms
Expand Down Expand Up @@ -351,7 +351,7 @@ create-external-incentive:
@echo

# THEN CREATE EXTERNAL INCENTIVE
@echo "" | gnokey maketx call -pkgpath gno.land/r/demo/staker -func CreateExternalIncentive -args "gno.land/r/demo/foo:gno.land/r/demo/gns:500" -args "gno.land/r/demo/obl" -args 100000000000000 -args $(INCENTIVE_START) -args $(INCENTIVE_END) -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" gnoswap_admin > /dev/null
@echo "" | gnokey maketx call -pkgpath gno.land/r/demo/staker -func CreateExternalIncentive -args "gno.land/r/demo/foo:gno.land/r/demo/gns:500" -args "gno.land/r/demo/obl" -args 100000000000000 -args $(TOMORROW_MIDNIGHT) -args $(INCENTIVE_END) -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" gnoswap_admin > /dev/null
@echo


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package common
import (
"std"

"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"
)

var (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module gno.land/r/gnoswap/common
module gno.land/r/demo/gnoswap/common

require (
gno.land/p/demo/gnoswap/int256 v0.0.0-latest
gno.land/p/demo/gnoswap/uint256 v0.0.0-latest
gno.land/r/gnoswap/consts v0.0.0-latest
gno.land/r/demo/gnoswap/consts v0.0.0-latest
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package common

import (
"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"

u256 "gno.land/p/demo/gnoswap/uint256"
)
Expand Down
1 change: 1 addition & 0 deletions _deploy/r/demo/gnoswap/consts/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/demo/gnoswap/consts
2 changes: 1 addition & 1 deletion _deploy/r/demo/gns/gno.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ require (
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/p/demo/users v0.0.0-latest
gno.land/r/demo/users v0.0.0-latest
gno.land/r/gnoswap/consts v0.0.0-latest
gno.land/r/demo/gnoswap/consts v0.0.0-latest
)
2 changes: 1 addition & 1 deletion _deploy/r/demo/gns/gns.gno
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

pusers "gno.land/p/demo/users"

"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"
)

const MAXIMUM_SUPPLY = uint64(1_000_000_000_000_000) // 1B
Expand Down
1 change: 0 additions & 1 deletion _deploy/r/gnoswap/consts/gno.mod

This file was deleted.

2 changes: 1 addition & 1 deletion gov/gno.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ require (
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/p/demo/users v0.0.0-latest
gno.land/r/demo/gns v0.0.0-latest
gno.land/r/gnoswap/consts v0.0.0-latest
gno.land/r/demo/gnoswap/consts v0.0.0-latest
)
2 changes: 1 addition & 1 deletion gov/gno_helper.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gov
import (
"std"

"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"
)

func GetOrigPkgAddr() std.Address {
Expand Down
4 changes: 2 additions & 2 deletions pool/_RPC_dry.gno
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package pool

import (
"gno.land/r/gnoswap/common"
"gno.land/r/demo/gnoswap/common"

"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"

plp "gno.land/p/demo/gnoswap/pool" // pool package

Expand Down
2 changes: 1 addition & 1 deletion pool/_TEST_/_TEST_0_INIT_TOKEN_REGISTER_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"gno.land/r/demo/gns"

"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"

pusers "gno.land/p/demo/users"
)
Expand Down
2 changes: 1 addition & 1 deletion pool/_TEST_/_TEST_0_INIT_VARIABLE_AND_HELPER_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"std"
"testing"

"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pool/_TEST_/_TEST_pool_dryswap_and_swap_test.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"std"
"testing"

"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"

"gno.land/r/demo/bar"
"gno.land/r/demo/foo"
Expand Down
2 changes: 1 addition & 1 deletion pool/_TEST_/_TEST_pool_multi_token_test.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"
"testing"

"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"

"gno.land/r/demo/bar"
"gno.land/r/demo/baz"
Expand Down
2 changes: 1 addition & 1 deletion pool/_TEST_/_TEST_pool_native_swap_test.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"std"
"testing"

"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"

"gno.land/r/demo/gns"

Expand Down
2 changes: 1 addition & 1 deletion pool/_TEST_/_TEST_pool_single_lp_test.gn
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"gno.land/r/demo/foo"
"gno.land/r/demo/gns"

"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"

"gno.land/p/demo/json"

Expand Down
2 changes: 1 addition & 1 deletion pool/_TEST_/_TEST_pool_test.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"gno.land/r/demo/baz"
"gno.land/r/demo/foo"

"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"

"gno.land/r/demo/gns"
)
Expand Down
2 changes: 1 addition & 1 deletion pool/_TEST_/z0_rpc_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"gno.land/p/demo/json"
pusers "gno.land/p/demo/users"

"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"

pl "gno.land/r/demo/pool"
)
Expand Down
2 changes: 1 addition & 1 deletion pool/_TEST_/z1_single_lp_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"gno.land/p/demo/json"
pusers "gno.land/p/demo/users"

"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"

pl "gno.land/r/demo/pool"
)
Expand Down
2 changes: 1 addition & 1 deletion pool/emergency_halt.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"std"

"gno.land/p/demo/ufmt"
"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions pool/gno.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ require (
gno.land/p/demo/users v0.0.0-latest
gno.land/r/demo/gns v0.0.0-latest
gno.land/r/demo/gov v0.0.0-latest
gno.land/r/gnoswap/common v0.0.0-latest
gno.land/r/gnoswap/consts v0.0.0-latest
gno.land/r/demo/gnoswap/common v0.0.0-latest
gno.land/r/demo/gnoswap/consts v0.0.0-latest
)
4 changes: 2 additions & 2 deletions pool/pool.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

plp "gno.land/p/demo/gnoswap/pool"

"gno.land/r/gnoswap/common"
"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/common"
"gno.land/r/demo/gnoswap/consts"

gv "gno.land/r/demo/gov"

Expand Down
4 changes: 2 additions & 2 deletions pool/pool_manager.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"gno.land/p/demo/ufmt"

"gno.land/r/gnoswap/common"
"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/common"
"gno.land/r/demo/gnoswap/consts"

"gno.land/r/demo/gns"

Expand Down
2 changes: 1 addition & 1 deletion pool/position.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"std"

"gno.land/p/demo/ufmt"
"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"

i256 "gno.land/p/demo/gnoswap/int256"
u256 "gno.land/p/demo/gnoswap/uint256"
Expand Down
2 changes: 1 addition & 1 deletion pool/position_modify.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pool

import (
"gno.land/r/gnoswap/common"
"gno.land/r/demo/gnoswap/common"

i256 "gno.land/p/demo/gnoswap/int256"

Expand Down
2 changes: 1 addition & 1 deletion pool/tick.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pool

import (
"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"

i256 "gno.land/p/demo/gnoswap/int256"
u256 "gno.land/p/demo/gnoswap/uint256"
Expand Down
2 changes: 1 addition & 1 deletion pool/tick_bitmap.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pool

import (
"gno.land/p/demo/ufmt"
"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"

plp "gno.land/p/demo/gnoswap/pool"

Expand Down
2 changes: 1 addition & 1 deletion pool/token_register.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

pusers "gno.land/p/demo/users"

"gno.land/r/gnoswap/consts"
"gno.land/r/demo/gnoswap/consts"
)

// GRC20Interface is the interface for GRC20 tokens
Expand Down
Loading
Loading