@agoric/fast-usdc 0.2.0-upgrade-19-dev-0754752.0 → 0.2.0-upgrade-18a-dev-4ee0508.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +25 -26
- package/src/cli/cli.js +1 -1
- package/src/cli/config-commands.js +1 -1
- package/src/cli/config.js +1 -1
- package/src/cli/lp-commands.js +39 -21
- package/src/cli/operator-commands.js +0 -1
- package/src/cli/transfer.js +5 -5
- package/src/exos/advancer.js +41 -109
- package/src/exos/liquidity-pool.js +34 -81
- package/src/exos/operator-kit.js +2 -0
- package/src/exos/settler.js +95 -154
- package/src/exos/status-manager.js +59 -97
- package/src/exos/transaction-feed.js +9 -30
- package/src/fast-usdc-policy.core.js +12 -2
- package/src/fast-usdc.contract.js +31 -23
- package/src/{start-fast-usdc.core.js → fast-usdc.start.js} +81 -13
- package/src/pool-share-math.js +9 -55
- package/src/type-guards.js +8 -37
- package/src/types.ts +5 -34
- package/src/utils/deploy-config.js +75 -36
- package/src/utils/fees.js +4 -3
- package/src/add-operators.core.js +0 -63
- package/src/clientSupport.js +0 -98
- package/src/distribute-fees.core.js +0 -93
- package/src/main.js +0 -1
- package/src/utils/chain-policies.js +0 -140
- package/src/utils/core-eval.js +0 -73
- /package/src/{cli/util → util}/agoric.js +0 -0
- /package/src/{cli/util → util}/bank.js +0 -0
- /package/src/{cli/util → util}/cctp.js +0 -0
- /package/src/{cli/util → util}/file.js +0 -0
- /package/src/{cli/util → util}/noble.js +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/fast-usdc",
|
|
3
|
-
"version": "0.2.0-upgrade-
|
|
3
|
+
"version": "0.2.0-upgrade-18a-dev-4ee0508.0+4ee0508",
|
|
4
4
|
"description": "CLI and library for Fast USDC product",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"src",
|
|
9
9
|
"tools"
|
|
10
10
|
],
|
|
11
|
-
"main": "src/main.js",
|
|
12
11
|
"bin": {
|
|
13
12
|
"fast-usdc": "./src/cli/bin.js"
|
|
14
13
|
},
|
|
@@ -23,9 +22,9 @@
|
|
|
23
22
|
"lint:eslint": "eslint ."
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
|
-
"@agoric/swingset-liveslots": "0.10.3-upgrade-
|
|
27
|
-
"@agoric/vats": "0.16.0-upgrade-
|
|
28
|
-
"@agoric/zone": "0.3.0-upgrade-
|
|
25
|
+
"@agoric/swingset-liveslots": "0.10.3-upgrade-18a-dev-4ee0508.0+4ee0508",
|
|
26
|
+
"@agoric/vats": "0.16.0-upgrade-18a-dev-4ee0508.0+4ee0508",
|
|
27
|
+
"@agoric/zone": "0.3.0-upgrade-18a-dev-4ee0508.0+4ee0508",
|
|
29
28
|
"@fast-check/ava": "^2.0.1",
|
|
30
29
|
"ava": "^5.3.0",
|
|
31
30
|
"c8": "^10.1.2",
|
|
@@ -33,29 +32,29 @@
|
|
|
33
32
|
"ts-blank-space": "^0.4.4"
|
|
34
33
|
},
|
|
35
34
|
"dependencies": {
|
|
36
|
-
"@agoric/client-utils": "0.2.0-upgrade-
|
|
37
|
-
"@agoric/cosmic-proto": "0.5.0-upgrade-
|
|
38
|
-
"@agoric/ertp": "0.16.3-upgrade-
|
|
39
|
-
"@agoric/internal": "0.4.0-upgrade-
|
|
40
|
-
"@agoric/notifier": "0.7.0-upgrade-
|
|
41
|
-
"@agoric/orchestration": "0.2.0-upgrade-
|
|
42
|
-
"@agoric/store": "0.9.3-upgrade-
|
|
43
|
-
"@agoric/vat-data": "0.5.3-upgrade-
|
|
44
|
-
"@agoric/vow": "0.2.0-upgrade-
|
|
45
|
-
"@agoric/zoe": "0.
|
|
35
|
+
"@agoric/client-utils": "0.2.0-upgrade-18a-dev-4ee0508.0+4ee0508",
|
|
36
|
+
"@agoric/cosmic-proto": "0.5.0-upgrade-18a-dev-4ee0508.0+4ee0508",
|
|
37
|
+
"@agoric/ertp": "0.16.3-upgrade-18a-dev-4ee0508.0+4ee0508",
|
|
38
|
+
"@agoric/internal": "0.4.0-upgrade-18a-dev-4ee0508.0+4ee0508",
|
|
39
|
+
"@agoric/notifier": "0.7.0-upgrade-18a-dev-4ee0508.0+4ee0508",
|
|
40
|
+
"@agoric/orchestration": "0.2.0-upgrade-18a-dev-4ee0508.0+4ee0508",
|
|
41
|
+
"@agoric/store": "0.9.3-upgrade-18a-dev-4ee0508.0+4ee0508",
|
|
42
|
+
"@agoric/vat-data": "0.5.3-upgrade-18a-dev-4ee0508.0+4ee0508",
|
|
43
|
+
"@agoric/vow": "0.2.0-upgrade-18a-dev-4ee0508.0+4ee0508",
|
|
44
|
+
"@agoric/zoe": "0.26.3-upgrade-18a-dev-4ee0508.0+4ee0508",
|
|
46
45
|
"@cosmjs/proto-signing": "^0.32.4",
|
|
47
46
|
"@cosmjs/stargate": "^0.32.4",
|
|
48
47
|
"@endo/base64": "^1.0.9",
|
|
49
|
-
"@endo/common": "^1.2.
|
|
50
|
-
"@endo/errors": "^1.2.
|
|
51
|
-
"@endo/eventual-send": "^1.
|
|
52
|
-
"@endo/far": "^1.1.
|
|
53
|
-
"@endo/init": "^1.1.
|
|
54
|
-
"@endo/marshal": "^1.6.
|
|
55
|
-
"@endo/nat": "^5.0.
|
|
56
|
-
"@endo/pass-style": "^1.4.
|
|
57
|
-
"@endo/patterns": "^1.4.
|
|
58
|
-
"@endo/promise-kit": "^1.1.
|
|
48
|
+
"@endo/common": "^1.2.8",
|
|
49
|
+
"@endo/errors": "^1.2.8",
|
|
50
|
+
"@endo/eventual-send": "^1.2.8",
|
|
51
|
+
"@endo/far": "^1.1.9",
|
|
52
|
+
"@endo/init": "^1.1.7",
|
|
53
|
+
"@endo/marshal": "^1.6.2",
|
|
54
|
+
"@endo/nat": "^5.0.13",
|
|
55
|
+
"@endo/pass-style": "^1.4.7",
|
|
56
|
+
"@endo/patterns": "^1.4.7",
|
|
57
|
+
"@endo/promise-kit": "^1.1.8",
|
|
59
58
|
"@nick134-bit/noblejs": "0.0.2",
|
|
60
59
|
"bech32": "^2.0.0",
|
|
61
60
|
"commander": "^12.1.0",
|
|
@@ -82,5 +81,5 @@
|
|
|
82
81
|
"publishConfig": {
|
|
83
82
|
"access": "public"
|
|
84
83
|
},
|
|
85
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "4ee05088e5ada989a866a11ff65838d395505ce6"
|
|
86
85
|
}
|
package/src/cli/cli.js
CHANGED
|
@@ -13,7 +13,7 @@ import { addConfigCommands } from './config-commands.js';
|
|
|
13
13
|
import { addOperatorCommands } from './operator-commands.js';
|
|
14
14
|
import * as configLib from './config.js';
|
|
15
15
|
import transferLib from './transfer.js';
|
|
16
|
-
import { makeFile } from '
|
|
16
|
+
import { makeFile } from '../util/file.js';
|
|
17
17
|
import { addLPCommands } from './lp-commands.js';
|
|
18
18
|
|
|
19
19
|
const packageJson = JSON.parse(
|
package/src/cli/config.js
CHANGED
package/src/cli/lp-commands.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* eslint-env node */
|
|
2
2
|
/**
|
|
3
3
|
* @import {Command} from 'commander';
|
|
4
|
-
* @import {Amount, Brand} from '@agoric/ertp';
|
|
5
4
|
* @import {OfferSpec} from '@agoric/smart-wallet/src/offers.js';
|
|
6
5
|
* @import {ExecuteOfferAction} from '@agoric/smart-wallet/src/smartWallet.js';
|
|
7
6
|
* @import {USDCProposalShapes} from '../pool-share-math.js';
|
|
@@ -15,13 +14,11 @@ import { AmountMath } from '@agoric/ertp';
|
|
|
15
14
|
import {
|
|
16
15
|
assertParsableNumber,
|
|
17
16
|
ceilDivideBy,
|
|
18
|
-
floorDivideBy,
|
|
19
17
|
multiplyBy,
|
|
20
18
|
parseRatio,
|
|
21
19
|
} from '@agoric/zoe/src/contractSupport/ratio.js';
|
|
22
20
|
import { InvalidArgumentError } from 'commander';
|
|
23
21
|
import { outputActionAndHint } from './bridge-action.js';
|
|
24
|
-
import { Offers } from '../clientSupport.js';
|
|
25
22
|
|
|
26
23
|
export const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
27
24
|
|
|
@@ -84,27 +81,30 @@ export const addLPCommands = (
|
|
|
84
81
|
.action(async opts => {
|
|
85
82
|
swkP ||= loadSwk();
|
|
86
83
|
const swk = await swkP;
|
|
87
|
-
|
|
88
84
|
/** @type {Brand<'nat'>} */
|
|
89
85
|
// @ts-expect-error it doesnt recognize usdc as a Brand type
|
|
90
86
|
const usdc = swk.agoricNames.brand.USDC;
|
|
91
87
|
assert(usdc, 'USDC brand not in agoricNames');
|
|
92
88
|
|
|
93
|
-
/** @type {Brand<'nat'>} */
|
|
94
|
-
// @ts-expect-error it doesnt recognize FastLP as a Brand type
|
|
95
|
-
const poolShare = swk.agoricNames.brand.FastLP;
|
|
96
|
-
assert(poolShare, 'FastLP brand not in agoricNames');
|
|
97
|
-
|
|
98
89
|
const usdcAmount = parseUSDCAmount(opts.amount, usdc);
|
|
99
90
|
|
|
100
|
-
|
|
101
|
-
const
|
|
91
|
+
/** @type {USDCProposalShapes['deposit']} */
|
|
92
|
+
const proposal = {
|
|
93
|
+
give: {
|
|
94
|
+
USDC: usdcAmount,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
102
97
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
98
|
+
/** @type {OfferSpec} */
|
|
99
|
+
const offer = {
|
|
100
|
+
id: opts.offerId,
|
|
101
|
+
invitationSpec: {
|
|
102
|
+
source: 'agoricContract',
|
|
103
|
+
instancePath: ['fastUsdc'],
|
|
104
|
+
callPipe: [['makeDepositInvitation', []]],
|
|
105
|
+
},
|
|
106
|
+
proposal,
|
|
107
|
+
};
|
|
108
108
|
|
|
109
109
|
/** @type {ExecuteOfferAction} */
|
|
110
110
|
const bridgeAction = {
|
|
@@ -125,6 +125,7 @@ export const addLPCommands = (
|
|
|
125
125
|
.requiredOption('--amount <number>', 'USDC amount', parseDecimal)
|
|
126
126
|
.option('--offerId <string>', 'Offer id', String, `lpWithdraw-${now()}`)
|
|
127
127
|
.action(async opts => {
|
|
128
|
+
swkP ||= loadSwk();
|
|
128
129
|
swkP ||= loadSwk();
|
|
129
130
|
const swk = await swkP;
|
|
130
131
|
|
|
@@ -140,14 +141,31 @@ export const addLPCommands = (
|
|
|
140
141
|
|
|
141
142
|
const usdcAmount = parseUSDCAmount(opts.amount, usdc);
|
|
142
143
|
|
|
144
|
+
/** @type {import('../types.js').PoolMetrics} */
|
|
145
|
+
// @ts-expect-error it treats this as "unknown"
|
|
143
146
|
const metrics = await swk.readPublished('fastUsdc.poolMetrics');
|
|
144
147
|
const fastLPAmount = ceilDivideBy(usdcAmount, metrics.shareWorth);
|
|
145
148
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
/** @type {USDCProposalShapes['withdraw']} */
|
|
150
|
+
const proposal = {
|
|
151
|
+
give: {
|
|
152
|
+
PoolShare: fastLPAmount,
|
|
153
|
+
},
|
|
154
|
+
want: {
|
|
155
|
+
USDC: usdcAmount,
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/** @type {OfferSpec} */
|
|
160
|
+
const offer = {
|
|
161
|
+
id: opts.offerId,
|
|
162
|
+
invitationSpec: {
|
|
163
|
+
source: 'agoricContract',
|
|
164
|
+
instancePath: ['fastUsdc'],
|
|
165
|
+
callPipe: [['makeWithdrawInvitation', []]],
|
|
166
|
+
},
|
|
167
|
+
proposal,
|
|
168
|
+
};
|
|
151
169
|
|
|
152
170
|
outputActionAndHint(
|
|
153
171
|
{ method: 'executeOffer', offer },
|
|
@@ -96,7 +96,6 @@ export const addOperatorCommands = (
|
|
|
96
96
|
.requiredOption('--recipientAddress <string>', 'bech32 address', String)
|
|
97
97
|
.requiredOption('--blockHash <0xhex>', 'hex hash', parseHex)
|
|
98
98
|
.requiredOption('--blockNumber <number>', 'number', parseNat)
|
|
99
|
-
.requiredOption('--blockTimestamp <number>', 'number', parseNat)
|
|
100
99
|
.requiredOption('--chainId <string>', 'chain id', Number)
|
|
101
100
|
.requiredOption('--amount <number>', 'number', parseNat)
|
|
102
101
|
.requiredOption('--forwardingAddress <string>', 'bech32 address', String)
|
package/src/cli/transfer.js
CHANGED
|
@@ -7,16 +7,16 @@ import {
|
|
|
7
7
|
pickEndpoint,
|
|
8
8
|
} from '@agoric/client-utils';
|
|
9
9
|
import { encodeAddressHook } from '@agoric/cosmic-proto/address-hooks.js';
|
|
10
|
-
import { queryFastUSDCLocalChainAccount } from '
|
|
11
|
-
import { depositForBurn, makeProvider } from '
|
|
10
|
+
import { queryFastUSDCLocalChainAccount } from '../util/agoric.js';
|
|
11
|
+
import { depositForBurn, makeProvider } from '../util/cctp.js';
|
|
12
12
|
import {
|
|
13
13
|
makeSigner,
|
|
14
14
|
queryForwardingAccount,
|
|
15
15
|
registerFwdAccount,
|
|
16
|
-
} from '
|
|
17
|
-
import { queryUSDCBalance } from '
|
|
16
|
+
} from '../util/noble.js';
|
|
17
|
+
import { queryUSDCBalance } from '../util/bank.js';
|
|
18
18
|
|
|
19
|
-
/** @import { File } from '
|
|
19
|
+
/** @import { File } from '../util/file' */
|
|
20
20
|
/** @import { VStorage } from '@agoric/client-utils' */
|
|
21
21
|
/** @import { SigningStargateClient } from '@cosmjs/stargate' */
|
|
22
22
|
/** @import { JsonRpcProvider as ethProvider } from 'ethers' */
|
package/src/exos/advancer.js
CHANGED
|
@@ -16,14 +16,13 @@ import { makeFeeTools } from '../utils/fees.js';
|
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @import {HostInterface} from '@agoric/async-flow';
|
|
19
|
-
* @import {Amount, Brand} from '@agoric/ertp';
|
|
20
19
|
* @import {TypedPattern} from '@agoric/internal'
|
|
21
20
|
* @import {NatAmount} from '@agoric/ertp';
|
|
22
21
|
* @import {ChainAddress, ChainHub, Denom, OrchestrationAccount} from '@agoric/orchestration';
|
|
23
22
|
* @import {ZoeTools} from '@agoric/orchestration/src/utils/zoe-tools.js';
|
|
24
23
|
* @import {VowTools} from '@agoric/vow';
|
|
25
24
|
* @import {Zone} from '@agoric/zone';
|
|
26
|
-
* @import {AddressHook, EvmHash, FeeConfig, LogFn, NobleAddress, EvidenceWithRisk} from '../types.js';
|
|
25
|
+
* @import {CctpTxEvidence, AddressHook, EvmHash, FeeConfig, LogFn, NobleAddress, EvidenceWithRisk} from '../types.js';
|
|
27
26
|
* @import {StatusManager} from './status-manager.js';
|
|
28
27
|
* @import {LiquidityPoolKit} from './liquidity-pool.js';
|
|
29
28
|
*/
|
|
@@ -32,12 +31,12 @@ import { makeFeeTools } from '../utils/fees.js';
|
|
|
32
31
|
* @typedef {{
|
|
33
32
|
* chainHub: ChainHub;
|
|
34
33
|
* feeConfig: FeeConfig;
|
|
34
|
+
* localTransfer: ZoeTools['localTransfer'];
|
|
35
35
|
* log?: LogFn;
|
|
36
36
|
* statusManager: StatusManager;
|
|
37
37
|
* usdc: { brand: Brand<'nat'>; denom: Denom; };
|
|
38
38
|
* vowTools: VowTools;
|
|
39
39
|
* zcf: ZCF;
|
|
40
|
-
* zoeTools: ZoeTools;
|
|
41
40
|
* }} AdvancerKitPowers
|
|
42
41
|
*/
|
|
43
42
|
|
|
@@ -64,21 +63,12 @@ const AdvancerKitI = harden({
|
|
|
64
63
|
onRejected: M.call(M.error(), AdvancerVowCtxShape).returns(),
|
|
65
64
|
}),
|
|
66
65
|
transferHandler: M.interface('TransferHandlerI', {
|
|
66
|
+
// TODO confirm undefined, and not bigint (sequence)
|
|
67
67
|
onFulfilled: M.call(M.undefined(), AdvancerVowCtxShape).returns(
|
|
68
68
|
M.undefined(),
|
|
69
69
|
),
|
|
70
70
|
onRejected: M.call(M.error(), AdvancerVowCtxShape).returns(M.undefined()),
|
|
71
71
|
}),
|
|
72
|
-
withdrawHandler: M.interface('WithdrawHandlerI', {
|
|
73
|
-
onFulfilled: M.call(M.undefined(), {
|
|
74
|
-
advanceAmount: AnyNatAmountShape,
|
|
75
|
-
tmpReturnSeat: M.remotable(),
|
|
76
|
-
}).returns(M.undefined()),
|
|
77
|
-
onRejected: M.call(M.error(), {
|
|
78
|
-
advanceAmount: AnyNatAmountShape,
|
|
79
|
-
tmpReturnSeat: M.remotable(),
|
|
80
|
-
}).returns(M.undefined()),
|
|
81
|
-
}),
|
|
82
72
|
});
|
|
83
73
|
|
|
84
74
|
/**
|
|
@@ -91,14 +81,6 @@ const AdvancerKitI = harden({
|
|
|
91
81
|
* }} AdvancerVowCtx
|
|
92
82
|
*/
|
|
93
83
|
|
|
94
|
-
export const stateShape = harden({
|
|
95
|
-
notifier: M.remotable(),
|
|
96
|
-
borrower: M.remotable(),
|
|
97
|
-
poolAccount: M.remotable(),
|
|
98
|
-
intermediateRecipient: M.opt(ChainAddressShape),
|
|
99
|
-
settlementAddress: M.opt(ChainAddressShape),
|
|
100
|
-
});
|
|
101
|
-
|
|
102
84
|
/**
|
|
103
85
|
* @param {Zone} zone
|
|
104
86
|
* @param {AdvancerKitPowers} caps
|
|
@@ -108,12 +90,12 @@ export const prepareAdvancerKit = (
|
|
|
108
90
|
{
|
|
109
91
|
chainHub,
|
|
110
92
|
feeConfig,
|
|
93
|
+
localTransfer,
|
|
111
94
|
log = makeTracer('Advancer', true),
|
|
112
95
|
statusManager,
|
|
113
96
|
usdc,
|
|
114
97
|
vowTools: { watch, when },
|
|
115
98
|
zcf,
|
|
116
|
-
zoeTools: { localTransfer, withdrawToSeat },
|
|
117
99
|
},
|
|
118
100
|
) => {
|
|
119
101
|
assertAllDefined({
|
|
@@ -132,8 +114,8 @@ export const prepareAdvancerKit = (
|
|
|
132
114
|
AdvancerKitI,
|
|
133
115
|
/**
|
|
134
116
|
* @param {{
|
|
135
|
-
*
|
|
136
|
-
*
|
|
117
|
+
* notifyFacet: import('./settler.js').SettlerKit['notify'];
|
|
118
|
+
* borrowerFacet: LiquidityPoolKit['borrower'];
|
|
137
119
|
* poolAccount: HostInterface<OrchestrationAccount<{chainId: 'agoric'}>>;
|
|
138
120
|
* settlementAddress: ChainAddress;
|
|
139
121
|
* intermediateRecipient?: ChainAddress;
|
|
@@ -170,7 +152,9 @@ export const prepareAdvancerKit = (
|
|
|
170
152
|
statusManager.skipAdvance(evidence, risk.risksIdentified);
|
|
171
153
|
return;
|
|
172
154
|
}
|
|
173
|
-
|
|
155
|
+
|
|
156
|
+
const { borrowerFacet, poolAccount, settlementAddress } =
|
|
157
|
+
this.state;
|
|
174
158
|
const { recipientAddress } = evidence.aux;
|
|
175
159
|
const decoded = decodeAddressHook(recipientAddress);
|
|
176
160
|
mustMatch(decoded, AddressHookShape);
|
|
@@ -183,20 +167,12 @@ export const prepareAdvancerKit = (
|
|
|
183
167
|
const destination = chainHub.makeChainAddress(EUD);
|
|
184
168
|
|
|
185
169
|
const fullAmount = toAmount(evidence.tx.amount);
|
|
186
|
-
const { borrower, notifier, poolAccount } = this.state;
|
|
187
|
-
// do not advance if we've already received a mint/settlement
|
|
188
|
-
const mintedEarly = notifier.checkMintedEarly(
|
|
189
|
-
evidence,
|
|
190
|
-
destination,
|
|
191
|
-
);
|
|
192
|
-
if (mintedEarly) return;
|
|
193
|
-
|
|
194
170
|
// throws if requested does not exceed fees
|
|
195
171
|
const advanceAmount = feeTools.calculateAdvance(fullAmount);
|
|
196
172
|
|
|
197
173
|
const { zcfSeat: tmpSeat } = zcf.makeEmptySeatKit();
|
|
198
174
|
// throws if the pool has insufficient funds
|
|
199
|
-
|
|
175
|
+
borrowerFacet.borrow(tmpSeat, advanceAmount);
|
|
200
176
|
|
|
201
177
|
// this cannot throw since `.isSeen()` is called in the same turn
|
|
202
178
|
statusManager.advance(evidence);
|
|
@@ -217,7 +193,7 @@ export const prepareAdvancerKit = (
|
|
|
217
193
|
});
|
|
218
194
|
} catch (error) {
|
|
219
195
|
log('Advancer error:', error);
|
|
220
|
-
statusManager.
|
|
196
|
+
statusManager.observe(evidence);
|
|
221
197
|
}
|
|
222
198
|
},
|
|
223
199
|
/** @param {ChainAddress} intermediateRecipient */
|
|
@@ -231,21 +207,14 @@ export const prepareAdvancerKit = (
|
|
|
231
207
|
* @param {AdvancerVowCtx & { tmpSeat: ZCFSeat }} ctx
|
|
232
208
|
*/
|
|
233
209
|
onFulfilled(result, ctx) {
|
|
234
|
-
const { poolAccount, intermediateRecipient
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const transferOrSendV =
|
|
243
|
-
destination.chainId === settlementAddress.chainId
|
|
244
|
-
? E(poolAccount).send(destination, amount)
|
|
245
|
-
: E(poolAccount).transfer(destination, amount, {
|
|
246
|
-
forwardOpts: { intermediateRecipient },
|
|
247
|
-
});
|
|
248
|
-
return watch(transferOrSendV, this.facets.transferHandler, {
|
|
210
|
+
const { poolAccount, intermediateRecipient } = this.state;
|
|
211
|
+
const { destination, advanceAmount, ...detail } = ctx;
|
|
212
|
+
const transferV = E(poolAccount).transfer(
|
|
213
|
+
destination,
|
|
214
|
+
{ denom: usdc.denom, value: advanceAmount.value },
|
|
215
|
+
{ forwardOpts: { intermediateRecipient } },
|
|
216
|
+
);
|
|
217
|
+
return watch(transferV, this.facets.transferHandler, {
|
|
249
218
|
destination,
|
|
250
219
|
advanceAmount,
|
|
251
220
|
...detail,
|
|
@@ -268,10 +237,9 @@ export const prepareAdvancerKit = (
|
|
|
268
237
|
error,
|
|
269
238
|
);
|
|
270
239
|
try {
|
|
271
|
-
const {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
tmpSeat.exit();
|
|
240
|
+
const { borrowerFacet, notifyFacet } = this.state;
|
|
241
|
+
notifyFacet.notifyAdvancingResult(restCtx, false);
|
|
242
|
+
borrowerFacet.returnToPool(tmpSeat, advanceAmount);
|
|
275
243
|
} catch (e) {
|
|
276
244
|
log('🚨 deposit to localOrchAccount failure recovery failed', e);
|
|
277
245
|
}
|
|
@@ -279,80 +247,44 @@ export const prepareAdvancerKit = (
|
|
|
279
247
|
},
|
|
280
248
|
transferHandler: {
|
|
281
249
|
/**
|
|
282
|
-
* @param {
|
|
250
|
+
* @param {unknown} result TODO confirm this is not a bigint (sequence)
|
|
283
251
|
* @param {AdvancerVowCtx} ctx
|
|
284
252
|
*/
|
|
285
253
|
onFulfilled(result, ctx) {
|
|
286
|
-
const {
|
|
254
|
+
const { notifyFacet } = this.state;
|
|
287
255
|
const { advanceAmount, destination, ...detail } = ctx;
|
|
288
|
-
log('Advance
|
|
256
|
+
log('Advance transfer fulfilled', {
|
|
257
|
+
advanceAmount,
|
|
258
|
+
destination,
|
|
259
|
+
result,
|
|
260
|
+
});
|
|
289
261
|
// During development, due to a bug, this call threw.
|
|
290
262
|
// The failure was silent (no diagnostics) due to:
|
|
291
263
|
// - #10576 Vows do not report unhandled rejections
|
|
292
264
|
// For now, the advancer kit relies on consistency between
|
|
293
|
-
//
|
|
265
|
+
// notifyFacet, statusManager, and callers of handleTransactionEvent().
|
|
294
266
|
// TODO: revisit #10576 during #10510
|
|
295
|
-
|
|
267
|
+
notifyFacet.notifyAdvancingResult({ destination, ...detail }, true);
|
|
296
268
|
},
|
|
297
269
|
/**
|
|
298
270
|
* @param {Error} error
|
|
299
271
|
* @param {AdvancerVowCtx} ctx
|
|
300
272
|
*/
|
|
301
273
|
onRejected(error, ctx) {
|
|
302
|
-
const {
|
|
303
|
-
log('Advance
|
|
304
|
-
|
|
305
|
-
notifier.notifyAdvancingResult(restCtx, false);
|
|
306
|
-
const { zcfSeat: tmpReturnSeat } = zcf.makeEmptySeatKit();
|
|
307
|
-
const withdrawV = withdrawToSeat(
|
|
308
|
-
// @ts-expect-error LocalAccountMethods vs OrchestrationAccount
|
|
309
|
-
poolAccount,
|
|
310
|
-
tmpReturnSeat,
|
|
311
|
-
harden({ USDC: advanceAmount }),
|
|
312
|
-
);
|
|
313
|
-
void watch(withdrawV, this.facets.withdrawHandler, {
|
|
314
|
-
advanceAmount,
|
|
315
|
-
tmpReturnSeat,
|
|
316
|
-
});
|
|
317
|
-
},
|
|
318
|
-
},
|
|
319
|
-
withdrawHandler: {
|
|
320
|
-
/**
|
|
321
|
-
*
|
|
322
|
-
* @param {undefined} result
|
|
323
|
-
* @param {{ advanceAmount: Amount<'nat'>; tmpReturnSeat: ZCFSeat; }} ctx
|
|
324
|
-
*/
|
|
325
|
-
onFulfilled(result, { advanceAmount, tmpReturnSeat }) {
|
|
326
|
-
const { borrower } = this.state;
|
|
327
|
-
try {
|
|
328
|
-
borrower.returnToPool(tmpReturnSeat, advanceAmount);
|
|
329
|
-
} catch (e) {
|
|
330
|
-
// If we reach here, the unused advance funds will remain in `tmpReturnSeat`
|
|
331
|
-
// and must be retrieved from recovery sets.
|
|
332
|
-
log(
|
|
333
|
-
`🚨 return ${q(advanceAmount)} to pool failed. funds remain on "tmpReturnSeat"`,
|
|
334
|
-
e,
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
tmpReturnSeat.exit();
|
|
338
|
-
},
|
|
339
|
-
/**
|
|
340
|
-
* @param {Error} error
|
|
341
|
-
* @param {{ advanceAmount: Amount<'nat'>; tmpReturnSeat: ZCFSeat; }} ctx
|
|
342
|
-
*/
|
|
343
|
-
onRejected(error, { advanceAmount, tmpReturnSeat }) {
|
|
344
|
-
log(
|
|
345
|
-
`🚨 withdraw ${q(advanceAmount)} from "poolAccount" to return to pool failed`,
|
|
346
|
-
error,
|
|
347
|
-
);
|
|
348
|
-
// If we reach here, the unused advance funds will remain in the `poolAccount`.
|
|
349
|
-
// A contract update will be required to return them to the LiquidityPool.
|
|
350
|
-
tmpReturnSeat.exit();
|
|
274
|
+
const { notifyFacet } = this.state;
|
|
275
|
+
log('Advance transfer rejected', error);
|
|
276
|
+
notifyFacet.notifyAdvancingResult(ctx, false);
|
|
351
277
|
},
|
|
352
278
|
},
|
|
353
279
|
},
|
|
354
280
|
{
|
|
355
|
-
stateShape
|
|
281
|
+
stateShape: harden({
|
|
282
|
+
notifyFacet: M.remotable(),
|
|
283
|
+
borrowerFacet: M.remotable(),
|
|
284
|
+
poolAccount: M.remotable(),
|
|
285
|
+
intermediateRecipient: M.opt(ChainAddressShape),
|
|
286
|
+
settlementAddress: M.opt(ChainAddressShape),
|
|
287
|
+
}),
|
|
356
288
|
},
|
|
357
289
|
);
|
|
358
290
|
};
|