# Payment flow for wrapped ICP

**URL:** <https://forum.dfinity.org/t/payment-flow-for-wrapped-icp/17144>\
**Category:** Developers\
**Created:** [December 7, 2022, 12:38pm UTC](https://forum.dfinity.org/t/payment-flow-for-wrapped-icp/17144 "2022-12-07T12:38:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![timo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timo/32/5543_2.png) [@timo](https://forum.dfinity.org/u/timo)\
**Post date:** [December 7, 2022, 12:38pm UTC](https://forum.dfinity.org/t/payment-flow-for-wrapped-icp/17144/1 "2022-12-07T12:38:15Z")

</div>

I have looked for code repos for “wrapped ICP”. I found only these:

- [GitHub - ICPSwap-Labs/ic-wicp](https://github.com/ICPSwap-Labs/ic-wicp)
- [GitHub - Psychedelic/wicp: Wrapped ICP (WICP) - A composable and interoperable wrapped version of ICP.](https://github.com/Psychedelic/wicp)
- [GitHub - C3-Protocol/Wrapped-ICP: motoko code for a Wrapped ICP token canister on DFINITY's IC](https://github.com/C3-Protocol/Wrapped-ICP)

From what I understand they work in this way:

- different users are sending to the same deposit account id
- when users claim their wrapped tokens they must do so by calling from the principal that made the deposit on the ICP ledger
- users (or their frontend) remembers the block height of the deposit and submit it when claiming the wrapped tokens

Does anyone know other repos that do it differently? The approach chosen here is surprising because it does not make use of subaccounts in the ICP ledger. The two downsides of the approach taken here are, if I understand correctly:

- you cannot deposit funds from an account you do not control (e.g. an exchange) and if you accidentally do then you lose the funds
- the wrapped token canister has to keep a record of the used block heights forever or otherwise they could get claimed a second time

An approach using one subaccount per user seems preferable and not have these drawback. Am I missing something? Or why was this approach chosen? And is there a public repo that has a different payment flow?

---

<div class="post-metadata">

**Author:** ![infu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/infu/32/11321_2.png) [@infu](https://forum.dfinity.org/u/infu)\
**Post date:** [December 7, 2022, 2:11pm UTC](https://forum.dfinity.org/t/payment-flow-for-wrapped-icp/17144/2 "2022-12-07T14:11:41Z")

</div>

There is also Anvil [nftanvil/packages/nftanvil\_canisters/mo/pwr.mo at main · infu/nftanvil · GitHub](https://github.com/infu/nftanvil/blob/main/packages/nftanvil_canisters/mo/pwr.mo#L997) (related functions: pwr\_purchase\_intent, pwr\_purchase\_claim, pwr\_withdraw, nft\_mint)  
and Sonic (not OS, [GitHub - Psychedelic/sonic-js: Sonic-js is a library that holds an API for interacting with Swap Canister](https://github.com/Psychedelic/sonic-js)) which wraps wrapped ICP. This way swaps happen with one request without additional inter-canister calls.

The reason we needed to wrap ICP was so we can create the missing notify (or something like it) function and allow our whitelisted canisters to use it. It’s a lot easier and takes 1 update call to the ICP wrapping canister, which makes another call to the canister which consumes it.

> [@timo](#):
>
> you cannot deposit funds from an account you do not control (e.g. an exchange) and if you accidentally do then you lose the funds

We are using dedicated subaccounts for every user depositing ICP and we haven’t had such a problem.

> [@timo](#):
>
> - the wrapped token canister has to keep a record of the used block heights forever or otherwise they could get claimed a second time

We are finalizing the claim only after the funds get transferred from the user subaccount into the main canister account. Not using block heights at all.

> [@timo](#):
>
> An approach using one subaccount per user seems preferable and not have these drawback. Am I missing something? Or why was this approach chosen?

I believe their devs complained they have to load their canisters with complex crypto hashing functions and it was hard for developers to understand subaccounts. One of the reasons why ICRC-1’s implementation doesn’t require hashing functions.

---

<div class="post-metadata">

**Author:** ![timo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timo/32/5543_2.png) [@timo](https://forum.dfinity.org/u/timo)\
**Post date:** [December 7, 2022, 3:11pm UTC](https://forum.dfinity.org/t/payment-flow-for-wrapped-icp/17144/3 "2022-12-07T15:11:35Z")

</div>

Sorry, I couldn’t follow. Are you saying the Sonic swap canister (which I guess isn’t open source?) wraps wrapped ICP, and the outer wrapping has a different flow? But the inner wrapping happens is still based on block height notification?

---

<div class="post-metadata">

**Author:** ![infu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/infu/32/11321_2.png) [@infu](https://forum.dfinity.org/u/infu)\
**Post date:** [December 7, 2022, 4:05pm UTC](https://forum.dfinity.org/t/payment-flow-for-wrapped-icp/17144/4 "2022-12-07T16:05:21Z")

</div>

Yes, it’s not open-source or at least I don’t know where its source is. I know that because I made a blast for it [[Internet Computer Content Validation Bootstrap](https://jglts-daaaa-aaaai-qnpma-cai.ic0.app/sonic)] you can see how it works yourself.  
Sonic wraps all tokens including wicp.  
I am not sure I understand what you are referring to by ‘inner’ and ‘outer’, but yeah they have different flows.  
The first wrapping uses block height.

 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/a/a58819e91ee234333e4af05f06542a7752fd5475.png)  
The second one is using `approve` flow  
 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/b/b0330facc9133acef1be0943c2c24989cf2beb88.png)

---

<div class="post-metadata">

**Author:** ![timo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timo/32/5543_2.png) [@timo](https://forum.dfinity.org/u/timo)\
**Post date:** [December 7, 2022, 4:15pm UTC](https://forum.dfinity.org/t/payment-flow-for-wrapped-icp/17144/5 "2022-12-07T16:15:22Z")

</div>

Ok, thanks. Yes, `inner = first = wicp`, `outer = second = sonic`.
