@bananapus/core-v6 0.0.24 → 0.0.25
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/ADMINISTRATION.md +16 -3
- package/ARCHITECTURE.md +28 -9
- package/AUDIT_INSTRUCTIONS.md +102 -17
- package/CHANGE_LOG.md +18 -8
- package/README.md +58 -2
- package/RISKS.md +13 -20
- package/SKILLS.md +158 -11
- package/STYLE_GUIDE.md +11 -6
- package/USER_JOURNEYS.md +53 -16
- package/foundry.toml +1 -1
- package/package.json +2 -2
- package/script/Deploy.s.sol +2 -2
- package/script/DeployPeriphery.s.sol +2 -5
- package/script/helpers/CoreDeploymentLib.sol +2 -2
- package/src/JBChainlinkV3PriceFeed.sol +1 -1
- package/src/JBChainlinkV3SequencerPriceFeed.sol +1 -1
- package/src/JBController.sol +14 -7
- package/src/JBDeadline.sol +1 -1
- package/src/JBDirectory.sol +1 -1
- package/src/JBERC20.sol +6 -2
- package/src/JBFeelessAddresses.sol +1 -1
- package/src/JBFundAccessLimits.sol +1 -1
- package/src/JBMultiTerminal.sol +53 -4
- package/src/JBPermissions.sol +6 -2
- package/src/JBPrices.sol +1 -1
- package/src/JBProjects.sol +1 -1
- package/src/JBRulesets.sol +1 -1
- package/src/JBSplits.sol +1 -1
- package/src/JBTerminalStore.sol +57 -53
- package/src/JBTokens.sol +5 -1
- package/src/interfaces/IJBController.sol +7 -1
- package/src/libraries/JBPayoutSplitGroupLib.sol +1 -1
- package/src/periphery/JBDeadline1Day.sol +1 -1
- package/src/periphery/JBDeadline3Days.sol +1 -1
- package/src/periphery/JBDeadline3Hours.sol +1 -1
- package/src/periphery/JBDeadline7Days.sol +1 -1
- package/src/periphery/JBMatchingPriceFeed.sol +1 -1
- package/test/TestAccessToFunds.sol +4 -4
- package/test/TestFeeFreeCashOutBypass.sol +332 -0
- package/test/TestJBERC20Inheritance.sol +1 -1
- package/test/TestMetadataOffsetOverflow.sol +1 -1
- package/test/TestMetadataParserLib.sol +1 -1
- package/test/TestMultiTerminalSurplus.sol +1 -1
- package/test/TestMultiTokenSurplus.sol +1 -1
- package/test/TestMultipleAccessLimits.sol +4 -4
- package/test/TestPermit2DataHook.t.sol +1 -1
- package/test/TestPermit2Terminal.sol +1 -1
- package/test/TestTerminalPreviewParity.sol +1 -1
- package/test/audit/CashOutReenterPay.t.sol +496 -0
- package/test/audit/FeeFreeSurplusLifecycle.t.sol +392 -0
- package/test/audit/FeeFreeSurplusStale.t.sol +242 -0
- package/test/audit/USDTVoidReturnCompat.t.sol +519 -0
- package/test/fork/TestChainlinkPriceFeedFork.sol +1 -1
- package/test/fork/TestSequencerPriceFeedFork.sol +1 -1
- package/test/fork/TestTerminalPreviewParityFork.sol +1 -1
- package/test/helpers/JBTest.sol +1 -1
- package/test/helpers/MetadataResolverHelper.sol +1 -1
- package/test/mock/MockERC20.sol +1 -1
- package/test/mock/MockMaliciousBeneficiary.sol +1 -1
- package/test/mock/MockMaliciousSplitHook.sol +1 -1
- package/test/mock/MockPriceFeed.sol +1 -1
- package/test/mock/MockUSDT.sol +80 -0
- package/test/regression/HoldFeesCashOutReserved.t.sol +2 -2
- package/test/units/static/JBChainlinkV3PriceFeed/TestPriceFeed.sol +1 -1
- package/test/units/static/JBController/JBControllerSetup.sol +1 -1
- package/test/units/static/JBController/TestBurnTokensOf.sol +1 -1
- package/test/units/static/JBController/TestClaimTokensFor.sol +1 -1
- package/test/units/static/JBController/TestDeployErc20For.sol +1 -1
- package/test/units/static/JBController/TestLaunchProjectFor.sol +1 -1
- package/test/units/static/JBController/TestLaunchRulesetsFor.sol +1 -1
- package/test/units/static/JBController/TestMigrateController.sol +1 -1
- package/test/units/static/JBController/TestMintTokensOfUnits.sol +1 -1
- package/test/units/static/JBController/TestOmnichainRulesetOperator.sol +324 -0
- package/test/units/static/JBController/TestPayReservedTokenToTerminal.sol +1 -1
- package/test/units/static/JBController/TestPreviewMintOf.sol +1 -1
- package/test/units/static/JBController/TestReceiveMigrationFrom.sol +1 -1
- package/test/units/static/JBController/TestRulesetViews.sol +1 -1
- package/test/units/static/JBController/TestSendReservedTokensToSplitsOf.sol +1 -1
- package/test/units/static/JBController/TestSetSplitGroupsOf.sol +1 -1
- package/test/units/static/JBController/TestSetTokenFor.sol +1 -1
- package/test/units/static/JBController/TestSetUriOf.sol +1 -1
- package/test/units/static/JBController/TestTransferCreditsFrom.sol +1 -1
- package/test/units/static/JBDeadline/TestDeadlineFuzz.sol +1 -1
- package/test/units/static/JBDirectory/JBDirectorySetup.sol +1 -1
- package/test/units/static/JBDirectory/TestPrimaryTerminalOf.sol +1 -1
- package/test/units/static/JBDirectory/TestSetControllerOf.sol +1 -1
- package/test/units/static/JBDirectory/TestSetControllerOfMigrationOrder.sol +1 -1
- package/test/units/static/JBDirectory/TestSetPrimaryTerminalOf.sol +1 -1
- package/test/units/static/JBDirectory/TestSetTerminalsOf.sol +1 -1
- package/test/units/static/JBERC20/JBERC20Setup.sol +11 -4
- package/test/units/static/JBERC20/SigUtils.sol +1 -1
- package/test/units/static/JBERC20/TestInitialize.sol +8 -1
- package/test/units/static/JBERC20/TestName.sol +1 -1
- package/test/units/static/JBERC20/TestNonces.sol +1 -1
- package/test/units/static/JBERC20/TestSymbol.sol +1 -1
- package/test/units/static/JBFeelessAdresses/JBFeelessSetup.sol +1 -1
- package/test/units/static/JBFeelessAdresses/TestInterfaces.sol +1 -1
- package/test/units/static/JBFeelessAdresses/TestSetFeelessAddress.sol +1 -1
- package/test/units/static/JBFees/TestFeesFuzz.sol +1 -1
- package/test/units/static/JBFixedPointNumber/TestAdjustDecimals.sol +1 -1
- package/test/units/static/JBFixedPointNumber/TestAdjustDecimalsFuzz.sol +1 -1
- package/test/units/static/JBFundAccessLimits/JBFundAccessSetup.sol +1 -1
- package/test/units/static/JBFundAccessLimits/TestFundAccessLimitsEdge.sol +1 -1
- package/test/units/static/JBFundAccessLimits/TestPayoutLimitOf.sol +1 -1
- package/test/units/static/JBFundAccessLimits/TestPayoutLimitsOf.sol +1 -1
- package/test/units/static/JBFundAccessLimits/TestSetFundAccessLimitsFor.sol +1 -1
- package/test/units/static/JBFundAccessLimits/TestSurplusAllowanceOf.sol +1 -1
- package/test/units/static/JBFundAccessLimits/TestSurplusAllowancesOf.sol +1 -1
- package/test/units/static/JBMetadataResolver/TestGetDataFor.sol +1 -1
- package/test/units/static/JBMetadataResolver/TestMetadataResolverEdgeCases.sol +1 -1
- package/test/units/static/JBMetadataResolver/TestMetadataResolverFuzz.sol +1 -1
- package/test/units/static/JBMultiTerminal/JBMultiTerminalSetup.sol +1 -1
- package/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol +1 -1
- package/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol +1 -1
- package/test/units/static/JBMultiTerminal/TestAddToBalanceOf.sol +1 -1
- package/test/units/static/JBMultiTerminal/TestCashOutTokensOf.sol +1 -1
- package/test/units/static/JBMultiTerminal/TestExecutePayout.sol +1 -1
- package/test/units/static/JBMultiTerminal/TestExecuteProcessFee.sol +1 -1
- package/test/units/static/JBMultiTerminal/TestMigrateBalanceOf.sol +1 -1
- package/test/units/static/JBMultiTerminal/TestPay.sol +1 -1
- package/test/units/static/JBMultiTerminal/TestPreviewCashOutFrom.sol +1 -1
- package/test/units/static/JBMultiTerminal/TestPreviewPayFor.sol +1 -1
- package/test/units/static/JBMultiTerminal/TestProcessHeldFeesOf.sol +1 -1
- package/test/units/static/JBMultiTerminal/TestSendPayoutsOf.sol +1 -1
- package/test/units/static/JBMultiTerminal/TestUseAllowanceOf.sol +1 -1
- package/test/units/static/JBPermissions/JBPermissionsSetup.sol +1 -1
- package/test/units/static/JBPermissions/TestHasPermission.sol +1 -1
- package/test/units/static/JBPermissions/TestHasPermissions.sol +1 -1
- package/test/units/static/JBPermissions/TestSetPermissionsFor.sol +1 -1
- package/test/units/static/JBPrices/JBPricesSetup.sol +1 -1
- package/test/units/static/JBPrices/TestAddPriceFeedFor.sol +1 -1
- package/test/units/static/JBPrices/TestPricePerUnitOf.sol +1 -1
- package/test/units/static/JBPrices/TestPrices.sol +1 -1
- package/test/units/static/JBProjects/JBProjectsSetup.sol +1 -1
- package/test/units/static/JBProjects/TestCreateFor.sol +1 -1
- package/test/units/static/JBProjects/TestInitialProject.sol +1 -1
- package/test/units/static/JBProjects/TestInterfaces.sol +1 -1
- package/test/units/static/JBProjects/TestSetResolver.sol +1 -1
- package/test/units/static/JBProjects/TestTokenUri.sol +1 -1
- package/test/units/static/JBRulesetMetadataResolver/TestSetCashOutTaxRateTo.sol +1 -1
- package/test/units/static/JBRulesets/JBRulesetsSetup.sol +1 -1
- package/test/units/static/JBRulesets/TestCurrentApprovalStatusForLatestRulesetOf.sol +1 -1
- package/test/units/static/JBRulesets/TestCurrentOf.sol +1 -1
- package/test/units/static/JBRulesets/TestGetRulesetOf.sol +1 -1
- package/test/units/static/JBRulesets/TestLatestQueuedRulesetOf.sol +1 -1
- package/test/units/static/JBRulesets/TestRulesets.sol +1 -1
- package/test/units/static/JBRulesets/TestRulesetsOf.sol +1 -1
- package/test/units/static/JBRulesets/TestUpcomingRulesetOf.sol +1 -1
- package/test/units/static/JBRulesets/TestUpdateRulesetWeightCache.sol +1 -1
- package/test/units/static/JBSplits/JBSplitsSetup.sol +1 -1
- package/test/units/static/JBSplits/TestSelfManagedSplitGroups.sol +1 -1
- package/test/units/static/JBSplits/TestSetSplitGroupsOf.sol +1 -1
- package/test/units/static/JBSplits/TestSplitsLockedEdge.sol +1 -1
- package/test/units/static/JBSplits/TestSplitsOf.sol +1 -1
- package/test/units/static/JBSplits/TestSplitsPacking.sol +1 -1
- package/test/units/static/JBSurplus/TestSurplusFuzz.sol +1 -1
- package/test/units/static/JBTerminalStore/JBTerminalStoreSetup.sol +1 -1
- package/test/units/static/JBTerminalStore/TestCurrentReclaimableSurplusOf.sol +1 -1
- package/test/units/static/JBTerminalStore/TestCurrentSurplusOf.sol +1 -1
- package/test/units/static/JBTerminalStore/TestCurrentTotalSurplusOf.sol +1 -1
- package/test/units/static/JBTerminalStore/TestPreviewCashOutFrom.sol +1 -1
- package/test/units/static/JBTerminalStore/TestPreviewPayFrom.sol +1 -1
- package/test/units/static/JBTerminalStore/TestRecordCashOutsFor.sol +1 -1
- package/test/units/static/JBTerminalStore/TestRecordPaymentFrom.sol +1 -1
- package/test/units/static/JBTerminalStore/TestRecordPayoutFor.sol +1 -1
- package/test/units/static/JBTerminalStore/TestRecordTerminalMigration.sol +1 -1
- package/test/units/static/JBTerminalStore/TestRecordUsedAllowanceOf.sol +1 -1
- package/test/units/static/JBTerminalStore/TestUint224Overflow.sol +1 -1
- package/test/units/static/JBTokens/JBTokensSetup.sol +1 -1
- package/test/units/static/JBTokens/TestBurnFrom.sol +1 -1
- package/test/units/static/JBTokens/TestClaimTokensFor.sol +1 -1
- package/test/units/static/JBTokens/TestDeployERC20ForUnits.sol +1 -1
- package/test/units/static/JBTokens/TestMintFor.sol +1 -1
- package/test/units/static/JBTokens/TestSetTokenFor.sol +1 -1
- package/test/units/static/JBTokens/TestTotalBalanceOf.sol +1 -1
- package/test/units/static/JBTokens/TestTotalSupplyOf.sol +1 -1
- package/test/units/static/JBTokens/TestTransferCreditsFrom.sol +1 -1
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.6;
|
|
3
|
+
|
|
4
|
+
// Import the shared base test workflow that deploys all core Juicebox contracts.
|
|
5
|
+
import {TestBaseWorkflow} from "../helpers/TestBaseWorkflow.sol";
|
|
6
|
+
// Import the void-returning USDT mock token.
|
|
7
|
+
import {MockUSDT} from "../mock/MockUSDT.sol";
|
|
8
|
+
// Import the approval hook interface needed for ruleset configuration.
|
|
9
|
+
import {IJBRulesetApprovalHook} from "../../src/interfaces/IJBRulesetApprovalHook.sol";
|
|
10
|
+
// Import the split hook interface needed for split configuration.
|
|
11
|
+
import {IJBSplitHook} from "../../src/interfaces/IJBSplitHook.sol";
|
|
12
|
+
// Import constants used for fee maximums, native token address, and split percentages.
|
|
13
|
+
import {JBConstants} from "../../src/libraries/JBConstants.sol";
|
|
14
|
+
// Import the metadata resolver to pack/unpack ruleset metadata bits.
|
|
15
|
+
import {JBRulesetMetadataResolver} from "../../src/libraries/JBRulesetMetadataResolver.sol";
|
|
16
|
+
// Import the ruleset struct used to read current ruleset state.
|
|
17
|
+
import {JBRuleset} from "../../src/structs/JBRuleset.sol";
|
|
18
|
+
// Import currency amount struct for payout/surplus limit configuration.
|
|
19
|
+
import {JBCurrencyAmount} from "../../src/structs/JBCurrencyAmount.sol";
|
|
20
|
+
// Import fund access limit group struct for payout limit configuration.
|
|
21
|
+
import {JBFundAccessLimitGroup} from "../../src/structs/JBFundAccessLimitGroup.sol";
|
|
22
|
+
// Import ruleset config struct for project launch configuration.
|
|
23
|
+
import {JBRulesetConfig} from "../../src/structs/JBRulesetConfig.sol";
|
|
24
|
+
// Import ruleset metadata struct for per-ruleset settings.
|
|
25
|
+
import {JBRulesetMetadata} from "../../src/structs/JBRulesetMetadata.sol";
|
|
26
|
+
// Import split struct for defining payout split recipients.
|
|
27
|
+
import {JBSplit} from "../../src/structs/JBSplit.sol";
|
|
28
|
+
// Import split group struct for grouping splits by token.
|
|
29
|
+
import {JBSplitGroup} from "../../src/structs/JBSplitGroup.sol";
|
|
30
|
+
// Import terminal config struct for linking terminals to accounting contexts.
|
|
31
|
+
import {JBTerminalConfig} from "../../src/structs/JBTerminalConfig.sol";
|
|
32
|
+
// Import accounting context struct for token acceptance configuration.
|
|
33
|
+
import {JBAccountingContext} from "../../src/structs/JBAccountingContext.sol";
|
|
34
|
+
|
|
35
|
+
/// @notice Tests that USDT-style void-returning ERC-20 tokens work with JBMultiTerminal.
|
|
36
|
+
/// @dev USDT's transfer/transferFrom/approve return void instead of bool. The terminal
|
|
37
|
+
/// uses SafeERC20 which handles void returns, and Permit2 which uses low-level calls.
|
|
38
|
+
/// These tests prove the full pay -> payout -> cashOut lifecycle works with such tokens.
|
|
39
|
+
contract USDTVoidReturnCompat is TestBaseWorkflow {
|
|
40
|
+
// Use the metadata resolver library on ruleset structs.
|
|
41
|
+
using JBRulesetMetadataResolver for JBRuleset;
|
|
42
|
+
|
|
43
|
+
// The USDT mock token instance used across all tests.
|
|
44
|
+
MockUSDT public usdt;
|
|
45
|
+
// The project owner address (multisig from the base workflow).
|
|
46
|
+
address public projectOwner;
|
|
47
|
+
// The address that receives split payouts in test scenarios.
|
|
48
|
+
address public splitBeneficiary;
|
|
49
|
+
|
|
50
|
+
function setUp() public override {
|
|
51
|
+
// Deploy all core Juicebox contracts via the base workflow.
|
|
52
|
+
super.setUp();
|
|
53
|
+
// Use the multisig as the project owner for test projects.
|
|
54
|
+
projectOwner = multisig();
|
|
55
|
+
// Create a dedicated address for receiving split payouts.
|
|
56
|
+
splitBeneficiary = address(0xBEEF);
|
|
57
|
+
// Deploy the void-returning USDT mock.
|
|
58
|
+
usdt = new MockUSDT();
|
|
59
|
+
// Label the USDT contract for clearer trace output.
|
|
60
|
+
vm.label(address(usdt), "MockUSDT");
|
|
61
|
+
// Launch the fee-collector project (project #1) required by the protocol.
|
|
62
|
+
_launchFeeProject();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// =========================================================================
|
|
66
|
+
// Fee project helper — project #1 collects protocol fees
|
|
67
|
+
// =========================================================================
|
|
68
|
+
|
|
69
|
+
/// @notice Deploys project #1 which receives protocol fees.
|
|
70
|
+
function _launchFeeProject() internal {
|
|
71
|
+
// Create a single-element array for the fee project's ruleset configuration.
|
|
72
|
+
JBRulesetConfig[] memory feeRulesetConfig = new JBRulesetConfig[](1);
|
|
73
|
+
// The fee project starts immediately (no delay).
|
|
74
|
+
feeRulesetConfig[0].mustStartAtOrAfter = 0;
|
|
75
|
+
// Duration of 0 means the ruleset never expires automatically.
|
|
76
|
+
feeRulesetConfig[0].duration = 0;
|
|
77
|
+
// Set the weight to 1000 tokens per unit paid, scaled to 18 decimals.
|
|
78
|
+
feeRulesetConfig[0].weight = 1000e18;
|
|
79
|
+
// No weight decay between cycles.
|
|
80
|
+
feeRulesetConfig[0].weightCutPercent = 0;
|
|
81
|
+
// No approval hook required for this ruleset.
|
|
82
|
+
feeRulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
|
|
83
|
+
// Configure metadata: minimal settings, accept accounting contexts.
|
|
84
|
+
feeRulesetConfig[0].metadata = JBRulesetMetadata({
|
|
85
|
+
reservedPercent: 0,
|
|
86
|
+
cashOutTaxRate: 0,
|
|
87
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
88
|
+
pausePay: false,
|
|
89
|
+
pauseCreditTransfers: false,
|
|
90
|
+
allowOwnerMinting: false,
|
|
91
|
+
allowSetCustomToken: false,
|
|
92
|
+
allowTerminalMigration: false,
|
|
93
|
+
allowSetTerminals: false,
|
|
94
|
+
ownerMustSendPayouts: false,
|
|
95
|
+
allowSetController: false,
|
|
96
|
+
allowAddAccountingContext: true,
|
|
97
|
+
allowAddPriceFeed: false,
|
|
98
|
+
holdFees: false,
|
|
99
|
+
useTotalSurplusForCashOuts: false,
|
|
100
|
+
useDataHookForPay: false,
|
|
101
|
+
useDataHookForCashOut: false,
|
|
102
|
+
dataHook: address(0),
|
|
103
|
+
metadata: 0
|
|
104
|
+
});
|
|
105
|
+
// No splits for the fee project.
|
|
106
|
+
feeRulesetConfig[0].splitGroups = new JBSplitGroup[](0);
|
|
107
|
+
// No fund access limits for the fee project.
|
|
108
|
+
feeRulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
|
|
109
|
+
|
|
110
|
+
// Configure the terminal to accept native ETH tokens.
|
|
111
|
+
JBTerminalConfig[] memory termConfigs = new JBTerminalConfig[](1);
|
|
112
|
+
// Create accounting context for native token with 18 decimals.
|
|
113
|
+
JBAccountingContext[] memory tokensToAccept = new JBAccountingContext[](1);
|
|
114
|
+
tokensToAccept[0] = JBAccountingContext({
|
|
115
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
116
|
+
});
|
|
117
|
+
// Link the terminal to the accounting context.
|
|
118
|
+
termConfigs[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: tokensToAccept});
|
|
119
|
+
|
|
120
|
+
// Launch project #1 as the fee collector.
|
|
121
|
+
jbController()
|
|
122
|
+
.launchProjectFor({
|
|
123
|
+
owner: address(420),
|
|
124
|
+
projectUri: "feeCollector",
|
|
125
|
+
rulesetConfigurations: feeRulesetConfig,
|
|
126
|
+
terminalConfigurations: termConfigs,
|
|
127
|
+
memo: ""
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// =========================================================================
|
|
132
|
+
// Test 1: Pay into a project with void-returning MockUSDT
|
|
133
|
+
// =========================================================================
|
|
134
|
+
|
|
135
|
+
/// @notice Verifies that paying with a void-returning token succeeds.
|
|
136
|
+
/// @dev The terminal uses SafeERC20 which correctly handles tokens that return no data.
|
|
137
|
+
function test_usdt_void_return_pay() public {
|
|
138
|
+
// Launch a project that accepts USDT.
|
|
139
|
+
uint256 pid = _launchUSDTProject();
|
|
140
|
+
// Use a dedicated payer address.
|
|
141
|
+
address payer = address(0xBA1E);
|
|
142
|
+
// Mint 1000 USDT (6 decimals) to the payer.
|
|
143
|
+
uint256 payAmount = 1000e6;
|
|
144
|
+
usdt.mint(payer, payAmount);
|
|
145
|
+
|
|
146
|
+
// Approve the terminal to spend the payer's USDT via Permit2.
|
|
147
|
+
vm.prank(payer);
|
|
148
|
+
// Approve Permit2 contract to pull USDT from the payer.
|
|
149
|
+
usdt.approve(address(permit2()), payAmount);
|
|
150
|
+
|
|
151
|
+
// Grant Permit2 allowance for the terminal to pull tokens.
|
|
152
|
+
vm.prank(payer);
|
|
153
|
+
permit2().approve(address(usdt), address(jbMultiTerminal()), uint160(payAmount), type(uint48).max);
|
|
154
|
+
|
|
155
|
+
// Execute the payment — this is the critical call that must handle void returns.
|
|
156
|
+
vm.prank(payer);
|
|
157
|
+
uint256 tokensReceived = jbMultiTerminal()
|
|
158
|
+
.pay({
|
|
159
|
+
projectId: pid,
|
|
160
|
+
token: address(usdt),
|
|
161
|
+
amount: payAmount,
|
|
162
|
+
beneficiary: payer,
|
|
163
|
+
minReturnedTokens: 0,
|
|
164
|
+
memo: "",
|
|
165
|
+
metadata: new bytes(0)
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// Verify the payer received project tokens in exchange for the payment.
|
|
169
|
+
assertTrue(tokensReceived > 0, "Payer should receive project tokens from USDT payment");
|
|
170
|
+
|
|
171
|
+
// Verify the terminal recorded the balance correctly.
|
|
172
|
+
uint256 recordedBalance = jbTerminalStore().balanceOf(address(jbMultiTerminal()), pid, address(usdt));
|
|
173
|
+
// The recorded balance should equal the full payment amount (no transfer fee).
|
|
174
|
+
assertEq(recordedBalance, payAmount, "Terminal should record the full USDT pay amount");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// =========================================================================
|
|
178
|
+
// Test 2: Execute a split payout that sends MockUSDT to a beneficiary
|
|
179
|
+
// =========================================================================
|
|
180
|
+
|
|
181
|
+
/// @notice Verifies that split payouts work with void-returning tokens.
|
|
182
|
+
/// @dev Split payouts go through executePayout -> _transferFrom -> SafeERC20.safeTransfer
|
|
183
|
+
/// which handles void returns by checking returndata length.
|
|
184
|
+
function test_usdt_void_return_split_payout() public {
|
|
185
|
+
// Launch a project with a split that pays out to splitBeneficiary.
|
|
186
|
+
uint256 pid = _launchUSDTProjectWithSplit();
|
|
187
|
+
// Use a dedicated payer address.
|
|
188
|
+
address payer = address(0xBA1E);
|
|
189
|
+
// Mint 1000 USDT to the payer.
|
|
190
|
+
uint256 payAmount = 1000e6;
|
|
191
|
+
usdt.mint(payer, payAmount);
|
|
192
|
+
|
|
193
|
+
// Approve Permit2 to pull USDT from payer.
|
|
194
|
+
vm.prank(payer);
|
|
195
|
+
usdt.approve(address(permit2()), payAmount);
|
|
196
|
+
|
|
197
|
+
// Grant Permit2 allowance for the terminal.
|
|
198
|
+
vm.prank(payer);
|
|
199
|
+
permit2().approve(address(usdt), address(jbMultiTerminal()), uint160(payAmount), type(uint48).max);
|
|
200
|
+
|
|
201
|
+
// Pay into the project to fund it.
|
|
202
|
+
vm.prank(payer);
|
|
203
|
+
jbMultiTerminal()
|
|
204
|
+
.pay({
|
|
205
|
+
projectId: pid,
|
|
206
|
+
token: address(usdt),
|
|
207
|
+
amount: payAmount,
|
|
208
|
+
beneficiary: payer,
|
|
209
|
+
minReturnedTokens: 0,
|
|
210
|
+
memo: "",
|
|
211
|
+
metadata: new bytes(0)
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// Record the split beneficiary's USDT balance before the payout.
|
|
215
|
+
uint256 beneficiaryBefore = usdt.balanceOf(splitBeneficiary);
|
|
216
|
+
|
|
217
|
+
// Execute the payout — sends USDT through the split to the beneficiary.
|
|
218
|
+
vm.prank(projectOwner);
|
|
219
|
+
jbMultiTerminal()
|
|
220
|
+
.sendPayoutsOf({
|
|
221
|
+
projectId: pid,
|
|
222
|
+
token: address(usdt),
|
|
223
|
+
amount: 500e6,
|
|
224
|
+
currency: uint32(uint160(address(usdt))),
|
|
225
|
+
minTokensPaidOut: 0
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// Calculate how much USDT the beneficiary actually received.
|
|
229
|
+
uint256 beneficiaryAfter = usdt.balanceOf(splitBeneficiary);
|
|
230
|
+
uint256 received = beneficiaryAfter - beneficiaryBefore;
|
|
231
|
+
|
|
232
|
+
// The beneficiary should have received tokens (less fees).
|
|
233
|
+
assertTrue(received > 0, "Split beneficiary should receive USDT from payout");
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// =========================================================================
|
|
237
|
+
// Test 3: Cash out project tokens for MockUSDT reclaim
|
|
238
|
+
// =========================================================================
|
|
239
|
+
|
|
240
|
+
/// @notice Verifies that cashing out tokens reclaims void-returning USDT.
|
|
241
|
+
/// @dev The cashOut flow uses _transferFrom -> SafeERC20.safeTransfer on the outbound side.
|
|
242
|
+
function test_usdt_void_return_cashOut() public {
|
|
243
|
+
// Launch a project that accepts USDT with 0% cashout tax for full reclaim.
|
|
244
|
+
uint256 pid = _launchUSDTProject();
|
|
245
|
+
// Use a dedicated payer address.
|
|
246
|
+
address payer = address(0xBA1E);
|
|
247
|
+
// Mint 1000 USDT to the payer.
|
|
248
|
+
uint256 payAmount = 1000e6;
|
|
249
|
+
usdt.mint(payer, payAmount);
|
|
250
|
+
|
|
251
|
+
// Approve Permit2 to pull USDT from payer.
|
|
252
|
+
vm.prank(payer);
|
|
253
|
+
usdt.approve(address(permit2()), payAmount);
|
|
254
|
+
|
|
255
|
+
// Grant Permit2 allowance for the terminal.
|
|
256
|
+
vm.prank(payer);
|
|
257
|
+
permit2().approve(address(usdt), address(jbMultiTerminal()), uint160(payAmount), type(uint48).max);
|
|
258
|
+
|
|
259
|
+
// Pay into the project to receive project tokens.
|
|
260
|
+
vm.prank(payer);
|
|
261
|
+
uint256 tokensReceived = jbMultiTerminal()
|
|
262
|
+
.pay({
|
|
263
|
+
projectId: pid,
|
|
264
|
+
token: address(usdt),
|
|
265
|
+
amount: payAmount,
|
|
266
|
+
beneficiary: payer,
|
|
267
|
+
minReturnedTokens: 0,
|
|
268
|
+
memo: "",
|
|
269
|
+
metadata: new bytes(0)
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// Record the payer's USDT balance before cashing out.
|
|
273
|
+
uint256 payerBefore = usdt.balanceOf(payer);
|
|
274
|
+
|
|
275
|
+
// Cash out all project tokens to reclaim USDT.
|
|
276
|
+
vm.prank(payer);
|
|
277
|
+
uint256 reclaimAmount = jbMultiTerminal()
|
|
278
|
+
.cashOutTokensOf({
|
|
279
|
+
holder: payer,
|
|
280
|
+
projectId: pid,
|
|
281
|
+
cashOutCount: tokensReceived,
|
|
282
|
+
tokenToReclaim: address(usdt),
|
|
283
|
+
minTokensReclaimed: 0,
|
|
284
|
+
beneficiary: payable(payer),
|
|
285
|
+
metadata: new bytes(0)
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// Calculate how much USDT the payer actually received back.
|
|
289
|
+
uint256 payerAfter = usdt.balanceOf(payer);
|
|
290
|
+
uint256 actualReclaimed = payerAfter - payerBefore;
|
|
291
|
+
|
|
292
|
+
// The reclaim amount should be positive (some goes to fees at 0% tax rate).
|
|
293
|
+
assertTrue(reclaimAmount > 0, "CashOut should reclaim USDT tokens");
|
|
294
|
+
// The payer should have received the reclaimed USDT.
|
|
295
|
+
assertEq(actualReclaimed, reclaimAmount, "Payer should receive the full reclaim amount");
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// =========================================================================
|
|
299
|
+
// Test 4: Full lifecycle — pay, payout, cashOut in sequence
|
|
300
|
+
// =========================================================================
|
|
301
|
+
|
|
302
|
+
/// @notice End-to-end test: pay with USDT, distribute payout, then cash out remainder.
|
|
303
|
+
/// @dev Proves the entire lifecycle works without reverting for void-returning tokens.
|
|
304
|
+
function test_usdt_void_return_full_lifecycle() public {
|
|
305
|
+
// Launch a project with splits and payout limits.
|
|
306
|
+
uint256 pid = _launchUSDTProjectWithSplit();
|
|
307
|
+
// Use a dedicated payer address.
|
|
308
|
+
address payer = address(0xBA1E);
|
|
309
|
+
// Mint 2000 USDT to the payer.
|
|
310
|
+
uint256 payAmount = 2000e6;
|
|
311
|
+
usdt.mint(payer, payAmount);
|
|
312
|
+
|
|
313
|
+
// Approve Permit2 to pull USDT from payer.
|
|
314
|
+
vm.prank(payer);
|
|
315
|
+
usdt.approve(address(permit2()), payAmount);
|
|
316
|
+
|
|
317
|
+
// Grant Permit2 allowance for the terminal.
|
|
318
|
+
vm.prank(payer);
|
|
319
|
+
permit2().approve(address(usdt), address(jbMultiTerminal()), uint160(payAmount), type(uint48).max);
|
|
320
|
+
|
|
321
|
+
// Step 1: Pay into the project.
|
|
322
|
+
vm.prank(payer);
|
|
323
|
+
uint256 tokensReceived = jbMultiTerminal()
|
|
324
|
+
.pay({
|
|
325
|
+
projectId: pid,
|
|
326
|
+
token: address(usdt),
|
|
327
|
+
amount: payAmount,
|
|
328
|
+
beneficiary: payer,
|
|
329
|
+
minReturnedTokens: 0,
|
|
330
|
+
memo: "",
|
|
331
|
+
metadata: new bytes(0)
|
|
332
|
+
});
|
|
333
|
+
// Verify payment succeeded by checking tokens were minted.
|
|
334
|
+
assertTrue(tokensReceived > 0, "Step 1: Payer should receive project tokens");
|
|
335
|
+
|
|
336
|
+
// Step 2: Distribute payouts through splits.
|
|
337
|
+
vm.prank(projectOwner);
|
|
338
|
+
jbMultiTerminal()
|
|
339
|
+
.sendPayoutsOf({
|
|
340
|
+
projectId: pid,
|
|
341
|
+
token: address(usdt),
|
|
342
|
+
amount: 500e6,
|
|
343
|
+
currency: uint32(uint160(address(usdt))),
|
|
344
|
+
minTokensPaidOut: 0
|
|
345
|
+
});
|
|
346
|
+
// Verify the split beneficiary received USDT.
|
|
347
|
+
assertTrue(usdt.balanceOf(splitBeneficiary) > 0, "Step 2: Split beneficiary should have USDT");
|
|
348
|
+
|
|
349
|
+
// Step 3: Cash out remaining project tokens.
|
|
350
|
+
vm.prank(payer);
|
|
351
|
+
uint256 reclaimAmount = jbMultiTerminal()
|
|
352
|
+
.cashOutTokensOf({
|
|
353
|
+
holder: payer,
|
|
354
|
+
projectId: pid,
|
|
355
|
+
cashOutCount: tokensReceived,
|
|
356
|
+
tokenToReclaim: address(usdt),
|
|
357
|
+
minTokensReclaimed: 0,
|
|
358
|
+
beneficiary: payable(payer),
|
|
359
|
+
metadata: new bytes(0)
|
|
360
|
+
});
|
|
361
|
+
// Verify the payer got USDT back from cashing out.
|
|
362
|
+
assertTrue(reclaimAmount > 0, "Step 3: CashOut should return USDT to payer");
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// =========================================================================
|
|
366
|
+
// Internal helpers
|
|
367
|
+
// =========================================================================
|
|
368
|
+
|
|
369
|
+
/// @notice Launches a project that accepts MockUSDT with no splits and no payout limits.
|
|
370
|
+
function _launchUSDTProject() internal returns (uint256) {
|
|
371
|
+
// Create a single-element array for the ruleset configuration.
|
|
372
|
+
JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
|
|
373
|
+
// Start immediately.
|
|
374
|
+
rulesetConfig[0].mustStartAtOrAfter = 0;
|
|
375
|
+
// Non-expiring ruleset.
|
|
376
|
+
rulesetConfig[0].duration = 0;
|
|
377
|
+
// Weight scaled to 18 decimals for token issuance calculations.
|
|
378
|
+
rulesetConfig[0].weight = 1000e18;
|
|
379
|
+
// No weight decay.
|
|
380
|
+
rulesetConfig[0].weightCutPercent = 0;
|
|
381
|
+
// No approval hook.
|
|
382
|
+
rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
|
|
383
|
+
// Configure metadata: use USDT as base currency, 0% cashout tax.
|
|
384
|
+
rulesetConfig[0].metadata = JBRulesetMetadata({
|
|
385
|
+
reservedPercent: 0,
|
|
386
|
+
cashOutTaxRate: 0,
|
|
387
|
+
baseCurrency: uint32(uint160(address(usdt))),
|
|
388
|
+
pausePay: false,
|
|
389
|
+
pauseCreditTransfers: false,
|
|
390
|
+
allowOwnerMinting: true,
|
|
391
|
+
allowSetCustomToken: true,
|
|
392
|
+
allowTerminalMigration: false,
|
|
393
|
+
allowSetTerminals: false,
|
|
394
|
+
ownerMustSendPayouts: false,
|
|
395
|
+
allowSetController: false,
|
|
396
|
+
allowAddAccountingContext: true,
|
|
397
|
+
allowAddPriceFeed: false,
|
|
398
|
+
holdFees: false,
|
|
399
|
+
useTotalSurplusForCashOuts: false,
|
|
400
|
+
useDataHookForPay: false,
|
|
401
|
+
useDataHookForCashOut: false,
|
|
402
|
+
dataHook: address(0),
|
|
403
|
+
metadata: 0
|
|
404
|
+
});
|
|
405
|
+
// No splits.
|
|
406
|
+
rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
|
|
407
|
+
// No fund access limits.
|
|
408
|
+
rulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
|
|
409
|
+
|
|
410
|
+
// Configure the terminal to accept MockUSDT with 6 decimals.
|
|
411
|
+
JBTerminalConfig[] memory termConfigs = new JBTerminalConfig[](1);
|
|
412
|
+
JBAccountingContext[] memory tokensToAccept = new JBAccountingContext[](1);
|
|
413
|
+
// Set up the accounting context for USDT: 6 decimals, currency = token address.
|
|
414
|
+
tokensToAccept[0] =
|
|
415
|
+
JBAccountingContext({token: address(usdt), decimals: 6, currency: uint32(uint160(address(usdt)))});
|
|
416
|
+
// Link the terminal to the USDT accounting context.
|
|
417
|
+
termConfigs[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: tokensToAccept});
|
|
418
|
+
|
|
419
|
+
// Launch the project and return its ID.
|
|
420
|
+
return jbController()
|
|
421
|
+
.launchProjectFor({
|
|
422
|
+
owner: projectOwner,
|
|
423
|
+
projectUri: "usdtProject",
|
|
424
|
+
rulesetConfigurations: rulesetConfig,
|
|
425
|
+
terminalConfigurations: termConfigs,
|
|
426
|
+
memo: ""
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/// @notice Launches a project that accepts MockUSDT with a 100% split to splitBeneficiary.
|
|
431
|
+
function _launchUSDTProjectWithSplit() internal returns (uint256) {
|
|
432
|
+
// Create a single-element array for the ruleset configuration.
|
|
433
|
+
JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
|
|
434
|
+
// Start immediately.
|
|
435
|
+
rulesetConfig[0].mustStartAtOrAfter = 0;
|
|
436
|
+
// Non-expiring ruleset.
|
|
437
|
+
rulesetConfig[0].duration = 0;
|
|
438
|
+
// Weight scaled to 18 decimals.
|
|
439
|
+
rulesetConfig[0].weight = 1000e18;
|
|
440
|
+
// No weight decay.
|
|
441
|
+
rulesetConfig[0].weightCutPercent = 0;
|
|
442
|
+
// No approval hook.
|
|
443
|
+
rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
|
|
444
|
+
// Configure metadata: USDT base currency, 0% cashout tax, 0% reserved.
|
|
445
|
+
rulesetConfig[0].metadata = JBRulesetMetadata({
|
|
446
|
+
reservedPercent: 0,
|
|
447
|
+
cashOutTaxRate: 0,
|
|
448
|
+
baseCurrency: uint32(uint160(address(usdt))),
|
|
449
|
+
pausePay: false,
|
|
450
|
+
pauseCreditTransfers: false,
|
|
451
|
+
allowOwnerMinting: true,
|
|
452
|
+
allowSetCustomToken: true,
|
|
453
|
+
allowTerminalMigration: false,
|
|
454
|
+
allowSetTerminals: false,
|
|
455
|
+
ownerMustSendPayouts: false,
|
|
456
|
+
allowSetController: false,
|
|
457
|
+
allowAddAccountingContext: true,
|
|
458
|
+
allowAddPriceFeed: false,
|
|
459
|
+
holdFees: false,
|
|
460
|
+
useTotalSurplusForCashOuts: false,
|
|
461
|
+
useDataHookForPay: false,
|
|
462
|
+
useDataHookForCashOut: false,
|
|
463
|
+
dataHook: address(0),
|
|
464
|
+
metadata: 0
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
// Create a split that sends 100% of payouts to splitBeneficiary.
|
|
468
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
469
|
+
splits[0] = JBSplit({
|
|
470
|
+
percent: uint32(JBConstants.SPLITS_TOTAL_PERCENT),
|
|
471
|
+
projectId: 0,
|
|
472
|
+
beneficiary: payable(splitBeneficiary),
|
|
473
|
+
preferAddToBalance: false,
|
|
474
|
+
lockedUntil: 0,
|
|
475
|
+
hook: IJBSplitHook(address(0))
|
|
476
|
+
});
|
|
477
|
+
// Group the splits under the USDT token's group ID (token address as uint256).
|
|
478
|
+
JBSplitGroup[] memory splitGroups = new JBSplitGroup[](1);
|
|
479
|
+
splitGroups[0] = JBSplitGroup({groupId: uint256(uint160(address(usdt))), splits: splits});
|
|
480
|
+
// Assign the split groups to the ruleset.
|
|
481
|
+
rulesetConfig[0].splitGroups = splitGroups;
|
|
482
|
+
|
|
483
|
+
// Configure a payout limit of 500 USDT so sendPayoutsOf can distribute funds.
|
|
484
|
+
JBCurrencyAmount[] memory payoutLimits = new JBCurrencyAmount[](1);
|
|
485
|
+
payoutLimits[0] = JBCurrencyAmount({amount: uint224(500e6), currency: uint32(uint160(address(usdt)))});
|
|
486
|
+
// Create the fund access limit group linking the terminal, token, and payout limit.
|
|
487
|
+
JBFundAccessLimitGroup[] memory fundAccessLimitGroups = new JBFundAccessLimitGroup[](1);
|
|
488
|
+
fundAccessLimitGroups[0] = JBFundAccessLimitGroup({
|
|
489
|
+
terminal: address(jbMultiTerminal()),
|
|
490
|
+
token: address(usdt),
|
|
491
|
+
payoutLimits: payoutLimits,
|
|
492
|
+
surplusAllowances: new JBCurrencyAmount[](0)
|
|
493
|
+
});
|
|
494
|
+
// Assign the fund access limit groups to the ruleset.
|
|
495
|
+
rulesetConfig[0].fundAccessLimitGroups = fundAccessLimitGroups;
|
|
496
|
+
|
|
497
|
+
// Configure the terminal to accept MockUSDT with 6 decimals.
|
|
498
|
+
JBTerminalConfig[] memory termConfigs = new JBTerminalConfig[](1);
|
|
499
|
+
JBAccountingContext[] memory tokensToAccept = new JBAccountingContext[](1);
|
|
500
|
+
// USDT accounting context: 6 decimals, currency keyed to token address.
|
|
501
|
+
tokensToAccept[0] =
|
|
502
|
+
JBAccountingContext({token: address(usdt), decimals: 6, currency: uint32(uint160(address(usdt)))});
|
|
503
|
+
// Link terminal to accounting context.
|
|
504
|
+
termConfigs[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: tokensToAccept});
|
|
505
|
+
|
|
506
|
+
// Launch the project with splits and payout limits, return its ID.
|
|
507
|
+
return jbController()
|
|
508
|
+
.launchProjectFor({
|
|
509
|
+
owner: projectOwner,
|
|
510
|
+
projectUri: "usdtSplitProject",
|
|
511
|
+
rulesetConfigurations: rulesetConfig,
|
|
512
|
+
terminalConfigurations: termConfigs,
|
|
513
|
+
memo: ""
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// Allow the test contract to receive native ETH (required for some test helpers).
|
|
518
|
+
receive() external payable {}
|
|
519
|
+
}
|
package/test/helpers/JBTest.sol
CHANGED
package/test/mock/MockERC20.sol
CHANGED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.28;
|
|
3
|
+
|
|
4
|
+
/// @notice Mimics Tether (USDT) whose transfer/transferFrom/approve return void instead of bool.
|
|
5
|
+
/// @dev Uses inline assembly to return empty data (no bool), matching USDT's on-chain behavior.
|
|
6
|
+
/// This breaks naive IERC20 callers that expect a bool return value.
|
|
7
|
+
contract MockUSDT {
|
|
8
|
+
// Token metadata matching USDT's 6-decimal convention.
|
|
9
|
+
string public name = "Mock Tether USD";
|
|
10
|
+
// Short ticker symbol for the mock token.
|
|
11
|
+
string public symbol = "USDT";
|
|
12
|
+
// USDT uses 6 decimals, not 18 like most ERC-20 tokens.
|
|
13
|
+
uint8 public decimals = 6;
|
|
14
|
+
// Running total of all minted tokens.
|
|
15
|
+
uint256 public totalSupply;
|
|
16
|
+
|
|
17
|
+
// Maps each address to its token balance.
|
|
18
|
+
mapping(address => uint256) public balanceOf;
|
|
19
|
+
// Maps owner => spender => allowance for delegated transfers.
|
|
20
|
+
mapping(address => mapping(address => uint256)) public allowance;
|
|
21
|
+
|
|
22
|
+
/// @notice Mints tokens to a recipient (test helper, not part of USDT interface).
|
|
23
|
+
/// @param to The address to receive newly minted tokens.
|
|
24
|
+
/// @param amount The number of tokens to mint.
|
|
25
|
+
function mint(address to, uint256 amount) external {
|
|
26
|
+
// Credit the recipient's balance with the minted amount.
|
|
27
|
+
balanceOf[to] += amount;
|
|
28
|
+
// Increase the total supply to reflect the new tokens.
|
|
29
|
+
totalSupply += amount;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/// @notice Sets the spender's allowance. Returns VOID like real USDT.
|
|
33
|
+
/// @param spender The address authorized to spend tokens.
|
|
34
|
+
/// @param amount The maximum amount the spender can transfer.
|
|
35
|
+
function approve(address spender, uint256 amount) external {
|
|
36
|
+
// Record the new allowance for the caller-spender pair.
|
|
37
|
+
allowance[msg.sender][spender] = amount;
|
|
38
|
+
// Use assembly to return without any data (void), matching USDT behavior.
|
|
39
|
+
assembly {
|
|
40
|
+
return(0, 0)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// @notice Transfers tokens from caller to recipient. Returns VOID like real USDT.
|
|
45
|
+
/// @param to The address to receive the tokens.
|
|
46
|
+
/// @param amount The number of tokens to transfer.
|
|
47
|
+
function transfer(address to, uint256 amount) external {
|
|
48
|
+
// Ensure the sender has enough tokens to cover the transfer.
|
|
49
|
+
require(balanceOf[msg.sender] >= amount, "MockUSDT: insufficient balance");
|
|
50
|
+
// Debit the sender's balance by the transfer amount.
|
|
51
|
+
balanceOf[msg.sender] -= amount;
|
|
52
|
+
// Credit the recipient's balance with the transferred tokens.
|
|
53
|
+
balanceOf[to] += amount;
|
|
54
|
+
// Use assembly to return without any data (void), matching USDT behavior.
|
|
55
|
+
assembly {
|
|
56
|
+
return(0, 0)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/// @notice Transfers tokens on behalf of an owner. Returns VOID like real USDT.
|
|
61
|
+
/// @param from The address whose tokens are being spent.
|
|
62
|
+
/// @param to The address to receive the tokens.
|
|
63
|
+
/// @param amount The number of tokens to transfer.
|
|
64
|
+
function transferFrom(address from, address to, uint256 amount) external {
|
|
65
|
+
// Ensure the owner has enough tokens for the transfer.
|
|
66
|
+
require(balanceOf[from] >= amount, "MockUSDT: insufficient balance");
|
|
67
|
+
// Ensure the caller is authorized to spend at least this amount.
|
|
68
|
+
require(allowance[from][msg.sender] >= amount, "MockUSDT: insufficient allowance");
|
|
69
|
+
// Reduce the caller's remaining allowance by the transferred amount.
|
|
70
|
+
allowance[from][msg.sender] -= amount;
|
|
71
|
+
// Debit the owner's balance by the transfer amount.
|
|
72
|
+
balanceOf[from] -= amount;
|
|
73
|
+
// Credit the recipient's balance with the transferred tokens.
|
|
74
|
+
balanceOf[to] += amount;
|
|
75
|
+
// Use assembly to return without any data (void), matching USDT behavior.
|
|
76
|
+
assembly {
|
|
77
|
+
return(0, 0)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|