Skip to content

Commit

Permalink
fix swap params
Browse files Browse the repository at this point in the history
  • Loading branch information
c8e4 committed Jun 2, 2024
1 parent a05e58c commit 70aa304
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/lib/wallet/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,6 @@ export function executeSwap(
tokensAsPayment: { tokenId: string; amount: Amount },
nanoErg: string | bigint = 2n * RECOMMENDED_MIN_FEE_VALUE + SAFE_MIN_BOX_VALUE
): EIP12UnsignedTransaction {
console.log('export function executeSwap')
console.dir({
blockchainHeight,
swapOrderInputBoxes,
paymentInputBoxes,
tokensFromSwapContract,
tokensAsPayment,
nanoErg
})
const paymentOutputBox = new OutputBuilder(nanoErg, DEPOSIT_ADDRESS)
.setAdditionalRegisters({
R4: swapOrderInputBoxes[0].additionalRegisters.R4,
Expand Down Expand Up @@ -185,11 +176,10 @@ export function createSwapOrderTx(
return unsignedTransaction;
}


export function createExecuteSwapOrderTx(swapParams: SwapRequest, db: BoxDB) {
const [rate, denom] = splitSellRate(swapParams.price);
const height = 1273521;

const swapOrderInputBoxes: any = db.boxRows.filter(
(b) =>
b.contract == 'SWAP' &&
Expand All @@ -200,9 +190,7 @@ export function createExecuteSwapOrderTx(swapParams: SwapRequest, db: BoxDB) {
swapOrderInputBoxes.length = 1;

const paymentInputBoxes: any = db.boxRows.filter(
(b) =>
b.contract == 'DEPOSIT' &&
b.parameters.userPk == swapParams.address
(b) => b.contract == 'DEPOSIT' && b.parameters.userPk == swapParams.address
);
if (swapOrderInputBoxes.length < 1 || paymentInputBoxes.length < 1) {
console.dir({ swapOrderInputBoxes, paymentInputBoxes });
Expand All @@ -214,8 +202,8 @@ export function createExecuteSwapOrderTx(swapParams: SwapRequest, db: BoxDB) {
);
}

const buyingAmount = +swapOrderInputBoxes[0].box.assets[0].amount;
const paymentAmount = +swapParams.price * +swapParams.amount;
const buyingAmount = +swapParams.price * +swapParams.amount;
const paymentAmount = +swapOrderInputBoxes[0].box.assets[0].amount;

const tokensFromSwapContract = {
tokenId: swapParams.buyingTokenId,
Expand All @@ -225,10 +213,10 @@ export function createExecuteSwapOrderTx(swapParams: SwapRequest, db: BoxDB) {

const unsignedTx = executeSwap(
height,
swapOrderInputBoxes.map(b => b.box),
paymentInputBoxes.map(b => b.box),
tokensFromSwapContract,
tokensAsPayment
swapOrderInputBoxes.map((b) => b.box),
paymentInputBoxes.map((b) => b.box),
tokensAsPayment,
tokensFromSwapContract
);
return unsignedTx;
}

0 comments on commit 70aa304

Please sign in to comment.