Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions packages/client-utils/src/signing-smart-wallet-kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type { SmartWalletKit } from './smart-wallet-kit.js';
import type { RetryOptionsAndPowers } from './sync-tools.js';

type TxOptions = RetryOptionsAndPowers & {
fee?: StdFee;
sendOnly?: boolean;
makeNonce?: () => string;
};
Expand Down Expand Up @@ -137,14 +138,21 @@ export const makeSigningSmartWalletKit = async (
return client.broadcastTx(txBytes);
};

const executeOffer = async (offer: OfferSpec): Promise<OfferStatus> => {
const executeOffer = async (
offer: OfferSpec,
fee?: StdFee,
memo?: string,
signerData?: SignerData,
): Promise<OfferStatus> => {
const offerP = swk.pollOffer(address, offer.id);

// Await for rejection handling
await sendBridgeAction({
method: 'executeOffer',
offer,
});
await sendBridgeAction(
{ method: 'executeOffer', offer },
fee,
memo,
signerData,
);

return offerP;
};
Expand Down Expand Up @@ -180,7 +188,7 @@ export const reflectWalletStore = (
) => {
const combinedOpts = { ...baseTxOpts, ...overrides } as TxOptions;
combinedOpts.setTimeout || Fail`missing setTimeout`;
const { sendOnly, makeNonce, ...retryOpts } = combinedOpts;
const { fee, sendOnly, makeNonce, ...retryOpts } = combinedOpts;
if (forSavingResults && !makeNonce && !sendOnly) {
throw Fail`makeNonce is required without sendOnly: true (to create an awaitable message id)`;
}
Expand All @@ -206,10 +214,10 @@ export const reflectWalletStore = (
args,
...(saveResult ? { saveResult } : undefined),
});
const tx = await sswk.sendBridgeAction({
method: 'invokeEntry',
message,
});
const tx = await sswk.sendBridgeAction(
{ method: 'invokeEntry', message },
fee,
);
if (tx.code !== 0) {
throw Error(tx.rawLog);
}
Expand Down Expand Up @@ -239,22 +247,24 @@ export const reflectWalletStore = (
overwrite?: boolean;
};
const {
fee,
sendOnly: _sendOnly,
makeNonce,
overwrite = true,
...retryOpts
} = combinedOpts;
if (!makeNonce) throw Fail`missing makeNonce`;
const id = `${description}.${makeNonce()}`;
const tx = await sswk.sendBridgeAction({
method: 'executeOffer',
offer: {
id,
invitationSpec: { source: 'purse', instance, description },
proposal: {},
saveResult: { name, overwrite },
},
});
const offer: OfferSpec = {
id,
invitationSpec: { source: 'purse', instance, description },
proposal: {},
saveResult: { name, overwrite },
};
const tx = await sswk.sendBridgeAction(
{ method: 'executeOffer', offer },
fee,
);
const status = await getOfferResult(
id,
sswk.query.getLastUpdate,
Expand Down
4 changes: 4 additions & 0 deletions services/ymax-planner/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ export const main = async (
const walletStore = reflectWalletStore(signingSmartWalletKit, {
setTimeout,
makeNonce: () => new Date(now()).toISOString(),
fee: {
amount: [{ denom: 'ubld', amount: '15000' }], // 0.015 BLD
gas: '19700000',
},
});

const spectrum = new SpectrumClient(simplePowers, {
Expand Down
8 changes: 7 additions & 1 deletion services/ymax-planner/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type SigningSmartWalletKit } from '@agoric/client-utils';
import type { OfferSpec } from '@agoric/smart-wallet/src/offers';
import type { TxStatus } from '@aglocal/portfolio-contract/src/resolver/constants.js';
import type { TxId } from '@aglocal/portfolio-contract/src/resolver/types';
import type { StdFee } from '@cosmjs/stargate';

type ResolveTxParams = {
signingSmartWalletKit: SigningSmartWalletKit;
Expand All @@ -10,6 +11,11 @@ type ResolveTxParams = {
proposal?: object;
};

const smartWalletFee: StdFee = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question

Is there a better file to put this constant in so both planner and resolver can use it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect the planner and resolver to become less integrated, not more. So this is fine.

amount: [{ denom: 'ubld', amount: '15000' }], // 0.015 BLD
gas: '19700000',
};

const getInvitationMakers = async (wallet: SigningSmartWalletKit) => {
const getCurrentWalletRecord = await wallet.query.getCurrentWalletRecord();
const invitation = getCurrentWalletRecord.offerToUsedInvitation
Expand Down Expand Up @@ -49,6 +55,6 @@ export const resolvePendingTx = async ({
proposal,
});

const result = await signingSmartWalletKit.executeOffer(action);
const result = await signingSmartWalletKit.executeOffer(action, smartWalletFee);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question

I only found the place where we're using executeOffer in resolver, but I was not able to find where we're using executeOffer under services/ymax-planner folder

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ymax-planner uses invokeEntry, wrapped in reflectWalletStore:

const planner = walletStore.get<PortfolioPlanner>('planner', {
sendOnly: true,
});
const { tx, id } = await planner.resolvePlan(
portfolioId,
flowId,
steps,
policyVersion,
rebalanceCount,
);

The fee could either be passed in to reflectWalletStore:

const walletStore = reflectWalletStore(signingSmartWalletKit, {
setTimeout,
makeNonce: () => new Date(now()).toISOString(),
});

Or another idea would be to add a signingSmartWalletKit.withFee(fee) method, much like cmdRunner.withEnv(...)

withEnv: env =>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LuqiPan I pushed a couple of commits; f6d30c8 extending wallet store reflection to support specifying a fee and f92e699 taking advantage of it in ymax-planner (but limited the extension to just fee while @dckc and I work out #12055 (comment) ). But feel free to tweak further as needed.

return result;
};
Loading