Skip to content

Commit

Permalink
Merge pull request #139 from notional-labs/dang/correct-memo
Browse files Browse the repository at this point in the history
correct memo
  • Loading branch information
GNaD13 authored Apr 19, 2023
2 parents bd94d66 + 8955fe4 commit 3c6994e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
9 changes: 4 additions & 5 deletions x/feeabs/types/build_memo.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,14 @@ func NewOsmosisSwapMsg(inputCoin sdk.Coin, outputDenom string, slippagePercentag
}

// ParseMsgToMemo build a memo from msg, contractAddr, compatible with ValidateAndParseMemo in https://github.com/osmosis-labs/osmosis/blob/nicolas/crosschain-swaps-new/x/ibc-hooks/wasm_hook.go
func ParseMsgToMemo(msg OsmosisSwapMsg, contractAddr string, receiverAddress string, chainName string) (string, error) {
func ParseMsgToMemo(msg OsmosisSwapMsg, contractAddr string) (string, error) {
// TODO: need to validate the msg && contract address
receiver := fmt.Sprintf("%s/%s", chainName, receiverAddress)
memo := OsmosisSpecialMemo{
Wasm: make(map[string]interface{}),
}

memo.Wasm["contract"] = contractAddr
memo.Wasm["msg"] = msg
memo.Wasm["receiver"] = receiver

memo_marshalled, err := json.Marshal(&memo)
if err != nil {
Expand All @@ -82,7 +80,8 @@ func ParseMsgToMemo(msg OsmosisSwapMsg, contractAddr string, receiverAddress str

// TODO: write test for this
// BuildNextMemo create memo for IBC hook, this execute `CrossChainSwap contract`
func BuildCrossChainSwapMemo(outputDenom string, contractAddress, receiver string, chainName string) (string, error) {
func BuildCrossChainSwapMemo(outputDenom string, contractAddress string, receiverAddress string, chainName string) (string, error) {
receiver := fmt.Sprintf("%s/%s", chainName, receiverAddress)
swap := Swap{
OutPutDenom: outputDenom,
Slippage: Twap{
Expand All @@ -98,7 +97,7 @@ func BuildCrossChainSwapMemo(outputDenom string, contractAddress, receiver strin
msgSwap := OsmosisSwapMsg{
OsmosisSwap: swap,
}
nextMemo, err := ParseMsgToMemo(msgSwap, contractAddress, receiver, chainName)
nextMemo, err := ParseMsgToMemo(msgSwap, contractAddress)
if err != nil {
return "", err
}
Expand Down
10 changes: 4 additions & 6 deletions x/feeabs/types/build_memo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@ func TestParseMsgToMemo(t *testing.T) {
}

mockAddress := "cosmos123456789"
mockReceiver := "cosmos123456789"
chainName := "feeappd-t1"

//TODO: need to check assert msg
_, err := types.ParseMsgToMemo(msgSwap, mockAddress, mockReceiver, chainName)
_, err := types.ParseMsgToMemo(msgSwap, mockAddress)
require.NoError(t, err)
}

// TODO: need to refactor this test, use driven table
func TestParseCrossChainSwapMsgToMemo(t *testing.T) {
outPutDenom := "uosmo"
contractAddress := "osmo1c3ljch9dfw5kf52nfwpxd2zmj2ese7agnx0p9tenkrryasrle5sqf3ftpg"
mockReceiver := "osmo1cd4nn8yzdrrsfqsmmvaafq8r03xn38qgqt8fzh"
chainName := "feeappd-t1"
mockReceiver := "feeabs1efd63aw40lxf3n4mhf7dzhjkr453axurwrhrrw"
chainName := "feeabs"

execepted_memo_str := `{"wasm":{"contract":"osmo1c3ljch9dfw5kf52nfwpxd2zmj2ese7agnx0p9tenkrryasrle5sqf3ftpg","msg":{"osmosis_swap":{"output_denom":"uosmo","slippage":{"twap":{"slippage_percentage":"20","window_seconds":10}},"receiver":"osmo1cd4nn8yzdrrsfqsmmvaafq8r03xn38qgqt8fzh","on_failed_delivery":"do_nothing"}},"receiver":"feeappd-t1/osmo1cd4nn8yzdrrsfqsmmvaafq8r03xn38qgqt8fzh"}}`
execepted_memo_str := `{"wasm":{"contract":"osmo1c3ljch9dfw5kf52nfwpxd2zmj2ese7agnx0p9tenkrryasrle5sqf3ftpg","msg":{"osmosis_swap":{"output_denom":"uosmo","slippage":{"twap":{"slippage_percentage":"20","window_seconds":10}},"receiver":"feeabs/feeabs1efd63aw40lxf3n4mhf7dzhjkr453axurwrhrrw","on_failed_delivery":"do_nothing"}}}}`
//TODO: need to check assert msg
memo_str, err := types.BuildCrossChainSwapMemo(outPutDenom, contractAddress, mockReceiver, chainName)

Expand Down

0 comments on commit 3c6994e

Please sign in to comment.