I'm trying to call the Plenty Router with Taquito to swap from kUSD (Kolibri USD) to tzBTC via Plenty token. In this example, I'm sending 1 kUSD. I'm using arbitrary minimum output (I do not compute them yet) but as far as I understand this should not be blocking.
I get the following error : "'[exchangeAddress] Address is not valid: undefined', stack: 'AddressValidationError: [exchangeAddress]"
const swapF = async () => {
// My address
const addressReceiver = "tz1d4649CmmMEzXBWzhTgTkFxy9ATNhb5HC3"
// Plenty-KUSD swap
const addressPlentyKusdSwap = "KT1UNBvCJXiwJY6tmHM7CJUVwNPew53XkSfh";
// Plenty-tzBTC swap
const addressPlentyTzbtcSwap = "KT1HaDP8fRW7kavK2beST7o4RvzuvZbn5VwV";
// Plenty token
const addressPlentyToken = "KT1GRSvLoikDsXujKgZPsGLX8k8VvR2Tq95b";
// tzBTC token
const addressTzbtcToken = "KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn";
// KUSD token contract
const addressKusd = "KT1K9gCRgaLRFKTErYt1wVxA3Frb9FjasjTV";
const contractKusdToken = await Tezos.wallet.at(addressKusd);
// Plenty Swap Router contract
const addressPlentySwapRouter = "KT1MEVCrGRCsoERXf6ahNLC4ik6J2vRH7Mm6"
const contractPlentySwapRouter = await Tezos.wallet.at(addressPlentySwapRouter);
// tzBTC token contract
const contractTzBtcToken = await Tezos.wallet.at(addressTzbtcToken);
try {
const routerMap = new MichelsonMap();
routerMap.set("0", [addressPlentyKusdSwap, 10, addressPlentyToken, 0]);
routerMap.set("1", [addressPlentyTzbtcSwap, 10, addressTzbtcToken, 0]);
const batch = Tezos.wallet
.batch()
.withContractCall(contractKusdToken.methods.transfer(
addressReceiver,
addressPlentySwapRouter,
1
))
.withContractCall(
contractPlentySwapRouter.methods.routerSwap(
routerMap,
1e12,
addressReceiver
)
);
console.error(batch);
const batchOp = await batch.send();
await batchOp.confirmation();
} catch (error) {
console.error(error);
}
I'm modeling my call to what I see on TzKT for a similar transaction
{
"Route": {
"0": {
"minimumOutput": "50009918356658060000",
"exchangeAddress": "KT1UNBvCJXiwJY6tmHM7CJUVwNPew53XkSfh",
"requiredTokenId": "0",
"requiredTokenAddress": "KT1GRSvLoikDsXujKgZPsGLX8k8VvR2Tq95b"
}
"1": {
"minimumOutput": "4880",
"exchangeAddress": "KT1HaDP8fRW7kavK2beST7o4RvzuvZbn5VwV",
"requiredTokenId": "0",
"requiredTokenAddress": "KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn"
}
}
"recipient": "tz1d4649CmmMEzXBWzhTgTkFxy9ATNhb5HC3",
"SwapAmount": "1000000000000000000"
}
The Michelson output when I interact with the contract on Better-Call.dev is
Pair
{ Elt 0
(Pair (Pair "KT1UNBvCJXiwJY6tmHM7CJUVwNPew53XkSfh" 10)
(Pair "KT1GRSvLoikDsXujKgZPsGLX8k8VvR2Tq95b" 0)) ;
Elt 1
(Pair (Pair "KT1HaDP8fRW7kavK2beST7o4RvzuvZbn5VwV" 10)
(Pair "KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn" 0)) }
(Pair 1 "tz1d4649CmmMEzXBWzhTgTkFxy9ATNhb5HC3")
That's why I'm using a MichelsonMap for the route and flat parameters.
Why is my exchangeAddress read as invalid ?