@@ -166,6 +166,91 @@ test.serial('BLD for OSMO, receiver on Agoric', async t => {
166
166
) ;
167
167
} ) ;
168
168
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
+
169
254
test . serial ( 'BLD for OSMO, receiver on CosmosHub' , async t => {
170
255
const {
171
256
wallets,
0 commit comments