You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Update send-anywhere.md
Various discrepancies have crept in between the docs and the code. This updates to match the code in agoric-sdk.
* chore: make lint happy
Copy file name to clipboardExpand all lines: main/guides/orchestration/contract-walkthroughs/send-anywhere.md
+32-26Lines changed: 32 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ The high-level flow of the contract is:
10
10
- Creates or ensures the existence of a local account (held by the contract) to handle temporary holding.
11
11
- Transfers the asset from the source address to the local account.
12
12
- Initiates a transfer to the destination address, which could reside on the remote blockchain.
13
-
- Gracefully handles the failures.
13
+
- Gracefully handles failures.
14
14
15
15
The contract is implemented in two separate files:
16
16
@@ -24,12 +24,12 @@ Let us walk through these files one by one.
24
24
25
25
The contract begins by importing various modules and utilities necessary for its functionality. These include:
26
26
27
-
-**State management**: `makeSharedStateRecord` is imported to create and manage the state across contract incarnations.
28
-
-**Type validation**: `AmountShape` and `InvitationShape` ensure that the contract works with correct data types, such as amounts and invitations.
27
+
-**State management**: `makeSharedStateRecord` is imported to create and manage state across contract incarnations.
28
+
-**Type validation**: `AnyNatAmountShape` and `InvitationShape` ensure that the contract works with correct data types, such as amounts and invitations.
29
29
-**Orchestration utilities**: `withOrchestration` is imported to facilitate interactions with Orchestration functions.
30
30
-**Flows**: The Orchestration flows for handling transfers are imported from `send-anywhere.flows.js` to be made available to Zoe.
31
31
32
-
These imports set up the contract for the validation, orchestration, and execution of transfers through Zoe API.
32
+
These imports set up the contract for the validation, orchestration, and execution of transfers through the Zoe API.
33
33
34
34
### Single Amount Record Validation
35
35
@@ -52,16 +52,14 @@ This validation ensures that the proposal shape submitted by users contains exac
52
52
The contract defines a shared state record as below:
This state keeps track of the local account that will hold the transferred assets temporarily before they are sent to the destination
63
-
address. The state starts with an undefined `localAccount`. This account will be created later during the offer handling process if
64
-
needed.
60
+
`sharedLocalAccountP` stores the local account that will hold the transferred assets temporarily before they
61
+
are sent to the destination address. Since this is initialized with a promise (`makeOnce` returns a promise, so
62
+
we add a `P` to the variable name), uses of `sharedLocalAccountP` will have to await it before making use of it.
65
63
66
64
### Logging setup
67
65
@@ -81,8 +79,8 @@ these functions with the necessary context (such as the contract state, logging,
81
79
82
80
```js
83
81
constorchFns=orchestrateAll(flows, {
84
-
contractState,
85
82
log,
83
+
sharedLocalAccountP,
86
84
zoeTools
87
85
});
88
86
```
@@ -111,7 +109,7 @@ const publicFacet = zone.exo(
111
109
```
112
110
113
111
The `makeSendInvitation` method creates an invitation for users, allowing them to initiate a transfer by submitting a proposal. The
114
-
proposal must match the structure defined by the `SingleNatAmountRecord`, ensuring that only one asset is transferred per transaction.
112
+
proposal must match the structure defined by `SingleNatAmountRecord`, ensuring that only one asset is transferred per transaction.
115
113
The invitation is connected to the `sendIt` function (explained later), which performs the asset transfer.
116
114
117
115
## 2. `send-anywhere.flows.js`
@@ -122,22 +120,26 @@ remote chains. The parameters passed to this function include:
122
120
123
121
-`orch`: The orchestrator object for managing chain/account interactions.
124
122
-`ctx`: The contract state and utility functions, including:
125
-
-`contractState`: Holds the local account for intermediate storage.
126
-
-`localTransfer`: The transfer function for moving assets between local accounts.
123
+
-`sharedLocalAccountP`: Holds the local account for intermediate storage.
124
+
-`log`: access to logging
125
+
- zoeTools: Helper functions for transferring assets. Contains
126
+
-`localTransfer`: Support for moving assets between local accounts.
127
+
-`withdrawToSeat`: Support for moving assets from a local account to an account on a remote chain.
127
128
-`seat`: The Zoe seat representing the assets to be transferred.
128
129
-`offerArgs`: Includes details about the destination chain and address.
129
130
130
-
The `sendIt` function performs following important steps:
131
+
The `sendIt` function performs the following important steps:
131
132
132
133
### Offer Validation and Setup
133
134
134
135
Upon receiving an offer, the `sendIt` function:
135
136
136
137
- Validates the offer arguments using [endo's pattern-matching library](https://github.com/endojs/endo/tree/master/packages/patterns) to ensure the correct structure is submitted.
137
-
- Retrieves the `proposal` from the seat, extracting the asset (`brand` and `amount`) being transferred.
138
-
- The contract ensures that the asset brand is registered on the local chain by querying the chain’s asset registry (`vbank`). If not
139
-
the contract throws an error and exits the transaction.
140
-
- If a local account for the contract doesn’t already exist, the function creates one.
138
+
- Retrieves the `proposal` from the seat, extracting (from `give`) the asset (`brand` and `amount`) being transferred.
139
+
- The contract ensures that the asset brand is registered on the local chain by querying the chain’s asset registry
140
+
(`vbank`). If not the contract throws an error and exits the transaction. It also gets the `denom` for the
0 commit comments