|
| 1 | +import anyTest from '@endo/ses-ava/prepare-endo.js'; |
| 2 | +import type { TestFn } from 'ava'; |
| 3 | +import { makeDoOffer } from '../../tools/e2e-tools.js'; |
| 4 | +import { |
| 5 | + commonSetup, |
| 6 | + type SetupContextWithWallets, |
| 7 | +} from '../support.js'; |
| 8 | +import { AmountMath } from '@agoric/ertp'; |
| 9 | +import { makeQueryClient } from '../../tools/query.js'; |
| 10 | + |
| 11 | +const test = anyTest as TestFn<SetupContextWithWallets>; |
| 12 | + |
| 13 | +const accounts = ['agoricSender', 'agoricReceiver']; |
| 14 | + |
| 15 | +const contractName = 'swapAnything'; |
| 16 | +const contractBuilder = |
| 17 | + '../packages/builders/scripts/testing/init-swap-anything.js'; |
| 18 | + |
| 19 | +test.before(async t => { |
| 20 | + const { setupTestKeys, ...common } = await commonSetup(t); |
| 21 | + const { commonBuilderOpts, deleteTestKeys, startContract } = common; |
| 22 | + await deleteTestKeys(accounts).catch(); |
| 23 | + const wallets = await setupTestKeys(accounts); |
| 24 | + console.log('WALLETS', wallets); |
| 25 | + t.context = { ...common, wallets }; |
| 26 | + await startContract(contractName, contractBuilder, commonBuilderOpts); |
| 27 | +}); |
| 28 | + |
| 29 | +test('BLD for OSMO, receiver on Agoric', async t => { |
| 30 | + const { |
| 31 | + wallets, |
| 32 | + provisionSmartWallet, |
| 33 | + vstorageClient, |
| 34 | + retryUntilCondition, |
| 35 | + useChain, |
| 36 | + } = t.context; |
| 37 | + |
| 38 | + // Provision the Agoric smart wallet |
| 39 | + const agoricAddr = wallets.agoricSender; |
| 40 | + const wdUser = await provisionSmartWallet(agoricAddr, { |
| 41 | + BLD: 1000n, |
| 42 | + IST: 1000n, |
| 43 | + }); |
| 44 | + t.log(`Provisioned Agoric smart wallet for ${agoricAddr}`); |
| 45 | + |
| 46 | + // const osmosisChainId = useChain('osmosis').chain.chain_id; |
| 47 | + |
| 48 | + // const { |
| 49 | + // transferChannel: { counterPartyChannelId, channelId }, |
| 50 | + // } = starshipChainInfo.agoric.connections[osmosisChainId]; |
| 51 | + |
| 52 | + const doOffer = makeDoOffer(wdUser); |
| 53 | + |
| 54 | + // Verify deposit |
| 55 | + const apiUrl = await useChain('agoric').getRestEndpoint(); |
| 56 | + const queryClient = makeQueryClient(apiUrl); |
| 57 | + |
| 58 | + const brands = await vstorageClient.queryData('published.agoricNames.brand'); |
| 59 | + const bldBrand = Object.fromEntries(brands).BLD; |
| 60 | + const swapInAmount = AmountMath.make(bldBrand, 125n); |
| 61 | + const { balances: balancesBefore } = await queryClient.queryBalances( |
| 62 | + wallets.agoricReceiver, |
| 63 | + ); |
| 64 | + |
| 65 | + // Send swap offer |
| 66 | + const makeAccountOfferId = `swap-ubld-uosmo-${Date.now()}`; |
| 67 | + await doOffer({ |
| 68 | + id: makeAccountOfferId, |
| 69 | + invitationSpec: { |
| 70 | + source: 'agoricContract', |
| 71 | + instancePath: [contractName], |
| 72 | + callPipe: [['makeSendInvitation']], |
| 73 | + }, |
| 74 | + offerArgs: { |
| 75 | + destAddr: 'osmo1ufs3tlq4umljk0qfe8k5ya0x6hpavn897u2cnf9k0en9jr7qarqq7fzxcr', |
| 76 | + receiverAddr: wallets.agoricReceiver, |
| 77 | + outDenom: 'uosmo', |
| 78 | + slippage: { slippagePercentage: '20', windowSeconds: 10 }, |
| 79 | + onFailedDelivery: 'do_nothing', |
| 80 | + }, |
| 81 | + proposal: { give: { Send: swapInAmount } }, |
| 82 | + }); |
| 83 | + |
| 84 | + const agoricReceiverBalance = await retryUntilCondition( |
| 85 | + () => queryClient.queryBalances(wallets.agoricReceiver), |
| 86 | + ({ balances }) => balances.length > balancesBefore.length, |
| 87 | + 'Deposit reflected in localOrchAccount balance', |
| 88 | + ); |
| 89 | + t.log(agoricReceiverBalance); |
| 90 | + |
| 91 | + t.pass(); |
| 92 | +}); |
| 93 | + |
| 94 | +test.after(async t => { |
| 95 | + const { deleteTestKeys } = t.context; |
| 96 | + deleteTestKeys(accounts); |
| 97 | +}); |
0 commit comments