Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] implementing delegate in contract, and submitting offer to handler from UI #28

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
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
16 changes: 10 additions & 6 deletions contract/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ATOM_DENOM=ibc/BA313C4A19DFBF943586C0387E6B11286F9E416B4DD27574E6909CABE0E342FA
ATOM=000000$(ATOM_DENOM)

# your deployer address made from make add-address
ADDR=agoric1mqvg26gpv6xzch2v0wpv569md3c2z4cdxq9clz
ADDR=agoric1aj5atgepztuv6qpl4a6993tvzthq4gdtvmgptj
PROVISION_POOL_ADDR=agoric1megzytg65cyrgzs6fvzxgrcqvwwl7ugpt62346

PROPOSAL=1
Expand Down Expand Up @@ -152,8 +152,13 @@ fund: fund-provision-pool check-balance
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd tx bank send faucet ${CLIENTADDR} 10000000000000uist -y;
make fund-osmo

fund-osmo:
fund-osmo: fund-osmo-ibc
kubectl exec -i osmosislocal-genesis-0 -c validator -- osmosisd tx bank send faucet ${CLIENT_OSMO_ADDR} 9870000000uosmo --fees 1000uosmo -y;

fund-osmo-ibc:
kubectl exec -i osmosislocal-genesis-0 -c validator -- osmosisd tx ibc-transfer transfer transfer channel-0 ${CLIENTADDR} 1000000uosmo --from faucet --chain-id osmosislocal --node http://127.0.0.1:26657 --fees 5000uosmo -y;
kubectl exec -i osmosislocal-genesis-0 -c validator -- osmosisd tx ibc-transfer transfer transfer channel-1 ${CLIENTADDR} 1000000uosmo --from faucet --chain-id osmosislocal --node http://127.0.0.1:26657 --fees 5000uosmo -y;

check-balance:
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd q bank balances $(ADDR)
fund-wallet:
Expand Down Expand Up @@ -259,10 +264,9 @@ e2e:
make copy-project
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn install"
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn add @endo/[email protected]"
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn add @agoric/[email protected]"
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn add @agoric/[email protected]"
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn add @agoric/[email protected]"
make copy-bn-js
# kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn add @agoric/[email protected]"
# kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn add @agoric/[email protected]"
# kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn add @agoric/[email protected]"
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn build:deployer"
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn node scripts/deploy-contract.js --install src/orca.contract.js --eval src/orca.proposal.js"
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn node scripts/deploy-contract.js --install src/orca.contract.js --eval src/orca.proposal.js"
Expand Down
112 changes: 11 additions & 101 deletions contract/src/orca.contract.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { AmountShape } from '@agoric/ertp';
import { makeTracer } from '@agoric/internal';
import { withOrchestration } from '@agoric/orchestration/src/utils/start-helper.js';
import { atomicTransfer } from '@agoric/zoe/src/contractSupport/index.js';
import { InvitationShape } from '@agoric/zoe/src/typeGuards.js';
import { Fail } from '@endo/errors';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import * as flows from './orca.flows.js';

Expand Down Expand Up @@ -73,110 +70,14 @@ const contract = async (
zcf,
privateArgs,
zone,
{ orchestrateAll, vowTools, zoeTools },
{ orchestrateAll, zoeTools },
) => {
trace('inside start function: v1.1.95');
trace('privateArgs', privateArgs);

const wrapper = () => {
const transfer = vowTools.retriable(
zone,
'transfer',
/**
* @type {Transfer}
*/
async (
srcSeat,
localAccount,
remoteAccount,
give,
amt,
localAddress,
remoteAddress,
) => {
!srcSeat.hasExited() || Fail`The seat cannot have exited.`;
const { zcfSeat: tempSeat, userSeat: userSeatP } =
zcf.makeEmptySeatKit();
trace('tempSeat:', tempSeat);
const userSeat = await userSeatP;
trace('userSeat:', userSeat);
trace('storageNode', privateArgs.storageNode);
atomicTransfer(zcf, srcSeat, tempSeat, give);
tempSeat.exit();

const pmt = await E(userSeat).getPayout('Deposit');
trace('pmt:', pmt);
trace('amt:', amt);

// NOTE: with watch
// const promises = Object.entries(give).map(async ([kw, _amount]) => {
// trace("kw::", kw)
// trace("_amount", _amount)
// trace("amt", amt)
// });
// const watcher = zone.exo(
// `watcher-transfer-${localAddress.value}-to-${remoteAddress.value}`, // Error: key (a string) has already been used in this zone and incarnation -- perhaps use timestamp or offerid as well?
// M.interface('watcher for transfer', {
// onFulfilled: M.call(M.any()).optional(M.any()).returns(VowShape),
// }
// ),
// {
// /**
// * @param {any} _result
// * @param {bigint} value
// */
// onFulfilled(
// _result,
// value
// ) {
// trace("inside onFulfilled:", value)
// return watch(localAccount.transfer(
// {
// denom: "ubld",
// value: value/2n,
// },
// remoteAddress
// ))
// },
// },
// );
// trace("about to watch transfer, watcher v0.16")
// trace("watcher", watcher)
// watch(
// E(localAccount).deposit(pmt),
// watcher,
// BigInt(amt.value),
// );
// await Promise.all(promises);

// NOTE: without watcher
await E(localAccount).deposit(pmt);
await localAccount.transfer(
{
denom: 'ubld',
value: amt.value / 2n,
},
remoteAddress,
);

// const localAccountBalance = await localAccount.getBalance(amt.brand)
// const remoteAccountbalance = await remoteAccount.getBalance(amt.brand)
// trace("localaccount balance: ", localAccountBalance);
// trace("remoteaccount balance: ", remoteAccountbalance);
},
);
return harden({
transfer,
});
};

const wrap = wrapper();
trace('wrapper.transfer', wrapper);

// @ts-expect-error XXX ZCFSeat not Passable
const { makeAccount, makeCreateAndFund } = orchestrateAll(flows, {
const { makeAccount, makeCreateAndFund, makeFundAndDelegate } = orchestrateAll(flows, {
localTransfer: zoeTools.localTransfer,
transfer: wrap.transfer,
// write: E(storageNode).write),
// makeChildNode: E(storageNode).makeChildNode,
// setValue: E(storageNode).setValue,
Expand All @@ -188,6 +89,7 @@ const contract = async (
M.interface('Orca PF', {
makeAccountInvitation: M.callWhen().returns(InvitationShape),
makeCreateAndFundInvitation: M.callWhen().returns(InvitationShape),
makeFundAndDelegateInvitation: M.callWhen().returns(InvitationShape)
}),
{
makeAccountInvitation() {
Expand All @@ -201,6 +103,14 @@ const contract = async (
M.splitRecord({ give: SingleAmountRecord }),
);
},
makeFundAndDelegateInvitation() {
return zcf.makeInvitation(
makeFundAndDelegate,
'Make an Orchestration Account, and Fund it',
undefined,
M.splitRecord({ give: SingleAmountRecord })
)
}
},
);

Expand Down
83 changes: 73 additions & 10 deletions contract/src/orca.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ harden(makeAccount);
*
* @param {Orchestrator} orch
* @param {object} ctx
* @param {Transfer} ctx.transfer
* @param {ZoeTools['localTransfer']} ctx.localTransfer
* @param {StorageNode['setValue']} ctx.setValue
* @param {ZCFSeat} seat
* @param {{ chainName: string }} offerArgs
*/
export const makeCreateAndFund = async (
orch,
{
transfer,
localTransfer,
// write,
// makeChildNode,
setValue,
Expand Down Expand Up @@ -100,17 +100,80 @@ export const makeCreateAndFund = async (
trace('remoteAddress', remoteAddress);
trace('fund new orch account');
trace('seat', seat);
trace('transfer', transfer);
await transfer(
seat,
localAccount,
remoteAccount,
give,
amt,
localAddress,
await localTransfer(seat, localAccount, give);
await localAccount.transfer(
{
denom: 'ubld',
value: amt.value / 2n,
},
remoteAddress,
);
seat.exit();
return remoteAccount.asContinuingOffer();
};
harden(makeCreateAndFund);

/**
* Create an account on a Cosmos chain, transfer funds to it, and delegate
*
* @param {Orchestrator} orch
* @param {object} ctx
* @param {ZoeTools['localTransfer']} ctx.localTransfer
* @param {StorageNode['setValue']} ctx.setValue
* @param {ZCFSeat} seat
* @param {{ chainName: string, validator: string }} offerArgs
*/
export const makeFundAndDelegate = async (
orch,
{
localTransfer,
// write,
// makeChildNode,
setValue,
},
seat,
{ chainName, validator },
) => {

trace('inside makeFundAndDelegate')
const { give } = seat.getProposal();
const [[_kw, amt]] = Object.entries(give);
trace('_kw', _kw);
trace('amt', amt);
trace('give:', give);
trace("chainName:", chainName)
trace("validator:", validator)
const [agoric, chain] = await Promise.all([
orch.getChain('agoric'),
orch.getChain(chainName),
]);

const info = await chain.getChainInfo();
trace('chain info', info);
const assets = await agoric.getVBankAssetInfo();
trace('fetched assets:', assets);
const localAccount = await agoric.makeAccount();
trace('localAccount', localAccount);
const remoteAccount = await chain.makeAccount();
trace('remoteAccount', remoteAccount);
const [localAddress, remoteAddress] = await Promise.all([
localAccount.getAddress(),
remoteAccount.getAddress(),
]);

await localTransfer(seat, localAccount, give);
await localAccount.transfer(
{
denom: amt.brand,
value: amt.value / 2n,
},
remoteAddress,
);
await remoteAccount.delegate(validator, {
brand: amt.brand,
value: 1n
});
seat.exit();
return remoteAccount.asContinuingOffer();
};
harden(makeFundAndDelegate);
Loading
Loading