Skip to content

Commit

Permalink
feat: Add delimiter to referrer tag (#154)
Browse files Browse the repository at this point in the history
* feat: Add delimiter to referrer tag

To make it easier for clients to identify referred transactions, add a delimitter in front of referrer address. By adding in front, this allows referrer-identification logic to be backwards compatible

* Make delimitter optional

* Spelling delimiter

* change delimiter value

* Update constants.ts

* fix

Signed-off-by: nicholaspai <npai.nyc@gmail.com>
  • Loading branch information
nicholaspai committed Jul 8, 2022
1 parent 65bdf8c commit 93644ef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/utils/bridge.ts
Expand Up @@ -19,6 +19,7 @@ import {
queriesTable,
FLAT_RELAY_CAPITAL_FEE,
relayerFeeCapitalCostConfig,
referrerDelimiterHex,
} from "./constants";

import { parseEther, tagAddress } from "./format";
Expand Down Expand Up @@ -237,7 +238,7 @@ export async function sendAcrossDeposit(
// do not tag a referrer if data is not provided as a hex string.
tx.data =
referrer && ethers.utils.isAddress(referrer)
? tagAddress(tx.data!, referrer)
? tagAddress(tx.data!, referrer, referrerDelimiterHex)
: tx.data;

return signer.sendTransaction(tx);
Expand Down
2 changes: 2 additions & 0 deletions src/utils/constants.ts
Expand Up @@ -677,3 +677,5 @@ const getQueriesTable = () => {
};

export const queriesTable = getQueriesTable();

export const referrerDelimiterHex = "0xd00dfeeddeadbeef";
16 changes: 12 additions & 4 deletions src/utils/format.ts
Expand Up @@ -86,9 +86,13 @@ export function stringToHex(value: string) {
}

// appends hex tag to data
export function tagHex(dataHex: string, tagHex: string) {
export function tagHex(
dataHex: string,
tagHex: string,
delimitterHex: string = ""
) {
assert(ethers.utils.isHexString(dataHex), "Data must be valid hex string");
return ethers.utils.hexConcat([dataHex, tagHex]);
return ethers.utils.hexConcat([dataHex, delimitterHex, tagHex]);
}

// converts a string tag to hex and appends, currently not in use
Expand All @@ -97,9 +101,13 @@ export function tagString(dataHex: string, tagString: string) {
}

// tags only an address
export function tagAddress(dataHex: string, address: string) {
export function tagAddress(
dataHex: string,
address: string,
delimiterHex: string = ""
) {
assert(ethers.utils.isAddress(address), "Data must be a valid address");
return tagHex(dataHex, address);
return tagHex(dataHex, address, delimiterHex);
}

export function capitalizeFirstLetter(str: string) {
Expand Down

4 comments on commit 93644ef

@vercel
Copy link

@vercel vercel bot commented on 93644ef Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kovan-frontend-v2 – ./

kovan-frontend-v2-uma.vercel.app
kovan-frontend-v2.vercel.app
kovan-frontend-v2-git-master-uma.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 93644ef Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 93644ef Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

goerli-frontend-v2 – ./

goerli-frontend-v2-uma.vercel.app
goerli-frontend-v2.vercel.app
goerli-frontend-v2-git-master-uma.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 93644ef Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.