Skip to content

Commit 4000599

Browse files
Jorge-Lopesanilhelvaci
authored andcommitted
test: swap OSMO for BLD with receiver on Agoric
1 parent 9260a3c commit 4000599

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed

multichain-testing/scripts/create-osmosis-pool.sh

+56
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,59 @@ echo "Querying pool route ..."
186186
)
187187

188188
echo "Liquidity Pool open and stored on swaprouter successfully."
189+
190+
SET_REVERSE_ROUTE_JSON=$(jq -n \
191+
--arg tokenIn "$TOKEN_OUT_DENOM" \
192+
--arg tokenOut "$TOKEN_IN_DENOM" \
193+
--arg poolId "$POOL_ID" \
194+
'{
195+
set_route: {
196+
input_denom: $tokenIn,
197+
output_denom: $tokenOut,
198+
pool_route: [
199+
{
200+
pool_id: $poolId,
201+
token_out_denom: $tokenOut
202+
}
203+
]
204+
}
205+
}')
206+
207+
GET_REVERSE_ROUTE_JSON=$(jq -n \
208+
--arg tokenIn "$TOKEN_OUT_DENOM" \
209+
--arg tokenOut "$TOKEN_IN_DENOM" \
210+
'{
211+
"get_route": {
212+
"input_denom": $tokenIn,
213+
"output_denom": $tokenOut
214+
}
215+
}')
216+
217+
echo "Storing reverse pool on swaprouter contract ..."
218+
osmosis-exec tx wasm execute "$SWAPROUTER_ADDRESS" "$SET_REVERSE_ROUTE_JSON" --from "$SWAPROUTER_OWNER_ADDRESS" --chain-id osmosislocal --yes --fees 1000uosmo
219+
220+
echo "Querying reverse pool route ..."
221+
(
222+
set +e # handle failure of "osmosis-exec query wasm contract-state smart"
223+
224+
for ((i = 1; i <= MAX_RETRIES; i++)); do
225+
echo "Attempt $i of $MAX_RETRIES..."
226+
pool_route_json=$(osmosis-exec query wasm contract-state smart "$SWAPROUTER_ADDRESS" "$GET_REVERSE_ROUTE_JSON" 2> /dev/null)
227+
228+
if [[ $? -eq 0 ]]; then
229+
echo "Pool route found:"
230+
echo "$pool_route_json"
231+
break
232+
fi
233+
234+
if [[ $i -eq MAX_RETRIES ]]; then
235+
echo "Pool not stored after $MAX_RETRIES attempts."
236+
exit 1
237+
fi
238+
239+
echo "Query failed. Waiting $DELAY seconds before retrying..."
240+
sleep "$DELAY"
241+
done
242+
)
243+
244+
echo "Reverse liquidity Pool open and stored on swaprouter successfully."

multichain-testing/test/xcs-swap-anything/swap-anything.test.ts

+85
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,91 @@ test.serial('BLD for OSMO, receiver on Agoric', async t => {
166166
);
167167
});
168168

169+
test.serial('OSMO for BLD, receiver on Agoric', async t => {
170+
const {
171+
wallets,
172+
provisionSmartWallet,
173+
vstorageClient,
174+
retryUntilCondition,
175+
useChain,
176+
} = t.context;
177+
178+
// Provision the Agoric smart wallet
179+
const agoricAddr = wallets.agoricReceiver;
180+
const wdUser = await provisionSmartWallet(agoricAddr, {
181+
BLD: 1000n,
182+
IST: 1000n,
183+
});
184+
t.log(`Provisioned Agoric smart wallet for ${agoricAddr}`);
185+
186+
const { swapAddress } = await getXcsContractsAddress();
187+
188+
const doOffer = makeDoOffer(wdUser);
189+
190+
// Verify deposit
191+
const apiUrl = await useChain('agoric').getRestEndpoint();
192+
const queryClient = makeQueryClient(apiUrl);
193+
194+
const brands = await vstorageClient.queryData('published.agoricNames.brand');
195+
const bldBrand = Object.fromEntries(brands).OSMO;
196+
const swapInAmount = AmountMath.make(bldBrand, 75n);
197+
const { balances: balancesBefore } = await queryClient.queryBalances(
198+
wallets.agoricReceiver,
199+
);
200+
201+
const osmosisApiUrl = await useChain('osmosis').getRestEndpoint();
202+
const osmosisQueryClient = makeQueryClient(osmosisApiUrl);
203+
204+
const agoricChainId = useChain('agoric').chain.chain_id;
205+
206+
const {
207+
transferChannel: { channelId },
208+
} = starshipChainInfo.osmosis.connections[agoricChainId];
209+
210+
const { hash: outDenomHash } = await osmosisQueryClient.queryDenom(
211+
`transfer/${channelId}`,
212+
'ubld',
213+
);
214+
215+
// Send swap offer
216+
const makeAccountOfferId = `swap-ubld-uosmo-${Date.now()}`;
217+
await doOffer({
218+
id: makeAccountOfferId,
219+
invitationSpec: {
220+
source: 'agoricContract',
221+
instancePath: [contractName],
222+
callPipe: [['makeSendInvitation']],
223+
},
224+
offerArgs: {
225+
// TODO: get the contract address dynamically
226+
destAddr: swapAddress,
227+
receiverAddr: wallets.agoricReceiver,
228+
outDenom: `ibc/${outDenomHash}`,
229+
slippage: { slippagePercentage: '20', windowSeconds: 10 },
230+
onFailedDelivery: 'do_nothing',
231+
},
232+
proposal: { give: { Send: swapInAmount } },
233+
});
234+
235+
const { balances: agoricReceiverBalances } = await retryUntilCondition(
236+
() => queryClient.queryBalances(wallets.agoricReceiver),
237+
({ balances }) => {
238+
const balancesBeforeAmount = BigInt(balancesBefore[0]?.amount || 0);
239+
const currentBalanceAmount = BigInt(balances[0]?.amount || 0);
240+
return currentBalanceAmount < balancesBeforeAmount;
241+
},
242+
'Deposit reflected in localOrchAccount balance',
243+
);
244+
t.log(agoricReceiverBalances);
245+
246+
t.assert(
247+
BigInt(balancesBefore[0].amount) > BigInt(agoricReceiverBalances[0].amount),
248+
);
249+
t.assert(
250+
BigInt(balancesBefore[1].amount) < BigInt(agoricReceiverBalances[1].amount),
251+
);
252+
});
253+
169254
test.serial('BLD for OSMO, receiver on CosmosHub', async t => {
170255
const {
171256
wallets,

0 commit comments

Comments
 (0)