Skip to content

Commit

Permalink
Update deposit and withdraw memo (#911)
Browse files Browse the repository at this point in the history
* fix: affiliate info taking place of pair addr when pair address is not present

* fix: remove affiliate info from withdraw memos

* chore: changeset
  • Loading branch information
mfaizan1 committed Jul 17, 2024
1 parent f763277 commit ebe27fa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-pianos-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@swapkit/helpers": patch
---

remove affiliate info from withdraw memos, and fix pair address spot being taken buy affiliate info.
10 changes: 10 additions & 0 deletions packages/swapkit/helpers/src/helpers/__tests__/memo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ describe("getMemoForDeposit", () => {
const result = getMemoForDeposit({ chain: Chain.Ethereum, symbol: "ETH" });
expect(result).toBe("+:ETH.ETH");
});

test("returns correct memo when paired address is not available but affiliate info is present", () => {
const result = getMemoForDeposit({
chain: Chain.Ethereum,
symbol: "ETH",
affiliateAddress: "thor1abc123",
affiliateBasisPoints: 500,
});
expect(result).toBe("+:ETH.ETH::thor1abc123:500");
});
});

describe("getMemoForWithdraw", () => {
Expand Down
18 changes: 7 additions & 11 deletions packages/swapkit/helpers/src/helpers/memo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ export function getMemoForDeposit({
address?: string;
}>) {
const poolIdentifier = getPoolIdentifier({ chain, symbol });
const addressPart = address ? `:${address}` : "";
const hasAffiliateInfo = !!affiliate.affiliateAddress;
const addressPart = address ? `:${address}` : hasAffiliateInfo ? ":" : "";

return addAffiliate(`${MemoType.DEPOSIT}:${poolIdentifier}${addressPart}`, affiliate);
}
Expand All @@ -137,9 +138,8 @@ export function getMemoForSaverWithdraw({
chain,
symbol,
basisPoints,
...affiliate
}: WithAffiliate<{ chain: Chain; symbol: string; basisPoints: number }>) {
return addAffiliate(`${MemoType.WITHDRAW}:${chain}/${symbol}:${basisPoints}`, affiliate);
}: { chain: Chain; symbol: string; basisPoints: number }) {
return `${MemoType.WITHDRAW}:${chain}/${symbol}:${basisPoints}`;
}

export function getMemoForWithdraw({
Expand All @@ -148,22 +148,18 @@ export function getMemoForWithdraw({
ticker,
basisPoints,
targetAsset,
...affiliate
}: WithAffiliate<{
}: {
chain: Chain;
symbol: string;
ticker: string;
basisPoints: number;
targetAsset?: string;
}>) {
}) {
const shortenedSymbol =
chain === "ETH" && ticker !== "ETH" ? `${ticker}-${symbol.slice(-3)}` : symbol;
const targetPart = targetAsset ? `:${targetAsset}` : "";

return addAffiliate(
`${MemoType.WITHDRAW}:${chain}.${shortenedSymbol}:${basisPoints}${targetPart}`,
affiliate,
);
return `${MemoType.WITHDRAW}:${chain}.${shortenedSymbol}:${basisPoints}${targetPart}`;
}

/**
Expand Down

0 comments on commit ebe27fa

Please sign in to comment.