Skip to content

Commit

Permalink
Fix SDK pool (#4066)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul Sethuram authored Apr 26, 2023
1 parent 097b18d commit ff17270
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
8 changes: 7 additions & 1 deletion packages/agents/sdk/src/sdkPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ export class SdkPool extends SdkShared {
destinationAmount,
),
);
} else {
promises.push(Promise.resolve(undefined));
}

// Determine if fast liquidity is available (pre-destination-swap amount)
Expand All @@ -290,8 +292,12 @@ export class SdkPool extends SdkShared {
const total_balance: string = activeLiquidity[0].total_balance.toString();
isFastPath = BigNumber.from(this.scientificToBigInt(total_balance)).mul(70).div(100).gt(destinationAmount);
}

const destinationSlippage = BigNumber.from(
destinationAmount.sub(destinationAmountReceived).mul(10000).div(destinationAmount),
destinationAmount
.sub(destinationAmountReceived ?? destinationAmount)
.mul(10000)
.div(destinationAmount),
);

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/sdk-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"scripts": {
"build": "tsc -p tsconfig.json",
"start": "node dist/index.js",
"start": "node --enable-source-maps dist/index.js",
"dev": "yarn build && yarn start",
"lint": "eslint ./src --ext .ts --env node",
"clean": "rimraf ./dist ./tsconfig.tsBuildInfo",
Expand Down
26 changes: 15 additions & 11 deletions packages/examples/sdk-server/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,21 @@ export const baseRoutes = async (server: FastifyInstance, sdkBaseInstance: SdkBa
},
},
async (request, reply) => {
const { originDomain, destinationDomain, originTokenAddress, amount, receiveLocal, checkFastLiquidity } =
request.body;
const res = await sdkBaseInstance.calculateAmountReceived(
originDomain,
destinationDomain,
originTokenAddress,
amount,
receiveLocal,
checkFastLiquidity,
);
reply.status(200).send(res);
try {
const { originDomain, destinationDomain, originTokenAddress, amount, receiveLocal, checkFastLiquidity } =
request.body;
const res = await sdkBaseInstance.calculateAmountReceived(
originDomain,
destinationDomain,
originTokenAddress,
amount,
receiveLocal,
checkFastLiquidity,
);
reply.status(200).send(res);
} catch (e: unknown) {
console.log(e);
}
},
);
};

0 comments on commit ff17270

Please sign in to comment.