# TesorerIA > A group's shared fund in Argentine pesos (wARS) on Celo, run by an agent within limits that a contract enforces. Members contribute wARS or USDT; the agent converts the USDT to wARS, pays members back for the expense the group agreed on, up to a weekly cap, and turns every other payment into a proposal the members vote on. Every fund is its own contract, deployed by a factory: the FundFactory (version 1) or the FundFactoryV2 (version 2), which is where new funds come from. The agent can only pay members, never above the weekly cap, and, in a FundFactoryV2 fund, send the fee that fund sets aside (each one sets its own; the web creates them at 0.25 %) to TesorerIA's account, which anyone can do; and it can't change the rules. Everything else takes the votes the fund requires: any other payment, adding, removing or replacing a member, changing the weekly cap, the votes or the agent, and closing the fund. A member who leaves is voted out and takes their share of the fund, in proportion to what they contributed; closing the fund splits it the same way among the members. ## Network - Celo mainnet, chain id 42220 - [Blockscout](https://celo.blockscout.com): the explorer the addresses here link to ## Contracts - [FundFactory](https://celo.blockscout.com/address/0xdF3B0d9edCA58Aac7c9Db4F2931f3559daf82020): deploys each version 1 fund (`Fund`), and is verified - [FundFactoryV2](https://celo.blockscout.com/address/0x1337a61CF7fDeF412E04894FE705d4341878d4d3): deploys each version 2 fund (`FundV2`), the kind new funds are, and is verified - Every fund they deployed: `funds(i)` for each `i` below `fundCount()`, on either factory - [A real group's fund](https://celo.blockscout.com/address/0x9A74F670F3c59Ae4B8450fdD477b0461b89D2dfD): its Fund, with all it did on chain - [Its public page](https://tesoreria.finance/f/0x9A74F670F3c59Ae4B8450fdD477b0461b89D2dfD/publico): the same fund on this site, read-only ## Tokens and market - [wARS](https://celo.blockscout.com/address/0x0DC4F92879B7670e5f4e4e6e3c801D229129D90D): Ripio's Argentine peso, 18 decimals - [USDT](https://celo.blockscout.com/address/0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e): 6 decimals - [The wARS/USDT pool](https://celo.blockscout.com/address/0x5D8ef8B839be522b9E3d60a51EDB5837CD0b2391): Uniswap v3, fee tier 100 (0.01 %), where the agent converts USDT to wARS ### Where the money comes from Each member has an account on this site: a Safe smart account on Celo, which their passkey controls. They bring pesos as wARS from Ripio, or from any Celo wallet that holds wARS. From Ripio, in its app they withdraw wARS on the Celo network to that account, or they load them from the fund's screen. Or they send USDT on Celo from any exchange. The wARS the agent pays a member back, they can pass to their own Ripio account and sell them 1:1 for pesos there. ### USDT contributions in version 1 In a version 1 fund, a USDT contribution is credited to the member at once, in wARS, at the pool's 30-minute TWAP: that's `creditedWars` in `Contribution`, and what the contract counts, also when it splits the fund at the close. The agent then converts the USDT with `convert`, whose minimum can't be more than 2 % below the TWAP quote. What the swap gets is `warsOut` in `Conversion`. Toward a member's dues, this site counts each USDT contribution at what its conversion got, matching conversions to USDT contributions in order of arrival: the member who contributed that USDT covers the difference from what was credited, or keeps it if the swap got more. Until it's converted, it counts at what was credited. What's left to pay under 0.5 % of the weekly fee isn't called a debt; it goes with the next week's. ## Agent - [Its wallet](https://celo.blockscout.com/address/0x6BE3c1eB63A4edbc6C23c281F93F81B14eF3a671): it pays gas in USDT and tags every transaction with celo_fbe4d00a2cb4 - [Its ERC-8004 identity](https://8004scan.io/agents/celo/9887): agent 9887 in the [Identity Registry](https://celo.blockscout.com/address/0x8004A169FB4a3325136EB29fA0ceB6D2e539a432) - [Its ERC-8004 registration file](https://raw.githubusercontent.com/ruizemanuel/TesorerIA/main/packages/agent/registration.json): who it is, what it does and its limits, as JSON ### Its own limits On top of the contract's, in each fund, where a day is the last 86,400 blocks. A reimbursement over a limit becomes a proposal for the members to vote on, never a payment. They live in the agent's code, not in the contract, so the chain can't check them the way it checks the contract's. - At most 100,000 wARS per reimbursement, and 150,000 wARS a day - At most 500 USDT per conversion, and 1,000 USDT a day - At most 20 transactions a day ## The week A fund's week is `currentWeek() = (block.timestamp - startTime) / 7 days`, where `startTime` is the `block.timestamp` of the fund's deployment, set in its constructor. So each fund's week turns at the day and time it was deployed, not at midnight. The weekly cap counts `spentInWeek[currentWeek()]`: what the agent reimbursed for the agreed expense in the current week. The contract counts weeks from 0, and so does the `week` in `Reimbursement`. This site's weekly summaries count them from 1, as people do: its week N is the contract's week N − 1. ## Functions The ones of `Fund` (version 1) the agent and this site call. Members call `contributeWars`, `contributeUsdt`, `propose` and `vote`, and a contribution needs an ERC-20 `approve` of the fund first. The agent calls `convert`, `reimburseAgreedExpense` and `propose`. A member's proposal counts their vote at once; the agent's starts with none. And anyone can call `execute` once a proposal has the votes it needs. - `convert(uint256 usdtAmount, uint256 minWarsOut)` - `reimburseAgreedExpense(address member, uint256 amount, bytes32 ref)` - `propose(uint8 action, address a, address b, uint256 amount, string note)` - `contributeWars(uint256 amount)` - `contributeUsdt(uint256 amount)` - `vote(uint256 id)` - `execute(uint256 id)` And what they read, which anyone can: - `agent()` - `closed()` - `members()` - `votesRequired()` - `weeklyCap()` - `startTime()` - `currentWeek()` - `spentInWeek(uint256)` - `contributed(address)` - `totalContributed()` - `proposalCount()` - `balanceCap()` - `quoteUsdtInWars(uint256 usdtAmount)` - `name()` - `agreedExpense()` - `balanceInWars()` - `getProposal(uint256 id)` - `voteCount(uint256 id)` - `hasVoted(uint256 id, address member)` - `isMember(address member)` `propose`'s `action` is `Fund.Action`: 0 Pay, 1 AddMember, 2 RemoveMember, 3 ReplaceMember, 4 SetWeeklyCap, 5 SetVotesRequired, 6 SetAgent, 7 Close. ## Version 2 A version 2 fund (`FundV2`, deployed by the [FundFactoryV2](https://celo.blockscout.com/address/0x1337a61CF7fDeF412E04894FE705d4341878d4d3)) is what new funds are: the web creates them. What is not said here works as in the sections above, except that version 2 has no `contributeWars`, `contributeUsdt`, `balanceInWars` or `quoteUsdtInWars` (it has `contribute`, `contributeDollar`, `balanceInCurrency` and `quoteDollar` instead), and its `convert` is not version 1's `convert(uint256,uint256)`. - **Any currency.** A fund's currency is a parameter of `createFund`: any wFIAT, with or without a dollar and the Uniswap v3 pool of the two. Read them with `currency()`, `dollar()` and `pool()`. A fund without a dollar takes only its currency. Version 2 funds can use any wFIAT, and the web creates them in wARS with USDT today. - **USDT is pending until it is converted.** A USDT contribution is not credited when it arrives: it stays pending, in `pendingDollar(address)` (the sum is `totalPendingDollar()`), until the agent converts it. Then each member is credited at what the conversion really got, net of the fee: that's `credited` in `Conversion`, which comes once per member. `Contribution` carries `credited` = 0 for USDT. A member voted out gets their pending USDT back, and a replacement account takes it over. - **Conversion.** `convert` is the agent's: it swaps several members' dollars in one swap, with the same floor as version 1 (its minimum can't be more than 2 % below the TWAP quote of the whole amount), and gives each member the share `received * amount / total`, rounded down (that's `currencyOut` in their `Conversion`: their part of the swap, not the whole swap), takes the fee off it and credits the rest (`credited`). A swap that doesn't take all the dollars reverts. - **The fee.** New funds keep 0.25 % for gas: each fund has a `feeBps`, fixed when it's created (the contract allows up to 1 %; the web sets 0.25 %), and sets that share aside, in its currency, from every contribution and every converted share. What is set aside is `feeOwed`; `contributed` counts what is left; `availableCurrency()` is what the fund can pay or split, its balance of the currency minus `feeOwed`. And anyone can call `payFee` to send `feeOwed` to the [fee recipient](https://celo.blockscout.com/address/0x5Dc9C76C6999C6C604b3D91C040D17b125ca4581), with the fund open or closed. - **`GiveBack`.** `GiveBack` pays a member back part of what they contributed, by vote, and lowers their `contributed` by as much, so their share if they leave or the fund closes is right. - **Limits.** Each member, and the agent, can make at most 10 proposals a week, counted from zero again each week (`proposalsInWeek`), with notes of at most 560 bytes. `weeklyCap` can't exceed `balanceCap`, which counts the available currency and the pending dollars, at the TWAP. Members call `contribute`, `contributeDollar`, `propose` and `vote`, and a contribution needs an ERC-20 `approve` of the fund first. The agent calls `convert`, `reimburseAgreedExpense` and `propose`, and sends `payFee` once a week. Anyone can call `execute` once a proposal has the votes it needs. What version 2 adds or changes: - `contribute(uint256 amount)` - `contributeDollar(uint256 amount)` - `convert(address[] members_, uint256[] dollarAmounts, uint256 minCurrencyOut)` - `payFee()` And what it reads: - `currency()` - `dollar()` - `pool()` - `feeBps()` - `feeOwed()` - `availableCurrency()` - `balanceInCurrency()` - `quoteDollar(uint256 dollarAmount)` - `pendingDollar(address)` - `totalPendingDollar()` - `proposalsInWeek(uint256 week, address)` `propose`'s `action` is `FundV2.Action`: 0 Pay, 1 AddMember, 2 RemoveMember, 3 ReplaceMember, 4 SetWeeklyCap, 5 SetVotesRequired, 6 SetAgent, 7 Close, 8 GiveBack. Its events keep version 1's types, so the same decoders read them, but some arguments have other names: `Contribution` has `credited` where version 1's has `creditedWars`, `MemberRemoved` has `currencyReturned` and `dollarReturned` (version 1: `warsReturned`, `usdtReturned`), and `FundClosed` and `RemainderDistributed` have `currencyBalance` and `dollarBalance` (version 1: `warsBalance`, `usdtBalance`). `Conversion` is the one that differs: `Conversion(member, dollarIn, currencyOut, credited)` comes once per member, and `currencyOut` is that member's share of the swap. New are `ContributionGivenBack(member, amount)` and `FeePaid(amount)`. ## Errors The errors of `Fund` (version 1), none with parameters, and their selectors. `FundV2` has them all too, and five more: - `InvalidParams()` 0xa86b6512 - `NotMember()` 0x291fc442 - `OnlyAgent()` 0x73620441 - `OnlyMemberOrAgent()` 0x6f94c5f4 - `FundIsClosed()` 0xcf3503dc - `ZeroAmount()` 0x1f2a2005 - `BalanceCapExceeded()` 0x2c5ff865 - `WeeklyCapExceeded()` 0xc80ff02b - `InsufficientBalance()` 0xf4d678b8 - `RecipientNotMember()` 0x919941a4 - `MinOutTooLow()` 0x7218c912 - `InsufficientOutput()` 0xbb2875c3 - `OnlyPool()` 0x4b602735 - `ProposalNotFound()` 0x635e8737 - `ProposalExpired()` 0x28a72379 - `ProposalAlreadyExecuted()` 0x51618d53 - `AlreadyVoted()` 0x7c9a1cf9 - `NotEnoughVotes()` 0x0b7b8dc6 - `SwapOverpayment()` 0xdf0f68a0 - `FundNotClosed()` 0x593cbbf1 The five `FundV2` adds: - `NoDollar()` 0xad2b14af - `InsufficientPending()` 0xeed47552 - `GiveBackTooLarge()` 0x23a618cb - `TooManyProposals()` 0x188f201e - `NoteTooLong()` 0x155be563 ## On this site Pages answer in Spanish or in English: the `lang` cookie (`es` or `en`) that the ES · EN switch sets, or else the Accept-Language header. A fund's pages, where `` is its address: - `https://tesoreria.finance/f//publico`: its public page, read-only, if its group turned it on - `https://tesoreria.finance/f//publico/movimientos`: all its movements - `https://tesoreria.finance/f//publico?p=resumen&semana=`: the summary of its week N, counted from 1 - `https://tesoreria.finance/f//publico?p=comprobante&id=:`: one movement's receipt ## Optional - [Source code](https://github.com/ruizemanuel/TesorerIA): the contracts, the agent and this site