Skip to content

Commit

Permalink
feat: calculateAmountReceived uses filtered getAssets
Browse files Browse the repository at this point in the history
  • Loading branch information
just-a-node committed Apr 26, 2024
1 parent b121086 commit 80584f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
13 changes: 7 additions & 6 deletions packages/agents/sdk/src/sdkPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,14 @@ export class SdkPool extends SdkShared {
amount,
signerAddress,
});
const [originPool, [canonicalDomain, canonicalId]] = await Promise.all([
this.getPool(originDomain, _originTokenAddress),
this.getCanonicalTokenId(originDomain, _originTokenAddress),
]);

const originPool = await this.getPool(originDomain, _originTokenAddress);
const isNextAsset = originPool ? utils.getAddress(originPool.local.address) === _originTokenAddress : undefined;
const key = this.calculateCanonicalKey(canonicalDomain, canonicalId);
const destinationAssetData = await this.getAssetsDataByDomainAndKey(destinationDomain, key);
const destinationAssetData = (await this.getAssetsData({
domain: originDomain,
localAsset: _originTokenAddress,
limit: 1
}))[0];
if (!destinationAssetData) {
throw new Error("Origin token cannot be bridged to any token on this destination domain");
}
Expand Down
12 changes: 6 additions & 6 deletions packages/agents/sdk/test/sdkPool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ describe("SdkPool", () => {
.onCall(0) // swap once for destination pool
.resolves(destinationAmountAfterSwap);
stub(sdkPool, "getCanonicalTokenId").resolves([mockAssetData.canonical_domain, mockAssetData.canonical_id]);
stub(sdkPool, "getAssetsDataByDomainAndKey").resolves(mockAssetData);
stub(sdkPool, "getAssetsData").resolves([mockAssetData]);

const res = await sdkPool.calculateAmountReceived(
mockPool.domainId,
Expand Down Expand Up @@ -472,7 +472,7 @@ describe("SdkPool", () => {
.onCall(1) // swap once for destination pool
.resolves(destinationAmountAfterSwap);
stub(sdkPool, "getCanonicalTokenId").resolves([mockAssetData.canonical_domain, mockAssetData.canonical_id]);
stub(sdkPool, "getAssetsDataByDomainAndKey").resolves(mockAssetData);
stub(sdkPool, "getAssetsData").resolves([mockAssetData]);

const res = await sdkPool.calculateAmountReceived(
mockPool.domainId,
Expand Down Expand Up @@ -500,7 +500,7 @@ describe("SdkPool", () => {
.onCall(0) // swap once for origin pool
.resolves(originAmountAfterSwap);
stub(sdkPool, "getCanonicalTokenId").resolves([mockAssetData.canonical_domain, mockAssetData.canonical_id]);
stub(sdkPool, "getAssetsDataByDomainAndKey").resolves(mockAssetData);
stub(sdkPool, "getAssetsData").resolves([mockAssetData]);

const res = await sdkPool.calculateAmountReceived(
mockPool.domainId,
Expand All @@ -522,7 +522,7 @@ describe("SdkPool", () => {
const destinationSlippage = "0"; // 0% in BPS

stub(sdkPool, "getCanonicalTokenId").resolves([mockAssetData.canonical_domain, mockAssetData.canonical_id]);
stub(sdkPool, "getAssetsDataByDomainAndKey").resolves(mockAssetData);
stub(sdkPool, "getAssetsData").resolves([mockAssetData]);

const res = await sdkPool.calculateAmountReceived(
mockPool.domainId,
Expand Down Expand Up @@ -564,7 +564,7 @@ describe("SdkPool", () => {
.onCall(0) // swap once for destination pool
.resolves(destinationAmountAfterSwapConverted);
stub(sdkPool, "getCanonicalTokenId").resolves([mockAssetData.canonical_domain, mockAssetData.canonical_id]);
stub(sdkPool, "getAssetsDataByDomainAndKey").resolves(mockAssetData);
stub(sdkPool, "getAssetsData").resolves([mockAssetData]);

const res = await sdkPool.calculateAmountReceived(
mockPoolDifferentDecimals.domainId,
Expand Down Expand Up @@ -602,7 +602,7 @@ describe("SdkPool", () => {
.onCall(0) // swap once for origin pool
.resolves(originAmountAfterSwapConverted);
stub(sdkPool, "getCanonicalTokenId").resolves([mockAssetData.canonical_domain, mockAssetData.canonical_id]);
stub(sdkPool, "getAssetsDataByDomainAndKey").resolves(mockAssetData);
stub(sdkPool, "getAssetsData").resolves([mockAssetData]);

const res = await sdkPool.calculateAmountReceived(
mockPoolDifferentDecimals.domainId,
Expand Down

0 comments on commit 80584f1

Please sign in to comment.