diff --git a/proto/arkeo/claim/tx.proto b/proto/arkeo/claim/tx.proto index e5db7efa..61a95b7f 100644 --- a/proto/arkeo/claim/tx.proto +++ b/proto/arkeo/claim/tx.proto @@ -9,6 +9,7 @@ option go_package = "github.com/arkeonetwork/arkeo/x/claim/types"; service Msg { rpc ClaimEth(MsgClaimEth) returns (MsgClaimEthResponse); rpc ClaimArkeo(MsgClaimArkeo) returns (MsgClaimArkeoResponse); + rpc ClaimThorchain(MsgClaimThorchain) returns (MsgClaimThorchainResponse); rpc TransferClaim(MsgTransferClaim) returns (MsgTransferClaimResponse); rpc AddClaim(MsgAddClaim) returns (MsgAddClaimResponse); // this line is used by starport scaffolding # proto/tx/rpc @@ -16,9 +17,8 @@ service Msg { message MsgClaimEth { bytes creator = 1 [ (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress" ]; - string eth_address = 2; // the adress the claim is for + string eth_address = 2; // the address the claim is for string signature = 3; // EIP712 signature that has to be signed by ethAddress - string thor_tx = 4; // the tx hash of the thorchain tx that delegates the arkeo claim } message MsgClaimEthResponse {} @@ -26,11 +26,19 @@ message MsgClaimEthResponse {} message MsgClaimArkeo { bytes creator = 1 [ (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress" ]; - string thor_tx = 2; // the tx hash of the thorchain tx that delegates the arkeo claim } message MsgClaimArkeoResponse {} +message MsgClaimThorchain { + bytes creator = 1 [ (gogoproto.casttype) = + "github.com/cosmos/cosmos-sdk/types.AccAddress" ]; + string fromAddress = 2; // the address that is delegating the claim + string toAddress = 3; // the address to delegate the claim to +} + +message MsgClaimThorchainResponse {} + message MsgTransferClaim { bytes creator = 1 [ (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress" ]; diff --git a/scripts/genesis.sh b/scripts/genesis.sh index 854f2188..05b692b5 100755 --- a/scripts/genesis.sh +++ b/scripts/genesis.sh @@ -90,11 +90,14 @@ if [ ! -f ~/.arkeo/config/genesis.json ]; then # Thorchain derived test addresses add_account "tarkeo1dllfyp57l4xj5umqfcqy6c2l3xfk0qk6zpc3t7" $TOKEN 1000000000000000 # bob, 10m add_claim_records "ARKEO" "tarkeo1dllfyp57l4xj5umqfcqy6c2l3xfk0qk6zpc3t7" 1000 1000 1000 true + add_account "tarkeo1xrz7z3zwtpc45xm72tpnevuf3wn53re8q4u4nr" $TOKEN 1000000000000000 + add_claim_records "ARKEO" "tarkeo1xrz7z3zwtpc45xm72tpnevuf3wn53re8q4u4nr" 1000 1000 1000 true # add_claim_records "ARKEO" "{YOUR ARKEO ADDRESS}" 500000 500000 500000 true # add_account "{YOUR ARKEO ADDRESS}" $TOKEN 1000000000000000 # add_claim_records "ETHEREUM" "{YOUR ETH ADDRESS}" 500000 600000 700000 true + add_claim_records "ETHEREUM" "0x92E14917A0508Eb56C90C90619f5F9Adbf49f47d" 500000 600000 700000 true # enable CORs on testnet/localnet sed -i 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/g' ~/.arkeo/config/app.toml diff --git a/x/claim/keeper/msg_server_claim_arkeo.go b/x/claim/keeper/msg_server_claim_arkeo.go index 0c085911..937caafd 100644 --- a/x/claim/keeper/msg_server_claim_arkeo.go +++ b/x/claim/keeper/msg_server_claim_arkeo.go @@ -14,13 +14,6 @@ func (k msgServer) ClaimArkeo(goCtx context.Context, msg *types.MsgClaimArkeo) ( return nil, errors.Wrapf(err, "failed to get claim record for %s", msg.Creator) } - if msg.ThorTx != "" { - arkeoClaimRecord, err = k.updateThorClaimRecord(ctx, msg.Creator.String(), msg.ThorTx, arkeoClaimRecord) - if err != nil { - return nil, errors.Wrapf(err, "failed to get claim record for %s", msg.ThorTx) - } - } - if arkeoClaimRecord.IsEmpty() || arkeoClaimRecord.AmountClaim.IsZero() { return nil, errors.Wrapf(types.ErrNoClaimableAmount, "no claimable amount for %s", msg.Creator) } diff --git a/x/claim/keeper/msg_server_claim_eth.go b/x/claim/keeper/msg_server_claim_eth.go index a1d138b5..76161b03 100644 --- a/x/claim/keeper/msg_server_claim_eth.go +++ b/x/claim/keeper/msg_server_claim_eth.go @@ -81,13 +81,6 @@ func (k msgServer) ClaimEth(goCtx context.Context, msg *types.MsgClaimEth) (*typ return nil, errors.Wrapf(err, "failed to set claim record for %s", msg.Creator) } - if msg.ThorTx != "" { - arkeoClaim, err = k.updateThorClaimRecord(ctx, msg.Creator.String(), msg.ThorTx, arkeoClaim) - if err != nil { - return nil, errors.Wrapf(err, "failed to get claim record for %s", msg.ThorTx) - } - } - // call claim on arkeo to claim arkeo (note: this could CLAIM for all tokens that are now merged) _, err = k.ClaimCoinsForAction(ctx, msg.Creator.String(), types.ACTION_CLAIM) if err != nil { diff --git a/x/claim/keeper/msg_server_claim_thorchain.go b/x/claim/keeper/msg_server_claim_thorchain.go index 6fed0ea4..f132c7d6 100644 --- a/x/claim/keeper/msg_server_claim_thorchain.go +++ b/x/claim/keeper/msg_server_claim_thorchain.go @@ -1,78 +1,21 @@ package keeper import ( - "encoding/json" "fmt" "github.com/arkeonetwork/arkeo/x/claim/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/pkg/errors" - "io" - "net/http" - "strings" ) -type ThorTxData struct { - ObservedTx struct { - Tx struct { - FromAddress string `json:"from_address"` - Memo string `json:"memo"` - } `json:"tx"` - } `json:"observed_tx"` -} - // Verify and update the claim record based on the memo of the thorchain tx -func (k msgServer) updateThorClaimRecord(ctx sdk.Context, creator string, thorTx string, arkeoClaimRecord types.ClaimRecord) (types.ClaimRecord, error) { - url := fmt.Sprintf("https://thornode.ninerealms.com/thorchain/tx/%s", thorTx) - - req, err := http.NewRequest(http.MethodGet, url, nil) - if err != nil { - return types.ClaimRecord{}, errors.Wrapf(err, "failed to build request %s", req.RequestURI) - } - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return types.ClaimRecord{}, errors.Wrapf(err, "failed to get thorchain tx for %s", thorTx) - } - defer resp.Body.Close() - - if resp.StatusCode != http.StatusOK { - return types.ClaimRecord{}, fmt.Errorf("received non-OK HTTP status: %d", resp.StatusCode) - } - - body, err := io.ReadAll(resp.Body) - if err != nil { - return types.ClaimRecord{}, fmt.Errorf("error reading response body: %w", err) - } - - var txData ThorTxData - if err := json.Unmarshal(body, &txData); err != nil { - return types.ClaimRecord{}, fmt.Errorf("error unmarshalling transaction data: %w", err) - } - thorAddress := txData.ObservedTx.Tx.FromAddress - memo := txData.ObservedTx.Tx.Memo +func (k msgServer) ClaimThorchain(ctx sdk.Context, msg *types.MsgClaimThorchain) (types.ClaimRecord, error) { - thorAddressBytes, err := sdk.GetFromBech32(thorAddress, "thor") + thorClaimRecord, err := k.GetClaimRecord(ctx, originalArkeoAddress, types.ARKEO) if err != nil { - return types.ClaimRecord{}, fmt.Errorf("invalid thorchain address: %w", err) - } - prefix := sdk.GetConfig().GetBech32AccountAddrPrefix() - - // Re-encode the raw bytes with the new prefix - thorDerivedArkeoAddress, err := sdk.Bech32ifyAddressBytes(prefix, thorAddressBytes) - if err != nil { - return types.ClaimRecord{}, fmt.Errorf("failed to encode address bytes with new prefix: %w", err) - } - - thorClaimRecord, err := k.GetClaimRecord(ctx, thorDerivedArkeoAddress, types.ARKEO) - if err != nil { - return types.ClaimRecord{}, errors.Wrapf(err, "failed to get claim record for %s", thorDerivedArkeoAddress) + return types.ClaimRecord{}, errors.Wrapf(err, "failed to get claim record for %s", originalArkeoAddress) } if thorClaimRecord.IsEmpty() || thorClaimRecord.AmountClaim.IsZero() { - return types.ClaimRecord{}, errors.Wrapf(types.ErrNoClaimableAmount, "no claimable amount for %s", thorDerivedArkeoAddress) - } - parts := strings.Split(memo, ":") - if len(parts) != 3 || parts[0] != "delegate" || parts[1] != "arkeo" { - return types.ClaimRecord{}, fmt.Errorf("invalid memo: %s", memo) + return types.ClaimRecord{}, errors.Wrapf(types.ErrNoClaimableAmount, "no claimable amount for %s", originalArkeoAddress) } combinedClaimRecord := types.ClaimRecord{