-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NONEVM-629: Link Token Changes (#535)
- Loading branch information
1 parent
4be11f6
commit bfc10fe
Showing
19 changed files
with
440 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
mod erc677; | ||
mod v1; | ||
mod v2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod erc677; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod erc677; | ||
mod erc677_receiver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use starknet::ContractAddress; | ||
|
||
const IERC677_ID: felt252 = 0x3c4538abc63e0cdf912cef3d2e1389d0b2c3f24ee0c06b21736229f52ece6c8; | ||
|
||
#[starknet::interface] | ||
trait IERC677<TContractState> { | ||
fn transfer_and_call( | ||
ref self: TContractState, to: ContractAddress, value: u256, data: Array<felt252> | ||
) -> bool; | ||
} | ||
|
||
#[starknet::component] | ||
mod ERC677Component { | ||
use starknet::ContractAddress; | ||
use openzeppelin::token::erc20::interface::IERC20; | ||
use openzeppelin::introspection::interface::{ISRC5, ISRC5Dispatcher, ISRC5DispatcherTrait}; | ||
use array::ArrayTrait; | ||
use array::SpanTrait; | ||
use clone::Clone; | ||
use array::ArrayTCloneImpl; | ||
use chainlink::libraries::token::v2::erc677_receiver::{ | ||
IERC677ReceiverDispatcher, IERC677ReceiverDispatcherTrait, IERC677_RECEIVER_ID | ||
}; | ||
|
||
#[storage] | ||
struct Storage {} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
TransferAndCall: TransferAndCall, | ||
} | ||
|
||
#[derive(Drop, starknet::Event)] | ||
struct TransferAndCall { | ||
#[key] | ||
from: ContractAddress, | ||
#[key] | ||
to: ContractAddress, | ||
value: u256, | ||
data: Array<felt252> | ||
} | ||
|
||
#[embeddable_as(ERC677Impl)] | ||
impl ERC677< | ||
TContractState, | ||
+HasComponent<TContractState>, | ||
+IERC20<TContractState>, | ||
+Drop<TContractState>, | ||
> of super::IERC677<ComponentState<TContractState>> { | ||
fn transfer_and_call( | ||
ref self: ComponentState<TContractState>, | ||
to: ContractAddress, | ||
value: u256, | ||
data: Array<felt252> | ||
) -> bool { | ||
let sender = starknet::info::get_caller_address(); | ||
|
||
let mut contract = self.get_contract_mut(); | ||
contract.transfer(to, value); | ||
self | ||
.emit( | ||
Event::TransferAndCall( | ||
TransferAndCall { from: sender, to: to, value: value, data: data.clone(), } | ||
) | ||
); | ||
|
||
let receiver = ISRC5Dispatcher { contract_address: to }; | ||
|
||
let supports = receiver.supports_interface(IERC677_RECEIVER_ID); | ||
|
||
if supports { | ||
IERC677ReceiverDispatcher { contract_address: to } | ||
.on_token_transfer(sender, value, data); | ||
} | ||
true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use starknet::ContractAddress; | ||
|
||
const IERC677_RECEIVER_ID: felt252 = | ||
0x224f0246bc4ebdcc391196e93f522342f12393c1a456db2a57043638940254; | ||
|
||
#[starknet::interface] | ||
trait IERC677Receiver<TContractState> { | ||
fn on_token_transfer( | ||
ref self: TContractState, sender: ContractAddress, value: u256, data: Array<felt252> | ||
); | ||
} | ||
|
||
#[starknet::component] | ||
mod ERC677ReceiverComponent { | ||
use openzeppelin::introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; | ||
use openzeppelin::introspection::src5::SRC5Component; | ||
use starknet::ContractAddress; | ||
use super::{IERC677Receiver, IERC677_RECEIVER_ID}; | ||
|
||
#[storage] | ||
struct Storage {} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event {} | ||
|
||
#[generate_trait] | ||
impl InternalImpl< | ||
TContractState, | ||
+HasComponent<TContractState>, | ||
// ensure that the contract implements the IERC677Receiver interface | ||
+IERC677Receiver<TContractState>, | ||
impl SRC5: SRC5Component::HasComponent<TContractState>, | ||
+Drop<TContractState> | ||
> of InternalTrait<TContractState> { | ||
/// Initializes the contract by registering the IERC677Receiver interface ID. | ||
/// This should be used inside the contract's constructor. | ||
fn initializer(ref self: ComponentState<TContractState>) { | ||
let mut src5_component = get_dep_component_mut!(ref self, SRC5); | ||
src5_component.register_interface(IERC677_RECEIVER_ID); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
trait IERC677Receiver { | ||
fn on_token_transfer(sender: ContractAddress, value: u256, data: Array<felt252>); | ||
} | ||
|
||
trait IERC677 { | ||
fn transfer_and_call(to: ContractAddress, value: u256, data: Array<felt252>) -> bool; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
mod link_token; | ||
mod v1; | ||
mod v2; | ||
mod mock; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.