From 449f26dc5286d7f816a1b8d22548c1b68ee63e6d Mon Sep 17 00:00:00 2001 From: Michael Liu Date: Tue, 26 Nov 2024 23:50:35 -0500 Subject: [PATCH 01/16] Solana autoredeem upgrade --- packages/huma-shared/src/solana/idl/huma.json | 1400 +++-------------- packages/huma-shared/src/solana/idl/huma.ts | 110 +- .../src/solana/types/solanaPoolState.ts | 1 + .../Lend/solanaAddRedemption/3-Transfer.tsx | 4 +- .../Lend/solanaSupply/6-Transfer.tsx | 42 +- 5 files changed, 311 insertions(+), 1246 deletions(-) diff --git a/packages/huma-shared/src/solana/idl/huma.json b/packages/huma-shared/src/solana/idl/huma.json index 394d9694..1a9d27c2 100644 --- a/packages/huma-shared/src/solana/idl/huma.json +++ b/packages/huma-shared/src/solana/idl/huma.json @@ -312,6 +312,7 @@ "Records a new redemption request.", "", "# Arguments", + "* `lender` - The lender whose shares are being requested for redemption.", "* `shares` - The number of shares the lender wants to redeem.", "", "# Access Control", @@ -320,7 +321,7 @@ "discriminator": [72, 203, 201, 17, 75, 60, 157, 47], "accounts": [ { - "name": "lender", + "name": "signer", "signer": true }, { @@ -405,7 +406,7 @@ "path": "tranche_mint" }, { - "kind": "account", + "kind": "arg", "path": "lender" } ] @@ -434,59 +435,11 @@ }, { "name": "pool_tranche_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "tranche_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "lender_tranche_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "lender" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "tranche_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "extra_account_meta_list", @@ -520,6 +473,10 @@ } ], "args": [ + { + "name": "lender", + "type": "pubkey" + }, { "name": "shares", "type": "u128" @@ -989,59 +946,11 @@ }, { "name": "pool_tranche_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "tranche_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "lender_tranche_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "lender" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "tranche_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "extra_account_meta_list", @@ -1389,31 +1298,7 @@ } }, { - "name": "pool_underlying_token", - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "underlying_token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "name": "pool_underlying_token" }, { "name": "junior_mint", @@ -1493,60 +1378,12 @@ }, { "name": "pool_junior_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "tranche_token_program" - }, - { - "kind": "account", - "path": "junior_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "pool_senior_token", "writable": true, - "optional": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "tranche_token_program" - }, - { - "kind": "account", - "path": "senior_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "optional": true }, { "name": "underlying_token_program" @@ -1631,31 +1468,7 @@ }, { "name": "lender_tranche_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "lender" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "tranche_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "token_program", @@ -1751,31 +1564,7 @@ } }, { - "name": "pool_underlying_token", - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "underlying_token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "name": "pool_underlying_token" }, { "name": "junior_mint", @@ -1855,60 +1644,12 @@ }, { "name": "pool_junior_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "tranche_token_program" - }, - { - "kind": "account", - "path": "junior_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "pool_senior_token", "writable": true, - "optional": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "tranche_token_program" - }, - { - "kind": "account", - "path": "senior_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "optional": true }, { "name": "underlying_token_program" @@ -2079,31 +1820,7 @@ }, { "name": "lender_tranche_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "lender" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "tranche_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "token_program", @@ -2238,31 +1955,7 @@ }, { "name": "pool_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "token_program" @@ -2709,87 +2402,15 @@ }, { "name": "pool_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "underlying_token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "depositor_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "depositor" - }, - { - "kind": "account", - "path": "underlying_token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "depositor_tranche_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "depositor" - }, - { - "kind": "account", - "path": "tranche_token_program" - }, - { - "kind": "account", - "path": "tranche_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "underlying_token_program" @@ -2989,59 +2610,11 @@ }, { "name": "pool_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "lender_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "lender" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "token_program" @@ -3182,59 +2755,11 @@ }, { "name": "pool_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "borrower_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "borrower" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "token_program" @@ -3387,118 +2912,18 @@ } }, { - "name": "pool_owner_treasury_junior_token", - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_config.pool_owner_treasury", - "account": "PoolConfig" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "junior_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "name": "pool_owner_treasury_junior_token" }, { "name": "pool_owner_treasury_senior_token", - "optional": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_config.pool_owner_treasury", - "account": "PoolConfig" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "senior_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "optional": true }, { - "name": "ea_junior_token", - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_config.evaluation_agent", - "account": "PoolConfig" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "junior_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "name": "ea_junior_token" }, { "name": "ea_senior_token", - "optional": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_config.evaluation_agent", - "account": "PoolConfig" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "senior_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "optional": true }, { "name": "token_program", @@ -3862,87 +3287,15 @@ }, { "name": "pool_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "underlying_token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "depositor_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "depositor" - }, - { - "kind": "account", - "path": "underlying_token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "depositor_tranche_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "depositor" - }, - { - "kind": "account", - "path": "tranche_token_program" - }, - { - "kind": "account", - "path": "tranche_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "underlying_token_program" @@ -4105,60 +3458,11 @@ }, { "name": "pool_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "borrower_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "credit_state.borrower", - "account": "CreditState" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "token_program" @@ -4320,59 +3624,11 @@ }, { "name": "pool_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "borrower_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "borrower" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "token_program" @@ -4695,6 +3951,42 @@ ], "args": [] }, + { + "name": "realloc_pool_config", + "discriminator": [23, 125, 97, 240, 16, 108, 85, 88], + "accounts": [ + { + "name": "signer", + "writable": true, + "signer": true + }, + { + "name": "huma_config", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [104, 117, 109, 97, 95, 99, 111, 110, 102, 105, 103] + }, + { + "kind": "account", + "path": "huma_config.id", + "account": "HumaConfig" + } + ] + } + }, + { + "name": "pool_config", + "writable": true + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [] + }, { "name": "refresh_credit", "docs": [ @@ -5250,31 +4542,7 @@ } }, { - "name": "new_ea_junior_token", - "pda": { - "seeds": [ - { - "kind": "arg", - "path": "new_ea" - }, - { - "kind": "account", - "path": "tranche_token_program" - }, - { - "kind": "account", - "path": "junior_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "name": "new_ea_junior_token" }, { "name": "underlying_mint", @@ -5282,60 +4550,11 @@ }, { "name": "pool_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "underlying_token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "ea_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_config.evaluation_agent", - "account": "PoolConfig" - }, - { - "kind": "account", - "path": "underlying_token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "underlying_token_program" @@ -5580,158 +4799,61 @@ } }, { - "name": "senior_mint", - "optional": true, - "pda": { - "seeds": [ - { - "kind": "const", - "value": [ - 115, 101, 110, 105, 111, 114, 95, 116, 114, 97, 110, 99, 104, - 101, 95, 109, 105, 110, 116 - ] - }, - { - "kind": "account", - "path": "pool_config" - } - ] - } - }, - { - "name": "pool_authority", - "pda": { - "seeds": [ - { - "kind": "const", - "value": [ - 112, 111, 111, 108, 95, 97, 117, 116, 104, 111, 114, 105, 116, - 121 - ] - }, - { - "kind": "account", - "path": "pool_config" - } - ] - } - }, - { - "name": "new_treasury_junior_token", - "pda": { - "seeds": [ - { - "kind": "arg", - "path": "new_treasury" - }, - { - "kind": "account", - "path": "tranche_token_program" - }, - { - "kind": "account", - "path": "junior_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } - }, - { - "name": "new_treasury_senior_token", - "optional": true, - "pda": { - "seeds": [ - { - "kind": "arg", - "path": "new_treasury" - }, - { - "kind": "account", - "path": "tranche_token_program" - }, - { - "kind": "account", - "path": "senior_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } - }, - { - "name": "underlying_mint", - "relations": ["pool_config"] - }, - { - "name": "pool_underlying_token", - "writable": true, + "name": "senior_mint", + "optional": true, "pda": { "seeds": [ { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "underlying_token_program" + "kind": "const", + "value": [ + 115, 101, 110, 105, 111, 114, 95, 116, 114, 97, 110, 99, 104, + 101, 95, 109, 105, 110, 116 + ] }, { "kind": "account", - "path": "underlying_mint" + "path": "pool_config" } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } + ] } }, { - "name": "pool_owner_treasury_underlying_token", - "writable": true, + "name": "pool_authority", "pda": { "seeds": [ { - "kind": "account", - "path": "pool_config.pool_owner_treasury", - "account": "PoolConfig" - }, - { - "kind": "account", - "path": "underlying_token_program" + "kind": "const", + "value": [ + 112, 111, 111, 108, 95, 97, 117, 116, 104, 111, 114, 105, 116, + 121 + ] }, { "kind": "account", - "path": "underlying_mint" + "path": "pool_config" } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } + ] } }, + { + "name": "new_treasury_junior_token" + }, + { + "name": "new_treasury_senior_token", + "optional": true + }, + { + "name": "underlying_mint", + "relations": ["pool_config"] + }, + { + "name": "pool_underlying_token", + "writable": true + }, + { + "name": "pool_owner_treasury_underlying_token", + "writable": true + }, { "name": "underlying_token_program" }, @@ -7025,87 +6147,15 @@ }, { "name": "pool_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "underlying_token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "lender_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "lender" - }, - { - "kind": "account", - "path": "underlying_token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "lender_tranche_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "lender" - }, - { - "kind": "account", - "path": "tranche_token_program" - }, - { - "kind": "account", - "path": "tranche_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "underlying_token_program" @@ -7208,60 +6258,11 @@ }, { "name": "pool_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "ea_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_config.evaluation_agent", - "account": "PoolConfig" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "token_program" @@ -7364,59 +6365,11 @@ }, { "name": "pool_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "signer_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "signer" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "token_program" @@ -7519,59 +6472,11 @@ }, { "name": "pool_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "pool_authority" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "signer_underlying_token", - "writable": true, - "pda": { - "seeds": [ - { - "kind": "account", - "path": "signer" - }, - { - "kind": "account", - "path": "token_program" - }, - { - "kind": "account", - "path": "underlying_mint" - } - ], - "program": { - "kind": "const", - "value": [ - 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, - 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, - 219, 233, 248, 89 - ] - } - } + "writable": true }, { "name": "token_program" @@ -7804,6 +6709,10 @@ "name": "PoolClosedEvent", "discriminator": [76, 55, 28, 161, 130, 142, 226, 133] }, + { + "name": "PoolConfigReallocatedEvent", + "discriminator": [90, 254, 193, 102, 77, 252, 10, 50] + }, { "name": "PoolCreatedEvent", "discriminator": [25, 94, 75, 47, 112, 99, 53, 63] @@ -7990,6 +6899,10 @@ "code": 6214, "name": "AuthorizedInitialDepositorRequired" }, + { + "code": 6215, + "name": "LenderOrSentinelRequired" + }, { "code": 6301, "name": "ProtocolFeeHigherThanUpperLimit" @@ -8086,6 +6999,10 @@ "code": 6418, "name": "PoolNameTooLong" }, + { + "code": 6419, + "name": "InvalidPoolConfig" + }, { "code": 6501, "name": "PreviousAssetsNotWithdrawn" @@ -8106,6 +7023,14 @@ "code": 6505, "name": "EpochClosedTooEarly" }, + { + "code": 6506, + "name": "InsufficientAuthorizationForAutoRedemption" + }, + { + "code": 6507, + "name": "RedemptionCancellationDisabled" + }, { "code": 6601, "name": "ZeroPayPeriodsProvided" @@ -9477,7 +8402,8 @@ "* `max_senior_junior_ratio` - The upper bound of senior-to-junior ratio allowed.", "* `fixed_senior_yield_bps` - The fixed yield for senior tranche. Either this or tranches_risk_adjustment_bps is non-zero.", "* `tranches_risk_adjustment_bps` - Percentage of yield to be shifted from senior to junior. Either this or fixed_senior_yield_bps is non-zero.", - "* `withdrawal_lockup_period_days` - How long a lender has to wait after the last deposit before they can withdraw." + "* `withdrawal_lockup_period_days` - How long a lender has to wait after the last deposit before they can withdraw.", + "* `auto_redemption_after_lockup` - When enabled, lenders' shares are automatically redeemed after the lockup period." ], "type": { "kind": "struct", @@ -9501,6 +8427,10 @@ { "name": "withdrawal_lockup_period_days", "type": "u16" + }, + { + "name": "auto_redemption_after_lockup", + "type": "bool" } ] } @@ -10464,6 +9394,40 @@ "name": "FeeStructure" } } + }, + { + "name": "padding", + "type": { + "array": ["u8", 160] + } + } + ] + } + }, + { + "name": "PoolConfigReallocatedEvent", + "docs": [ + "The pool config has been reallocated.", + "", + "# Fields", + "* `pool_config` - The address of the pool config account.", + "* `account_span` - The size of the pool config account.", + "* `lamports_diff` - The increased rent." + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "pool_config", + "type": "pubkey" + }, + { + "name": "account_span", + "type": "u64" + }, + { + "name": "lamports_diff", + "type": "u64" } ] } diff --git a/packages/huma-shared/src/solana/idl/huma.ts b/packages/huma-shared/src/solana/idl/huma.ts index 67f788c5..1514c19c 100644 --- a/packages/huma-shared/src/solana/idl/huma.ts +++ b/packages/huma-shared/src/solana/idl/huma.ts @@ -356,6 +356,7 @@ export type Huma = { 'Records a new redemption request.', '', '# Arguments', + '* `lender` - The lender whose shares are being requested for redemption.', '* `shares` - The number of shares the lender wants to redeem.', '', '# Access Control', @@ -364,7 +365,7 @@ export type Huma = { discriminator: [72, 203, 201, 17, 75, 60, 157, 47] accounts: [ { - name: 'lender' + name: 'signer' signer: true }, { @@ -472,7 +473,7 @@ export type Huma = { path: 'trancheMint' }, { - kind: 'account' + kind: 'arg' path: 'lender' }, ] @@ -560,7 +561,7 @@ export type Huma = { }, { name: 'hookProgram' - address: 'BzaHku1HrxKYWTr89JwnWn232QYdnxz444VZ4nWeaziX' + address: 'JAhzUQ7nK7zeTdnbLDQR3y7UwSKnxeqdctCbjG8Z2abM' }, { name: 'tokenProgram' @@ -568,6 +569,10 @@ export type Huma = { }, ] args: [ + { + name: 'lender' + type: 'pubkey' + }, { name: 'shares' type: 'u128' @@ -1184,7 +1189,7 @@ export type Huma = { }, { name: 'hookProgram' - address: 'BzaHku1HrxKYWTr89JwnWn232QYdnxz444VZ4nWeaziX' + address: 'JAhzUQ7nK7zeTdnbLDQR3y7UwSKnxeqdctCbjG8Z2abM' }, { name: 'tokenProgram' @@ -3777,7 +3782,7 @@ export type Huma = { }, { name: 'hookProgram' - address: 'BzaHku1HrxKYWTr89JwnWn232QYdnxz444VZ4nWeaziX' + address: 'JAhzUQ7nK7zeTdnbLDQR3y7UwSKnxeqdctCbjG8Z2abM' }, { name: 'poolAuthority' @@ -4709,6 +4714,42 @@ export type Huma = { ] args: [] }, + { + name: 'reallocPoolConfig' + discriminator: [23, 125, 97, 240, 16, 108, 85, 88] + accounts: [ + { + name: 'signer' + writable: true + signer: true + }, + { + name: 'humaConfig' + pda: { + seeds: [ + { + kind: 'const' + value: [104, 117, 109, 97, 95, 99, 111, 110, 102, 105, 103] + }, + { + kind: 'account' + path: 'huma_config.id' + account: 'humaConfig' + }, + ] + } + }, + { + name: 'poolConfig' + writable: true + }, + { + name: 'systemProgram' + address: '11111111111111111111111111111111' + }, + ] + args: [] + }, { name: 'refreshCredit' docs: [ @@ -7733,6 +7774,10 @@ export type Huma = { name: 'poolClosedEvent' discriminator: [76, 55, 28, 161, 130, 142, 226, 133] }, + { + name: 'poolConfigReallocatedEvent' + discriminator: [90, 254, 193, 102, 77, 252, 10, 50] + }, { name: 'poolCreatedEvent' discriminator: [25, 94, 75, 47, 112, 99, 53, 63] @@ -7919,6 +7964,10 @@ export type Huma = { code: 6214 name: 'authorizedInitialDepositorRequired' }, + { + code: 6215 + name: 'lenderOrSentinelRequired' + }, { code: 6301 name: 'protocolFeeHigherThanUpperLimit' @@ -8015,6 +8064,10 @@ export type Huma = { code: 6418 name: 'poolNameTooLong' }, + { + code: 6419 + name: 'invalidPoolConfig' + }, { code: 6501 name: 'previousAssetsNotWithdrawn' @@ -8035,6 +8088,14 @@ export type Huma = { code: 6505 name: 'epochClosedTooEarly' }, + { + code: 6506 + name: 'insufficientAuthorizationForAutoRedemption' + }, + { + code: 6507 + name: 'redemptionCancellationDisabled' + }, { code: 6601 name: 'zeroPayPeriodsProvided' @@ -9407,6 +9468,7 @@ export type Huma = { '* `fixed_senior_yield_bps` - The fixed yield for senior tranche. Either this or tranches_risk_adjustment_bps is non-zero.', '* `tranches_risk_adjustment_bps` - Percentage of yield to be shifted from senior to junior. Either this or fixed_senior_yield_bps is non-zero.', '* `withdrawal_lockup_period_days` - How long a lender has to wait after the last deposit before they can withdraw.', + "* `auto_redemption_after_lockup` - When enabled, lenders' shares are automatically redeemed after the lockup period.", ] type: { kind: 'struct' @@ -9431,6 +9493,10 @@ export type Huma = { name: 'withdrawalLockupPeriodDays' type: 'u16' }, + { + name: 'autoRedemptionAfterLockup' + type: 'bool' + }, ] } }, @@ -10394,6 +10460,40 @@ export type Huma = { } } }, + { + name: 'padding' + type: { + array: ['u8', 160] + } + }, + ] + } + }, + { + name: 'poolConfigReallocatedEvent' + docs: [ + 'The pool config has been reallocated.', + '', + '# Fields', + '* `pool_config` - The address of the pool config account.', + '* `account_span` - The size of the pool config account.', + '* `lamports_diff` - The increased rent.', + ] + type: { + kind: 'struct' + fields: [ + { + name: 'poolConfig' + type: 'pubkey' + }, + { + name: 'accountSpan' + type: 'u64' + }, + { + name: 'lamportsDiff' + type: 'u64' + }, ] } }, diff --git a/packages/huma-web-shared/src/solana/types/solanaPoolState.ts b/packages/huma-web-shared/src/solana/types/solanaPoolState.ts index eb5cfdf4..144ca73b 100644 --- a/packages/huma-web-shared/src/solana/types/solanaPoolState.ts +++ b/packages/huma-web-shared/src/solana/types/solanaPoolState.ts @@ -36,4 +36,5 @@ export type SolanaPoolState = { poolOwnerIncomeWithdrawn: string } campaign?: SolanaCampaign + autoRedemptionAfterLockup?: boolean } diff --git a/packages/huma-widget/src/components/Lend/solanaAddRedemption/3-Transfer.tsx b/packages/huma-widget/src/components/Lend/solanaAddRedemption/3-Transfer.tsx index 35d99656..686af240 100644 --- a/packages/huma-widget/src/components/Lend/solanaAddRedemption/3-Transfer.tsx +++ b/packages/huma-widget/src/components/Lend/solanaAddRedemption/3-Transfer.tsx @@ -61,9 +61,9 @@ export function Transfer({ poolJuniorTrancheATA, } = getTokenAccounts(poolInfo, publicKey) const tx = await program.methods - .addRedemptionRequest(redeemBN) + .addRedemptionRequest(publicKey, redeemBN) .accountsPartial({ - lender: publicKey, + signer: publicKey, humaConfig: poolInfo.humaConfig, poolConfig: poolInfo.poolConfig, trancheMint: diff --git a/packages/huma-widget/src/components/Lend/solanaSupply/6-Transfer.tsx b/packages/huma-widget/src/components/Lend/solanaSupply/6-Transfer.tsx index 5f6c775e..d271893d 100644 --- a/packages/huma-widget/src/components/Lend/solanaSupply/6-Transfer.tsx +++ b/packages/huma-widget/src/components/Lend/solanaSupply/6-Transfer.tsx @@ -142,27 +142,6 @@ export function Transfer({ tx.add(createLenderAccountsTx) } - const depositTx = await program.methods - .deposit(supplyBigNumber) - .accountsPartial({ - approvedLender, - depositor: publicKey, - poolConfig: poolInfo.poolConfig, - underlyingMint: poolInfo.underlyingMint.address, - trancheMint: - selectedTranche === 'senior' - ? poolInfo.seniorTrancheMint - : poolInfo.juniorTrancheMint, - poolUnderlyingToken: poolInfo.poolUnderlyingTokenAccount, - depositorUnderlyingToken: underlyingTokenATA, - depositorTrancheToken: - selectedTranche === 'senior' ? seniorTrancheATA : juniorTrancheATA, - humaConfig: poolInfo.humaConfig, - underlyingTokenProgram: TOKEN_PROGRAM_ID, - }) - .transaction() - tx.add(depositTx) - // Approve automatic redemptions const sharesAmount = convertToShares( selectedTranche === 'senior' @@ -201,6 +180,27 @@ export function Transfer({ ), ) + const depositTx = await program.methods + .deposit(supplyBigNumber) + .accountsPartial({ + approvedLender, + depositor: publicKey, + poolConfig: poolInfo.poolConfig, + underlyingMint: poolInfo.underlyingMint.address, + trancheMint: + selectedTranche === 'senior' + ? poolInfo.seniorTrancheMint + : poolInfo.juniorTrancheMint, + poolUnderlyingToken: poolInfo.poolUnderlyingTokenAccount, + depositorUnderlyingToken: underlyingTokenATA, + depositorTrancheToken: + selectedTranche === 'senior' ? seniorTrancheATA : juniorTrancheATA, + humaConfig: poolInfo.humaConfig, + underlyingTokenProgram: TOKEN_PROGRAM_ID, + }) + .transaction() + tx.add(depositTx) + setTransaction(tx) } getTx() From fe642753c76cdcb6772aa389134489432652e411 Mon Sep 17 00:00:00 2001 From: Michael Liu Date: Sun, 22 Dec 2024 15:49:42 -0500 Subject: [PATCH 02/16] Upgrade stellar contract interface --- packages/examples/package.json | 10 ++++---- .../src/stellar/metadata/testnet.ts | 25 ++++++++++--------- .../huma-shared/src/stellar/types/metadata.ts | 2 +- packages/huma-web-shared/package.json | 10 ++++---- .../utils/fetchStellarDepositRecord.ts | 8 +++--- packages/huma-widget/package.json | 2 +- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/packages/examples/package.json b/packages/examples/package.json index 43f5ed74..e5af121d 100644 --- a/packages/examples/package.json +++ b/packages/examples/package.json @@ -43,11 +43,11 @@ "@solana/wallet-adapter-react-ui": "^0.9.35", "@solana/wallet-adapter-wallets": "^0.19.32", "@stellar/freighter-api": "^3.0.0", - "@huma-finance/soroban-credit-storage": "0.0.15-beta.50", - "@huma-finance/soroban-huma-config": "0.0.15-beta.50", - "@huma-finance/soroban-pool-storage": "0.0.15-beta.50", - "@huma-finance/soroban-sdk": "^0.0.15-beta.50", - "@huma-finance/soroban-tranche-vault": "0.0.15-beta.50", + "@huma-finance/soroban-credit-storage": "0.0.17", + "@huma-finance/soroban-huma-config": "0.0.17", + "@huma-finance/soroban-pool-storage": "0.0.17", + "@huma-finance/soroban-sdk": "^0.0.17", + "@huma-finance/soroban-tranche-vault": "0.0.17", "@stellar/stellar-sdk": "^12.3.0", "@coral-xyz/borsh": "^0.30.1", "@mui/icons-material": "^5.3.0", diff --git a/packages/huma-shared/src/stellar/metadata/testnet.ts b/packages/huma-shared/src/stellar/metadata/testnet.ts index d835beef..fc5eb50d 100644 --- a/packages/huma-shared/src/stellar/metadata/testnet.ts +++ b/packages/huma-shared/src/stellar/metadata/testnet.ts @@ -3,20 +3,21 @@ import { StellarPoolsInfo } from '../types/metadata' import { POOL_NAME, POOL_TYPE } from '../../utils/pool' export const STELLAR_TESTNET_METADATA: StellarPoolsInfo = { - Roam: { - title: 'Roam - Supply Chain Financing', - poolName: POOL_NAME.Roam, + ArfCreditPoolV2: { + title: 'Arf', + poolName: POOL_NAME.ArfCreditPoolV2, poolType: POOL_TYPE.CreditLine, chainId: StellarChainEnum.StellarTestnet, - industry: 'Supply Chain Financing', + industry: 'Remittance Financing', desc: '', - poolStorage: 'CBA35JCIXFRAEPRVD3JAQ5WLC7SYZP3RABUKJ52LU5EI2YQ6CDNIAQZF', - pool: 'CBAJF4BORH2YLIZH4QQSBGDD62VVUKVTNESXRV7KVXTSQ2X4WWP2M3NC', - poolManager: 'CDLLMPQMNIT7HE2Q6PGVSWYKAE7FLUHVM4QYV7D4ISLT3GD4XZDVSBXV', - poolCredit: 'CDPYWOCBSXC3W6BYRKO645OQLJNDDZ2EDSZ2Y547BL4LHMSRU7FUVTVG', - creditManager: 'CBEH5SKVKC6GXP5FQLAUFX43GAFRXZDOHDUQW3CRFD5BQVH7L6YSBP4V', - creditStorage: 'CADDOLDFYN6Y2DXNYMX2ILVLPLU5W7MAQ7GBOOYWJ6JCH4DGHLUH2FB3', - juniorTranche: 'CB6K4IUC3CJHIWVHHLBDTGXVS6CT64EKGD5CGBIDNMSAKVZHCWQ3LM2D', + poolStorage: 'CCIMD2GVMKRK5UNOD7JJSM74HFLOFJ6ODAXY2OQBA46JQ4QYAZ4P34EF', + pool: 'CCXBTYYRX3TALCODB7SWOJRPREXJYPCRZMVKSTXSTVQYB2AV5BF6HL44', + poolManager: 'CB334NWVJ4SDD3ON6H2WRE2K57NCETY3NJVUSBVWSVTT6ATB4ADMWJED', + poolCredit: 'CDCNJDPWCGLSOD3W2W3G34XILCIF7WPBG2SCXHTVSTJL4QGD4HFWBZFM', + creditManager: 'CDY6NTTINATBCG7TOVXB23XFRDES4QBR4CF2375YZEYKVNJZJR423ITR', + creditStorage: 'CBXWR7FOC4IQHGGTSF7OHNQAGBACVTY7U6SR6LPDXWE3F4S74MOF3JDR', + juniorTranche: 'CBN6KKNSWJLYVQS3YPX4FK7DJZGTSRTCQN52FX2CZ342EC7LWHWJFBHH', + seniorTranche: 'CADMAL7SRLFVF2JI7RJZY6UTIZBPZUT7NBTMWXSCH255JK3LLWQHU5Y3', trancheDecimals: 6, underlyingToken: { address: 'CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA', @@ -25,7 +26,7 @@ export const STELLAR_TESTNET_METADATA: StellarPoolsInfo = { icon: 'USDC', }, extra: { - borrower: 'GCHMCS6HZBPFENKVRJHV3CTSSOJECHOLLODDNVLGEBXPHIBRT54JGMW6', + borrower: 'GCI3WLD2P3OHSMMDZU6X2FMSRHFXOI6JCH5HQK5GBRN5Z2NVMOJMBIDV', }, }, } diff --git a/packages/huma-shared/src/stellar/types/metadata.ts b/packages/huma-shared/src/stellar/types/metadata.ts index b3ee1c5a..26a7a4a2 100644 --- a/packages/huma-shared/src/stellar/types/metadata.ts +++ b/packages/huma-shared/src/stellar/types/metadata.ts @@ -58,7 +58,7 @@ export type StellarChainsInfo = { export const STELLAR_CHAINS_INFO: StellarChainsInfo = { [StellarChainEnum.StellarTestnet]: { rpc: 'https://soroban-testnet.stellar.org', - humaConfig: 'CDX6NBJ3OV4TWRCZK4DFBHDHE37UUDS66PPGNIPBGUI56D254EKVFETX', + humaConfig: 'CAAVSHWNTUFIZCKCCXRDRFRRUDEBTKNRWBPHHOA4ZIYD3ELAOY4LOHUY', networkPassphrase: 'Test SDF Network ; September 2015', }, [StellarChainEnum.StellarMainnet]: { diff --git a/packages/huma-web-shared/package.json b/packages/huma-web-shared/package.json index 526a031e..97c96806 100644 --- a/packages/huma-web-shared/package.json +++ b/packages/huma-web-shared/package.json @@ -83,11 +83,11 @@ }, "peerDependencies": { "@coral-xyz/anchor": "^0.30.1", - "@huma-finance/soroban-credit-storage": "0.0.15-beta.50", - "@huma-finance/soroban-huma-config": "0.0.15-beta.50", - "@huma-finance/soroban-pool-storage": "0.0.15-beta.50", - "@huma-finance/soroban-sdk": "^0.0.15-beta.50", - "@huma-finance/soroban-tranche-vault": "0.0.15-beta.50", + "@huma-finance/soroban-credit-storage": "0.0.17", + "@huma-finance/soroban-huma-config": "0.0.17", + "@huma-finance/soroban-pool-storage": "0.0.17", + "@huma-finance/soroban-sdk": "^0.0.17", + "@huma-finance/soroban-tranche-vault": "0.0.17", "@solana/spl-token": "^0.4.8", "@solana/wallet-adapter-base": "^0.9.23", "@solana/wallet-adapter-react": "^0.15.35", diff --git a/packages/huma-web-shared/src/stellar/utils/fetchStellarDepositRecord.ts b/packages/huma-web-shared/src/stellar/utils/fetchStellarDepositRecord.ts index b0081bbd..0e5a372f 100644 --- a/packages/huma-web-shared/src/stellar/utils/fetchStellarDepositRecord.ts +++ b/packages/huma-web-shared/src/stellar/utils/fetchStellarDepositRecord.ts @@ -28,7 +28,7 @@ export async function fetchStellarDepositRecord( poolInfo: StellarPoolInfo, tranche: TrancheType, account: string, -): Promise { +): Promise { try { const chainMetadata = STELLAR_CHAINS_INFO[poolInfo.chainId] const server = new SorobanRpc.Server(chainMetadata.rpc) @@ -49,7 +49,7 @@ export async function fetchStellarDepositRecord( data.last_deposit_time === undefined || data.principal === undefined ) { - throw new Error('Failed to fetch deposit record') + return null } return { @@ -58,9 +58,9 @@ export async function fetchStellarDepositRecord( } } - throw new Error('Failed to fetch deposit record') + return null } catch (error) { console.error('Error fetching deposit record:', error) - throw error + return null } } diff --git a/packages/huma-widget/package.json b/packages/huma-widget/package.json index b9265cbe..ce0d26d5 100644 --- a/packages/huma-widget/package.json +++ b/packages/huma-widget/package.json @@ -181,7 +181,7 @@ "@coral-xyz/anchor": "^0.30.1", "@emotion/react": "^11.5.0", "@emotion/styled": "^11.3.0", - "@huma-finance/soroban-tranche-vault": "0.0.15-beta.50", + "@huma-finance/soroban-tranche-vault": "0.0.17", "@mui/icons-material": "^5.3.0", "@mui/material": "^5.0.6", "@mui/styles": "^5.0.2", From da635aab2da086444a65b34cbc3d143736cefe08 Mon Sep 17 00:00:00 2001 From: Michael Liu Date: Mon, 23 Dec 2024 21:49:48 -0500 Subject: [PATCH 03/16] Update sdk ver --- packages/examples/package.json | 12 ++++++------ packages/huma-web-shared/package.json | 12 ++++++------ .../src/stellar/utils/fetchStellarDepositRecord.ts | 4 ++-- .../src/stellar/utils/fetchStellarTokenBalance.ts | 4 ++-- packages/huma-widget/package.json | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/examples/package.json b/packages/examples/package.json index e5af121d..9c6fc084 100644 --- a/packages/examples/package.json +++ b/packages/examples/package.json @@ -43,12 +43,12 @@ "@solana/wallet-adapter-react-ui": "^0.9.35", "@solana/wallet-adapter-wallets": "^0.19.32", "@stellar/freighter-api": "^3.0.0", - "@huma-finance/soroban-credit-storage": "0.0.17", - "@huma-finance/soroban-huma-config": "0.0.17", - "@huma-finance/soroban-pool-storage": "0.0.17", - "@huma-finance/soroban-sdk": "^0.0.17", - "@huma-finance/soroban-tranche-vault": "0.0.17", - "@stellar/stellar-sdk": "^12.3.0", + "@huma-finance/soroban-credit-storage": "0.0.18", + "@huma-finance/soroban-huma-config": "0.0.18", + "@huma-finance/soroban-pool-storage": "0.0.18", + "@huma-finance/soroban-sdk": "^0.0.18", + "@huma-finance/soroban-tranche-vault": "0.0.18", + "@stellar/stellar-sdk": "13.0.0", "@coral-xyz/borsh": "^0.30.1", "@mui/icons-material": "^5.3.0", "@mui/material": "^5.0.6", diff --git a/packages/huma-web-shared/package.json b/packages/huma-web-shared/package.json index 97c96806..9d40c6d4 100644 --- a/packages/huma-web-shared/package.json +++ b/packages/huma-web-shared/package.json @@ -83,11 +83,11 @@ }, "peerDependencies": { "@coral-xyz/anchor": "^0.30.1", - "@huma-finance/soroban-credit-storage": "0.0.17", - "@huma-finance/soroban-huma-config": "0.0.17", - "@huma-finance/soroban-pool-storage": "0.0.17", - "@huma-finance/soroban-sdk": "^0.0.17", - "@huma-finance/soroban-tranche-vault": "0.0.17", + "@huma-finance/soroban-credit-storage": "0.0.18", + "@huma-finance/soroban-huma-config": "0.0.18", + "@huma-finance/soroban-pool-storage": "0.0.18", + "@huma-finance/soroban-sdk": "0.0.18", + "@huma-finance/soroban-tranche-vault": "0.0.18", "@solana/spl-token": "^0.4.8", "@solana/wallet-adapter-base": "^0.9.23", "@solana/wallet-adapter-react": "^0.15.35", @@ -95,7 +95,7 @@ "@solana/wallet-adapter-wallets": "^0.19.32", "@solana/web3.js": "^1.95.3", "@stellar/freighter-api": "^3.0.0", - "@stellar/stellar-sdk": "^12.3.0", + "@stellar/stellar-sdk": "13.0.0", "ethers": "^5.6.1", "lodash": "^4.17.21" }, diff --git a/packages/huma-web-shared/src/stellar/utils/fetchStellarDepositRecord.ts b/packages/huma-web-shared/src/stellar/utils/fetchStellarDepositRecord.ts index 0e5a372f..aa51ad82 100644 --- a/packages/huma-web-shared/src/stellar/utils/fetchStellarDepositRecord.ts +++ b/packages/huma-web-shared/src/stellar/utils/fetchStellarDepositRecord.ts @@ -3,7 +3,7 @@ import { StellarPoolInfo, TrancheType, } from '@huma-finance/shared' -import { SorobanRpc, Address, xdr, scValToNative } from '@stellar/stellar-sdk' +import { rpc, Address, xdr, scValToNative } from '@stellar/stellar-sdk' const getDepositRecordKey = (contractId: string, address: string) => { const addressScVal = new Address(address).toScVal() @@ -31,7 +31,7 @@ export async function fetchStellarDepositRecord( ): Promise { try { const chainMetadata = STELLAR_CHAINS_INFO[poolInfo.chainId] - const server = new SorobanRpc.Server(chainMetadata.rpc) + const server = new rpc.Server(chainMetadata.rpc) const key = getDepositRecordKey( tranche === 'senior' ? poolInfo.seniorTranche! : poolInfo.juniorTranche, diff --git a/packages/huma-web-shared/src/stellar/utils/fetchStellarTokenBalance.ts b/packages/huma-web-shared/src/stellar/utils/fetchStellarTokenBalance.ts index 30962a1d..54162a8d 100644 --- a/packages/huma-web-shared/src/stellar/utils/fetchStellarTokenBalance.ts +++ b/packages/huma-web-shared/src/stellar/utils/fetchStellarTokenBalance.ts @@ -1,6 +1,6 @@ import { StellarChainInfo } from '@huma-finance/shared' import { - SorobanRpc, + rpc, Contract, Address, scValToNative, @@ -16,7 +16,7 @@ export async function fetchStellarTokenBalance( sourceAddress?: string, ) { try { - const server = new SorobanRpc.Server(chainMetadata.rpc) + const server = new rpc.Server(chainMetadata.rpc) // Create a Contract instance const contract = new Contract(tokenAddress) diff --git a/packages/huma-widget/package.json b/packages/huma-widget/package.json index ce0d26d5..abf798ba 100644 --- a/packages/huma-widget/package.json +++ b/packages/huma-widget/package.json @@ -181,7 +181,7 @@ "@coral-xyz/anchor": "^0.30.1", "@emotion/react": "^11.5.0", "@emotion/styled": "^11.3.0", - "@huma-finance/soroban-tranche-vault": "0.0.17", + "@huma-finance/soroban-tranche-vault": "0.0.18", "@mui/icons-material": "^5.3.0", "@mui/material": "^5.0.6", "@mui/styles": "^5.0.2", From 8bd49c510c2bcb126fe6cbb59409bc66cc827e63 Mon Sep 17 00:00:00 2001 From: Michael Liu Date: Mon, 30 Dec 2024 12:42:41 -0500 Subject: [PATCH 04/16] Yield withdraw --- packages/examples/package.json | 1 + packages/examples/src/solana/withdrawYield.ts | 46 ++ .../helpers/solana/HumaSolanaProgramHelper.ts | 97 ++- packages/huma-shared/src/solana/idl/huma.json | 469 +++++++++++++- packages/huma-shared/src/solana/idl/huma.ts | 573 +++++++++++++++++- 5 files changed, 1175 insertions(+), 11 deletions(-) create mode 100644 packages/examples/src/solana/withdrawYield.ts diff --git a/packages/examples/package.json b/packages/examples/package.json index 9c6fc084..97a17e40 100644 --- a/packages/examples/package.json +++ b/packages/examples/package.json @@ -27,6 +27,7 @@ "solanaFetchAvailableCredit": "ts-node src/solana/fetchAvailableCredit.ts", "solanaFetchBorrowerDetails": "ts-node src/solana/fetchBorrowerDetails.ts", "solanaDrawdown": "ts-node src/solana/drawdown.ts", + "solanaWithdrawYield": "ts-node src/solana/withdrawYield.ts", "solanaPayback": "ts-node src/solana/payback.ts", "lint-staged": "lint-staged" }, diff --git a/packages/examples/src/solana/withdrawYield.ts b/packages/examples/src/solana/withdrawYield.ts new file mode 100644 index 00000000..24a6b0ed --- /dev/null +++ b/packages/examples/src/solana/withdrawYield.ts @@ -0,0 +1,46 @@ +import { Connection, Keypair, sendAndConfirmTransaction } from '@solana/web3.js' +import { + AnchorProvider, + BN, + setProvider, + Wallet, + web3, +} from '@coral-xyz/anchor' +import { POOL_NAME, SolanaChainEnum } from '@huma-finance/shared' +import { HumaSolanaContext, HumaSolanaProgramHelper } from '@huma-finance/sdk' + +require('dotenv').config() + +async function main() { + const TEST_PRIVATE_KEY = process.env.TEST_PRIVATE_KEY + const connection = new Connection( + 'https://api.devnet.solana.com', + 'confirmed', + ) + + const keypair = web3.Keypair.fromSecretKey( + Buffer.from(JSON.parse(TEST_PRIVATE_KEY)), + ) + const wallet = new Wallet(keypair) + setProvider(new AnchorProvider(connection, wallet)) + + const solanaHumaContext = new HumaSolanaContext({ + publicKey: wallet.publicKey, + connection: connection, + chainId: SolanaChainEnum.SolanaDevnet, + poolName: POOL_NAME.ArfCreditPool3Months, + }) + + const humaSolanaProgramHelper = new HumaSolanaProgramHelper({ + solanaContext: solanaHumaContext, + }) + + const tx = await humaSolanaProgramHelper.buildWithdrawYieldsTransaction() + + console.log(tx) + + const txResult = await sendAndConfirmTransaction(connection, tx, [keypair]) + console.log(txResult) +} + +main() diff --git a/packages/huma-sdk/src/helpers/solana/HumaSolanaProgramHelper.ts b/packages/huma-sdk/src/helpers/solana/HumaSolanaProgramHelper.ts index 9f3f3662..7151c141 100644 --- a/packages/huma-sdk/src/helpers/solana/HumaSolanaProgramHelper.ts +++ b/packages/huma-sdk/src/helpers/solana/HumaSolanaProgramHelper.ts @@ -1,4 +1,4 @@ -import { BN } from '@coral-xyz/anchor' +import { BN, utils } from '@coral-xyz/anchor' import { getCreditAccounts, getHumaProgram, @@ -11,6 +11,7 @@ import { createApproveCheckedInstruction, createAssociatedTokenAccountInstruction, getAccount, + TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, TokenAccountNotFoundError, } from '@solana/spl-token' @@ -127,6 +128,100 @@ export class HumaSolanaProgramHelper { return tx } + async buildWithdrawYieldsTransaction(): Promise { + const { publicKey, connection, chainId, poolName } = this.#solanaContext + const program = getHumaProgram(chainId, connection) + const poolInfo = getSolanaPoolInfo(chainId, poolName) + + if (!poolInfo) { + throw new Error('Could not find pool') + } + + const tx: Transaction = new Transaction() + + const { underlyingTokenATA, seniorTrancheATA, juniorTrancheATA } = + getTokenAccounts(poolInfo, publicKey) + const [juniorYieldDistributingLenderAccount] = + PublicKey.findProgramAddressSync( + [ + utils.bytes.utf8.encode('yield_distributing_lender'), + new PublicKey(poolInfo.juniorTrancheMint).toBuffer(), + publicKey.toBuffer(), + ], + program.programId, + ) + const programTx = await program.methods + .withdrawYields() + .accountsPartial({ + lender: publicKey, + humaConfig: poolInfo.humaConfig, + poolConfig: poolInfo.poolConfig, + yieldDistributingLender: juniorYieldDistributingLenderAccount, + underlyingMint: poolInfo.underlyingMint.address, + poolUnderlyingToken: poolInfo.poolUnderlyingTokenAccount, + lenderUnderlyingToken: underlyingTokenATA, + trancheMint: poolInfo.juniorTrancheMint, + lenderTrancheToken: juniorTrancheATA, + underlyingTokenProgram: TOKEN_PROGRAM_ID, + trancheTokenProgram: TOKEN_2022_PROGRAM_ID, + }) + .transaction() + const txAccounts: PublicKey[] = [ + publicKey, + new PublicKey(poolInfo.humaConfig), + new PublicKey(poolInfo.poolConfig), + juniorYieldDistributingLenderAccount, + new PublicKey(poolInfo.underlyingMint.address), + new PublicKey(poolInfo.poolUnderlyingTokenAccount), + underlyingTokenATA, + new PublicKey(poolInfo.juniorTrancheMint), + juniorTrancheATA, + TOKEN_PROGRAM_ID, + TOKEN_2022_PROGRAM_ID, + ] + tx.add(programTx) + + if (poolInfo.seniorTrancheMint) { + const [seniorYieldDistributingLenderAccount] = + PublicKey.findProgramAddressSync( + [ + utils.bytes.utf8.encode('yield_distributing_lender'), + new PublicKey(poolInfo.seniorTrancheMint).toBuffer(), + publicKey.toBuffer(), + ], + program.programId, + ) + const programTx = await program.methods + .withdrawYields() + .accountsPartial({ + lender: publicKey, + humaConfig: poolInfo.humaConfig, + poolConfig: poolInfo.poolConfig, + yieldDistributingLender: seniorYieldDistributingLenderAccount, + underlyingMint: poolInfo.underlyingMint.address, + poolUnderlyingToken: poolInfo.poolUnderlyingTokenAccount, + lenderUnderlyingToken: underlyingTokenATA, + trancheMint: poolInfo.seniorTrancheMint, + lenderTrancheToken: seniorTrancheATA, + underlyingTokenProgram: TOKEN_PROGRAM_ID, + trancheTokenProgram: TOKEN_2022_PROGRAM_ID, + }) + .transaction() + txAccounts.push( + ...[ + seniorYieldDistributingLenderAccount, + new PublicKey(poolInfo.seniorTrancheMint), + seniorTrancheATA, + ], + ) + tx.add(programTx) + } + + await buildOptimalTransaction(tx, txAccounts, this.#solanaContext) + + return tx + } + async buildDrawdownTransaction(amount: BN): Promise { const { publicKey, connection, chainId, poolName } = this.#solanaContext const program = getHumaProgram(chainId, connection) diff --git a/packages/huma-shared/src/solana/idl/huma.json b/packages/huma-shared/src/solana/idl/huma.json index 1a9d27c2..bde458ae 100644 --- a/packages/huma-shared/src/solana/idl/huma.json +++ b/packages/huma-shared/src/solana/idl/huma.json @@ -2,7 +2,7 @@ "address": "EVQ4s1b6N1vmWFDv8PRNc77kufBP8HcrSNWXQAhRsJq9", "metadata": { "name": "huma", - "version": "0.1.0", + "version": "2.2.0", "spec": "0.1.0", "description": "Created with Anchor" }, @@ -483,6 +483,101 @@ } ] }, + { + "name": "add_yield_distributing_lender", + "docs": [ + "Adds an approved lender as a yield distributing lender.", + "", + "", + "# Arguments", + "* `lender` - The lender address.", + "", + "# Access Control", + "Only pool operators can call this instruction." + ], + "discriminator": [33, 123, 56, 23, 130, 142, 148, 129], + "accounts": [ + { + "name": "pool_operator", + "writable": true, + "signer": true + }, + { + "name": "pool_config", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [112, 111, 111, 108, 95, 99, 111, 110, 102, 105, 103] + }, + { + "kind": "account", + "path": "pool_config.pool_id", + "account": "PoolConfig" + } + ] + } + }, + { + "name": "pool_state", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [112, 111, 111, 108, 95, 115, 116, 97, 116, 101] + }, + { + "kind": "account", + "path": "pool_config" + } + ] + } + }, + { + "name": "tranche_mint" + }, + { + "name": "approved_lender" + }, + { + "name": "pool_operator_config" + }, + { + "name": "yield_distributing_lender_config", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 121, 105, 101, 108, 100, 95, 100, 105, 115, 116, 114, 105, 98, + 117, 116, 105, 110, 103, 95, 108, 101, 110, 100, 101, 114 + ] + }, + { + "kind": "account", + "path": "tranche_mint" + }, + { + "kind": "arg", + "path": "lender" + } + ] + } + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [ + { + "name": "lender", + "type": "pubkey" + } + ] + }, { "name": "approve_credit", "docs": [ @@ -4100,7 +4195,7 @@ "The capital that the lender has contributed will continue to work as normal.", "", "# Dev Notes", - "It is intentional not to delete depositRecord for the lender so that they do not", + "It is intentional not to delete `DepositRecord` for the lender so that they do not", "lose existing investment. They can request redemption post removal as a lender.", "Because of lockup period and pool liquidity constraints, we cannot automatically", "disburse the investment by this lender.", @@ -4177,6 +4272,30 @@ } ] } + }, + { + "name": "yield_distributing_lender_config", + "writable": true, + "optional": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 121, 105, 101, 108, 100, 95, 100, 105, 115, 116, 114, 105, 98, + 117, 116, 105, 110, 103, 95, 108, 101, 110, 100, 101, 114 + ] + }, + { + "kind": "account", + "path": "tranche_mint" + }, + { + "kind": "arg", + "path": "lender" + } + ] + } } ], "args": [ @@ -4375,6 +4494,92 @@ } ] }, + { + "name": "remove_yield_distributing_lender", + "docs": [ + "Marks a lender as ineligible for yield distribution.", + "", + "# Arguments", + "* `lender` - The lender address.", + "", + "# Access Control", + "Only pool operators can call this instruction." + ], + "discriminator": [140, 153, 125, 9, 100, 99, 177, 200], + "accounts": [ + { + "name": "pool_operator", + "writable": true, + "signer": true + }, + { + "name": "pool_config", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [112, 111, 111, 108, 95, 99, 111, 110, 102, 105, 103] + }, + { + "kind": "account", + "path": "pool_config.pool_id", + "account": "PoolConfig" + } + ] + } + }, + { + "name": "pool_state", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [112, 111, 111, 108, 95, 115, 116, 97, 116, 101] + }, + { + "kind": "account", + "path": "pool_config" + } + ] + } + }, + { + "name": "tranche_mint" + }, + { + "name": "pool_operator_config" + }, + { + "name": "yield_distributing_lender_config", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 121, 105, 101, 108, 100, 95, 100, 105, 115, 116, 114, 105, 98, + 117, 116, 105, 110, 103, 95, 108, 101, 110, 100, 101, 114 + ] + }, + { + "kind": "account", + "path": "tranche_mint" + }, + { + "kind": "arg", + "path": "lender" + } + ] + } + } + ], + "args": [ + { + "name": "lender", + "type": "pubkey" + } + ] + }, { "name": "set_admin_rnr", "docs": [ @@ -6488,6 +6693,142 @@ "type": "u128" } ] + }, + { + "name": "withdraw_yields", + "docs": [ + "Withdraws the yield accrued by the lender.", + "", + "# Access Control", + "Only yield distributing lenders can call this instruction." + ], + "discriminator": [248, 111, 218, 8, 55, 252, 196, 181], + "accounts": [ + { + "name": "lender", + "signer": true + }, + { + "name": "huma_config", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [104, 117, 109, 97, 95, 99, 111, 110, 102, 105, 103] + }, + { + "kind": "account", + "path": "huma_config.id", + "account": "HumaConfig" + } + ] + }, + "relations": ["pool_config"] + }, + { + "name": "pool_config", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [112, 111, 111, 108, 95, 99, 111, 110, 102, 105, 103] + }, + { + "kind": "account", + "path": "pool_config.pool_id", + "account": "PoolConfig" + } + ] + } + }, + { + "name": "pool_state", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [112, 111, 111, 108, 95, 115, 116, 97, 116, 101] + }, + { + "kind": "account", + "path": "pool_config" + } + ] + } + }, + { + "name": "yield_distributing_lender" + }, + { + "name": "lender_state", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 108, 101, 110, 100, 101, 114, 95, 115, 116, 97, 116, 101 + ] + }, + { + "kind": "account", + "path": "tranche_mint" + }, + { + "kind": "account", + "path": "lender" + } + ] + } + }, + { + "name": "pool_authority", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, 111, 111, 108, 95, 97, 117, 116, 104, 111, 114, 105, 116, + 121 + ] + }, + { + "kind": "account", + "path": "pool_config" + } + ] + } + }, + { + "name": "underlying_mint", + "relations": ["pool_config"] + }, + { + "name": "pool_underlying_token", + "writable": true + }, + { + "name": "lender_underlying_token", + "writable": true + }, + { + "name": "tranche_mint", + "writable": true + }, + { + "name": "lender_tranche_token", + "writable": true + }, + { + "name": "underlying_token_program" + }, + { + "name": "tranche_token_program", + "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" + } + ], + "args": [] } ], "accounts": [ @@ -6542,6 +6883,10 @@ { "name": "TrancheState", "discriminator": [212, 231, 254, 24, 238, 63, 92, 105] + }, + { + "name": "YieldDistributingLender", + "discriminator": [179, 145, 84, 62, 168, 249, 253, 29] } ], "events": [ @@ -6805,6 +7150,14 @@ "name": "RemainingPeriodsExtendedEvent", "discriminator": [19, 250, 33, 106, 8, 220, 78, 241] }, + { + "name": "YieldDistributingLenderAddedEvent", + "discriminator": [198, 65, 87, 191, 19, 49, 27, 80] + }, + { + "name": "YieldDistributingLenderRemovedEvent", + "discriminator": [97, 210, 181, 37, 25, 43, 227, 77] + }, { "name": "YieldTrackerRefreshedEvent", "discriminator": [48, 100, 71, 36, 117, 201, 145, 140] @@ -6812,6 +7165,10 @@ { "name": "YieldUpdatedEvent", "discriminator": [177, 90, 108, 19, 131, 243, 44, 244] + }, + { + "name": "YieldsWithdrawnEvent", + "discriminator": [151, 129, 132, 11, 52, 147, 28, 227] } ], "errors": [ @@ -6903,6 +7260,10 @@ "code": 6215, "name": "LenderOrSentinelRequired" }, + { + "code": 6216, + "name": "YieldDistributingLenderRequired" + }, { "code": 6301, "name": "ProtocolFeeHigherThanUpperLimit" @@ -7003,6 +7364,10 @@ "code": 6419, "name": "InvalidPoolConfig" }, + { + "code": 6420, + "name": "InsufficientBalanceForYieldWithdrawal" + }, { "code": 6501, "name": "PreviousAssetsNotWithdrawn" @@ -10611,6 +10976,68 @@ ] } }, + { + "name": "YieldDistributingLender", + "docs": [ + "Designation of whether a lender is eligible for yield distribution. A lender with this", + "designation has the option to withdraw their yield generated from the pool." + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "type": "u8" + } + ] + } + }, + { + "name": "YieldDistributingLenderAddedEvent", + "docs": [ + "A lender has been designated as eligible for yield distribution.", + "", + "# Fields", + "* `tranche` - The tranche mint key.", + "* `lender` - The address of the lender with the designation." + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "tranche", + "type": "pubkey" + }, + { + "name": "lender", + "type": "pubkey" + } + ] + } + }, + { + "name": "YieldDistributingLenderRemovedEvent", + "docs": [ + "A lender has been designated as no longer eligible for yield distribution.", + "", + "# Fields", + "* `tranche` - The tranche mint key.", + "* `lender` - The address of the lender whose designation is being removed." + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "tranche", + "type": "pubkey" + }, + { + "name": "lender", + "type": "pubkey" + } + ] + } + }, { "name": "YieldTrackerRefreshedEvent", "docs": [ @@ -10671,6 +11098,39 @@ } ] } + }, + { + "name": "YieldsWithdrawnEvent", + "docs": [ + "A lender has withdrawn their yield.", + "", + "# Fields", + "* `tranche` - The tranche mint key.", + "* `lender` - The lender withdrawing yield.", + "* `yields` - The amount of yield being withdrawn.", + "* `shares_burned` - The number of shares burned." + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "tranche", + "type": "pubkey" + }, + { + "name": "lender", + "type": "pubkey" + }, + { + "name": "yields", + "type": "u128" + }, + { + "name": "shares_burned", + "type": "u128" + } + ] + } } ], "constants": [ @@ -10838,6 +11298,11 @@ "name": "TRANCHE_STATE_SEED", "type": "bytes", "value": "[116, 114, 97, 110, 99, 104, 101, 95, 115, 116, 97, 116, 101]" + }, + { + "name": "YIELD_DISTRIBUTING_LENDER_SEED", + "type": "bytes", + "value": "[121, 105, 101, 108, 100, 95, 100, 105, 115, 116, 114, 105, 98, 117, 116, 105, 110, 103, 95, 108, 101, 110, 100, 101, 114]" } ] } diff --git a/packages/huma-shared/src/solana/idl/huma.ts b/packages/huma-shared/src/solana/idl/huma.ts index 1514c19c..bae49d3c 100644 --- a/packages/huma-shared/src/solana/idl/huma.ts +++ b/packages/huma-shared/src/solana/idl/huma.ts @@ -8,7 +8,7 @@ export type Huma = { address: 'EVQ4s1b6N1vmWFDv8PRNc77kufBP8HcrSNWXQAhRsJq9' metadata: { name: 'huma' - version: '0.1.0' + version: '2.2.0' spec: '0.1.0' description: 'Created with Anchor' } @@ -561,7 +561,7 @@ export type Huma = { }, { name: 'hookProgram' - address: 'JAhzUQ7nK7zeTdnbLDQR3y7UwSKnxeqdctCbjG8Z2abM' + address: 'BzaHku1HrxKYWTr89JwnWn232QYdnxz444VZ4nWeaziX' }, { name: 'tokenProgram' @@ -579,6 +579,124 @@ export type Huma = { }, ] }, + { + name: 'addYieldDistributingLender' + docs: [ + 'Adds an approved lender as a yield distributing lender.', + '', + '', + '# Arguments', + '* `lender` - The lender address.', + '', + '# Access Control', + 'Only pool operators can call this instruction.', + ] + discriminator: [33, 123, 56, 23, 130, 142, 148, 129] + accounts: [ + { + name: 'poolOperator' + writable: true + signer: true + }, + { + name: 'poolConfig' + pda: { + seeds: [ + { + kind: 'const' + value: [112, 111, 111, 108, 95, 99, 111, 110, 102, 105, 103] + }, + { + kind: 'account' + path: 'pool_config.pool_id' + account: 'poolConfig' + }, + ] + } + }, + { + name: 'poolState' + writable: true + pda: { + seeds: [ + { + kind: 'const' + value: [112, 111, 111, 108, 95, 115, 116, 97, 116, 101] + }, + { + kind: 'account' + path: 'poolConfig' + }, + ] + } + }, + { + name: 'trancheMint' + }, + { + name: 'approvedLender' + }, + { + name: 'poolOperatorConfig' + }, + { + name: 'yieldDistributingLenderConfig' + writable: true + pda: { + seeds: [ + { + kind: 'const' + value: [ + 121, + 105, + 101, + 108, + 100, + 95, + 100, + 105, + 115, + 116, + 114, + 105, + 98, + 117, + 116, + 105, + 110, + 103, + 95, + 108, + 101, + 110, + 100, + 101, + 114, + ] + }, + { + kind: 'account' + path: 'trancheMint' + }, + { + kind: 'arg' + path: 'lender' + }, + ] + } + }, + { + name: 'systemProgram' + address: '11111111111111111111111111111111' + }, + ] + args: [ + { + name: 'lender' + type: 'pubkey' + }, + ] + }, { name: 'approveCredit' docs: [ @@ -1189,7 +1307,7 @@ export type Huma = { }, { name: 'hookProgram' - address: 'JAhzUQ7nK7zeTdnbLDQR3y7UwSKnxeqdctCbjG8Z2abM' + address: 'BzaHku1HrxKYWTr89JwnWn232QYdnxz444VZ4nWeaziX' }, { name: 'tokenProgram' @@ -3782,7 +3900,7 @@ export type Huma = { }, { name: 'hookProgram' - address: 'JAhzUQ7nK7zeTdnbLDQR3y7UwSKnxeqdctCbjG8Z2abM' + address: 'BzaHku1HrxKYWTr89JwnWn232QYdnxz444VZ4nWeaziX' }, { name: 'poolAuthority' @@ -4873,7 +4991,7 @@ export type Huma = { 'The capital that the lender has contributed will continue to work as normal.', '', '# Dev Notes', - 'It is intentional not to delete depositRecord for the lender so that they do not', + 'It is intentional not to delete `DepositRecord` for the lender so that they do not', 'lose existing investment. They can request redemption post removal as a lender.', 'Because of lockup period and pool liquidity constraints, we cannot automatically', 'disburse the investment by this lender.', @@ -4964,6 +5082,53 @@ export type Huma = { ] } }, + { + name: 'yieldDistributingLenderConfig' + writable: true + optional: true + pda: { + seeds: [ + { + kind: 'const' + value: [ + 121, + 105, + 101, + 108, + 100, + 95, + 100, + 105, + 115, + 116, + 114, + 105, + 98, + 117, + 116, + 105, + 110, + 103, + 95, + 108, + 101, + 110, + 100, + 101, + 114, + ] + }, + { + kind: 'account' + path: 'trancheMint' + }, + { + kind: 'arg' + path: 'lender' + }, + ] + } + }, ] args: [ { @@ -5169,11 +5334,120 @@ export type Huma = { }, { kind: 'account' - path: 'poolConfig' + path: 'poolConfig' + }, + { + kind: 'arg' + path: 'operator' + }, + ] + } + }, + ] + args: [ + { + name: 'operator' + type: 'pubkey' + }, + ] + }, + { + name: 'removeYieldDistributingLender' + docs: [ + 'Marks a lender as ineligible for yield distribution.', + '', + '# Arguments', + '* `lender` - The lender address.', + '', + '# Access Control', + 'Only pool operators can call this instruction.', + ] + discriminator: [140, 153, 125, 9, 100, 99, 177, 200] + accounts: [ + { + name: 'poolOperator' + writable: true + signer: true + }, + { + name: 'poolConfig' + pda: { + seeds: [ + { + kind: 'const' + value: [112, 111, 111, 108, 95, 99, 111, 110, 102, 105, 103] + }, + { + kind: 'account' + path: 'pool_config.pool_id' + account: 'poolConfig' + }, + ] + } + }, + { + name: 'poolState' + pda: { + seeds: [ + { + kind: 'const' + value: [112, 111, 111, 108, 95, 115, 116, 97, 116, 101] + }, + { + kind: 'account' + path: 'poolConfig' + }, + ] + } + }, + { + name: 'trancheMint' + }, + { + name: 'poolOperatorConfig' + }, + { + name: 'yieldDistributingLenderConfig' + writable: true + pda: { + seeds: [ + { + kind: 'const' + value: [ + 121, + 105, + 101, + 108, + 100, + 95, + 100, + 105, + 115, + 116, + 114, + 105, + 98, + 117, + 116, + 105, + 110, + 103, + 95, + 108, + 101, + 110, + 100, + 101, + 114, + ] + }, + { + kind: 'account' + path: 'trancheMint' }, { kind: 'arg' - path: 'operator' + path: 'lender' }, ] } @@ -5181,7 +5455,7 @@ export type Huma = { ] args: [ { - name: 'operator' + name: 'lender' type: 'pubkey' }, ] @@ -7554,6 +7828,165 @@ export type Huma = { }, ] }, + { + name: 'withdrawYields' + docs: [ + 'Withdraws the yield accrued by the lender.', + '', + '# Access Control', + 'Only yield distributing lenders can call this instruction.', + ] + discriminator: [248, 111, 218, 8, 55, 252, 196, 181] + accounts: [ + { + name: 'lender' + signer: true + }, + { + name: 'humaConfig' + pda: { + seeds: [ + { + kind: 'const' + value: [104, 117, 109, 97, 95, 99, 111, 110, 102, 105, 103] + }, + { + kind: 'account' + path: 'huma_config.id' + account: 'humaConfig' + }, + ] + } + relations: ['poolConfig'] + }, + { + name: 'poolConfig' + pda: { + seeds: [ + { + kind: 'const' + value: [112, 111, 111, 108, 95, 99, 111, 110, 102, 105, 103] + }, + { + kind: 'account' + path: 'pool_config.pool_id' + account: 'poolConfig' + }, + ] + } + }, + { + name: 'poolState' + writable: true + pda: { + seeds: [ + { + kind: 'const' + value: [112, 111, 111, 108, 95, 115, 116, 97, 116, 101] + }, + { + kind: 'account' + path: 'poolConfig' + }, + ] + } + }, + { + name: 'yieldDistributingLender' + }, + { + name: 'lenderState' + writable: true + pda: { + seeds: [ + { + kind: 'const' + value: [ + 108, + 101, + 110, + 100, + 101, + 114, + 95, + 115, + 116, + 97, + 116, + 101, + ] + }, + { + kind: 'account' + path: 'trancheMint' + }, + { + kind: 'account' + path: 'lender' + }, + ] + } + }, + { + name: 'poolAuthority' + pda: { + seeds: [ + { + kind: 'const' + value: [ + 112, + 111, + 111, + 108, + 95, + 97, + 117, + 116, + 104, + 111, + 114, + 105, + 116, + 121, + ] + }, + { + kind: 'account' + path: 'poolConfig' + }, + ] + } + }, + { + name: 'underlyingMint' + relations: ['poolConfig'] + }, + { + name: 'poolUnderlyingToken' + writable: true + }, + { + name: 'lenderUnderlyingToken' + writable: true + }, + { + name: 'trancheMint' + writable: true + }, + { + name: 'lenderTrancheToken' + writable: true + }, + { + name: 'underlyingTokenProgram' + }, + { + name: 'trancheTokenProgram' + address: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb' + }, + ] + args: [] + }, ] accounts: [ { @@ -7608,6 +8041,10 @@ export type Huma = { name: 'trancheState' discriminator: [212, 231, 254, 24, 238, 63, 92, 105] }, + { + name: 'yieldDistributingLender' + discriminator: [179, 145, 84, 62, 168, 249, 253, 29] + }, ] events: [ { @@ -7870,6 +8307,14 @@ export type Huma = { name: 'remainingPeriodsExtendedEvent' discriminator: [19, 250, 33, 106, 8, 220, 78, 241] }, + { + name: 'yieldDistributingLenderAddedEvent' + discriminator: [198, 65, 87, 191, 19, 49, 27, 80] + }, + { + name: 'yieldDistributingLenderRemovedEvent' + discriminator: [97, 210, 181, 37, 25, 43, 227, 77] + }, { name: 'yieldTrackerRefreshedEvent' discriminator: [48, 100, 71, 36, 117, 201, 145, 140] @@ -7878,6 +8323,10 @@ export type Huma = { name: 'yieldUpdatedEvent' discriminator: [177, 90, 108, 19, 131, 243, 44, 244] }, + { + name: 'yieldsWithdrawnEvent' + discriminator: [151, 129, 132, 11, 52, 147, 28, 227] + }, ] errors: [ { @@ -7968,6 +8417,10 @@ export type Huma = { code: 6215 name: 'lenderOrSentinelRequired' }, + { + code: 6216 + name: 'yieldDistributingLenderRequired' + }, { code: 6301 name: 'protocolFeeHigherThanUpperLimit' @@ -8068,6 +8521,10 @@ export type Huma = { code: 6419 name: 'invalidPoolConfig' }, + { + code: 6420 + name: 'insufficientBalanceForYieldWithdrawal' + }, { code: 6501 name: 'previousAssetsNotWithdrawn' @@ -11676,6 +12133,68 @@ export type Huma = { ] } }, + { + name: 'yieldDistributingLender' + docs: [ + 'Designation of whether a lender is eligible for yield distribution. A lender with this', + 'designation has the option to withdraw their yield generated from the pool.', + ] + type: { + kind: 'struct' + fields: [ + { + name: 'bump' + type: 'u8' + }, + ] + } + }, + { + name: 'yieldDistributingLenderAddedEvent' + docs: [ + 'A lender has been designated as eligible for yield distribution.', + '', + '# Fields', + '* `tranche` - The tranche mint key.', + '* `lender` - The address of the lender with the designation.', + ] + type: { + kind: 'struct' + fields: [ + { + name: 'tranche' + type: 'pubkey' + }, + { + name: 'lender' + type: 'pubkey' + }, + ] + } + }, + { + name: 'yieldDistributingLenderRemovedEvent' + docs: [ + 'A lender has been designated as no longer eligible for yield distribution.', + '', + '# Fields', + '* `tranche` - The tranche mint key.', + '* `lender` - The address of the lender whose designation is being removed.', + ] + type: { + kind: 'struct' + fields: [ + { + name: 'tranche' + type: 'pubkey' + }, + { + name: 'lender' + type: 'pubkey' + }, + ] + } + }, { name: 'yieldTrackerRefreshedEvent' docs: [ @@ -11737,6 +12256,39 @@ export type Huma = { ] } }, + { + name: 'yieldsWithdrawnEvent' + docs: [ + 'A lender has withdrawn their yield.', + '', + '# Fields', + '* `tranche` - The tranche mint key.', + '* `lender` - The lender withdrawing yield.', + '* `yields` - The amount of yield being withdrawn.', + '* `shares_burned` - The number of shares burned.', + ] + type: { + kind: 'struct' + fields: [ + { + name: 'tranche' + type: 'pubkey' + }, + { + name: 'lender' + type: 'pubkey' + }, + { + name: 'yields' + type: 'u128' + }, + { + name: 'sharesBurned' + type: 'u128' + }, + ] + } + }, ] constants: [ { @@ -11904,5 +12456,10 @@ export type Huma = { type: 'bytes' value: '[116, 114, 97, 110, 99, 104, 101, 95, 115, 116, 97, 116, 101]' }, + { + name: 'yieldDistributingLenderSeed' + type: 'bytes' + value: '[121, 105, 101, 108, 100, 95, 100, 105, 115, 116, 114, 105, 98, 117, 116, 105, 110, 103, 95, 108, 101, 110, 100, 101, 114]' + }, ] } From af5df1618a6094624bc34cdee8d4cc600d497571 Mon Sep 17 00:00:00 2001 From: humaci Date: Tue, 31 Dec 2024 01:05:13 +0000 Subject: [PATCH 05/16] v0.0.63 --- lerna.json | 2 +- packages/huma-sdk/package.json | 4 ++-- packages/huma-shared/package.json | 2 +- packages/huma-web-shared/package.json | 2 +- packages/huma-widget/package.json | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lerna.json b/lerna.json index b800daf9..38de5172 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", "useWorkspaces": true, - "version": "0.0.62" + "version": "0.0.63" } diff --git a/packages/huma-sdk/package.json b/packages/huma-sdk/package.json index 4e9d9264..4a36c118 100644 --- a/packages/huma-sdk/package.json +++ b/packages/huma-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@huma-finance/sdk", - "version": "0.0.62", + "version": "0.0.63", "types": "./dist/index.d.ts", "main": "./dist/cjs/index.js", "module": "./dist/index.js", @@ -29,7 +29,7 @@ "@ethersproject/constants": "^5.7.0", "@ethersproject/contracts": "^5.7.0", "@ethersproject/providers": "^5.6.0", - "@huma-finance/shared": "^0.0.62", + "@huma-finance/shared": "^0.0.63", "@irys/sdk": "^0.2.11", "axios": "^1.4.0", "bignumber.js": "^9.1.1", diff --git a/packages/huma-shared/package.json b/packages/huma-shared/package.json index 652cceb3..828e7a1d 100644 --- a/packages/huma-shared/package.json +++ b/packages/huma-shared/package.json @@ -1,6 +1,6 @@ { "name": "@huma-finance/shared", - "version": "0.0.62", + "version": "0.0.63", "types": "./dist/index.d.ts", "main": "./dist/cjs/index.js", "module": "./dist/index.js", diff --git a/packages/huma-web-shared/package.json b/packages/huma-web-shared/package.json index 9d40c6d4..1e5a530e 100644 --- a/packages/huma-web-shared/package.json +++ b/packages/huma-web-shared/package.json @@ -1,6 +1,6 @@ { "name": "@huma-finance/web-shared", - "version": "0.0.62", + "version": "0.0.63", "types": "./dist/index.d.ts", "main": "./dist/cjs/index.js", "module": "./dist/index.js", diff --git a/packages/huma-widget/package.json b/packages/huma-widget/package.json index abf798ba..9dfdcc49 100644 --- a/packages/huma-widget/package.json +++ b/packages/huma-widget/package.json @@ -1,6 +1,6 @@ { "name": "@huma-finance/widgets", - "version": "0.0.62", + "version": "0.0.63", "publishConfig": { "access": "public" }, @@ -29,9 +29,9 @@ "@ethersproject/experimental": "^5.7.0", "@ethersproject/providers": "^5.6.0", "@ethersproject/units": "^5.6.0", - "@huma-finance/sdk": "^0.0.62", - "@huma-finance/shared": "^0.0.62", - "@huma-finance/web-shared": "^0.0.62", + "@huma-finance/sdk": "^0.0.63", + "@huma-finance/shared": "^0.0.63", + "@huma-finance/web-shared": "^0.0.63", "@mui/x-date-pickers": "^5.0.7", "@notifi-network/notifi-frontend-client": "^1.1.2", "@notifi-network/notifi-react": "^1.1.2", From bbfb6b56cfa3271183d62492477989aa638e233e Mon Sep 17 00:00:00 2001 From: shan-57blocks Date: Tue, 31 Dec 2024 21:49:00 +0800 Subject: [PATCH 06/16] update scroll config --- .../huma-shared/src/v2/metadata/scroll.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/huma-shared/src/v2/metadata/scroll.ts b/packages/huma-shared/src/v2/metadata/scroll.ts index e8ec2858..106d9d05 100644 --- a/packages/huma-shared/src/v2/metadata/scroll.ts +++ b/packages/huma-shared/src/v2/metadata/scroll.ts @@ -10,14 +10,14 @@ export const SCROLL_METADATA: PoolsInfoV2 = { industry: 'Remittance Financing', poolName: POOL_NAME.ArfCreditPool3Months, poolType: POOL_TYPE.ReceivableBackedCreditLine, - pool: '0x5227254a6aCa397e95F310b52f6D3143A5A9Ee14', - poolConfig: '0xEBA0756b813e49bA84Cb3B8E2d717bcF0C07fC99', - poolCredit: '0xc6F10af4746784a0DD095f4E5718d53ff94eB4a0', - poolCreditManager: '0x061411d05074Bc974f814AC86309D2204f4c265d', - poolSafe: '0x7F4f55fAeE753D8dbB3E5F04861dB38E9DB70c3D', - seniorTrancheVault: '0x4cdCedcF50266aD9ed809048BC9874320EC902bC', - juniorTrancheVault: '0x483D02C11f8F1E31C267040A6C86AaB80c428BaB', - epochManager: '0x1a2C87Be5e785493310526faA7739Bbe4E10c0F6', + pool: '0x51051d2E2bac59b525C7f001E91d31193c4CafFe', + poolConfig: '0xcEC52856813d5061FdCDEC8A7464B685294c5cad', + poolCredit: '0x7eb695ad4D4ffC80548b520F3f0E277b14c564db', + poolCreditManager: '0xA4Ab74C3618Eda38DB4E63bA4D91fb5b9aB2b209', + poolSafe: '0x7DFB8cF225e760D69939496eE6BaDA4d660D351b', + seniorTrancheVault: '0xD8208374c5E358031e7A81392F705c04106bB990', + juniorTrancheVault: '0xB135B9cfE868D456B5Fa480817E830960BdE80b3', + epochManager: '0x7297862107E73794BF44332B1654bf3708018310', receivable: '0x89B599dCc82c42Ef2f17ae39c44e4F6764003518', poolUnderlyingToken: { address: '0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4', @@ -27,8 +27,8 @@ export const SCROLL_METADATA: PoolsInfoV2 = { }, firstLossCovers: { [FirstLossCoverIndex.borrower]: - '0xceA6753113741f82A7a3d86355D4d9BB7126F25E', - [FirstLossCoverIndex.admin]: '0x4222372912cc6554a11ecBeC141cBf6b7d62B630', + '0xb3629a52e5FC292d1f0f8EB927ADabe872b5e5a3', + [FirstLossCoverIndex.admin]: '0xc4E07CFa7Ae39f595895B43bd35dc078f7FE6eF1', }, seniorAPY: '10-20%', juniorAPY: '10-20%', From 0a1fefaf5b349c015ffaa5145340b10be2ac9835 Mon Sep 17 00:00:00 2001 From: shan-57blocks Date: Tue, 31 Dec 2024 22:22:28 +0800 Subject: [PATCH 07/16] add useRedemptionStatusV2 --- .../huma-web-shared/src/hooks/usePoolV2.ts | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/packages/huma-web-shared/src/hooks/usePoolV2.ts b/packages/huma-web-shared/src/hooks/usePoolV2.ts index 3a787863..00fb6ffc 100644 --- a/packages/huma-web-shared/src/hooks/usePoolV2.ts +++ b/packages/huma-web-shared/src/hooks/usePoolV2.ts @@ -636,6 +636,52 @@ export function useCancellableRedemptionInfoV2( return [redemptionInfo, refresh] } +type RedemptionStatus = { + numSharesRequested: string + withdrawableAssets: string + cancellableRedemptionShares: string + cancellableRedemptionAssets: string +} + +export function useRedemptionStatusV2( + poolName: POOL_NAME, + trancheType: TrancheType, + account: string | undefined, + provider: JsonRpcProvider | Web3Provider | undefined, +): [RedemptionStatus | undefined, () => void] { + const [redemptionStatus, setRedemptionStatus] = useState() + const vaultContract = useTrancheVaultContractV2( + poolName, + trancheType, + provider, + ) + const [refreshCount, refresh] = useForceRefresh() + + useEffect(() => { + if (account && vaultContract) { + const fetchData = async () => { + const redemptionRecords = await vaultContract.lenderRedemptionRecords( + account, + ) + const cancellableRedemptionShares = + await vaultContract.cancellableRedemptionShares(account) + const cancellableRedemptionAssets = await vaultContract.convertToAssets( + cancellableRedemptionShares, + ) + setRedemptionStatus({ + numSharesRequested: redemptionRecords.numSharesRequested.toString(), + withdrawableAssets: redemptionRecords.totalAmountProcessed.toString(), + cancellableRedemptionShares: cancellableRedemptionShares.toString(), + cancellableRedemptionAssets: cancellableRedemptionAssets.toString(), + }) + } + fetchData() + } + }, [account, vaultContract, refreshCount]) + + return [redemptionStatus, refresh] +} + export function useCreditStatsV2( poolName: POOL_NAME, account: string | undefined, From 75ab86b398138b4969a5494620979ddcffffa636 Mon Sep 17 00:00:00 2001 From: shan-57blocks Date: Tue, 31 Dec 2024 22:58:20 +0800 Subject: [PATCH 08/16] map old arf 3 months pool scroll receivables --- packages/huma-sdk/src/services/SubgraphService.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/huma-sdk/src/services/SubgraphService.ts b/packages/huma-sdk/src/services/SubgraphService.ts index 32365369..1d1f84f7 100644 --- a/packages/huma-sdk/src/services/SubgraphService.ts +++ b/packages/huma-sdk/src/services/SubgraphService.ts @@ -1,13 +1,13 @@ import { + CHAIN_POOLS_INFO_V2, + ChainEnum, CreditEvent, + isV2Pool, POOL_NAME, POOL_TYPE, PoolContractMap, PoolSubgraphMap, RealWorldReceivableInfoBase, - CHAIN_POOLS_INFO_V2, - ChainEnum, - isV2Pool, requestPost, } from '@huma-finance/shared' import { gql } from 'graphql-request' @@ -258,6 +258,14 @@ function getReceivableV2Info( poolAddress = CHAIN_POOLS_INFO_V2[chainId as ChainEnum]?.[poolName]?.pool } + const ARF_3_MONTH_POOL_SCROLL_OLD = + '0x5227254a6aCa397e95F310b52f6D3143A5A9Ee14' + const ARF_3_MONTH_POOL_SCROLL_NEW = + '0x51051d2E2bac59b525C7f001E91d31193c4CafFe' + if (poolAddress === ARF_3_MONTH_POOL_SCROLL_NEW) { + poolAddress = ARF_3_MONTH_POOL_SCROLL_OLD + } + const ReceivablesV2Query = ` query { rwreceivables( From 96b33728642e4750cb31f74ddf1df2c843b7a3a9 Mon Sep 17 00:00:00 2001 From: shan-57blocks Date: Tue, 31 Dec 2024 23:04:00 +0800 Subject: [PATCH 09/16] map old arf pool to new pool --- packages/huma-sdk/src/services/SubgraphService.ts | 9 +++------ packages/huma-shared/src/v2/utils/const.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/huma-sdk/src/services/SubgraphService.ts b/packages/huma-sdk/src/services/SubgraphService.ts index 1d1f84f7..7c164f9a 100644 --- a/packages/huma-sdk/src/services/SubgraphService.ts +++ b/packages/huma-sdk/src/services/SubgraphService.ts @@ -1,4 +1,5 @@ import { + ARF_3_MONTH_POOL_SCROLL_MAP, CHAIN_POOLS_INFO_V2, ChainEnum, CreditEvent, @@ -258,12 +259,8 @@ function getReceivableV2Info( poolAddress = CHAIN_POOLS_INFO_V2[chainId as ChainEnum]?.[poolName]?.pool } - const ARF_3_MONTH_POOL_SCROLL_OLD = - '0x5227254a6aCa397e95F310b52f6D3143A5A9Ee14' - const ARF_3_MONTH_POOL_SCROLL_NEW = - '0x51051d2E2bac59b525C7f001E91d31193c4CafFe' - if (poolAddress === ARF_3_MONTH_POOL_SCROLL_NEW) { - poolAddress = ARF_3_MONTH_POOL_SCROLL_OLD + if (poolAddress === ARF_3_MONTH_POOL_SCROLL_MAP.poolNew) { + poolAddress = ARF_3_MONTH_POOL_SCROLL_MAP.poolOld } const ReceivablesV2Query = ` diff --git a/packages/huma-shared/src/v2/utils/const.ts b/packages/huma-shared/src/v2/utils/const.ts index 461b359a..d63659e4 100644 --- a/packages/huma-shared/src/v2/utils/const.ts +++ b/packages/huma-shared/src/v2/utils/const.ts @@ -57,3 +57,12 @@ export const ARF_PERSONA_KYC_COPY = { buttonText: 'GO TO PURCHASE AGREEMENT', }, } + +export const ARF_3_MONTH_POOL_SCROLL_MAP = { + poolOld: '0x5227254a6aCa397e95F310b52f6D3143A5A9Ee14', + poolNew: '0x51051d2E2bac59b525C7f001E91d31193c4CafFe', + seniorTrancheOld: '0x4cdCedcF50266aD9ed809048BC9874320EC902bC', + seniorTrancheNew: '0xD8208374c5E358031e7A81392F705c04106bB990', + juniorTrancheOld: '0x483D02C11f8F1E31C267040A6C86AaB80c428BaB', + juniorTrancheNew: '0xB135B9cfE868D456B5Fa480817E830960BdE80b3', +} From 18dbd92e4f6ac32dd735dfab567b6057a580b289 Mon Sep 17 00:00:00 2001 From: shan-57blocks Date: Tue, 31 Dec 2024 23:35:51 +0800 Subject: [PATCH 10/16] update useRedemptionStatusV2 --- packages/huma-web-shared/src/hooks/usePoolV2.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/huma-web-shared/src/hooks/usePoolV2.ts b/packages/huma-web-shared/src/hooks/usePoolV2.ts index 00fb6ffc..638f965c 100644 --- a/packages/huma-web-shared/src/hooks/usePoolV2.ts +++ b/packages/huma-web-shared/src/hooks/usePoolV2.ts @@ -660,7 +660,7 @@ export function useRedemptionStatusV2( useEffect(() => { if (account && vaultContract) { const fetchData = async () => { - const redemptionRecords = await vaultContract.lenderRedemptionRecords( + const redemptionRecord = await vaultContract.lenderRedemptionRecords( account, ) const cancellableRedemptionShares = @@ -668,9 +668,12 @@ export function useRedemptionStatusV2( const cancellableRedemptionAssets = await vaultContract.convertToAssets( cancellableRedemptionShares, ) + const withdrawableAssets = await vaultContract.withdrawableAssets( + account, + ) setRedemptionStatus({ - numSharesRequested: redemptionRecords.numSharesRequested.toString(), - withdrawableAssets: redemptionRecords.totalAmountProcessed.toString(), + numSharesRequested: redemptionRecord.numSharesRequested.toString(), + withdrawableAssets: withdrawableAssets.toString(), cancellableRedemptionShares: cancellableRedemptionShares.toString(), cancellableRedemptionAssets: cancellableRedemptionAssets.toString(), }) From f94b94b68ecedab04ef74cebe559145e0b27c6ce Mon Sep 17 00:00:00 2001 From: shan-57blocks Date: Wed, 1 Jan 2025 00:12:45 +0800 Subject: [PATCH 11/16] update useRedemptionStatusV2 --- .../huma-web-shared/src/hooks/usePoolV2.ts | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/packages/huma-web-shared/src/hooks/usePoolV2.ts b/packages/huma-web-shared/src/hooks/usePoolV2.ts index 638f965c..8ffea915 100644 --- a/packages/huma-web-shared/src/hooks/usePoolV2.ts +++ b/packages/huma-web-shared/src/hooks/usePoolV2.ts @@ -14,6 +14,7 @@ import { getDueDetailV2, getPoolUnderlyingTokenBalanceV2, getPoolUnderlyingTokenInfoV2, + getTrancheRedemptionStatusV2, isChainEnum, POOL_ABI_V2, POOL_CONFIG_V2_ABI, @@ -650,37 +651,32 @@ export function useRedemptionStatusV2( provider: JsonRpcProvider | Web3Provider | undefined, ): [RedemptionStatus | undefined, () => void] { const [redemptionStatus, setRedemptionStatus] = useState() - const vaultContract = useTrancheVaultContractV2( - poolName, - trancheType, - provider, - ) const [refreshCount, refresh] = useForceRefresh() useEffect(() => { - if (account && vaultContract) { + if (account) { const fetchData = async () => { - const redemptionRecord = await vaultContract.lenderRedemptionRecords( - account, - ) - const cancellableRedemptionShares = - await vaultContract.cancellableRedemptionShares(account) - const cancellableRedemptionAssets = await vaultContract.convertToAssets( - cancellableRedemptionShares, - ) - const withdrawableAssets = await vaultContract.withdrawableAssets( + const redemptionStatus = await getTrancheRedemptionStatusV2( + poolName, + trancheType, account, + provider, ) - setRedemptionStatus({ - numSharesRequested: redemptionRecord.numSharesRequested.toString(), - withdrawableAssets: withdrawableAssets.toString(), - cancellableRedemptionShares: cancellableRedemptionShares.toString(), - cancellableRedemptionAssets: cancellableRedemptionAssets.toString(), - }) + if (redemptionStatus) { + setRedemptionStatus({ + numSharesRequested: + redemptionStatus.lenderRedemptionRecords.numSharesRequested.toString(), + withdrawableAssets: redemptionStatus.withdrawableAssets.toString(), + cancellableRedemptionShares: + redemptionStatus.cancellableRedemptionShares.toString(), + cancellableRedemptionAssets: + redemptionStatus.cancellableRedemptionAssets.toString(), + }) + } } fetchData() } - }, [account, vaultContract, refreshCount]) + }, [account, poolName, provider, trancheType, refreshCount]) return [redemptionStatus, refresh] } From 772a8c7e877698bdd1e64dc1a153affe9e1e56ac Mon Sep 17 00:00:00 2001 From: shan-57blocks Date: Wed, 1 Jan 2025 00:19:43 +0800 Subject: [PATCH 12/16] remove unused useRedemptionStatusV2 --- .../huma-web-shared/src/hooks/usePoolV2.ts | 45 ------------------- 1 file changed, 45 deletions(-) diff --git a/packages/huma-web-shared/src/hooks/usePoolV2.ts b/packages/huma-web-shared/src/hooks/usePoolV2.ts index 8ffea915..3a787863 100644 --- a/packages/huma-web-shared/src/hooks/usePoolV2.ts +++ b/packages/huma-web-shared/src/hooks/usePoolV2.ts @@ -14,7 +14,6 @@ import { getDueDetailV2, getPoolUnderlyingTokenBalanceV2, getPoolUnderlyingTokenInfoV2, - getTrancheRedemptionStatusV2, isChainEnum, POOL_ABI_V2, POOL_CONFIG_V2_ABI, @@ -637,50 +636,6 @@ export function useCancellableRedemptionInfoV2( return [redemptionInfo, refresh] } -type RedemptionStatus = { - numSharesRequested: string - withdrawableAssets: string - cancellableRedemptionShares: string - cancellableRedemptionAssets: string -} - -export function useRedemptionStatusV2( - poolName: POOL_NAME, - trancheType: TrancheType, - account: string | undefined, - provider: JsonRpcProvider | Web3Provider | undefined, -): [RedemptionStatus | undefined, () => void] { - const [redemptionStatus, setRedemptionStatus] = useState() - const [refreshCount, refresh] = useForceRefresh() - - useEffect(() => { - if (account) { - const fetchData = async () => { - const redemptionStatus = await getTrancheRedemptionStatusV2( - poolName, - trancheType, - account, - provider, - ) - if (redemptionStatus) { - setRedemptionStatus({ - numSharesRequested: - redemptionStatus.lenderRedemptionRecords.numSharesRequested.toString(), - withdrawableAssets: redemptionStatus.withdrawableAssets.toString(), - cancellableRedemptionShares: - redemptionStatus.cancellableRedemptionShares.toString(), - cancellableRedemptionAssets: - redemptionStatus.cancellableRedemptionAssets.toString(), - }) - } - } - fetchData() - } - }, [account, poolName, provider, trancheType, refreshCount]) - - return [redemptionStatus, refresh] -} - export function useCreditStatsV2( poolName: POOL_NAME, account: string | undefined, From 3f2a800ff3456057ab9a225a13a06cf033a3e4a5 Mon Sep 17 00:00:00 2001 From: humaci Date: Tue, 31 Dec 2024 16:33:53 +0000 Subject: [PATCH 13/16] v0.0.64 --- lerna.json | 2 +- packages/huma-sdk/package.json | 4 ++-- packages/huma-shared/package.json | 2 +- packages/huma-web-shared/package.json | 2 +- packages/huma-widget/package.json | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lerna.json b/lerna.json index 38de5172..f0ec247b 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", "useWorkspaces": true, - "version": "0.0.63" + "version": "0.0.64" } diff --git a/packages/huma-sdk/package.json b/packages/huma-sdk/package.json index 4a36c118..4e231765 100644 --- a/packages/huma-sdk/package.json +++ b/packages/huma-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@huma-finance/sdk", - "version": "0.0.63", + "version": "0.0.64", "types": "./dist/index.d.ts", "main": "./dist/cjs/index.js", "module": "./dist/index.js", @@ -29,7 +29,7 @@ "@ethersproject/constants": "^5.7.0", "@ethersproject/contracts": "^5.7.0", "@ethersproject/providers": "^5.6.0", - "@huma-finance/shared": "^0.0.63", + "@huma-finance/shared": "^0.0.64", "@irys/sdk": "^0.2.11", "axios": "^1.4.0", "bignumber.js": "^9.1.1", diff --git a/packages/huma-shared/package.json b/packages/huma-shared/package.json index 828e7a1d..259324cc 100644 --- a/packages/huma-shared/package.json +++ b/packages/huma-shared/package.json @@ -1,6 +1,6 @@ { "name": "@huma-finance/shared", - "version": "0.0.63", + "version": "0.0.64", "types": "./dist/index.d.ts", "main": "./dist/cjs/index.js", "module": "./dist/index.js", diff --git a/packages/huma-web-shared/package.json b/packages/huma-web-shared/package.json index 1e5a530e..c9639fff 100644 --- a/packages/huma-web-shared/package.json +++ b/packages/huma-web-shared/package.json @@ -1,6 +1,6 @@ { "name": "@huma-finance/web-shared", - "version": "0.0.63", + "version": "0.0.64", "types": "./dist/index.d.ts", "main": "./dist/cjs/index.js", "module": "./dist/index.js", diff --git a/packages/huma-widget/package.json b/packages/huma-widget/package.json index 9dfdcc49..f819101d 100644 --- a/packages/huma-widget/package.json +++ b/packages/huma-widget/package.json @@ -1,6 +1,6 @@ { "name": "@huma-finance/widgets", - "version": "0.0.63", + "version": "0.0.64", "publishConfig": { "access": "public" }, @@ -29,9 +29,9 @@ "@ethersproject/experimental": "^5.7.0", "@ethersproject/providers": "^5.6.0", "@ethersproject/units": "^5.6.0", - "@huma-finance/sdk": "^0.0.63", - "@huma-finance/shared": "^0.0.63", - "@huma-finance/web-shared": "^0.0.63", + "@huma-finance/sdk": "^0.0.64", + "@huma-finance/shared": "^0.0.64", + "@huma-finance/web-shared": "^0.0.64", "@mui/x-date-pickers": "^5.0.7", "@notifi-network/notifi-frontend-client": "^1.1.2", "@notifi-network/notifi-react": "^1.1.2", From 221f72d1bfd44a253c00dea504722c006e2d2f57 Mon Sep 17 00:00:00 2001 From: Michael Liu Date: Tue, 31 Dec 2024 12:01:03 -0500 Subject: [PATCH 14/16] Declare payment by token id --- packages/examples/package.json | 1 + .../examples/src/declarePaymentByTokenIdV2.ts | 37 +++++++++++++++++++ .../src/services/v2/HumaReceivableHandler.ts | 18 +++++++++ 3 files changed, 56 insertions(+) create mode 100644 packages/examples/src/declarePaymentByTokenIdV2.ts diff --git a/packages/examples/package.json b/packages/examples/package.json index 97a17e40..3e524037 100644 --- a/packages/examples/package.json +++ b/packages/examples/package.json @@ -11,6 +11,7 @@ "startCreateAlt": "ts-node src/createReceivableAlternateNetwork.ts", "startPay": "ts-node src/payReceivable.ts", "startPayReference": "ts-node src/payReceivableWithReferenceId.ts", + "startDeclarePaymentByTokenIdV2": "ts-node src/declarePaymentByTokenIdV2.ts", "startDrawdownPayback": "ts-node src/drawdownAndPaybackToPool.ts", "startDrawdownPaybackV2": "ts-node src/drawdownAndPaybackReceivableV2.ts", "startPoolHelpers": "ts-node src/poolContract.ts", diff --git a/packages/examples/src/declarePaymentByTokenIdV2.ts b/packages/examples/src/declarePaymentByTokenIdV2.ts new file mode 100644 index 00000000..8d8802d2 --- /dev/null +++ b/packages/examples/src/declarePaymentByTokenIdV2.ts @@ -0,0 +1,37 @@ +import { BigNumber, Wallet, ethers } from 'ethers' +import { ChainEnum, POOL_NAME, POOL_TYPE } from '@huma-finance/shared' +import { HumaReceivableHandler, HumaContext } from '@huma-finance/sdk' +require('dotenv').config() + +async function main() { + const TEST_PRIVATE_KEY = process.env.TEST_PRIVATE_KEY + const provider = new ethers.providers.JsonRpcProvider( + `https://rpc-amoy.polygon.technology`, + { + name: 'Amoy', + chainId: ChainEnum.Amoy, + }, + ) + const wallet = new Wallet(TEST_PRIVATE_KEY, provider) + + const humaContext = new HumaContext({ + signer: wallet, + provider, + chainId: ChainEnum.Amoy, + poolName: POOL_NAME.ArfCreditPoolV2, + poolType: POOL_TYPE.ReceivableBackedCreditLine, + }) + const receivableHandler = new HumaReceivableHandler({ + humaContext, + }) + + // Mint a receivable with metadata uploaded to ARWeave + const tx = await receivableHandler.declarePaymentByTokenId( + BigNumber.from(10), // receivableAmount + BigNumber.from(1), // token ID + ) + const txResponse = await tx.wait() + console.log(`Success. Tx hash: ${txResponse.transactionHash}`) +} + +main() diff --git a/packages/huma-sdk/src/services/v2/HumaReceivableHandler.ts b/packages/huma-sdk/src/services/v2/HumaReceivableHandler.ts index a225aa6d..7b67add0 100644 --- a/packages/huma-sdk/src/services/v2/HumaReceivableHandler.ts +++ b/packages/huma-sdk/src/services/v2/HumaReceivableHandler.ts @@ -48,6 +48,24 @@ export class HumaReceivableHandler { return contract.declarePayment(tokenId, paymentAmount, gasOpts) } + async declarePaymentByTokenId( + paymentAmount: BigNumber, + tokenId: BigNumber, + gasOpts: Overrides = {}, + ): Promise { + const contract = await getReceivableContractV2( + this.#humaContext.poolName, + this.#humaContext.signer, + ) + if (!contract) { + throw new Error('Could not find Receivable contract') + } + + gasOpts = await getDefaultGasOptions(gasOpts, this.#humaContext.chainId) + + return contract.declarePayment(tokenId, paymentAmount, gasOpts) + } + async burnReceivable( tokenId: BigNumberish, gasOpts: Overrides = {}, From 8c4de87f3cdd93b8f8b16e976faf71846af3b214 Mon Sep 17 00:00:00 2001 From: humaci Date: Tue, 31 Dec 2024 17:08:32 +0000 Subject: [PATCH 15/16] v0.0.65 --- lerna.json | 2 +- packages/huma-sdk/package.json | 4 ++-- packages/huma-shared/package.json | 2 +- packages/huma-web-shared/package.json | 2 +- packages/huma-widget/package.json | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lerna.json b/lerna.json index f0ec247b..dbb8737a 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", "useWorkspaces": true, - "version": "0.0.64" + "version": "0.0.65" } diff --git a/packages/huma-sdk/package.json b/packages/huma-sdk/package.json index 4e231765..3417bf12 100644 --- a/packages/huma-sdk/package.json +++ b/packages/huma-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@huma-finance/sdk", - "version": "0.0.64", + "version": "0.0.65", "types": "./dist/index.d.ts", "main": "./dist/cjs/index.js", "module": "./dist/index.js", @@ -29,7 +29,7 @@ "@ethersproject/constants": "^5.7.0", "@ethersproject/contracts": "^5.7.0", "@ethersproject/providers": "^5.6.0", - "@huma-finance/shared": "^0.0.64", + "@huma-finance/shared": "^0.0.65", "@irys/sdk": "^0.2.11", "axios": "^1.4.0", "bignumber.js": "^9.1.1", diff --git a/packages/huma-shared/package.json b/packages/huma-shared/package.json index 259324cc..26b2857d 100644 --- a/packages/huma-shared/package.json +++ b/packages/huma-shared/package.json @@ -1,6 +1,6 @@ { "name": "@huma-finance/shared", - "version": "0.0.64", + "version": "0.0.65", "types": "./dist/index.d.ts", "main": "./dist/cjs/index.js", "module": "./dist/index.js", diff --git a/packages/huma-web-shared/package.json b/packages/huma-web-shared/package.json index c9639fff..5ae53854 100644 --- a/packages/huma-web-shared/package.json +++ b/packages/huma-web-shared/package.json @@ -1,6 +1,6 @@ { "name": "@huma-finance/web-shared", - "version": "0.0.64", + "version": "0.0.65", "types": "./dist/index.d.ts", "main": "./dist/cjs/index.js", "module": "./dist/index.js", diff --git a/packages/huma-widget/package.json b/packages/huma-widget/package.json index f819101d..eaae68ae 100644 --- a/packages/huma-widget/package.json +++ b/packages/huma-widget/package.json @@ -1,6 +1,6 @@ { "name": "@huma-finance/widgets", - "version": "0.0.64", + "version": "0.0.65", "publishConfig": { "access": "public" }, @@ -29,9 +29,9 @@ "@ethersproject/experimental": "^5.7.0", "@ethersproject/providers": "^5.6.0", "@ethersproject/units": "^5.6.0", - "@huma-finance/sdk": "^0.0.64", - "@huma-finance/shared": "^0.0.64", - "@huma-finance/web-shared": "^0.0.64", + "@huma-finance/sdk": "^0.0.65", + "@huma-finance/shared": "^0.0.65", + "@huma-finance/web-shared": "^0.0.65", "@mui/x-date-pickers": "^5.0.7", "@notifi-network/notifi-frontend-client": "^1.1.2", "@notifi-network/notifi-react": "^1.1.2", From 15e469d89525881ad065ed1d3ff5619d19f28a0e Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 2 Jan 2025 16:39:42 +0800 Subject: [PATCH 16/16] update number util --- packages/huma-shared/src/utils/number.ts | 49 +++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/packages/huma-shared/src/utils/number.ts b/packages/huma-shared/src/utils/number.ts index 768e2d8c..e935a77a 100644 --- a/packages/huma-shared/src/utils/number.ts +++ b/packages/huma-shared/src/utils/number.ts @@ -30,6 +30,25 @@ export const formatMoney = ( return moneyFormatter.format(numCast) } +export const formatMoneyFixed = ( + num: number | string | undefined, + toFixed = 0, +) => { + if (isEmpty(num) || Number.isNaN(num)) { + return num + } + + const numCast = Number(num) + const moneyFormatter = new Intl.NumberFormat('en-US', { + style: 'currency', + currency: 'USD', + minimumFractionDigits: toFixed, + maximumFractionDigits: toFixed, + }) + + return moneyFormatter.format(numCast) +} + export const formatAssets = ( assets: BigNumberish | undefined, decimals: number | undefined, @@ -50,6 +69,22 @@ export const formatNumber = (num: number | string | undefined) => { return numberFormatter.format(numCast) } +export const formatNumberFixed = ( + num: number | string | undefined, + toFixed = 0, +) => { + if (isEmpty(num) || Number.isNaN(num)) { + return num + } + + const numberFormatter = new Intl.NumberFormat('en-US', { + maximumFractionDigits: toFixed, + minimumFractionDigits: toFixed, + }) + const numCast = Number(num) + return numberFormatter.format(numCast) +} + export const formatAmount = ( assets: BigNumberish | undefined, decimals: number | undefined, @@ -125,5 +160,17 @@ export const formatBNFixed = ( return '--' } const amount = ethers.utils.formatUnits(amountBN, decimals) - return Number(amount).toFixed(toFixed) + return formatNumberFixed(amount, toFixed) +} + +export const formatMoneyBNFixed = ( + amountBN: BigNumber | undefined, + decimals: number, + toFixed: number = 0, +) => { + if (!amountBN) { + return '--' + } + const amount = ethers.utils.formatUnits(amountBN, decimals) + return formatMoneyFixed(amount, toFixed) }