-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14e6e9f
commit e26d2f4
Showing
6 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package query | ||
|
||
import ( | ||
"context" | ||
|
||
gmptypes "github.com/ojo-network/ojo/x/gmp/types" | ||
) | ||
|
||
func (c *Client) GmpQueryClient() gmptypes.QueryClient { | ||
return gmptypes.NewQueryClient(c.grpcConn) | ||
} | ||
|
||
func (c *Client) QueryPayments() (*gmptypes.AllPaymentsResponse, error) { | ||
ctx, cancel := context.WithTimeout(context.Background(), queryTimeout) | ||
defer cancel() | ||
|
||
queryResponse, err := c.GmpQueryClient().AllPayments( | ||
ctx, | ||
&gmptypes.AllPaymentsRequest{}, | ||
) | ||
|
||
return queryResponse, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package tx | ||
|
||
import ( | ||
"cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
gmptypes "github.com/ojo-network/ojo/x/gmp/types" | ||
) | ||
|
||
// TxCreatePayment creates a gmp payment transaction | ||
func (c *Client) TxCreatePayment() (*sdk.TxResponse, error) { | ||
fromAddr, err := c.keyringRecord.GetAddress() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
msg := gmptypes.NewMsgCreatePayment( | ||
fromAddr.String(), | ||
"Arbitrum", | ||
"BTC", | ||
sdk.NewCoin("uojo", math.NewInt(10_000_000_000)), | ||
math.LegacyOneDec(), | ||
100, | ||
) | ||
|
||
return c.BroadcastTx(msg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package types | ||
|
||
import ( | ||
"cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func (p Payment) TriggerUpdate(rate math.LegacyDec, ctx sdk.Context) bool { | ||
return p.LastPrice.Sub(rate).Abs().GT(p.Deviation) || | ||
p.LastBlock < ctx.BlockHeight()-p.Heartbeat | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPayment_TriggerUpdate(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
payment Payment | ||
rate math.LegacyDec | ||
ctx sdk.Context | ||
want bool | ||
}{ | ||
{ | ||
name: "should trigger update - price deviation", | ||
payment: Payment{ | ||
LastPrice: math.LegacyMustNewDecFromStr("100"), | ||
Deviation: math.LegacyMustNewDecFromStr("1"), | ||
Heartbeat: 100, | ||
LastBlock: 1, | ||
}, | ||
rate: math.LegacyMustNewDecFromStr("101.1"), | ||
ctx: sdk.Context{}.WithBlockHeight(1), | ||
want: true, | ||
}, | ||
{ | ||
name: "should not trigger update - no expiration", | ||
payment: Payment{ | ||
LastPrice: math.LegacyMustNewDecFromStr("100"), | ||
Deviation: math.LegacyMustNewDecFromStr("1"), | ||
Heartbeat: 100, | ||
LastBlock: 100, | ||
}, | ||
rate: math.LegacyMustNewDecFromStr("101"), | ||
ctx: sdk.Context{}, | ||
want: false, | ||
}, | ||
{ | ||
name: "should trigger update - heartbeat expired", | ||
payment: Payment{ | ||
LastPrice: math.LegacyMustNewDecFromStr("100"), | ||
Deviation: math.LegacyMustNewDecFromStr("1"), | ||
Heartbeat: 100, | ||
LastBlock: 1, | ||
}, | ||
rate: math.LegacyMustNewDecFromStr("100"), | ||
ctx: sdk.Context{}.WithBlockHeight(102), | ||
want: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := tt.payment.TriggerUpdate(tt.rate, tt.ctx) | ||
require.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |